sideby 0.33.0 → 0.35.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 (38) 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 +67 -17
  4. package/dist/src/cli/json-schemas.js +11 -3
  5. package/dist/src/cli/main.js +11 -5
  6. package/dist/src/core/cli-commands.js +2 -2
  7. package/dist/src/core/live-sessions.d.ts +4 -0
  8. package/dist/src/core/live-sessions.js +17 -3
  9. package/dist/src/core/messages.d.ts +9 -0
  10. package/dist/src/core/messages.js +36 -2
  11. package/dist/src/core/session-status.d.ts +55 -0
  12. package/dist/src/core/session-status.js +59 -0
  13. package/dist/src/core/unattended-retry.d.ts +39 -0
  14. package/dist/src/core/unattended-retry.js +107 -0
  15. package/dist/src/core/unattended.d.ts +2 -2
  16. package/dist/src/core/unattended.js +10 -2
  17. package/dist/src/families/claude/deliver.js +6 -2
  18. package/dist/src/families/claude/messaging.d.ts +8 -1
  19. package/dist/src/families/claude/messaging.js +15 -3
  20. package/dist/src/families/messaging.d.ts +6 -0
  21. package/dist/src/handoff/messages.js +1 -1
  22. package/dist/src/panel/i18n.d.ts +13 -0
  23. package/dist/src/panel/i18n.js +35 -9
  24. package/dist/src/panel/page-logic.d.ts +49 -5
  25. package/dist/src/panel/page-logic.js +74 -10
  26. package/dist/src/panel/page-script.js +59 -17
  27. package/dist/src/panel/page-styles.js +11 -0
  28. package/dist/src/unattended/hook.d.ts +4 -0
  29. package/dist/src/unattended/hook.js +86 -2
  30. package/package.json +1 -1
  31. package/schemas/new.json +4 -1
  32. package/schemas/sessions.json +22 -1
  33. package/skills/sideby/SKILL.md +2 -2
  34. package/skills/sideby/references/accounts.md +10 -0
  35. package/skills/sideby/references/ai-tasks.md +1 -1
  36. package/skills/sideby/references/sessions.md +1 -1
  37. package/skills/sideby/references/setup.md +1 -1
  38. package/skills/sideby/references/unattended.md +4 -2
@@ -0,0 +1,107 @@
1
+ // Turn Retry (spec §3.37 item 6, ADR-0067): while Unattended Mode is on, a Claude turn that ended on a passing failure
2
+ // (an overloaded or failing server, a rate limit that is not a used-up Quota, a dropped or refused connection) is
3
+ // started again by `unattended-hook`'s background `StopFailure` entry, at most `RETRY_LIMIT` times in a row per
4
+ // session, each after a longer wait. A leaf module (Node built-ins and core/fs-safe.ts only): the hook imports it.
5
+ //
6
+ // The streak of one session is a file under `<state>/unattended/retries/`, named by a hash of the session id, so a
7
+ // session id never becomes a path. Both folders must be real folders of the user that nobody else can write to
8
+ // (`ownedFolder`, as for Pending Decisions); when one is not, nothing is read or written there and no turn is retried.
9
+ import { randomBytes } from 'node:crypto';
10
+ import { rm } from 'node:fs/promises';
11
+ import { join } from 'node:path';
12
+ import { ownedFolder, readSmallFile, sha256, writeFileAtomic } from './fs-safe.js';
13
+ /** How many times in a row one session's failed turn is started again before it is left for the user. */
14
+ export const RETRY_LIMIT = 3;
15
+ /** The wait before the first retry; each next one waits twice as long (1, 2 and 4 minutes). */
16
+ export const RETRY_FIRST_MS = 60_000;
17
+ /** A streak older than this starts again from one (a failure the next night is not the fourth of last night's). */
18
+ export const RETRY_FRESH_MS = 6 * 60 * 60_000;
19
+ /** The `timeout` of the hook entry: the longest wait (4 minutes) with room to spare. */
20
+ export const RETRY_HOOK_TIMEOUT_S = 600;
21
+ /** The wait before retry `n` (1-based). */
22
+ export const retryDelay = (n) => RETRY_FIRST_MS * 2 ** (Math.max(1, n) - 1);
23
+ /** The `StopFailure` error types (Claude Code's hook `error` field) that can be a passing failure. */
24
+ export const PASSING_ERRORS = ['rate_limit', 'overloaded', 'server_error', 'unknown'];
25
+ /**
26
+ * Claude Code's wording when a Quota, a plan limit, a spend cap or credits are used up (its error reference: "You've
27
+ * hit your session limit", "Fable limit reached", "monthly spend limit", "Credit balance is too low", "Usage credits
28
+ * required"). Waiting minutes does not help those: Auto Handoff or `autoContinueAtUsageLimit` takes them. A plain
29
+ * "Rate limit reached" is a throttle, not a used-up Quota.
30
+ */
31
+ const USED_UP = /hit your|usage limit|out of (?:extra )?usage|spend limit|spending limit|credit balance|usage credits|(?<!rate )limit reached/i;
32
+ /** What an `unknown` error must say to count as passing: a timeout or overload status, or a dropped connection. */
33
+ const PASSING_TEXT = /\b(?:408|429|5\d\d)\b|timed? ?out|timeout|ECONNRESET|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|EPIPE|socket hang up|connection (?:refused|reset|error|closed)|network|overloaded|temporarily/i;
34
+ /**
35
+ * Whether a failed turn's error is a passing one, from the hook input's `error` type and its text
36
+ * (`last_assistant_message`, `error_details`). Checked with Claude Code 2.1.316 against a local server: HTTP 500 and
37
+ * a refused connection come as `server_error`, 429 as `rate_limit`, 408 as `unknown`.
38
+ */
39
+ export function passingFailure(error, text) {
40
+ if (!error || !PASSING_ERRORS.includes(error) || USED_UP.test(text))
41
+ return false;
42
+ return error !== 'unknown' || PASSING_TEXT.test(text);
43
+ }
44
+ const PARTS = ['unattended', 'retries'];
45
+ const fileName = (sessionId) => `${sha256(sessionId).slice(0, 32)}.json`;
46
+ function parse(text) {
47
+ if (!text)
48
+ return undefined;
49
+ try {
50
+ const v = JSON.parse(text);
51
+ if (typeof v.count !== 'number' || !Number.isInteger(v.count) || v.count < 1)
52
+ return undefined;
53
+ if (typeof v.token !== 'string' || typeof v.at !== 'string' || !Number.isFinite(Date.parse(v.at)))
54
+ return undefined;
55
+ return { count: v.count, token: v.token, at: v.at };
56
+ }
57
+ catch {
58
+ return undefined;
59
+ }
60
+ }
61
+ /** The session's streak, or undefined when there is none or its folder is not safe to read. */
62
+ export async function readRetryStreak(stateDir, sessionId) {
63
+ const dir = await ownedFolder(stateDir, PARTS, { create: false }).catch(() => null);
64
+ if (!dir)
65
+ return undefined;
66
+ return parse(await readSmallFile(join(dir, fileName(sessionId)), 4096));
67
+ }
68
+ /**
69
+ * Counts one more failure for the session and returns the streak with a new token. A streak older than
70
+ * `RETRY_FRESH_MS` starts again from one. Throws when the folder is not safe to use (the caller then retries nothing).
71
+ */
72
+ export async function countFailure(stateDir, sessionId, now) {
73
+ const dir = (await ownedFolder(stateDir, PARTS, { create: true, private: true }));
74
+ const file = join(dir, fileName(sessionId));
75
+ const old = parse(await readSmallFile(file, 4096));
76
+ const fresh = old && now.getTime() - Date.parse(old.at) < RETRY_FRESH_MS;
77
+ const streak = {
78
+ count: fresh ? old.count + 1 : 1,
79
+ token: randomBytes(8).toString('hex'),
80
+ at: now.toISOString(),
81
+ };
82
+ await writeFileAtomic(file, `${JSON.stringify(streak)}\n`, 0o600);
83
+ return streak;
84
+ }
85
+ /** Ends the session's streak: its turn finished, or it was left for the user. */
86
+ export async function clearRetryStreak(stateDir, sessionId) {
87
+ const dir = await ownedFolder(stateDir, PARTS, { create: false }).catch(() => null);
88
+ if (dir)
89
+ await rm(join(dir, fileName(sessionId)), { force: true });
90
+ }
91
+ const clip = (s, max) => {
92
+ const one = s.replace(/\s+/g, ' ').trim();
93
+ return one.length <= max ? one : `${one.slice(0, max - 1)}…`;
94
+ };
95
+ /** What the model reads when its session is woken to go on after a passing failure. */
96
+ export function retryMessage(error, text, count, zh) {
97
+ const why = clip(`${error}${text ? `: ${text}` : ''}`, 200);
98
+ if (zh)
99
+ return `sideby 无人值守:你上一个回合因为暂时性的错误中断了(${why}),没人在,sideby 让会话接着做(第 ${count} 次,最多 ${RETRY_LIMIT} 次)。先看看已经做完了什么,不要重做,从中断的地方继续完成任务。`;
100
+ return `sideby's Unattended Mode: your last turn failed for a passing reason (${why}), and nobody is here to start it again, so sideby did (retry ${count} of ${RETRY_LIMIT}). Check what is already done, do not redo it, and continue the task where it stopped.`;
101
+ }
102
+ /** What the user reads in the morning when the retries ran out: kept as a Pending Decision. */
103
+ export function retryGaveUpText(error, text) {
104
+ const why = clip(`${error}${text ? `: ${text}` : ''}`, 300);
105
+ const waits = Array.from({ length: RETRY_LIMIT }, (_, i) => retryDelay(i + 1) / 60_000).join(', ');
106
+ return `The session stopped: its turn kept failing for a passing reason (${why}). sideby started it again ${RETRY_LIMIT} times (after ${waits} minutes) and then left it. Continue the session when you are back.`;
107
+ }
@@ -132,8 +132,8 @@ export declare const unattendedClock: (iso: string, now: Date, zh?: boolean) =>
132
132
  /**
133
133
  * Unattended Mode's session hooks: before the ask tool and when the model ends its turn (`Stop`, which keeps a turn
134
134
  * 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 and every MCP server form (`Elicitation`). Codex has no such events for them; its own approval
136
- * prompts are not covered.
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.
137
137
  */
138
138
  export declare function unattendedHookPart(): SessionHookPart;
139
139
  /** The line a Claude Launch prints when the user's own `--settings` leaves no room for the hook. */
@@ -9,6 +9,7 @@ import { UserError } from './errors.js';
9
9
  import { ownedFolder, writeFileAtomic } from './fs-safe.js';
10
10
  import { sidebyHookCommand } from './session-hooks.js';
11
11
  import { listPendingDecisions } from './unattended-pending.js';
12
+ import { RETRY_HOOK_TIMEOUT_S } from './unattended-retry.js';
12
13
  import { clearUnattendedOverride, clockText, ensureUnattendedDir, MAX_MANUAL_MS, parseClock, parseDays, parseSlot, readUnattendedConfig, readUnattendedOverride, scheduleStretchAt, slotEnd, UNATTENDED_ENV, unattendedState, writeUnattendedOverride, } from './unattended-state.js';
13
14
  /** Families whose sessions Unattended Mode covers in v1. */
14
15
  export const UNATTENDED_FAMILIES = ['claude', 'codex'];
@@ -291,8 +292,8 @@ export const unattendedClock = (iso, now, zh = false) => clockText(Date.parse(is
291
292
  /**
292
293
  * Unattended Mode's session hooks: before the ask tool and when the model ends its turn (`Stop`, which keeps a turn
293
294
  * that ended on a question going once) in Claude and Codex; and in Claude on every permission request Claude Code is
294
- * about to show and every MCP server form (`Elicitation`). Codex has no such events for them; its own approval
295
- * prompts are not covered.
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.
296
297
  */
297
298
  export function unattendedHookPart() {
298
299
  const command = (family, event = 'PreToolUse') => sidebyHookCommand('unattended-hook', family, event);
@@ -305,6 +306,13 @@ export function unattendedHookPart() {
305
306
  PermissionRequest: [{ matcher: '*', hooks: claude('PermissionRequest') }],
306
307
  Stop: [{ hooks: claude('Stop') }],
307
308
  Elicitation: [{ matcher: '*', hooks: claude('Elicitation') }],
309
+ // Waits up to 4 minutes before it wakes the session; Claude Code still enforces `timeout` on `asyncRewake`.
310
+ // No matcher: every failed turn reaches it, so a later failure that is not retried still ends an earlier wait.
311
+ StopFailure: [
312
+ {
313
+ hooks: [{ ...claude('StopFailure')[0], asyncRewake: true, timeout: RETRY_HOOK_TIMEOUT_S }],
314
+ },
315
+ ],
308
316
  },
309
317
  codex: {
310
318
  PreToolUse: [`{matcher="^request_user_input$",${codex('PreToolUse')}}`],
@@ -3,7 +3,7 @@
3
3
  // back as a paste with the reason; nothing here reads a key file or a token.
4
4
  import { inboundGroups } from '../../core/inbound.js';
5
5
  import { hostArgs } from '../../core/live-sessions-procs.js';
6
- import { checkSocket, claudeSocketOf, DELIVER_TIMEOUT_MS, messageLine, sessionBypass, socketChanged, socketRoots, UnconfirmedWrite, writeToSocket, } from './messaging.js';
6
+ import { checkSocket, claudeSocketOf, DELIVER_TIMEOUT_MS, messageLine, PassingWriteError, sessionBypass, socketChanged, socketRoots, UnconfirmedWrite, writeToSocket, } from './messaging.js';
7
7
  export async function deliverClaude(req) {
8
8
  const { rt, to, acct, pid, procs, deps } = req;
9
9
  const paste = (note) => ({ status: 'paste-needed', note });
@@ -35,7 +35,11 @@ export async function deliverClaude(req) {
35
35
  note: `sideby wrote it to ${to.label} but could not confirm it arrived (${err.message}).${ended ? ' The session has ended since.' : ''} It may still show up; check the session before you send it again`,
36
36
  };
37
37
  }
38
- return paste(`sideby could not reach ${to.label} (${err.message}); paste the line into its tab`);
38
+ // Nothing was written: a failure that may pass is tried again (core/messages.ts), any other is a paste.
39
+ return {
40
+ ...paste(`sideby could not reach ${to.label} (${err.message}); paste the line into its tab`),
41
+ ...(err instanceof PassingWriteError ? { retry: true } : {}),
42
+ };
39
43
  }
40
44
  if (inbound === 'accept')
41
45
  return { status: 'delivered' };
@@ -60,10 +60,17 @@ export declare const messageLine: (text: string) => string;
60
60
  */
61
61
  export declare class UnconfirmedWrite extends Error {
62
62
  }
63
+ /**
64
+ * Nothing was written, and the failure may pass: the session refused or dropped the connection, its queue was full,
65
+ * or it did not answer in time. Sending again cannot deliver the line twice, so the delivery is tried again.
66
+ */
67
+ export declare class PassingWriteError extends Error {
68
+ }
63
69
  /**
64
70
  * Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
65
71
  * connection as soon as the line is flushed, also when the peer keeps its end open. Rejects on a refused connection
66
- * or after `timeoutMs`; with `UnconfirmedWrite` once the line was written and the flush did not come.
72
+ * or after `timeoutMs` (with `PassingWriteError` when nothing was written and it may pass); with `UnconfirmedWrite`
73
+ * once the line was written and the flush did not come.
67
74
  */
68
75
  export declare function writeToSocket(path: string, line: string, timeoutMs?: number, verify?: () => Promise<string | null>): Promise<void>;
69
76
  /** Whether Host arguments start Claude Code in bypass permission mode. */
@@ -111,10 +111,19 @@ export const messageLine = (text) => `${JSON.stringify({ type: 'user', message:
111
111
  */
112
112
  export class UnconfirmedWrite extends Error {
113
113
  }
114
+ /**
115
+ * Nothing was written, and the failure may pass: the session refused or dropped the connection, its queue was full,
116
+ * or it did not answer in time. Sending again cannot deliver the line twice, so the delivery is tried again.
117
+ */
118
+ export class PassingWriteError extends Error {
119
+ }
120
+ /** Socket errors before anything is written that a session that is busy for a moment gives. */
121
+ const PASSING_CODES = new Set(['ECONNREFUSED', 'ECONNRESET', 'EAGAIN', 'ETIMEDOUT', 'EPIPE']);
114
122
  /**
115
123
  * Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
116
124
  * connection as soon as the line is flushed, also when the peer keeps its end open. Rejects on a refused connection
117
- * or after `timeoutMs`; with `UnconfirmedWrite` once the line was written and the flush did not come.
125
+ * or after `timeoutMs` (with `PassingWriteError` when nothing was written and it may pass); with `UnconfirmedWrite`
126
+ * once the line was written and the flush did not come.
118
127
  */
119
128
  export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify) {
120
129
  return new Promise((resolve, reject) => {
@@ -132,7 +141,7 @@ export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify
132
141
  else
133
142
  resolve();
134
143
  };
135
- const timer = setTimeout(() => finish(new Error(`it did not answer within ${timeoutMs / 1000} s`)), timeoutMs);
144
+ const timer = setTimeout(() => finish(new PassingWriteError(`it did not answer within ${timeoutMs / 1000} s`)), timeoutMs);
136
145
  sock.once('connect', async () => {
137
146
  const changed = verify ? await verify().catch((e) => e.message) : null;
138
147
  if (changed)
@@ -142,7 +151,10 @@ export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify
142
151
  written = true;
143
152
  sock.end(line, () => finish(null));
144
153
  });
145
- sock.once('error', (err) => finish(new Error(err.code === 'ECONNREFUSED' ? 'it refused the connection' : (err.code ?? err.message))));
154
+ sock.once('error', (err) => {
155
+ const why = err.code === 'ECONNREFUSED' ? 'it refused the connection' : (err.code ?? err.message);
156
+ finish(err.code && PASSING_CODES.has(err.code) ? new PassingWriteError(why) : new Error(why));
157
+ });
146
158
  });
147
159
  }
148
160
  /** Whether Host arguments start Claude Code in bypass permission mode. */
@@ -28,5 +28,11 @@ export interface Delivery {
28
28
  note?: string;
29
29
  /** The Host took it but shows it only after the user approves it in the target's terminal (ADR-0045). */
30
30
  needsApproval?: boolean;
31
+ /**
32
+ * A `paste-needed` whose channel took nothing and failed in a way that may pass (a refused connection, no answer
33
+ * before writing): sending again cannot deliver it twice, so `core/messages.ts` tries again after a wait. Never
34
+ * kept in a receipt.
35
+ */
36
+ retry?: boolean;
31
37
  }
32
38
  export declare const DELIVERERS: Readonly<Record<string, (req: DeliveryRequest) => Promise<Delivery>>>;
@@ -52,7 +52,7 @@ const WHY = {
52
52
  };
53
53
  /** The next session's first prompt: the Brief's path only, never its text (it would show in a process list). */
54
54
  export function firstPrompt(fromRef, brief, trigger) {
55
- return `This task was handed over from ${fromRef} by sideby because ${WHY[trigger]}. Read ${brief} first, then continue the task it describes. If the user asks to move the task to another account (back to ${fromRef}, say), run \`sideby handoff ready --to <account>\` and end your turn.`;
55
+ return `This task was handed over from ${fromRef} by sideby because ${WHY[trigger]}. Read ${brief} first, then continue the task it describes. The previous session may have stopped mid-step: check the working tree, git history and any remote state before you repeat an outside action such as a push, a message or a pull request, and do not repeat one that already happened. If the user asks to move the task to another account (back to ${fromRef}, say), run \`sideby handoff ready --to <account>\` and end your turn.`;
56
56
  }
57
57
  const clock = (iso) => new Date(iso).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
58
58
  /** For the user, not the model (ADR-0018): this session will wait for the reset, and how to move on now instead. */
@@ -265,6 +265,7 @@ declare const en: {
265
265
  'group.attentionShow': string;
266
266
  'acct.alias': string;
267
267
  'acct.aliasArgs': string;
268
+ 'acct.titleAlias': string;
268
269
  'acct.api': string;
269
270
  'acct.model': string;
270
271
  'acct.signedOut': string;
@@ -935,6 +936,12 @@ declare const en: {
935
936
  'spage.status.busy': string;
936
937
  'spage.status.idle': string;
937
938
  'spage.status.unknown': string;
939
+ 'spage.why.host-waits': string;
940
+ 'spage.why.pending-decision': string;
941
+ 'spage.why.message-to-approve': string;
942
+ 'spage.why.message-to-paste': string;
943
+ 'spage.decision': string;
944
+ 'spage.decisionTip': string;
938
945
  'spage.guessed': string;
939
946
  'spage.guessedTip': string;
940
947
  'spage.run': string;
@@ -1233,6 +1240,12 @@ declare const en: {
1233
1240
  'nf.aliasPh': string;
1234
1241
  'nf.aliasHint': string;
1235
1242
  'nf.aliasSuggested': string;
1243
+ 'nf.aliasVendor': string;
1244
+ 'nf.aliasVendorTip': string;
1245
+ 'nf.vendor': string;
1246
+ 'nf.vendorPh': string;
1247
+ 'nf.vendorHint': string;
1248
+ 'nf.vendorWord': string;
1236
1249
  'nf.aliasBad': string;
1237
1250
  'nf.aliasReserved': string;
1238
1251
  'nf.aliasTaken': string;
@@ -267,6 +267,7 @@ const en = {
267
267
  'group.attentionShow': 'Show {name}',
268
268
  'acct.alias': 'Alias',
269
269
  'acct.aliasArgs': 'Alias, starts this account with {args}',
270
+ 'acct.titleAlias': '{alias} starts {ref}',
270
271
  'acct.api': 'API',
271
272
  'acct.model': 'Model',
272
273
  'acct.signedOut': 'Signed out',
@@ -937,6 +938,12 @@ const en = {
937
938
  'spage.status.busy': 'Working',
938
939
  'spage.status.idle': 'Idle',
939
940
  'spage.status.unknown': 'Running',
941
+ 'spage.why.host-waits': 'It waits in its terminal for your answer or your approval.',
942
+ 'spage.why.pending-decision': 'It asked something while you were away, and the answer is still yours to give. See it under Unattended.',
943
+ 'spage.why.message-to-approve': 'A message sent to it shows only once you approve it in its terminal.',
944
+ 'spage.why.message-to-paste': 'A message sent to it is waiting for you to paste it into its tab.',
945
+ 'spage.decision': 'Decision waiting',
946
+ 'spage.decisionTip': 'Open Unattended to see what it asked and mark it done.',
940
947
  'spage.guessed': 'newest session (guessed)',
941
948
  'spage.guessedTip': 'sideby could not tell which session this account is running, so it shows the newest one.',
942
949
  'spage.run': 'Task: {title}',
@@ -1235,6 +1242,12 @@ const en = {
1235
1242
  'nf.aliasPh': 'none',
1236
1243
  'nf.aliasHint': 'A shell command that starts this account. Leave it empty for none.',
1237
1244
  'nf.aliasSuggested': 'Follows the short commands of your other {host} accounts.',
1245
+ 'nf.aliasVendor': 'Named after the vendor, so you can tell your API accounts apart.',
1246
+ 'nf.aliasVendorTip': 'Fill in the vendor above to get {example}.',
1247
+ 'nf.vendor': 'Vendor',
1248
+ 'nf.vendorPh': 'ds, kimi, glm…',
1249
+ 'nf.vendorHint': 'Who this key is from, in a few letters. It names the short command.',
1250
+ 'nf.vendorWord': 'vendor',
1238
1251
  'nf.aliasBad': 'Use letters, digits, "_" or "-", starting with a letter or "_".',
1239
1252
  'nf.aliasReserved': '"{alias}" is a shell keyword or builtin. Pick another.',
1240
1253
  'nf.aliasTaken': '{alias} already starts {ref}.',
@@ -1512,13 +1525,13 @@ const en = {
1512
1525
  'ua.untilDay': 'until {day} {time}',
1513
1526
  'ua.backToday': 'back on at {time}',
1514
1527
  'ua.backDay': 'back on {day} {time}',
1515
- 'ua.nextToday': 'next: {time}',
1516
- 'ua.nextDay': 'next: {day} {time}',
1528
+ 'ua.nextToday': 'turns on at {time}',
1529
+ 'ua.nextDay': 'turns on {day} {time}',
1517
1530
  'ua.today': 'today',
1518
1531
  'ua.tomorrow': 'tomorrow',
1519
1532
  'ua.noEnd': 'stays on: your Schedule covers every hour',
1520
1533
  'ua.pausedOpen': 'until you turn it on again',
1521
- 'ua.onNote': 'Sessions sideby starts do not stop to wait for you. Questions go on with the recommended choice; a step Claude Code wants you to confirm is refused, and the session finds another way or skips it. What they skipped is listed below.',
1534
+ 'ua.onNote': 'Sessions sideby starts do not stop to wait for you. Questions go on with the recommended choice; a step Claude Code wants you to confirm is refused, and the session finds another way or skips it; a Claude turn cut off by a passing server or network error is started again, up to 3 times. What they skipped is listed below.',
1522
1535
  'ua.offNote': 'When it is on, sessions sideby starts do not stop to wait for you: no questions, and no prompts asking you to confirm a step.',
1523
1536
  'ua.pausedNote': 'Until then, sessions ask you as usual. Turn it on now to go back.',
1524
1537
  'ua.turnOn': 'Turn on now',
@@ -1862,6 +1875,7 @@ const zh = {
1862
1875
  'group.attentionShow': '定位到 {name}',
1863
1876
  'acct.alias': '别名',
1864
1877
  'acct.aliasArgs': '别名,启动这个账号并附加 {args}',
1878
+ 'acct.titleAlias': '{alias} 启动 {ref}',
1865
1879
  'acct.api': 'API',
1866
1880
  'acct.model': '模型',
1867
1881
  'acct.signedOut': '未登录',
@@ -2532,6 +2546,12 @@ const zh = {
2532
2546
  'spage.status.busy': '运行中',
2533
2547
  'spage.status.idle': '空闲',
2534
2548
  'spage.status.unknown': '在运行',
2549
+ 'spage.why.host-waits': '它在终端里等你回答或批准。',
2550
+ 'spage.why.pending-decision': '你不在时它问过一件事,还等你决定。在「无人值守」页能看到。',
2551
+ 'spage.why.message-to-approve': '发给它的消息要你在它的终端里批准后才显示。',
2552
+ 'spage.why.message-to-paste': '发给它的消息还等你粘贴到它的标签页里。',
2553
+ 'spage.decision': '有事待你决定',
2554
+ 'spage.decisionTip': '打开「无人值守」页,看它问了什么,处理完标为已完成。',
2535
2555
  'spage.guessed': '最新会话(推测)',
2536
2556
  'spage.guessedTip': 'sideby 没法确定这个账号正在跑哪个会话,先显示它最新的一个。',
2537
2557
  'spage.run': '任务:{title}',
@@ -2830,6 +2850,12 @@ const zh = {
2830
2850
  'nf.aliasPh': '不设置',
2831
2851
  'nf.aliasHint': '在终端里启动这个账号的命令。留空表示不设置。',
2832
2852
  'nf.aliasSuggested': '按你其他 {host} 账号的短命令规律填入。',
2853
+ 'nf.aliasVendor': '按厂商命名,几个 API 账号一眼就能分清。',
2854
+ 'nf.aliasVendorTip': '在上面填厂商,就会得到 {example}。',
2855
+ 'nf.vendor': '厂商',
2856
+ 'nf.vendorPh': 'ds、kimi、glm…',
2857
+ 'nf.vendorHint': '这个 key 是哪家的,写几个字母就行。短命令按它命名。',
2858
+ 'nf.vendorWord': '厂商',
2833
2859
  'nf.aliasBad': '只能用字母、数字、“_”或“-”,并以字母或“_”开头。',
2834
2860
  'nf.aliasReserved': '“{alias}”是 shell 关键字或内置命令,请换一个。',
2835
2861
  'nf.aliasTaken': '{alias} 已用于启动 {ref}。',
@@ -3104,16 +3130,16 @@ const zh = {
3104
3130
  'ua.slotQuoted': '时段『{name}』',
3105
3131
  'ua.slotN': '时段 {n}',
3106
3132
  'ua.untilToday': '到 {time}',
3107
- 'ua.untilDay': '到{day} {time}',
3108
- 'ua.backToday': '到 {time} 后恢复',
3109
- 'ua.backDay': '到{day} {time} 后恢复',
3110
- 'ua.nextToday': '下一次 {time}',
3111
- 'ua.nextDay': '下一次 {day} {time}',
3133
+ 'ua.untilDay': '到 {day} {time}',
3134
+ 'ua.backToday': '{time} 自动恢复',
3135
+ 'ua.backDay': '{day} {time} 自动恢复',
3136
+ 'ua.nextToday': '{time} 自动开启',
3137
+ 'ua.nextDay': '{day} {time} 自动开启',
3112
3138
  'ua.today': '今天',
3113
3139
  'ua.tomorrow': '明天',
3114
3140
  'ua.noEnd': '一直开着:时间表覆盖了每个小时',
3115
3141
  'ua.pausedOpen': '等你再打开',
3116
- 'ua.onNote': 'sideby 启动的会话不会停下来等你:提问按推荐继续;Claude Code 要你确认的操作直接拒绝,会话换个做法或跳过。跳过的记在下面。',
3142
+ 'ua.onNote': 'sideby 启动的会话不会停下来等你:提问按推荐继续;Claude Code 要你确认的操作直接拒绝,会话换个做法或跳过;Claude 回合因为服务器或网络的暂时问题中断时,自动接着跑,最多 3 次。跳过的记在下面。',
3117
3143
  'ua.offNote': '开着时,sideby 启动的会话不停下来等你:不提问,也不弹要你确认的框。',
3118
3144
  'ua.pausedNote': '在那之前,会话照常问你。现在开就恢复。',
3119
3145
  'ua.turnOn': '现在开',
@@ -352,13 +352,41 @@ export declare function fixPrompt(findings: readonly {
352
352
  check: string;
353
353
  }): string;
354
354
  /**
355
- * A short command to offer for a new Account `name` of a Family, from the config aliases of its existing Accounts:
356
- * an alias that is a prefix plus its Account's name (`cc001` for `claude:001`) gives the prefix, the most common
357
- * one wins (then the longer, then the first alphabetically), and the offer is that prefix plus `name` (`cc008`).
358
- * Aliases that do not end in their Account's name (`codex001` for `codex:main`) are ignored. Empty when no
359
- * pattern shows, or without a name. The caller still checks the result like any alias.
355
+ * The prefix a Family's short commands put before their Account's name, from the config aliases of its Accounts: an
356
+ * alias that is a prefix plus its Account's name (`cc001` for `claude:001`) gives the prefix, and the most common one
357
+ * wins (then the longer, then the first alphabetically). Aliases that do not end in their Account's name (`codex001`
358
+ * for `codex:main`, `cc-ds` for `claude:011`) are ignored. Empty when no pattern shows.
359
+ */
360
+ export declare function aliasPrefix(accounts: LogicAccount[], family: string): string;
361
+ /**
362
+ * A short command to offer for a new Subscription Account `name` of a Family: its alias prefix (`aliasPrefix`) plus
363
+ * `name` (`cc008`). Empty when no pattern shows, or without a name. The caller still checks the result like any alias.
360
364
  */
361
365
  export declare function suggestAlias(accounts: LogicAccount[], family: string, name: string): string;
366
+ /**
367
+ * A short command to offer for a new API Account of a Family that calls `vendor` (its Vendor Slug, used as given): the
368
+ * Family's alias prefix, a dash and the slug (`cc-ds`), so the name says what the Account calls rather than a number.
369
+ * A prefix that already ends in a dash or underscore (`cc-` from `cc-001`) gets no second one. Empty without a slug,
370
+ * or when the Family's short commands show no prefix: sideby never invents one. The caller still checks the result
371
+ * like any alias (an invalid or taken slug fails there).
372
+ */
373
+ export declare function vendorAlias(accounts: LogicAccount[], family: string, vendor: string): string;
374
+ /**
375
+ * An Account's short commands in the order the Panel lists them: those that only start it (`pi001`) first, then those
376
+ * that add Host arguments (`pi-glm`, `pi-kimi`), each group in name order.
377
+ */
378
+ export declare function orderedAliases(a: LogicAccount): string[];
379
+ /**
380
+ * What names an Account in its row or card. An API Account with a short command that adds no arguments is named by
381
+ * it (`cc-kimi`): the short command says which Vendor it calls, its name is only a number, and its ref stays in the
382
+ * line under the title. Every other Account keeps its name. `aliases`: the short commands shown after the title, in
383
+ * `orderedAliases` order.
384
+ */
385
+ export declare function accountTitle(a: LogicAccount): {
386
+ title: string;
387
+ byAlias: boolean;
388
+ aliases: string[];
389
+ };
362
390
  /**
363
391
  * Why `alias` cannot become the short command of `ref`, by the config rules: `pattern` (not a shell-safe name,
364
392
  * matched against the config's own pattern source), `reserved` (a shell keyword, builtin or `sideby`), `taken`
@@ -402,6 +430,22 @@ export declare function sortSessions<T extends LogicSession>(list: readonly T[])
402
430
  * shown before comes ahead of the shown ones, in `sortSessions` order.
403
431
  */
404
432
  export declare function steadyOrder<T extends LogicSession>(shown: readonly string[], list: readonly T[]): T[];
433
+ /**
434
+ * Everything a Sessions row shows except its age, as plain values: the page redraws a row only when this changes.
435
+ * `reason` is in it, so a Session that keeps `needs-you` for another reason (a decision instead of its Host asking)
436
+ * gets its button and its hint redrawn.
437
+ */
438
+ export declare function sessionRowShape(s: LogicSession & {
439
+ family?: string;
440
+ reason?: string;
441
+ guessed?: boolean;
442
+ copy?: unknown;
443
+ orca?: unknown;
444
+ run?: unknown;
445
+ }, msg?: {
446
+ status: string;
447
+ needsApproval?: boolean;
448
+ }): unknown[];
405
449
  /** How long ago a Session was last active, as a message key and count; null when it has no time at all. */
406
450
  export declare function sessionAge(s: LogicSession, now: number): {
407
451
  key: string;
@@ -702,15 +702,12 @@ export function fixPrompt(findings, words) {
702
702
  return [words.lead, items.join('\n\n'), ...tail].join('\n\n');
703
703
  }
704
704
  /**
705
- * A short command to offer for a new Account `name` of a Family, from the config aliases of its existing Accounts:
706
- * an alias that is a prefix plus its Account's name (`cc001` for `claude:001`) gives the prefix, the most common
707
- * one wins (then the longer, then the first alphabetically), and the offer is that prefix plus `name` (`cc008`).
708
- * Aliases that do not end in their Account's name (`codex001` for `codex:main`) are ignored. Empty when no
709
- * pattern shows, or without a name. The caller still checks the result like any alias.
705
+ * The prefix a Family's short commands put before their Account's name, from the config aliases of its Accounts: an
706
+ * alias that is a prefix plus its Account's name (`cc001` for `claude:001`) gives the prefix, and the most common one
707
+ * wins (then the longer, then the first alphabetically). Aliases that do not end in their Account's name (`codex001`
708
+ * for `codex:main`, `cc-ds` for `claude:011`) are ignored. Empty when no pattern shows.
710
709
  */
711
- export function suggestAlias(accounts, family, name) {
712
- if (!name)
713
- return '';
710
+ export function aliasPrefix(accounts, family) {
714
711
  const counts = {};
715
712
  for (const a of accounts) {
716
713
  if (a.family !== family)
@@ -721,8 +718,52 @@ export function suggestAlias(accounts, family, name) {
721
718
  counts[prefix] = (counts[prefix] || 0) + 1;
722
719
  }
723
720
  }
724
- const best = Object.keys(counts).sort((x, y) => (counts[y] || 0) - (counts[x] || 0) || y.length - x.length || (x < y ? -1 : x > y ? 1 : 0))[0];
725
- return best ? best + name : '';
721
+ return (Object.keys(counts).sort((x, y) => (counts[y] || 0) - (counts[x] || 0) || y.length - x.length || (x < y ? -1 : x > y ? 1 : 0))[0] || '');
722
+ }
723
+ /**
724
+ * A short command to offer for a new Subscription Account `name` of a Family: its alias prefix (`aliasPrefix`) plus
725
+ * `name` (`cc008`). Empty when no pattern shows, or without a name. The caller still checks the result like any alias.
726
+ */
727
+ export function suggestAlias(accounts, family, name) {
728
+ if (!name)
729
+ return '';
730
+ const prefix = aliasPrefix(accounts, family);
731
+ return prefix ? prefix + name : '';
732
+ }
733
+ /**
734
+ * A short command to offer for a new API Account of a Family that calls `vendor` (its Vendor Slug, used as given): the
735
+ * Family's alias prefix, a dash and the slug (`cc-ds`), so the name says what the Account calls rather than a number.
736
+ * A prefix that already ends in a dash or underscore (`cc-` from `cc-001`) gets no second one. Empty without a slug,
737
+ * or when the Family's short commands show no prefix: sideby never invents one. The caller still checks the result
738
+ * like any alias (an invalid or taken slug fails there).
739
+ */
740
+ export function vendorAlias(accounts, family, vendor) {
741
+ const slug = String(vendor || '').trim();
742
+ if (!slug)
743
+ return '';
744
+ const prefix = aliasPrefix(accounts, family).replace(/[-_]+$/, '');
745
+ return prefix ? prefix + '-' + slug : '';
746
+ }
747
+ /**
748
+ * An Account's short commands in the order the Panel lists them: those that only start it (`pi001`) first, then those
749
+ * that add Host arguments (`pi-glm`, `pi-kimi`), each group in name order.
750
+ */
751
+ export function orderedAliases(a) {
752
+ const all = (a.aliases || []).slice().sort((x, y) => (x < y ? -1 : x > y ? 1 : 0));
753
+ return all.filter((x) => !aliasArgsOf(a, x)).concat(all.filter((x) => aliasArgsOf(a, x)));
754
+ }
755
+ /**
756
+ * What names an Account in its row or card. An API Account with a short command that adds no arguments is named by
757
+ * it (`cc-kimi`): the short command says which Vendor it calls, its name is only a number, and its ref stays in the
758
+ * line under the title. Every other Account keeps its name. `aliases`: the short commands shown after the title, in
759
+ * `orderedAliases` order.
760
+ */
761
+ export function accountTitle(a) {
762
+ const all = orderedAliases(a);
763
+ const plain = a.kind === 'api' ? all.filter((x) => !aliasArgsOf(a, x))[0] : undefined;
764
+ if (plain)
765
+ return { title: plain, byAlias: true, aliases: all.filter((x) => x !== plain) };
766
+ return { title: a.name, byAlias: false, aliases: all };
726
767
  }
727
768
  /**
728
769
  * Why `alias` cannot become the short command of `ref`, by the config rules: `pattern` (not a shell-safe name,
@@ -801,6 +842,29 @@ export function steadyOrder(shown, list) {
801
842
  rank.sort((a, b) => needs(a.s) - needs(b.s) || a.seen - b.seen || a.at - b.at);
802
843
  return rank.map((x) => x.s);
803
844
  }
845
+ /**
846
+ * Everything a Sessions row shows except its age, as plain values: the page redraws a row only when this changes.
847
+ * `reason` is in it, so a Session that keeps `needs-you` for another reason (a decision instead of its Host asking)
848
+ * gets its button and its hint redrawn.
849
+ */
850
+ export function sessionRowShape(s, msg) {
851
+ return [
852
+ s.sessionId,
853
+ s.account,
854
+ s.accountLabel,
855
+ s.family,
856
+ s.title,
857
+ s.label,
858
+ s.status,
859
+ s.reason || '',
860
+ s.cwd,
861
+ s.guessed,
862
+ s.copy,
863
+ Boolean(s.orca),
864
+ s.run || null,
865
+ msg ? msg.status + (msg.needsApproval ? '+approve' : '') : '',
866
+ ];
867
+ }
804
868
  /** How long ago a Session was last active, as a message key and count; null when it has no time at all. */
805
869
  export function sessionAge(s, now) {
806
870
  const ts = Date.parse(s.updatedAt || s.startedAt || '');