osborn 0.9.291 → 0.9.293

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.claude/skills/browser-apply/SKILL.md +5 -4
  2. package/.claude/skills/browser-apply/candidate.example.env +4 -1
  3. package/.claude/skills/browser-apply/fill.mjs +13 -2
  4. package/.claude/skills/meetings/SKILL.md +26 -7
  5. package/.env.example +6 -0
  6. package/dist/agent-store.d.ts +6 -0
  7. package/dist/agent-store.js +36 -6
  8. package/dist/approval-policy.d.ts +99 -0
  9. package/dist/approval-policy.js +196 -0
  10. package/dist/claude-llm.d.ts +3 -2
  11. package/dist/claude-llm.js +49 -19
  12. package/dist/config.d.ts +12 -16
  13. package/dist/config.js +80 -22
  14. package/dist/content/compaction-lens-worker.d.ts +5 -0
  15. package/dist/content/compaction-lens-worker.js +78 -7
  16. package/dist/content/content-llm.d.ts +14 -3
  17. package/dist/content/content-llm.js +33 -142
  18. package/dist/content/lens-db.d.ts +16 -5
  19. package/dist/content/lens-db.js +58 -11
  20. package/dist/content/lens-ingest.d.ts +1 -0
  21. package/dist/content/lens-ingest.js +1 -1
  22. package/dist/content/lens-launch.d.ts +42 -1
  23. package/dist/content/lens-launch.js +202 -40
  24. package/dist/content/lens-library-digest.d.ts +85 -0
  25. package/dist/content/lens-library-digest.js +305 -0
  26. package/dist/content/lens-library-index.d.ts +14 -3
  27. package/dist/content/lens-library-index.js +35 -8
  28. package/dist/content/lens-library-select.d.ts +1 -1
  29. package/dist/content/lens-library-select.js +1 -1
  30. package/dist/content/lens-library-sweep.d.ts +36 -0
  31. package/dist/content/lens-library-sweep.js +331 -0
  32. package/dist/content/lens-library.d.ts +29 -0
  33. package/dist/content/lens-library.js +130 -20
  34. package/dist/content/lens-model.d.ts +4 -0
  35. package/dist/content/lens-model.js +5 -0
  36. package/dist/content/lens-paths.d.ts +72 -0
  37. package/dist/content/lens-paths.js +248 -5
  38. package/dist/content/period-run.js +2 -2
  39. package/dist/content/secret-rules.d.ts +51 -0
  40. package/dist/content/secret-rules.js +185 -0
  41. package/dist/content/transcript-sanitizer.d.ts +1 -41
  42. package/dist/content/transcript-sanitizer.js +4 -171
  43. package/dist/data-sender-auth.d.ts +43 -6
  44. package/dist/data-sender-auth.js +61 -45
  45. package/dist/env-keys.d.ts +10 -2
  46. package/dist/env-keys.js +26 -5
  47. package/dist/index.js +499 -106
  48. package/dist/phone-code.d.ts +76 -0
  49. package/dist/phone-code.js +124 -0
  50. package/dist/phone-voice-actions.d.ts +132 -0
  51. package/dist/phone-voice-actions.js +223 -0
  52. package/dist/pipeline-direct-llm.d.ts +7 -1
  53. package/dist/pipeline-direct-llm.js +12 -1
  54. package/dist/prompts/library-digest.md +11 -0
  55. package/dist/prompts.js +2 -2
  56. package/dist/pushover.d.ts +2 -1
  57. package/dist/pushover.js +7 -6
  58. package/dist/risk-tier.d.ts +14 -0
  59. package/dist/risk-tier.js +140 -0
  60. package/dist/session-store.d.ts +1 -0
  61. package/dist/session-store.js +3 -2
  62. package/dist/session-switch.d.ts +22 -7
  63. package/dist/session-switch.js +58 -24
  64. package/dist/steward-verdict.d.ts +16 -3
  65. package/dist/steward-verdict.js +37 -18
  66. package/dist/watch-gateway.js +3 -1
  67. package/package.json +1 -1
  68. package/dist/bridge-llm.d.ts +0 -22
  69. package/dist/bridge-llm.js +0 -39
  70. package/dist/codex-handler.d.ts +0 -38
  71. package/dist/codex-handler.js +0 -83
  72. package/dist/codex-llm.d.ts +0 -40
  73. package/dist/codex-llm.js +0 -144
  74. package/dist/fast-brain.d.ts +0 -176
  75. package/dist/fast-brain.js +0 -1887
  76. package/dist/index-3-2-26-legacy.d.ts +0 -1
  77. package/dist/index-3-2-26-legacy.js +0 -2233
  78. package/dist/leagcyprompts2.d.ts +0 -0
  79. package/dist/leagcyprompts2.js +0 -573
  80. package/dist/prompts-2-25-26.d.ts +0 -0
  81. package/dist/prompts-2-25-26.js +0 -518
  82. package/dist/prompts-3-2-26.d.ts +0 -78
  83. package/dist/prompts-3-2-26.js +0 -1319
  84. package/dist/summary-index.d.ts +0 -90
  85. package/dist/summary-index.js +0 -585
@@ -0,0 +1,76 @@
1
+ /**
2
+ * phone-code.ts — the emailed code that admits a phone caller (#362).
3
+ *
4
+ * With PHONE_EMAIL_CODE_ENABLED on, the agent joins the caller's room but does
5
+ * not adopt the caller: no voice session, no voice actions, no tools. The
6
+ * frontend emails the account a 6-digit code and tells the caller to type it.
7
+ * Every keypad press goes to the code (never to approvals) until the frontend
8
+ * (POST /api/phone/code, which counts tries and expiry) says it matched; then
9
+ * the caller is adopted as before. Pure parts here; the wiring is in index.ts.
10
+ */
11
+ import { RoomServiceClient } from 'livekit-server-sdk';
12
+ export declare const PHONE_CODE_LENGTH = 6;
13
+ /** The code's window (CALL_CODE_TTL_MS in frontend/src/lib/phone-code.ts). */
14
+ export declare const PHONE_CODE_TTL_MS: number;
15
+ /**
16
+ * The agent ends a call still waiting for its code this long after the step
17
+ * opened, in case the frontend that follows the call is gone. The frontend's
18
+ * own expiry goodbye comes first.
19
+ */
20
+ export declare const PHONE_CODE_TIMEOUT_MS: number;
21
+ /** After a locked or expired answer, time for the frontend's goodbye line before the agent hangs up itself. */
22
+ export declare const PHONE_CODE_HANGUP_GRACE_MS = 12000;
23
+ /**
24
+ * The frontend's spoken lines (hold #365, code prompt, retry) join a call's
25
+ * room as URL ingress participants: never adopted, and their leaving ends
26
+ * nothing. Independent of PHONE_EMAIL_CODE_ENABLED: it also stops the hold
27
+ * line's leave from tearing down a call the agent has just taken (#365).
28
+ */
29
+ export declare function isPhoneLinePlayer(ingress: boolean, activeRoomName: string | null, phoneRoomName: string | null): boolean;
30
+ /**
31
+ * What a phone caller joining gets: the voice session, the code step first,
32
+ * or (flag on but no sync token, so no code can be checked) a hang-up.
33
+ */
34
+ export declare function phoneCallerAdmission(s: {
35
+ verifiedRoom: string | null;
36
+ room: string | null;
37
+ hasSyncToken: boolean;
38
+ }, codeEnabled?: boolean): 'adopt' | 'code' | 'refuse';
39
+ /**
40
+ * Whether /connect-room asks the frontend to email a code: only for a phone
41
+ * room, with the flag on, on a machine whose sync token can check the code.
42
+ */
43
+ export declare function offerPhoneCode(phoneRoom: string | undefined, hasSyncToken: boolean, codeEnabled?: boolean): boolean;
44
+ /**
45
+ * One keypad press during the code step. Digits add up to PHONE_CODE_LENGTH and
46
+ * then submit; `*` starts again; anything else (`#`, letters) is ignored.
47
+ * `holding` (a try is being checked): digits are kept, the last six, and wait
48
+ * for the next try instead of submitting.
49
+ */
50
+ export declare function addCodeDigit(buffer: string, digit: string | undefined | null, holding?: boolean): {
51
+ buffer: string;
52
+ submit?: string;
53
+ };
54
+ /** Digits held during a check that make a full code: submit them when the check comes back. */
55
+ export declare function heldCode(buffer: string): {
56
+ buffer: string;
57
+ submit?: string;
58
+ };
59
+ export type PhoneCodeResult = 'ok' | 'wrong' | 'locked' | 'expired' | 'error';
60
+ /**
61
+ * What the agent does with the answer to a try: take the call, hang up (after
62
+ * the frontend's goodbye) when the code is used up, or keep waiting.
63
+ */
64
+ export declare function phoneCodeAction(result: PhoneCodeResult): 'adopt' | 'hang-up' | 'wait';
65
+ /**
66
+ * Ends a phone call: removes the SIP caller from the room (LiveKit hangs up
67
+ * the line). False when it could not (no LiveKit config, or the API refused).
68
+ */
69
+ export declare function removePhoneCaller(roomName: string, identity: string, client?: Pick<RoomServiceClient, 'removeParticipant'> | null): Promise<boolean>;
70
+ /** The frontend's answer to POST /api/phone/code, read strictly: anything unexpected is an error. */
71
+ export declare function readPhoneCodeReply(status: number, body: unknown): PhoneCodeResult;
72
+ /**
73
+ * Asks the frontend whether `code` is the one emailed for `roomName`. The
74
+ * machine's sync token proves which account is asking.
75
+ */
76
+ export declare function checkPhoneCode(frontendUrl: string, syncToken: string | undefined, roomName: string, code: string, fetchFn?: typeof fetch): Promise<PhoneCodeResult>;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * phone-code.ts — the emailed code that admits a phone caller (#362).
3
+ *
4
+ * With PHONE_EMAIL_CODE_ENABLED on, the agent joins the caller's room but does
5
+ * not adopt the caller: no voice session, no voice actions, no tools. The
6
+ * frontend emails the account a 6-digit code and tells the caller to type it.
7
+ * Every keypad press goes to the code (never to approvals) until the frontend
8
+ * (POST /api/phone/code, which counts tries and expiry) says it matched; then
9
+ * the caller is adopted as before. Pure parts here; the wiring is in index.ts.
10
+ */
11
+ import { RoomServiceClient } from 'livekit-server-sdk';
12
+ import { PHONE_EMAIL_CODE_ENABLED, isPhoneCallLive } from './data-sender-auth.js';
13
+ export const PHONE_CODE_LENGTH = 6;
14
+ /** The code's window (CALL_CODE_TTL_MS in frontend/src/lib/phone-code.ts). */
15
+ export const PHONE_CODE_TTL_MS = 5 * 60_000;
16
+ /**
17
+ * The agent ends a call still waiting for its code this long after the step
18
+ * opened, in case the frontend that follows the call is gone. The frontend's
19
+ * own expiry goodbye comes first.
20
+ */
21
+ export const PHONE_CODE_TIMEOUT_MS = PHONE_CODE_TTL_MS + 30_000;
22
+ /** After a locked or expired answer, time for the frontend's goodbye line before the agent hangs up itself. */
23
+ export const PHONE_CODE_HANGUP_GRACE_MS = 12_000;
24
+ /**
25
+ * The frontend's spoken lines (hold #365, code prompt, retry) join a call's
26
+ * room as URL ingress participants: never adopted, and their leaving ends
27
+ * nothing. Independent of PHONE_EMAIL_CODE_ENABLED: it also stops the hold
28
+ * line's leave from tearing down a call the agent has just taken (#365).
29
+ */
30
+ export function isPhoneLinePlayer(ingress, activeRoomName, phoneRoomName) {
31
+ return ingress && isPhoneCallLive(activeRoomName, phoneRoomName, true);
32
+ }
33
+ /**
34
+ * What a phone caller joining gets: the voice session, the code step first,
35
+ * or (flag on but no sync token, so no code can be checked) a hang-up.
36
+ */
37
+ export function phoneCallerAdmission(s, codeEnabled = PHONE_EMAIL_CODE_ENABLED) {
38
+ if (!codeEnabled || (s.room && s.verifiedRoom === s.room))
39
+ return 'adopt';
40
+ return s.hasSyncToken ? 'code' : 'refuse';
41
+ }
42
+ /**
43
+ * Whether /connect-room asks the frontend to email a code: only for a phone
44
+ * room, with the flag on, on a machine whose sync token can check the code.
45
+ */
46
+ export function offerPhoneCode(phoneRoom, hasSyncToken, codeEnabled = PHONE_EMAIL_CODE_ENABLED) {
47
+ return !!phoneRoom && codeEnabled && hasSyncToken;
48
+ }
49
+ /**
50
+ * One keypad press during the code step. Digits add up to PHONE_CODE_LENGTH and
51
+ * then submit; `*` starts again; anything else (`#`, letters) is ignored.
52
+ * `holding` (a try is being checked): digits are kept, the last six, and wait
53
+ * for the next try instead of submitting.
54
+ */
55
+ export function addCodeDigit(buffer, digit, holding = false) {
56
+ if (digit === '*')
57
+ return { buffer: '' };
58
+ if (typeof digit !== 'string' || !/^[0-9]$/.test(digit))
59
+ return { buffer };
60
+ const next = (buffer + digit).slice(-PHONE_CODE_LENGTH);
61
+ return next.length === PHONE_CODE_LENGTH && !holding ? { buffer: '', submit: next } : { buffer: next };
62
+ }
63
+ /** Digits held during a check that make a full code: submit them when the check comes back. */
64
+ export function heldCode(buffer) {
65
+ return buffer.length === PHONE_CODE_LENGTH ? { buffer: '', submit: buffer } : { buffer };
66
+ }
67
+ /**
68
+ * What the agent does with the answer to a try: take the call, hang up (after
69
+ * the frontend's goodbye) when the code is used up, or keep waiting.
70
+ */
71
+ export function phoneCodeAction(result) {
72
+ if (result === 'ok')
73
+ return 'adopt';
74
+ if (result === 'locked' || result === 'expired')
75
+ return 'hang-up';
76
+ return 'wait';
77
+ }
78
+ /**
79
+ * Ends a phone call: removes the SIP caller from the room (LiveKit hangs up
80
+ * the line). False when it could not (no LiveKit config, or the API refused).
81
+ */
82
+ export async function removePhoneCaller(roomName, identity, client = defaultRoomService()) {
83
+ if (!client)
84
+ return false;
85
+ try {
86
+ await client.removeParticipant(roomName, identity);
87
+ return true;
88
+ }
89
+ catch (e) {
90
+ console.warn(`📞 could not hang up ${identity} in ${roomName}: ${e.message}`);
91
+ return false;
92
+ }
93
+ }
94
+ function defaultRoomService() {
95
+ const { LIVEKIT_URL: url, LIVEKIT_API_KEY: key, LIVEKIT_API_SECRET: secret } = process.env;
96
+ return url && key && secret ? new RoomServiceClient(url, key, secret) : null;
97
+ }
98
+ /** The frontend's answer to POST /api/phone/code, read strictly: anything unexpected is an error. */
99
+ export function readPhoneCodeReply(status, body) {
100
+ const r = body?.result;
101
+ if (status === 200 && (r === 'ok' || r === 'wrong' || r === 'locked' || r === 'expired'))
102
+ return r;
103
+ return 'error';
104
+ }
105
+ /**
106
+ * Asks the frontend whether `code` is the one emailed for `roomName`. The
107
+ * machine's sync token proves which account is asking.
108
+ */
109
+ export async function checkPhoneCode(frontendUrl, syncToken, roomName, code, fetchFn = fetch) {
110
+ if (!syncToken)
111
+ return 'error';
112
+ try {
113
+ const r = await fetchFn(`${frontendUrl}/api/phone/code`, {
114
+ method: 'POST',
115
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${syncToken}` },
116
+ body: JSON.stringify({ roomName, code }),
117
+ signal: AbortSignal.timeout(15_000),
118
+ });
119
+ return readPhoneCodeReply(r.status, await r.json().catch(() => null));
120
+ }
121
+ catch {
122
+ return 'error';
123
+ }
124
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * phone-voice-actions.ts — the first voice actions on a phone call (#367).
3
+ *
4
+ * A call has no buttons, so a short spoken command ("stop that", "what are
5
+ * you doing?", "switch to my billing project") is matched here and run as the
6
+ * app's own action (index.ts dispatchAction, PHONE_ACTION_TYPES) instead of
7
+ * going to the model. Approvals are answered here too, never by the model.
8
+ *
9
+ * Pure: matching and the spoken replies. Conservative on purpose: only a short
10
+ * utterance that is the whole command matches; anything else is a normal turn.
11
+ */
12
+ import { type ApprovalMode } from './approval-policy.js';
13
+ export type VoiceAction = {
14
+ kind: 'answer';
15
+ answer: 'allow' | 'deny';
16
+ } | {
17
+ kind: 'mode';
18
+ mode: ApprovalMode;
19
+ }
20
+ /** A mode change or a session switch while a request waits: not done (the caller hears how to answer it). */
21
+ | {
22
+ kind: 'blocked';
23
+ what: 'mode' | 'switch';
24
+ } | {
25
+ kind: 'status';
26
+ } | {
27
+ kind: 'stop';
28
+ agent?: string;
29
+ } | {
30
+ kind: 'sessions';
31
+ }
32
+ /** "switch to …" picked a session: ask "Switch to <title>?" and wait for a yes. */
33
+ | {
34
+ kind: 'switch';
35
+ query: string;
36
+ target: SessionChoice;
37
+ } | {
38
+ kind: 'confirm_switch';
39
+ } | {
40
+ kind: 'cancel_switch';
41
+ } | {
42
+ kind: 'outputs';
43
+ } | {
44
+ kind: 'keep_working';
45
+ };
46
+ /** Lower case, no punctuation, without leading fillers ("ok", "hey osborn") or a trailing "please". */
47
+ export declare function normalizeUtterance(text: string): string;
48
+ /**
49
+ * The voice action a caller's utterance asks for, or null (a normal turn for
50
+ * the model).
51
+ * - `permissionPending` (the request the caller heard read out): a yes/no answers it.
52
+ * - `anyPermissionPending`: while any request waits, a mode command and a
53
+ * switch (proposing or confirming one) are not done ('blocked'); "allow all"
54
+ * and a switch "yes" are never taken as an answer to it.
55
+ * - `switchProposed`: the turn after "Switch to <title>?", a yes confirms and a
56
+ * no cancels; anything else is a normal turn (and drops the proposal).
57
+ * - A switch is only proposed when `sessions` holds a session whose title the
58
+ * name picks (pickSession); otherwise the turn goes to the model.
59
+ */
60
+ export declare function matchVoiceAction(text: string, ctx: {
61
+ permissionPending: boolean;
62
+ anyPermissionPending?: boolean;
63
+ switchProposed?: boolean;
64
+ sessions?: SessionChoice[];
65
+ }): VoiceAction | null;
66
+ /**
67
+ * May a caller change the saved approval mode? The mode also applies to the
68
+ * browser, so until the caller is confirmed by a second factor (keypad
69
+ * approvals on, #362) a call may only make it stricter.
70
+ */
71
+ export declare function phoneMayChangeMode(from: ApprovalMode, to: ApprovalMode, approvalsEnabled: boolean): boolean;
72
+ export interface SessionChoice {
73
+ sessionId: string;
74
+ title?: string;
75
+ cwd?: string;
76
+ projectPath?: string;
77
+ }
78
+ /**
79
+ * The session a spoken name points at: the most words of the query in its
80
+ * title or project folder name. It needs at least half the query's words
81
+ * (rounded up), and at least 2 when the query has 2 or more, so a stray
82
+ * shared word ("next") never picks a session. Ties go to the earlier (most
83
+ * recent) entry; too few words in common → null.
84
+ */
85
+ export declare function pickSession<T extends SessionChoice>(query: string, sessions: T[]): T | null;
86
+ /** "What are you doing?" from busyState, the running tasks and the pending request. */
87
+ export declare function sayStatus(s: {
88
+ turnInFlight: boolean;
89
+ compacting?: boolean;
90
+ tasks: {
91
+ subagentType?: string;
92
+ description?: string;
93
+ }[];
94
+ pending: string | null;
95
+ /** Keypad approvals on: the caller can allow from the phone. */
96
+ keypad?: boolean;
97
+ /** The pending request is the one read out on this call (only then can the caller answer it). */
98
+ heard?: boolean;
99
+ }): string;
100
+ /** "What were my recent sessions?" from a sessions_list reply. */
101
+ export declare function saySessions(sessions: SessionChoice[], max?: number): string;
102
+ /** "What did you make?" from a session_artifacts reply. */
103
+ export declare function sayOutputs(artifacts: {
104
+ fileName?: string;
105
+ }[], max?: number): string;
106
+ /** A mode command while a request waits: nothing changed; how to answer the request instead. */
107
+ export declare function sayBlocked(blocked: 'mode' | 'switch', pending: string | null, keypad: boolean, heard: boolean): string;
108
+ /**
109
+ * Whether the caller heard a spoken prompt in full: its playout finished and
110
+ * was not interrupted (talking over it does not count). No handle → not heard.
111
+ */
112
+ export declare function promptHeard(handle: {
113
+ waitForPlayout?(): Promise<unknown>;
114
+ interrupted?: boolean;
115
+ } | null | undefined): Promise<boolean>;
116
+ /**
117
+ * How the caller can answer a pending request. Only the request read out on
118
+ * this call (phonePromptedRequestId, set after its prompt played in full) can
119
+ * be answered by phone; any other is answered in the app.
120
+ */
121
+ export declare function howToAnswer(heard: boolean, keypad: boolean): string;
122
+ /**
123
+ * What a confirmed switch actually did, from the switch_session replies
124
+ * (session_switched / session_switch_pending, as the app receives them).
125
+ */
126
+ export declare function saySwitchOutcome(replies: {
127
+ type?: string;
128
+ success?: boolean;
129
+ reason?: string;
130
+ }[], name: string): string;
131
+ /** The spoken confirmation of a mode change. */
132
+ export declare function sayModeChanged(mode: ApprovalMode): string;
@@ -0,0 +1,223 @@
1
+ /**
2
+ * phone-voice-actions.ts — the first voice actions on a phone call (#367).
3
+ *
4
+ * A call has no buttons, so a short spoken command ("stop that", "what are
5
+ * you doing?", "switch to my billing project") is matched here and run as the
6
+ * app's own action (index.ts dispatchAction, PHONE_ACTION_TYPES) instead of
7
+ * going to the model. Approvals are answered here too, never by the model.
8
+ *
9
+ * Pure: matching and the spoken replies. Conservative on purpose: only a short
10
+ * utterance that is the whole command matches; anything else is a normal turn.
11
+ */
12
+ import { approvalModeLabel } from './approval-policy.js';
13
+ const MAX_WORDS = 10;
14
+ /** Lower case, no punctuation, without leading fillers ("ok", "hey osborn") or a trailing "please". */
15
+ export function normalizeUtterance(text) {
16
+ let s = String(text || '').toLowerCase().replace(/[’']/g, '').replace(/[^a-z0-9 ]+/g, ' ').replace(/\s+/g, ' ').trim();
17
+ for (let prev = ''; prev !== s;) {
18
+ prev = s;
19
+ s = s.replace(/^(ok|okay|hey|hi|so|um|uh|please|osborn|alright|right|now)\s+/, '');
20
+ }
21
+ return s.replace(/\s+(please|thanks|thank you|now)$/, '').trim();
22
+ }
23
+ // Every pattern is a whole, short, unmistakable command; everyday speech that
24
+ // merely starts the same way ("go to the next step", "keep going", "stop the
25
+ // build") is a normal turn for the model.
26
+ // Yes/no count only while the request the caller heard read out is pending.
27
+ const ANSWER_ALLOW = /^(?:yes|yeah|yep|yup|allow|allow it|approve|approve it)$/;
28
+ const ANSWER_DENY = /^(?:no|nope|deny|deny it|reject|reject it|dont allow it|do not allow it)$/;
29
+ // A spoken mode change is saved (the app and later calls use it too); there is no call-only mode.
30
+ const MODE_PREFIX = '(?:switch to |use |turn on |set approvals to )?';
31
+ const MODE_PATTERNS = [
32
+ [new RegExp(`^${MODE_PREFIX}(?:allow all|allow everything|approve everything)(?: mode)?$`), 'allow-all'],
33
+ [new RegExp(`^${MODE_PREFIX}auto ?review(?: mode)?$`), 'auto-review'],
34
+ [new RegExp(`^${MODE_PREFIX}ask me(?: first)? mode$`), 'ask'],
35
+ [/^(?:switch to ask me|ask me before (?:each|every) action|ask me every time)$/, 'ask'],
36
+ ];
37
+ const STATUS = /^(?:what are you (?:doing|working on)|whats pending|what is pending|are you (?:busy|still working)|status|status update|give me a status update)$/;
38
+ const STOP_MAIN = /^(?:stop|stop that|stop it|stop everything|stop working|cancel that)$/;
39
+ // A named agent: one of the built-in roles, or anything followed by "agent".
40
+ const AGENT_ROLES = '(?:researcher|reasoner|writer|steward|reviewer|tester|planner|reader)';
41
+ const STOP_AGENT = new RegExp(`^stop the (?:(${AGENT_ROLES})(?: agent)?|([a-z][a-z0-9 -]*?) (?:agent|sub agent|subagent))$`);
42
+ const SESSIONS = /^(?:what (?:were|are) my recent (?:sessions|conversations)|(?:list|read me) my (?:recent )?sessions|my recent sessions)$/;
43
+ // Only an explicit session switch, with the noun said: "switch to the X
44
+ // session/project/conversation" or "switch session to X". Then the name must
45
+ // pick a session by its title, and the caller confirms with a yes.
46
+ const SWITCH = /^(?:switch to (?:my |the )?(.+?) (?:session|project|conversation)|switch session to (?:my |the )?(.+))$/;
47
+ const CONFIRM_YES = /^(?:yes|yeah|yep|yup|yes please|do it|switch)$/;
48
+ const CONFIRM_NO = /^(?:no|nope|cancel|dont|do not|stay|stay here)$/;
49
+ const OUTPUTS = /^(?:what did you make(?: in this session)?|what files did you (?:make|create)(?: in this session)?|read me the session summary|what are (?:the|your) outputs)$/;
50
+ const KEEP_WORKING = /^(?:keep working (?:after i hang up|when i hang up|in the background)|work in the background)$/;
51
+ /**
52
+ * The voice action a caller's utterance asks for, or null (a normal turn for
53
+ * the model).
54
+ * - `permissionPending` (the request the caller heard read out): a yes/no answers it.
55
+ * - `anyPermissionPending`: while any request waits, a mode command and a
56
+ * switch (proposing or confirming one) are not done ('blocked'); "allow all"
57
+ * and a switch "yes" are never taken as an answer to it.
58
+ * - `switchProposed`: the turn after "Switch to <title>?", a yes confirms and a
59
+ * no cancels; anything else is a normal turn (and drops the proposal).
60
+ * - A switch is only proposed when `sessions` holds a session whose title the
61
+ * name picks (pickSession); otherwise the turn goes to the model.
62
+ */
63
+ export function matchVoiceAction(text, ctx) {
64
+ const s = normalizeUtterance(text);
65
+ if (!s || s.split(' ').length > MAX_WORDS)
66
+ return null;
67
+ if (ctx.permissionPending) {
68
+ if (ANSWER_ALLOW.test(s))
69
+ return { kind: 'answer', answer: 'allow' };
70
+ if (ANSWER_DENY.test(s))
71
+ return { kind: 'answer', answer: 'deny' };
72
+ }
73
+ const waiting = ctx.permissionPending || !!ctx.anyPermissionPending;
74
+ if (ctx.switchProposed) {
75
+ if (CONFIRM_YES.test(s))
76
+ return waiting ? { kind: 'blocked', what: 'switch' } : { kind: 'confirm_switch' };
77
+ if (CONFIRM_NO.test(s))
78
+ return { kind: 'cancel_switch' };
79
+ }
80
+ for (const [re, mode] of MODE_PATTERNS) {
81
+ if (re.test(s))
82
+ return waiting ? { kind: 'blocked', what: 'mode' } : { kind: 'mode', mode };
83
+ }
84
+ if (STATUS.test(s))
85
+ return { kind: 'status' };
86
+ if (STOP_MAIN.test(s))
87
+ return { kind: 'stop' };
88
+ const agent = STOP_AGENT.exec(s);
89
+ if (agent)
90
+ return { kind: 'stop', agent: (agent[1] || agent[2]).trim() };
91
+ if (SESSIONS.test(s))
92
+ return { kind: 'sessions' };
93
+ if (OUTPUTS.test(s))
94
+ return { kind: 'outputs' };
95
+ if (KEEP_WORKING.test(s))
96
+ return { kind: 'keep_working' };
97
+ const sw = SWITCH.exec(s);
98
+ const query = (sw?.[1] || sw?.[2] || '').trim();
99
+ if (query) {
100
+ const target = pickSession(query, ctx.sessions ?? []);
101
+ if (target)
102
+ return waiting ? { kind: 'blocked', what: 'switch' } : { kind: 'switch', query, target };
103
+ }
104
+ return null;
105
+ }
106
+ const MODE_RANK = { 'ask': 0, 'auto-review': 1, 'allow-all': 2 };
107
+ /**
108
+ * May a caller change the saved approval mode? The mode also applies to the
109
+ * browser, so until the caller is confirmed by a second factor (keypad
110
+ * approvals on, #362) a call may only make it stricter.
111
+ */
112
+ export function phoneMayChangeMode(from, to, approvalsEnabled) {
113
+ return approvalsEnabled || MODE_RANK[to] <= MODE_RANK[from];
114
+ }
115
+ const STOP_WORDS = new Set(['my', 'the', 'a', 'an', 'session', 'project', 'conversation', 'chat', 'one', 'about', 'on', 'for', 'with']);
116
+ const words = (s) => normalizeUtterance(s).split(' ').filter((w) => w && !STOP_WORDS.has(w));
117
+ /**
118
+ * The session a spoken name points at: the most words of the query in its
119
+ * title or project folder name. It needs at least half the query's words
120
+ * (rounded up), and at least 2 when the query has 2 or more, so a stray
121
+ * shared word ("next") never picks a session. Ties go to the earlier (most
122
+ * recent) entry; too few words in common → null.
123
+ */
124
+ export function pickSession(query, sessions) {
125
+ const q = [...new Set(words(query))];
126
+ if (!q.length)
127
+ return null;
128
+ const need = Math.max(Math.ceil(q.length / 2), q.length >= 2 ? 2 : 1);
129
+ let best = null;
130
+ let bestScore = need - 1;
131
+ for (const s of sessions) {
132
+ // The title only: a project folder name alone ("api", "web") is too common in speech.
133
+ const hay = new Set(words(s.title || ''));
134
+ const score = q.filter((w) => hay.has(w)).length;
135
+ if (score > bestScore) {
136
+ best = s;
137
+ bestScore = score;
138
+ }
139
+ }
140
+ return best;
141
+ }
142
+ const list = (items) => items.length <= 1 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`;
143
+ const short = (s, n = 60) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? `${t.slice(0, n).replace(/\s+\S*$/, '')}…` : t; };
144
+ /** "What are you doing?" from busyState, the running tasks and the pending request. */
145
+ export function sayStatus(s) {
146
+ const parts = [];
147
+ if (s.pending)
148
+ parts.push(`I'm waiting for your OK to ${s.pending}. ${howToAnswer(!!s.heard, !!s.keypad)}`);
149
+ if (s.tasks.length) {
150
+ const named = s.tasks.slice(0, 3).map((t) => `the ${t.subagentType || 'helper'} agent${t.description ? ` on ${short(t.description, 50)}` : ''}`);
151
+ parts.push(`${s.tasks.length === 1 ? 'One agent is' : `${s.tasks.length} agents are`} running: ${list(named)}.`);
152
+ }
153
+ if (s.turnInFlight && !s.tasks.length)
154
+ parts.push("I'm working on your last request.");
155
+ if (s.compacting)
156
+ parts.push("I'm tidying up the conversation history.");
157
+ return parts.length ? parts.join(' ') : "I'm not working on anything right now.";
158
+ }
159
+ /** "What were my recent sessions?" from a sessions_list reply. */
160
+ export function saySessions(sessions, max = 5) {
161
+ const named = sessions.map((s) => short(s.title || '', 50)).filter(Boolean).slice(0, max);
162
+ if (!named.length)
163
+ return "I couldn't find any sessions.";
164
+ return `Your recent sessions: ${named.map((t, i) => `${i + 1}, ${t}`).join('. ')}. Say "switch to" and a name to open one.`;
165
+ }
166
+ /** "What did you make?" from a session_artifacts reply. */
167
+ export function sayOutputs(artifacts, max = 5) {
168
+ const names = artifacts.map((a) => String(a.fileName || '')).filter(Boolean);
169
+ if (!names.length)
170
+ return "This session hasn't made any files yet.";
171
+ const more = names.length > max ? `, and ${names.length - max} more` : '';
172
+ return `This session made ${names.length === 1 ? 'one file' : `${names.length} files`}: ${list(names.slice(0, max))}${more}. They are in the app under Outputs.`;
173
+ }
174
+ /** A mode command while a request waits: nothing changed; how to answer the request instead. */
175
+ export function sayBlocked(blocked, pending, keypad, heard) {
176
+ const didnt = blocked === 'mode' ? "didn't change the approval mode" : "didn't switch sessions";
177
+ const what = pending ? `Osborn wants to ${pending}. ` : '';
178
+ return `There's a request waiting, so I ${didnt}. ${what}${howToAnswer(heard, keypad)}`;
179
+ }
180
+ /**
181
+ * Whether the caller heard a spoken prompt in full: its playout finished and
182
+ * was not interrupted (talking over it does not count). No handle → not heard.
183
+ */
184
+ export async function promptHeard(handle) {
185
+ if (!handle?.waitForPlayout)
186
+ return false;
187
+ await handle.waitForPlayout();
188
+ return !handle.interrupted;
189
+ }
190
+ /**
191
+ * How the caller can answer a pending request. Only the request read out on
192
+ * this call (phonePromptedRequestId, set after its prompt played in full) can
193
+ * be answered by phone; any other is answered in the app.
194
+ */
195
+ export function howToAnswer(heard, keypad) {
196
+ if (!heard)
197
+ return 'Approve or deny it in the app.';
198
+ return keypad ? 'Press 1 to allow or 2 to deny.' : 'Say no to deny it, or approve it in the app.';
199
+ }
200
+ /**
201
+ * What a confirmed switch actually did, from the switch_session replies
202
+ * (session_switched / session_switch_pending, as the app receives them).
203
+ */
204
+ export function saySwitchOutcome(replies, name) {
205
+ if (replies.some((r) => r.type === 'session_switch_cancelled' && r.reason === 'already_live'))
206
+ return `You're already in ${name}.`;
207
+ if (replies.some((r) => r.type === 'session_switch_pending'))
208
+ return `I'll switch to ${name} as soon as I finish the current step.`;
209
+ const done = replies.find((r) => r.type === 'session_switched');
210
+ if (done?.success)
211
+ return `Switched to ${name}.`;
212
+ switch (done?.reason) {
213
+ case 'needs_you': return `I can't switch yet: a request is waiting for your answer. Answer it first, then ask again.`;
214
+ case 'meeting_active': return `I can't switch while I'm in a meeting.`;
215
+ case 'not_found': return `I couldn't open ${name}; it may have been moved or deleted.`;
216
+ case 'target_busy_in_background': return `${name} is busy in the background right now. Try again in a moment.`;
217
+ }
218
+ return done ? `I couldn't switch to ${name}.` : `I asked to switch to ${name}; it hasn't confirmed yet.`;
219
+ }
220
+ /** The spoken confirmation of a mode change. */
221
+ export function sayModeChanged(mode) {
222
+ return `${approvalModeLabel(mode)} is on. That's saved, so it stays on in the app and on later calls until you change it.`;
223
+ }
@@ -61,6 +61,11 @@ export interface PipelineDirectOptions extends ClaudeLLMOptions {
61
61
  getAndConsumeInterruptionContext?: () => InterruptionContext | null;
62
62
  /** Returns pending client notices as a hidden-context block and clears them ('' = none). */
63
63
  getAndConsumeClientNotes?: () => string;
64
+ /**
65
+ * Phone voice actions (#367): true when the utterance was an app command the
66
+ * caller handled itself (it runs and speaks its own reply); the model never sees it.
67
+ */
68
+ takeVoiceAction?: (userText: string) => boolean;
64
69
  }
65
70
  export interface FastBrainPanelResult {
66
71
  question: string;
@@ -100,11 +105,12 @@ export declare class PipelineDirectLLM extends llm.LLM {
100
105
  permissionPending: boolean;
101
106
  idle: boolean;
102
107
  };
103
- respondToPermission(allow: boolean, msg?: string): void;
108
+ respondToPermission(allow: boolean, msg?: string, requestId?: string): boolean;
104
109
  hasPendingPermission(): boolean;
105
110
  getPendingPermission(): {
106
111
  toolName: string;
107
112
  input: any;
113
+ requestId: string;
108
114
  };
109
115
  getMcpServers(): Record<string, import("@anthropic-ai/claude-agent-sdk").McpServerConfig>;
110
116
  setMcpServers(s: any): void;
@@ -234,7 +234,7 @@ export class PipelineDirectLLM extends llm.LLM {
234
234
  get workingDirectory() { return this.#opts.workingDirectory; }
235
235
  get spawnedResumeId() { return this.#claudeLLM.spawnedResumeId; }
236
236
  busyState() { return this.#claudeLLM.busyState(); }
237
- respondToPermission(allow, msg) { this.#claudeLLM.respondToPermission(allow, msg); }
237
+ respondToPermission(allow, msg, requestId) { return this.#claudeLLM.respondToPermission(allow, msg, requestId); }
238
238
  hasPendingPermission() { return this.#claudeLLM.hasPendingPermission(); }
239
239
  getPendingPermission() { return this.#claudeLLM.getPendingPermission(); }
240
240
  getMcpServers() { return this.#claudeLLM.getMcpServers(); }
@@ -317,6 +317,15 @@ export class PipelineDirectLLM extends llm.LLM {
317
317
  this.chat({ chatCtx, toolCtx, connOptions, abortController });
318
318
  });
319
319
  }
320
+ // ── PHONE VOICE ACTIONS (#367) ───────────────────────────────────────────
321
+ // "stop that", "what are you doing?", a yes/no to a pending approval … run
322
+ // as the app's own action, not a model turn. Before the interruption
323
+ // enrichment, so its context waits for the next real turn. The empty
324
+ // deferred stream gives LiveKit a reply with nothing to say.
325
+ if (userText.trim() && !userText.startsWith('[MEETING') && this.#opts.takeVoiceAction?.(userText)) {
326
+ console.log(`📞 [voice-action] handled without the model: "${userText.slice(0, 60)}"`);
327
+ return new NoiseGateStream(this, { chatCtx, toolCtx, connOptions }, async () => { });
328
+ }
320
329
  // ── SESSION TAIL injection (seam-only) ───────────────────────────────────
321
330
  // Inject the tail ONCE on the first real user turn after a compaction
322
331
  // completes. Never injected on every turn (avoids catastrophic accumulation
@@ -619,6 +628,8 @@ export function buildGuardedAgentControl(args) {
619
628
  // bypass marker so the full normal path (enrichment, Claude, fast brain) runs.
620
629
  // Mirrors ClaudeLLMStream's direct-mode shape: run() returns quickly and the
621
630
  // pipeline is released; the real reply flows via tts_say/assistant events.
631
+ // A reply stream that only runs `task` (no model output): the noise gate's
632
+ // deferred triage, and an empty reply for a handled phone voice action.
622
633
  class NoiseGateStream extends llm.LLMStream {
623
634
  #task;
624
635
  constructor(llmInstance, { chatCtx, toolCtx, connOptions }, task) {
@@ -0,0 +1,11 @@
1
+ DAILY DIGEST. Below are {{count}} short chat(s) from {{day}} between a person (user) and their AI assistant, each inside <chat n="…">. Read all of them; your task follows after them.
2
+
3
+ <chats>
4
+
5
+ {{chats}}
6
+
7
+ </chats>
8
+
9
+ TASK: for EACH chat above give a short title (3-8 words) and a summary of one or two lines: what the person wanted and what came of it. Never invent facts. Client details are masked as tags like [client], [founder], [amount]: keep the tags, never guess real names. Never include secrets, keys, tokens, emails or private personal details.
10
+
11
+ Output ONLY: {"chats": [{"n": 1, "title": "...", "summary": "..."}]}
package/dist/prompts.js CHANGED
@@ -374,7 +374,7 @@ For actual user speech (not system injections), follow this decision tree. Stop
374
374
 
375
375
  STEP 1 — Is this a permission response?
376
376
  User says "allow", "deny", or "always allow" in response to a permission request?
377
- → Call respond_permission with their answer. Done.
377
+ → Do nothing and say nothing about it: the agent settles approvals itself (the app's card, the phone keypad, or a spoken yes/no it hears directly). You never decide an approval. Done.
378
378
 
379
379
  STEP 2 — Everything else: ask your brain.
380
380
  This includes: greetings, questions, decisions, follow-ups, requests, topic changes — everything the user says.
@@ -463,7 +463,7 @@ VERBOSITY:
463
463
  </speech-behavior>
464
464
 
465
465
  <permissions>
466
- When a permission request appears: tell the user what action needs permission and ask "allow, deny, or always allow?" Then call respond_permission with their answer.
466
+ Approvals are not yours to answer. The user answers them directly: the card in the app, or on a phone call the keypad (1 allow, 2 deny, 3 always allow) or a spoken yes/no that the agent handles before it reaches you. Never claim to approve or deny anything yourself.
467
467
  </permissions>`;
468
468
  }
469
469
  // ═══════════════════════════════════════════════════════════════