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.
- 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/file-memo.js +26 -4
- 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 +304 -3
- package/dist/src/panel/i18n.js +669 -67
- 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 +255 -13
- package/dist/src/panel/page-logic.js +483 -1
- package/dist/src/panel/page-script.js +2265 -207
- package/dist/src/panel/page-styles.js +404 -32
- package/dist/src/panel/page.js +1 -0
- package/dist/src/plugins/account-script.js +61 -27
- 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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { claudeSignInId } from './claude/browser.js';
|
|
2
2
|
import { codexSignInId } from './codex/browser.js';
|
|
3
|
-
|
|
3
|
+
import { grokSignInId } from './grok/browser.js';
|
|
4
|
+
const BUILTIN = new Map([
|
|
4
5
|
{
|
|
5
6
|
family: 'claude',
|
|
6
7
|
url: 'https://claude.ai',
|
|
@@ -11,13 +12,23 @@ const WEBSITES = new Map([
|
|
|
11
12
|
url: 'https://chatgpt.com',
|
|
12
13
|
match: { origin: 'https://chatgpt.com', signInId: codexSignInId },
|
|
13
14
|
},
|
|
14
|
-
|
|
15
|
+
// grok.com keys such as `dismissed:<x>:<user_id>` carry the x.ai user id (checked 2026-10-20, ADR-0043).
|
|
16
|
+
{
|
|
17
|
+
family: 'grok',
|
|
18
|
+
url: 'https://grok.com',
|
|
19
|
+
match: { origin: 'https://grok.com', signInId: grokSignInId },
|
|
20
|
+
},
|
|
15
21
|
].map((w) => [w.family, w]));
|
|
16
|
-
/** The website of a built-in
|
|
17
|
-
export function websiteDef(familyId) {
|
|
18
|
-
|
|
22
|
+
/** The website of a Family: sideby's own for a built-in one, else the one its plugin declares. */
|
|
23
|
+
export function websiteDef(families, familyId) {
|
|
24
|
+
const own = BUILTIN.get(familyId);
|
|
25
|
+
if (own)
|
|
26
|
+
return own;
|
|
27
|
+
const w = families.get(familyId)?.website;
|
|
28
|
+
return w ? { ...w, family: familyId } : undefined;
|
|
19
29
|
}
|
|
20
|
-
/** Every website that can be matched, for the origins to read. */
|
|
21
|
-
export function matchedOrigins() {
|
|
22
|
-
|
|
30
|
+
/** Every website origin that can be matched, for the origins to read. */
|
|
31
|
+
export function matchedOrigins(families) {
|
|
32
|
+
const ids = new Set([...BUILTIN.keys(), ...families.keys()]);
|
|
33
|
+
return [...new Set([...ids].flatMap((id) => websiteDef(families, id)?.match?.origin ?? []))];
|
|
23
34
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Delivering a Message into a running Claude Code session (spec §3.32 step 2, ADR-0040): the session's own message
|
|
2
|
+
// socket, after `crossSessionInbound` and the socket's owner, folder and identity are checked. Every refusal comes
|
|
3
|
+
// back as a paste with the reason; nothing here reads a key file or a token.
|
|
4
|
+
import { inboundGroups } from '../../core/inbound.js';
|
|
5
|
+
import { hostArgs } from '../../core/live-sessions-procs.js';
|
|
6
|
+
import { checkSocket, claudeSocketOf, DELIVER_TIMEOUT_MS, messageLine, sessionBypass, socketChanged, socketRoots, writeToSocket, } from './messaging.js';
|
|
7
|
+
export async function deliverClaude(req) {
|
|
8
|
+
const { rt, to, acct, pid, procs, deps } = req;
|
|
9
|
+
const paste = (note) => ({ status: 'paste-needed', note });
|
|
10
|
+
const [group] = await inboundGroups([acct], rt.readContext());
|
|
11
|
+
const inbound = group?.state ?? 'default';
|
|
12
|
+
// A settings file sideby cannot read may still hold "refuse" for the running session, so it is not a guess to act on.
|
|
13
|
+
if (inbound === 'blocked')
|
|
14
|
+
return paste(`sideby could not tell if ${to.accountLabel} accepts messages (${group?.reason}); paste this line into its tab`);
|
|
15
|
+
if (inbound === 'refuse')
|
|
16
|
+
return paste(`${to.accountLabel} blocks messages from other sessions (crossSessionInbound is "refuse"). Paste the line into its tab, or change crossSessionInbound in its settings.json`);
|
|
17
|
+
const sock = await claudeSocketOf(acct.dir, pid, to.sessionId, procs);
|
|
18
|
+
if ('problem' in sock)
|
|
19
|
+
return paste(`sideby did not deliver it because ${sock.problem}; paste the line into its tab`);
|
|
20
|
+
const checked = await checkSocket(sock.path, {
|
|
21
|
+
tempRoots: deps.tempRoots ?? socketRoots(rt.env),
|
|
22
|
+
uid: deps.uid ?? process.getuid?.(),
|
|
23
|
+
});
|
|
24
|
+
if ('problem' in checked)
|
|
25
|
+
return paste(`sideby did not deliver it because ${checked.problem}; paste the line into its tab`);
|
|
26
|
+
try {
|
|
27
|
+
await (deps.write ?? writeToSocket)(sock.path, messageLine(req.text), deps.timeoutMs ?? DELIVER_TIMEOUT_MS, () => socketChanged(sock.path, checked.identity));
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
return paste(`sideby could not reach ${to.label} (${err.message}); paste the line into its tab`);
|
|
31
|
+
}
|
|
32
|
+
if (inbound === 'accept')
|
|
33
|
+
return { status: 'delivered' };
|
|
34
|
+
const proc = await procs.get(pid);
|
|
35
|
+
const args = (await procs.argv(pid)) ?? (proc ? hostArgs(proc.command) : []);
|
|
36
|
+
if (inbound === 'hold' || (await sessionBypass(to.transcript, args)))
|
|
37
|
+
return {
|
|
38
|
+
status: 'delivered',
|
|
39
|
+
needsApproval: true,
|
|
40
|
+
note: `sent, but ${to.accountLabel} needs your approval: approve the message in its terminal within 5 minutes, or run \`sideby messages inbound accept\` to receive future messages right away`,
|
|
41
|
+
};
|
|
42
|
+
return { status: 'delivered' };
|
|
43
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Claude Code's Session History (spec §3.33): one `projects/<encoded cwd>/<id>.jsonl` per Session, written by Claude
|
|
2
|
+
// Code itself (tried with Claude Code 2.1.304 on 2026-10-20), and `<id>/subagents/agent-*.jsonl` for the subagents
|
|
3
|
+
// that Session started. The folder name is only an encoding of the working directory and may be cut, so the
|
|
4
|
+
// directory is taken from the records' `cwd`, never decoded from the name.
|
|
5
|
+
import { basename, dirname, join } from 'node:path';
|
|
6
|
+
import { blockText, dirEntries, fileLines, historyFile, isoTime, jsonText, parseRecord, SessionText, str, titleFromText, typedText, } from '../shared/history-text.js';
|
|
7
|
+
const SESSION_FILE = /^(.+)\.jsonl$/;
|
|
8
|
+
const SUBAGENT_FILE = /^agent-.+\.jsonl$/;
|
|
9
|
+
// Record types that carry something Session History reads; every other line is skipped before it is parsed.
|
|
10
|
+
const WANTED = /"type":"(user|assistant|ai-title|custom-title|summary)"/;
|
|
11
|
+
// A tool's result comes back as a `user` record with this key; it is never read, so its (often huge) line is not
|
|
12
|
+
// parsed. Inside a message's text the key would be escaped and does not match.
|
|
13
|
+
const TOOL_RESULT = '"toolUseResult"';
|
|
14
|
+
/** The text a person typed in a `user` record, or '' for tool results, meta and injected turns. */
|
|
15
|
+
function userText(rec) {
|
|
16
|
+
if (rec.isMeta === true || rec.isCompactSummary === true || rec.isVisibleInTranscriptOnly === true)
|
|
17
|
+
return '';
|
|
18
|
+
const msg = rec.message;
|
|
19
|
+
return typedText(blockText(msg?.content));
|
|
20
|
+
}
|
|
21
|
+
function assistantText(rec) {
|
|
22
|
+
const msg = rec.message;
|
|
23
|
+
return blockText(msg?.content).trim();
|
|
24
|
+
}
|
|
25
|
+
function toolNames(rec) {
|
|
26
|
+
const content = rec.message?.content;
|
|
27
|
+
if (!Array.isArray(content))
|
|
28
|
+
return [];
|
|
29
|
+
return content
|
|
30
|
+
.filter((b) => b && typeof b === 'object' && b.type === 'tool_use')
|
|
31
|
+
.map((b) => str(b.name) ?? 'tool');
|
|
32
|
+
}
|
|
33
|
+
export const claudeHistory = {
|
|
34
|
+
family: 'claude',
|
|
35
|
+
async list(account) {
|
|
36
|
+
const out = [];
|
|
37
|
+
const projects = join(account.dir, 'projects');
|
|
38
|
+
for (const p of await dirEntries(projects)) {
|
|
39
|
+
if (!p.isDirectory())
|
|
40
|
+
continue;
|
|
41
|
+
const dir = join(projects, p.name);
|
|
42
|
+
for (const e of await dirEntries(dir)) {
|
|
43
|
+
if (e.isFile() && SESSION_FILE.test(e.name)) {
|
|
44
|
+
const f = await historyFile(join(dir, e.name));
|
|
45
|
+
if (f)
|
|
46
|
+
out.push(f);
|
|
47
|
+
}
|
|
48
|
+
else if (e.isDirectory()) {
|
|
49
|
+
const sub = join(dir, e.name, 'subagents');
|
|
50
|
+
for (const s of await dirEntries(sub)) {
|
|
51
|
+
if (!s.isFile() || !SUBAGENT_FILE.test(s.name))
|
|
52
|
+
continue;
|
|
53
|
+
const f = await historyFile(join(sub, s.name), { parent: e.name });
|
|
54
|
+
if (f)
|
|
55
|
+
out.push(f);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
},
|
|
62
|
+
async parse(file) {
|
|
63
|
+
const sub = Boolean(file.parent);
|
|
64
|
+
let sessionId = sub ? basename(file.path, '.jsonl') : SESSION_FILE.exec(basename(file.path))?.[1];
|
|
65
|
+
let cwd;
|
|
66
|
+
let branch;
|
|
67
|
+
let model;
|
|
68
|
+
let entrypoint;
|
|
69
|
+
let startedAt;
|
|
70
|
+
let updatedAt;
|
|
71
|
+
let custom;
|
|
72
|
+
let aiTitle;
|
|
73
|
+
let summary;
|
|
74
|
+
const text = new SessionText();
|
|
75
|
+
for await (const line of fileLines(file.path)) {
|
|
76
|
+
if (!WANTED.test(line) || line.includes(TOOL_RESULT))
|
|
77
|
+
continue;
|
|
78
|
+
const rec = parseRecord(line);
|
|
79
|
+
if (!rec)
|
|
80
|
+
continue;
|
|
81
|
+
const type = rec.type;
|
|
82
|
+
if (type === 'custom-title')
|
|
83
|
+
custom = str(rec.customTitle) ?? custom;
|
|
84
|
+
else if (type === 'ai-title')
|
|
85
|
+
aiTitle = str(rec.aiTitle) ?? aiTitle;
|
|
86
|
+
else if (type === 'summary')
|
|
87
|
+
summary = str(rec.summary) ?? summary;
|
|
88
|
+
if (type !== 'user' && type !== 'assistant')
|
|
89
|
+
continue;
|
|
90
|
+
// A subagent's own file is all sidechain; in the main file a sidechain line belongs to a subagent.
|
|
91
|
+
if (!sub && rec.isSidechain === true)
|
|
92
|
+
continue;
|
|
93
|
+
if (!sub && !sessionId)
|
|
94
|
+
sessionId = str(rec.sessionId);
|
|
95
|
+
cwd ??= str(rec.cwd);
|
|
96
|
+
entrypoint ??= str(rec.entrypoint);
|
|
97
|
+
branch = str(rec.gitBranch) ?? branch;
|
|
98
|
+
const at = isoTime(rec.timestamp);
|
|
99
|
+
if (at) {
|
|
100
|
+
startedAt ??= at;
|
|
101
|
+
updatedAt = at;
|
|
102
|
+
}
|
|
103
|
+
if (type === 'user') {
|
|
104
|
+
const t = userText(rec);
|
|
105
|
+
if (t)
|
|
106
|
+
text.prompt(t);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const m = str(rec.message?.model);
|
|
110
|
+
if (m && m !== '<synthetic>')
|
|
111
|
+
model = m;
|
|
112
|
+
const t = assistantText(rec);
|
|
113
|
+
if (t)
|
|
114
|
+
text.reply(t);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!sessionId || !text.count)
|
|
118
|
+
return undefined;
|
|
119
|
+
const [title, titleFrom] = custom
|
|
120
|
+
? [titleFromText(custom), 'user']
|
|
121
|
+
: aiTitle
|
|
122
|
+
? [titleFromText(aiTitle), 'host']
|
|
123
|
+
: summary
|
|
124
|
+
? [titleFromText(summary), 'host']
|
|
125
|
+
: text.first
|
|
126
|
+
? [titleFromText(text.first), 'prompt']
|
|
127
|
+
: [undefined, 'none'];
|
|
128
|
+
const s = {
|
|
129
|
+
sessionId,
|
|
130
|
+
titleFrom,
|
|
131
|
+
messages: text.count,
|
|
132
|
+
script: sub || /^sdk/i.test(entrypoint ?? ''),
|
|
133
|
+
prompts: text.prompts,
|
|
134
|
+
replies: text.replies,
|
|
135
|
+
...(text.cut ? { cut: true } : {}),
|
|
136
|
+
};
|
|
137
|
+
if (title)
|
|
138
|
+
s.title = title;
|
|
139
|
+
if (cwd)
|
|
140
|
+
s.cwd = cwd;
|
|
141
|
+
if (branch && branch !== 'HEAD')
|
|
142
|
+
s.branch = branch;
|
|
143
|
+
if (model)
|
|
144
|
+
s.model = model;
|
|
145
|
+
if (startedAt)
|
|
146
|
+
s.startedAt = startedAt;
|
|
147
|
+
if (updatedAt)
|
|
148
|
+
s.updatedAt = updatedAt;
|
|
149
|
+
if (file.parent)
|
|
150
|
+
s.parent = file.parent;
|
|
151
|
+
return s;
|
|
152
|
+
},
|
|
153
|
+
async *messages(path) {
|
|
154
|
+
// As in parse(): a subagent's own file is all sidechain, and in the main file a sidechain line is a subagent's.
|
|
155
|
+
const sub = basename(dirname(path)) === 'subagents';
|
|
156
|
+
for await (const line of fileLines(path)) {
|
|
157
|
+
if (!/"type":"(user|assistant)"/.test(line) || line.includes(TOOL_RESULT))
|
|
158
|
+
continue;
|
|
159
|
+
const rec = parseRecord(line);
|
|
160
|
+
if (!rec || (!sub && rec.isSidechain === true))
|
|
161
|
+
continue;
|
|
162
|
+
const at = isoTime(rec.timestamp);
|
|
163
|
+
if (rec.type === 'user') {
|
|
164
|
+
const text = userText(rec);
|
|
165
|
+
if (text)
|
|
166
|
+
yield { role: 'user', text, ...(at ? { at } : {}) };
|
|
167
|
+
}
|
|
168
|
+
else if (rec.type === 'assistant') {
|
|
169
|
+
const text = assistantText(rec);
|
|
170
|
+
if (text)
|
|
171
|
+
yield { role: 'assistant', text, ...(at ? { at } : {}) };
|
|
172
|
+
for (const tool of toolNames(rec))
|
|
173
|
+
yield { role: 'tool', text: tool, tool, ...(at ? { at } : {}) };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
async *toolText(path) {
|
|
178
|
+
for await (const line of fileLines(path)) {
|
|
179
|
+
if (!/"type":"(user|assistant)"/.test(line))
|
|
180
|
+
continue;
|
|
181
|
+
const content = parseRecord(line)?.message?.content;
|
|
182
|
+
if (!Array.isArray(content))
|
|
183
|
+
continue;
|
|
184
|
+
for (const b of content) {
|
|
185
|
+
if (b?.type === 'tool_use')
|
|
186
|
+
yield jsonText(b.input);
|
|
187
|
+
else if (b?.type === 'tool_result')
|
|
188
|
+
yield jsonText(b.content);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LiveSessionStatus } from '../../core/live-sessions.ts';
|
|
2
|
+
import type { LiveSessionReader } from '../live-sessions.ts';
|
|
3
|
+
/** Claude Code's `status`: `busy` and `shell` run, `idle` waits for a prompt, a blocked one waits for the user. */
|
|
4
|
+
export declare function claudeStatus(s: unknown): LiveSessionStatus;
|
|
5
|
+
/** The transcript Claude Code writes for a session: `projects/<cwd with every other character as ->/<id>.jsonl`. */
|
|
6
|
+
export declare const claudeTranscript: (dir: string, cwd: string, id: string) => string;
|
|
7
|
+
/**
|
|
8
|
+
* The title Claude Code gave the session itself (the one it shows as the terminal tab title): the last `ai-title`
|
|
9
|
+
* record near the end of the transcript. Only lines of that type are parsed; nothing else of the conversation is read
|
|
10
|
+
* into a result. Remembered until the file changes.
|
|
11
|
+
*/
|
|
12
|
+
export declare function claudeAiTitle(transcript: string): Promise<string | undefined>;
|
|
13
|
+
export declare const claudeLiveSessions: LiveSessionReader;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Claude Code's Live Sessions (spec §3.32): one `<dir>/sessions/<pid>.json` per running session, written by Claude
|
|
2
|
+
// Code itself (tried with Claude Code 2.1.304 on 2026-10-20). A file whose process is gone, or whose pid now belongs
|
|
3
|
+
// to another process (`procStart` differs), is skipped and left in place.
|
|
4
|
+
import { readdir } from 'node:fs/promises';
|
|
5
|
+
import { basename, join } from 'node:path';
|
|
6
|
+
import { statOrNull } from '../../core/fs-safe.js';
|
|
7
|
+
import { isoOf } from '../../core/live-sessions-procs.js';
|
|
8
|
+
import { readSessionRecord, recordRunsOn, recordStart, tailLinesWith } from './session-files.js';
|
|
9
|
+
const PID_FILE = /^(\d+)\.json$/;
|
|
10
|
+
/** Claude Code's `status`: `busy` and `shell` run, `idle` waits for a prompt, a blocked one waits for the user. */
|
|
11
|
+
export function claudeStatus(s) {
|
|
12
|
+
if (typeof s !== 'string')
|
|
13
|
+
return 'unknown';
|
|
14
|
+
if (s === 'busy' || s === 'shell')
|
|
15
|
+
return 'busy';
|
|
16
|
+
if (s === 'idle')
|
|
17
|
+
return 'idle';
|
|
18
|
+
if (/blocked|wait|permission|input|approv/i.test(s))
|
|
19
|
+
return 'needs-you';
|
|
20
|
+
return 'unknown';
|
|
21
|
+
}
|
|
22
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
|
|
23
|
+
const str = (v) => (typeof v === 'string' && v ? v : undefined);
|
|
24
|
+
/** The transcript Claude Code writes for a session: `projects/<cwd with every other character as ->/<id>.jsonl`. */
|
|
25
|
+
export const claudeTranscript = (dir, cwd, id) => join(dir, 'projects', cwd.replace(/[^a-zA-Z0-9]/g, '-'), `${id}.jsonl`);
|
|
26
|
+
const titleMemo = new Map();
|
|
27
|
+
/**
|
|
28
|
+
* The title Claude Code gave the session itself (the one it shows as the terminal tab title): the last `ai-title`
|
|
29
|
+
* record near the end of the transcript. Only lines of that type are parsed; nothing else of the conversation is read
|
|
30
|
+
* into a result. Remembered until the file changes.
|
|
31
|
+
*/
|
|
32
|
+
export async function claudeAiTitle(transcript) {
|
|
33
|
+
const st = await statOrNull(transcript);
|
|
34
|
+
if (!st?.isFile())
|
|
35
|
+
return undefined;
|
|
36
|
+
const sig = `${st.size}:${st.mtimeMs}`;
|
|
37
|
+
const known = titleMemo.get(transcript);
|
|
38
|
+
if (known?.sig === sig)
|
|
39
|
+
return known.title;
|
|
40
|
+
let title;
|
|
41
|
+
const lines = await tailLinesWith(transcript, '"ai-title"');
|
|
42
|
+
for (let i = lines.length - 1; i >= 0 && !title; i--) {
|
|
43
|
+
try {
|
|
44
|
+
const rec = JSON.parse(lines[i]);
|
|
45
|
+
if (rec.type === 'ai-title')
|
|
46
|
+
title = str(rec.aiTitle)?.trim() || undefined;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// a line still being written
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
titleMemo.set(transcript, { sig, title });
|
|
53
|
+
return title;
|
|
54
|
+
}
|
|
55
|
+
export const claudeLiveSessions = {
|
|
56
|
+
family: 'claude',
|
|
57
|
+
async read(account, procs, problems) {
|
|
58
|
+
const root = join(account.dir, 'sessions');
|
|
59
|
+
let names;
|
|
60
|
+
try {
|
|
61
|
+
names = await readdir(root);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (err.code === 'ENOENT')
|
|
65
|
+
return [];
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
const out = [];
|
|
69
|
+
for (const name of names) {
|
|
70
|
+
const m = PID_FILE.exec(name);
|
|
71
|
+
if (!m)
|
|
72
|
+
continue;
|
|
73
|
+
const pid = Number(m[1]);
|
|
74
|
+
const proc = await procs.get(pid);
|
|
75
|
+
if (!proc)
|
|
76
|
+
continue;
|
|
77
|
+
const file = join(root, name);
|
|
78
|
+
const rec = await readSessionRecord(file);
|
|
79
|
+
if (!rec) {
|
|
80
|
+
problems.push(`${account.ref}: could not read ${file}; it is skipped (Claude Code rewrites it as it runs)`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const sessionId = str(rec.sessionId);
|
|
84
|
+
if (!sessionId)
|
|
85
|
+
continue;
|
|
86
|
+
// The pid may have been reused since: `procStart` is when Claude Code's own process started (UTC). Without
|
|
87
|
+
// a start time to compare, the file cannot be tied to this process, so it is left out.
|
|
88
|
+
if (Number.isNaN(recordStart(rec))) {
|
|
89
|
+
problems.push(`${account.ref}: ${file} has no start time sideby can read, so it cannot tell whether process ${pid} still runs that session and leaves it out; an update of Claude Code writes it again`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!recordRunsOn(rec, proc))
|
|
93
|
+
continue;
|
|
94
|
+
const cwd = str(rec.cwd);
|
|
95
|
+
const candidate = cwd ? claudeTranscript(account.dir, cwd, sessionId) : undefined;
|
|
96
|
+
const transcript = candidate && (await statOrNull(candidate)) ? candidate : undefined;
|
|
97
|
+
// A name the user gave (`/rename`, `-n`) wins; a derived one (`<dir>-3f`) loses to Claude Code's own title.
|
|
98
|
+
const named = rec.nameSource !== 'derived' ? str(rec.name) : undefined;
|
|
99
|
+
const aiTitle = named || !transcript ? undefined : await claudeAiTitle(transcript).catch(() => undefined);
|
|
100
|
+
const title = named ?? aiTitle ?? str(rec.name) ?? (cwd ? basename(cwd) : undefined);
|
|
101
|
+
out.push({
|
|
102
|
+
sessionId,
|
|
103
|
+
...(title ? { title } : {}),
|
|
104
|
+
status: claudeStatus(rec.status),
|
|
105
|
+
...(cwd ? { cwd } : {}),
|
|
106
|
+
pid,
|
|
107
|
+
...(isoOf(num(rec.startedAt)) ? { startedAt: isoOf(num(rec.startedAt)) } : {}),
|
|
108
|
+
...(isoOf(num(rec.updatedAt) ?? num(rec.statusUpdatedAt))
|
|
109
|
+
? { updatedAt: isoOf(num(rec.updatedAt) ?? num(rec.statusUpdatedAt)) }
|
|
110
|
+
: {}),
|
|
111
|
+
guessed: false,
|
|
112
|
+
...(transcript ? { transcript } : {}),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ProcessView } from '../../core/live-sessions-procs.ts';
|
|
2
|
+
/** How long sideby waits for a session's socket to accept the Message. */
|
|
3
|
+
export declare const DELIVER_TIMEOUT_MS = 3000;
|
|
4
|
+
/** The socket path a running session's record names, read from that record only (no other field leaves here). */
|
|
5
|
+
export declare function claudeSocketOf(accountDir: string, pid: number, sessionId: string, procs: ProcessView): Promise<{
|
|
6
|
+
path: string;
|
|
7
|
+
} | {
|
|
8
|
+
problem: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** What a checked socket and its folder were on disk, to tell later that the path still names the same ones. */
|
|
11
|
+
export interface SocketIdentity {
|
|
12
|
+
dev: number;
|
|
13
|
+
ino: number;
|
|
14
|
+
uid: number;
|
|
15
|
+
dirDev: number;
|
|
16
|
+
dirIno: number;
|
|
17
|
+
dirUid: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The folders a Claude Code inbox socket's `cc-socks` directory may sit in: `$XDG_RUNTIME_DIR` when set to an
|
|
21
|
+
* absolute path (Claude Code's first choice on Linux and WSL), then the system temp directories.
|
|
22
|
+
*/
|
|
23
|
+
export declare function socketRoots(env: NodeJS.ProcessEnv): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Whether `name` is a socket folder Claude Code creates: `cc-socks`, or the per-user `cc-socks-<uid>` it falls back to.
|
|
26
|
+
* A suffix must be this user's id when it is known, so another user's fallback folder is never accepted.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isSocketFolderName(name: string, uid: number | undefined): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Checks `path` as a socket sideby may write to: an absolute path whose directory is `cc-socks` (or this user's
|
|
31
|
+
* `cc-socks-<uid>`) right inside one of `tempRoots` (`socketRoots`), that directory a real directory of `uid` that no
|
|
32
|
+
* one else can enter, and `path` itself a socket of `uid`, not a link. Returns why not, or what the socket and its
|
|
33
|
+
* folder are on disk.
|
|
34
|
+
*/
|
|
35
|
+
export declare function checkSocket(path: string, o: {
|
|
36
|
+
tempRoots: readonly string[];
|
|
37
|
+
uid: number | undefined;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
problem: string;
|
|
40
|
+
} | {
|
|
41
|
+
identity: SocketIdentity;
|
|
42
|
+
}>;
|
|
43
|
+
/** `checkSocket` as a reason only: null when sideby may write to `path`. */
|
|
44
|
+
export declare function socketProblem(path: string, o: {
|
|
45
|
+
tempRoots: readonly string[];
|
|
46
|
+
uid: number | undefined;
|
|
47
|
+
}): Promise<string | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Why `path` no longer names the socket and folder `id` describes (replaced, made a link, given to another user), or
|
|
50
|
+
* null when it still does. Run after connecting and before writing, so a swap after the check is caught.
|
|
51
|
+
* Node offers no way to ask a Unix socket's peer for its pid without a native module (macOS `LOCAL_PEERPID`, Linux
|
|
52
|
+
* `SO_PEERCRED`), so the peer itself is not compared; the path, its folder and their owners are.
|
|
53
|
+
*/
|
|
54
|
+
export declare function socketChanged(path: string, id: SocketIdentity): Promise<string | null>;
|
|
55
|
+
/** The one line Claude Code reads from its socket as a user message. */
|
|
56
|
+
export declare const messageLine: (text: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
|
|
59
|
+
* connection as soon as the line is flushed, also when the peer keeps its end open. Rejects on a refused connection
|
|
60
|
+
* or after `timeoutMs`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function writeToSocket(path: string, line: string, timeoutMs?: number, verify?: () => Promise<string | null>): Promise<void>;
|
|
63
|
+
/** Whether Host arguments start Claude Code in bypass permission mode. */
|
|
64
|
+
export declare function argsBypass(args: readonly string[]): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether a running session is in bypass permission mode: the last `permission-mode` record near the end of its
|
|
67
|
+
* transcript (it follows Shift+Tab), else its process arguments. Only those records are parsed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function sessionBypass(transcript: string | undefined, args: readonly string[]): Promise<boolean>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Claude Code's own cross-session channel (spec §3.32 step 2, ADR-0040; tried with Claude Code 2.1.304 on
|
|
2
|
+
// 2026-10-20). Each running session names a Unix socket in its `<dir>/sessions/<pid>.json` (`messagingSocketPath`).
|
|
3
|
+
// Claude Code binds it under `$XDG_RUNTIME_DIR/cc-socks/` where that variable is set (Linux, WSL), else under the
|
|
4
|
+
// system temp directory's `cc-socks/`, and falls back to a per-user `cc-socks-<uid>/` when it cannot accept the shared
|
|
5
|
+
// folder (its docs, "The session's inbox socket"). One JSON line written to it reaches that session as "Another
|
|
6
|
+
// Claude session sent a message". sideby writes there only after the checks below, sends no token, and never opens
|
|
7
|
+
// the `<pid>.<hash>.key` files next to the record.
|
|
8
|
+
import { createConnection } from 'node:net';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { basename, dirname, isAbsolute } from 'node:path';
|
|
11
|
+
import { lstatOrNull, realpathOrNull } from '../../core/fs-safe.js';
|
|
12
|
+
import { readSessionRecord, recordRunsOn, sessionRecordPath, tailLinesWith } from './session-files.js';
|
|
13
|
+
/** How long sideby waits for a session's socket to accept the Message. */
|
|
14
|
+
export const DELIVER_TIMEOUT_MS = 3_000;
|
|
15
|
+
/** The socket path a running session's record names, read from that record only (no other field leaves here). */
|
|
16
|
+
export async function claudeSocketOf(accountDir, pid, sessionId, procs) {
|
|
17
|
+
const rec = await readSessionRecord(sessionRecordPath(accountDir, pid));
|
|
18
|
+
if (!rec)
|
|
19
|
+
return { problem: 'sideby could not read its session info' };
|
|
20
|
+
if (rec.sessionId !== sessionId)
|
|
21
|
+
return { problem: 'that terminal is now running a different session' };
|
|
22
|
+
if (!recordRunsOn(rec, await procs.get(pid)))
|
|
23
|
+
return { problem: 'the session has ended' };
|
|
24
|
+
const path = rec.messagingSocketPath;
|
|
25
|
+
if (typeof path !== 'string' || !path)
|
|
26
|
+
return {
|
|
27
|
+
problem: 'this Claude Code version cannot receive messages directly (update to 2.1.304 or newer)',
|
|
28
|
+
};
|
|
29
|
+
return { path };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The folders a Claude Code inbox socket's `cc-socks` directory may sit in: `$XDG_RUNTIME_DIR` when set to an
|
|
33
|
+
* absolute path (Claude Code's first choice on Linux and WSL), then the system temp directories.
|
|
34
|
+
*/
|
|
35
|
+
export function socketRoots(env) {
|
|
36
|
+
const runtime = env.XDG_RUNTIME_DIR;
|
|
37
|
+
return [...(runtime && isAbsolute(runtime) ? [runtime] : []), tmpdir(), '/tmp'];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether `name` is a socket folder Claude Code creates: `cc-socks`, or the per-user `cc-socks-<uid>` it falls back to.
|
|
41
|
+
* A suffix must be this user's id when it is known, so another user's fallback folder is never accepted.
|
|
42
|
+
*/
|
|
43
|
+
export function isSocketFolderName(name, uid) {
|
|
44
|
+
const m = /^cc-socks(?:-(\d+))?$/.exec(name);
|
|
45
|
+
if (!m)
|
|
46
|
+
return false;
|
|
47
|
+
return m[1] === undefined || uid === undefined || Number(m[1]) === uid;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Checks `path` as a socket sideby may write to: an absolute path whose directory is `cc-socks` (or this user's
|
|
51
|
+
* `cc-socks-<uid>`) right inside one of `tempRoots` (`socketRoots`), that directory a real directory of `uid` that no
|
|
52
|
+
* one else can enter, and `path` itself a socket of `uid`, not a link. Returns why not, or what the socket and its
|
|
53
|
+
* folder are on disk.
|
|
54
|
+
*/
|
|
55
|
+
export async function checkSocket(path, o) {
|
|
56
|
+
const no = (problem) => ({ problem });
|
|
57
|
+
if (!isAbsolute(path))
|
|
58
|
+
return no('its message channel path is invalid (restart the session to fix it)');
|
|
59
|
+
const dir = dirname(path);
|
|
60
|
+
if (!isSocketFolderName(basename(dir), o.uid))
|
|
61
|
+
return no('its message channel is not in a cc-socks folder (restart the session to fix it)');
|
|
62
|
+
const roots = new Set((await Promise.all(o.tempRoots.map((r) => realpathOrNull(r)))).filter((r) => r !== null));
|
|
63
|
+
const parent = await realpathOrNull(dirname(dir));
|
|
64
|
+
if (!parent || !roots.has(parent))
|
|
65
|
+
return no('its message channel is outside the system temp folder (restart the session to fix it)');
|
|
66
|
+
const d = await lstatOrNull(dir);
|
|
67
|
+
if (!d?.isDirectory())
|
|
68
|
+
return no('its message channel folder is not a real folder (restart the session to fix it)');
|
|
69
|
+
if (o.uid !== undefined && d.uid !== o.uid)
|
|
70
|
+
return no('its message channel folder belongs to another user on this computer');
|
|
71
|
+
if (d.mode & 0o077)
|
|
72
|
+
return no('other users on this computer can access its message channel folder (restart the session to fix it)');
|
|
73
|
+
const s = await lstatOrNull(path);
|
|
74
|
+
if (!s)
|
|
75
|
+
return no('its message channel is gone (the session may have ended)');
|
|
76
|
+
if (s.isSymbolicLink())
|
|
77
|
+
return no('its message channel is a symlink instead of a live channel (restart the session to fix it)');
|
|
78
|
+
if (!s.isSocket())
|
|
79
|
+
return no('its message channel is not a valid channel file (restart the session to fix it)');
|
|
80
|
+
if (o.uid !== undefined && s.uid !== o.uid)
|
|
81
|
+
return no('its message channel belongs to another user on this computer');
|
|
82
|
+
return {
|
|
83
|
+
identity: { dev: s.dev, ino: s.ino, uid: s.uid, dirDev: d.dev, dirIno: d.ino, dirUid: d.uid },
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** `checkSocket` as a reason only: null when sideby may write to `path`. */
|
|
87
|
+
export async function socketProblem(path, o) {
|
|
88
|
+
const r = await checkSocket(path, o);
|
|
89
|
+
return 'problem' in r ? r.problem : null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Why `path` no longer names the socket and folder `id` describes (replaced, made a link, given to another user), or
|
|
93
|
+
* null when it still does. Run after connecting and before writing, so a swap after the check is caught.
|
|
94
|
+
* Node offers no way to ask a Unix socket's peer for its pid without a native module (macOS `LOCAL_PEERPID`, Linux
|
|
95
|
+
* `SO_PEERCRED`), so the peer itself is not compared; the path, its folder and their owners are.
|
|
96
|
+
*/
|
|
97
|
+
export async function socketChanged(path, id) {
|
|
98
|
+
const d = await lstatOrNull(dirname(path));
|
|
99
|
+
if (!d?.isDirectory() || d.dev !== id.dirDev || d.ino !== id.dirIno || d.uid !== id.dirUid)
|
|
100
|
+
return 'its message channel folder changed while sending (send again)';
|
|
101
|
+
const s = await lstatOrNull(path);
|
|
102
|
+
if (!s?.isSocket() || s.dev !== id.dev || s.ino !== id.ino || s.uid !== id.uid)
|
|
103
|
+
return 'its message channel changed while sending (send again)';
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
/** The one line Claude Code reads from its socket as a user message. */
|
|
107
|
+
export const messageLine = (text) => `${JSON.stringify({ type: 'user', message: { role: 'user', content: text } })}\n`;
|
|
108
|
+
/**
|
|
109
|
+
* Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
|
|
110
|
+
* connection as soon as the line is flushed, also when the peer keeps its end open. Rejects on a refused connection
|
|
111
|
+
* or after `timeoutMs`.
|
|
112
|
+
*/
|
|
113
|
+
export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify) {
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
let done = false;
|
|
116
|
+
const sock = createConnection({ path });
|
|
117
|
+
const finish = (err) => {
|
|
118
|
+
if (done)
|
|
119
|
+
return;
|
|
120
|
+
done = true;
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
sock.destroy();
|
|
123
|
+
if (err)
|
|
124
|
+
reject(err);
|
|
125
|
+
else
|
|
126
|
+
resolve();
|
|
127
|
+
};
|
|
128
|
+
const timer = setTimeout(() => finish(new Error(`it did not answer within ${timeoutMs / 1000} s`)), timeoutMs);
|
|
129
|
+
sock.once('connect', async () => {
|
|
130
|
+
const changed = verify ? await verify().catch((e) => e.message) : null;
|
|
131
|
+
if (changed)
|
|
132
|
+
return finish(new Error(changed));
|
|
133
|
+
if (done)
|
|
134
|
+
return;
|
|
135
|
+
sock.end(line, () => finish(null));
|
|
136
|
+
});
|
|
137
|
+
sock.once('error', (err) => finish(new Error(err.code === 'ECONNREFUSED' ? 'it refused the connection' : (err.code ?? err.message))));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** Whether Host arguments start Claude Code in bypass permission mode. */
|
|
141
|
+
export function argsBypass(args) {
|
|
142
|
+
return args.some((a, i) => a === '--dangerously-skip-permissions' ||
|
|
143
|
+
a === '--permission-mode=bypassPermissions' ||
|
|
144
|
+
(a === '--permission-mode' && args[i + 1] === 'bypassPermissions'));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Whether a running session is in bypass permission mode: the last `permission-mode` record near the end of its
|
|
148
|
+
* transcript (it follows Shift+Tab), else its process arguments. Only those records are parsed.
|
|
149
|
+
*/
|
|
150
|
+
export async function sessionBypass(transcript, args) {
|
|
151
|
+
if (transcript) {
|
|
152
|
+
const lines = await tailLinesWith(transcript, '"permission-mode"').catch(() => []);
|
|
153
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
154
|
+
try {
|
|
155
|
+
const rec = JSON.parse(lines[i]);
|
|
156
|
+
if (rec.type === 'permission-mode' && typeof rec.permissionMode === 'string')
|
|
157
|
+
return rec.permissionMode === 'bypassPermissions';
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// a line still being written
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return argsBypass(args);
|
|
165
|
+
}
|