sideby 0.28.3 → 0.30.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 (64) hide show
  1. package/dist/build.json +1 -1
  2. package/dist/src/cli/commands.d.ts +12 -0
  3. package/dist/src/cli/commands.js +337 -13
  4. package/dist/src/cli/json-schemas.js +87 -1
  5. package/dist/src/cli/main.js +65 -4
  6. package/dist/src/core/config.d.ts +25 -0
  7. package/dist/src/core/config.js +34 -0
  8. package/dist/src/core/fs-safe.d.ts +22 -1
  9. package/dist/src/core/fs-safe.js +68 -1
  10. package/dist/src/core/handoff-run.d.ts +2 -0
  11. package/dist/src/core/handoff-run.js +12 -6
  12. package/dist/src/core/launch.d.ts +6 -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 +12 -34
  16. package/dist/src/core/network.d.ts +5 -2
  17. package/dist/src/core/network.js +15 -45
  18. package/dist/src/core/run-link.d.ts +6 -1
  19. package/dist/src/core/run-link.js +62 -22
  20. package/dist/src/core/search-catalog.d.ts +1 -1
  21. package/dist/src/core/search-catalog.js +37 -0
  22. package/dist/src/core/session-handoffs.d.ts +22 -0
  23. package/dist/src/core/session-handoffs.js +110 -0
  24. package/dist/src/core/session-hooks.d.ts +33 -0
  25. package/dist/src/core/session-hooks.js +92 -0
  26. package/dist/src/core/session-select.d.ts +18 -3
  27. package/dist/src/core/session-select.js +82 -8
  28. package/dist/src/core/unattended-ended.d.ts +62 -0
  29. package/dist/src/core/unattended-ended.js +275 -0
  30. package/dist/src/core/unattended-pending.d.ts +56 -0
  31. package/dist/src/core/unattended-pending.js +182 -0
  32. package/dist/src/core/unattended-state.d.ts +129 -0
  33. package/dist/src/core/unattended-state.js +373 -0
  34. package/dist/src/core/unattended.d.ts +142 -0
  35. package/dist/src/core/unattended.js +349 -0
  36. package/dist/src/panel/background.js +8 -0
  37. package/dist/src/panel/handler.d.ts +37 -0
  38. package/dist/src/panel/handler.js +156 -2
  39. package/dist/src/panel/i18n.d.ts +97 -0
  40. package/dist/src/panel/i18n.js +194 -0
  41. package/dist/src/panel/page-logic.d.ts +129 -0
  42. package/dist/src/panel/page-logic.js +166 -0
  43. package/dist/src/panel/page-script.js +638 -7
  44. package/dist/src/panel/page-styles.js +69 -0
  45. package/dist/src/panel/page.js +2 -0
  46. package/dist/src/plugins/bus.js +1 -0
  47. package/dist/src/runtime.d.ts +17 -1
  48. package/dist/src/runtime.js +78 -15
  49. package/dist/src/types.d.ts +48 -0
  50. package/dist/src/unattended/hook.d.ts +46 -0
  51. package/dist/src/unattended/hook.js +288 -0
  52. package/package.json +1 -1
  53. package/schemas/config.json +76 -0
  54. package/schemas/messages.json +4 -0
  55. package/schemas/send.json +4 -0
  56. package/schemas/sessions-copy.json +4 -0
  57. package/schemas/sessions-open-run.json +4 -0
  58. package/schemas/sessions.json +7 -0
  59. package/schemas/unattended-defer.json +143 -0
  60. package/schemas/unattended-pending.json +154 -0
  61. package/schemas/unattended.json +291 -0
  62. package/skills/sideby/SKILL.md +3 -2
  63. package/skills/sideby/references/sessions.md +1 -1
  64. package/skills/sideby/references/unattended.md +58 -0
@@ -1295,6 +1295,75 @@ select:is(:hover, :focus) { --chevron: var(--text); }
1295
1295
  .hide-btn.is-on { color: var(--muted); }
1296
1296
  .hide-btn:disabled { opacity: .4; cursor: not-allowed; }
1297
1297
 
1298
+ /* Unattended Mode (spec §3.37): the status card (green while on, amber while paused), the chooser under it, the
1299
+ Schedule's rows of day chips and times, and what sessions left for the user, grouped by session. Parts that come
1300
+ and go are animated from the script (uaPatch); these rules only lay them out. */
1301
+ .ua-badge { gap: 6px; border-color: color-mix(in srgb, var(--ok-bar) 45%, var(--border-strong)); background: color-mix(in srgb, var(--ok-soft) 70%, var(--surface)); color: var(--ok); }
1302
+ .ua-badge .ic { width: 15px; height: 15px; }
1303
+ .ua-badge:hover { border-color: var(--ok-bar); }
1304
+ .ua-status.is-paused { border-color: color-mix(in srgb, var(--warn-bar) 40%, var(--border)); background: color-mix(in srgb, var(--warn-soft) 50%, var(--surface)); }
1305
+ .ua-status.is-paused .hp-status-ic { background: var(--warn-soft); box-shadow: none; color: var(--warn); }
1306
+ .ua-status-rest { font-weight: 500; color: var(--text); }
1307
+ .ua-chooser { max-width: 560px; margin-top: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
1308
+ .ua-chooser-title { font-weight: var(--strong-weight); margin-bottom: 8px; }
1309
+ .ua-opts { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
1310
+ .ua-opt { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 10px; border-radius: calc(var(--ctl-radius) - 2px); cursor: pointer; transition: background-color .12s; }
1311
+ .ua-opt:hover { background: var(--hover); }
1312
+ .ua-opt.is-on { background: var(--accent-soft); }
1313
+ .ua-radio { display: inline-flex; align-items: center; gap: 10px; padding: 0; border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; min-width: 9.5em; text-align: left; }
1314
+ .ua-radio:focus-visible { outline: var(--focus-outline); outline-offset: 3px; border-radius: 4px; }
1315
+ .ua-dot { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--border-strong); background: var(--surface); transition: border-color .12s, box-shadow .12s; }
1316
+ .ua-radio[aria-checked=true] .ua-dot { border-color: var(--accent); box-shadow: inset 0 0 0 3.5px var(--surface), inset 0 0 0 8px var(--accent); }
1317
+ .ua-when { margin-left: auto; font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
1318
+ input.ua-time { width: 4.6em; height: var(--ctl-h-sm); padding: 0 6px; border: 1px solid var(--border-strong); border-radius: var(--ctl-radius); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; transition: border-color .12s, box-shadow .12s; }
1319
+ input.ua-time:hover:not(:disabled) { border-color: var(--btn-hover-border); }
1320
+ input.ua-time:focus { border-color: var(--focus); outline: none; box-shadow: var(--focus-ring); }
1321
+ input.ua-time:invalid { border-color: var(--fail); }
1322
+ input.ua-time:disabled { background: var(--surface-2); color: var(--faint); }
1323
+ input.ua-time::placeholder { color: var(--faint); }
1324
+ .ua-slots, .ua-cover, .ua-items { list-style: none; margin: 0; padding: 0; }
1325
+ .ua-slots { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
1326
+ .ua-slot { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; padding: 10px 12px 10px 16px; border-top: 1px solid var(--border); }
1327
+ .ua-slot:first-child { border-top: 0; }
1328
+ .ua-slot-name { min-width: 7em; font-weight: var(--strong-weight); }
1329
+ .ua-days { display: inline-flex; gap: 4px; }
1330
+ .ua-day { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; transition: background-color .12s, border-color .12s, color .12s; }
1331
+ .ua-day:hover:not(:disabled) { border-color: var(--btn-hover-border); color: var(--text); }
1332
+ .ua-day[aria-pressed=true] { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: var(--strong-weight); }
1333
+ .ua-day:disabled { cursor: default; }
1334
+ .ua-day[aria-pressed=false]:disabled { opacity: .5; }
1335
+ .ua-day:focus-visible { outline: var(--focus-outline); outline-offset: 1px; box-shadow: var(--focus-ring); }
1336
+ .ua-times { display: inline-flex; align-items: center; gap: 6px; }
1337
+ .ua-dash { color: var(--muted); }
1338
+ .ua-night { animation: fade-in .16s ease-out; }
1339
+ .ua-del { margin-left: auto; }
1340
+ .ua-del .ic { width: 15px; height: 15px; }
1341
+ .ua-add-row { margin-top: 10px; }
1342
+ .ua-empty { gap: 8px; }
1343
+ .ua-empty .ic, .ua-first .ic { width: 15px; height: 15px; flex: none; }
1344
+ .ua-first { margin-top: 12px; }
1345
+ #unattended-page > .note:not(.ua-first, .ua-empty) { margin-bottom: 12px; }
1346
+ .ua-sec-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
1347
+ .ua-sec-row .tab-count { margin-left: 4px; vertical-align: 1px; }
1348
+ .ua-groups { display: flex; flex-direction: column; }
1349
+ .ua-group { margin-bottom: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
1350
+ .ua-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
1351
+ .ua-group-who { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
1352
+ .ua-cwd { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
1353
+ .ua-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 12px 12px 12px 16px; border-top: 1px solid var(--border); }
1354
+ .ua-item:first-child { border-top: 0; }
1355
+ .ua-item-meta { display: flex; align-items: center; gap: 8px; grid-column: 1; }
1356
+ .ua-text { grid-column: 1; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
1357
+ .ua-text.is-clamped { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden; }
1358
+ .ua-item-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: flex-start; gap: 10px; }
1359
+ .ua-cover { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
1360
+ .ua-cover li::before { content: "·"; margin-right: 8px; color: var(--faint); }
1361
+ :where(:root[data-width=narrow], :root[data-width=phone]) .ua-item { grid-template-columns: minmax(0, 1fr); }
1362
+ :where(:root[data-width=narrow], :root[data-width=phone]) .ua-item-actions { grid-column: 1; grid-row: auto; }
1363
+ :where(:root[data-width=phone]) .ua-del { margin-left: 0; }
1364
+ :where(:root[data-width=phone]) .ua-badge span { display: none; }
1365
+ @media (prefers-reduced-motion: reduce) { .ua-opt, .ua-dot, .ua-day, input.ua-time { transition: none; } .ua-night { animation: none; } }
1366
+
1298
1367
  /* Command Palette (spec §3.36): a search box over one list; the dialog keeps its top edge while the list changes. */
1299
1368
  .kbd-inline { font: 11px/16px var(--mono); color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-left: 2px; }
1300
1369
  .dialog.dialog-pal { width: min(620px, calc(100vw - 24px)); flex-direction: column; }
@@ -90,6 +90,7 @@ export function renderPage(opts) {
90
90
  </div>
91
91
  </div>
92
92
  <div class="top-actions">
93
+ <button id="ua-badge" class="btn ua-badge" type="button" hidden></button>
93
94
  <button id="update" class="btn update-btn" type="button" hidden></button>
94
95
  <button id="search-btn" class="btn" type="button" aria-haspopup="dialog" aria-label="Search"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4.2-4.2"/></svg><span class="hide-sm" data-i18n="pal.button">Search</span><kbd id="search-kbd" class="kbd-inline hide-sm" aria-hidden="true"></kbd></button>
95
96
  <button id="ask-ai" class="btn" type="button" aria-haspopup="dialog" aria-label="Let AI do it"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9h12a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2zM12 5v4M9.5 13.5v1M14.5 13.5v1"/></svg><span class="hide-sm" data-i18n="ask.button">Let AI do it</span></button>
@@ -106,6 +107,7 @@ export function renderPage(opts) {
106
107
  <section id="handoff-page" class="block page" aria-labelledby="h-handoff" hidden></section>
107
108
  <section id="tuning-page" class="block page" aria-labelledby="h-tuning" hidden></section>
108
109
  <section id="sessions-page" class="block page" aria-labelledby="h-sessions" hidden></section>
110
+ <section id="unattended-page" class="block page" aria-labelledby="h-unattended" hidden></section>
109
111
  <section id="accounts-page" class="block" aria-labelledby="h-accounts">
110
112
  <div class="section-head acct-head"><h2 id="h-accounts"><span data-i18n="acct.title">Accounts</span><span id="acct-count" class="muted small"></span></h2><span id="updated" class="muted small" role="status">Loading…</span></div>
111
113
  <div id="toolbar" class="toolbar" hidden></div>
@@ -3,6 +3,7 @@ export const HOOK_TIMEOUT_MS = {
3
3
  'account.create.before': 10_000,
4
4
  'account.created': 30_000,
5
5
  'doctor.check': 10_000,
6
+ 'unattended.ended': 30_000,
6
7
  };
7
8
  /** Error thrown by a hook, labelled with the Plugin that raised it. */
8
9
  export class HookError extends Error {
@@ -18,8 +18,9 @@ import { type RemoteControlChange, type RemoteControlGroup } from './core/remote
18
18
  import { type Shell, type ShellInitWrite } from './core/shell-init.ts';
19
19
  import { type TuneEntry, type TuneGroup } from './core/tuning.ts';
20
20
  import { type TuneApplyPlan, type TuneChange, type TuneUndoRecord } from './core/tuning-apply.ts';
21
+ import { type UnattendedStatus } from './core/unattended.ts';
21
22
  import { type BuiltinPlugin, type LoadedPlugin, type PluginLoadError } from './plugins/loader.ts';
22
- import type { Account, AccountIdentity, Env, FamilyDef, LoginState, QuotaResult, QuotaSetupPlan, ReadContext, ShareMode, TuningResult, UsageResult } from './types.ts';
23
+ import type { Account, AccountIdentity, Env, FamilyDef, LoginState, QuotaResult, QuotaSetupPlan, ReadContext, ShareMode, TuningResult, UnattendedEndedContext, UsageResult } from './types.ts';
23
24
  export type { AccountIdentity, AccountRefError, DoctorHistory, Shell, ShellInitWrite };
24
25
  /** How `sideby resume` starts the Host (spec §3.15). */
25
26
  export interface ResumeLaunch {
@@ -259,11 +260,25 @@ export interface Runtime {
259
260
  prepareLaunch(ref: string, userArgs: readonly string[], command: 'run' | 'login', opts?: {
260
261
  aiTask?: boolean;
261
262
  ignoreNetwork?: boolean;
263
+ unattended?: boolean;
262
264
  }): Promise<PreparedLaunch>;
263
265
  /** Network Guard's state (spec §3.35): the cached result per address, or with `check` one request per address. */
264
266
  networkStatus(opts?: {
265
267
  check?: boolean;
266
268
  }): Promise<NetworkOverview>;
269
+ /**
270
+ * Unattended Mode (spec §3.37): whether it is on and why, until when, the Schedule, the open Pending Decisions and
271
+ * which Families' sessions it covers. Read fresh on every call.
272
+ */
273
+ unattendedStatus(): Promise<UnattendedStatus>;
274
+ /**
275
+ * Runs every Plugin's `unattended.ended` hook for one stretch that ended; a failing Plugin affects only itself and is
276
+ * returned with its error.
277
+ */
278
+ unattendedEnded(ctx: UnattendedEndedContext): Promise<{
279
+ plugin: string;
280
+ error: string;
281
+ }[]>;
267
282
  /**
268
283
  * The Host and arguments `prepareLaunch` starts from, without reading the Secret File or running `launch.before`
269
284
  * hooks: what a preview may show before the user agrees to start anything.
@@ -280,6 +295,7 @@ export interface Runtime {
280
295
  */
281
296
  resumeLaunch(familyId: string, userArgs: readonly string[], opts?: {
282
297
  ignoreNetwork?: boolean;
298
+ unattended?: boolean;
283
299
  }): Promise<ResumeLaunch>;
284
300
  /**
285
301
  * The Account's Quota. For an Account of a Same Login (spec §3.21) it is the group's freshest reading, with `from`
@@ -14,7 +14,7 @@ import { inboundFindings } from './core/inbound.js';
14
14
  import { mergeDoctorHistory, readDoctorHistory, writeDoctorHistory, } from './core/last-doctor.js';
15
15
  import { accountEnv, beforeDashes, brokenOnPath, launchCommand, prepareLaunch, which, } from './core/launch.js';
16
16
  import { memoStore } from './core/memo-store.js';
17
- import { codexNetworkTrustLine, guardLaunch, guardOn, ipChangedLine, networkHookArgs, networkOverview, networkSettingsLine, } from './core/network.js';
17
+ import { codexNetworkTrustLine, guardLaunch, guardOn, ipChangedLine, networkHookPart, networkOverview, networkSettingsLine, } from './core/network.js';
18
18
  import { resolvePaths } from './core/paths.js';
19
19
  import { choosePick, suggestPickName } from './core/pick-commands.js';
20
20
  import { categoryReader } from './core/project-categories.js';
@@ -23,10 +23,13 @@ import { takeoverLimit } from './core/quota-levels.js';
23
23
  import { remoteControlGroups, turnRemoteControlOff, turnRemoteControlOn, undoRemoteControlOff, } from './core/remote-control.js';
24
24
  import { findResumeRoute } from './core/resume.js';
25
25
  import { SAME_LOGIN_FAMILIES, sameLoginGroups, sharedQuota } from './core/same-login.js';
26
+ import { sessionHookArgs } from './core/session-hooks.js';
26
27
  import { shareMeaning } from './core/share-meaning.js';
27
28
  import { SHELLS, shellInitScript, writeShellInitFile, } from './core/shell-init.js';
28
29
  import { groupSuggestion, MAX_COMPACT_WINDOW, MIN_COMPACT_WINDOW, } from './core/tuning.js';
29
30
  import { applyTune, planTuneApply, readTuneSettings, settingsFileOf, tuneUndoInfo, undoTune, } from './core/tuning-apply.js';
31
+ import { codexUnattendedTrustLine, UNATTENDED_FAMILIES, unattendedFamilyLine, unattendedHookPart, unattendedSettingsLine, unattendedStatus, } from './core/unattended.js';
32
+ import { UNATTENDED_ENV } from './core/unattended-state.js';
30
33
  import { packageVersion } from './core/version.js';
31
34
  import { withClaudeMod } from './families/claude/mod.js';
32
35
  import { BUILTIN_PLUGINS } from './families/index.js';
@@ -83,9 +86,15 @@ export async function createRuntime(opts = {}) {
83
86
  const categories = loaded.categories && categoryReader(loaded.categories.def, loaded.categories.owner);
84
87
  const ignore = new Set(config.ignore ?? []);
85
88
  const now = opts.now ?? (() => new Date());
89
+ /** Adds lines to what a Launch prints before it starts. */
90
+ const addNotice = (p, lines) => {
91
+ const notice = [p.notice, ...lines].filter(Boolean).join('\n');
92
+ if (notice)
93
+ p.notice = notice;
94
+ };
86
95
  /**
87
96
  * Network Guard on a prepared Launch (spec §3.35): refuses it (a UserError) when the Egress is wrong or cannot be
88
- * told, and for a session (`hooks`) adds the variables and hook arguments that keep checking inside it.
97
+ * told, and for a session (`hooks`) adds the variables its hooks read and returns the hooks that keep checking.
89
98
  */
90
99
  const guardPrepared = async (p, hooks) => {
91
100
  const g = await guardLaunch({
@@ -99,23 +108,64 @@ export async function createRuntime(opts = {}) {
99
108
  now,
100
109
  });
101
110
  if (!g)
102
- return;
111
+ return null;
103
112
  const lines = [ipChangedLine(g.verdict, p.env)];
113
+ let part = null;
104
114
  if (hooks) {
105
115
  const own = p.family.id === 'claude' && hasOption(p.args, ['--settings']);
106
116
  if (own)
107
117
  lines.push(networkSettingsLine(p.env));
108
118
  else {
109
119
  Object.assign(p.env, g.env);
110
- p.networkArgs = await networkHookArgs(p.family.id, paths.stateDir);
111
- p.args = beforeDashes(p.args, p.networkArgs);
120
+ part = networkHookPart();
112
121
  if (p.family.id === 'codex')
113
122
  lines.push(await codexNetworkTrustLine(paths.stateDir, p.account.ref, p.env));
114
123
  }
115
124
  }
116
- const notice = [p.notice, ...lines].filter(Boolean).join('\n');
117
- if (notice)
118
- p.notice = notice;
125
+ addNotice(p, lines);
126
+ return part;
127
+ };
128
+ /**
129
+ * Unattended Mode on a session sideby starts (spec §3.37): its hook once the config has an `unattended` section, or
130
+ * when the run asks for it (`--unattended`, which also marks the session as on whatever the Schedule says).
131
+ */
132
+ const unattendedPrepared = async (p, asked) => {
133
+ if (asked)
134
+ p.env[UNATTENDED_ENV] = '1';
135
+ if (!asked && config.unattended === undefined)
136
+ return null;
137
+ if (!UNATTENDED_FAMILIES.includes(p.family.id)) {
138
+ if (asked)
139
+ addNotice(p, [unattendedFamilyLine(p.family.id, p.env)]);
140
+ return null;
141
+ }
142
+ if (p.family.id === 'claude' && hasOption(p.args, ['--settings'])) {
143
+ addNotice(p, [unattendedSettingsLine(p.env)]);
144
+ return null;
145
+ }
146
+ if (p.family.id === 'codex')
147
+ addNotice(p, [await codexUnattendedTrustLine(paths.stateDir, p.account.ref, p.env)]);
148
+ return unattendedHookPart();
149
+ };
150
+ /** Puts every session hook into the Launch's arguments: one `--settings` for Claude, `-c hooks.*` for Codex. */
151
+ const addSessionHooks = async (p, list) => {
152
+ const parts = list.filter((x) => x !== null);
153
+ const args = await sessionHookArgs(p.family.id, paths.stateDir, parts);
154
+ if (!args.length)
155
+ return;
156
+ p.sessionHookArgs = args;
157
+ if (parts.some((x) => x.id === 'network'))
158
+ p.networkArgs = args;
159
+ p.args = beforeDashes(p.args, args);
160
+ };
161
+ /** Network Guard and Unattended Mode on a prepared Launch, in that order; hooks only for a session (`run`). */
162
+ const sessionReady = async (p, session, o) => {
163
+ const parts = [];
164
+ if (!o.ignoreNetwork)
165
+ parts.push(await guardPrepared(p, session));
166
+ if (session)
167
+ parts.push(await unattendedPrepared(p, Boolean(o.unattended)));
168
+ await addSessionHooks(p, parts);
119
169
  };
120
170
  const familyOf = (id) => {
121
171
  const f = families.get(id);
@@ -660,8 +710,10 @@ export async function createRuntime(opts = {}) {
660
710
  async prepareLaunch(ref, userArgs, command, opts = {}) {
661
711
  // A Handoff chain can run for hours: an Account's arguments changed meanwhile apply to its next start.
662
712
  const fresh = await loadConfig(paths.configFile).catch(() => null);
663
- if (fresh)
713
+ if (fresh) {
664
714
  config.accounts = fresh.accounts;
715
+ config.unattended = fresh.unattended;
716
+ }
665
717
  const all = await accounts();
666
718
  const inputs = launchInputs(ref, all, userArgs, command);
667
719
  const p = await prepareLaunch({
@@ -678,11 +730,19 @@ export async function createRuntime(opts = {}) {
678
730
  env: p.env,
679
731
  stateDir: paths.stateDir,
680
732
  });
681
- // Network Guard (spec §3.35): last, on the environment the Host gets, so the check takes the Host's route.
682
- if (!opts.ignoreNetwork)
683
- await guardPrepared(p, command === 'run');
733
+ // Network Guard (spec §3.35) and Unattended Mode (§3.37): last, on the environment the Host gets, so the check
734
+ // takes the Host's route.
735
+ await sessionReady(p, command === 'run', opts);
684
736
  return p;
685
737
  },
738
+ async unattendedStatus() {
739
+ return unattendedStatus({ paths, families: [...families.keys()], env, now: now() });
740
+ },
741
+ async unattendedEnded(ctx) {
742
+ return (await bus.runIsolated('unattended.ended', '', ctx))
743
+ .filter((r) => r.error)
744
+ .map((r) => ({ plugin: r.plugin, error: r.error.message }));
745
+ },
686
746
  async networkStatus(o = {}) {
687
747
  return networkOverview({
688
748
  accounts: await accounts(),
@@ -705,15 +765,18 @@ export async function createRuntime(opts = {}) {
705
765
  if (!family.resumedSession || !family.sessionWrittenAt)
706
766
  throw new UserError(`${family.title} sessions cannot be routed; start an account yourself with \`sideby run <account> -- …\``);
707
767
  const host = { family, bin: family.bin, args: [...userArgs], env };
708
- // The Host run unchanged still talks to its vendor: Network Guard checks it as the Main Account (spec §3.35).
768
+ // The Host run unchanged still talks to its vendor: Network Guard checks it as the Main Account (spec §3.35), and
769
+ // it is a session sideby starts, so Unattended Mode covers it (§3.37).
709
770
  const guarded = async (h) => {
710
- if (ro.ignoreNetwork || !guardOn(config, h.env))
771
+ const net = !ro.ignoreNetwork && guardOn(config, h.env);
772
+ const unattended = Boolean(ro.unattended) || config.unattended !== undefined;
773
+ if (!net && !unattended)
711
774
  return h;
712
775
  const main = (await accounts()).find((a) => a.family === family.id && a.isMain);
713
776
  if (!main)
714
777
  return h;
715
778
  const p = { ...h, account: main, args: [...h.args], env: { ...h.env } };
716
- await guardPrepared(p, true);
779
+ await sessionReady(p, true, { ignoreNetwork: !net, ...(ro.unattended ? { unattended: true } : {}) });
717
780
  return {
718
781
  family: p.family,
719
782
  bin: p.bin,
@@ -614,6 +614,50 @@ export interface DoctorContext {
614
614
  export interface HookFilter {
615
615
  family?: string;
616
616
  }
617
+ /** A question the model was not allowed to ask, or an action it left undone, during Unattended Mode (spec §3.37). */
618
+ export interface PendingDecisionInfo {
619
+ id: string;
620
+ /** When it was kept (ISO). */
621
+ at: string;
622
+ /**
623
+ * `question`: the Host's ask tool was refused; `permission`: a permission request Claude Code was about to show was
624
+ * refused; `deferred`: the model ran `sideby unattended defer`.
625
+ */
626
+ kind: 'question' | 'permission' | 'deferred';
627
+ family: string;
628
+ /** The Account the session ran as. */
629
+ account?: string;
630
+ sessionId?: string;
631
+ cwd?: string;
632
+ /** The subagent a permission request came from, when one did (Claude Code's `agent_id`, `agent_type`). */
633
+ agentId?: string;
634
+ agentType?: string;
635
+ /** The question with its options, the tool and what it was to do, or the deferred text (at most 4000 characters). */
636
+ text: string;
637
+ doneAt?: string;
638
+ }
639
+ /**
640
+ * `unattended.ended`: one stretch of Unattended Mode, for the whole computer, has ended (spec §3.37). Emitted by the
641
+ * first sideby process that notices, at least once per stretch (see `id`); it belongs to no Family, so a handler with a
642
+ * `family` filter never gets it. sideby itself sends no notification: a Plugin may pass this on to the user's own notification tool.
643
+ */
644
+ export interface UnattendedEndedContext {
645
+ /**
646
+ * The same each time this event is delivered. Delivery is at least once: an event whose delivery did not finish
647
+ * (sideby was ended while the plugins ran, say) is delivered again by a later look, so skip an `id` you have seen.
648
+ */
649
+ id: string;
650
+ /** When the stretch began (ISO). */
651
+ startedAt: string;
652
+ /** When it ended (ISO). */
653
+ endedAt: string;
654
+ /** What turned it on: a Slot of the Schedule, or the user. */
655
+ reason: 'slot' | 'manual';
656
+ /** True when it was noticed more than twelve hours after it ended (no sideby process ran meanwhile). */
657
+ late?: true;
658
+ /** The Pending Decisions kept during the stretch that are still open. */
659
+ pending: PendingDecisionInfo[];
660
+ }
617
661
  export interface HookEvents {
618
662
  'launch.before': {
619
663
  ctx: LaunchContext;
@@ -631,6 +675,10 @@ export interface HookEvents {
631
675
  ctx: DoctorContext;
632
676
  result: CheckResult[] | undefined;
633
677
  };
678
+ 'unattended.ended': {
679
+ ctx: UnattendedEndedContext;
680
+ result: void;
681
+ };
634
682
  }
635
683
  export type HookEvent = keyof HookEvents;
636
684
  export type HookHandler<E extends HookEvent> = (ctx: HookEvents[E]['ctx']) => HookEvents[E]['result'] | Promise<HookEvents[E]['result']>;
@@ -0,0 +1,46 @@
1
+ import { type UnattendedState } from '../core/unattended-state.ts';
2
+ export declare const UNATTENDED_HOOK_COMMAND = "sideby unattended-hook";
3
+ /** The tool each Host's model asks the user with. */
4
+ export declare const ASK_TOOLS: Readonly<Record<string, string>>;
5
+ type Env = Record<string, string | undefined>;
6
+ export interface UnattendedHookDeps {
7
+ now?: () => Date;
8
+ }
9
+ /**
10
+ * The question as the user should read it later: each question (with its short header) and its options' labels.
11
+ * Claude's `AskUserQuestion` and Codex's `request_user_input` both take a `questions` list; anything else is kept as
12
+ * the tool's input.
13
+ */
14
+ export declare function questionText(input: Record<string, unknown>): string;
15
+ /** What the model reads instead of an answer. */
16
+ export declare function questionReason(state: UnattendedState, now: Date, zh: boolean, kept: boolean): string;
17
+ /**
18
+ * The program a command runs, by its file name only: the first word after `NAME=value` settings and wrappers such as
19
+ * `sudo` and `env`. Undefined when it cannot be told plainly (a quote, a variable, a subshell, anything but a name).
20
+ * Nothing else of the command is kept: its arguments can hold a token in any form.
21
+ */
22
+ export declare function commandProgram(command: string): string | undefined;
23
+ /**
24
+ * What a refused permission request is kept as, from a short list of fields per tool and never the whole input (an
25
+ * MCP tool's input can carry a header with a token): for Bash the program alone and the model's own description of
26
+ * the command, never its arguments (the whole command stays in the session's own record, reached through "back to
27
+ * the session"); the file of Read, Write, Edit, MultiEdit and NotebookEdit; the host WebFetch was to open; for any
28
+ * other tool its name only.
29
+ */
30
+ export declare function permissionText(tool: string, input: Record<string, unknown>): string;
31
+ /** What the model reads instead of the permission prompt Claude Code would have shown. */
32
+ export declare function permissionReason(state: UnattendedState, now: Date, kept: boolean): string;
33
+ /**
34
+ * Returns the exit code: 0 lets the Host go on, 2 refuses the tool call (the reason is written to `err`). A permission
35
+ * request is refused with exit 0 and the decision written to `out`. Errors before the decision write nothing and
36
+ * exit 0; once it is a refusal, it is answered as one whatever happens to the record.
37
+ */
38
+ export declare function runUnattendedHook(argv: readonly string[], env: Env, input: AsyncIterable<string | Uint8Array> | string, io: {
39
+ out: {
40
+ write(s: string): unknown;
41
+ };
42
+ err: {
43
+ write(s: string): unknown;
44
+ };
45
+ }, deps?: UnattendedHookDeps): Promise<number>;
46
+ export {};