toolroll 0.9.115 → 0.9.117
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/CHANGELOG.md +55 -0
- package/README.md +43 -26
- package/dist/acp-agents.js +14 -1
- package/dist/acp-client.js +19 -1
- package/dist/agent-change-check.js +60 -0
- package/dist/agent-change-schema.js +19 -0
- package/dist/agent-detect.js +11 -1
- package/dist/agent-fence.js +39 -10
- package/dist/agent-network-request.js +108 -0
- package/dist/agent-requests.js +105 -0
- package/dist/approval-summary.js +3 -3
- package/dist/backup.js +17 -1
- package/dist/batch-checks.js +81 -18
- package/dist/browser/terminal.js +41 -41
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +36 -36
- package/dist/builder.js +3 -1
- package/dist/candidate-materialize.js +119 -0
- package/dist/central-enrollment-contract.js +156 -0
- package/dist/central-recovery-stage.js +329 -0
- package/dist/chat-actions.js +101 -2
- package/dist/chat-channel.js +40 -0
- package/dist/check-only-standing.js +13 -0
- package/dist/check-only.js +25 -13
- package/dist/check-recovery-hold.js +199 -0
- package/dist/check-recovery-index-schema.js +3 -0
- package/dist/check-screenshots.js +83 -0
- package/dist/cli.js +125 -6
- package/dist/codex-limits.js +4 -0
- package/dist/connect-cli.js +257 -11
- package/dist/contracts/chat-actions.js +4 -0
- package/dist/contracts/console-api.js +15 -4
- package/dist/contracts/engine-api.js +344 -2
- package/dist/contracts/lead-tools.js +56 -2
- package/dist/contracts/provider.js +1 -1
- package/dist/contracts/route.js +1 -1
- package/dist/contracts/terminal-connection.js +50 -0
- package/dist/converse.js +80 -4
- package/dist/device-pair.js +280 -0
- package/dist/direct-chat-artifacts.js +347 -0
- package/dist/direct-chat-catalog.js +311 -0
- package/dist/direct-chat-fence.js +96 -0
- package/dist/direct-chat-git.js +343 -0
- package/dist/direct-chat-laptop.js +19 -0
- package/dist/direct-chat-schema.js +181 -0
- package/dist/direct-chat-ship.js +861 -0
- package/dist/direct-chat-workspace.js +389 -0
- package/dist/direct-chat.js +2107 -0
- package/dist/doctor.js +1 -1
- package/dist/easy-start.js +18 -0
- package/dist/egress.js +25 -4
- package/dist/engine-chat.js +454 -0
- package/dist/engine-reads.js +141 -13
- package/dist/exec.js +4 -3
- package/dist/flexible-agents.js +8 -16
- package/dist/flexible-authority-end.js +2 -0
- package/dist/flexible-interactive-schema.js +133 -0
- package/dist/flexible-interactive.js +94 -0
- package/dist/flexible-session.js +117 -49
- package/dist/flexible-ship.js +87 -7
- package/dist/flexible-sign-in.js +10 -0
- package/dist/flexible-start.js +21 -3
- package/dist/flexible-thread.js +2 -3
- package/dist/flexible-turns.js +26 -5
- package/dist/flexible.js +13 -0
- package/dist/flow-triggers.js +13 -4
- package/dist/flows-ui.js +54 -20
- package/dist/handoff-cli.js +630 -0
- package/dist/invoke.js +55 -13
- package/dist/lead-contract.js +5 -4
- package/dist/lead-doors.js +80 -1
- package/dist/lead-progress.js +9 -0
- package/dist/lead-tools.js +682 -10
- package/dist/lead.js +37 -9
- package/dist/live-bus.js +11 -0
- package/dist/live-terminal.js +132 -12
- package/dist/local-handoff.js +363 -0
- package/dist/local-owner-acts.js +264 -2
- package/dist/local-owner.js +16 -1
- package/dist/multiplayer-handoff.js +528 -0
- package/dist/multiplayer-presence.js +471 -0
- package/dist/names.js +17 -4
- package/dist/needs-you.js +10 -0
- package/dist/operate.js +280 -19
- package/dist/policy.js +2 -2
- package/dist/project-delete-ui.js +18 -11
- package/dist/project-delete.js +65 -4
- package/dist/project-tools.js +1 -1
- package/dist/prompt.js +1 -1
- package/dist/provider-connection.js +2 -0
- package/dist/provider-home.js +251 -8
- package/dist/provider.js +3 -2
- package/dist/publish.js +119 -64
- package/dist/pull-request-flow.js +35 -14
- package/dist/read-executor-worker.js +1 -1
- package/dist/read-executor.js +95 -1
- package/dist/restore-retirement.js +152 -0
- package/dist/result-follow-ups.js +116 -37
- package/dist/route-change.js +44 -4
- package/dist/scope.js +62 -5
- package/dist/serve.js +49 -5
- package/dist/server/chat.js +94 -13
- package/dist/server/console.css +9 -9
- package/dist/server/direct-chat.js +583 -0
- package/dist/server/engine-api.js +219 -21
- package/dist/server/flows.js +47 -13
- package/dist/server/found-repos.js +25 -0
- package/dist/server/guards.js +20 -6
- package/dist/server/live.js +81 -23
- package/dist/server/pages.js +67 -13
- package/dist/server/people-tokens.js +47 -6
- package/dist/server/remote.js +29 -0
- package/dist/server/render-results.js +6 -2
- package/dist/server/render-settings.js +4 -2
- package/dist/server/render-tasks.js +18 -17
- package/dist/server/route-table.js +69 -2
- package/dist/server/settings.js +22 -7
- package/dist/server/task-views.js +15 -3
- package/dist/server/tasks.js +39 -2
- package/dist/server/terminals.js +185 -11
- package/dist/settings-proofs.js +1 -1
- package/dist/spend-report.js +2 -2
- package/dist/spend.js +3 -3
- package/dist/store.js +600 -59
- package/dist/subagent-admin.js +23 -10
- package/dist/subagent-backup-schema.js +36 -0
- package/dist/subagent-backup.js +92 -0
- package/dist/subagent-week.js +2 -2
- package/dist/subagent-work.js +70 -47
- package/dist/subagents-ui.js +6 -2
- package/dist/subagents.js +5 -2
- package/dist/subscription-chat.js +36 -5
- package/dist/subscription-usage.js +233 -0
- package/dist/task-live.js +2 -1
- package/dist/teardown-git.js +34 -4
- package/dist/terminal-connection.js +159 -0
- package/dist/terminal-safety.js +114 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-contract.js +1 -1
- package/dist/tui-launch.js +32 -1
- package/dist/workspace-identity-schema.js +21 -0
- package/package.json +4 -2
package/dist/project-delete.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { existsSync, lstatSync, rmSync } from "node:fs";
|
|
2
2
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import { run as execRun } from "./exec.js";
|
|
4
|
+
import { CHECK_RECOVERY_HELD, readCheckRecoveryHoldsForTaskRef } from "./check-recovery-hold.js";
|
|
3
5
|
import { teardownGit, refusal } from "./teardown-git.js";
|
|
4
6
|
import { BUILT_IN, forgetProjectModels, V149_REPO_TABLES } from "./store.js";
|
|
5
7
|
import { BRANCH_PREFIXES, isOwnBranch } from "./names.js";
|
|
@@ -75,6 +77,7 @@ export function projectRunning(store, repo, now) {
|
|
|
75
77
|
const agents = tableExists(db, "flexible_thread_launch")
|
|
76
78
|
? count("SELECT COUNT(*) AS n FROM flexible_thread_launch WHERE state <> 'exited' AND thread IN (SELECT id FROM flexible_thread WHERE repo = ?)", repo) : 0;
|
|
77
79
|
return [
|
|
80
|
+
...(projectRecoveryDeletionProblem(store, repo) !== null ? [PROJECT_RECOVERY_DELETE_MESSAGE] : []),
|
|
78
81
|
...(building > 0 ? [`${plural(building, "task")} ${building === 1 ? "is" : "are"} being built`] : []),
|
|
79
82
|
...(slots > 0 ? ["an agent is working"] : []),
|
|
80
83
|
...(chats > 0 ? ["a chat is answering"] : []),
|
|
@@ -106,6 +109,7 @@ async function removeCheckoutsAndBranches(store, repo, d, git, poolRoot) {
|
|
|
106
109
|
for (const row of recorded) {
|
|
107
110
|
if (poolRoot === null || !inside(poolRoot, row.path) || !existsSync(row.path))
|
|
108
111
|
continue;
|
|
112
|
+
assertProjectRecoveryDeletion(store, repo);
|
|
109
113
|
rmSync(row.path, { recursive: true, force: true });
|
|
110
114
|
checkouts++;
|
|
111
115
|
}
|
|
@@ -149,6 +153,7 @@ async function removeCheckoutsAndBranches(store, repo, d, git, poolRoot) {
|
|
|
149
153
|
continue;
|
|
150
154
|
if (trees.some(tree => resolve(tree.path) === resolve(row.path)))
|
|
151
155
|
continue;
|
|
156
|
+
assertProjectRecoveryDeletion(store, repo);
|
|
152
157
|
rmSync(row.path, { recursive: true, force: true });
|
|
153
158
|
checkouts++;
|
|
154
159
|
}
|
|
@@ -249,6 +254,7 @@ function deleteRows(store, repo, d, now) {
|
|
|
249
254
|
del("deploy_in_flight", IN("task_ref"), T);
|
|
250
255
|
del("publication", IN("id"), publications);
|
|
251
256
|
del("artifact", IN("id"), A);
|
|
257
|
+
del("pending_agent_change", IN("task_ref"), T);
|
|
252
258
|
del("run", IN("id"), R);
|
|
253
259
|
del("plan_revision", IN("task_ref"), T);
|
|
254
260
|
for (const table of ["claim", "hold", "task_steer"])
|
|
@@ -312,21 +318,38 @@ function deleteRows(store, repo, d, now) {
|
|
|
312
318
|
return rows;
|
|
313
319
|
}
|
|
314
320
|
export async function deleteProject(store, repo, options) {
|
|
315
|
-
const
|
|
316
|
-
(_file, args, execOptions) => options.git(args, execOptions.cwd))
|
|
317
|
-
const
|
|
321
|
+
const rawRunner = options.runner ?? (options.git === undefined ? execRun :
|
|
322
|
+
(_file, args, execOptions) => options.git(args, execOptions.cwd));
|
|
323
|
+
const hardened = teardownGit((file, args, execOptions) => { assertProjectRecoveryDeletion(store, repo); return rawRunner(file, args, execOptions); });
|
|
324
|
+
const git = async (args, cwd) => {
|
|
325
|
+
assertProjectRecoveryDeletion(store, repo);
|
|
326
|
+
const result = await hardened(cwd, args);
|
|
327
|
+
assertProjectRecoveryDeletion(store, repo);
|
|
328
|
+
return result;
|
|
329
|
+
};
|
|
330
|
+
const recovery = projectRecoveryDeletionProblem(store, repo);
|
|
331
|
+
if (recovery !== null)
|
|
332
|
+
return { ok: false, reason: "recovery-held", said: recovery };
|
|
318
333
|
const running = projectRunning(store, repo, options.now);
|
|
334
|
+
if (running.includes(PROJECT_RECOVERY_DELETE_MESSAGE))
|
|
335
|
+
return { ok: false, reason: "recovery-held", said: PROJECT_RECOVERY_DELETE_MESSAGE };
|
|
319
336
|
if (running.length > 0)
|
|
320
337
|
return { ok: false, reason: "running", said: `Nothing was deleted: ${running.join(", ")}. Stop it, then try again.`, running };
|
|
321
338
|
const db = store.handle;
|
|
322
339
|
const held = projectHoldings(store, repo);
|
|
323
340
|
let d = doomed(db, repo);
|
|
324
|
-
store.transact(() => {
|
|
341
|
+
const admission = store.transact(() => {
|
|
342
|
+
const problem = projectRecoveryDeletionProblem(store, repo);
|
|
343
|
+
if (problem !== null)
|
|
344
|
+
return problem;
|
|
325
345
|
for (const ref of d.refs) {
|
|
326
346
|
db.prepare(`INSERT INTO hold (task_ref, owner_kind, owner_id, reason, until, held_at) VALUES (?, 'operator', ?, 'Its project is being deleted', NULL, ?)
|
|
327
347
|
ON CONFLICT (owner_kind, owner_id) DO NOTHING`).run(ref, `project-delete:${ref}`, options.now.toISOString());
|
|
328
348
|
}
|
|
349
|
+
return null;
|
|
329
350
|
});
|
|
351
|
+
if (admission !== null)
|
|
352
|
+
return { ok: false, reason: "recovery-held", said: admission };
|
|
330
353
|
const release = () => store.transact(() => { db.prepare("DELETE FROM hold WHERE owner_kind = 'operator' AND owner_id LIKE 'project-delete:%' AND task_ref IN (SELECT value FROM json_each(?))").run(json(d.refs)); });
|
|
331
354
|
let git_;
|
|
332
355
|
try {
|
|
@@ -334,11 +357,14 @@ export async function deleteProject(store, repo, options) {
|
|
|
334
357
|
}
|
|
335
358
|
catch (error) {
|
|
336
359
|
release();
|
|
360
|
+
if (error instanceof RecoveryDeletionHeld)
|
|
361
|
+
return { ok: false, reason: "recovery-held", said: `${PROJECT_RECOVERY_DELETE_MESSAGE} Earlier deletion steps may already have completed.` };
|
|
337
362
|
return { ok: false, reason: "failed", said: `Nothing was deleted: the checkouts couldn't be removed (${error instanceof Error ? error.message : String(error)}).` };
|
|
338
363
|
}
|
|
339
364
|
let rows = 0, ledgerId = 0;
|
|
340
365
|
try {
|
|
341
366
|
store.transact(() => {
|
|
367
|
+
assertProjectRecoveryDeletion(store, repo);
|
|
342
368
|
const again = projectRunning(store, repo, options.now);
|
|
343
369
|
if (again.length > 0)
|
|
344
370
|
throw new RunningError(again);
|
|
@@ -371,6 +397,8 @@ export async function deleteProject(store, repo, options) {
|
|
|
371
397
|
}
|
|
372
398
|
catch (error) {
|
|
373
399
|
release();
|
|
400
|
+
if (error instanceof RecoveryDeletionHeld)
|
|
401
|
+
return { ok: false, reason: "recovery-held", said: `${PROJECT_RECOVERY_DELETE_MESSAGE} Earlier deletion steps may already have completed; project records were kept.` };
|
|
374
402
|
if (error instanceof RunningError)
|
|
375
403
|
return { ok: false, reason: "running", said: `Nothing was deleted: ${error.running.join(", ")}. Stop it, then try again.`, running: error.running };
|
|
376
404
|
return { ok: false, reason: "failed", said: `Nothing was deleted from the database: ${error instanceof Error ? error.message : String(error)}.` };
|
|
@@ -378,6 +406,9 @@ export async function deleteProject(store, repo, options) {
|
|
|
378
406
|
if (options.evidenceRoot !== null) {
|
|
379
407
|
for (const runId of d.runs) {
|
|
380
408
|
const folder = resolve(options.evidenceRoot, String(runId));
|
|
409
|
+
const problem = projectRecoveryDeletionProblem(store, repo);
|
|
410
|
+
if (problem !== null)
|
|
411
|
+
return { ok: false, reason: "recovery-held", said: `${problem} Project records were deleted; remaining evidence was kept.` };
|
|
381
412
|
try {
|
|
382
413
|
if (lstatSync(folder).isDirectory() && inside(options.evidenceRoot, folder))
|
|
383
414
|
rmSync(folder, { recursive: true, force: true });
|
|
@@ -394,3 +425,33 @@ class RunningError extends Error {
|
|
|
394
425
|
this.running = running;
|
|
395
426
|
}
|
|
396
427
|
}
|
|
428
|
+
export const PROJECT_RECOVERY_DELETE_MESSAGE = "Project deletion is on hold after recovery. Earlier check execution is unverified.";
|
|
429
|
+
export function projectRecoveryDeletionProblem(store, repo) {
|
|
430
|
+
const db = store.handle;
|
|
431
|
+
if (db.prepare("SELECT 1 FROM action_ledger WHERE action = ? LIMIT 1").get(CHECK_RECOVERY_HELD) === undefined)
|
|
432
|
+
return null;
|
|
433
|
+
const recorded = db.prepare(`SELECT 1 FROM action_ledger h WHERE h.action = ? AND (h.repo = ? OR EXISTS
|
|
434
|
+
(SELECT 1 FROM action_ledger q WHERE q.id=CAST(h.outcome AS INTEGER) AND CAST(q.id AS TEXT)=h.outcome AND q.repo = ?)) LIMIT 1`)
|
|
435
|
+
.get(CHECK_RECOVERY_HELD, repo, repo);
|
|
436
|
+
if (recorded !== undefined)
|
|
437
|
+
return PROJECT_RECOVERY_DELETE_MESSAGE;
|
|
438
|
+
const covered = new Set();
|
|
439
|
+
for (const row of db.prepare("SELECT id FROM task_ref WHERE repo = ?").all(repo)) {
|
|
440
|
+
const ref = Number(row["id"]);
|
|
441
|
+
if (covered.has(ref))
|
|
442
|
+
continue;
|
|
443
|
+
const evidence = readCheckRecoveryHoldsForTaskRef(store, ref);
|
|
444
|
+
if (evidence.kind !== "no-evidence")
|
|
445
|
+
return PROJECT_RECOVERY_DELETE_MESSAGE;
|
|
446
|
+
for (const member of evidence.familyRefs)
|
|
447
|
+
covered.add(member);
|
|
448
|
+
}
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
class RecoveryDeletionHeld extends Error {
|
|
452
|
+
constructor() { super(PROJECT_RECOVERY_DELETE_MESSAGE); }
|
|
453
|
+
}
|
|
454
|
+
function assertProjectRecoveryDeletion(store, repo) {
|
|
455
|
+
if (projectRecoveryDeletionProblem(store, repo) !== null)
|
|
456
|
+
throw new RecoveryDeletionHeld();
|
|
457
|
+
}
|
package/dist/project-tools.js
CHANGED
|
@@ -724,7 +724,7 @@ export function toolLaunchFor(store, runId, home) {
|
|
|
724
724
|
return launch;
|
|
725
725
|
}
|
|
726
726
|
export function secretToolRefusal(provider, containment) {
|
|
727
|
-
if (provider === "codex" || provider === "openrouter")
|
|
727
|
+
if ((provider === "codex" || provider === "openrouter") && containment.fence !== "macos-sandbox")
|
|
728
728
|
return "This tool needs a Claude build to protect its sign-in details.";
|
|
729
729
|
if (containment.platform === "linux")
|
|
730
730
|
return "Toolroll doesn't start tools with sign-in details on Linux: a build there could read them from the running tool.";
|
package/dist/prompt.js
CHANGED
|
@@ -6,7 +6,7 @@ export function interactive() {
|
|
|
6
6
|
}
|
|
7
7
|
const AGENT_VARIABLES = ["CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "GEMINI_CLI", "CURSOR_AGENT", "OPENCODE", "GOOSE_TERMINAL", "AIDER_CHAT",
|
|
8
8
|
"CODEX_SANDBOX", "CODEX_SANDBOX_NETWORK_DISABLED", "CODEX_THREAD_ID", "CODEX_CI", "CODEX_MANAGED_BY_NPM", "CODEX_MANAGED_BY_BUN"];
|
|
9
|
-
const AGENT_PROGRAMS = new Set(["claude", "codex", "gemini", "cursor-agent", "opencode", "aider", "copilot", "amp", "goose", "crush", "qwen"]);
|
|
9
|
+
const AGENT_PROGRAMS = new Set(["claude", "codex", "gemini", "agy", "cursor-agent", "opencode", "aider", "copilot", "amp", "goose", "crush", "qwen"]);
|
|
10
10
|
export function ancestorPrograms() {
|
|
11
11
|
if (process.platform === "win32")
|
|
12
12
|
return [];
|
|
@@ -12,6 +12,8 @@ export function signInFacts(provider, result, now = new Date()) {
|
|
|
12
12
|
return { ...base, state: "not-installed" };
|
|
13
13
|
if (result.timedOut)
|
|
14
14
|
return { ...base, state: "unverified" };
|
|
15
|
+
if (result.code === 127)
|
|
16
|
+
return { ...base, state: "unverified", launchIssue: "command-not-found" };
|
|
15
17
|
if (provider === "claude") {
|
|
16
18
|
try {
|
|
17
19
|
const value = JSON.parse(result.stdout);
|
package/dist/provider-home.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { chmodSync, closeSync, constants as fsConstants, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readdirSync, readFileSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { homedir, tmpdir } from "node:os";
|
|
3
|
-
import {
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { dirname, join, relative } from "node:path";
|
|
4
6
|
import { validModelId } from "./provider.js";
|
|
5
7
|
const EFFORT = /^[a-z]{1,16}$/;
|
|
6
8
|
export function claudeConfigDir(env = process.env, home = homedir()) {
|
|
@@ -57,18 +59,259 @@ export function codexDefaults(codexHome) {
|
|
|
57
59
|
...(effort !== undefined && EFFORT.test(effort) ? { effort } : {}),
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
|
-
|
|
62
|
+
const SESSIONS_MAX_BYTES = 512 * 1024 * 1024;
|
|
63
|
+
const SESSIONS_MAX_ENTRIES = 20_000;
|
|
64
|
+
const SESSIONS_MAX_DEPTH = 8;
|
|
65
|
+
const SESSION_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,200}$/;
|
|
66
|
+
export function isolatedCodexHome(source, root = tmpdir(), options = { signIn: true }) {
|
|
61
67
|
const dir = mkdtempSync(join(root, "so-codex-"));
|
|
68
|
+
const home = realpathSync(dir);
|
|
69
|
+
const sessions = join(dir, "sessions");
|
|
70
|
+
let homeFd;
|
|
71
|
+
try {
|
|
72
|
+
homeFd = openSync(home, fsConstants.O_RDONLY | fsConstants.O_DIRECTORY | fsConstants.O_NOFOLLOW);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
rmSync(dir, { recursive: true, force: true });
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
62
78
|
try {
|
|
63
79
|
chmodSync(dir, 0o700);
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
if (options.signIn) {
|
|
81
|
+
const auth = signInBytes(join(source, "auth.json"));
|
|
82
|
+
if (auth !== null)
|
|
83
|
+
writeFileSync(join(dir, "auth.json"), auth, { mode: 0o600, flag: "wx" });
|
|
84
|
+
}
|
|
85
|
+
mkdirSync(sessions, { mode: 0o700 });
|
|
86
|
+
if (options.sessions != null)
|
|
87
|
+
copySessions(options.sessions, sessions);
|
|
68
88
|
}
|
|
69
89
|
catch (error) {
|
|
90
|
+
closeSync(homeFd);
|
|
70
91
|
rmSync(dir, { recursive: true, force: true });
|
|
71
92
|
throw error;
|
|
72
93
|
}
|
|
73
|
-
|
|
94
|
+
const sameHome = () => {
|
|
95
|
+
try {
|
|
96
|
+
const held = fstatSync(homeFd), there = lstatSync(home);
|
|
97
|
+
return there.isDirectory() && !there.isSymbolicLink() && there.ino === held.ino && there.dev === held.dev;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
let closed = false;
|
|
104
|
+
return {
|
|
105
|
+
dir,
|
|
106
|
+
keep: provenGone => {
|
|
107
|
+
if (options.sessions == null || !provenGone || closed)
|
|
108
|
+
return;
|
|
109
|
+
const kept = options.sessions;
|
|
110
|
+
try {
|
|
111
|
+
withCodexSessionsLock(dirname(kept), () => { if (!sameHome())
|
|
112
|
+
throw new Error("the launch's home changed"); keepSessions(sessions, home, kept); });
|
|
113
|
+
}
|
|
114
|
+
catch { }
|
|
115
|
+
},
|
|
116
|
+
cleanup: () => { if (!closed) {
|
|
117
|
+
closed = true;
|
|
118
|
+
closeSync(homeFd);
|
|
119
|
+
} rmSync(dir, { recursive: true, force: true }); },
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function signInBytes(path) {
|
|
123
|
+
let real;
|
|
124
|
+
try {
|
|
125
|
+
real = realpathSync(path);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const fd = openSync(real, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK);
|
|
131
|
+
try {
|
|
132
|
+
const held = fstatSync(fd);
|
|
133
|
+
if (!held.isFile() || held.size > 1024 * 1024)
|
|
134
|
+
throw new Error("the Codex sign-in isn't a plain file");
|
|
135
|
+
return readFileSync(fd);
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
closeSync(fd);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function provenFile(root, path, limit) {
|
|
142
|
+
let fd;
|
|
143
|
+
try {
|
|
144
|
+
fd = openSync(path, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const held = fstatSync(fd);
|
|
151
|
+
if (!held.isFile() || held.size > limit || held.nlink !== 1)
|
|
152
|
+
return null;
|
|
153
|
+
const there = lstatSync(path);
|
|
154
|
+
if (!there.isFile() || there.nlink !== 1 || there.ino !== held.ino || there.dev !== held.dev)
|
|
155
|
+
return null;
|
|
156
|
+
const inside = relative(root, realpathSync(dirname(path)));
|
|
157
|
+
if (inside.startsWith("..") || inside.startsWith("/"))
|
|
158
|
+
return null;
|
|
159
|
+
const bytes = Buffer.alloc(held.size);
|
|
160
|
+
let read = 0;
|
|
161
|
+
while (read < held.size) {
|
|
162
|
+
const got = readSync(fd, bytes, read, held.size - read, read);
|
|
163
|
+
if (got === 0)
|
|
164
|
+
break;
|
|
165
|
+
read += got;
|
|
166
|
+
}
|
|
167
|
+
return bytes.subarray(0, read);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
closeSync(fd);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function provenFolder(path, expected) {
|
|
177
|
+
try {
|
|
178
|
+
const held = lstatSync(path);
|
|
179
|
+
return held.isDirectory() && !held.isSymbolicLink() && realpathSync(path) === expected;
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function copyTree(root, to) {
|
|
186
|
+
let entries = 0, bytes = 0;
|
|
187
|
+
const walk = (dir, depth) => {
|
|
188
|
+
if (depth > SESSIONS_MAX_DEPTH)
|
|
189
|
+
return;
|
|
190
|
+
const here = join(root, dir);
|
|
191
|
+
if (!provenFolder(here, here))
|
|
192
|
+
return;
|
|
193
|
+
let names;
|
|
194
|
+
try {
|
|
195
|
+
names = readdirSync(here);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (!provenFolder(here, here))
|
|
201
|
+
return;
|
|
202
|
+
for (const name of names) {
|
|
203
|
+
if (!SESSION_NAME.test(name) || ++entries > SESSIONS_MAX_ENTRIES)
|
|
204
|
+
continue;
|
|
205
|
+
const rel = join(dir, name);
|
|
206
|
+
let held;
|
|
207
|
+
try {
|
|
208
|
+
held = lstatSync(join(root, rel));
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (held.isDirectory()) {
|
|
214
|
+
mkdirSync(join(to, rel), { recursive: true, mode: 0o700 });
|
|
215
|
+
walk(rel, depth + 1);
|
|
216
|
+
}
|
|
217
|
+
else if (held.isFile()) {
|
|
218
|
+
const content = provenFile(root, join(root, rel), SESSIONS_MAX_BYTES - bytes);
|
|
219
|
+
if (content === null)
|
|
220
|
+
continue;
|
|
221
|
+
bytes += content.length;
|
|
222
|
+
mkdirSync(join(to, dir), { recursive: true, mode: 0o700 });
|
|
223
|
+
writeFileSync(join(to, rel), content, { mode: 0o600, flag: "wx" });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
walk("", 0);
|
|
228
|
+
}
|
|
229
|
+
function copySessions(kept, into) {
|
|
230
|
+
let root;
|
|
231
|
+
try {
|
|
232
|
+
root = realpathSync(kept);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (!provenFolder(kept, root))
|
|
238
|
+
return;
|
|
239
|
+
copyTree(root, into);
|
|
240
|
+
}
|
|
241
|
+
function keepSessions(from, home, kept) {
|
|
242
|
+
const expected = join(home, "sessions");
|
|
243
|
+
if (!provenFolder(from, expected))
|
|
244
|
+
throw new Error("the launch's sessions folder isn't the one Toolroll made");
|
|
245
|
+
const parent = dirname(kept);
|
|
246
|
+
mkdirSync(parent, { recursive: true, mode: 0o700 });
|
|
247
|
+
const tag = randomBytes(8).toString("hex");
|
|
248
|
+
const next = `${kept}.new-${tag}`;
|
|
249
|
+
const old = `${kept}.old-${tag}`;
|
|
250
|
+
mkdirSync(next, { mode: 0o700 });
|
|
251
|
+
try {
|
|
252
|
+
copyTree(expected, next);
|
|
253
|
+
let had = false;
|
|
254
|
+
try {
|
|
255
|
+
renameSync(kept, old);
|
|
256
|
+
had = true;
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
had = false;
|
|
260
|
+
}
|
|
261
|
+
renameSync(next, kept);
|
|
262
|
+
if (had)
|
|
263
|
+
rmSync(old, { recursive: true, force: true });
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
rmSync(next, { recursive: true, force: true });
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export function pruneCodexSessions(root, keep) {
|
|
271
|
+
let names;
|
|
272
|
+
try {
|
|
273
|
+
names = readdirSync(root);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
for (const name of names) {
|
|
279
|
+
if (name.startsWith(CODEX_SESSIONS_LOCK))
|
|
280
|
+
continue;
|
|
281
|
+
const task = /^([0-9a-f]{32})(?:\.(?:new|old)-[0-9a-f]{16})?$/.exec(name)?.[1];
|
|
282
|
+
if (task !== undefined && keep.has(task))
|
|
283
|
+
continue;
|
|
284
|
+
try {
|
|
285
|
+
rmSync(join(root, name), { recursive: true, force: true });
|
|
286
|
+
}
|
|
287
|
+
catch { }
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const CODEX_SESSIONS_LOCK = ".lock";
|
|
291
|
+
export function withCodexSessionsLock(root, work, waitMs = 30_000) {
|
|
292
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
293
|
+
const file = join(root, CODEX_SESSIONS_LOCK);
|
|
294
|
+
try {
|
|
295
|
+
if (lstatSync(file).isSymbolicLink())
|
|
296
|
+
throw new Error("the Codex sessions lock is a link");
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
if (error.code !== "ENOENT")
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
const { DatabaseSync: Sqlite } = createRequire(import.meta.url)("node:sqlite");
|
|
303
|
+
const db = new Sqlite(file);
|
|
304
|
+
try {
|
|
305
|
+
chmodSync(file, 0o600);
|
|
306
|
+
db.exec(`PRAGMA busy_timeout=${Math.max(0, Math.trunc(waitMs))}; BEGIN EXCLUSIVE`);
|
|
307
|
+
try {
|
|
308
|
+
return work();
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
db.exec("ROLLBACK");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
finally {
|
|
315
|
+
db.close();
|
|
316
|
+
}
|
|
74
317
|
}
|
package/dist/provider.js
CHANGED
|
@@ -304,7 +304,8 @@ const codexArgv = (extra) => (invocation) => {
|
|
|
304
304
|
...(invocation.phase === "review"
|
|
305
305
|
? CODEX_REVIEW_ISOLATION_ARGV(resuming)
|
|
306
306
|
: invocation.fence !== undefined && invocation.fence.length > 0
|
|
307
|
-
?
|
|
307
|
+
? invocation.fenceMethod === "macos-sandbox" ? ["--dangerously-bypass-approvals-and-sandbox"]
|
|
308
|
+
: codexFenceArgv(invocation.fence, invocation.skipPermissions, invocation.fenceGrants)
|
|
308
309
|
: invocation.skipPermissions
|
|
309
310
|
? ["--dangerously-bypass-approvals-and-sandbox"]
|
|
310
311
|
: codexSandboxArgv("workspace-write", resuming)),
|
|
@@ -625,7 +626,7 @@ const AUDITS = withAcp({
|
|
|
625
626
|
sessionIdentity: "announced",
|
|
626
627
|
terminalContract: "none",
|
|
627
628
|
isolation: { flag: "--ignore-user-config --ignore-rules", resumeSafe: true, enforced: true },
|
|
628
|
-
configSurface: ["the project's named tools (Settings → Tools)", "repository AGENTS.md", "sign-in and sessions
|
|
629
|
+
configSurface: ["the project's named tools (Settings → Tools)", "repository AGENTS.md", "a copy of your sign-in and the task's own sessions in CODEX_HOME (no skills or AGENTS.md)", "your model and reasoning effort, when the route names no model"],
|
|
629
630
|
},
|
|
630
631
|
openrouter: {
|
|
631
632
|
transport: "streaming-jsonl",
|