sideby 0.19.1 → 0.21.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.
- package/README.md +7 -4
- package/ai-tasks.json +28 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +22 -1
- package/dist/src/cli/commands.js +815 -21
- package/dist/src/cli/format.d.ts +4 -0
- package/dist/src/cli/format.js +42 -4
- package/dist/src/cli/json-schemas.js +334 -4
- package/dist/src/cli/main.js +159 -13
- package/dist/src/core/accounts.d.ts +6 -0
- package/dist/src/core/accounts.js +12 -0
- package/dist/src/core/autostart.d.ts +11 -0
- package/dist/src/core/autostart.js +32 -5
- package/dist/src/core/browser-profiles.d.ts +23 -2
- package/dist/src/core/browser-profiles.js +148 -37
- package/dist/src/core/claude-settings-file.d.ts +18 -0
- package/dist/src/core/claude-settings-file.js +52 -3
- package/dist/src/core/config.d.ts +5 -0
- package/dist/src/core/config.js +12 -1
- package/dist/src/core/edit-settings.d.ts +7 -0
- package/dist/src/core/edit-settings.js +10 -5
- package/dist/src/core/history-group.d.ts +28 -0
- package/dist/src/core/history-group.js +47 -0
- package/dist/src/core/history-index.d.ts +145 -0
- package/dist/src/core/history-index.js +447 -0
- package/dist/src/core/history-project.d.ts +13 -0
- package/dist/src/core/history-project.js +87 -0
- package/dist/src/core/history.d.ts +210 -0
- package/dist/src/core/history.js +952 -0
- package/dist/src/core/inbound.d.ts +62 -0
- package/dist/src/core/inbound.js +215 -0
- package/dist/src/core/launch.d.ts +9 -1
- package/dist/src/core/launch.js +58 -24
- package/dist/src/core/live-sessions-copy.d.ts +5 -0
- package/dist/src/core/live-sessions-copy.js +46 -0
- package/dist/src/core/live-sessions-procs.d.ts +89 -0
- package/dist/src/core/live-sessions-procs.js +296 -0
- package/dist/src/core/live-sessions-title.d.ts +28 -0
- package/dist/src/core/live-sessions-title.js +80 -0
- package/dist/src/core/live-sessions.d.ts +68 -0
- package/dist/src/core/live-sessions.js +163 -0
- package/dist/src/core/login-check.d.ts +15 -0
- package/dist/src/core/login-check.js +32 -0
- package/dist/src/core/messages.d.ts +83 -0
- package/dist/src/core/messages.js +433 -0
- package/dist/src/core/project-categories.d.ts +14 -0
- package/dist/src/core/project-categories.js +48 -0
- package/dist/src/core/quota-fetch.d.ts +3 -3
- package/dist/src/core/quota-fetch.js +5 -5
- package/dist/src/core/quota-levels.d.ts +5 -0
- package/dist/src/core/quota-levels.js +5 -0
- package/dist/src/core/remote-control.d.ts +2 -0
- package/dist/src/core/remote-control.js +34 -59
- package/dist/src/core/run-link.d.ts +76 -0
- package/dist/src/core/run-link.js +245 -0
- package/dist/src/core/same-login.d.ts +4 -3
- package/dist/src/core/same-login.js +10 -7
- package/dist/src/core/session-select.d.ts +31 -0
- package/dist/src/core/session-select.js +44 -0
- package/dist/src/families/browser.d.ts +7 -18
- package/dist/src/families/browser.js +19 -8
- package/dist/src/families/claude/deliver.d.ts +2 -0
- package/dist/src/families/claude/deliver.js +43 -0
- package/dist/src/families/claude/history.d.ts +2 -0
- package/dist/src/families/claude/history.js +192 -0
- package/dist/src/families/claude/live-sessions.d.ts +13 -0
- package/dist/src/families/claude/live-sessions.js +117 -0
- package/dist/src/families/claude/messaging.d.ts +69 -0
- package/dist/src/families/claude/messaging.js +165 -0
- package/dist/src/families/claude/mod.d.ts +26 -0
- package/dist/src/families/claude/mod.js +105 -0
- package/dist/src/families/claude/session-files.d.ts +21 -0
- package/dist/src/families/claude/session-files.js +54 -0
- package/dist/src/families/codex/deliver.d.ts +5 -0
- package/dist/src/families/codex/deliver.js +76 -0
- package/dist/src/families/codex/history.d.ts +7 -0
- package/dist/src/families/codex/history.js +174 -0
- package/dist/src/families/codex/index.js +2 -0
- package/dist/src/families/codex/live-sessions.d.ts +12 -0
- package/dist/src/families/codex/live-sessions.js +193 -0
- package/dist/src/families/codex/quota.d.ts +3 -0
- package/dist/src/families/codex/quota.js +123 -0
- package/dist/src/families/codex/rate-limits.js +2 -0
- package/dist/src/families/codex/rollout.js +1 -1
- package/dist/src/families/grok/browser.d.ts +3 -0
- package/dist/src/families/grok/browser.js +5 -0
- package/dist/src/families/grok/history.d.ts +2 -0
- package/dist/src/families/grok/history.js +157 -0
- package/dist/src/families/grok/live-sessions.d.ts +4 -0
- package/dist/src/families/grok/live-sessions.js +80 -0
- package/dist/src/families/grok/login-key.d.ts +14 -0
- package/dist/src/families/grok/login-key.js +37 -0
- package/dist/src/families/history.d.ts +20 -0
- package/dist/src/families/history.js +81 -0
- package/dist/src/families/live-sessions.d.ts +26 -0
- package/dist/src/families/live-sessions.js +9 -0
- package/dist/src/families/login-keys.js +5 -1
- package/dist/src/families/messaging.d.ts +27 -0
- package/dist/src/families/messaging.js +6 -0
- package/dist/src/families/pi/history.d.ts +2 -0
- package/dist/src/families/pi/history.js +124 -0
- package/dist/src/families/pi/live-sessions.d.ts +2 -0
- package/dist/src/families/pi/live-sessions.js +70 -0
- package/dist/src/families/shared/history-text.d.ts +65 -0
- package/dist/src/families/shared/history-text.js +261 -0
- package/dist/src/menubar/hotkey.d.ts +86 -0
- package/dist/src/menubar/hotkey.js +159 -0
- package/dist/src/menubar/script.d.ts +2 -0
- package/dist/src/menubar/script.js +118 -22
- package/dist/src/menubar/snapshot.d.ts +8 -4
- package/dist/src/menubar/snapshot.js +45 -13
- package/dist/src/menubar/strings.d.ts +24 -6
- package/dist/src/menubar/strings.js +24 -6
- package/dist/src/panel/handler.d.ts +69 -0
- package/dist/src/panel/handler.js +686 -15
- package/dist/src/panel/i18n.d.ts +305 -3
- package/dist/src/panel/i18n.js +622 -18
- package/dist/src/panel/orca.d.ts +48 -0
- package/dist/src/panel/orca.js +153 -0
- package/dist/src/panel/page-logic.d.ts +260 -13
- package/dist/src/panel/page-logic.js +497 -1
- package/dist/src/panel/page-script.js +2309 -204
- package/dist/src/panel/page-styles.js +398 -32
- package/dist/src/panel/page.js +1 -0
- package/dist/src/plugins/check.js +16 -4
- package/dist/src/plugins/loader.d.ts +8 -1
- package/dist/src/plugins/loader.js +72 -7
- package/dist/src/runtime.d.ts +5 -0
- package/dist/src/runtime.js +27 -5
- package/dist/src/types.d.ts +116 -1
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.js +5 -0
- package/mods/claude/.claude-plugin/plugin.json +7 -0
- package/mods/claude/hooks/hooks.json +1 -0
- package/mods/claude/hooks/register.js +261 -0
- package/package.json +5 -2
- package/schemas/autostart.json +74 -1
- package/schemas/browser-set.json +110 -0
- package/schemas/browser.json +22 -2
- package/schemas/config.json +26 -1
- package/schemas/history-index.json +209 -0
- package/schemas/history-projects.json +133 -0
- package/schemas/history-show.json +275 -0
- package/schemas/history.json +410 -0
- package/schemas/menubar-hotkey.json +139 -0
- package/schemas/menubar-snapshot.json +36 -2
- package/schemas/menubar.json +74 -1
- package/schemas/messages-inbound.json +258 -0
- package/schemas/messages.json +164 -0
- package/schemas/send.json +165 -0
- package/schemas/sessions-copy.json +113 -0
- package/schemas/sessions-open-run.json +97 -0
- package/schemas/sessions.json +237 -0
- package/skills/sideby/SKILL.md +10 -5
- package/skills/sideby/references/accounts.md +11 -0
- package/skills/sideby/references/ai-tasks.md +17 -1
- package/skills/sideby/references/panel.md +6 -4
- package/skills/sideby/references/quota.md +2 -2
- package/skills/sideby/references/sessions.md +79 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// The running processes Live Sessions are checked against (spec §3.32). Every program sideby runs here (`ps`,
|
|
2
|
+
// `lsof`) goes through LiveSessionDeps, so tests replace it and never look at the machine's real processes.
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { open, readFile } from 'node:fs/promises';
|
|
5
|
+
import { basename, isAbsolute, relative, resolve } from 'node:path';
|
|
6
|
+
import { which } from './launch.js';
|
|
7
|
+
/**
|
|
8
|
+
* Runs a program and returns its stdout. It always settles: on a non-zero exit, on `signal`, or after `timeoutMs`
|
|
9
|
+
* (it rejects at once, sends SIGTERM, and SIGKILL after `graceMs` for a program that ignores SIGTERM).
|
|
10
|
+
*/
|
|
11
|
+
export function runProgram(bin, args, env, signal, o = {}) {
|
|
12
|
+
const timeoutMs = o.timeoutMs ?? 5_000;
|
|
13
|
+
const graceMs = o.graceMs ?? 1_000;
|
|
14
|
+
const maxBytes = o.maxBytes ?? 32 * 1024 * 1024;
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
if (signal?.aborted)
|
|
17
|
+
return reject(new Error(`${basename(bin)} was stopped`));
|
|
18
|
+
const child = spawn(bin, args, { env: env, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
19
|
+
const chunks = [];
|
|
20
|
+
let size = 0;
|
|
21
|
+
let settled = false;
|
|
22
|
+
const end = (err) => {
|
|
23
|
+
if (settled)
|
|
24
|
+
return;
|
|
25
|
+
settled = true;
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
signal?.removeEventListener('abort', onAbort);
|
|
28
|
+
if (err) {
|
|
29
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
30
|
+
child.kill('SIGTERM');
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
33
|
+
child.kill('SIGKILL');
|
|
34
|
+
}, graceMs).unref();
|
|
35
|
+
}
|
|
36
|
+
reject(err);
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
resolve(Buffer.concat(chunks).toString('utf8'));
|
|
40
|
+
};
|
|
41
|
+
const onAbort = () => end(new Error(`${basename(bin)} was stopped`));
|
|
42
|
+
const timer = setTimeout(() => end(new Error(`${basename(bin)} did not answer within ${timeoutMs / 1000} s`)), timeoutMs);
|
|
43
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
44
|
+
child.stdout.on('data', (d) => {
|
|
45
|
+
size += d.length;
|
|
46
|
+
if (size > maxBytes)
|
|
47
|
+
end(new Error(`${basename(bin)} printed more than sideby reads`));
|
|
48
|
+
else
|
|
49
|
+
chunks.push(d);
|
|
50
|
+
});
|
|
51
|
+
child.once('error', (err) => end(err));
|
|
52
|
+
child.once('close', (code, sig) => end(code === 0 ? null : new Error(`${basename(bin)} exited with ${sig ?? code}`)));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const run = (bin, args, env, signal) => runProgram(bin, args, env, signal);
|
|
56
|
+
const MONTHS = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
|
|
57
|
+
/** `Tue Oct 20 02:14:43 2026` read as UTC (`ps -o lstart` under `TZ=UTC`, Claude Code's `procStart`); NaN otherwise. */
|
|
58
|
+
export function parseLstart(s) {
|
|
59
|
+
const m = /^\s*\w{3}\s+(\w{3})\s+(\d{1,2})\s+(\d{1,2}):(\d{2}):(\d{2})\s+(\d{4})\s*$/.exec(s);
|
|
60
|
+
if (!m)
|
|
61
|
+
return Number.NaN;
|
|
62
|
+
const month = MONTHS.indexOf(m[1]);
|
|
63
|
+
if (month < 0)
|
|
64
|
+
return Number.NaN;
|
|
65
|
+
return Date.UTC(Number(m[6]), month, Number(m[2]), Number(m[3]), Number(m[4]), Number(m[5]));
|
|
66
|
+
}
|
|
67
|
+
/** Parses `ps -Ao pid=,ppid=,lstart=,command=` output; lines it cannot read are skipped. */
|
|
68
|
+
export function parsePs(out) {
|
|
69
|
+
const procs = [];
|
|
70
|
+
for (const line of out.split('\n')) {
|
|
71
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+[\d:]{8}\s+\d{4})\s+(.*)$/.exec(line);
|
|
72
|
+
if (!m)
|
|
73
|
+
continue;
|
|
74
|
+
const startMs = parseLstart(m[3]);
|
|
75
|
+
if (Number.isNaN(startMs))
|
|
76
|
+
continue;
|
|
77
|
+
procs.push({ pid: Number(m[1]), ppid: Number(m[2]), startMs, command: m[4].trim() });
|
|
78
|
+
}
|
|
79
|
+
return procs;
|
|
80
|
+
}
|
|
81
|
+
const ENV_NAME = /\s[A-Za-z_][A-Za-z0-9_]*=/g;
|
|
82
|
+
/**
|
|
83
|
+
* One environment variable of a process on macOS, from two `ps` outputs of it: `argvOut` (`ps -ww -o command=`, the
|
|
84
|
+
* arguments only) and `ewwOut` (`ps eww -o command=`, the same arguments followed by the environment). Only what
|
|
85
|
+
* follows the exact arguments is read, so an argument such as `CODEX_HOME=/x` is never taken for the environment.
|
|
86
|
+
* A value runs to the next ` NAME=`, so a path with spaces stays whole. Throws when the environment cannot be read:
|
|
87
|
+
* the outputs do not match (the process changed, or one was cut off) or no environment is shown.
|
|
88
|
+
*/
|
|
89
|
+
export function envFromPs(argvOut, ewwOut, name) {
|
|
90
|
+
const argv = argvOut.replace(/\n+$/, '');
|
|
91
|
+
const eww = ewwOut.replace(/\n+$/, '');
|
|
92
|
+
if (!argv || !eww.startsWith(argv))
|
|
93
|
+
throw new Error('the environment of this process cannot be read');
|
|
94
|
+
const env = eww.slice(argv.length);
|
|
95
|
+
if (!/^\s/.test(env) || !/\sPATH=/.test(env))
|
|
96
|
+
throw new Error('the environment of this process cannot be read');
|
|
97
|
+
const key = ` ${name}=`;
|
|
98
|
+
const at = env.indexOf(key);
|
|
99
|
+
if (at < 0)
|
|
100
|
+
return undefined;
|
|
101
|
+
const from = at + key.length;
|
|
102
|
+
ENV_NAME.lastIndex = from;
|
|
103
|
+
const next = ENV_NAME.exec(env);
|
|
104
|
+
return env.slice(from, next ? next.index : undefined);
|
|
105
|
+
}
|
|
106
|
+
/** The real `ps` and `lsof`, found on `env.PATH`. */
|
|
107
|
+
export function systemDeps(env) {
|
|
108
|
+
const tool = async (name) => {
|
|
109
|
+
const bin = await which(name, env);
|
|
110
|
+
if (!bin)
|
|
111
|
+
throw new Error(`\`${name}\` is not on PATH`);
|
|
112
|
+
return bin;
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
async processes(signal) {
|
|
116
|
+
// Only this user's processes; UTC and the C locale make `lstart` one fixed format to read.
|
|
117
|
+
const uid = process.getuid?.();
|
|
118
|
+
const who = uid === undefined ? ['-A'] : ['-U', String(uid)];
|
|
119
|
+
const out = await run(await tool('ps'), [...who, '-o', 'pid=,ppid=,lstart=,command='], { ...env, TZ: 'UTC', LC_ALL: 'C' }, signal);
|
|
120
|
+
return parsePs(out);
|
|
121
|
+
},
|
|
122
|
+
async envVar(pid, name, signal) {
|
|
123
|
+
if (process.platform === 'linux') {
|
|
124
|
+
let raw;
|
|
125
|
+
try {
|
|
126
|
+
raw = await readFile(`/proc/${pid}/environ`, 'utf8');
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
throw new Error(`the environment of process ${pid} cannot be read (${err.code})`);
|
|
130
|
+
}
|
|
131
|
+
const hit = raw.split('\0').find((kv) => kv.startsWith(`${name}=`));
|
|
132
|
+
return hit?.slice(name.length + 1);
|
|
133
|
+
}
|
|
134
|
+
const ps = await tool('ps');
|
|
135
|
+
const [argvOut, ewwOut] = await Promise.all([
|
|
136
|
+
run(ps, ['-ww', '-o', 'command=', '-p', String(pid)], env, signal),
|
|
137
|
+
run(ps, ['eww', '-o', 'command=', '-p', String(pid)], env, signal),
|
|
138
|
+
]);
|
|
139
|
+
return envFromPs(argvOut, ewwOut, name);
|
|
140
|
+
},
|
|
141
|
+
async argv(pid) {
|
|
142
|
+
if (process.platform !== 'linux')
|
|
143
|
+
return undefined;
|
|
144
|
+
try {
|
|
145
|
+
const raw = await readFile(`/proc/${pid}/cmdline`, 'utf8');
|
|
146
|
+
const words = raw.split('\0');
|
|
147
|
+
if (words.at(-1) === '')
|
|
148
|
+
words.pop();
|
|
149
|
+
const prog = basename(words[0] ?? '');
|
|
150
|
+
return /^(node|bun|deno)$/.test(prog) ? words.slice(2) : words.slice(1);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
async openFiles(pid, signal) {
|
|
157
|
+
try {
|
|
158
|
+
const out = await run(await tool('lsof'), ['-n', '-P', '-Fn', '-p', String(pid)], env, signal);
|
|
159
|
+
return out
|
|
160
|
+
.split('\n')
|
|
161
|
+
.filter((l) => l.startsWith('n/'))
|
|
162
|
+
.map((l) => l.slice(1));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export function processView(deps, signal) {
|
|
171
|
+
let listed;
|
|
172
|
+
const list = () => {
|
|
173
|
+
listed ??= deps.processes(signal);
|
|
174
|
+
return listed;
|
|
175
|
+
};
|
|
176
|
+
const files = new Map();
|
|
177
|
+
const envs = new Map();
|
|
178
|
+
return {
|
|
179
|
+
list,
|
|
180
|
+
async get(pid) {
|
|
181
|
+
return (await list()).find((p) => p.pid === pid);
|
|
182
|
+
},
|
|
183
|
+
envVar(pid, name) {
|
|
184
|
+
const key = `${pid}\0${name}`;
|
|
185
|
+
let v = envs.get(key);
|
|
186
|
+
if (!v) {
|
|
187
|
+
v = deps.envVar(pid, name, signal);
|
|
188
|
+
envs.set(key, v);
|
|
189
|
+
}
|
|
190
|
+
return v;
|
|
191
|
+
},
|
|
192
|
+
argv: async (pid) => (deps.argv ? deps.argv(pid, signal).catch(() => undefined) : undefined),
|
|
193
|
+
openFiles(pid) {
|
|
194
|
+
let f = files.get(pid);
|
|
195
|
+
if (!f) {
|
|
196
|
+
f = deps.openFiles(pid, signal);
|
|
197
|
+
files.set(pid, f);
|
|
198
|
+
}
|
|
199
|
+
return f;
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** Whether a start time a Host recorded is this process's: within 2 s, as `ps` rounds to the second. */
|
|
204
|
+
export const sameStart = (proc, recordedMs) => Math.abs(proc.startMs - recordedMs) <= 2000;
|
|
205
|
+
/**
|
|
206
|
+
* Whether a command line runs the Host `bin`: its program is named `bin`, or it is `node` (or another
|
|
207
|
+
* interpreter) running a script named `bin` or `bin.js`.
|
|
208
|
+
*/
|
|
209
|
+
export function runsHost(command, bin) {
|
|
210
|
+
const [prog, script] = command.split(/\s+/);
|
|
211
|
+
const name = (s) => (s ? basename(s).replace(/\.(c|m)?js$/, '') : '');
|
|
212
|
+
if (name(prog) === bin)
|
|
213
|
+
return true;
|
|
214
|
+
return /^(node|bun|deno)$/.test(name(prog)) && name(script) === bin;
|
|
215
|
+
}
|
|
216
|
+
/** The arguments of a command line after the Host program (and after the script, when an interpreter runs it). */
|
|
217
|
+
export function hostArgs(command) {
|
|
218
|
+
const words = command.split(/\s+/).filter(Boolean);
|
|
219
|
+
const prog = basename(words[0] ?? '');
|
|
220
|
+
return /^(node|bun|deno)$/.test(prog) ? words.slice(2) : words.slice(1);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The Host processes of one Account: those running `bin` (and not left out by `skip`) whose variable `envName`
|
|
224
|
+
* `belongs` to it. The variable is asked for all of them at once. A process whose environment cannot be read is left
|
|
225
|
+
* out and named in `problems`, never taken as one without the variable (which would be the Main Account's).
|
|
226
|
+
*/
|
|
227
|
+
export async function accountProcesses(procs, o, problems) {
|
|
228
|
+
const candidates = (await procs.list()).filter((p) => runsHost(p.command, o.bin));
|
|
229
|
+
const owned = await Promise.all(candidates.map(async (p) => {
|
|
230
|
+
if (o.skip) {
|
|
231
|
+
const exact = await procs.argv(p.pid);
|
|
232
|
+
if (o.skip(exact ?? hostArgs(p.command), exact !== undefined))
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
return o.belongs(await procs.envVar(p.pid, o.envName)) ? p.pid : null;
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
problems.push(`could not tell which account ${o.bin} process ${p.pid} runs as (${err.message}), so its session is left out; run the command again, or check that the process is yours`);
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}));
|
|
243
|
+
return owned.filter((pid) => pid !== null);
|
|
244
|
+
}
|
|
245
|
+
/** Runs `fn` over `items` with at most `limit` at a time, keeping their order. */
|
|
246
|
+
export async function mapLimit(items, limit, fn) {
|
|
247
|
+
const out = new Array(items.length);
|
|
248
|
+
let next = 0;
|
|
249
|
+
const worker = async () => {
|
|
250
|
+
while (next < items.length) {
|
|
251
|
+
const i = next++;
|
|
252
|
+
out[i] = await fn(items[i]);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
/** The first `max` bytes of a file as text, for reading a header line without loading a large record. */
|
|
259
|
+
export async function readHead(path, max = 64 * 1024) {
|
|
260
|
+
const fh = await open(path, 'r');
|
|
261
|
+
try {
|
|
262
|
+
const buf = Buffer.alloc(max);
|
|
263
|
+
const { bytesRead } = await fh.read(buf, 0, max, 0);
|
|
264
|
+
return buf.subarray(0, bytesRead).toString('utf8');
|
|
265
|
+
}
|
|
266
|
+
finally {
|
|
267
|
+
await fh.close();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/** A string field of a JSON header line, also when the line is cut off before it ends. */
|
|
271
|
+
export function headerField(head, key) {
|
|
272
|
+
const line = head.split('\n')[0] ?? '';
|
|
273
|
+
try {
|
|
274
|
+
const obj = JSON.parse(line);
|
|
275
|
+
const payload = (obj.payload ?? obj);
|
|
276
|
+
const v = payload[key] ?? obj[key];
|
|
277
|
+
return typeof v === 'string' ? v : undefined;
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
const m = new RegExp(`"${key}"\\s*:\\s*("(?:[^"\\\\]|\\\\.)*")`).exec(line);
|
|
281
|
+
if (!m)
|
|
282
|
+
return undefined;
|
|
283
|
+
try {
|
|
284
|
+
return JSON.parse(m[1]);
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/** Whether `path` lies inside the directory `dir` (not merely next to it, as `dir-backup/` would). */
|
|
292
|
+
export function isInside(dir, path) {
|
|
293
|
+
const rel = relative(resolve(dir), resolve(path));
|
|
294
|
+
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
|
|
295
|
+
}
|
|
296
|
+
export const isoOf = (ms) => ms !== undefined && Number.isFinite(ms) ? new Date(ms).toISOString() : undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Account } from '../types.ts';
|
|
2
|
+
import { type LiveSessionDeps } from './live-sessions-procs.ts';
|
|
3
|
+
export declare const TITLE_EVERY_MS = 10000;
|
|
4
|
+
/** The first look comes sooner: Claude Code writes its session file as it starts. */
|
|
5
|
+
export declare const TITLE_FIRST_MS = 3000;
|
|
6
|
+
/** One check gives up after this long, so a slow `ps` or `lsof` never piles up behind the next one. */
|
|
7
|
+
export declare const TITLE_DEADLINE_MS = 8000;
|
|
8
|
+
export interface TitleWatchOptions {
|
|
9
|
+
account: Account;
|
|
10
|
+
/** The short name in the title (`SIDEBY_LABEL`), for example `cc002`. */
|
|
11
|
+
accountLabel: string;
|
|
12
|
+
/** The Host process sideby started. */
|
|
13
|
+
pid: number;
|
|
14
|
+
/** Writes one title; called only when it changes. */
|
|
15
|
+
write(title: string): void;
|
|
16
|
+
deps?: LiveSessionDeps;
|
|
17
|
+
env?: Record<string, string | undefined>;
|
|
18
|
+
everyMs?: number;
|
|
19
|
+
firstMs?: number;
|
|
20
|
+
deadlineMs?: number;
|
|
21
|
+
}
|
|
22
|
+
/** The title for the Live Session of the Host process `pid`, or undefined while it has none. */
|
|
23
|
+
export declare function sessionTitleOf(o: Pick<TitleWatchOptions, 'account' | 'accountLabel' | 'pid' | 'deps' | 'env'>, signal?: AbortSignal): Promise<string | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Checks every 10 s and writes the title only when it changes. Each check has a deadline, and the returned function
|
|
26
|
+
* stops the timers and ends a check still running (its `ps` and `lsof`), so nothing keeps sideby alive after the Host.
|
|
27
|
+
*/
|
|
28
|
+
export declare function watchSessionTitle(o: TitleWatchOptions): () => void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The tab title of a running Host (spec §3.32, config `accountTitle`): `[cc002]` grows into the Session Label once
|
|
2
|
+
// the Account's Live Session for this Host process shows up. Runs only in the `sideby` process that started the
|
|
3
|
+
// Host, never in `statusline-tap` or `handoff-hook`.
|
|
4
|
+
import { liveSessionReader } from '../families/live-sessions.js';
|
|
5
|
+
import { sessionLabel } from './live-sessions.js';
|
|
6
|
+
import { processView, systemDeps } from './live-sessions-procs.js';
|
|
7
|
+
export const TITLE_EVERY_MS = 10_000;
|
|
8
|
+
/** The first look comes sooner: Claude Code writes its session file as it starts. */
|
|
9
|
+
export const TITLE_FIRST_MS = 3_000;
|
|
10
|
+
/** One check gives up after this long, so a slow `ps` or `lsof` never piles up behind the next one. */
|
|
11
|
+
export const TITLE_DEADLINE_MS = 8_000;
|
|
12
|
+
/** Control characters would end the escape sequence early. */
|
|
13
|
+
const clean = (s) => [...s].filter((ch) => ch >= ' ' && ch !== '\x7f').join('');
|
|
14
|
+
/** Whether `pid` is `root` or runs under it (a Host started through a wrapper script). */
|
|
15
|
+
function under(pid, root, procs) {
|
|
16
|
+
const parent = new Map(procs.map((p) => [p.pid, p.ppid]));
|
|
17
|
+
for (let p = pid, n = 0; p !== undefined && n < 64; p = parent.get(p), n++)
|
|
18
|
+
if (p === root)
|
|
19
|
+
return true;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
/** The title for the Live Session of the Host process `pid`, or undefined while it has none. */
|
|
23
|
+
export async function sessionTitleOf(o, signal) {
|
|
24
|
+
const reader = liveSessionReader(o.account.family);
|
|
25
|
+
if (!reader)
|
|
26
|
+
return undefined;
|
|
27
|
+
const procs = processView(o.deps ?? systemDeps(o.env ?? process.env), signal);
|
|
28
|
+
const list = await procs.list();
|
|
29
|
+
const raw = await reader.read(o.account, procs, []);
|
|
30
|
+
// A guess is not tied to a process: it may be another tab's session.
|
|
31
|
+
const mine = raw.find((s) => !s.guessed && s.pid !== undefined && under(s.pid, o.pid, list));
|
|
32
|
+
return mine ? clean(`[${sessionLabel(o.accountLabel, mine.title ?? '', mine.sessionId)}]`) : undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks every 10 s and writes the title only when it changes. Each check has a deadline, and the returned function
|
|
36
|
+
* stops the timers and ends a check still running (its `ps` and `lsof`), so nothing keeps sideby alive after the Host.
|
|
37
|
+
*/
|
|
38
|
+
export function watchSessionTitle(o) {
|
|
39
|
+
let last;
|
|
40
|
+
let busy = false;
|
|
41
|
+
let stopped = false;
|
|
42
|
+
let current;
|
|
43
|
+
const check = async () => {
|
|
44
|
+
if (busy || stopped)
|
|
45
|
+
return;
|
|
46
|
+
busy = true;
|
|
47
|
+
const ctl = new AbortController();
|
|
48
|
+
current = ctl;
|
|
49
|
+
const deadline = setTimeout(() => ctl.abort(), o.deadlineMs ?? TITLE_DEADLINE_MS);
|
|
50
|
+
deadline.unref();
|
|
51
|
+
try {
|
|
52
|
+
const aborted = new Promise((_, reject) => ctl.signal.addEventListener('abort', () => reject(new Error('aborted')), { once: true }));
|
|
53
|
+
aborted.catch(() => { });
|
|
54
|
+
const title = await Promise.race([sessionTitleOf(o, ctl.signal), aborted]);
|
|
55
|
+
if (!stopped && !ctl.signal.aborted && title && title !== last) {
|
|
56
|
+
last = title;
|
|
57
|
+
o.write(title);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// keep the title as it is; the next check tries again
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
clearTimeout(deadline);
|
|
65
|
+
if (current === ctl)
|
|
66
|
+
current = undefined;
|
|
67
|
+
busy = false;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const first = setTimeout(check, o.firstMs ?? TITLE_FIRST_MS);
|
|
71
|
+
const every = setInterval(check, o.everyMs ?? TITLE_EVERY_MS);
|
|
72
|
+
first.unref();
|
|
73
|
+
every.unref();
|
|
74
|
+
return () => {
|
|
75
|
+
stopped = true;
|
|
76
|
+
clearTimeout(first);
|
|
77
|
+
clearInterval(every);
|
|
78
|
+
current?.abort();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type RawLiveSession } from '../families/live-sessions.ts';
|
|
2
|
+
import type { Runtime } from '../runtime.ts';
|
|
3
|
+
import type { Account } from '../types.ts';
|
|
4
|
+
import { type LiveSessionDeps } from './live-sessions-procs.ts';
|
|
5
|
+
import type { SessionRun } from './run-link.ts';
|
|
6
|
+
export type LiveSessionStatus = 'needs-you' | 'busy' | 'idle' | 'unknown';
|
|
7
|
+
export interface LiveSession {
|
|
8
|
+
/** The Account ref, for example `claude:002`. */
|
|
9
|
+
account: string;
|
|
10
|
+
/** The short name shown for the Account (its Alias when it has one, for example `cc002`). */
|
|
11
|
+
accountLabel: string;
|
|
12
|
+
family: string;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
/** The Host's own title for the Session, or the working directory name when the Host has none. */
|
|
15
|
+
title: string;
|
|
16
|
+
/** `<accountLabel> · <title> · <first 8 of sessionId>`. */
|
|
17
|
+
label: string;
|
|
18
|
+
status: LiveSessionStatus;
|
|
19
|
+
cwd?: string;
|
|
20
|
+
pid?: number;
|
|
21
|
+
startedAt?: string;
|
|
22
|
+
updatedAt?: string;
|
|
23
|
+
/** True when sideby could not tie a running process to the Session and took the Account's newest one. */
|
|
24
|
+
guessed: boolean;
|
|
25
|
+
/** Path of the Session's record (transcript), when known. */
|
|
26
|
+
transcript?: string;
|
|
27
|
+
/** The command that resumes the Session in the Account that holds it. */
|
|
28
|
+
resumeCommand: string;
|
|
29
|
+
/** The Session Reference in English, as `sessionCopyText(s, 'reference', 'en')` gives it. */
|
|
30
|
+
reference: string;
|
|
31
|
+
/** The Run of a local orchestrator the Session works for (spec §3.32 step 2b); set by `withRuns`, not the readers. */
|
|
32
|
+
run?: SessionRun;
|
|
33
|
+
}
|
|
34
|
+
export interface LiveSessionsResult {
|
|
35
|
+
sessions: LiveSession[];
|
|
36
|
+
/** One line per Account or Family that could not be read; never aborts the listing. */
|
|
37
|
+
problems: string[];
|
|
38
|
+
}
|
|
39
|
+
export type SessionCopyAs = 'reference' | 'id' | 'resume';
|
|
40
|
+
export declare const shortId: (id: string) => string;
|
|
41
|
+
/** `<accountLabel> · <title> · <first 8 of id>`; a Session without a title leaves its part out. */
|
|
42
|
+
export declare const sessionLabel: (accountLabel: string, title: string, id: string) => string;
|
|
43
|
+
/** The key that names a Session across Accounts: the same id in two Accounts is two Sessions. */
|
|
44
|
+
export declare const liveKey: (account: string, sessionId: string) => string;
|
|
45
|
+
/** The Host arguments that resume Session `id` of a Family. */
|
|
46
|
+
export declare function hostResumeArgs(family: string, id: string): string;
|
|
47
|
+
/** The command that resumes `id` (Resume Routing, spec §3.15, starts the Account that holds it). */
|
|
48
|
+
export declare function resumeCommandFor(family: string, account: string, id: string): string;
|
|
49
|
+
/** The short name an Account is shown by: its first Alias without Host arguments, else its first Alias, else its ref. */
|
|
50
|
+
export declare function accountLabels(rt: Pick<Runtime, 'config'>, accounts: readonly Account[]): Map<string, string>;
|
|
51
|
+
/** A Family reader's record as a Live Session of `account`. */
|
|
52
|
+
export declare function toLiveSession(account: Account, accountLabel: string, raw: RawLiveSession): LiveSession;
|
|
53
|
+
/** `needs-you` first, then the most recent activity. */
|
|
54
|
+
export declare function sortSessions(list: LiveSession[]): LiveSession[];
|
|
55
|
+
/** How long one listing may take before it returns what it has. */
|
|
56
|
+
export declare const LIST_DEADLINE_MS = 8000;
|
|
57
|
+
/**
|
|
58
|
+
* Lists Live Sessions of every Account, `needs-you` first, then by most recent activity. After `deadlineMs` it stops
|
|
59
|
+
* the programs it still waits for and returns what it has, with a problem line naming the Accounts left out.
|
|
60
|
+
*/
|
|
61
|
+
export declare function listLiveSessions(rt: Runtime, opts?: {
|
|
62
|
+
only?: string;
|
|
63
|
+
deadlineMs?: number;
|
|
64
|
+
}, deps?: LiveSessionDeps): Promise<LiveSessionsResult>;
|
|
65
|
+
export type ReferenceFields = Pick<LiveSession, 'accountLabel' | 'sessionId' | 'title' | 'cwd' | 'transcript' | 'guessed' | 'resumeCommand'>;
|
|
66
|
+
export declare function referenceText(s: ReferenceFields, lang: 'en' | 'zh'): string;
|
|
67
|
+
/** The text a copy button copies: the Session Reference (default), the bare id, or the resume command. */
|
|
68
|
+
export declare function sessionCopyText(s: LiveSession, as: SessionCopyAs, lang: 'en' | 'zh'): string;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Live Sessions across Accounts (spec §3.32, ADR-0039): which Session each Account is running now, its Session
|
|
2
|
+
// Label, and the Session Reference a copy button copies. Read-only: built from the Hosts' own non-credential files;
|
|
3
|
+
// nothing here copies, edits or ends a Session.
|
|
4
|
+
import { liveSessionReader } from '../families/live-sessions.js';
|
|
5
|
+
import { aliasesByAccount } from './accounts.js';
|
|
6
|
+
import { aliasArgs, aliasRefs } from './config.js';
|
|
7
|
+
import { processView, systemDeps } from './live-sessions-procs.js';
|
|
8
|
+
export const shortId = (id) => id.slice(0, 8);
|
|
9
|
+
/** `<accountLabel> · <title> · <first 8 of id>`; a Session without a title leaves its part out. */
|
|
10
|
+
export const sessionLabel = (accountLabel, title, id) => [accountLabel, title, shortId(id)].filter(Boolean).join(' · ');
|
|
11
|
+
/** The key that names a Session across Accounts: the same id in two Accounts is two Sessions. */
|
|
12
|
+
export const liveKey = (account, sessionId) => `${account}\0${sessionId}`;
|
|
13
|
+
/** The Host arguments that resume Session `id` of a Family. */
|
|
14
|
+
export function hostResumeArgs(family, id) {
|
|
15
|
+
if (family === 'codex')
|
|
16
|
+
return `resume ${id}`;
|
|
17
|
+
if (family === 'claude' || family === 'grok')
|
|
18
|
+
return `--resume ${id}`;
|
|
19
|
+
return `--session ${id}`;
|
|
20
|
+
}
|
|
21
|
+
/** The command that resumes `id` (Resume Routing, spec §3.15, starts the Account that holds it). */
|
|
22
|
+
export function resumeCommandFor(family, account, id) {
|
|
23
|
+
if (family === 'codex' || family === 'claude' || family === 'grok')
|
|
24
|
+
return `sideby resume ${family} -- ${hostResumeArgs(family, id)}`;
|
|
25
|
+
// pi has no Resume Routing: start the Account itself on that session.
|
|
26
|
+
return `sideby run ${account} -- ${hostResumeArgs(family, id)}`;
|
|
27
|
+
}
|
|
28
|
+
/** The short name an Account is shown by: its first Alias without Host arguments, else its first Alias, else its ref. */
|
|
29
|
+
export function accountLabels(rt, accounts) {
|
|
30
|
+
const aliases = rt.config.aliases;
|
|
31
|
+
const byAccount = aliasesByAccount(aliasRefs(aliases), accounts);
|
|
32
|
+
const out = new Map();
|
|
33
|
+
for (const a of accounts) {
|
|
34
|
+
const names = byAccount.get(a.ref) ?? [];
|
|
35
|
+
const plain = names.filter((n) => aliasArgs(aliases?.[n]).length === 0);
|
|
36
|
+
out.set(a.ref, plain[0] ?? names[0] ?? a.ref);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/** A Family reader's record as a Live Session of `account`. */
|
|
41
|
+
export function toLiveSession(account, accountLabel, raw) {
|
|
42
|
+
const title = raw.title ?? '';
|
|
43
|
+
const s = {
|
|
44
|
+
account: account.ref,
|
|
45
|
+
accountLabel,
|
|
46
|
+
family: account.family,
|
|
47
|
+
sessionId: raw.sessionId,
|
|
48
|
+
title,
|
|
49
|
+
label: sessionLabel(accountLabel, title, raw.sessionId),
|
|
50
|
+
status: raw.status,
|
|
51
|
+
...(raw.cwd ? { cwd: raw.cwd } : {}),
|
|
52
|
+
...(raw.pid !== undefined ? { pid: raw.pid } : {}),
|
|
53
|
+
...(raw.startedAt ? { startedAt: raw.startedAt } : {}),
|
|
54
|
+
...(raw.updatedAt ? { updatedAt: raw.updatedAt } : {}),
|
|
55
|
+
guessed: raw.guessed,
|
|
56
|
+
...(raw.transcript ? { transcript: raw.transcript } : {}),
|
|
57
|
+
resumeCommand: resumeCommandFor(account.family, account.ref, raw.sessionId),
|
|
58
|
+
};
|
|
59
|
+
return { ...s, reference: referenceText(s, 'en') };
|
|
60
|
+
}
|
|
61
|
+
const time = (s) => Date.parse(s.updatedAt ?? s.startedAt ?? '') || 0;
|
|
62
|
+
/** `needs-you` first, then the most recent activity. */
|
|
63
|
+
export function sortSessions(list) {
|
|
64
|
+
return list.sort((a, b) => Number(b.status === 'needs-you') - Number(a.status === 'needs-you') ||
|
|
65
|
+
time(b) - time(a) ||
|
|
66
|
+
a.label.localeCompare(b.label));
|
|
67
|
+
}
|
|
68
|
+
/** How long one listing may take before it returns what it has. */
|
|
69
|
+
export const LIST_DEADLINE_MS = 8_000;
|
|
70
|
+
/**
|
|
71
|
+
* Lists Live Sessions of every Account, `needs-you` first, then by most recent activity. After `deadlineMs` it stops
|
|
72
|
+
* the programs it still waits for and returns what it has, with a problem line naming the Accounts left out.
|
|
73
|
+
*/
|
|
74
|
+
export async function listLiveSessions(rt, opts = {}, deps) {
|
|
75
|
+
const all = await rt.accounts();
|
|
76
|
+
let accounts = all;
|
|
77
|
+
if (opts.only) {
|
|
78
|
+
if (rt.families.has(opts.only))
|
|
79
|
+
accounts = all.filter((a) => a.family === opts.only);
|
|
80
|
+
else {
|
|
81
|
+
const one = await rt.resolve(opts.only);
|
|
82
|
+
accounts = all.filter((a) => a.ref === one.ref);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const labels = accountLabels(rt, all);
|
|
86
|
+
const problems = [];
|
|
87
|
+
const readable = accounts.filter((a) => liveSessionReader(a.family));
|
|
88
|
+
if (!readable.length)
|
|
89
|
+
return { sessions: [], problems };
|
|
90
|
+
const ctl = new AbortController();
|
|
91
|
+
const procs = processView(deps ?? systemDeps(rt.env), ctl.signal);
|
|
92
|
+
const found = [];
|
|
93
|
+
const pending = new Set(readable.map((a) => a.ref));
|
|
94
|
+
const work = (async () => {
|
|
95
|
+
try {
|
|
96
|
+
await procs.list();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
if (ctl.signal.aborted)
|
|
100
|
+
return;
|
|
101
|
+
problems.push(`could not list running programs (${err.message}); sideby needs \`ps\` on PATH to tell which sessions still run`);
|
|
102
|
+
pending.clear();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
await Promise.all(readable.map(async (account) => {
|
|
106
|
+
try {
|
|
107
|
+
const raw = await liveSessionReader(account.family).read(account, procs, problems);
|
|
108
|
+
if (ctl.signal.aborted)
|
|
109
|
+
return;
|
|
110
|
+
found.push(...raw.map((r) => toLiveSession(account, labels.get(account.ref) ?? account.ref, r)));
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
if (ctl.signal.aborted)
|
|
114
|
+
return;
|
|
115
|
+
problems.push(`${account.ref}: could not read its sessions (${err.code ?? err.message}); check that ${account.dir} is readable`);
|
|
116
|
+
}
|
|
117
|
+
pending.delete(account.ref);
|
|
118
|
+
}));
|
|
119
|
+
})();
|
|
120
|
+
const deadlineMs = opts.deadlineMs ?? LIST_DEADLINE_MS;
|
|
121
|
+
let timer;
|
|
122
|
+
const late = new Promise((resolve) => {
|
|
123
|
+
timer = setTimeout(() => resolve('late'), deadlineMs);
|
|
124
|
+
});
|
|
125
|
+
if ((await Promise.race([work.then(() => 'done'), late])) === 'late') {
|
|
126
|
+
ctl.abort();
|
|
127
|
+
problems.push(`stopped looking after ${deadlineMs / 1000} s; ${[...pending].join(', ') || 'some accounts'} may run sessions that are not shown; run \`sideby sessions\` again`);
|
|
128
|
+
}
|
|
129
|
+
clearTimeout(timer);
|
|
130
|
+
// One unreadable process is met by every Account of its Family: say it once.
|
|
131
|
+
return { sessions: sortSessions([...found]), problems: [...new Set(problems)] };
|
|
132
|
+
}
|
|
133
|
+
export function referenceText(s, lang) {
|
|
134
|
+
const id = shortId(s.sessionId);
|
|
135
|
+
if (lang === 'zh') {
|
|
136
|
+
const parts = [
|
|
137
|
+
`${s.accountLabel} 的会话 ${id}${s.title ? `(${s.title})` : ''}${s.guessed ? '(最新会话,推测)' : ''}`,
|
|
138
|
+
];
|
|
139
|
+
if (s.cwd)
|
|
140
|
+
parts.push(`工作目录 ${s.cwd}`);
|
|
141
|
+
if (s.transcript)
|
|
142
|
+
parts.push(`记录在 ${s.transcript}`);
|
|
143
|
+
const tail = s.transcript ? '去读它的记录了解上下文。' : `用 \`${s.resumeCommand}\` 恢复它。`;
|
|
144
|
+
return `${parts.join(',')}。${tail}`;
|
|
145
|
+
}
|
|
146
|
+
const parts = [
|
|
147
|
+
`${s.accountLabel}'s session ${id}${s.title ? ` (${s.title})` : ''}${s.guessed ? ' (its newest session, a guess)' : ''}`,
|
|
148
|
+
];
|
|
149
|
+
if (s.cwd)
|
|
150
|
+
parts.push(`working directory ${s.cwd}`);
|
|
151
|
+
if (s.transcript)
|
|
152
|
+
parts.push(`record at ${s.transcript}`);
|
|
153
|
+
const tail = s.transcript ? 'Read its record for the context.' : `Resume it with \`${s.resumeCommand}\`.`;
|
|
154
|
+
return `${parts.join(', ')}. ${tail}`;
|
|
155
|
+
}
|
|
156
|
+
/** The text a copy button copies: the Session Reference (default), the bare id, or the resume command. */
|
|
157
|
+
export function sessionCopyText(s, as, lang) {
|
|
158
|
+
if (as === 'id')
|
|
159
|
+
return s.sessionId;
|
|
160
|
+
if (as === 'resume')
|
|
161
|
+
return s.resumeCommand;
|
|
162
|
+
return referenceText(s, lang);
|
|
163
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LoginState } from '../types.ts';
|
|
2
|
+
/** What `sideby login` reads of an Account around the sign-in: identity fields and Same Login peers only. */
|
|
3
|
+
export interface LoginSnapshot {
|
|
4
|
+
login: LoginState | 'not-needed';
|
|
5
|
+
email?: string;
|
|
6
|
+
/** The other Accounts of its Same Login (spec §3.21). */
|
|
7
|
+
sameLogin: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/** The line before the sign-in: who the Account is now, and how to choose another login. Undefined when signed out. */
|
|
10
|
+
export declare function loginBeforeLine(ref: string, before: LoginSnapshot): string | undefined;
|
|
11
|
+
/** The result after the sign-in, with what to do next when it did not give the Account a login of its own. */
|
|
12
|
+
export declare function loginAfterLine(ref: string, before: LoginSnapshot, after: LoginSnapshot): {
|
|
13
|
+
line: string;
|
|
14
|
+
ok: boolean;
|
|
15
|
+
} | undefined;
|