sideby 0.19.0 → 0.20.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 (161) hide show
  1. package/README.md +7 -4
  2. package/ai-tasks.json +28 -0
  3. package/dist/build.json +1 -1
  4. package/dist/src/cli/commands.d.ts +22 -1
  5. package/dist/src/cli/commands.js +815 -21
  6. package/dist/src/cli/format.d.ts +4 -0
  7. package/dist/src/cli/format.js +42 -4
  8. package/dist/src/cli/json-schemas.js +334 -4
  9. package/dist/src/cli/main.js +159 -13
  10. package/dist/src/core/accounts.d.ts +6 -0
  11. package/dist/src/core/accounts.js +12 -0
  12. package/dist/src/core/autostart.d.ts +11 -0
  13. package/dist/src/core/autostart.js +32 -5
  14. package/dist/src/core/browser-profiles.d.ts +23 -2
  15. package/dist/src/core/browser-profiles.js +148 -37
  16. package/dist/src/core/claude-settings-file.d.ts +18 -0
  17. package/dist/src/core/claude-settings-file.js +52 -3
  18. package/dist/src/core/config.d.ts +5 -0
  19. package/dist/src/core/config.js +12 -1
  20. package/dist/src/core/edit-settings.d.ts +7 -0
  21. package/dist/src/core/edit-settings.js +10 -5
  22. package/dist/src/core/file-memo.js +26 -4
  23. package/dist/src/core/history-group.d.ts +28 -0
  24. package/dist/src/core/history-group.js +47 -0
  25. package/dist/src/core/history-index.d.ts +145 -0
  26. package/dist/src/core/history-index.js +447 -0
  27. package/dist/src/core/history-project.d.ts +13 -0
  28. package/dist/src/core/history-project.js +87 -0
  29. package/dist/src/core/history.d.ts +210 -0
  30. package/dist/src/core/history.js +952 -0
  31. package/dist/src/core/inbound.d.ts +62 -0
  32. package/dist/src/core/inbound.js +215 -0
  33. package/dist/src/core/launch.d.ts +9 -1
  34. package/dist/src/core/launch.js +58 -24
  35. package/dist/src/core/live-sessions-copy.d.ts +5 -0
  36. package/dist/src/core/live-sessions-copy.js +46 -0
  37. package/dist/src/core/live-sessions-procs.d.ts +89 -0
  38. package/dist/src/core/live-sessions-procs.js +296 -0
  39. package/dist/src/core/live-sessions-title.d.ts +28 -0
  40. package/dist/src/core/live-sessions-title.js +80 -0
  41. package/dist/src/core/live-sessions.d.ts +68 -0
  42. package/dist/src/core/live-sessions.js +163 -0
  43. package/dist/src/core/login-check.d.ts +15 -0
  44. package/dist/src/core/login-check.js +32 -0
  45. package/dist/src/core/messages.d.ts +83 -0
  46. package/dist/src/core/messages.js +433 -0
  47. package/dist/src/core/project-categories.d.ts +14 -0
  48. package/dist/src/core/project-categories.js +48 -0
  49. package/dist/src/core/quota-fetch.d.ts +3 -3
  50. package/dist/src/core/quota-fetch.js +5 -5
  51. package/dist/src/core/quota-levels.d.ts +5 -0
  52. package/dist/src/core/quota-levels.js +5 -0
  53. package/dist/src/core/remote-control.d.ts +2 -0
  54. package/dist/src/core/remote-control.js +34 -59
  55. package/dist/src/core/run-link.d.ts +76 -0
  56. package/dist/src/core/run-link.js +245 -0
  57. package/dist/src/core/same-login.d.ts +4 -3
  58. package/dist/src/core/same-login.js +10 -7
  59. package/dist/src/core/session-select.d.ts +31 -0
  60. package/dist/src/core/session-select.js +44 -0
  61. package/dist/src/families/browser.d.ts +7 -18
  62. package/dist/src/families/browser.js +19 -8
  63. package/dist/src/families/claude/deliver.d.ts +2 -0
  64. package/dist/src/families/claude/deliver.js +43 -0
  65. package/dist/src/families/claude/history.d.ts +2 -0
  66. package/dist/src/families/claude/history.js +192 -0
  67. package/dist/src/families/claude/live-sessions.d.ts +13 -0
  68. package/dist/src/families/claude/live-sessions.js +117 -0
  69. package/dist/src/families/claude/messaging.d.ts +69 -0
  70. package/dist/src/families/claude/messaging.js +165 -0
  71. package/dist/src/families/claude/mod.d.ts +26 -0
  72. package/dist/src/families/claude/mod.js +105 -0
  73. package/dist/src/families/claude/session-files.d.ts +21 -0
  74. package/dist/src/families/claude/session-files.js +54 -0
  75. package/dist/src/families/codex/deliver.d.ts +5 -0
  76. package/dist/src/families/codex/deliver.js +76 -0
  77. package/dist/src/families/codex/history.d.ts +7 -0
  78. package/dist/src/families/codex/history.js +174 -0
  79. package/dist/src/families/codex/index.js +2 -0
  80. package/dist/src/families/codex/live-sessions.d.ts +12 -0
  81. package/dist/src/families/codex/live-sessions.js +193 -0
  82. package/dist/src/families/codex/quota.d.ts +3 -0
  83. package/dist/src/families/codex/quota.js +123 -0
  84. package/dist/src/families/codex/rate-limits.js +2 -0
  85. package/dist/src/families/codex/rollout.js +1 -1
  86. package/dist/src/families/grok/browser.d.ts +3 -0
  87. package/dist/src/families/grok/browser.js +5 -0
  88. package/dist/src/families/grok/history.d.ts +2 -0
  89. package/dist/src/families/grok/history.js +157 -0
  90. package/dist/src/families/grok/live-sessions.d.ts +4 -0
  91. package/dist/src/families/grok/live-sessions.js +80 -0
  92. package/dist/src/families/grok/login-key.d.ts +14 -0
  93. package/dist/src/families/grok/login-key.js +37 -0
  94. package/dist/src/families/history.d.ts +20 -0
  95. package/dist/src/families/history.js +81 -0
  96. package/dist/src/families/live-sessions.d.ts +26 -0
  97. package/dist/src/families/live-sessions.js +9 -0
  98. package/dist/src/families/login-keys.js +5 -1
  99. package/dist/src/families/messaging.d.ts +27 -0
  100. package/dist/src/families/messaging.js +6 -0
  101. package/dist/src/families/pi/history.d.ts +2 -0
  102. package/dist/src/families/pi/history.js +124 -0
  103. package/dist/src/families/pi/live-sessions.d.ts +2 -0
  104. package/dist/src/families/pi/live-sessions.js +70 -0
  105. package/dist/src/families/shared/history-text.d.ts +65 -0
  106. package/dist/src/families/shared/history-text.js +261 -0
  107. package/dist/src/menubar/hotkey.d.ts +86 -0
  108. package/dist/src/menubar/hotkey.js +159 -0
  109. package/dist/src/menubar/script.d.ts +2 -0
  110. package/dist/src/menubar/script.js +118 -22
  111. package/dist/src/menubar/snapshot.d.ts +8 -4
  112. package/dist/src/menubar/snapshot.js +45 -13
  113. package/dist/src/menubar/strings.d.ts +24 -6
  114. package/dist/src/menubar/strings.js +24 -6
  115. package/dist/src/panel/handler.d.ts +69 -0
  116. package/dist/src/panel/handler.js +686 -15
  117. package/dist/src/panel/i18n.d.ts +304 -3
  118. package/dist/src/panel/i18n.js +669 -67
  119. package/dist/src/panel/orca.d.ts +48 -0
  120. package/dist/src/panel/orca.js +153 -0
  121. package/dist/src/panel/page-logic.d.ts +255 -13
  122. package/dist/src/panel/page-logic.js +483 -1
  123. package/dist/src/panel/page-script.js +2265 -207
  124. package/dist/src/panel/page-styles.js +404 -32
  125. package/dist/src/panel/page.js +1 -0
  126. package/dist/src/plugins/account-script.js +61 -27
  127. package/dist/src/plugins/check.js +16 -4
  128. package/dist/src/plugins/loader.d.ts +8 -1
  129. package/dist/src/plugins/loader.js +72 -7
  130. package/dist/src/runtime.d.ts +5 -0
  131. package/dist/src/runtime.js +27 -5
  132. package/dist/src/types.d.ts +116 -1
  133. package/dist/testing/index.d.ts +5 -0
  134. package/dist/testing/index.js +5 -0
  135. package/mods/claude/.claude-plugin/plugin.json +7 -0
  136. package/mods/claude/hooks/hooks.json +1 -0
  137. package/mods/claude/hooks/register.js +261 -0
  138. package/package.json +5 -2
  139. package/schemas/autostart.json +74 -1
  140. package/schemas/browser-set.json +110 -0
  141. package/schemas/browser.json +22 -2
  142. package/schemas/config.json +26 -1
  143. package/schemas/history-index.json +209 -0
  144. package/schemas/history-projects.json +133 -0
  145. package/schemas/history-show.json +275 -0
  146. package/schemas/history.json +410 -0
  147. package/schemas/menubar-hotkey.json +139 -0
  148. package/schemas/menubar-snapshot.json +36 -2
  149. package/schemas/menubar.json +74 -1
  150. package/schemas/messages-inbound.json +258 -0
  151. package/schemas/messages.json +164 -0
  152. package/schemas/send.json +165 -0
  153. package/schemas/sessions-copy.json +113 -0
  154. package/schemas/sessions-open-run.json +97 -0
  155. package/schemas/sessions.json +237 -0
  156. package/skills/sideby/SKILL.md +10 -5
  157. package/skills/sideby/references/accounts.md +11 -0
  158. package/skills/sideby/references/ai-tasks.md +17 -1
  159. package/skills/sideby/references/panel.md +6 -4
  160. package/skills/sideby/references/quota.md +2 -2
  161. package/skills/sideby/references/sessions.md +79 -0
@@ -0,0 +1,62 @@
1
+ import type { Account, CheckResult, ReadContext } from '../types.ts';
2
+ export declare const INBOUND_KEY = "crossSessionInbound";
3
+ /**
4
+ * `accept`, `hold`, `refuse`: the key holds that value; `default`: no key, so Claude Code's default decides (a session
5
+ * in bypass permission mode holds Messages); `other`: a value sideby does not know; `missing`: no `settings.json`;
6
+ * `blocked`: see `reason`.
7
+ */
8
+ export type InboundState = 'accept' | 'hold' | 'refuse' | 'default' | 'other' | 'missing' | 'blocked';
9
+ export interface InboundGroup {
10
+ /** The real settings file (canonical); for `missing`, where it would be. */
11
+ file: string;
12
+ /** Refs of the Accounts whose `settings.json` is `file`, in discovery order. */
13
+ accounts: string[];
14
+ state: InboundState;
15
+ /** For `blocked`, `missing` and `refuse`: why, and what to do. */
16
+ reason?: string;
17
+ /** sideby set it here and can put the earlier value back. */
18
+ undo: boolean;
19
+ }
20
+ export interface InboundChange {
21
+ ok: boolean;
22
+ results: {
23
+ file: string;
24
+ accounts: string[];
25
+ ok: boolean;
26
+ message: string;
27
+ }[];
28
+ message: string;
29
+ }
30
+ export declare function inboundStateOf(v: unknown): InboundState;
31
+ /** Every Claude Account's setting, grouped by the file it lives in. Reads only the one key; writes nothing. */
32
+ export declare function inboundGroups(accounts: readonly Account[], ctx: ReadContext): Promise<InboundGroup[]>;
33
+ /** The setting of one Account (`default` when it cannot be read: Claude Code then uses its default as well). */
34
+ export declare function inboundOf(account: Account, ctx: ReadContext): Promise<InboundState>;
35
+ /**
36
+ * The settings files whose sessions hold a Message for approval (ADR-0045): set to `hold`, or not set while one of
37
+ * its Accounts starts in bypass permission mode (doctor's `messages.inbound-held`). Reads what doctor reads.
38
+ */
39
+ export declare function waitingFiles(groups: readonly InboundGroup[], accounts: readonly Account[], starts: (a: Account) => readonly (readonly string[])[]): Promise<Set<string>>;
40
+ /** The groups `accept` would change: not set, or `hold`. A `refuse` or a value sideby does not know is left alone. */
41
+ export declare function groupsToAccept(groups: readonly InboundGroup[]): InboundGroup[];
42
+ /** The groups `accept` leaves alone and why: refused, unknown, blocked or without a settings file. */
43
+ export declare function inboundLeftAlone(groups: readonly InboundGroup[]): InboundGroup[];
44
+ /** Groups sideby can put back: it wrote there and the key still holds what it wrote. */
45
+ export declare function inboundGroupsToUndo(groups: readonly InboundGroup[]): InboundGroup[];
46
+ /**
47
+ * What `accept` or `undo` says when `groups` leave it nothing to do. Pure: the preview path uses it, so a run without
48
+ * `--yes` never writes, even when a file changes after this read. A run that changes nothing is not `ok` (exit 1).
49
+ */
50
+ export declare function inboundNothingToDo(action: 'accept' | 'undo', groups: readonly InboundGroup[]): InboundChange;
51
+ /** Sets `crossSessionInbound` to `accept` in every group `groupsToAccept` names, remembering each old value. */
52
+ export declare function acceptInbound(accounts: readonly Account[], ctx: ReadContext): Promise<InboundChange>;
53
+ /** Puts back what each file had before `acceptInbound`, only while the key still holds what sideby wrote. */
54
+ export declare function undoInbound(accounts: readonly Account[], ctx: ReadContext): Promise<InboundChange>;
55
+ /**
56
+ * Doctor's warning (spec §3.32 step 2): the Account starts its sessions in bypass permission mode (one of `starts`,
57
+ * its short commands' and config arguments, or `permissions.defaultMode` in its settings) while
58
+ * `crossSessionInbound` is not `accept`, so a Message from another session waits for approval and is dropped after
59
+ * about five minutes. Not fixable by `doctor --fix`: the file may be shared with other Accounts, so the fix is the
60
+ * previewed `sideby messages inbound accept`. Reads only `crossSessionInbound` and `permissions.defaultMode`.
61
+ */
62
+ export declare function inboundFindings(account: Account, starts: readonly (readonly string[])[]): Promise<CheckResult[]>;
@@ -0,0 +1,215 @@
1
+ // Cross-session inbound (spec §3.32 step 2, ADR-0040): reads and writes one key, `crossSessionInbound`, of each
2
+ // Claude Account's `settings.json`. It decides what a session does with a Message from another session: `accept`
3
+ // shows it at once, `hold` waits for the user to approve it in the session's terminal (and drops it after about five
4
+ // minutes), `refuse` drops it. Writes follow Remote Control's rules (spec §3.22): a preview first, `writeIfUnchanged`,
5
+ // every other key kept, a shared file written once at its real target, never a settings.json created, and undo only
6
+ // while the key still holds what sideby wrote. A `refuse` the user chose is never changed.
7
+ import { rm } from 'node:fs/promises';
8
+ import { argsBypass } from '../families/claude/messaging.js';
9
+ import { isObj, keyRecordPath, locate, readKeyRecord, readObject, settingsFileGroups, writeKeyRecord, writeSettingsKey, } from './claude-settings-file.js';
10
+ export const INBOUND_KEY = 'crossSessionInbound';
11
+ const RECORDS = 'cross-session-inbound';
12
+ const NO_SETTINGS = 'this account has no settings.json; run `sideby doctor --fix` so it shares the main one, then try again';
13
+ const REFUSE = 'you set it to refuse, so sideby leaves it alone; Messages to these sessions need pasting. To get them, set "crossSessionInbound": "accept" in this file yourself';
14
+ const OTHER = 'it holds a value sideby does not know, so sideby leaves it alone; set "crossSessionInbound" to "accept" in this file yourself, or remove the key and run `sideby messages inbound accept` again';
15
+ export function inboundStateOf(v) {
16
+ if (v === undefined)
17
+ return 'default';
18
+ return v === 'accept' || v === 'hold' || v === 'refuse' ? v : 'other';
19
+ }
20
+ async function readRecord(ctx, file) {
21
+ const r = await readKeyRecord(ctx.stateDir, RECORDS, file);
22
+ return r && typeof r.wrote === 'string' && typeof r.hadKey === 'boolean'
23
+ ? r
24
+ : null;
25
+ }
26
+ /** Every Claude Account's setting, grouped by the file it lives in. Reads only the one key; writes nothing. */
27
+ export async function inboundGroups(accounts, ctx) {
28
+ const out = [];
29
+ for (const { file, accounts: refs, where } of await settingsFileGroups(accounts)) {
30
+ const group = { file, accounts: refs, state: 'missing', undo: false };
31
+ out.push(group);
32
+ if (where.broken) {
33
+ group.state = 'blocked';
34
+ group.reason =
35
+ 'settings.json is a link to a file that does not exist; run `sideby doctor` to see how to fix it';
36
+ }
37
+ else if (!where.exists)
38
+ group.reason = NO_SETTINGS;
39
+ else {
40
+ const read = await readObject(where.file);
41
+ if ('error' in read) {
42
+ group.state = 'blocked';
43
+ group.reason = `settings.json cannot be changed safely: ${read.error}. Fix or move the file, then try again`;
44
+ }
45
+ else {
46
+ group.state = inboundStateOf(read.obj[INBOUND_KEY]);
47
+ if (group.state === 'refuse')
48
+ group.reason = REFUSE;
49
+ if (group.state === 'other')
50
+ group.reason = OTHER;
51
+ const record = await readRecord(ctx, where.file);
52
+ group.undo = record !== null && read.obj[INBOUND_KEY] === record.wrote;
53
+ }
54
+ }
55
+ }
56
+ return out;
57
+ }
58
+ /** The setting of one Account (`default` when it cannot be read: Claude Code then uses its default as well). */
59
+ export async function inboundOf(account, ctx) {
60
+ const [g] = await inboundGroups([account], ctx);
61
+ return g?.state ?? 'default';
62
+ }
63
+ /**
64
+ * The settings files whose sessions hold a Message for approval (ADR-0045): set to `hold`, or not set while one of
65
+ * its Accounts starts in bypass permission mode (doctor's `messages.inbound-held`). Reads what doctor reads.
66
+ */
67
+ export async function waitingFiles(groups, accounts, starts) {
68
+ const out = new Set();
69
+ for (const g of groups) {
70
+ if (g.state === 'hold')
71
+ out.add(g.file);
72
+ if (g.state !== 'default')
73
+ continue;
74
+ for (const a of accounts.filter((x) => g.accounts.includes(x.ref)))
75
+ if ((await inboundFindings(a, starts(a))).length) {
76
+ out.add(g.file);
77
+ break;
78
+ }
79
+ }
80
+ return out;
81
+ }
82
+ /** The groups `accept` would change: not set, or `hold`. A `refuse` or a value sideby does not know is left alone. */
83
+ export function groupsToAccept(groups) {
84
+ return groups.filter((g) => g.state === 'default' || g.state === 'hold');
85
+ }
86
+ /** The groups `accept` leaves alone and why: refused, unknown, blocked or without a settings file. */
87
+ export function inboundLeftAlone(groups) {
88
+ return groups.filter((g) => g.state !== 'accept' && g.state !== 'default' && g.state !== 'hold');
89
+ }
90
+ const leftAloneLines = (groups) => inboundLeftAlone(groups).map((g) => `${g.accounts.join(', ')}: ${g.reason}`);
91
+ /** Groups sideby can put back: it wrote there and the key still holds what it wrote. */
92
+ export function inboundGroupsToUndo(groups) {
93
+ return groups.filter((g) => g.undo);
94
+ }
95
+ /**
96
+ * What `accept` or `undo` says when `groups` leave it nothing to do. Pure: the preview path uses it, so a run without
97
+ * `--yes` never writes, even when a file changes after this read. A run that changes nothing is not `ok` (exit 1).
98
+ */
99
+ export function inboundNothingToDo(action, groups) {
100
+ if (action === 'undo')
101
+ return { ok: false, results: [], message: 'There is nothing from sideby to undo.' };
102
+ if (!groups.length)
103
+ return { ok: false, results: [], message: 'No Claude accounts found, so nothing was changed.' };
104
+ const left = leftAloneLines(groups);
105
+ return {
106
+ ok: false,
107
+ results: [],
108
+ message: left.length
109
+ ? `Nothing was changed. ${left.join('. ')}.`
110
+ : 'Claude sessions already show Messages from other sessions at once (already accept, nothing changed).',
111
+ };
112
+ }
113
+ /** Sets `crossSessionInbound` to `accept` in every group `groupsToAccept` names, remembering each old value. */
114
+ export async function acceptInbound(accounts, ctx) {
115
+ const groups = await inboundGroups(accounts, ctx);
116
+ const todo = groupsToAccept(groups);
117
+ if (todo.length === 0)
118
+ return inboundNothingToDo('accept', groups);
119
+ const results = [];
120
+ for (const g of todo) {
121
+ let before = { hadKey: false };
122
+ const failed = await writeSettingsKey(g.file, (obj) => {
123
+ before = INBOUND_KEY in obj ? { hadKey: true, previous: obj[INBOUND_KEY] } : { hadKey: false };
124
+ obj[INBOUND_KEY] = 'accept';
125
+ return obj;
126
+ }, (obj) => obj[INBOUND_KEY] === undefined || obj[INBOUND_KEY] === 'hold'
127
+ ? null
128
+ : obj[INBOUND_KEY] === 'accept'
129
+ ? 'It was set to accept meanwhile; nothing changed.'
130
+ : 'It was changed meanwhile, so sideby left it alone.');
131
+ if (failed) {
132
+ results.push({ file: g.file, accounts: g.accounts, ok: false, message: failed });
133
+ continue;
134
+ }
135
+ const record = { file: g.file, ...before, wrote: 'accept', at: new Date().toISOString() };
136
+ await writeKeyRecord(ctx.stateDir, RECORDS, g.file, record);
137
+ results.push({ file: g.file, accounts: g.accounts, ok: true, message: 'Set to accept.' });
138
+ }
139
+ const ok = results.every((r) => r.ok);
140
+ const left = leftAloneLines(groups);
141
+ return {
142
+ ok,
143
+ results,
144
+ message: (ok
145
+ ? 'Done. New sessions show Messages from other sessions at once, also in bypass permission mode; restart sessions that are already running. Undo it with `sideby messages inbound undo`.'
146
+ : 'Some files could not be changed; see each line.') +
147
+ (left.length ? ` Left alone: ${left.join('. ')}.` : ''),
148
+ };
149
+ }
150
+ /** Puts back what each file had before `acceptInbound`, only while the key still holds what sideby wrote. */
151
+ export async function undoInbound(accounts, ctx) {
152
+ const groups = await inboundGroups(accounts, ctx);
153
+ const todo = inboundGroupsToUndo(groups);
154
+ if (todo.length === 0)
155
+ return inboundNothingToDo('undo', groups);
156
+ const results = [];
157
+ for (const g of todo) {
158
+ const record = await readRecord(ctx, g.file);
159
+ if (!record)
160
+ continue;
161
+ const failed = await writeSettingsKey(g.file, (obj) => {
162
+ if (!record.hadKey)
163
+ delete obj[INBOUND_KEY];
164
+ else
165
+ obj[INBOUND_KEY] = record.previous;
166
+ return obj;
167
+ }, (obj) => obj[INBOUND_KEY] === record.wrote
168
+ ? null
169
+ : 'The setting was changed after sideby set it, so it was left alone.');
170
+ if (!failed)
171
+ await rm(keyRecordPath(ctx.stateDir, RECORDS, g.file), { force: true });
172
+ results.push({ file: g.file, accounts: g.accounts, ok: !failed, message: failed ?? 'Put back.' });
173
+ }
174
+ const ok = results.length > 0 && results.every((r) => r.ok);
175
+ return {
176
+ ok,
177
+ results,
178
+ message: ok
179
+ ? 'Undone. New sessions go back to the previous setting.'
180
+ : 'Some files could not be put back; see each line.',
181
+ };
182
+ }
183
+ /**
184
+ * Doctor's warning (spec §3.32 step 2): the Account starts its sessions in bypass permission mode (one of `starts`,
185
+ * its short commands' and config arguments, or `permissions.defaultMode` in its settings) while
186
+ * `crossSessionInbound` is not `accept`, so a Message from another session waits for approval and is dropped after
187
+ * about five minutes. Not fixable by `doctor --fix`: the file may be shared with other Accounts, so the fix is the
188
+ * previewed `sideby messages inbound accept`. Reads only `crossSessionInbound` and `permissions.defaultMode`.
189
+ */
190
+ export async function inboundFindings(account, starts) {
191
+ if (account.family !== 'claude')
192
+ return [];
193
+ const where = await locate(account);
194
+ if (!where.exists)
195
+ return [];
196
+ const read = await readObject(where.file);
197
+ if ('error' in read)
198
+ return [];
199
+ const state = inboundStateOf(read.obj[INBOUND_KEY]);
200
+ if (state === 'accept' || state === 'refuse')
201
+ return [];
202
+ const perms = read.obj.permissions;
203
+ const bypass = starts.some((args) => argsBypass(args)) || (isObj(perms) && perms.defaultMode === 'bypassPermissions');
204
+ if (!bypass)
205
+ return [];
206
+ return [
207
+ {
208
+ level: 'warn',
209
+ item: 'settings.json',
210
+ code: 'messages.inbound-held',
211
+ message: `${account.ref} starts in bypass permission mode, so a message from another session waits for approval in its terminal and is dropped after about 5 minutes`,
212
+ hint: 'run `sideby messages inbound accept` so its sessions show messages at once (it shows the change first)',
213
+ },
214
+ ];
215
+ }
@@ -13,7 +13,15 @@ export interface PreparedLaunch {
13
13
  title?: string;
14
14
  }
15
15
  /** What `runHost` needs: a prepared Account launch, or the Host run unchanged (`sideby resume`). */
16
- export type HostLaunch = Pick<PreparedLaunch, 'family' | 'bin' | 'args' | 'env' | 'title'>;
16
+ export type HostLaunch = Pick<PreparedLaunch, 'family' | 'bin' | 'args' | 'env' | 'title'> & {
17
+ /** The Account the Host runs as, when sideby chose one: its Live Session can then grow the title (spec §3.32). */
18
+ account?: Account;
19
+ };
20
+ /**
21
+ * Whether the title `[cc002]` should grow into the Session Label as the Host runs (spec §3.32): only with config
22
+ * `accountTitle`, for a known Account, and on a terminal.
23
+ */
24
+ export declare const watchesTitle: (p: HostLaunch, isTTY: boolean | undefined) => boolean;
17
25
  /** Finds an executable on PATH; returns null when the Host is not installed. */
18
26
  export declare function which(bin: string, env: Env): Promise<string | null>;
19
27
  /**
@@ -4,6 +4,11 @@ import { constants as osConstants } from 'node:os';
4
4
  import { delimiter, join } from 'node:path';
5
5
  import { lstatOrNull, realpathOrNull } from './fs-safe.js';
6
6
  import { readSecretFile } from './secret-file.js';
7
+ /**
8
+ * Whether the title `[cc002]` should grow into the Session Label as the Host runs (spec §3.32): only with config
9
+ * `accountTitle`, for a known Account, and on a terminal.
10
+ */
11
+ export const watchesTitle = (p, isTTY) => Boolean(p.title && p.account && isTTY);
7
12
  /** Finds an executable on PATH; returns null when the Host is not installed. */
8
13
  export async function which(bin, env) {
9
14
  for (const dir of (env.PATH ?? '').split(delimiter)) {
@@ -155,29 +160,58 @@ export function spawnHost(p) {
155
160
  // OSC 0 sets the terminal's tab and window title; only on a terminal, never into a pipe.
156
161
  if (p.title && process.stdout.isTTY)
157
162
  process.stdout.write(`\x1b]0;${p.title}\x07`);
158
- const child = spawn(p.bin, p.args, { stdio: 'inherit', env: p.env });
159
- const exited = new Promise((resolve) => {
160
- const ignore = () => { };
161
- const forwarded = new Set();
162
- const forward = (sig) => () => {
163
- if (forwarded.has(sig) || child.exitCode !== null || child.signalCode !== null)
164
- return;
165
- forwarded.add(sig);
166
- child.kill(sig);
167
- };
168
- const handlers = [
169
- ['SIGINT', ignore],
170
- ['SIGQUIT', ignore],
171
- ['SIGTERM', forward('SIGTERM')],
172
- ['SIGHUP', forward('SIGHUP')],
173
- ];
163
+ // The handlers go in before the Host exists: once spawn() returns, the Host may already be running and a signal
164
+ // can arrive before the next line, and with the default action it would end sideby instead of reaching the Host.
165
+ // A handler only runs from the event loop, so `child` is always set by then.
166
+ let child;
167
+ const ignore = () => { };
168
+ const forwarded = new Set();
169
+ const forward = (sig) => () => {
170
+ if (!child || forwarded.has(sig) || child.exitCode !== null || child.signalCode !== null)
171
+ return;
172
+ forwarded.add(sig);
173
+ child.kill(sig);
174
+ };
175
+ const handlers = [
176
+ ['SIGINT', ignore],
177
+ ['SIGQUIT', ignore],
178
+ ['SIGTERM', forward('SIGTERM')],
179
+ ['SIGHUP', forward('SIGHUP')],
180
+ ];
181
+ let ended = false;
182
+ let stopTitle;
183
+ const cleanup = () => {
184
+ ended = true;
185
+ stopTitle?.();
174
186
  for (const [s, h] of handlers)
175
- process.on(s, h);
176
- const cleanup = () => {
177
- for (const [s, h] of handlers)
178
- process.off(s, h);
179
- };
180
- child.once('error', (err) => {
187
+ process.off(s, h);
188
+ };
189
+ for (const [s, h] of handlers)
190
+ process.on(s, h);
191
+ try {
192
+ child = spawn(p.bin, p.args, { stdio: 'inherit', env: p.env });
193
+ }
194
+ catch (err) {
195
+ cleanup();
196
+ throw err;
197
+ }
198
+ const host = child;
199
+ if (watchesTitle(p, process.stdout.isTTY) && host.pid !== undefined) {
200
+ const watch = { account: p.account, accountLabel: p.env.SIDEBY_LABEL || p.account.ref, pid: host.pid };
201
+ // Loaded only here, so a Launch without the title pays nothing for it.
202
+ import('./live-sessions-title.js')
203
+ .then((m) => {
204
+ if (ended)
205
+ return;
206
+ stopTitle = m.watchSessionTitle({
207
+ ...watch,
208
+ write: (t) => process.stdout.write(`\x1b]0;${t}\x07`),
209
+ });
210
+ })
211
+ .catch(() => { });
212
+ }
213
+ const exited = new Promise((resolve) => {
214
+ host.once('error', (err) => {
181
215
  cleanup();
182
216
  const msg = err.code === 'ENOENT'
183
217
  ? `${p.family.title} is not installed (\`${p.bin}\` not found on PATH); install it: ${installHint(p.family)}`
@@ -185,7 +219,7 @@ export function spawnHost(p) {
185
219
  process.stderr.write(`sideby: ${msg}\n`);
186
220
  resolve(1);
187
221
  });
188
- child.once('exit', (code, signal) => {
222
+ host.once('exit', (code, signal) => {
189
223
  cleanup();
190
224
  if (signal)
191
225
  resolve(128 + (osConstants.signals[signal] ?? 0));
@@ -193,5 +227,5 @@ export function spawnHost(p) {
193
227
  resolve(code ?? 1);
194
228
  });
195
229
  });
196
- return { child, exited };
230
+ return { child: host, exited };
197
231
  }
@@ -0,0 +1,5 @@
1
+ import type { Env } from '../types.ts';
2
+ /** The clipboard programs to try, in order, on this system. */
3
+ export declare function clipboardPrograms(platform: NodeJS.Platform, env: Env): [string, string[]][];
4
+ /** Writes `text` to the clipboard; returns the program used, or null when none is installed or each one failed. */
5
+ export declare function copyToClipboard(text: string, env: Env, platform?: NodeJS.Platform, timeoutMs?: number): Promise<string | null>;
@@ -0,0 +1,46 @@
1
+ // `sideby sessions copy` (spec §3.32): the system clipboard.
2
+ import { spawn } from 'node:child_process';
3
+ import { which } from './launch.js';
4
+ /** The clipboard programs to try, in order, on this system. */
5
+ export function clipboardPrograms(platform, env) {
6
+ if (platform === 'darwin')
7
+ return [['pbcopy', []]];
8
+ const wayland = ['wl-copy', []];
9
+ const x11 = ['xclip', ['-selection', 'clipboard']];
10
+ return env.WAYLAND_DISPLAY ? [wayland, x11] : [x11, wayland];
11
+ }
12
+ /** Writes `text` to the clipboard; returns the program used, or null when none is installed or each one failed. */
13
+ export async function copyToClipboard(text, env, platform = process.platform, timeoutMs = 3000) {
14
+ for (const [name, args] of clipboardPrograms(platform, env)) {
15
+ const bin = await which(name, env);
16
+ if (!bin)
17
+ continue;
18
+ if (await writeTo(bin, args, text, env, timeoutMs))
19
+ return name;
20
+ }
21
+ return null;
22
+ }
23
+ /**
24
+ * Runs one clipboard program with `text` on its stdin. Every way it can fail resolves false: it cannot start, it
25
+ * closes its input early (EPIPE), it exits non-zero, or it is still running after `timeoutMs` (then it is ended).
26
+ */
27
+ function writeTo(bin, args, text, env, timeoutMs) {
28
+ return new Promise((resolve) => {
29
+ let done = false;
30
+ const child = spawn(bin, args, { stdio: ['pipe', 'ignore', 'ignore'], env: env });
31
+ const finish = (ok) => {
32
+ if (done)
33
+ return;
34
+ done = true;
35
+ clearTimeout(timer);
36
+ if (!ok && child.exitCode === null && child.signalCode === null)
37
+ child.kill('SIGKILL');
38
+ resolve(ok);
39
+ };
40
+ const timer = setTimeout(() => finish(false), timeoutMs);
41
+ child.once('error', () => finish(false));
42
+ child.stdin.once('error', () => finish(false));
43
+ child.once('exit', (code) => finish(code === 0));
44
+ child.stdin.end(text);
45
+ });
46
+ }
@@ -0,0 +1,89 @@
1
+ import type { Env } from '../types.ts';
2
+ export interface ProcessInfo {
3
+ pid: number;
4
+ ppid: number;
5
+ /** When the process started, epoch milliseconds (whole seconds, as `ps` gives it). */
6
+ startMs: number;
7
+ /** The command line as `ps` shows it. */
8
+ command: string;
9
+ }
10
+ export interface LiveSessionDeps {
11
+ /** Every process of the current user, or throws when `ps` cannot run. */
12
+ processes(signal?: AbortSignal): Promise<ProcessInfo[]>;
13
+ /**
14
+ * The value of one environment variable of a running process (never any other variable); undefined when the
15
+ * process does not set it. Throws when the process's environment cannot be read, so a caller never takes "could
16
+ * not read" for "not set".
17
+ */
18
+ envVar(pid: number, name: string, signal?: AbortSignal): Promise<string | undefined>;
19
+ /** Paths of the files a process holds open (`lsof`); empty when they cannot be read. */
20
+ openFiles(pid: number, signal?: AbortSignal): Promise<string[]>;
21
+ /**
22
+ * The exact arguments of a process (after the program), where the system gives them word by word (Linux
23
+ * `/proc/<pid>/cmdline`); undefined where only the flattened `ps` line exists (macOS).
24
+ */
25
+ argv?(pid: number, signal?: AbortSignal): Promise<string[] | undefined>;
26
+ }
27
+ /**
28
+ * Runs a program and returns its stdout. It always settles: on a non-zero exit, on `signal`, or after `timeoutMs`
29
+ * (it rejects at once, sends SIGTERM, and SIGKILL after `graceMs` for a program that ignores SIGTERM).
30
+ */
31
+ export declare function runProgram(bin: string, args: string[], env: Env, signal?: AbortSignal, o?: {
32
+ timeoutMs?: number;
33
+ graceMs?: number;
34
+ maxBytes?: number;
35
+ }): Promise<string>;
36
+ /** `Tue Oct 20 02:14:43 2026` read as UTC (`ps -o lstart` under `TZ=UTC`, Claude Code's `procStart`); NaN otherwise. */
37
+ export declare function parseLstart(s: string): number;
38
+ /** Parses `ps -Ao pid=,ppid=,lstart=,command=` output; lines it cannot read are skipped. */
39
+ export declare function parsePs(out: string): ProcessInfo[];
40
+ /**
41
+ * One environment variable of a process on macOS, from two `ps` outputs of it: `argvOut` (`ps -ww -o command=`, the
42
+ * arguments only) and `ewwOut` (`ps eww -o command=`, the same arguments followed by the environment). Only what
43
+ * follows the exact arguments is read, so an argument such as `CODEX_HOME=/x` is never taken for the environment.
44
+ * A value runs to the next ` NAME=`, so a path with spaces stays whole. Throws when the environment cannot be read:
45
+ * the outputs do not match (the process changed, or one was cut off) or no environment is shown.
46
+ */
47
+ export declare function envFromPs(argvOut: string, ewwOut: string, name: string): string | undefined;
48
+ /** The real `ps` and `lsof`, found on `env.PATH`. */
49
+ export declare function systemDeps(env: Env): LiveSessionDeps;
50
+ /** What a Family's reader sees of the processes: one `ps` per listing, the rest asked per process. */
51
+ export interface ProcessView {
52
+ list(): Promise<ProcessInfo[]>;
53
+ get(pid: number): Promise<ProcessInfo | undefined>;
54
+ envVar(pid: number, name: string): Promise<string | undefined>;
55
+ openFiles(pid: number): Promise<string[]>;
56
+ /** See `LiveSessionDeps.argv`. */
57
+ argv(pid: number): Promise<string[] | undefined>;
58
+ }
59
+ export declare function processView(deps: LiveSessionDeps, signal?: AbortSignal): ProcessView;
60
+ /** Whether a start time a Host recorded is this process's: within 2 s, as `ps` rounds to the second. */
61
+ export declare const sameStart: (proc: ProcessInfo, recordedMs: number) => boolean;
62
+ /**
63
+ * Whether a command line runs the Host `bin`: its program is named `bin`, or it is `node` (or another
64
+ * interpreter) running a script named `bin` or `bin.js`.
65
+ */
66
+ export declare function runsHost(command: string, bin: string): boolean;
67
+ /** The arguments of a command line after the Host program (and after the script, when an interpreter runs it). */
68
+ export declare function hostArgs(command: string): string[];
69
+ /**
70
+ * The Host processes of one Account: those running `bin` (and not left out by `skip`) whose variable `envName`
71
+ * `belongs` to it. The variable is asked for all of them at once. A process whose environment cannot be read is left
72
+ * out and named in `problems`, never taken as one without the variable (which would be the Main Account's).
73
+ */
74
+ export declare function accountProcesses(procs: ProcessView, o: {
75
+ bin: string;
76
+ envName: string;
77
+ belongs(value: string | undefined): boolean;
78
+ /** `argv` holds the exact arguments where the system gives them, else the flattened `ps` words. */
79
+ skip?(argv: string[], exact: boolean): boolean;
80
+ }, problems: string[]): Promise<number[]>;
81
+ /** Runs `fn` over `items` with at most `limit` at a time, keeping their order. */
82
+ export declare function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]>;
83
+ /** The first `max` bytes of a file as text, for reading a header line without loading a large record. */
84
+ export declare function readHead(path: string, max?: number): Promise<string>;
85
+ /** A string field of a JSON header line, also when the line is cut off before it ends. */
86
+ export declare function headerField(head: string, key: string): string | undefined;
87
+ /** Whether `path` lies inside the directory `dir` (not merely next to it, as `dir-backup/` would). */
88
+ export declare function isInside(dir: string, path: string): boolean;
89
+ export declare const isoOf: (ms: number | undefined) => string | undefined;