@ordewell/web 0.15.5 → 0.15.6

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.
@@ -311,6 +311,18 @@ function loadSavedCredentials(env = process.env, file = core.globalEnvFile()) {
311
311
  if (isSavedCredential(key) && env[key] === void 0) env[key] = value;
312
312
  }
313
313
  }
314
+ function loadSavedPlannerChoice(env = process.env, file = core.globalEnvFile()) {
315
+ let saved;
316
+ try {
317
+ saved = core.readEnvFile(file);
318
+ } catch (err) {
319
+ console.error(`[web] could not read the saved planner choice from ${file}: ${err instanceof Error ? err.message : String(err)}`);
320
+ return;
321
+ }
322
+ for (const key of PLANNER_CHOICE_ENV) {
323
+ if (saved[key] !== void 0 && env[key] === void 0) env[key] = saved[key];
324
+ }
325
+ }
314
326
  var MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
315
327
  var SEALED_OUTPUT_GRACE_MS = 1e3;
316
328
  function run(file, args, opts) {
@@ -668,7 +680,8 @@ var OrchestratorPool = class {
668
680
  this.runner = deps.runner ?? new core.StructuredRunner();
669
681
  this.suppliedRunnerInstallation = deps.runnerInstallation;
670
682
  this.runnerInstallation = deps.runnerInstallation ?? new core.RunnerInstallation(this.registry, void 0, void 0, {
671
- env: () => core.workspaceEnvOf(process.cwd()),
683
+ // A workspace's view (installationFor) asks this for its own env.
684
+ env: (workspace) => core.workspaceEnvOf(workspace ?? process.cwd()),
672
685
  workspace: () => process.cwd()
673
686
  });
674
687
  this.suppliedModelResolver = deps.modelResolver !== void 0;
@@ -1342,9 +1355,11 @@ var OrchestratorPool = class {
1342
1355
  return this.modelResolver.withRunnerEnv(key, async () => ({ ...process.env, ...await core.workspaceEnvOf(key) }));
1343
1356
  }
1344
1357
  /**
1345
- * The probe that judges a login for `workspace`, cached so its install and
1346
- * auth verdicts survive between runner-list refreshes. Without a workspace
1347
- * the daemon's cwd is what the request would plan with anyway.
1358
+ * The probe that judges a login for `workspace`, cached so its auth
1359
+ * verdicts survive between runner-list refreshes. Without a workspace the
1360
+ * daemon's cwd is what the request would plan with anyway. A view of the
1361
+ * daemon's own probe: whether a CLI is installed is the host's, so one
1362
+ * `--version` answers detection and every workspace's list alike.
1348
1363
  */
1349
1364
  installationFor(workspace) {
1350
1365
  if (this.suppliedRunnerInstallation) return this.suppliedRunnerInstallation;
@@ -1352,7 +1367,8 @@ var OrchestratorPool = class {
1352
1367
  const key = path.resolve(workspace);
1353
1368
  let installation = this.workspaceInstallations.get(key);
1354
1369
  if (!installation) {
1355
- installation = new core.RunnerInstallation(this.registry, void 0, void 0, {
1370
+ const host = this.runnerInstallation;
1371
+ installation = host instanceof core.RunnerInstallation ? host.at(key) : new core.RunnerInstallation(this.registry, void 0, void 0, {
1356
1372
  env: () => core.workspaceEnvOf(key),
1357
1373
  workspace: () => key
1358
1374
  });
@@ -1366,41 +1382,43 @@ var OrchestratorPool = class {
1366
1382
  * runner can't be spawned. `workspace` names whose account the auth verdict
1367
1383
  * is about; without it the daemon's cwd stands in.
1368
1384
  */
1369
- async getInstalledRunners(workspace, { recheck = [] } = {}) {
1385
+ async getInstalledRunners(workspace, { recheck = [], cached: cached2 = false } = {}) {
1370
1386
  const check = this.signInCheck(workspace);
1371
1387
  await Promise.all(recheck.filter((runner) => this.registry.getManifest(runner)).map((runner) => core.recheckRunnerSignIn(runner, check)));
1372
- await this.codexSandbox.refresh();
1373
1388
  const installation = this.installationFor(workspace);
1374
- for (const probe of /* @__PURE__ */ new Set([installation, this.runnerInstallation])) probe.refresh?.();
1375
- await this.detectInstalledPlanner();
1389
+ if (!cached2) {
1390
+ await this.codexSandbox.refresh();
1391
+ for (const probe of /* @__PURE__ */ new Set([installation, this.runnerInstallation])) probe.refresh?.();
1392
+ }
1393
+ const detected = cached2 ? core.installedPlannerDetected() : this.detectInstalledPlanner();
1394
+ const runners = this.registry.list();
1395
+ const judged = installation.filterInstalled(runners.map((p) => p.manifest.name)).then((installed) => {
1396
+ const installedIds = new Set(installed);
1397
+ return Promise.all(runners.filter((p) => installedIds.has(p.manifest.name)).map(async (p) => ({ p, usability: await installation.runnerUsability(p.manifest.name) })));
1398
+ });
1399
+ judged.catch(() => void 0);
1400
+ await detected;
1376
1401
  const config = new WebConfig({ enabledRunners: this.enabledRunnerOverride() });
1377
1402
  const enabled = new Set(config.enabledRunners);
1378
1403
  const unlisted = this.resolverFor(workspace).getRunnerUnlisted();
1379
- const runners = this.registry.list();
1380
- const installedIds = new Set(
1381
- await installation.filterInstalled(runners.map((p) => p.manifest.name))
1382
- );
1383
- return Promise.all(
1384
- runners.filter((p) => installedIds.has(p.manifest.name)).map(async (p) => {
1385
- const usability = await installation.runnerUsability(p.manifest.name);
1386
- const { usable, reason, auth, version } = usability;
1387
- const provider = core.inProcessProvider(p.manifest);
1388
- return {
1389
- id: p.manifest.name,
1390
- name: p.manifest.displayName,
1391
- enabled: enabled.has(p.manifest.name),
1392
- ...usable ? {} : { usable: false, ...reason ? { reason } : {} },
1393
- ...auth ? { auth } : {},
1394
- ...version ? { version } : {},
1395
- // Read from the same record and discovery answer the write checks
1396
- // read (`refuseBlockedRunner`), so the list and the refusal agree.
1397
- readiness: core.runnerReadiness(usability, unlisted[p.manifest.name]),
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 } } : {},
1400
- ...provider ? { provider } : {}
1401
- };
1402
- })
1403
- );
1404
+ return (await judged).map(({ p, usability }) => {
1405
+ const { usable, reason, auth, version } = usability;
1406
+ const provider = core.inProcessProvider(p.manifest);
1407
+ return {
1408
+ id: p.manifest.name,
1409
+ name: p.manifest.displayName,
1410
+ enabled: enabled.has(p.manifest.name),
1411
+ ...usable ? {} : { usable: false, ...reason ? { reason } : {} },
1412
+ ...auth ? { auth } : {},
1413
+ ...version ? { version } : {},
1414
+ // Read from the same record and discovery answer the write checks
1415
+ // read (`refuseBlockedRunner`), so the list and the refusal agree.
1416
+ readiness: core.runnerReadiness(usability, unlisted[p.manifest.name]),
1417
+ plans: core.runnerPlans(p.manifest.name),
1418
+ ...p.manifest.account ? { account: { runner: p.manifest.account.runner, id: p.manifest.account.id, runnerId: p.manifest.name, label: p.manifest.account.label } } : {},
1419
+ ...provider ? { provider } : {}
1420
+ };
1421
+ });
1404
1422
  }
1405
1423
  async generatePlan(sessionId, goal, runners, workspace, modelOverride) {
1406
1424
  const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
@@ -1511,6 +1529,7 @@ var OrchestratorPool = class {
1511
1529
  }
1512
1530
  }
1513
1531
  async enableRunner(id, enabled, workspace) {
1532
+ if (this.enabledRunnerOverride() === void 0) await core.installedPlannerDetected();
1514
1533
  const on = new WebConfig({ enabledRunners: this.enabledRunnerOverride() }).enabledRunners.includes(id);
1515
1534
  if (enabled && !on) await this.refuseBlockedRunner(id, workspace);
1516
1535
  this.setRunnerEnabled(id, enabled);
@@ -2486,7 +2505,9 @@ function runnersRoute(pool) {
2486
2505
  try {
2487
2506
  const workspace = c.req.query("workspace");
2488
2507
  const recheck = c.req.query("recheck")?.split(",").filter(Boolean);
2489
- const runners = await pool.getInstalledRunners(workspace, ...recheck?.length ? [{ recheck }] : []);
2508
+ const cached2 = c.req.query("cached") === "1";
2509
+ const options = { ...recheck?.length ? { recheck } : {}, ...cached2 ? { cached: cached2 } : {} };
2510
+ const runners = await pool.getInstalledRunners(workspace, ...Object.keys(options).length ? [options] : []);
2490
2511
  await pool.discoverPlannerCatalogs(void 0, workspace);
2491
2512
  const state = pool.getRunnerState(workspace);
2492
2513
  return c.json({
@@ -2499,7 +2520,6 @@ function runnersRoute(pool) {
2499
2520
  });
2500
2521
  router.put("/:id", async (c) => {
2501
2522
  try {
2502
- await core.installedPlannerDetected();
2503
2523
  const id = c.req.param("id");
2504
2524
  const { enabled } = await jsonObject(c);
2505
2525
  if (typeof enabled !== "boolean") return refuse(c, 400, "enabled must be true or false");
@@ -2693,7 +2713,7 @@ function settingsRoute(pool) {
2693
2713
  });
2694
2714
  router.get("/", async (c) => {
2695
2715
  try {
2696
- await core.installedPlannerDetected();
2716
+ if (!core.isPlannerBackend(process.env.AI_PROVIDER ?? "")) await core.installedPlannerDetected();
2697
2717
  const sessionId = c.req.query("sessionId") || void 0;
2698
2718
  const workspace = c.req.query("workspace") || void 0;
2699
2719
  await pool.discoverPlannerCatalogs(sessionId, workspace);
@@ -3314,6 +3334,7 @@ function runDaemon(args) {
3314
3334
  let ownsPidFile = false;
3315
3335
  core.processLeaseHost().describe(daemonHostKind(args, port));
3316
3336
  loadSavedCredentials();
3337
+ loadSavedPlannerChoice();
3317
3338
  const pool = new OrchestratorPool({ runner: new core.StructuredRunner() });
3318
3339
  void pool.detectInstalledPlanner();
3319
3340
  const server = http.createServer();