toolroll 0.9.107 → 0.9.109

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 (105) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +4 -3
  3. package/dist/advanced-view.js +0 -1
  4. package/dist/agent-fence.js +35 -4
  5. package/dist/agent-state.js +5 -2
  6. package/dist/assignment-ui.js +5 -5
  7. package/dist/assignment.js +5 -2
  8. package/dist/browser/terminal.js +1 -1
  9. package/dist/browser/workspace.css +1 -1
  10. package/dist/browser/workspace.js +38 -33
  11. package/dist/browser-crew.js +4 -4
  12. package/dist/browser-shell.js +1 -1
  13. package/dist/browser-workspace.js +4 -11
  14. package/dist/builder.js +9 -1
  15. package/dist/chat-controls.js +6 -5
  16. package/dist/chat-decide.js +1 -1
  17. package/dist/chat-quiet.js +3 -3
  18. package/dist/chat-voice.js +2 -2
  19. package/dist/cli-help.js +17 -13
  20. package/dist/cli.js +4 -3
  21. package/dist/console-chrome.js +10 -3
  22. package/dist/contracts/cli.js +2 -0
  23. package/dist/contracts/console-api.js +5 -4
  24. package/dist/contracts/handoff.js +4 -0
  25. package/dist/decision.js +17 -0
  26. package/dist/demo-chat.js +1 -1
  27. package/dist/demo.js +6 -0
  28. package/dist/design/kit.js +4 -3
  29. package/dist/dispatch.js +3 -8
  30. package/dist/flexible-available.js +1 -0
  31. package/dist/flexible-schema.js +32 -0
  32. package/dist/flexible-thread-schema.js +30 -0
  33. package/dist/flexible-thread.js +526 -0
  34. package/dist/flexible-ui.js +44 -0
  35. package/dist/flexible.js +359 -0
  36. package/dist/folder-look.js +65 -4
  37. package/dist/git-views.js +38 -38
  38. package/dist/guides.js +14 -11
  39. package/dist/keymap.js +1 -1
  40. package/dist/lead-cli.js +2 -1
  41. package/dist/lead-context.js +1 -1
  42. package/dist/limits-ui.js +1 -1
  43. package/dist/live-bus.js +82 -12
  44. package/dist/login-secrets.js +43 -0
  45. package/dist/needs-you.js +3 -3
  46. package/dist/nightly-github.js +2 -2
  47. package/dist/operate.js +278 -21
  48. package/dist/project-admission.js +60 -29
  49. package/dist/project-delete-ui.js +2 -1
  50. package/dist/project-delete.js +1 -0
  51. package/dist/project.js +73 -0
  52. package/dist/provider-auth.js +1 -1
  53. package/dist/release.js +1 -0
  54. package/dist/repos.js +37 -0
  55. package/dist/result-actions.js +3 -0
  56. package/dist/result-evidence-readers.js +8 -2
  57. package/dist/result-review.js +20 -9
  58. package/dist/route-hooks.js +1 -0
  59. package/dist/sample-project.js +167 -9
  60. package/dist/scope.js +17 -2
  61. package/dist/serve.js +47 -32
  62. package/dist/server/chat.js +9 -9
  63. package/dist/server/chrome.js +16 -16
  64. package/dist/server/guards.js +10 -4
  65. package/dist/server/home.js +37 -5
  66. package/dist/server/http.js +4 -2
  67. package/dist/server/in-place.js +5 -4
  68. package/dist/server/kit.js +2 -2
  69. package/dist/server/live.js +103 -10
  70. package/dist/server/login-help.js +67 -0
  71. package/dist/server/pages.js +258 -78
  72. package/dist/server/people-tokens.js +36 -24
  73. package/dist/server/render-chat.js +1 -1
  74. package/dist/server/render-history.js +18 -4
  75. package/dist/server/render-new-task.js +2 -2
  76. package/dist/server/render-pages.js +21 -39
  77. package/dist/server/render-people.js +16 -4
  78. package/dist/server/render-projects.js +63 -15
  79. package/dist/server/render-results.js +26 -10
  80. package/dist/server/render-tasks.js +26 -17
  81. package/dist/server/retired-routes.js +37 -4
  82. package/dist/server/route-policy.js +8 -0
  83. package/dist/server/route-table.js +15 -5
  84. package/dist/server/settings-computers.js +140 -0
  85. package/dist/server/settings-scripts.js +15 -0
  86. package/dist/server/settings-section-table.js +56 -0
  87. package/dist/server/settings-sections.js +258 -0
  88. package/dist/server/settings.js +167 -19
  89. package/dist/server/task-views.js +47 -13
  90. package/dist/server/tasks.js +143 -90
  91. package/dist/server/welcome.js +35 -23
  92. package/dist/settings-groups-ui.js +34 -106
  93. package/dist/settings-proofs.js +5 -2
  94. package/dist/sqlite-telemetry.js +70 -21
  95. package/dist/store.js +141 -9
  96. package/dist/surface.js +4 -1
  97. package/dist/task-link.js +64 -0
  98. package/dist/task-outcome-cli.js +99 -4
  99. package/dist/tui-source.js +11 -3
  100. package/dist/tui.js +39 -39
  101. package/dist/typed-words-schema.js +18 -0
  102. package/dist/welcome-facts.js +15 -7
  103. package/dist/work-index.js +126 -29
  104. package/dist/work-reads.js +279 -0
  105. package/package.json +4 -2
@@ -30,6 +30,7 @@ const SETTINGS = [
30
30
  ["learning_policy", "repo"], ["operating_mode", "repo"], ["project_knowledge", "repo"], ["live_detail_setting", "repo"],
31
31
  ["project_decision", "repo"], ["flow_script", "repo"], ["workflow_recipe", "repo"], ["team_lead_project", "project"],
32
32
  ["fallback_setting", "repo"],
33
+ ["flexible_terms", "repo"],
33
34
  ];
34
35
  export const MODEL_SETTINGS = Object.freeze([["phase_config", "scope"], ["phase_tier_config", "scope"], ["phase_tier_alternate", "scope"]]);
35
36
  export const PROJECT_SETTINGS = Object.freeze(SETTINGS.map(one => [...one]));
package/dist/project.js CHANGED
@@ -88,3 +88,76 @@ export function rowVisible(ceiling, repo) {
88
88
  export function projectName(path) {
89
89
  return basename(path);
90
90
  }
91
+ export function expandHomePath(path, home) {
92
+ if (path === "~")
93
+ return home;
94
+ if (path.startsWith("~/"))
95
+ return resolve(home, path.slice(2));
96
+ if (path.startsWith("~"))
97
+ return null;
98
+ return path;
99
+ }
100
+ export const SYSTEM_TREES = ["/System", "/Library", "/usr", "/bin", "/sbin", "/etc", "/dev", "/private", "/var", "/proc", "/sys", "/boot", "/run", "/lib", "/lib64", "/cores", "/Network"];
101
+ export const SYSTEM_TOPS = ["/Applications", "/Volumes", "/Users", "/home", "/opt", "/mnt", "/media", "/srv", "/tmp", "/root", "/snap"];
102
+ export function comparisonPaths(home, protectedDirs) {
103
+ return ["/", home, resolve(home, "Library"), ...protectedDirs, ...SYSTEM_TOPS, ...SYSTEM_TREES];
104
+ }
105
+ export function comparisonsOf(found, protectedCount) {
106
+ const after = 3 + protectedCount;
107
+ const unread = { kind: "unreadable" };
108
+ return {
109
+ root: found[0] ?? unread, home: found[1] ?? unread, library: found[2] ?? unread,
110
+ protectedDirs: found.slice(3, after), tops: found.slice(after, after + SYSTEM_TOPS.length), trees: found.slice(after + SYSTEM_TOPS.length),
111
+ };
112
+ }
113
+ export function folderRefusal(kind, target, facts) {
114
+ const id = (one) => one.chain[0];
115
+ const lower = (path) => path.toLowerCase();
116
+ const underPath = (path, outer) => lower(path) === lower(outer) || lower(path).startsWith(outer === "/" ? "/" : `${lower(outer)}/`);
117
+ const within = (one, outer) => outer.kind === "found" ? one.chain.includes(id(outer)) : outer.kind === "missing" ? underPath(one.real, outer.path) : null;
118
+ const holds = (one, inner) => inner.kind === "found" ? inner.chain.includes(id(one)) : inner.kind === "missing" ? underPath(inner.path, one.real) : null;
119
+ const same = (one, other) => other.kind === "found" ? id(other) === id(one) : other.kind === "missing" ? lower(other.path) === lower(one.real) : null;
120
+ const cant = (why) => kind === "folder" ? `${why} can’t be the projects folder` : `${why} can’t be added`;
121
+ const unchecked = cant("a folder Toolroll couldn’t check against its own and the system’s folders");
122
+ const { root, home, library } = facts;
123
+ if (root.kind !== "found" || home.kind !== "found")
124
+ return unchecked;
125
+ if (id(target) === id(root))
126
+ return cant("the top of the disk");
127
+ if (id(target) === id(home))
128
+ return kind === "folder" ? "your home folder itself can’t be the projects folder. Choose a folder inside it, like ~/Developer" : "your home folder itself can’t be added";
129
+ if (holds(target, home))
130
+ return `that folder holds your home folder, so it can’t be ${kind === "folder" ? "the projects folder" : "added"}`;
131
+ for (const dir of facts.protectedDirs) {
132
+ const inDir = within(target, dir);
133
+ const holdsDir = dir.kind === "found" && id(dir) === id(home) ? false : holds(target, dir);
134
+ if (inDir === null || holdsDir === null)
135
+ return unchecked;
136
+ if ((dir.kind === "found" && id(dir) === id(home) ? false : inDir) || holdsDir)
137
+ return cant("a folder holding Toolroll’s own settings, records or task checkouts");
138
+ }
139
+ const inLibrary = within(target, library);
140
+ if (inLibrary === null)
141
+ return unchecked;
142
+ if (inLibrary)
143
+ return cant("a folder in ~/Library");
144
+ if (target.real.split("/").some(name => name.startsWith(".")))
145
+ return cant("a hidden folder");
146
+ if (within(target, home))
147
+ return null;
148
+ for (const top of facts.tops) {
149
+ const is = same(target, top);
150
+ if (is === null)
151
+ return unchecked;
152
+ if (is)
153
+ return cant("a system folder");
154
+ }
155
+ for (const tree of facts.trees) {
156
+ const under = within(target, tree);
157
+ if (under === null)
158
+ return unchecked;
159
+ if (under)
160
+ return cant("a system folder");
161
+ }
162
+ return null;
163
+ }
@@ -105,7 +105,7 @@ function notifyOperators(store, key, message, now) {
105
105
  dedupeKey: `${SIGN_IN_KEY_PREFIX}${key}:${recipient}`,
106
106
  kind: message.kind,
107
107
  pushClass: "attention",
108
- link: "/tasks",
108
+ link: "/",
109
109
  subject: message.subject,
110
110
  body: message.body,
111
111
  recipient,
package/dist/release.js CHANGED
@@ -36,6 +36,7 @@ export const ADVISORY_PR_CHECKS = {
36
36
  "upgrade path": ".github/workflows/upgrade-path.yml",
37
37
  "install smoke · ubuntu-24.04": ".github/workflows/install-smoke.yml",
38
38
  "install smoke · macos-latest": ".github/workflows/install-smoke.yml",
39
+ "wire budgets": ".github/workflows/wire-budgets.yml",
39
40
  };
40
41
  export const RELEASE_TAG_CHECKS = ["release proof", "publish"];
41
42
  export const RELEASE_TAG_WORKFLOW = ".github/workflows/publish.yml";
package/dist/repos.js CHANGED
@@ -271,3 +271,40 @@ function bumpRegistryRemovals(file, lines, tag) {
271
271
  writeFileSync(temp, `${JSON.stringify(counts)}\n`, { flag: "wx", mode: 0o600 });
272
272
  renameFile(temp, registryRemovalsFile(file));
273
273
  }
274
+ export function readProjectRegistryNow(file) {
275
+ let text;
276
+ try {
277
+ const fd = openFd(file, fsConstants.O_RDONLY);
278
+ try {
279
+ const size = fstatSync(fd).size;
280
+ if (size > 4 * 1024 * 1024)
281
+ return { error: `${file} is too large to be a Toolroll config` };
282
+ const buffer = Buffer.alloc(size);
283
+ let read = 0;
284
+ while (read < size) {
285
+ const got = readSync(fd, buffer, read, size - read, read);
286
+ if (got === 0)
287
+ break;
288
+ read += got;
289
+ }
290
+ text = buffer.subarray(0, read).toString("utf8");
291
+ }
292
+ finally {
293
+ closeFd(fd);
294
+ }
295
+ }
296
+ catch (cause) {
297
+ if (cause.code === "ENOENT")
298
+ return { repos: [], roots: [] };
299
+ return { error: `${file} could not be read (${String(cause.message)})` };
300
+ }
301
+ let parsed;
302
+ try {
303
+ parsed = JSON.parse(text);
304
+ }
305
+ catch {
306
+ return { error: `${file} is not valid JSON` };
307
+ }
308
+ const registry = readProjectRegistryStrict(parsed);
309
+ return registry === null ? { error: `${file} does not look like a Toolroll config` } : { repos: sortUnique(registry.repos), roots: sortUnique(registry.roots) };
310
+ }
@@ -1,5 +1,6 @@
1
1
  import { verifyResultImage } from "./chat-evidence.js";
2
2
  import { createHash, randomBytes } from "node:crypto";
3
+ import { markTypedByPerson } from "./store.js";
3
4
  import { EVIDENCE_CAPS, readVerifiedArtifact, writeEvidenceFile } from "./evidence.js";
4
5
  import { parseFeedbackImage, sameFeedbackImage, isRevisionFeedback, parseRevisionBatch, revisionSourceOf, commentSourceKey, REQUEST_TOKEN } from "./result-review.js";
5
6
  import { validateNote, hasForbiddenControls } from "./decision.js";
@@ -68,6 +69,8 @@ export function requestResultChanges(store, evidenceRoot, input, now) {
68
69
  const noteId = earlier?.id ?? store.addDiffComment({ artifactId: artifact.id, runId: run.id, path, line, note: valid.note, author: input.actor, sourceKey, image: input.image ?? null }, now);
69
70
  if (noteId === null)
70
71
  return fail(409, "This feedback changed while saving. Your draft is unchanged; reopen the result.");
72
+ if (earlier === null)
73
+ markTypedByPerson(store, { comment: noteId }, input.actor, input.typedWords, now);
71
74
  const result = createResultRevision(store, evidenceRoot, { ...input, batch: [...new Set([...batch, noteId])].sort((a, b) => a - b).join(",") }, now);
72
75
  if (!result.ok)
73
76
  return fail(result.status, result.message);
@@ -1,5 +1,5 @@
1
1
  import { readVerifiedArtifact } from "./evidence.js";
2
- import { hasForbiddenControls } from "./decision.js";
2
+ import { HANDOFF_REPORT_CAP, hasDisguisedText, hasForbiddenControls } from "./decision.js";
3
3
  import { parseHandoffArtifact } from "./contracts/handoff.js";
4
4
  const CAPTURE_EXIT = /\(exit ([0-9]{1,4})\)\s*$/;
5
5
  export const SCREENSHOT_CAPTURE = /^agent-claimed screenshot at (.+) \(validated (?:png|jpeg)\)/;
@@ -25,7 +25,13 @@ export function structuredHandoffView(artifacts, root, displayText = text => tex
25
25
  .filter(one => one.trim() !== "" && !hasForbiddenControls(one))
26
26
  .slice(0, 8)
27
27
  .map(one => oneLineOf(one, 240));
28
- return { conclusion, changes: list(handoff.changes), verification: list(handoff.verification), followUps: list(handoff.followUps) };
28
+ const reported = (items) => (items ?? [])
29
+ .filter(one => one.trim() !== "" && !hasDisguisedText(one))
30
+ .slice(0, HANDOFF_REPORT_CAP)
31
+ .map(one => oneLineOf(displayText(one), 240))
32
+ .filter(one => one !== "" && !hasDisguisedText(one));
33
+ return { conclusion, changes: list(handoff.changes), verification: list(handoff.verification), followUps: list(handoff.followUps),
34
+ report: { decisions: reported(handoff.decisions), assumptions: reported(handoff.assumptions), notDone: reported(handoff.notDone), risks: reported(handoff.risks) } };
29
35
  }
30
36
  export function terminalDiffView(artifacts, root) {
31
37
  const patchArtifact = artifacts.find(one => one.kind === "terminal-diff");
@@ -145,8 +145,8 @@ export function resultReturnTarget(raw, runId, tasks = []) {
145
145
  return raw;
146
146
  if (tasks.some(task => raw === `/t/${encodeURIComponent(task)}`))
147
147
  return raw;
148
- const tab = /^\/t\/([A-Za-z0-9._~%-]{1,200})\?(?:version=[A-Za-z0-9._~%-]{1,200}&)?tab=result&run=([0-9]{1,15})(?:&section=(?:summary|changes|checks))?$/.exec(raw);
149
- if (tab !== null && Number(tab[2]) === runId && tasks.some(task => tab[1] === encodeURIComponent(task)))
148
+ const tab = /^\/t\/([A-Za-z0-9._~%-]{1,200})\?(?:version=[A-Za-z0-9._~%-]{1,200}&)?tab=result(?:&run=([0-9]{1,15}))?(?:&section=(?:summary|changes|checks))?$/.exec(raw);
149
+ if (tab !== null && (tab[2] === undefined || Number(tab[2]) === runId) && tasks.some(task => tab[1] === encodeURIComponent(task)))
150
150
  return raw;
151
151
  }
152
152
  return `/r/${runId}`;
@@ -236,6 +236,15 @@ export const RESULT_REVIEW_SCRIPT = String.raw `
236
236
  if(form){
237
237
  var noteBox=form.querySelector('[name=note]'),pathBox=form.querySelector('[name=path]'),lineBox=form.querySelector('[name=line]'),pin=form.querySelector('details.result-pin');
238
238
  var imageBox=form.querySelector('[name=image]'),imagePreview=form.querySelector('[data-feedback-image]');
239
+ // What the page fills in for the person (a reviewer's note to act on, a requirement marked Not right) is its own
240
+ // field, shown as sent with the note and never written into the person's own box: only what they type is theirs.
241
+ var contextBox=form.querySelector('[name=context]'),contextLine=form.querySelector('[data-request-context-line]');
242
+ // One item per line; each is shown, as text, in a list under "Sent with it".
243
+ function setContext(text){if(!contextBox)return;contextBox.value=text;if(contextLine){contextLine.textContent='';var items=text.split('\n').filter(function(one){return one.trim()!=='';});
244
+ if(items.length>0){contextLine.appendChild(document.createTextNode('Sent with it:'));var list=document.createElement('ul');items.forEach(function(one){var li=document.createElement('li');li.textContent=one;list.appendChild(li);});contextLine.appendChild(list);}
245
+ contextLine.hidden=items.length===0;}}
246
+ // A further item joins what is already there (the same one again changes nothing): earlier feedback is never lost.
247
+ function addContext(item){if(!contextBox||!item.trim())return;var items=contextBox.value.split('\n').filter(function(one){return one.trim()!=='';});if(items.indexOf(item)<0)items.push(item);setContext(items.join('\n'));}
239
248
  function showImage(){
240
249
  if(!imageBox||!imagePreview)return;
241
250
  imagePreview.hidden=!imageBox.value;
@@ -253,7 +262,7 @@ export const RESULT_REVIEW_SCRIPT = String.raw `
253
262
  });
254
263
  var limit=document.getElementById('comment-note-limit'),requestBox=form.querySelector('[name=request]');
255
264
  function updateActions(){
256
- var typed=!!(noteBox&&noteBox.value.trim()),batch=form.querySelector('[name=batch]');
265
+ var typed=!!(noteBox&&noteBox.value.trim())||!!(contextBox&&contextBox.value.trim()),batch=form.querySelector('[name=batch]');
257
266
  var requestAction=form.querySelector('[data-request-changes]'),saveAction=form.querySelector('[data-save-feedback]');
258
267
  if(requestAction)requestAction.disabled=!typed&&!(batch&&batch.value);
259
268
  if(saveAction)saveAction.disabled=!typed;
@@ -266,8 +275,7 @@ export const RESULT_REVIEW_SCRIPT = String.raw `
266
275
  document.addEventListener('click',function(ev){
267
276
  var button=ev.target&&ev.target.closest?ev.target.closest('button.pick-file,button.pick-line'):null;if(!button)return;
268
277
  var reviewNote=button.getAttribute('data-review-note');
269
- if(reviewNote!==null&&noteBox&&noteBox.value&&!window.confirm('Replace the feedback draft with this note?'))return;
270
- if(reviewNote!==null&&noteBox)noteBox.value=reviewNote;
278
+ if(reviewNote!==null){var at=button.getAttribute('data-path');addContext(reviewNote.replace(/\s+/g,' ')+(at?' ('+at+(button.getAttribute('data-line')?':'+button.getAttribute('data-line'):'')+')':''));}
271
279
  if(pathBox)pathBox.value=button.getAttribute('data-path')||'';
272
280
  if(lineBox)lineBox.value=button.getAttribute('data-line')||'';
273
281
  if(pin)pin.open=true;
@@ -285,7 +293,8 @@ export const RESULT_REVIEW_SCRIPT = String.raw `
285
293
  // A fresh request identity: 16 random bytes as hex, the server's own shape.
286
294
  function mint(){var bytes=new Uint8Array(16);try{crypto.getRandomValues(bytes);}catch(e){for(var i=0;i<16;i++)bytes[i]=Math.floor(Math.random()*256);}
287
295
  var hex='';for(var j=0;j<16;j++)hex+=(bytes[j]<16?'0':'')+bytes[j].toString(16);return hex;}
288
- function payload(){return JSON.stringify([noteBox?noteBox.value:'',pathBox?pathBox.value:'',lineBox?lineBox.value:'',imageBox?imageBox.value:'']);}
296
+ // The filled-in field joins the identity only when it holds something, so a draft sent before it existed keeps its own.
297
+ function payload(){var parts=[noteBox?noteBox.value:'',pathBox?pathBox.value:'',lineBox?lineBox.value:'',imageBox?imageBox.value:''];if(contextBox&&contextBox.value)parts.push(contextBox.value);return JSON.stringify(parts);}
289
298
  // What the current token was last submitted with; null = never sent.
290
299
  var sent=null,bound=null;
291
300
  // The server refused this token for a different note or another result:
@@ -308,8 +317,9 @@ export const RESULT_REVIEW_SCRIPT = String.raw `
308
317
  if(typeof saved.request==='string'&&/^[a-f0-9]{32}$/.test(saved.request)&&requestBox)requestBox.value=saved.request;
309
318
  if(typeof saved.sent==='string')sent=saved.sent;
310
319
  if(imageBox&&typeof saved.image==='string'&&saved.image.length<250)imageBox.value=saved.image;
320
+ if(contextBox&&!contextBox.value&&typeof saved.context==='string'&&saved.context.length<=4000)setContext(saved.context);
311
321
  showImage();
312
- bound=JSON.stringify([saved.note,saved.path||'',saved.line||'',saved.image||'']);
322
+ bound=JSON.stringify([saved.note,saved.path||'',saved.line||'',saved.image||''].concat(saved.context?[saved.context]:[]));
313
323
  if(noteBox)noteBox.dispatchEvent(new Event('input'));
314
324
  }
315
325
  function save(){
@@ -319,8 +329,9 @@ export const RESULT_REVIEW_SCRIPT = String.raw `
319
329
  var current=payload();
320
330
  if((bound!==null&&current!==bound)||(sent!==null&&current!==sent)){sent=null;if(requestBox)requestBox.value=mint();}
321
331
  bound=current;
322
- if(!note&&!path&&!line&&!(imageBox&&imageBox.value)){write(draftKey,null);return;}
323
- write(draftKey,{note:note,path:path,line:line,image:imageBox?imageBox.value:'',request:requestBox?requestBox.value:'',sent:sent,at:Date.now()});
332
+ var context=contextBox?contextBox.value:'';
333
+ if(!note&&!path&&!line&&!context&&!(imageBox&&imageBox.value)){write(draftKey,null);return;}
334
+ write(draftKey,{note:note,path:path,line:line,image:imageBox?imageBox.value:'',context:context,request:requestBox?requestBox.value:'',sent:sent,at:Date.now()});
324
335
  if(!storage&&limit)limit.textContent='Draft stays on this page only. Browser storage is unavailable.';
325
336
  }
326
337
  form.addEventListener('input',save);
@@ -11,6 +11,7 @@ const REVISION_CALLERS = [
11
11
  { file: "src/chat-review.ts", inside: "applyChatReview", calls: "createResultRevision", from: "./result-actions.js", args: true, why: "a confirmed review card passes the origin it was given" },
12
12
  { file: "src/lead-doors.ts", inside: "executeProposal", calls: "applyChatReview", from: "./chat-review.js", args: true, why: "a review card a person confirms is the person's; under a lead chain or remote run, the lead's" },
13
13
  { file: "src/task-outcome-cli.ts", inside: "runTaskOutcomeCommand", calls: "requestResultChanges", from: "./result-actions.js", args: true, why: "the command line tells a person from a lead or a machine" },
14
+ { file: "src/task-outcome-cli.ts", inside: "reviseAsLocalOwner", calls: "requestResultChanges", from: "./result-actions.js", args: true, why: "the terminal's local owner is the person at this computer, in their own words" },
14
15
  { file: "src/server/tasks.ts", inside: "createTasksHandlers", calls: "requestResultChanges", from: "../result-actions.js", args: true, why: "a browser session is a person; a bearer credential a machine" },
15
16
  { file: "src/server/tasks.ts", inside: "createTasksHandlers", calls: "createResultRevision", from: "../result-actions.js", args: true, why: "a browser session is a person; a bearer credential a machine" },
16
17
  ];
@@ -1,7 +1,10 @@
1
- import { lstatSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
- import { isAbsolute, join } from "node:path";
1
+ import { randomBytes } from "node:crypto";
2
+ import { lstatSync, mkdirSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { dirname, isAbsolute, join } from "node:path";
3
4
  import { run } from "./exec.js";
4
5
  import { SAMPLE_PROJECT_NAME } from "./first-run.js";
6
+ import { admitProject } from "./project-admission.js";
7
+ import { authorizedProject, canonicalProject, rowVisible, unscoped } from "./project.js";
5
8
  import { ENV, ENV_ALLOWLIST } from "./remote-main.js";
6
9
  import { TEARDOWN_FLAGS } from "./teardown-git.js";
7
10
  const MARKER = "toolroll-sample";
@@ -60,26 +63,49 @@ function isOurs(target) {
60
63
  return false;
61
64
  }
62
65
  }
63
- export async function createSampleProject(root, git = run) {
66
+ function removeMade(target, made) {
67
+ try {
68
+ const seen = lstatSync(target);
69
+ if (!seen.isDirectory() || seen.isSymbolicLink() || seen.dev !== made.dev || seen.ino !== made.ino)
70
+ return false;
71
+ const marker = join(target, ".git", MARKER);
72
+ if (kindOf(marker) !== "missing" && !isOurs(target))
73
+ return false;
74
+ rmSync(target, { recursive: true, force: true });
75
+ return kindOf(target) === "missing";
76
+ }
77
+ catch {
78
+ return false;
79
+ }
80
+ }
81
+ export async function createSampleProject(root, git = run, guard = () => true) {
82
+ const made = await claimSample(root, git, guard);
83
+ return made.ok ? { ok: true, path: made.path, created: made.created } : made;
84
+ }
85
+ async function claimSample(root, git, guard) {
64
86
  if (root === null || root === "" || !isAbsolute(root) || kindOf(root) !== "dir") {
65
87
  return { ok: false, reason: "no-root", message: "There's no project folder to put the sample in." };
66
88
  }
67
89
  const target = join(root, SAMPLE_PROJECT_NAME);
68
90
  if (isOurs(target))
69
- return { ok: true, path: target, created: false };
91
+ return { ok: true, path: target, created: false, identity: null };
92
+ const refused = { ok: false, reason: "refused", message: "Your access changed while the sample was being made. Nothing was added." };
93
+ if (!guard())
94
+ return refused;
95
+ let identity;
70
96
  try {
71
97
  mkdirSync(target);
98
+ const seen = lstatSync(target);
99
+ identity = { dev: seen.dev, ino: seen.ino };
72
100
  }
73
101
  catch {
74
102
  return { ok: false, reason: "exists", message: `A folder named ${SAMPLE_PROJECT_NAME} is already there, so nothing was changed.` };
75
103
  }
76
104
  const fail = () => {
77
- try {
78
- rmSync(target, { recursive: true, force: true });
79
- }
80
- catch { }
105
+ removeMade(target, identity);
81
106
  return { ok: false, reason: "failed", message: "The sample project couldn't be made. Nothing was added." };
82
107
  };
108
+ const stop = () => { removeMade(target, identity); return refused; };
83
109
  try {
84
110
  for (const [file, body] of Object.entries(FILES)) {
85
111
  const path = join(target, file);
@@ -88,7 +114,11 @@ export async function createSampleProject(root, git = run) {
88
114
  }
89
115
  const options = { cwd: target, env: ENV, envAllowlist: ENV_ALLOWLIST, timeoutMs: 30_000 };
90
116
  for (const args of [["init", "-q", "--template=", "-b", "main"], ["add", "--", "."], ["commit", "-q", "--no-verify", "-m", "Sample project"]]) {
117
+ if (!guard())
118
+ return stop();
91
119
  const ran = await git("git", [...SAMPLE_FLAGS, ...args], options);
120
+ if (!guard())
121
+ return stop();
92
122
  if (ran.code !== 0)
93
123
  return fail();
94
124
  }
@@ -97,7 +127,7 @@ export async function createSampleProject(root, git = run) {
97
127
  catch {
98
128
  return fail();
99
129
  }
100
- return { ok: true, path: target, created: true };
130
+ return { ok: true, path: target, created: true, identity };
101
131
  }
102
132
  export const SAMPLE_CHECK_COMMAND = "node --test";
103
133
  const SAMPLE_CHECK_TIMEOUT_MS = 60_000;
@@ -114,3 +144,131 @@ export function registerSampleCheck(store, made, repo, addedBy, now) {
114
144
  return true;
115
145
  });
116
146
  }
147
+ export function sampleRootOf(ceiling) {
148
+ if (unscoped(ceiling))
149
+ return null;
150
+ const root = ceiling.roots[0];
151
+ return root === undefined || root === "" || !isAbsolute(root) ? null : root.replace(/\/+$/, "") || null;
152
+ }
153
+ export async function addSampleProject(input) {
154
+ const { authority } = input;
155
+ if (!authority.stands())
156
+ return { ok: false, reason: "refused" };
157
+ const root = sampleRootOf(input.ceiling());
158
+ if (root === null)
159
+ return { ok: false, reason: "no-root" };
160
+ const expected = join(root, SAMPLE_PROJECT_NAME);
161
+ const rootServed = (ceiling) => !unscoped(ceiling) && ceiling.roots.some(one => one.replace(/\/+$/, "") === root);
162
+ const standing = () => !authority.stands() ? "refused" : !rootServed(input.ceiling()) ? "not-added" : null;
163
+ const lock = sampleLock(input.registryFile === null ? join(root, ".toolroll-sample.lock") : `${input.registryFile}.sample.lock`);
164
+ if (!(await lock.take()))
165
+ return { ok: false, reason: "not-added" };
166
+ try {
167
+ return await addHolding(input, root, expected, rootServed, standing);
168
+ }
169
+ finally {
170
+ lock.release();
171
+ }
172
+ }
173
+ async function addHolding(input, root, expected, rootServed, standing) {
174
+ const { store, authority } = input;
175
+ const made = await claimSample(root, input.git ?? run, () => standing() === null);
176
+ if (!made.ok)
177
+ return { ok: false, reason: made.reason === "refused" ? standing() ?? "refused" : made.reason };
178
+ const undo = (reason) => {
179
+ if (made.identity !== null && !store.listProjects().some(one => one.path === made.path))
180
+ removeMade(made.path, made.identity);
181
+ return { ok: false, reason };
182
+ };
183
+ const after = standing();
184
+ if (after !== null)
185
+ return undo(after);
186
+ const decidedOn = input.generation?.() ?? null;
187
+ const canonical = await (input.resolveFolder ?? (async (path) => canonicalProject(path)))(made.path);
188
+ const later = standing();
189
+ if (later !== null)
190
+ return undo(later);
191
+ const visible = (repo) => input.visible === undefined || input.visible(repo);
192
+ const servedBy = (ceiling, repo) => repo === expected && rootServed(ceiling) && rowVisible(ceiling, repo);
193
+ if (canonical === null || canonical === "no-answer" || canonical !== expected || !servedBy(input.ceiling(), canonical)
194
+ || !(await authorizedProject(input.ceiling(), canonical)) || !visible(canonical))
195
+ return undo("not-added");
196
+ const stillAllowed = (repo) => repo === canonical && authority.stands()
197
+ && (decidedOn === null || input.generation?.() === decidedOn) && servedBy(input.ceiling(), repo) && visible(repo);
198
+ let checkSet = false;
199
+ const admitted = await admitProject(store, {
200
+ registryFile: input.registryFile, path: canonical, actor: authority.actor, now: input.now, stillAllowed,
201
+ registryAllowed: (repo, registry) => stillAllowed(repo) && servedBy(input.ceiling(registry), repo),
202
+ withinAdmission: repo => { checkSet = registerSampleCheck(store, made, repo, authority.actor.label, input.now); },
203
+ ...(input.resolveFolder === undefined ? {} : { resolveFolder: input.resolveFolder }),
204
+ });
205
+ if (!admitted.ok) {
206
+ if (admitted.reason === "incomplete")
207
+ return { ok: false, reason: "incomplete", message: admitted.message };
208
+ return undo(standing() ?? "not-added");
209
+ }
210
+ return { ok: true, repo: admitted.repo, created: made.created, added: admitted.added, checkSet };
211
+ }
212
+ function sampleLock(path) {
213
+ const token = `${process.pid}.${randomBytes(8).toString("hex")}`;
214
+ let held = false;
215
+ return {
216
+ async take() {
217
+ try {
218
+ mkdirSync(dirname(path), { recursive: true });
219
+ }
220
+ catch {
221
+ return false;
222
+ }
223
+ const deadline = Date.now() + 60_000;
224
+ while (Date.now() < deadline) {
225
+ try {
226
+ writeFileSync(path, token, { flag: "wx", mode: 0o600 });
227
+ held = true;
228
+ return true;
229
+ }
230
+ catch (error) {
231
+ if (error.code !== "EEXIST")
232
+ return false;
233
+ }
234
+ let seen = "";
235
+ try {
236
+ seen = readFileSync(path, "utf8");
237
+ }
238
+ catch {
239
+ continue;
240
+ }
241
+ const owner = Number(seen.split(".")[0]);
242
+ let gone = !Number.isInteger(owner) || owner <= 0;
243
+ if (!gone) {
244
+ try {
245
+ process.kill(owner, 0);
246
+ }
247
+ catch (error) {
248
+ gone = error.code === "ESRCH";
249
+ }
250
+ }
251
+ if (gone) {
252
+ try {
253
+ if (readFileSync(path, "utf8") === seen)
254
+ unlinkSync(path);
255
+ }
256
+ catch { }
257
+ continue;
258
+ }
259
+ await new Promise(resolve => setTimeout(resolve, 50));
260
+ }
261
+ return false;
262
+ },
263
+ release() {
264
+ if (!held)
265
+ return;
266
+ held = false;
267
+ try {
268
+ if (readFileSync(path, "utf8") === token)
269
+ unlinkSync(path);
270
+ }
271
+ catch { }
272
+ },
273
+ };
274
+ }
package/dist/scope.js CHANGED
@@ -1243,8 +1243,20 @@ const LOCAL_RETRY_WORDS = {
1243
1243
  unsandboxed: "This project's checks run without a sandbox, so retrying needs your password.",
1244
1244
  imported: "A task from outside needs your password to retry.",
1245
1245
  };
1246
+ const LOCAL_REVISE_WORDS = {
1247
+ "local-mode-off": "Local mode is off, so sending this result back needs your password.",
1248
+ "not-owner": "Only this computer's owner sends results back here without a password.",
1249
+ "no-scope": "This task has no plan, so sending its result back needs your password.",
1250
+ release: "Sending a release back needs your password.",
1251
+ protected: "This result is protected work, so sending it back needs your password.",
1252
+ escalated: "Work with wider permissions needs your password to send back.",
1253
+ coordinator: "Work a coordinator filed needs your password to send back.",
1254
+ unsandboxed: "This project's checks run without a sandbox, so sending back needs your password.",
1255
+ imported: "A task from outside needs your password to send back.",
1256
+ };
1246
1257
  export function localWorkEligible(store, by, taskId, purpose) {
1247
- const words = purpose.act === "approve" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "plan" ? LOCAL_PLAN_WORDS : LOCAL_RETRY_WORDS;
1258
+ const words = purpose.act === "approve" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "revise" ? LOCAL_REVISE_WORDS
1259
+ : purpose.act === "plan" ? LOCAL_PLAN_WORDS : LOCAL_RETRY_WORDS;
1248
1260
  const no = (reason) => ({ ok: false, reason, message: words[reason] });
1249
1261
  if (!localModeOn(store))
1250
1262
  return no("local-mode-off");
@@ -1281,7 +1293,7 @@ export function localWorkEligible(store, by, taskId, purpose) {
1281
1293
  }
1282
1294
  if (ref === undefined || ref["coordinator_cid"] != null)
1283
1295
  return no("coordinator");
1284
- if (purpose.act === "complete")
1296
+ if (purpose.act === "complete" || purpose.act === "revise")
1285
1297
  return { ok: true };
1286
1298
  if ((purpose.act === "plan" || purpose.act === "retry") && issueImported(store, taskId))
1287
1299
  return no("imported");
@@ -1290,3 +1302,6 @@ export function localWorkEligible(store, by, taskId, purpose) {
1290
1302
  return no("unsandboxed");
1291
1303
  return { ok: true };
1292
1304
  }
1305
+ export function typedPasswordNow(proved) {
1306
+ return proved.ok && proved.method === "password-now";
1307
+ }