@qmediat.io/gemini-code-context-mcp 1.24.0 → 1.25.1
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 +110 -1
- package/README.md +1 -1
- package/dist/cache/cache-manager.d.ts +23 -34
- package/dist/cache/cache-manager.d.ts.map +1 -1
- package/dist/cache/cache-manager.js +324 -272
- package/dist/cache/cache-manager.js.map +1 -1
- package/dist/cache/caching-mode.d.ts +5 -3
- package/dist/cache/caching-mode.d.ts.map +1 -1
- package/dist/cache/caching-mode.js +6 -4
- package/dist/cache/caching-mode.js.map +1 -1
- package/dist/cache/ttl-watcher.d.ts.map +1 -1
- package/dist/cache/ttl-watcher.js +7 -1
- package/dist/cache/ttl-watcher.js.map +1 -1
- package/dist/cache/ttl.d.ts +8 -0
- package/dist/cache/ttl.d.ts.map +1 -0
- package/dist/cache/ttl.js +10 -0
- package/dist/cache/ttl.js.map +1 -0
- package/dist/manifest/db.d.ts.map +1 -1
- package/dist/manifest/db.js +2 -1
- package/dist/manifest/db.js.map +1 -1
- package/dist/tools/agentic/dispatch.d.ts +68 -0
- package/dist/tools/agentic/dispatch.d.ts.map +1 -0
- package/dist/tools/agentic/dispatch.js +167 -0
- package/dist/tools/agentic/dispatch.js.map +1 -0
- package/dist/tools/agentic/input.d.ts +28 -0
- package/dist/tools/agentic/input.d.ts.map +1 -0
- package/dist/tools/agentic/input.js +66 -0
- package/dist/tools/agentic/input.js.map +1 -0
- package/dist/tools/agentic/instructions.d.ts +46 -0
- package/dist/tools/agentic/instructions.d.ts.map +1 -0
- package/dist/tools/agentic/instructions.js +170 -0
- package/dist/tools/agentic/instructions.js.map +1 -0
- package/dist/tools/agentic/iteration.d.ts +81 -0
- package/dist/tools/agentic/iteration.d.ts.map +1 -0
- package/dist/tools/agentic/iteration.js +317 -0
- package/dist/tools/agentic/iteration.js.map +1 -0
- package/dist/tools/agentic/ledger.d.ts +64 -0
- package/dist/tools/agentic/ledger.d.ts.map +1 -0
- package/dist/tools/agentic/ledger.js +110 -0
- package/dist/tools/agentic/ledger.js.map +1 -0
- package/dist/tools/agentic/loop.d.ts +10 -0
- package/dist/tools/agentic/loop.d.ts.map +1 -0
- package/dist/tools/agentic/loop.js +179 -0
- package/dist/tools/agentic/loop.js.map +1 -0
- package/dist/tools/agentic/no-progress.d.ts +90 -0
- package/dist/tools/agentic/no-progress.d.ts.map +1 -0
- package/dist/tools/agentic/no-progress.js +107 -0
- package/dist/tools/agentic/no-progress.js.map +1 -0
- package/dist/tools/agentic/pass-clock.d.ts +85 -0
- package/dist/tools/agentic/pass-clock.d.ts.map +1 -0
- package/dist/tools/agentic/pass-clock.js +162 -0
- package/dist/tools/agentic/pass-clock.js.map +1 -0
- package/dist/tools/agentic/phase-defaults.d.ts +29 -0
- package/dist/tools/agentic/phase-defaults.d.ts.map +1 -0
- package/dist/tools/agentic/phase-defaults.js +23 -0
- package/dist/tools/agentic/phase-defaults.js.map +1 -0
- package/dist/tools/agentic/rescue.d.ts +69 -0
- package/dist/tools/agentic/rescue.d.ts.map +1 -0
- package/dist/tools/agentic/rescue.js +203 -0
- package/dist/tools/agentic/rescue.js.map +1 -0
- package/dist/tools/agentic/response.d.ts +16 -0
- package/dist/tools/agentic/response.d.ts.map +1 -0
- package/dist/tools/agentic/response.js +25 -0
- package/dist/tools/agentic/response.js.map +1 -0
- package/dist/tools/agentic/results.d.ts +76 -0
- package/dist/tools/agentic/results.d.ts.map +1 -0
- package/dist/tools/agentic/results.js +228 -0
- package/dist/tools/agentic/results.js.map +1 -0
- package/dist/tools/agentic/run.d.ts +130 -0
- package/dist/tools/agentic/run.d.ts.map +1 -0
- package/dist/tools/agentic/run.js +128 -0
- package/dist/tools/agentic/run.js.map +1 -0
- package/dist/tools/agentic/sandbox.d.ts +13 -2
- package/dist/tools/agentic/sandbox.d.ts.map +1 -1
- package/dist/tools/agentic/sandbox.js +127 -111
- package/dist/tools/agentic/sandbox.js.map +1 -1
- package/dist/tools/agentic/workspace-tools.d.ts +30 -27
- package/dist/tools/agentic/workspace-tools.d.ts.map +1 -1
- package/dist/tools/agentic/workspace-tools.js +324 -385
- package/dist/tools/agentic/workspace-tools.js.map +1 -1
- package/dist/tools/ask/answer.d.ts +9 -0
- package/dist/tools/ask/answer.d.ts.map +1 -0
- package/dist/tools/ask/answer.js +28 -0
- package/dist/tools/ask/answer.js.map +1 -0
- package/dist/tools/ask/attachments.d.ts +25 -0
- package/dist/tools/ask/attachments.d.ts.map +1 -0
- package/dist/tools/ask/attachments.js +85 -0
- package/dist/tools/ask/attachments.js.map +1 -0
- package/dist/tools/ask/call.d.ts +61 -0
- package/dist/tools/ask/call.d.ts.map +1 -0
- package/dist/tools/ask/call.js +6 -0
- package/dist/tools/ask/call.js.map +1 -0
- package/dist/tools/ask/guard.d.ts +24 -0
- package/dist/tools/ask/guard.d.ts.map +1 -0
- package/dist/tools/ask/guard.js +79 -0
- package/dist/tools/ask/guard.js.map +1 -0
- package/dist/tools/ask/input.d.ts +45 -0
- package/dist/tools/ask/input.d.ts.map +1 -0
- package/dist/tools/ask/input.js +93 -0
- package/dist/tools/ask/input.js.map +1 -0
- package/dist/tools/ask/instruction.d.ts +8 -0
- package/dist/tools/ask/instruction.d.ts.map +1 -0
- package/dist/tools/ask/instruction.js +13 -0
- package/dist/tools/ask/instruction.js.map +1 -0
- package/dist/tools/ask/request.d.ts +14 -0
- package/dist/tools/ask/request.d.ts.map +1 -0
- package/dist/tools/ask/request.js +38 -0
- package/dist/tools/ask/request.js.map +1 -0
- package/dist/tools/ask/results.d.ts +23 -0
- package/dist/tools/ask/results.d.ts.map +1 -0
- package/dist/tools/ask/results.js +107 -0
- package/dist/tools/ask/results.js.map +1 -0
- package/dist/tools/ask/setup.d.ts +22 -0
- package/dist/tools/ask/setup.d.ts.map +1 -0
- package/dist/tools/ask/setup.js +57 -0
- package/dist/tools/ask/setup.js.map +1 -0
- package/dist/tools/ask/sizing.d.ts +10 -0
- package/dist/tools/ask/sizing.d.ts.map +1 -0
- package/dist/tools/ask/sizing.js +33 -0
- package/dist/tools/ask/sizing.js.map +1 -0
- package/dist/tools/ask/thinking.d.ts +54 -0
- package/dist/tools/ask/thinking.d.ts.map +1 -0
- package/dist/tools/ask/thinking.js +69 -0
- package/dist/tools/ask/thinking.js.map +1 -0
- package/dist/tools/ask-agentic-fallback.d.ts +33 -0
- package/dist/tools/ask-agentic-fallback.d.ts.map +1 -0
- package/dist/tools/ask-agentic-fallback.js +113 -0
- package/dist/tools/ask-agentic-fallback.js.map +1 -0
- package/dist/tools/ask-agentic.tool.d.ts +11 -44
- package/dist/tools/ask-agentic.tool.d.ts.map +1 -1
- package/dist/tools/ask-agentic.tool.js +139 -1618
- package/dist/tools/ask-agentic.tool.js.map +1 -1
- package/dist/tools/ask.tool.d.ts +3 -41
- package/dist/tools/ask.tool.d.ts.map +1 -1
- package/dist/tools/ask.tool.js +46 -944
- package/dist/tools/ask.tool.js.map +1 -1
- package/dist/tools/code.tool.d.ts.map +1 -1
- package/dist/tools/code.tool.js +376 -514
- package/dist/tools/code.tool.js.map +1 -1
- package/dist/tools/reindex.tool.d.ts.map +1 -1
- package/dist/tools/reindex.tool.js +19 -22
- package/dist/tools/reindex.tool.js.map +1 -1
- package/dist/tools/shared/abort-timeout.d.ts +43 -5
- package/dist/tools/shared/abort-timeout.d.ts.map +1 -1
- package/dist/tools/shared/abort-timeout.js +111 -102
- package/dist/tools/shared/abort-timeout.js.map +1 -1
- package/dist/tools/shared/call-ledger.d.ts +27 -12
- package/dist/tools/shared/call-ledger.d.ts.map +1 -1
- package/dist/tools/shared/call-ledger.js +57 -39
- package/dist/tools/shared/call-ledger.js.map +1 -1
- package/dist/tools/shared/continuation.d.ts +1 -1
- package/dist/tools/shared/continuation.d.ts.map +1 -1
- package/dist/tools/shared/eager-answer.d.ts +78 -0
- package/dist/tools/shared/eager-answer.d.ts.map +1 -0
- package/dist/tools/shared/eager-answer.js +130 -0
- package/dist/tools/shared/eager-answer.js.map +1 -0
- package/dist/tools/shared/eager-call.d.ts +114 -0
- package/dist/tools/shared/eager-call.d.ts.map +1 -0
- package/dist/tools/shared/eager-call.js +95 -0
- package/dist/tools/shared/eager-call.js.map +1 -0
- package/dist/tools/shared/eager-steps.d.ts +114 -0
- package/dist/tools/shared/eager-steps.d.ts.map +1 -0
- package/dist/tools/shared/eager-steps.js +152 -0
- package/dist/tools/shared/eager-steps.js.map +1 -0
- package/dist/tools/shared/question-fields.d.ts +10 -0
- package/dist/tools/shared/question-fields.d.ts.map +1 -0
- package/dist/tools/shared/question-fields.js +13 -0
- package/dist/tools/shared/question-fields.js.map +1 -0
- package/dist/tools/shared/service-tier.d.ts +9 -0
- package/dist/tools/shared/service-tier.d.ts.map +1 -1
- package/dist/tools/shared/service-tier.js +15 -0
- package/dist/tools/shared/service-tier.js.map +1 -1
- package/dist/tools/shared/settle-call.d.ts +11 -6
- package/dist/tools/shared/settle-call.d.ts.map +1 -1
- package/dist/tools/shared/settle-call.js +14 -10
- package/dist/tools/shared/settle-call.js.map +1 -1
- package/dist/tools/shared/thinking.d.ts +9 -0
- package/dist/tools/shared/thinking.d.ts.map +1 -1
- package/dist/tools/shared/thinking.js +10 -0
- package/dist/tools/shared/thinking.js.map +1 -1
- package/dist/tools/shared/throttle.d.ts +7 -0
- package/dist/tools/shared/throttle.d.ts.map +1 -1
- package/dist/tools/shared/throttle.js +18 -0
- package/dist/tools/shared/throttle.js.map +1 -1
- package/dist/tools/shared/workspace-refusal.d.ts +13 -0
- package/dist/tools/shared/workspace-refusal.d.ts.map +1 -0
- package/dist/tools/shared/workspace-refusal.js +23 -0
- package/dist/tools/shared/workspace-refusal.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The results `ask_agentic` returns once the loop has started: the answer (organic or forced), and every error that
|
|
3
|
+
* ends the loop. `apiCalls` is the authoritative total `generateContent` count on every one of them.
|
|
4
|
+
*/
|
|
5
|
+
import { errorResult, textResult } from '../registry.js';
|
|
6
|
+
import { ABORTED_REQUEST_NOTE } from '../shared/abort-timeout.js';
|
|
7
|
+
/** An answer's structured fields; `overBudget` says whether its input tokens passed `maxTotalInputTokens`. */
|
|
8
|
+
function answerFields(run, state, totals, source) {
|
|
9
|
+
const { resolved } = run;
|
|
10
|
+
return {
|
|
11
|
+
resolvedModel: resolved.resolved,
|
|
12
|
+
requestedModel: resolved.requested,
|
|
13
|
+
fallbackApplied: resolved.fallbackApplied,
|
|
14
|
+
modelCategory: resolved.category,
|
|
15
|
+
contextWindow: resolved.inputTokenLimit,
|
|
16
|
+
iterations: state.iterations,
|
|
17
|
+
apiCalls: totals.apiCalls,
|
|
18
|
+
cumulativeInputTokens: totals.inputTokens,
|
|
19
|
+
cumulativeOutputTokens: totals.outputTokens,
|
|
20
|
+
cumulativeThinkingTokens: totals.thinkingTokens,
|
|
21
|
+
filesRead: state.filesReadSet.size,
|
|
22
|
+
filesReadList: [...state.filesReadSet].slice(0, 40),
|
|
23
|
+
durationMs: Date.now() - run.started,
|
|
24
|
+
thinkingSummary: totals.thinkingSummary,
|
|
25
|
+
...(source === 'forced' ? { convergenceForced: true } : {}),
|
|
26
|
+
overBudget: totals.inputTokens > run.limits.maxTotalInputTokens,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Organic final-text path: no forced-finalization pass ran, so total `generateContent` calls equals loop iterations. */
|
|
30
|
+
export function organicAnswer(run, state, finalText, thinkingSummary) {
|
|
31
|
+
return textResult(finalText, answerFields(run, state, {
|
|
32
|
+
apiCalls: state.iterations,
|
|
33
|
+
inputTokens: state.cumulativeInputTokens,
|
|
34
|
+
outputTokens: state.cumulativeOutputTokens,
|
|
35
|
+
thinkingTokens: state.cumulativeThinkingTokens,
|
|
36
|
+
thinkingSummary,
|
|
37
|
+
}, 'organic'));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The daily budget refused an iteration's reservation. BUDGET_REJECT is pre-dispatch — `iterations`
|
|
41
|
+
* was incremented at the top of the loop body, but this iteration's `generateContent` never fired.
|
|
42
|
+
* Subtract 1 to match the schema contract that `apiCalls` is the AUTHORITATIVE total
|
|
43
|
+
* generateContent count. `Math.max(0, ...)` guards the first-iteration-rejection edge (iter 1 +
|
|
44
|
+
* reject → 0 calls).
|
|
45
|
+
*/
|
|
46
|
+
export function budgetRejected(run, state, spentMicros, estimateUsd) {
|
|
47
|
+
const spentUsd = spentMicros / 1_000_000;
|
|
48
|
+
const { dailyBudgetUsd } = run.ctx.config;
|
|
49
|
+
return errorResult(`Daily budget cap would be exceeded: spent $${spentUsd.toFixed(4)} + estimate $${estimateUsd.toFixed(4)} > cap $${dailyBudgetUsd.toFixed(2)}. Retry after UTC midnight, or raise GEMINI_DAILY_BUDGET_USD.`, {
|
|
50
|
+
errorCode: 'BUDGET_REJECT',
|
|
51
|
+
retryable: false,
|
|
52
|
+
iterations: state.iterations,
|
|
53
|
+
apiCalls: Math.max(0, state.iterations - 1),
|
|
54
|
+
cumulativeInputTokens: state.cumulativeInputTokens,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** What the message of an iteration booked before it timed out says of its cost. */
|
|
58
|
+
const BOOKED_ITERATION_NOTE = "The iteration's model call had completed: it is booked at the token and cost fields this result reports.";
|
|
59
|
+
/** The default a bound reports when no knob bounded its phase, by phase (`phase-defaults.ts`); the TPM wait has none. */
|
|
60
|
+
const DEFAULT_HINTS = {
|
|
61
|
+
opening: (n, ms) => `No chunk arrived within the ${ms} ms default for a request's opening. Set \`${n.totalMs}\` per call or \`${n.totalEnv}\` to bound each iteration yourself.`,
|
|
62
|
+
stream: (n, ms) => `The stream sent nothing for the ${ms} ms default. Set \`${n.stallMs}\` per call or \`${n.stallEnv}\` to bound a stream's silence yourself.`,
|
|
63
|
+
tools: (n, ms) => `The iteration's tool calls made no progress for the ${ms} ms default. Set \`${n.totalMs}\` per call or \`${n.totalEnv}\` to bound each iteration yourself.`,
|
|
64
|
+
finalization: (n, ms) => `A request of the forced-finalization pass ran past the ${ms} ms default. Set \`${n.totalMs}\` per call or \`${n.totalEnv}\` to bound it yourself.`,
|
|
65
|
+
};
|
|
66
|
+
/** The knob that raises a bound a caller set. */
|
|
67
|
+
const KNOB_HINTS = {
|
|
68
|
+
iterationTimeoutMs: (n) => `Increase \`${n.totalMs}\` per call or set \`${n.totalEnv}\` higher.`,
|
|
69
|
+
stallMs: (n) => `Increase \`${n.stallMs}\` per call or set \`${n.stallEnv}\` higher. Stall fires when the stream goes silent — usually a dead socket or a Gemini server-side hiccup.`,
|
|
70
|
+
};
|
|
71
|
+
/** An `external` timeout names no bound of this call: it quotes the error's own message. */
|
|
72
|
+
const externalHint = (timeout) => `No bound of this call fired: the request ended with a timeout of its own ("${timeout.message.slice(0, 200)}").`;
|
|
73
|
+
/**
|
|
74
|
+
* What a timeout message tells the caller to change: the knob that fired, the default of the phase and its knob, or —
|
|
75
|
+
* for an `external` timeout — that none of this call's bounds fired.
|
|
76
|
+
*/
|
|
77
|
+
export function timeoutHint(timeout, names) {
|
|
78
|
+
if (timeout.source === 'external')
|
|
79
|
+
return externalHint(timeout);
|
|
80
|
+
const hint = timeout.source === 'default' ? DEFAULT_HINTS[timeout.phase] : KNOB_HINTS[timeout.source];
|
|
81
|
+
return hint(names, timeout.limitMs);
|
|
82
|
+
}
|
|
83
|
+
/** "timed out (kind) after N ms", the limit left out for an `external` timeout: no bound of this call set one. */
|
|
84
|
+
function timedOutAfter(timeout) {
|
|
85
|
+
const after = timeout.limitMs === null ? '' : ` after ${timeout.limitMs}ms`;
|
|
86
|
+
return `timed out (${timeout.kind})${after}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The whole agentic call fails on an iteration timeout — the failed iteration's function-call results never came back,
|
|
90
|
+
* so the conversation is structurally incomplete.
|
|
91
|
+
*
|
|
92
|
+
* `timeoutMs` / `stallMs` report the configured knobs (as `ask` / `code` do); `timeoutKind` says which kind fired
|
|
93
|
+
* (`stall` for a stream's gap only), `timeoutPhase` where, `timeoutSource` which bound. `dispatched` false means the
|
|
94
|
+
* bound fired in the TPM wait and this iteration never reached the API: `apiCalls` leaves it out. An iteration booked
|
|
95
|
+
* before it timed out (the bound fired in its tools phase) reports its billed fields and its message says so; the abort
|
|
96
|
+
* note is for an iteration whose call was cancelled (`billed: null`). A TIMEOUT is retryable unless tool calls of the
|
|
97
|
+
* iteration still run (`toolCallsRunning`): a retry would stack file-system work on the same thread pool.
|
|
98
|
+
*/
|
|
99
|
+
export function iterationTimedOut(iterations, t) {
|
|
100
|
+
const { timeout } = t;
|
|
101
|
+
const costNote = t.billed === null ? ABORTED_REQUEST_NOTE : BOOKED_ITERATION_NOTE;
|
|
102
|
+
return errorResult(`ask_agentic: iteration ${iterations} ${timedOutAfter(timeout)}. ${timeoutHint(timeout, t.knobNames)} ${costNote}`, {
|
|
103
|
+
errorCode: 'TIMEOUT',
|
|
104
|
+
timeoutMs: t.timeoutMs,
|
|
105
|
+
stallMs: t.stallMs,
|
|
106
|
+
timeoutKind: timeout.kind,
|
|
107
|
+
timeoutPhase: timeout.phase,
|
|
108
|
+
timeoutSource: timeout.source,
|
|
109
|
+
iteration: iterations,
|
|
110
|
+
iterations,
|
|
111
|
+
apiCalls: t.dispatched ? iterations : Math.max(0, iterations - 1),
|
|
112
|
+
retryable: t.toolCallsRunning === 0,
|
|
113
|
+
...(t.toolCallsRunning > 0 ? { toolCallsRunning: t.toolCallsRunning } : {}),
|
|
114
|
+
...(t.billed ?? {}),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** The budget guard fires AFTER the iteration's generateContent completed — the call IS counted in apiCalls. */
|
|
118
|
+
export function inputBudgetExceeded(run, state) {
|
|
119
|
+
const { iterations, cumulativeInputTokens } = state;
|
|
120
|
+
const { maxTotalInputTokens } = run.limits;
|
|
121
|
+
return errorResult(`ask_agentic: cumulative input tokens (${cumulativeInputTokens.toLocaleString()}) exceeded budget (${maxTotalInputTokens.toLocaleString()}) after ${iterations} iterations. Increase maxTotalInputTokens, narrow your prompt, or lower thinkingLevel.`, {
|
|
122
|
+
errorCode: 'UNKNOWN',
|
|
123
|
+
retryable: false,
|
|
124
|
+
subReason: 'AGENTIC_INPUT_BUDGET_EXCEEDED',
|
|
125
|
+
iterations,
|
|
126
|
+
apiCalls: iterations,
|
|
127
|
+
cumulativeInputTokens,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* R2 message enrichment (v1.16.1 — /6step PARTIAL TP): some MCP consumers (notably Claude Code's
|
|
132
|
+
* tool-result rendering) collapse isError responses to the message string only and don't surface
|
|
133
|
+
* `structuredContent` — wire format includes both per CallToolResultSchema (independent optional
|
|
134
|
+
* fields) but rendering is consumer-side. Operator-actionable fields (iterations, filesRead) are
|
|
135
|
+
* mirrored into the message string so they're visible regardless of consumer rendering. Dedupe fires
|
|
136
|
+
* AFTER the iteration's generateContent completed — the call IS counted in apiCalls.
|
|
137
|
+
*/
|
|
138
|
+
export function noProgressDetected(state, stuck) {
|
|
139
|
+
const { iterations } = state;
|
|
140
|
+
const filesRead = state.filesReadSet.size;
|
|
141
|
+
const sig = stuck.signature;
|
|
142
|
+
return errorResult(`ask_agentic: no-progress loop detected — call '${sig.slice(0, 200)}' was repeated ${stuck.count} times without new file reads between repeats (after ${iterations} iter${iterations === 1 ? '' : 's'}, ${filesRead} file${filesRead === 1 ? '' : 's'} read). Returning partial state.`, {
|
|
143
|
+
errorCode: 'UNKNOWN',
|
|
144
|
+
retryable: false,
|
|
145
|
+
subReason: 'AGENTIC_NO_PROGRESS',
|
|
146
|
+
iterations,
|
|
147
|
+
apiCalls: iterations,
|
|
148
|
+
repeatedSignature: sig.slice(0, 500),
|
|
149
|
+
cumulativeInputTokens: state.cumulativeInputTokens,
|
|
150
|
+
filesRead,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The end of a loop that exhausted `maxIterations`: the forced answer when the finalization pass
|
|
155
|
+
* produced text, else `AGENTIC_MAX_ITERATIONS`.
|
|
156
|
+
*
|
|
157
|
+
* Token totals are after the finalization pass. When the pass succeeded at the API level its tokens
|
|
158
|
+
* ARE billed even if its text came back empty, so both results report the post-pass totals.
|
|
159
|
+
* `apiCalls` counts the pass from its explicit `attempted` flag (set IMMEDIATELY BEFORE the dispatch)
|
|
160
|
+
* rather than from its usage — timeouts and pre-response network failures leave usageMetadata empty
|
|
161
|
+
* even though the request was sent. Skipped paths
|
|
162
|
+
* (daily-budget reject) leave `attempted` false so they report `apiCalls = iterations`. Operators can
|
|
163
|
+
* branch on `apiCalls > iterations` to detect the forced pass without parsing `convergenceForced`.
|
|
164
|
+
*/
|
|
165
|
+
export function maxIterationsResult(run, state, rescue) {
|
|
166
|
+
const totals = {
|
|
167
|
+
apiCalls: state.iterations + (rescue.attempted ? 1 : 0),
|
|
168
|
+
inputTokens: state.cumulativeInputTokens + rescue.usage.promptTokenCount,
|
|
169
|
+
outputTokens: state.cumulativeOutputTokens + rescue.usage.candidatesTokenCount,
|
|
170
|
+
thinkingTokens: state.cumulativeThinkingTokens + rescue.usage.thoughtsTokenCount,
|
|
171
|
+
thinkingSummary: rescue.thinkingSummary,
|
|
172
|
+
};
|
|
173
|
+
if (rescue.text.length > 0) {
|
|
174
|
+
return textResult(rescue.text, answerFields(run, state, totals, 'forced'));
|
|
175
|
+
}
|
|
176
|
+
return rescueFailed(run, state, rescue, totals);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The message of a forced pass that produced no answer: skipped for the daily budget, or ran and failed — a timeout then
|
|
180
|
+
* says what fired and the knob that raises it, as a loop iteration's does.
|
|
181
|
+
*/
|
|
182
|
+
function rescueFailureMessage(run, rescue) {
|
|
183
|
+
const head = `ask_agentic: reached maxIterations (${run.limits.maxIterations}) without a final answer`;
|
|
184
|
+
if (rescue.skipReason === 'daily-budget') {
|
|
185
|
+
return `${head}; forced-finalization pass skipped because daily budget cap reached. Wait for daily reset (UTC midnight) or raise GEMINI_DAILY_BUDGET_USD.`;
|
|
186
|
+
}
|
|
187
|
+
const remedy = 'Increase maxIterations or narrow your prompt.';
|
|
188
|
+
if (rescue.timeout === null)
|
|
189
|
+
return `${head}. ${remedy}`;
|
|
190
|
+
const { timeout } = rescue;
|
|
191
|
+
return `${head}; the forced-finalization pass ${timedOutAfter(timeout)}. ${timeoutHint(timeout, run.knobNames)} ${remedy}`;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* v1.14.2 Fix 5: the error message branches on whether the rescue was skipped due to daily-budget
|
|
195
|
+
* exhaustion vs ran-and-failed (empty text / network error / timeout). The generic "Increase
|
|
196
|
+
* maxIterations" message would lie to operators on the daily-budget skip path — the actual
|
|
197
|
+
* remediation is to wait for daily reset or raise GEMINI_DAILY_BUDGET_USD. `finalizationSkipReason`
|
|
198
|
+
* is present only when set.
|
|
199
|
+
*
|
|
200
|
+
* P4 (v1.15.0): `rescueErrorCode` is the caller-visible rescue failure-class, present when the rescue
|
|
201
|
+
* ran-but-failed; absent when it was skipped (daily budget). Wrappers can branch retry behaviour on
|
|
202
|
+
* this without log scraping. P8 (v1.15.0): thinking tokens are part of the failure-path cumulative
|
|
203
|
+
* telemetry too, so a rescue-attempted-but-failed call does not under-report its billing footprint.
|
|
204
|
+
* A pass booked before it failed (an empty text, a response that could not be read) reports its billed
|
|
205
|
+
* fields, as a failed loop iteration does. A pass that timed out reports `timeoutPhase` (`tpm-wait` | `finalization`)
|
|
206
|
+
* and `timeoutSource`, read from its clock.
|
|
207
|
+
*/
|
|
208
|
+
function rescueFailed(run, state, rescue, totals) {
|
|
209
|
+
return errorResult(rescueFailureMessage(run, rescue), {
|
|
210
|
+
errorCode: 'UNKNOWN',
|
|
211
|
+
retryable: false,
|
|
212
|
+
subReason: 'AGENTIC_MAX_ITERATIONS',
|
|
213
|
+
...(rescue.skipReason !== null ? { finalizationSkipReason: rescue.skipReason } : {}),
|
|
214
|
+
...(rescue.errorCode !== null ? { rescueErrorCode: rescue.errorCode } : {}),
|
|
215
|
+
...(rescue.timeout !== null
|
|
216
|
+
? { timeoutPhase: rescue.timeout.phase, timeoutSource: rescue.timeout.source }
|
|
217
|
+
: {}),
|
|
218
|
+
...(rescue.errorMessage !== null ? { rescueErrorMessage: rescue.errorMessage } : {}),
|
|
219
|
+
iterations: state.iterations,
|
|
220
|
+
apiCalls: totals.apiCalls,
|
|
221
|
+
cumulativeInputTokens: totals.inputTokens,
|
|
222
|
+
cumulativeOutputTokens: totals.outputTokens,
|
|
223
|
+
cumulativeThinkingTokens: totals.thinkingTokens,
|
|
224
|
+
filesRead: state.filesReadSet.size,
|
|
225
|
+
...(rescue.billed ?? {}),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../../src/tools/agentic/results.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAuB,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAmBlE,8GAA8G;AAC9G,SAAS,YAAY,CACnB,GAAe,EACf,KAAgB,EAChB,MAAoB,EACpB,MAAoB;IAEpB,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC;IACzB,OAAO;QACL,aAAa,EAAE,QAAQ,CAAC,QAAQ;QAChC,cAAc,EAAE,QAAQ,CAAC,SAAS;QAClC,eAAe,EAAE,QAAQ,CAAC,eAAe;QACzC,aAAa,EAAE,QAAQ,CAAC,QAAQ;QAChC,aAAa,EAAE,QAAQ,CAAC,eAAe;QACvC,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,qBAAqB,EAAE,MAAM,CAAC,WAAW;QACzC,sBAAsB,EAAE,MAAM,CAAC,YAAY;QAC3C,wBAAwB,EAAE,MAAM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AC3E,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,IAAI;YACzB,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE;YAC9E,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,MAAM,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,qBAAqB,EAAE,MAAM,CAAC,WAAW;QACzC,sBAAsB,EAAE,MAAM,CAAC,YAAY;QAC3C,wBAAwB,EAAE,MAAM,CAAC,cAAc;QAC/C,SAAS,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI;QAClC,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;KACzB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed state of one `ask_agentic` call: what is fixed when the loop starts (`AgenticRun` — the model, the
|
|
3
|
+
* limits, the request config, the per-pass reservation inputs) and what the loop accumulates (`LoopState`).
|
|
4
|
+
*/
|
|
5
|
+
import type { Content, GenerateContentConfig } from '@google/genai';
|
|
6
|
+
import type { resolveModel } from '../../gemini/models.js';
|
|
7
|
+
import type { MatchConfig } from '../../indexer/globs.js';
|
|
8
|
+
import type { ProgressEmitter } from '../../utils/progress.js';
|
|
9
|
+
import type { ToolContext } from '../registry.js';
|
|
10
|
+
import type { BilledFields } from '../shared/call-ledger.js';
|
|
11
|
+
import type { AskAgenticInput } from './input.js';
|
|
12
|
+
import type { SignatureCounts } from './no-progress.js';
|
|
13
|
+
import type { AgenticKnobs } from './pass-clock.js';
|
|
14
|
+
import type { UsageCounts } from './response.js';
|
|
15
|
+
export type ResolvedModel = Awaited<ReturnType<typeof resolveModel>>;
|
|
16
|
+
export declare const DEFAULT_MAX_ITERATIONS = 20;
|
|
17
|
+
export declare const DEFAULT_MAX_TOTAL_INPUT_TOKENS = 1000000;
|
|
18
|
+
export declare const DEFAULT_MAX_FILES_READ = 40;
|
|
19
|
+
/**
|
|
20
|
+
* Conservative per-iteration input estimate for the pre-iteration
|
|
21
|
+
* budget reservation. An agentic iter typically sends a few KB of
|
|
22
|
+
* prompt + accumulated tool responses + model thinking + short output.
|
|
23
|
+
* We over-estimate on purpose so `reserveBudget` atomicity catches
|
|
24
|
+
* overspend early rather than silently racing past the cap. PR #24
|
|
25
|
+
* review by Grok (P0: budget bypass on agentic path).
|
|
26
|
+
*/
|
|
27
|
+
export declare const PER_ITERATION_INPUT_TOKENS = 50000;
|
|
28
|
+
/** The env var that bounds an iteration (and the finalization pass) when the call sets no `iterationTimeoutMs`. */
|
|
29
|
+
export declare const ITERATION_TIMEOUT_ENV = "GEMINI_CODE_CONTEXT_AGENTIC_ITERATION_TIMEOUT_MS";
|
|
30
|
+
/** The env var that bounds a stream's gaps when the call sets no `stallMs`. */
|
|
31
|
+
export declare const AGENTIC_STALL_ENV = "GEMINI_CODE_CONTEXT_AGENTIC_STALL_MS";
|
|
32
|
+
/** The names a timeout message gives the two knobs and their env vars: the caller's — `ask_agentic`'s or `ask`'s. */
|
|
33
|
+
export interface KnobNames {
|
|
34
|
+
readonly totalMs: string;
|
|
35
|
+
readonly totalEnv: string;
|
|
36
|
+
readonly stallMs: string;
|
|
37
|
+
readonly stallEnv: string;
|
|
38
|
+
}
|
|
39
|
+
/** The knobs of a direct `ask_agentic` call. */
|
|
40
|
+
export declare const AGENTIC_KNOB_NAMES: KnobNames;
|
|
41
|
+
/** Where a knob that is set came from: the call's own field, or its env var. */
|
|
42
|
+
export type KnobOrigin = 'call' | 'env';
|
|
43
|
+
/** The call's knobs as resolved, with the origin of each one (`null` when it is unset). */
|
|
44
|
+
export interface ResolvedKnobs extends AgenticKnobs {
|
|
45
|
+
readonly iterationFrom: KnobOrigin | null;
|
|
46
|
+
readonly stallFrom: KnobOrigin | null;
|
|
47
|
+
}
|
|
48
|
+
/** The call's knobs, resolved once: per call, else the env var, clamped as every timeout knob is. */
|
|
49
|
+
export declare function resolveAgenticKnobs(input: AskAgenticInput): ResolvedKnobs;
|
|
50
|
+
/**
|
|
51
|
+
* The knob names a call's timeout messages give: the caller's, except that a knob its env var set is named by that
|
|
52
|
+
* env var — the agentic one. On `ask`'s fallback, `ask` forwards its own knobs per call; where it set none of a kind,
|
|
53
|
+
* the agentic env var of that kind bounds the loop, and the message names it, never an `ask` variable that set nothing.
|
|
54
|
+
*/
|
|
55
|
+
export declare function messageKnobNames(names: KnobNames, knobs: ResolvedKnobs): KnobNames;
|
|
56
|
+
export interface RunLimits {
|
|
57
|
+
maxIterations: number;
|
|
58
|
+
maxTotalInputTokens: number;
|
|
59
|
+
maxFilesRead: number;
|
|
60
|
+
}
|
|
61
|
+
/** What every pass's reservation is priced from, beside the resolved model. */
|
|
62
|
+
export interface PassBudget {
|
|
63
|
+
/** Output (and thinking) tokens a pass reserves for. */
|
|
64
|
+
outputTokens: number;
|
|
65
|
+
/** The longest an iteration (or the finalization pass) can run: the window each reservation covers. */
|
|
66
|
+
coverMs: number | null;
|
|
67
|
+
dailyBudgetEnforced: boolean;
|
|
68
|
+
tpmEnforced: boolean;
|
|
69
|
+
}
|
|
70
|
+
/** One call, fixed once the loop starts. */
|
|
71
|
+
export interface AgenticRun {
|
|
72
|
+
input: AskAgenticInput;
|
|
73
|
+
ctx: ToolContext;
|
|
74
|
+
emitter: ProgressEmitter;
|
|
75
|
+
resolved: ResolvedModel;
|
|
76
|
+
/** Canonical (symlink-resolved) workspace root every tool call resolves against. */
|
|
77
|
+
workspaceRoot: string;
|
|
78
|
+
/** When the call started (`Date.now()`), for `durationMs`. */
|
|
79
|
+
started: number;
|
|
80
|
+
limits: RunLimits;
|
|
81
|
+
/** The user-glob filter, threaded through every executor invocation in the loop. */
|
|
82
|
+
matchConfig: MatchConfig;
|
|
83
|
+
baseConfig: GenerateContentConfig;
|
|
84
|
+
budget: PassBudget;
|
|
85
|
+
/** The knobs every pass's clock is built from, with their origins. */
|
|
86
|
+
knobs: ResolvedKnobs;
|
|
87
|
+
/** The knob names a timeout message gives (`messageKnobNames`): `ask`'s when the call is its fallback. */
|
|
88
|
+
knobNames: KnobNames;
|
|
89
|
+
}
|
|
90
|
+
/** What the loop accumulates across iterations. */
|
|
91
|
+
export interface LoopState {
|
|
92
|
+
conversation: Content[];
|
|
93
|
+
signatureCounts: SignatureCounts;
|
|
94
|
+
filesReadSet: Set<string>;
|
|
95
|
+
cumulativeInputTokens: number;
|
|
96
|
+
cumulativeOutputTokens: number;
|
|
97
|
+
cumulativeThinkingTokens: number;
|
|
98
|
+
/** P5 (v1.15.0): approximate token count of the tool-response Parts
|
|
99
|
+
* appended to `conversation` after the most recent iteration's
|
|
100
|
+
* `generateContent` returned. Folded into the rescue's
|
|
101
|
+
* `finalizationEstimate` so its TPM/budget reservation covers the data
|
|
102
|
+
* the rescue actually replays. Pre-P5 the estimate omitted this delta;
|
|
103
|
+
* with the parallel tool-dispatch (default 10 in v1.15.1+, was 3
|
|
104
|
+
* pre-bump) reading large files, the rescue could under-reserve by
|
|
105
|
+
* 100k+ tokens and 429 mid-flight. */
|
|
106
|
+
lastToolResponseTokens: number;
|
|
107
|
+
iterations: number;
|
|
108
|
+
/** The most recent iteration's actual `promptTokenCount` (size of the
|
|
109
|
+
* conversation as sent in the LAST loop iter). Used by the v1.14.2
|
|
110
|
+
* forced-finalization rescue's reservation estimate — the rescue replays
|
|
111
|
+
* the same accumulated history, so its real prompt size ≈ this value, not
|
|
112
|
+
* the static `PER_ITERATION_INPUT_TOKENS = 50_000` that under-reserves by
|
|
113
|
+
* 4–6× on a 20-iter loop with file reads. Stays 0 if the loop never
|
|
114
|
+
* produced a usage record (defensive — falls back to the static estimate
|
|
115
|
+
* at the use site). */
|
|
116
|
+
lastIterationPromptTokens: number;
|
|
117
|
+
/** The billed fields of the iteration that was booked and then failed with an error the loop does not shape;
|
|
118
|
+
* the outer catch puts them in its error result. `null` while no such failure happened. */
|
|
119
|
+
failedPassBilled: BilledFields | null;
|
|
120
|
+
}
|
|
121
|
+
export declare function runLimitsOf(input: AskAgenticInput): RunLimits;
|
|
122
|
+
/** The config of every loop request. */
|
|
123
|
+
export declare function baseConfigOf(input: AskAgenticInput): GenerateContentConfig;
|
|
124
|
+
export declare function passBudgetOf(input: AskAgenticInput, ctx: ToolContext, knobs: AgenticKnobs): PassBudget;
|
|
125
|
+
/** The tokens one pass is reserved for: its input estimate, and `budget.outputTokens` of output and of thinking. */
|
|
126
|
+
export declare function passReservedUsage(run: AgenticRun, inputTokens: number): UsageCounts;
|
|
127
|
+
/** One pass's reservation for the resolved model, at the rates in force from now until its timeout. */
|
|
128
|
+
export declare function passReservationUsd(run: AgenticRun, inputTokens: number): number;
|
|
129
|
+
export declare function newLoopState(prompt: string): LoopState;
|
|
130
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/run.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,qBAAqB,EAAkB,MAAM,eAAe,CAAC;AACpF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE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YAAY,GAAG,IAAI,CAAC;CACvC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,CAM7D;AAUD,wCAAwC;AACxC,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,qBAAqB,CAU1E;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,YAAY,GAClB,UAAU,CAOZ;AAED,oHAAoH;AACpH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,WAAW,CAMnF;AAED,uGAAuG;AACvG,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAY/E;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAatD"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed state of one `ask_agentic` call: what is fixed when the loop starts (`AgenticRun` — the model, the
|
|
3
|
+
* limits, the request config, the per-pass reservation inputs) and what the loop accumulates (`LoopState`).
|
|
4
|
+
*/
|
|
5
|
+
import { estimateReservationUsd } from '../../utils/cost-estimator.js';
|
|
6
|
+
import { resolveStallTimeoutMs, resolveTotalTimeoutMs } from '../shared/abort-timeout.js';
|
|
7
|
+
import { levelThinkingConfig } from '../shared/thinking.js';
|
|
8
|
+
import { SYSTEM_INSTRUCTION_AGENTIC, buildFunctionDeclarations } from './instructions.js';
|
|
9
|
+
export const DEFAULT_MAX_ITERATIONS = 20;
|
|
10
|
+
export const DEFAULT_MAX_TOTAL_INPUT_TOKENS = 1_000_000;
|
|
11
|
+
export const DEFAULT_MAX_FILES_READ = 40;
|
|
12
|
+
/**
|
|
13
|
+
* Conservative per-iteration input estimate for the pre-iteration
|
|
14
|
+
* budget reservation. An agentic iter typically sends a few KB of
|
|
15
|
+
* prompt + accumulated tool responses + model thinking + short output.
|
|
16
|
+
* We over-estimate on purpose so `reserveBudget` atomicity catches
|
|
17
|
+
* overspend early rather than silently racing past the cap. PR #24
|
|
18
|
+
* review by Grok (P0: budget bypass on agentic path).
|
|
19
|
+
*/
|
|
20
|
+
export const PER_ITERATION_INPUT_TOKENS = 50_000;
|
|
21
|
+
/** The env var that bounds an iteration (and the finalization pass) when the call sets no `iterationTimeoutMs`. */
|
|
22
|
+
export const ITERATION_TIMEOUT_ENV = 'GEMINI_CODE_CONTEXT_AGENTIC_ITERATION_TIMEOUT_MS';
|
|
23
|
+
/** The env var that bounds a stream's gaps when the call sets no `stallMs`. */
|
|
24
|
+
export const AGENTIC_STALL_ENV = 'GEMINI_CODE_CONTEXT_AGENTIC_STALL_MS';
|
|
25
|
+
/** The knobs of a direct `ask_agentic` call. */
|
|
26
|
+
export const AGENTIC_KNOB_NAMES = Object.freeze({
|
|
27
|
+
totalMs: 'iterationTimeoutMs',
|
|
28
|
+
totalEnv: ITERATION_TIMEOUT_ENV,
|
|
29
|
+
stallMs: 'stallMs',
|
|
30
|
+
stallEnv: AGENTIC_STALL_ENV,
|
|
31
|
+
});
|
|
32
|
+
const originOf = (ms, perCall) => {
|
|
33
|
+
if (ms === null)
|
|
34
|
+
return null;
|
|
35
|
+
return perCall !== undefined ? 'call' : 'env';
|
|
36
|
+
};
|
|
37
|
+
/** The call's knobs, resolved once: per call, else the env var, clamped as every timeout knob is. */
|
|
38
|
+
export function resolveAgenticKnobs(input) {
|
|
39
|
+
const iterationMs = resolveTotalTimeoutMs(input.iterationTimeoutMs, ITERATION_TIMEOUT_ENV);
|
|
40
|
+
const stallMs = resolveStallTimeoutMs(input.stallMs, AGENTIC_STALL_ENV);
|
|
41
|
+
return {
|
|
42
|
+
iterationMs,
|
|
43
|
+
stallMs,
|
|
44
|
+
iterationFrom: originOf(iterationMs, input.iterationTimeoutMs),
|
|
45
|
+
stallFrom: originOf(stallMs, input.stallMs),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The knob names a call's timeout messages give: the caller's, except that a knob its env var set is named by that
|
|
50
|
+
* env var — the agentic one. On `ask`'s fallback, `ask` forwards its own knobs per call; where it set none of a kind,
|
|
51
|
+
* the agentic env var of that kind bounds the loop, and the message names it, never an `ask` variable that set nothing.
|
|
52
|
+
*/
|
|
53
|
+
export function messageKnobNames(names, knobs) {
|
|
54
|
+
return {
|
|
55
|
+
...names,
|
|
56
|
+
...(knobs.iterationFrom === 'env' ? { totalEnv: ITERATION_TIMEOUT_ENV } : {}),
|
|
57
|
+
...(knobs.stallFrom === 'env' ? { stallEnv: AGENTIC_STALL_ENV } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function runLimitsOf(input) {
|
|
61
|
+
return {
|
|
62
|
+
maxIterations: input.maxIterations ?? DEFAULT_MAX_ITERATIONS,
|
|
63
|
+
maxTotalInputTokens: input.maxTotalInputTokens ?? DEFAULT_MAX_TOTAL_INPUT_TOKENS,
|
|
64
|
+
maxFilesRead: input.maxFilesRead ?? DEFAULT_MAX_FILES_READ,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function thinkingConfigOf(input) {
|
|
68
|
+
if (input.thinkingLevel !== undefined)
|
|
69
|
+
return levelThinkingConfig(input.thinkingLevel);
|
|
70
|
+
if (input.thinkingBudget !== undefined) {
|
|
71
|
+
return { thinkingBudget: input.thinkingBudget, includeThoughts: true };
|
|
72
|
+
}
|
|
73
|
+
return { includeThoughts: true };
|
|
74
|
+
}
|
|
75
|
+
/** The config of every loop request. */
|
|
76
|
+
export function baseConfigOf(input) {
|
|
77
|
+
return {
|
|
78
|
+
systemInstruction: SYSTEM_INSTRUCTION_AGENTIC,
|
|
79
|
+
tools: [{ functionDeclarations: buildFunctionDeclarations() }],
|
|
80
|
+
thinkingConfig: thinkingConfigOf(input),
|
|
81
|
+
...(input.maxOutputTokens !== undefined ? { maxOutputTokens: input.maxOutputTokens } : {}),
|
|
82
|
+
// One request per model call: a response that stops with `CONTINUATION` is never continued here (long decode
|
|
83
|
+
// is `ask` / `code` only, `shared/continuation.ts`).
|
|
84
|
+
automaticContinuation: false,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function passBudgetOf(input, ctx, knobs) {
|
|
88
|
+
return {
|
|
89
|
+
outputTokens: typeof input.maxOutputTokens === 'number' ? input.maxOutputTokens : 4096,
|
|
90
|
+
coverMs: knobs.iterationMs,
|
|
91
|
+
dailyBudgetEnforced: Number.isFinite(ctx.config.dailyBudgetUsd),
|
|
92
|
+
tpmEnforced: ctx.config.tpmThrottleLimit > 0,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** The tokens one pass is reserved for: its input estimate, and `budget.outputTokens` of output and of thinking. */
|
|
96
|
+
export function passReservedUsage(run, inputTokens) {
|
|
97
|
+
return {
|
|
98
|
+
promptTokenCount: inputTokens,
|
|
99
|
+
candidatesTokenCount: run.budget.outputTokens,
|
|
100
|
+
thoughtsTokenCount: run.budget.outputTokens,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** One pass's reservation for the resolved model, at the rates in force from now until its timeout. */
|
|
104
|
+
export function passReservationUsd(run, inputTokens) {
|
|
105
|
+
const reserved = passReservedUsage(run, inputTokens);
|
|
106
|
+
return estimateReservationUsd({
|
|
107
|
+
model: run.resolved.resolved,
|
|
108
|
+
uncachedInputTokens: reserved.promptTokenCount,
|
|
109
|
+
cachedInputTokens: 0,
|
|
110
|
+
outputTokens: reserved.candidatesTokenCount,
|
|
111
|
+
thinkingTokens: reserved.thoughtsTokenCount,
|
|
112
|
+
}, run.budget.coverMs);
|
|
113
|
+
}
|
|
114
|
+
export function newLoopState(prompt) {
|
|
115
|
+
return {
|
|
116
|
+
conversation: [{ role: 'user', parts: [{ text: prompt }] }],
|
|
117
|
+
signatureCounts: new Map(),
|
|
118
|
+
filesReadSet: new Set(),
|
|
119
|
+
cumulativeInputTokens: 0,
|
|
120
|
+
cumulativeOutputTokens: 0,
|
|
121
|
+
cumulativeThinkingTokens: 0,
|
|
122
|
+
lastToolResponseTokens: 0,
|
|
123
|
+
iterations: 0,
|
|
124
|
+
lastIterationPromptTokens: 0,
|
|
125
|
+
failedPassBilled: null,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/tools/agentic/run.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAGvE,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAE1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAO1F,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,8BAA8B,GAAG,SAAS,CAAC;AACxD,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAEjD,mHAAmH;AACnH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kDAAkD,CAAC;AACxF,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,sCAAsC,CAAC;AAUxE,gDAAgD;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAc,MAAM,CAAC,MAAM,CAAC;IACzD,OAAO,EAAE,oBAAoB;IAC7B,QAAQ,EAAE,qBAAqB;IAC/B,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC,CAAC;AAWH,MAAM,QAAQ,GAAG,CAAC,EAAiB,EAAE,OAA2B,EAAqB,EAAE;IACrF,IAAI,EAAE,KAAK,IAAI;QAAE,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CAAC,YAAY;QAC7C,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,YAAY;KAC5C,CAAC;AACJ,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,kBAAkB,CAAC,GAAe,EAAE,WAAmB;IACrE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACrD,OAAO,sBAAsB,CAC3B;QACE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ;QAC5B,mBAAmB,EAAE,QAAQ,CAAC,gBAAgB;QAC9C,iBAAiB,EAAE,CAAC;QACpB,YAAY,EAAE,QAAQ,CAAC,oBAAoB;QAC3C,cAAc,EAAE,QAAQ,CAAC,kBAAkB;KAC5C,EACD,GAAG,CAAC,MAAM,CAAC,OAAO,CACnB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO;QACL,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;QAC3D,eAAe,EAAE,IAAI,GAAG,EAAE;QAC1B,YAAY,EAAE,IAAI,GAAG,EAAU;QAC/B,qBAAqB,EAAE,CAAC;QACxB,sBAAsB,EAAE,CAAC;QACzB,wBAAwB,EAAE,CAAC;QAC3B,sBAAsB,EAAE,CAAC;QACzB,UAAU,EAAE,CAAC;QACb,yBAAyB,EAAE,CAAC;QAC5B,gBAAgB,EAAE,IAAI;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -21,20 +21,28 @@
|
|
|
21
21
|
* unsafe. This module implements `realpath + root jail` per that feedback.
|
|
22
22
|
*/
|
|
23
23
|
import { type PathKind } from '../../indexer/globs.js';
|
|
24
|
+
/** Which list of the secret denylist a file name is on: its exact basename, or its extension. */
|
|
25
|
+
export type SecretList = 'basename' | 'extension';
|
|
26
|
+
/**
|
|
27
|
+
* The list of the secret denylist `fileName` (a basename) is on, case-insensitively, or `null` when it is on neither.
|
|
28
|
+
* The one test of the denylist: `read_file` refuses such a file (`resolveInsideWorkspace`), `list_directory` hides it,
|
|
29
|
+
* and the walk of `find_files` and `grep` never visits it — its name, size and content stay out of every response.
|
|
30
|
+
*/
|
|
31
|
+
export declare function secretListOf(fileName: string): SecretList | null;
|
|
24
32
|
/**
|
|
25
33
|
* Where each code fires (v1.9.0 — keep this map current as new throw sites
|
|
26
34
|
* are added):
|
|
27
35
|
*
|
|
28
36
|
* PATH_TRAVERSAL — sandbox.ts (jail violation: symlink escape, abs path outside)
|
|
29
37
|
* SECRET_DENYLIST — sandbox.ts (basename / extension / dir on hardcoded secret list)
|
|
30
|
-
* EXCLUDED_DIR — sandbox.ts (DEFAULT_EXCLUDE_DIRS hit,
|
|
38
|
+
* EXCLUDED_DIR — sandbox.ts (DEFAULT_EXCLUDE_DIRS hit, excludedDirError)
|
|
31
39
|
* AND workspace-tools.ts top-level gates (v1.9.0+):
|
|
32
40
|
* listDirectoryExecutor + grepExecutor's pathPrefix,
|
|
33
41
|
* when the requested dir matches user-supplied excludeGlobs
|
|
34
42
|
* EXCLUDED_FILE — workspace-tools.ts (v1.9.0+): readFileExecutor when
|
|
35
43
|
* the file is excluded by user globs (filename / extension
|
|
36
44
|
* / dir-prefix). Generic message — no path leak.
|
|
37
|
-
* EXCLUDED_FILENAME — sandbox.ts (DEFAULT_EXCLUDE_FILE_NAMES hit,
|
|
45
|
+
* EXCLUDED_FILENAME — sandbox.ts (DEFAULT_EXCLUDE_FILE_NAMES hit, refuseDefaultExcluded)
|
|
38
46
|
* NON_SOURCE_FILE — workspace-tools.ts: readFileExecutor when no
|
|
39
47
|
* include-extension matches (path retained — different
|
|
40
48
|
* threat model from EXCLUDED_FILE)
|
|
@@ -73,6 +81,9 @@ export declare function resolveWorkspaceRoot(rootInput: string): Promise<string>
|
|
|
73
81
|
* attacker — indirect enumeration signal. Acceptable trade-off: the
|
|
74
82
|
* missing-file error for a valid path inside the root still surfaces as
|
|
75
83
|
* `NOT_FOUND` once the parent resolves.
|
|
84
|
+
*
|
|
85
|
+
* The steps run in this order and each refuses with its own code: the argument, the jail, the secret denylist (before
|
|
86
|
+
* the `stat` of the target), the default excludes.
|
|
76
87
|
*/
|
|
77
88
|
export declare function resolveInsideWorkspace(workspaceRoot: string, relOrAbs: string): Promise<ResolvedPath>;
|
|
78
89
|
/** A path inside the workspace, resolved: what it is decides whether it can be an excluded directory itself. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAGL,KAAK,QAAQ,EAId,MAAM,wBAAwB,CAAC;AAqDhC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,cAAc,GACd,eAAe,GACf,mBAAmB,GACnB,iBAAiB,GACjB,iBAAiB,GACjB,WAAW,GACX,iBAAiB,GACjB,eAAe,CAAC;AAuBpB,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,YAAY,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAKzE;CACF;AAED;;wCAEwC;AACxC,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU7E;
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAGL,KAAK,QAAQ,EAId,MAAM,wBAAwB,CAAC;AAqDhC,iGAAiG;AACjG,MAAM,MAAM,U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