@ashx-j/lunr 0.2.27 → 0.2.28
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/CHANGELOG.md +10 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.d.ts.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.js +5 -2
- package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.d.ts +4 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.js +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts +5 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.js +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts +5 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +68 -40
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts +0 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +28 -4
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.d.ts +7 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.js +70 -38
- package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +9 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js +13 -62
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
- package/dist/builtin-extensions/pi-tps.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-tps.js +10 -2
- package/dist/builtin-extensions/pi-tps.js.map +1 -1
- package/dist/catalog/models.json +1 -1
- package/dist/catalog/providers/google-vertex.json +1 -1
- package/dist/catalog/providers/google.json +1 -1
- package/dist/catalog/publication.json +3 -3
- package/dist/core/agent-session.d.ts +6 -15
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +35 -50
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/cache-stats.d.ts +1 -1
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +2 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +5 -11
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +38 -92
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/context-breakdown.d.ts +2 -2
- package/dist/core/context-breakdown.d.ts.map +1 -1
- package/dist/core/context-breakdown.js +22 -20
- package/dist/core/context-breakdown.js.map +1 -1
- package/dist/core/extensions/types.d.ts +3 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/session-manager.d.ts +5 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +16 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/usage-accounting.d.ts +47 -0
- package/dist/core/usage-accounting.d.ts.map +1 -0
- package/dist/core/usage-accounting.js +205 -0
- package/dist/core/usage-accounting.js.map +1 -0
- package/dist/core/usage-history.d.ts +1 -18
- package/dist/core/usage-history.d.ts.map +1 -1
- package/dist/core/usage-history.js +46 -114
- package/dist/core/usage-history.js.map +1 -1
- package/dist/gateway/mobile-commands.d.ts.map +1 -1
- package/dist/gateway/mobile-commands.js +13 -1
- package/dist/gateway/mobile-commands.js.map +1 -1
- package/dist/modes/interactive/components/context-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/context-view.js +2 -2
- package/dist/modes/interactive/components/context-view.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +8 -12
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/usage-view.d.ts +5 -0
- package/dist/modes/interactive/components/usage-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/usage-view.js +21 -6
- package/dist/modes/interactive/components/usage-view.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -5
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +55 -22
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/node-runtime/{agent-session-services-KDMSPQDY.js → agent-session-services-RTUGP3XR.js} +5 -4
- package/dist/node-runtime/{builtin-extensions-OX6KELNX.js → builtin-extensions-N4EUD6SB.js} +1 -1
- package/dist/node-runtime/{chunk-A2WO6WIN.js → chunk-4QRUZ64T.js} +11 -5
- package/dist/node-runtime/{chunk-ZDJUR45D.js → chunk-BMRXLQWQ.js} +41 -38
- package/dist/node-runtime/{chunk-MQPKUHRN.js → chunk-DFMPRAQQ.js} +8 -8
- package/dist/node-runtime/{chunk-C3P6Q3B2.js → chunk-E5DQGNJI.js} +10 -10
- package/dist/node-runtime/{chunk-FIRA54AC.js → chunk-ICKGAKWX.js} +22 -55
- package/dist/node-runtime/{chunk-JWEVT363.js → chunk-JEK35V2M.js} +14 -8
- package/dist/node-runtime/{chunk-EPR2F3GU.js → chunk-PWHTSQC4.js} +15 -1
- package/dist/node-runtime/{chunk-AYHH7YSD.js → chunk-QT3F6UEV.js} +61 -30
- package/dist/node-runtime/{chunk-JQYNHAKX.js → chunk-RY3FJ6WI.js} +29 -27
- package/dist/node-runtime/{chunk-I2H5QMWW.js → chunk-STMX7W5I.js} +1 -1
- package/dist/node-runtime/chunk-SWWHZ2RI.js +158 -0
- package/dist/node-runtime/{chunk-QNVMKNNN.js → chunk-U3YVZ6UC.js} +4 -4
- package/dist/node-runtime/{command-3HMSY6W2.js → command-YRT7I2BW.js} +1 -1
- package/dist/node-runtime/{commands-OCSSEEWJ.js → commands-2ETOWWRA.js} +5 -5
- package/dist/node-runtime/{export-html-BRWF5AHI.js → export-html-DBQRRMAY.js} +1 -1
- package/dist/node-runtime/{gateway-6623C2U3.js → gateway-V6K2CDWN.js} +9 -9
- package/dist/node-runtime/{goal-AIHEDUYA.js → goal-J7TYMOBK.js} +9 -3
- package/dist/node-runtime/index.js +9 -8
- package/dist/node-runtime/{interactive-mode-FM5DNUSW.js → interactive-mode-ASZ7APYP.js} +7 -6
- package/dist/node-runtime/{lunr-cron-LKVA5CZZ.js → lunr-cron-WD3YH4CR.js} +4 -4
- package/dist/node-runtime/main.js +7 -6
- package/dist/node-runtime/{mobile-commands-XT3NQXLD.js → mobile-commands-ICUXFW5V.js} +2 -2
- package/dist/node-runtime/{pi-subagents-LT3CTO4E.js → pi-subagents-QPU3OXE4.js} +17 -62
- package/dist/node-runtime/rpc-entry.js +7 -6
- package/dist/node-runtime/{session-handoff-LNSPDTKY.js → session-handoff-LYH53ESV.js} +2 -2
- package/dist/node-runtime/{session-manager-YIFIAVGC.js → session-manager-ZJ3N5Q74.js} +1 -1
- package/dist/node-runtime/{subagent-executor-Q5F7DBVM.js → subagent-executor-UI6SHG3X.js} +294 -231
- package/docs/features.md +10 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/install-lock/package-lock.json +24 -24
- package/install-lock/package.json +2 -2
- package/npm-shrinkwrap.json +21 -21
- package/package.json +7 -7
|
@@ -34,7 +34,7 @@ import { attachPostExitStdioGuard, trySignalChild } from "../../shared/post-exit
|
|
|
34
34
|
import { detectSubagentError, extractTextFromContent, extractToolArgsPreview, getFinalOutput, readStatus } from "../../shared/utils.js";
|
|
35
35
|
import { evaluateCompletionMutationGuard } from "../shared/completion-guard.js";
|
|
36
36
|
import { createMutatingFailureState, didMutatingToolFail, isMutatingTool, nextLongRunningTrigger, recordMutatingFailure, resetMutatingFailureState, resolveCurrentPath, shouldEscalateMutatingFailures, summarizeRecentMutatingFailures, } from "../shared/long-running-guard.js";
|
|
37
|
-
import {
|
|
37
|
+
import { parseSessionRequests, parseSessionUsage, sessionUsageDelta, tokenUsageFromUsage } from "../../shared/session-tokens.js";
|
|
38
38
|
import { cleanupWorktrees, createWorktrees, diffWorktrees, findWorktreeTaskCwdConflict, formatWorktreeDiffSummary, formatWorktreeTaskCwdConflict, } from "../shared/worktree.js";
|
|
39
39
|
import { resolveEffectiveThinking } from "../../shared/model-info.js";
|
|
40
40
|
import { writeInitialProgressFile } from "../../shared/settings.js";
|
|
@@ -127,7 +127,7 @@ function findLatestSessionFile(sessionDir) {
|
|
|
127
127
|
.map((f) => path.join(sessionDir, f));
|
|
128
128
|
if (files.length === 0)
|
|
129
129
|
return null;
|
|
130
|
-
files.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs);
|
|
130
|
+
files.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs || b.localeCompare(a));
|
|
131
131
|
return files[0] ?? null;
|
|
132
132
|
}
|
|
133
133
|
catch {
|
|
@@ -136,19 +136,18 @@ function findLatestSessionFile(sessionDir) {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
function emptyUsage() {
|
|
139
|
-
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
139
|
+
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0, unknownRequests: 0, partialRequests: 0, unknownCosts: 0 };
|
|
140
140
|
}
|
|
141
141
|
function tokenUsageFromAttempts(attempts) {
|
|
142
|
-
if (!attempts
|
|
142
|
+
if (!attempts?.some((attempt) => attempt.usage))
|
|
143
143
|
return null;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return total > 0 ? { input, output, total } : null;
|
|
144
|
+
const usage = emptyUsage();
|
|
145
|
+
for (const attempt of attempts)
|
|
146
|
+
if (attempt.usage) {
|
|
147
|
+
for (const key of Object.keys(usage))
|
|
148
|
+
usage[key] += attempt.usage[key] ?? 0;
|
|
149
|
+
}
|
|
150
|
+
return tokenUsageFromUsage(usage);
|
|
152
151
|
}
|
|
153
152
|
function costSummaryFromAttempts(attempts) {
|
|
154
153
|
if (!attempts || attempts.length === 0)
|
|
@@ -157,7 +156,7 @@ function costSummaryFromAttempts(attempts) {
|
|
|
157
156
|
let outputTokens = 0;
|
|
158
157
|
let costUsd = 0;
|
|
159
158
|
for (const attempt of attempts) {
|
|
160
|
-
inputTokens += attempt.usage?.input ?? 0;
|
|
159
|
+
inputTokens += (attempt.usage?.input ?? 0) + (attempt.usage?.cacheRead ?? 0) + (attempt.usage?.cacheWrite ?? 0);
|
|
161
160
|
outputTokens += attempt.usage?.output ?? 0;
|
|
162
161
|
costUsd += attempt.usage?.cost ?? 0;
|
|
163
162
|
}
|
|
@@ -345,6 +344,9 @@ function runPiStreaming(args, cwd, outputFile, env, piPackageRoot, piArgv1, maxS
|
|
|
345
344
|
usage.cacheRead += eventUsage.cacheRead ?? 0;
|
|
346
345
|
usage.cacheWrite += eventUsage.cacheWrite ?? 0;
|
|
347
346
|
usage.cost += eventUsage.cost?.total ?? 0;
|
|
347
|
+
usage.unknownRequests += Number(eventUsage.measurement === "unknown");
|
|
348
|
+
usage.partialRequests += Number(eventUsage.measurement === "partial");
|
|
349
|
+
usage.unknownCosts += Number(eventUsage.costSource === "unknown");
|
|
348
350
|
}
|
|
349
351
|
if (isTerminalAssistantStop(event.message)) {
|
|
350
352
|
if (!event.message.errorMessage && extractTextFromContent(event.message.content).trim())
|
|
@@ -771,6 +773,8 @@ export async function runSingleStep(step, ctx) {
|
|
|
771
773
|
model: imported.model,
|
|
772
774
|
attemptedModels: imported.attemptedModels,
|
|
773
775
|
modelAttempts: imported.modelAttempts,
|
|
776
|
+
receiptUsage: imported.usage,
|
|
777
|
+
usageRequests: imported.usageRequests,
|
|
774
778
|
totalCost: imported.totalCost,
|
|
775
779
|
structuredOutput: timedOut || stopped ? undefined : imported.structuredOutput,
|
|
776
780
|
structuredOutputPath: timedOut || stopped ? undefined : imported.structuredOutputPath,
|
|
@@ -827,6 +831,7 @@ export async function runSingleStep(step, ctx) {
|
|
|
827
831
|
: [undefined];
|
|
828
832
|
const attemptedModels = [];
|
|
829
833
|
const modelAttempts = [];
|
|
834
|
+
const priorRequestIds = new Set(parseSessionRequests(step.sessionFile ?? sessionDir).map((request) => request.id));
|
|
830
835
|
const attemptNotes = [];
|
|
831
836
|
const eventsPath = path.join(path.dirname(ctx.outputFile), "events.jsonl");
|
|
832
837
|
let finalResult;
|
|
@@ -903,7 +908,11 @@ export async function runSingleStep(step, ctx) {
|
|
|
903
908
|
waitToolEnabled: step.waitToolEnabled,
|
|
904
909
|
parentPermissionMode,
|
|
905
910
|
});
|
|
911
|
+
const usageBeforeAttempt = parseSessionUsage(step.sessionFile ?? sessionDir);
|
|
906
912
|
const run = await runPiStreaming(args, step.cwd ?? ctx.cwd, ctx.outputFile, env, ctx.piPackageRoot, ctx.piArgv1, step.maxSubagentDepth, { eventsPath, runId: ctx.id, stepIndex: ctx.flatIndex, agent: step.agent }, ctx.registerInterrupt, ctx.onChildEvent, transcriptWriter, ctx.registerTimeout, ctx.timeoutMessage, ctx.registerStop, ctx.stopMessage, ctx.registerTurnBudgetAbort, ctx.onWriterProcess);
|
|
913
|
+
const persistedUsage = parseSessionUsage(step.sessionFile ?? sessionDir);
|
|
914
|
+
if (persistedUsage)
|
|
915
|
+
run.usage = sessionUsageDelta(persistedUsage, usageBeforeAttempt);
|
|
907
916
|
if (run.turnBudget)
|
|
908
917
|
turnBudget = run.turnBudget;
|
|
909
918
|
else if (ctx.turnBudget) {
|
|
@@ -1093,6 +1102,7 @@ export async function runSingleStep(step, ctx) {
|
|
|
1093
1102
|
}, null, 2), "utf-8");
|
|
1094
1103
|
}
|
|
1095
1104
|
}
|
|
1105
|
+
const usageRequests = parseSessionRequests(step.sessionFile ?? sessionDir).filter((request) => Boolean(step.sessionFile) || !priorRequestIds.has(request.id));
|
|
1096
1106
|
return {
|
|
1097
1107
|
childId: step.childId,
|
|
1098
1108
|
description: step.description,
|
|
@@ -1102,7 +1112,9 @@ export async function runSingleStep(step, ctx) {
|
|
|
1102
1112
|
exitCode: effectiveFinalExitCode,
|
|
1103
1113
|
error: effectiveFinalError,
|
|
1104
1114
|
protocolError: finalResult?.protocolError,
|
|
1105
|
-
sessionFile: step.sessionFile,
|
|
1115
|
+
sessionFile: step.sessionFile ?? (sessionDir ? findLatestSessionFile(sessionDir) ?? undefined : undefined),
|
|
1116
|
+
receiptUsage: step.sessionFile ? parseSessionUsage(step.sessionFile) ?? undefined : undefined,
|
|
1117
|
+
usageRequests: usageRequests.length > 0 ? usageRequests : undefined,
|
|
1106
1118
|
intercomTarget: ctx.childIntercomTarget,
|
|
1107
1119
|
model: finalResult?.model,
|
|
1108
1120
|
attemptedModels: attemptedModels.length > 0 ? attemptedModels : undefined,
|
|
@@ -2052,7 +2064,7 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
2052
2064
|
step.turnCount = (step.turnCount ?? 0) + 1;
|
|
2053
2065
|
const usage = event.message.usage;
|
|
2054
2066
|
if (usage) {
|
|
2055
|
-
const input = usage.input ?? usage.inputTokens ?? 0;
|
|
2067
|
+
const input = (usage.input ?? usage.inputTokens ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
|
|
2056
2068
|
const output = usage.output ?? usage.outputTokens ?? 0;
|
|
2057
2069
|
const previousInput = step.tokens?.input ?? 0;
|
|
2058
2070
|
const previousOutput = step.tokens?.output ?? 0;
|
|
@@ -2632,6 +2644,10 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
2632
2644
|
for (const pr of parallelResults) {
|
|
2633
2645
|
results.push({
|
|
2634
2646
|
agent: pr.agent,
|
|
2647
|
+
childId: pr.childId,
|
|
2648
|
+
description: pr.description,
|
|
2649
|
+
receiptUsage: pr.receiptUsage,
|
|
2650
|
+
usageRequests: pr.usageRequests,
|
|
2635
2651
|
output: pr.output,
|
|
2636
2652
|
error: pr.error,
|
|
2637
2653
|
protocolError: pr.protocolError,
|
|
@@ -2851,7 +2867,7 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
2851
2867
|
type: "subagent.step.started", ts: taskStartTime, runId: id, stepIndex: fi, agent: task.agent,
|
|
2852
2868
|
}));
|
|
2853
2869
|
const taskSessionDir = config.sessionDir
|
|
2854
|
-
? path.join(config.sessionDir, `parallel-${taskIdx}`)
|
|
2870
|
+
? path.join(config.sessionDir, `parallel-${stepIndex}-${taskIdx}`)
|
|
2855
2871
|
: undefined;
|
|
2856
2872
|
const { taskForRun, taskCwd } = prepareParallelTaskRun(task, cwd, worktreeSetup, taskIdx);
|
|
2857
2873
|
flushPendingStepSteers(fi);
|
|
@@ -2954,10 +2970,7 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
2954
2970
|
flatIndex += group.parallel.length;
|
|
2955
2971
|
for (let t = 0; t < group.parallel.length; t++) {
|
|
2956
2972
|
const fi = groupStartFlatIndex + t;
|
|
2957
|
-
const
|
|
2958
|
-
? parseSessionTokens(path.join(config.sessionDir, `parallel-${t}`))
|
|
2959
|
-
: null;
|
|
2960
|
-
const taskTokens = sessionTokens ?? tokenUsageFromAttempts(parallelResults[t]?.modelAttempts);
|
|
2973
|
+
const taskTokens = tokenUsageFromAttempts(parallelResults[t]?.modelAttempts);
|
|
2961
2974
|
if (!taskTokens)
|
|
2962
2975
|
continue;
|
|
2963
2976
|
statusPayload.steps[fi].tokens = taskTokens;
|
|
@@ -2973,6 +2986,10 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
2973
2986
|
for (const pr of parallelResults) {
|
|
2974
2987
|
results.push({
|
|
2975
2988
|
agent: pr.agent,
|
|
2989
|
+
childId: pr.childId,
|
|
2990
|
+
description: pr.description,
|
|
2991
|
+
receiptUsage: pr.receiptUsage,
|
|
2992
|
+
usageRequests: pr.usageRequests,
|
|
2976
2993
|
output: pr.output,
|
|
2977
2994
|
error: pr.error,
|
|
2978
2995
|
protocolError: pr.protocolError,
|
|
@@ -3099,6 +3116,10 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
3099
3116
|
const childStopped = singleResult.stopped === true;
|
|
3100
3117
|
results.push({
|
|
3101
3118
|
agent: singleResult.agent,
|
|
3119
|
+
childId: singleResult.childId,
|
|
3120
|
+
description: singleResult.description,
|
|
3121
|
+
receiptUsage: singleResult.receiptUsage,
|
|
3122
|
+
usageRequests: singleResult.usageRequests,
|
|
3102
3123
|
output: stopped || childStopped ? stopMessage : timedOut ? (timeoutMessage ?? "Subagent timed out.") : singleResult.output,
|
|
3103
3124
|
error: stopped || childStopped ? stopMessage : timedOut ? (timeoutMessage ?? "Subagent timed out.") : singleResult.error,
|
|
3104
3125
|
protocolError: singleResult.protocolError,
|
|
@@ -3135,26 +3156,15 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
3135
3156
|
}, stepIndex);
|
|
3136
3157
|
}
|
|
3137
3158
|
statusPayload.outputs = outputs;
|
|
3138
|
-
const
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
input:
|
|
3142
|
-
output:
|
|
3143
|
-
total:
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
previousCumulativeTokens = cumulativeTokens;
|
|
3148
|
-
}
|
|
3149
|
-
else {
|
|
3150
|
-
stepTokens = tokenUsageFromAttempts(singleResult.modelAttempts);
|
|
3151
|
-
if (stepTokens) {
|
|
3152
|
-
previousCumulativeTokens = {
|
|
3153
|
-
input: previousCumulativeTokens.input + stepTokens.input,
|
|
3154
|
-
output: previousCumulativeTokens.output + stepTokens.output,
|
|
3155
|
-
total: previousCumulativeTokens.total + stepTokens.total,
|
|
3156
|
-
};
|
|
3157
|
-
}
|
|
3159
|
+
const stepTokens = tokenUsageFromAttempts(singleResult.modelAttempts);
|
|
3160
|
+
if (stepTokens) {
|
|
3161
|
+
previousCumulativeTokens = {
|
|
3162
|
+
input: previousCumulativeTokens.input + stepTokens.input,
|
|
3163
|
+
output: previousCumulativeTokens.output + stepTokens.output,
|
|
3164
|
+
total: previousCumulativeTokens.total + stepTokens.total,
|
|
3165
|
+
cacheRead: (previousCumulativeTokens.cacheRead ?? 0) + (stepTokens.cacheRead ?? 0),
|
|
3166
|
+
cacheWrite: (previousCumulativeTokens.cacheWrite ?? 0) + (stepTokens.cacheWrite ?? 0),
|
|
3167
|
+
};
|
|
3158
3168
|
}
|
|
3159
3169
|
const stepEndTime = Date.now();
|
|
3160
3170
|
const childInterrupted = singleResult.interrupted === true;
|
|
@@ -3244,6 +3254,17 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
3244
3254
|
outputTokens: sum.outputTokens + (result.totalCost?.outputTokens ?? 0),
|
|
3245
3255
|
costUsd: sum.costUsd + (result.totalCost?.costUsd ?? 0),
|
|
3246
3256
|
}), { inputTokens: 0, outputTokens: 0, costUsd: 0 });
|
|
3257
|
+
statusPayload.totalTokens = results.reduce((total, result) => {
|
|
3258
|
+
const usage = tokenUsageFromAttempts(result.modelAttempts);
|
|
3259
|
+
if (usage) {
|
|
3260
|
+
total.input += usage.input;
|
|
3261
|
+
total.output += usage.output;
|
|
3262
|
+
total.total += usage.total;
|
|
3263
|
+
total.cacheRead += usage.cacheRead ?? 0;
|
|
3264
|
+
total.cacheWrite += usage.cacheWrite ?? 0;
|
|
3265
|
+
}
|
|
3266
|
+
return total;
|
|
3267
|
+
}, { input: 0, output: 0, total: 0, cacheRead: 0, cacheWrite: 0 });
|
|
3247
3268
|
const finalTotalCost = totalCost.inputTokens > 0 || totalCost.outputTokens > 0 || totalCost.costUsd > 0 ? totalCost : undefined;
|
|
3248
3269
|
const finalFlatAgents = statusPayload.steps.map((step) => step.agent);
|
|
3249
3270
|
const agentName = finalFlatAgents.length === 1
|
|
@@ -3407,6 +3428,13 @@ async function runSubagent(config, onWriterProcess) {
|
|
|
3407
3428
|
attemptedModels: r.attemptedModels,
|
|
3408
3429
|
modelAttempts: r.modelAttempts,
|
|
3409
3430
|
totalCost: r.totalCost,
|
|
3431
|
+
usageRequests: r.usageRequests,
|
|
3432
|
+
usage: r.receiptUsage ?? r.modelAttempts?.reduce((total, attempt) => {
|
|
3433
|
+
if (attempt.usage)
|
|
3434
|
+
for (const key of Object.keys(total))
|
|
3435
|
+
total[key] += attempt.usage[key] ?? 0;
|
|
3436
|
+
return total;
|
|
3437
|
+
}, emptyUsage()),
|
|
3410
3438
|
artifactPaths: r.artifactPaths,
|
|
3411
3439
|
truncated: r.truncated,
|
|
3412
3440
|
transcriptPath: r.transcriptPath,
|