@nathanstephenson/flow 0.1.10-beta.4 → 0.1.10-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/build/backend-worker-chunks/{chunk-JOI2POLP.mjs → chunk-U73G6KK4.mjs} +18 -0
- package/build/backend-worker-chunks/{claude-GY27HBAY.mjs → claude-THGSOTC2.mjs} +7 -1
- package/build/backend-worker-chunks/{pi-JV6MWPW7.mjs → pi-5LAWIJNE.mjs} +82 -3
- package/build/backend-worker.mjs +7 -3
- package/build/workflow-runtime.cjs +12 -12
- package/dist/backend/claude/index.js +6 -0
- package/dist/backend/claude/workflow-parent.js +1 -1
- package/dist/backend/fake/index.js +6 -0
- package/dist/backend/pi/index.js +34 -2
- package/dist/backend/pi/model-auth.js +2 -2
- package/dist/backend/pi/plan-limits.js +41 -0
- package/dist/backend/pi/workflow-parent.js +1 -1
- package/dist/backend/plan-limits.js +17 -0
- package/dist/backend/worker/entry.js +4 -1
- package/dist/backend/worker/index.js +9 -3
- package/dist/backend/worker/launcher.js +11 -4
- package/dist/backend/worker/protocol.js +2 -1
- 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/context-usage.js +1 -1
- package/dist/client/markdown.js +3 -2
- package/dist/daemon/changes.js +116 -0
- package/dist/daemon/commit.js +84 -0
- package/dist/daemon/config-store.js +4 -3
- package/dist/daemon/config.js +31 -2
- package/dist/daemon/git-state.js +197 -0
- 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 +280 -81
- package/dist/daemon/log.js +3 -0
- package/dist/daemon/mcp-auth.js +1 -1
- package/dist/daemon/pi-model-cache.js +1 -1
- 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 +28 -21
- package/dist/daemon/secret-store.js +1 -1
- package/dist/daemon/server.js +37 -10
- 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 +127 -656
- package/dist/daemon/summariser.js +30 -12
- package/dist/daemon/tour.js +42 -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-routes.js +2 -2
- package/dist/daemon/workflow-builder.js +8 -6
- package/dist/daemon/workflow-environment.js +5 -5
- package/dist/daemon/workflow-execution-launch.js +5 -5
- package/dist/daemon/workflow-execution-resources.js +4 -4
- 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 +22 -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 +9 -8
- package/dist/isolation/toolchain-assets.js +1 -1
- package/dist/protocol/spend.js +2 -0
- 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 +35 -23
- package/dist/workflows/schema.js +1 -1
- package/dist/workflows/store.js +19 -5
- package/package.json +3 -2
- package/web/dist/assets/index-BhfJhrVJ.js +51 -0
- package/web/dist/assets/index-BvkM2cWL.css +2 -0
- package/web/dist/assets/{settings-mcp-bcNKV147.js → settings-mcp-3cgqQB28.js} +1 -1
- package/web/dist/assets/settings-workflows-Cutm8isB.js +23 -0
- package/web/dist/assets/{switch-DIogWclb.js → switch-B00FEUA7.js} +1 -1
- package/web/dist/assets/{workflows-DHG-CIo3.js → workflows-D6oEUUhj.js} +31 -31
- package/web/dist/assets/{workflows-pane-9u_hJvgQ.js → workflows-pane-KIdSDKJB.js} +1 -1
- package/web/dist/index.html +4 -4
- package/dist/daemon/publish.js +0 -289
- package/web/dist/assets/index-BWKZK5HD.css +0 -2
- package/web/dist/assets/index-nIc09tKZ.js +0 -40
- package/web/dist/assets/settings-workflows-C_TKOhVa.js +0 -23
- /package/dist/protocol/{publish.js → plan-limits.js} +0 -0
package/README.md
CHANGED
|
@@ -146,7 +146,7 @@ Steering is a deliberate action.
|
|
|
146
146
|
section.
|
|
147
147
|
|
|
148
148
|
Settings, Projects, MCP connections and fonts are described in
|
|
149
|
-
[docs/configuration.md](docs/configuration.md).
|
|
149
|
+
[docs/configuration.md](docs/configuration.md). Commit, push, pull requests and stacked pull requests are
|
|
150
150
|
described in [docs/git.md](docs/git.md).
|
|
151
151
|
|
|
152
152
|
## Where state lives
|
|
@@ -186,7 +186,7 @@ requirements, the browser update, systemd setup and the repair procedure.
|
|
|
186
186
|
| [docs/isolation.md](docs/isolation.md) | Filesystem isolation, Bubblewrap and sandboxes |
|
|
187
187
|
| [docs/remote-access.md](docs/remote-access.md) | Container access and the OIDC gate |
|
|
188
188
|
| [docs/configuration.md](docs/configuration.md) | Settings, MCP connections, Projects, fonts, environment variables |
|
|
189
|
-
| [docs/git.md](docs/git.md) |
|
|
189
|
+
| [docs/git.md](docs/git.md) | Commit, push, pull requests and stacked pull requests |
|
|
190
190
|
| [docs/workflow-builder-scope.md](docs/workflow-builder-scope.md) | Workflows, including direct MCP steps |
|
|
191
191
|
| [docs/development.md](docs/development.md) | Build, test, web development, releases |
|
|
192
192
|
| [docs/milestones.md](docs/milestones.md) | Project status and design notes from each milestone |
|
|
@@ -3,6 +3,23 @@ import {
|
|
|
3
3
|
external_exports
|
|
4
4
|
} from "./chunk-NZZME2I3.mjs";
|
|
5
5
|
|
|
6
|
+
// src/backend/plan-limits.ts
|
|
7
|
+
function anthropicPlanLimits(usage) {
|
|
8
|
+
const short = anthropicWindow("5-hour", usage?.five_hour);
|
|
9
|
+
const long = anthropicWindow("7-day", usage?.seven_day);
|
|
10
|
+
if (!short || !long) return void 0;
|
|
11
|
+
const others = [
|
|
12
|
+
anthropicWindow("Opus", usage?.seven_day_opus),
|
|
13
|
+
anthropicWindow("Sonnet", usage?.seven_day_sonnet),
|
|
14
|
+
...(usage?.model_scoped ?? []).map((scoped) => anthropicWindow(scoped.display_name, scoped))
|
|
15
|
+
].filter((window) => window !== void 0);
|
|
16
|
+
return { short, long, others };
|
|
17
|
+
}
|
|
18
|
+
function anthropicWindow(label, window) {
|
|
19
|
+
if (window?.utilization == null) return void 0;
|
|
20
|
+
return { label, utilization: window.utilization, ...window.resets_at ? { resetsAt: window.resets_at } : {} };
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
// src/backend/effort.ts
|
|
7
24
|
var EFFORT_ORDER = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
8
25
|
function clampEffort(wanted, available) {
|
|
@@ -128,6 +145,7 @@ export {
|
|
|
128
145
|
sessionCreateDescription,
|
|
129
146
|
sessionSendDescription,
|
|
130
147
|
workflowBuilderTools,
|
|
148
|
+
anthropicPlanLimits,
|
|
131
149
|
EFFORT_ORDER,
|
|
132
150
|
clampEffort
|
|
133
151
|
};
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
} from "./chunk-K774KOGL.mjs";
|
|
44
44
|
import {
|
|
45
45
|
EFFORT_ORDER,
|
|
46
|
+
anthropicPlanLimits,
|
|
46
47
|
clampEffort,
|
|
47
48
|
inspectDescription,
|
|
48
49
|
recoverDescription,
|
|
@@ -60,7 +61,7 @@ import {
|
|
|
60
61
|
workflowInspectInput,
|
|
61
62
|
workflowRecoverInput,
|
|
62
63
|
workflowRelayInput
|
|
63
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-U73G6KK4.mjs";
|
|
64
65
|
import {
|
|
65
66
|
AutoPermissionUnavailable,
|
|
66
67
|
ZodOptional,
|
|
@@ -35058,6 +35059,11 @@ var ClaudeSession = class {
|
|
|
35058
35059
|
* That it also rescans the disk is the behaviour worth having: a human who has just written a
|
|
35059
35060
|
* Skill opens the menu expecting to find it.
|
|
35060
35061
|
*/
|
|
35062
|
+
async planLimits() {
|
|
35063
|
+
const { rate_limits } = await this.stream.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true });
|
|
35064
|
+
const limits = anthropicPlanLimits(rate_limits);
|
|
35065
|
+
return limits ? [limits] : [];
|
|
35066
|
+
}
|
|
35061
35067
|
async skills() {
|
|
35062
35068
|
if (this.options.workflowBuilder) return [];
|
|
35063
35069
|
const { skills } = await this.stream.reloadSkills();
|
|
@@ -2,6 +2,7 @@ import { createRequire as __flowCreateRequire } from 'node:module'; const requir
|
|
|
2
2
|
import "./chunk-LAEUXDNH.mjs";
|
|
3
3
|
import {
|
|
4
4
|
EFFORT_ORDER,
|
|
5
|
+
anthropicPlanLimits,
|
|
5
6
|
clampEffort,
|
|
6
7
|
inspectDescription,
|
|
7
8
|
recoverDescription,
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
workflowInspectInput,
|
|
20
21
|
workflowRecoverInput,
|
|
21
22
|
workflowRelayInput
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-U73G6KK4.mjs";
|
|
23
24
|
import {
|
|
24
25
|
__commonJS,
|
|
25
26
|
__export,
|
|
@@ -7018,9 +7019,57 @@ var PiAgentPermissions = class {
|
|
|
7018
7019
|
}
|
|
7019
7020
|
};
|
|
7020
7021
|
|
|
7022
|
+
// src/backend/pi/plan-limits.ts
|
|
7023
|
+
async function fetchAnthropicPlanLimits(token, signal) {
|
|
7024
|
+
const usage = await getJson(
|
|
7025
|
+
"https://api.anthropic.com/api/oauth/usage",
|
|
7026
|
+
{ authorization: `Bearer ${token}`, "anthropic-beta": "oauth-2025-04-20" },
|
|
7027
|
+
signal
|
|
7028
|
+
);
|
|
7029
|
+
const limits = anthropicPlanLimits(usage);
|
|
7030
|
+
return limits && { provider: "Anthropic", ...limits };
|
|
7031
|
+
}
|
|
7032
|
+
async function fetchCodexPlanLimits(token, signal) {
|
|
7033
|
+
const usage = await getJson(
|
|
7034
|
+
"https://chatgpt.com/backend-api/wham/usage",
|
|
7035
|
+
{ authorization: `Bearer ${token}`, "chatgpt-account-id": codexAccountId(token), "user-agent": "codex-cli" },
|
|
7036
|
+
signal
|
|
7037
|
+
);
|
|
7038
|
+
return codexPlanLimits(usage);
|
|
7039
|
+
}
|
|
7040
|
+
function codexPlanLimits(usage) {
|
|
7041
|
+
const short = codexWindow("", usage.rate_limit?.primary_window);
|
|
7042
|
+
const long = codexWindow("", usage.rate_limit?.secondary_window);
|
|
7043
|
+
if (!short || !long) return void 0;
|
|
7044
|
+
const others = (usage.additional_rate_limits ?? []).flatMap((limit) => [
|
|
7045
|
+
codexWindow(`${limit.limit_name} `, limit.rate_limit?.primary_window),
|
|
7046
|
+
codexWindow(`${limit.limit_name} `, limit.rate_limit?.secondary_window)
|
|
7047
|
+
]).filter((window) => window !== void 0);
|
|
7048
|
+
return { provider: "Codex", short, long, others };
|
|
7049
|
+
}
|
|
7050
|
+
function codexWindow(prefix, window) {
|
|
7051
|
+
if (!window) return void 0;
|
|
7052
|
+
const hours = window.limit_window_seconds / 3600;
|
|
7053
|
+
const span = hours < 24 ? `${Math.round(hours)}-hour` : `${Math.round(hours / 24)}-day`;
|
|
7054
|
+
return { label: `${prefix}${span}`, utilization: window.used_percent, resetsAt: new Date(window.reset_at * 1e3).toISOString() };
|
|
7055
|
+
}
|
|
7056
|
+
function codexAccountId(token) {
|
|
7057
|
+
const payload = JSON.parse(Buffer.from(token.split(".")[1] ?? "", "base64url").toString());
|
|
7058
|
+
const id = payload["https://api.openai.com/auth"]?.chatgpt_account_id;
|
|
7059
|
+
if (!id) throw new Error("No ChatGPT account ID in the Codex token");
|
|
7060
|
+
return id;
|
|
7061
|
+
}
|
|
7062
|
+
async function getJson(url, headers, signal) {
|
|
7063
|
+
const response = await fetch(url, { headers, ...signal ? { signal } : {} });
|
|
7064
|
+
if (!response.ok) throw new Error(`${url} answered ${response.status}`);
|
|
7065
|
+
return await response.json();
|
|
7066
|
+
}
|
|
7067
|
+
|
|
7021
7068
|
// src/backend/pi/index.ts
|
|
7022
7069
|
var PiSession = class {
|
|
7023
7070
|
capabilities;
|
|
7071
|
+
spend;
|
|
7072
|
+
counted;
|
|
7024
7073
|
answerEnquiry;
|
|
7025
7074
|
enquiries;
|
|
7026
7075
|
work;
|
|
@@ -7074,6 +7123,8 @@ var PiSession = class {
|
|
|
7074
7123
|
this.agentPermissions = support.agentPermissions;
|
|
7075
7124
|
if (support.permissionProducer) this.permissionProducer = support.permissionProducer;
|
|
7076
7125
|
this.session = session;
|
|
7126
|
+
this.spend = support.priorSpend;
|
|
7127
|
+
this.counted = statsOf(session);
|
|
7077
7128
|
this.applyAutoCompaction = support.autoCompaction;
|
|
7078
7129
|
this.workflowAutoCompaction = support.workflowAutoCompaction;
|
|
7079
7130
|
this.workflowCompactionModelId = support.workflowCompactionModelId;
|
|
@@ -7210,6 +7261,14 @@ var PiSession = class {
|
|
|
7210
7261
|
}))
|
|
7211
7262
|
];
|
|
7212
7263
|
}
|
|
7264
|
+
async planLimits() {
|
|
7265
|
+
const read = async (provider, fetchLimits) => {
|
|
7266
|
+
const token = (await this.session.modelRuntime.getAuth(provider).catch(() => void 0))?.auth.apiKey;
|
|
7267
|
+
return token ? await fetchLimits(token).catch(() => void 0) : void 0;
|
|
7268
|
+
};
|
|
7269
|
+
const limits = await Promise.all([read("anthropic", fetchAnthropicPlanLimits), read("openai-codex", fetchCodexPlanLimits)]);
|
|
7270
|
+
return limits.filter((limit) => limit !== void 0);
|
|
7271
|
+
}
|
|
7213
7272
|
applyEffort(wanted) {
|
|
7214
7273
|
const level = clampEffort(wanted, availableEffort(this.session));
|
|
7215
7274
|
if (!level) {
|
|
@@ -7397,11 +7456,27 @@ var PiSession = class {
|
|
|
7397
7456
|
if (thinking) this.emit({ type: "thinking", id: `${id}-thinking`, text: thinking, final });
|
|
7398
7457
|
}
|
|
7399
7458
|
reportContextUsage() {
|
|
7459
|
+
this.countSpend();
|
|
7400
7460
|
const usage = this.session.getContextUsage();
|
|
7401
7461
|
if (usage && typeof usage.tokens === "number") {
|
|
7402
|
-
this.emit({ type: "context_usage", used: usage.tokens, window: usage.contextWindow });
|
|
7462
|
+
this.emit({ type: "context_usage", used: usage.tokens, window: usage.contextWindow, ...this.spend ? { spend: this.spend } : {} });
|
|
7403
7463
|
}
|
|
7404
7464
|
}
|
|
7465
|
+
countSpend() {
|
|
7466
|
+
const now = statsOf(this.session);
|
|
7467
|
+
const added = { tokens: now.tokens - this.counted.tokens, cached: now.cached - this.counted.cached, costUSD: now.costUSD - this.counted.costUSD };
|
|
7468
|
+
this.counted = now;
|
|
7469
|
+
if (added.tokens <= 0 && added.costUSD <= 0) return;
|
|
7470
|
+
const id = this.session.model ? describeModel(this.session.model).id : "unknown";
|
|
7471
|
+
const spend = this.spend ?? { tokens: 0, cached: 0, costUSD: 0, models: [] };
|
|
7472
|
+
const model = spend.models.find((item) => item.id === id) ?? { id, tokens: 0, cached: 0, costUSD: 0 };
|
|
7473
|
+
this.spend = {
|
|
7474
|
+
tokens: spend.tokens + added.tokens,
|
|
7475
|
+
cached: spend.cached + added.cached,
|
|
7476
|
+
costUSD: spend.costUSD + added.costUSD,
|
|
7477
|
+
models: [...spend.models.filter((item) => item.id !== id), { id, tokens: model.tokens + added.tokens, cached: model.cached + added.cached, costUSD: model.costUSD + added.costUSD }]
|
|
7478
|
+
};
|
|
7479
|
+
}
|
|
7405
7480
|
};
|
|
7406
7481
|
var PiBackend = class {
|
|
7407
7482
|
name = "pi";
|
|
@@ -7496,7 +7571,7 @@ var PiBackend = class {
|
|
|
7496
7571
|
throw new Error(`Could not load the Pi compaction model hook: ${extensionError}`);
|
|
7497
7572
|
}
|
|
7498
7573
|
const autoCompaction = structuredClone(options.autoCompaction);
|
|
7499
|
-
const piSession = new PiSession(session, options.emit, sessionDir, { workflowBuilder: !!builder, ...mcp ? { mcp } : {}, work, subagents, standingAuthorisations: options.standingAuthorisations ?? [], ...agentPermissions ? { agentPermissions } : {}, autoCompaction: piAutoCompaction(settingsManager, autoCompaction), ...autoCompaction ? { workflowAutoCompaction: autoCompaction } : {}, ...options.compactionModelId ? { workflowCompactionModelId: options.compactionModelId } : {}, ...enquiries ? { enquiries } : {}, ...mcp ? { recreate: async (current) => session = (await start(current)).session } : {} });
|
|
7574
|
+
const piSession = new PiSession(session, options.emit, sessionDir, { workflowBuilder: !!builder, ...mcp ? { mcp } : {}, work, subagents, standingAuthorisations: options.standingAuthorisations ?? [], ...agentPermissions ? { agentPermissions } : {}, ...options.priorSpend ? { priorSpend: options.priorSpend } : {}, autoCompaction: piAutoCompaction(settingsManager, autoCompaction), ...autoCompaction ? { workflowAutoCompaction: autoCompaction } : {}, ...options.compactionModelId ? { workflowCompactionModelId: options.compactionModelId } : {}, ...enquiries ? { enquiries } : {}, ...mcp ? { recreate: async (current) => session = (await start(current)).session } : {} });
|
|
7500
7575
|
const modelId = options.modelId ?? (settingsManager.getDefaultProvider() === "azure-openai-responses" && settingsManager.getDefaultModel() ? `azure-openai-responses/${settingsManager.getDefaultModel()}` : void 0);
|
|
7501
7576
|
if (modelId) {
|
|
7502
7577
|
try {
|
|
@@ -7657,6 +7732,10 @@ function joinBlocks(content, kind) {
|
|
|
7657
7732
|
function isString(value) {
|
|
7658
7733
|
return typeof value === "string";
|
|
7659
7734
|
}
|
|
7735
|
+
function statsOf(session) {
|
|
7736
|
+
const stats = session.getSessionStats();
|
|
7737
|
+
return { tokens: stats.tokens.total, cached: stats.tokens.cacheRead, costUSD: stats.cost };
|
|
7738
|
+
}
|
|
7660
7739
|
export {
|
|
7661
7740
|
PiBackend,
|
|
7662
7741
|
PiSession,
|
package/build/backend-worker.mjs
CHANGED
|
@@ -3955,7 +3955,8 @@ function snapshot(session) {
|
|
|
3955
3955
|
return {
|
|
3956
3956
|
capabilities: session.capabilities,
|
|
3957
3957
|
resume: session.resumeToken(),
|
|
3958
|
-
|
|
3958
|
+
spend: session.spend,
|
|
3959
|
+
methods: ["refreshMcp", "startWorkflowSubagent", "compact", "rewindFiles", "skills", "planLimits", "answerEnquiry", "answerPermission", "setPermissionMode"].filter((method) => typeof session[method] === "function")
|
|
3959
3960
|
};
|
|
3960
3961
|
}
|
|
3961
3962
|
|
|
@@ -4146,7 +4147,7 @@ function runWorker() {
|
|
|
4146
4147
|
let backend;
|
|
4147
4148
|
const importing = performance.now();
|
|
4148
4149
|
try {
|
|
4149
|
-
backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-
|
|
4150
|
+
backend = backendModule ? isSea3() ? createRequire(pathToFileURL(process.execPath))(fileURLToPath(backendModule)).default : (await import(backendModule)).default : backendName === "claude" ? new (await import("./backend-worker-chunks/claude-THGSOTC2.mjs")).ClaudeBackend() : new (await import("./backend-worker-chunks/pi-5LAWIJNE.mjs")).PiBackend();
|
|
4150
4151
|
} catch (error) {
|
|
4151
4152
|
throw new Error(`Backend "${backendName}" is not available in this build: ${errorText(error)}`);
|
|
4152
4153
|
}
|
|
@@ -4170,7 +4171,7 @@ function runWorker() {
|
|
|
4170
4171
|
...sessionToolsEnabled && options.tools !== "none" ? { sessionTools } : {}
|
|
4171
4172
|
},
|
|
4172
4173
|
emit: (event) => {
|
|
4173
|
-
const changed = session && (session.capabilities !== published?.capabilities || session.resumeToken() !== published?.resume);
|
|
4174
|
+
const changed = session && (session.capabilities !== published?.capabilities || session.resumeToken() !== published?.resume || session.spend !== published?.spend);
|
|
4174
4175
|
rpc.notify("event", { event, ...changed ? { snapshot: publishSnapshot() } : {} });
|
|
4175
4176
|
}
|
|
4176
4177
|
});
|
|
@@ -4217,6 +4218,9 @@ function runWorker() {
|
|
|
4217
4218
|
case "skills":
|
|
4218
4219
|
result = await session.skills?.();
|
|
4219
4220
|
break;
|
|
4221
|
+
case "planLimits":
|
|
4222
|
+
result = await session.planLimits?.();
|
|
4223
|
+
break;
|
|
4220
4224
|
case "answerEnquiry":
|
|
4221
4225
|
result = await session.answerEnquiry?.(args[0], args[1]) ?? false;
|
|
4222
4226
|
break;
|
|
@@ -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
|
|
@@ -5,6 +5,7 @@ import { randomUUID } from "node:crypto";
|
|
|
5
5
|
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
|
+
import { anthropicPlanLimits } from "../plan-limits.js";
|
|
8
9
|
import { ClaudeWorkflowSubagent, spawnWorkflowProcess } from "./workflow-subagent.js";
|
|
9
10
|
import { clampEffort, EFFORT_ORDER } from "../effort.js";
|
|
10
11
|
import { AsyncQueue } from "./async-queue.js";
|
|
@@ -524,6 +525,11 @@ class ClaudeSession {
|
|
|
524
525
|
* That it also rescans the disk is the behaviour worth having: a human who has just written a
|
|
525
526
|
* Skill opens the menu expecting to find it.
|
|
526
527
|
*/
|
|
528
|
+
async planLimits() {
|
|
529
|
+
const { rate_limits } = await this.stream.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true });
|
|
530
|
+
const limits = anthropicPlanLimits(rate_limits);
|
|
531
|
+
return limits ? [limits] : [];
|
|
532
|
+
}
|
|
527
533
|
async skills() {
|
|
528
534
|
if (this.options.workflowBuilder)
|
|
529
535
|
return [];
|
|
@@ -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 {};
|
|
@@ -44,6 +44,7 @@ export class FakeSession {
|
|
|
44
44
|
rewindFiles;
|
|
45
45
|
/** What this session was told the Agent Session had already spent, for asserting a Revive. */
|
|
46
46
|
priorSpend;
|
|
47
|
+
spend;
|
|
47
48
|
/** What this session was told the machine already authorises, for asserting the read-at-create. */
|
|
48
49
|
standingAuthorisations;
|
|
49
50
|
/** Parent Workflow tools, exposed so relay orchestration can be driven without a model in tests. */
|
|
@@ -215,6 +216,10 @@ export class FakeSession {
|
|
|
215
216
|
async skills() {
|
|
216
217
|
return this.skillList;
|
|
217
218
|
}
|
|
219
|
+
planLimitWindows = [];
|
|
220
|
+
async planLimits() {
|
|
221
|
+
return this.planLimitWindows;
|
|
222
|
+
}
|
|
218
223
|
async setEffort(effort) {
|
|
219
224
|
this.wantedEffort = effort;
|
|
220
225
|
const levels = FAKE_CAPABILITIES.models.find((model) => model.id === this.modelId)?.effortLevels;
|
|
@@ -247,6 +252,7 @@ export class FakeSession {
|
|
|
247
252
|
}
|
|
248
253
|
/** Test affordance: report Spend, which is how a Revive gets something to carry forward. */
|
|
249
254
|
reportSpend(spend) {
|
|
255
|
+
this.spend = spend;
|
|
250
256
|
this.emit({ type: "context_usage", used: 10, window: 100, spend });
|
|
251
257
|
}
|
|
252
258
|
/** Test affordance: emit a complete tool call. */
|
package/dist/backend/pi/index.js
CHANGED
|
@@ -19,9 +19,12 @@ import { ASK_TOOL, PiEnquiries } from "./enquiries.js";
|
|
|
19
19
|
import { backgroundTools } from "./background-calls.js";
|
|
20
20
|
import { SUBAGENT_TOOL, subagentTool } from "./subagents.js";
|
|
21
21
|
import { PiAgentPermissions } from "./agent-permissions.js";
|
|
22
|
+
import { fetchAnthropicPlanLimits, fetchCodexPlanLimits } from "./plan-limits.js";
|
|
22
23
|
import { PiWork, callIdFor, resultText, textResult } from "./work.js";
|
|
23
24
|
export class PiSession {
|
|
24
25
|
capabilities;
|
|
26
|
+
spend;
|
|
27
|
+
counted;
|
|
25
28
|
answerEnquiry;
|
|
26
29
|
enquiries;
|
|
27
30
|
work;
|
|
@@ -77,6 +80,8 @@ export class PiSession {
|
|
|
77
80
|
if (support.permissionProducer)
|
|
78
81
|
this.permissionProducer = support.permissionProducer;
|
|
79
82
|
this.session = session;
|
|
83
|
+
this.spend = support.priorSpend;
|
|
84
|
+
this.counted = statsOf(session);
|
|
80
85
|
this.applyAutoCompaction = support.autoCompaction;
|
|
81
86
|
this.workflowAutoCompaction = support.workflowAutoCompaction;
|
|
82
87
|
this.workflowCompactionModelId = support.workflowCompactionModelId;
|
|
@@ -226,6 +231,14 @@ export class PiSession {
|
|
|
226
231
|
})),
|
|
227
232
|
];
|
|
228
233
|
}
|
|
234
|
+
async planLimits() {
|
|
235
|
+
const read = async (provider, fetchLimits) => {
|
|
236
|
+
const token = (await this.session.modelRuntime.getAuth(provider).catch(() => undefined))?.auth.apiKey;
|
|
237
|
+
return token ? await fetchLimits(token).catch(() => undefined) : undefined;
|
|
238
|
+
};
|
|
239
|
+
const limits = await Promise.all([read("anthropic", fetchAnthropicPlanLimits), read("openai-codex", fetchCodexPlanLimits)]);
|
|
240
|
+
return limits.filter((limit) => limit !== undefined);
|
|
241
|
+
}
|
|
229
242
|
applyEffort(wanted) {
|
|
230
243
|
const level = clampEffort(wanted, availableEffort(this.session));
|
|
231
244
|
// Nothing to set on a model with no effort control. The request stays on file, so switching
|
|
@@ -435,11 +448,26 @@ export class PiSession {
|
|
|
435
448
|
this.emit({ type: "thinking", id: `${id}-thinking`, text: thinking, final });
|
|
436
449
|
}
|
|
437
450
|
reportContextUsage() {
|
|
451
|
+
this.countSpend();
|
|
438
452
|
const usage = this.session.getContextUsage();
|
|
439
453
|
if (usage && typeof usage.tokens === "number") {
|
|
440
|
-
this.emit({ type: "context_usage", used: usage.tokens, window: usage.contextWindow });
|
|
454
|
+
this.emit({ type: "context_usage", used: usage.tokens, window: usage.contextWindow, ...(this.spend ? { spend: this.spend } : {}) });
|
|
441
455
|
}
|
|
442
456
|
}
|
|
457
|
+
countSpend() {
|
|
458
|
+
const now = statsOf(this.session);
|
|
459
|
+
const added = { tokens: now.tokens - this.counted.tokens, cached: now.cached - this.counted.cached, costUSD: now.costUSD - this.counted.costUSD };
|
|
460
|
+
this.counted = now;
|
|
461
|
+
if (added.tokens <= 0 && added.costUSD <= 0)
|
|
462
|
+
return;
|
|
463
|
+
const id = this.session.model ? describeModel(this.session.model).id : "unknown";
|
|
464
|
+
const spend = this.spend ?? { tokens: 0, cached: 0, costUSD: 0, models: [] };
|
|
465
|
+
const model = spend.models.find((item) => item.id === id) ?? { id, tokens: 0, cached: 0, costUSD: 0 };
|
|
466
|
+
this.spend = {
|
|
467
|
+
tokens: spend.tokens + added.tokens, cached: spend.cached + added.cached, costUSD: spend.costUSD + added.costUSD,
|
|
468
|
+
models: [...spend.models.filter((item) => item.id !== id), { id, tokens: model.tokens + added.tokens, cached: model.cached + added.cached, costUSD: model.costUSD + added.costUSD }],
|
|
469
|
+
};
|
|
470
|
+
}
|
|
443
471
|
}
|
|
444
472
|
export class PiBackend {
|
|
445
473
|
name = "pi";
|
|
@@ -537,7 +565,7 @@ export class PiBackend {
|
|
|
537
565
|
throw new Error(`Could not load the Pi compaction model hook: ${extensionError}`);
|
|
538
566
|
}
|
|
539
567
|
const autoCompaction = structuredClone(options.autoCompaction);
|
|
540
|
-
const piSession = new PiSession(session, options.emit, sessionDir, { workflowBuilder: !!builder, ...(mcp ? { mcp } : {}), work, subagents, standingAuthorisations: options.standingAuthorisations ?? [], ...(agentPermissions ? { agentPermissions } : {}), autoCompaction: piAutoCompaction(settingsManager, autoCompaction), ...(autoCompaction ? { workflowAutoCompaction: autoCompaction } : {}), ...(options.compactionModelId ? { workflowCompactionModelId: options.compactionModelId } : {}), ...(enquiries ? { enquiries } : {}), ...(mcp ? { recreate: async (current) => (session = (await start(current)).session) } : {}) });
|
|
568
|
+
const piSession = new PiSession(session, options.emit, sessionDir, { workflowBuilder: !!builder, ...(mcp ? { mcp } : {}), work, subagents, standingAuthorisations: options.standingAuthorisations ?? [], ...(agentPermissions ? { agentPermissions } : {}), ...(options.priorSpend ? { priorSpend: options.priorSpend } : {}), autoCompaction: piAutoCompaction(settingsManager, autoCompaction), ...(autoCompaction ? { workflowAutoCompaction: autoCompaction } : {}), ...(options.compactionModelId ? { workflowCompactionModelId: options.compactionModelId } : {}), ...(enquiries ? { enquiries } : {}), ...(mcp ? { recreate: async (current) => (session = (await start(current)).session) } : {}) });
|
|
541
569
|
const modelId = options.modelId ?? (settingsManager.getDefaultProvider() === "azure-openai-responses" && settingsManager.getDefaultModel()
|
|
542
570
|
? `azure-openai-responses/${settingsManager.getDefaultModel()}` : undefined);
|
|
543
571
|
if (modelId) {
|
|
@@ -708,3 +736,7 @@ function joinBlocks(content, kind) {
|
|
|
708
736
|
function isString(value) {
|
|
709
737
|
return typeof value === "string";
|
|
710
738
|
}
|
|
739
|
+
function statsOf(session) {
|
|
740
|
+
const stats = session.getSessionStats();
|
|
741
|
+
return { tokens: stats.tokens.total, cached: stats.tokens.cacheRead, costUSD: stats.cost };
|
|
742
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { registerPiNativeProvider, unregisterPiNativeProvider, withPi099RadiusCatalog } from
|
|
2
|
-
export { createPiModelAuth } from
|
|
1
|
+
import { registerPiNativeProvider, unregisterPiNativeProvider, withPi099RadiusCatalog } from './model-catalog.js';
|
|
2
|
+
export { createPiModelAuth } from './host-auth.js';
|
|
3
3
|
const emptyCredentials = {
|
|
4
4
|
async read(_providerId, options) { options?.signal?.throwIfAborted(); return undefined; },
|
|
5
5
|
async list(options) { options?.signal?.throwIfAborted(); return []; },
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { anthropicPlanLimits } from "../plan-limits.js";
|
|
2
|
+
export async function fetchAnthropicPlanLimits(token, signal) {
|
|
3
|
+
const usage = await getJson("https://api.anthropic.com/api/oauth/usage", { authorization: `Bearer ${token}`, "anthropic-beta": "oauth-2025-04-20" }, signal);
|
|
4
|
+
const limits = anthropicPlanLimits(usage);
|
|
5
|
+
return limits && { provider: "Anthropic", ...limits };
|
|
6
|
+
}
|
|
7
|
+
export async function fetchCodexPlanLimits(token, signal) {
|
|
8
|
+
const usage = await getJson("https://chatgpt.com/backend-api/wham/usage", { authorization: `Bearer ${token}`, "chatgpt-account-id": codexAccountId(token), "user-agent": "codex-cli" }, signal);
|
|
9
|
+
return codexPlanLimits(usage);
|
|
10
|
+
}
|
|
11
|
+
export function codexPlanLimits(usage) {
|
|
12
|
+
const short = codexWindow("", usage.rate_limit?.primary_window);
|
|
13
|
+
const long = codexWindow("", usage.rate_limit?.secondary_window);
|
|
14
|
+
if (!short || !long)
|
|
15
|
+
return undefined;
|
|
16
|
+
const others = (usage.additional_rate_limits ?? []).flatMap((limit) => [
|
|
17
|
+
codexWindow(`${limit.limit_name} `, limit.rate_limit?.primary_window),
|
|
18
|
+
codexWindow(`${limit.limit_name} `, limit.rate_limit?.secondary_window),
|
|
19
|
+
]).filter((window) => window !== undefined);
|
|
20
|
+
return { provider: "Codex", short, long, others };
|
|
21
|
+
}
|
|
22
|
+
function codexWindow(prefix, window) {
|
|
23
|
+
if (!window)
|
|
24
|
+
return undefined;
|
|
25
|
+
const hours = window.limit_window_seconds / 3600;
|
|
26
|
+
const span = hours < 24 ? `${Math.round(hours)}-hour` : `${Math.round(hours / 24)}-day`;
|
|
27
|
+
return { label: `${prefix}${span}`, utilization: window.used_percent, resetsAt: new Date(window.reset_at * 1000).toISOString() };
|
|
28
|
+
}
|
|
29
|
+
function codexAccountId(token) {
|
|
30
|
+
const payload = JSON.parse(Buffer.from(token.split(".")[1] ?? "", "base64url").toString());
|
|
31
|
+
const id = payload["https://api.openai.com/auth"]?.chatgpt_account_id;
|
|
32
|
+
if (!id)
|
|
33
|
+
throw new Error("No ChatGPT account ID in the Codex token");
|
|
34
|
+
return id;
|
|
35
|
+
}
|
|
36
|
+
async function getJson(url, headers, signal) {
|
|
37
|
+
const response = await fetch(url, { headers, ...(signal ? { signal } : {}) });
|
|
38
|
+
if (!response.ok)
|
|
39
|
+
throw new Error(`${url} answered ${response.status}`);
|
|
40
|
+
return await response.json();
|
|
41
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from 'typebox';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { workflowInspectInput, workflowRecoverInput, workflowRelayInput, inspectDescription, recoverDescription, relayEnquiryDescription, relayPermissionDescription } from
|
|
3
|
+
import { workflowInspectInput, workflowRecoverInput, workflowRelayInput, inspectDescription, recoverDescription, relayEnquiryDescription, relayPermissionDescription } from '../workflow-tools.js';
|
|
4
4
|
export function workflowParentTools(parent) {
|
|
5
5
|
if (!parent)
|
|
6
6
|
return [];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function anthropicPlanLimits(usage) {
|
|
2
|
+
const short = anthropicWindow("5-hour", usage?.five_hour);
|
|
3
|
+
const long = anthropicWindow("7-day", usage?.seven_day);
|
|
4
|
+
if (!short || !long)
|
|
5
|
+
return undefined;
|
|
6
|
+
const others = [
|
|
7
|
+
anthropicWindow("Opus", usage?.seven_day_opus),
|
|
8
|
+
anthropicWindow("Sonnet", usage?.seven_day_sonnet),
|
|
9
|
+
...(usage?.model_scoped ?? []).map((scoped) => anthropicWindow(scoped.display_name, scoped)),
|
|
10
|
+
].filter((window) => window !== undefined);
|
|
11
|
+
return { short, long, others };
|
|
12
|
+
}
|
|
13
|
+
function anthropicWindow(label, window) {
|
|
14
|
+
if (window?.utilization == null)
|
|
15
|
+
return undefined;
|
|
16
|
+
return { label, utilization: window.utilization, ...(window.resets_at ? { resetsAt: window.resets_at } : {}) };
|
|
17
|
+
}
|
|
@@ -122,7 +122,7 @@ export function runWorker() {
|
|
|
122
122
|
emit: (event) => {
|
|
123
123
|
// Models can be a large catalogue. Do not resend it for every text/tool delta, but do
|
|
124
124
|
// mirror any changed state before the event that exposes it to the Session Host.
|
|
125
|
-
const changed = session && (session.capabilities !== published?.capabilities || session.resumeToken() !== published?.resume);
|
|
125
|
+
const changed = session && (session.capabilities !== published?.capabilities || session.resumeToken() !== published?.resume || session.spend !== published?.spend);
|
|
126
126
|
rpc.notify("event", { event, ...(changed ? { snapshot: publishSnapshot() } : {}) });
|
|
127
127
|
},
|
|
128
128
|
});
|
|
@@ -174,6 +174,9 @@ export function runWorker() {
|
|
|
174
174
|
case "skills":
|
|
175
175
|
result = await session.skills?.();
|
|
176
176
|
break;
|
|
177
|
+
case "planLimits":
|
|
178
|
+
result = await session.planLimits?.();
|
|
179
|
+
break;
|
|
177
180
|
case "answerEnquiry":
|
|
178
181
|
result = await session.answerEnquiry?.(args[0], args[1]) ?? false;
|
|
179
182
|
break;
|
|
@@ -10,7 +10,7 @@ import { validateFilesystemScope } from "../../isolation/filesystem.js";
|
|
|
10
10
|
import { workflowBuilderFolder } from "../../isolation/shared-sandbox.js";
|
|
11
11
|
import { nodeExecutionAssets } from "../../isolation/node-assets.js";
|
|
12
12
|
import { launchWorker, workerCommand } from "./launcher.js";
|
|
13
|
-
import { seaSdkExecutionAssets } from
|
|
13
|
+
import { seaSdkExecutionAssets } from './assets.js';
|
|
14
14
|
import { WorkerRpc } from "./rpc.js";
|
|
15
15
|
import { SandboxMcpSession } from "./sandbox-mcp.js";
|
|
16
16
|
import { mcpMetadata } from "./protocol.js";
|
|
@@ -18,7 +18,7 @@ import { workflowInspectInput, workflowRecoverInput, workflowRelayInput } from "
|
|
|
18
18
|
import { sessionListInput, sessionInspectInput, sessionCreateInput, sessionSendInput } from "../session-tools.js";
|
|
19
19
|
import { migrateLegacyClaudeState, prepareClaudeState, relocateClaudeState, forkClaudeState } from "./claude-state.js";
|
|
20
20
|
import { relocatePiState, forkPiState } from "../pi/state.js";
|
|
21
|
-
import { createPiModelAuth } from
|
|
21
|
+
import { createPiModelAuth } from '../pi/model-auth.js';
|
|
22
22
|
import { recordTiming } from "../../daemon/timings.js";
|
|
23
23
|
/** One owned worker per Backend Session, optionally enforcing a filesystem boundary. */
|
|
24
24
|
export class WorkerBackend {
|
|
@@ -264,6 +264,7 @@ class WorkerSession {
|
|
|
264
264
|
capabilities;
|
|
265
265
|
get sandbox() { return this.launchOptions.sandboxed; }
|
|
266
266
|
resume;
|
|
267
|
+
spend;
|
|
267
268
|
worker;
|
|
268
269
|
rpc;
|
|
269
270
|
failed;
|
|
@@ -276,6 +277,7 @@ class WorkerSession {
|
|
|
276
277
|
compact;
|
|
277
278
|
rewindFiles;
|
|
278
279
|
skills;
|
|
280
|
+
planLimits;
|
|
279
281
|
answerEnquiry;
|
|
280
282
|
answerPermission;
|
|
281
283
|
setPermissionMode;
|
|
@@ -347,7 +349,8 @@ class WorkerSession {
|
|
|
347
349
|
}, (name, value) => this.notify(name, value));
|
|
348
350
|
this.worker.onMessage((message) => this.rpc.receive(message), (error) => this.fail(error));
|
|
349
351
|
child.once("error", (error) => this.fail(error));
|
|
350
|
-
child.stdout?.once("close", () => this.
|
|
352
|
+
child.stdout?.once("close", () => void Promise.race([this.worker.exited, new Promise((resolve) => setTimeout(resolve, 1000).unref())])
|
|
353
|
+
.then(() => this.fail(new Error("Backend worker disconnected"))));
|
|
351
354
|
child.once("exit", (code, signal) => this.fail(new Error(`Backend worker exited (${signal ?? code ?? "unknown"})${this.worker.diagnostics() ? `: ${this.worker.diagnostics()}` : ""}`)));
|
|
352
355
|
}
|
|
353
356
|
requirePiAuth() {
|
|
@@ -409,6 +412,8 @@ class WorkerSession {
|
|
|
409
412
|
this.rewindFiles = (messageId) => this.rpc.call("rewindFiles", [messageId]);
|
|
410
413
|
if (methods.has("skills"))
|
|
411
414
|
this.skills = () => this.rpc.call("skills");
|
|
415
|
+
if (methods.has("planLimits"))
|
|
416
|
+
this.planLimits = () => this.rpc.call("planLimits");
|
|
412
417
|
if (methods.has("answerEnquiry"))
|
|
413
418
|
this.answerEnquiry = (id, answers) => this.rpc.call("answerEnquiry", [id, answers]);
|
|
414
419
|
if (methods.has("answerPermission"))
|
|
@@ -427,6 +432,7 @@ class WorkerSession {
|
|
|
427
432
|
updateSnapshot(state) {
|
|
428
433
|
this.capabilities = state.capabilities;
|
|
429
434
|
this.resume = state.resume;
|
|
435
|
+
this.spend = state.spend;
|
|
430
436
|
}
|
|
431
437
|
notify(name, value) {
|
|
432
438
|
switch (name) {
|