toolroll 0.9.106 → 0.9.108

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 (46) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +5 -4
  3. package/dist/browser/workspace.css +1 -1
  4. package/dist/browser/workspace.js +27 -25
  5. package/dist/browser-shell.js +1 -1
  6. package/dist/cli-help.js +5 -0
  7. package/dist/cli.js +18 -11
  8. package/dist/contracts/cli.js +3 -1
  9. package/dist/contracts/console-api.js +1 -1
  10. package/dist/demo-sign-in.js +1 -55
  11. package/dist/easy-start-args.js +4 -2
  12. package/dist/easy-start.js +78 -24
  13. package/dist/first-run.js +4 -1
  14. package/dist/folder-look.js +65 -4
  15. package/dist/git-floor.js +9 -2
  16. package/dist/guides.js +3 -1
  17. package/dist/lead-cli.js +2 -1
  18. package/dist/live-bus.js +14 -1
  19. package/dist/login-secrets.js +43 -0
  20. package/dist/operate.js +195 -27
  21. package/dist/project-admission.js +60 -29
  22. package/dist/project.js +73 -0
  23. package/dist/repos.js +37 -0
  24. package/dist/route-hooks.js +1 -0
  25. package/dist/sample-project.js +167 -9
  26. package/dist/sandbox-runtime.js +1 -1
  27. package/dist/scope.js +17 -2
  28. package/dist/serve.js +15 -3
  29. package/dist/server/live.js +5 -2
  30. package/dist/server/login-help.js +67 -0
  31. package/dist/server/pages.js +180 -26
  32. package/dist/server/people-tokens.js +36 -24
  33. package/dist/server/render-people.js +14 -2
  34. package/dist/server/render-projects.js +58 -10
  35. package/dist/server/route-table.js +2 -1
  36. package/dist/server/settings.js +3 -0
  37. package/dist/server/welcome.js +29 -18
  38. package/dist/settings-groups-ui.js +10 -1
  39. package/dist/sign-in-page.js +197 -0
  40. package/dist/store.js +33 -0
  41. package/dist/surface.js +4 -1
  42. package/dist/task-outcome-cli.js +99 -4
  43. package/dist/tui-source.js +11 -3
  44. package/dist/tui.js +46 -46
  45. package/dist/welcome-facts.js +17 -7
  46. package/package.json +1 -1
@@ -1,17 +1,20 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { assignmentOf, checkAssignmentAsOperator, completeAsLocalOwner } from './assignment.js';
3
- import { currentLocalOwner, localModeOn } from './local-owner.js';
3
+ import { currentLocalOwner, localActNow, localModeOn, LOCAL_OWNER_LAPSED } from './local-owner.js';
4
4
  import { validateNote } from './decision.js';
5
5
  import { assignmentForCoordinator, coordinatorToken } from './assignment-adapters.js';
6
6
  import { authenticateCoordinator } from './coordinator.js';
7
- import { reproveApprover } from './principal.js';
8
- import { authenticateApprover, machineActing, personProof } from './scope.js';
7
+ import { reproveApprover, verifyApproverStanding } from './principal.js';
8
+ import { authenticateApprover, localWorkEligible, machineActing, personProof } from './scope.js';
9
9
  import { currentActor } from './actor.js';
10
10
  import { requestResultChanges } from './result-actions.js';
11
11
  import { commentSourceKey, revisionSourceOf } from './result-review.js';
12
12
  import { envelopeJson } from './envelope.js';
13
13
  import { completeAndOpenPullRequest, mergeAsPerson, MERGE_NEEDS_PERSON, newestPullRequestOf, publishingOf, pullRequestViewOf } from './pull-request-flow.js';
14
14
  import { proveRunStopped } from './stop-proof.js';
15
+ import { familyChangedFiles } from './result-completion.js';
16
+ import { activeRemote } from './remote-run.js';
17
+ import { underAgent } from './prompt.js';
15
18
  export async function runTaskOutcomeCommand(action, positional, flags, context) {
16
19
  const command = context.command ?? `task ${action}`;
17
20
  const emit = (result, lines) => {
@@ -34,10 +37,13 @@ export async function runTaskOutcomeCommand(action, positional, flags, context)
34
37
  return fail('usage', 'Choose your lead\'s credential or your own sign-in, not both.');
35
38
  if (credential.token !== null && pullRequest)
36
39
  return fail('unauthenticated', 'Opening a pull request is an approver\'s act. Use your own sign-in (--as and --token), not your lead\'s credential.');
40
+ const key = action === 'complete' ? 'c' : 'b';
41
+ if (credential.token === null && passwordFreeShell(context.store))
42
+ return fail('local-owner', passwordFreeShellWords(key, shellCallerOf(context.json, context.caller)));
37
43
  const operator = credential.token === null ? await context.operator() : null;
38
44
  if (credential.token === null && operator === null) {
39
45
  return fail('unauthenticated', passwordFreeOwner(context.store)
40
- ? `Open \`toolroll\` and press ${action === 'complete' ? 'c' : 'b'} on the task.`
46
+ ? passwordFreeShellWords(key, shellCallerOf(context.json, context.caller))
41
47
  : 'Run this at a terminal to sign in when asked, or open `toolroll`. Your lead can use --token-file or --token-env with its own credential.');
42
48
  }
43
49
  const { store, now, evidenceRoot } = context;
@@ -228,6 +234,95 @@ export async function runLocalCompletion(positional, flags, context) {
228
234
  ...(assignment.readiness?.checksOff ? [] : [receipt.checks.detail]),
229
235
  ]);
230
236
  }
237
+ export function reviseAsLocalOwner(store, taskId, input, now, evidenceRoot) {
238
+ const fail = (reason, message) => ({ ok: false, reason, message });
239
+ try {
240
+ return store.transact(() => {
241
+ const local = localActNow(store, 'request-revision');
242
+ if (local === null)
243
+ return fail('local-owner', LOCAL_OWNER_LAPSED);
244
+ const standing = verifyApproverStanding(store, local.account, local.accountGeneration, store.knownRepos().filter(repo => store.accountCanAccess(local.account, repo)));
245
+ if (!standing.ok)
246
+ return fail('local-owner', LOCAL_OWNER_LAPSED);
247
+ const who = standing.who, repos = who.repos;
248
+ const current = assignmentOf(store, taskId, now, { principal: 'operator', repos }, evidenceRoot);
249
+ if (current === null || !store.accountCanAccess(who.name, current.repo))
250
+ return fail('not-found', 'That task is unavailable in your projects.');
251
+ const run = store.getRun(input.runId);
252
+ const runTask = run === null ? null : store.externalIdFor(run.taskRef);
253
+ const family = runTask === null ? null : store.taskFamilyOf(runTask, repos, false);
254
+ if (run === null || runTask === null || family?.root.id !== current.rootId || run.outcome === null)
255
+ return fail('not-found', 'That finished result is unavailable for this task.');
256
+ const changed = familyChangedFiles(store, runTask, run.id, evidenceRoot, { missing: 'unknown' });
257
+ for (const one of new Set([taskId, runTask, current.rootId])) {
258
+ const eligible = localWorkEligible(store, who.name, one, { act: 'revise', changed });
259
+ if (!eligible.ok)
260
+ return fail('local-owner', `${eligible.message} ${store.accountOf(who.name)?.passwordSet === true ? 'Sign in with your password to do this.' : 'Set a password first: run `toolroll password set`.'}`);
261
+ }
262
+ const source = revisionSourceOf(store.getScope(runTask)?.digest ?? null);
263
+ const key = createHash('sha256').update(JSON.stringify([who.name, run.id, source, input.feedback])).digest('hex').slice(0, 32);
264
+ const previous = store.diffCommentBySourceKey(commentSourceKey(who.name, key));
265
+ if ((family.current.id !== runTask || (current.receipt !== null && current.receipt.runId !== run.id)) && previous?.consumedBy == null)
266
+ return fail('stale-result', 'A newer version is current. Read its result before sending it back.');
267
+ const revised = requestResultChanges(store, evidenceRoot, { run: run.id, source, actor: who.name, repos,
268
+ batch: '', note: input.feedback, path: '', line: '', request: key, allowMode: true,
269
+ origin: 'person' }, now);
270
+ if (!revised.ok)
271
+ return fail(revised.status === 400 ? 'usage' : 'stale-result', revised.message);
272
+ const scope = store.getScope(revised.id);
273
+ return { ok: true, id: revised.id, rootId: current.rootId, sourceRun: run.id, source, key,
274
+ approved: scope?.approvedDigest != null && scope.approvedDigest === scope.digest, planning: store.lookupRef(revised.id)?.plan === 'requested' };
275
+ });
276
+ }
277
+ catch (error) {
278
+ if (error instanceof Error && error.message === LOCAL_OWNER_LAPSED)
279
+ return fail('local-owner', LOCAL_OWNER_LAPSED);
280
+ throw error;
281
+ }
282
+ }
283
+ export async function runLocalRevision(positional, flags, context) {
284
+ const command = 'task revise';
285
+ const emit = (result, lines) => {
286
+ context.write(context.json ? envelopeJson({ ...result, command }) : result.ok ? (lines ?? []).join('\n') : result.message ?? 'The action was refused.');
287
+ return result.ok ? 0 : result.reason === 'usage' ? 2 : 3;
288
+ };
289
+ const fail = (reason, message) => emit({ ok: false, reason, message });
290
+ const usage = 'Use task revise <task> --run <build> --feedback "requested change".';
291
+ const allowed = new Set(['json', 'db', 'run', 'feedback']);
292
+ for (const key of flags.keys())
293
+ if (!allowed.has(key))
294
+ return fail('usage', `--${key} is not a ${command} option here.`);
295
+ const task = positional[0];
296
+ if (positional.length !== 1 || !task || task.length > 64 || /[\x00-\x1f]/.test(task))
297
+ return fail('usage', usage);
298
+ const run = flags.get('run'), feedback = flags.get('feedback');
299
+ if (typeof run !== 'string' || !/^[1-9]\d{0,14}$/.test(run))
300
+ return fail('usage', `--run needs the exact build number of the result you read. ${usage}`);
301
+ if (typeof feedback !== 'string' || !feedback.trim())
302
+ return fail('usage', 'Describe the requested change with --feedback.');
303
+ const done = reviseAsLocalOwner(context.store, task, { runId: Number(run), feedback }, context.now, context.evidenceRoot);
304
+ if (!done.ok)
305
+ return emit(done);
306
+ const { ok: _ok, ...result } = done;
307
+ return emit({ ok: true, result }, [`${done.rootId} · Revision created`, `Execution: ${done.id}`,
308
+ done.approved ? 'Covered by your existing operating mode.' : done.planning ? 'Updating the plan with your notes; approve it when it is ready.' : 'The revision is waiting for approval.']);
309
+ }
310
+ export function shellCallerOf(json, seam) {
311
+ return seam?.() ?? { json, agent: underAgent(process.env), terminal: process.stdin.isTTY === true && process.stdout.isTTY === true };
312
+ }
313
+ export function passwordFreeShell(store) {
314
+ return currentLocalOwner() === null && activeRemote() === null && currentActor()?.lead !== true && passwordFreeOwner(store);
315
+ }
316
+ export function passwordFreeShellWords(key, caller) {
317
+ const fix = `Open \`toolroll\` in your own terminal and press ${key} on the task.`;
318
+ if (caller.agent)
319
+ return `Your coding agent can't do this for you. ${fix}`;
320
+ if (caller.json)
321
+ return `With --json nothing can ask you, and you haven't set a password. ${fix}`;
322
+ if (!caller.terminal)
323
+ return `This can't ask you when it runs piped or in the background, and you haven't set a password. ${fix}`;
324
+ return `You haven't set a password, so there's nothing to sign in with here. Open \`toolroll\` and press ${key} on the task.`;
325
+ }
231
326
  export function passwordFreeOwner(store) {
232
327
  try {
233
328
  if (!localModeOn(store))
@@ -15,7 +15,7 @@ import { flakyCount } from "./flaky.js";
15
15
  import { memoryWaiting } from "./lesson-notes.js";
16
16
  import { homeGroupOf } from "./home-groups.js";
17
17
  import { terminalText } from "./terminal-text.js";
18
- import { welcomeHere, welcomeLines } from "./welcome-facts.js";
18
+ import { sampleOffered, welcomeHere, welcomeLines } from "./welcome-facts.js";
19
19
  import { planSourceOf, retryPinsOf } from "./local-owner-acts.js";
20
20
  const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
21
21
  const words = (value, fallback = "") => typeof value === "string" ? value : fallback;
@@ -157,13 +157,17 @@ export function createTuiSource(options) {
157
157
  done = "Stopping. Its work so far is kept.";
158
158
  break;
159
159
  case "revise":
160
- argv = ["task", "revise", act.id, "--feedback", act.text];
160
+ argv = ["task", "revise", act.id, "--run", String(act.runId), "--feedback", act.text];
161
161
  done = "Sent back with your note.";
162
162
  break;
163
163
  case "answer":
164
164
  argv = ["decide", String(act.decision), "--choose", act.option];
165
165
  done = "Answered.";
166
166
  break;
167
+ case "sample":
168
+ argv = ["welcome", "sample"];
169
+ done = "Added the sample project. Press n to write a first task.";
170
+ break;
167
171
  case "retry":
168
172
  argv = ["task", "requeue", act.id, "--run", String(act.runId), "--digest", act.digest];
169
173
  done = "Retrying. It starts next.";
@@ -174,8 +178,11 @@ export function createTuiSource(options) {
174
178
  break;
175
179
  }
176
180
  const answer = await command(argv);
181
+ setupCache = null;
177
182
  if (answer.ok !== true)
178
183
  return refusalOf(answer);
184
+ if (act.kind === "sample")
185
+ return { ok: true, message: answer["added"] === false ? "The sample project is already added. Press n to write a first task." : done };
179
186
  if (act.kind === "complete" && answer["replayed"] === true)
180
187
  return { ok: true, message: "Already accepted. The task is done." };
181
188
  if (act.kind === "plan" && answer["replayed"] === true)
@@ -230,7 +237,8 @@ export function createTuiSource(options) {
230
237
  });
231
238
  if (here === null)
232
239
  return null;
233
- const value = here.model.left === 0 ? null : { left: here.model.left, lines: welcomeLines(here.model).map(line => terminalText(line)) };
240
+ const offered = sampleOffered(here.model, localModeOf(store)?.enabled === true, store.isDemo());
241
+ const value = here.model.left === 0 ? null : { left: here.model.left, lines: welcomeLines(here.model, offered ? "key" : null).map(line => terminalText(line)), sample: offered };
234
242
  setupCache = { at: Date.now(), value };
235
243
  return value;
236
244
  },