@ordewell/web 0.15.2 → 0.15.4

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,10 +30,19 @@ 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).
36
+ - [@nabeelbaghoor](https://github.com/nabeelbaghoor) — added a Planning indicator to
37
+ the open session in the sessions sidebar (#256).
35
38
 
36
39
  - [@torialfaro](https://github.com/torialfaro) and [@aavykyy](https://github.com/aavykyy) — made VS Code task prompts keyboard accessible (#141).
40
+ - **Harmit Patel** ([@Harmit3](https://github.com/Harmit3)) — added tests for the
41
+ wall-clock time helpers (#269) and made a mistyped CLI command suggest the
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).
37
46
 
38
47
  Thank you. Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
39
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);
@@ -1680,6 +1761,39 @@ function sameWorkspace(a, b) {
1680
1761
  function workspaceKey(workspace) {
1681
1762
  return path.resolve(workspace ?? process.cwd());
1682
1763
  }
1764
+ function accountAgents() {
1765
+ return core.accountRunners().flatMap((runner) => {
1766
+ const support = core.runnerAccountSupport(runner);
1767
+ return support ? [{ runner, label: core.RUNNER_LABELS[runner] ?? runner, homeVariable: support.homeVariable, defaultHome: support.defaultHome }] : [];
1768
+ });
1769
+ }
1770
+ function accountEntry(account, enabled, usability) {
1771
+ const agentLabel = core.RUNNER_LABELS[account.runner] ?? account.runner;
1772
+ return {
1773
+ runner: account.runner,
1774
+ id: account.id,
1775
+ runnerId: account.runnerId,
1776
+ label: account.label,
1777
+ agentLabel,
1778
+ name: core.accountRunnerLabel(agentLabel, account.label),
1779
+ home: account.home,
1780
+ shownHome: shownFolder(account.home),
1781
+ homeVariable: core.runnerAccountSupport(account.runner)?.homeVariable ?? "",
1782
+ enabled,
1783
+ plans: core.runnerPlans(account.runnerId),
1784
+ ...usability?.auth ? { auth: usability.auth } : {},
1785
+ ...usability && !usability.usable && usability.reason ? { reason: usability.reason } : {},
1786
+ ...byHandOf(account)
1787
+ };
1788
+ }
1789
+ function shownFolder(folder) {
1790
+ const home = os.homedir();
1791
+ return home && folder.startsWith(home + path.sep) ? `~${folder.slice(home.length)}` : folder;
1792
+ }
1793
+ function byHandOf(account) {
1794
+ const signIn = core.accountSignIn(account);
1795
+ return "byHand" in signIn ? { byHand: signIn.byHand } : {};
1796
+ }
1683
1797
 
1684
1798
  // server/routes/errors.ts
1685
1799
  var InvalidBodyError = class extends Error {
@@ -1712,6 +1826,7 @@ function classify(err) {
1712
1826
  if (err instanceof ChildNotFoundError) return { status: 404, code: "child_not_found" };
1713
1827
  if (err instanceof core.SessionHeldError) return { status: 409, code: "session_held" };
1714
1828
  if (err instanceof SessionOpenElsewhereError) return { status: 409, code: "refused" };
1829
+ if (err instanceof core.RunnerAccountError) return { status: err.status, code: err.status === 404 ? "account_not_found" : "refused" };
1715
1830
  if (err instanceof core.NoPlanError) return { status: 400, code: "no_plan" };
1716
1831
  if (err instanceof core.AlreadyExecutingError) return { status: 409, code: "already_executing" };
1717
1832
  if (err instanceof core.WorkspaceNotFoundError) return { status: 400, code: "workspace_not_found" };
@@ -2361,6 +2476,57 @@ function runnersRoute(pool) {
2361
2476
  });
2362
2477
  return router;
2363
2478
  }
2479
+ function accountsRoute(pool) {
2480
+ const router = new hono.Hono();
2481
+ const workspaceOf2 = (query) => query || void 0;
2482
+ router.get("/", async (c) => {
2483
+ try {
2484
+ return c.json(await pool.listAccounts(workspaceOf2(c.req.query("workspace"))));
2485
+ } catch (err) {
2486
+ return failure(c, err, "list accounts");
2487
+ }
2488
+ });
2489
+ router.post("/", async (c) => {
2490
+ try {
2491
+ const body = await jsonObject(c);
2492
+ if (typeof body.runner !== "string" || typeof body.label !== "string") return refuse(c, 400, "An account takes { runner, label }, with id and home optional.");
2493
+ 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.");
2494
+ const request = {
2495
+ runner: body.runner,
2496
+ label: body.label,
2497
+ ...body.id !== void 0 ? { id: body.id } : {},
2498
+ ...body.home !== void 0 ? { home: body.home } : {}
2499
+ };
2500
+ return c.json(await pool.addAccount(request, workspaceOf2(c.req.query("workspace"))));
2501
+ } catch (err) {
2502
+ return failure(c, err, "add account", { fallback: 400 });
2503
+ }
2504
+ });
2505
+ router.patch("/:id", async (c) => {
2506
+ try {
2507
+ const { label } = await jsonObject(c);
2508
+ if (typeof label !== "string") return refuse(c, 400, "A rename takes { label }.");
2509
+ return c.json(await pool.renameAccount(c.req.param("id"), label, workspaceOf2(c.req.query("workspace"))));
2510
+ } catch (err) {
2511
+ return failure(c, err, "rename account", { fallback: 400 });
2512
+ }
2513
+ });
2514
+ router.delete("/:id", async (c) => {
2515
+ try {
2516
+ return c.json(await pool.removeAccount(c.req.param("id"), workspaceOf2(c.req.query("workspace"))));
2517
+ } catch (err) {
2518
+ return failure(c, err, "remove account", { fallback: 400 });
2519
+ }
2520
+ });
2521
+ router.post("/:id/login", (c) => {
2522
+ try {
2523
+ return c.json(pool.accountLogin(c.req.param("id")));
2524
+ } catch (err) {
2525
+ return failure(c, err, "account login", { fallback: 400 });
2526
+ }
2527
+ });
2528
+ return router;
2529
+ }
2364
2530
  function skillsRoute() {
2365
2531
  const router = new hono.Hono();
2366
2532
  router.get("/", (c) => {
@@ -2937,6 +3103,7 @@ function createApp(pool, admission, reader = core.createWorkspaceReader({ config
2937
3103
  app.route("/api/plans", mergePreflightRoute(reader));
2938
3104
  app.route("/api/plans", plansRoute(pool));
2939
3105
  app.route("/api/runners", runnersRoute(pool));
3106
+ app.route("/api/accounts", accountsRoute(pool));
2940
3107
  app.route("/api/skills", skillsRoute());
2941
3108
  app.route("/api/models", modelsRoute(pool));
2942
3109
  app.route("/api/settings", settingsRoute(pool));