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.
Files changed (145) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +43 -26
  3. package/dist/acp-agents.js +14 -1
  4. package/dist/acp-client.js +19 -1
  5. package/dist/agent-change-check.js +60 -0
  6. package/dist/agent-change-schema.js +19 -0
  7. package/dist/agent-detect.js +11 -1
  8. package/dist/agent-fence.js +39 -10
  9. package/dist/agent-network-request.js +108 -0
  10. package/dist/agent-requests.js +105 -0
  11. package/dist/approval-summary.js +3 -3
  12. package/dist/backup.js +17 -1
  13. package/dist/batch-checks.js +81 -18
  14. package/dist/browser/terminal.js +41 -41
  15. package/dist/browser/workspace.css +2 -2
  16. package/dist/browser/workspace.js +36 -36
  17. package/dist/builder.js +3 -1
  18. package/dist/candidate-materialize.js +119 -0
  19. package/dist/central-enrollment-contract.js +156 -0
  20. package/dist/central-recovery-stage.js +329 -0
  21. package/dist/chat-actions.js +101 -2
  22. package/dist/chat-channel.js +40 -0
  23. package/dist/check-only-standing.js +13 -0
  24. package/dist/check-only.js +25 -13
  25. package/dist/check-recovery-hold.js +199 -0
  26. package/dist/check-recovery-index-schema.js +3 -0
  27. package/dist/check-screenshots.js +83 -0
  28. package/dist/cli.js +125 -6
  29. package/dist/codex-limits.js +4 -0
  30. package/dist/connect-cli.js +257 -11
  31. package/dist/contracts/chat-actions.js +4 -0
  32. package/dist/contracts/console-api.js +15 -4
  33. package/dist/contracts/engine-api.js +344 -2
  34. package/dist/contracts/lead-tools.js +56 -2
  35. package/dist/contracts/provider.js +1 -1
  36. package/dist/contracts/route.js +1 -1
  37. package/dist/contracts/terminal-connection.js +50 -0
  38. package/dist/converse.js +80 -4
  39. package/dist/device-pair.js +280 -0
  40. package/dist/direct-chat-artifacts.js +347 -0
  41. package/dist/direct-chat-catalog.js +311 -0
  42. package/dist/direct-chat-fence.js +96 -0
  43. package/dist/direct-chat-git.js +343 -0
  44. package/dist/direct-chat-laptop.js +19 -0
  45. package/dist/direct-chat-schema.js +181 -0
  46. package/dist/direct-chat-ship.js +861 -0
  47. package/dist/direct-chat-workspace.js +389 -0
  48. package/dist/direct-chat.js +2107 -0
  49. package/dist/doctor.js +1 -1
  50. package/dist/easy-start.js +18 -0
  51. package/dist/egress.js +25 -4
  52. package/dist/engine-chat.js +454 -0
  53. package/dist/engine-reads.js +141 -13
  54. package/dist/exec.js +4 -3
  55. package/dist/flexible-agents.js +8 -16
  56. package/dist/flexible-authority-end.js +2 -0
  57. package/dist/flexible-interactive-schema.js +133 -0
  58. package/dist/flexible-interactive.js +94 -0
  59. package/dist/flexible-session.js +117 -49
  60. package/dist/flexible-ship.js +87 -7
  61. package/dist/flexible-sign-in.js +10 -0
  62. package/dist/flexible-start.js +21 -3
  63. package/dist/flexible-thread.js +2 -3
  64. package/dist/flexible-turns.js +26 -5
  65. package/dist/flexible.js +13 -0
  66. package/dist/flow-triggers.js +13 -4
  67. package/dist/flows-ui.js +54 -20
  68. package/dist/handoff-cli.js +630 -0
  69. package/dist/invoke.js +55 -13
  70. package/dist/lead-contract.js +5 -4
  71. package/dist/lead-doors.js +80 -1
  72. package/dist/lead-progress.js +9 -0
  73. package/dist/lead-tools.js +682 -10
  74. package/dist/lead.js +37 -9
  75. package/dist/live-bus.js +11 -0
  76. package/dist/live-terminal.js +132 -12
  77. package/dist/local-handoff.js +363 -0
  78. package/dist/local-owner-acts.js +264 -2
  79. package/dist/local-owner.js +16 -1
  80. package/dist/multiplayer-handoff.js +528 -0
  81. package/dist/multiplayer-presence.js +471 -0
  82. package/dist/names.js +17 -4
  83. package/dist/needs-you.js +10 -0
  84. package/dist/operate.js +280 -19
  85. package/dist/policy.js +2 -2
  86. package/dist/project-delete-ui.js +18 -11
  87. package/dist/project-delete.js +65 -4
  88. package/dist/project-tools.js +1 -1
  89. package/dist/prompt.js +1 -1
  90. package/dist/provider-connection.js +2 -0
  91. package/dist/provider-home.js +251 -8
  92. package/dist/provider.js +3 -2
  93. package/dist/publish.js +119 -64
  94. package/dist/pull-request-flow.js +35 -14
  95. package/dist/read-executor-worker.js +1 -1
  96. package/dist/read-executor.js +95 -1
  97. package/dist/restore-retirement.js +152 -0
  98. package/dist/result-follow-ups.js +116 -37
  99. package/dist/route-change.js +44 -4
  100. package/dist/scope.js +62 -5
  101. package/dist/serve.js +49 -5
  102. package/dist/server/chat.js +94 -13
  103. package/dist/server/console.css +9 -9
  104. package/dist/server/direct-chat.js +583 -0
  105. package/dist/server/engine-api.js +219 -21
  106. package/dist/server/flows.js +47 -13
  107. package/dist/server/found-repos.js +25 -0
  108. package/dist/server/guards.js +20 -6
  109. package/dist/server/live.js +81 -23
  110. package/dist/server/pages.js +67 -13
  111. package/dist/server/people-tokens.js +47 -6
  112. package/dist/server/remote.js +29 -0
  113. package/dist/server/render-results.js +6 -2
  114. package/dist/server/render-settings.js +4 -2
  115. package/dist/server/render-tasks.js +18 -17
  116. package/dist/server/route-table.js +69 -2
  117. package/dist/server/settings.js +22 -7
  118. package/dist/server/task-views.js +15 -3
  119. package/dist/server/tasks.js +39 -2
  120. package/dist/server/terminals.js +185 -11
  121. package/dist/settings-proofs.js +1 -1
  122. package/dist/spend-report.js +2 -2
  123. package/dist/spend.js +3 -3
  124. package/dist/store.js +600 -59
  125. package/dist/subagent-admin.js +23 -10
  126. package/dist/subagent-backup-schema.js +36 -0
  127. package/dist/subagent-backup.js +92 -0
  128. package/dist/subagent-week.js +2 -2
  129. package/dist/subagent-work.js +70 -47
  130. package/dist/subagents-ui.js +6 -2
  131. package/dist/subagents.js +5 -2
  132. package/dist/subscription-chat.js +36 -5
  133. package/dist/subscription-usage.js +233 -0
  134. package/dist/task-live.js +2 -1
  135. package/dist/teardown-git.js +34 -4
  136. package/dist/terminal-connection.js +159 -0
  137. package/dist/terminal-safety.js +114 -0
  138. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  139. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  140. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  141. package/dist/tui/linux-x64/toolroll-tui +0 -0
  142. package/dist/tui-contract.js +1 -1
  143. package/dist/tui-launch.js +32 -1
  144. package/dist/workspace-identity-schema.js +21 -0
  145. package/package.json +4 -2
@@ -0,0 +1,389 @@
1
+ import { execFile, execFileSync } from "node:child_process";
2
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync } from "node:fs";
3
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
4
+ import { promisify } from "node:util";
5
+ import { assertTrustedCloneGit, runHardenedMainGit, runHardenedMainGitAsync, runTrustedCloneGit, } from "./direct-chat-git.js";
6
+ const execFileAsync = promisify(execFile);
7
+ const SKIPPED_DIR_SEGMENTS = new Set([
8
+ ".git",
9
+ ".venv",
10
+ "venv",
11
+ ".next",
12
+ ".turbo",
13
+ ".nuxt",
14
+ ".svelte-kit",
15
+ ".cache",
16
+ "dist",
17
+ "build",
18
+ ]);
19
+ const MAX_SYMLINK_SCAN_ENTRIES = 250_000;
20
+ const MAX_SYMLINK_SCAN_DEPTH = 48;
21
+ export function scanNodeModulesSafety(nodeModulesDir, opts) {
22
+ const maxEntries = opts?.maxEntries ?? MAX_SYMLINK_SCAN_ENTRIES;
23
+ const maxDepth = opts?.maxDepth ?? MAX_SYMLINK_SCAN_DEPTH;
24
+ let rootReal;
25
+ let boundaryReal;
26
+ try {
27
+ rootReal = realpathSync(nodeModulesDir);
28
+ boundaryReal = opts?.repoRoot ? realpathSync(opts.repoRoot) : rootReal;
29
+ }
30
+ catch {
31
+ return { safe: false, reason: "Directory could not be resolved." };
32
+ }
33
+ let entries = 0;
34
+ const stack = [{ dir: rootReal, depth: 0 }];
35
+ while (stack.length > 0) {
36
+ const current = stack.pop();
37
+ if (current.depth > maxDepth) {
38
+ return { safe: false, reason: "Directory nesting exceeds safety depth limit." };
39
+ }
40
+ let items;
41
+ try {
42
+ items = readdirSync(current.dir, { withFileTypes: true });
43
+ }
44
+ catch {
45
+ return { safe: false, reason: "Unreadable directory inside node_modules." };
46
+ }
47
+ for (const dirent of items) {
48
+ const name = dirent.name;
49
+ entries += 1;
50
+ if (entries > maxEntries) {
51
+ return { safe: false, reason: "Dependency tree exceeds symlink scan cap." };
52
+ }
53
+ const full = join(current.dir, name);
54
+ if (dirent.isSymbolicLink()) {
55
+ let linkTarget;
56
+ try {
57
+ linkTarget = readlinkSync(full);
58
+ }
59
+ catch {
60
+ return { safe: false, reason: "Unreadable symlink inside node_modules." };
61
+ }
62
+ if (isAbsolute(linkTarget)) {
63
+ return { safe: false, reason: `Absolute symlink (${name}) points outside node_modules.` };
64
+ }
65
+ const resolved = resolve(dirname(full), linkTarget);
66
+ const rel = relative(boundaryReal, resolved);
67
+ if (rel === ".." || rel.startsWith(`..${"/"}`) || rel.startsWith(`..${"\\"}`) || isAbsolute(rel)) {
68
+ return { safe: false, reason: `Relative symlink (${name}) escapes allowed workspace boundary.` };
69
+ }
70
+ }
71
+ else if (dirent.isDirectory()) {
72
+ stack.push({ dir: full, depth: current.depth + 1 });
73
+ }
74
+ }
75
+ }
76
+ return { safe: true, entries };
77
+ }
78
+ export function discoverNodeModulesDirs(repo) {
79
+ let raw = "";
80
+ try {
81
+ raw = runHardenedMainGit(["ls-files", "-o", "-i", "--exclude-standard", "--directory"], repo);
82
+ }
83
+ catch {
84
+ return [];
85
+ }
86
+ const found = [];
87
+ for (const line of raw.split("\n")) {
88
+ const trimmed = line.trim().replace(/\/+$/, "");
89
+ if (trimmed === "")
90
+ continue;
91
+ const parts = trimmed.split("/");
92
+ if (parts.at(-1) !== "node_modules")
93
+ continue;
94
+ if (parts.some(seg => seg === ".." || seg === "." || SKIPPED_DIR_SEGMENTS.has(seg)))
95
+ continue;
96
+ if (parts.slice(0, -1).includes("node_modules"))
97
+ continue;
98
+ found.push(trimmed);
99
+ }
100
+ return [...new Set(found)].sort();
101
+ }
102
+ export function cloneSafeNodeModules(input) {
103
+ const platform = input.platform ?? process.platform;
104
+ const result = { cloned: [], skipped: [] };
105
+ if (platform !== "darwin") {
106
+ return result;
107
+ }
108
+ const dirs = discoverNodeModulesDirs(input.repo);
109
+ if (dirs.length === 0)
110
+ return result;
111
+ let cloneDev;
112
+ try {
113
+ cloneDev = statSync(input.clonePath).dev;
114
+ }
115
+ catch {
116
+ return result;
117
+ }
118
+ const copyFn = input.copyCoW ?? ((src, dst) => {
119
+ execFileSync("/bin/cp", ["-cR", src, dst], {
120
+ timeout: 15_000,
121
+ stdio: ["ignore", "pipe", "pipe"],
122
+ });
123
+ });
124
+ for (const relPath of dirs) {
125
+ const src = join(input.repo, relPath);
126
+ const dst = join(input.clonePath, relPath);
127
+ if (!existsSync(src))
128
+ continue;
129
+ if (existsSync(dst)) {
130
+ result.skipped.push({ path: relPath, reason: "Already exists in clone." });
131
+ continue;
132
+ }
133
+ let srcStat;
134
+ try {
135
+ srcStat = lstatSync(src);
136
+ }
137
+ catch {
138
+ result.skipped.push({ path: relPath, reason: "Source could not be read." });
139
+ continue;
140
+ }
141
+ if (!srcStat.isDirectory() || srcStat.isSymbolicLink()) {
142
+ result.skipped.push({ path: relPath, reason: "Not a real directory." });
143
+ continue;
144
+ }
145
+ if (srcStat.dev !== cloneDev) {
146
+ result.skipped.push({ path: relPath, reason: "Different filesystem volume (APFS clonefile unavailable)." });
147
+ continue;
148
+ }
149
+ const safety = scanNodeModulesSafety(src, { repoRoot: input.repo });
150
+ if (!safety.safe) {
151
+ result.skipped.push({ path: relPath, reason: safety.reason });
152
+ continue;
153
+ }
154
+ try {
155
+ mkdirSync(dirname(dst), { recursive: true });
156
+ copyFn(src, dst);
157
+ result.cloned.push(relPath);
158
+ }
159
+ catch (error) {
160
+ try {
161
+ if (existsSync(dst))
162
+ rmSync(dst, { recursive: true, force: true });
163
+ }
164
+ catch {
165
+ }
166
+ result.skipped.push({
167
+ path: relPath,
168
+ reason: error instanceof Error ? error.message.slice(0, 140) : "Copy-on-write clone failed.",
169
+ });
170
+ }
171
+ }
172
+ return result;
173
+ }
174
+ async function scanNodeModulesSafetyAsync(nodeModulesDir, opts) {
175
+ const maxEntries = opts?.maxEntries ?? MAX_SYMLINK_SCAN_ENTRIES;
176
+ const maxDepth = opts?.maxDepth ?? MAX_SYMLINK_SCAN_DEPTH;
177
+ let rootReal;
178
+ let boundaryReal;
179
+ try {
180
+ rootReal = realpathSync(nodeModulesDir);
181
+ boundaryReal = opts?.repoRoot ? realpathSync(opts.repoRoot) : rootReal;
182
+ }
183
+ catch {
184
+ return { safe: false, reason: "Directory could not be resolved." };
185
+ }
186
+ let entries = 0;
187
+ const stack = [{ dir: rootReal, depth: 0 }];
188
+ while (stack.length > 0) {
189
+ const current = stack.pop();
190
+ if (current.depth > maxDepth) {
191
+ return { safe: false, reason: "Directory nesting exceeds safety depth limit." };
192
+ }
193
+ let items;
194
+ try {
195
+ items = readdirSync(current.dir, { withFileTypes: true });
196
+ }
197
+ catch {
198
+ return { safe: false, reason: "Unreadable directory inside node_modules." };
199
+ }
200
+ for (const dirent of items) {
201
+ const name = dirent.name;
202
+ entries += 1;
203
+ if (entries > maxEntries) {
204
+ return { safe: false, reason: "Dependency tree exceeds symlink scan cap." };
205
+ }
206
+ if (entries % 2_000 === 0) {
207
+ await new Promise(resolveYield => setImmediate(resolveYield));
208
+ }
209
+ const full = join(current.dir, name);
210
+ if (dirent.isSymbolicLink()) {
211
+ let linkTarget;
212
+ try {
213
+ linkTarget = readlinkSync(full);
214
+ }
215
+ catch {
216
+ return { safe: false, reason: "Unreadable symlink inside node_modules." };
217
+ }
218
+ if (isAbsolute(linkTarget)) {
219
+ return { safe: false, reason: `Absolute symlink (${name}) points outside node_modules.` };
220
+ }
221
+ const resolved = resolve(dirname(full), linkTarget);
222
+ const rel = relative(boundaryReal, resolved);
223
+ if (rel === ".." || rel.startsWith(`..${"/"}`) || rel.startsWith(`..${"\\"}`) || isAbsolute(rel)) {
224
+ return { safe: false, reason: `Relative symlink (${name}) escapes allowed workspace boundary.` };
225
+ }
226
+ }
227
+ else if (dirent.isDirectory()) {
228
+ stack.push({ dir: full, depth: current.depth + 1 });
229
+ }
230
+ }
231
+ }
232
+ return { safe: true, entries };
233
+ }
234
+ async function discoverNodeModulesDirsAsync(repo) {
235
+ let raw = "";
236
+ try {
237
+ raw = await runHardenedMainGitAsync(["ls-files", "-o", "-i", "--exclude-standard", "--directory"], repo);
238
+ }
239
+ catch {
240
+ return [];
241
+ }
242
+ const found = [];
243
+ for (const line of raw.split("\n")) {
244
+ const trimmed = line.trim().replace(/\/+$/, "");
245
+ if (trimmed === "")
246
+ continue;
247
+ const parts = trimmed.split("/");
248
+ if (parts.at(-1) !== "node_modules")
249
+ continue;
250
+ if (parts.some(seg => seg === ".." || seg === "." || SKIPPED_DIR_SEGMENTS.has(seg)))
251
+ continue;
252
+ if (parts.slice(0, -1).includes("node_modules"))
253
+ continue;
254
+ found.push(trimmed);
255
+ }
256
+ return [...new Set(found)].sort();
257
+ }
258
+ export async function cloneSafeNodeModulesAsync(input) {
259
+ const platform = input.platform ?? process.platform;
260
+ const result = { cloned: [], skipped: [] };
261
+ if (platform !== "darwin") {
262
+ return result;
263
+ }
264
+ const dirs = await discoverNodeModulesDirsAsync(input.repo);
265
+ if (dirs.length === 0)
266
+ return result;
267
+ let cloneDev;
268
+ try {
269
+ cloneDev = statSync(input.clonePath).dev;
270
+ }
271
+ catch {
272
+ return result;
273
+ }
274
+ const copyFn = input.copyCoW ?? (async (src, dst) => {
275
+ await execFileAsync("/bin/cp", ["-cR", src, dst], {
276
+ timeout: 15_000,
277
+ });
278
+ });
279
+ for (const relPath of dirs) {
280
+ const src = join(input.repo, relPath);
281
+ const dst = join(input.clonePath, relPath);
282
+ if (!existsSync(src))
283
+ continue;
284
+ if (existsSync(dst)) {
285
+ result.skipped.push({ path: relPath, reason: "Already exists in clone." });
286
+ continue;
287
+ }
288
+ let srcStat;
289
+ try {
290
+ srcStat = lstatSync(src);
291
+ }
292
+ catch {
293
+ result.skipped.push({ path: relPath, reason: "Source could not be read." });
294
+ continue;
295
+ }
296
+ if (!srcStat.isDirectory() || srcStat.isSymbolicLink()) {
297
+ result.skipped.push({ path: relPath, reason: "Not a real directory." });
298
+ continue;
299
+ }
300
+ if (srcStat.dev !== cloneDev) {
301
+ result.skipped.push({ path: relPath, reason: "Different filesystem volume (APFS clonefile unavailable)." });
302
+ continue;
303
+ }
304
+ const safety = await scanNodeModulesSafetyAsync(src, { repoRoot: input.repo });
305
+ if (!safety.safe) {
306
+ result.skipped.push({ path: relPath, reason: safety.reason });
307
+ continue;
308
+ }
309
+ try {
310
+ mkdirSync(dirname(dst), { recursive: true });
311
+ await copyFn(src, dst);
312
+ result.cloned.push(relPath);
313
+ }
314
+ catch (error) {
315
+ try {
316
+ if (existsSync(dst))
317
+ rmSync(dst, { recursive: true, force: true });
318
+ }
319
+ catch {
320
+ }
321
+ result.skipped.push({
322
+ path: relPath,
323
+ reason: error instanceof Error ? error.message.slice(0, 140) : "Copy-on-write clone failed.",
324
+ });
325
+ }
326
+ }
327
+ return result;
328
+ }
329
+ export function applyMainDirtyPatch(input) {
330
+ if (!existsSync(input.repo)) {
331
+ return { ok: false, status: 404, error: "Project directory is missing." };
332
+ }
333
+ const verified = assertTrustedCloneGit(input.binding);
334
+ if (!verified.ok) {
335
+ return { ok: false, status: 409, error: verified.error };
336
+ }
337
+ let patch = "";
338
+ let changedTracked = [];
339
+ let untrackedFiles = [];
340
+ try {
341
+ patch = runHardenedMainGit(["diff", "--binary", "--no-ext-diff", "--no-textconv", "HEAD"], input.repo);
342
+ changedTracked = runHardenedMainGit(["diff", "--name-only", "--no-ext-diff", "--no-textconv", "HEAD"], input.repo)
343
+ .split("\n")
344
+ .map(s => s.trim())
345
+ .filter(Boolean);
346
+ untrackedFiles = runHardenedMainGit(["ls-files", "--others", "--exclude-standard"], input.repo)
347
+ .split("\n")
348
+ .map(s => s.trim())
349
+ .filter(Boolean)
350
+ .slice(0, 50);
351
+ }
352
+ catch (error) {
353
+ return {
354
+ ok: false,
355
+ status: 500,
356
+ error: `Could not read uncommitted changes from ${basename(input.repo)}: ${error instanceof Error ? error.message : String(error)}`,
357
+ };
358
+ }
359
+ if (patch.trim() === "") {
360
+ if (untrackedFiles.length > 0) {
361
+ return {
362
+ ok: true,
363
+ appliedFiles: [],
364
+ untrackedFiles,
365
+ said: `No tracked edits to apply (${untrackedFiles.length} untracked file${untrackedFiles.length === 1 ? "" : "s"} left in main checkout).`,
366
+ };
367
+ }
368
+ return { ok: true, appliedFiles: [], untrackedFiles: [], said: "Main checkout has no uncommitted edits." };
369
+ }
370
+ try {
371
+ runTrustedCloneGit(input.binding, ["apply", "--3way", "--whitespace=nowarn"], patch);
372
+ }
373
+ catch (error) {
374
+ return {
375
+ ok: false,
376
+ status: 409,
377
+ error: `Could not cleanly apply main checkout edits into this chat's clone: ${error instanceof Error ? error.message.slice(0, 240) : String(error)}`,
378
+ };
379
+ }
380
+ const suffix = untrackedFiles.length > 0
381
+ ? ` (${untrackedFiles.length} untracked file${untrackedFiles.length === 1 ? "" : "s"} stay in main checkout)`
382
+ : "";
383
+ return {
384
+ ok: true,
385
+ appliedFiles: changedTracked,
386
+ untrackedFiles,
387
+ said: `Brought in ${changedTracked.length} modified file${changedTracked.length === 1 ? "" : "s"} from main checkout${suffix}.`,
388
+ };
389
+ }