@ferris1225/pi-subagents 6.0.0 → 6.0.2

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.
@@ -1,4 +1,4 @@
1
- /** Searchable pickers and the /subagents-setup role register. */
1
+ /** Linear setup menus and searchable choices within Pi's input dock. */
2
2
 
3
3
  import {
4
4
  Input, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi,
@@ -15,22 +15,29 @@ function setupHeight(tui: TUI): number {
15
15
  return Math.max(3, (tui.terminal?.rows ?? 28) - 14);
16
16
  }
17
17
 
18
+ export interface SetupItem extends SelectItem {
19
+ /** Saved state is independent of the navigation cursor. */
20
+ saved?: boolean;
21
+ }
18
22
  interface PickerOptions {
19
23
  title: string;
20
24
  hint: string;
21
25
  initialValue?: string;
26
+ searchable: boolean;
22
27
  }
23
28
 
24
29
  /** Input owns Unicode editing, paste, horizontal scrolling and the IME cursor.
25
- * Selection and paging use the host's configurable keybindings. */
30
+ * The bounded list takes priority; Tab exposes complete, scrollable details. */
26
31
  class Picker implements Component, Focusable {
27
32
  private _focused = false;
28
33
  private cursor = 0;
29
- private pageRows = PAGE_SIZE;
30
- private filtered: SelectItem[];
31
- private readonly search = new Input({ prompt: "Search: ", placeholder: "type to filter" });
34
+ private pageRows = 1;
35
+ private details = false;
36
+ private detailTop = 0;
37
+ private filtered: SetupItem[];
38
+ private readonly search = new Input({ prompt: "Search: ", placeholder: "name, provider or reference" });
32
39
 
33
- private readonly items: SelectItem[];
40
+ private readonly items: SetupItem[];
34
41
  private readonly options: PickerOptions;
35
42
  private readonly tui: TUI;
36
43
  private readonly theme: Theme;
@@ -38,7 +45,7 @@ class Picker implements Component, Focusable {
38
45
  private readonly done: (value: string | undefined) => void;
39
46
 
40
47
  constructor(
41
- items: SelectItem[], options: PickerOptions, tui: TUI, theme: Theme,
48
+ items: SetupItem[], options: PickerOptions, tui: TUI, theme: Theme,
42
49
  keybindings: KeybindingsManager, done: (value: string | undefined) => void,
43
50
  ) {
44
51
  this.items = items;
@@ -49,53 +56,103 @@ class Picker implements Component, Focusable {
49
56
  this.done = done;
50
57
  this.filtered = items;
51
58
  const initial = items.findIndex((item) => item.value === options.initialValue);
52
- if (initial >= 0) this.cursor = initial;
59
+ const saved = items.findIndex((item) => item.saved);
60
+ this.cursor = Math.max(0, initial >= 0 ? initial : saved);
53
61
  }
54
62
 
55
63
  get focused(): boolean { return this._focused; }
56
- set focused(value: boolean) { this._focused = value; this.search.focused = value; }
64
+ set focused(value: boolean) {
65
+ this._focused = value;
66
+ this.search.focused = value && this.options.searchable && !this.details;
67
+ }
68
+
69
+ private isSaved(item: SetupItem): boolean {
70
+ return item.saved ?? (this.options.searchable && item.value === this.options.initialValue);
71
+ }
72
+
73
+ private detailLines(width: number): string[] {
74
+ const item = this.filtered[this.cursor];
75
+ if (!item) return ["No matches. Clear or change the search."];
76
+ return [item.label + (this.isSaved(item) ? " [saved]" : ""), item.description ?? item.value]
77
+ .flatMap((text) => wrapTextWithAnsi(text, width));
78
+ }
57
79
 
58
80
  render(width: number): string[] {
59
81
  if (width <= 0) return [];
60
82
  const theme = this.theme;
61
- const dim = (text: string) => theme.fg("dim", text);
83
+ const muted = (text: string) => theme.fg("muted", text);
62
84
  const height = setupHeight(this.tui);
63
- if (height < 8) {
64
- this.pageRows = 1;
65
- const item = this.filtered[this.cursor];
66
- return [theme.bold(this.options.title), ...this.search.render(width),
67
- item ? theme.fg("accent", "› ") + theme.underline(item.label) : "No matches. Clear or change the search."]
68
- .map((line) => truncateToWidth(line, width, "…"));
85
+ const compact = height < 6;
86
+ const lines: string[] = [];
87
+ // At three rows, retain search, a choice and controls instead of a title.
88
+ if (!(height === 3 && this.options.searchable && !this.details)) {
89
+ lines.push(theme.bold(this.options.title + (this.details ? " · Details" : "")));
69
90
  }
70
- const lines = [theme.bold("Subagents · " + this.options.title)];
71
- if (this.options.hint && height >= 16) lines.push(...wrapTextWithAnsi(this.options.hint, width).slice(0, 2).map(dim));
72
- lines.push(...this.search.render(width), "");
73
- const footer = [dim("↑/↓ move · PgUp/PgDn page"), dim("Enter select · Esc back")];
74
- const item = this.filtered[this.cursor];
75
- // The complete selected identity lives beside its capabilities, even when
76
- // a long provider/model id was truncated in the list above.
77
- const details = item ? ["", ...wrapTextWithAnsi(item.label, width).slice(0, 2),
78
- ...wrapTextWithAnsi(item.description ?? "", width).slice(0, 3).map(dim)] : [];
79
- const detailBudget = Math.max(0, Math.min(details.length, height - lines.length - footer.length - 2));
80
- const visibleDetails = details.slice(0, detailBudget);
81
- this.pageRows = Math.max(1, Math.min(PAGE_SIZE, height - lines.length - footer.length - visibleDetails.length - 1));
82
- const start = Math.max(0, Math.min(this.cursor - Math.floor(this.pageRows / 2), this.filtered.length - this.pageRows));
83
- const visible = this.filtered.slice(start, start + this.pageRows);
84
- if (!visible.length) lines.push(dim(this.search.getValue() ? "No matches. Clear or change the search." : "No choices available."));
85
- for (const [index, choice] of visible.entries()) {
86
- const selected = start + index === this.cursor;
87
- const label = truncateToWidth(choice.label, Math.max(0, width - 2), "…");
88
- lines.push(selected ? theme.fg("accent", "› ") + theme.underline(theme.bold(label)) : " " + label);
91
+ if (!this.details && this.options.hint && height >= 10) lines.push(muted(this.options.hint));
92
+ if (!this.details && this.options.searchable) lines.push(...this.search.render(width));
93
+ const footer = compact
94
+ ? [muted(this.details ? "↑↓ scroll · Tab list · Esc" : "↑↓ Enter Esc · Tab details")]
95
+ : this.details
96
+ ? [muted("↑/↓ scroll · Tab list · Esc back"), muted("PgUp/Dn page · Enter select")]
97
+ : [muted("↑/↓ move · Enter select · Esc back"), muted(
98
+ (this.filtered.length ? (this.cursor + 1) + "/" + this.filtered.length + " · " : "") + "PgUp/Dn · Tab details")];
99
+ const budget = Math.max(1, height - lines.length - footer.length);
100
+ if (this.details) {
101
+ this.pageRows = budget;
102
+ const details = this.detailLines(width);
103
+ this.detailTop = Math.max(0, Math.min(this.detailTop, details.length - budget));
104
+ lines.push(...details.slice(this.detailTop, this.detailTop + budget));
105
+ } else {
106
+ this.pageRows = Math.min(PAGE_SIZE, budget);
107
+ const start = Math.max(0, Math.min(this.cursor - Math.floor(this.pageRows / 2), this.filtered.length - this.pageRows));
108
+ const visible = this.filtered.slice(start, start + this.pageRows);
109
+ if (!visible.length) lines.push(muted(this.search.getValue() ? "No matches. Clear or change the search." : "No choices available."));
110
+ for (const [index, item] of visible.entries()) {
111
+ const active = start + index === this.cursor;
112
+ const suffix = this.isSaved(item) ? " [saved]" : "";
113
+ const label = truncateToWidth(item.label, Math.max(0, width - 2 - visibleWidth(suffix)), "…") + suffix;
114
+ lines.push(active ? theme.fg("accent", "› ") + theme.underline(theme.bold(label)) : " " + label);
115
+ }
116
+ // Menus show the active role/setting's explanation. Choice lists only
117
+ // use spare rows for context, never displacing another choice.
118
+ const spare = Math.min(3, height - lines.length - footer.length);
119
+ const item = this.filtered[this.cursor];
120
+ if (spare > 0 && item?.description) {
121
+ const wrapped = wrapTextWithAnsi(item.description, width);
122
+ const preview = wrapped.slice(0, spare);
123
+ if (wrapped.length > spare) preview[spare - 1] = truncateToWidth(preview[spare - 1]! + "…", width, "…");
124
+ lines.push(...preview.map(muted));
125
+ }
89
126
  }
90
- if (item) lines.push(dim((this.cursor + 1) + "/" + this.filtered.length + " matches"));
91
- lines.push(...visibleDetails, ...footer);
92
- return lines.map((line) => truncateToWidth(line, width, "…"));
127
+ return [...lines, ...footer].map((line) => truncateToWidth(line, width, "…"));
93
128
  }
94
129
 
95
130
  handleInput(data: string): void {
96
131
  const kb = this.keybindings;
97
132
  const count = this.filtered.length;
98
- if (kb.matches(data, "tui.select.up")) {
133
+ if (kb.matches(data, "tui.select.cancel")) {
134
+ if (this.details) {
135
+ this.details = false;
136
+ this.detailTop = 0;
137
+ this.focused = this._focused;
138
+ } else {
139
+ this.done(undefined);
140
+ return;
141
+ }
142
+ } else if (kb.matches(data, "tui.select.confirm")) {
143
+ const item = this.filtered[this.cursor];
144
+ if (item) this.done(item.value);
145
+ return;
146
+ } else if (matchesKey(data, "tab")) {
147
+ this.details = !this.details;
148
+ this.detailTop = 0;
149
+ this.focused = this._focused;
150
+ } else if (this.details) {
151
+ if (kb.matches(data, "tui.select.up")) this.detailTop--;
152
+ else if (kb.matches(data, "tui.select.down")) this.detailTop++;
153
+ else if (kb.matches(data, "tui.select.pageUp")) this.detailTop -= this.pageRows;
154
+ else if (kb.matches(data, "tui.select.pageDown")) this.detailTop += this.pageRows;
155
+ } else if (kb.matches(data, "tui.select.up")) {
99
156
  if (count) this.cursor = (this.cursor - 1 + count) % count;
100
157
  } else if (kb.matches(data, "tui.select.down")) {
101
158
  if (count) this.cursor = (this.cursor + 1) % count;
@@ -103,14 +160,7 @@ class Picker implements Component, Focusable {
103
160
  this.cursor = Math.max(0, this.cursor - this.pageRows);
104
161
  } else if (kb.matches(data, "tui.select.pageDown")) {
105
162
  this.cursor = Math.max(0, Math.min(count - 1, this.cursor + this.pageRows));
106
- } else if (kb.matches(data, "tui.select.confirm")) {
107
- const item = this.filtered[this.cursor];
108
- if (item) this.done(item.value);
109
- return;
110
- } else if (kb.matches(data, "tui.select.cancel")) {
111
- this.done(undefined);
112
- return;
113
- } else {
163
+ } else if (this.options.searchable) {
114
164
  const before = this.search.getValue();
115
165
  this.search.handleInput(data);
116
166
  if (before !== this.search.getValue()) {
@@ -125,187 +175,25 @@ class Picker implements Component, Focusable {
125
175
  invalidate(): void { this.search.invalidate(); }
126
176
  }
127
177
 
128
- /** Single-select with fuzzy search and paging. Esc returns without a change. */
129
- export function promptSelectOne(
130
- ctx: PickerContext, title: string, hint: string, items: SelectItem[], initialValue?: string,
131
- ): Promise<string | undefined> {
178
+ function prompt(ctx: PickerContext, items: SetupItem[], options: PickerOptions): Promise<string | undefined> {
132
179
  if (ctx.mode !== "tui") {
133
180
  ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
134
181
  return Promise.resolve(undefined);
135
182
  }
136
183
  return ctx.ui.custom<string | undefined>((tui, theme, keybindings, done) =>
137
- new Picker(items, { title, hint, initialValue }, tui, theme, keybindings, done));
138
- }
139
-
140
- export interface RoleGridRow {
141
- role: string;
142
- model: string;
143
- /** Effective level, optionally followed by the requested level when clamped. */
144
- thinking: string;
145
- thinkingOverridden?: boolean;
146
- description: string;
184
+ new Picker(items, options, tui, theme, keybindings, done));
147
185
  }
148
- export interface RoleGridFocus { row?: number; column?: number; }
149
- const GRID_COLUMNS = ["model", "thinking", "reset"] as const;
150
- export type RoleGridColumn = (typeof GRID_COLUMNS)[number];
151
- export interface RoleGridChoice { row: number; column: number; role: string; field: RoleGridColumn; }
152
-
153
- /** A role register beside the selected role's settings; narrow terminals stack
154
- * the same regions. Full effective values are never squeezed into grid cells. */
155
- class RoleGrid implements Component {
156
- private row: number;
157
- private column: number;
158
- private scrollTop = 0;
159
- private pageRows = 1;
160
- private viewport = "";
161
- private revealField = true;
162
-
163
- private readonly rows: RoleGridRow[];
164
- private readonly status: string;
165
- private readonly tui: TUI;
166
- private readonly theme: Theme;
167
- private readonly keybindings: KeybindingsManager;
168
- private readonly done: (choice: RoleGridChoice | undefined) => void;
169
186
 
170
- constructor(
171
- rows: RoleGridRow[], status: string, focus: RoleGridFocus, tui: TUI, theme: Theme,
172
- keybindings: KeybindingsManager, done: (choice: RoleGridChoice | undefined) => void,
173
- ) {
174
- this.rows = rows;
175
- this.status = status;
176
- this.tui = tui;
177
- this.theme = theme;
178
- this.keybindings = keybindings;
179
- this.done = done;
180
- this.row = Math.min(Math.max(0, focus.row ?? 0), Math.max(0, rows.length - 1));
181
- this.column = Math.min(Math.max(0, focus.column ?? 0), GRID_COLUMNS.length - 1);
182
- }
183
-
184
- private settings(width: number): { lines: string[]; start: number; end: number } {
185
- const focused = this.rows[this.row];
186
- if (!focused) return { lines: [this.theme.fg("dim", "No roles configured.")], start: 0, end: 1 };
187
- const theme = this.theme;
188
- const dim = (text: string) => theme.fg("dim", text);
189
- const field = GRID_COLUMNS[this.column]!;
190
- const label = field === "thinking" ? "Thinking (reasoning effort)" : field === "reset" ? "Reset" : "Model";
191
- const lines = [theme.bold(focused.role + " · " + label), ""];
192
- const starts: number[] = [];
193
- const setting = (column: number, name: string, hint: string): void => {
194
- starts.push(lines.length);
195
- const active = this.column === column;
196
- lines.push((active ? theme.fg("accent", "› ") : " ") + (active ? theme.underline(theme.bold(name)) : name) + dim(" · " + hint));
197
- };
198
- const value = (text: string): void => {
199
- lines.push(...wrapTextWithAnsi(text, Math.max(1, width - 2)).map((line) => " " + line));
200
- };
201
- setting(0, "Model", "Enter edit");
202
- value(focused.model);
203
- setting(1, "Thinking", "effective");
204
- value(focused.thinking);
205
- lines.push(dim(" Source: " + (focused.thinkingOverridden ? "override *" : "role default")));
206
- setting(2, "Reset", "Enter restore defaults");
207
- const end = lines.length;
208
- lines.push("", ...wrapTextWithAnsi(focused.description, width).map(dim));
209
- return { lines, start: starts[this.column]!, end: starts[this.column + 1] ?? end };
210
- }
211
-
212
- render(width: number): string[] {
213
- if (width <= 0) return [];
214
- const theme = this.theme;
215
- const dim = (text: string) => theme.fg("dim", text);
216
- const lines = [theme.bold("Subagents · Roles"), dim(this.status), ""];
217
- const height = setupHeight(this.tui);
218
- const wide = width >= 88;
219
- // The two panes close exactly: roleWidth + 3-column gutter + detailWidth = width.
220
- const roleWidth = wide ? Math.min(24, Math.floor(width * 0.24)) : width;
221
- const roles: string[] = [];
222
- for (const [index, role] of this.rows.entries()) {
223
- const selected = index === this.row;
224
- const name = selected ? theme.bold(role.role) : role.role;
225
- roles.push((selected ? "› " : " ") + name);
226
- if (wide) roles.push(dim(" " + truncateToWidth(role.model, roleWidth - 2, "…")));
227
- }
228
- const details = this.settings(wide ? width - roleWidth - 3 : width);
229
- const detailOffset = wide ? 0 : roles.length + 1;
230
- const body: string[] = [];
231
- if (wide) {
232
- for (let i = 0; i < Math.max(roles.length, details.lines.length); i++) {
233
- const left = truncateToWidth(roles[i] ?? "", roleWidth, "…");
234
- body.push(left + " ".repeat(roleWidth - visibleWidth(left) + 3) + (details.lines[i] ?? ""));
235
- }
236
- } else {
237
- body.push(...roles, "", ...details.lines);
238
- }
239
- const footer = [dim("↑/↓ role · ←/→ field"), dim("Enter edit · Esc close")];
240
- if (lines.length + body.length + footer.length + 1 <= height) {
241
- this.scrollTop = 0;
242
- this.revealField = true;
243
- return [...lines, ...body, "", ...footer].map((line) => truncateToWidth(line, width, "…"));
244
- }
245
- // Pin the selected identity while scrolling the existing pane content.
246
- // The field's complete value and provenance remain reachable by paging.
247
- const compact = height < 8;
248
- const header = compact ? [details.lines[0]!] : [...lines.slice(0, 2), details.lines[0]!];
249
- const controls = compact ? [dim("PgUp/Dn scroll · Enter edit · Esc")]
250
- : [footer[0]!, dim("PgUp/Dn scroll · Enter edit · Esc")];
251
- this.pageRows = Math.max(1, height - header.length - controls.length);
252
- const viewport = width + ":" + this.pageRows;
253
- if (this.revealField || this.viewport !== viewport) {
254
- const start = detailOffset + details.start;
255
- const end = detailOffset + details.end;
256
- // One-line viewports show the value rather than repeating its label.
257
- this.scrollTop = end - start > this.pageRows ? start + Number(this.pageRows === 1 && end > start + 1)
258
- : Math.max(0, end - this.pageRows);
259
- }
260
- this.viewport = viewport;
261
- this.revealField = false;
262
- this.scrollTop = Math.max(0, Math.min(this.scrollTop, body.length - this.pageRows));
263
- return [...header, ...body.slice(this.scrollTop, this.scrollTop + this.pageRows), ...controls]
264
- .map((line) => truncateToWidth(line, width, "…"));
265
- }
266
-
267
- handleInput(data: string): void {
268
- const kb = this.keybindings;
269
- const rows = this.rows.length;
270
- const previousRow = this.row;
271
- const previousColumn = this.column;
272
- if (kb.matches(data, "tui.select.pageUp")) {
273
- this.scrollTop -= this.pageRows;
274
- } else if (kb.matches(data, "tui.select.pageDown")) {
275
- this.scrollTop += this.pageRows;
276
- } else if (kb.matches(data, "tui.select.up")) {
277
- if (rows) this.row = (this.row - 1 + rows) % rows;
278
- } else if (kb.matches(data, "tui.select.down")) {
279
- if (rows) this.row = (this.row + 1) % rows;
280
- } else if (matchesKey(data, "left") || kb.matches(data, "tui.editor.cursorLeft")) {
281
- this.column = (this.column - 1 + GRID_COLUMNS.length) % GRID_COLUMNS.length;
282
- } else if (matchesKey(data, "right") || kb.matches(data, "tui.editor.cursorRight")) {
283
- this.column = (this.column + 1) % GRID_COLUMNS.length;
284
- } else if (kb.matches(data, "tui.select.confirm")) {
285
- const focused = this.rows[this.row];
286
- if (focused) {
287
- this.done({ row: this.row, column: this.column, role: focused.role, field: GRID_COLUMNS[this.column]! });
288
- return;
289
- }
290
- } else if (kb.matches(data, "tui.select.cancel")) {
291
- this.done(undefined);
292
- return;
293
- } else return;
294
- if (this.row !== previousRow || this.column !== previousColumn) this.revealField = true;
295
- this.tui.requestRender();
296
- }
297
-
298
- invalidate(): void {}
187
+ /** Searchable choices. Esc returns one level without saving the cursor. */
188
+ export function promptSelectOne(
189
+ ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
190
+ ): Promise<string | undefined> {
191
+ return prompt(ctx, items, { title, hint, initialValue, searchable: true });
299
192
  }
300
193
 
301
- /** Role × setting navigation. Esc closes without a change. */
302
- export function promptRoleGrid(
303
- ctx: PickerContext, rows: RoleGridRow[], focus: RoleGridFocus = {}, status = "Changes save immediately",
304
- ): Promise<RoleGridChoice | undefined> {
305
- if (ctx.mode !== "tui") {
306
- ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
307
- return Promise.resolve(undefined);
308
- }
309
- return ctx.ui.custom<RoleGridChoice | undefined>((tui, theme, keybindings, done) =>
310
- new RoleGrid(rows, status, focus, tui, theme, keybindings, done));
194
+ /** A familiar vertical menu. initialValue restores navigation, not saved state. */
195
+ export function promptMenu(
196
+ ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
197
+ ): Promise<string | undefined> {
198
+ return prompt(ctx, items, { title, hint, initialValue, searchable: false });
311
199
  }
@@ -40,8 +40,7 @@ export type ToolMetadata = Pick<ToolInfo, "name" | "annotations" | "reachesTools
40
40
  exposure?: ToolInfo["exposure"];
41
41
  };
42
42
 
43
- /** Exposures reached through a script or `tool_search` instead of a declaration.
44
- * The session can call these, so a child can be given them directly. */
43
+ /** Exposures callable through a script or `tool_search` without activation. */
45
44
  const INDIRECT_EXPOSURES: ReadonlySet<string> = new Set(["codemode", "deferred"]);
46
45
  /** Live tool metadata keyed by name. Read-only and write capability come from it
47
46
  * instead of a maintained list of extension or MCP tool names. */
@@ -66,11 +65,9 @@ function isReadOnlyToolName(name: string, index: ToolInfoIndex): boolean {
66
65
  return info ? isReadOnlyTool(info) : BUILTIN_READ_ONLY_TOOL_SET.has(name);
67
66
  }
68
67
 
69
- /** Resolve a child against the parent's live tool selection. Broad roles
70
- * inherit the complete active set. A read-only role keeps every active tool
71
- * that is proven read-only, so retrieval extensions and MCP servers work
72
- * without being named anywhere. pi-subagents controls are always removed so
73
- * children stay leaves. */
68
+ /** Resolve a child against the parent's active and callable indirect tools.
69
+ * Inactive direct tools stay excluded. Scout promotes only tools marked
70
+ * read-only; pi-subagents controls are removed so children stay leaves. */
74
71
  export function resolveAgentTools(
75
72
  agent: AgentConfig,
76
73
  activeToolNames: readonly string[],
@@ -78,23 +75,19 @@ export function resolveAgentTools(
78
75
  ): AgentConfig {
79
76
  const active = [...new Set(activeToolNames)].filter((tool) => !SUBAGENT_TOOL_NAME_SET.has(tool));
80
77
  const toolIndex = indexToolInfos(toolInfos);
81
- if (agent.name !== "scout") return { ...agent, tools: active };
82
- // Scout is a hard read-only boundary, so its surface is derived from the
83
- // live catalog alone — the role can never widen past what the host proves
84
- // read-only. Codemode and tool_search are excluded because they reach other
85
- // tools.
78
+ const indirect = [...toolIndex.values()]
79
+ .filter((tool) => tool.exposure && INDIRECT_EXPOSURES.has(tool.exposure) && !SUBAGENT_TOOL_NAME_SET.has(tool.name))
80
+ .map((tool) => tool.name)
81
+ .filter((name) => !active.includes(name))
82
+ .sort();
83
+ if (agent.name !== "scout") return { ...agent, tools: [...active, ...indirect] };
84
+ // Scout uses the live catalog's read-only classification. Codemode and
85
+ // tool_search are excluded because they can reach tools outside that set.
86
86
  const tools = active.filter((tool) => isReadOnlyToolName(tool, toolIndex));
87
- // A read-only tool the session reaches through codemode or tool_search is
88
- // part of the same capability, and the child can be handed it directly.
89
- // Declaring it is the only way to give scout an MCP server it cannot
90
- // reconfigure, without also giving it a tool that reaches a writer.
87
+ // The child explicitly activates these after registration, without giving
88
+ // scout an orchestrating tool that could also reach writers.
91
89
  if (active.some((tool) => toolIndex.get(tool)?.reachesTools)) {
92
- const indirect = [...toolIndex.values()]
93
- .filter((tool) => typeof tool.exposure === "string" && INDIRECT_EXPOSURES.has(tool.exposure) && isReadOnlyTool(tool))
94
- .map((tool) => tool.name)
95
- .filter((name) => !tools.includes(name))
96
- .sort();
97
- tools.push(...indirect);
90
+ tools.push(...indirect.filter((name) => isReadOnlyToolName(name, toolIndex)));
98
91
  }
99
92
  return { ...agent, tools };
100
93
  }