@nathanstephenson/flow 0.1.10-beta.1 → 0.1.10-beta.10
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 +52 -22
- package/build/backend-worker-chunks/{chunk-CYE5L6Z5.mjs → chunk-3KDHJA5P.mjs} +41 -10
- 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-JG2FXYBQ.mjs +35859 -0
- package/build/backend-worker-chunks/{pi-UKRC4DDM.mjs → pi-KJSP23AO.mjs} +2091 -92
- package/build/backend-worker.mjs +69 -122
- package/build/workflow-runtime.cjs +12 -12
- package/dist/backend/claude/background-calls.js +7 -3
- package/dist/backend/claude/import.js +415 -0
- package/dist/backend/claude/index.js +188 -25
- package/dist/backend/claude/subagents.js +41 -9
- package/dist/backend/claude/todo-list.js +114 -0
- package/dist/backend/claude/workflow-parent.js +1 -1
- package/dist/backend/diff-excerpt-instructions.js +8 -0
- package/dist/backend/fake/index.js +54 -6
- package/dist/backend/mcp.js +4 -1
- package/dist/backend/pi/agent-permissions.js +1 -1
- 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/import.js +269 -0
- package/dist/backend/pi/index.js +118 -20
- 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/plan-limits.js +41 -0
- package/dist/backend/pi/state.js +19 -1
- package/dist/backend/pi/subagents.js +7 -3
- package/dist/backend/pi/todo-list.js +23 -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/plan-limits.js +17 -0
- package/dist/backend/session-tools.js +1 -1
- package/dist/backend/worker/claude-state.js +48 -0
- package/dist/backend/worker/entry.js +42 -8
- package/dist/backend/worker/index.js +131 -15
- package/dist/backend/worker/launcher.js +11 -4
- package/dist/backend/worker/protocol.js +2 -1
- package/dist/backend/worker/rpc.js +13 -0
- package/dist/backend/worker/sandbox-mcp.js +18 -7
- package/dist/backend/workflow-tools.js +9 -7
- package/dist/build-id +1 -1
- package/dist/cli/application.js +48 -42
- package/dist/cli/bootstrap.js +2 -2
- package/dist/cli/host-control.js +1 -1
- package/dist/cli/install-guard.js +2 -2
- 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/connection.js +46 -0
- package/dist/client/context-usage.js +3 -4
- package/dist/client/diff.js +40 -0
- package/dist/client/enquiry.js +0 -6
- package/dist/client/markdown.js +3 -2
- package/dist/client/model-choices.js +1 -1
- package/dist/client/permission.js +1 -2
- package/dist/client/project-name.js +3 -1
- package/dist/client/reduce.js +77 -3
- package/dist/client/relative-time.js +1 -1
- package/dist/client/scope-kind.js +6 -3
- package/dist/client/search.js +1 -1
- package/dist/client/status.js +1 -1
- package/dist/client/subagent-tree.js +49 -0
- package/dist/client/tool-chains.js +1 -1
- package/dist/client/tool-summary.js +28 -18
- package/dist/daemon/changes.js +128 -0
- package/dist/daemon/commit.js +84 -0
- package/dist/daemon/config-store.js +8 -3
- package/dist/daemon/config.js +105 -4
- package/dist/daemon/diff-excerpts.js +52 -0
- package/dist/daemon/git-state.js +197 -0
- package/dist/daemon/git.js +53 -10
- package/dist/daemon/github-image.js +18 -0
- package/dist/daemon/github.js +54 -0
- package/dist/daemon/host-control-routes.js +1 -1
- package/dist/daemon/host.js +940 -119
- package/dist/daemon/http.js +4 -1
- 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 +223 -138
- package/dist/daemon/push.js +43 -0
- package/dist/daemon/repository.js +123 -0
- package/dist/daemon/runtime.js +103 -22
- package/dist/daemon/secret-store.js +1 -1
- package/dist/daemon/server.js +111 -14
- package/dist/daemon/skills.js +24 -0
- package/dist/daemon/spend-ledger.js +118 -0
- package/dist/daemon/stack-metadata.js +12 -5
- package/dist/daemon/stack.js +162 -657
- package/dist/daemon/store.js +2 -0
- package/dist/daemon/summariser.js +30 -12
- package/dist/daemon/tour.js +56 -0
- package/dist/daemon/whisper.js +144 -0
- 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-guidance.js +1 -1
- package/dist/daemon/workflow-builder-routes.js +2 -2
- package/dist/daemon/workflow-builder.js +44 -17
- package/dist/daemon/workflow-environment.js +193 -0
- package/dist/daemon/workflow-execution-launch.js +77 -0
- package/dist/daemon/workflow-execution-resources.js +76 -0
- package/dist/daemon/workflow-execution-routes.js +12 -9
- package/dist/daemon/workflow-execution-values.js +128 -0
- package/dist/daemon/workflow-executions.js +400 -311
- 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 +60 -2
- package/dist/daemon/workflow-schedule-driver.js +251 -0
- package/dist/daemon/workflow-schedule-routes.js +137 -0
- package/dist/daemon/workflow-schedules.js +342 -0
- package/dist/isolation/filesystem.js +6 -2
- package/dist/isolation/sandbox.js +61 -18
- package/dist/isolation/shared-sandbox.js +3 -3
- package/dist/isolation/toolchain-assets.js +1 -1
- package/dist/protocol/events.js +3 -0
- package/dist/protocol/plan-limits.js +1 -0
- package/dist/protocol/settings.js +1 -0
- package/dist/protocol/spend.js +2 -0
- package/dist/protocol/stack.js +12 -39
- package/dist/protocol/workflow-schedules.js +1 -0
- package/dist/workflows/calls.js +53 -0
- package/dist/workflows/errors.js +2 -0
- package/dist/workflows/executors.js +6 -5
- package/dist/workflows/graph.js +83 -9
- package/dist/workflows/invocations.js +23 -0
- package/dist/workflows/mcp.js +1 -1
- package/dist/workflows/owner.js +45 -0
- package/dist/workflows/records.js +127 -11
- package/dist/workflows/recovery.js +38 -2
- package/dist/workflows/runtime-settings.js +16 -16
- package/dist/workflows/runtime.js +2 -2
- package/dist/workflows/schedule-errors.js +2 -0
- package/dist/workflows/schedule-store.js +385 -0
- package/dist/workflows/scheduler.js +367 -96
- package/dist/workflows/schedules.js +130 -0
- package/dist/workflows/schema.js +3 -1
- package/dist/workflows/store.js +126 -13
- package/package.json +10 -6
- package/web/dist/assets/index-C76t-z4w.css +2 -0
- package/web/dist/assets/{index-DRfeO6GJ.js → index-WPfbYVQ4.js} +39 -23
- package/web/dist/assets/{switch-DIogWclb.js → select-C5Ly2OpB.js} +1 -1
- package/web/dist/assets/{settings-mcp-Clp_jMWW.js → settings-mcp-BF-yqpeQ.js} +1 -1
- package/web/dist/assets/{settings-secrets-BIO_hXZ1.js → settings-secrets-WLarr2QP.js} +1 -1
- package/web/dist/assets/settings-workflows-DdcdRWFD.js +23 -0
- package/web/dist/assets/workflow-api-GjAmHc22.js +6 -0
- package/web/dist/assets/workflows-BhY3Uibo.js +149 -0
- package/web/dist/assets/workflows-pane-DElCcEpN.js +1 -0
- package/web/dist/index.html +6 -5
- package/build/backend-worker-chunks/claude-UXZDJKZQ.mjs +0 -30816
- package/dist/daemon/publish.js +0 -289
- package/dist/tui/app.js +0 -612
- package/dist/tui/keys.js +0 -90
- package/dist/tui/render.js +0 -411
- package/web/dist/assets/index-DgQFpKbn.css +0 -2
- package/web/dist/assets/settings-workflows-H-6eCff3.js +0 -23
- package/web/dist/assets/workflow-api-BfExddae.js +0 -6
- package/web/dist/assets/workflow-editors-CsbVx4WJ.js +0 -139
- package/web/dist/assets/workflows-Bv0sj7d0.js +0 -7
- package/web/dist/assets/workflows-pane-DHm44w7P.js +0 -1
- /package/dist/protocol/{publish.js → imports.js} +0 -0
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({
|
|
@@ -1061,7 +1065,7 @@ async function prepareFilesystemIsolation(options) {
|
|
|
1061
1065
|
mkdirSync(join3(privateHome, ".pi/agent"), { recursive: true, mode: 448 });
|
|
1062
1066
|
mkdirSync(join3(privateHome, ".claude"), { mode: 448 });
|
|
1063
1067
|
args.push(
|
|
1064
|
-
"--bind-fd",
|
|
1068
|
+
options.scopeReadOnly ? "--ro-bind-fd" : "--bind-fd",
|
|
1065
1069
|
pinned(scope, options.expectedScopeIdentity),
|
|
1066
1070
|
scope,
|
|
1067
1071
|
"--dir",
|
|
@@ -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"));
|
|
@@ -3680,12 +3688,14 @@ var McpSession = class {
|
|
|
3680
3688
|
stateRoot;
|
|
3681
3689
|
isolationMode;
|
|
3682
3690
|
expectedScopeIdentity;
|
|
3691
|
+
scopeReadOnly;
|
|
3683
3692
|
/** Sandbox workers: the host owns OAuth, refreshes on request and returns only access tokens. */
|
|
3684
3693
|
hostToken;
|
|
3685
3694
|
/** Sandbox workers start local servers from host paths over the VM's shared file system. */
|
|
3686
3695
|
connectTimeoutMs = 1e4;
|
|
3687
|
-
constructor(connections, scope, auth2, direct = false, resolveSecret, protectedPaths, stateRoot, isolationMode = "bubblewrap", expectedScopeIdentity, hostToken) {
|
|
3696
|
+
constructor(connections, scope, auth2, direct = false, resolveSecret, protectedPaths, stateRoot, isolationMode = "bubblewrap", expectedScopeIdentity, hostToken, scopeReadOnly = false) {
|
|
3688
3697
|
this.hostToken = hostToken;
|
|
3698
|
+
this.scopeReadOnly = scopeReadOnly;
|
|
3689
3699
|
this.connections = structuredClone(connections);
|
|
3690
3700
|
this.scope = scope;
|
|
3691
3701
|
this.auth = auth2;
|
|
@@ -3814,7 +3824,8 @@ var McpSession = class {
|
|
|
3814
3824
|
},
|
|
3815
3825
|
...this.protectedPaths ? { protectedPaths: this.protectedPaths } : {},
|
|
3816
3826
|
...this.stateRoot ? { stateRoot: this.stateRoot } : {},
|
|
3817
|
-
credentials: "none"
|
|
3827
|
+
credentials: "none",
|
|
3828
|
+
scopeReadOnly: this.scopeReadOnly
|
|
3818
3829
|
});
|
|
3819
3830
|
if (this.disposed) {
|
|
3820
3831
|
isolation.cleanup();
|
|
@@ -3942,118 +3953,13 @@ var McpSession = class {
|
|
|
3942
3953
|
}
|
|
3943
3954
|
};
|
|
3944
3955
|
|
|
3945
|
-
// src/backend/worker/rpc.ts
|
|
3946
|
-
function errorText(error) {
|
|
3947
|
-
return error instanceof Error ? error.message : String(error);
|
|
3948
|
-
}
|
|
3949
|
-
var WorkerRpc = class {
|
|
3950
|
-
nextId = 0;
|
|
3951
|
-
failure;
|
|
3952
|
-
pending = /* @__PURE__ */ new Map();
|
|
3953
|
-
incoming = /* @__PURE__ */ new Map();
|
|
3954
|
-
send;
|
|
3955
|
-
dispatch;
|
|
3956
|
-
notification;
|
|
3957
|
-
constructor(send, dispatch, notification) {
|
|
3958
|
-
this.send = send;
|
|
3959
|
-
this.dispatch = dispatch;
|
|
3960
|
-
this.notification = notification;
|
|
3961
|
-
}
|
|
3962
|
-
call(method, args = [], signal) {
|
|
3963
|
-
if (this.failure) return Promise.reject(this.failure);
|
|
3964
|
-
if (signal?.aborted) return Promise.reject(new Error("Worker call cancelled"));
|
|
3965
|
-
const id = ++this.nextId;
|
|
3966
|
-
return new Promise((resolve4, reject) => {
|
|
3967
|
-
const abort = () => {
|
|
3968
|
-
this.pending.delete(id);
|
|
3969
|
-
try {
|
|
3970
|
-
this.send({ kind: "cancel", id });
|
|
3971
|
-
} catch {
|
|
3972
|
-
}
|
|
3973
|
-
reject(new Error("Worker call cancelled"));
|
|
3974
|
-
};
|
|
3975
|
-
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
3976
|
-
this.pending.set(id, {
|
|
3977
|
-
resolve: (value) => {
|
|
3978
|
-
cleanup();
|
|
3979
|
-
resolve4(value);
|
|
3980
|
-
},
|
|
3981
|
-
reject: (error) => {
|
|
3982
|
-
cleanup();
|
|
3983
|
-
reject(error);
|
|
3984
|
-
}
|
|
3985
|
-
});
|
|
3986
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
3987
|
-
try {
|
|
3988
|
-
this.send({ kind: "call", id, method, args });
|
|
3989
|
-
} catch (error) {
|
|
3990
|
-
this.pending.delete(id);
|
|
3991
|
-
cleanup();
|
|
3992
|
-
reject(error);
|
|
3993
|
-
}
|
|
3994
|
-
});
|
|
3995
|
-
}
|
|
3996
|
-
notify(name, value) {
|
|
3997
|
-
if (!this.failure) this.send({ kind: "notification", name, value });
|
|
3998
|
-
}
|
|
3999
|
-
receive(raw) {
|
|
4000
|
-
if (this.failure || !raw || typeof raw !== "object") return;
|
|
4001
|
-
const message = raw;
|
|
4002
|
-
switch (message.kind) {
|
|
4003
|
-
case "reply": {
|
|
4004
|
-
const pending = this.pending.get(message.id);
|
|
4005
|
-
this.pending.delete(message.id);
|
|
4006
|
-
if (message.error !== void 0) pending?.reject(message.errorCode === "auto_permission_unavailable" ? new AutoPermissionUnavailable(message.error) : new Error(message.error));
|
|
4007
|
-
else pending?.resolve(message.value);
|
|
4008
|
-
break;
|
|
4009
|
-
}
|
|
4010
|
-
case "cancel":
|
|
4011
|
-
this.incoming.get(message.id)?.abort();
|
|
4012
|
-
break;
|
|
4013
|
-
case "notification":
|
|
4014
|
-
this.notification(message.name, message.value);
|
|
4015
|
-
break;
|
|
4016
|
-
case "call": {
|
|
4017
|
-
if (!Number.isSafeInteger(message.id) || typeof message.method !== "string" || !Array.isArray(message.args) || this.incoming.has(message.id)) return;
|
|
4018
|
-
const controller = new AbortController();
|
|
4019
|
-
this.incoming.set(message.id, controller);
|
|
4020
|
-
void Promise.resolve().then(() => this.dispatch(message.method, message.args, controller.signal)).then(
|
|
4021
|
-
(value) => this.reply({ kind: "reply", id: message.id, value }),
|
|
4022
|
-
(error) => this.reply({
|
|
4023
|
-
kind: "reply",
|
|
4024
|
-
id: message.id,
|
|
4025
|
-
error: errorText(error),
|
|
4026
|
-
...error instanceof AutoPermissionUnavailable ? { errorCode: "auto_permission_unavailable" } : {}
|
|
4027
|
-
})
|
|
4028
|
-
).finally(() => this.incoming.delete(message.id));
|
|
4029
|
-
break;
|
|
4030
|
-
}
|
|
4031
|
-
}
|
|
4032
|
-
}
|
|
4033
|
-
reply(message) {
|
|
4034
|
-
if (this.failure) return;
|
|
4035
|
-
try {
|
|
4036
|
-
this.send(message);
|
|
4037
|
-
} catch (error) {
|
|
4038
|
-
this.close(new Error(errorText(error)));
|
|
4039
|
-
}
|
|
4040
|
-
}
|
|
4041
|
-
close(error) {
|
|
4042
|
-
if (this.failure) return;
|
|
4043
|
-
this.failure = error;
|
|
4044
|
-
for (const pending of this.pending.values()) pending.reject(error);
|
|
4045
|
-
this.pending.clear();
|
|
4046
|
-
for (const controller of this.incoming.values()) controller.abort();
|
|
4047
|
-
this.incoming.clear();
|
|
4048
|
-
}
|
|
4049
|
-
};
|
|
4050
|
-
|
|
4051
3956
|
// src/backend/worker/protocol.ts
|
|
4052
3957
|
function snapshot(session) {
|
|
4053
3958
|
return {
|
|
4054
3959
|
capabilities: session.capabilities,
|
|
4055
3960
|
resume: session.resumeToken(),
|
|
4056
|
-
|
|
3961
|
+
spend: session.spend,
|
|
3962
|
+
methods: ["refreshMcp", "startWorkflowSubagent", "compact", "rewindFiles", "skills", "planLimits", "answerEnquiry", "answerPermission", "setPermissionMode"].filter((method) => typeof session[method] === "function")
|
|
4057
3963
|
};
|
|
4058
3964
|
}
|
|
4059
3965
|
|
|
@@ -4179,11 +4085,31 @@ function runWorker() {
|
|
|
4179
4085
|
});
|
|
4180
4086
|
};
|
|
4181
4087
|
const rpc = new WorkerRpc(send, async (method, args, signal) => {
|
|
4088
|
+
if (method === "mcp.initialize") {
|
|
4089
|
+
signal.throwIfAborted();
|
|
4090
|
+
if (creating || closing) throw new Error("Worker already initialized");
|
|
4091
|
+
creating = true;
|
|
4092
|
+
const options = args[0];
|
|
4093
|
+
localMcp = new McpSession(
|
|
4094
|
+
options.connections,
|
|
4095
|
+
options.scope,
|
|
4096
|
+
void 0,
|
|
4097
|
+
true,
|
|
4098
|
+
void 0,
|
|
4099
|
+
void 0,
|
|
4100
|
+
void 0,
|
|
4101
|
+
"none",
|
|
4102
|
+
void 0,
|
|
4103
|
+
(connectionId, refresh) => rpc.call("mcp.token", [connectionId, refresh])
|
|
4104
|
+
);
|
|
4105
|
+
localMcp.connectTimeoutMs = 12e4;
|
|
4106
|
+
return;
|
|
4107
|
+
}
|
|
4182
4108
|
if (method === "create") {
|
|
4183
4109
|
const ready = performance.now();
|
|
4184
4110
|
if (creating || closing) throw new Error("Backend worker already initialized");
|
|
4185
4111
|
creating = true;
|
|
4186
|
-
const { mcpTools, mcpConnectionIds, mcpSandbox, workflowEnabled, sessionToolsEnabled, workflowBuilderInstructions, backendModule, backend: backendName = "pi", ...options } = args[0];
|
|
4112
|
+
const { mcpTools, mcpConnectionIds, mcpSandbox, workflowEnabled, sessionToolsEnabled, workflowBuilderInstructions, piAuth, backendModule, backend: backendName = "pi", ...options } = args[0];
|
|
4187
4113
|
const workflowBuilder = workflowBuilderInstructions === void 0 ? void 0 : {
|
|
4188
4114
|
instructions: workflowBuilderInstructions,
|
|
4189
4115
|
read: (path) => rpc.call("workflowBuilder.read", [path]),
|
|
@@ -4224,20 +4150,31 @@ function runWorker() {
|
|
|
4224
4150
|
let backend;
|
|
4225
4151
|
const importing = performance.now();
|
|
4226
4152
|
try {
|
|
4227
|
-
backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-
|
|
4153
|
+
backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-JG2FXYBQ.mjs")).ClaudeBackend() : new (await import("./backend-worker-chunks/pi-KJSP23AO.mjs")).PiBackend();
|
|
4228
4154
|
} catch (error) {
|
|
4229
4155
|
throw new Error(`Backend "${backendName}" is not available in this build: ${errorText(error)}`);
|
|
4230
4156
|
}
|
|
4231
4157
|
const imported = performance.now();
|
|
4158
|
+
let initialAuth = piAuth;
|
|
4232
4159
|
session = await backend.create({
|
|
4233
4160
|
...options,
|
|
4161
|
+
...piAuth ? { piAuth: {
|
|
4162
|
+
snapshot: async (signal2) => {
|
|
4163
|
+
signal2?.throwIfAborted();
|
|
4164
|
+
if (!initialAuth) return rpc.call("pi.auth.snapshot", [], signal2);
|
|
4165
|
+
const metadata = initialAuth;
|
|
4166
|
+
initialAuth = void 0;
|
|
4167
|
+
return metadata;
|
|
4168
|
+
},
|
|
4169
|
+
resolve: (providerId, signal2) => rpc.call("pi.auth.resolve", [providerId], signal2)
|
|
4170
|
+
} } : {},
|
|
4234
4171
|
...workflowBuilder ? { workflowBuilder } : {
|
|
4235
4172
|
...localMcp ? { mcp: localMcp } : mcpTools ? { mcp: { connections: (mcpConnectionIds ?? []).map((id) => ({ id })), tools: () => tools } } : {},
|
|
4236
4173
|
...workflowEnabled ? { workflow } : {},
|
|
4237
4174
|
...sessionToolsEnabled && options.tools !== "none" ? { sessionTools } : {}
|
|
4238
4175
|
},
|
|
4239
4176
|
emit: (event) => {
|
|
4240
|
-
const changed = session && (session.capabilities !== published?.capabilities || session.resumeToken() !== published?.resume);
|
|
4177
|
+
const changed = session && (session.capabilities !== published?.capabilities || session.resumeToken() !== published?.resume || session.spend !== published?.spend);
|
|
4241
4178
|
rpc.notify("event", { event, ...changed ? { snapshot: publishSnapshot() } : {} });
|
|
4242
4179
|
}
|
|
4243
4180
|
});
|
|
@@ -4252,11 +4189,11 @@ function runWorker() {
|
|
|
4252
4189
|
setImmediate(() => process.stdout.end(() => process.exit(0)));
|
|
4253
4190
|
return;
|
|
4254
4191
|
}
|
|
4255
|
-
if (!session ||
|
|
4192
|
+
if (closing || !session && (!localMcp || !method.startsWith("mcp."))) throw new Error("Worker is not running");
|
|
4256
4193
|
let result;
|
|
4257
4194
|
switch (method) {
|
|
4258
4195
|
case "prompt":
|
|
4259
|
-
result = await session.prompt(args[0], args[1]);
|
|
4196
|
+
result = await session.prompt(args[0], args[1], args[2]);
|
|
4260
4197
|
break;
|
|
4261
4198
|
case "abort":
|
|
4262
4199
|
result = await session.abort();
|
|
@@ -4277,9 +4214,16 @@ function runWorker() {
|
|
|
4277
4214
|
case "compact":
|
|
4278
4215
|
result = await session.compact?.(args[0]);
|
|
4279
4216
|
break;
|
|
4217
|
+
case "rewindFiles":
|
|
4218
|
+
if (!session.rewindFiles) throw new Error("File rewind is not supported");
|
|
4219
|
+
result = await session.rewindFiles(args[0]);
|
|
4220
|
+
break;
|
|
4280
4221
|
case "skills":
|
|
4281
4222
|
result = await session.skills?.();
|
|
4282
4223
|
break;
|
|
4224
|
+
case "planLimits":
|
|
4225
|
+
result = await session.planLimits?.();
|
|
4226
|
+
break;
|
|
4283
4227
|
case "answerEnquiry":
|
|
4284
4228
|
result = await session.answerEnquiry?.(args[0], args[1]) ?? false;
|
|
4285
4229
|
break;
|
|
@@ -4305,9 +4249,11 @@ function runWorker() {
|
|
|
4305
4249
|
break;
|
|
4306
4250
|
case "mcp.direct": {
|
|
4307
4251
|
if (!localMcp) throw new Error("No sandbox MCP clients");
|
|
4252
|
+
signal.throwIfAborted();
|
|
4308
4253
|
const id = args[0];
|
|
4309
|
-
if (localMcp.status().find((state) => state.id === id)?.state !== "connected") await localMcp.retry(id).catch(() => {
|
|
4310
|
-
});
|
|
4254
|
+
if (localMcp.status().find((state) => state.id === id)?.state !== "connected") await waitForAbort(localMcp.retry(id).catch(() => {
|
|
4255
|
+
}), signal);
|
|
4256
|
+
signal.throwIfAborted();
|
|
4311
4257
|
result = {
|
|
4312
4258
|
status: localMcp.status().find((state) => state.id === id) ?? { id, state: "failed", tools: 0 },
|
|
4313
4259
|
tools: localMcp.tools().filter((tool) => tool.connectionId === id).map(({ call: _, ...tool }) => tool)
|
|
@@ -4315,6 +4261,7 @@ function runWorker() {
|
|
|
4315
4261
|
break;
|
|
4316
4262
|
}
|
|
4317
4263
|
case "mcp.callTool": {
|
|
4264
|
+
signal.throwIfAborted();
|
|
4318
4265
|
const tool = localMcp?.tools().find((entry) => entry.name === args[0]);
|
|
4319
4266
|
if (!tool) throw new Error("Unknown MCP tool");
|
|
4320
4267
|
result = await tool.call(args[1], signal, args[2]);
|
|
@@ -4345,7 +4292,7 @@ function runWorker() {
|
|
|
4345
4292
|
default:
|
|
4346
4293
|
throw new Error(`Unknown worker method: ${method}`);
|
|
4347
4294
|
}
|
|
4348
|
-
rpc.notify("snapshot", publishSnapshot());
|
|
4295
|
+
if (session) rpc.notify("snapshot", publishSnapshot());
|
|
4349
4296
|
return result;
|
|
4350
4297
|
}, () => {
|
|
4351
4298
|
});
|
|
@@ -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
|
|
@@ -93,13 +93,17 @@ export class BackgroundCalls {
|
|
|
93
93
|
return brief;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
-
* Forget this turn's announced calls
|
|
96
|
+
* Forget this turn's announced calls, except those `keep` accepts — a call made by detached work
|
|
97
|
+
* belongs to no turn.
|
|
97
98
|
*
|
|
98
99
|
* Open Background Calls and their task ids deliberately survive: one outlives the turn that made
|
|
99
100
|
* it, and the snapshot closing it is emitted turns later from the brief kept here.
|
|
100
101
|
*/
|
|
101
|
-
clear() {
|
|
102
|
-
this.pending
|
|
102
|
+
clear(keep = () => false) {
|
|
103
|
+
for (const [callId, brief] of this.pending) {
|
|
104
|
+
if (!keep(brief))
|
|
105
|
+
this.pending.delete(callId);
|
|
106
|
+
}
|
|
103
107
|
}
|
|
104
108
|
/** Forget open Calls too, for a Backend Session being taken away. They are children of it. */
|
|
105
109
|
abandon() {
|