sideby 0.40.0 → 0.41.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 +2 -2
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +7 -0
- package/dist/src/cli/commands.js +144 -0
- package/dist/src/cli/json-schemas.js +68 -0
- package/dist/src/cli/main.js +30 -0
- package/dist/src/core/claude-trust.d.ts +198 -0
- package/dist/src/core/claude-trust.js +559 -0
- package/dist/src/core/cli-commands.js +14 -2
- package/dist/src/core/config.d.ts +7 -3
- package/dist/src/core/config.js +12 -5
- package/dist/src/core/handoff-run.js +192 -175
- package/dist/src/core/search-catalog.js +23 -0
- package/dist/src/core/session-hooks.d.ts +7 -0
- package/dist/src/core/session-hooks.js +27 -0
- package/dist/src/families/claude/handoff.js +3 -1
- package/dist/src/panel/handler.d.ts +14 -0
- package/dist/src/panel/handler.js +55 -0
- package/dist/src/panel/i18n.d.ts +22 -0
- package/dist/src/panel/i18n.js +44 -0
- package/dist/src/panel/page-script.js +79 -1
- package/dist/src/runtime.d.ts +32 -0
- package/dist/src/runtime.js +74 -1
- package/package.json +2 -2
- package/schemas/config.json +5 -1
- package/schemas/trust-set.json +117 -0
- package/schemas/trust-undo.json +155 -0
- package/schemas/trust.json +183 -0
- package/skills/sideby/SKILL.md +2 -1
- package/skills/sideby/references/trust.md +28 -0
|
@@ -14,7 +14,7 @@ import { briefPath, chainDir, ensureChainDir, FILES, HANDOFF_ENV, newId, readJso
|
|
|
14
14
|
import { beforeDashes, runHost, sidebyBinProblem, spawnHost } from './launch.js';
|
|
15
15
|
import { withoutArgs } from './network.js';
|
|
16
16
|
import { quotaPressure } from './quota-levels.js';
|
|
17
|
-
import { withClaudeSessionHooks } from './session-hooks.js';
|
|
17
|
+
import { withClaudeDirs, withClaudeSessionHooks } from './session-hooks.js';
|
|
18
18
|
/** How long the Host gets to exit after SIGTERM (time for its SessionEnd hooks) before sideby gives up. */
|
|
19
19
|
export const EXIT_GRACE_MS = 10_000;
|
|
20
20
|
const PLAN_REFRESH_MS = 60_000;
|
|
@@ -201,188 +201,205 @@ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
|
|
|
201
201
|
const own = rt.config.aliases?.[ref];
|
|
202
202
|
let hop = { ref, args: [...aliasArgs(own), ...userArgs] };
|
|
203
203
|
let n = 1;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
// Later hops carry no `--` of their own (continueArgs drops it), so the prompt goes after a fresh one.
|
|
234
|
-
if (hop.prompt)
|
|
235
|
-
args.push(...h.promptArgs(hop.prompt));
|
|
236
|
-
hops.hops.push({ ref: account.ref, startedAt: new Date().toISOString() });
|
|
237
|
-
await writeJsonFile(join(dir, FILES.chain), hops);
|
|
238
|
-
if (launch.notice)
|
|
239
|
-
io.err(launch.notice);
|
|
240
|
-
if (!canStart)
|
|
241
|
-
return runHost({ ...launch, args, env });
|
|
242
|
-
// Plan writes run one after another, and none lands after this hop is over: a late one would carry this
|
|
243
|
-
// run's id into the next hop's plan.json and silence its hook.
|
|
244
|
-
let stopped = false;
|
|
245
|
-
let pending = Promise.resolve();
|
|
246
|
-
const writePlan = () => {
|
|
247
|
-
pending = pending.then(async () => {
|
|
248
|
-
try {
|
|
249
|
-
// Read by the hook once the threshold is crossed, so it answers for that moment (spec §3.17 "选号" 1).
|
|
250
|
-
const d = await rt.handoffDecision(account, hops.hops, { ahead: true });
|
|
251
|
-
if (stopped)
|
|
252
|
-
return;
|
|
253
|
-
const plan = {
|
|
254
|
-
runId,
|
|
255
|
-
brief,
|
|
256
|
-
at: new Date().toISOString(),
|
|
257
|
-
decision: d.kind,
|
|
258
|
-
...(d.kind === 'pick' ? { pick: d.ref } : {}),
|
|
259
|
-
...(d.kind === 'wait' ? { until: d.until } : {}),
|
|
260
|
-
prepareAt: settings.prepareAt,
|
|
261
|
-
threshold: settings.threshold,
|
|
262
|
-
adaptive: settings.adaptive,
|
|
263
|
-
...(elig.agentBrief === false ? { agentBrief: false } : {}),
|
|
264
|
-
acceptsTo: true,
|
|
265
|
-
};
|
|
266
|
-
await writeJsonFile(join(dir, FILES.plan), plan);
|
|
204
|
+
const chainSettings = join(rt.paths.stateDir, 'handoff', 'chains', `${chain}-claude.json`);
|
|
205
|
+
try {
|
|
206
|
+
for (;;) {
|
|
207
|
+
const launch = n === 1 ? firstLaunch : await rt.prepareLaunch(hop.ref, hop.args, 'run', launchOpts);
|
|
208
|
+
const account = launch.account;
|
|
209
|
+
const h = launch.family.handoff;
|
|
210
|
+
if (!h)
|
|
211
|
+
return await runHost(launch);
|
|
212
|
+
const elig = n === 1 ? firstElig : await h.eligibility(withoutNetwork(launch), account, launch.env);
|
|
213
|
+
const canStart = h.starts.length > 0 && elig.start && HOOK_FAMILIES.includes(account.family);
|
|
214
|
+
if (!canStart && elig.reason)
|
|
215
|
+
io.err(`sideby: ${account.ref} will not hand over: ${elig.reason}`);
|
|
216
|
+
const runId = newId();
|
|
217
|
+
const brief = briefPath(dir, n, account.ref);
|
|
218
|
+
const extra = [...(elig.args ?? [])];
|
|
219
|
+
const env = { ...launch.env };
|
|
220
|
+
// Claude takes one `--settings`: sideby's session hooks (Network Guard §3.35, Unattended Mode §3.37) go into Auto
|
|
221
|
+
// Handoff's file.
|
|
222
|
+
const sessionArgs = launch.sessionHookArgs ?? launch.networkArgs ?? [];
|
|
223
|
+
const mergeNet = canStart && account.family === 'claude' && sessionArgs.length > 0;
|
|
224
|
+
let dirInSettings = false;
|
|
225
|
+
if (canStart) {
|
|
226
|
+
const hookArgs = (await h.hookArgs?.(hookCommand(account.family), rt.paths.stateDir)) ?? [];
|
|
227
|
+
let settingsArgs = mergeNet ? await withClaudeSessionHooks(hookArgs, sessionArgs) : hookArgs;
|
|
228
|
+
// Claude Code 2.1.326 asks to trust a folder given by `--add-dir`; one in sideby's `--settings` file needs no
|
|
229
|
+
// question. The file is the chain's own, outside the chain directory the session may write to.
|
|
230
|
+
if (account.family === 'claude' && settingsArgs.includes('--settings')) {
|
|
231
|
+
settingsArgs = await withClaudeDirs(settingsArgs, [dir], chainSettings);
|
|
232
|
+
dirInSettings = true;
|
|
267
233
|
}
|
|
268
|
-
|
|
269
|
-
|
|
234
|
+
extra.push(...settingsArgs);
|
|
235
|
+
env[HANDOFF_ENV.run] = runId;
|
|
236
|
+
env[HANDOFF_ENV.family] = account.family;
|
|
237
|
+
env[HANDOFF_ENV.dir] = dir;
|
|
238
|
+
if (account.family === 'codex')
|
|
239
|
+
await codexTrustNotice(rt, account, io);
|
|
240
|
+
}
|
|
241
|
+
// Where sideby cannot add to `--settings` (the user gave their own), Claude Code asks to trust the folder.
|
|
242
|
+
if (!dirInSettings)
|
|
243
|
+
extra.push(...(h.dirArgs?.(dir) ?? []));
|
|
244
|
+
const args = beforeDashes(mergeNet ? withoutNetwork(launch) : launch.args, extra);
|
|
245
|
+
// Later hops carry no `--` of their own (continueArgs drops it), so the prompt goes after a fresh one.
|
|
246
|
+
if (hop.prompt)
|
|
247
|
+
args.push(...h.promptArgs(hop.prompt));
|
|
248
|
+
hops.hops.push({ ref: account.ref, startedAt: new Date().toISOString() });
|
|
249
|
+
await writeJsonFile(join(dir, FILES.chain), hops);
|
|
250
|
+
if (launch.notice)
|
|
251
|
+
io.err(launch.notice);
|
|
252
|
+
if (!canStart)
|
|
253
|
+
return await runHost({ ...launch, args, env });
|
|
254
|
+
// Plan writes run one after another, and none lands after this hop is over: a late one would carry this
|
|
255
|
+
// run's id into the next hop's plan.json and silence its hook.
|
|
256
|
+
let stopped = false;
|
|
257
|
+
let pending = Promise.resolve();
|
|
258
|
+
const writePlan = () => {
|
|
259
|
+
pending = pending.then(async () => {
|
|
260
|
+
try {
|
|
261
|
+
// Read by the hook once the threshold is crossed, so it answers for that moment (spec §3.17 "选号" 1).
|
|
262
|
+
const d = await rt.handoffDecision(account, hops.hops, { ahead: true });
|
|
263
|
+
if (stopped)
|
|
264
|
+
return;
|
|
265
|
+
const plan = {
|
|
266
|
+
runId,
|
|
267
|
+
brief,
|
|
268
|
+
at: new Date().toISOString(),
|
|
269
|
+
decision: d.kind,
|
|
270
|
+
...(d.kind === 'pick' ? { pick: d.ref } : {}),
|
|
271
|
+
...(d.kind === 'wait' ? { until: d.until } : {}),
|
|
272
|
+
prepareAt: settings.prepareAt,
|
|
273
|
+
threshold: settings.threshold,
|
|
274
|
+
adaptive: settings.adaptive,
|
|
275
|
+
...(elig.agentBrief === false ? { agentBrief: false } : {}),
|
|
276
|
+
acceptsTo: true,
|
|
277
|
+
};
|
|
278
|
+
await writeJsonFile(join(dir, FILES.plan), plan);
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// the hook treats a missing plan as "do not interrupt"
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
return pending;
|
|
285
|
+
};
|
|
286
|
+
await writePlan();
|
|
287
|
+
const refresh = setInterval(() => void writePlan(), PLAN_REFRESH_MS);
|
|
288
|
+
const host = spawnHost({ ...launch, args, env });
|
|
289
|
+
const exited = host.exited.then((code) => ({ kind: 'exit', code }));
|
|
290
|
+
// Nothing to move on to (or better to wait): leave the session alone, keep listening (the user may still ask to
|
|
291
|
+
// move on while it waits, ADR-0018), and say why once it ends.
|
|
292
|
+
let kept;
|
|
293
|
+
let outcome;
|
|
294
|
+
for (;;) {
|
|
295
|
+
const watcher = watchReady(dir, runId);
|
|
296
|
+
const got = await Promise.race([
|
|
297
|
+
exited,
|
|
298
|
+
watcher.ready.then((ready) => ({ kind: 'ready', ready })),
|
|
299
|
+
]);
|
|
300
|
+
watcher.stop();
|
|
301
|
+
if (got.kind === 'exit') {
|
|
302
|
+
outcome = got;
|
|
303
|
+
break;
|
|
270
304
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
305
|
+
const d = await decide(rt, account, hops.hops, got.ready.to, got.ready.trigger === 'manual');
|
|
306
|
+
if (d.kind === 'pick') {
|
|
307
|
+
outcome = { ...got, decision: d };
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
await rm(join(dir, FILES.ready), { force: true });
|
|
311
|
+
// A session kept at its limit (or kept to wait) ends no turn until it continues, so a request would never be
|
|
312
|
+
// picked up: `waiting.json` lets `handoff ready` hand over at once (ADR-0018). A `threshold` none is still in
|
|
313
|
+
// its turns and gets none.
|
|
314
|
+
const until = d.kind === 'wait' ? d.until : got.ready.trigger === 'limit' ? limitUntil(got.ready) : undefined;
|
|
315
|
+
if (until)
|
|
316
|
+
await writeJsonFile(join(dir, FILES.waiting), {
|
|
317
|
+
runId,
|
|
318
|
+
until,
|
|
319
|
+
at: new Date().toISOString(),
|
|
320
|
+
trigger: got.ready.trigger,
|
|
321
|
+
});
|
|
322
|
+
kept = d;
|
|
323
|
+
}
|
|
324
|
+
clearInterval(refresh);
|
|
325
|
+
stopped = true;
|
|
326
|
+
await pending;
|
|
327
|
+
await rm(join(dir, FILES.waiting), { force: true });
|
|
328
|
+
if (outcome.kind === 'exit') {
|
|
329
|
+
if (kept)
|
|
330
|
+
io.err(`sideby: ${account.ref} did not hand over: ${explain(kept)}`);
|
|
331
|
+
else
|
|
332
|
+
await noteUnhandedHighQuota(rt, account, hops.hops, settings.threshold, io);
|
|
333
|
+
return outcome.code;
|
|
292
334
|
}
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
335
|
+
const decision = outcome.decision;
|
|
336
|
+
// The session is ready: end the Host, give it time to save, never kill it.
|
|
337
|
+
host.child.kill('SIGTERM');
|
|
338
|
+
const ended = await Promise.race([
|
|
339
|
+
host.exited.then((code) => ({ code })),
|
|
340
|
+
new Promise((r) => setTimeout(() => r(null), grace).unref()),
|
|
341
|
+
]);
|
|
342
|
+
if (!ended) {
|
|
343
|
+
io.err(`sideby: ${account.ref} did not exit within ${grace / 1000}s, so nothing was handed over; exit it yourself, then start the next account with \`sideby run ${decision.ref}\``);
|
|
344
|
+
return await host.exited;
|
|
297
345
|
}
|
|
346
|
+
const ready = outcome.ready;
|
|
347
|
+
const assembled = await h
|
|
348
|
+
.briefFromSession?.(account, {
|
|
349
|
+
...(ready.sessionId ? { id: ready.sessionId } : {}),
|
|
350
|
+
...(ready.transcriptPath ? { transcriptPath: ready.transcriptPath } : {}),
|
|
351
|
+
})
|
|
352
|
+
.catch(() => undefined);
|
|
353
|
+
const done = await finishBrief({
|
|
354
|
+
target: brief,
|
|
355
|
+
ready,
|
|
356
|
+
...(assembled ? { assembled } : {}),
|
|
357
|
+
cwd: process.cwd(),
|
|
358
|
+
});
|
|
359
|
+
const last = hops.hops[hops.hops.length - 1];
|
|
360
|
+
Object.assign(last, {
|
|
361
|
+
trigger: ready.trigger,
|
|
362
|
+
briefSource: done.source,
|
|
363
|
+
brief: done.path,
|
|
364
|
+
...(ready.window ? { window: ready.window } : {}),
|
|
365
|
+
});
|
|
366
|
+
await writeJsonFile(join(dir, FILES.chain), hops);
|
|
298
367
|
await rm(join(dir, FILES.ready), { force: true });
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
await noteUnhandedHighQuota(rt, account, hops.hops, settings.threshold, io);
|
|
321
|
-
return outcome.code;
|
|
322
|
-
}
|
|
323
|
-
const decision = outcome.decision;
|
|
324
|
-
// The session is ready: end the Host, give it time to save, never kill it.
|
|
325
|
-
host.child.kill('SIGTERM');
|
|
326
|
-
const ended = await Promise.race([
|
|
327
|
-
host.exited.then((code) => ({ code })),
|
|
328
|
-
new Promise((r) => setTimeout(() => r(null), grace).unref()),
|
|
329
|
-
]);
|
|
330
|
-
if (!ended) {
|
|
331
|
-
io.err(`sideby: ${account.ref} did not exit within ${grace / 1000}s, so nothing was handed over; exit it yourself, then start the next account with \`sideby run ${decision.ref}\``);
|
|
332
|
-
return host.exited;
|
|
333
|
-
}
|
|
334
|
-
const ready = outcome.ready;
|
|
335
|
-
const assembled = await h
|
|
336
|
-
.briefFromSession?.(account, {
|
|
337
|
-
...(ready.sessionId ? { id: ready.sessionId } : {}),
|
|
338
|
-
...(ready.transcriptPath ? { transcriptPath: ready.transcriptPath } : {}),
|
|
339
|
-
})
|
|
340
|
-
.catch(() => undefined);
|
|
341
|
-
const done = await finishBrief({
|
|
342
|
-
target: brief,
|
|
343
|
-
ready,
|
|
344
|
-
...(assembled ? { assembled } : {}),
|
|
345
|
-
cwd: process.cwd(),
|
|
346
|
-
});
|
|
347
|
-
const last = hops.hops[hops.hops.length - 1];
|
|
348
|
-
Object.assign(last, {
|
|
349
|
-
trigger: ready.trigger,
|
|
350
|
-
briefSource: done.source,
|
|
351
|
-
brief: done.path,
|
|
352
|
-
...(ready.window ? { window: ready.window } : {}),
|
|
353
|
-
});
|
|
354
|
-
await writeJsonFile(join(dir, FILES.chain), hops);
|
|
355
|
-
await rm(join(dir, FILES.ready), { force: true });
|
|
356
|
-
await rm(join(dir, FILES.request), { force: true });
|
|
357
|
-
io.err(`sideby: ${account.ref} saved its session and is handing over because ${WHY[ready.trigger]}${ready.window ? ` (${windowText(ready.window)})` : ''}; next is ${decision.ref}${skippedText(decision)}. Brief: ${done.path}`);
|
|
358
|
-
if (settings.countdownSeconds > 0 &&
|
|
359
|
-
(await countdown(io, settings.countdownSeconds, decision.ref, account.ref))) {
|
|
360
|
-
io.err(`sideby: staying in ${account.ref}`);
|
|
361
|
-
if (!ready.sessionId) {
|
|
362
|
-
io.err(`sideby: the session id is unknown, so start ${account.ref} yourself; the Brief is at ${done.path}`);
|
|
368
|
+
await rm(join(dir, FILES.request), { force: true });
|
|
369
|
+
io.err(`sideby: ${account.ref} saved its session and is handing over because ${WHY[ready.trigger]}${ready.window ? ` (${windowText(ready.window)})` : ''}; next is ${decision.ref}${skippedText(decision)}. Brief: ${done.path}`);
|
|
370
|
+
if (settings.countdownSeconds > 0 &&
|
|
371
|
+
(await countdown(io, settings.countdownSeconds, decision.ref, account.ref))) {
|
|
372
|
+
io.err(`sideby: staying in ${account.ref}`);
|
|
373
|
+
if (!ready.sessionId) {
|
|
374
|
+
io.err(`sideby: the session id is unknown, so start ${account.ref} yourself; the Brief is at ${done.path}`);
|
|
375
|
+
return ended.code;
|
|
376
|
+
}
|
|
377
|
+
const backArgs = [...h.continueArgs(hop.args), ...h.resumeArgs(ready.sessionId)];
|
|
378
|
+
const back = await rt.prepareLaunch(account.ref, backArgs, 'run', launchOpts);
|
|
379
|
+
// The same per-Account arguments as before (Grok's leader socket), without sideby's hooks.
|
|
380
|
+
const backElig = await h.eligibility(withoutNetwork(back), account, back.env);
|
|
381
|
+
return await runHost({ ...back, args: beforeDashes(back.args, backElig.args ?? []) });
|
|
382
|
+
}
|
|
383
|
+
let next;
|
|
384
|
+
try {
|
|
385
|
+
next = await rt.resolve(decision.ref);
|
|
386
|
+
}
|
|
387
|
+
catch (err) {
|
|
388
|
+
io.err(`sideby: cannot start ${decision.ref}: ${err.message}; the Brief is at ${done.path}`);
|
|
363
389
|
return ended.code;
|
|
364
390
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
try {
|
|
373
|
-
next = await rt.resolve(decision.ref);
|
|
374
|
-
}
|
|
375
|
-
catch (err) {
|
|
376
|
-
io.err(`sideby: cannot start ${decision.ref}: ${err.message}; the Brief is at ${done.path}`);
|
|
377
|
-
return ended.code;
|
|
391
|
+
io.err(`sideby: handing over from ${account.ref} to ${next.ref}`);
|
|
392
|
+
hop = {
|
|
393
|
+
ref: next.ref,
|
|
394
|
+
args: next.family === account.family ? h.continueArgs(hop.args) : [],
|
|
395
|
+
prompt: firstPrompt(account.ref, done.path, ready.trigger),
|
|
396
|
+
};
|
|
397
|
+
n++;
|
|
378
398
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
prompt: firstPrompt(account.ref, done.path, ready.trigger),
|
|
384
|
-
};
|
|
385
|
-
n++;
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
// Read by Claude Code while a session runs, so it goes only once the chain's last Host is over.
|
|
402
|
+
await rm(chainSettings, { force: true });
|
|
386
403
|
}
|
|
387
404
|
}
|
|
388
405
|
/** After a session ended on its own: when its Quota passed the threshold but nothing could take over, say why. */
|
|
@@ -205,6 +205,29 @@ const ENTRIES = [
|
|
|
205
205
|
target: { settings: 'accounts', find: 'advisor' },
|
|
206
206
|
cliCommand: 'sideby advisor',
|
|
207
207
|
},
|
|
208
|
+
{
|
|
209
|
+
id: 'setting.trust',
|
|
210
|
+
kind: 'setting',
|
|
211
|
+
title: { en: 'Folder trust', zh: '文件夹信任' },
|
|
212
|
+
synonyms: [
|
|
213
|
+
'trust',
|
|
214
|
+
'trust this folder',
|
|
215
|
+
'do you trust',
|
|
216
|
+
'quick safety check',
|
|
217
|
+
'accessing workspace',
|
|
218
|
+
'workspace trust',
|
|
219
|
+
'trust dialog',
|
|
220
|
+
'carry trust',
|
|
221
|
+
'信任',
|
|
222
|
+
'信任文件夹',
|
|
223
|
+
'信任此文件夹',
|
|
224
|
+
'安全检查',
|
|
225
|
+
'每次都问信任',
|
|
226
|
+
],
|
|
227
|
+
panel: at(SET, { en: 'Folder trust', zh: '文件夹信任' }),
|
|
228
|
+
target: { settings: 'trust', find: 'trust' },
|
|
229
|
+
cliCommand: 'sideby trust',
|
|
230
|
+
},
|
|
208
231
|
{
|
|
209
232
|
id: 'setting.quota-checks',
|
|
210
233
|
kind: 'setting',
|
|
@@ -31,6 +31,13 @@ export declare function sessionHookArgs(family: string, stateDir: string, parts:
|
|
|
31
31
|
* Code takes one `--settings`). Auto Handoff's own hooks and options come first and are kept as they are.
|
|
32
32
|
*/
|
|
33
33
|
export declare function withClaudeHooks(hookArgs: readonly string[], extra: ClaudeHooks, out: string): Promise<string[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Claude `--settings` arguments with `dirs` added to the file's `permissions.additionalDirectories`, written as `out`.
|
|
36
|
+
* Claude Code 2.1.326 asks the user to trust every `--add-dir` folder it has not seen before the session starts, and
|
|
37
|
+
* exits on "No"; a folder from `--settings` becomes a working directory without that question (tried with Claude Code
|
|
38
|
+
* 2.1.326 on 2026-11-17). Each folder is listed as given and, when a link leads to it, by its real path too.
|
|
39
|
+
*/
|
|
40
|
+
export declare function withClaudeDirs(args: readonly string[], dirs: readonly string[], out: string): Promise<string[]>;
|
|
34
41
|
/**
|
|
35
42
|
* Auto Handoff's Claude hook arguments with the session's own sideby hooks (`sessionArgs`, from `sessionHookArgs`)
|
|
36
43
|
* merged into one `--settings` file, written next to the session's file with `-handoff` added to its name.
|
|
@@ -92,6 +92,33 @@ export async function withClaudeHooks(hookArgs, extra, out) {
|
|
|
92
92
|
const at = hookArgs.indexOf('--settings');
|
|
93
93
|
return at === -1 ? [...hookArgs, '--settings', out] : hookArgs.map((a, i) => (i === at + 1 ? out : a));
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Claude `--settings` arguments with `dirs` added to the file's `permissions.additionalDirectories`, written as `out`.
|
|
97
|
+
* Claude Code 2.1.326 asks the user to trust every `--add-dir` folder it has not seen before the session starts, and
|
|
98
|
+
* exits on "No"; a folder from `--settings` becomes a working directory without that question (tried with Claude Code
|
|
99
|
+
* 2.1.326 on 2026-11-17). Each folder is listed as given and, when a link leads to it, by its real path too.
|
|
100
|
+
*/
|
|
101
|
+
export async function withClaudeDirs(args, dirs, out) {
|
|
102
|
+
const settings = await settingsOf(args);
|
|
103
|
+
const permissions = settings.permissions && typeof settings.permissions === 'object' && !Array.isArray(settings.permissions)
|
|
104
|
+
? settings.permissions
|
|
105
|
+
: {};
|
|
106
|
+
const had = Array.isArray(permissions.additionalDirectories) ? permissions.additionalDirectories : [];
|
|
107
|
+
const add = dirs.flatMap((d) => {
|
|
108
|
+
try {
|
|
109
|
+
const real = realpathSync(d);
|
|
110
|
+
return real === d ? [d] : [d, real];
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return [d];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
const additionalDirectories = [...new Set([...had, ...add])];
|
|
117
|
+
await mkdir(dirname(out), { recursive: true, mode: 0o700 });
|
|
118
|
+
await writeFileAtomic(out, `${JSON.stringify({ ...settings, permissions: { ...permissions, additionalDirectories } }, null, 2)}\n`, 0o600);
|
|
119
|
+
const at = args.indexOf('--settings');
|
|
120
|
+
return at === -1 ? [...args, '--settings', out] : args.map((a, i) => (i === at + 1 ? out : a));
|
|
121
|
+
}
|
|
95
122
|
/**
|
|
96
123
|
* Auto Handoff's Claude hook arguments with the session's own sideby hooks (`sessionArgs`, from `sessionHookArgs`)
|
|
97
124
|
* merged into one `--settings` file, written next to the session's file with `-handoff` added to its name.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// How Claude Code takes part in a Handoff (spec §3.17): hooks through `--settings`, which merges with the
|
|
2
|
-
// Account's own settings hooks (verified 2026-10-09)
|
|
2
|
+
// Account's own settings hooks (verified 2026-10-09). The Brief's directory goes into that file's
|
|
3
|
+
// `permissions.additionalDirectories` (`withClaudeDirs`): Claude Code 2.1.326 asks to trust an `--add-dir` folder it
|
|
4
|
+
// has not seen, so `dirArgs` is used only where sideby cannot add to `--settings`.
|
|
3
5
|
import { mkdir } from 'node:fs/promises';
|
|
4
6
|
import { join } from 'node:path';
|
|
5
7
|
import { locate, readObject } from '../../core/claude-settings-file.js';
|
|
@@ -304,6 +304,20 @@ export interface PanelState {
|
|
|
304
304
|
unattended?: PanelUnattendedStatus;
|
|
305
305
|
/** Progress Reminders (spec §3.42): on or off, how often, and the choices; absent without Claude Accounts. */
|
|
306
306
|
progress?: ProgressView;
|
|
307
|
+
/**
|
|
308
|
+
* Carried trust (spec §3.43): config `claude.carryTrust` and the marks sideby copied, from sideby's own records (no
|
|
309
|
+
* `.claude.json` is read for it); absent with fewer than two Claude Accounts, unless it is on or has marks.
|
|
310
|
+
*/
|
|
311
|
+
trust?: PanelTrust;
|
|
312
|
+
}
|
|
313
|
+
export interface PanelTrust {
|
|
314
|
+
on: boolean;
|
|
315
|
+
carried: {
|
|
316
|
+
account: string;
|
|
317
|
+
path: string;
|
|
318
|
+
from: string;
|
|
319
|
+
at: string;
|
|
320
|
+
}[];
|
|
307
321
|
}
|
|
308
322
|
/** One Pending Decision as the Panel's Unattended page lists it, with the way back to its Session. */
|
|
309
323
|
export interface PanelPendingDecision extends PendingDecision {
|
|
@@ -650,6 +650,7 @@ async function buildState(rt, opts) {
|
|
|
650
650
|
.catch(() => undefined);
|
|
651
651
|
const showBrowser = browser && (browser.families.matched.length || browser.families.openOnly.length);
|
|
652
652
|
const progress = accounts.some((a) => PROGRESS_FAMILIES.includes(a.family)) ? rt.progressView() : undefined;
|
|
653
|
+
const trust = await panelTrust(rt, accounts).catch(() => undefined);
|
|
653
654
|
const permissions = aiTaskPermissions(rt.config);
|
|
654
655
|
return {
|
|
655
656
|
schemaVersion: 1,
|
|
@@ -698,6 +699,17 @@ async function buildState(rt, opts) {
|
|
|
698
699
|
...(network ? { network } : {}),
|
|
699
700
|
...(unattended ? { unattended } : {}),
|
|
700
701
|
...(progress ? { progress } : {}),
|
|
702
|
+
...(trust ? { trust } : {}),
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
/** The Panel's view of carried trust (spec §3.43), or undefined when there is nothing to show. */
|
|
706
|
+
async function panelTrust(rt, accounts) {
|
|
707
|
+
const st = await rt.trustStatus();
|
|
708
|
+
if (accounts.filter((a) => a.family === 'claude').length < 2 && !st.on && !st.carried.length)
|
|
709
|
+
return undefined;
|
|
710
|
+
return {
|
|
711
|
+
on: st.on,
|
|
712
|
+
carried: st.carried.map(({ key, ...x }) => ({ ...x, path: tildify(key, rt.paths.home) })),
|
|
701
713
|
};
|
|
702
714
|
}
|
|
703
715
|
const SHELL_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
@@ -1488,6 +1500,49 @@ export function createPanelHandler(opts) {
|
|
|
1488
1500
|
apply: (rt) => rt.remoteControlOn(),
|
|
1489
1501
|
}),
|
|
1490
1502
|
'/api/remote-control/undo': previewedChange({ apply: (rt) => rt.remoteControlUndo() }),
|
|
1503
|
+
// Carried trust (spec §3.43, ADR-0078): config `claude.carryTrust`, shown first like every config change; the
|
|
1504
|
+
// switch sends `confirm` with the words it shows beside it.
|
|
1505
|
+
'/api/trust/settings': {
|
|
1506
|
+
writes: (body) => body.confirm === true,
|
|
1507
|
+
async run(body) {
|
|
1508
|
+
if (typeof body.on !== 'boolean')
|
|
1509
|
+
throw new HttpError(400, '"on" must be true or false');
|
|
1510
|
+
const rt = await getRuntime();
|
|
1511
|
+
const r = await rt.trustSet(body.on, { apply: optBool(body, 'confirm') });
|
|
1512
|
+
return { ...r, file: tildify(r.file, rt.paths.home) };
|
|
1513
|
+
},
|
|
1514
|
+
},
|
|
1515
|
+
// Takes back the trust marks sideby copied (`sideby trust undo`): without `confirm` what it would do, with it done.
|
|
1516
|
+
'/api/trust/undo': {
|
|
1517
|
+
writes: (body) => body.confirm === true,
|
|
1518
|
+
async run(body) {
|
|
1519
|
+
const rt = await getRuntime();
|
|
1520
|
+
// Inside text too: a reason names a path in the middle of a sentence.
|
|
1521
|
+
const show = (p) => p.split(`${rt.paths.home}/`).join('~/');
|
|
1522
|
+
const apply = optBool(body, 'confirm');
|
|
1523
|
+
// A confirmation names the carries the page showed: one made since (a Launch meanwhile) is not taken back unseen.
|
|
1524
|
+
let only;
|
|
1525
|
+
if (apply) {
|
|
1526
|
+
const list = body.items;
|
|
1527
|
+
if (!Array.isArray(list) ||
|
|
1528
|
+
!list.every((x) => x &&
|
|
1529
|
+
typeof x === 'object' &&
|
|
1530
|
+
typeof x.id === 'string' &&
|
|
1531
|
+
/^[0-9a-f]{32}$/.test(x.id) &&
|
|
1532
|
+
typeof x.at === 'string'))
|
|
1533
|
+
throw new HttpError(400, '"items" must list the shown carries as { id, at }; review the list again');
|
|
1534
|
+
only = list.map((x) => ({ id: x.id, at: x.at }));
|
|
1535
|
+
}
|
|
1536
|
+
const items = await rt.trustUndo({ apply, ...(only ? { only } : {}) });
|
|
1537
|
+
return {
|
|
1538
|
+
items: items.map(({ key, why, ...x }) => ({
|
|
1539
|
+
...x,
|
|
1540
|
+
path: show(key),
|
|
1541
|
+
...(why ? { why: show(why) } : {}),
|
|
1542
|
+
})),
|
|
1543
|
+
};
|
|
1544
|
+
},
|
|
1545
|
+
},
|
|
1491
1546
|
// Claude Code's advisor (spec §3.41, ADR-0074): the same change as `sideby advisor <model>|off [--account]`. It
|
|
1492
1547
|
// writes `advisorModel` only into the files the page showed (`previewedChange`); a model also turns config
|
|
1493
1548
|
// `advisor.unlock` on, and config `claude.apiBetasOff` where the variable leaves a file API Accounts share, both
|
package/dist/src/panel/i18n.d.ts
CHANGED
|
@@ -1774,6 +1774,28 @@ declare const en: {
|
|
|
1774
1774
|
'pr.everyToast': string;
|
|
1775
1775
|
'pr.offToast': string;
|
|
1776
1776
|
'pr.failed': string;
|
|
1777
|
+
'ai.ask.trust': string;
|
|
1778
|
+
'tr.title': string;
|
|
1779
|
+
'tr.hint': string;
|
|
1780
|
+
'tr.switch': string;
|
|
1781
|
+
'tr.what': string;
|
|
1782
|
+
'tr.only': string;
|
|
1783
|
+
'tr.offKeeps': string;
|
|
1784
|
+
'tr.carried.one': string;
|
|
1785
|
+
'tr.carried.other': string;
|
|
1786
|
+
'tr.review': string;
|
|
1787
|
+
'tr.undoIntro': string;
|
|
1788
|
+
'tr.undoRow': string;
|
|
1789
|
+
'tr.changed': string;
|
|
1790
|
+
'tr.gone': string;
|
|
1791
|
+
'tr.remove': string;
|
|
1792
|
+
'tr.nothing': string;
|
|
1793
|
+
'tr.removed.one': string;
|
|
1794
|
+
'tr.removed.other': string;
|
|
1795
|
+
'tr.notRemoved': string;
|
|
1796
|
+
'tr.onToast': string;
|
|
1797
|
+
'tr.offToast': string;
|
|
1798
|
+
'tr.failed': string;
|
|
1777
1799
|
};
|
|
1778
1800
|
export type MessageKey = keyof typeof en;
|
|
1779
1801
|
export declare const MESSAGES: Record<PanelLang, Record<string, string>>;
|