@ordewell/web 0.15.3 → 0.15.5

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
@@ -20,8 +20,8 @@ record of who built what, rather than `git log`.
20
20
  typing across the monorepo, the ESLint configuration, and the original CI
21
21
  workflow.
22
22
  - [@directsol](https://github.com/directsol) — verified the Codex transcript
23
- reader against a live rollout store (#16) and made the VS Code chat panel
24
- follow light themes (#20).
23
+ reader against a live rollout store (#16), made the VS Code chat panel follow
24
+ light themes (#20) and wrote the supervisor's wake-up policy (#68).
25
25
  - **Mayuri** ([@mayuriphad](https://github.com/mayuriphad)) — diagnosed and fixed the
26
26
  planner's duplicated usage-limit message (#79, #96).
27
27
  - [@haltingstate](https://github.com/haltingstate) — made the terminal UI's
@@ -30,8 +30,9 @@ record of who built what, rather than `git log`.
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
- planners and runners get their models and credentials (#140) and added Pi
34
- as a runner and harness planner (#78).
33
+ planners and runners get their models and credentials (#140), added command
34
+ tips to the empty planner composer (#142) and added Pi as a runner and harness
35
+ planner (#78).
35
36
  - [@nabeelbaghoor](https://github.com/nabeelbaghoor) — added a Planning indicator to
36
37
  the open session in the sessions sidebar (#256).
37
38
 
@@ -39,6 +40,9 @@ record of who built what, rather than `git log`.
39
40
  - **Harmit Patel** ([@Harmit3](https://github.com/Harmit3)) — added tests for the
40
41
  wall-clock time helpers (#269) and made a mistyped CLI command suggest the
41
42
  closest one (#271).
43
+ - [@Fegendet](https://github.com/Fegendet) — suggested runner accounts, several
44
+ sign-ins for one coding agent, and showed them working in a patched copy
45
+ (#150).
42
46
 
43
47
  Thank you. Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
44
48
 
@@ -5,9 +5,9 @@ var hono = require('hono');
5
5
  var core = require('@ordewell/core');
6
6
  var child_process = require('child_process');
7
7
  var crypto = require('crypto');
8
+ var os = require('os');
8
9
  var path = require('path');
9
10
  var fs = require('fs');
10
- var os = require('os');
11
11
  var ws = require('ws');
12
12
  var http = require('http');
13
13
 
@@ -29,9 +29,9 @@ function _interopNamespace(e) {
29
29
  return Object.freeze(n);
30
30
  }
31
31
 
32
+ var os__namespace = /*#__PURE__*/_interopNamespace(os);
32
33
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
33
34
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
34
- var os__namespace = /*#__PURE__*/_interopNamespace(os);
35
35
 
36
36
  // server/pool/childStreams.ts
37
37
  var ChildStreams = class {
@@ -687,7 +687,14 @@ var OrchestratorPool = class {
687
687
  return [
688
688
  core.claudeAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("claude-code") }),
689
689
  core.codexAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("codex"), command: server?.command, args: server?.args }),
690
- core.openCodeGoAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("opencode") })
690
+ core.openCodeGoAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("opencode") }),
691
+ // Each runner account's own limits, read under its own folder (ADR-0082).
692
+ ...core.listRunnerAccounts().flatMap((account) => {
693
+ const limits = { runnerId: account.runnerId, label: core.accountRunnerLabel(core.RUNNER_LABELS[account.runner] ?? account.runner, account.label), env: core.accountEnv(account.runnerId) };
694
+ if (account.runner === "claude-code") return [core.claudeAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("claude-code"), account: limits })];
695
+ if (account.runner === "codex") return [core.codexAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("codex"), command: server?.command, args: server?.args, account: limits })];
696
+ return [];
697
+ })
691
698
  ];
692
699
  });
693
700
  }
@@ -1389,6 +1396,7 @@ var OrchestratorPool = class {
1389
1396
  // read (`refuseBlockedRunner`), so the list and the refusal agree.
1390
1397
  readiness: core.runnerReadiness(usability, unlisted[p.manifest.name]),
1391
1398
  plans: core.runnerPlans(p.manifest.name),
1399
+ ...p.manifest.account ? { account: { runner: p.manifest.account.runner, id: p.manifest.account.id, runnerId: p.manifest.name, label: p.manifest.account.label } } : {},
1392
1400
  ...provider ? { provider } : {}
1393
1401
  };
1394
1402
  })
@@ -1429,6 +1437,79 @@ var OrchestratorPool = class {
1429
1437
  * Switch `id` on or off for planning. Switching on is a new pick, judged by
1430
1438
  * {@link refuseBlockedRunner}; one already on stays on, and off is never refused.
1431
1439
  */
1440
+ /** The user's runner accounts (ADR-0082), each with its sign-in as `workspace`'s probe reads it. */
1441
+ async listAccounts(workspace) {
1442
+ const installation = this.installationFor(workspace);
1443
+ const enabled = new Set(new WebConfig({ enabledRunners: this.enabledRunnerOverride() }).enabledRunners);
1444
+ const accounts = await Promise.all(core.listRunnerAccounts().map(async (account) => {
1445
+ const usability = await installation.runnerUsability(account.runnerId).catch(() => void 0);
1446
+ return accountEntry(account, enabled.has(account.runnerId), usability);
1447
+ }));
1448
+ return { accounts, agents: accountAgents() };
1449
+ }
1450
+ /**
1451
+ * Add an account and switch its runner on: the user made it to use it, and
1452
+ * until its login runs its readiness says it is signed out (ADR-0052), which
1453
+ * every picker already flags.
1454
+ */
1455
+ async addAccount(request, workspace) {
1456
+ const account = core.addRunnerAccount(request);
1457
+ this.modelResolver.forgetRunnerModels(account.runnerId);
1458
+ this.setRunnerEnabled(account.runnerId, true);
1459
+ this.accountsChanged();
1460
+ return this.accountChange(account.runnerId, workspace);
1461
+ }
1462
+ /** A new label: the id, and every plan and setting naming it, stay. */
1463
+ async renameAccount(runnerId, label, workspace) {
1464
+ core.renameRunnerAccount(runnerId, label);
1465
+ this.accountsChanged();
1466
+ return this.accountChange(runnerId, workspace);
1467
+ }
1468
+ /** Forget an account and switch its runner off; its folder and the sign-in in it stay where they are. */
1469
+ async removeAccount(runnerId, workspace) {
1470
+ const removed = core.removeRunnerAccount(runnerId);
1471
+ this.modelResolver.forgetRunnerModels(runnerId);
1472
+ this.setRunnerEnabled(runnerId, false);
1473
+ this.installationFor(workspace).refresh?.();
1474
+ this.accountsChanged();
1475
+ return { account: accountEntry(removed, false), ...await this.listAccounts(workspace) };
1476
+ }
1477
+ /**
1478
+ * The agent's own login for an account, as the client's login terminal runs
1479
+ * any runner's (ADR-0052): the daemon names the command and the account's
1480
+ * variables, and the client runs it where the person can type.
1481
+ */
1482
+ accountLogin(runnerId) {
1483
+ const account = core.findRunnerAccount(runnerId);
1484
+ if (!account) throw new core.RunnerAccountError(`No account "${runnerId}" on this machine.`, 404);
1485
+ const label = core.accountRunnerLabel(core.RUNNER_LABELS[account.runner] ?? account.runner, account.label);
1486
+ const signIn = core.accountSignIn(account);
1487
+ if ("byHand" in signIn) throw new core.RunnerAccountError(`Ordewell has no login to run for ${label}. ${signIn.byHand}`);
1488
+ return { runner: runnerId, label, argv: signIn.login, env: core.accountEnv(runnerId) };
1489
+ }
1490
+ async accountChange(runnerId, workspace) {
1491
+ const list = await this.listAccounts(workspace);
1492
+ const account = list.accounts.find((entry) => entry.runnerId === runnerId);
1493
+ if (!account) throw new core.RunnerAccountError(`No account "${runnerId}" on this machine.`, 404);
1494
+ return { account, ...list };
1495
+ }
1496
+ /**
1497
+ * Every open socket hears the new list, and each workspace's limits are read
1498
+ * again with a collector per account; the runner lists read the registry,
1499
+ * which reads the accounts afresh.
1500
+ */
1501
+ accountsChanged() {
1502
+ for (const [workspace, monitor] of this.accountLimits) {
1503
+ monitor.dispose();
1504
+ this.accountLimits.delete(workspace);
1505
+ }
1506
+ const accounts = core.listRunnerAccounts().map(({ runner, id, runnerId, label }) => ({ runner, id, runnerId, label }));
1507
+ const payload = JSON.stringify({ type: "accounts_changed", accounts });
1508
+ for (const [sessionId, clients] of this.clients) {
1509
+ this.send(sessionId, void 0, payload);
1510
+ for (const ws of clients) if (ws.readyState === ws.OPEN) this.connectAccountLimits(sessionId, ws);
1511
+ }
1512
+ }
1432
1513
  async enableRunner(id, enabled, workspace) {
1433
1514
  const on = new WebConfig({ enabledRunners: this.enabledRunnerOverride() }).enabledRunners.includes(id);
1434
1515
  if (enabled && !on) await this.refuseBlockedRunner(id, workspace);
@@ -1489,7 +1570,27 @@ var OrchestratorPool = class {
1489
1570
  async startPlanning(sessionId, goal, runners, workspace, modelOverride, options) {
1490
1571
  const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
1491
1572
  const session = opening instanceof Promise ? await opening : opening;
1492
- return this.firstTurn(sessionId, session, () => session.startPlanning(goal, runners, { surface: options?.surface }));
1573
+ return this.firstTurn(sessionId, session, () => session.startPlanning(goal, runners, options));
1574
+ }
1575
+ /**
1576
+ * Planning nobody watches (ADR-0083): resolved once the goal is admitted,
1577
+ * past the planner and runner refusals, while its first turn runs on asking
1578
+ * nobody. How the turn ends is the session's to keep, as an opening that
1579
+ * fails keeps its failure in the transcript, so nothing here waits for it.
1580
+ * Worded for the command line: the person runs the plan with `ordewell run`.
1581
+ */
1582
+ async startUnattendedPlanning(sessionId, goal, runners, workspace) {
1583
+ let admitted = () => void 0;
1584
+ const opened = new Promise((resolve3) => {
1585
+ admitted = resolve3;
1586
+ });
1587
+ const planning = this.startPlanning(sessionId, goal, runners, workspace, void 0, { surface: "cli", unattended: true, admitted });
1588
+ planning.catch(() => void 0);
1589
+ await Promise.race([opened, planning.then(() => void 0)]);
1590
+ }
1591
+ /** The workspaces of the sessions this daemon holds. */
1592
+ workspacesHeld() {
1593
+ return [...new Set(this.sessionWorkspaces.values())];
1493
1594
  }
1494
1595
  /**
1495
1596
  * Continue the planner dialogue with the user's reply: queued behind the
@@ -1680,6 +1781,39 @@ function sameWorkspace(a, b) {
1680
1781
  function workspaceKey(workspace) {
1681
1782
  return path.resolve(workspace ?? process.cwd());
1682
1783
  }
1784
+ function accountAgents() {
1785
+ return core.accountRunners().flatMap((runner) => {
1786
+ const support = core.runnerAccountSupport(runner);
1787
+ return support ? [{ runner, label: core.RUNNER_LABELS[runner] ?? runner, homeVariable: support.homeVariable, defaultHome: support.defaultHome }] : [];
1788
+ });
1789
+ }
1790
+ function accountEntry(account, enabled, usability) {
1791
+ const agentLabel = core.RUNNER_LABELS[account.runner] ?? account.runner;
1792
+ return {
1793
+ runner: account.runner,
1794
+ id: account.id,
1795
+ runnerId: account.runnerId,
1796
+ label: account.label,
1797
+ agentLabel,
1798
+ name: core.accountRunnerLabel(agentLabel, account.label),
1799
+ home: account.home,
1800
+ shownHome: shownFolder(account.home),
1801
+ homeVariable: core.runnerAccountSupport(account.runner)?.homeVariable ?? "",
1802
+ enabled,
1803
+ plans: core.runnerPlans(account.runnerId),
1804
+ ...usability?.auth ? { auth: usability.auth } : {},
1805
+ ...usability && !usability.usable && usability.reason ? { reason: usability.reason } : {},
1806
+ ...byHandOf(account)
1807
+ };
1808
+ }
1809
+ function shownFolder(folder) {
1810
+ const home = os.homedir();
1811
+ return home && folder.startsWith(home + path.sep) ? `~${folder.slice(home.length)}` : folder;
1812
+ }
1813
+ function byHandOf(account) {
1814
+ const signIn = core.accountSignIn(account);
1815
+ return "byHand" in signIn ? { byHand: signIn.byHand } : {};
1816
+ }
1683
1817
 
1684
1818
  // server/routes/errors.ts
1685
1819
  var InvalidBodyError = class extends Error {
@@ -1712,6 +1846,7 @@ function classify(err) {
1712
1846
  if (err instanceof ChildNotFoundError) return { status: 404, code: "child_not_found" };
1713
1847
  if (err instanceof core.SessionHeldError) return { status: 409, code: "session_held" };
1714
1848
  if (err instanceof SessionOpenElsewhereError) return { status: 409, code: "refused" };
1849
+ if (err instanceof core.RunnerAccountError) return { status: err.status, code: err.status === 404 ? "account_not_found" : "refused" };
1715
1850
  if (err instanceof core.NoPlanError) return { status: 400, code: "no_plan" };
1716
1851
  if (err instanceof core.AlreadyExecutingError) return { status: 409, code: "already_executing" };
1717
1852
  if (err instanceof core.WorkspaceNotFoundError) return { status: 400, code: "workspace_not_found" };
@@ -2022,6 +2157,21 @@ function plansRoute(pool) {
2022
2157
  return failure(c, err, "generate", { message: "Plan generation failed" });
2023
2158
  }
2024
2159
  });
2160
+ router.post("/:sessionId/start", async (c) => {
2161
+ try {
2162
+ const { goal, runners, workspace, ancestry } = await jsonObject(c);
2163
+ if (typeof goal !== "string" || !goal.trim()) return c.json({ error: "goal is required" }, 400);
2164
+ const ws = typeof workspace === "string" && workspace || c.req.query("workspace") || process.cwd();
2165
+ const runnerList = Array.isArray(runners) && runners.every((r) => typeof r === "string") ? runners : void 0;
2166
+ const groups = core.liveRunnerGroups([ws, ...pool.workspacesHeld(), ...scanWorkspaces2()]);
2167
+ if (core.callerInRunnerGroup(core.parseCallerAncestry(ancestry), groups)) return refuse(c, 403, core.RUNNER_PLAN_REFUSAL, "refused");
2168
+ const sessionId = c.req.param("sessionId");
2169
+ await pool.startUnattendedPlanning(sessionId, goal, runnerList, ws);
2170
+ return c.json({ sessionId });
2171
+ } catch (err) {
2172
+ return failure(c, err, "start planning", { message: "Planning failed" });
2173
+ }
2174
+ });
2025
2175
  router.post("/:sessionId/execute", async (c) => {
2026
2176
  try {
2027
2177
  const session = pool.session(c.req.param("sessionId"), callerWorkspace(c));
@@ -2361,6 +2511,57 @@ function runnersRoute(pool) {
2361
2511
  });
2362
2512
  return router;
2363
2513
  }
2514
+ function accountsRoute(pool) {
2515
+ const router = new hono.Hono();
2516
+ const workspaceOf2 = (query) => query || void 0;
2517
+ router.get("/", async (c) => {
2518
+ try {
2519
+ return c.json(await pool.listAccounts(workspaceOf2(c.req.query("workspace"))));
2520
+ } catch (err) {
2521
+ return failure(c, err, "list accounts");
2522
+ }
2523
+ });
2524
+ router.post("/", async (c) => {
2525
+ try {
2526
+ const body = await jsonObject(c);
2527
+ if (typeof body.runner !== "string" || typeof body.label !== "string") return refuse(c, 400, "An account takes { runner, label }, with id and home optional.");
2528
+ if (body.id !== void 0 && typeof body.id !== "string" || body.home !== void 0 && typeof body.home !== "string") return refuse(c, 400, "id and home are strings when given.");
2529
+ const request = {
2530
+ runner: body.runner,
2531
+ label: body.label,
2532
+ ...body.id !== void 0 ? { id: body.id } : {},
2533
+ ...body.home !== void 0 ? { home: body.home } : {}
2534
+ };
2535
+ return c.json(await pool.addAccount(request, workspaceOf2(c.req.query("workspace"))));
2536
+ } catch (err) {
2537
+ return failure(c, err, "add account", { fallback: 400 });
2538
+ }
2539
+ });
2540
+ router.patch("/:id", async (c) => {
2541
+ try {
2542
+ const { label } = await jsonObject(c);
2543
+ if (typeof label !== "string") return refuse(c, 400, "A rename takes { label }.");
2544
+ return c.json(await pool.renameAccount(c.req.param("id"), label, workspaceOf2(c.req.query("workspace"))));
2545
+ } catch (err) {
2546
+ return failure(c, err, "rename account", { fallback: 400 });
2547
+ }
2548
+ });
2549
+ router.delete("/:id", async (c) => {
2550
+ try {
2551
+ return c.json(await pool.removeAccount(c.req.param("id"), workspaceOf2(c.req.query("workspace"))));
2552
+ } catch (err) {
2553
+ return failure(c, err, "remove account", { fallback: 400 });
2554
+ }
2555
+ });
2556
+ router.post("/:id/login", (c) => {
2557
+ try {
2558
+ return c.json(pool.accountLogin(c.req.param("id")));
2559
+ } catch (err) {
2560
+ return failure(c, err, "account login", { fallback: 400 });
2561
+ }
2562
+ });
2563
+ return router;
2564
+ }
2364
2565
  function skillsRoute() {
2365
2566
  const router = new hono.Hono();
2366
2567
  router.get("/", (c) => {
@@ -2937,6 +3138,7 @@ function createApp(pool, admission, reader = core.createWorkspaceReader({ config
2937
3138
  app.route("/api/plans", mergePreflightRoute(reader));
2938
3139
  app.route("/api/plans", plansRoute(pool));
2939
3140
  app.route("/api/runners", runnersRoute(pool));
3141
+ app.route("/api/accounts", accountsRoute(pool));
2940
3142
  app.route("/api/skills", skillsRoute());
2941
3143
  app.route("/api/models", modelsRoute(pool));
2942
3144
  app.route("/api/settings", settingsRoute(pool));