sideby 0.38.0 → 0.39.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 (47) 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 +88 -0
  4. package/dist/src/cli/json-schemas.js +35 -0
  5. package/dist/src/cli/main.js +32 -1
  6. package/dist/src/core/cli-commands.js +14 -2
  7. package/dist/src/core/config.d.ts +13 -0
  8. package/dist/src/core/config.js +18 -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/network.d.ts +11 -1
  12. package/dist/src/core/network.js +21 -1
  13. package/dist/src/core/progress-state.d.ts +80 -0
  14. package/dist/src/core/progress-state.js +216 -0
  15. package/dist/src/core/progress.d.ts +36 -0
  16. package/dist/src/core/progress.js +77 -0
  17. package/dist/src/core/prompt-origin.d.ts +40 -0
  18. package/dist/src/core/prompt-origin.js +98 -0
  19. package/dist/src/core/search-catalog.js +25 -0
  20. package/dist/src/core/unattended-attended.d.ts +109 -0
  21. package/dist/src/core/unattended-attended.js +337 -0
  22. package/dist/src/core/unattended.d.ts +10 -2
  23. package/dist/src/core/unattended.js +11 -2
  24. package/dist/src/handoff/hook.js +19 -4
  25. package/dist/src/menubar/script.js +9 -3
  26. package/dist/src/network/hook.d.ts +9 -0
  27. package/dist/src/network/hook.js +186 -4
  28. package/dist/src/panel/handler.d.ts +3 -0
  29. package/dist/src/panel/handler.js +15 -0
  30. package/dist/src/panel/i18n.d.ts +18 -0
  31. package/dist/src/panel/i18n.js +36 -0
  32. package/dist/src/panel/page-script.js +67 -2
  33. package/dist/src/panel/page-styles.js +14 -0
  34. package/dist/src/progress/hook.d.ts +50 -0
  35. package/dist/src/progress/hook.js +251 -0
  36. package/dist/src/runtime.d.ts +9 -0
  37. package/dist/src/runtime.js +45 -2
  38. package/dist/src/unattended/hook.d.ts +5 -0
  39. package/dist/src/unattended/hook.js +103 -9
  40. package/package.json +1 -1
  41. package/schemas/config.json +13 -0
  42. package/schemas/progress.json +137 -0
  43. package/schemas/unattended.json +38 -0
  44. package/skills/sideby/SKILL.md +3 -1
  45. package/skills/sideby/references/network.md +1 -1
  46. package/skills/sideby/references/progress.md +25 -0
  47. package/skills/sideby/references/unattended.md +9 -1
@@ -2,13 +2,142 @@
2
2
  // call in a session sideby started with Network Guard on, so it imports only Node built-ins and leaf modules: never
3
3
  // the Runtime, a Family index or core/accounts.ts. Unlike `handoff-hook` it exists to stop the Host: exit 2 with the
4
4
  // reason on stderr blocks the prompt or the tool call; anything it cannot tell blocks too, after asking again for up to
5
- // about 30 seconds (a prompt the Host made itself is not sent again once blocked).
5
+ // about 30 seconds. A prompt the Host made itself (a background task's notification) is not sent again once blocked,
6
+ // so Claude Code also runs the `Held` entry in the background: it keeps such a prompt in memory while the exit is not
7
+ // allowed, and wakes the session with it (exit 2) once a new check passes.
6
8
  import { spawn } from 'node:child_process';
7
- import { blockMessage, inCi, NETWORK_ENV, prefersChinese, readNetworkConfig, refresh, verdict, } from '../core/egress.js';
9
+ import { lstat, readdir, unlink } from 'node:fs/promises';
10
+ import { join } from 'node:path';
11
+ import { setTimeout as delay } from 'node:timers/promises';
12
+ import { blockMessage, inCi, judge, NETWORK_ENV, prefersChinese, readNetworkConfig, refresh, verdict, } from '../core/egress.js';
13
+ import { ownedFolder, readSmallFile, sha256, writeFileAtomic } from '../core/fs-safe.js';
8
14
  import { resolvePaths } from '../core/paths.js';
15
+ import { HELD_CLOSE, HELD_OPEN, hookWakeUp, hostMade } from '../core/prompt-origin.js';
9
16
  export const NETWORK_HOOK_COMMAND = 'sideby network-hook';
10
17
  /** The Host events this entry answers, and when each happens; `Refresh` is its own detached refresh. */
11
18
  const MOMENTS = { UserPromptSubmit: 'prompt', PreToolUse: 'tool' };
19
+ /** A prompt larger than this is not read: the hook then decides as if it were given nothing. */
20
+ const STDIN_MAX = 1024 * 1024;
21
+ /** Input that has not ended after this long is not waited for: the hook then decides as if it were given nothing. */
22
+ const STDIN_WAIT_MS = 5000;
23
+ /** `Held` asks again after these waits, then every `HELD_EVERY_MS`: one request each time. */
24
+ export const HELD_DELAYS_MS = [15_000, 30_000];
25
+ export const HELD_EVERY_MS = 60_000;
26
+ /** `Held` ends by itself after this long, two minutes before the 5 hours Claude Code gives it (core/network.ts). */
27
+ export const HELD_BUDGET_MS = 5 * 3600_000 - 120_000;
28
+ /**
29
+ * How long `Held` waits for the decision of the hook that checks the same prompt: the 60 seconds Claude Code gives
30
+ * that hook (`CLAUDE_NETWORK_HOOK_TIMEOUT_S`, core/network.ts) and a little more.
31
+ */
32
+ const DECISION_WAIT_MS = 65_000;
33
+ const DECISION_POLL_MS = 200;
34
+ /** A decision nobody read (a session started before `Held` existed) is removed after this long. */
35
+ const DECISION_KEPT_MS = 3600_000;
36
+ /** The most of a held message that is handed over. */
37
+ const HELD_MAX_CHARS = 8000;
38
+ async function readInput(input) {
39
+ if (input === undefined)
40
+ return '';
41
+ if (typeof input === 'string')
42
+ return input;
43
+ const read = (async () => {
44
+ const chunks = [];
45
+ let size = 0;
46
+ for await (const chunk of input) {
47
+ const b = Buffer.from(chunk);
48
+ size += b.length;
49
+ if (size > STDIN_MAX)
50
+ return '';
51
+ chunks.push(b);
52
+ }
53
+ return Buffer.concat(chunks).toString('utf8');
54
+ })();
55
+ read.catch(() => { });
56
+ // A Host that never ends the input must not keep the check from starting.
57
+ let timer;
58
+ const late = new Promise((resolve) => {
59
+ timer = setTimeout(() => {
60
+ // Let go of the stream too: an open stdin would keep the process alive after the hook has decided.
61
+ ;
62
+ input.destroy?.();
63
+ resolve('');
64
+ }, STDIN_WAIT_MS);
65
+ });
66
+ try {
67
+ return await Promise.race([read, late]);
68
+ }
69
+ finally {
70
+ clearTimeout(timer);
71
+ }
72
+ }
73
+ /** The prompt and its id when the Host made the prompt itself; undefined for a typed prompt or unreadable input. */
74
+ async function hostMadePrompt(input) {
75
+ try {
76
+ const v = JSON.parse(await readInput(input));
77
+ if (!v || typeof v.prompt !== 'string' || typeof v.prompt_id !== 'string' || !v.prompt_id)
78
+ return undefined;
79
+ return hostMade(v.prompt) ? { id: v.prompt_id, prompt: v.prompt } : undefined;
80
+ }
81
+ catch {
82
+ return undefined;
83
+ }
84
+ }
85
+ /** The file that tells `Held` what the checking hook decided for one prompt: named by a hash of the prompt's id. */
86
+ const decisionName = (id) => sha256(id).slice(0, 32);
87
+ /**
88
+ * Keeps the decision for a prompt the Host made (`ok` or `blocked`, nothing of the prompt) where `Held` finds it, and
89
+ * removes decisions nobody read. A failure changes nothing: `Held` then hands nothing over, as before it existed.
90
+ */
91
+ async function keepDecision(dir, id, decision, now) {
92
+ try {
93
+ const folder = (await ownedFolder(dir, ['held'], { create: true, private: true }));
94
+ for (const name of await readdir(folder)) {
95
+ const st = await lstat(join(folder, name)).catch(() => null);
96
+ if (st && now - st.mtimeMs > DECISION_KEPT_MS)
97
+ await unlink(join(folder, name)).catch(() => { });
98
+ }
99
+ await writeFileAtomic(join(folder, decisionName(id)), decision, 0o600);
100
+ }
101
+ catch {
102
+ // no decision kept
103
+ }
104
+ }
105
+ /** Reads the decision for a prompt and removes it; undefined while there is none. */
106
+ async function takeDecision(dir, id) {
107
+ try {
108
+ const folder = await ownedFolder(dir, ['held'], { create: false });
109
+ if (!folder)
110
+ return undefined;
111
+ const file = join(folder, decisionName(id));
112
+ const text = await readSmallFile(file, 16);
113
+ if (text === undefined)
114
+ return undefined;
115
+ await unlink(file).catch(() => { });
116
+ return text === 'ok' ? 'ok' : 'blocked';
117
+ }
118
+ catch {
119
+ return undefined;
120
+ }
121
+ }
122
+ /** What the session is woken with: why the message is late, and the message between the two tags. */
123
+ function heldMessage(prompt, zh) {
124
+ // A wake-up that was blocked again carries the first message inside the tags: hand over that one alone.
125
+ const from = prompt.indexOf(HELD_OPEN);
126
+ const to = prompt.lastIndexOf(HELD_CLOSE);
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;
129
+ const whole = (inner ? prompt.slice(from + HELD_OPEN.length, to) : prompt).trim();
130
+ const text = whole.slice(0, HELD_MAX_CHARS);
131
+ const cut = whole.length > HELD_MAX_CHARS
132
+ ? zh
133
+ ? `\n(原文在 ${HELD_MAX_CHARS} 个字符处截断。)`
134
+ : `\n(The message was cut at ${HELD_MAX_CHARS} characters.)`
135
+ : '';
136
+ const why = zh
137
+ ? 'sideby 的网络检查在网络出口不被允许或查不出期间,扣住了一条 Claude Code 自己生成的消息(例如后台任务的结果)。现在可以送达了,原文如下:'
138
+ : "sideby's Network Guard held back a message Claude Code made itself (such as a background task's result) while this network's exit was not allowed or could not be told. It can go through now. The message as it was:";
139
+ return `${why}\n${HELD_OPEN}\n${text}\n${HELD_CLOSE}${cut}\n`;
140
+ }
12
141
  function startRefresh(family, env) {
13
142
  try {
14
143
  const entry = process.argv[1];
@@ -40,7 +169,9 @@ export async function runNetworkHook(argv, env, err, deps = {}) {
40
169
  // The switch and the list as config says now, so turning the check off or allowing a country in the Panel or with
41
170
  // `sideby network` reaches sessions already running. When config cannot be read, the list the session started with.
42
171
  const current = await readNetworkConfig(resolvePaths(env).configFile);
43
- if (current && !current.guard)
172
+ // `Held` goes on when the check is off: a prompt blocked a moment before the switch still has to be handed over.
173
+ const off = Boolean(current && !current.guard);
174
+ if (off && event !== 'Held')
44
175
  return 0;
45
176
  const allow = current?.allow ?? (env[NETWORK_ENV.allow] ?? '').split(',').filter(Boolean);
46
177
  const common = {
@@ -55,9 +186,56 @@ export async function runNetworkHook(argv, env, err, deps = {}) {
55
186
  await refresh(common);
56
187
  return 0;
57
188
  }
189
+ const clock = () => (deps.now?.() ?? new Date()).getTime();
190
+ if (event === 'Held') {
191
+ const made = await hostMadePrompt(deps.input);
192
+ if (!made)
193
+ return 0;
194
+ const sleep = deps.sleep ?? delay;
195
+ // The hook that checks this prompt says what it decided; no answer in time means it let the prompt through.
196
+ const asked = clock();
197
+ let decision;
198
+ while (true) {
199
+ decision = await takeDecision(dir, made.id);
200
+ if (decision || clock() - asked >= DECISION_WAIT_MS)
201
+ break;
202
+ await sleep(DECISION_POLL_MS);
203
+ }
204
+ if (decision !== 'blocked')
205
+ return 0;
206
+ const deliver = () => {
207
+ err.write(heldMessage(made.prompt, prefersChinese(env)));
208
+ return 2;
209
+ };
210
+ if (off)
211
+ return deliver();
212
+ const parentGone = deps.parentGone ?? (() => process.ppid === 1);
213
+ for (let i = 0;; i++) {
214
+ const wait = HELD_DELAYS_MS[i] ?? HELD_EVERY_MS;
215
+ if (clock() - asked + wait > HELD_BUDGET_MS)
216
+ return 0;
217
+ await sleep(wait);
218
+ if (parentGone())
219
+ return 0;
220
+ // As for every check: config as it is now, and the session's own list when config cannot be read.
221
+ const now = await readNetworkConfig(resolvePaths(env).configFile);
222
+ if (now && !now.guard)
223
+ return deliver();
224
+ const list = now?.allow ?? allow;
225
+ // Only a new answer that passes hands the message over; `refresh` never throws.
226
+ if (judge((await refresh(common)).entry, list) === 'ok')
227
+ return deliver();
228
+ }
229
+ }
58
230
  const moment = MOMENTS[event];
59
231
  if (!moment)
60
232
  return 0;
233
+ // A prompt the Host made itself is not sent again once blocked: tell `Held` what is decided for it.
234
+ const made = event === 'UserPromptSubmit' ? await hostMadePrompt(deps.input) : undefined;
235
+ const decided = async (d) => {
236
+ if (made)
237
+ await keepDecision(dir, made.id, d, clock());
238
+ };
61
239
  try {
62
240
  const v = await verdict({
63
241
  ...common,
@@ -66,12 +244,16 @@ export async function runNetworkHook(argv, env, err, deps = {}) {
66
244
  ...(deps.sleep ? { sleep: deps.sleep } : {}),
67
245
  background: () => (deps.background ?? startRefresh)(family, env),
68
246
  });
69
- if (v.status === 'ok')
247
+ if (v.status === 'ok') {
248
+ await decided('ok');
70
249
  return 0;
250
+ }
251
+ await decided('blocked');
71
252
  err.write(`${blockMessage(v, allow, { ref: env.SIDEBY_LABEL || env.SIDEBY_ACCOUNT, at: moment, zh: prefersChinese(env) })}\n`);
72
253
  return 2;
73
254
  }
74
255
  catch {
256
+ await decided('blocked');
75
257
  err.write(`${prefersChinese(env)
76
258
  ? '已拦截:sideby 的网络检查出错,没能确认网络出口。重新发送试试;一直出错就运行 `sideby network check`。'
77
259
  : "Blocked: sideby's network check failed and could not tell this network's exit. Try again; if it keeps failing, run `sideby network check`."}\n`);
@@ -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';
@@ -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_@%+=:,./-]+$/;
@@ -2299,6 +2303,17 @@ export function createPanelHandler(opts) {
2299
2303
  return { family, ...(await rt.setQuotaCheck(family, body.on)) };
2300
2304
  },
2301
2305
  },
2306
+ // Progress Reminders on with `every` minutes, or off with null: config `progress` (spec §3.42).
2307
+ '/api/progress': {
2308
+ async run(body) {
2309
+ const every = body.every;
2310
+ if (every !== null && !validEvery(every))
2311
+ throw new HttpError(400, '"every" must be whole minutes from 1 to 240, or null to turn it off');
2312
+ const rt = await getRuntime();
2313
+ const r = await rt.setProgress(validEvery(every) ? every : undefined);
2314
+ return { changed: r.changed, ...(r.after === undefined ? {} : { every: r.after }) };
2315
+ },
2316
+ },
2302
2317
  // The Panel's theme and language (spec §3.29): config `panel.theme` and `panel.language`; null removes one.
2303
2318
  '/api/panel/settings': {
2304
2319
  async run(body) {
@@ -1714,6 +1714,10 @@ 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;
1717
1721
  'ua.pending': string;
1718
1722
  'ua.pendingNote': string;
1719
1723
  'ua.pendingEmpty': string;
@@ -1747,6 +1751,20 @@ declare const en: {
1747
1751
  'ua.problem': string;
1748
1752
  'ua.unreadable': string;
1749
1753
  'ai.ask.unattended': string;
1754
+ 'ai.ask.progress': string;
1755
+ 'pr.title': string;
1756
+ 'pr.hint': string;
1757
+ 'pr.switch': string;
1758
+ 'pr.every': string;
1759
+ 'pr.minutes': string;
1760
+ 'pr.everyLong': string;
1761
+ 'pr.cost': string;
1762
+ 'pr.scope': string;
1763
+ 'pr.codex': string;
1764
+ 'pr.onToast': string;
1765
+ 'pr.everyToast': string;
1766
+ 'pr.offToast': string;
1767
+ 'pr.failed': string;
1750
1768
  };
1751
1769
  export type MessageKey = keyof typeof en;
1752
1770
  export declare const MESSAGES: Record<PanelLang, Record<string, string>>;
@@ -1716,6 +1716,10 @@ 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}',
1719
1723
  'ua.pending': 'Waiting for you',
1720
1724
  'ua.pendingNote': 'Questions sessions did not ask you, steps that needed your OK, and steps they skipped. Nothing here was done.',
1721
1725
  'ua.pendingEmpty': 'Nothing is waiting for you.',
@@ -1749,6 +1753,20 @@ const en = {
1749
1753
  'ua.problem': 'sideby cannot keep its state: {msg}',
1750
1754
  'ua.unreadable': 'sideby could not read Unattended Mode. Refresh to try again.',
1751
1755
  'ai.ask.unattended': 'Run unattended tonight, until 8 tomorrow morning.',
1756
+ 'ai.ask.progress': 'While background tasks run, tell me every 10 minutes what my sessions are waiting for.',
1757
+ 'pr.title': 'Progress updates',
1758
+ 'pr.hint': 'When a Claude session waits on background work (subagents, long commands), it tells you every few minutes what it is waiting for and for how long.',
1759
+ 'pr.switch': 'Report progress while waiting',
1760
+ 'pr.every': 'How often',
1761
+ 'pr.minutes': '{n} min',
1762
+ 'pr.everyLong': 'Every {n} minutes',
1763
+ 'pr.cost': 'Each update is one model turn, which reads the whole conversation, so it uses quota.',
1764
+ '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).',
1765
+ 'pr.codex': 'Codex is not covered: it has no way to wake a waiting session.',
1766
+ 'pr.onToast': 'Progress updates on, every {n} minutes. Claude sessions you start from now on get them.',
1767
+ 'pr.everyToast': 'Progress updates now every {n} minutes.',
1768
+ 'pr.offToast': 'Progress updates off.',
1769
+ 'pr.failed': 'Could not change progress updates: {msg}. It is back as it was; try again, or run sideby progress in a terminal.',
1752
1770
  };
1753
1771
  const zh = {
1754
1772
  'top.tagline': '所有 AI 编程账号,并排运行。',
@@ -3465,6 +3483,10 @@ const zh = {
3465
3483
  'ua.overnight': '次日',
3466
3484
  'ua.allDay': '全天',
3467
3485
  'ua.remove': '删除{slot}',
3486
+ 'ua.here': '照常问你的会话',
3487
+ 'ua.hereNote': '你 30 分钟内在这些会话里打过字,它们照常问你;每发一条消息,那个会话再算 30 分钟。其他会话仍然无人值守。',
3488
+ 'ua.hereHint': '提前回来了?在哪个会话里打字,那个会话 30 分钟内照常问你,其他会话不受影响。',
3489
+ 'ua.hereSession': '会话 {id}',
3468
3490
  'ua.pending': '待你决定',
3469
3491
  'ua.pendingNote': '会话没问你的问题、要你确认的操作和跳过的操作。这里的事都还没做。',
3470
3492
  'ua.pendingEmpty': '没有待你决定的事',
@@ -3498,5 +3520,19 @@ const zh = {
3498
3520
  'ua.problem': 'sideby 没法保存状态:{msg}',
3499
3521
  'ua.unreadable': 'sideby 读不到无人值守的状态。刷新再试一次。',
3500
3522
  'ai.ask.unattended': '今晚无人值守,到明早 8 点',
3523
+ 'ai.ask.progress': '后台任务跑着时,每 10 分钟告诉我会话在等什么。',
3524
+ 'pr.title': '进度提醒',
3525
+ 'pr.hint': 'Claude 会话等后台任务(子任务、长命令)时,每隔几分钟告诉你在等什么、等了多久。',
3526
+ 'pr.switch': '等待时报进度',
3527
+ 'pr.every': '多久一次',
3528
+ 'pr.minutes': '{n} 分钟',
3529
+ 'pr.everyLong': '每 {n} 分钟',
3530
+ 'pr.cost': '每次提醒是一轮模型调用,会读一遍整个对话,会用额度。',
3531
+ 'pr.scope': '打开后启动的 Claude 会话才有;关掉对已经开着的会话也生效。无人值守时不提醒。',
3532
+ 'pr.codex': 'Codex 不支持:它没有办法叫醒等待中的会话。',
3533
+ 'pr.onToast': '已打开进度提醒,每 {n} 分钟一次。之后启动的 Claude 会话会有。',
3534
+ 'pr.everyToast': '进度提醒改为每 {n} 分钟一次。',
3535
+ 'pr.offToast': '已关闭进度提醒。',
3536
+ 'pr.failed': '没能改进度提醒:{msg}。已恢复原样;可以再试一次,或在终端运行 sideby progress。',
3501
3537
  };
3502
3538
  export const MESSAGES = { en, zh };
@@ -6754,6 +6754,28 @@ const MAIN = String.raw `
6754
6754
  h('p', { class: 'muted small' }, t('ua.pendingNote'))), box]
6755
6755
  }
6756
6756
 
6757
+ // ---------- Attended Sessions (ADR-0075) ----------
6758
+ // While it is on: the sessions someone typed into within the last 30 minutes, which ask as usual, each with until
6759
+ // when; with none, one line that says typing in a session is all it takes. Only shown: nothing here sets it.
6760
+ function uaHereBlock(st, p) {
6761
+ if (p.state !== 'on' || st.problem) return []
6762
+ const now = Date.now()
6763
+ const list = (st.attended || []).filter((x) => Date.parse(x.until) > now)
6764
+ if (!list.length) return [h('p', { class: 'note ua-here-hint', 'data-key': 'ua-here-hint', 'data-ua': 'here-hint' }, icon('messages'), t('ua.hereHint'))]
6765
+ return [h('div', { class: 'ua-here', 'data-key': 'ua-here', 'data-ua': 'here', 'data-patch': '' },
6766
+ h('div', { class: 'page-sec-head' },
6767
+ h('h3', { class: 'page-sec' }, t('ua.here'), ' ', h('span', { class: 'tab-count' }, String(list.length))),
6768
+ h('p', { class: 'muted small' }, t('ua.hereNote'))),
6769
+ h('ul', { class: 'ua-here-list', 'data-patch': '' }, list.map((x) => {
6770
+ const folder = x.cwd ? x.cwd.split(/[\\/]/).filter(Boolean).pop() : null
6771
+ return h('li', { class: 'ua-here-row', 'data-key': 'ua-here-' + x.sessionId, 'data-ua': 'here-' + x.sessionId, 'data-patch': '', 'data-tip': t('ua.hereSession', { id: x.sessionId.slice(0, 8) }) },
6772
+ badge(x.family, 'sm'),
6773
+ h('b', null, x.account ? accountLabel(x.account) : family(x.family).title),
6774
+ folder ? h('code', { class: 'ua-cwd' }, folder) : null,
6775
+ h('span', { class: 'ua-when muted' }, uaAt('until', Date.parse(x.until))))
6776
+ })))]
6777
+ }
6778
+
6757
6779
  // ---------- the page ----------
6758
6780
  function uaCoverage(st) {
6759
6781
  const have = new Set(S.state.accounts.map((a) => a.family))
@@ -6836,6 +6858,7 @@ const MAIN = String.raw `
6836
6858
  main))
6837
6859
  if (ua.choosing && p.state !== 'on') kids.push(uaChooser(st))
6838
6860
  if (!st.configured || ua.firstUse) kids.push(h('p', { class: 'note ua-first', 'data-key': 'ua-first', 'data-ua': 'first' }, icon('clock'), t('ua.firstUse')))
6861
+ kids.push(...uaHereBlock(st, p))
6839
6862
  kids.push(...uaScheduleBlock())
6840
6863
  kids.push(...uaPendingBlock(st))
6841
6864
  kids.push(...uaCoverage(st))
@@ -6949,6 +6972,45 @@ const MAIN = String.raw `
6949
6972
  } catch (e) { toast(t('quota.checkFailed', { msg: e.message }), { kind: 'fail' }) }
6950
6973
  load({ silent: true })
6951
6974
  }
6975
+ // Progress Reminders (spec §3.42): on with every minutes, or off with null. The switch moves at once (the state
6976
+ // here first), so the interval row grows in or folds away without waiting for the server; a failure puts it back.
6977
+ async function setProgressEvery(every) {
6978
+ const p = S.state && S.state.progress
6979
+ if (!p) return
6980
+ const was = { on: p.on, every: p.every }
6981
+ S.state.progress = Object.assign({}, p, every === null ? { on: false, every: undefined } : { on: true, every })
6982
+ refreshSettings()
6983
+ try {
6984
+ await api('/api/progress', { every })
6985
+ toast(every === null ? t('pr.offToast') : was.on ? t('pr.everyToast', { n: every }) : t('pr.onToast', { n: every }))
6986
+ } catch (e) {
6987
+ S.state.progress = Object.assign({}, S.state.progress, was)
6988
+ refreshSettings()
6989
+ toast(t('pr.failed', { msg: e.message }), { kind: 'fail' })
6990
+ }
6991
+ load({ silent: true })
6992
+ }
6993
+ // The section's rows: the switch, the interval (it grows in under the switch while on), and three short notes.
6994
+ function progressItems() {
6995
+ const p = S.state.progress
6996
+ const every = p.every || p.defaultEvery
6997
+ const label = t('pr.switch')
6998
+ const seg = (name, opts, cur, pick) => h('div', { class: 'seg', role: 'group', 'aria-label': name, 'data-patch': '' }, opts.map(([v, text]) =>
6999
+ h('button', { class: 'seg-btn', type: 'button', 'aria-pressed': String(v === cur), onclick: () => { if (v !== cur) pick(v) } }, text)))
7000
+ const out = [fm('progress', h('div', { class: 'set-row', 'data-patch': '' },
7001
+ h('span', { class: 'set-label' }, label),
7002
+ BOOT.readOnly ? h('span', { class: 'chip chip-sm' + (p.on ? ' chip-ok' : '') }, p.on ? t('pr.everyLong', { n: every }) : t('ah.off'))
7003
+ : seg(label, [[true, t('ah.on')], [false, t('ah.off')]], p.on, (v) => setProgressEvery(v ? every : null))))]
7004
+ if (!BOOT.readOnly)
7005
+ out.push(h('div', { class: 'reveal' + (p.on ? ' is-open' : ''), 'data-patch': '', 'data-key': 'pr-every', inert: p.on ? undefined : true },
7006
+ h('div', { class: 'reveal-in', 'data-patch': '' }, h('div', { class: 'set-row pr-every', 'data-patch': '' },
7007
+ h('span', { class: 'set-label' }, t('pr.every')),
7008
+ seg(t('pr.every'), p.choices.map((n) => [n, t('pr.minutes', { n })]), p.on ? every : null, (n) => setProgressEvery(n))))))
7009
+ out.push(h('ul', { class: 'pr-notes' }, h('li', null, t('pr.cost')), h('li', null, t('pr.scope')), h('li', null, t('pr.codex'))))
7010
+ if (!BOOT.readOnly && !askBridged(BOOT, window))
7011
+ out.push(h('p', { class: 'small' }, h('button', { class: 'link-btn small', type: 'button', 'data-key': 'pr-ask', onclick: () => openAsk({ text: t('ai.ask.progress') }) }, t('adv.ask'))))
7012
+ return out
7013
+ }
6952
7014
  function famTitleOf(fam) { const f = S.state && S.state.families.find((x) => x.id === fam); return f ? f.title : fam }
6953
7015
  // ---------- settings ----------
6954
7016
  // One header button holds what is set once and rarely changed: language, theme, Remote Control and Auto Handoff.
@@ -6965,6 +7027,7 @@ const MAIN = String.raw `
6965
7027
  if (S.state && ahState()) out.push('ah')
6966
7028
  if (S.state && (S.state.quotaChecks || []).length) out.push('checks')
6967
7029
  if (S.state && S.state.network) out.push('net')
7030
+ if (S.state && S.state.progress) out.push('progress')
6968
7031
  return out
6969
7032
  }
6970
7033
  function renderSettingsButton() {
@@ -7012,7 +7075,8 @@ const MAIN = String.raw `
7012
7075
  function aiLink(leave) {
7013
7076
  return setLink(leave, t('ai.title'), t(skillInstalled() ? 'ai.installed' : 'ai.notInstalled'), skillInstalled() ? 'chip-ok' : '', () => openAsk(), true)
7014
7077
  }
7015
- // The dialog's sections, in order: General, Menu bar, Accounts, Quota checks, Auto Handoff, Let AI help. Each is
7078
+ // The dialog's sections, in order: General, Menu bar, Accounts, Quota checks, Auto Handoff, Progress updates,
7079
+ // Network check, Let AI help. Each is
7016
7080
  // { id, title, items, foot }: foot is the one line that explains the whole section.
7017
7081
  function settingsGroups(leave) {
7018
7082
  const secs = settingsSections()
@@ -7077,6 +7141,7 @@ const MAIN = String.raw `
7077
7141
  { id: 'accounts', title: t('set.g.accounts'), items: acct },
7078
7142
  { id: 'quota', title: t('set.g.quota'), items: checks, foot: t('set.quotaChecksHint', { n: every }) },
7079
7143
  { id: 'handoff', title: t('ah.button'), items: [ahLink(leave)].filter(Boolean), foot: t('set.ahHint') },
7144
+ { id: 'progress', title: t('pr.title'), items: secs.includes('progress') ? progressItems() : [], foot: t('pr.hint') },
7080
7145
  { id: 'network', title: t('net.title'), items: netItems, foot: t('net.hint') },
7081
7146
  { id: 'ai', title: t('set.g.ai'), items: ai, foot: t('set.aiHint') },
7082
7147
  ].filter((g) => g.items.length)
@@ -7777,7 +7842,7 @@ const MAIN = String.raw `
7777
7842
  return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
7778
7843
  }
7779
7844
  // Example phrases: a click puts one in the Let AI do it box (spec §3.28).
7780
- const AI_ASKS = ['ai.ask.quota', 'ai.ask.reset', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.expired', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.advisor', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.commands', 'ai.ask.tool']
7845
+ const AI_ASKS = ['ai.ask.quota', 'ai.ask.reset', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.expired', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.advisor', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.progress', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.commands', 'ai.ask.tool']
7781
7846
  // Network Guard (spec §3.35): one dialog with the switch, the allowed countries and the newest result per address.
7782
7847
  // Countries are never ticked for the user, the current one included: a wrong network would allow itself.
7783
7848
  const NET_COMMON = ['US', 'JP', 'SG', 'GB', 'DE', 'FR', 'NL', 'CA', 'AU', 'KR', 'TW', 'HK']
@@ -977,6 +977,15 @@ ${UI_CSS}
977
977
  .set-foot { margin: -8px 0 4px; color: var(--muted); font-size: 12px; line-height: 1.5; }
978
978
  .set-dialog .set-hint { max-width: none; }
979
979
  .set-dialog .set-link { margin: 0 -12px; width: calc(100% + 20px); }
980
+ /* Progress updates (spec §3.42): the interval grows in under the switch while it is on. Folded, it takes no room: the
981
+ group's gap above it is taken back and given inside instead. */
982
+ .set-group > .reveal[data-key=pr-every] { margin-top: -8px; }
983
+ .reveal[data-key=pr-every] > .reveal-in > .pr-every { padding-top: 8px; }
984
+ .pr-notes { margin: 4px 0 0; padding-left: 16px; display: grid; gap: 4px; color: var(--muted); font-size: 12px; line-height: 1.5; }
985
+ .pr-every .seg-btn { white-space: nowrap; }
986
+ :where(:root[data-width=phone]) .pr-every { flex-direction: column; align-items: flex-start; gap: 8px; }
987
+ :where(:root[data-width=phone]) .pr-every .seg { max-width: 100%; }
988
+ :where(:root[data-width=phone]) .pr-every .seg-btn { padding: 0 8px; }
980
989
  :where(:root[data-width=narrow], :root[data-width=phone]) {
981
990
  .set-dialog { grid-template-columns: minmax(0, 1fr); gap: 16px; min-height: 0; }
982
991
  .set-nav { flex-direction: row; overflow-x: auto; padding: 0 0 8px; border-right: 0; border-bottom: 1px solid var(--border); }
@@ -1454,6 +1463,11 @@ input.ua-time::placeholder { color: var(--faint); }
1454
1463
  .ua-item-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: flex-start; gap: 12px; }
1455
1464
  .ua-cover { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
1456
1465
  .ua-cover li::before { content: "·"; margin-right: 8px; color: var(--faint); }
1466
+ .ua-here-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); }
1467
+ .ua-here-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
1468
+ .ua-here-row:first-child { border-top: 0; }
1469
+ .ua-here-hint { gap: 8px; margin-top: 12px; }
1470
+ .ua-here-hint .ic { width: 15px; height: 15px; flex: none; }
1457
1471
  :where(:root[data-width=narrow], :root[data-width=phone]) .ua-item { grid-template-columns: minmax(0, 1fr); }
1458
1472
  :where(:root[data-width=narrow], :root[data-width=phone]) .ua-item-actions { grid-column: 1; grid-row: auto; }
1459
1473
  :where(:root[data-width=phone]) .ua-del { margin-left: 0; }
@@ -0,0 +1,50 @@
1
+ type Env = Record<string, string | undefined>;
2
+ /** How often a watch looks whether it is still wanted. */
3
+ export declare const CHECK_EVERY_MS = 60000;
4
+ /** A watch ends by itself after this long, under the five-hour `timeout` Claude Code gives the hook. */
5
+ export declare const WATCH_FOR_MS: number;
6
+ export interface ProgressHookDeps {
7
+ now?: () => Date;
8
+ sleep?: (ms: number) => Promise<void>;
9
+ /** Whether the Host that started the hook is gone; by default, whether this process's parent changed. */
10
+ parentGone?: () => boolean;
11
+ /** This watch's id; random by default. */
12
+ id?: string;
13
+ checkEveryMs?: number;
14
+ /** How long a write waits for the session's lock (for tests). */
15
+ lockWait?: {
16
+ timeoutMs: number;
17
+ pollMs: number;
18
+ };
19
+ /** Runs between the last check of the watch record and marking it woken, inside the lock (for tests). */
20
+ beforeWake?: () => Promise<void>;
21
+ }
22
+ type Input = AsyncIterable<string | Uint8Array> | string;
23
+ /** The background tasks as the reminder names them: kind and description, never the command. */
24
+ export declare function taskList(tasks: readonly unknown[]): string;
25
+ /**
26
+ * What the model is woken with. It starts with `PROGRESS_MARK`, names the clock time the wait began (so a reminder
27
+ * Network Guard held and delivered late still makes sense), and asks for one or two sentences and the end of the turn.
28
+ */
29
+ export declare function reminderMessage(o: {
30
+ tasks: readonly unknown[];
31
+ since: string;
32
+ now: Date;
33
+ every: number;
34
+ }): string;
35
+ /**
36
+ * The `Stop` watch (spec §3.42). Replaces the session's earlier watch first, then, while background work runs and the
37
+ * setting is on, wakes the session every `progress.every` minutes with a reminder (exit 2). Ends with exit 0 when a
38
+ * later `Stop` took over, the session's latest prompt is not the one this `Stop` ended, the parent is gone, the
39
+ * setting is off, Auto Handoff is handing over, or time runs out. While the session is unattended a reminder is skipped and the wait starts again.
40
+ */
41
+ export declare function watchWhileWaiting(input: Record<string, unknown>, env: Env, deps?: ProgressHookDeps): Promise<{
42
+ exit: 0 | 2;
43
+ message?: string;
44
+ }>;
45
+ export declare function runProgressHook(argv: readonly string[], env: Env, input: Input, io: {
46
+ err: {
47
+ write(s: string): unknown;
48
+ };
49
+ }, deps?: ProgressHookDeps): Promise<number>;
50
+ export {};