@ordewell/web 0.12.5 → 0.13.0
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 +542 -217
- package/dist/server/main.js.map +1 -1
- package/package.json +2 -2
package/dist/server/main.js
CHANGED
|
@@ -70,6 +70,16 @@ function classify(err) {
|
|
|
70
70
|
if (err instanceof core.PlannerTurnStoppedError) return { status: 409, code: "planner_turn_stopped" };
|
|
71
71
|
if (err instanceof core.PlannerTurnDiscardedError) return { status: 409, code: "planner_turn_discarded" };
|
|
72
72
|
if (err instanceof core.ConversationBusyError) return { status: 409, code: "conversation_busy" };
|
|
73
|
+
if (err instanceof core.WorkspaceReadError) {
|
|
74
|
+
if (err.code === "gone") return { status: 410, code: "gone" };
|
|
75
|
+
if (err.code === "path_refused") return { status: 403, code: "path_refused" };
|
|
76
|
+
if (err.code === "path_not_found") return { status: 404, code: "path_not_found" };
|
|
77
|
+
return { status: 400, code: "refused" };
|
|
78
|
+
}
|
|
79
|
+
if (err instanceof core.UserGitError) {
|
|
80
|
+
if (err.code === "landing_branch_held" || err.code === "confirm_stale" || err.code === "stale") return { status: 409, code: err.code };
|
|
81
|
+
return { status: 400, code: err.code };
|
|
82
|
+
}
|
|
73
83
|
if (err instanceof core.ConversationEditError || err instanceof core.PlanEditError || err instanceof core.TaskControlError) {
|
|
74
84
|
return { status: 400, code: "refused" };
|
|
75
85
|
}
|
|
@@ -88,7 +98,9 @@ function failure(c, err, label, { fallback = 500, message = "Internal error" } =
|
|
|
88
98
|
...classified ? { code: classified.code } : {},
|
|
89
99
|
...err instanceof core.WorkspaceNotAProjectError ? { workspace: err.workspace } : {},
|
|
90
100
|
...err instanceof core.PlannerNotReadyError ? { plannerNotReady: err.reason } : {},
|
|
91
|
-
...err instanceof core.SessionHeldError ? { sessionHeld: err.held } : {}
|
|
101
|
+
...err instanceof core.SessionHeldError ? { sessionHeld: err.held } : {},
|
|
102
|
+
...err instanceof core.UserGitError && err.detail.held ? { landingBranchHeld: err.detail.held } : {},
|
|
103
|
+
...err instanceof core.UserGitError && err.detail.difference ? { confirmStale: err.detail.difference } : {}
|
|
92
104
|
};
|
|
93
105
|
return c.json(body, status);
|
|
94
106
|
}
|
|
@@ -101,14 +113,14 @@ var CONTROL_REFUSALS = {
|
|
|
101
113
|
no_task: { status: 404, code: "child_task_not_found" },
|
|
102
114
|
not_waiting: { status: 409, code: "checkpoint_not_waiting" }
|
|
103
115
|
};
|
|
104
|
-
function childrenRoute(
|
|
116
|
+
function childrenRoute(pool) {
|
|
105
117
|
const router = new hono.Hono();
|
|
106
118
|
const childOf = async (c) => {
|
|
107
|
-
const child = await
|
|
119
|
+
const child = await pool.session(c.req.param("id")).children.find(c.req.param("childId"));
|
|
108
120
|
if (!child) throw new ChildNotFoundError();
|
|
109
121
|
return child;
|
|
110
122
|
};
|
|
111
|
-
const position = (c) =>
|
|
123
|
+
const position = (c) => pool.childPosition(c.req.param("id"), c.req.param("childId"));
|
|
112
124
|
const controlled = (c, outcome) => {
|
|
113
125
|
if (!outcome.ok) return refuse(c, CONTROL_REFUSALS[outcome.code].status, outcome.message, CONTROL_REFUSALS[outcome.code].code);
|
|
114
126
|
return c.json({ message: outcome.message, ...outcome.id ? { id: outcome.id } : {} });
|
|
@@ -116,7 +128,7 @@ function childrenRoute(pool2) {
|
|
|
116
128
|
const asksAboveItsPlan = (body) => "raiseTokens" in body || "force" in body;
|
|
117
129
|
router.get("/:id/children", async (c) => {
|
|
118
130
|
try {
|
|
119
|
-
return c.json({ children: await
|
|
131
|
+
return c.json({ children: await pool.session(c.req.param("id")).children.list() });
|
|
120
132
|
} catch (err) {
|
|
121
133
|
return failure(c, err, "list child plans");
|
|
122
134
|
}
|
|
@@ -356,24 +368,30 @@ function scanWorkspacesImpl(deps) {
|
|
|
356
368
|
} catch {
|
|
357
369
|
}
|
|
358
370
|
}
|
|
359
|
-
|
|
371
|
+
const hidden = projectDir === void 0 ? void 0 : pathModule.resolve(projectDir);
|
|
372
|
+
return [...paths].filter((p) => p !== hidden).sort();
|
|
360
373
|
}
|
|
361
|
-
function scanWorkspaces() {
|
|
374
|
+
function scanWorkspaces(sea = {}) {
|
|
362
375
|
return scanWorkspacesImpl({
|
|
363
376
|
fsModule: fs__namespace,
|
|
364
377
|
pathModule: path__namespace,
|
|
365
378
|
cwd: process.cwd(),
|
|
366
379
|
// Not HOME, which Windows does not set: os.homedir() reads USERPROFILE there.
|
|
367
380
|
home: os__namespace.homedir(),
|
|
368
|
-
|
|
381
|
+
// Four up from dist/server/ is the root of an Ordewell source checkout,
|
|
382
|
+
// whose own `.ordewell/` (its committed skills) is no workspace of the
|
|
383
|
+
// user's. The binary has no checkout: its `__dirname` is the executable's
|
|
384
|
+
// folder, and four up from there could be the home or a projects folder
|
|
385
|
+
// that does hold one, so nothing is hidden (ADR-0065 C2).
|
|
386
|
+
projectDir: core.isSea(sea) ? void 0 : path__namespace.resolve(__dirname, "..", "..", "..", "..")
|
|
369
387
|
});
|
|
370
388
|
}
|
|
371
389
|
var MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
372
390
|
var SEALED_OUTPUT_GRACE_MS = 1e3;
|
|
373
|
-
function run(file,
|
|
391
|
+
function run(file, args, opts) {
|
|
374
392
|
return new Promise((resolve3) => {
|
|
375
393
|
try {
|
|
376
|
-
const child = child_process.execFile(file,
|
|
394
|
+
const child = child_process.execFile(file, args, {
|
|
377
395
|
cwd: opts.cwd,
|
|
378
396
|
timeout: opts.timeout,
|
|
379
397
|
maxBuffer: MAX_OUTPUT_BYTES,
|
|
@@ -558,15 +576,15 @@ var PoolFileSystem = class _PoolFileSystem extends core.BaseFileSystem {
|
|
|
558
576
|
}
|
|
559
577
|
}
|
|
560
578
|
async execBashImpl(command, shell, signal, cwd) {
|
|
561
|
-
const { file, args
|
|
562
|
-
const result = file === null ? await run(command, [], { cwd, timeout: BASH_TIMEOUT_MS, shell: true, env, signal }) : await run(file, [...
|
|
579
|
+
const { file, args, env, wallTimeMs } = shell;
|
|
580
|
+
const result = file === null ? await run(command, [], { cwd, timeout: BASH_TIMEOUT_MS, shell: true, env, signal }) : await run(file, [...args, command], { cwd, timeout: wallTimeMs ?? BASH_TIMEOUT_MS, env, signal, sealed: wallTimeMs !== void 0 });
|
|
563
581
|
const out = (result.stdout || "").trim();
|
|
564
582
|
const err = (result.stderr || "").trim();
|
|
565
583
|
if (signal?.aborted) return { success: false, output: core.STOPPED_TOOL_RESULT, truncated: false };
|
|
566
584
|
if (result.code !== 0) {
|
|
567
585
|
const detail = err || out || `exited with code ${result.code}`;
|
|
568
586
|
return { success: false, output: `Command exited ${result.code}:
|
|
569
|
-
${
|
|
587
|
+
${core.headLines(detail, 2e4)}`, truncated: detail.length > 2e4, ...result.timedOut ? { timedOut: true } : {}, ...result.signal ? { signal: result.signal } : {} };
|
|
570
588
|
}
|
|
571
589
|
const combined = err ? `${out}
|
|
572
590
|
[stderr]
|
|
@@ -600,8 +618,8 @@ var PoolAwareRunner = class {
|
|
|
600
618
|
this.owned.add(session.id);
|
|
601
619
|
session.onExit(() => this.owned.delete(session.id));
|
|
602
620
|
this.broadcast({ type: "task_started", taskId: opts.taskId, order: opts.order ?? 0, title: opts.title ?? "", runner: opts.runner, modelId: opts.modelId });
|
|
603
|
-
session.onOutput((
|
|
604
|
-
this.broadcast({ type: "task_output", taskId: opts.taskId, text });
|
|
621
|
+
session.onOutput((text2) => {
|
|
622
|
+
this.broadcast({ type: "task_output", taskId: opts.taskId, text: text2 });
|
|
605
623
|
});
|
|
606
624
|
return session;
|
|
607
625
|
}
|
|
@@ -689,10 +707,10 @@ var OrchestratorPool = class {
|
|
|
689
707
|
this.accountLimitCollectors = deps.accountLimitCollectors ?? ((workspace) => {
|
|
690
708
|
const workspaceRoot = () => workspace;
|
|
691
709
|
const isInstalled = (runner) => async () => (await this.runnerInstallation.filterInstalled([runner])).includes(runner);
|
|
692
|
-
const
|
|
710
|
+
const server = this.registry.getManifest("codex")?.modelDiscovery.appServer;
|
|
693
711
|
return [
|
|
694
712
|
core.claudeAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("claude-code") }),
|
|
695
|
-
core.codexAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("codex"), command:
|
|
713
|
+
core.codexAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("codex"), command: server?.command, args: server?.args }),
|
|
696
714
|
core.openCodeGoAccountLimitCollector({ workspaceRoot, isInstalled: isInstalled("opencode") })
|
|
697
715
|
];
|
|
698
716
|
});
|
|
@@ -830,6 +848,33 @@ var OrchestratorPool = class {
|
|
|
830
848
|
hasSession(sessionId) {
|
|
831
849
|
return this.sessions.has(sessionId);
|
|
832
850
|
}
|
|
851
|
+
/** The session open here under this id for this workspace, if any: an id names a session only within its workspace. */
|
|
852
|
+
heldHere(sessionId, workspace) {
|
|
853
|
+
const held = this.sessionWorkspaces.get(sessionId);
|
|
854
|
+
return held !== void 0 && path.resolve(held) === path.resolve(workspace) ? this.sessions.get(sessionId) : void 0;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Whether a session's run holds its landing branch (ADR-0062 G7): this
|
|
858
|
+
* host's own word for a session open here; for one another live host holds,
|
|
859
|
+
* that host's word in its lease record, or the saved record where the holder
|
|
860
|
+
* says nothing; and for one nobody holds, nothing is at work.
|
|
861
|
+
*/
|
|
862
|
+
userRunIsLive(sessionId, workspace, plan) {
|
|
863
|
+
const session = this.heldHere(sessionId, workspace);
|
|
864
|
+
if (session) return session.runIsLive;
|
|
865
|
+
const held = (this.leaseHost ?? core.processLeaseHost()).peek(sessionId, workspace);
|
|
866
|
+
return held !== null && (held.holder.runLive === true || core.savedRunLooksLive(plan));
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* A user git action into the session's timeline (ADR-0062 G6): straight in
|
|
870
|
+
* for a session open here, else left in its directory for whichever host
|
|
871
|
+
* holds it, or next opens it, to fold (ADR-0049 L5).
|
|
872
|
+
*/
|
|
873
|
+
recordUserAction(sessionId, workspace, text2) {
|
|
874
|
+
const session = this.heldHere(sessionId, workspace);
|
|
875
|
+
if (session?.planState) session.recordUserAction(text2);
|
|
876
|
+
else core.appendUserAction(sessionId, workspace, { text: text2, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
877
|
+
}
|
|
833
878
|
/** Answer an approval prompt, the planner's or a task runner's. False means the id was unknown or already settled. */
|
|
834
879
|
resolveApproval(sessionId, approvalId, answer) {
|
|
835
880
|
return this.sessions.get(sessionId)?.resolveApproval(approvalId, answer) ?? false;
|
|
@@ -843,6 +888,13 @@ var OrchestratorPool = class {
|
|
|
843
888
|
isExecuting(sessionId) {
|
|
844
889
|
return this.sessions.get(sessionId)?.isExecuting ?? false;
|
|
845
890
|
}
|
|
891
|
+
/** Work under way in any session held here, which stopping this daemon would cut off: a run not settled, or a planner turn answering. */
|
|
892
|
+
workLive() {
|
|
893
|
+
for (const session of this.sessions.values()) {
|
|
894
|
+
if (session.runIsLive || session.plannerTurnId !== void 0) return true;
|
|
895
|
+
}
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
846
898
|
getPlan(sessionId) {
|
|
847
899
|
return this.sessions.get(sessionId)?.planState ?? null;
|
|
848
900
|
}
|
|
@@ -972,6 +1024,9 @@ var OrchestratorPool = class {
|
|
|
972
1024
|
// to render the current level; without it the picker shows "default"
|
|
973
1025
|
// for a planner that is running at "high".
|
|
974
1026
|
plannerThinkingEffort: config.plannerThinkingEffort ?? "",
|
|
1027
|
+
// The saved level, read through the service so an environment override
|
|
1028
|
+
// is reported the way the next plan will read it (ADR-0001, ADR-0030).
|
|
1029
|
+
autonomousMode: this.settingsService.autonomousMode(),
|
|
975
1030
|
maxParallel: config.maxParallelSessions,
|
|
976
1031
|
modelAllowlist: userSettings.modelAllowlist,
|
|
977
1032
|
// The model remembered per planner backend (this task), so a surface can
|
|
@@ -988,9 +1043,9 @@ var OrchestratorPool = class {
|
|
|
988
1043
|
* they were opened with. Throws a {@link RunSettingsError}, saving nothing,
|
|
989
1044
|
* for a value out of range.
|
|
990
1045
|
*/
|
|
991
|
-
updateRunSettings(
|
|
992
|
-
this.settingsService.updateRunSettings(
|
|
993
|
-
if (sessionId) this.sessions.get(sessionId)?.applyRunSettings(
|
|
1046
|
+
updateRunSettings(changes2, sessionId, workspace) {
|
|
1047
|
+
this.settingsService.updateRunSettings(changes2);
|
|
1048
|
+
if (sessionId) this.sessions.get(sessionId)?.applyRunSettings(changes2);
|
|
994
1049
|
return this.getSettings(sessionId, workspace);
|
|
995
1050
|
}
|
|
996
1051
|
/** The `containers` setting as a surface shows it: `prove` starts a throwaway container to measure (ADR-0059 L3). */
|
|
@@ -1052,14 +1107,14 @@ var OrchestratorPool = class {
|
|
|
1052
1107
|
* reads a catalog not yet held, waits for that one; every other write — a
|
|
1053
1108
|
* key, an allowlist, a limit — lands at once (ADR-0040).
|
|
1054
1109
|
*/
|
|
1055
|
-
async writeSettings(
|
|
1056
|
-
const change = plannerChangeOf(
|
|
1057
|
-
if (!changesPlanner(change)) return this.updateSettings(
|
|
1110
|
+
async writeSettings(changes2, sessionId, requestWorkspace) {
|
|
1111
|
+
const change = plannerChangeOf(changes2, admittedEnv(changes2)?.accepted);
|
|
1112
|
+
if (!changesPlanner(change)) return this.updateSettings(changes2, sessionId, requestWorkspace);
|
|
1058
1113
|
const turn = this.plannerWrites.then(async () => {
|
|
1059
1114
|
const workspace = this.settingsWorkspace(sessionId, requestWorkspace);
|
|
1060
1115
|
const judging = this.catalogJudging(change, workspace);
|
|
1061
1116
|
await this.discoverUnheld(workspace, judging ? [judging] : []);
|
|
1062
|
-
return this.updateSettings(
|
|
1117
|
+
return this.updateSettings(changes2, sessionId, requestWorkspace);
|
|
1063
1118
|
});
|
|
1064
1119
|
this.plannerWrites = turn.catch(() => void 0);
|
|
1065
1120
|
return turn;
|
|
@@ -1094,12 +1149,12 @@ var OrchestratorPool = class {
|
|
|
1094
1149
|
plannerProviderInEffect(workspace) {
|
|
1095
1150
|
return this.plannerConfig(void 0, workspace).aiProvider;
|
|
1096
1151
|
}
|
|
1097
|
-
updateSettings(
|
|
1152
|
+
updateSettings(changes2, sessionId, requestWorkspace) {
|
|
1098
1153
|
const workspace = this.settingsWorkspace(sessionId, requestWorkspace);
|
|
1099
1154
|
const current = this.plannerConfig(void 0, workspace).planner;
|
|
1100
|
-
const admission = admittedEnv(
|
|
1155
|
+
const admission = admittedEnv(changes2);
|
|
1101
1156
|
const envChanges = admission ? admission.accepted : void 0;
|
|
1102
|
-
const plannerChange = plannerChangeOf(
|
|
1157
|
+
const plannerChange = plannerChangeOf(changes2, envChanges);
|
|
1103
1158
|
const selection = changesPlanner(plannerChange) ? core.selectPlanner(current, plannerChange, this.plannerModelMemory, this.plannerCatalogFor(plannerChange.provider ?? current.provider, workspace)) : void 0;
|
|
1104
1159
|
if (envChanges) {
|
|
1105
1160
|
let touched = false;
|
|
@@ -1117,6 +1172,8 @@ var OrchestratorPool = class {
|
|
|
1117
1172
|
if (touched) {
|
|
1118
1173
|
this.modelResolver.invalidate();
|
|
1119
1174
|
this.dropUnkeyedProviderLists();
|
|
1175
|
+
core.forgetSignedOutRunnerAuth();
|
|
1176
|
+
for (const installation of /* @__PURE__ */ new Set([this.runnerInstallation, ...this.workspaceInstallations.values()])) installation.refresh?.();
|
|
1120
1177
|
}
|
|
1121
1178
|
}
|
|
1122
1179
|
if (selection) {
|
|
@@ -1126,8 +1183,8 @@ var OrchestratorPool = class {
|
|
|
1126
1183
|
this.pickedModel = { model: selection.next.model, provider: this.plannerProviderInEffect(workspace), workspace: workspaceKey(workspace) };
|
|
1127
1184
|
}
|
|
1128
1185
|
}
|
|
1129
|
-
if (
|
|
1130
|
-
const allowlist =
|
|
1186
|
+
if (changes2.modelAllowlist && typeof changes2.modelAllowlist === "object") {
|
|
1187
|
+
const allowlist = changes2.modelAllowlist;
|
|
1131
1188
|
for (const [runner, ids] of Object.entries(allowlist)) {
|
|
1132
1189
|
if (Array.isArray(ids)) {
|
|
1133
1190
|
this.settingsService.setModelAllowlist(runner, ids.map(String));
|
|
@@ -1136,6 +1193,9 @@ var OrchestratorPool = class {
|
|
|
1136
1193
|
}
|
|
1137
1194
|
}
|
|
1138
1195
|
}
|
|
1196
|
+
if (typeof changes2.autonomousMode === "boolean") {
|
|
1197
|
+
this.settingsService.setAutonomousMode(changes2.autonomousMode);
|
|
1198
|
+
}
|
|
1139
1199
|
if (envChanges) for (const monitor of this.accountLimits.values()) monitor.refresh();
|
|
1140
1200
|
if (selection?.remember) {
|
|
1141
1201
|
const { provider, model, effort } = selection.remember;
|
|
@@ -1175,13 +1235,14 @@ var OrchestratorPool = class {
|
|
|
1175
1235
|
const config = new WebConfig();
|
|
1176
1236
|
const resolver = this.resolverFor(workspace);
|
|
1177
1237
|
const runnerIds = this.registry.list().map((p) => p.manifest.name);
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
]);
|
|
1238
|
+
const sandbox = this.codexSandbox.ensure();
|
|
1239
|
+
sandbox.catch(() => {
|
|
1240
|
+
});
|
|
1241
|
+
const providerLists = await resolver.refresh();
|
|
1242
|
+
const [runnerModels] = await Promise.all([resolver.modelsForRunners(runnerIds), sandbox]);
|
|
1183
1243
|
const orchestratorModels = await resolver.pickerOptions();
|
|
1184
1244
|
const providerErrors = resolver.getDiscoveryErrors();
|
|
1245
|
+
const runnerErrors = resolver.getRunnerDiscoveryErrors();
|
|
1185
1246
|
this.cachedProviderLists = providerLists;
|
|
1186
1247
|
const allModels = [];
|
|
1187
1248
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -1203,7 +1264,8 @@ var OrchestratorPool = class {
|
|
|
1203
1264
|
orchestratorModel: this.plannerConfig(void 0, workspace).orchestratorModel,
|
|
1204
1265
|
providers,
|
|
1205
1266
|
orchestratorModels,
|
|
1206
|
-
providerErrors
|
|
1267
|
+
providerErrors,
|
|
1268
|
+
runnerErrors
|
|
1207
1269
|
};
|
|
1208
1270
|
}
|
|
1209
1271
|
getRunnerState(workspace) {
|
|
@@ -1258,19 +1320,19 @@ var OrchestratorPool = class {
|
|
|
1258
1320
|
const installedIds = new Set(
|
|
1259
1321
|
await installation.filterInstalled(runners.map((p) => p.manifest.name))
|
|
1260
1322
|
);
|
|
1261
|
-
|
|
1323
|
+
return Promise.all(
|
|
1262
1324
|
runners.filter((p) => installedIds.has(p.manifest.name)).map(async (p) => {
|
|
1263
|
-
const { usable, auth } = await installation.
|
|
1264
|
-
if (!usable) return null;
|
|
1325
|
+
const { usable, reason, auth, version } = await installation.runnerUsability(p.manifest.name);
|
|
1265
1326
|
return {
|
|
1266
1327
|
id: p.manifest.name,
|
|
1267
1328
|
name: p.manifest.displayName,
|
|
1268
1329
|
enabled: enabled.has(p.manifest.name),
|
|
1269
|
-
...
|
|
1330
|
+
...usable ? {} : { usable: false, ...reason ? { reason } : {} },
|
|
1331
|
+
...auth ? { auth } : {},
|
|
1332
|
+
...version ? { version } : {}
|
|
1270
1333
|
};
|
|
1271
1334
|
})
|
|
1272
1335
|
);
|
|
1273
|
-
return rows.filter((row) => row !== null);
|
|
1274
1336
|
}
|
|
1275
1337
|
async generatePlan(sessionId, goal, runners, workspace, modelOverride, options) {
|
|
1276
1338
|
const recheck = this.recheckSignedOutPlanner(workspace, this.plannerConfig(modelOverride).aiProvider);
|
|
@@ -1391,6 +1453,7 @@ var OrchestratorPool = class {
|
|
|
1391
1453
|
}
|
|
1392
1454
|
this.destroy(sessionId);
|
|
1393
1455
|
this.registerSession(sessionId, workspace, session);
|
|
1456
|
+
session.foldUserActions();
|
|
1394
1457
|
return session.planState ?? saved.plan;
|
|
1395
1458
|
}
|
|
1396
1459
|
/**
|
|
@@ -1471,15 +1534,15 @@ async function removeSession(sessionId, workspace, stop, close, reclaim) {
|
|
|
1471
1534
|
await reclaim();
|
|
1472
1535
|
return core.deleteSession(sessionId, workspace);
|
|
1473
1536
|
}
|
|
1474
|
-
function admittedEnv(
|
|
1475
|
-
const raw =
|
|
1537
|
+
function admittedEnv(changes2) {
|
|
1538
|
+
const raw = changes2.env;
|
|
1476
1539
|
return raw && typeof raw === "object" && !Array.isArray(raw) ? core.admitSettingsEnv(raw) : void 0;
|
|
1477
1540
|
}
|
|
1478
|
-
function plannerChangeOf(
|
|
1479
|
-
return
|
|
1541
|
+
function plannerChangeOf(changes2, envChanges) {
|
|
1542
|
+
return changes2.inherited === true ? {} : {
|
|
1480
1543
|
provider: envChanges?.AI_PROVIDER,
|
|
1481
|
-
model: envChanges?.ORCHESTRATOR_MODEL ?? stringField(
|
|
1482
|
-
effort: envChanges?.ORDEWELL_PLANNER_EFFORT ?? stringField(
|
|
1544
|
+
model: envChanges?.ORCHESTRATOR_MODEL ?? stringField(changes2.orchestratorModel),
|
|
1545
|
+
effort: envChanges?.ORDEWELL_PLANNER_EFFORT ?? stringField(changes2.plannerThinkingEffort)
|
|
1483
1546
|
};
|
|
1484
1547
|
}
|
|
1485
1548
|
function changesPlanner(change) {
|
|
@@ -1491,7 +1554,7 @@ function stringField(value) {
|
|
|
1491
1554
|
function workspaceKey(workspace) {
|
|
1492
1555
|
return path.resolve(workspace ?? process.cwd());
|
|
1493
1556
|
}
|
|
1494
|
-
function sessionsRoute(
|
|
1557
|
+
function sessionsRoute(pool) {
|
|
1495
1558
|
const router = new hono.Hono();
|
|
1496
1559
|
router.get("/", (c) => {
|
|
1497
1560
|
const ws = c.req.query("workspace") || process.cwd();
|
|
@@ -1501,14 +1564,18 @@ function sessionsRoute(pool2) {
|
|
|
1501
1564
|
router.get("/:id", (c) => {
|
|
1502
1565
|
const ws = c.req.query("workspace") || process.cwd();
|
|
1503
1566
|
const id = c.req.param("id");
|
|
1504
|
-
const saved = core.
|
|
1567
|
+
const saved = core.loadSession(id, ws);
|
|
1505
1568
|
if (!saved) return refuse(c, 404, "Session not found", "session_not_found");
|
|
1506
|
-
const run2 =
|
|
1507
|
-
const
|
|
1569
|
+
const run2 = pool.runSnapshot(id);
|
|
1570
|
+
const plannerTurnId = pool.plannerTurnId(id);
|
|
1571
|
+
const plannerCompaction = pool.plannerCompaction(id);
|
|
1572
|
+
const { conversationHistory, researchLog, plannerUsage, pendingTurns } = core.surfacePlan(pool.getPlan(id) ?? saved.plan);
|
|
1508
1573
|
return c.json({
|
|
1509
1574
|
meta: saved.meta,
|
|
1510
|
-
plan: core.surfacePlanState(
|
|
1575
|
+
plan: core.surfacePlanState(pool.getPlanState(id) ?? core.migratePlanState(saved.plan)),
|
|
1576
|
+
conversation: { conversationHistory, researchLog, plannerUsage, pendingTurns },
|
|
1511
1577
|
...run2 ? { run: run2 } : {},
|
|
1578
|
+
...plannerTurnId ? { plannerTurnId } : {},
|
|
1512
1579
|
...plannerCompaction ? { plannerCompaction } : {}
|
|
1513
1580
|
});
|
|
1514
1581
|
});
|
|
@@ -1516,14 +1583,14 @@ function sessionsRoute(pool2) {
|
|
|
1516
1583
|
const ws = c.req.query("workspace") || process.cwd();
|
|
1517
1584
|
try {
|
|
1518
1585
|
const id = c.req.param("id");
|
|
1519
|
-
const plan =
|
|
1520
|
-
const run2 =
|
|
1521
|
-
const plannerTurnId =
|
|
1522
|
-
const plannerCompaction =
|
|
1586
|
+
const plan = pool.adoptSavedSession(id, ws);
|
|
1587
|
+
const run2 = pool.runSnapshot(id);
|
|
1588
|
+
const plannerTurnId = pool.plannerTurnId(id);
|
|
1589
|
+
const plannerCompaction = pool.plannerCompaction(id);
|
|
1523
1590
|
return c.json({
|
|
1524
1591
|
ok: true,
|
|
1525
1592
|
plan: core.surfacePlan(plan),
|
|
1526
|
-
goal:
|
|
1593
|
+
goal: pool.getGoal(id),
|
|
1527
1594
|
...run2 ? { run: run2 } : {},
|
|
1528
1595
|
...plannerTurnId ? { plannerTurnId } : {},
|
|
1529
1596
|
...plannerCompaction ? { plannerCompaction } : {}
|
|
@@ -1534,21 +1601,21 @@ function sessionsRoute(pool2) {
|
|
|
1534
1601
|
});
|
|
1535
1602
|
router.get("/:id/tasks/:taskId/log", (c) => {
|
|
1536
1603
|
const ws = c.req.query("workspace") || process.cwd();
|
|
1537
|
-
return c.json({ attempts: core.listTaskLogAttempts({ baseDir: ws, sessionId: c.req.param("id") }, c.req.param("taskId")), position:
|
|
1604
|
+
return c.json({ attempts: core.listTaskLogAttempts({ baseDir: ws, sessionId: c.req.param("id") }, c.req.param("taskId")), position: pool.streamPosition(c.req.param("id")) });
|
|
1538
1605
|
});
|
|
1539
1606
|
router.get("/:id/tasks/:taskId/log/:attempt", (c) => {
|
|
1540
1607
|
const ws = c.req.query("workspace") || process.cwd();
|
|
1541
1608
|
const attempt = Number(c.req.param("attempt"));
|
|
1542
1609
|
if (!Number.isInteger(attempt) || attempt < 1) return refuse(c, 400, "attempt must be a positive integer");
|
|
1543
|
-
return c.json({ attempt, events: core.taskLogForSurface(core.readTaskLog({ baseDir: ws, sessionId: c.req.param("id") }, c.req.param("taskId"), attempt)), position:
|
|
1610
|
+
return c.json({ attempt, events: core.taskLogForSurface(core.readTaskLog({ baseDir: ws, sessionId: c.req.param("id") }, c.req.param("taskId"), attempt)), position: pool.streamPosition(c.req.param("id")) });
|
|
1544
1611
|
});
|
|
1545
1612
|
router.delete("/:id", async (c) => {
|
|
1546
1613
|
const ws = c.req.query("workspace") || process.cwd();
|
|
1547
1614
|
const id = c.req.param("id");
|
|
1548
|
-
const held =
|
|
1615
|
+
const held = pool.hasSession(id);
|
|
1549
1616
|
let removed;
|
|
1550
1617
|
try {
|
|
1551
|
-
removed = await removeSession(id, ws, () =>
|
|
1618
|
+
removed = await removeSession(id, ws, () => pool.stopTree(id), () => pool.close(id), () => pool.reclaim(id));
|
|
1552
1619
|
} catch (err) {
|
|
1553
1620
|
return c.json({ ok: false, message: err instanceof Error ? err.message : String(err) });
|
|
1554
1621
|
}
|
|
@@ -1559,7 +1626,7 @@ function sessionsRoute(pool2) {
|
|
|
1559
1626
|
});
|
|
1560
1627
|
});
|
|
1561
1628
|
router.post("/:id/close", async (c) => {
|
|
1562
|
-
await
|
|
1629
|
+
await pool.close(c.req.param("id"));
|
|
1563
1630
|
return c.json({ ok: true });
|
|
1564
1631
|
});
|
|
1565
1632
|
return router;
|
|
@@ -1573,7 +1640,7 @@ async function runUserCommand(session, command) {
|
|
|
1573
1640
|
if (!outcome.ok) throw new core.TaskControlError(outcome.message);
|
|
1574
1641
|
return outcome;
|
|
1575
1642
|
}
|
|
1576
|
-
function plansRoute(
|
|
1643
|
+
function plansRoute(pool) {
|
|
1577
1644
|
const router = new hono.Hono();
|
|
1578
1645
|
router.post("/:sessionId/generate", async (c) => {
|
|
1579
1646
|
try {
|
|
@@ -1582,9 +1649,9 @@ function plansRoute(pool2) {
|
|
|
1582
1649
|
const ws = workspace || c.req.query("workspace") || process.cwd();
|
|
1583
1650
|
const queryRunners = c.req.query("runners");
|
|
1584
1651
|
const runnerList = Array.isArray(runners) ? runners : runners ? [runners] : queryRunners ? queryRunners.split(",").map((s) => s.trim()).filter(Boolean) : void 0;
|
|
1585
|
-
const plan = await
|
|
1586
|
-
const { models, modelsByRunner } = await
|
|
1587
|
-
const notes = (
|
|
1652
|
+
const plan = await pool.generatePlan(c.req.param("sessionId"), goal, runnerList, ws, model, { allowInit });
|
|
1653
|
+
const { models, modelsByRunner } = await pool.getProviderModels(ws);
|
|
1654
|
+
const notes = (pool.session(c.req.param("sessionId")).planState?.conversationHistory ?? []).filter((e) => e.kind === "system").map((e) => e.content);
|
|
1588
1655
|
return c.json({ plan: core.surfacePlanState(plan), models, modelsByRunner, ...notes.length > 0 ? { notes } : {} });
|
|
1589
1656
|
} catch (err) {
|
|
1590
1657
|
return failure(c, err, "generate", { message: "Plan generation failed" });
|
|
@@ -1592,7 +1659,7 @@ function plansRoute(pool2) {
|
|
|
1592
1659
|
});
|
|
1593
1660
|
router.post("/:sessionId/execute", async (c) => {
|
|
1594
1661
|
try {
|
|
1595
|
-
const session =
|
|
1662
|
+
const session = pool.session(c.req.param("sessionId"));
|
|
1596
1663
|
if (!session.planState || session.planTasks.length === 0) throw new core.NoPlanError("execute");
|
|
1597
1664
|
const { message } = await runUserCommand(session, { command: "run_plan" });
|
|
1598
1665
|
return c.json({ status: "running", message });
|
|
@@ -1602,8 +1669,8 @@ function plansRoute(pool2) {
|
|
|
1602
1669
|
});
|
|
1603
1670
|
router.post("/:sessionId/stop", async (c) => {
|
|
1604
1671
|
try {
|
|
1605
|
-
if (
|
|
1606
|
-
const session =
|
|
1672
|
+
if (pool.hasSession(c.req.param("sessionId"))) {
|
|
1673
|
+
const session = pool.session(c.req.param("sessionId"));
|
|
1607
1674
|
const outcome = await session.execute({ command: "stop_run" }, { kind: "user" });
|
|
1608
1675
|
if (!outcome.ok && (session.isExecuting || session.startsPending)) throw new core.TaskControlError(outcome.message);
|
|
1609
1676
|
return c.json({ status: "stopped", message: outcome.message });
|
|
@@ -1614,14 +1681,14 @@ function plansRoute(pool2) {
|
|
|
1614
1681
|
}
|
|
1615
1682
|
});
|
|
1616
1683
|
router.post("/:sessionId/planning/stop", (c) => {
|
|
1617
|
-
const cancelled =
|
|
1684
|
+
const cancelled = pool.cancelPlanning(c.req.param("sessionId"));
|
|
1618
1685
|
return c.json({ cancelled });
|
|
1619
1686
|
});
|
|
1620
1687
|
router.post("/:sessionId/execute-command", async (c) => {
|
|
1621
1688
|
try {
|
|
1622
1689
|
const parsed = core.parseExecutionCommand(await jsonObject(c));
|
|
1623
1690
|
if (!parsed.ok) return refuse(c, 400, parsed.message, "refused");
|
|
1624
|
-
const outcome = await
|
|
1691
|
+
const outcome = await pool.session(c.req.param("sessionId")).execute(parsed.command, { kind: "user" });
|
|
1625
1692
|
if (!outcome.ok) {
|
|
1626
1693
|
return c.json({ error: outcome.message, code: "refused", ...outcome.payload ? { payload: outcome.payload } : {} }, 400);
|
|
1627
1694
|
}
|
|
@@ -1632,7 +1699,7 @@ function plansRoute(pool2) {
|
|
|
1632
1699
|
});
|
|
1633
1700
|
router.get("/:sessionId/escalations", (c) => {
|
|
1634
1701
|
try {
|
|
1635
|
-
return c.json({ escalations:
|
|
1702
|
+
return c.json({ escalations: pool.session(c.req.param("sessionId")).escalations() });
|
|
1636
1703
|
} catch (err) {
|
|
1637
1704
|
return failure(c, err, "escalations");
|
|
1638
1705
|
}
|
|
@@ -1641,7 +1708,7 @@ function plansRoute(pool2) {
|
|
|
1641
1708
|
try {
|
|
1642
1709
|
const { id, option, note, confirmed } = await jsonObject(c);
|
|
1643
1710
|
if (typeof id !== "string" || typeof option !== "string") return refuse(c, 400, "id and option are required", "refused");
|
|
1644
|
-
const outcome = await
|
|
1711
|
+
const outcome = await pool.session(c.req.param("sessionId")).answerEscalation(id, option, typeof note === "string" ? note : void 0, confirmed === true);
|
|
1645
1712
|
if (!outcome.ok) return c.json({ error: outcome.message, code: "refused", ...outcome.payload ? { payload: outcome.payload } : {} }, 400);
|
|
1646
1713
|
return c.json({ ok: true, message: outcome.message, ...outcome.payload ? { payload: outcome.payload } : {} });
|
|
1647
1714
|
} catch (err) {
|
|
@@ -1653,8 +1720,8 @@ function plansRoute(pool2) {
|
|
|
1653
1720
|
const body = await c.req.json().catch(() => ({}));
|
|
1654
1721
|
const fields = typeof body === "object" && body !== null ? body : {};
|
|
1655
1722
|
if (typeof fields.name !== "string" || !fields.name.trim()) return c.json({ error: "name is required" }, 400);
|
|
1656
|
-
const
|
|
1657
|
-
const id =
|
|
1723
|
+
const args = typeof fields.args === "string" ? fields.args : "";
|
|
1724
|
+
const id = pool.session(c.req.param("sessionId")).invokeTaskCommand(c.req.param("taskId"), fields.name.trim(), args);
|
|
1658
1725
|
return c.json({ id });
|
|
1659
1726
|
} catch (err) {
|
|
1660
1727
|
return failure(c, err, "task edit");
|
|
@@ -1668,7 +1735,7 @@ function plansRoute(pool2) {
|
|
|
1668
1735
|
const raiseTokens = typeof body === "object" && body !== null && "raiseTokens" in body ? body.raiseTokens : void 0;
|
|
1669
1736
|
const raise = typeof raiseTokens === "number" && Number.isSafeInteger(raiseTokens) && raiseTokens > 0 ? raiseTokens : void 0;
|
|
1670
1737
|
if (raiseTokens !== void 0 && raise === void 0) return refuse(c, 400, "A raise is a whole number of tokens, 1 or more.", "refused");
|
|
1671
|
-
const session =
|
|
1738
|
+
const session = pool.session(c.req.param("sessionId"));
|
|
1672
1739
|
const taskId = idOfRef(session, c.req.param("taskId"));
|
|
1673
1740
|
if (!session.awaitsCheckpoint(taskId)) return refuse(c, 409, NO_CHECKPOINT, "checkpoint_not_waiting");
|
|
1674
1741
|
const { message } = await runUserCommand(session, { command: "answer_checkpoint", task: taskId, answer, ...reason ? { reason } : {}, ...raise !== void 0 ? { raiseTokens: raise } : {} });
|
|
@@ -1680,7 +1747,7 @@ function plansRoute(pool2) {
|
|
|
1680
1747
|
}
|
|
1681
1748
|
router.get("/:sessionId/tasks/:taskId/merge-gate", (c) => {
|
|
1682
1749
|
try {
|
|
1683
|
-
const session =
|
|
1750
|
+
const session = pool.session(c.req.param("sessionId"));
|
|
1684
1751
|
const tasks = core.flattenTasks(session.planState?.tasks ?? []);
|
|
1685
1752
|
const mergeGate = session.mergeGate(idOfRef(session, c.req.param("taskId"))).map((id) => {
|
|
1686
1753
|
const dep = tasks.find((t) => t.id === id);
|
|
@@ -1693,7 +1760,7 @@ function plansRoute(pool2) {
|
|
|
1693
1760
|
});
|
|
1694
1761
|
router.get("/:sessionId/tasks/:taskId/revert-preview", async (c) => {
|
|
1695
1762
|
try {
|
|
1696
|
-
const session =
|
|
1763
|
+
const session = pool.session(c.req.param("sessionId"));
|
|
1697
1764
|
return c.json(await session.revertPreview(idOfRef(session, c.req.param("taskId"))));
|
|
1698
1765
|
} catch (err) {
|
|
1699
1766
|
return failure(c, err, "task edit");
|
|
@@ -1701,7 +1768,7 @@ function plansRoute(pool2) {
|
|
|
1701
1768
|
});
|
|
1702
1769
|
router.get("/:sessionId/isolation/diff", async (c) => {
|
|
1703
1770
|
try {
|
|
1704
|
-
return c.json({ diff: await
|
|
1771
|
+
return c.json({ diff: await pool.session(c.req.param("sessionId")).reviewRunDiff() });
|
|
1705
1772
|
} catch (err) {
|
|
1706
1773
|
return failure(c, err, "task edit");
|
|
1707
1774
|
}
|
|
@@ -1710,7 +1777,7 @@ function plansRoute(pool2) {
|
|
|
1710
1777
|
try {
|
|
1711
1778
|
const body = await c.req.json().catch(() => ({}));
|
|
1712
1779
|
const pastChecks = typeof body === "object" && body !== null && "pastChecks" in body && body.pastChecks === true;
|
|
1713
|
-
const outcome = await
|
|
1780
|
+
const outcome = await pool.session(c.req.param("sessionId")).execute(pastChecks ? { command: "merge_all", pastChecks: true } : { command: "merge_all" }, { kind: "user" });
|
|
1714
1781
|
if (outcome.payload?.kind === "merge") return c.json(outcome.payload.result);
|
|
1715
1782
|
if (outcome.payload?.kind === "merge_hold") return refuse(c, 409, outcome.message, "merge_past_check");
|
|
1716
1783
|
if (!outcome.ok) throw new core.TaskControlError(outcome.message);
|
|
@@ -1727,7 +1794,7 @@ function plansRoute(pool2) {
|
|
|
1727
1794
|
]) {
|
|
1728
1795
|
router.post(`/:sessionId/isolation/${segment}`, async (c) => {
|
|
1729
1796
|
try {
|
|
1730
|
-
await run2(
|
|
1797
|
+
await run2(pool.session(c.req.param("sessionId")));
|
|
1731
1798
|
return c.json({ ok: true });
|
|
1732
1799
|
} catch (err) {
|
|
1733
1800
|
return failure(c, err, "task edit");
|
|
@@ -1736,7 +1803,7 @@ function plansRoute(pool2) {
|
|
|
1736
1803
|
}
|
|
1737
1804
|
router.post("/:sessionId/tasks/:taskId/resolve-conflict", async (c) => {
|
|
1738
1805
|
try {
|
|
1739
|
-
const plan = await
|
|
1806
|
+
const plan = await pool.session(c.req.param("sessionId")).resolveConflictAsTask(c.req.param("taskId"));
|
|
1740
1807
|
return c.json({ plan: plan && core.surfacePlan(plan) });
|
|
1741
1808
|
} catch (err) {
|
|
1742
1809
|
return failure(c, err, "task edit");
|
|
@@ -1744,9 +1811,9 @@ function plansRoute(pool2) {
|
|
|
1744
1811
|
});
|
|
1745
1812
|
router.put("/:sessionId/tasks/:taskId", async (c) => {
|
|
1746
1813
|
try {
|
|
1747
|
-
const
|
|
1748
|
-
if (
|
|
1749
|
-
const result = await
|
|
1814
|
+
const changes2 = await jsonObject(c);
|
|
1815
|
+
if (changes2.assignedModel === null) changes2.assignedModel = void 0;
|
|
1816
|
+
const result = await pool.session(c.req.param("sessionId")).updateTask(c.req.param("taskId"), changes2);
|
|
1750
1817
|
if (!result) return refuse(c, 404, "Task not found", "task_not_found");
|
|
1751
1818
|
return c.json({ ok: true });
|
|
1752
1819
|
} catch (err) {
|
|
@@ -1755,7 +1822,7 @@ function plansRoute(pool2) {
|
|
|
1755
1822
|
});
|
|
1756
1823
|
router.delete("/:sessionId/tasks/:taskId", async (c) => {
|
|
1757
1824
|
try {
|
|
1758
|
-
const result = await
|
|
1825
|
+
const result = await pool.session(c.req.param("sessionId")).removeTask(c.req.param("taskId"));
|
|
1759
1826
|
if (!result) return refuse(c, 404, "Task not found", "task_not_found");
|
|
1760
1827
|
return c.json({ ok: true });
|
|
1761
1828
|
} catch (err) {
|
|
@@ -1765,7 +1832,7 @@ function plansRoute(pool2) {
|
|
|
1765
1832
|
router.post("/:sessionId/tasks", async (c) => {
|
|
1766
1833
|
try {
|
|
1767
1834
|
const body = await jsonObject(c);
|
|
1768
|
-
const result = await
|
|
1835
|
+
const result = await pool.session(c.req.param("sessionId")).addTask(body);
|
|
1769
1836
|
if (!result) return refuse(c, 404, "Session not found", "session_not_found");
|
|
1770
1837
|
return c.json({ ok: true });
|
|
1771
1838
|
} catch (err) {
|
|
@@ -1774,7 +1841,7 @@ function plansRoute(pool2) {
|
|
|
1774
1841
|
});
|
|
1775
1842
|
router.post("/:sessionId/review/approve", async (c) => {
|
|
1776
1843
|
try {
|
|
1777
|
-
const session =
|
|
1844
|
+
const session = pool.session(c.req.param("sessionId"));
|
|
1778
1845
|
const plan = session.planState;
|
|
1779
1846
|
if (!plan) throw new core.NoPlanError("review");
|
|
1780
1847
|
const { message } = await runUserCommand(session, { command: "approve_review" });
|
|
@@ -1789,7 +1856,7 @@ function plansRoute(pool2) {
|
|
|
1789
1856
|
if (!goal) return c.json({ error: "goal is required" }, 400);
|
|
1790
1857
|
const ws = workspace || c.req.query("workspace") || process.cwd();
|
|
1791
1858
|
const runnerList = Array.isArray(runners) ? runners : runners ? [runners] : void 0;
|
|
1792
|
-
const plan = await
|
|
1859
|
+
const plan = await pool.startPlanning(c.req.param("sessionId"), goal, runnerList, ws, model, { allowInit });
|
|
1793
1860
|
return c.json({ plan: core.surfacePlan(plan) });
|
|
1794
1861
|
} catch (err) {
|
|
1795
1862
|
return failure(c, err, "converse start", { message: "Planning failed" });
|
|
@@ -1799,7 +1866,7 @@ function plansRoute(pool2) {
|
|
|
1799
1866
|
try {
|
|
1800
1867
|
const { message } = await jsonObject(c);
|
|
1801
1868
|
if (!message) return c.json({ error: "message is required" }, 400);
|
|
1802
|
-
const plan = await
|
|
1869
|
+
const plan = await pool.continuePlanning(c.req.param("sessionId"), message);
|
|
1803
1870
|
return c.json({ plan: core.surfacePlan(plan) });
|
|
1804
1871
|
} catch (err) {
|
|
1805
1872
|
return failure(c, err, "conversation message");
|
|
@@ -1809,7 +1876,7 @@ function plansRoute(pool2) {
|
|
|
1809
1876
|
try {
|
|
1810
1877
|
const { message } = await jsonObject(c);
|
|
1811
1878
|
if (!message) return c.json({ error: "message is required" }, 400);
|
|
1812
|
-
const plan = await
|
|
1879
|
+
const plan = await pool.forceSendPrompt(c.req.param("sessionId"), message);
|
|
1813
1880
|
return c.json({ plan: core.surfacePlan(plan) });
|
|
1814
1881
|
} catch (err) {
|
|
1815
1882
|
return failure(c, err, "conversation message");
|
|
@@ -1817,7 +1884,7 @@ function plansRoute(pool2) {
|
|
|
1817
1884
|
});
|
|
1818
1885
|
router.post("/:sessionId/converse/resend/cancel", (c) => {
|
|
1819
1886
|
try {
|
|
1820
|
-
const cancelled =
|
|
1887
|
+
const cancelled = pool.session(c.req.param("sessionId")).cancelPlannerResend();
|
|
1821
1888
|
return c.json({ cancelled });
|
|
1822
1889
|
} catch (err) {
|
|
1823
1890
|
return failure(c, err, "cancel resend", { fallback: 404, message: "Not found" });
|
|
@@ -1825,7 +1892,7 @@ function plansRoute(pool2) {
|
|
|
1825
1892
|
});
|
|
1826
1893
|
router.post("/:sessionId/conversation/fork", (c) => {
|
|
1827
1894
|
try {
|
|
1828
|
-
const fork =
|
|
1895
|
+
const fork = pool.forkConversation(c.req.param("sessionId"));
|
|
1829
1896
|
return c.json({ ...fork, plan: core.surfacePlan(fork.plan) });
|
|
1830
1897
|
} catch (err) {
|
|
1831
1898
|
return failure(c, err, "conversation edit");
|
|
@@ -1833,7 +1900,7 @@ function plansRoute(pool2) {
|
|
|
1833
1900
|
});
|
|
1834
1901
|
router.get("/:sessionId/conversation/rewind-targets", (c) => {
|
|
1835
1902
|
try {
|
|
1836
|
-
return c.json({ targets:
|
|
1903
|
+
return c.json({ targets: pool.session(c.req.param("sessionId")).rewindTargets() });
|
|
1837
1904
|
} catch (err) {
|
|
1838
1905
|
return failure(c, err, "conversation edit");
|
|
1839
1906
|
}
|
|
@@ -1842,7 +1909,7 @@ function plansRoute(pool2) {
|
|
|
1842
1909
|
try {
|
|
1843
1910
|
const { index } = await jsonObject(c);
|
|
1844
1911
|
if (typeof index !== "number" || !Number.isInteger(index) || index < 0) return c.json({ error: "index must be a non-negative integer" }, 400);
|
|
1845
|
-
const rewound =
|
|
1912
|
+
const rewound = pool.rewindConversation(c.req.param("sessionId"), index);
|
|
1846
1913
|
return c.json({ ...rewound, plan: core.surfacePlan(rewound.plan) });
|
|
1847
1914
|
} catch (err) {
|
|
1848
1915
|
return failure(c, err, "conversation edit");
|
|
@@ -1850,7 +1917,7 @@ function plansRoute(pool2) {
|
|
|
1850
1917
|
});
|
|
1851
1918
|
router.post("/:sessionId/conversation/compact", async (c) => {
|
|
1852
1919
|
try {
|
|
1853
|
-
const compacted = await
|
|
1920
|
+
const compacted = await pool.compactConversation(c.req.param("sessionId"));
|
|
1854
1921
|
return c.json({ ...compacted, plan: core.surfacePlan(compacted.plan) });
|
|
1855
1922
|
} catch (err) {
|
|
1856
1923
|
return failure(c, err, "conversation edit");
|
|
@@ -1858,26 +1925,26 @@ function plansRoute(pool2) {
|
|
|
1858
1925
|
});
|
|
1859
1926
|
router.post("/:sessionId/conversation/compact/retry", async (c) => {
|
|
1860
1927
|
try {
|
|
1861
|
-
const plan = await
|
|
1928
|
+
const plan = await pool.retryPlannerCompaction(c.req.param("sessionId"));
|
|
1862
1929
|
return c.json({ plan: core.surfacePlan(plan) });
|
|
1863
1930
|
} catch (err) {
|
|
1864
1931
|
return failure(c, err, "retry compaction");
|
|
1865
1932
|
}
|
|
1866
1933
|
});
|
|
1867
1934
|
router.get("/:sessionId/prd", (c) => {
|
|
1868
|
-
const plan =
|
|
1935
|
+
const plan = pool.getPlan(c.req.param("sessionId"));
|
|
1869
1936
|
if (!plan?.prdMarkdown) return refuse(c, 404, "No PRD found");
|
|
1870
1937
|
return c.json({ prdMarkdown: plan.prdMarkdown });
|
|
1871
1938
|
});
|
|
1872
1939
|
return router;
|
|
1873
1940
|
}
|
|
1874
|
-
function runnersRoute(
|
|
1941
|
+
function runnersRoute(pool) {
|
|
1875
1942
|
const router = new hono.Hono();
|
|
1876
1943
|
router.get("/", async (c) => {
|
|
1877
1944
|
const workspace = c.req.query("workspace");
|
|
1878
|
-
const runners = await
|
|
1879
|
-
await
|
|
1880
|
-
const state =
|
|
1945
|
+
const runners = await pool.getInstalledRunners(workspace);
|
|
1946
|
+
await pool.discoverPlannerCatalogs(void 0, workspace);
|
|
1947
|
+
const state = pool.getRunnerState(workspace);
|
|
1881
1948
|
return c.json({
|
|
1882
1949
|
runners,
|
|
1883
1950
|
orchestratorModel: state.orchestratorModel
|
|
@@ -1889,7 +1956,7 @@ function runnersRoute(pool2) {
|
|
|
1889
1956
|
const id = c.req.param("id");
|
|
1890
1957
|
const { enabled } = await jsonObject(c);
|
|
1891
1958
|
if (typeof enabled !== "boolean") return refuse(c, 400, "enabled must be true or false");
|
|
1892
|
-
|
|
1959
|
+
pool.setRunnerEnabled(id, enabled);
|
|
1893
1960
|
return c.json({ ok: true });
|
|
1894
1961
|
} catch (err) {
|
|
1895
1962
|
return failure(c, err, "runner toggle", { fallback: 400 });
|
|
@@ -1897,21 +1964,21 @@ function runnersRoute(pool2) {
|
|
|
1897
1964
|
});
|
|
1898
1965
|
return router;
|
|
1899
1966
|
}
|
|
1900
|
-
function modelsRoute(
|
|
1967
|
+
function modelsRoute(pool) {
|
|
1901
1968
|
const router = new hono.Hono();
|
|
1902
1969
|
router.get("/", async (c) => {
|
|
1903
|
-
const result = await
|
|
1970
|
+
const result = await pool.getProviderModels(c.req.query("workspace"));
|
|
1904
1971
|
return c.json(result);
|
|
1905
1972
|
});
|
|
1906
1973
|
return router;
|
|
1907
1974
|
}
|
|
1908
|
-
function workspacesRoute(
|
|
1975
|
+
function workspacesRoute(pool) {
|
|
1909
1976
|
const router = new hono.Hono();
|
|
1910
1977
|
router.get("/isolation-preview", async (c) => {
|
|
1911
1978
|
try {
|
|
1912
1979
|
const workspace = c.req.query("workspace") || process.cwd();
|
|
1913
1980
|
core.assertWorkspaceExists(workspace);
|
|
1914
|
-
const preview = await
|
|
1981
|
+
const preview = await pool.previewIsolation(workspace);
|
|
1915
1982
|
return c.json({ preview });
|
|
1916
1983
|
} catch (err) {
|
|
1917
1984
|
return failure(c, err, "read isolation preview", { message: "Could not read the repositories" });
|
|
@@ -1931,30 +1998,30 @@ function answerOf(body) {
|
|
|
1931
1998
|
if (decision === "deny" && typeof note === "string" && note.trim()) return { decision, note: note.trim() };
|
|
1932
1999
|
return { decision: "deny" };
|
|
1933
2000
|
}
|
|
1934
|
-
function approvalsRoute(
|
|
2001
|
+
function approvalsRoute(pool) {
|
|
1935
2002
|
const router = new hono.Hono();
|
|
1936
2003
|
router.get("/:sessionId", (c) => {
|
|
1937
2004
|
const sessionId = c.req.param("sessionId");
|
|
1938
|
-
if (!
|
|
2005
|
+
if (!pool.hasSession(sessionId)) return refuse(c, 404, `Unknown session: ${sessionId}`, "session_not_found");
|
|
1939
2006
|
return c.json({
|
|
1940
|
-
pending:
|
|
1941
|
-
approvedScopes:
|
|
2007
|
+
pending: pool.outstandingApprovals(sessionId),
|
|
2008
|
+
approvedScopes: pool.approvedScopes(sessionId)
|
|
1942
2009
|
});
|
|
1943
2010
|
});
|
|
1944
2011
|
router.post("/:sessionId/:approvalId", async (c) => {
|
|
1945
2012
|
const sessionId = c.req.param("sessionId");
|
|
1946
2013
|
const approvalId = c.req.param("approvalId");
|
|
1947
|
-
if (!
|
|
2014
|
+
if (!pool.hasSession(sessionId)) return refuse(c, 404, `Unknown session: ${sessionId}`, "session_not_found");
|
|
1948
2015
|
const answer = answerOf(await c.req.json().catch(() => null));
|
|
1949
2016
|
const decided = core.toApprovalDecision(answer);
|
|
1950
|
-
const request =
|
|
2017
|
+
const request = pool.outstandingApprovals(sessionId).find((pending) => pending.id === approvalId)?.request;
|
|
1951
2018
|
if (request?.taskId) {
|
|
1952
|
-
const outcome = await
|
|
2019
|
+
const outcome = await pool.session(sessionId).execute(
|
|
1953
2020
|
{ command: "answer_approval", task: request.taskId, approval: approvalId, answer: decided.decision, ...decided.decision === "deny" && decided.note ? { note: decided.note } : {} },
|
|
1954
2021
|
{ kind: "user" }
|
|
1955
2022
|
);
|
|
1956
2023
|
if (!outcome.ok) return refuse(c, 400, outcome.message, "refused");
|
|
1957
|
-
} else if (!
|
|
2024
|
+
} else if (!pool.resolveApproval(sessionId, approvalId, answer)) {
|
|
1958
2025
|
return refuse(c, 409, "Approval is no longer outstanding: it timed out or was already answered.", "approval_not_outstanding");
|
|
1959
2026
|
}
|
|
1960
2027
|
return c.json({ ok: true, granted: core.isGranted(decided), decision: decided.decision });
|
|
@@ -1968,7 +2035,7 @@ function containerChange(body) {
|
|
|
1968
2035
|
if (typeof change.image === "string") return { image: change.image };
|
|
1969
2036
|
return "login" in change ? { login: change.login } : null;
|
|
1970
2037
|
}
|
|
1971
|
-
function settingsRoute(
|
|
2038
|
+
function settingsRoute(pool) {
|
|
1972
2039
|
const router = new hono.Hono();
|
|
1973
2040
|
router.use("/containers", async (c, next) => {
|
|
1974
2041
|
if (!core.containersOffered()) return refuse(c, 404, "This build does not offer containers");
|
|
@@ -1976,7 +2043,7 @@ function settingsRoute(pool2) {
|
|
|
1976
2043
|
});
|
|
1977
2044
|
router.get("/containers", async (c) => {
|
|
1978
2045
|
try {
|
|
1979
|
-
const status = await
|
|
2046
|
+
const status = await pool.containerStatus(c.req.query("prove") === "1", c.req.query("workspace") || void 0);
|
|
1980
2047
|
return c.json(status);
|
|
1981
2048
|
} catch (err) {
|
|
1982
2049
|
return failure(c, err, "containers status");
|
|
@@ -1988,7 +2055,7 @@ function settingsRoute(pool2) {
|
|
|
1988
2055
|
const change = containerChange(body);
|
|
1989
2056
|
if (!change) return refuse(c, 400, "One of on, image or login is required");
|
|
1990
2057
|
const { workspace } = body;
|
|
1991
|
-
const result = await
|
|
2058
|
+
const result = await pool.changeContainers(change, typeof workspace === "string" ? workspace || void 0 : void 0);
|
|
1992
2059
|
return c.json(result);
|
|
1993
2060
|
} catch (err) {
|
|
1994
2061
|
return failure(c, err, "containers change", { fallback: 400 });
|
|
@@ -1998,8 +2065,8 @@ function settingsRoute(pool2) {
|
|
|
1998
2065
|
await core.installedPlannerDetected();
|
|
1999
2066
|
const sessionId = c.req.query("sessionId") || void 0;
|
|
2000
2067
|
const workspace = c.req.query("workspace") || void 0;
|
|
2001
|
-
await
|
|
2002
|
-
const settings =
|
|
2068
|
+
await pool.discoverPlannerCatalogs(sessionId, workspace);
|
|
2069
|
+
const settings = pool.getSettings(sessionId, workspace);
|
|
2003
2070
|
return c.json(settings);
|
|
2004
2071
|
});
|
|
2005
2072
|
router.patch("/", async (c) => {
|
|
@@ -2017,13 +2084,13 @@ function settingsRoute(pool2) {
|
|
|
2017
2084
|
if (run2 !== void 0) {
|
|
2018
2085
|
if (!run2 || typeof run2 !== "object" || Array.isArray(run2)) return refuse(c, 400, "run must be an object of run settings");
|
|
2019
2086
|
try {
|
|
2020
|
-
|
|
2087
|
+
pool.updateRunSettings(run2, sessionId, workspace);
|
|
2021
2088
|
} catch (err) {
|
|
2022
2089
|
if (err instanceof core.RunSettingsError) return refuse(c, 400, err.message);
|
|
2023
2090
|
throw err;
|
|
2024
2091
|
}
|
|
2025
2092
|
}
|
|
2026
|
-
const result = Object.keys(rest).length > 0 ? await
|
|
2093
|
+
const result = Object.keys(rest).length > 0 ? await pool.writeSettings(rest, sessionId, workspace) : pool.getSettings(sessionId, workspace);
|
|
2027
2094
|
return c.json(result);
|
|
2028
2095
|
} catch (err) {
|
|
2029
2096
|
return failure(c, err, "settings update", { fallback: 400 });
|
|
@@ -2043,17 +2110,226 @@ function commandsRoute() {
|
|
|
2043
2110
|
});
|
|
2044
2111
|
return router;
|
|
2045
2112
|
}
|
|
2113
|
+
var SCOPES = ["checkout", "integration", "task"];
|
|
2114
|
+
function workspaceOf(c) {
|
|
2115
|
+
const workspace = c.req.query("workspace") || process.cwd();
|
|
2116
|
+
core.assertWorkspaceExists(workspace);
|
|
2117
|
+
return workspace;
|
|
2118
|
+
}
|
|
2119
|
+
function targetOf(c) {
|
|
2120
|
+
const scope = c.req.query("scope");
|
|
2121
|
+
if (scope !== void 0 && !SCOPES.includes(scope)) {
|
|
2122
|
+
throw new core.WorkspaceReadError("refused", `Unknown scope "${scope}": name ${SCOPES.join(", ")}.`);
|
|
2123
|
+
}
|
|
2124
|
+
const target = { workspace: workspaceOf(c) };
|
|
2125
|
+
const repo = c.req.query("repo");
|
|
2126
|
+
const sessionId = c.req.query("sessionId");
|
|
2127
|
+
const taskId = c.req.query("taskId");
|
|
2128
|
+
if (repo) target.repo = repo;
|
|
2129
|
+
if (scope) target.scope = scope;
|
|
2130
|
+
if (sessionId) target.sessionId = sessionId;
|
|
2131
|
+
if (taskId) target.taskId = taskId;
|
|
2132
|
+
return target;
|
|
2133
|
+
}
|
|
2134
|
+
function required(c, name) {
|
|
2135
|
+
const value = c.req.query(name);
|
|
2136
|
+
if (!value) throw new core.WorkspaceReadError("refused", `Name the ${name} to read.`);
|
|
2137
|
+
return value;
|
|
2138
|
+
}
|
|
2139
|
+
function flag(c, name) {
|
|
2140
|
+
const value = c.req.query(name);
|
|
2141
|
+
return value === "1" || value === "true";
|
|
2142
|
+
}
|
|
2143
|
+
function count(c, name) {
|
|
2144
|
+
const value = c.req.query(name);
|
|
2145
|
+
if (value === void 0) return void 0;
|
|
2146
|
+
const n = Number(value);
|
|
2147
|
+
if (!Number.isInteger(n) || n < 1) throw new core.WorkspaceReadError("refused", `"${name}" must be a positive whole number.`);
|
|
2148
|
+
return n;
|
|
2149
|
+
}
|
|
2150
|
+
function optional(c, name) {
|
|
2151
|
+
return c.req.query(name) || void 0;
|
|
2152
|
+
}
|
|
2153
|
+
function read(label, answer) {
|
|
2154
|
+
return async (c) => {
|
|
2155
|
+
try {
|
|
2156
|
+
return c.json(await answer(c));
|
|
2157
|
+
} catch (err) {
|
|
2158
|
+
return failure(c, err, label, { message: "Could not read the workspace" });
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
function filesRoute(reader) {
|
|
2163
|
+
const router = new hono.Hono();
|
|
2164
|
+
router.get("/tree", read("read tree", (c) => reader.tree(targetOf(c), c.req.query("dir") ?? "")));
|
|
2165
|
+
router.get("/content", read("read file", async (c) => {
|
|
2166
|
+
const target = targetOf(c);
|
|
2167
|
+
return reader.content(target, required(c, "path"));
|
|
2168
|
+
}));
|
|
2169
|
+
router.get("/find", read("find files", async (c) => {
|
|
2170
|
+
const target = targetOf(c);
|
|
2171
|
+
return reader.find(target, { query: required(c, "query"), text: flag(c, "text"), limit: count(c, "limit") });
|
|
2172
|
+
}));
|
|
2173
|
+
return router;
|
|
2174
|
+
}
|
|
2175
|
+
function gitRoute(reader) {
|
|
2176
|
+
const router = new hono.Hono();
|
|
2177
|
+
router.get("/repos", read("read repositories", (c) => reader.repos(workspaceOf(c))));
|
|
2178
|
+
router.get("/status", read("read status", (c) => reader.status(targetOf(c))));
|
|
2179
|
+
router.get("/diff", read("read diff", async (c) => {
|
|
2180
|
+
const target = targetOf(c);
|
|
2181
|
+
const kind = c.req.query("kind");
|
|
2182
|
+
if (kind !== void 0 && kind !== "staged" && kind !== "unstaged") throw new core.WorkspaceReadError("refused", `Unknown diff kind "${kind}": name staged or unstaged.`);
|
|
2183
|
+
return reader.diff(target, { kind, from: optional(c, "from"), to: optional(c, "to"), path: optional(c, "path") });
|
|
2184
|
+
}));
|
|
2185
|
+
router.get("/log", read("read log", async (c) => {
|
|
2186
|
+
const target = targetOf(c);
|
|
2187
|
+
return reader.log(target, { ref: optional(c, "ref"), cursor: optional(c, "cursor"), limit: count(c, "limit") });
|
|
2188
|
+
}));
|
|
2189
|
+
router.get("/commit", read("read commit", async (c) => {
|
|
2190
|
+
const target = targetOf(c);
|
|
2191
|
+
return reader.commit(target, required(c, "sha"), optional(c, "path"));
|
|
2192
|
+
}));
|
|
2193
|
+
router.get("/branches", read("read branches", (c) => reader.branches(targetOf(c))));
|
|
2194
|
+
return router;
|
|
2195
|
+
}
|
|
2196
|
+
function taskDiffRoute(reader) {
|
|
2197
|
+
const router = new hono.Hono();
|
|
2198
|
+
router.get("/:sessionId/tasks/:taskId/diff", read("read task diff", (c) => reader.taskDiff(workspaceOf(c), c.req.param("sessionId") ?? "", c.req.param("taskId") ?? "", {
|
|
2199
|
+
repo: optional(c, "repo"),
|
|
2200
|
+
path: optional(c, "path"),
|
|
2201
|
+
names: flag(c, "names")
|
|
2202
|
+
})));
|
|
2203
|
+
return router;
|
|
2204
|
+
}
|
|
2205
|
+
function bad(message) {
|
|
2206
|
+
throw new InvalidBodyError(message);
|
|
2207
|
+
}
|
|
2208
|
+
function text(body, name) {
|
|
2209
|
+
const value = body[name];
|
|
2210
|
+
if (typeof value !== "string") bad(`"${name}" must be a string.`);
|
|
2211
|
+
return value;
|
|
2212
|
+
}
|
|
2213
|
+
function optionalText(body, name) {
|
|
2214
|
+
return body[name] === void 0 ? void 0 : text(body, name);
|
|
2215
|
+
}
|
|
2216
|
+
function texts(body, name) {
|
|
2217
|
+
const value = body[name];
|
|
2218
|
+
if (value === void 0) return void 0;
|
|
2219
|
+
if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) bad(`"${name}" must be a list of strings.`);
|
|
2220
|
+
return value;
|
|
2221
|
+
}
|
|
2222
|
+
function yes(body, name) {
|
|
2223
|
+
const value = body[name];
|
|
2224
|
+
if (value === void 0) return void 0;
|
|
2225
|
+
if (typeof value !== "boolean") bad(`"${name}" must be true or false.`);
|
|
2226
|
+
return value;
|
|
2227
|
+
}
|
|
2228
|
+
function confirmOf(body) {
|
|
2229
|
+
const value = body.confirm;
|
|
2230
|
+
if (value === void 0) return {};
|
|
2231
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) bad('"confirm" must be an object.');
|
|
2232
|
+
return value;
|
|
2233
|
+
}
|
|
2234
|
+
function scopeOf(body) {
|
|
2235
|
+
const workspace = optionalText(body, "workspace") || process.cwd();
|
|
2236
|
+
core.assertWorkspaceExists(workspace);
|
|
2237
|
+
const repo = optionalText(body, "repo");
|
|
2238
|
+
return repo ? { workspace, repo } : { workspace };
|
|
2239
|
+
}
|
|
2240
|
+
function changes(body) {
|
|
2241
|
+
const paths = texts(body, "paths");
|
|
2242
|
+
const hunks = optionalText(body, "hunks");
|
|
2243
|
+
if (paths === void 0 === (hunks === void 0)) bad('Name either "paths" or "hunks".');
|
|
2244
|
+
return hunks !== void 0 ? { hunks } : { paths };
|
|
2245
|
+
}
|
|
2246
|
+
function act(label, action) {
|
|
2247
|
+
return async (c) => {
|
|
2248
|
+
try {
|
|
2249
|
+
const body = await jsonObject(c);
|
|
2250
|
+
return c.json(await action(scopeOf(body), body));
|
|
2251
|
+
} catch (err) {
|
|
2252
|
+
return failure(c, err, label, { message: "Could not act on the repository" });
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
}
|
|
2256
|
+
function fileWriteRoute(git) {
|
|
2257
|
+
const router = new hono.Hono();
|
|
2258
|
+
router.put("/content", act("save file", (scope, body) => {
|
|
2259
|
+
const baseHash = body.baseHash === null ? null : text(body, "baseHash");
|
|
2260
|
+
return git.save(scope, { path: text(body, "path"), text: text(body, "text"), baseHash });
|
|
2261
|
+
}));
|
|
2262
|
+
return router;
|
|
2263
|
+
}
|
|
2264
|
+
function gitWriteRoute(git) {
|
|
2265
|
+
const router = new hono.Hono();
|
|
2266
|
+
router.post("/stage", act("stage", (scope, body) => git.stage(scope, changes(body))));
|
|
2267
|
+
router.post("/unstage", act("unstage", (scope, body) => git.unstage(scope, changes(body))));
|
|
2268
|
+
router.post("/commit", act("commit", (scope, body) => {
|
|
2269
|
+
const amend = yes(body, "amend");
|
|
2270
|
+
const head = confirmOf(body).head;
|
|
2271
|
+
return git.commit(scope, {
|
|
2272
|
+
message: text(body, "message"),
|
|
2273
|
+
...amend !== void 0 ? { amend } : {},
|
|
2274
|
+
...typeof head === "string" ? { confirm: { head } } : {}
|
|
2275
|
+
});
|
|
2276
|
+
}));
|
|
2277
|
+
router.post("/discard", act("discard", (scope, body) => {
|
|
2278
|
+
const files = texts(confirmOf(body), "files") ?? [];
|
|
2279
|
+
return git.discard(scope, { ...changes(body), confirm: { files } });
|
|
2280
|
+
}));
|
|
2281
|
+
router.post("/branch", act("create branch", (scope, body) => {
|
|
2282
|
+
const from = optionalText(body, "from");
|
|
2283
|
+
const switching = yes(body, "switch");
|
|
2284
|
+
return git.createBranch(scope, { name: text(body, "name"), ...from !== void 0 ? { from } : {}, ...switching !== void 0 ? { switch: switching } : {} });
|
|
2285
|
+
}));
|
|
2286
|
+
router.post("/switch", act("switch branch", (scope, body) => git.switchBranch(scope, { branch: text(body, "branch") })));
|
|
2287
|
+
router.post("/branch-delete", act("delete branch", (scope, body) => {
|
|
2288
|
+
const confirm = confirmOf(body);
|
|
2289
|
+
const shown = typeof confirm.branch === "string" ? confirm.branch : "";
|
|
2290
|
+
if (typeof confirm.unmerged !== "boolean") bad('"confirm.unmerged" must say whether the branch was shown as unmerged.');
|
|
2291
|
+
return git.deleteBranch(scope, { branch: text(body, "branch"), confirm: { branch: shown, unmerged: confirm.unmerged } });
|
|
2292
|
+
}));
|
|
2293
|
+
router.post("/stash", act("stash", (scope, body) => {
|
|
2294
|
+
const paths = texts(body, "paths");
|
|
2295
|
+
const message = optionalText(body, "message");
|
|
2296
|
+
return git.stash(scope, { ...paths !== void 0 ? { paths } : {}, ...message !== void 0 ? { message } : {} });
|
|
2297
|
+
}));
|
|
2298
|
+
router.post("/stash-pop", act("pop stash", (scope, body) => git.stashPop(scope, { stash: text(body, "stash") })));
|
|
2299
|
+
router.post("/stash-drop", act("drop stash", (scope, body) => git.stashDrop(scope, { stash: text(body, "stash") })));
|
|
2300
|
+
router.post("/fetch", act("fetch", (scope) => git.fetch(scope)));
|
|
2301
|
+
const remote = (body) => {
|
|
2302
|
+
const confirm = confirmOf(body);
|
|
2303
|
+
return { remote: typeof confirm.remote === "string" ? confirm.remote : "", branch: typeof confirm.branch === "string" ? confirm.branch : "" };
|
|
2304
|
+
};
|
|
2305
|
+
router.post("/pull", act("pull", (scope, body) => git.pull(scope, { confirm: remote(body) })));
|
|
2306
|
+
router.post("/push", act("push", (scope, body) => git.push(scope, { confirm: remote(body) })));
|
|
2307
|
+
return router;
|
|
2308
|
+
}
|
|
2309
|
+
function mergePreflightRoute(reader) {
|
|
2310
|
+
const router = new hono.Hono();
|
|
2311
|
+
router.get("/:sessionId/isolation/merge-preflight", async (c) => {
|
|
2312
|
+
try {
|
|
2313
|
+
const workspace = c.req.query("workspace") || process.cwd();
|
|
2314
|
+
core.assertWorkspaceExists(workspace);
|
|
2315
|
+
return c.json(await reader.mergePreflight(workspace, c.req.param("sessionId") ?? ""));
|
|
2316
|
+
} catch (err) {
|
|
2317
|
+
return failure(c, err, "merge preflight", { message: "Could not read the run" });
|
|
2318
|
+
}
|
|
2319
|
+
});
|
|
2320
|
+
return router;
|
|
2321
|
+
}
|
|
2046
2322
|
var CHILD_PATH = /^\/ws\/session\/([^/]+)\/child\/([^/]+)$/;
|
|
2047
|
-
function joinChild(
|
|
2048
|
-
const leave = () =>
|
|
2323
|
+
function joinChild(pool, ws, rootId, childId) {
|
|
2324
|
+
const leave = () => pool.unwatchChild(rootId, childId, ws);
|
|
2049
2325
|
ws.on("close", leave);
|
|
2050
2326
|
ws.on("error", leave);
|
|
2051
2327
|
const refuse3 = () => ws.close(4404, "No such child plan in this tree");
|
|
2052
|
-
void
|
|
2328
|
+
void pool.watchChild(rootId, childId, ws).then((watching) => {
|
|
2053
2329
|
if (!watching) refuse3();
|
|
2054
2330
|
}, refuse3);
|
|
2055
2331
|
}
|
|
2056
|
-
function createWsHandler(
|
|
2332
|
+
function createWsHandler(pool) {
|
|
2057
2333
|
const wss = new ws.WebSocketServer({
|
|
2058
2334
|
noServer: true,
|
|
2059
2335
|
// Select the plain subprotocol explicitly. Left to itself `ws` echoes back
|
|
@@ -2065,32 +2341,32 @@ function createWsHandler(pool2) {
|
|
|
2065
2341
|
const url = new URL(request.url ?? "", `http://${request.headers.host}`);
|
|
2066
2342
|
const child = CHILD_PATH.exec(url.pathname);
|
|
2067
2343
|
if (child) {
|
|
2068
|
-
joinChild(
|
|
2344
|
+
joinChild(pool, ws, child[1], child[2]);
|
|
2069
2345
|
return;
|
|
2070
2346
|
}
|
|
2071
2347
|
const sessionId = url.pathname.split("/").pop() || "";
|
|
2072
2348
|
ws.on("close", () => {
|
|
2073
|
-
|
|
2349
|
+
pool.unsubscribe(sessionId, ws);
|
|
2074
2350
|
});
|
|
2075
2351
|
ws.on("error", () => {
|
|
2076
|
-
|
|
2352
|
+
pool.unsubscribe(sessionId, ws);
|
|
2077
2353
|
});
|
|
2078
2354
|
ws.send(JSON.stringify({ type: "connected", sessionId }));
|
|
2079
|
-
const view =
|
|
2355
|
+
const view = pool.runSnapshot(sessionId);
|
|
2080
2356
|
if (view) {
|
|
2081
2357
|
ws.send(JSON.stringify({
|
|
2082
2358
|
type: "run_snapshot",
|
|
2083
2359
|
sessionId,
|
|
2084
2360
|
view,
|
|
2085
|
-
approvals:
|
|
2086
|
-
...
|
|
2361
|
+
approvals: pool.announcedApprovals(sessionId),
|
|
2362
|
+
...pool.streamPosition(sessionId)
|
|
2087
2363
|
}));
|
|
2088
2364
|
}
|
|
2089
|
-
const compaction =
|
|
2365
|
+
const compaction = pool.plannerCompaction(sessionId);
|
|
2090
2366
|
if (compaction) ws.send(JSON.stringify(compaction));
|
|
2091
|
-
const detection =
|
|
2367
|
+
const detection = pool.plannerDetection(sessionId);
|
|
2092
2368
|
if (detection?.waiting) ws.send(JSON.stringify(detection));
|
|
2093
|
-
|
|
2369
|
+
pool.subscribe(sessionId, ws);
|
|
2094
2370
|
});
|
|
2095
2371
|
return (request, socket, head) => {
|
|
2096
2372
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
@@ -2124,12 +2400,12 @@ function decideAdmission(headers, context) {
|
|
|
2124
2400
|
}
|
|
2125
2401
|
return ADMIT;
|
|
2126
2402
|
}
|
|
2127
|
-
function isOwnLoopbackAuthority(host,
|
|
2403
|
+
function isOwnLoopbackAuthority(host, port) {
|
|
2128
2404
|
if (!host) return false;
|
|
2129
2405
|
const authority = splitAuthority(host);
|
|
2130
2406
|
if (!authority) return false;
|
|
2131
2407
|
if (!LOOPBACK_HOSTNAMES.has(authority.hostname.toLowerCase())) return false;
|
|
2132
|
-
return authority.port ===
|
|
2408
|
+
return authority.port === port;
|
|
2133
2409
|
}
|
|
2134
2410
|
var DEFAULT_HTTP_PORT = 80;
|
|
2135
2411
|
function splitAuthority(host) {
|
|
@@ -2149,13 +2425,46 @@ function splitAuthority(host) {
|
|
|
2149
2425
|
if (value.indexOf(":", colon + 1) !== -1) return void 0;
|
|
2150
2426
|
return withPort(value.slice(0, colon), value.slice(colon + 1));
|
|
2151
2427
|
}
|
|
2152
|
-
function withPort(hostname,
|
|
2153
|
-
if (!/^\d+$/.test(
|
|
2154
|
-
return { hostname, port: Number(
|
|
2428
|
+
function withPort(hostname, port) {
|
|
2429
|
+
if (!/^\d+$/.test(port)) return void 0;
|
|
2430
|
+
return { hostname, port: Number(port) };
|
|
2431
|
+
}
|
|
2432
|
+
var cached;
|
|
2433
|
+
function serverVersion(from = __dirname, sea = {}) {
|
|
2434
|
+
const embedded = embeddedVersion(sea);
|
|
2435
|
+
if (embedded) return embedded;
|
|
2436
|
+
if (cached !== void 0) return cached;
|
|
2437
|
+
cached = findVersion(from);
|
|
2438
|
+
return cached;
|
|
2439
|
+
}
|
|
2440
|
+
function embeddedVersion(sea) {
|
|
2441
|
+
try {
|
|
2442
|
+
return core.seaVersion(sea);
|
|
2443
|
+
} catch {
|
|
2444
|
+
return "unknown";
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
function findVersion(from) {
|
|
2448
|
+
for (let dir = from; ; dir = path.dirname(dir)) {
|
|
2449
|
+
try {
|
|
2450
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
2451
|
+
const { name, version } = pkg;
|
|
2452
|
+
if (name === "@ordewell/web" && typeof version === "string" && version) return version;
|
|
2453
|
+
} catch {
|
|
2454
|
+
}
|
|
2455
|
+
if (path.dirname(dir) === dir) return "unknown";
|
|
2456
|
+
}
|
|
2155
2457
|
}
|
|
2156
2458
|
|
|
2157
2459
|
// server/app.ts
|
|
2158
|
-
function
|
|
2460
|
+
function userGitFor(pool, reader) {
|
|
2461
|
+
return core.createUserGit({
|
|
2462
|
+
reader,
|
|
2463
|
+
landingRuns: (checkout) => core.landingRuns(checkout, (workspace, sessionId, plan) => pool.userRunIsLive(sessionId, workspace, plan)),
|
|
2464
|
+
record: (workspace, held, text2) => pool.recordUserAction(held.sessionId, workspace, text2)
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
function createApp(pool, admission, reader = core.createWorkspaceReader({ config: new WebConfig() }), userGit = userGitFor(pool, reader)) {
|
|
2159
2468
|
const app = new hono.Hono();
|
|
2160
2469
|
app.use("*", async (c, next) => {
|
|
2161
2470
|
const decision = decideAdmission({
|
|
@@ -2169,21 +2478,33 @@ function createApp(pool2, admission) {
|
|
|
2169
2478
|
if (!decision.admit) return c.json({ error: decision.reason }, decision.status);
|
|
2170
2479
|
await next();
|
|
2171
2480
|
});
|
|
2172
|
-
app.get("/api/server", (c) => c.json({
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2481
|
+
app.get("/api/server", (c) => c.json({
|
|
2482
|
+
pid: process.pid,
|
|
2483
|
+
port: admission.port,
|
|
2484
|
+
version: serverVersion(),
|
|
2485
|
+
contract: core.DAEMON_CONTRACT,
|
|
2486
|
+
live: pool.workLive()
|
|
2487
|
+
}));
|
|
2488
|
+
app.route("/api/sessions", sessionsRoute(pool));
|
|
2489
|
+
app.route("/api/sessions", childrenRoute(pool));
|
|
2490
|
+
app.route("/api/plans", plansRoute(pool));
|
|
2491
|
+
app.route("/api/plans", taskDiffRoute(reader));
|
|
2492
|
+
app.route("/api/plans", mergePreflightRoute(reader));
|
|
2493
|
+
app.route("/api/runners", runnersRoute(pool));
|
|
2494
|
+
app.route("/api/models", modelsRoute(pool));
|
|
2495
|
+
app.route("/api/settings", settingsRoute(pool));
|
|
2179
2496
|
app.route("/api/commands", commandsRoute());
|
|
2180
|
-
app.route("/api/workspaces", workspacesRoute(
|
|
2181
|
-
app.route("/api/approvals", approvalsRoute(
|
|
2497
|
+
app.route("/api/workspaces", workspacesRoute(pool));
|
|
2498
|
+
app.route("/api/approvals", approvalsRoute(pool));
|
|
2499
|
+
app.route("/api/files", filesRoute(reader));
|
|
2500
|
+
app.route("/api/git", gitRoute(reader));
|
|
2501
|
+
app.route("/api/files", fileWriteRoute(userGit));
|
|
2502
|
+
app.route("/api/git", gitWriteRoute(userGit));
|
|
2182
2503
|
return app;
|
|
2183
2504
|
}
|
|
2184
|
-
function attachWsHandler(
|
|
2185
|
-
const handler = createWsHandler(
|
|
2186
|
-
|
|
2505
|
+
function attachWsHandler(server, pool, admission) {
|
|
2506
|
+
const handler = createWsHandler(pool);
|
|
2507
|
+
server.on("upgrade", (request, socket, head) => {
|
|
2187
2508
|
const decision = decideAdmission({
|
|
2188
2509
|
origin: request.headers.origin ?? null,
|
|
2189
2510
|
host: request.headers.host ?? null,
|
|
@@ -2322,73 +2643,77 @@ function createRequestListener(app, admission, maxBodyBytes = MAX_BODY_BYTES) {
|
|
|
2322
2643
|
}
|
|
2323
2644
|
};
|
|
2324
2645
|
}
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
2329
|
-
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
core.processLeaseHost().describe({ kind: "daemon", port, ...watchParentPid ? { ownerPid: watchParentPid } : {} });
|
|
2337
|
-
|
|
2338
|
-
void pool.detectInstalledPlanner();
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
server.listen(port, "127.0.0.1", () => {
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
});
|
|
2359
|
-
function shutdown() {
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2646
|
+
function runDaemon(args) {
|
|
2647
|
+
let port = 3742;
|
|
2648
|
+
const portIdx = args.indexOf("--port");
|
|
2649
|
+
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
2650
|
+
port = parseInt(args[portIdx + 1], 10) || 3742;
|
|
2651
|
+
}
|
|
2652
|
+
const watchParentIdx = args.indexOf("--watch-parent");
|
|
2653
|
+
const watchParentPid = watchParentIdx !== -1 ? parseInt(args[watchParentIdx + 1], 10) : void 0;
|
|
2654
|
+
const pidFileIdx = args.indexOf("--pid-file");
|
|
2655
|
+
const pidFile = pidFileIdx !== -1 ? args[pidFileIdx + 1] : void 0;
|
|
2656
|
+
let ownsPidFile = false;
|
|
2657
|
+
core.processLeaseHost().describe({ kind: "daemon", port, ...watchParentPid ? { ownerPid: watchParentPid } : {} });
|
|
2658
|
+
const pool = new OrchestratorPool({ runner: new core.StructuredRunner() });
|
|
2659
|
+
void pool.detectInstalledPlanner();
|
|
2660
|
+
const server = http.createServer();
|
|
2661
|
+
let ownsToken = false;
|
|
2662
|
+
server.listen(port, "127.0.0.1", () => {
|
|
2663
|
+
const { token, file: tokenFile } = core.mintDaemonToken(port);
|
|
2664
|
+
ownsToken = true;
|
|
2665
|
+
if (pidFile) {
|
|
2666
|
+
fs.mkdirSync(path.dirname(pidFile), { recursive: true });
|
|
2667
|
+
fs.writeFileSync(pidFile, String(process.pid), { mode: 384 });
|
|
2668
|
+
ownsPidFile = true;
|
|
2669
|
+
}
|
|
2670
|
+
const admission = { port, token, tokenFile };
|
|
2671
|
+
const app = createApp(pool, admission);
|
|
2672
|
+
app.get("/", (c) => c.json({ message: "Ordewell API", docs: "/api/workspaces" }));
|
|
2673
|
+
server.on("request", createRequestListener(app, admission));
|
|
2674
|
+
attachWsHandler(server, pool, admission);
|
|
2675
|
+
pool.getProviderModels().catch((err) => {
|
|
2676
|
+
console.error(`[web] model discovery warmup failed: ${err?.message ?? err}`);
|
|
2677
|
+
});
|
|
2678
|
+
console.error(`[web] Ordewell API server: http://localhost:${port}`);
|
|
2679
|
+
});
|
|
2680
|
+
function shutdown() {
|
|
2681
|
+
if (ownsToken) core.clearDaemonToken(port);
|
|
2682
|
+
if (ownsPidFile && pidFile) {
|
|
2683
|
+
try {
|
|
2684
|
+
fs.unlinkSync(pidFile);
|
|
2685
|
+
} catch {
|
|
2686
|
+
}
|
|
2365
2687
|
}
|
|
2688
|
+
pool.destroyAll();
|
|
2689
|
+
server.close();
|
|
2690
|
+
process.exit(0);
|
|
2691
|
+
}
|
|
2692
|
+
process.on("unhandledRejection", (reason) => {
|
|
2693
|
+
console.error(`[web] unhandled rejection: ${reason instanceof Error ? reason.stack ?? reason.message : String(reason)}`);
|
|
2694
|
+
});
|
|
2695
|
+
process.on("SIGINT", () => {
|
|
2696
|
+
if (!watchParentPid) shutdown();
|
|
2697
|
+
});
|
|
2698
|
+
process.on("SIGTERM", () => {
|
|
2699
|
+
shutdown();
|
|
2700
|
+
});
|
|
2701
|
+
process.on("SIGHUP", () => {
|
|
2702
|
+
shutdown();
|
|
2703
|
+
});
|
|
2704
|
+
if (watchParentPid) {
|
|
2705
|
+
const parentCheck = setInterval(() => {
|
|
2706
|
+
try {
|
|
2707
|
+
process.kill(watchParentPid, 0);
|
|
2708
|
+
} catch {
|
|
2709
|
+
clearInterval(parentCheck);
|
|
2710
|
+
shutdown();
|
|
2711
|
+
}
|
|
2712
|
+
}, 5e3);
|
|
2366
2713
|
}
|
|
2367
|
-
pool.destroyAll();
|
|
2368
|
-
server.close();
|
|
2369
|
-
process.exit(0);
|
|
2370
|
-
}
|
|
2371
|
-
process.on("unhandledRejection", (reason) => {
|
|
2372
|
-
console.error(`[web] unhandled rejection: ${reason instanceof Error ? reason.stack ?? reason.message : String(reason)}`);
|
|
2373
|
-
});
|
|
2374
|
-
process.on("SIGINT", () => {
|
|
2375
|
-
if (!watchParentPid) shutdown();
|
|
2376
|
-
});
|
|
2377
|
-
process.on("SIGTERM", () => {
|
|
2378
|
-
shutdown();
|
|
2379
|
-
});
|
|
2380
|
-
process.on("SIGHUP", () => {
|
|
2381
|
-
shutdown();
|
|
2382
|
-
});
|
|
2383
|
-
if (watchParentPid) {
|
|
2384
|
-
const parentCheck = setInterval(() => {
|
|
2385
|
-
try {
|
|
2386
|
-
process.kill(watchParentPid, 0);
|
|
2387
|
-
} catch {
|
|
2388
|
-
clearInterval(parentCheck);
|
|
2389
|
-
shutdown();
|
|
2390
|
-
}
|
|
2391
|
-
}, 5e3);
|
|
2392
2714
|
}
|
|
2715
|
+
|
|
2716
|
+
// server/main.ts
|
|
2717
|
+
runDaemon(process.argv.slice(2));
|
|
2393
2718
|
//# sourceMappingURL=main.js.map
|
|
2394
2719
|
//# sourceMappingURL=main.js.map
|