sideby 0.28.2 → 0.29.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 +2 -0
  3. package/dist/src/cli/commands.js +34 -7
  4. package/dist/src/cli/json-schemas.js +15 -0
  5. package/dist/src/cli/main.js +1 -1
  6. package/dist/src/core/handoff-chain.d.ts +2 -0
  7. package/dist/src/core/handoff-chain.js +4 -2
  8. package/dist/src/core/handoff-doctor.d.ts +8 -3
  9. package/dist/src/core/handoff-doctor.js +9 -1
  10. package/dist/src/core/handoff-enable.d.ts +2 -0
  11. package/dist/src/core/handoff-enable.js +7 -1
  12. package/dist/src/core/handoff-status.js +4 -1
  13. package/dist/src/core/live-sessions.d.ts +2 -0
  14. package/dist/src/core/messages.d.ts +2 -0
  15. package/dist/src/core/messages.js +3 -3
  16. package/dist/src/core/run-link.d.ts +6 -1
  17. package/dist/src/core/run-link.js +62 -22
  18. package/dist/src/core/session-handoffs.d.ts +22 -0
  19. package/dist/src/core/session-handoffs.js +110 -0
  20. package/dist/src/core/session-select.d.ts +18 -3
  21. package/dist/src/core/session-select.js +82 -8
  22. package/dist/src/families/claude/handoff.js +10 -1
  23. package/dist/src/families/claude/quota.js +3 -2
  24. package/dist/src/handoff/hook.d.ts +28 -1
  25. package/dist/src/handoff/hook.js +83 -5
  26. package/dist/src/handoff/messages.d.ts +5 -0
  27. package/dist/src/handoff/messages.js +7 -0
  28. package/dist/src/panel/handler.js +3 -1
  29. package/dist/src/panel/i18n.d.ts +3 -0
  30. package/dist/src/panel/i18n.js +6 -0
  31. package/dist/src/panel/page-script.js +10 -5
  32. package/dist/src/quota/claude-statusline.d.ts +5 -0
  33. package/dist/src/quota/claude-statusline.js +61 -7
  34. package/dist/src/runtime.js +2 -2
  35. package/dist/src/types.d.ts +10 -2
  36. package/package.json +4 -3
  37. package/schemas/handoff-setup.json +4 -0
  38. package/schemas/messages.json +4 -0
  39. package/schemas/quota-setup.json +4 -0
  40. package/schemas/send.json +4 -0
  41. package/schemas/sessions-copy.json +4 -0
  42. package/schemas/sessions-open-run.json +4 -0
  43. package/schemas/sessions.json +7 -0
  44. package/skills/sideby/SKILL.md +2 -2
  45. package/skills/sideby/references/handoff.md +1 -1
  46. package/skills/sideby/references/quota.md +2 -0
  47. package/skills/sideby/references/sessions.md +1 -1
@@ -1,11 +1,22 @@
1
1
  import type { Runtime } from '../runtime.ts';
2
2
  import { type LiveSession, type LiveSessionsResult } from './live-sessions.ts';
3
3
  import type { LiveSessionDeps } from './live-sessions-procs.ts';
4
+ import { type HandoffChain } from './session-handoffs.ts';
4
5
  /** How the candidates are offered when a target names several Sessions. */
5
6
  export interface SessionNext {
6
7
  verb: string;
7
8
  command: (id: string) => string;
8
9
  }
10
+ /** The Session picked, and the original id when an Auto Handoff chain led from it to this Session (ADR-0057). */
11
+ export interface PickedSession {
12
+ session: LiveSession;
13
+ handedOverFrom?: string;
14
+ }
15
+ export interface Handoffs {
16
+ chains: readonly HandoffChain[];
17
+ /** The Account label of a session id that no longer runs, when the Host still has its record. */
18
+ accountOf?: (sessionId: string) => string | undefined;
19
+ }
9
20
  /**
10
21
  * The one Session `target` names: a session id (or its first 8 or more characters), else an Account whose single
11
22
  * Live Session it is. Several Sessions, or none, are a UserError that says what to run next.
@@ -15,11 +26,14 @@ export declare function pickSession(target: string, sessions: readonly LiveSessi
15
26
  label: string;
16
27
  } | undefined,
17
28
  /** How the candidates are offered; `sessions copy` when left out. */
18
- next?: SessionNext): LiveSession;
29
+ next?: SessionNext,
30
+ /** The Handoff chains, and the Account label of a session id whose record the Host still has. */
31
+ handoffs?: Handoffs): PickedSession;
19
32
  /**
20
33
  * Lists the Live Sessions and picks the one `target` names, reading `target` as an Account (ref or alias) when it is
21
- * one. `onListed` sees the listing before the pick, so its problems can be shown also when the pick fails; the
22
- * listing is returned too, for callers that look for the sending Session in it.
34
+ * one, and following a Handoff chain when it is a session id that no longer runs (ADR-0057). `onListed` sees the
35
+ * listing before the pick, so its problems can be shown also when the pick fails; the listing is returned too, for
36
+ * callers that look for the sending Session in it. Its Sessions carry `handedOverFrom` where a chain led to them.
23
37
  */
24
38
  export declare function selectSession(rt: Runtime, target: string, opts?: {
25
39
  next?: SessionNext;
@@ -28,4 +42,5 @@ export declare function selectSession(rt: Runtime, target: string, opts?: {
28
42
  }): Promise<{
29
43
  session: LiveSession;
30
44
  listed: LiveSessionsResult;
45
+ handedOverFrom?: string;
31
46
  }>;
@@ -1,20 +1,56 @@
1
1
  import { UserError } from './errors.js';
2
- import { listLiveSessions, shortId } from './live-sessions.js';
2
+ import { accountLabels, listLiveSessions, shortId, } from './live-sessions.js';
3
+ import { chainIdsMatching, laterHops, readHandoffChains, withHandoffs, } from './session-handoffs.js';
3
4
  const COPY = { verb: 'copy', command: (id) => `sideby sessions copy ${id}` };
5
+ /** The one session id of a Handoff chain `target` names, when it names exactly one and a later hop exists. */
6
+ function handedOverId(target, chains, next) {
7
+ const ids = chainIdsMatching(chains, target);
8
+ if (ids.length > 1) {
9
+ const rows = ids.map((id) => ` ${next.command(id)}`).join('\n');
10
+ throw new UserError(`${target} matches ${ids.length} sessions that were handed over; ${next.verb} one by its full id:\n${rows}`, { code: 'several-sessions' });
11
+ }
12
+ const id = ids[0];
13
+ return id && laterHops(chains, id).length ? id : undefined;
14
+ }
15
+ /**
16
+ * Follows a session id an Auto Handoff chain passed on: the newest later hop that is a Live Session. Undefined when
17
+ * the id is in no chain or is its last hop; a UserError naming the last hop when no later hop still runs.
18
+ */
19
+ function followHandoff(target, sessions, next, handoffs) {
20
+ const from = handedOverId(target, handoffs.chains, next);
21
+ if (!from)
22
+ return undefined;
23
+ const later = laterHops(handoffs.chains, from);
24
+ for (const id of later) {
25
+ const live = sessions.find((s) => s.sessionId === id);
26
+ if (live)
27
+ return { session: live, handedOverFrom: from };
28
+ }
29
+ const last = later[0];
30
+ const account = handoffs.accountOf?.(last);
31
+ throw new UserError(`${shortId(from)} was handed over to session ${last}${account ? ` of ${account}` : ''}, which is not running now; run \`sideby sessions\` to see the running sessions`, { code: 'no-session' });
32
+ }
4
33
  /**
5
34
  * The one Session `target` names: a session id (or its first 8 or more characters), else an Account whose single
6
35
  * Live Session it is. Several Sessions, or none, are a UserError that says what to run next.
7
36
  */
8
37
  export function pickSession(target, sessions, account,
9
38
  /** How the candidates are offered; `sessions copy` when left out. */
10
- next = COPY) {
39
+ next = COPY,
40
+ /** The Handoff chains, and the Account label of a session id whose record the Host still has. */
41
+ handoffs = { chains: [] }) {
11
42
  const byId = sessions.filter((s) => s.sessionId === target || (target.length >= 8 && s.sessionId.startsWith(target)));
12
43
  if (byId.length === 1)
13
- return byId[0];
44
+ return { session: byId[0] };
14
45
  const list = byId.length ? byId : account ? sessions.filter((s) => s.account === account.ref) : [];
15
46
  if (list.length === 1)
16
- return list[0];
47
+ return { session: list[0] };
17
48
  if (!list.length) {
49
+ if (!account) {
50
+ const followed = followHandoff(target, sessions, next, handoffs);
51
+ if (followed)
52
+ return followed;
53
+ }
18
54
  if (account)
19
55
  throw new UserError(`${account.label} has no running session now; start one with \`sideby run ${account.label}\`, or run \`sideby sessions\` to see the others`, { code: 'no-session' });
20
56
  throw new UserError(`no running session or account named ${target}; run \`sideby sessions\` to see the running sessions`, { code: 'no-session' });
@@ -27,11 +63,14 @@ next = COPY) {
27
63
  }
28
64
  /**
29
65
  * Lists the Live Sessions and picks the one `target` names, reading `target` as an Account (ref or alias) when it is
30
- * one. `onListed` sees the listing before the pick, so its problems can be shown also when the pick fails; the
31
- * listing is returned too, for callers that look for the sending Session in it.
66
+ * one, and following a Handoff chain when it is a session id that no longer runs (ADR-0057). `onListed` sees the
67
+ * listing before the pick, so its problems can be shown also when the pick fails; the listing is returned too, for
68
+ * callers that look for the sending Session in it. Its Sessions carry `handedOverFrom` where a chain led to them.
32
69
  */
33
70
  export async function selectSession(rt, target, opts = {}) {
34
- const listed = await listLiveSessions(rt, {}, opts.deps);
71
+ const raw = await listLiveSessions(rt, {}, opts.deps);
72
+ const chains = await readHandoffChains(rt.paths.stateDir);
73
+ const listed = { ...raw, sessions: withHandoffs(chains, raw.sessions) };
35
74
  opts.onListed?.(listed);
36
75
  let account;
37
76
  try {
@@ -40,5 +79,40 @@ export async function selectSession(rt, target, opts = {}) {
40
79
  catch {
41
80
  // not an Account: a session id
42
81
  }
43
- return { session: pickSession(target, listed.sessions, account, opts.next), listed };
82
+ const handoffs = { chains };
83
+ if (!account) {
84
+ // Only when the pick would end at a chain whose later hops all ended: which Account still has the last one.
85
+ const last = endedLastHop(target, listed.sessions, chains);
86
+ if (last) {
87
+ const label = await recordAccount(rt, last);
88
+ handoffs.accountOf = (id) => (id === last ? label : undefined);
89
+ }
90
+ }
91
+ const picked = pickSession(target, listed.sessions, account, opts.next, handoffs);
92
+ return { ...picked, listed };
93
+ }
94
+ /** The last hop of the chain `target` names, when neither `target` nor any later hop is a Live Session. */
95
+ function endedLastHop(target, sessions, chains) {
96
+ if (sessions.some((s) => s.sessionId === target || (target.length >= 8 && s.sessionId.startsWith(target))))
97
+ return undefined;
98
+ const ids = chainIdsMatching(chains, target);
99
+ if (ids.length !== 1)
100
+ return undefined;
101
+ const later = laterHops(chains, ids[0]);
102
+ if (!later.length || later.some((id) => sessions.some((s) => s.sessionId === id)))
103
+ return undefined;
104
+ return later[0];
105
+ }
106
+ /** The label of the Account whose Host last wrote (else last started) session `id`; undefined when none did. */
107
+ async function recordAccount(rt, id) {
108
+ const accounts = await rt.accounts();
109
+ let best;
110
+ for (const a of accounts) {
111
+ const family = rt.families.get(a.family);
112
+ const at = (await family?.sessionWrittenAt?.(a, id).catch(() => undefined)) ??
113
+ (await family?.sessionStartedAt?.(a, id).catch(() => undefined));
114
+ if (at !== undefined && (!best || at > best.at))
115
+ best = { ref: a.ref, at };
116
+ }
117
+ return best && (accountLabels(rt, accounts).get(best.ref) ?? best.ref);
44
118
  }
@@ -88,7 +88,16 @@ export const claudeHandoff = {
88
88
  hooks: {
89
89
  SessionStart: hook('SessionStart'),
90
90
  PostToolUse: hook('PostToolUse'),
91
- Stop: hook('Stop'),
91
+ // The second Stop hook runs in the background (`asyncRewake`): while the session waits on background work it
92
+ // watches the Quota and wakes the session at the hand-over level (ADR-0056). 18000 s: five hours.
93
+ Stop: [
94
+ {
95
+ hooks: [
96
+ { type: 'command', command: command('Stop') },
97
+ { type: 'command', command: command('IdleWatch'), asyncRewake: true, timeout: 18000 },
98
+ ],
99
+ },
100
+ ],
92
101
  StopFailure: [
93
102
  { matcher: 'rate_limit', hooks: [{ type: 'command', command: command('StopFailure') }] },
94
103
  ],
@@ -30,8 +30,9 @@ async function withoutCache(account, ctx) {
30
30
  reason: 'not-enabled',
31
31
  detail: "this account's settings.json is not shared with the main account, so its quota needs its own status line setup",
32
32
  };
33
- const planStatus = await claudeStatusline.plan(ctx).then((p) => p.status, () => 'blocked');
34
- if (wiring === 'shared' && planStatus !== 'enabled')
33
+ // A plan that only adds the refresh (ADR-0056) means the wrapper is already on.
34
+ const on = await claudeStatusline.plan(ctx).then((p) => p.status === 'enabled' || (p.status === 'ready' && p.upgrade === true), () => false);
35
+ if (wiring === 'shared' && !on)
35
36
  return {
36
37
  status: 'unavailable',
37
38
  reason: 'not-enabled',
@@ -3,6 +3,9 @@ import { type HookInput } from './reader.ts';
3
3
  export declare const HOOK_COMMAND = "sideby handoff-hook";
4
4
  /** Families whose hooks this entry understands; only they can start a Handoff. */
5
5
  export declare const HOOK_FAMILIES: readonly string[];
6
+ /** How often `IdleWatch` reads the Quota, and how long it watches at most: under its five-hour hook timeout. */
7
+ export declare const WATCH_EVERY_MS = 15000;
8
+ export declare const WATCH_FOR_MS: number;
6
9
  /** What one hook call decided: output for the Host, and files to write. Separate from I/O for the tests. */
7
10
  export declare function decide(opts: {
8
11
  family: string;
@@ -13,4 +16,28 @@ export declare function decide(opts: {
13
16
  }): Promise<{
14
17
  output?: unknown;
15
18
  }>;
16
- export declare function runHandoffHook(argv: readonly string[], env: Env, stdin: AsyncIterable<Uint8Array | string>, stdout: NodeJS.WritableStream): Promise<number>;
19
+ export interface IdleWatchOptions {
20
+ family: string;
21
+ input: HookInput;
22
+ env: Env;
23
+ /** Replaced in tests; the defaults are the clock, a real wait, and whether the parent is gone (`ppid` 1). */
24
+ clock?: () => Date;
25
+ sleep?: (ms: number) => Promise<void>;
26
+ parentGone?: () => boolean;
27
+ everyMs?: number;
28
+ forMs?: number;
29
+ /** This watch's id in `watch-<run>.json`; random by default. */
30
+ id?: string;
31
+ }
32
+ /**
33
+ * Claude's background `Stop` hook (spec §3.17 "主会话等后台任务时", ADR-0056). While the session waits on background
34
+ * work, reads the Quota every 15 s; when a window reaches its Hand-over Level under a `pick` plan, marks the threshold
35
+ * as sent and returns the message with exit 2, which wakes the session. Ends with exit 0 when a later `Stop` starts a
36
+ * new watch, the run is over or handing over, the session handled the threshold itself, the parent is gone, or time
37
+ * runs out. A `wait` or `none` plan never wakes the session.
38
+ */
39
+ export declare function idleWatch(o: IdleWatchOptions): Promise<{
40
+ exit: 0 | 2;
41
+ message?: string;
42
+ }>;
43
+ export declare function runHandoffHook(argv: readonly string[], env: Env, stdin: AsyncIterable<Uint8Array | string>, stdout: NodeJS.WritableStream, stderr?: NodeJS.WritableStream, watch?: Partial<IdleWatchOptions>): Promise<number>;
@@ -1,6 +1,8 @@
1
1
  // Entry for `sideby handoff-hook <family> <event>` (spec §3.17). A Host runs it on PostToolUse, Stop and
2
- // StopFailure, so it imports only Node built-ins and leaf modules: never the Runtime, a Family index or
3
- // core/accounts.ts. It never fails the Host: any problem means no output and exit 0.
2
+ // StopFailure, and Claude also runs `IdleWatch` in the background after a Stop (ADR-0056), so it imports only Node
3
+ // built-ins and leaf modules: never the Runtime, a Family index or core/accounts.ts. It never fails the Host: any
4
+ // problem means no output and exit 0.
5
+ import { randomBytes } from 'node:crypto';
4
6
  import { readFile, rm, stat } from 'node:fs/promises';
5
7
  import { join } from 'node:path';
6
8
  import { BRIEF_DONE, FILES, HANDOFF_ENV, readJsonFile, writeJsonFile, } from '../core/handoff-chain.js';
@@ -8,7 +10,7 @@ import { claudeHookReader } from '../families/claude/handoff-hook.js';
8
10
  import { codexHookReader } from '../families/codex/handoff-hook.js';
9
11
  import { grokHookReader } from '../families/grok/handoff-hook.js';
10
12
  import { crossedWindow, firstMark, fullestWindow, recordTurn } from './levels.js';
11
- import { endTurnMessage, notifySequence, prepareMessage, sessionStartMessage, stopMessage, thresholdMessage, waitNotice, } from './messages.js';
13
+ import { endTurnMessage, idleThresholdMessage, notifySequence, prepareMessage, sessionStartMessage, stopMessage, thresholdMessage, waitNotice, } from './messages.js';
12
14
  import { field } from './reader.js';
13
15
  export const HOOK_COMMAND = 'sideby handoff-hook';
14
16
  const READERS = {
@@ -18,7 +20,10 @@ const READERS = {
18
20
  };
19
21
  /** Families whose hooks this entry understands; only they can start a Handoff. */
20
22
  export const HOOK_FAMILIES = Object.keys(READERS);
21
- const EVENTS = new Set(['SessionStart', 'PostToolUse', 'Stop', 'StopFailure']);
23
+ const EVENTS = new Set(['SessionStart', 'PostToolUse', 'Stop', 'StopFailure', 'IdleWatch']);
24
+ /** How often `IdleWatch` reads the Quota, and how long it watches at most: under its five-hour hook timeout. */
25
+ export const WATCH_EVERY_MS = 15_000;
26
+ export const WATCH_FOR_MS = (4 * 60 + 55) * 60_000;
22
27
  async function readAll(stream) {
23
28
  const chunks = [];
24
29
  try {
@@ -54,6 +59,12 @@ export async function decide(opts) {
54
59
  // Not a run sideby started for a Handoff, or another Family's hook (Grok also runs Claude's settings hooks).
55
60
  if (!runId || !dir || env[HANDOFF_ENV.family] !== family || !reader)
56
61
  return {};
62
+ // `IdleWatch` has its own entry; a `PostToolUse` inside a subagent or teammate (`agent_id`) would speak to that agent,
63
+ // not the main conversation, so it says nothing and marks nothing sent (ADR-0056).
64
+ if (event === 'IdleWatch')
65
+ return {};
66
+ if (event === 'PostToolUse' && field(input, 'agent_id', 'agentId'))
67
+ return {};
57
68
  const plan = await readJsonFile(join(dir, FILES.plan));
58
69
  const usable = plan && plan.runId === runId ? plan : null;
59
70
  const runFile = join(dir, FILES.run(runId));
@@ -176,7 +187,65 @@ export async function decide(opts) {
176
187
  }
177
188
  return {};
178
189
  }
179
- export async function runHandoffHook(argv, env, stdin, stdout) {
190
+ /**
191
+ * Claude's background `Stop` hook (spec §3.17 "主会话等后台任务时", ADR-0056). While the session waits on background
192
+ * work, reads the Quota every 15 s; when a window reaches its Hand-over Level under a `pick` plan, marks the threshold
193
+ * as sent and returns the message with exit 2, which wakes the session. Ends with exit 0 when a later `Stop` starts a
194
+ * new watch, the run is over or handing over, the session handled the threshold itself, the parent is gone, or time
195
+ * runs out. A `wait` or `none` plan never wakes the session.
196
+ */
197
+ export async function idleWatch(o) {
198
+ const { family, input, env } = o;
199
+ const runId = env[HANDOFF_ENV.run];
200
+ const dir = env[HANDOFF_ENV.dir];
201
+ const reader = READERS[family];
202
+ // Only Claude Code can wake an idle session from a hook.
203
+ if (family !== 'claude' || !runId || !dir || env[HANDOFF_ENV.family] !== family || !reader?.windows)
204
+ return { exit: 0 };
205
+ const clock = o.clock ?? (() => new Date());
206
+ const sleep = o.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
207
+ const parentGone = o.parentGone ?? (() => process.ppid === 1);
208
+ const id = o.id ?? randomBytes(8).toString('hex');
209
+ const watchFile = join(dir, FILES.watch(runId));
210
+ const runFile = join(dir, FILES.run(runId));
211
+ // Written first, so a watch left by an earlier Stop ends even when this one has nothing to watch.
212
+ await writeJsonFile(watchFile, { id });
213
+ const tasks = input.background_tasks ?? input.backgroundTasks;
214
+ if (!Array.isArray(tasks) || tasks.length === 0)
215
+ return { exit: 0 };
216
+ const start = clock().getTime();
217
+ for (;;) {
218
+ // The Stop that started this watch judged the Quota itself; the first reading comes one interval later.
219
+ await sleep(o.everyMs ?? WATCH_EVERY_MS);
220
+ const now = clock();
221
+ if (now.getTime() - start >= (o.forMs ?? WATCH_FOR_MS) || parentGone())
222
+ return { exit: 0 };
223
+ if ((await readJsonFile(watchFile))?.id !== id)
224
+ return { exit: 0 };
225
+ const plan = await readJsonFile(join(dir, FILES.plan));
226
+ if (!plan || plan.runId !== runId)
227
+ return { exit: 0 };
228
+ if (await readJsonFile(join(dir, FILES.ready)))
229
+ return { exit: 0 };
230
+ const state = (await readJsonFile(runFile)) ?? {};
231
+ if (state.thresholdSentAt)
232
+ return { exit: 0 };
233
+ if (plan.decision !== 'pick')
234
+ continue;
235
+ const windows = await reader.windows(input, env, now);
236
+ const crossed = windows ? crossedWindow(windows, plan, state) : undefined;
237
+ if (!crossed)
238
+ continue;
239
+ // Read again just before marking, so a turn that handled the threshold meanwhile is neither repeated nor undone.
240
+ const fresh = (await readJsonFile(runFile)) ?? {};
241
+ if (fresh.thresholdSentAt)
242
+ return { exit: 0 };
243
+ await writeJsonFile(runFile, { ...fresh, thresholdSentAt: now.toISOString(), thresholdWindow: crossed });
244
+ const message = plan.agentBrief === false ? endTurnMessage(crossed) : idleThresholdMessage(plan.brief, crossed);
245
+ return { exit: 2, message };
246
+ }
247
+ }
248
+ export async function runHandoffHook(argv, env, stdin, stdout, stderr = process.stderr, watch = {}) {
180
249
  // `sideby run` asks this first, so an older sideby on PATH without the hook entry is caught before any hook runs.
181
250
  if (argv[0] === '--check') {
182
251
  stdout.write('ok\n');
@@ -195,6 +264,15 @@ export async function runHandoffHook(argv, env, stdin, stdout) {
195
264
  }
196
265
  if (input === null || typeof input !== 'object' || Array.isArray(input))
197
266
  return 0;
267
+ if (event === 'IdleWatch') {
268
+ const w = await idleWatch({ ...watch, family, input: input, env });
269
+ // Exit 2 wakes the session (asyncRewake), which shows stderr to the model.
270
+ if (w.exit === 2 && w.message) {
271
+ stderr.write(`${w.message}\n`);
272
+ return 2;
273
+ }
274
+ return 0;
275
+ }
198
276
  const r = await decide({
199
277
  family,
200
278
  event: event,
@@ -3,6 +3,11 @@ import { type WindowReading } from '../core/handoff-chain.ts';
3
3
  export declare function windowText(w: WindowReading): string;
4
4
  export declare function prepareMessage(brief: string, window: WindowReading): string;
5
5
  export declare function thresholdMessage(brief: string, window: WindowReading): string;
6
+ /**
7
+ * At the threshold while the session waits on background work (ADR-0056): sideby woke it, so it says who is speaking,
8
+ * and the Brief must carry the background tasks, which stop when sideby ends the session.
9
+ */
10
+ export declare function idleThresholdMessage(brief: string, window: WindowReading): string;
6
11
  /** At the threshold when the session cannot write a Brief: sideby puts one together from its records. */
7
12
  export declare function endTurnMessage(window: WindowReading): string;
8
13
  export declare function stopMessage(brief: string): string;
@@ -27,6 +27,13 @@ export function prepareMessage(brief, window) {
27
27
  export function thresholdMessage(brief, window) {
28
28
  return `sideby: this account's ${windowText(window)}. Finish the current step, update the handoff brief at ${brief} (${TEMPLATE}; ${RULES}), then end your turn. sideby will start the next account from that brief.`;
29
29
  }
30
+ /**
31
+ * At the threshold while the session waits on background work (ADR-0056): sideby woke it, so it says who is speaking,
32
+ * and the Brief must carry the background tasks, which stop when sideby ends the session.
33
+ */
34
+ export function idleThresholdMessage(brief, window) {
35
+ return `sideby: this is sideby Auto Handoff, set up when this session started. While you wait on background work, this account's ${windowText(window)}. Update the handoff brief at ${brief} (${TEMPLATE}; also name each background task still running, what it is doing and where its work lives: they stop when sideby ends this session, so the next account has to pick them up; ${RULES}). Start no new background work, then end your turn. sideby will start the next account from that brief.`;
36
+ }
30
37
  /** At the threshold when the session cannot write a Brief: sideby puts one together from its records. */
31
38
  export function endTurnMessage(window) {
32
39
  return `sideby: this account's ${windowText(window)}. Finish the current step and end your turn; sideby will start the next account and tell it what you did.`;
@@ -25,6 +25,7 @@ import { tildify } from '../core/paths.js';
25
25
  import { remoteControlTodo } from '../core/remote-control.js';
26
26
  import { openRunBoard, withRuns } from '../core/run-link.js';
27
27
  import { SECRET_VAR_NAME, secretVarFor, setSecret } from '../core/secret-file.js';
28
+ import { readHandoffChains, withHandoffs } from '../core/session-handoffs.js';
28
29
  import { SKILL_INSTALL } from '../core/skill-check.js';
29
30
  import { launchArgs, TERMINALS } from '../core/terminal.js';
30
31
  import { checkThemeData, listThemes, NO_THEME, previewColors, removeThemeFile, resolveColors, saveThemeFile, undoTheme, useTheme, } from '../core/themes.js';
@@ -1330,7 +1331,8 @@ export function createPanelHandler(opts) {
1330
1331
  const home = rt.paths.home;
1331
1332
  // The Run each Session works for, only where the Session Index and its board file check out (ADR-0041).
1332
1333
  const [sessions, tabs] = await Promise.all([
1333
- withRuns(rt.env, home, listed.sessions),
1334
+ // A Session an Auto Handoff chain led to stays linked to its Run under the earlier ids (ADR-0057).
1335
+ readHandoffChains(rt.paths.stateDir).then((chains) => withRuns(rt.env, home, withHandoffs(chains, listed.sessions))),
1334
1336
  orcaTabs(orcaOf(rt), listed.sessions),
1335
1337
  ]);
1336
1338
  const problems = listed.problems;
@@ -121,6 +121,7 @@ declare const en: {
121
121
  'toast.created': string;
122
122
  'toast.createdProblems': string;
123
123
  'toast.quotaOn': string;
124
+ 'toast.quotaUpdated': string;
124
125
  'toast.quotaOff': string;
125
126
  'toast.undo': string;
126
127
  'toast.undoFailed': string;
@@ -830,6 +831,7 @@ declare const en: {
830
831
  'hp.willDo': string;
831
832
  'hp.step.config': string;
832
833
  'hp.step.quota': string;
834
+ 'hp.step.quotaRefresh': string;
833
835
  'hp.step.hook': string;
834
836
  'hp.step.copy': string;
835
837
  'hp.showChange': string;
@@ -1261,6 +1263,7 @@ declare const en: {
1261
1263
  'toast.ahOn': string;
1262
1264
  'toast.ahOff': string;
1263
1265
  'qs.title': string;
1266
+ 'qs.titleUpdate': string;
1264
1267
  'qs.preparing': string;
1265
1268
  'qs.changes': string;
1266
1269
  'qs.undoHint': string;
@@ -123,6 +123,7 @@ const en = {
123
123
  'toast.created': 'Created {ref}',
124
124
  'toast.createdProblems': 'Created {ref} with problems',
125
125
  'toast.quotaOn': '{host} quota display is on',
126
+ 'toast.quotaUpdated': '{host} quota now stays current while a session waits',
126
127
  'toast.quotaOff': '{host} quota display is off again; the settings file is restored',
127
128
  'toast.undo': 'Undo',
128
129
  'toast.undoFailed': 'Could not undo: {msg}',
@@ -832,6 +833,7 @@ const en = {
832
833
  'hp.willDo': 'To turn it on, sideby will:',
833
834
  'hp.step.config': 'Switch Auto Handoff on in sideby’s settings',
834
835
  'hp.step.quota': 'Show {host} quota (Auto Handoff needs it to track usage)',
836
+ 'hp.step.quotaRefresh': 'Keep {host} quota current while a session waits on background agents',
835
837
  'hp.step.hook': 'Add sideby’s handoff hook to {host}',
836
838
  'hp.step.copy': 'Copy the hook file into your other {host} accounts ({accounts}); nothing else in them changes',
837
839
  'hp.showChange': 'Show the change',
@@ -1263,6 +1265,7 @@ const en = {
1263
1265
  'toast.ahOn': 'Auto Handoff is on for sessions you start with sideby.',
1264
1266
  'toast.ahOff': 'Auto Handoff is off.',
1265
1267
  'qs.title': 'Turn on {host} quota',
1268
+ 'qs.titleUpdate': 'Update {host} quota display',
1266
1269
  'qs.preparing': 'Preparing the change…',
1267
1270
  'qs.changes': 'This changes {file}:',
1268
1271
  'qs.undoHint': 'You can undo it right after, or later with sideby quota teardown.',
@@ -1598,6 +1601,7 @@ const zh = {
1598
1601
  'toast.created': '已创建 {ref}',
1599
1602
  'toast.createdProblems': '已创建 {ref},但有问题',
1600
1603
  'toast.quotaOn': '已开启 {host} 额度显示',
1604
+ 'toast.quotaUpdated': '{host} 的额度在会话等待时也会保持更新',
1601
1605
  'toast.quotaOff': '已关闭 {host} 额度显示,设置文件已还原',
1602
1606
  'toast.undo': '撤销',
1603
1607
  'toast.undoFailed': '撤销失败:{msg}',
@@ -2307,6 +2311,7 @@ const zh = {
2307
2311
  'hp.willDo': '开启时 sideby 会:',
2308
2312
  'hp.step.config': '在 sideby 的设置里打开自动接力',
2309
2313
  'hp.step.quota': '打开 {host} 的额度显示(自动接力需要查看当前用量)',
2314
+ 'hp.step.quotaRefresh': '让 {host} 的额度在会话等后台任务时也保持更新',
2310
2315
  'hp.step.hook': '给 {host} 装上 sideby 的接力钩子',
2311
2316
  'hp.step.copy': '把钩子文件复制到你的其他 {host} 账号({accounts}),它们的其他文件不动',
2312
2317
  'hp.showChange': '查看改动',
@@ -2738,6 +2743,7 @@ const zh = {
2738
2743
  'toast.ahOn': '自动接力已开启,对用 sideby 启动的会话生效。',
2739
2744
  'toast.ahOff': '自动接力已关闭。',
2740
2745
  'qs.title': '开启 {host} 额度显示',
2746
+ 'qs.titleUpdate': '更新 {host} 额度显示',
2741
2747
  'qs.preparing': '正在准备改动…',
2742
2748
  'qs.changes': '将修改 {file}:',
2743
2749
  'qs.undoHint': '应用后可以马上撤销,之后也能用 sideby quota teardown 还原。',
@@ -2004,7 +2004,8 @@ const MAIN = String.raw `
2004
2004
  // Quota is on but no account of the Family has numbers yet: say what brings the first ones.
2005
2005
  function waitingForQuota(fam) {
2006
2006
  const setup = setupFor(fam)
2007
- if (!setup || setup.plan.status !== 'enabled') return false
2007
+ // A plan that only adds the refresh (ADR-0056) means quota is already on.
2008
+ if (!setup || !(setup.plan.status === 'enabled' || setup.plan.upgrade)) return false
2008
2009
  const all = S.state.accounts.filter((a) => a.family === fam && a.kind !== 'api')
2009
2010
  const waiting = all.some((a) => a.quota && a.quota.status === 'unavailable' && a.quota.reason === 'no-session')
2010
2011
  const any = all.some((a) => a.quota && a.quota.status === 'ok')
@@ -4991,7 +4992,8 @@ const MAIN = String.raw `
4991
4992
  if (p.status === 'enabled') body.push(h('p', null, p.message || t('qs.alreadyOn', { host: fam.title })))
4992
4993
  else if (p.status === 'blocked') body.push(h('p', { class: 'note note-warn' }, p.message))
4993
4994
  else {
4994
- body.push(h('p', { class: 'muted' }, qs.summary || p.message))
4995
+ // An update adds one key to a setup that is already on; its own message says what that key does.
4996
+ body.push(h('p', { class: 'muted' }, p.upgrade ? p.message : qs.summary || p.message))
4995
4997
  if (p.file) body.push(h('p', { class: 'small' }, tx('qs.changes', { file: h('code', null, p.file) })))
4996
4998
  if (p.diff) body.push(diffView(p.diff))
4997
4999
  body.push(h('p', { class: 'muted small' }, t('qs.undoHint')))
@@ -5000,7 +5002,7 @@ const MAIN = String.raw `
5000
5002
  }
5001
5003
  }
5002
5004
  if (!foot.length) foot.push(h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close')))
5003
- setKids(dlg.el, dialogFrame(t('qs.title', { host: fam.title }), qs.family, body, foot))
5005
+ setKids(dlg.el, dialogFrame(t(qs.plan && qs.plan.upgrade ? 'qs.titleUpdate' : 'qs.title', { host: fam.title }), qs.family, body, foot))
5004
5006
  }
5005
5007
  async function applySetup() {
5006
5008
  const st = qs
@@ -5014,7 +5016,9 @@ const MAIN = String.raw `
5014
5016
  if (r.plan.status === 'enabled') {
5015
5017
  const fam = st.family
5016
5018
  dlg.el.close()
5017
- toast(t('toast.quotaOn', { host: family(fam).title }), { action: { label: t('toast.undo'), run: () => undoSetup(fam) }, duration: 10000 })
5019
+ // Teardown undoes the whole setup, not just an update's one key, so an update gets no undo here.
5020
+ if (st.plan && st.plan.upgrade) toast(t('toast.quotaUpdated', { host: family(fam).title }))
5021
+ else toast(t('toast.quotaOn', { host: family(fam).title }), { action: { label: t('toast.undo'), run: () => undoSetup(fam) }, duration: 10000 })
5018
5022
  // The first numbers arrive with the next status line refresh; poll quickly for a while to show them soon.
5019
5023
  S.fastUntil = Date.now() + FAST_FOR_MS
5020
5024
  S.fastFamily = fam
@@ -5426,7 +5430,8 @@ const MAIN = String.raw `
5426
5430
  }
5427
5431
  function hpStepTitle(step) {
5428
5432
  const host = step.family ? family(step.family).title : ''
5429
- return t('hp.step.' + step.id, { host, accounts: (step.accounts || []).join(', ') })
5433
+ const id = step.id === 'quota' && step.upgrade ? 'quotaRefresh' : step.id
5434
+ return t('hp.step.' + id, { host, accounts: (step.accounts || []).join(', ') })
5430
5435
  }
5431
5436
  function hpSteps(plan) {
5432
5437
  return h('ul', { class: 'hp-steps' }, plan.steps.map((step) => h('li', null, h('div', null,
@@ -11,6 +11,11 @@ export declare function backupFile(stateDir: string): string;
11
11
  export declare function mainSettingsFile(home: string): string;
12
12
  export declare function isWrapped(command: unknown): boolean;
13
13
  export declare function wrapCommand(original: string | undefined): string;
14
+ /**
15
+ * Seconds between status line runs while a session is idle (ADR-0056): without it Claude Code runs the status line only
16
+ * on events in the main conversation, so the cache goes stale while the session waits on background agents.
17
+ */
18
+ export declare const REFRESH_INTERVAL = 30;
14
19
  export declare const claudeStatusline: QuotaSetup;
15
20
  /**
16
21
  * Hides values of secret-looking JSON keys in a diff line. settings.json often keeps API keys in `env`,