@ordewell/web 0.15.1 → 0.15.3

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
@@ -32,8 +32,13 @@ record of who built what, rather than `git log`.
32
32
  - Hanbin Tan ([@hskl18](https://github.com/hskl18)) — documented how
33
33
  planners and runners get their models and credentials (#140) and added Pi
34
34
  as a runner and harness planner (#78).
35
+ - [@nabeelbaghoor](https://github.com/nabeelbaghoor) — added a Planning indicator to
36
+ the open session in the sessions sidebar (#256).
35
37
 
36
38
  - [@torialfaro](https://github.com/torialfaro) and [@aavykyy](https://github.com/aavykyy) — made VS Code task prompts keyboard accessible (#141).
39
+ - **Harmit Patel** ([@Harmit3](https://github.com/Harmit3)) — added tests for the
40
+ wall-clock time helpers (#269) and made a mistyped CLI command suggest the
41
+ closest one (#271).
37
42
 
38
43
  Thank you. Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
39
44
 
@@ -227,6 +227,22 @@ var WebConfig = class extends core.BaseConfig {
227
227
  return out.length > 0 ? out : [...core.DEFAULT_RUNNERS];
228
228
  }
229
229
  };
230
+
231
+ // server/adapters/daemonPlannerChoice.ts
232
+ var PLANNER_CHOICE_ENV = ["AI_PROVIDER", "ORCHESTRATOR_MODEL", "ORDEWELL_PLANNER_EFFORT"];
233
+ function daemonPlannerChoice(opts) {
234
+ return {
235
+ current: () => opts.config().planner,
236
+ savedProvider: () => process.env.AI_PROVIDER ?? "",
237
+ save: ({ provider, model, effort }) => {
238
+ if (provider !== void 0) process.env.AI_PROVIDER = provider;
239
+ if (model !== void 0) process.env.ORCHESTRATOR_MODEL = model;
240
+ if (effort !== void 0) process.env.ORDEWELL_PLANNER_EFFORT = effort;
241
+ },
242
+ notePick: opts.notePick,
243
+ memory: opts.memory
244
+ };
245
+ }
230
246
  function scanWorkspacesImpl(deps) {
231
247
  const { fsModule, pathModule, cwd, home, projectDir } = deps;
232
248
  const paths = /* @__PURE__ */ new Set();
@@ -633,11 +649,12 @@ var OrchestratorPool = class {
633
649
  */
634
650
  pickedModel;
635
651
  /**
636
- * The last planner write a route made, so each lands after the ones made
637
- * before it: a switch still waiting for its catalog must not write over a
638
- * pick made while it waited (ADR-0040).
652
+ * Every planner change, in every workspace, lands after the ones made
653
+ * before it: the environment it writes is the daemon's one, and a switch
654
+ * still waiting for its catalog must not write over a pick made while it
655
+ * waited (ADR-0040).
639
656
  */
640
- plannerWrites = Promise.resolve();
657
+ plannerChanges = new core.PlannerChangeApplier();
641
658
  runner;
642
659
  /** One probe per daemon, asked again whenever the runner list is refreshed (ADR-0033). */
643
660
  codexSandbox;
@@ -994,6 +1011,8 @@ var OrchestratorPool = class {
994
1011
  broadcast,
995
1012
  // The notification channel above is silent here; this is how a client hears how the run isolates.
996
1013
  onNotice: (notice) => this.broadcast(sessionId, workspace, notice),
1014
+ // The planner gate asks a signed-out planner again with this workspace's own probe (ADR-0052).
1015
+ signIn: this.sessionSignIn(workspace),
997
1016
  modelResolver: this.resolverFor(workspace),
998
1017
  settings: () => this.runtimeSettings(),
999
1018
  sessionId,
@@ -1137,38 +1156,31 @@ var OrchestratorPool = class {
1137
1156
  await this.discoverUnheld(workspace, consulted);
1138
1157
  }
1139
1158
  /**
1140
- * {@link updateSettings} as a route makes it. A write that changes who plans
1141
- * lands after the planner writes made before it and, where its judgement
1142
- * reads a catalog not yet held, waits for that one; every other write — a
1143
- * key, an allowlist, a limit — lands at once (ADR-0040).
1159
+ * Save a settings write, as a route makes it. A write that changes who
1160
+ * plans goes through the planner-change rule, after the planner changes
1161
+ * made before it, waiting for a catalog only where it decides the answer;
1162
+ * every other write (a key, an allowlist, a limit) lands at once (ADR-0040).
1144
1163
  */
1145
1164
  async writeSettings(changes2, sessionId, requestWorkspace) {
1146
1165
  const change = plannerChangeOf(changes2, admittedEnv(changes2)?.accepted);
1147
- if (!changesPlanner(change)) return this.updateSettings(changes2, sessionId, requestWorkspace);
1148
- const turn = this.plannerWrites.then(async () => {
1149
- const workspace = this.settingsWorkspace(sessionId, requestWorkspace);
1150
- const judging = this.catalogJudging(change, workspace);
1151
- await this.discoverUnheld(workspace, judging ? [judging] : []);
1152
- const incoming = change.provider !== void 0 && change.provider !== this.plannerProviderInEffect(workspace) ? core.runnerForProvider(change.provider) : void 0;
1153
- if (incoming) await this.refuseBlockedRunner(incoming, workspace);
1154
- return this.updateSettings(changes2, sessionId, requestWorkspace);
1155
- });
1156
- this.plannerWrites = turn.catch(() => void 0);
1157
- return turn;
1166
+ if (!changesPlanner(change)) return this.saveSettings(changes2, sessionId, requestWorkspace);
1167
+ const workspace = this.settingsWorkspace(sessionId, requestWorkspace);
1168
+ const selection = await this.plannerChanges.apply(change, this.plannerChangeHost(workspace));
1169
+ return this.saveSettings(changes2, sessionId, requestWorkspace, selection);
1158
1170
  }
1159
- /**
1160
- * The provider whose catalog `selectPlanner` reads to judge `change`: a
1161
- * switch with no model of its own restores the remembered pick only from
1162
- * the incoming catalog, and an agent's effort alone survives only where its
1163
- * model in effect offers it. An explicit model is the user's word whatever
1164
- * the catalog lists, and a cold catalog refuses no effort, so it reads none.
1165
- */
1166
- catalogJudging(change, workspace) {
1167
- const current = this.plannerProviderInEffect(workspace);
1168
- const provider = change.provider ?? current;
1169
- const model = change.model?.trim();
1170
- if (provider !== current) return model ? void 0 : provider;
1171
- return model === void 0 && change.effort !== void 0 && core.runnerForProvider(provider) ? provider : void 0;
1171
+ /** Where a planner change in `workspace` reads its state and catalogs, and saves its answer. */
1172
+ plannerChangeHost(workspace) {
1173
+ return {
1174
+ store: daemonPlannerChoice({
1175
+ config: () => this.plannerConfig(void 0, workspace),
1176
+ memory: this.plannerModelMemory,
1177
+ notePick: (model, provider) => {
1178
+ this.pickedModel = { model, provider, workspace: workspaceKey(workspace) };
1179
+ }
1180
+ }),
1181
+ catalogs: this.resolverFor(workspace),
1182
+ refuseBlockedRunner: (runner) => this.refuseBlockedRunner(runner, workspace)
1183
+ };
1172
1184
  }
1173
1185
  /**
1174
1186
  * Discover the catalogs of `providers` that `workspace`'s resolver does not
@@ -1180,26 +1192,20 @@ var OrchestratorPool = class {
1180
1192
  await Promise.all([...new Set(providers)].map((provider) => resolver.plannerCatalog(provider)));
1181
1193
  }
1182
1194
  /**
1183
- * The provider planning right now. A vendor planner is resolved from its
1184
- * model id, so this is read again after a write rather than carried over.
1195
+ * Everything in a settings write but its planner change, which `selection`
1196
+ * says was already applied: the planner's own variables are then the rule's
1197
+ * to write, not the body's.
1185
1198
  */
1186
- plannerProviderInEffect(workspace) {
1187
- return this.plannerConfig(void 0, workspace).aiProvider;
1188
- }
1189
- updateSettings(changes2, sessionId, requestWorkspace) {
1199
+ saveSettings(changes2, sessionId, requestWorkspace, selection) {
1190
1200
  const workspace = this.settingsWorkspace(sessionId, requestWorkspace);
1191
- const current = this.plannerConfig(void 0, workspace).planner;
1192
1201
  const admission = admittedEnv(changes2);
1193
1202
  const envChanges = admission ? admission.accepted : void 0;
1194
- const plannerChange = plannerChangeOf(changes2, envChanges);
1195
- const selection = changesPlanner(plannerChange) ? core.selectPlanner(current, plannerChange, this.plannerModelMemory, this.plannerCatalogFor(plannerChange.provider ?? current.provider, workspace)) : void 0;
1196
- const agentPick = selection?.remember && selection.remember.provider === current.provider && core.isAgentPick(current.provider, selection.remember.model) ? selection.remember : void 0;
1197
- if (agentPick) this.plannerModelMemory.remember(agentPick.provider, agentPick.model, agentPick.effort);
1198
1203
  let unsavedEnvKeys = [];
1199
1204
  if (envChanges) {
1200
1205
  let touched = false;
1201
1206
  let saved = false;
1202
1207
  for (const [key, value] of Object.entries(envChanges)) {
1208
+ if (selection && isPlannerChoiceEnv(key)) continue;
1203
1209
  if (core.removesCredential(key, value)) delete process.env[key];
1204
1210
  else process.env[key] = value;
1205
1211
  if (core.PROVIDER_CREDENTIAL_ENV.has(key)) touched = true;
@@ -1220,13 +1226,6 @@ var OrchestratorPool = class {
1220
1226
  for (const installation of /* @__PURE__ */ new Set([this.runnerInstallation, ...this.workspaceInstallations.values()])) installation.refresh?.();
1221
1227
  }
1222
1228
  }
1223
- if (selection) {
1224
- if (plannerChange.provider !== void 0 || plannerChange.model !== void 0) process.env.ORCHESTRATOR_MODEL = selection.next.model;
1225
- process.env.ORDEWELL_PLANNER_EFFORT = selection.next.effort;
1226
- if (plannerChange.model !== void 0) {
1227
- this.pickedModel = { model: selection.next.model, provider: this.plannerProviderInEffect(workspace), workspace: workspaceKey(workspace) };
1228
- }
1229
- }
1230
1229
  if (changes2.modelAllowlist && typeof changes2.modelAllowlist === "object") {
1231
1230
  const allowlist = changes2.modelAllowlist;
1232
1231
  for (const [runner, ids] of Object.entries(allowlist)) {
@@ -1241,11 +1240,6 @@ var OrchestratorPool = class {
1241
1240
  this.settingsService.setAutonomousMode(changes2.autonomousMode);
1242
1241
  }
1243
1242
  if (envChanges) for (const monitor of this.accountLimits.values()) monitor.refresh();
1244
- if (selection?.remember && !agentPick) {
1245
- const { provider, model, effort } = selection.remember;
1246
- const switched = provider !== current.provider;
1247
- this.plannerModelMemory.remember(switched ? provider : this.plannerProviderInEffect(workspace), model, effort);
1248
- }
1249
1243
  const rejectedEnvKeys = admission?.rejected ?? [];
1250
1244
  const settings = this.getSettings(sessionId, workspace);
1251
1245
  if (rejectedEnvKeys.length > 0) settings.rejectedEnvKeys = rejectedEnvKeys;
@@ -1401,9 +1395,8 @@ var OrchestratorPool = class {
1401
1395
  );
1402
1396
  }
1403
1397
  async generatePlan(sessionId, goal, runners, workspace, modelOverride) {
1404
- const recheck = this.recheckSignedOutPlanner(workspace, this.plannerConfig(modelOverride, workspace).aiProvider);
1405
- if (recheck) await recheck;
1406
- const session = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
1398
+ const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
1399
+ const session = opening instanceof Promise ? await opening : opening;
1407
1400
  return core.migratePlanState(await this.firstTurn(sessionId, session, () => session.generatePlan(goal, runners)));
1408
1401
  }
1409
1402
  /**
@@ -1441,20 +1434,16 @@ var OrchestratorPool = class {
1441
1434
  if (enabled && !on) await this.refuseBlockedRunner(id, workspace);
1442
1435
  this.setRunnerEnabled(id, enabled);
1443
1436
  }
1437
+ /** The probe and the catalog that judge `workspace`'s account, for {@link recheckRunnerSignIn} and a pick's judgment. */
1444
1438
  /**
1445
- * Judge the planner as the workspace's account is now, not as it was when the
1446
- * list was last read: the signed-out refusal itself offers the runner's own
1447
- * `auth login` as a way back, and that happens in another process. Only a
1448
- * recorded signed-out verdict is asked again — unknown never blocks, and a
1449
- * signed-in one is the runner's own failure to report. Null when there is
1450
- * nothing to ask, so the turn registers at once as it always did.
1439
+ * How a session's planner gate asks again in `workspace`, and a child's in
1440
+ * its own worktree. A worktree's probe and resolver view are the pool's, kept
1441
+ * for its lifetime as a root workspace's are: a child's end never lets them
1442
+ * go, since a Session may still be opening there, its probe out.
1451
1443
  */
1452
- recheckSignedOutPlanner(workspace, provider) {
1453
- const runner = core.runnerForProvider(provider);
1454
- if (!runner || core.recordedRunnerAuth(runner, workspace)?.state !== "signed-out") return null;
1455
- return core.verifyRunnerSignIn(runner, this.signInCheck(workspace)).then(() => void 0);
1444
+ sessionSignIn(workspace) {
1445
+ return { installation: this.signInCheck(workspace).installation, at: (child) => this.sessionSignIn(child) };
1456
1446
  }
1457
- /** The probe and the catalog that judge `workspace`'s account, for {@link verifyRunnerSignIn} and {@link recheckRunnerSignIn}. */
1458
1447
  signInCheck(workspace) {
1459
1448
  const installation = this.installationFor(workspace);
1460
1449
  return {
@@ -1470,10 +1459,18 @@ var OrchestratorPool = class {
1470
1459
  /**
1471
1460
  * Build the session a new planning conversation runs in and register it in
1472
1461
  * place of any live one, for {@link firstTurn} to run its first turn on.
1462
+ * A planner recorded signed out is asked again first, as the first turn's
1463
+ * gate would ask it (ADR-0052), since the judgment below comes before that
1464
+ * gate; with nothing to ask the session is registered in this tick.
1473
1465
  */
1474
1466
  openPlanningSession(sessionId, runners, workspace, modelOverride) {
1475
1467
  this.live(sessionId, workspace);
1476
1468
  const session = this.createSessionFor(sessionId, workspace, modelOverride);
1469
+ const asking = core.installedPlannerAnswered() ? session.askPlannerSignIn() : null;
1470
+ return asking ? asking.then(() => this.seatPlanningSession(sessionId, runners, workspace, session)) : this.seatPlanningSession(sessionId, runners, workspace, session);
1471
+ }
1472
+ seatPlanningSession(sessionId, runners, workspace, session) {
1473
+ this.live(sessionId, workspace);
1477
1474
  if (core.installedPlannerAnswered()) {
1478
1475
  session.assertPlannerReady();
1479
1476
  session.assertRunnersEnabled(runners);
@@ -1490,49 +1487,39 @@ var OrchestratorPool = class {
1490
1487
  * assistant message lives in conversationHistory).
1491
1488
  */
1492
1489
  async startPlanning(sessionId, goal, runners, workspace, modelOverride, options) {
1493
- const recheck = this.recheckSignedOutPlanner(workspace, this.plannerConfig(modelOverride, workspace).aiProvider);
1494
- if (recheck) await recheck;
1495
- const session = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
1490
+ const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
1491
+ const session = opening instanceof Promise ? await opening : opening;
1496
1492
  return this.firstTurn(sessionId, session, () => session.startPlanning(goal, runners, { surface: options?.surface }));
1497
1493
  }
1498
1494
  /**
1499
1495
  * Continue the planner dialogue with the user's reply: queued behind the
1500
1496
  * first turn, even while it waits for the installed-planner probe, and
1501
1497
  * refused only while a turn of another kind holds the conversation. The
1502
- * session's own planner gate waits for the probe and judges the planner, as
1503
- * it does for every turn.
1498
+ * session's own planner gate waits for the probe, asks a planner recorded
1499
+ * signed out again, and judges the planner, as it does for every turn.
1504
1500
  */
1505
1501
  async continuePlanning(sessionId, message, workspace, surface) {
1506
1502
  const session = this.session(sessionId, workspace);
1507
- const recheck = this.recheckSignedOutPlanner(session.workspaceRoot, session.plannerProvider);
1508
- if (recheck) await recheck;
1509
1503
  return session.continueConversation(message, { surface });
1510
1504
  }
1511
1505
  /** Condense a session's conversation. The summary turn is a planner turn, so `cancelPlanning` stops it. */
1512
1506
  async compactConversation(sessionId, workspace) {
1513
1507
  const session = this.session(sessionId, workspace);
1514
- const recheck = this.recheckSignedOutPlanner(session.workspaceRoot, session.plannerProvider);
1515
- if (recheck) await recheck;
1516
1508
  const compaction = await session.compactConversation();
1517
1509
  return { ...compaction, plan: session.planState };
1518
1510
  }
1519
1511
  /**
1520
1512
  * Send now (ADR-0023): the Session stops the planner turn in flight and
1521
1513
  * answers this message in the turn that replaces it, ahead of anything
1522
- * waiting. The recheck is the one a reply does before the gate: a login done
1523
- * with the runner's own command is seen here too.
1514
+ * waiting.
1524
1515
  */
1525
1516
  async forceSendPrompt(sessionId, message, workspace, surface) {
1526
1517
  const session = this.session(sessionId, workspace);
1527
- const recheck = this.recheckSignedOutPlanner(session.workspaceRoot, session.plannerProvider);
1528
- if (recheck) await recheck;
1529
1518
  return session.forceSendPrompt(message, { surface });
1530
1519
  }
1531
1520
  /** Retry a compaction paused on the planner's context: a planner turn, and gated as one. */
1532
1521
  async retryPlannerCompaction(sessionId, workspace) {
1533
1522
  const session = this.session(sessionId, workspace);
1534
- const recheck = this.recheckSignedOutPlanner(session.workspaceRoot, session.plannerProvider);
1535
- if (recheck) await recheck;
1536
1523
  return session.retryPlannerCompaction();
1537
1524
  }
1538
1525
  /**
@@ -1681,6 +1668,9 @@ function plannerChangeOf(changes2, envChanges) {
1681
1668
  function changesPlanner(change) {
1682
1669
  return Object.values(change).some((v) => v !== void 0);
1683
1670
  }
1671
+ function isPlannerChoiceEnv(key) {
1672
+ return PLANNER_CHOICE_ENV.includes(key);
1673
+ }
1684
1674
  function stringField(value) {
1685
1675
  return typeof value === "string" ? value : void 0;
1686
1676
  }