@ordewell/web 0.14.12 → 0.14.14

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.
@@ -653,7 +653,9 @@ var OrchestratorPool = class {
653
653
  });
654
654
  this.suppliedModelResolver = deps.modelResolver !== void 0;
655
655
  this.modelResolver = deps.modelResolver ?? new core.ModelResolver(this.registry, new WebConfig(), {
656
- env: async () => ({ ...process.env, ...await core.workspaceEnvOf(process.cwd()) })
656
+ env: async () => ({ ...process.env, ...await core.workspaceEnvOf(process.cwd()) }),
657
+ // What its ACP handshake hears is recorded for the account it asked (ADR-0052).
658
+ workspace: () => process.cwd()
657
659
  });
658
660
  this.codexSandbox = deps.codexSandbox ?? new core.CodexSandboxAvailability(this.registry, { spawn: child_process.spawn, fetch: globalThis.fetch }, { cwd: process.cwd(), env: process.env });
659
661
  this.leaseHost = deps.leaseHost;
@@ -1144,6 +1146,8 @@ var OrchestratorPool = class {
1144
1146
  const workspace = this.settingsWorkspace(sessionId, requestWorkspace);
1145
1147
  const judging = this.catalogJudging(change, workspace);
1146
1148
  await this.discoverUnheld(workspace, judging ? [judging] : []);
1149
+ const incoming = change.provider !== void 0 && change.provider !== this.plannerProviderInEffect(workspace) ? core.runnerForProvider(change.provider) : void 0;
1150
+ if (incoming) await this.refuseBlockedRunner(incoming, workspace);
1147
1151
  return this.updateSettings(changes2, sessionId, requestWorkspace);
1148
1152
  });
1149
1153
  this.plannerWrites = turn.catch(() => void 0);
@@ -1356,20 +1360,24 @@ var OrchestratorPool = class {
1356
1360
  * runner can't be spawned. `workspace` names whose account the auth verdict
1357
1361
  * is about; without it the daemon's cwd stands in.
1358
1362
  */
1359
- async getInstalledRunners(workspace) {
1363
+ async getInstalledRunners(workspace, { recheck = [] } = {}) {
1364
+ const check = this.signInCheck(workspace);
1365
+ await Promise.all(recheck.filter((runner) => this.registry.getManifest(runner)).map((runner) => core.recheckRunnerSignIn(runner, check)));
1360
1366
  await this.codexSandbox.refresh();
1361
1367
  const installation = this.installationFor(workspace);
1362
1368
  for (const probe of /* @__PURE__ */ new Set([installation, this.runnerInstallation])) probe.refresh?.();
1363
1369
  await this.detectInstalledPlanner();
1364
1370
  const config = new WebConfig({ enabledRunners: this.enabledRunnerOverride() });
1365
1371
  const enabled = new Set(config.enabledRunners);
1372
+ const unlisted = this.resolverFor(workspace).getRunnerUnlisted();
1366
1373
  const runners = this.registry.list();
1367
1374
  const installedIds = new Set(
1368
1375
  await installation.filterInstalled(runners.map((p) => p.manifest.name))
1369
1376
  );
1370
1377
  return Promise.all(
1371
1378
  runners.filter((p) => installedIds.has(p.manifest.name)).map(async (p) => {
1372
- const { usable, reason, auth, version } = await installation.runnerUsability(p.manifest.name);
1379
+ const usability = await installation.runnerUsability(p.manifest.name);
1380
+ const { usable, reason, auth, version } = usability;
1373
1381
  const provider = core.inProcessProvider(p.manifest);
1374
1382
  return {
1375
1383
  id: p.manifest.name,
@@ -1378,6 +1386,9 @@ var OrchestratorPool = class {
1378
1386
  ...usable ? {} : { usable: false, ...reason ? { reason } : {} },
1379
1387
  ...auth ? { auth } : {},
1380
1388
  ...version ? { version } : {},
1389
+ // Read from the same record and discovery answer the write checks
1390
+ // read (`refuseBlockedRunner`), so the list and the refusal agree.
1391
+ readiness: core.runnerReadiness(usability, unlisted[p.manifest.name]),
1381
1392
  plans: core.runnerPlans(p.manifest.name),
1382
1393
  ...provider ? { provider } : {}
1383
1394
  };
@@ -1390,6 +1401,41 @@ var OrchestratorPool = class {
1390
1401
  const session = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
1391
1402
  return core.migratePlanState(await this.firstTurn(sessionId, session, () => session.generatePlan(goal, runners)));
1392
1403
  }
1404
+ /**
1405
+ * Refuse a new pick of `runner` in `workspace` — a planner switched to it, it
1406
+ * switched on, a task moved onto it — when its readiness blocks one
1407
+ * (ADR-0052). The picker's list may be stale, so it is judged here, as the
1408
+ * send gate judges a planner: a recorded sign-out is asked again first, so a
1409
+ * sign-in done since lets the pick through. A choice already made is never
1410
+ * the caller's to pass here, and an unusable runner is refused at its start,
1411
+ * as before.
1412
+ */
1413
+ async refuseBlockedRunner(runner, workspace) {
1414
+ const manifest = this.registry.getManifest(runner);
1415
+ if (!manifest) return;
1416
+ const resolver = this.resolverFor(workspace);
1417
+ await core.refuseBlockedPick(runner, manifest.displayName, {
1418
+ ...this.signInCheck(workspace),
1419
+ ...workspace !== void 0 ? { workspace } : {},
1420
+ unlisted: () => resolver.getRunnerUnlisted()
1421
+ });
1422
+ }
1423
+ /** {@link refuseBlockedRunner} for a task edit: only a move onto another runner is a new pick. */
1424
+ async refuseBlockedTaskRunner(sessionId, workspace, taskId, runner) {
1425
+ const session = this.session(sessionId, workspace);
1426
+ const task = core.flattenTasks(session.planTasks).find((t) => t.id === taskId);
1427
+ if (!task || task.assignedRunner === runner) return;
1428
+ await this.refuseBlockedRunner(runner, session.workspaceRoot);
1429
+ }
1430
+ /**
1431
+ * Switch `id` on or off for planning. Switching on is a new pick, judged by
1432
+ * {@link refuseBlockedRunner}; one already on stays on, and off is never refused.
1433
+ */
1434
+ async enableRunner(id, enabled, workspace) {
1435
+ const on = new WebConfig({ enabledRunners: this.enabledRunnerOverride() }).enabledRunners.includes(id);
1436
+ if (enabled && !on) await this.refuseBlockedRunner(id, workspace);
1437
+ this.setRunnerEnabled(id, enabled);
1438
+ }
1393
1439
  /**
1394
1440
  * Judge the planner as the workspace's account is now, not as it was when the
1395
1441
  * list was last read: the signed-out refusal itself offers the runner's own
@@ -1401,9 +1447,20 @@ var OrchestratorPool = class {
1401
1447
  recheckSignedOutPlanner(workspace, provider) {
1402
1448
  const runner = core.runnerForProvider(provider);
1403
1449
  if (!runner || core.recordedRunnerAuth(runner, workspace)?.state !== "signed-out") return null;
1450
+ return core.verifyRunnerSignIn(runner, this.signInCheck(workspace)).then(() => void 0);
1451
+ }
1452
+ /** The probe and the catalog that judge `workspace`'s account, for {@link verifyRunnerSignIn} and {@link recheckRunnerSignIn}. */
1453
+ signInCheck(workspace) {
1404
1454
  const installation = this.installationFor(workspace);
1405
- installation.refresh?.();
1406
- return installation.plannerUsability(runner).then(() => void 0);
1455
+ return {
1456
+ installation: {
1457
+ refresh: () => installation.refresh?.(),
1458
+ recheck: (runner) => installation.recheck ? installation.recheck(runner) : installation.runnerUsability(runner),
1459
+ runnerUsability: (runner) => installation.runnerUsability(runner)
1460
+ },
1461
+ resolver: this.resolverFor(workspace),
1462
+ manifests: this.registry
1463
+ };
1407
1464
  }
1408
1465
  /**
1409
1466
  * Build the session a new planning conversation runs in and register it in
@@ -1664,6 +1721,8 @@ function classify(err) {
1664
1721
  if (err instanceof core.AlreadyExecutingError) return { status: 409, code: "already_executing" };
1665
1722
  if (err instanceof core.WorkspaceNotFoundError) return { status: 400, code: "workspace_not_found" };
1666
1723
  if (err instanceof core.PlannerNotReadyError) return { status: 409, code: "planner_not_ready" };
1724
+ if (err instanceof core.RunnerNotReadyError) return { status: 409, code: "runner_not_ready" };
1725
+ if (err instanceof core.RunnerSignedOutError) return { status: 409, code: "runner_signed_out" };
1667
1726
  if (err instanceof core.PlannerTurnStoppedError) return { status: 409, code: "planner_turn_stopped" };
1668
1727
  if (err instanceof core.PlannerTurnDiscardedError) return { status: 409, code: "planner_turn_discarded" };
1669
1728
  if (err instanceof core.ConversationBusyError) return { status: 409, code: "conversation_busy" };
@@ -1694,6 +1753,8 @@ function failure(c, err, label, { fallback = 500, message = "Internal error" } =
1694
1753
  error: err instanceof Error && err.message || message,
1695
1754
  ...classified ? { code: classified.code } : {},
1696
1755
  ...err instanceof core.PlannerNotReadyError ? { plannerNotReady: err.reason } : {},
1756
+ ...err instanceof core.RunnerNotReadyError ? { runnerNotReady: { runner: err.runner, readiness: err.readiness } } : {},
1757
+ ...err instanceof core.RunnerSignedOutError ? { signIn: err.signIn } : {},
1697
1758
  ...err instanceof core.SessionHeldError ? { sessionHeld: err.held } : {},
1698
1759
  ...err instanceof core.UserGitError && err.detail.held ? { landingBranchHeld: err.detail.held } : {},
1699
1760
  ...err instanceof core.UserGitError && err.detail.difference ? { confirmStale: err.detail.difference } : {}
@@ -2132,6 +2193,7 @@ function plansRoute(pool) {
2132
2193
  try {
2133
2194
  const changes2 = await jsonObject(c);
2134
2195
  if (changes2.assignedModel === null) changes2.assignedModel = void 0;
2196
+ if (typeof changes2.assignedRunner === "string") await pool.refuseBlockedTaskRunner(c.req.param("sessionId"), callerWorkspace(c), c.req.param("taskId"), changes2.assignedRunner);
2135
2197
  const result = await pool.session(c.req.param("sessionId"), callerWorkspace(c)).updateTask(c.req.param("taskId"), changes2);
2136
2198
  if (!result) return refuse(c, 404, "Task not found", "task_not_found");
2137
2199
  return c.json({ ok: true });
@@ -2143,6 +2205,7 @@ function plansRoute(pool) {
2143
2205
  try {
2144
2206
  const edit = await jsonObject(c);
2145
2207
  if (!core.isCardEdit(edit)) return refuse(c, 400, "Unknown card edit");
2208
+ if (edit.kind === "runner") await pool.refuseBlockedTaskRunner(c.req.param("sessionId"), callerWorkspace(c), c.req.param("taskId"), edit.runner);
2146
2209
  const result = await pool.session(c.req.param("sessionId"), callerWorkspace(c)).cardEdit(c.req.param("taskId"), edit);
2147
2210
  if (!result) return refuse(c, 404, "Task not found", "task_not_found");
2148
2211
  return c.json({ ok: true });
@@ -2277,7 +2340,8 @@ function runnersRoute(pool) {
2277
2340
  router.get("/", async (c) => {
2278
2341
  try {
2279
2342
  const workspace = c.req.query("workspace");
2280
- const runners = await pool.getInstalledRunners(workspace);
2343
+ const recheck = c.req.query("recheck")?.split(",").filter(Boolean);
2344
+ const runners = await pool.getInstalledRunners(workspace, ...recheck?.length ? [{ recheck }] : []);
2281
2345
  await pool.discoverPlannerCatalogs(void 0, workspace);
2282
2346
  const state = pool.getRunnerState(workspace);
2283
2347
  return c.json({
@@ -2294,7 +2358,7 @@ function runnersRoute(pool) {
2294
2358
  const id = c.req.param("id");
2295
2359
  const { enabled } = await jsonObject(c);
2296
2360
  if (typeof enabled !== "boolean") return refuse(c, 400, "enabled must be true or false");
2297
- pool.setRunnerEnabled(id, enabled);
2361
+ await pool.enableRunner(id, enabled, c.req.query("workspace") || void 0);
2298
2362
  return c.json({ ok: true });
2299
2363
  } catch (err) {
2300
2364
  return failure(c, err, "runner toggle", { fallback: 400 });