Skip to content

Commit 4e9cdcc

Browse files
Gustav-SimonssonTheGreatAxios
authored andcommitted
refactor(agent): deepen comment compression in the toolset cluster
1 parent cf0040e commit 4e9cdcc

5 files changed

Lines changed: 80 additions & 102 deletions

File tree

‎src/agent/tool-aliases.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe("grant aliases", () => {
9999
// todo/doing/done statuses, while manage_tasks spans the full lifecycle.
100100
// A stored update_plan grant never covers a manage_tasks request; live
101101
// requests are coerced before matching and seeders drop stored
102-
// update_plan keys, so that replay path is unreachable in production.
102+
// update_plan keys, so that replay path is unreachable.
103103
test("a stored update_plan grant does not cover manage_tasks", async () => {
104104
expect(
105105
await evaluateApprovals({

‎src/agent/tool-aliases.ts‎

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
/**
2-
* Advertised tool names are a projection of registry engine ids that depends
3-
* on the model family: each family sees exactly one name per tool, the one it
4-
* was trained on. Incoming calls accept every name any profile advertises, so
5-
* dispatch, grants, and history replay never depend on the active profile.
6-
*/
1+
// Advertised tool names are a projection of registry engine ids by model
2+
// family: each family sees exactly one name per tool, the one it was trained
3+
// on. Incoming calls accept every name any profile advertises, so dispatch,
4+
// grants, and history replay never depend on the active profile.
75

86
import { type } from "arktype";
97
import type { ToolCall, ToolDefinition } from "@intx/types/runtime";
@@ -51,10 +49,8 @@ const PATCH_FOLDED_ENGINES: ReadonlySet<string> = new Set([
5149
"delete_file",
5250
]);
5351

54-
/**
55-
* gpt models are trained on apply_patch, not write/edit/delete. Other
56-
* profiles and lists with no file-mutation tool pass through unchanged.
57-
*/
52+
/** gpt models are trained on apply_patch, not write/edit/delete. Other
53+
* profiles and lists without a file-mutation tool pass through unchanged. */
5854
export function foldFileToolNames(
5955
names: readonly string[],
6056
profile: ToolProfile,
@@ -131,10 +127,8 @@ export function advertisedToolName(
131127
return table[engine] ?? engine;
132128
}
133129

134-
/**
135-
* True when `name` (wire, engine, or hidden alias) is covered by an
136-
* advertised or activated listing, which may store wire or engine ids.
137-
*/
130+
/** True when `name` (wire, engine, or hidden alias) is covered by an
131+
* advertised or activated listing (which may store wire or engine ids). */
138132
export function nameMatchesAdvertisedListing(
139133
name: string,
140134
isListed: (candidate: string) => boolean,
@@ -194,13 +188,11 @@ export function projectToolDefinitions(
194188
return defs.map((def) => projectToolDefinition(def, profile));
195189
}
196190

197-
/**
198-
* Authz parity: the reactor authz snapshot is keyed by parked wire name, so
199-
* without per-alias copies an ask-tier `bash`/`shell` call throws a
191+
/** Authz parity: the reactor authz snapshot is keyed by parked wire name,
192+
* so without per-alias copies an ask-tier `bash`/`shell` call throws a
200193
* wiring-defect error instead of suspending. `update_plan` is never
201194
* snapshotted (its grant is create-only narrow); non-aliased defs (MCP,
202-
* leaf-only) pass through unchanged.
203-
*/
195+
* leaf-only) pass through. */
204196
export function authzParityDefinitions(
205197
defs: readonly ToolDefinition[],
206198
): ToolDefinition[] {
@@ -223,10 +215,8 @@ export function authzParityDefinitions(
223215
return out;
224216
}
225217

226-
/**
227-
* Tool bundle wrapper (e.g. DynamicToolRunner): identical except the
228-
* `definitions` getter returns `authzParityDefinitions` over the live set.
229-
*/
218+
/** Tool bundle wrapper (e.g. DynamicToolRunner): identical except the
219+
* `definitions` getter returns `authzParityDefinitions` over the live set. */
230220
export function withAuthzParityDefinitions<
231221
T extends { readonly definitions: readonly ToolDefinition[] },
232222
>(bundle: T): T {
@@ -255,10 +245,8 @@ export function shellQuote(arg: string): string {
255245
return `'${arg.replace(/'/g, `'\\''`)}'`;
256246
}
257247

258-
/**
259-
* Codex `shell` sends `command` as a string or argv array, while `run_shell`
260-
* takes a single shell string.
261-
*/
248+
/** Codex `shell` sends `command` as a string or argv array, while
249+
* `run_shell` takes a single shell string. */
262250
export function normalizeShellCommand(command: string | string[]): string {
263251
if (typeof command === "string") return command;
264252
const wrapper = command[0];
@@ -352,10 +340,8 @@ function incomingAlias(requested: string): string {
352340
return name;
353341
}
354342

355-
/**
356-
* Coerce hidden Codex-shaped arguments onto the engine tool. Callers pass the
357-
* already-resolved engine.
358-
*/
343+
/** Coerce hidden Codex-shaped arguments onto the engine tool. Callers pass
344+
* the already-resolved engine. */
359345
export function prepareDispatchedToolCall(
360346
call: ToolCall,
361347
engine: string,

‎src/agent/tool-search.ts‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { ORCHESTRATOR_TOOLS, READ_TOOLS } from "./directors/tool-sets.js";
2727
// so tool_search finds it on demand. Write/edit/delete stay in CORE so the
2828
// primary dispatch can do tiny/bounded edits without a search round-trip;
2929
// substantial work spawns build / docs directors. Codex natives
30-
// (apply_patch / shell / update_plan) are not advertised.
30+
// (apply_patch / shell / update_plan) stay off.
3131
export const CORE_TOOL_NAMES: readonly string[] = [
3232
"read",
3333
"write",
@@ -63,8 +63,8 @@ const ORCHESTRATOR_ONLY_TOOL_NAMES: readonly string[] = [
6363
];
6464

6565
// Session-start facts gating a core tool's advertisement, fixed for the
66-
// session: the tools array is a provider cache prefix, so a value that
67-
// could flip mid-session forces a re-prefill worse than the bytes it saves.
66+
// session: the tools array is a provider cache prefix, so a value that flips
67+
// mid-session forces a re-prefill worse than the bytes it saves.
6868
export interface ToolAvailability {
6969
// Whether a language server was resolvable for this project at startup.
7070
languageServerAvailable: boolean;
@@ -74,7 +74,7 @@ export interface ToolAvailability {
7474
operatorAvailable?: boolean;
7575
// Whether createAgentToolset mounted wait_agents: true only on exec
7676
// primary; TUI primary and nested orchestrators collect via mailbox mail.
77-
// False/omitted filters it out of the core and advertised name sets.
77+
// False/omitted filters it out of the core and advertised sets.
7878
waitAgentsMounted?: boolean;
7979
}
8080

@@ -110,11 +110,9 @@ const WORKER_WIRE_ALWAYS: readonly string[] = [
110110
"submit_result",
111111
];
112112

113-
/**
114-
* Advertised wire prefix for a spawned worker: the director's tool allowlist
115-
* plus `tool_search` and the leaf reporting channel. No shared preset across
116-
* roles; MCP stays off until tool_search / promote-on-execute.
117-
*/
113+
/** Advertised wire prefix for a spawned worker: the director's tool
114+
* allowlist plus `tool_search` and the leaf reporting channel. No shared
115+
* preset across roles; MCP stays off until tool_search / promote-on-execute. */
118116
export function advertisedToolNamesForWorker(opts: {
119117
allow?: readonly string[];
120118
orchestrator?: boolean;
@@ -141,7 +139,7 @@ export function advertisedToolNamesForWorker(opts: {
141139
}
142140

143141
// Built-in file/search/web tools advertised with full schema alongside the
144-
// core set; MCP tools are absent — discovered blind via tool_search. list_dir
142+
// core set; MCP tools are absent — found blind via tool_search. list_dir
145143
// stays mounted but unadvertised and excluded from tool_search (use glob).
146144
// web_fetch/web_search are catalog, not deferred: URL reads and search are
147145
// first-class primary work; gating them behind tool_search thrashed on
@@ -192,8 +190,8 @@ export const UNADVERTISED_MOUNTED_BUILTINS = new Set([
192190
// followed by wire-committed tools in first-commit order. Callers pass names
193191
// committed via flushPromotions (on promote and at cache-safe boundaries),
194192
// never the live activation list, so a mid-handler discovery cannot append
195-
// until the promoter commits it. Names are deduped so raw matches cannot
196-
// reorder or duplicate an entry.
193+
// until the promoter commits it. Deduped so raw matches cannot reorder or
194+
// duplicate an entry.
197195
export function advertisedTools(
198196
all: readonly ToolDefinition[],
199197
activated: readonly string[] = [],
@@ -225,15 +223,15 @@ export function advertisedTools(
225223

226224
// Non-built-in tool names the session has activated (promote-on-execute of a
227225
// called name, or a director-side trigger like the lsp hint), in
228-
// first-activation order. Backed by a Set: re-activating a known name is a
229-
// no-op.
226+
// first-activation order. Backed by a Set, so re-activating a known name is
227+
// a no-op.
230228
export interface ActivatedToolTracker {
231229
// Adds any new names; returns whether the set changed.
232230
activate(names: readonly string[]): boolean;
233231
has(name: string): boolean;
234232
list(): string[];
235233
// Session rotation (/clear, /new) mints a fresh transcript whose model
236-
// never saw the activations — the advertised set starts clean with it.
234+
// never saw the activations — the advertised set starts clean.
237235
clear(): void;
238236
}
239237

@@ -352,7 +350,7 @@ export interface ToolSearchDeps {
352350
promote?: (names: string[]) => void;
353351
// Remaining in-flight MCP handshake count after a bounded wait. The
354352
// handler re-races this so a stuck dependency (hung OAuth) cannot hang the
355-
// call. Omitted callers have no pending handshakes.
353+
// call. Omitted callers have none.
356354
awaitPendingConnections?: (timeoutMs?: number) => Promise<number>;
357355
// True when a reconnecting MCP server holds tools that could match
358356
// `query`, justifying one short extra wait for the redial to remount them.

‎src/agent/tools.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ interface ModuleStub {
5959
}
6060

6161
// Table-driven stub registrations: one entry per mocked module, installed in
62-
// order through withMockedModule.
62+
// order.
6363
const MODULE_STUBS: readonly ModuleStub[] = [
6464
{
6565
path: import.meta.resolve("@intx/tools-posix"),

0 commit comments

Comments
 (0)