sideby 0.38.1 → 0.40.0

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 (51) hide show
  1. package/dist/build.json +1 -1
  2. package/dist/src/cli/commands.d.ts +6 -0
  3. package/dist/src/cli/commands.js +120 -1
  4. package/dist/src/cli/json-schemas.js +44 -2
  5. package/dist/src/cli/main.js +37 -0
  6. package/dist/src/core/cli-commands.js +26 -2
  7. package/dist/src/core/config.d.ts +14 -0
  8. package/dist/src/core/config.js +21 -0
  9. package/dist/src/core/launch.d.ts +5 -0
  10. package/dist/src/core/launch.js +11 -1
  11. package/dist/src/core/progress-state.d.ts +94 -0
  12. package/dist/src/core/progress-state.js +240 -0
  13. package/dist/src/core/progress.d.ts +36 -0
  14. package/dist/src/core/progress.js +77 -0
  15. package/dist/src/core/prompt-origin.d.ts +40 -0
  16. package/dist/src/core/prompt-origin.js +98 -0
  17. package/dist/src/core/search-catalog.js +43 -0
  18. package/dist/src/core/unattended-attended.d.ts +109 -0
  19. package/dist/src/core/unattended-attended.js +337 -0
  20. package/dist/src/core/unattended-pending.d.ts +14 -2
  21. package/dist/src/core/unattended-pending.js +27 -3
  22. package/dist/src/core/unattended-state.d.ts +19 -1
  23. package/dist/src/core/unattended-state.js +31 -5
  24. package/dist/src/core/unattended-wait.d.ts +86 -0
  25. package/dist/src/core/unattended-wait.js +125 -0
  26. package/dist/src/core/unattended.d.ts +29 -2
  27. package/dist/src/core/unattended.js +48 -6
  28. package/dist/src/handoff/hook.js +19 -4
  29. package/dist/src/network/hook.js +4 -8
  30. package/dist/src/panel/handler.d.ts +3 -0
  31. package/dist/src/panel/handler.js +31 -1
  32. package/dist/src/panel/i18n.d.ts +27 -0
  33. package/dist/src/panel/i18n.js +56 -2
  34. package/dist/src/panel/page-script.js +118 -4
  35. package/dist/src/panel/page-styles.js +21 -0
  36. package/dist/src/progress/hook.d.ts +57 -0
  37. package/dist/src/progress/hook.js +258 -0
  38. package/dist/src/runtime.d.ts +9 -0
  39. package/dist/src/runtime.js +45 -2
  40. package/dist/src/types.d.ts +5 -0
  41. package/dist/src/unattended/hook.d.ts +26 -6
  42. package/dist/src/unattended/hook.js +361 -25
  43. package/package.json +1 -1
  44. package/schemas/config.json +27 -0
  45. package/schemas/progress.json +137 -0
  46. package/schemas/unattended-defer.json +5 -0
  47. package/schemas/unattended-pending.json +5 -0
  48. package/schemas/unattended.json +54 -2
  49. package/skills/sideby/SKILL.md +4 -1
  50. package/skills/sideby/references/progress.md +25 -0
  51. package/skills/sideby/references/unattended.md +25 -3
@@ -0,0 +1,125 @@
1
+ // Answer Wait (spec §3.37 item 7, ADR-0077): a question or a confirmation Claude Code shows in a session sideby started
2
+ // waits for a person; once it has waited `unattended.answerWait` minutes and Unattended Mode is on, `unattended-hook`
3
+ // lets the session go on without an answer. A leaf module (Node built-ins and core/fs-safe.ts only): the hook imports it.
4
+ //
5
+ // What is on screen is read from Claude Code's own session record, `<config dir>/sessions/<pid>.json`, the pid being the
6
+ // hook's parent (the Host): its `sessionId`, `status` and `statusUpdatedAt`, nothing else. Tried with Claude Code
7
+ // 2.1.325 on 2026-11-16: `status` is `waiting` while a question or a permission prompt is on screen and `idle` while the
8
+ // session waits for a prompt, and `statusUpdatedAt` changes when either ends or another dialog takes its place (it
9
+ // stayed the same for 11 minutes while one prompt waited). The record is written before the hook starts.
10
+ import { homedir } from 'node:os';
11
+ import { join } from 'node:path';
12
+ import { readSmallFile } from './fs-safe.js';
13
+ /**
14
+ * The `timeout` of the hook entries that wait. A question shown at 18:00 with Unattended Mode off still goes on when a
15
+ * Slot begins at 23:00; Claude Code ends the hook after this and the question then simply stays on screen.
16
+ */
17
+ export const ANSWER_HOOK_TIMEOUT_S = 12 * 60 * 60;
18
+ /** How long a hook looks for the record to show what it waits on before it gives up (it is written before the hook). */
19
+ const SHOWN_WAIT_MS = 2000;
20
+ const SHOWN_POLL_MS = 100;
21
+ /** How often a waiting hook looks again: an answered question frees its hook within this. */
22
+ export const WATCH_POLL_MS = 3000;
23
+ /** Claude Code's config folder for the session: `CLAUDE_CONFIG_DIR`, else `~/.claude`. */
24
+ export function claudeConfigDir(env) {
25
+ return env.CLAUDE_CONFIG_DIR || join(env.HOME || homedir(), '.claude');
26
+ }
27
+ /**
28
+ * The status the record of process `pid` holds for session `sessionId`; undefined when it cannot be read, is a link,
29
+ * names another session, or lacks `status` or `statusUpdatedAt`.
30
+ */
31
+ export async function readScreen(env, pid, sessionId) {
32
+ if (!Number.isInteger(pid) || pid <= 1)
33
+ return undefined;
34
+ const text = await readSmallFile(join(claudeConfigDir(env), 'sessions', `${pid}.json`), 64 * 1024);
35
+ if (text === undefined)
36
+ return undefined;
37
+ try {
38
+ const v = JSON.parse(text);
39
+ if (!v || v.sessionId !== sessionId)
40
+ return undefined;
41
+ if (typeof v.status !== 'string' || typeof v.statusUpdatedAt !== 'number')
42
+ return undefined;
43
+ return { status: v.status, at: v.statusUpdatedAt };
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ }
49
+ /**
50
+ * Waits while the session shows `expect` (`waiting`: a question or a permission prompt; `idle`: a turn ended and the
51
+ * session waits for a prompt). Returns the record's mark once the wait has passed since `startedAt` and Unattended
52
+ * Mode is on, so the caller can look once more just before it acts (`lastLook`), and undefined as soon as anything
53
+ * says a person (or anything else) moved on or it cannot tell: there is no record for the session, it does not show
54
+ * `expect` within 2 seconds, it shows a dialog put up after `shownBy` (the dialog this hook was started for was on
55
+ * screen before the hook began, so a later one is another dialog: the person answered this one meanwhile), it changes
56
+ * (another status or another `statusUpdatedAt`), it cannot be read, `moved` says so (a person typed after the turn
57
+ * the hook watches), the Host is gone, or the wait was set to never. While the mode is off past the wait it keeps
58
+ * waiting; Claude Code's `timeout` ends it in the end. With `from` it goes on watching that mark, without looking for it
59
+ * first.
60
+ */
61
+ export async function watchScreen(opts) {
62
+ let mark = opts.from;
63
+ if (!mark) {
64
+ // No record for this session at all: nothing is shown in a terminal that sideby can watch.
65
+ mark = await readScreen(opts.env, opts.pid, opts.sessionId);
66
+ if (!mark)
67
+ return undefined;
68
+ for (let waited = 0; mark?.status !== opts.expect; waited += SHOWN_POLL_MS) {
69
+ if (waited >= SHOWN_WAIT_MS)
70
+ return undefined;
71
+ await opts.sleep(SHOWN_POLL_MS);
72
+ mark = await readScreen(opts.env, opts.pid, opts.sessionId);
73
+ }
74
+ if (opts.shownBy !== undefined && mark.at > opts.shownBy)
75
+ return undefined;
76
+ if (await opts.moved?.())
77
+ return undefined;
78
+ }
79
+ for (;;) {
80
+ await opts.sleep(WATCH_POLL_MS);
81
+ if (opts.parentGone())
82
+ return undefined;
83
+ const m = await readScreen(opts.env, opts.pid, opts.sessionId);
84
+ if (!sameMark(m, mark))
85
+ return undefined;
86
+ if (await opts.moved?.())
87
+ return undefined;
88
+ const d = await due(opts.settings, opts.clock, opts.startedAt);
89
+ if (d === 'stop')
90
+ return undefined;
91
+ if (d === 'act')
92
+ return mark;
93
+ }
94
+ }
95
+ const sameMark = (a, b) => a !== undefined && a.status === b.status && a.at === b.at;
96
+ /** With the wait and the mode as they are now: act, keep waiting (not due yet, or the mode is off), or stop (never). */
97
+ async function due(settings, clock, startedAt) {
98
+ const s = await settings();
99
+ if (s.wait === null)
100
+ return 'stop';
101
+ return clock() - startedAt >= s.wait * 60_000 && s.on ? 'act' : 'wait';
102
+ }
103
+ /**
104
+ * The last look before a waiting hook acts (and again after it kept the Pending Decision), with the wait and the mode
105
+ * read afresh: `act` while the Host is still there, the record still shows `mark`, nothing sideby noted says the
106
+ * session moved on, the wait (as set now) has passed and Unattended Mode is on; `wait` when all that holds but the
107
+ * wait was made longer and has not passed, or the mode went off: the hook goes on watching; `stop` for anything else,
108
+ * the wait set to never, or anything it cannot read: the hook then lets it be.
109
+ */
110
+ export async function lastLook(opts) {
111
+ try {
112
+ if (opts.parentGone())
113
+ return 'stop';
114
+ if (!sameMark(await readScreen(opts.env, opts.pid, opts.sessionId), opts.mark))
115
+ return 'stop';
116
+ if (await opts.moved?.())
117
+ return 'stop';
118
+ return await due(opts.settings, opts.clock, opts.startedAt);
119
+ }
120
+ catch {
121
+ return 'stop';
122
+ }
123
+ }
124
+ /** Whole minutes from `startedAt` to `now`, at least 1: how long the question waited, as the user reads it. */
125
+ export const waitedMinutes = (startedAt, now) => Math.max(1, Math.round((now - startedAt) / 60_000));
@@ -1,6 +1,7 @@
1
1
  import type { Env } from '../types.ts';
2
2
  import type { Paths } from './paths.ts';
3
3
  import { type SessionHookPart } from './session-hooks.ts';
4
+ import { type AttendedSession } from './unattended-attended.ts';
4
5
  import { type UnattendedOverride, type UnattendedSlot, type UnattendedState } from './unattended-state.ts';
5
6
  /** Families whose sessions Unattended Mode covers in v1. */
6
7
  export declare const UNATTENDED_FAMILIES: readonly string[];
@@ -14,8 +15,18 @@ export interface UnattendedStatus extends UnattendedState {
14
15
  /** The config has an `unattended` section, so sessions sideby starts get the hook. */
15
16
  configured: boolean;
16
17
  schedule: UnattendedSlot[];
18
+ /**
19
+ * Answer Wait (ADR-0077): minutes a question or permission prompt shown in a Claude session waits for a person
20
+ * before, with the mode on, the session goes on without an answer; null: never. 10 when not set.
21
+ */
22
+ answerWait: number | null;
17
23
  /** Open Pending Decisions. */
18
24
  pending: number;
25
+ /**
26
+ * Attended Sessions (ADR-0075): Claude sessions someone typed into within the last 30 minutes, which ask as usual
27
+ * while the mode stays on for the rest. Latest end first.
28
+ */
29
+ attended: AttendedSession[];
19
30
  coverage: Record<string, UnattendedCoverage>;
20
31
  /** When `on --slot-end` would end: the end of the current or next Slot, when that is within 72 hours. */
21
32
  slotEnd?: string;
@@ -116,6 +127,18 @@ export declare function setUnattendedSchedule(opts: {
116
127
  }): Promise<UnattendedChange & {
117
128
  previous: UnattendedSlot[];
118
129
  }>;
130
+ /**
131
+ * Sets the Answer Wait (ADR-0077): whole minutes from 1 to 120, or null for never, creating the config section. It
132
+ * reaches running sessions at once (their hooks read it at every look). Throws a UserError for any other value.
133
+ */
134
+ export declare function setAnswerWait(opts: {
135
+ paths: Paths;
136
+ families: readonly string[];
137
+ minutes: number | null;
138
+ now?: Date;
139
+ }): Promise<UnattendedChange & {
140
+ before: number | null;
141
+ }>;
119
142
  /** The preset names `schedule preset` takes, with what each adds. */
120
143
  export declare const UNATTENDED_PRESETS: Readonly<Record<string, UnattendedSlot>>;
121
144
  /** The Slot `schedule add` was given, or why it cannot be one (the message says what to do). */
@@ -132,8 +155,12 @@ export declare const unattendedClock: (iso: string, now: Date, zh?: boolean) =>
132
155
  /**
133
156
  * Unattended Mode's session hooks: before the ask tool and when the model ends its turn (`Stop`, which keeps a turn
134
157
  * that ended on a question going once) in Claude and Codex; and in Claude on every permission request Claude Code is
135
- * about to show, every MCP server form (`Elicitation`), and every turn that failed on an API error (`StopFailure`, in the background with `asyncRewake`, so its exit 2 wakes the session: Turn Retry,
136
- * ADR-0067). Codex has no such events for them; its own approval prompts and failed turns are not covered.
158
+ * about to show, every MCP server form (`Elicitation`), every turn that failed on an API error (`StopFailure`, in the
159
+ * background with `asyncRewake`, so its exit 2 wakes the session: Turn Retry, ADR-0067), and every prompt
160
+ * (`UserPromptSubmit`, in the background with `async`, so it never holds a prompt back: Attended Sessions, ADR-0075).
161
+ * For Answer Wait (ADR-0077) the `PermissionRequest` entry may wait while its prompt is on screen, so it has a long
162
+ * `timeout`, and a second `Stop` entry waits in the background (`asyncRewake`) after a turn that ended on a question.
163
+ * Codex has no such events for them; its own approval prompts and failed turns are not covered.
137
164
  */
138
165
  export declare function unattendedHookPart(): SessionHookPart;
139
166
  /** The line a Claude Launch prints when the user's own `--settings` leaves no room for the hook. */
@@ -8,9 +8,11 @@ import { editConfigUnattended } from './config.js';
8
8
  import { UserError } from './errors.js';
9
9
  import { ownedFolder, writeFileAtomic } from './fs-safe.js';
10
10
  import { sidebyHookCommand } from './session-hooks.js';
11
+ import { ATTENDED_HOOK_TIMEOUT_S, listAttended } from './unattended-attended.js';
11
12
  import { listPendingDecisions } from './unattended-pending.js';
12
13
  import { RETRY_HOOK_TIMEOUT_S } from './unattended-retry.js';
13
- import { clearUnattendedOverride, clockText, ensureUnattendedDir, MAX_MANUAL_MS, parseClock, parseDays, parseSlot, readUnattendedConfig, readUnattendedOverride, scheduleStretchAt, slotEnd, UNATTENDED_ENV, unattendedState, writeUnattendedOverride, } from './unattended-state.js';
14
+ import { ANSWER_WAIT_DEFAULT, clearUnattendedOverride, clockText, ensureUnattendedDir, MAX_MANUAL_MS, parseClock, parseDays, parseSlot, readUnattendedConfig, readUnattendedOverride, scheduleStretchAt, slotEnd, UNATTENDED_ENV, unattendedState, validAnswerWait, writeUnattendedOverride, } from './unattended-state.js';
15
+ import { ANSWER_HOOK_TIMEOUT_S } from './unattended-wait.js';
14
16
  /** Families whose sessions Unattended Mode covers in v1. */
15
17
  export const UNATTENDED_FAMILIES = ['claude', 'codex'];
16
18
  const DEFAULT_HOURS = 12;
@@ -49,7 +51,7 @@ function coverageOf(families, configured) {
49
51
  /** The full status. `env` matters only for a session started with `--unattended`. */
50
52
  export async function unattendedStatus(opts) {
51
53
  const now = opts.now ?? new Date();
52
- const { configured, schedule } = await readUnattendedConfig(opts.paths.configFile);
54
+ const { configured, schedule, answerWait } = await readUnattendedConfig(opts.paths.configFile);
53
55
  const override = await readUnattendedOverride(opts.paths.stateDir);
54
56
  const state = unattendedState({ schedule, override, now, session: opts.env?.[UNATTENDED_ENV] === '1' });
55
57
  const end = slotEnd(schedule, now);
@@ -59,7 +61,9 @@ export async function unattendedStatus(opts) {
59
61
  ...state,
60
62
  configured,
61
63
  schedule,
64
+ answerWait,
62
65
  pending: (await listPendingDecisions(opts.paths.stateDir, { now, prune: !opts.readOnly })).length,
66
+ attended: await listAttended(opts.paths.stateDir, now, { prune: !opts.readOnly }),
63
67
  coverage: coverageOf(opts.families, configured),
64
68
  ...(end !== undefined && end - now.getTime() <= MAX_MANUAL_MS
65
69
  ? { slotEnd: new Date(end).toISOString() }
@@ -268,6 +272,28 @@ export async function setUnattendedSchedule(opts) {
268
272
  });
269
273
  return { changed: r.changed, status: await unattendedStatus(opts), previous };
270
274
  }
275
+ /** The command that sets the Answer Wait to `minutes` (null: never). */
276
+ const waitCommand = (minutes) => `sideby unattended wait ${minutes === null ? 'off' : minutes}`;
277
+ /**
278
+ * Sets the Answer Wait (ADR-0077): whole minutes from 1 to 120, or null for never, creating the config section. It
279
+ * reaches running sessions at once (their hooks read it at every look). Throws a UserError for any other value.
280
+ */
281
+ export async function setAnswerWait(opts) {
282
+ if (opts.minutes !== null && !validAnswerWait(opts.minutes))
283
+ throw new UserError('the wait takes whole minutes from 1 to 120, or off; for example `sideby unattended wait 10`', {
284
+ code: 'bad-wait',
285
+ });
286
+ let before = ANSWER_WAIT_DEFAULT;
287
+ const r = await editConfigUnattended(opts.paths.configFile, (current) => {
288
+ before = current?.answerWait === false ? null : (current?.answerWait ?? ANSWER_WAIT_DEFAULT);
289
+ if (current && current.answerWait !== undefined && before === opts.minutes)
290
+ return null;
291
+ return { ...current, answerWait: opts.minutes === null ? false : opts.minutes };
292
+ });
293
+ const status = await unattendedStatus(opts);
294
+ const changed = r.changed && before !== opts.minutes;
295
+ return { changed, status, before, ...(changed ? { undo: waitCommand(before) } : {}) };
296
+ }
271
297
  /** The preset names `schedule preset` takes, with what each adds. */
272
298
  export const UNATTENDED_PRESETS = { weeknights: WEEKNIGHTS };
273
299
  /** The Slot `schedule add` was given, or why it cannot be one (the message says what to do). */
@@ -292,8 +318,12 @@ export const unattendedClock = (iso, now, zh = false) => clockText(Date.parse(is
292
318
  /**
293
319
  * Unattended Mode's session hooks: before the ask tool and when the model ends its turn (`Stop`, which keeps a turn
294
320
  * that ended on a question going once) in Claude and Codex; and in Claude on every permission request Claude Code is
295
- * about to show, every MCP server form (`Elicitation`), and every turn that failed on an API error (`StopFailure`, in the background with `asyncRewake`, so its exit 2 wakes the session: Turn Retry,
296
- * ADR-0067). Codex has no such events for them; its own approval prompts and failed turns are not covered.
321
+ * about to show, every MCP server form (`Elicitation`), every turn that failed on an API error (`StopFailure`, in the
322
+ * background with `asyncRewake`, so its exit 2 wakes the session: Turn Retry, ADR-0067), and every prompt
323
+ * (`UserPromptSubmit`, in the background with `async`, so it never holds a prompt back: Attended Sessions, ADR-0075).
324
+ * For Answer Wait (ADR-0077) the `PermissionRequest` entry may wait while its prompt is on screen, so it has a long
325
+ * `timeout`, and a second `Stop` entry waits in the background (`asyncRewake`) after a turn that ended on a question.
326
+ * Codex has no such events for them; its own approval prompts and failed turns are not covered.
297
327
  */
298
328
  export function unattendedHookPart() {
299
329
  const command = (family, event = 'PreToolUse') => sidebyHookCommand('unattended-hook', family, event);
@@ -303,8 +333,15 @@ export function unattendedHookPart() {
303
333
  id: 'unattended',
304
334
  claude: {
305
335
  PreToolUse: [{ matcher: 'AskUserQuestion', hooks: claude('PreToolUse') }],
306
- PermissionRequest: [{ matcher: '*', hooks: claude('PermissionRequest') }],
307
- Stop: [{ hooks: claude('Stop') }],
336
+ // Waits while its prompt is on screen (Answer Wait), so Claude Code's 10-minute default would cut it short.
337
+ PermissionRequest: [
338
+ { matcher: '*', hooks: [{ ...claude('PermissionRequest')[0], timeout: ANSWER_HOOK_TIMEOUT_S }] },
339
+ ],
340
+ Stop: [
341
+ { hooks: claude('Stop') },
342
+ // Answer Wait for a question written as text: in the background, so the turn ends at once.
343
+ { hooks: [{ ...claude('StopWait')[0], asyncRewake: true, timeout: ANSWER_HOOK_TIMEOUT_S }] },
344
+ ],
308
345
  Elicitation: [{ matcher: '*', hooks: claude('Elicitation') }],
309
346
  // Waits up to 4 minutes before it wakes the session; Claude Code still enforces `timeout` on `asyncRewake`.
310
347
  // No matcher: every failed turn reaches it, so a later failure that is not retried still ends an earlier wait.
@@ -313,6 +350,11 @@ export function unattendedHookPart() {
313
350
  hooks: [{ ...claude('StopFailure')[0], asyncRewake: true, timeout: RETRY_HOOK_TIMEOUT_S }],
314
351
  },
315
352
  ],
353
+ // Waits up to 10 seconds for the prompt's transcript line; `async`, so the prompt goes on at once and nothing
354
+ // the hook prints or returns reaches the session.
355
+ UserPromptSubmit: [
356
+ { hooks: [{ ...claude('UserPromptSubmit')[0], async: true, timeout: ATTENDED_HOOK_TIMEOUT_S }] },
357
+ ],
316
358
  },
317
359
  codex: {
318
360
  PreToolUse: [`{matcher="^request_user_input$",${codex('PreToolUse')}}`],
@@ -6,6 +6,8 @@ import { randomBytes } from 'node:crypto';
6
6
  import { readFile, rm, stat } from 'node:fs/promises';
7
7
  import { join } from 'node:path';
8
8
  import { BRIEF_DONE, FILES, HANDOFF_ENV, readJsonFile, writeJsonFile, } from '../core/handoff-chain.js';
9
+ import { resolvePaths } from '../core/paths.js';
10
+ import { progressReminderTurn } from '../core/progress-state.js';
9
11
  import { claudeHookReader } from '../families/claude/handoff-hook.js';
10
12
  import { codexHookReader } from '../families/codex/handoff-hook.js';
11
13
  import { grokHookReader } from '../families/grok/handoff-hook.js';
@@ -121,6 +123,10 @@ export async function decide(opts) {
121
123
  const reason = field(input, 'reason');
122
124
  if (reason && reason !== 'end_turn')
123
125
  return {};
126
+ // A turn a Progress Reminder started while the session waits on background work (spec §3.42, ADR-0076): handled so
127
+ // that handing over goes as it would without the reminder. A record that is missing or late says no: an ordinary turn.
128
+ const reminder = family === 'claude' &&
129
+ (await progressReminderTurn(resolvePaths(env).stateDir, sessionId, field(input, 'prompt_id', 'promptId')));
124
130
  // A finished turn means a Host kept at its limit has continued: a later `handoff ready` waits for the turn again.
125
131
  const waitingFile = join(dir, FILES.waiting);
126
132
  const held = await readJsonFile(waitingFile);
@@ -134,8 +140,10 @@ export async function decide(opts) {
134
140
  }
135
141
  if (!usable)
136
142
  return {};
137
- // The turn that just ended joins the window's recent turns before anything is judged (ADR-0032).
138
- if (windows)
143
+ // The turn that just ended joins the window's recent turns before anything is judged (ADR-0032). A reminder's turn
144
+ // does not: what the wait used counts toward the next real turn, as without reminders, so one wait is not cut into
145
+ // small turns that would move the adaptive level later.
146
+ if (windows && !reminder)
139
147
  await keep(recordTurn(st, windows));
140
148
  const notice = await waitOutput();
141
149
  if (notice)
@@ -148,7 +156,10 @@ export async function decide(opts) {
148
156
  if (st.thresholdSentAt) {
149
157
  if (await briefFinished(usable.brief, Date.parse(st.thresholdSentAt)))
150
158
  await ready({ trigger: 'threshold', brief: usable.brief, briefSource: 'agent', ...window });
151
- else if (!st.stopBlocked && input.stop_hook_active !== true && input.stopHookActive !== true) {
159
+ // A reminder's turn always has `stop_hook_active` (a hook woke it), but nobody asked it for the Brief yet: hold
160
+ // it once like an ordinary turn instead of handing over without the agent's Brief.
161
+ else if (!st.stopBlocked &&
162
+ (reminder || (input.stop_hook_active !== true && input.stopHookActive !== true))) {
152
163
  await keep({ ...st, stopBlocked: true });
153
164
  return { output: blockOutput(stopMessage(usable.brief)) };
154
165
  }
@@ -164,7 +175,11 @@ export async function decide(opts) {
164
175
  return {};
165
176
  }
166
177
  await keep({ ...st, thresholdSentAt: now.toISOString(), thresholdWindow: crossed, stopBlocked: true });
167
- return { output: blockOutput(thresholdMessage(usable.brief, crossed)) };
178
+ // A reminder's turn ends while background work runs: the message IdleWatch would have sent.
179
+ const text = reminder
180
+ ? idleThresholdMessage(usable.brief, crossed)
181
+ : thresholdMessage(usable.brief, crossed);
182
+ return { output: blockOutput(text) };
168
183
  }
169
184
  return {};
170
185
  }
@@ -12,6 +12,7 @@ import { setTimeout as delay } from 'node:timers/promises';
12
12
  import { blockMessage, inCi, judge, NETWORK_ENV, prefersChinese, readNetworkConfig, refresh, verdict, } from '../core/egress.js';
13
13
  import { ownedFolder, readSmallFile, sha256, writeFileAtomic } from '../core/fs-safe.js';
14
14
  import { resolvePaths } from '../core/paths.js';
15
+ import { HELD_CLOSE, HELD_OPEN, hookWakeUp, hostMade } from '../core/prompt-origin.js';
15
16
  export const NETWORK_HOOK_COMMAND = 'sideby network-hook';
16
17
  /** The Host events this entry answers, and when each happens; `Refresh` is its own detached refresh. */
17
18
  const MOMENTS = { UserPromptSubmit: 'prompt', PreToolUse: 'tool' };
@@ -19,10 +20,6 @@ const MOMENTS = { UserPromptSubmit: 'prompt', PreToolUse: 'tool' };
19
20
  const STDIN_MAX = 1024 * 1024;
20
21
  /** Input that has not ended after this long is not waited for: the hook then decides as if it were given nothing. */
21
22
  const STDIN_WAIT_MS = 5000;
22
- /** A wake-up Claude Code makes from a background hook's exit 2 starts like this; only such a prompt carries a held message. */
23
- const WAKE_UP = /^<task-notification>\s*<summary>Stop hook feedback<\/summary>/;
24
- /** A prompt Claude Code made itself starts with this (a background task's notification, a hook's wake-up). */
25
- const HOST_MADE = '<task-notification>';
26
23
  /** `Held` asks again after these waits, then every `HELD_EVERY_MS`: one request each time. */
27
24
  export const HELD_DELAYS_MS = [15_000, 30_000];
28
25
  export const HELD_EVERY_MS = 60_000;
@@ -38,8 +35,6 @@ const DECISION_POLL_MS = 200;
38
35
  const DECISION_KEPT_MS = 3600_000;
39
36
  /** The most of a held message that is handed over. */
40
37
  const HELD_MAX_CHARS = 8000;
41
- const HELD_OPEN = '<sideby-held-message>';
42
- const HELD_CLOSE = '</sideby-held-message>';
43
38
  async function readInput(input) {
44
39
  if (input === undefined)
45
40
  return '';
@@ -81,7 +76,7 @@ async function hostMadePrompt(input) {
81
76
  const v = JSON.parse(await readInput(input));
82
77
  if (!v || typeof v.prompt !== 'string' || typeof v.prompt_id !== 'string' || !v.prompt_id)
83
78
  return undefined;
84
- return v.prompt.trimStart().startsWith(HOST_MADE) ? { id: v.prompt_id, prompt: v.prompt } : undefined;
79
+ return hostMade(v.prompt) ? { id: v.prompt_id, prompt: v.prompt } : undefined;
85
80
  }
86
81
  catch {
87
82
  return undefined;
@@ -129,7 +124,8 @@ function heldMessage(prompt, zh) {
129
124
  // A wake-up that was blocked again carries the first message inside the tags: hand over that one alone.
130
125
  const from = prompt.indexOf(HELD_OPEN);
131
126
  const to = prompt.lastIndexOf(HELD_CLOSE);
132
- const inner = WAKE_UP.test(prompt.trimStart()) && from !== -1 && to > from;
127
+ // Only a wake-up Claude Code made from a background hook's exit 2 carries a held message.
128
+ const inner = hookWakeUp(prompt) && from !== -1 && to > from;
133
129
  const whole = (inner ? prompt.slice(from + HELD_OPEN.length, to) : prompt).trim();
134
130
  const text = whole.slice(0, HELD_MAX_CHARS);
135
131
  const cut = whole.length > HELD_MAX_CHARS
@@ -9,6 +9,7 @@ import { type LiveSession, type LiveSessionsResult, sessionCopyText } from '../c
9
9
  import { listMessages, type MessageReceipt, sendMessage } from '../core/messages.ts';
10
10
  import { type AccountModel } from '../core/model-choice.ts';
11
11
  import { type NetworkOverview } from '../core/network.ts';
12
+ import { type ProgressView } from '../core/progress.ts';
12
13
  import { type RemoteControlGroup } from '../core/remote-control.ts';
13
14
  import { type UnattendedStatus } from '../core/unattended.ts';
14
15
  import { type PendingDecision } from '../core/unattended-pending.ts';
@@ -301,6 +302,8 @@ export interface PanelState {
301
302
  network?: NetworkOverview;
302
303
  /** Unattended Mode (spec §3.37): whether it is on for the computer, why, until when, the Schedule; absent when unreadable. */
303
304
  unattended?: PanelUnattendedStatus;
305
+ /** Progress Reminders (spec §3.42): on or off, how often, and the choices; absent without Claude Accounts. */
306
+ progress?: ProgressView;
304
307
  }
305
308
  /** One Pending Decision as the Panel's Unattended page lists it, with the way back to its Session. */
306
309
  export interface PanelPendingDecision extends PendingDecision {
@@ -25,6 +25,8 @@ import { listMessages, sendMessage } from '../core/messages.js';
25
25
  import { accountModel, setAccountModel } from '../core/model-choice.js';
26
26
  import { GUARDED_FAMILIES, setNetwork } from '../core/network.js';
27
27
  import { tildify } from '../core/paths.js';
28
+ import { PROGRESS_FAMILIES } from '../core/progress.js';
29
+ import { validEvery } from '../core/progress-state.js';
28
30
  import { quotaAsking } from '../core/quota-fetch.js';
29
31
  import { takeoverLimits } from '../core/quota-levels.js';
30
32
  import { remoteControlTodo } from '../core/remote-control.js';
@@ -35,7 +37,7 @@ import { SKILL_INSTALL } from '../core/skill-check.js';
35
37
  import { launchArgs, TERMINALS } from '../core/terminal.js';
36
38
  import { checkThemeData, listThemes, NO_THEME, previewColors, removeThemeFile, resolveColors, saveThemeFile, undoTheme, useTheme, } from '../core/themes.js';
37
39
  import { MIN_CALLS } from '../core/tuning.js';
38
- import { onUntil, setUnattendedSchedule, turnUnattendedOff, turnUnattendedOn, unattendedStatus, } from '../core/unattended.js';
40
+ import { onUntil, setAnswerWait, setUnattendedSchedule, turnUnattendedOff, turnUnattendedOn, unattendedStatus, } from '../core/unattended.js';
39
41
  import { checkUnattendedEnded } from '../core/unattended-ended.js';
40
42
  import { listPendingDecisions, markPendingDone, reopenPendingDecision, } from '../core/unattended-pending.js';
41
43
  import { readUnattendedConfig } from '../core/unattended-state.js';
@@ -647,6 +649,7 @@ async function buildState(rt, opts) {
647
649
  .then((st) => withPendingIds(st, rt.paths.stateDir))
648
650
  .catch(() => undefined);
649
651
  const showBrowser = browser && (browser.families.matched.length || browser.families.openOnly.length);
652
+ const progress = accounts.some((a) => PROGRESS_FAMILIES.includes(a.family)) ? rt.progressView() : undefined;
650
653
  const permissions = aiTaskPermissions(rt.config);
651
654
  return {
652
655
  schemaVersion: 1,
@@ -694,6 +697,7 @@ async function buildState(rt, opts) {
694
697
  ...(rt.config.panel && Object.keys(rt.config.panel).length ? { panel: rt.config.panel } : {}),
695
698
  ...(network ? { network } : {}),
696
699
  ...(unattended ? { unattended } : {}),
700
+ ...(progress ? { progress } : {}),
697
701
  };
698
702
  }
699
703
  const SHELL_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
@@ -1996,6 +2000,21 @@ export function createPanelHandler(opts) {
1996
2000
  };
1997
2001
  },
1998
2002
  },
2003
+ // Answer Wait (ADR-0077): `minutes` from 1 to 120, or null for never. Its Undo sends `before` back.
2004
+ '/api/unattended/wait': {
2005
+ async run(body) {
2006
+ const minutes = body.minutes;
2007
+ if (minutes !== null && typeof minutes !== 'number')
2008
+ throw new HttpError(400, '"minutes" must be whole minutes from 1 to 120, or null for never', 'bad-wait');
2009
+ const rt = await getRuntime();
2010
+ const r = await setAnswerWait({ paths: rt.paths, families: [...rt.families.keys()], minutes });
2011
+ return {
2012
+ changed: r.changed,
2013
+ status: await withPendingIds(r.status, rt.paths.stateDir),
2014
+ before: r.before,
2015
+ };
2016
+ },
2017
+ },
1999
2018
  // Marks one Pending Decision done (or every open one with `all`), or with `done: false` opens one again.
2000
2019
  '/api/unattended/pending': {
2001
2020
  async run(body) {
@@ -2299,6 +2318,17 @@ export function createPanelHandler(opts) {
2299
2318
  return { family, ...(await rt.setQuotaCheck(family, body.on)) };
2300
2319
  },
2301
2320
  },
2321
+ // Progress Reminders on with `every` minutes, or off with null: config `progress` (spec §3.42).
2322
+ '/api/progress': {
2323
+ async run(body) {
2324
+ const every = body.every;
2325
+ if (every !== null && !validEvery(every))
2326
+ throw new HttpError(400, '"every" must be whole minutes from 1 to 240, or null to turn it off');
2327
+ const rt = await getRuntime();
2328
+ const r = await rt.setProgress(validEvery(every) ? every : undefined);
2329
+ return { changed: r.changed, ...(r.after === undefined ? {} : { every: r.after }) };
2330
+ },
2331
+ },
2302
2332
  // The Panel's theme and language (spec §3.29): config `panel.theme` and `panel.language`; null removes one.
2303
2333
  '/api/panel/settings': {
2304
2334
  async run(body) {
@@ -1714,6 +1714,19 @@ declare const en: {
1714
1714
  'ua.overnight': string;
1715
1715
  'ua.allDay': string;
1716
1716
  'ua.remove': string;
1717
+ 'ua.here': string;
1718
+ 'ua.hereNote': string;
1719
+ 'ua.hereHint': string;
1720
+ 'ua.hereSession': string;
1721
+ 'ua.wait': string;
1722
+ 'ua.waitNote': string;
1723
+ 'ua.waitLabel': string;
1724
+ 'ua.waitMin': string;
1725
+ 'ua.waitNever': string;
1726
+ 'ua.waitToast': string;
1727
+ 'ua.waitNeverToast': string;
1728
+ 'ua.waitFailed': string;
1729
+ 'ua.waited': string;
1717
1730
  'ua.pending': string;
1718
1731
  'ua.pendingNote': string;
1719
1732
  'ua.pendingEmpty': string;
@@ -1747,6 +1760,20 @@ declare const en: {
1747
1760
  'ua.problem': string;
1748
1761
  'ua.unreadable': string;
1749
1762
  'ai.ask.unattended': string;
1763
+ 'ai.ask.progress': string;
1764
+ 'pr.title': string;
1765
+ 'pr.hint': string;
1766
+ 'pr.switch': string;
1767
+ 'pr.every': string;
1768
+ 'pr.minutes': string;
1769
+ 'pr.everyLong': string;
1770
+ 'pr.cost': string;
1771
+ 'pr.scope': string;
1772
+ 'pr.codex': string;
1773
+ 'pr.onToast': string;
1774
+ 'pr.everyToast': string;
1775
+ 'pr.offToast': string;
1776
+ 'pr.failed': string;
1750
1777
  };
1751
1778
  export type MessageKey = keyof typeof en;
1752
1779
  export declare const MESSAGES: Record<PanelLang, Record<string, string>>;
@@ -1716,8 +1716,21 @@ const en = {
1716
1716
  'ua.overnight': 'next day',
1717
1717
  'ua.allDay': 'all day',
1718
1718
  'ua.remove': 'Remove {slot}',
1719
+ 'ua.here': 'Asking you as usual',
1720
+ 'ua.hereNote': 'You typed in these sessions in the last 30 minutes, so they ask you as usual. Each message you send gives that session another 30 minutes. Every other session stays unattended.',
1721
+ 'ua.hereHint': 'Back early? Type in a session and it asks you as usual for 30 minutes. The others stay unattended.',
1722
+ 'ua.hereSession': 'Session {id}',
1723
+ 'ua.wait': 'If nobody answers',
1724
+ 'ua.waitNote': 'A question in a session you are in waits this long for your answer. If Unattended Mode is on by then, the session goes on without you: it takes the recommended choice where that can be undone, and skips a step that needs your OK. Each one shows up under Waiting for you.',
1725
+ 'ua.waitLabel': 'Go on after',
1726
+ 'ua.waitMin': '{n} min',
1727
+ 'ua.waitNever': 'Never',
1728
+ 'ua.waitToast': 'Questions now wait {n} min for you.',
1729
+ 'ua.waitNeverToast': 'Questions now wait for you, however long.',
1730
+ 'ua.waitFailed': 'Could not change it: {msg}',
1731
+ 'ua.waited': 'No answer for {n} min',
1719
1732
  'ua.pending': 'Waiting for you',
1720
- 'ua.pendingNote': 'Questions sessions did not ask you, steps that needed your OK, and steps they skipped. Nothing here was done.',
1733
+ 'ua.pendingNote': 'Questions sessions did not ask you or nobody answered, steps that needed your OK, and steps they skipped. Nothing here was done.',
1721
1734
  'ua.pendingEmpty': 'Nothing is waiting for you.',
1722
1735
  'ua.pendingBlocked': 'sideby cannot read them until the folder named above is fixed.',
1723
1736
  'ua.loading': 'Reading…',
@@ -1749,6 +1762,20 @@ const en = {
1749
1762
  'ua.problem': 'sideby cannot keep its state: {msg}',
1750
1763
  'ua.unreadable': 'sideby could not read Unattended Mode. Refresh to try again.',
1751
1764
  'ai.ask.unattended': 'Run unattended tonight, until 8 tomorrow morning.',
1765
+ 'ai.ask.progress': 'While background tasks run, tell me every 30 minutes what my sessions are waiting for.',
1766
+ 'pr.title': 'Progress updates',
1767
+ 'pr.hint': 'When a Claude session waits on background work (subagents, long commands), it tells you what it is waiting for and for how long, every 30 minutes or as often as you pick.',
1768
+ 'pr.switch': 'Report progress while waiting',
1769
+ 'pr.every': 'How often',
1770
+ 'pr.minutes': '{n} min',
1771
+ 'pr.everyLong': 'Every {n} minutes',
1772
+ 'pr.cost': 'Each update is one model turn, which reads the whole conversation, so it uses quota; a longer interval uses less.',
1773
+ 'pr.scope': 'Claude sessions you start after turning it on get it. Turning it off stops it in open sessions too. No updates while you are away (Unattended Mode).',
1774
+ 'pr.codex': 'Codex is not covered: it has no way to wake a waiting session.',
1775
+ 'pr.onToast': 'Progress updates on, every {n} minutes. Claude sessions you start from now on get them.',
1776
+ 'pr.everyToast': 'Progress updates now every {n} minutes.',
1777
+ 'pr.offToast': 'Progress updates off.',
1778
+ 'pr.failed': 'Could not change progress updates: {msg}. It is back as it was; try again, or run sideby progress in a terminal.',
1752
1779
  };
1753
1780
  const zh = {
1754
1781
  'top.tagline': '所有 AI 编程账号,并排运行。',
@@ -3465,8 +3492,21 @@ const zh = {
3465
3492
  'ua.overnight': '次日',
3466
3493
  'ua.allDay': '全天',
3467
3494
  'ua.remove': '删除{slot}',
3495
+ 'ua.here': '照常问你的会话',
3496
+ 'ua.hereNote': '你 30 分钟内在这些会话里打过字,它们照常问你;每发一条消息,那个会话再算 30 分钟。其他会话仍然无人值守。',
3497
+ 'ua.hereHint': '提前回来了?在哪个会话里打字,那个会话 30 分钟内照常问你,其他会话不受影响。',
3498
+ 'ua.hereSession': '会话 {id}',
3499
+ 'ua.wait': '没人回答时',
3500
+ 'ua.waitNote': '你在的会话里出现提问,会等你这么久。到时无人值守开着,会话就不再等:能撤回的按推荐选项继续,要你确认的操作跳过不做。每一条都记在下面“待你决定”里。',
3501
+ 'ua.waitLabel': '等多久后继续',
3502
+ 'ua.waitMin': '{n} 分钟',
3503
+ 'ua.waitNever': '一直等',
3504
+ 'ua.waitToast': '提问现在等你 {n} 分钟。',
3505
+ 'ua.waitNeverToast': '提问现在一直等你回答。',
3506
+ 'ua.waitFailed': '没改成:{msg}',
3507
+ 'ua.waited': '等了 {n} 分钟没人回答',
3468
3508
  'ua.pending': '待你决定',
3469
- 'ua.pendingNote': '会话没问你的问题、要你确认的操作和跳过的操作。这里的事都还没做。',
3509
+ 'ua.pendingNote': '会话没问你或没人回答的问题、要你确认的操作和跳过的操作。这里的事都还没做。',
3470
3510
  'ua.pendingEmpty': '没有待你决定的事',
3471
3511
  'ua.pendingBlocked': '上面说的文件夹修好之前,sideby 读不到它们。',
3472
3512
  'ua.loading': '正在读取…',
@@ -3498,5 +3538,19 @@ const zh = {
3498
3538
  'ua.problem': 'sideby 没法保存状态:{msg}',
3499
3539
  'ua.unreadable': 'sideby 读不到无人值守的状态。刷新再试一次。',
3500
3540
  'ai.ask.unattended': '今晚无人值守,到明早 8 点',
3541
+ 'ai.ask.progress': '后台任务跑着时,每 30 分钟告诉我会话在等什么。',
3542
+ 'pr.title': '进度提醒',
3543
+ 'pr.hint': 'Claude 会话等后台任务(子任务、长命令)时,告诉你在等什么、等了多久:默认每 30 分钟一次,也可以自己选。',
3544
+ 'pr.switch': '等待时报进度',
3545
+ 'pr.every': '多久一次',
3546
+ 'pr.minutes': '{n} 分钟',
3547
+ 'pr.everyLong': '每 {n} 分钟',
3548
+ 'pr.cost': '每次提醒是一轮模型调用,会读一遍整个对话,会用额度;间隔越长用得越少。',
3549
+ 'pr.scope': '打开后启动的 Claude 会话才有;关掉对已经开着的会话也生效。无人值守时不提醒。',
3550
+ 'pr.codex': 'Codex 不支持:它没有办法叫醒等待中的会话。',
3551
+ 'pr.onToast': '已打开进度提醒,每 {n} 分钟一次。之后启动的 Claude 会话会有。',
3552
+ 'pr.everyToast': '进度提醒改为每 {n} 分钟一次。',
3553
+ 'pr.offToast': '已关闭进度提醒。',
3554
+ 'pr.failed': '没能改进度提醒:{msg}。已恢复原样;可以再试一次,或在终端运行 sideby progress。',
3501
3555
  };
3502
3556
  export const MESSAGES = { en, zh };