Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
8ab4d2b
test(bots): cover complete action cards in the mounted chat
bvsr365 Nov 16, 2026
e3045fa
feat(bots): review and answer complete stored action cards in chat
bvsr365 Nov 16, 2026
4d8827a
test(bots): cover settled card find ranges and service-level About co…
bvsr365 Nov 16, 2026
eb2916c
fix(bots): give settled action statuses matching find highlights
bvsr365 Nov 16, 2026
d202bd8
test(bots): distinguish nested hidden fields from escaped literal mar…
bvsr365 Nov 16, 2026
ed73693
fix(bots): preserve real hidden markers inside literal argument objects
bvsr365 Nov 16, 2026
377731c
docs(bots): explain reviewing held calls in chat
bvsr365 Nov 16, 2026
742d1da
test(bots): require stored action cards in service chat
bvsr365 Nov 16, 2026
4ff1463
feat(bots): project stored masked action cards in chat
bvsr365 Nov 16, 2026
9eac949
test(bots): require repeat warnings for calls reaching the server
bvsr365 Nov 16, 2026
2e1f932
feat(bots): warn when identical work already reached the service
bvsr365 Nov 16, 2026
0b29acb
test(bots): require bridge cards and oversized review fallback
bvsr365 Nov 16, 2026
1781ba4
feat(bots): keep bridge action reviews complete or disable Send
bvsr365 Nov 16, 2026
80f99c5
test(bots): require per-service asks-first About marks
bvsr365 Nov 16, 2026
96fddc8
feat(bots): mark asking services in About without tool names
bvsr365 Nov 16, 2026
580a393
test(bots): require action-name-only telling through quiet hours
bvsr365 Nov 16, 2026
630dd40
feat(bots): tell held actions by name through existing telling rules
bvsr365 Nov 16, 2026
be28eeb
test(bots): require readable safe action names
bvsr365 Nov 16, 2026
4b76604
fix(bots): clean action names before storing review titles
bvsr365 Nov 16, 2026
ff167e5
test(bots): require hidden paths through escaped argument objects
bvsr365 Nov 16, 2026
67e8dfa
fix(bots): retain hidden paths within escaped argument containers
bvsr365 Nov 16, 2026
9816be8
test(bots): prioritize held actions in folded telling
bvsr365 Nov 16, 2026
e24a361
fix(bots): prioritize held actions in folded notifications
bvsr365 Nov 16, 2026
4f83dbe
refactor(bots): read only review fields when projecting action cards
bvsr365 Nov 16, 2026
b18e4fb
refactor(bots): use the shared action card contract in chat
bvsr365 Nov 16, 2026
5509195
fix(bots): resolve the shared action card type from the renderer
bvsr365 Nov 16, 2026
9904680
test(bots): preserve hidden field path segments across devices
bvsr365 Nov 16, 2026
fb53a78
fix(bots): keep hidden field paths as distinct segments
bvsr365 Nov 16, 2026
1c33821
test(bots): detect duplicate actions across a bot’s work and schedules
bvsr365 Nov 16, 2026
ab1d38a
fix(bots): warn about identical actions across the same bot
bvsr365 Nov 16, 2026
3677705
test(bots): qualify the asks-first service tooltip
bvsr365 Nov 16, 2026
a1aba2a
fix(bots): qualify when a service asks before actions
bvsr365 Nov 16, 2026
ad297f1
test(bots): cover action telling when only needs-you updates are wanted
bvsr365 Nov 16, 2026
cf781ea
test(bots): bound folded telling to one projection per row
bvsr365 Nov 16, 2026
d305d34
perf(bots): project each folded notification row once
bvsr365 Nov 16, 2026
cab5308
docs(bots): explain card data, repeat limits and title search
bvsr365 Nov 16, 2026
6d2e424
test(bots): separate hostile card data from Mousse notices
bvsr365 Nov 16, 2026
6a12a30
fix(bots): frame action data and quote bot notes apart from notices
bvsr365 Nov 16, 2026
b36a3fa
test(bots): distinguish strings from scalar and empty data
bvsr365 Nov 16, 2026
50d4642
fix(bots): render scalar-looking strings and non-text values distinctly
bvsr365 Nov 16, 2026
6c514d0
test(bots): keep settled action cards compact and timed
bvsr365 Nov 16, 2026
7809454
fix(bots): fold settled action arguments behind a compact summary
bvsr365 Nov 16, 2026
fa3f482
test(bots): expose long values and remaining scrollable arguments
bvsr365 Nov 16, 2026
e9a47ff
fix(bots): fold long argument values and signal more below
bvsr365 Nov 16, 2026
e0cd9ab
test(bots): cover the actual too-large device stub
bvsr365 Nov 16, 2026
fc67e71
fix(bots): explain too-large cards without drawing missing arguments
bvsr365 Nov 16, 2026
0aa27af
test(bots): preserve hidden-field segment boundaries and long names
bvsr365 Nov 16, 2026
916e0f7
fix(bots): quote each stored hidden-field path segment independently
bvsr365 Nov 16, 2026
632df29
test(bots): guard invisible characters and look-alike address letters
bvsr365 Nov 16, 2026
2bc30be
fix(bots): share the text guard and flag look-alike address data
bvsr365 Nov 16, 2026
bf76a9f
test(bots): date earlier repeated action warnings
bvsr365 Nov 16, 2026
e3fc68b
fix(bots): include the calendar day on earlier repeated calls
bvsr365 Nov 16, 2026
b69643c
test(bots): retain service refusal reasons and redraw settled rows
bvsr365 Nov 16, 2026
24e0778
fix(bots): show structured service refusals after refreshing the card
bvsr365 Nov 16, 2026
beabe81
test(bots): pair literal card title matches with highlight ranges
bvsr365 Nov 16, 2026
3ad943f
fix(bots): index literal card titles and visible status as separate p…
bvsr365 Nov 16, 2026
0179885
fix(bots): keep expanded argument text in the outer scroll region
bvsr365 Nov 16, 2026
339d19c
refactor(bots): align renderer fixtures with the review contract
bvsr365 Nov 16, 2026
82dbeb3
test(bots): update the argument cue when a fold opens
bvsr365 Nov 16, 2026
14695ac
fix(bots): observe argument folds through the native capture API
bvsr365 Nov 16, 2026
81dbec3
fix(bots): show every collapsed argument field before scrolling
bvsr365 Nov 16, 2026
568d2df
docs(bots): state which card data chat search excludes
bvsr365 Nov 16, 2026
9d5327b
test(bots): name settled reviews by what happened
bvsr365 Nov 16, 2026
0193d7a
test(bots): lead settled reviews with their outcome
bvsr365 Nov 16, 2026
8063ad9
test(bots): distinguish quotes inside text and empty-label text
bvsr365 Nov 16, 2026
fc37037
test(bots): note non-ASCII address and phone characters
bvsr365 Nov 16, 2026
81ad0a6
test(bots): make empty and multiline field names readable
bvsr365 Nov 16, 2026
6fce8dc
test(bots): keep quote-shaped hidden names inside one segment
bvsr365 Nov 16, 2026
6fd7cc7
test(bots): keep folded notification projection cost unchanged
bvsr365 Nov 16, 2026
650e6c5
test(bots): skip repeat lookups for settled cards
bvsr365 Nov 16, 2026
e8b7334
fix(bots): reserve the shield for permission asks
bvsr365 Nov 16, 2026
5efdd9f
fix(bots): describe reviews in the owner’s words
bvsr365 Nov 16, 2026
389e196
fix(bots): put the outcome first on settled reviews
bvsr365 Nov 16, 2026
eef6faf
style(bots): show field names in the normal font
bvsr365 Nov 16, 2026
96b6a27
style(bots): indent nested fields under their parent
bvsr365 Nov 16, 2026
2f828cb
fix(bots): escape quoted text and the empty-text label
bvsr365 Nov 16, 2026
405f9fe
fix(bots): note non-ASCII address and phone data neutrally
bvsr365 Nov 16, 2026
17ae00a
fix(bots): show line breaks and empty field names explicitly
bvsr365 Nov 16, 2026
fb685d1
fix(bots): draw hidden names as unquoted data segments
bvsr365 Nov 16, 2026
360c2fd
test(bots): exercise both projection switches in the telling fixture
bvsr365 Nov 16, 2026
083d440
perf(bots): project only the first folded notification message
bvsr365 Nov 16, 2026
0ccd720
perf(bots): look for previous sends only on open reviews
bvsr365 Nov 16, 2026
3019389
docs(bots): describe outcome-led reviews and data labels
bvsr365 Nov 16, 2026
70accd8
test(bots): keep settled cost fixtures within the action schema
bvsr365 Nov 16, 2026
ad51ca3
merge: keep held-call lifecycle and current bot permissions with revi…
bvsr365 Nov 16, 2026
9fe9450
test(bots): distinguish held service waits from dispatch and timeout
bvsr365 Nov 16, 2026
e29306a
fix(bots): show stored service waits and accepted-window timeout outc…
bvsr365 Nov 16, 2026
a6de1a0
test(bots): erase forgotten card content while preserving its outcome
bvsr365 Nov 16, 2026
cf24d2d
fix(bots): project forgotten reviews as content-free timed outcomes
bvsr365 Nov 16, 2026
bafedca
test(bots): resolve complete nudge cards from their original held row
bvsr365 Nov 16, 2026
337aff5
fix(bots): reread original stored action cards for their two nudges
bvsr365 Nov 16, 2026
0202cf2
test(bots): cover real forgetting and all seven protocol refusal sent…
bvsr365 Nov 16, 2026
884a73a
test(bots): retain exact refusal text when its card disappears
bvsr365 Nov 16, 2026
3ba4129
fix(bots): keep service refusals visible after a gone card is refreshed
bvsr365 Nov 16, 2026
05aad6f
test(bots): retain timeout outcomes on oversized device reviews
bvsr365 Nov 16, 2026
f4a5974
fix(bots): retain timed-out service outcomes in oversized device cards
bvsr365 Nov 16, 2026
cc58ec2
test(bots): preserve no-action snapshots and valid named outcome times
bvsr365 Nov 16, 2026
818f4e8
test(bots): keep approved review wording distinct from active dispatch
bvsr365 Nov 16, 2026
fb48e1d
fix(bots): describe approved reviews as waiting to send
bvsr365 Nov 16, 2026
e25a838
docs(bots): explain accepted waits and forgotten reviews
bvsr365 Nov 16, 2026
2225d00
test(bots): follow up held actions from their first telling
bvsr365 Nov 16, 2026
172ca91
feat(bots): nudge open held cards through question follow-ups
bvsr365 Nov 16, 2026
a142b07
test(bots): hold action nudges through quiet hours without wake excep…
bvsr365 Nov 16, 2026
4d68423
fix(bots): defer action nudges for quiet hours without exceptions
bvsr365 Nov 16, 2026
443df74
test(bots): share question nudge spacing and preserve delivery receipts
bvsr365 Nov 16, 2026
0af8197
fix(bots): share spacing budgets between questions and held actions
bvsr365 Nov 16, 2026
15da777
test(bots): suppress stale pending nudges across switch and quiet cha…
bvsr365 Nov 16, 2026
910774a
fix(bots): suppress settled pending nudges after switch-off
bvsr365 Nov 16, 2026
e030dab
test(bots): process due action nudges with a moving wall clock
bvsr365 Nov 16, 2026
6d5f9be
fix(bots): use the upkeep clock when selecting due action nudges
bvsr365 Nov 16, 2026
5d39318
docs(bots): explain telling-based action nudge timing
bvsr365 Nov 16, 2026
024383e
merge: take current bot engine and chat changes into review cards
bvsr365 Nov 17, 2026
a5830ec
test(bots): expose owner MCP calls refused by use_tool
bvsr365 Nov 17, 2026
6d4d432
test(bots): cover merged sidebar About usage and readable MCP review …
bvsr365 Nov 17, 2026
cb06f70
fix(bots): show the stored readable review name in sidebar state words
bvsr365 Nov 17, 2026
b62504a
test(bots): keep own-tool permission notifications in plain card words
bvsr365 Nov 17, 2026
e28665a
test(bots): keep owner MCP offers separate from registered catalogue …
bvsr365 Nov 17, 2026
1d8bc9c
test(bots): expose held action facts missing from resumed epochs
bvsr365 Nov 17, 2026
ebb262a
test(bots): cover action digest inputs and job report bridge projection
bvsr365 Nov 17, 2026
8ad38fd
fix(bots): carry held action facts into resumed chat and digests
bvsr365 Nov 17, 2026
5fa1582
test(bots): refuse wrapped owner MCP names on Claude too
bvsr365 Nov 17, 2026
b9ad1ef
docs(bots): explain review updates in resumed conversations
bvsr365 Nov 17, 2026
831de92
test(bots): retain legacy sidebar words only with asks first off
bvsr365 Nov 17, 2026
29119bf
merge: preserve review nudges with current bot runtime and device rules
bvsr365 Nov 17, 2026
93c1618
test(bots): require the same device preset for both kinds of approval
bvsr365 Nov 17, 2026
ca0f200
fix(bots): hold action approvals to the device Work permission
bvsr365 Nov 17, 2026
b616208
test(bots): preserve single streamed card rows and enforce device rea…
bvsr365 Nov 17, 2026
001cfb1
docs(bots): state the device permission needed to answer a review
bvsr365 Nov 17, 2026
1fef6ba
test(bots): cover wrapped MCP review retries and post-hold fences
bvsr365 Nov 17, 2026
2e9f154
test(bots): cover current action context format and open-question coe…
bvsr365 Nov 17, 2026
79e66ee
fix(bots): serialize review status and nudge context with shared notices
bvsr365 Nov 17, 2026
112bd46
test(bots): check nested retry keys and exact held question answers
bvsr365 Nov 17, 2026
f70ce4b
merge: take the shared tool authority compiler into review cards
bvsr365 Nov 17, 2026
a8882ae
test(bots): fence work and subagent tools through the authority compiler
bvsr365 Nov 17, 2026
97de427
merge: keep scheduled approval lifecycle and complete review cards
bvsr365 Nov 17, 2026
21cfedb
test(bots): keep one review and two quiet lines after action nudges
bvsr365 Nov 17, 2026
1aa6e05
fix(bots): move each full action review to its newest chat row
bvsr365 Nov 17, 2026
583446f
test(bots): distinguish empty names arrows whitespace and wide quotes
bvsr365 Nov 17, 2026
3f8379d
fix(bots): escape ambiguous names and reserve alphabet notes for addr…
bvsr365 Nov 17, 2026
25ce787
test(bots): show one outcome time and avoid repeated expiry and send …
bvsr365 Nov 17, 2026
7acd95c
fix(bots): show one placeable outcome time and concise waiting and ex…
bvsr365 Nov 17, 2026
3104b83
test(bots): expand expired reviews without counting nudge copies
bvsr365 Nov 17, 2026
2e415cf
feat(bots): expand grouped expiries into their compact stored reviews
bvsr365 Nov 17, 2026
76caa95
test(bots): align card wording assertions and cover compact flag-only…
bvsr365 Nov 17, 2026
c9f8db3
test(bots): keep expired reviews closed across nudge refresh ordering
bvsr365 Nov 17, 2026
c5bf0f0
fix(bots): retain known expiry when displaying the newest nudge copy
bvsr365 Nov 17, 2026
ea22413
docs(bots): explain newest review rows and expandable schedule expiries
bvsr365 Nov 17, 2026
d4eca1e
test(bots): retain an asked time before a review settles
bvsr365 Nov 17, 2026
7935cea
fix(bots): label the asked time until a review settles
bvsr365 Nov 17, 2026
95651e4
test(bots): refuse reused action ids for different calls
bvsr365 Nov 17, 2026
748b161
fix(bots): distinguish retries from conflicting held calls
bvsr365 Nov 17, 2026
fd09598
test(bots): expose forgotten action copies and unsafe context framing
bvsr365 Nov 17, 2026
6f36395
fix(bots): quote original review rows in resumed context
bvsr365 Nov 17, 2026
35497cb
fix(bots): record only settled action context facts
bvsr365 Nov 17, 2026
520ae63
fix(bots): forget action context copies and suppress late facts
bvsr365 Nov 17, 2026
83ae662
test(bots): bound nudge history reads and verify pending card policy
bvsr365 Nov 17, 2026
1418459
fix(bots): distinguish waiting cards in unattended cap wording
bvsr365 Nov 17, 2026
3f6b369
perf(bots): share nudge history across open cards and upkeep
bvsr365 Nov 17, 2026
0aa6e58
test(bots): preserve forgotten call receipts and reuse final timer hi…
bvsr365 Nov 17, 2026
c1935e8
fix(bots): acknowledge forgotten call ids without inventing a hold
bvsr365 Nov 17, 2026
832c1ef
perf(bots): reuse nudge history when rearming the upkeep timer
bvsr365 Nov 17, 2026
311ab08
test(bots): remove forgotten action references from context envelopes
bvsr365 Nov 17, 2026
f49e5c5
fix(bots): omit action envelopes for redacted context rows
bvsr365 Nov 17, 2026
f3c19af
test(bots): forget action copies already folded into chat history
bvsr365 Nov 17, 2026
6461c64
fix(bots): invalidate folded history when forgetting action copies
bvsr365 Nov 17, 2026
71ebf6f
test(bots): verify two nudges on long scheduled approval cards
bvsr365 Nov 17, 2026
a85421f
test(bots): align held summary checks with waiting wording
bvsr365 Nov 17, 2026
22753c3
test(bots): retain the tool error outcome on oversized device cards
bvsr365 Nov 17, 2026
3e0c8e5
fix(bots): retain tool error outcomes on oversized device cards
bvsr365 Nov 17, 2026
20b49d8
test(bots): device refusals stay definite before held action effects
bvsr365 Nov 17, 2026
daa8e7c
fix(bots): refuse device sends before effects with precise outcomes
bvsr365 Nov 17, 2026
c92b97d
fix(net): keep held action refusals readable by older peers
bvsr365 Nov 17, 2026
21653a1
test(bots): carry action refusal codes without network sentences
bvsr365 Nov 17, 2026
4fbc5c2
fix(bots): format refusal codes locally without network error text
bvsr365 Nov 17, 2026
8863181
test(net): verify action refusals with the prior error decoder
bvsr365 Nov 17, 2026
2b5ce13
test(bots): retire overdue and obsolete cards during device preflight
bvsr365 Nov 17, 2026
cc92060
fix(bots): retire stale lifecycle state before refusing a device answer
bvsr365 Nov 17, 2026
ac1c8e6
test(bots): expect shared local refusal wording in the chat
bvsr365 Nov 17, 2026
d5d8e08
test(bots): prove device refusals use cached local card names
bvsr365 Nov 17, 2026
4247601
test(bots): keep hidden path boxes free of enclosing quotes
bvsr365 Nov 17, 2026
b8c5650
fix(bots): keep path segment boxes unquoted while escaping their content
bvsr365 Nov 17, 2026
7f46086
test(bots): include action preflight in the scripted reach boundary
bvsr365 Nov 17, 2026
b7fd295
merge: retain review fixes with current approval and tool authority r…
bvsr365 Nov 17, 2026
7d2cf4e
test(bots): exercise canonical refusals through remote conflict reasons
bvsr365 Nov 17, 2026
0c16530
test(bots): preserve changed schedule refusals locally and over devices
bvsr365 Nov 17, 2026
70e73ef
fix(bots): preserve changed schedule refusals with a distinct code
bvsr365 Nov 17, 2026
4f7f40f
test(bots): distinguish reminders and retain the original asked time
bvsr365 Nov 17, 2026
a173f05
fix(bots): label reminders and keep the call original asked time
bvsr365 Nov 17, 2026
bb07456
test(bots): keep expiry history inside its cards with asked times
bvsr365 Nov 17, 2026
9b6a79d
fix(bots): keep expiry history with each compact review
bvsr365 Nov 17, 2026
5163e9a
test(bots): avoid claiming a plain conflict sent nothing
bvsr365 Nov 17, 2026
47420dd
fix(bots): keep unknown conflict wording neutral about prior effects
bvsr365 Nov 17, 2026
85739ac
docs(bots): describe schedule refusal and review history times
bvsr365 Nov 17, 2026
4f35817
fix(bots): read the stored asked timestamp in device projections
bvsr365 Nov 17, 2026
507e9ee
fix(bots): type the named creation time in review projections
bvsr365 Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Use these terms in issues, PRs, comments, and docs. If you need a term that is n
- **Bot work:** something a bot does beside its bot chat, so the chat stays free while it works. The chat hands work off (anything on the web, in the browser, with commands, or with several steps), work runs on a thread of its own, one piece at a time, and its report answers the message that asked for it. While it runs, the owner can ask how it's going, add to it or stop it. Scheduled runs share the same line. See `docs/bots.md`.
- **Reminder (bot):** a one-off time a bot keeps for its owner ("in 20 minutes", "at 9 tomorrow"). It says its text at that time, with no model run, or starts work then. For 24 hours after it is said, a text reminder can be snoozed with quick replies for 10 minutes, 1 hour or tomorrow at 09:00 on this computer. Snoozing creates a new reminder without a model run. Repeating ones are schedules.
- **Ask:** a bot's request for a permission, shown as a card in its bot chat with Allow and Not now. In a chat turn it is a wall; in a run, the bot carries on without the permission and later runs skip that step until the owner answers. A bot has one open ask per permission, and asks never expire. After Not now, a run may ask again only after 24 hours. Allowed permissions are listed in About, with Remove.
- **Asks first:** a tool permission that holds each call for the owner to review its complete masked arguments, then choose Send or Not now. Built behind an experimental switch that stays off. About lists permissions per service; it has no “Always” choice.
- **Held call:** one exact tool call stored by Mousse while its work waits for review. Send names that call and the arguments the card showed; Mousse executes the stored call once. Its card keeps the masked content and outcome afterwards.
- **Question (bot):** a bot's question to its owner with answers to tap: 2 to 5 short choices or yes/no, and "Other…" for an answer in their own words, shown as a bubble with quick replies under the bot's reply. A tap is the owner's reply, but not their own words: the turn it starts can't act on their threads or switch models. Any other message from the owner moves past it, and a later tap still answers it. It grants nothing; a permission is an ask. Work the owner asked for can ask too: it waits for the answer without holding a run slot, shows as waiting on you, and goes on in its own thread once answered. If the owner doesn't answer, Mousse nudges them, or the bot goes with its default answer, as the bot chose when it asked. See `docs/bots.md`, Questions.
- **Nudge:** a fixed line Mousse posts under a bot's question its owner hasn't answered, "Still need your answer on this one.", with the question's buttons again; no model runs. At most two per question (the first when the bot said, the next about a day later), and at most one an hour and three a day per bot. Work that waits on the question keeps waiting.
- **Card (bot):** a small block a bot attaches to its message: facts (keys and values), a checklist, progress, or a gallery of pictures from its files folder. The app draws each kind from its own components; the bot sends only text and numbers. Each also reads as plain text, for notifications, other devices and the bot's memory. See `docs/bots.md`, Cards.
Expand Down
23 changes: 19 additions & 4 deletions docs/bots.md

Large diffs are not rendered by default.

42 changes: 34 additions & 8 deletions src/mms/bots/actions/BotActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import type { BotMcpTool } from '../../../shared/bots/personal/authority'
import type { BotActivationRow, BotStore } from '../store/BotStore'
import { canonicalJson, shortHash } from '../../integrations/revision'
import { maskMemoryCredentials } from '../memory/guard'
import type { BotMcpCallOutcome } from '../mcp/BotMcp'
import { plainText, type BotMcpCallOutcome } from '../mcp/BotMcp'
import type { ToolOutcome } from '../../run/mcp/appTools/types'

/** The sole feature-switch read. No UI sets it until the complete feature ships. */
export function botAsksFirst(settings?: Pick<MousseSettings, 'experimental'>): boolean {
return settings?.experimental.botAsksFirst === true
}
export function readableActionTitle(name: string): string {
const words = plainText(name, 160).replace(/([a-z])([A-Z])/g, '$1 $2').replace(/[_ .:/-]+/g, ' ').trim()
return words ? words[0]!.toUpperCase() + words.slice(1) : 'Send this action'
}
export const actionDigest = (value: unknown): string => shortHash(canonicalJson(value), 64)
const hiddenKey = (key: string): boolean => /(?:authorization|password|passwd|secret|token|apikey)$/i.test(key.replace(/[^a-z0-9]/gi, ''))
export const ACTION_HIDDEN_VALUE = Object.freeze({ $mousse: 'hidden', text: 'hidden · will be sent' })
Expand Down Expand Up @@ -227,6 +231,13 @@ export class BotActions {
}
/** Erase call content without erasing owner intervention facts or the run-once key. */
forgetText(botId: string, actionId?: string): void {
for (const action of this.host.store.all('SELECT message_id FROM bot_actions WHERE bot_id = ? AND (? IS NULL OR id = ?)', botId, actionId ?? null, actionId ?? null)) {
const source = `bm:${action.message_id}`
const statusPrefix = `${source}:status:`
this.host.store.run(`UPDATE bot_journal SET text = ?, keys = '', json = NULL, redacted_at = COALESCE(redacted_at, ?)
WHERE bot_id = ? AND (source_key IN (?, ?) OR substr(source_key, 1, ?) = ?)`,
'[removed at your request]', this.host.store.now(), botId, `${source}_n1`, `${source}_n2`, statusPrefix.length, statusPrefix)
}
this.host.store.run(`UPDATE bot_actions SET args_json = ?, args_digest = '[forgotten]',
card_json = json_object('text', '[forgotten]', 'ownerSeq', COALESCE(json_extract(card_json, '$.ownerSeq'), 0), 'noteSeq', COALESCE(json_extract(card_json, '$.noteSeq'), 0),
'toolReportedError', COALESCE(json_extract(result_json, '$.toolReportedError'), json_extract(card_json, '$.toolReportedError')),
Expand Down Expand Up @@ -294,7 +305,11 @@ export class BotActions {
if (!this.host.enabled()) return { text: 'Asks first is off.', isError: true }
if (!toolCallId) return { text: 'This call cannot be held without its call id. Carry on without it.', isError: true }
const callKey = JSON.stringify([row.id, dispatch, toolCallId])
const existing = this.host.store.get('SELECT id FROM bot_actions WHERE call_key = ?', callKey)
const existing = this.host.store.get('SELECT id, args_digest, target_json FROM bot_actions WHERE call_key = ?', callKey)
if (existing?.args_digest === '[forgotten]' && existing.target_json === JSON.stringify({ server: tool.server, tool: tool.tool }))
return { text: 'This call id belongs to a forgotten call. Nothing new was held or sent.' }
if (existing && (existing.args_digest !== actionDigest(args) || existing.target_json !== JSON.stringify({ server: tool.server, tool: tool.tool })))
return { text: 'This call id was already used for a different call. Nothing was held for this call.', isError: true }
if (existing) return { text: 'This call is held for your owner. End your turn now.' }
if (pending.has(this.forWork(row.id)?.status ?? '')) return { text: 'A call is already held for your owner. End your turn now.', isError: true }
const origin = this.host.origin(row)
Expand Down Expand Up @@ -330,7 +345,7 @@ export class BotActions {
this.host.store.run(`INSERT INTO bot_actions(id, call_key, bot_id, activation_id, lane, kind, target_json, exec_args,
args_json, args_digest, binding_json, card_json, status, message_id, expires_at, created_at)
VALUES(?, ?, ?, ?, 'run', 'mcp', ?, ?, ?, ?, ?, ?, 'open', ?, ?, ?)`,
id, callKey, row.botId, row.id, JSON.stringify({ server: tool.server, tool: tool.tool }), exact, JSON.stringify(review.args), actionDigest(JSON.parse(exact)), JSON.stringify(binding), JSON.stringify({ hasHiddenValues: review.hasHiddenValues, serverName: tool.serverName }), messageId,
id, callKey, row.botId, row.id, JSON.stringify({ server: tool.server, tool: tool.tool }), exact, JSON.stringify(review.args), actionDigest(JSON.parse(exact)), JSON.stringify(binding), JSON.stringify({ hasHiddenValues: review.hasHiddenValues, title: readableActionTitle(tool.tool), serverName: tool.serverName }), messageId,
new Date(Date.parse(this.host.store.now()) + this.host.lifetime(row)).toISOString(), this.host.store.now())
this.host.park(row)
this.host.post(row, messageId, `${tool.serverName} · ${tool.tool}\n${review.hasHiddenValues ? 'Hidden values will be sent.\n' : ''}${JSON.stringify(review.args)}`)
Expand Down Expand Up @@ -391,26 +406,37 @@ export class BotActions {
}
if (!action || action.status !== 'running' || !this.valid(action)) throw changed()
}
async answer(input: { actionId: string; digest: string; answer: 'send' | 'not_now' }): Promise<{ status: string }> {
/** Admission may retire stale lifecycle state; it never approves or dispatches the call. */
check(input: { actionId: string; digest: string; answer: 'send' | 'not_now' }): void {
this.checked(input, true)
}
private checked(input: { actionId: string; digest: string; answer: 'send' | 'not_now' }, settle: boolean): ActionRow {
const action = this.get(input.actionId)
if (!action) throw new BotActionChanged("This can't be sent any more.", 'bot_action_gone')
if (action.result_json && JSON.parse(action.result_json).notSentInTime) throw new BotActionChanged(JSON.parse(action.result_json).text, 'bot_action_unreachable')
if (action.status === 'expired') throw new BotActionChanged('This expired, so nothing was sent.', 'bot_action_expired')
if (action.status === 'withdrawn') throw new BotActionChanged(action.result_json && JSON.parse(action.result_json).text?.includes('changed since') ? 'This changed since you saw it. Nothing was sent.' : 'No longer needed, so nothing was sent.', 'bot_action_withdrawn')
if (action.status === 'withdrawn') {
if (action.result_json && JSON.parse(action.result_json).text?.includes('changed since')) throw new BotActionChanged('This changed since you saw it. Nothing was sent.', 'bot_action_schedule_changed')
throw new BotActionChanged('No longer needed, so nothing was sent.', 'bot_action_withdrawn')
}
if (action.status !== 'open') throw new BotActionChanged('This was already answered.', 'bot_action_settled')
if (action && action.status === 'open' && Date.parse(action.expires_at) <= Date.parse(this.host.store.now())) {
this.expireDue()
if (settle) this.expireDue()
throw new BotActionChanged('This expired, so nothing was sent.', 'bot_action_expired')
}
if (action && input.answer === 'send' && this.host.store.registry(action.bot_id)?.pausedReason === 'owner') throw new BotActionChanged(`Resume ${this.host.name(action.bot_id)} to send this.`, 'bot_action_paused')
const row = this.host.store.activation(action.activation_id)
if (row?.trigger.kind === 'schedule' && this.host.obsolete(action)) {
this.host.store.db.transaction(() => {
if (settle) this.host.store.db.transaction(() => {
if (this.transition(action.id, 'open', 'withdrawn', { text: 'This schedule changed since you saw it. Nothing was sent; carry on without it.' })) this.host.store.db.afterCommit(() => this.finish(action))
})
throw new BotActionChanged('This changed since you saw it. Nothing was sent.', 'bot_action_withdrawn')
throw new BotActionChanged('This changed since you saw it. Nothing was sent.', 'bot_action_schedule_changed')
}
if (!action || action.status !== 'open' || action.args_digest !== input.digest || !this.valid(action)) throw changed()
return action
}
async answer(input: { actionId: string; digest: string; answer: 'send' | 'not_now' }): Promise<{ status: string }> {
const action = this.checked(input, true)
if (input.answer === 'not_now') {
this.host.store.db.transaction(() => {
if (!this.transition(action.id, 'open', 'declined', { text: 'Your owner chose not to send this: carry on without it and say what you skipped.' })) throw changed()
Expand Down
Loading
Loading