@nathanstephenson/flow 0.1.10-beta.3 → 0.1.10-beta.5
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/README.md +11 -3
- package/build/backend-worker-chunks/{chunk-LO7O6NAM.mjs → chunk-JOI2POLP.mjs} +1 -1
- package/build/backend-worker-chunks/{chunk-UQDH2COY.mjs → chunk-K774KOGL.mjs} +2 -7
- package/build/backend-worker-chunks/chunk-LAEUXDNH.mjs +130 -0
- package/build/backend-worker-chunks/{chunk-MLOUI3ZM.mjs → chunk-NZZME2I3.mjs} +6 -1
- package/build/backend-worker-chunks/claude-GY27HBAY.mjs +35739 -0
- package/build/backend-worker-chunks/{pi-QNU2YE4G.mjs → pi-JV6MWPW7.mjs} +1891 -35
- package/build/backend-worker.mjs +25 -126
- package/build/workflow-runtime.cjs +12 -12
- package/dist/backend/claude/index.js +69 -11
- package/dist/backend/claude/subagents.js +11 -0
- package/dist/backend/claude/workflow-parent.js +1 -1
- package/dist/backend/fake/index.js +8 -2
- package/dist/backend/pi/cache-warming.js +8 -0
- package/dist/backend/pi/canonical-json.js +120 -0
- package/dist/backend/pi/compaction-model.js +3 -2
- package/dist/backend/pi/host-auth.js +258 -0
- package/dist/backend/pi/index.js +37 -12
- package/dist/backend/pi/model-auth.js +159 -0
- package/dist/backend/pi/model-catalog.js +120 -0
- package/dist/backend/pi/model-config.js +5 -0
- package/dist/backend/pi/model-selection.js +32 -0
- package/dist/backend/pi/work.js +9 -1
- package/dist/backend/pi/workflow-parent.js +1 -1
- package/dist/backend/pi/workflow-subagent.js +4 -3
- package/dist/backend/worker/entry.js +13 -1
- package/dist/backend/worker/index.js +69 -7
- package/dist/backend/worker/launcher.js +11 -4
- package/dist/build-id +1 -1
- package/dist/cli/application.js +5 -5
- package/dist/cli/bootstrap.js +1 -1
- package/dist/cli/host-control.js +1 -1
- package/dist/cli/install-guard.js +1 -1
- package/dist/cli/main.js +4 -4
- package/dist/cli/systemd-update.js +3 -3
- package/dist/cli/update.js +6 -6
- package/dist/cli/web-update.js +6 -6
- package/dist/client/reduce.js +2 -0
- package/dist/client/tool-summary.js +26 -15
- package/dist/daemon/changes.js +116 -0
- package/dist/daemon/commit.js +84 -0
- package/dist/daemon/config-store.js +3 -3
- package/dist/daemon/git-state.js +197 -0
- package/dist/daemon/github.js +54 -0
- package/dist/daemon/host-control-routes.js +1 -1
- package/dist/daemon/host.js +147 -78
- package/dist/daemon/log.js +3 -0
- package/dist/daemon/mcp-auth.js +1 -1
- package/dist/daemon/models.js +2 -2
- package/dist/daemon/pi-model-cache.js +44 -0
- package/dist/daemon/pull-request.js +156 -129
- package/dist/daemon/push.js +43 -0
- package/dist/daemon/repository.js +106 -0
- package/dist/daemon/runtime.js +27 -20
- package/dist/daemon/secret-store.js +1 -1
- package/dist/daemon/server.js +11 -10
- package/dist/daemon/stack-metadata.js +12 -5
- package/dist/daemon/stack.js +127 -656
- package/dist/daemon/summariser.js +19 -8
- package/dist/daemon/workflow-authoring-scope-checks.js +1 -1
- package/dist/daemon/workflow-authoring-scope.js +1 -1
- package/dist/daemon/workflow-builder-files.js +2 -2
- package/dist/daemon/workflow-builder-routes.js +2 -2
- package/dist/daemon/workflow-builder.js +5 -5
- package/dist/daemon/workflow-environment.js +5 -5
- package/dist/daemon/workflow-execution-launch.js +5 -5
- package/dist/daemon/workflow-execution-resources.js +3 -3
- package/dist/daemon/workflow-execution-routes.js +3 -3
- package/dist/daemon/workflow-execution-values.js +5 -5
- package/dist/daemon/workflow-executions.js +19 -19
- package/dist/daemon/workflow-mcp-authoring-routes.js +2 -2
- package/dist/daemon/workflow-mcp-authoring.js +4 -4
- package/dist/daemon/workflow-mcp.js +1 -1
- package/dist/daemon/workflow-routes.js +3 -3
- package/dist/daemon/workflow-schedule-driver.js +8 -8
- package/dist/daemon/workflow-schedule-routes.js +5 -5
- package/dist/daemon/workflow-schedules.js +3 -3
- package/dist/isolation/filesystem.js +5 -1
- package/dist/isolation/sandbox.js +31 -4
- package/dist/isolation/toolchain-assets.js +1 -1
- package/dist/protocol/stack.js +1 -41
- package/dist/workflows/calls.js +2 -2
- package/dist/workflows/executors.js +3 -3
- package/dist/workflows/graph.js +6 -6
- package/dist/workflows/invocations.js +1 -1
- package/dist/workflows/mcp.js +1 -1
- package/dist/workflows/records.js +6 -6
- package/dist/workflows/recovery.js +2 -2
- package/dist/workflows/runtime-settings.js +1 -1
- package/dist/workflows/runtime.js +2 -2
- package/dist/workflows/schedule-store.js +2 -2
- package/dist/workflows/scheduler.js +9 -9
- package/dist/workflows/schema.js +1 -1
- package/dist/workflows/store.js +3 -3
- package/package.json +9 -6
- package/web/dist/assets/index-BqZ_iUmY.css +2 -0
- package/web/dist/assets/index-CxdSb7k0.js +51 -0
- package/web/dist/assets/{settings-mcp-Vf_fCXyE.js → settings-mcp-BwOPXAfH.js} +1 -1
- package/web/dist/assets/settings-workflows-DocTa31_.js +23 -0
- package/web/dist/assets/{switch-DIogWclb.js → switch-B00FEUA7.js} +1 -1
- package/web/dist/assets/{workflows-Dobqzjg-.js → workflows-DJqUuGyg.js} +41 -41
- package/web/dist/assets/{workflows-pane-KB-Q76KZ.js → workflows-pane-oM1fO_BC.js} +1 -1
- package/web/dist/index.html +4 -4
- package/build/backend-worker-chunks/claude-6L5KCQWJ.mjs +0 -30894
- package/dist/daemon/publish.js +0 -289
- package/dist/protocol/publish.js +0 -1
- package/web/dist/assets/index-BGu3YSP7.css +0 -2
- package/web/dist/assets/index-Miy2nveb.js +0 -40
- package/web/dist/assets/settings-workflows-DVKxJWQm.js +0 -23
package/build/backend-worker.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRequire as __flowCreateRequire } from 'node:module'; const require = __flowCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
AjvJsonSchemaValidator,
|
|
4
|
-
AutoPermissionUnavailable,
|
|
5
4
|
CallToolResultSchema,
|
|
6
5
|
CompleteResultSchema,
|
|
7
6
|
CreateMessageRequestSchema,
|
|
@@ -37,7 +36,12 @@ import {
|
|
|
37
36
|
isJSONRPCResultResponse,
|
|
38
37
|
mergeCapabilities,
|
|
39
38
|
safeParse
|
|
40
|
-
} from "./backend-worker-chunks/chunk-
|
|
39
|
+
} from "./backend-worker-chunks/chunk-K774KOGL.mjs";
|
|
40
|
+
import {
|
|
41
|
+
WorkerRpc,
|
|
42
|
+
errorText,
|
|
43
|
+
waitForAbort
|
|
44
|
+
} from "./backend-worker-chunks/chunk-LAEUXDNH.mjs";
|
|
41
45
|
import {
|
|
42
46
|
NEVER,
|
|
43
47
|
ZodIssueCode,
|
|
@@ -54,7 +58,7 @@ import {
|
|
|
54
58
|
object,
|
|
55
59
|
string,
|
|
56
60
|
url
|
|
57
|
-
} from "./backend-worker-chunks/chunk-
|
|
61
|
+
} from "./backend-worker-chunks/chunk-NZZME2I3.mjs";
|
|
58
62
|
|
|
59
63
|
// node_modules/isexe/windows.js
|
|
60
64
|
var require_windows = __commonJS({
|
|
@@ -1093,7 +1097,11 @@ async function prepareFilesystemIsolation(options) {
|
|
|
1093
1097
|
}
|
|
1094
1098
|
};
|
|
1095
1099
|
if (options.credentials === "pi") {
|
|
1096
|
-
|
|
1100
|
+
const auth2 = join3(piDir, "auth.json");
|
|
1101
|
+
if (existsSync3(auth2) && (!statSync3(auth2).isFile() || realpathSync3(auth2) !== resolve2(auth2))) {
|
|
1102
|
+
throw new Error(`Credential must be a regular, non-symlink file: ${auth2}`);
|
|
1103
|
+
}
|
|
1104
|
+
for (const name of ["models.json", "settings.json"]) stage(join3(piDir, name), join3(env.PI_CODING_AGENT_DIR, name));
|
|
1097
1105
|
if (!options.workflowBuilder) resources("Pi", piDir, env.PI_CODING_AGENT_DIR, ["AGENTS.md", "skills", "prompts", "themes", "extensions", "packages", "bin", "tools"]);
|
|
1098
1106
|
} else if (options.credentials === "claude") {
|
|
1099
1107
|
stage(join3(claudeAuthDir, ".credentials.json"), join3(env.CLAUDE_CONFIG_DIR, ".credentials.json"));
|
|
@@ -3942,126 +3950,6 @@ var McpSession = class {
|
|
|
3942
3950
|
}
|
|
3943
3951
|
};
|
|
3944
3952
|
|
|
3945
|
-
// src/backend/worker/rpc.ts
|
|
3946
|
-
function waitForAbort(work, signal) {
|
|
3947
|
-
if (!signal) return work;
|
|
3948
|
-
return new Promise((resolve4, reject) => {
|
|
3949
|
-
const abort = () => {
|
|
3950
|
-
reject(signal.reason);
|
|
3951
|
-
};
|
|
3952
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
3953
|
-
void work.then(resolve4, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
3954
|
-
if (signal.aborted) {
|
|
3955
|
-
signal.removeEventListener("abort", abort);
|
|
3956
|
-
abort();
|
|
3957
|
-
}
|
|
3958
|
-
});
|
|
3959
|
-
}
|
|
3960
|
-
function errorText(error) {
|
|
3961
|
-
return error instanceof Error ? error.message : String(error);
|
|
3962
|
-
}
|
|
3963
|
-
var WorkerRpc = class {
|
|
3964
|
-
nextId = 0;
|
|
3965
|
-
failure;
|
|
3966
|
-
pending = /* @__PURE__ */ new Map();
|
|
3967
|
-
incoming = /* @__PURE__ */ new Map();
|
|
3968
|
-
send;
|
|
3969
|
-
dispatch;
|
|
3970
|
-
notification;
|
|
3971
|
-
constructor(send, dispatch, notification) {
|
|
3972
|
-
this.send = send;
|
|
3973
|
-
this.dispatch = dispatch;
|
|
3974
|
-
this.notification = notification;
|
|
3975
|
-
}
|
|
3976
|
-
call(method, args = [], signal) {
|
|
3977
|
-
if (this.failure) return Promise.reject(this.failure);
|
|
3978
|
-
if (signal?.aborted) return Promise.reject(new Error("Worker call cancelled"));
|
|
3979
|
-
const id = ++this.nextId;
|
|
3980
|
-
return new Promise((resolve4, reject) => {
|
|
3981
|
-
const abort = () => {
|
|
3982
|
-
this.pending.delete(id);
|
|
3983
|
-
try {
|
|
3984
|
-
this.send({ kind: "cancel", id });
|
|
3985
|
-
} catch {
|
|
3986
|
-
}
|
|
3987
|
-
reject(new Error("Worker call cancelled"));
|
|
3988
|
-
};
|
|
3989
|
-
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
3990
|
-
this.pending.set(id, {
|
|
3991
|
-
resolve: (value) => {
|
|
3992
|
-
cleanup();
|
|
3993
|
-
resolve4(value);
|
|
3994
|
-
},
|
|
3995
|
-
reject: (error) => {
|
|
3996
|
-
cleanup();
|
|
3997
|
-
reject(error);
|
|
3998
|
-
}
|
|
3999
|
-
});
|
|
4000
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
4001
|
-
try {
|
|
4002
|
-
this.send({ kind: "call", id, method, args });
|
|
4003
|
-
} catch (error) {
|
|
4004
|
-
this.pending.delete(id);
|
|
4005
|
-
cleanup();
|
|
4006
|
-
reject(error);
|
|
4007
|
-
}
|
|
4008
|
-
});
|
|
4009
|
-
}
|
|
4010
|
-
notify(name, value) {
|
|
4011
|
-
if (!this.failure) this.send({ kind: "notification", name, value });
|
|
4012
|
-
}
|
|
4013
|
-
receive(raw) {
|
|
4014
|
-
if (this.failure || !raw || typeof raw !== "object") return;
|
|
4015
|
-
const message = raw;
|
|
4016
|
-
switch (message.kind) {
|
|
4017
|
-
case "reply": {
|
|
4018
|
-
const pending = this.pending.get(message.id);
|
|
4019
|
-
this.pending.delete(message.id);
|
|
4020
|
-
if (message.error !== void 0) pending?.reject(message.errorCode === "auto_permission_unavailable" ? new AutoPermissionUnavailable(message.error) : new Error(message.error));
|
|
4021
|
-
else pending?.resolve(message.value);
|
|
4022
|
-
break;
|
|
4023
|
-
}
|
|
4024
|
-
case "cancel":
|
|
4025
|
-
this.incoming.get(message.id)?.abort();
|
|
4026
|
-
break;
|
|
4027
|
-
case "notification":
|
|
4028
|
-
this.notification(message.name, message.value);
|
|
4029
|
-
break;
|
|
4030
|
-
case "call": {
|
|
4031
|
-
if (!Number.isSafeInteger(message.id) || typeof message.method !== "string" || !Array.isArray(message.args) || this.incoming.has(message.id)) return;
|
|
4032
|
-
const controller = new AbortController();
|
|
4033
|
-
this.incoming.set(message.id, controller);
|
|
4034
|
-
void Promise.resolve().then(() => this.dispatch(message.method, message.args, controller.signal)).then(
|
|
4035
|
-
(value) => this.reply({ kind: "reply", id: message.id, value }),
|
|
4036
|
-
(error) => this.reply({
|
|
4037
|
-
kind: "reply",
|
|
4038
|
-
id: message.id,
|
|
4039
|
-
error: errorText(error),
|
|
4040
|
-
...error instanceof AutoPermissionUnavailable ? { errorCode: "auto_permission_unavailable" } : {}
|
|
4041
|
-
})
|
|
4042
|
-
).finally(() => this.incoming.delete(message.id));
|
|
4043
|
-
break;
|
|
4044
|
-
}
|
|
4045
|
-
}
|
|
4046
|
-
}
|
|
4047
|
-
reply(message) {
|
|
4048
|
-
if (this.failure) return;
|
|
4049
|
-
try {
|
|
4050
|
-
this.send(message);
|
|
4051
|
-
} catch (error) {
|
|
4052
|
-
this.close(new Error(errorText(error)));
|
|
4053
|
-
}
|
|
4054
|
-
}
|
|
4055
|
-
close(error) {
|
|
4056
|
-
if (this.failure) return;
|
|
4057
|
-
this.failure = error;
|
|
4058
|
-
for (const pending of this.pending.values()) pending.reject(error);
|
|
4059
|
-
this.pending.clear();
|
|
4060
|
-
for (const controller of this.incoming.values()) controller.abort();
|
|
4061
|
-
this.incoming.clear();
|
|
4062
|
-
}
|
|
4063
|
-
};
|
|
4064
|
-
|
|
4065
3953
|
// src/backend/worker/protocol.ts
|
|
4066
3954
|
function snapshot(session) {
|
|
4067
3955
|
return {
|
|
@@ -4217,7 +4105,7 @@ function runWorker() {
|
|
|
4217
4105
|
const ready = performance.now();
|
|
4218
4106
|
if (creating || closing) throw new Error("Backend worker already initialized");
|
|
4219
4107
|
creating = true;
|
|
4220
|
-
const { mcpTools, mcpConnectionIds, mcpSandbox, workflowEnabled, sessionToolsEnabled, workflowBuilderInstructions, backendModule, backend: backendName = "pi", ...options } = args[0];
|
|
4108
|
+
const { mcpTools, mcpConnectionIds, mcpSandbox, workflowEnabled, sessionToolsEnabled, workflowBuilderInstructions, piAuth, backendModule, backend: backendName = "pi", ...options } = args[0];
|
|
4221
4109
|
const workflowBuilder = workflowBuilderInstructions === void 0 ? void 0 : {
|
|
4222
4110
|
instructions: workflowBuilderInstructions,
|
|
4223
4111
|
read: (path) => rpc.call("workflowBuilder.read", [path]),
|
|
@@ -4258,13 +4146,24 @@ function runWorker() {
|
|
|
4258
4146
|
let backend;
|
|
4259
4147
|
const importing = performance.now();
|
|
4260
4148
|
try {
|
|
4261
|
-
backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-
|
|
4149
|
+
backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-GY27HBAY.mjs")).ClaudeBackend() : new (await import("./backend-worker-chunks/pi-JV6MWPW7.mjs")).PiBackend();
|
|
4262
4150
|
} catch (error) {
|
|
4263
4151
|
throw new Error(`Backend "${backendName}" is not available in this build: ${errorText(error)}`);
|
|
4264
4152
|
}
|
|
4265
4153
|
const imported = performance.now();
|
|
4154
|
+
let initialAuth = piAuth;
|
|
4266
4155
|
session = await backend.create({
|
|
4267
4156
|
...options,
|
|
4157
|
+
...piAuth ? { piAuth: {
|
|
4158
|
+
snapshot: async (signal2) => {
|
|
4159
|
+
signal2?.throwIfAborted();
|
|
4160
|
+
if (!initialAuth) return rpc.call("pi.auth.snapshot", [], signal2);
|
|
4161
|
+
const metadata = initialAuth;
|
|
4162
|
+
initialAuth = void 0;
|
|
4163
|
+
return metadata;
|
|
4164
|
+
},
|
|
4165
|
+
resolve: (providerId, signal2) => rpc.call("pi.auth.resolve", [providerId], signal2)
|
|
4166
|
+
} } : {},
|
|
4268
4167
|
...workflowBuilder ? { workflowBuilder } : {
|
|
4269
4168
|
...localMcp ? { mcp: localMcp } : mcpTools ? { mcp: { connections: (mcpConnectionIds ?? []).map((id) => ({ id })), tools: () => tools } } : {},
|
|
4270
4169
|
...workflowEnabled ? { workflow } : {},
|
|
@@ -42,9 +42,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
42
42
|
mod
|
|
43
43
|
));
|
|
44
44
|
|
|
45
|
-
// node_modules/typescript/lib/typescript.js
|
|
45
|
+
// node_modules/typescript-api/lib/typescript.js
|
|
46
46
|
var require_typescript = __commonJS({
|
|
47
|
-
"node_modules/typescript/lib/typescript.js"(exports2, module2) {
|
|
47
|
+
"node_modules/typescript-api/lib/typescript.js"(exports2, module2) {
|
|
48
48
|
var ts2 = {};
|
|
49
49
|
((module3) => {
|
|
50
50
|
"use strict";
|
|
@@ -212503,7 +212503,7 @@ var import_node_child_process = require("node:child_process");
|
|
|
212503
212503
|
var import_node_fs = require("node:fs");
|
|
212504
212504
|
var import_node_path = require("node:path");
|
|
212505
212505
|
var import_node_readline = require("node:readline");
|
|
212506
|
-
var
|
|
212506
|
+
var import_typescript_api = __toESM(require_typescript(), 1);
|
|
212507
212507
|
|
|
212508
212508
|
// node_modules/quickjs-emscripten-core/dist/index.mjs
|
|
212509
212509
|
init_chunk_V2S4ZYJR();
|
|
@@ -213698,16 +213698,16 @@ async function main(): Promise<${outputType}> {
|
|
|
213698
213698
|
${code}
|
|
213699
213699
|
}
|
|
213700
213700
|
main();`;
|
|
213701
|
-
const file =
|
|
213701
|
+
const file = import_typescript_api.default.createSourceFile("/guest.ts", source, import_typescript_api.default.ScriptTarget.ES2020, true);
|
|
213702
213702
|
const visit = (node) => {
|
|
213703
|
-
if (
|
|
213704
|
-
|
|
213703
|
+
if (import_typescript_api.default.isImportDeclaration(node) || import_typescript_api.default.isExportDeclaration(node) || import_typescript_api.default.isImportEqualsDeclaration(node) || import_typescript_api.default.isImportTypeNode(node) || node.kind === import_typescript_api.default.SyntaxKind.ImportKeyword) throw new Error("Imports are not supported");
|
|
213704
|
+
import_typescript_api.default.forEachChild(node, visit);
|
|
213705
213705
|
};
|
|
213706
213706
|
visit(file);
|
|
213707
|
-
const options = { strict: true, target:
|
|
213707
|
+
const options = { strict: true, target: import_typescript_api.default.ScriptTarget.ES2020, module: import_typescript_api.default.ModuleKind.None, types: [], noEmitOnError: true, skipLibCheck: true };
|
|
213708
213708
|
let javascript = "";
|
|
213709
213709
|
const host = {
|
|
213710
|
-
getSourceFile: (path) => path === "/guest.ts" ? file : libraries[path.replace(/^\//, "")] === void 0 ? void 0 :
|
|
213710
|
+
getSourceFile: (path) => path === "/guest.ts" ? file : libraries[path.replace(/^\//, "")] === void 0 ? void 0 : import_typescript_api.default.createSourceFile(path, libraries[path.replace(/^\//, "")], import_typescript_api.default.ScriptTarget.ES2020, true),
|
|
213711
213711
|
getDefaultLibFileName: () => "/lib.es2020.d.ts",
|
|
213712
213712
|
writeFile: (_path, text) => {
|
|
213713
213713
|
javascript = text;
|
|
@@ -213720,9 +213720,9 @@ main();`;
|
|
|
213720
213720
|
useCaseSensitiveFileNames: () => true,
|
|
213721
213721
|
getNewLine: () => "\n"
|
|
213722
213722
|
};
|
|
213723
|
-
const program =
|
|
213724
|
-
const errors =
|
|
213725
|
-
if (errors.length) throw new Error(
|
|
213723
|
+
const program = import_typescript_api.default.createProgram(["/guest.ts"], options, host);
|
|
213724
|
+
const errors = import_typescript_api.default.getPreEmitDiagnostics(program);
|
|
213725
|
+
if (errors.length) throw new Error(import_typescript_api.default.flattenDiagnosticMessageText(errors[0].messageText, "\n"));
|
|
213726
213726
|
program.emit();
|
|
213727
213727
|
return javascript;
|
|
213728
213728
|
}
|
|
@@ -213901,7 +213901,7 @@ async function guest(request) {
|
|
|
213901
213901
|
}
|
|
213902
213902
|
/*! Bundled license information:
|
|
213903
213903
|
|
|
213904
|
-
typescript/lib/typescript.js:
|
|
213904
|
+
typescript-api/lib/typescript.js:
|
|
213905
213905
|
(*! *****************************************************************************
|
|
213906
213906
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
213907
213907
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -6,7 +6,7 @@ import { claudeAutoCompactionEnv } from "./auto-compaction.js";
|
|
|
6
6
|
import { spawn, spawnSync } from "node:child_process";
|
|
7
7
|
import { query, } from "@anthropic-ai/claude-agent-sdk";
|
|
8
8
|
import { ClaudeWorkflowSubagent, spawnWorkflowProcess } from "./workflow-subagent.js";
|
|
9
|
-
import { clampEffort } from "../effort.js";
|
|
9
|
+
import { clampEffort, EFFORT_ORDER } from "../effort.js";
|
|
10
10
|
import { AsyncQueue } from "./async-queue.js";
|
|
11
11
|
import { ASK_TOOL, PendingEnquiries, questionsOf } from "./enquiries.js";
|
|
12
12
|
import { claudeMcpServers, refreshClaudeMcp } from "./mcp.js";
|
|
@@ -106,11 +106,23 @@ function promptOf(input) {
|
|
|
106
106
|
const prompt = input?.prompt;
|
|
107
107
|
return typeof prompt === "string" && prompt !== "" ? prompt : undefined;
|
|
108
108
|
}
|
|
109
|
-
export function briefOf(input) {
|
|
109
|
+
export function briefOf(input, inherited = {}, agentModels = new Map()) {
|
|
110
110
|
const fields = (input ?? {});
|
|
111
111
|
const name = typeof fields.subagent_type === "string" ? fields.subagent_type : SUBAGENT_TOOL;
|
|
112
112
|
const description = typeof fields.description === "string" ? fields.description : undefined;
|
|
113
|
-
|
|
113
|
+
const model = typeof fields.model === "string" ? fields.model : agentModels.get(name) ?? inherited.model;
|
|
114
|
+
const effort = EFFORT_ORDER.find((known) => known === fields.effort) ?? inherited.effort;
|
|
115
|
+
return {
|
|
116
|
+
name,
|
|
117
|
+
...(description === undefined ? {} : { description }),
|
|
118
|
+
...(model === undefined ? {} : { model }),
|
|
119
|
+
...(effort === undefined ? {} : { effort }),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** The model an `Agent` result says the Subagent ran on, as the picker names it where it can. */
|
|
123
|
+
export function resolvedModelOf(result, aliasOf) {
|
|
124
|
+
const resolved = result?.resolvedModel;
|
|
125
|
+
return typeof resolved === "string" ? aliasOf.get(resolved) ?? resolved : undefined;
|
|
114
126
|
}
|
|
115
127
|
/**
|
|
116
128
|
* Whether an `Agent` tool result is a launch receipt rather than the Subagent's answer.
|
|
@@ -186,6 +198,8 @@ class ClaudeSession {
|
|
|
186
198
|
announced;
|
|
187
199
|
/** Alias (`opus[1m]`) keyed by the id the SDK reports once a model is resolved. */
|
|
188
200
|
aliasOf = new Map();
|
|
201
|
+
/** The model each agent definition names, read once per session. `inherit` is left out. */
|
|
202
|
+
agentModels = new Map();
|
|
189
203
|
/** What the human asked for, kept apart from what is in force so a clamp is never destructive. */
|
|
190
204
|
wantedEffort;
|
|
191
205
|
effort;
|
|
@@ -258,17 +272,24 @@ class ClaudeSession {
|
|
|
258
272
|
const env = claudeAutoCompactionEnv(this.workflowAutoCompaction, claudeState.env) ?? claudeState.env;
|
|
259
273
|
const queryOptions = {
|
|
260
274
|
cwd: options.scope,
|
|
261
|
-
env,
|
|
275
|
+
env: builder ? { ...env, ENABLE_TOOL_SEARCH: "false" } : env,
|
|
262
276
|
includePartialMessages: true,
|
|
263
277
|
mcpServers: builder ? this.parentWorkflow : toolless ? {} : { ...claudeMcpServers(options.mcp), ...this.parentWorkflow, ...this.parentSessions },
|
|
264
278
|
// Pre-approval and native Auto can bypass canUseTool. Hooks run before either, so even
|
|
265
279
|
// read-only session tools remain parent-only when the SDK inherits MCP into Subagents.
|
|
266
|
-
...(!builder && !toolless
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
280
|
+
...(!builder && !toolless ? { hooks: { PreToolUse: [...(options.sessionTools ? [{
|
|
281
|
+
matcher: `${SESSION_TOOL_PREFIX}.*`,
|
|
282
|
+
hooks: [async (input) => input.hook_event_name === "PreToolUse" && input.agent_id
|
|
283
|
+
? { hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny",
|
|
284
|
+
permissionDecisionReason: "Agent Session tools are available only to the parent Agent Session" } }
|
|
285
|
+
: {}],
|
|
286
|
+
}] : []), {
|
|
287
|
+
// A Subagent's own tool calls are the only place the CLI says which effort it settled on.
|
|
288
|
+
hooks: [async (input) => {
|
|
289
|
+
if (input.hook_event_name === "PreToolUse" && input.agent_id)
|
|
290
|
+
this.noteSubagentEffort(input.agent_id, input.effort?.level);
|
|
291
|
+
return {};
|
|
292
|
+
}],
|
|
272
293
|
}] } } : {}),
|
|
273
294
|
strictMcpConfig: true,
|
|
274
295
|
// NOT bypassPermissions: it auto-approves before canUseTool is consulted, and the SDK warns
|
|
@@ -336,6 +357,7 @@ class ClaudeSession {
|
|
|
336
357
|
this.stream = (backendOptions.query ?? query)({ prompt: this.inbox, options: queryOptions });
|
|
337
358
|
this.pump = this.consume();
|
|
338
359
|
this.modelsReady = this.loadModels();
|
|
360
|
+
void this.loadAgentModels();
|
|
339
361
|
// A meter that only fills once a turn ends reads as "no window" when it is really just early.
|
|
340
362
|
// Occupancy is already meaningful here: system prompt, tools and memory files are loaded
|
|
341
363
|
// before anything is sent.
|
|
@@ -367,6 +389,25 @@ class ClaudeSession {
|
|
|
367
389
|
this.noteBootedModel(this.bootedModel ?? this.modelId ?? defaultModel(models));
|
|
368
390
|
await this.reapplyEffort();
|
|
369
391
|
}
|
|
392
|
+
/** Without the list a Subagent's starting model falls back to the parent's, which the result corrects. */
|
|
393
|
+
async loadAgentModels() {
|
|
394
|
+
try {
|
|
395
|
+
const agents = await this.stream.supportedAgents();
|
|
396
|
+
this.agentModels = new Map(agents.flatMap((agent) => agent.model && agent.model !== "inherit" ? [[agent.name, agent.model]] : []));
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
noteSubagentEffort(taskId, level) {
|
|
403
|
+
const callId = this.subagents.callIdOf(taskId);
|
|
404
|
+
const effort = EFFORT_ORDER.find((known) => known === level);
|
|
405
|
+
if (callId === undefined || effort === undefined)
|
|
406
|
+
return;
|
|
407
|
+
const refined = this.subagents.refine(callId, { effort });
|
|
408
|
+
if (refined)
|
|
409
|
+
this.emit({ type: "subagent", subagentId: callId, ...refined, ...attribution(this.subagents.parentOf(callId)), state: "running" });
|
|
410
|
+
}
|
|
370
411
|
/**
|
|
371
412
|
* The init message names the model in its resolved form (`claude-sonnet-...`), but the picker
|
|
372
413
|
* lists aliases (`sonnet`). Report the alias so the id a client holds matches an entry it can
|
|
@@ -756,6 +797,15 @@ class ClaudeSession {
|
|
|
756
797
|
translate(sdkMessage) {
|
|
757
798
|
switch (sdkMessage.type) {
|
|
758
799
|
case "system":
|
|
800
|
+
if (sdkMessage.subtype === "informational") {
|
|
801
|
+
this.emit({ type: "notice", level: sdkMessage.level === "warning" ? "warn" : "info", text: sdkMessage.content });
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (sdkMessage.subtype === "session_writes_lost") {
|
|
805
|
+
const lost = sdkMessage.lost.map(part => part === "transcript" ? "its conversation record" : "its global configuration");
|
|
806
|
+
this.emit({ type: "notice", level: "warn", text: `Claude Code could not save ${lost.join(" and ")} (${sdkMessage.error_code}).` });
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
759
809
|
if (sdkMessage.subtype === "init") {
|
|
760
810
|
this.sdkSessionId = sdkMessage.session_id;
|
|
761
811
|
this.noteBootedModel(sdkMessage.model);
|
|
@@ -846,7 +896,10 @@ class ClaudeSession {
|
|
|
846
896
|
this.calls.called(block.id, { tool: block.name, ...attribution(producer) });
|
|
847
897
|
if (block.name !== SUBAGENT_TOOL)
|
|
848
898
|
continue;
|
|
849
|
-
const brief = briefOf(block.input)
|
|
899
|
+
const brief = briefOf(block.input, this.subagents.describe(producer) ?? {
|
|
900
|
+
...(this.modelId === undefined ? {} : { model: this.modelId }),
|
|
901
|
+
...(this.effort === undefined ? {} : { effort: this.effort }),
|
|
902
|
+
}, this.agentModels);
|
|
850
903
|
this.subagents.spawn(block.id, brief, producer);
|
|
851
904
|
this.emit({ type: "subagent", subagentId: block.id, ...brief, ...attribution(producer), state: "running" });
|
|
852
905
|
const prompt = promptOf(block.input);
|
|
@@ -875,7 +928,12 @@ class ClaudeSession {
|
|
|
875
928
|
// A launch receipt, not an answer: the Subagent is only now starting work, so it gets
|
|
876
929
|
// no terminal snapshot and its card stays running. What it does give up is its hold on
|
|
877
930
|
// the turn, which is what keeps the Steering Queue live while it runs (ADR 0016).
|
|
931
|
+
const resolved = resolvedModelOf(sdkMessage.tool_use_result, this.aliasOf);
|
|
932
|
+
const refined = resolved === undefined ? undefined : this.subagents.refine(block.tool_use_id, { model: resolved });
|
|
878
933
|
if (isAsyncLaunch(sdkMessage.tool_use_result)) {
|
|
934
|
+
if (refined) {
|
|
935
|
+
this.emit({ type: "subagent", subagentId: block.tool_use_id, ...refined, ...attribution(this.subagents.parentOf(block.tool_use_id)), state: "running" });
|
|
936
|
+
}
|
|
879
937
|
const released = this.subagents.background(block.tool_use_id);
|
|
880
938
|
if (released)
|
|
881
939
|
this.endTurn(released);
|
|
@@ -48,6 +48,17 @@ export class Subagents {
|
|
|
48
48
|
describe(callId) {
|
|
49
49
|
return this.spawned(callId)?.brief;
|
|
50
50
|
}
|
|
51
|
+
/** Correct what an open or detached Subagent runs on. Answers the new brief, or undefined when nothing changed. */
|
|
52
|
+
refine(callId, patch) {
|
|
53
|
+
const spawned = this.spawned(callId);
|
|
54
|
+
if (spawned === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
const { brief } = spawned;
|
|
57
|
+
if ((patch.model ?? brief.model) === brief.model && (patch.effort ?? brief.effort) === brief.effort)
|
|
58
|
+
return undefined;
|
|
59
|
+
spawned.brief = { ...brief, ...patch };
|
|
60
|
+
return spawned.brief;
|
|
61
|
+
}
|
|
51
62
|
/**
|
|
52
63
|
* Record that a Subagent was backgrounded, so it stops holding the turn without ending.
|
|
53
64
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
-
import { workflowInspectInput, workflowRecoverInput, workflowRelayInput, inspectDescription, recoverDescription, relayEnquiryDescription, relayPermissionDescription } from
|
|
2
|
+
import { workflowInspectInput, workflowRecoverInput, workflowRelayInput, inspectDescription, recoverDescription, relayEnquiryDescription, relayPermissionDescription } from '../workflow-tools.js';
|
|
3
3
|
export function workflowParentServer(parent) {
|
|
4
4
|
if (!parent)
|
|
5
5
|
return {};
|
|
@@ -328,7 +328,7 @@ export class FakeSession {
|
|
|
328
328
|
*/
|
|
329
329
|
beginSubagent(name, description, producer) {
|
|
330
330
|
const subagentId = randomUUID();
|
|
331
|
-
const subagent = new FakeSubagent(subagentId, name, description, this.emit, producer);
|
|
331
|
+
const subagent = new FakeSubagent(subagentId, name, description, this.emit, this.modelId, this.effort, producer);
|
|
332
332
|
this.subagents.push(subagent);
|
|
333
333
|
this.emit({ type: "tool_started", callId: subagentId, name: "Agent", input: { name, description }, ...(producer ? { producer } : {}) });
|
|
334
334
|
subagent.snapshot({ state: "running" });
|
|
@@ -392,17 +392,21 @@ export class FakeSubagent {
|
|
|
392
392
|
subagentId;
|
|
393
393
|
name;
|
|
394
394
|
description;
|
|
395
|
+
model;
|
|
396
|
+
effort;
|
|
395
397
|
producer;
|
|
396
398
|
finished = false;
|
|
397
399
|
launched = false;
|
|
398
400
|
emit;
|
|
399
401
|
/** Bumped when a message finalises, so a partial and its finished half share one id. */
|
|
400
402
|
messageIndex = 0;
|
|
401
|
-
constructor(subagentId, name, description, emit, producer) {
|
|
403
|
+
constructor(subagentId, name, description, emit, model, effort, producer) {
|
|
402
404
|
this.subagentId = subagentId;
|
|
403
405
|
this.name = name;
|
|
404
406
|
this.description = description;
|
|
405
407
|
this.emit = emit;
|
|
408
|
+
this.model = model;
|
|
409
|
+
this.effort = effort;
|
|
406
410
|
this.producer = producer;
|
|
407
411
|
}
|
|
408
412
|
/**
|
|
@@ -481,6 +485,8 @@ export class FakeSubagent {
|
|
|
481
485
|
subagentId: this.subagentId,
|
|
482
486
|
name: this.name,
|
|
483
487
|
...(this.description === undefined ? {} : { description: this.description }),
|
|
488
|
+
model: this.model,
|
|
489
|
+
...(this.effort === undefined ? {} : { effort: this.effort }),
|
|
484
490
|
...this.attribution(),
|
|
485
491
|
...state,
|
|
486
492
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function streamingCacheWarming(settings) {
|
|
2
|
+
return { name: "flow-streaming-cache-warming", hidden: true, factory: (pi) => {
|
|
3
|
+
pi.on("cache_warming_decision", (_event, ctx) => {
|
|
4
|
+
if (settings.getGlobalSettings().cacheWarming !== "idle" && ctx.isIdle())
|
|
5
|
+
return { action: "stop" };
|
|
6
|
+
});
|
|
7
|
+
} };
|
|
8
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { constants, closeSync, fstatSync, ftruncateSync, lstatSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
3
|
+
import lockfile from 'proper-lockfile';
|
|
4
|
+
function object(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
export class PiCanonicalJson {
|
|
8
|
+
path;
|
|
9
|
+
name;
|
|
10
|
+
constructor(path, name) { this.path = path; this.name = name; }
|
|
11
|
+
check(stat) {
|
|
12
|
+
if (!stat.isFile() || (this.name === 'models-store.json' && stat.nlink !== 1)) {
|
|
13
|
+
throw new Error(this.name === 'auth.json' ? 'Pi auth.json must be a regular file, not a symbolic link'
|
|
14
|
+
: 'Pi models-store.json must be a regular file, not a symbolic or hard link');
|
|
15
|
+
}
|
|
16
|
+
if (this.name === 'models-store.json' && stat.size > 16 * 1024 * 1024) {
|
|
17
|
+
throw new Error('Pi models-store.json exceeds the catalog size limit');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exists() {
|
|
21
|
+
try {
|
|
22
|
+
this.check(lstatSync(this.path));
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
return false;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
open(flags) {
|
|
32
|
+
this.exists();
|
|
33
|
+
const fd = openSync(this.path, flags | constants.O_NOFOLLOW | constants.O_NONBLOCK, 0o600);
|
|
34
|
+
try {
|
|
35
|
+
this.check(fstatSync(fd));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
closeSync(fd);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
return fd;
|
|
42
|
+
}
|
|
43
|
+
readRaw() {
|
|
44
|
+
if (!this.exists())
|
|
45
|
+
return {};
|
|
46
|
+
const fd = this.open(constants.O_RDONLY);
|
|
47
|
+
try {
|
|
48
|
+
let raw;
|
|
49
|
+
try {
|
|
50
|
+
const content = readFileSync(fd, 'utf8').replace(/^\uFEFF/, '');
|
|
51
|
+
raw = this.name === 'models-store.json' && !content ? {} : JSON.parse(content);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error(`Invalid Pi ${this.name}: expected valid JSON`);
|
|
55
|
+
}
|
|
56
|
+
if (!object(raw))
|
|
57
|
+
throw new Error(`Invalid Pi ${this.name}: expected an object`);
|
|
58
|
+
return raw;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
closeSync(fd);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
writeRaw(raw) {
|
|
65
|
+
const create = this.name === 'models-store.json' && !this.exists();
|
|
66
|
+
const content = JSON.stringify(raw, null, 2);
|
|
67
|
+
if (this.name === 'models-store.json' && Buffer.byteLength(content) > 16 * 1024 * 1024) {
|
|
68
|
+
throw new Error('Pi models-store.json exceeds the catalog size limit');
|
|
69
|
+
}
|
|
70
|
+
const fd = this.open(constants.O_WRONLY | (create ? constants.O_CREAT | constants.O_EXCL : 0));
|
|
71
|
+
try {
|
|
72
|
+
ftruncateSync(fd, 0);
|
|
73
|
+
writeFileSync(fd, content, { encoding: 'utf8', mode: 0o600 });
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
closeSync(fd);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async locked(fn, signal, create = false) {
|
|
80
|
+
signal?.throwIfAborted();
|
|
81
|
+
if (!this.exists() && !create)
|
|
82
|
+
return fn({}, () => { });
|
|
83
|
+
const deadline = Date.now() + 30_000;
|
|
84
|
+
let compromised;
|
|
85
|
+
let release;
|
|
86
|
+
const assertLock = () => { if (compromised)
|
|
87
|
+
throw compromised; };
|
|
88
|
+
for (let attempt = 0; !release; attempt++) {
|
|
89
|
+
signal?.throwIfAborted();
|
|
90
|
+
try {
|
|
91
|
+
release = await lockfile.lock(this.path, {
|
|
92
|
+
realpath: false, stale: 30_000, retries: 0,
|
|
93
|
+
onCompromised: error => { compromised = error; },
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error.code !== 'ELOCKED' || Date.now() >= deadline)
|
|
98
|
+
throw error;
|
|
99
|
+
await sleep(Math.min(10 * 2 ** Math.min(attempt, 7), 1000, deadline - Date.now()), undefined, signal ? { signal } : {});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
assertLock();
|
|
104
|
+
signal?.throwIfAborted();
|
|
105
|
+
return await fn(this.readRaw(), assertLock);
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
try {
|
|
109
|
+
await release();
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (!compromised)
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
raw(signal) {
|
|
118
|
+
return this.locked(raw => raw, signal);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compact } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { findPiModel, piModelUnavailable } from "./model-selection.js";
|
|
2
3
|
/** Keep Pi's preparation, split-turn handling, file tracking and usage accounting, changing only
|
|
3
4
|
* the model for its summary calls. External extensions remain disabled in Flow's Backend Sessions. */
|
|
4
5
|
export function compactionExtensionError(errors) {
|
|
@@ -8,9 +9,9 @@ export function compactionModelExtension(modelId, notice) {
|
|
|
8
9
|
return { name: "flow-compaction-model", hidden: true, factory: (pi) => {
|
|
9
10
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
10
11
|
try {
|
|
11
|
-
const model = ctx.modelRegistry.getAvailable()
|
|
12
|
+
const model = findPiModel(ctx.modelRegistry.getAvailable(), modelId);
|
|
12
13
|
if (!model)
|
|
13
|
-
throw new Error(
|
|
14
|
+
throw new Error(piModelUnavailable(modelId, "Configured compaction model is unavailable"));
|
|
14
15
|
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
15
16
|
if (!auth.ok)
|
|
16
17
|
throw new Error(auth.error);
|