@sagentlab/navarch-runtime 0.1.150 → 0.1.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/claude.cjs +6 -2
- package/dist/exit-conditions.cjs +3 -1
- package/dist/session.cjs +19 -1
- package/package.json +1 -1
package/dist/adapters/claude.cjs
CHANGED
|
@@ -39,7 +39,7 @@ function operatorOwnsSession(extraArgs) {
|
|
|
39
39
|
* the same result object (`type: "result"`, `usage`, `total_cost_usd`) that
|
|
40
40
|
* `--output-format json` prints alone; parseClaudeJsonResult() reads that
|
|
41
41
|
* last record. If the real shape differs, parseClaudeJsonResult() returns null and
|
|
42
|
-
* tokensIn/tokensOut/costUsd
|
|
42
|
+
* tokensIn/tokensOut/costUsd remain unset (session.cts's existing
|
|
43
43
|
* default) rather than throwing -- see runtime/README.md.
|
|
44
44
|
*/
|
|
45
45
|
async function runClaudeCodeAdapter(options) {
|
|
@@ -95,7 +95,11 @@ async function runClaudeCodeAdapter(options) {
|
|
|
95
95
|
tokensIn: addUsage(primary.tokensIn, fallback.tokensIn),
|
|
96
96
|
tokensOut: addUsage(primary.tokensOut, fallback.tokensOut),
|
|
97
97
|
cacheHitTokensIn: addUsage(primary.cacheHitTokensIn, fallback.cacheHitTokensIn),
|
|
98
|
-
|
|
98
|
+
// A resumed result is cumulative for the same conversation. Fresh
|
|
99
|
+
// conversations require both reports; missing is never a zero addend.
|
|
100
|
+
costUsd: canResume ? fallback.costUsd
|
|
101
|
+
: primary.costUsd === undefined || fallback.costUsd === undefined ? undefined
|
|
102
|
+
: primary.costUsd + fallback.costUsd,
|
|
99
103
|
};
|
|
100
104
|
}
|
|
101
105
|
function addUsage(first, second) {
|
package/dist/exit-conditions.cjs
CHANGED
|
@@ -113,7 +113,9 @@ function extractUsageFromClaudeJson(parsed) {
|
|
|
113
113
|
(usage.cache_creation_input_tokens ?? 0) +
|
|
114
114
|
(usage.cache_read_input_tokens ?? 0);
|
|
115
115
|
const tokensOut = usage.output_tokens ?? 0;
|
|
116
|
-
const
|
|
116
|
+
const reportedCost = parsed.total_cost_usd ?? parsed.cost_usd;
|
|
117
|
+
const costUsd = typeof reportedCost === "number" && Number.isFinite(reportedCost) && reportedCost >= 0
|
|
118
|
+
? reportedCost : undefined;
|
|
117
119
|
return { tokensIn, tokensOut, cacheHitTokensIn: usage.cache_read_input_tokens ?? 0, costUsd };
|
|
118
120
|
}
|
|
119
121
|
/**
|
package/dist/session.cjs
CHANGED
|
@@ -864,6 +864,10 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
864
864
|
// Running usage totals the resumable conversation last reported, for the
|
|
865
865
|
// fields its adapter reports cumulatively (AgentAdapter.cumulativeResumeUsage).
|
|
866
866
|
let conversationUsage = {};
|
|
867
|
+
// Claude costs are cumulative per conversation, including resumed turns.
|
|
868
|
+
const claudeCosts = new Map();
|
|
869
|
+
const missingClaudeCosts = new Set();
|
|
870
|
+
let claudeConversation = 0;
|
|
867
871
|
// Claim-time guidance is part of the brief (task_context's "Human
|
|
868
872
|
// guidance" section, lib/navarch/context.ts), so guidance turns carry only
|
|
869
873
|
// what arrived after the claim.
|
|
@@ -1027,6 +1031,17 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
1027
1031
|
antigravityResume = turnResult.antigravityResume;
|
|
1028
1032
|
if (runtime === "muse")
|
|
1029
1033
|
museSessionId = turnResult.agentSessionId;
|
|
1034
|
+
if (runtime === "claude-code") {
|
|
1035
|
+
if (!resumed)
|
|
1036
|
+
claudeConversation += 1;
|
|
1037
|
+
const cost = turnResult.costUsd;
|
|
1038
|
+
if (typeof cost === "number" && Number.isFinite(cost) && cost >= 0) {
|
|
1039
|
+
claudeCosts.set(claudeConversation, Math.max(claudeCosts.get(claudeConversation) ?? 0, cost));
|
|
1040
|
+
missingClaudeCosts.delete(claudeConversation);
|
|
1041
|
+
}
|
|
1042
|
+
else
|
|
1043
|
+
missingClaudeCosts.add(claudeConversation);
|
|
1044
|
+
}
|
|
1030
1045
|
if (adapter.cumulativeResumeUsage) {
|
|
1031
1046
|
// A resumed run reports the conversation's running total: record only
|
|
1032
1047
|
// this turn's increase. A fresh conversation starts its own total.
|
|
@@ -1144,7 +1159,10 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
1144
1159
|
tokensIn: sumReportedUsage(attempts, "tokensIn", runtime === "muse"),
|
|
1145
1160
|
tokensOut: sumReportedUsage(attempts, "tokensOut", runtime === "muse"),
|
|
1146
1161
|
cacheHitTokensIn: sumReportedUsage(attempts, "cacheHitTokensIn", runtime === "muse"),
|
|
1147
|
-
costUsd: runtime === "
|
|
1162
|
+
costUsd: runtime === "claude-code"
|
|
1163
|
+
? missingClaudeCosts.size > 0 || claudeCosts.size === 0 ? undefined
|
|
1164
|
+
: [...claudeCosts.values()].reduce((sum, cost) => sum + cost, 0)
|
|
1165
|
+
: runtime === "muse" ? (0, muse_cjs_1.sumMuseSessionCost)(attempts) : sumReportedUsage(attempts, "costUsd"),
|
|
1148
1166
|
};
|
|
1149
1167
|
const mapping = (0, exit_conditions_cjs_1.mapExitCondition)({
|
|
1150
1168
|
...result,
|
package/package.json
CHANGED