toolroll 0.9.119 → 0.9.122

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +18 -31
  3. package/dist/agent-fence.js +57 -9
  4. package/dist/assignment.js +9 -7
  5. package/dist/batch-checks.js +2 -2
  6. package/dist/browser/workspace.js +23 -23
  7. package/dist/builder.js +12 -8
  8. package/dist/central-recovery-stage.js +3 -3
  9. package/dist/cli-help.js +1 -0
  10. package/dist/codex-limits.js +40 -22
  11. package/dist/coding-provider.js +3 -3
  12. package/dist/contracts/console-api.js +3 -0
  13. package/dist/direct-chat-fence.js +9 -3
  14. package/dist/direct-chat.js +82 -10
  15. package/dist/engine-reads.js +3 -1
  16. package/dist/flexible-agents.js +16 -2
  17. package/dist/flexible-import.js +38 -0
  18. package/dist/flexible-save.js +128 -0
  19. package/dist/flexible-session.js +11 -3
  20. package/dist/flexible-ship.js +3 -3
  21. package/dist/flexible-thread.js +7 -3
  22. package/dist/install-method.js +1 -3
  23. package/dist/invoke.js +11 -9
  24. package/dist/lead-tools.js +3 -2
  25. package/dist/live-terminal.js +24 -3
  26. package/dist/local-checks.js +32 -0
  27. package/dist/local-landing.js +321 -63
  28. package/dist/local-owner.js +3 -0
  29. package/dist/operate.js +25 -7
  30. package/dist/plan-limits-demand.js +48 -0
  31. package/dist/planner.js +2 -0
  32. package/dist/project-delete.js +1 -1
  33. package/dist/project-skills.js +105 -17
  34. package/dist/result-follow-ups.js +24 -10
  35. package/dist/review-context.js +2 -1
  36. package/dist/scout.js +2 -1
  37. package/dist/serve.js +8 -1
  38. package/dist/server/direct-chat.js +25 -3
  39. package/dist/server/engine-api.js +24 -3
  40. package/dist/server/render-release.js +27 -15
  41. package/dist/server/render-results.js +6 -4
  42. package/dist/server/route-table.js +8 -1
  43. package/dist/server/send-back-build.js +4 -0
  44. package/dist/server/settings.js +153 -3
  45. package/dist/server/task-views.js +8 -3
  46. package/dist/server/tasks.js +51 -9
  47. package/dist/server/terminals.js +3 -1
  48. package/dist/settings-groups-ui.js +1 -1
  49. package/dist/skill-library-schema.js +70 -0
  50. package/dist/skill-library.js +693 -0
  51. package/dist/skill-local-sync.js +334 -0
  52. package/dist/skills-manifest.js +6 -3
  53. package/dist/skills-ui.js +122 -1
  54. package/dist/store.js +22 -4
  55. package/dist/subscription-usage.js +11 -5
  56. package/dist/surface.js +3 -2
  57. package/dist/task-base.js +23 -4
  58. package/dist/task-outcome-cli.js +10 -1
  59. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  60. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  61. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  62. package/dist/tui/linux-x64/toolroll-tui +0 -0
  63. package/dist/verification-evidence.js +3 -1
  64. package/package.json +2 -1
package/dist/builder.js CHANGED
@@ -4,6 +4,7 @@ import { agentSaidTail } from "./agent-said.js";
4
4
  import { CHECK_ACCESS_DEFAULT, checkAccessHere, checkNetworkOf, localModeCap } from "./check-access.js";
5
5
  import { localModeOn } from "./local-owner.js";
6
6
  import { checkoutGit, refusal as gitRefusal } from "./teardown-git.js";
7
+ import { wholeChangeBaseOf } from "./task-base.js";
7
8
  import { isAcpProvider } from "./acp-agents.js";
8
9
  import { OBSERVATION_MAILBOX, observationBrief, parseObservationCases, collectObservations } from "./observations.js";
9
10
  import { checkCommandFor, effectiveCheckLevel, recordRunCheckLevel } from "./check-levels.js";
@@ -214,10 +215,10 @@ function buildCheckoutGit(given, worktree, mainCheckout = null) {
214
215
  return trusted !== null && at === trusted && at !== own && query ? given(file, args, options) : hardened(file, args, options);
215
216
  };
216
217
  }
217
- function commandRunner(store, runId, profile, inner) {
218
+ function commandRunner(store, runId, profile, inner, customEvidenceRoot = null) {
218
219
  const { access, network } = checkLaunchOf(store, runId, profile);
219
220
  store.stampRunCheckAccess(runId, access, network);
220
- return fencedCommands(store, runId, launchWritesOf(profile), inner, undefined, access, network ?? undefined, launchSandboxOf(profile));
221
+ return fencedCommands(store, runId, launchWritesOf(profile), inner, undefined, access, network ?? undefined, launchSandboxOf(profile), customEvidenceRoot);
221
222
  }
222
223
  export function checkLaunchOf(store, runId, profile, platform = process.platform) {
223
224
  const asked = checkAccessHere(profile.checkAccess ?? CHECK_ACCESS_DEFAULT, platform);
@@ -530,7 +531,7 @@ export async function build(store, request) {
530
531
  }
531
532
  const runSetup = request.setup ?? run;
532
533
  const shell = approvedCommandShell(setupWanted.command);
533
- const made = await underStopWatch(store, request.runId, () => runWithIsolatedDatabase(witnessedRunner(store, request.runId, request.clock ?? (() => now), commandRunner(store, request.runId, effective.profile, runSetup)), shell.file, shell.args, {
534
+ const made = await underStopWatch(store, request.runId, () => runWithIsolatedDatabase(witnessedRunner(store, request.runId, request.clock ?? (() => now), commandRunner(store, request.runId, effective.profile, runSetup, request.evidenceRoot ?? evidenceRoot(homedir()))), shell.file, shell.args, {
534
535
  cwd: worktree,
535
536
  timeoutMs: setupWanted.timeoutMs,
536
537
  processGroup: true,
@@ -1021,6 +1022,7 @@ export async function build(store, request) {
1021
1022
  network: launchNetworkOf(store, request.taskRef, effective.profile),
1022
1023
  writes: launchWritesOf(effective.profile), sandbox: launchSandboxOf(effective.profile),
1023
1024
  skills: projectSkills,
1025
+ evidenceRoot: root,
1024
1026
  ...(agent === undefined ? {} : { runner: agent }),
1025
1027
  onSpawn: (pid) => { spawned = true; request.onProviderSpawn?.(pid); },
1026
1028
  onStreamEvent: (event) => liveLog.observe(event),
@@ -1292,7 +1294,7 @@ export async function settleProviderOutcome(captured, result) {
1292
1294
  .filter(line => line.trim() !== "" &&
1293
1295
  !line.trimEnd().endsWith(LEASE_MARKER) &&
1294
1296
  !(line.startsWith("?? ") && looksLikeProtocolFile(line.slice(3))));
1295
- const pinnedBase = store.firstBuilderBase(taskRef, branch) ?? baseRevision;
1297
+ const pinnedBase = wholeChangeBaseOf(store, taskRef, branch) ?? baseRevision;
1296
1298
  if (handoff.status === "no-change") {
1297
1299
  if (dirty.length > 0) {
1298
1300
  return {
@@ -1338,7 +1340,7 @@ export async function settleProviderOutcome(captured, result) {
1338
1340
  };
1339
1341
  if (!eligible())
1340
1342
  throw Error("The observation source or execution authority changed.");
1341
- const execute = (file, args, options) => underStopWatch(store, request.runId, () => runWithIsolatedDatabase(witnessedRunner(store, request.runId, clock, commandRunner(store, request.runId, captured.effective.profile, request.verify ?? run)), file, args, {
1343
+ const execute = (file, args, options) => underStopWatch(store, request.runId, () => runWithIsolatedDatabase(witnessedRunner(store, request.runId, clock, commandRunner(store, request.runId, captured.effective.profile, request.verify ?? run, root)), file, args, {
1342
1344
  ...options, processGroup: true, owner: runOwnerTag(store, request.runId), beforeSpawn: eligible,
1343
1345
  onSpawn: pid => request.onProviderSpawn?.(pid), envAllowlist: SETUP_ENV_ALLOWLIST, omitEnv: SETUP_ENV_DENYLIST,
1344
1346
  }));
@@ -1766,7 +1768,7 @@ async function settleProof(captured, statArtifactId, sealedHead) {
1766
1768
  ? { code: 127, stdout: "", stderr: `Toolroll did not start the check: ${missing} wasn't found.`, timedOut: false, notFound: false }
1767
1769
  : await underStopWatch(store, runId, () => {
1768
1770
  loadWatch?.attemptStarted();
1769
- return runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, verifyRunner)), verifyShell.file, verifyShell.args, {
1771
+ return runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, verifyRunner, root)), verifyShell.file, verifyShell.args, {
1770
1772
  cwd: worktree,
1771
1773
  timeoutMs: loadWatch?.limitMs ?? configured.timeoutMs,
1772
1774
  processGroup: true,
@@ -1813,7 +1815,7 @@ async function settleProof(captured, statArtifactId, sealedHead) {
1813
1815
  detachShared(worktree, depsRoot);
1814
1816
  const label = "Own install · approved project setup (package.json or lockfile changed)";
1815
1817
  const setupShell = approvedCommandShell(live.command);
1816
- const installed = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, request.setup ?? run)), setupShell.file, setupShell.args, {
1818
+ const installed = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, request.setup ?? run, root)), setupShell.file, setupShell.args, {
1817
1819
  cwd: worktree,
1818
1820
  timeoutMs: live.timeoutMs,
1819
1821
  processGroup: true,
@@ -1902,7 +1904,7 @@ async function settleProof(captured, statArtifactId, sealedHead) {
1902
1904
  else {
1903
1905
  const setupRunner = request.setup ?? run;
1904
1906
  const setupShell = approvedCommandShell(liveBeforeSetup.command);
1905
- const restored = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, setupRunner)), setupShell.file, setupShell.args, {
1907
+ const restored = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, setupRunner, root)), setupShell.file, setupShell.args, {
1906
1908
  cwd: worktree,
1907
1909
  timeoutMs: liveBeforeSetup.timeoutMs,
1908
1910
  processGroup: true,
@@ -2184,6 +2186,7 @@ async function resumeUnhandedWork(captured, sessionId) {
2184
2186
  network: launchNetworkOf(store, request.taskRef, effective.profile),
2185
2187
  writes: launchWritesOf(effective.profile), sandbox: launchSandboxOf(effective.profile),
2186
2188
  skills: captured.skills ?? null,
2189
+ evidenceRoot: request.evidenceRoot ?? evidenceRoot(homedir()),
2187
2190
  ...(agent === undefined ? {} : { runner: agent }),
2188
2191
  ...(request.onProviderSpawn === undefined ? {} : { onSpawn: request.onProviderSpawn }),
2189
2192
  clock,
@@ -2431,6 +2434,7 @@ async function ingestPark(args) {
2431
2434
  omitEnv: AGENT_ENV_DENYLIST,
2432
2435
  ...(args.profile === undefined ? {} : { network: launchNetworkOf(store, request.taskRef, args.profile), writes: launchWritesOf(args.profile), sandbox: launchSandboxOf(args.profile) }),
2433
2436
  skills: resumableRepair ? (args.skills ?? null) : null,
2437
+ evidenceRoot: request.evidenceRoot ?? evidenceRoot(homedir()),
2434
2438
  ...(agent === undefined ? {} : { runner: agent }),
2435
2439
  ...(request.onProviderSpawn === undefined ? {} : { onSpawn: request.onProviderSpawn }),
2436
2440
  clock,
@@ -6,9 +6,9 @@ import { openStore } from "./store.js";
6
6
  import { holdAutoPublish, autoPublishHeld, PUBLISH_ALLOWED_ACTION, PUBLISH_HELD_ACTION } from "./release-auto.js";
7
7
  import { revokeCoordinator } from "./coordinator.js";
8
8
  export const MAX_STAGE_BYTES = 128 * 1024 * 1024;
9
- const SUPPORTED_SCHEMA = 185;
10
- const SCHEMA_OBJECT_COUNT = 726;
11
- const SCHEMA_DIGEST = "8e589635cf648eef4a4c85fb12c614b3c004d983df639ccd2bf95b3005bf5791";
9
+ const SUPPORTED_SCHEMA = 186;
10
+ const SCHEMA_OBJECT_COUNT = 732;
11
+ const SCHEMA_DIGEST = "5bd44762a424f9dccb0f4adeac674b53c6978b253cdf0c74c349c321ba43a361";
12
12
  const INVENTORY = [
13
13
  ["person-credentials", "store.ts:revokeApiToken", "credential", true],
14
14
  ["lead-credentials", "store.ts:revokeLeadCredentials", "credential", true],
package/dist/cli-help.js CHANGED
@@ -98,6 +98,7 @@ Tasks (\`toolroll task --help\` lists every task command)
98
98
  the yes — nothing builds without one
99
99
  toolroll task accept <id> --finish
100
100
  accept the result you read (--despite "<why>": accept it with a reason, without finishing)
101
+ toolroll task land <id> put accepted work on your branch as one commit (no pull requests)
101
102
  toolroll task send-back <id> --feedback "<what to change>"
102
103
  send the result back for changes
103
104
  toolroll task retry <id> build it again
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
3
3
  import { codingEnvironment } from "./coding-provider.js";
4
4
  import { codexLimitsOf, record } from "./provider-limits.js";
5
5
  import { refreshSubscriptions } from "./subscription-usage.js";
6
+ import { directChatRunning, onPlanLimitsViewed, planLimitsWanted } from "./plan-limits-demand.js";
6
7
  import { billingOf } from "./spend.js";
7
8
  import { envValue } from "./names.js";
8
9
  function accountBilling(account) {
@@ -103,28 +104,7 @@ export function readCodexLimits(options = {}) {
103
104
  export function startCodexLimits(store, signedIn, everyMs = 5 * 60_000) {
104
105
  if (process.env["VITEST"] !== undefined || envValue(process.env, "NO_PLAN_PROBE") !== undefined || store.isDemo())
105
106
  return () => { };
106
- let stopped = false, busy = false;
107
- const pass = async () => {
108
- if (stopped || busy)
109
- return;
110
- busy = true;
111
- try {
112
- await codexLimitsPass(store, { signedIn, stopped: () => stopped });
113
- if (!stopped) {
114
- await refreshSubscriptions(store, store.databaseFile(), { skipCodex: true });
115
- }
116
- }
117
- catch {
118
- }
119
- finally {
120
- busy = false;
121
- }
122
- };
123
- const timer = setInterval(() => void pass(), everyMs);
124
- timer.unref?.();
125
- const first = setTimeout(() => void pass(), 10_000);
126
- first.unref?.();
127
- return () => { stopped = true; clearInterval(timer); clearTimeout(first); };
107
+ return scheduleLimitsLoop(store, { signedIn }, everyMs);
128
108
  }
129
109
  export async function codexLimitsPass(store, seams) {
130
110
  if (billingOf("codex") !== "subscription")
@@ -132,8 +112,12 @@ export async function codexLimitsPass(store, seams) {
132
112
  const recent = new Date(Date.now() - 6 * 3_600_000).toISOString();
133
113
  if (store.handle.prepare("SELECT 1 AS live FROM run WHERE provider = 'codex' AND outcome IS NULL AND started_at > ? LIMIT 1").get(recent) !== undefined)
134
114
  return "skipped";
115
+ if (directChatRunning(store, "codex", new Date()))
116
+ return "skipped";
135
117
  if (!(await seams.signedIn()))
136
118
  return "skipped";
119
+ if (seams.stillWanted?.() === false)
120
+ return "skipped";
137
121
  const reading = await (seams.read ?? (() => readCodexLimits()))();
138
122
  if (reading !== null && seams.stopped?.() !== true)
139
123
  store.recordProviderLimits(reading, new Date());
@@ -144,3 +128,37 @@ export async function codexSignedInNow(check) {
144
128
  return false;
145
129
  return (await check("codex", true)).state === "connected";
146
130
  }
131
+ const VIEWED_PASS_GAP_MS = 60_000;
132
+ export function scheduleLimitsLoop(store, seams, everyMs = 5 * 60_000) {
133
+ const clock = seams.clock ?? (() => new Date());
134
+ let stopped = false, busy = false, lastPass = -Infinity;
135
+ const pass = async (viewed) => {
136
+ if (stopped || busy)
137
+ return;
138
+ const now = clock();
139
+ if (!planLimitsWanted(store, now))
140
+ return;
141
+ if (viewed && now.getTime() - lastPass < VIEWED_PASS_GAP_MS)
142
+ return;
143
+ busy = true;
144
+ lastPass = now.getTime();
145
+ try {
146
+ const stillWanted = () => !stopped && planLimitsWanted(store, clock());
147
+ await codexLimitsPass(store, { signedIn: seams.signedIn, stopped: () => stopped, stillWanted, ...(seams.readCodex === undefined ? {} : { read: seams.readCodex }) });
148
+ if (stillWanted()) {
149
+ await refreshSubscriptions(store, store.databaseFile(), { skipCodex: true, now: clock(), stillWanted, ...(seams.readers === undefined ? {} : { readers: seams.readers }) });
150
+ }
151
+ }
152
+ catch {
153
+ }
154
+ finally {
155
+ busy = false;
156
+ }
157
+ };
158
+ const timer = setInterval(() => void pass(false), everyMs);
159
+ timer.unref?.();
160
+ const first = setTimeout(() => void pass(false), 10_000);
161
+ first.unref?.();
162
+ const stopListening = onPlanLimitsViewed(store, () => void pass(true));
163
+ return () => { stopped = true; clearInterval(timer); clearTimeout(first); stopListening(); };
164
+ }
@@ -404,8 +404,8 @@ export function createCodexCodingProvider(options = {}) {
404
404
  close,
405
405
  };
406
406
  }
407
- export function codingSessionPermissions(store, worktreeRoot) {
408
- return input => sessionPermissions(store, { ...input, worktreeRoot });
407
+ export function codingSessionPermissions(store, worktreeRoot, evidenceRoot = null) {
408
+ return input => sessionPermissions(store, { ...input, worktreeRoot, evidenceRoot });
409
409
  }
410
410
  async function sessionPermissions(store, input) {
411
411
  const databaseFile = store.databaseFile();
@@ -420,7 +420,7 @@ async function sessionPermissions(store, input) {
420
420
  const skills = skillsGrant({ root: join(dirname(databaseFile), "coding-context"), manifest: input.skills ?? null });
421
421
  if (skills.problem !== null)
422
422
  return { problem: `${skills.problem}, so the session was not started.` };
423
- const launch = fenceFor("build", { databaseFile, worktree: input.worktree, boundary, binding, runFolders: runFolders(null), poolRoots, readDeny, extra: skills.deny, policy: FENCE_POLICY_CURRENT, storage, exactFiles: skills.files });
423
+ const launch = fenceFor("build", { databaseFile, worktree: input.worktree, boundary, binding, runFolders: runFolders(null), poolRoots, readDeny, evidenceRoot: input.evidenceRoot ?? null, extra: skills.deny, policy: FENCE_POLICY_CURRENT, storage, exactFiles: skills.files, exactDigests: skills.digests, exactFolders: skills.folders });
424
424
  return { config: codexFenceConfig(launch.fence, false, launch.fenceGrants) };
425
425
  }
426
426
  catch (error) {
@@ -62,12 +62,14 @@ export const CONSOLE_FORMS = {
62
62
  threadTurn: formContract("POST /agents/live/thread/<id>/turn", ["message", "key", "password"]),
63
63
  threadShip: formContract("POST /agents/live/thread/<id>/ship", ["terms", "digest"]),
64
64
  threadSendBack: formContract("POST /agents/live/thread/<id>/ship/send-back", ["feedback", "key", "password"]),
65
+ threadSave: formContract("POST /agents/live/thread/<id>/save", []),
65
66
  threadClose: formContract("POST /agents/live/thread/<id>/stop, /agents/live/thread/<id>/end, /agents/live/thread/<id>/ship/cancel", []),
66
67
  term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password", "task", "run"]),
67
68
  termAgent: formContract("POST /term/agent/sign-in, /term/agent/install", ["agent", "password", "confirm"]),
68
69
  agentsCheck: formContract("POST /engine/agents/check", []),
69
70
  skillsRevise: formContract("POST /settings/skills/revise", ["run", "repo", "feedback", "nonce"]),
70
71
  skillsChange: formContract("POST /settings/skills/import, /settings/skills/change", ["repo", "identity", "revision", "method", "content", "files", "url", "action", "sha", "sample", "nonce", "restore"]),
72
+ skillsLibrary: formContract("POST /settings/skills/library", ["action", "repo", "url", "skill", "sha", "bundle", "tool", "enabled", "autoUpdate", "optedOut", "method", "content", "files", "revision"]),
71
73
  kit: formContract("POST /kits/<kit>/<act>", ["repo", "password"]),
72
74
  subagents: formContract("POST /settings/lead/subagents/new, /settings/lead/subagents/<id>/<part>, /settings/lead/subagents/questions/<id>/answer", ["choice", "text", "repo", "template", "name", "soul", "op", "id", "schedule", "tool", "state", "note", "model", "dailyTurns", "manager", "password", "backupPresent", "codexBackupModel"], { prefixes: ["use.", "undo.", "field.", "over."] }),
73
75
  galleryUse: formContract("POST /flows/new/<template>", ["repo", "send-result", "name", "intent", "previewed", "password"], { dynamic: true }),
@@ -219,6 +221,7 @@ export const CONSOLE_FORMS = {
219
221
  directChatShipCancel: formContract("POST /engine/direct-chats/<id>/ship-cancel", ["shipId"]),
220
222
  directChatPageShipReview: formContract("POST /direct-chats/<id>/ship-review", []),
221
223
  directChatPageShip: formContract("POST /direct-chats/<id>/ship", ["mode", "termsDigest", "title", "goal", "password"]),
224
+ directChatPageReply: formContract("POST /direct-chats/<id>/reply", ["prompt", "request"]),
222
225
  };
223
226
  export const BODILESS_POSTS = [
224
227
  "POST /settings/models/<unknown action>",
@@ -5,6 +5,7 @@ import { fenceFor, FENCE_POLICY_CURRENT, linuxFenceAvailable, macosFenceAvailabl
5
5
  import { proxyEnv, repositoryEcosystems, resolveNetwork, startEgressProxy } from "./egress.js";
6
6
  import { readDenyPath } from "./project-sandbox.js";
7
7
  import { prepareProtectedStorage, storageRefusalOf } from "./protected-storage.js";
8
+ import { skillsGrant } from "./skills-manifest.js";
8
9
  import { poolRootOf } from "./worktree.js";
9
10
  const real = (path) => { try {
10
11
  return realpathSync(path);
@@ -12,7 +13,7 @@ const real = (path) => { try {
12
13
  catch {
13
14
  return path;
14
15
  } };
15
- export function directChatFence(store) {
16
+ export function directChatFence(store, evidenceRoot = null) {
16
17
  return async (input) => {
17
18
  if (!macosFenceAvailable() && !linuxFenceAvailable()) {
18
19
  return store.unfencedAgentsAllowed() ? { unfenced: true }
@@ -74,15 +75,20 @@ export function directChatFence(store) {
74
75
  const boundary = taskBoundary({ worktree: clone, provider: "claude", binding: null, policy: FENCE_POLICY_CURRENT, storage });
75
76
  const allowed = writeAllowlist({ provider: "claude", home, worktree: clone, binding: null, launchFolder: temp, cache: null });
76
77
  const gitReadOnly = ["config", "hooks", "info"].map(name => join(gitDir, name));
78
+ const skills = skillsGrant({ root: join(input.stateRoot, "direct-chat", "skills"), manifest: input.skills ?? null });
77
79
  const made = fenceFor("build", {
78
80
  databaseFile, worktree: clone, boundary, binding: null, runFolders: runFolders(temp), poolRoots, storage, policy: FENCE_POLICY_CURRENT, provider: "claude",
79
- extra: [repo, ...allowed.deny],
81
+ evidenceRoot,
82
+ extra: [repo, ...allowed.deny, ...skills.deny],
83
+ exactFiles: skills.files,
84
+ exactDigests: skills.digests,
85
+ exactFolders: skills.folders,
80
86
  readDeny: store.projectSandbox(input.repo).readDeny.map(one => readDenyPath(one, home)),
81
87
  writes: { writes: { subpaths: [...allowed.writes.subpaths, gitDir], prefixes: allowed.writes.prefixes }, readOnly: [...allowed.readOnly, ...gitReadOnly] },
82
88
  network: { mode: "allowlist", proxyPort: proxy.port, brokerPorts: [], loopback: policy.loopback, socketRoots: [clone, temp], token: proxy.secret },
83
89
  });
84
90
  const grants = { ...made.fenceGrants, readDenyOnly: [...made.fenceGrants.readDenyOnly ?? [], chats],
85
- readable: [...made.fenceGrants.readable, clone, gitDir], exactFiles: [...made.fenceGrants.exactFiles ?? [], clone, gitDir] };
91
+ readable: [...made.fenceGrants.readable, clone, gitDir, ...skills.files], exactFiles: [...made.fenceGrants.exactFiles ?? [], clone, gitDir, ...skills.files] };
86
92
  return { launch: { ...made, fenceGrants: grants }, temp, env: { ...proxyEnv(proxy, policy.loopback), TMPDIR: temp, TMP: temp, TEMP: temp, CLAUDE_CODE_TMPDIR: temp }, close };
87
93
  }
88
94
  catch (error) {
@@ -17,6 +17,8 @@ import { captureNewWorkspaceArtifacts, extractBase64ImagesFromLine, getDirectCha
17
17
  import { assertManagedClonePath, assertTrustedCloneGit, cloneIsolatedRepoAsync, pinnedConfigBackupPath, repairCloneGitBinding, runTrustedCloneGit, } from "./direct-chat-git.js";
18
18
  import { applyMainDirtyPatch, cloneSafeNodeModulesAsync } from "./direct-chat-workspace.js";
19
19
  import { defaultContextWindowFor, normalizeDirectChatEffort, resolveAgyModelForEffort } from "./direct-chat-catalog.js";
20
+ import { effectiveSkillsForRepo, materializeProjectSkills } from "./project-skills.js";
21
+ import { formatSkillsBrief } from "./skill-library.js";
20
22
  export const DIRECT_CHAT_PROVIDERS = Object.freeze(["claude", "codex", "gemini"]);
21
23
  export function isDirectChatProvider(value) {
22
24
  return value === "claude" || value === "codex" || value === "gemini";
@@ -568,6 +570,9 @@ export function buildTurnPrompt(input) {
568
570
  const parts = [];
569
571
  if (input.isFirstTurnForProvider) {
570
572
  parts.push(`[Workspace boundary: you are working in an isolated local clone on branch ${input.branch} with no remote. Work only inside this directory; never push, force-reset, or delete files outside this workspace. Leave your changes in the working tree — do not run git commit or git push, because Toolroll commits and ships snapshots for you.]`);
573
+ if (input.skillsPrompt && input.skillsPrompt.trim() !== "") {
574
+ parts.push(input.skillsPrompt.trim());
575
+ }
571
576
  if (input.priorTurns.length > 0) {
572
577
  const slice = input.priorTurns.slice(-HANDOFF_MAX_TURNS);
573
578
  let handoff = "[Context handed off from earlier turns in this chat:]\n";
@@ -728,6 +733,7 @@ export class DirectChatHost {
728
733
  spawnTurnFn;
729
734
  fenceTurnFn;
730
735
  turnFences = new Map();
736
+ turnSkillDirs = new Map();
731
737
  prepareCloneFn;
732
738
  readDiffFn;
733
739
  hasCustomReadDiff;
@@ -751,7 +757,7 @@ export class DirectChatHost {
751
757
  this.stopGraceMs = seams.stopGraceMs ?? DEFAULT_STOP_GRACE_MS;
752
758
  this.locateBinary = seams.locateBinary ?? (provider => locateDirectChatBinary(provider));
753
759
  this.spawnTurnFn = seams.spawnTurn ?? (input => defaultSpawnTurn(this.custody, input));
754
- this.fenceTurnFn = seams.fenceTurn ?? (seams.spawnTurn === undefined ? directChatFence(store) : null);
760
+ this.fenceTurnFn = seams.fenceTurn ?? (seams.spawnTurn === undefined ? directChatFence(store, seams.evidenceRoot ?? null) : null);
755
761
  this.prepareCloneFn = seams.prepareClone ?? defaultPrepareCloneAsync;
756
762
  this.hasCustomReadDiff = seams.readDiff !== undefined;
757
763
  this.readDiffFn = seams.readDiff ?? defaultReadDiff;
@@ -782,6 +788,13 @@ export class DirectChatHost {
782
788
  }
783
789
  for (const turnId of [...this.turnFences.keys()])
784
790
  this.closeTurnFence(turnId);
791
+ for (const [turnId, dir] of [...this.turnSkillDirs.entries()]) {
792
+ this.turnSkillDirs.delete(turnId);
793
+ try {
794
+ rmSync(dir, { recursive: true, force: true });
795
+ }
796
+ catch { }
797
+ }
785
798
  }
786
799
  closeTurnFence(turnId) {
787
800
  const close = this.turnFences.get(turnId);
@@ -1208,33 +1221,71 @@ export class DirectChatHost {
1208
1221
  const thread = this.mapThread(this.store.handle.prepare(`SELECT * FROM direct_chat_thread WHERE id = ?`).get(threadId));
1209
1222
  return { ok: true, thread, turn: started.turn, created: true };
1210
1223
  }
1224
+ prepareTurnSkills(repo, label) {
1225
+ try {
1226
+ const snapshot = effectiveSkillsForRepo(this.store, repo);
1227
+ if (snapshot.packages.length === 0)
1228
+ return { dir: null, prompt: "", manifest: null };
1229
+ const materialized = materializeProjectSkills(snapshot, join(this.stateRoot, "direct-chat", "skills"), label);
1230
+ return {
1231
+ dir: materialized.directory,
1232
+ prompt: formatSkillsBrief(materialized.catalog, "Skills supplied for this Direct Chat. "),
1233
+ manifest: materialized.manifest,
1234
+ };
1235
+ }
1236
+ catch {
1237
+ return { dir: null, prompt: "", manifest: null };
1238
+ }
1239
+ }
1211
1240
  async sendMessage(input) {
1212
1241
  const thread = HEX32.test(input.threadId) ? this.getThreadRecord(input.owner, input.threadId) : null;
1213
1242
  if (thread === null || thread.provider !== "claude" || thread.isLegacy || this.fenceTurnFn === null)
1214
- return this.sendMessageNow(input, null);
1243
+ return this.sendMessageNow(input, null, null);
1215
1244
  if (thread.gitDir === null)
1216
1245
  return { ok: false, status: 409, error: "This chat has no isolated Git folder, so its agent can't be fenced. Start a new chat instead." };
1217
1246
  const known = this.store.handle.prepare(`SELECT 1 FROM direct_chat_turn WHERE thread_id = ? AND request_id = ?`).get(thread.id, input.requestId);
1218
1247
  if (known !== undefined)
1219
- return this.sendMessageNow(input, null);
1220
- const made = await this.fenceTurnFn({ stateRoot: this.stateRoot, repo: thread.repo, clone: thread.clonePath, gitDir: thread.gitDir });
1221
- if ("problem" in made)
1248
+ return this.sendMessageNow(input, null, null);
1249
+ const preparedSkills = this.prepareTurnSkills(thread.repo, `dc-${randomBytes(6).toString("hex")}`);
1250
+ const made = await this.fenceTurnFn({ stateRoot: this.stateRoot, repo: thread.repo, clone: thread.clonePath, gitDir: thread.gitDir, skills: preparedSkills.manifest });
1251
+ if ("problem" in made) {
1252
+ if (preparedSkills.dir !== null) {
1253
+ try {
1254
+ rmSync(preparedSkills.dir, { recursive: true, force: true });
1255
+ }
1256
+ catch { }
1257
+ }
1222
1258
  return { ok: false, status: 409, error: made.problem };
1259
+ }
1223
1260
  const fence = "unfenced" in made ? null : made;
1224
1261
  let started;
1225
1262
  try {
1226
- started = this.sendMessageNow(input, fence);
1263
+ started = this.sendMessageNow(input, fence, preparedSkills);
1227
1264
  }
1228
1265
  catch (error) {
1229
1266
  if (fence !== null)
1230
1267
  await fence.close();
1268
+ if (preparedSkills.dir !== null) {
1269
+ try {
1270
+ rmSync(preparedSkills.dir, { recursive: true, force: true });
1271
+ }
1272
+ catch { }
1273
+ }
1231
1274
  throw error;
1232
1275
  }
1233
- if (fence !== null && (!started.ok || !started.created))
1234
- await fence.close();
1276
+ if (!started.ok || !started.created) {
1277
+ if (fence !== null)
1278
+ await fence.close();
1279
+ if (preparedSkills.dir !== null) {
1280
+ try {
1281
+ rmSync(preparedSkills.dir, { recursive: true, force: true });
1282
+ }
1283
+ catch { }
1284
+ }
1285
+ }
1235
1286
  return started;
1236
1287
  }
1237
- sendMessageNow(input, fence) {
1288
+ sendMessageNow(input, fence, prebuiltSkills) {
1238
1289
  if (!HEX32.test(input.threadId) || !HEX32.test(input.requestId)) {
1239
1290
  return { ok: false, status: 400, error: "Invalid thread or request id." };
1240
1291
  }
@@ -1272,11 +1323,13 @@ export class DirectChatHost {
1272
1323
  const logPath = join(this.stateRoot, "direct-chat", "turns", thread.id, `${turnId}.jsonl`);
1273
1324
  const stderrPath = join(this.stateRoot, "direct-chat", "turns", thread.id, `${turnId}.stderr`);
1274
1325
  const isFirstForProvider = thread.providerSessionId === null || thread.providerSessionId === "";
1326
+ const turnSkills = prebuiltSkills ?? this.prepareTurnSkills(thread.repo, `dc-${turnId.slice(0, 12)}`);
1275
1327
  const effectivePrompt = buildTurnPrompt({
1276
1328
  userPrompt: trimmed,
1277
1329
  branch: thread.branch,
1278
1330
  isFirstTurnForProvider: isFirstForProvider,
1279
1331
  priorTurns: priorTurns.filter(t => t.assistantText !== "" || t.userPrompt !== ""),
1332
+ ...(turnSkills.prompt !== "" ? { skillsPrompt: turnSkills.prompt } : {}),
1280
1333
  });
1281
1334
  const args = buildProviderCommand({
1282
1335
  provider: thread.provider,
@@ -1299,17 +1352,26 @@ export class DirectChatHost {
1299
1352
  `).run(turnId, thread.id, nextSeq, input.requestId, trimmed, switchedFrom, logPath, stderrPath, this.bootId(), stamp);
1300
1353
  let launched;
1301
1354
  try {
1355
+ const childEnv = buildSanitizedChildEnv(thread.provider);
1356
+ if (turnSkills.dir !== null)
1357
+ childEnv["TOOLROLL_SKILLS_DIR"] = turnSkills.dir;
1302
1358
  launched = this.spawnTurnFn({
1303
1359
  binary,
1304
1360
  args,
1305
1361
  cwd: managed.realClone,
1306
- env: buildSanitizedChildEnv(thread.provider),
1362
+ env: childEnv,
1307
1363
  logPath,
1308
1364
  stderrPath,
1309
1365
  ...(fence === null ? {} : { fence }),
1310
1366
  });
1311
1367
  }
1312
1368
  catch (error) {
1369
+ if (prebuiltSkills === null && turnSkills.dir !== null) {
1370
+ try {
1371
+ rmSync(turnSkills.dir, { recursive: true, force: true });
1372
+ }
1373
+ catch { }
1374
+ }
1313
1375
  const msg = `Could not launch ${thread.provider}: ${error instanceof Error ? error.message : String(error)}`;
1314
1376
  this.store.handle.prepare(`
1315
1377
  UPDATE direct_chat_turn SET status = 'failed', error_text = ?, finished_at = ? WHERE id = ?
@@ -1323,6 +1385,8 @@ export class DirectChatHost {
1323
1385
  }
1324
1386
  if (fence !== null)
1325
1387
  this.turnFences.set(turnId, fence.close);
1388
+ if (turnSkills.dir !== null)
1389
+ this.turnSkillDirs.set(turnId, turnSkills.dir);
1326
1390
  this.store.handle.prepare(`
1327
1391
  UPDATE direct_chat_turn SET pid = ?, start_identity = ?, pgid = ? WHERE id = ?
1328
1392
  `).run(launched.pid, launched.startIdentity, launched.pgid, turnId);
@@ -1886,6 +1950,14 @@ export class DirectChatHost {
1886
1950
  }
1887
1951
  cleanupTurnState(turnId) {
1888
1952
  this.closeTurnFence(turnId);
1953
+ const skillDir = this.turnSkillDirs.get(turnId);
1954
+ if (skillDir !== undefined) {
1955
+ this.turnSkillDirs.delete(turnId);
1956
+ try {
1957
+ rmSync(skillDir, { recursive: true, force: true });
1958
+ }
1959
+ catch { }
1960
+ }
1889
1961
  this.sawTerminalByTurn.delete(turnId);
1890
1962
  this.resetOnNextTextDelta.delete(turnId);
1891
1963
  this.preTurnImages.delete(turnId);
@@ -605,10 +605,12 @@ function shownPatch(text) {
605
605
  }
606
606
  const PRIVATE_KEY_MARK = /-----(?:BEGIN|END) [A-Z ]*PRIVATE KEY-----/;
607
607
  const HIDDEN_NAME = "[a name was hidden]";
608
- export function threadDiffOf(thread, turn, changes) {
608
+ export function threadDiffOf(thread, turn, changes, seen = {}) {
609
609
  const empty = (problem) => ({ version: ENGINE_API_VERSION, task: thread, run: turn, totals: null, files: [], patchTruncated: false, problem });
610
610
  if (!changes.ok)
611
611
  return empty(`This thread's changes can't be read: ${cleanLiveText(changes.message)}`);
612
+ if ("none" in changes && seen.edited === true)
613
+ return empty("The agent has uncommitted edits. Ask it to commit them: Ship and Save as branch take committed work only.");
612
614
  if ("none" in changes)
613
615
  return empty("No committed changes yet. Ask the agent to commit its work: Ship sends committed work only.");
614
616
  const files = patchFiles(changes.patch).map((text, index) => {
@@ -7,6 +7,8 @@ import { relayUrlInside } from "./flexible-relay.js";
7
7
  import { flexibleThread, flexibleThreadFence, flexibleThreadSpawn, stopFlexibleThreadAgent, withFlexibleThreadLock } from "./flexible-thread.js";
8
8
  import { beginFlexibleTurn, finishFlexibleTurn, flexibleTurn, interruptFlexibleTurnsOf, withdrawFlexibleTurn, withdrawFlexibleTurnsAbove } from "./flexible-turns.js";
9
9
  import { CLAUDE_BUILD_ISOLATION_ARGV, HEADLESS_DISALLOWED_TOOLS } from "./provider.js";
10
+ import { effectiveSkillsForRepo, materializeProjectSkills } from "./project-skills.js";
11
+ import { formatSkillsBrief } from "./skill-library.js";
10
12
  const WORDS = Object.freeze({
11
13
  "not-available": FLEXIBLE_UNAVAILABLE,
12
14
  "codex-unsupported": "Codex's own sandbox can't keep a Flexible thread away from threads and files made after it starts, so Codex and OpenRouter threads can't run yet. Nothing was started.",
@@ -124,13 +126,25 @@ async function startLocked(store, input) {
124
126
  outcome: "refused", detail: `thread ${turn.thread} · turn ${turn.id} · ${providerProblem}` });
125
127
  return { ok: false, reason: "setup-failed", message: "The agent's configuration folder isn't the one Toolroll made, so it didn't start. Nothing was removed." };
126
128
  }
129
+ let skillsDir = null;
130
+ let skillsPrompt = "";
131
+ try {
132
+ const snapshot = effectiveSkillsForRepo(store, turn.repo);
133
+ if (snapshot.packages.length > 0) {
134
+ const supplied = materializeProjectSkills(snapshot, join(fenced.paths.home, "skills"), turn.id.slice(0, 16));
135
+ skillsDir = supplied.directory;
136
+ skillsPrompt = formatSkillsBrief(supplied.catalog, "Skills supplied for this thread. ");
137
+ }
138
+ }
139
+ catch {
140
+ }
127
141
  let endpoint = null;
128
142
  const agentEnvFor = (launchId) => {
129
143
  endpoint = input.relay.issue({ thread: turn.thread, turn: turn.id, launch: launchId });
130
144
  const spec = flexibleAgentLaunch(turn.provider, turn.level, { model: turn.model, relay: { url: relayInside, token: endpoint.token }, configHome });
131
145
  if (!spec.ok)
132
146
  throw new Error(spec.message);
133
- return spec.spec.env;
147
+ return skillsDir === null ? spec.spec.env : { ...spec.spec.env, TOOLROLL_SKILLS_DIR: skillsDir };
134
148
  };
135
149
  const spawned = await flexibleThreadSpawn(store, { id: turn.thread, network, storage: input.storage,
136
150
  proxyEnv: input.network.proxyEnv, agentEnvFor, launch: { provider: turn.provider, level: turn.level, turn: turn.id, holder: input.holder },
@@ -150,7 +164,7 @@ async function startLocked(store, input) {
150
164
  void stopFlexibleThreadAgent(store, { id: turn.thread, reason: "its agent exited", expect: { launch: launchId, holder: input.holder }, ...(input.seams?.io === undefined ? {} : { io: input.seams.io }) })
151
165
  .then(settled => { input.seams?.exitSettled?.(launchId, settled); }, () => { input.seams?.exitSettled?.(launchId, null); });
152
166
  });
153
- return { ok: true, launched: "started", launchId: spawned.launchId, pid: spawned.pid, child: spawned.child, stopWatching };
167
+ return { ok: true, launched: "started", launchId: spawned.launchId, pid: spawned.pid, child: spawned.child, stopWatching, ...(skillsPrompt !== "" ? { skillsPrompt } : {}) };
154
168
  }
155
169
  export async function lowerFlexibleThreadLevel(store, input) {
156
170
  if (!isFlexibleLevel(input.level) || typeof input.by?.name !== "string" || !Number.isSafeInteger(input.by.generation))
@@ -786,6 +786,44 @@ export async function flexibleTaskBranch(store, input) {
786
786
  : await build(project, ["update-ref", "--no-deref", "-d", ref, input.at]);
787
787
  return done.code === 0;
788
788
  }
789
+ export async function projectThreadBranch(store, input) {
790
+ const thread = flexibleThread(store, input.thread);
791
+ if (thread === null)
792
+ return "unreadable";
793
+ let project;
794
+ try {
795
+ project = realpathSync(thread.repo);
796
+ recordedCommonDir(project);
797
+ }
798
+ catch {
799
+ return "unreadable";
800
+ }
801
+ const read = gitIn(input.runner ?? run, "read");
802
+ const held = await read(project, ["rev-parse", "--verify", "--quiet", "--end-of-options", `refs/heads/${flexibleThreadBranch(thread.id)}`]);
803
+ if (held.code === 0 && SHA.test(held.stdout.trim()))
804
+ return held.stdout.trim();
805
+ return held.code === 1 ? null : "unreadable";
806
+ }
807
+ export async function projectMergeHint(store, input) {
808
+ const thread = flexibleThread(store, input.thread);
809
+ if (thread === null || !SHA.test(input.candidate))
810
+ return null;
811
+ let project;
812
+ try {
813
+ project = realpathSync(thread.repo);
814
+ recordedCommonDir(project);
815
+ }
816
+ catch {
817
+ return null;
818
+ }
819
+ const read = gitIn(input.runner ?? run, "read");
820
+ const head = await read(project, ["symbolic-ref", "-q", "HEAD"]);
821
+ const ref = head.code === 0 ? head.stdout.trim() : "";
822
+ if (!ref.startsWith("refs/heads/"))
823
+ return { repo: project, branch: null, fastForward: false };
824
+ const ancestor = await read(project, ["merge-base", "--is-ancestor", "--end-of-options", ref, input.candidate]);
825
+ return { repo: project, branch: ref.slice("refs/heads/".length), fastForward: ancestor.code === 0 };
826
+ }
789
827
  export async function settleInterruptedImport(store, input) {
790
828
  const thread = flexibleThread(store, input.thread);
791
829
  if (thread === null)