@ordewell/web 0.15.4 → 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.
- package/dist/server/main.js +94 -38
- package/dist/server/main.js.map +1 -1
- package/package.json +2 -2
package/dist/server/main.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
1375
|
-
|
|
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
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
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);
|
|
@@ -1570,7 +1589,27 @@ var OrchestratorPool = class {
|
|
|
1570
1589
|
async startPlanning(sessionId, goal, runners, workspace, modelOverride, options) {
|
|
1571
1590
|
const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
|
|
1572
1591
|
const session = opening instanceof Promise ? await opening : opening;
|
|
1573
|
-
return this.firstTurn(sessionId, session, () => session.startPlanning(goal, runners,
|
|
1592
|
+
return this.firstTurn(sessionId, session, () => session.startPlanning(goal, runners, options));
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Planning nobody watches (ADR-0083): resolved once the goal is admitted,
|
|
1596
|
+
* past the planner and runner refusals, while its first turn runs on asking
|
|
1597
|
+
* nobody. How the turn ends is the session's to keep, as an opening that
|
|
1598
|
+
* fails keeps its failure in the transcript, so nothing here waits for it.
|
|
1599
|
+
* Worded for the command line: the person runs the plan with `ordewell run`.
|
|
1600
|
+
*/
|
|
1601
|
+
async startUnattendedPlanning(sessionId, goal, runners, workspace) {
|
|
1602
|
+
let admitted = () => void 0;
|
|
1603
|
+
const opened = new Promise((resolve3) => {
|
|
1604
|
+
admitted = resolve3;
|
|
1605
|
+
});
|
|
1606
|
+
const planning = this.startPlanning(sessionId, goal, runners, workspace, void 0, { surface: "cli", unattended: true, admitted });
|
|
1607
|
+
planning.catch(() => void 0);
|
|
1608
|
+
await Promise.race([opened, planning.then(() => void 0)]);
|
|
1609
|
+
}
|
|
1610
|
+
/** The workspaces of the sessions this daemon holds. */
|
|
1611
|
+
workspacesHeld() {
|
|
1612
|
+
return [...new Set(this.sessionWorkspaces.values())];
|
|
1574
1613
|
}
|
|
1575
1614
|
/**
|
|
1576
1615
|
* Continue the planner dialogue with the user's reply: queued behind the
|
|
@@ -2137,6 +2176,21 @@ function plansRoute(pool) {
|
|
|
2137
2176
|
return failure(c, err, "generate", { message: "Plan generation failed" });
|
|
2138
2177
|
}
|
|
2139
2178
|
});
|
|
2179
|
+
router.post("/:sessionId/start", async (c) => {
|
|
2180
|
+
try {
|
|
2181
|
+
const { goal, runners, workspace, ancestry } = await jsonObject(c);
|
|
2182
|
+
if (typeof goal !== "string" || !goal.trim()) return c.json({ error: "goal is required" }, 400);
|
|
2183
|
+
const ws = typeof workspace === "string" && workspace || c.req.query("workspace") || process.cwd();
|
|
2184
|
+
const runnerList = Array.isArray(runners) && runners.every((r) => typeof r === "string") ? runners : void 0;
|
|
2185
|
+
const groups = core.liveRunnerGroups([ws, ...pool.workspacesHeld(), ...scanWorkspaces2()]);
|
|
2186
|
+
if (core.callerInRunnerGroup(core.parseCallerAncestry(ancestry), groups)) return refuse(c, 403, core.RUNNER_PLAN_REFUSAL, "refused");
|
|
2187
|
+
const sessionId = c.req.param("sessionId");
|
|
2188
|
+
await pool.startUnattendedPlanning(sessionId, goal, runnerList, ws);
|
|
2189
|
+
return c.json({ sessionId });
|
|
2190
|
+
} catch (err) {
|
|
2191
|
+
return failure(c, err, "start planning", { message: "Planning failed" });
|
|
2192
|
+
}
|
|
2193
|
+
});
|
|
2140
2194
|
router.post("/:sessionId/execute", async (c) => {
|
|
2141
2195
|
try {
|
|
2142
2196
|
const session = pool.session(c.req.param("sessionId"), callerWorkspace(c));
|
|
@@ -2451,7 +2505,9 @@ function runnersRoute(pool) {
|
|
|
2451
2505
|
try {
|
|
2452
2506
|
const workspace = c.req.query("workspace");
|
|
2453
2507
|
const recheck = c.req.query("recheck")?.split(",").filter(Boolean);
|
|
2454
|
-
const
|
|
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] : []);
|
|
2455
2511
|
await pool.discoverPlannerCatalogs(void 0, workspace);
|
|
2456
2512
|
const state = pool.getRunnerState(workspace);
|
|
2457
2513
|
return c.json({
|
|
@@ -2464,7 +2520,6 @@ function runnersRoute(pool) {
|
|
|
2464
2520
|
});
|
|
2465
2521
|
router.put("/:id", async (c) => {
|
|
2466
2522
|
try {
|
|
2467
|
-
await core.installedPlannerDetected();
|
|
2468
2523
|
const id = c.req.param("id");
|
|
2469
2524
|
const { enabled } = await jsonObject(c);
|
|
2470
2525
|
if (typeof enabled !== "boolean") return refuse(c, 400, "enabled must be true or false");
|
|
@@ -2658,7 +2713,7 @@ function settingsRoute(pool) {
|
|
|
2658
2713
|
});
|
|
2659
2714
|
router.get("/", async (c) => {
|
|
2660
2715
|
try {
|
|
2661
|
-
await core.installedPlannerDetected();
|
|
2716
|
+
if (!core.isPlannerBackend(process.env.AI_PROVIDER ?? "")) await core.installedPlannerDetected();
|
|
2662
2717
|
const sessionId = c.req.query("sessionId") || void 0;
|
|
2663
2718
|
const workspace = c.req.query("workspace") || void 0;
|
|
2664
2719
|
await pool.discoverPlannerCatalogs(sessionId, workspace);
|
|
@@ -3279,6 +3334,7 @@ function runDaemon(args) {
|
|
|
3279
3334
|
let ownsPidFile = false;
|
|
3280
3335
|
core.processLeaseHost().describe(daemonHostKind(args, port));
|
|
3281
3336
|
loadSavedCredentials();
|
|
3337
|
+
loadSavedPlannerChoice();
|
|
3282
3338
|
const pool = new OrchestratorPool({ runner: new core.StructuredRunner() });
|
|
3283
3339
|
void pool.detectInstalledPlanner();
|
|
3284
3340
|
const server = http.createServer();
|