@ordewell/web 0.11.3 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AUTHORS.md CHANGED
@@ -26,12 +26,14 @@ record of who built what, rather than `git log`.
26
26
  planner's duplicated usage-limit message (#79, #96).
27
27
  - [@haltingstate](https://github.com/haltingstate) — made the terminal UI's
28
28
  stepper say what a saved step does next, instead of encoding it in a
29
- sentinel index (#123).
29
+ sentinel index (#123), and improved tool-call errors (#124).
30
30
  - [@Logic769](https://github.com/Logic769) — made `/resume` an alias of
31
31
  `/sessions` in the planner chat (#139).
32
32
  - Hanbin Tan ([@hskl18](https://github.com/hskl18)) — documented how
33
33
  planners and runners get their models and credentials (#140).
34
34
 
35
+ - [@torialfaro](https://github.com/torialfaro) and [@aavykyy](https://github.com/aavykyy) — made VS Code task prompts keyboard accessible (#141).
36
+
35
37
  Thank you. Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
36
38
 
37
39
  ## Acknowledgements
package/README.md CHANGED
@@ -27,7 +27,9 @@ task, skip, mark complete, message) are one `POST /api/plans/:id/execute-command
27
27
  whose body is core's `ExecutionCommand`. Mark complete and Mark not done on an
28
28
  AI or script task are refused while a run could advance the task, and otherwise
29
29
  need `"confirmed": true`, the user's yes (with `"seen"`, the task status they
30
- were asked about); a manual task's sign-off needs neither.
30
+ were asked about); a manual task's sign-off needs neither. What waits on a
31
+ person (ADR-0053) is `GET /api/plans/:id/escalations`, and on every status
32
+ update; `POST /api/plans/:id/escalations/answer` answers one by its id.
31
33
 
32
34
  Skills are read by the planner and the task orchestrator, not served as a
33
35
  route; the format is in [Writing skills](https://github.com/ordewell/ordewell/blob/main/docs/skills.md).
@@ -166,14 +166,14 @@ function run(file, args2, opts) {
166
166
  signal: opts.signal
167
167
  }, (err, stdout, stderr) => {
168
168
  const code = err && typeof err.code === "number" ? err.code : err ? 1 : 0;
169
- resolve3({ stdout: stdout ?? "", stderr: stderr ?? "", code, timedOut: err?.killed === true });
169
+ resolve3({ stdout: stdout ?? "", stderr: stderr ?? "", code, timedOut: err?.killed === true, signal: err?.signal ?? null });
170
170
  });
171
171
  if (opts.sealed) child.once("exit", () => setTimeout(() => {
172
172
  child.stdout?.destroy();
173
173
  child.stderr?.destroy();
174
174
  }, SEALED_OUTPUT_GRACE_MS).unref());
175
175
  } catch (err) {
176
- resolve3({ stdout: "", stderr: err.message, code: null, timedOut: false });
176
+ resolve3({ stdout: "", stderr: err.message, code: null, timedOut: false, signal: null });
177
177
  }
178
178
  });
179
179
  }
@@ -181,7 +181,7 @@ function run(file, args2, opts) {
181
181
  // server/adapters/PoolFileSystem.ts
182
182
  var SEARCH_TIMEOUT_MS = 2e4;
183
183
  var BASH_TIMEOUT_MS = 12e4;
184
- var PoolFileSystem = class extends core.BaseFileSystem {
184
+ var PoolFileSystem = class _PoolFileSystem extends core.BaseFileSystem {
185
185
  constructor(workspaceRoot) {
186
186
  super();
187
187
  this.workspaceRoot = workspaceRoot;
@@ -190,6 +190,9 @@ var PoolFileSystem = class extends core.BaseFileSystem {
190
190
  getWorkspaceRoot() {
191
191
  return this.workspaceRoot;
192
192
  }
193
+ rootedAt(workspace) {
194
+ return new _PoolFileSystem(workspace);
195
+ }
193
196
  /**
194
197
  * PATH for the search subprocesses. `execFile` starts them with no shell, so
195
198
  * on a Windows box whose POSIX tools live in the Git tree (`grep.exe` beside
@@ -338,7 +341,7 @@ var PoolFileSystem = class extends core.BaseFileSystem {
338
341
  if (result.code !== 0) {
339
342
  const detail = err || out || `exited with code ${result.code}`;
340
343
  return { success: false, output: `Command exited ${result.code}:
341
- ${detail.slice(0, 2e4)}`, truncated: detail.length > 2e4, ...result.timedOut ? { timedOut: true } : {} };
344
+ ${detail.slice(0, 2e4)}`, truncated: detail.length > 2e4, ...result.timedOut ? { timedOut: true } : {}, ...result.signal ? { signal: result.signal } : {} };
342
345
  }
343
346
  const combined = err ? `${out}
344
347
  [stderr]
@@ -611,6 +614,9 @@ var OrchestratorPool = class {
611
614
  plannerCompaction(sessionId) {
612
615
  return this.sessions.get(sessionId)?.plannerCompaction();
613
616
  }
617
+ plannerDetection(sessionId) {
618
+ return this.sessions.get(sessionId)?.plannerDetection();
619
+ }
614
620
  /** The planner's approval requests still waiting, as they were announced. */
615
621
  announcedApprovals(sessionId) {
616
622
  return this.sessions.get(sessionId)?.announcedApprovals() ?? [];
@@ -1166,6 +1172,20 @@ var OrchestratorPool = class {
1166
1172
  }
1167
1173
  this.clients.delete(sessionId);
1168
1174
  }
1175
+ /** Close a session for a surface that is done with it: it is dropped now, and this resolves once all it started has gone. */
1176
+ async close(sessionId) {
1177
+ const session = this.sessions.get(sessionId);
1178
+ this.destroy(sessionId, { notifyClients: true });
1179
+ await session?.gone;
1180
+ }
1181
+ /** Stop a session's whole tree, and wait until it has gone; the session stays open (ADR-0055 D16). */
1182
+ async stopTree(sessionId) {
1183
+ await this.sessions.get(sessionId)?.stopSubtree();
1184
+ }
1185
+ /** What a session's tree left in the engine, which only the `containers` setting says to look for (ADR-0059 L6). */
1186
+ reclaim(sessionId) {
1187
+ return core.reclaimContainers(sessionId, this.settingsService.getAll().containers);
1188
+ }
1169
1189
  destroyAll() {
1170
1190
  for (const id of this.sessions.keys()) this.destroy(id);
1171
1191
  }
@@ -1174,7 +1194,12 @@ var scanWorkspaces2 = scanWorkspaces;
1174
1194
  function getSessionList(workspace) {
1175
1195
  return core.listSessions(workspace);
1176
1196
  }
1177
- function removeSession(sessionId, workspace) {
1197
+ async function removeSession(sessionId, workspace, stop, close, reclaim) {
1198
+ await stop();
1199
+ const { refused } = await core.discardChildRuns(sessionId, workspace, core.createWorktreeIsolation({ config: new WebConfig() }));
1200
+ if (refused.length > 0) throw new Error(`The session was kept: ${refused.map(({ worktree, reason }) => `${worktree} (${reason})`).join(", ")}`);
1201
+ close();
1202
+ await reclaim();
1178
1203
  return core.deleteSession(sessionId, workspace);
1179
1204
  }
1180
1205
  function admittedEnv(changes) {
@@ -1302,20 +1327,24 @@ function sessionsRoute(pool2) {
1302
1327
  if (!Number.isInteger(attempt) || attempt < 1) return refuse(c, 400, "attempt must be a positive integer");
1303
1328
  return c.json({ attempt, events: core.taskLogForSurface(core.readTaskLog({ baseDir: ws, sessionId: c.req.param("id") }, c.req.param("taskId"), attempt)), position: pool2.streamPosition(c.req.param("id")) });
1304
1329
  });
1305
- router.delete("/:id", (c) => {
1330
+ router.delete("/:id", async (c) => {
1306
1331
  const ws = c.req.query("workspace") || process.cwd();
1307
1332
  const id = c.req.param("id");
1308
1333
  const held = pool2.hasSession(id);
1309
- pool2.destroy(id, { notifyClients: true });
1310
- const removed = removeSession(id, ws);
1334
+ let removed;
1335
+ try {
1336
+ removed = await removeSession(id, ws, () => pool2.stopTree(id), () => pool2.destroy(id, { notifyClients: true }), () => pool2.reclaim(id));
1337
+ } catch (err) {
1338
+ return c.json({ ok: false, message: err instanceof Error ? err.message : String(err) });
1339
+ }
1311
1340
  const ok = held || removed;
1312
1341
  return c.json({
1313
1342
  ok,
1314
1343
  ...ok ? {} : { message: `No session "${id}" was found in ${ws}.` }
1315
1344
  });
1316
1345
  });
1317
- router.post("/:id/close", (c) => {
1318
- pool2.destroy(c.req.param("id"), { notifyClients: true });
1346
+ router.post("/:id/close", async (c) => {
1347
+ await pool2.close(c.req.param("id"));
1319
1348
  return c.json({ ok: true });
1320
1349
  });
1321
1350
  return router;
@@ -1386,6 +1415,24 @@ function plansRoute(pool2) {
1386
1415
  return failure(c, err, "execute-command");
1387
1416
  }
1388
1417
  });
1418
+ router.get("/:sessionId/escalations", (c) => {
1419
+ try {
1420
+ return c.json({ escalations: pool2.session(c.req.param("sessionId")).escalations() });
1421
+ } catch (err) {
1422
+ return failure(c, err, "escalations");
1423
+ }
1424
+ });
1425
+ router.post("/:sessionId/escalations/answer", async (c) => {
1426
+ try {
1427
+ const { id, option, note, confirmed } = await jsonObject(c);
1428
+ if (typeof id !== "string" || typeof option !== "string") return refuse(c, 400, "id and option are required", "refused");
1429
+ const outcome = await pool2.session(c.req.param("sessionId")).answerEscalation(id, option, typeof note === "string" ? note : void 0, confirmed === true);
1430
+ if (!outcome.ok) return c.json({ error: outcome.message, code: "refused", ...outcome.payload ? { payload: outcome.payload } : {} }, 400);
1431
+ return c.json({ ok: true, message: outcome.message, ...outcome.payload ? { payload: outcome.payload } : {} });
1432
+ } catch (err) {
1433
+ return failure(c, err, "escalations");
1434
+ }
1435
+ });
1389
1436
  router.post("/:sessionId/tasks/:taskId/commands", async (c) => {
1390
1437
  try {
1391
1438
  const body = await c.req.json().catch(() => ({}));
@@ -1401,12 +1448,15 @@ function plansRoute(pool2) {
1401
1448
  for (const answer of ["approve", "reject"]) {
1402
1449
  router.post(`/:sessionId/tasks/:taskId/checkpoint/${answer}`, async (c) => {
1403
1450
  try {
1404
- const body = answer === "reject" ? await c.req.json().catch(() => ({})) : {};
1451
+ const body = await c.req.json().catch(() => ({}));
1405
1452
  const reason = typeof body === "object" && body !== null && "reason" in body && typeof body.reason === "string" ? body.reason.trim() : "";
1453
+ const raiseTokens = typeof body === "object" && body !== null && "raiseTokens" in body ? body.raiseTokens : void 0;
1454
+ const raise = typeof raiseTokens === "number" && Number.isSafeInteger(raiseTokens) && raiseTokens > 0 ? raiseTokens : void 0;
1455
+ if (raiseTokens !== void 0 && raise === void 0) return refuse(c, 400, "A raise is a whole number of tokens, 1 or more.", "refused");
1406
1456
  const session = pool2.session(c.req.param("sessionId"));
1407
1457
  const taskId = idOfRef(session, c.req.param("taskId"));
1408
1458
  if (!session.awaitsCheckpoint(taskId)) return refuse(c, 409, NO_CHECKPOINT, "checkpoint_not_waiting");
1409
- const { message } = await runUserCommand(session, { command: "answer_checkpoint", task: taskId, answer, ...reason ? { reason } : {} });
1459
+ const { message } = await runUserCommand(session, { command: "answer_checkpoint", task: taskId, answer, ...reason ? { reason } : {}, ...raise !== void 0 ? { raiseTokens: raise } : {} });
1410
1460
  return c.json({ ok: true, message });
1411
1461
  } catch (err) {
1412
1462
  return failure(c, err, "task edit");
@@ -1426,6 +1476,14 @@ function plansRoute(pool2) {
1426
1476
  return failure(c, err, "task edit");
1427
1477
  }
1428
1478
  });
1479
+ router.get("/:sessionId/tasks/:taskId/revert-preview", async (c) => {
1480
+ try {
1481
+ const session = pool2.session(c.req.param("sessionId"));
1482
+ return c.json(await session.revertPreview(idOfRef(session, c.req.param("taskId"))));
1483
+ } catch (err) {
1484
+ return failure(c, err, "task edit");
1485
+ }
1486
+ });
1429
1487
  router.get("/:sessionId/isolation/diff", async (c) => {
1430
1488
  try {
1431
1489
  return c.json({ diff: await pool2.session(c.req.param("sessionId")).reviewRunDiff() });
@@ -1435,8 +1493,11 @@ function plansRoute(pool2) {
1435
1493
  });
1436
1494
  router.post("/:sessionId/isolation/merge", async (c) => {
1437
1495
  try {
1438
- const outcome = await pool2.session(c.req.param("sessionId")).execute({ command: "merge_all" }, { kind: "user" });
1496
+ const body = await c.req.json().catch(() => ({}));
1497
+ const pastChecks = typeof body === "object" && body !== null && "pastChecks" in body && body.pastChecks === true;
1498
+ const outcome = await pool2.session(c.req.param("sessionId")).execute(pastChecks ? { command: "merge_all", pastChecks: true } : { command: "merge_all" }, { kind: "user" });
1439
1499
  if (outcome.payload?.kind === "merge") return c.json(outcome.payload.result);
1500
+ if (outcome.payload?.kind === "merge_hold") return refuse(c, 409, outcome.message, "merge_past_check");
1440
1501
  if (!outcome.ok) throw new core.TaskControlError(outcome.message);
1441
1502
  throw new Error("Merge all answered without its result.");
1442
1503
  } catch (err) {
@@ -1766,6 +1827,8 @@ function createWsHandler(pool2) {
1766
1827
  }
1767
1828
  const compaction = pool2.plannerCompaction(sessionId);
1768
1829
  if (compaction) ws.send(JSON.stringify(compaction));
1830
+ const detection = pool2.plannerDetection(sessionId);
1831
+ if (detection?.waiting) ws.send(JSON.stringify(detection));
1769
1832
  pool2.subscribe(sessionId, ws);
1770
1833
  });
1771
1834
  return (request, socket, head) => {