@qmediat.io/gemini-code-context-mcp 1.24.0 → 1.25.0
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 +90 -1
- package/README.md +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 +131 -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-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 +142 -1615
- package/dist/tools/ask-agentic.tool.js.map +1 -1
- package/dist/tools/ask.tool.d.ts.map +1 -1
- package/dist/tools/ask.tool.js +29 -178
- package/dist/tools/ask.tool.js.map +1 -1
- package/dist/tools/code.tool.js +9 -20
- package/dist/tools/code.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/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/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/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/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,94 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.25.0] - 2026-11-17
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- `ask_agentic`: every phase of a pass now has a bound. A phase that could hang forever now ends with `TIMEOUT` after
|
|
15
|
+
its default: 600 s for each request's opening (until its first chunk; a request sent again after a network failure
|
|
16
|
+
gets the whole 600 s, and so does the backoff before it), 600 s for a stream that sends nothing (a `stall`), 120 s
|
|
17
|
+
without progress in an iteration's path resolution and tool batch — the executors report progress at every directory,
|
|
18
|
+
file and read, so a long healthy `grep` batch over a large workspace runs on — and 600 s for each request of the
|
|
19
|
+
forced-finalization pass (`rescueErrorCode: 'TIMEOUT'`). A default applies only where no knob bounds the phase:
|
|
20
|
+
`iterationTimeoutMs` (or `GEMINI_CODE_CONTEXT_AGENTIC_ITERATION_TIMEOUT_MS`) bounds every phase of an iteration,
|
|
21
|
+
`stallMs` (or `GEMINI_CODE_CONTEXT_AGENTIC_STALL_MS`) the gaps of a stream only. The TPM wait keeps the throttle's own
|
|
22
|
+
delay. Before, with neither knob set — and with only `stallMs` for everything but a stream's gaps — such a phase never
|
|
23
|
+
ended and held the pass's daily-budget and TPM reservations.
|
|
24
|
+
- `ask_agentic`: `iterationTimeoutMs` ends a tool batch at the bound, not when the batch returns; no queued tool call
|
|
25
|
+
starts once a bound fired, the executors get the abort signal, and a late result is dropped. A `TIMEOUT` is
|
|
26
|
+
`retryable: false` when tool calls still run 1 s after the bound (`toolCallsRunning` says how many).
|
|
27
|
+
- `ask`'s fallback to `ask_agentic` (`onWorkspaceTooLarge: 'fallback-to-agentic'`) forwards `stallMs` as the loop's
|
|
28
|
+
`stallMs`, no longer as a per-iteration wall clock: a healthy stream or a tool batch longer than `stallMs` answers.
|
|
29
|
+
With only `stallMs` set a pass has no wall clock — a stream that keeps sending ends at the model's output cap, a tool
|
|
30
|
+
batch that keeps reporting progress when its walk ends; a caller who wants a wall clock per iteration sets
|
|
31
|
+
`iterationTimeoutMs` (`timeoutMs` on `ask`).
|
|
32
|
+
`timeoutMs` still becomes `iterationTimeoutMs`. `iterTimeoutSource` is now always `'timeoutMs'` (the values
|
|
33
|
+
`'stallMs'` and `'min(timeoutMs,stallMs)'` are gone), and the result reports the forwarded `stallMs`.
|
|
34
|
+
- `ask_agentic`'s timeout messages no longer say "default disabled"; a bound that fired at its default names the
|
|
35
|
+
default and the knob that sets it.
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- `ask_agentic`: a `TIMEOUT` result carries `timeoutPhase` (`tpm-wait`, `opening`, `stream`, `tools`) and
|
|
40
|
+
`timeoutSource` (`iterationTimeoutMs`, `stallMs`, `default`, or `external` — a timeout the SDK raised itself: the
|
|
41
|
+
message quotes it and names no bound of the call); `timeoutKind` keeps its two values (`stall` is a stream's gap
|
|
42
|
+
only). The forced-finalization pass's `AGENTIC_MAX_ITERATIONS` with `rescueErrorCode: 'TIMEOUT'` carries
|
|
43
|
+
`timeoutPhase` (`tpm-wait`, `finalization`) and `timeoutSource` too, and its message names the knob that raises the
|
|
44
|
+
bound. `ask`'s fallback lifts both to the top of its result, beside `timeoutKind`.
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- `ask_agentic`: a tool batch longer than `stallMs` no longer ends the call as a false `stall`; the stall watchdog
|
|
49
|
+
watches the stream only.
|
|
50
|
+
- `ask_agentic`: a tool batch, or a path resolution at the `maxFilesRead` cap, that never returns no longer hangs the
|
|
51
|
+
call: it ends at `iterationTimeoutMs`, else after 120 s without progress, with the pass booked.
|
|
52
|
+
- `ask`'s fallback to `ask_agentic` uses `ask`'s knobs as `ask` resolved them — per call, else
|
|
53
|
+
`GEMINI_CODE_CONTEXT_ASK_TIMEOUT_MS` / `GEMINI_CODE_CONTEXT_ASK_STALL_MS` (the env vars were ignored) — stops `ask`'s
|
|
54
|
+
own timer at the hand-off, and its timeout messages name `timeoutMs` / `stallMs`, not `iterationTimeoutMs`. Where
|
|
55
|
+
`ask` set no knob of a kind, `GEMINI_CODE_CONTEXT_AGENTIC_ITERATION_TIMEOUT_MS` / `_STALL_MS` still bound the loop,
|
|
56
|
+
and the message names that variable, not an `ask` one that set nothing.
|
|
57
|
+
- `ask_agentic`: a 429 on a loop iteration seeds the throttle's retry hint once, not twice. `ask`, `code` and
|
|
58
|
+
`ask_agentic` seed the hint through one function, once per error.
|
|
59
|
+
- `ask_agentic`: a loop iteration whose response carries no `usageMetadata` is booked and released at its estimate
|
|
60
|
+
(50,000 input tokens), as the forced-finalization pass already was: it used to book 0 USD against the daily budget
|
|
61
|
+
and release its TPM reservation at 0 tokens, so later calls were throttled as if it had sent nothing.
|
|
62
|
+
- `ask_agentic` without a daily budget (`GEMINI_DAILY_BUDGET_USD` unset) writes a usage row for each pass that
|
|
63
|
+
reached the model, as `ask` and `code` do: `status` (`spentTodayUsd`) counted none of its spend.
|
|
64
|
+
- `ask_agentic`: a loop iteration whose model call completed and which then failed — a timeout in its tool batch, a
|
|
65
|
+
response that could not be read — is booked at what it billed; it used to book nothing against the daily budget.
|
|
66
|
+
The error result of a pass booked before it failed (the loop iteration's `TIMEOUT` or `UNKNOWN`, the forced pass's
|
|
67
|
+
`AGENTIC_MAX_ITERATIONS`) carries that pass's `cachedTokens`, `uncachedTokens`, `outputTokens`, `thinkingTokens`
|
|
68
|
+
and `costEstimateUsd`.
|
|
69
|
+
- `ask_agentic`: the message of an iteration `TIMEOUT` whose pass was booked says it is booked at the result's token
|
|
70
|
+
and cost fields; it used to say the request was booked 0 beside those fields.
|
|
71
|
+
- `ask_agentic`: a pass whose usage could not be read (the read threw after its model call completed) is booked at
|
|
72
|
+
its whole reservation — the input estimate plus the reserved output and thinking tokens; it used to be booked at
|
|
73
|
+
the input estimate alone.
|
|
74
|
+
- Docs and timeout messages: whether Google bills a request aborted after its stream opened is not measured; the server
|
|
75
|
+
books it 0, so for such a request the daily budget and the TPM window are not a bound. `docs/cost-model.md` names
|
|
76
|
+
this and the `ask_agentic` iteration's fixed 50,000-token estimate (*What the daily budget does not bound*); the
|
|
77
|
+
phrases "true upper bound" / "true cap" are gone.
|
|
78
|
+
- `ask` and `code`: an answer whose usage row cannot be written (a busy or failing database) is returned, and the
|
|
79
|
+
failed write is logged; the paid answer used to be lost behind an error.
|
|
80
|
+
|
|
81
|
+
### Security
|
|
82
|
+
|
|
83
|
+
- `ask_agentic`: `list_directory`, `find_files` and `grep` no longer show a file on the secret denylist that `read_file`
|
|
84
|
+
refuses — a basename such as `.env`, `.env.local`, `credentials.json`, `secrets.yaml` or `service-account.json`, or a
|
|
85
|
+
name ending in `.pem`, `.key` or another secret extension, in any case. Before, since these tools shipped with
|
|
86
|
+
`ask_agentic`, `list_directory` listed such files with their sizes, `find_files` listed those its source rules admit
|
|
87
|
+
(`credentials.json`, `secrets.json`, `secrets.yaml`, …), and `grep` returned their matching lines. The three tools and
|
|
88
|
+
`read_file` now read one denylist.
|
|
89
|
+
|
|
90
|
+
### Notes
|
|
91
|
+
|
|
92
|
+
- Minor release. `errorCode`, `timeoutKind` and every result field that existed keep their values and meaning. What an
|
|
93
|
+
existing caller can observe: an `ask_agentic` call that hung with no knob set now ends with `TIMEOUT` at a default; a
|
|
94
|
+
`TIMEOUT` can be `retryable: false` (tool calls of the iteration still run); on `ask`'s fallback `stallMs` no longer
|
|
95
|
+
ends a healthy iteration, and `iterTimeoutSource` no longer takes the values `'stallMs'` and
|
|
96
|
+
`'min(timeoutMs,stallMs)'`; `list_directory`, `find_files` and `grep` no longer show a file on the secret denylist.
|
|
97
|
+
|
|
10
98
|
## [1.24.0] - 2026-11-17
|
|
11
99
|
|
|
12
100
|
### Added
|
|
@@ -1868,7 +1956,8 @@ Integration-test-surfaced and review-surfaced fixes landed before the v1.0.0 rel
|
|
|
1868
1956
|
- MIME type simplified to `text/plain` for all files.
|
|
1869
1957
|
- Unit test coverage gaps for cache-manager / files-uploader / ttl-watcher / profile-loader / parseEdits tracked in [`docs/FOLLOW-UP-PRS.md`](docs/FOLLOW-UP-PRS.md).
|
|
1870
1958
|
|
|
1871
|
-
[Unreleased]: https://github.com/qmediat/gemini-code-context-mcp/compare/v1.
|
|
1959
|
+
[Unreleased]: https://github.com/qmediat/gemini-code-context-mcp/compare/v1.25.0...HEAD
|
|
1960
|
+
[1.25.0]: https://github.com/qmediat/gemini-code-context-mcp/compare/v1.24.0...v1.25.0
|
|
1872
1961
|
[1.24.0]: https://github.com/qmediat/gemini-code-context-mcp/compare/v1.23.1...v1.24.0
|
|
1873
1962
|
[1.23.1]: https://github.com/qmediat/gemini-code-context-mcp/compare/v1.23.0...v1.23.1
|
|
1874
1963
|
[1.23.0]: https://github.com/qmediat/gemini-code-context-mcp/compare/v1.22.1...v1.23.0
|
package/README.md
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool executor dispatcher — takes a FunctionCall, routes to the right
|
|
3
|
+
* executor, maps `SandboxError` → `response.error` (recoverable signal), and
|
|
4
|
+
* runs one iteration's calls in parallel under the concurrency cap. Every
|
|
5
|
+
* executor gets the pass's watch (its abort signal, its progress report); once
|
|
6
|
+
* the signal fired, no queued call starts.
|
|
7
|
+
*/
|
|
8
|
+
import type { MatchConfig } from '../../indexer/globs.js';
|
|
9
|
+
import { type ToolWatch } from './workspace-tools.js';
|
|
10
|
+
/** Read + clamp the tool-execution concurrency at dispatch time.
|
|
11
|
+
*
|
|
12
|
+
* Why a function not a top-level const: env vars can change between calls
|
|
13
|
+
* within a long-lived MCP-server process (operator ctrl-Cs and re-launches
|
|
14
|
+
* with a different value mid-session). Resolving per-call keeps behaviour
|
|
15
|
+
* predictable. Cost: one env-read per iter; negligible vs the
|
|
16
|
+
* `generateContent` round-trip dominating wall-clock.
|
|
17
|
+
*
|
|
18
|
+
* Clamps numeric inputs to `[1, 50]`. Only NaN / unset / empty falls back
|
|
19
|
+
* to default. 50 cap prevents pathological "concurrency: 99999" misconfig
|
|
20
|
+
* from spawning ~unbounded `read_file` Promise chains. 0 / negative inputs
|
|
21
|
+
* clamp UP to 1 (= serial dispatch) — operators setting `0` or `-3` mean
|
|
22
|
+
* "minimise parallelism", not "use the default" (the v1.15.1 PR-Round-1
|
|
23
|
+
* 2-of-2 cross-reviewer correction: gemini-cli F2 + grok F1 flagged that
|
|
24
|
+
* silently mapping operator-supplied `0` back to 10× was the opposite of
|
|
25
|
+
* intent and a confusing UX on resource-constrained CI / Windows hosts).
|
|
26
|
+
*
|
|
27
|
+
* Exported for unit testing — not part of the public MCP surface. */
|
|
28
|
+
export declare function resolveToolExecutionConcurrency(): number;
|
|
29
|
+
/** One function call as the model issued it. */
|
|
30
|
+
export interface ToolCall {
|
|
31
|
+
name: string;
|
|
32
|
+
args: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
export interface DispatchedToolResult {
|
|
35
|
+
name: string;
|
|
36
|
+
/** What the model receives as the call's `functionResponse.response`: the executor's answer, or `{ error }`. */
|
|
37
|
+
response: Record<string, unknown>;
|
|
38
|
+
/** `true` when the call failed (an unknown tool, or an executor that threw): a failed `read_file` is never
|
|
39
|
+
* recorded as a file read (`recordRead`). */
|
|
40
|
+
isError: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Run one function call. SandboxError and anything else that happens in the
|
|
44
|
+
* executor surfaces as recoverable `response.error` so the model can try a
|
|
45
|
+
* different path. Hard failures (e.g. filesystem I/O errors) follow the same
|
|
46
|
+
* path — the worst case is we waste one iteration. An unknown function name
|
|
47
|
+
* returns an error response rather than throwing: the model may recover by
|
|
48
|
+
* picking a valid tool.
|
|
49
|
+
*/
|
|
50
|
+
export declare function dispatchToolCall(workspaceRoot: string, name: string, args: Record<string, unknown>, matchConfig: MatchConfig, watch?: ToolWatch): Promise<DispatchedToolResult>;
|
|
51
|
+
/** One iteration's tool calls as they run. */
|
|
52
|
+
export interface ToolBatch {
|
|
53
|
+
/** Every worker finished: each call it took settled, and it takes no more. Holds each call's result by position; a
|
|
54
|
+
* call never started (the signal fired first) has none. */
|
|
55
|
+
readonly settled: Promise<DispatchedToolResult[]>;
|
|
56
|
+
/** The executors started and not yet settled. */
|
|
57
|
+
running(): number;
|
|
58
|
+
/** The calls no worker took. */
|
|
59
|
+
neverStarted(): number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Run up to `concurrency` dispatches in parallel, preserving call order. A worker takes the next call only while the
|
|
63
|
+
* watch's signal has not fired, so no queued call starts after it; a running executor gets the watch.
|
|
64
|
+
*/
|
|
65
|
+
export declare function startToolBatch(workspaceRoot: string, calls: readonly ToolCall[], concurrency: number, matchConfig: MatchConfig, watch: ToolWatch & {
|
|
66
|
+
readonly signal: AbortSignal;
|
|
67
|
+
}): ToolBatch;
|
|
68
|
+
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EACL,KAAK,SAAS,EAKf,MAAM,sBAAsB,CAAC;AAqB9B;;;;;;;;;;;;;;;;;qEAiBqE;AACrE,wBAAgB,+BAA+B,IAAI,MAAM,CAUxD;AAED,gDAAgD;AAChD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,gHAAgH;IAChH,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC;iDAC6C;IAC7C,OAAO,EAAE,OAAO,CAAC;CAClB;AAuFD;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,WAAW,EAAE,WAAW,EACxB,KAAK,CAAC,EAAE,SAAS,GAChB,OAAO,CAAC,oBAAoB,CAAC,CAqB/B;AAED,8CAA8C;AAC9C,MAAM,WAAW,SAAS;IACxB;+DAC2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAClD,iDAAiD;IACjD,OAAO,IAAI,MAAM,CAAC;IAClB,gCAAgC;IAChC,YAAY,IAAI,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,SAAS,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAClD,SAAS,CA+BX"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool executor dispatcher — takes a FunctionCall, routes to the right
|
|
3
|
+
* executor, maps `SandboxError` → `response.error` (recoverable signal), and
|
|
4
|
+
* runs one iteration's calls in parallel under the concurrency cap. Every
|
|
5
|
+
* executor gets the pass's watch (its abort signal, its progress report); once
|
|
6
|
+
* the signal fired, no queued call starts.
|
|
7
|
+
*/
|
|
8
|
+
import { logger, safeForLog } from '../../utils/logger.js';
|
|
9
|
+
import { SandboxError } from './sandbox.js';
|
|
10
|
+
import { findFilesExecutor, grepExecutor, listDirectoryExecutor, readFileExecutor, } from './workspace-tools.js';
|
|
11
|
+
/**
|
|
12
|
+
* Default cap on parallel tool-call dispatch within a single iteration.
|
|
13
|
+
*
|
|
14
|
+
* Bumped 3 → 10 in v1.15.1 (P9_a). Pre-bump rationale was "be conservative,
|
|
15
|
+
* avoid hammering local filesystem I/O." Empirical: today's `read_file` /
|
|
16
|
+
* `grep` / `find_files` run against the SQLite-backed manifest + workspace
|
|
17
|
+
* mmap, all of which are CPU-bound and parallelism-friendly. The 3-wide cap
|
|
18
|
+
* forced the model to serialise even small batches like 5 `read_file` calls
|
|
19
|
+
* into 2 round-trips of the iteration loop, eating ~30-60s of HIGH-thinking
|
|
20
|
+
* latency per artificial split. 10-wide handles the typical batch a Gemini
|
|
21
|
+
* 3 Pro response emits without queuing.
|
|
22
|
+
*
|
|
23
|
+
* Operators can override via `GEMINI_CODE_CONTEXT_AGENTIC_TOOL_CONCURRENCY`
|
|
24
|
+
* env var (clamped to [1, 50]) — kill switch for environments where
|
|
25
|
+
* filesystem contention or local I/O bandwidth makes wider concurrency
|
|
26
|
+
* counter-productive.
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_TOOL_EXECUTION_CONCURRENCY = 10;
|
|
29
|
+
/** Read + clamp the tool-execution concurrency at dispatch time.
|
|
30
|
+
*
|
|
31
|
+
* Why a function not a top-level const: env vars can change between calls
|
|
32
|
+
* within a long-lived MCP-server process (operator ctrl-Cs and re-launches
|
|
33
|
+
* with a different value mid-session). Resolving per-call keeps behaviour
|
|
34
|
+
* predictable. Cost: one env-read per iter; negligible vs the
|
|
35
|
+
* `generateContent` round-trip dominating wall-clock.
|
|
36
|
+
*
|
|
37
|
+
* Clamps numeric inputs to `[1, 50]`. Only NaN / unset / empty falls back
|
|
38
|
+
* to default. 50 cap prevents pathological "concurrency: 99999" misconfig
|
|
39
|
+
* from spawning ~unbounded `read_file` Promise chains. 0 / negative inputs
|
|
40
|
+
* clamp UP to 1 (= serial dispatch) — operators setting `0` or `-3` mean
|
|
41
|
+
* "minimise parallelism", not "use the default" (the v1.15.1 PR-Round-1
|
|
42
|
+
* 2-of-2 cross-reviewer correction: gemini-cli F2 + grok F1 flagged that
|
|
43
|
+
* silently mapping operator-supplied `0` back to 10× was the opposite of
|
|
44
|
+
* intent and a confusing UX on resource-constrained CI / Windows hosts).
|
|
45
|
+
*
|
|
46
|
+
* Exported for unit testing — not part of the public MCP surface. */
|
|
47
|
+
export function resolveToolExecutionConcurrency() {
|
|
48
|
+
const raw = process.env.GEMINI_CODE_CONTEXT_AGENTIC_TOOL_CONCURRENCY;
|
|
49
|
+
if (raw === undefined || raw === '')
|
|
50
|
+
return DEFAULT_TOOL_EXECUTION_CONCURRENCY;
|
|
51
|
+
const parsed = Number.parseInt(raw, 10);
|
|
52
|
+
// Only NaN (genuinely malformed input like `'banana'`) falls back to
|
|
53
|
+
// default. Numeric inputs always clamp into [1, 50] so the operator's
|
|
54
|
+
// stated intent (lower bound = serial; upper bound = throughput cap)
|
|
55
|
+
// is honoured for any value parseInt can extract a number from.
|
|
56
|
+
if (Number.isNaN(parsed))
|
|
57
|
+
return DEFAULT_TOOL_EXECUTION_CONCURRENCY;
|
|
58
|
+
return Math.max(1, Math.min(parsed, 50));
|
|
59
|
+
}
|
|
60
|
+
/** A line number the model sent, or `undefined` when it is not a finite number. */
|
|
61
|
+
const finiteLine = (value) => typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
62
|
+
const runListDirectory = async (workspaceRoot, args, matchConfig, watch) => {
|
|
63
|
+
const path = String(args.path ?? '.');
|
|
64
|
+
return (await listDirectoryExecutor(workspaceRoot, path, matchConfig, watch));
|
|
65
|
+
};
|
|
66
|
+
const runFindFiles = async (workspaceRoot, args, matchConfig, watch) => {
|
|
67
|
+
const pattern = String(args.pattern ?? '');
|
|
68
|
+
return (await findFilesExecutor(workspaceRoot, pattern, matchConfig, watch));
|
|
69
|
+
};
|
|
70
|
+
const runReadFile = async (workspaceRoot, args, matchConfig, watch) => {
|
|
71
|
+
const path = String(args.path ?? '');
|
|
72
|
+
const startLine = finiteLine(args.startLine);
|
|
73
|
+
const endLine = finiteLine(args.endLine);
|
|
74
|
+
return (await readFileExecutor(workspaceRoot, path, startLine, endLine, matchConfig, watch));
|
|
75
|
+
};
|
|
76
|
+
const runGrep = async (workspaceRoot, args, matchConfig, watch) => {
|
|
77
|
+
const pattern = String(args.pattern ?? '');
|
|
78
|
+
const pathPrefix = typeof args.pathPrefix === 'string' && args.pathPrefix.length > 0 ? args.pathPrefix : undefined;
|
|
79
|
+
return (await grepExecutor(workspaceRoot, pattern, pathPrefix, matchConfig, watch));
|
|
80
|
+
};
|
|
81
|
+
/** The executor of each tool the model may call, by its declared name. */
|
|
82
|
+
const EXECUTORS = new Map([
|
|
83
|
+
['list_directory', runListDirectory],
|
|
84
|
+
['find_files', runFindFiles],
|
|
85
|
+
['read_file', runReadFile],
|
|
86
|
+
['grep', runGrep],
|
|
87
|
+
]);
|
|
88
|
+
/** The recoverable `response.error` text of an executor failure. */
|
|
89
|
+
function failureMessage(err) {
|
|
90
|
+
if (err instanceof SandboxError)
|
|
91
|
+
return `${err.code}: ${err.message}`;
|
|
92
|
+
return err instanceof Error ? err.message : String(err);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A sandbox refusal is logged at debug level with the path the model asked for: the message the model
|
|
96
|
+
* gets for `EXCLUDED_FILE` / `EXCLUDED_DIR` is path-free (no existence oracle), so this line is how an
|
|
97
|
+
* operator maps it back to a path (`GEMINI_CODE_CONTEXT_LOG_LEVEL=debug`).
|
|
98
|
+
*/
|
|
99
|
+
function logSandboxRefusal(name, err) {
|
|
100
|
+
if (!(err instanceof SandboxError))
|
|
101
|
+
return;
|
|
102
|
+
logger.debug(`agentic dispatch refused: tool=${safeForLog(name)} code=${safeForLog(err.code)} requestedPath=${safeForLog(err.requestedPath)}`);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Run one function call. SandboxError and anything else that happens in the
|
|
106
|
+
* executor surfaces as recoverable `response.error` so the model can try a
|
|
107
|
+
* different path. Hard failures (e.g. filesystem I/O errors) follow the same
|
|
108
|
+
* path — the worst case is we waste one iteration. An unknown function name
|
|
109
|
+
* returns an error response rather than throwing: the model may recover by
|
|
110
|
+
* picking a valid tool.
|
|
111
|
+
*/
|
|
112
|
+
export async function dispatchToolCall(workspaceRoot, name, args, matchConfig, watch) {
|
|
113
|
+
try {
|
|
114
|
+
const executor = EXECUTORS.get(name);
|
|
115
|
+
if (executor === undefined) {
|
|
116
|
+
return {
|
|
117
|
+
name,
|
|
118
|
+
response: { error: `unknown tool: ${name}` },
|
|
119
|
+
isError: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const response = await executor(workspaceRoot, args, matchConfig, watch);
|
|
123
|
+
return { name, response, isError: false };
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
const message = failureMessage(err);
|
|
127
|
+
logSandboxRefusal(name, err);
|
|
128
|
+
return {
|
|
129
|
+
name,
|
|
130
|
+
response: { error: message },
|
|
131
|
+
isError: true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Run up to `concurrency` dispatches in parallel, preserving call order. A worker takes the next call only while the
|
|
137
|
+
* watch's signal has not fired, so no queued call starts after it; a running executor gets the watch.
|
|
138
|
+
*/
|
|
139
|
+
export function startToolBatch(workspaceRoot, calls, concurrency, matchConfig, watch) {
|
|
140
|
+
const { signal } = watch;
|
|
141
|
+
const results = new Array(calls.length);
|
|
142
|
+
let next = 0;
|
|
143
|
+
let running = 0;
|
|
144
|
+
const worker = async () => {
|
|
145
|
+
while (next < calls.length && !signal.aborted) {
|
|
146
|
+
const i = next;
|
|
147
|
+
next += 1;
|
|
148
|
+
const call = calls[i];
|
|
149
|
+
if (!call)
|
|
150
|
+
continue;
|
|
151
|
+
running += 1;
|
|
152
|
+
try {
|
|
153
|
+
results[i] = await dispatchToolCall(workspaceRoot, call.name, call.args, matchConfig, watch);
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
running -= 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const workers = Array.from({ length: Math.max(1, Math.min(concurrency, calls.length)) }, worker);
|
|
161
|
+
return {
|
|
162
|
+
settled: Promise.all(workers).then(() => results),
|
|
163
|
+
running: () => running,
|
|
164
|
+
neverStarted: () => calls.length - next,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../../src/tools/agentic/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAEL,iBAA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I,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACjG,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC;QACjD,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO;QACtB,YAAY,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The input of `ask_agentic`: its zod schema (what the MCP host sees as the tool's input schema) and the type the
|
|
3
|
+
* call reads it as.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export declare const askAgenticInputSchema: z.ZodObject<{
|
|
7
|
+
prompt: z.ZodString;
|
|
8
|
+
workspace: z.ZodOptional<z.ZodString>;
|
|
9
|
+
model: z.ZodOptional<z.ZodString>;
|
|
10
|
+
includeGlobs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
excludeGlobs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
12
|
+
thinkingBudget: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
thinkingLevel: z.ZodOptional<z.ZodEnum<{
|
|
14
|
+
HIGH: "HIGH";
|
|
15
|
+
LOW: "LOW";
|
|
16
|
+
MEDIUM: "MEDIUM";
|
|
17
|
+
MINIMAL: "MINIMAL";
|
|
18
|
+
XHIGH: "XHIGH";
|
|
19
|
+
}>>;
|
|
20
|
+
maxOutputTokens: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
maxIterations: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
maxTotalInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
maxFilesRead: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
iterationTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
stallMs: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export type AskAgenticInput = z.infer<typeof askAgenticInputSchema>;
|
|
28
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;iBA0E9B,CAAC;AAEL,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The input of `ask_agentic`: its zod schema (what the MCP host sees as the tool's input schema) and the type the
|
|
3
|
+
* call reads it as.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { PROMPT_FIELD, WORKSPACE_FIELD } from '../shared/question-fields.js';
|
|
7
|
+
import { THINKING_LEVEL_FIELD } from '../shared/thinking.js';
|
|
8
|
+
export const askAgenticInputSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
prompt: PROMPT_FIELD,
|
|
11
|
+
workspace: WORKSPACE_FIELD,
|
|
12
|
+
model: z
|
|
13
|
+
.string()
|
|
14
|
+
.optional()
|
|
15
|
+
.describe("Model alias ('latest-pro', 'latest-pro-thinking', 'latest-flash') or literal model ID. Defaults to the configured default (GEMINI_CODE_CONTEXT_DEFAULT_MODEL, then the credentials profile, then `latest-pro-thinking`)."),
|
|
16
|
+
includeGlobs: z
|
|
17
|
+
.array(z.string())
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('Additional file extensions or filenames to include. Honoured by the four agentic tools (`list_directory`, `find_files`, `read_file`, `grep`) — the model never sees paths outside these globs. Mirrors the `ask` / `code` semantics so callers (or `ask` → `ask_agentic` fallback in v1.9.0+) get consistent filtering.'),
|
|
20
|
+
excludeGlobs: z
|
|
21
|
+
.array(z.string())
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Additional patterns to exclude. Same three shapes as `ask` / `code`: (1) directory names or path prefixes (`node_modules`, `src/vendor`, `./dist/`, `.vercel/`), (2) literal filenames exact-match including bare dot-prefixed names (`pr27-diff.txt`, `foo.bar.baz`, `.env`, `.tsbuildinfo`), (3) extension globs that match via endsWith (`*.tsbuildinfo`, `*.map`). Bare dot-prefixed names like `.env` are treated as exact filename literals — write `*.env` for extension semantics. Paths are POSIX-normalised. Case-insensitive. No mid-string `*` / `**` / `?`. **Privacy-relevant:** when `ask` falls back to `ask_agentic` on `WORKSPACE_TOO_LARGE`, the user-supplied excludes here are honoured by every executor: `read_file` rejects with `EXCLUDED_FILE` (generic message — does NOT echo the excluded path, so the error string cannot be used as a path-existence oracle); `list_directory` and `grep` reject the requested directory / `pathPrefix` itself with `EXCLUDED_DIR` when it matches an exclude (top-level gate, not just child filtering); `find_files` skips the dir during walk; child entries inside an unexcluded parent are still hidden when they themselves match an exclude.'),
|
|
24
|
+
thinkingBudget: z.number().int().min(-1).max(65_536).optional(),
|
|
25
|
+
thinkingLevel: THINKING_LEVEL_FIELD,
|
|
26
|
+
maxOutputTokens: z.number().int().min(1).optional(),
|
|
27
|
+
maxIterations: z
|
|
28
|
+
.number()
|
|
29
|
+
.int()
|
|
30
|
+
.min(1)
|
|
31
|
+
.max(50)
|
|
32
|
+
.optional()
|
|
33
|
+
.describe("Hard cap on agentic LOOP iterations (each iteration = one Gemini generateContent + possible tool calls). Default 20. When the loop exhausts this cap without producing final-text, ONE additional non-tool `generateContent` (forced-finalization rescue) runs to synthesise an answer from gathered tool responses. **`structuredContent.apiCalls` is the authoritative total `generateContent` count** (loop iterations + 1 if the rescue dispatched, regardless of outcome). `convergenceForced: true` indicates ONLY that the rescue produced text successfully — an attempted-but-failed rescue increments `apiCalls` without setting `convergenceForced`. Rescue is bounded by `dailyBudgetUsd` and `iterationTimeoutMs`, else the finalization default (600 s per request); see `maxTotalInputTokens` for the cap-overshoot contract. **v1.15.0:** rescue-attempted-but-failed paths additionally surface `structuredContent.rescueErrorCode` (`'TIMEOUT' | 'RATE_LIMIT' | 'INTERNAL' | 'API_ERROR' | 'NETWORK' | 'EMPTY_TEXT'`) + `rescueErrorMessage` (truncated to 500 chars) so wrappers can branch retry behaviour without log scraping. Retry policy: TIMEOUT → raise iterationTimeoutMs; RATE_LIMIT → wait retry-hint window; INTERNAL → investigate code (don't retry blindly); API_ERROR → check status (don't retry 4xx); NETWORK → safe to retry; EMPTY_TEXT → narrow prompt."),
|
|
34
|
+
maxTotalInputTokens: z
|
|
35
|
+
.number()
|
|
36
|
+
.int()
|
|
37
|
+
.min(10_000)
|
|
38
|
+
.optional()
|
|
39
|
+
.describe("Cumulative input-token budget across all iterations. Default 1_000_000. Loop iterations HARD-STOP past this cap (subReason: 'AGENTIC_INPUT_BUDGET_EXCEEDED'). The post-loop forced-finalization rescue is NOT gated on this cap — it may push cumulative tokens past by one call's worth, signalled via `overBudget: true` on the result. Rescue cost remains bounded by `dailyBudgetUsd`; wall-clock by `iterationTimeoutMs`, else the finalization default (600 s per request)."),
|
|
40
|
+
maxFilesRead: z
|
|
41
|
+
.number()
|
|
42
|
+
.int()
|
|
43
|
+
.min(1)
|
|
44
|
+
.max(500)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe('Cap on distinct files opened via `read_file` during this agentic call. Default 40.'),
|
|
47
|
+
iterationTimeoutMs: z
|
|
48
|
+
.number()
|
|
49
|
+
.int()
|
|
50
|
+
.min(1_000)
|
|
51
|
+
.max(1_800_000)
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("Per-iteration wall-clock timeout in ms (1s–30min). Each agentic iteration (its TPM throttle wait, the request, its stream, the path resolution and the tool batch) is bounded by this: a tool batch is ended at this bound, not when it returns. **A single iteration that times out FAILS THE WHOLE agentic call** with `errorCode: 'TIMEOUT'` (the failed iteration's function-call results never came back, leaving the conversation structurally incomplete — continuing with partial state would 400 on the next turn); `timeoutPhase` says where it fired (`tpm-wait`, `opening`, `stream`, `tools`) and `timeoutSource` which bound (`iterationTimeoutMs`, `stallMs`, `default`, or `external` for a timeout no bound of the call raised). A TIMEOUT is `retryable: true` unless tool calls of the iteration still run after a 1 s grace (`retryable: false`, `toolCallsRunning`). The post-loop forced-finalization rescue pass is ALSO bounded by this timeout, but its timeout behaviour DIFFERS: rescue timeouts are caught best-effort and fall through to the original `subReason: 'AGENTIC_MAX_ITERATIONS'` shape with `errorCode: 'UNKNOWN'` (NOT `'TIMEOUT'`; `rescueErrorCode: 'TIMEOUT'`, `timeoutPhase` and `timeoutSource` say what fired) — the rescue is the documented exit path, and surfacing TIMEOUT for it would obscure the underlying maxIterations exhaustion. Operators detect rescue-attempted-but-failed via `apiCalls > iterations` and `convergenceForced` absent. Whole-loop budget is also bounded by `maxIterations` × `maxTotalInputTokens`. When omitted, falls back to env var `GEMINI_CODE_CONTEXT_AGENTIC_ITERATION_TIMEOUT_MS`; when neither is set, each phase has a default bound: 600 s for each request's opening (until its first chunk) and for each request of the forced-finalization pass, 120 s without progress in an iteration's path resolution and tool batch, and 600 s for a silent stream (a `stall`) unless `stallMs` is set."),
|
|
54
|
+
stallMs: z
|
|
55
|
+
.number()
|
|
56
|
+
.int()
|
|
57
|
+
.min(1_000)
|
|
58
|
+
.max(600_000)
|
|
59
|
+
.optional()
|
|
60
|
+
.describe('Per-iteration HEARTBEAT-AWARE stall watchdog in ms (1s–10min). Armed at a stream\'s first chunk and reset on every chunk yielded by `generateContentStream` (text or thought) — fires ONLY when the stream goes silent for this long. Does NOT fire while the model is actively thinking, and bounds neither a request\'s opening (before its first chunk) nor the tool batch: a batch longer than `stallMs` answers. Right knob for "kill dead sockets quickly without penalising deep reasoning." Recommended: `60_000` (60s). Falls back to env var `GEMINI_CODE_CONTEXT_AGENTIC_STALL_MS`; when neither it nor `iterationTimeoutMs` is set, a stream silent for 600 s is a stall. Returns `errorCode: "TIMEOUT"` with `timeoutKind: "stall"`, `timeoutPhase: "stream"` on abort. Independent of `iterationTimeoutMs` — both can be set; whichever fires first wins. **Loop iterations only — the post-loop forced-finalization rescue pass does not stream and has no stall watchdog.**'),
|
|
61
|
+
})
|
|
62
|
+
.refine((data) => !(data.thinkingBudget !== undefined && data.thinkingLevel !== undefined), {
|
|
63
|
+
message: 'Cannot specify both `thinkingBudget` and `thinkingLevel` — mutually exclusive (Gemini rejects).',
|
|
64
|
+
path: [],
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/tools/agentic/input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC;KACnC,MAAM,CAAC;IACN,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,eAAe;IAC1B,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,0NAA0N,CAC3N;IACH,YAAY,EAAE,CAAC;SACZ,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,yTAAyT,CAC1T;IACH,YAAY,EAAE,CAAC;SACZ,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,opCAAopC,CACrpC;IACH,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,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,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `ask_agentic` sends the model besides the conversation: the system instructions of the loop and of the
|
|
3
|
+
* forced-finalization pass, and the declarations of the four sandboxed tools the loop may call.
|
|
4
|
+
*/
|
|
5
|
+
import type { FunctionDeclaration } from '@google/genai';
|
|
6
|
+
export declare const SYSTEM_INSTRUCTION_AGENTIC: string;
|
|
7
|
+
/**
|
|
8
|
+
* Forced-finalization system instruction. Sent on the post-loop synthesis
|
|
9
|
+
* pass when the iteration budget is exhausted. Combined with
|
|
10
|
+
* `toolConfig.functionCallingConfig.mode = NONE`, the model is prohibited
|
|
11
|
+
* from emitting further function calls (per Gemini API spec, NONE mode is
|
|
12
|
+
* "equivalent to sending a request without any function declarations") and
|
|
13
|
+
* must answer with text using the conversation it has already accumulated.
|
|
14
|
+
*
|
|
15
|
+
* Tightened in v1.14.4 after empirical replay (2026-04-30) showed Gemini 3 Pro
|
|
16
|
+
* under HIGH thinking treating the previous "Synthesize the evidence ... in
|
|
17
|
+
* the format the user originally requested" wording as an invitation to
|
|
18
|
+
* narrate its thought process — producing stream-of-consciousness output
|
|
19
|
+
* instead of the structured findings the caller requested. The CRITICAL
|
|
20
|
+
* OUTPUT INSTRUCTIONS block below is authoritative ordering: parse the
|
|
21
|
+
* caller's format spec, synthesize evidence into it, no preamble, no narrative,
|
|
22
|
+
* no apologies. The user's original prompt (with any output-format directive)
|
|
23
|
+
* is preserved across the rescue via `contents[0]`, so the model has the
|
|
24
|
+
* format spec available — the system instruction's job is to enforce
|
|
25
|
+
* compliance.
|
|
26
|
+
*
|
|
27
|
+
* SAFETY: this rescue runs with `mode: NONE` (tools disabled) but still
|
|
28
|
+
* evaluates the FULL conversation history including any malicious payloads
|
|
29
|
+
* surfaced by prior `read_file` / `grep` results (LLM calls are stateless
|
|
30
|
+
* per Gemini API semantics — each turn's output is generated under THAT
|
|
31
|
+
* turn's systemInstruction). The shared `SYSTEM_INSTRUCTION_SAFETY_AGENTIC` block
|
|
32
|
+
* (data-vs-instruction firewall) is therefore prepended below. A 3-of-3
|
|
33
|
+
* cross-reviewer audit on 2026-04-30 (gemini-cli + gemini-chat + grok)
|
|
34
|
+
* flagged the prior absence as an indirect-prompt-injection vector.
|
|
35
|
+
*
|
|
36
|
+
* v1.15.0 (C2): citation directive conditionalised symmetrically with the
|
|
37
|
+
* "Unknown" handling — both gemini-chat (Round-2) and Copilot (Round-1)
|
|
38
|
+
* flagged the v1.14.4 unconditional `Cite specific file:line` as a
|
|
39
|
+
* potential format-break for strict JSON / fixed-shape outputs (e.g., a
|
|
40
|
+
* pure JSON array of strings can't carry `(file:42)` annotations without
|
|
41
|
+
* mutating the data). Now reads "ONLY where the requested format provides
|
|
42
|
+
* a compatible place to put citations".
|
|
43
|
+
*/
|
|
44
|
+
export declare const SYSTEM_INSTRUCTION_FINALIZATION: string;
|
|
45
|
+
export declare function buildFunctionDeclarations(): FunctionDeclaration[];
|
|
46
|
+
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/instructions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAU,MAAM,eAAe,CAAC;AAmBjE,eAAO,MAAM,0BAA0B,QA0B3B,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,+BAA+B,QAYhC,CAAC;AAqFb,wBAAgB,yBAAyB,IAAI,mBAAmB,EAAE,CAOjE"}
|