@lunchbox-labs/kilo-tool-inspector 0.3.2 → 1.0.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.
Files changed (3) hide show
  1. package/dist/tui.d.ts +1 -0
  2. package/dist/tui.js +580 -551
  3. package/package.json +3 -3
package/dist/tui.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TuiPlugin } from "@kilocode/plugin/tui";
2
+ /** The Tool Inspector TUI plugin. */
2
3
  declare const plugin: {
3
4
  id: string;
4
5
  tui: TuiPlugin;
package/dist/tui.js CHANGED
@@ -1,14 +1,4 @@
1
- // ../core/src/agents.ts
2
- const editTools = /* @__PURE__ */ new Set([
3
- "edit",
4
- "write",
5
- "apply_patch"
6
- ]);
7
- const mcpResourceReadTools = /* @__PURE__ */ new Set([
8
- "list_mcp_resources",
9
- "list_mcp_resource_templates",
10
- "read_mcp_resource"
11
- ]);
1
+ // ../core/src/access.ts
12
2
  const unknownDecision = {
13
3
  access: "unknown",
14
4
  exceptions: [],
@@ -21,56 +11,6 @@ function field(value, key) {
21
11
  function isPermissionAction(value) {
22
12
  return value === "allow" || value === "ask" || value === "deny";
23
13
  }
24
- function readRule(value) {
25
- const permission = field(value, "permission");
26
- const pattern = field(value, "pattern");
27
- const action = field(value, "action");
28
- if (typeof permission !== "string" || typeof pattern !== "string" || !isPermissionAction(action)) return;
29
- return {
30
- permission,
31
- pattern,
32
- action
33
- };
34
- }
35
- function readRuleset(value) {
36
- if (!Array.isArray(value)) return;
37
- const rules = [];
38
- for (const item of value) {
39
- const rule = readRule(item);
40
- if (rule === void 0) return;
41
- rules.push(rule);
42
- }
43
- return rules;
44
- }
45
- function readStringList(value) {
46
- if (value === void 0) return [];
47
- if (!Array.isArray(value)) return;
48
- const strings = [];
49
- for (const item of value) {
50
- if (typeof item !== "string") return;
51
- strings.push(item);
52
- }
53
- return strings;
54
- }
55
- function readItems(value) {
56
- return Array.isArray(value) ? value : [];
57
- }
58
- function readAgent(value) {
59
- const name = field(value, "name");
60
- if (typeof name !== "string") return;
61
- const mode = field(value, "mode");
62
- return {
63
- name,
64
- mode: typeof mode === "string" ? mode : void 0,
65
- hidden: field(value, "hidden") === true,
66
- native: field(value, "native") === true,
67
- permission: field(value, "permission")
68
- };
69
- }
70
- function readToolId(value) {
71
- const id = typeof value === "string" ? value : field(value, "id");
72
- return typeof id === "string" ? id : void 0;
73
- }
74
14
  function readMode(mode) {
75
15
  return mode === "primary" || mode === "subagent" || mode === "all" ? mode : "unknown";
76
16
  }
@@ -95,7 +35,11 @@ function matchesWildcard(input, pattern) {
95
35
  function isCatchAllPattern(pattern) {
96
36
  return /^\*+(?: \*)?$/.test(pattern);
97
37
  }
98
- function decide(permission, rules) {
38
+ /**
39
+ * The general access and pattern exceptions the rules give one permission. `offered` receives the
40
+ * rules that name the permission, in order, and says whether the host still offers the tool.
41
+ */
42
+ function decide(permission, rules, offered) {
99
43
  const matching = rules.filter((rule) => matchesWildcard(permission, rule.permission));
100
44
  const lastCatchAll = matching.findLastIndex((rule) => isCatchAllPattern(rule.pattern));
101
45
  const access = matching[lastCatchAll]?.action ?? "ask";
@@ -110,242 +54,119 @@ function decide(permission, rules) {
110
54
  });
111
55
  }
112
56
  const firstChange = exceptions.findIndex((exception) => exception.access !== access);
113
- const lastRule = matching.at(-1);
114
57
  return {
115
58
  access,
116
59
  exceptions: firstChange === -1 ? [] : exceptions.slice(firstChange),
117
- offeredToModel: !(lastRule?.pattern === "*" && lastRule.action === "deny")
60
+ offeredToModel: offered(matching)
118
61
  };
119
62
  }
120
63
  function sameDecision(first, second) {
121
64
  return first.access === second.access && first.offeredToModel === second.offeredToModel && first.exceptions.length === second.exceptions.length && first.exceptions.every((exception, index) => exception.pattern === second.exceptions[index]?.pattern && exception.access === second.exceptions[index].access);
122
65
  }
123
- function denyAll(permission) {
66
+
67
+ // ../core/src/agent-text.ts
68
+ function muted$2(text) {
124
69
  return {
125
- permission,
126
- pattern: "*",
127
- action: "deny"
70
+ text,
71
+ tone: "muted"
128
72
  };
129
73
  }
130
- function subagentSessionRules(agentRules, parentSessionRules, primaryTools) {
131
- const namesPermission = (permission) => agentRules.some((rule) => rule.permission === permission);
132
- const inherited = [...parentSessionRules.filter((rule) => rule.action === "deny" || rule.permission === "external_directory"), ...["todowrite", "task"].filter((permission) => !namesPermission(permission)).map(denyAll)];
133
- const isInherited = (deny) => inherited.some((rule) => rule.permission === deny.permission && rule.pattern === deny.pattern && rule.action === deny.action);
134
- return [...inherited, ...primaryTools.map(denyAll).filter((deny) => !isInherited(deny))];
74
+ function decisionSummary(decision, actionLabels) {
75
+ if (decision.access === "unknown") return "Unknown";
76
+ if (decision.offeredToModel === false) return actionLabels.deny;
77
+ return actionLabels[decision.access];
135
78
  }
136
- function agentAccess(agent, permission, sessionRules, primaryTools) {
137
- const mode = readMode(agent.mode);
138
- const summary = {
139
- agent: agent.name,
140
- mode,
141
- hidden: agent.hidden === true,
142
- native: agent.native === true
143
- };
144
- const agentRules = readRuleset(agent.permission);
145
- if (agentRules === void 0) return {
146
- ...summary,
147
- ...unknownDecision
148
- };
149
- const primaryDecision = () => sessionRules === void 0 ? unknownDecision : decide(permission, [...agentRules, ...sessionRules]);
150
- const subagentDecision = () => primaryTools === void 0 || sessionRules === void 0 ? unknownDecision : decide(permission, [...agentRules, ...subagentSessionRules(agentRules, sessionRules, primaryTools)]);
151
- switch (mode) {
152
- case "subagent": return {
153
- ...summary,
154
- ...subagentDecision()
155
- };
156
- case "all": {
157
- const asPrimary = primaryDecision();
158
- const asSubagent = subagentDecision();
159
- return sameDecision(asPrimary, asSubagent) ? {
160
- ...summary,
161
- ...asPrimary
162
- } : {
163
- ...summary,
164
- ...asPrimary,
165
- whenSubagent: asSubagent
166
- };
167
- }
168
- case "primary":
169
- case "unknown": return {
170
- ...summary,
171
- ...primaryDecision()
172
- };
173
- }
79
+ function exceptionLines(decision, actionLabels) {
80
+ if (decision.offeredToModel === false) return [];
81
+ return decision.exceptions.map((exception) => [{
82
+ text: ` ${exception.pattern}`,
83
+ tone: "name"
84
+ }, muted$2(`: ${actionLabels[exception.access]}`)]);
174
85
  }
175
- function permissionForTool(toolId) {
176
- if (editTools.has(toolId)) return "edit";
177
- if (mcpResourceReadTools.has(toolId)) return "read";
178
- return toolId;
86
+ function agentLines(agent, actionLabels) {
87
+ return [[{
88
+ text: agent.agent,
89
+ tone: "name"
90
+ }, muted$2(` ${decisionSummary(agent, actionLabels)}`)], ...exceptionLines(agent, actionLabels)];
179
91
  }
180
- function resolveToolAgentAccess(tools, agents, options = {}) {
181
- const sessionRules = readRuleset(field(options, "sessionPermission") ?? []);
182
- const primaryTools = readStringList(field(options, "primaryTools"));
183
- const readableAgents = readItems(agents).map(readAgent).filter((agent) => agent !== void 0);
184
- return readItems(tools).map(readToolId).filter((tool) => tool !== void 0).map((tool) => {
185
- const permission = permissionForTool(tool);
186
- return {
187
- tool,
188
- permission,
189
- agents: readableAgents.map((agent) => agentAccess(agent, permission, sessionRules, primaryTools))
190
- };
191
- });
92
+ /** The host's own hidden agents, such as `compaction` and `title`, never take tool calls. */
93
+ function listed(agent) {
94
+ return !(agent.native && agent.hidden);
95
+ }
96
+ function primaryFirst(left, right) {
97
+ const rank = (agent) => agent.mode === "subagent" ? 1 : 0;
98
+ return rank(left) - rank(right);
99
+ }
100
+ function notesFor(notes, key) {
101
+ return notes !== void 0 && Object.hasOwn(notes, key) ? notes[key] : [];
102
+ }
103
+ function accessNoteLines(notes, access) {
104
+ return [
105
+ ...notes.always ?? [],
106
+ ...notesFor(notes.permission, access.permission),
107
+ ...notesFor(notes.tool, access.tool)
108
+ ].map((note) => [muted$2(note)]);
109
+ }
110
+ /** Renders which agents can use a tool, primary agents first. */
111
+ function agentAccessLines(access, host) {
112
+ const { actionLabels } = host;
113
+ const agents = access.agents.filter(listed).sort(primaryFirst);
114
+ if (agents.length === 0) return [[muted$2(`${host.name} reported no agents that use tools.`)]];
115
+ return [
116
+ ...access.permission === access.tool ? [] : [[muted$2(`Checked as the ${access.permission} permission.`)]],
117
+ ...accessNoteLines(host.accessNotes, access),
118
+ ...agents.flatMap((agent) => agentLines(agent, actionLabels))
119
+ ];
192
120
  }
193
121
 
194
- // ../core/src/detail-viewer.ts
195
- const chromeRows = 9;
196
- /** Renders a tool's detail sections in a keyboard-scrollable box inside the host's dialog frame. */
197
- async function createDetailViewer(api) {
198
- const { BoxRenderable, RenderableEvents, ScrollBoxRenderable, StyledText, TextAttributes, TextRenderable } = await import("@opentui/core");
199
- return (detail) => {
200
- const { renderer } = api;
201
- const theme = api.theme.current;
202
- const toneColours = {
203
- plain: theme.text,
204
- name: theme.text,
205
- muted: theme.textMuted
206
- };
207
- const styled = (lines) => new StyledText(lines.flatMap((line, index) => [...index === 0 ? [] : [{
208
- __isChunk: true,
209
- text: "\n"
210
- }], ...line.map((segment) => ({
211
- __isChunk: true,
212
- text: segment.text,
213
- fg: toneColours[segment.tone],
214
- ...segment.tone === "name" ? { attributes: TextAttributes.BOLD } : {}
215
- }))]));
216
- const rows = () => Math.max(1, renderer.height - Math.floor(renderer.height / 4) - chromeRows);
217
- const view = new BoxRenderable(renderer, {
218
- flexDirection: "column",
219
- paddingX: 2,
220
- paddingBottom: 1,
221
- gap: 1
222
- });
223
- view.add(new TextRenderable(renderer, {
224
- content: detail.title,
225
- fg: theme.text,
226
- attributes: TextAttributes.BOLD,
227
- selectable: false
228
- }));
229
- const body = new BoxRenderable(renderer, {
230
- flexDirection: "column",
231
- gap: 1
232
- });
233
- if (detail.subtitle !== void 0) body.add(new TextRenderable(renderer, {
234
- content: detail.subtitle,
235
- fg: theme.textMuted,
236
- wrapMode: "word"
237
- }));
238
- for (const section of detail.sections) {
239
- const block = new BoxRenderable(renderer, { flexDirection: "column" });
240
- block.add(new TextRenderable(renderer, {
241
- content: section.heading,
242
- fg: theme.accent,
243
- attributes: TextAttributes.BOLD,
244
- selectable: false
245
- }));
246
- block.add(new TextRenderable(renderer, {
247
- content: styled(section.lines),
248
- fg: theme.text,
249
- wrapMode: "word"
250
- }));
251
- body.add(block);
252
- }
253
- const unwrappedRows = detail.sections.reduce((total, section) => total + section.lines.length + 2, detail.subtitle === void 0 ? 0 : 2);
254
- const scroll = new ScrollBoxRenderable(renderer, {
255
- height: Math.min(rows(), unwrappedRows),
256
- flexShrink: 0,
257
- verticalScrollbarOptions: {
258
- paddingLeft: 1,
259
- trackOptions: {
260
- backgroundColor: theme.backgroundElement,
261
- foregroundColor: theme.border
262
- }
263
- }
264
- });
265
- const fit = () => {
266
- if (!scroll.isDestroyed) scroll.height = Math.max(1, Math.min(rows(), body.height));
267
- };
268
- body.onSizeChange = fit;
269
- scroll.add(body);
270
- view.add(scroll);
271
- view.add(new TextRenderable(renderer, {
272
- content: "↑/↓ scroll · pgup/pgdn page · home/end · esc back",
273
- fg: theme.textMuted,
274
- selectable: false
275
- }));
276
- renderer.on("resize", fit);
277
- const unbind = api.keymap.registerLayer({
278
- target: scroll,
279
- targetMode: "focus",
280
- bindings: [
281
- {
282
- key: "pageup",
283
- cmd: () => scroll.scrollBy(-1 / 2, "viewport")
284
- },
285
- {
286
- key: "pagedown",
287
- cmd: () => scroll.scrollBy(1 / 2, "viewport")
288
- },
289
- {
290
- key: "home",
291
- cmd: () => scroll.scrollBy(-1, "content")
292
- },
293
- {
294
- key: "end",
295
- cmd: () => scroll.scrollBy(1, "content")
296
- }
297
- ]
298
- });
299
- const focus = setTimeout(() => {
300
- if (!scroll.isDestroyed && !api.lifecycle.signal.aborted) scroll.focus();
301
- }, 1);
302
- const dispose = () => view.destroyRecursively();
303
- api.lifecycle.signal.addEventListener("abort", dispose, { once: true });
304
- view.on(RenderableEvents.DESTROYED, () => {
305
- clearTimeout(focus);
306
- renderer.off("resize", fit);
307
- unbind();
308
- api.lifecycle.signal.removeEventListener("abort", dispose);
309
- });
310
- return view;
311
- };
312
- }
313
-
314
- // ../core/src/schema-text.ts
315
- const indentWidth = 2;
316
- const maximumDepth = 8;
317
- const maximumLines = 400;
318
- const maximumLineLength = 400;
319
- const maximumCharacters = 1e5;
320
- const maximumTypeLength = 200;
321
- const maximumDescriptionLength = 4e3;
322
- /** Enum values, tuple elements and union options named in a type before the rest are counted. */
323
- const maximumNamedValues = 10;
324
- /** How deep array items, unions and `allOf` members are followed when looking for fields. */
325
- const maximumNesting = 64;
326
- /**
327
- * Caps the reference lookups behind one schema, so schemas whose references fan out are cut
328
- * short instead of stalling the TUI.
329
- */
330
- const maximumReferenceLookups = 5e4;
331
- /** Thrown when a schema would take more lines, text or lookups than a detail view shows. */
332
- var SchemaTooLarge = class extends Error {};
333
- function shortened(text, maximumLength) {
334
- return text.length > maximumLength ? `${text.slice(0, maximumLength - 1)}…` : text;
335
- }
336
- /** Keeps a line within the line length, ending a cut line with "…". */
337
- function fittedLine(line) {
338
- let remaining = maximumLineLength;
339
- const fitted = [];
340
- for (const segment of line) {
341
- if (segment.text.length < remaining) {
342
- fitted.push(segment);
343
- remaining -= segment.text.length;
344
- continue;
345
- }
346
- fitted.push({
347
- ...segment,
348
- text: shortened(segment.text, remaining)
122
+ // ../core/src/errors.ts
123
+ /** A readable message for anything a host or its client throws or returns as an error. */
124
+ function errorText(error) {
125
+ if (error instanceof Error) return error.message;
126
+ if (typeof error === "object" && error !== null) {
127
+ const record = error;
128
+ if (typeof record.message === "string") return record.message;
129
+ if (typeof record.data?.message === "string") return record.data.message;
130
+ return JSON.stringify(error);
131
+ }
132
+ return String(error);
133
+ }
134
+
135
+ // ../core/src/schema-text.ts
136
+ const indentWidth = 2;
137
+ const maximumDepth = 8;
138
+ const maximumLines = 400;
139
+ const maximumLineLength = 400;
140
+ const maximumCharacters = 1e5;
141
+ const maximumTypeLength = 200;
142
+ const maximumDescriptionLength = 4e3;
143
+ /** Enum values, tuple elements and union options named in a type before the rest are counted. */
144
+ const maximumNamedValues = 10;
145
+ /** How deep array items, unions and `allOf` members are followed when looking for fields. */
146
+ const maximumNesting = 64;
147
+ /**
148
+ * Caps the reference lookups behind one schema, so schemas whose references fan out are cut
149
+ * short instead of stalling the TUI.
150
+ */
151
+ const maximumReferenceLookups = 5e4;
152
+ /** Thrown when a schema would take more lines, text or lookups than a detail view shows. */
153
+ var SchemaTooLarge = class extends Error {};
154
+ function shortened(text, maximumLength) {
155
+ return text.length > maximumLength ? `${text.slice(0, maximumLength - 1)}…` : text;
156
+ }
157
+ /** Keeps a line within the line length, ending a cut line with "…". */
158
+ function fittedLine(line) {
159
+ let remaining = maximumLineLength;
160
+ const fitted = [];
161
+ for (const segment of line) {
162
+ if (segment.text.length < remaining) {
163
+ fitted.push(segment);
164
+ remaining -= segment.text.length;
165
+ continue;
166
+ }
167
+ fitted.push({
168
+ ...segment,
169
+ text: shortened(segment.text, remaining)
349
170
  });
350
171
  break;
351
172
  }
@@ -398,7 +219,7 @@ function plain(text) {
398
219
  tone: "plain"
399
220
  };
400
221
  }
401
- function muted$2(text) {
222
+ function muted$1(text) {
402
223
  return {
403
224
  text,
404
225
  tone: "muted"
@@ -445,9 +266,9 @@ function pointerTarget(root, reference) {
445
266
  }
446
267
  const definitionSections = ["#/$defs/", "#/definitions/"];
447
268
  /**
448
- * The schema a local reference names, and the reference as the schema spells it. OpenCode 1.19
449
- * and Kilo 7.8 rename zod's `$defs` to `definitions` without rewriting the references to them,
450
- * so a miss under either name is retried under the other.
269
+ * The schema a local reference names, and the reference as the schema spells it. Hosts with the
270
+ * OpenCode 1 plugin API, such as Kilo 7.8, rename zod's `$defs` to `definitions` without
271
+ * rewriting the references to them, so a miss under either name is retried under the other.
451
272
  */
452
273
  function referenceTarget(root, reference) {
453
274
  const target = pointerTarget(root, reference);
@@ -619,10 +440,7 @@ function typeName(schema, rendering, visiting, depth) {
619
440
  return node.items === void 0 || Array.isArray(node.items) ? "array" : `array of ${pluralType(nestedName(node.items))}`;
620
441
  };
621
442
  if (Object.hasOwn(node, "const")) return literal(node.const);
622
- if (Array.isArray(node.enum) && node.enum.length > 0) {
623
- const values = node.enum;
624
- return namedValues(values, literal, " | ");
625
- }
443
+ if (Array.isArray(node.enum) && node.enum.length > 0) return namedValues(node.enum, literal, " | ");
626
444
  const alternatives = variants(node);
627
445
  if (alternatives !== void 0) return namedValues(alternatives, nestedName, " | ", { distinct: true });
628
446
  const type = node.type;
@@ -736,7 +554,7 @@ function writeProperties(rendering, objectSchema, visiting, depth, path) {
736
554
  */
737
555
  const writeListedAt = (listing) => {
738
556
  if (listing === void 0) return false;
739
- write(rendering, [plain(indentText(depth + 1)), muted$2(`Same fields as ${listing.path}.`)]);
557
+ write(rendering, [plain(indentText(depth + 1)), muted$1(`Same fields as ${listing.path}.`)]);
740
558
  return true;
741
559
  };
742
560
  const listingOf = (definition) => definition === void 0 ? void 0 : rendering.listedDefinitions.get(definition);
@@ -777,183 +595,459 @@ function writeProperties(rendering, objectSchema, visiting, depth, path) {
777
595
  write(rendering, [
778
596
  plain(indentText(depth)),
779
597
  {
780
- text: name,
781
- tone: "name"
598
+ text: name,
599
+ tone: "name"
600
+ },
601
+ muted$1(` ${details.join(", ")}`)
602
+ ]);
603
+ writeDescription(rendering, resolved.description, depth + 1);
604
+ const fields = isObject(property) ? nestedObject(property, rendering, visiting) ?? objectUnion(property, rendering, visiting) : void 0;
605
+ if (fields !== void 0) writeFields(fields, fieldPath);
606
+ else if (isObject(property)) writeListedAt(listingOf(recursiveDefinition(property, rendering, visiting)));
607
+ }
608
+ }
609
+ if (rendering.cutMerges.has(objectSchema)) write(rendering, [plain(`${indentText(depth)}…`)]);
610
+ if (properties.length > 0 && listedOptions.length > 0) write(rendering, [plain(indentText(depth)), muted$1("And one of:")]);
611
+ listedOptions.forEach((variant, index) => {
612
+ const heading = [plain(indentText(depth)), {
613
+ text: `Option ${index + 1}`,
614
+ tone: "name"
615
+ }];
616
+ write(rendering, heading);
617
+ const linesAfterHeading = rendering.lines.length;
618
+ const fields = isObject(variant) ? nestedObject(variant, rendering, visiting) : void 0;
619
+ if (fields !== void 0) writeFields(fields, `${path === "" ? "" : `${path} `}option ${index + 1}`);
620
+ if (rendering.lines.length === linesAfterHeading) rendering.lines[linesAfterHeading - 1] = [...heading, muted$1(` ${typeName(variant, rendering, visiting, depth)}`)];
621
+ });
622
+ }
623
+ function rawSchemaLines(hostName, schema) {
624
+ return [[muted$1(`${hostName} reported this input schema:`)], ...JSON.stringify(schema, void 0, indentWidth).split("\n").map((line) => [muted$1(line)])];
625
+ }
626
+ function capped(lines) {
627
+ if (lines.length <= maximumLines) return lines;
628
+ return [...lines.slice(0, maximumLines), [muted$1(`… ${lines.length - maximumLines} more lines not shown.`)]];
629
+ }
630
+ function rootLines(rendering, schema) {
631
+ const noneVisiting = /* @__PURE__ */ new Set();
632
+ const nested = nestedObject(schema, rendering, noneVisiting);
633
+ if (nested !== void 0) {
634
+ writeProperties(rendering, nested.node, nested.visiting, 0, "");
635
+ if (rendering.lines.length > 0) return rendering.lines;
636
+ }
637
+ const resolved = resolveReference(schema, rendering, noneVisiting).node;
638
+ const merged = mergedAllOf(resolved, rendering, noneVisiting);
639
+ if (variants(merged)?.some((variant) => informativeVariant(variant, rendering, noneVisiting)) === true) {
640
+ write(rendering, [muted$1("Takes one of these inputs:")]);
641
+ writeProperties(rendering, merged, noneVisiting, 0, "");
642
+ return rendering.lines;
643
+ }
644
+ const type = typeName(schema, rendering, noneVisiting, 0);
645
+ if (type === "object" || type === "any") return hasCombinators(resolved) ? capped(rawSchemaLines(rendering.hostName, schema)) : [[muted$1("Takes no input.")]];
646
+ return [[plain("Input is "), {
647
+ text: type,
648
+ tone: "name"
649
+ }]];
650
+ }
651
+ /**
652
+ * Renders a tool's input JSON schema as indented, readable lines. A shared definition's fields
653
+ * are listed once, and a schema too large to show is cut short with a note. `hostName` names the
654
+ * host in notes about what it reported.
655
+ */
656
+ function schemaLines(schema, hostName) {
657
+ if (!isObject(schema)) return [[muted$1(`${hostName} did not report an input schema.`)]];
658
+ const rendering = {
659
+ hostName,
660
+ root: schema,
661
+ lines: [],
662
+ remainingLookups: maximumReferenceLookups,
663
+ remainingCharacters: maximumCharacters,
664
+ listedDefinitions: /* @__PURE__ */ new Map(),
665
+ depthCutoffs: 0,
666
+ typedFields: /* @__PURE__ */ new Map(),
667
+ cutMerges: /* @__PURE__ */ new WeakSet()
668
+ };
669
+ try {
670
+ return rootLines(rendering, schema);
671
+ } catch (error) {
672
+ if (error instanceof SchemaTooLarge && rendering.lines.length > 0) return [...rendering.lines, [muted$1("… Schema too large to show in full.")]];
673
+ return capped(rawSchemaLines(rendering.hostName, schema));
674
+ }
675
+ }
676
+ function linesText(lines) {
677
+ return lines.map((line) => line.map((segment) => segment.text).join("")).join("\n");
678
+ }
679
+
680
+ // ../core/src/tool-detail.ts
681
+ function muted(text) {
682
+ return [[{
683
+ text,
684
+ tone: "muted"
685
+ }]];
686
+ }
687
+ /** A text as plain lines, without the whitespace around it. */
688
+ function textLines(text) {
689
+ return text.trim().split(/\r?\n/).map((line) => [{
690
+ text: line,
691
+ tone: "plain"
692
+ }]);
693
+ }
694
+ /**
695
+ * The detail view's content. The Agents section is left out when the host's agents couldn't be
696
+ * read, and `inputNotice` replaces the input's fields when the host couldn't describe them.
697
+ */
698
+ function toolDetail(host, tool, subtitle, access, inputNotice) {
699
+ const detailsMissing = `${host.name} reported only this tool's name.`;
700
+ return {
701
+ title: tool.id,
702
+ subtitle,
703
+ sections: [
704
+ {
705
+ heading: "Input",
706
+ lines: inputNotice !== void 0 ? muted(inputNotice) : tool.description === void 0 && tool.parameters === void 0 ? muted(detailsMissing) : schemaLines(tool.parameters, host.name)
707
+ },
708
+ ...access === void 0 ? [] : [{
709
+ heading: "Agents",
710
+ lines: agentAccessLines(access, host)
711
+ }],
712
+ {
713
+ heading: "Description",
714
+ lines: tool.description === void 0 ? muted(detailsMissing) : tool.description.trim() === "" ? muted("No description.") : textLines(tool.description)
715
+ }
716
+ ]
717
+ };
718
+ }
719
+ /** The plain-text fallback can't scroll, so long sections are cut short. */
720
+ const plainTextSectionLines = 20;
721
+ /** A tool's detail as one message, for hosts whose OpenTUI the detail view can't load. */
722
+ function plainTextDetail(detail) {
723
+ return detail.sections.map((section) => `${section.heading}\n${linesText(section.lines.slice(0, plainTextSectionLines))}${section.lines.length > plainTextSectionLines ? "\n…" : ""}`).join("\n\n");
724
+ }
725
+
726
+ // ../core/src/tools.ts
727
+ function isRecord$1(value) {
728
+ return typeof value === "object" && value !== null;
729
+ }
730
+ const summaryLength = 100;
731
+ /** The first line of a description without its list marker, short enough for one list row. */
732
+ function descriptionSummary(description) {
733
+ const firstLine = description?.split(/\r?\n/).map((line) => line.trim().replace(/^[-*•]\s+/, "")).find((line) => line !== "") ?? "";
734
+ return firstLine.length > summaryLength ? `${firstLine.slice(0, 99).trimEnd()}…` : firstLine;
735
+ }
736
+ /**
737
+ * The number of top-level input properties, or undefined when the schema has none to count, such
738
+ * as a union beside empty `properties`.
739
+ */
740
+ function inputCount(parameters) {
741
+ if (!isRecord$1(parameters) || !isRecord$1(parameters.properties)) return;
742
+ const count = Object.keys(parameters.properties).length;
743
+ return count === 0 && (parameters.anyOf !== void 0 || parameters.oneOf !== void 0) ? void 0 : count;
744
+ }
745
+ /** A tool's input count for its list row, such as "2 inputs". */
746
+ function inputCountLabel(tool) {
747
+ const count = inputCount(tool.parameters);
748
+ if (count === void 0) return;
749
+ return count === 1 ? "1 input" : `${count} inputs`;
750
+ }
751
+
752
+ // src/agents.ts
753
+ /**
754
+ * Works out which agents may use each tool, following the permission rules
755
+ * Kilo 7.8 applies when it offers tools to a model and when a tool asks for
756
+ * permission.
757
+ *
758
+ * Pass the agents from `client.app.agents()` and either the items of
759
+ * `client.tool.list({ provider, model })` or the ids from `client.tool.ids()`.
760
+ * Each agent's `permission` ruleset already combines the host's defaults, the
761
+ * global `permission` and legacy `tools` settings and the agent's own rules,
762
+ * and disabled agents are already left out. Only permissions are applied here:
763
+ * the host also withholds some tools depending on the model, such as
764
+ * `websearch` without a search provider, and `tool.list` already leaves those
765
+ * out for the model it is given. Kilo also applies input-sensitive guards,
766
+ * saved approvals and hard limits at call time, which these rules don't show.
767
+ */
768
+ const editTools = /* @__PURE__ */ new Set([
769
+ "edit",
770
+ "write",
771
+ "apply_patch"
772
+ ]);
773
+ const mcpResourceReadTools = /* @__PURE__ */ new Set([
774
+ "list_mcp_resources",
775
+ "list_mcp_resource_templates",
776
+ "read_mcp_resource"
777
+ ]);
778
+ function readRule(value) {
779
+ const permission = field(value, "permission");
780
+ const pattern = field(value, "pattern");
781
+ const action = field(value, "action");
782
+ if (typeof permission !== "string" || typeof pattern !== "string" || !isPermissionAction(action)) return;
783
+ return {
784
+ permission,
785
+ pattern,
786
+ action
787
+ };
788
+ }
789
+ function readRuleset(value) {
790
+ if (!Array.isArray(value)) return;
791
+ const rules = [];
792
+ for (const item of value) {
793
+ const rule = readRule(item);
794
+ if (rule === void 0) return;
795
+ rules.push(rule);
796
+ }
797
+ return rules;
798
+ }
799
+ function readStringList(value) {
800
+ if (value === void 0) return [];
801
+ if (!Array.isArray(value)) return;
802
+ const strings = [];
803
+ for (const item of value) {
804
+ if (typeof item !== "string") return;
805
+ strings.push(item);
806
+ }
807
+ return strings;
808
+ }
809
+ function readItems(value) {
810
+ return Array.isArray(value) ? value : [];
811
+ }
812
+ function readAgent(value) {
813
+ const name = field(value, "name");
814
+ if (typeof name !== "string") return;
815
+ const mode = field(value, "mode");
816
+ return {
817
+ name,
818
+ mode: typeof mode === "string" ? mode : void 0,
819
+ hidden: field(value, "hidden") === true,
820
+ native: field(value, "native") === true,
821
+ permission: field(value, "permission")
822
+ };
823
+ }
824
+ function readToolId(value) {
825
+ const id = typeof value === "string" ? value : field(value, "id");
826
+ return typeof id === "string" ? id : void 0;
827
+ }
828
+ /**
829
+ * The host withholds a tool only when the last rule for its permission denies the `*` pattern, so
830
+ * a tool can be offered even when every call is denied.
831
+ */
832
+ function offered(matching) {
833
+ const lastRule = matching.at(-1);
834
+ return !(lastRule?.pattern === "*" && lastRule.action === "deny");
835
+ }
836
+ function denyAll(permission) {
837
+ return {
838
+ permission,
839
+ pattern: "*",
840
+ action: "deny"
841
+ };
842
+ }
843
+ function subagentSessionRules(agentRules, parentSessionRules, primaryTools) {
844
+ const namesPermission = (permission) => agentRules.some((rule) => rule.permission === permission);
845
+ const inherited = [...parentSessionRules.filter((rule) => rule.action === "deny" || rule.permission === "external_directory"), ...["todowrite", "task"].filter((permission) => !namesPermission(permission)).map(denyAll)];
846
+ const isInherited = (deny) => inherited.some((rule) => rule.permission === deny.permission && rule.pattern === deny.pattern && rule.action === deny.action);
847
+ return [...inherited, ...primaryTools.map(denyAll).filter((deny) => !isInherited(deny))];
848
+ }
849
+ function agentAccess(agent, permission, sessionRules, primaryTools) {
850
+ const mode = readMode(agent.mode);
851
+ const summary = {
852
+ agent: agent.name,
853
+ mode,
854
+ hidden: agent.hidden === true,
855
+ native: agent.native === true
856
+ };
857
+ const agentRules = readRuleset(agent.permission);
858
+ if (agentRules === void 0) return {
859
+ ...summary,
860
+ ...unknownDecision
861
+ };
862
+ const primaryDecision = () => sessionRules === void 0 ? unknownDecision : decide(permission, [...agentRules, ...sessionRules], offered);
863
+ const subagentDecision = () => primaryTools === void 0 || sessionRules === void 0 ? unknownDecision : decide(permission, [...agentRules, ...subagentSessionRules(agentRules, sessionRules, primaryTools)], offered);
864
+ switch (mode) {
865
+ case "subagent": return {
866
+ ...summary,
867
+ ...subagentDecision()
868
+ };
869
+ case "all": {
870
+ const asPrimary = primaryDecision();
871
+ const asSubagent = subagentDecision();
872
+ return sameDecision(asPrimary, asSubagent) ? {
873
+ ...summary,
874
+ ...asPrimary
875
+ } : {
876
+ ...summary,
877
+ ...asPrimary,
878
+ whenSubagent: asSubagent
879
+ };
880
+ }
881
+ case "primary":
882
+ case "unknown": return {
883
+ ...summary,
884
+ ...primaryDecision()
885
+ };
886
+ }
887
+ }
888
+ function permissionForTool(toolId) {
889
+ if (editTools.has(toolId)) return "edit";
890
+ if (mcpResourceReadTools.has(toolId)) return "read";
891
+ return toolId;
892
+ }
893
+ function resolveToolAgentAccess(tools, agents, options = {}) {
894
+ const sessionRules = readRuleset(field(options, "sessionPermission") ?? []);
895
+ const primaryTools = readStringList(field(options, "primaryTools"));
896
+ const readableAgents = readItems(agents).map(readAgent).filter((agent) => agent !== void 0);
897
+ return readItems(tools).map(readToolId).filter((tool) => tool !== void 0).map((tool) => {
898
+ const permission = permissionForTool(tool);
899
+ return {
900
+ tool,
901
+ permission,
902
+ agents: readableAgents.map((agent) => agentAccess(agent, permission, sessionRules, primaryTools))
903
+ };
904
+ });
905
+ }
906
+
907
+ // src/detail-viewer.ts
908
+ const chromeRows = 9;
909
+ /** Renders a tool's detail sections in a keyboard-scrollable box inside the host's dialog frame. */
910
+ async function createDetailViewer(api) {
911
+ const { BoxRenderable, RenderableEvents, ScrollBoxRenderable, StyledText, TextAttributes, TextRenderable } = await import("@opentui/core");
912
+ return (detail) => {
913
+ const { renderer } = api;
914
+ const theme = api.theme.current;
915
+ const toneColours = {
916
+ plain: theme.text,
917
+ name: theme.text,
918
+ muted: theme.textMuted
919
+ };
920
+ const styled = (lines) => new StyledText(lines.flatMap((line, index) => [...index === 0 ? [] : [{
921
+ __isChunk: true,
922
+ text: "\n"
923
+ }], ...line.map((segment) => ({
924
+ __isChunk: true,
925
+ text: segment.text,
926
+ fg: toneColours[segment.tone],
927
+ ...segment.tone === "name" ? { attributes: TextAttributes.BOLD } : {}
928
+ }))]));
929
+ const rows = () => Math.max(1, renderer.height - Math.floor(renderer.height / 4) - chromeRows);
930
+ const view = new BoxRenderable(renderer, {
931
+ flexDirection: "column",
932
+ paddingX: 2,
933
+ paddingBottom: 1,
934
+ gap: 1
935
+ });
936
+ view.add(new TextRenderable(renderer, {
937
+ content: detail.title,
938
+ fg: theme.text,
939
+ attributes: TextAttributes.BOLD,
940
+ selectable: false
941
+ }));
942
+ const body = new BoxRenderable(renderer, {
943
+ flexDirection: "column",
944
+ gap: 1
945
+ });
946
+ if (detail.subtitle !== void 0) body.add(new TextRenderable(renderer, {
947
+ content: detail.subtitle,
948
+ fg: theme.textMuted,
949
+ wrapMode: "word"
950
+ }));
951
+ for (const section of detail.sections) {
952
+ const block = new BoxRenderable(renderer, { flexDirection: "column" });
953
+ block.add(new TextRenderable(renderer, {
954
+ content: section.heading,
955
+ fg: theme.accent,
956
+ attributes: TextAttributes.BOLD,
957
+ selectable: false
958
+ }));
959
+ block.add(new TextRenderable(renderer, {
960
+ content: styled(section.lines),
961
+ fg: theme.text,
962
+ wrapMode: "word"
963
+ }));
964
+ body.add(block);
965
+ }
966
+ const unwrappedRows = detail.sections.reduce((total, section) => total + section.lines.length + 2, detail.subtitle === void 0 ? 0 : 2);
967
+ const scroll = new ScrollBoxRenderable(renderer, {
968
+ height: Math.min(rows(), unwrappedRows),
969
+ flexShrink: 0,
970
+ verticalScrollbarOptions: {
971
+ paddingLeft: 1,
972
+ trackOptions: {
973
+ backgroundColor: theme.backgroundElement,
974
+ foregroundColor: theme.border
975
+ }
976
+ }
977
+ });
978
+ const fit = () => {
979
+ if (!scroll.isDestroyed) scroll.height = Math.max(1, Math.min(rows(), body.height));
980
+ };
981
+ body.onSizeChange = fit;
982
+ scroll.add(body);
983
+ view.add(scroll);
984
+ view.add(new TextRenderable(renderer, {
985
+ content: "↑/↓ scroll · pgup/pgdn page · home/end · esc back",
986
+ fg: theme.textMuted,
987
+ selectable: false
988
+ }));
989
+ renderer.on("resize", fit);
990
+ const unbind = api.keymap.registerLayer({
991
+ target: scroll,
992
+ targetMode: "focus",
993
+ bindings: [
994
+ {
995
+ key: "pageup",
996
+ cmd: () => scroll.scrollBy(-.5, "viewport")
997
+ },
998
+ {
999
+ key: "pagedown",
1000
+ cmd: () => scroll.scrollBy(.5, "viewport")
782
1001
  },
783
- muted$2(` ${details.join(", ")}`)
784
- ]);
785
- writeDescription(rendering, resolved.description, depth + 1);
786
- const fields = isObject(property) ? nestedObject(property, rendering, visiting) ?? objectUnion(property, rendering, visiting) : void 0;
787
- if (fields !== void 0) writeFields(fields, fieldPath);
788
- else if (isObject(property)) writeListedAt(listingOf(recursiveDefinition(property, rendering, visiting)));
789
- }
790
- }
791
- if (rendering.cutMerges.has(objectSchema)) write(rendering, [plain(`${indentText(depth)}…`)]);
792
- if (properties.length > 0 && listedOptions.length > 0) write(rendering, [plain(indentText(depth)), muted$2("And one of:")]);
793
- listedOptions.forEach((variant, index) => {
794
- const heading = [plain(indentText(depth)), {
795
- text: `Option ${index + 1}`,
796
- tone: "name"
797
- }];
798
- write(rendering, heading);
799
- const linesAfterHeading = rendering.lines.length;
800
- const fields = isObject(variant) ? nestedObject(variant, rendering, visiting) : void 0;
801
- if (fields !== void 0) writeFields(fields, `${path === "" ? "" : `${path} `}option ${index + 1}`);
802
- if (rendering.lines.length === linesAfterHeading) rendering.lines[linesAfterHeading - 1] = [...heading, muted$2(` ${typeName(variant, rendering, visiting, depth)}`)];
803
- });
804
- }
805
- function rawSchemaLines(hostName, schema) {
806
- return [[muted$2(`${hostName} reported this input schema:`)], ...JSON.stringify(schema, void 0, indentWidth).split("\n").map((line) => [muted$2(line)])];
807
- }
808
- function capped(lines) {
809
- if (lines.length <= maximumLines) return lines;
810
- return [...lines.slice(0, maximumLines), [muted$2(`… ${lines.length - maximumLines} more lines not shown.`)]];
811
- }
812
- function rootLines(rendering, schema) {
813
- const noneVisiting = /* @__PURE__ */ new Set();
814
- const nested = nestedObject(schema, rendering, noneVisiting);
815
- if (nested !== void 0) {
816
- writeProperties(rendering, nested.node, nested.visiting, 0, "");
817
- if (rendering.lines.length > 0) return rendering.lines;
818
- }
819
- const resolved = resolveReference(schema, rendering, noneVisiting).node;
820
- const merged = mergedAllOf(resolved, rendering, noneVisiting);
821
- if (variants(merged)?.some((variant) => informativeVariant(variant, rendering, noneVisiting)) === true) {
822
- write(rendering, [muted$2("Takes one of these inputs:")]);
823
- writeProperties(rendering, merged, noneVisiting, 0, "");
824
- return rendering.lines;
825
- }
826
- const type = typeName(schema, rendering, noneVisiting, 0);
827
- if (type === "object" || type === "any") return hasCombinators(resolved) ? capped(rawSchemaLines(rendering.hostName, schema)) : [[muted$2("Takes no input.")]];
828
- return [[plain("Input is "), {
829
- text: type,
830
- tone: "name"
831
- }]];
832
- }
833
- /**
834
- * Renders a tool's input JSON schema as indented, readable lines. A shared definition's fields
835
- * are listed once, and a schema too large to show is cut short with a note. `hostName` names the
836
- * host in notes about what it reported.
837
- */
838
- function schemaLines(schema, hostName) {
839
- if (!isObject(schema)) return [[muted$2(`${hostName} did not report an input schema.`)]];
840
- const rendering = {
841
- hostName,
842
- root: schema,
843
- lines: [],
844
- remainingLookups: maximumReferenceLookups,
845
- remainingCharacters: maximumCharacters,
846
- listedDefinitions: /* @__PURE__ */ new Map(),
847
- depthCutoffs: 0,
848
- typedFields: /* @__PURE__ */ new Map(),
849
- cutMerges: /* @__PURE__ */ new WeakSet()
850
- };
851
- try {
852
- return rootLines(rendering, schema);
853
- } catch (error) {
854
- if (error instanceof SchemaTooLarge && rendering.lines.length > 0) return [...rendering.lines, [muted$2("… Schema too large to show in full.")]];
855
- return capped(rawSchemaLines(rendering.hostName, schema));
856
- }
857
- }
858
- function linesText(lines) {
859
- return lines.map((line) => line.map((segment) => segment.text).join("")).join("\n");
860
- }
861
-
862
- // ../core/src/agent-text.ts
863
- function muted$1(text) {
864
- return {
865
- text,
866
- tone: "muted"
1002
+ {
1003
+ key: "home",
1004
+ cmd: () => scroll.scrollBy(-1, "content")
1005
+ },
1006
+ {
1007
+ key: "end",
1008
+ cmd: () => scroll.scrollBy(1, "content")
1009
+ }
1010
+ ]
1011
+ });
1012
+ const focus = setTimeout(() => {
1013
+ if (!scroll.isDestroyed && !api.lifecycle.signal.aborted) scroll.focus();
1014
+ }, 1);
1015
+ const dispose = () => view.destroyRecursively();
1016
+ api.lifecycle.signal.addEventListener("abort", dispose, { once: true });
1017
+ view.on(RenderableEvents.DESTROYED, () => {
1018
+ clearTimeout(focus);
1019
+ renderer.off("resize", fit);
1020
+ unbind();
1021
+ api.lifecycle.signal.removeEventListener("abort", dispose);
1022
+ });
1023
+ return view;
867
1024
  };
868
1025
  }
869
- function decisionSummary(decision, actionLabels) {
870
- if (decision.access === "unknown") return "Unknown";
871
- if (decision.offeredToModel === false) return actionLabels.deny;
872
- return actionLabels[decision.access];
873
- }
874
- function exceptionLines(decision, actionLabels) {
875
- if (decision.offeredToModel === false) return [];
876
- return decision.exceptions.map((exception) => [{
877
- text: ` ${exception.pattern}`,
878
- tone: "name"
879
- }, muted$1(`: ${actionLabels[exception.access]}`)]);
880
- }
881
- function agentLines(agent, actionLabels) {
882
- return [[{
883
- text: agent.agent,
884
- tone: "name"
885
- }, muted$1(` ${decisionSummary(agent, actionLabels)}`)], ...exceptionLines(agent, actionLabels)];
886
- }
887
- /** The host's own hidden agents, such as `compaction` and `title`, never take tool calls. */
888
- function listed(agent) {
889
- return !(agent.native && agent.hidden);
890
- }
891
- function primaryFirst(left, right) {
892
- const rank = (agent) => agent.mode === "subagent" ? 1 : 0;
893
- return rank(left) - rank(right);
894
- }
895
- function notesFor(notes, key) {
896
- return notes !== void 0 && Object.hasOwn(notes, key) ? notes[key] : [];
897
- }
898
- function accessNoteLines(notes, access) {
899
- return [
900
- ...notes.always ?? [],
901
- ...notesFor(notes.permission, access.permission),
902
- ...notesFor(notes.tool, access.tool)
903
- ].map((note) => [muted$1(note)]);
904
- }
905
- /** Renders which agents can use a tool, primary agents first. */
906
- function agentAccessLines(access, host) {
907
- const { actionLabels } = host;
908
- const agents = access.agents.filter(listed).sort(primaryFirst);
909
- if (agents.length === 0) return [[muted$1(`${host.name} reported no agents that use tools.`)]];
910
- return [
911
- ...access.permission === access.tool ? [] : [[muted$1(`Checked as the ${access.permission} permission.`)]],
912
- ...accessNoteLines(host.accessNotes, access),
913
- ...agents.flatMap((agent) => agentLines(agent, actionLabels))
914
- ];
915
- }
916
1026
 
917
- // ../core/src/tool-detail.ts
918
- function muted(text) {
919
- return [[{
920
- text,
921
- tone: "muted"
922
- }]];
923
- }
924
- function textLines(text) {
925
- return text.trim().split(/\r?\n/).map((line) => [{
926
- text: line,
927
- tone: "plain"
928
- }]);
929
- }
1027
+ // src/host.ts
1028
+ const protectedConfigPaths = ["Kilo checks protected config paths separately; broad read grants do not automatically authorize sensitive .env files."];
930
1029
  /**
931
- * The detail view's content. The Agents section is left out when the host's agents couldn't be
932
- * read.
1030
+ * Kilo applies call-time checks beyond the configured rules, so its notes distinguish the
1031
+ * configured permissions from a final authorization decision.
933
1032
  */
934
- function toolDetail(host, tool, modelLabel, access) {
935
- const detailsMissing = `${host.name} reported only this tool's name.`;
936
- return {
937
- title: tool.id,
938
- subtitle: modelLabel === void 0 ? void 0 : `As offered to ${modelLabel}`,
939
- sections: [
940
- {
941
- heading: "Input",
942
- lines: tool.description === void 0 && tool.parameters === void 0 ? muted(detailsMissing) : schemaLines(tool.parameters, host.name)
943
- },
944
- ...access === void 0 ? [] : [{
945
- heading: "Agents",
946
- lines: agentAccessLines(access, host)
947
- }],
948
- {
949
- heading: "Description",
950
- lines: tool.description === void 0 ? muted(detailsMissing) : tool.description.trim() === "" ? muted("No description.") : textLines(tool.description)
951
- }
952
- ]
953
- };
954
- }
1033
+ const kiloHost = {
1034
+ name: "Kilo",
1035
+ actionLabels: {
1036
+ allow: "Allow",
1037
+ ask: "Ask",
1038
+ deny: "Deny"
1039
+ },
1040
+ accessNotes: {
1041
+ always: ["Configured rules only. Kilo can still ask or deny at call time; saved approvals, hard limits, skill commands and sandbox escalation are not resolved here."],
1042
+ permission: {
1043
+ read: protectedConfigPaths,
1044
+ edit: protectedConfigPaths
1045
+ },
1046
+ tool: { agent_manager: ["Agent manager prompt, stop, move and answer actions need exact action rules; broad grants can still ask first."] }
1047
+ }
1048
+ };
955
1049
 
956
- // ../core/src/tools.ts
1050
+ // src/tool-list.ts
957
1051
  const sourceLabels = {
958
1052
  session: "this session's model",
959
1053
  configured: "configured model",
@@ -1028,36 +1122,9 @@ function toolsFromIds(response) {
1028
1122
  parameters: void 0
1029
1123
  })).sort(byId);
1030
1124
  }
1031
- const summaryLength = 100;
1032
- /** The first line of a description without its list marker, short enough for one list row. */
1033
- function descriptionSummary(description) {
1034
- const firstLine = description?.split(/\r?\n/).map((line) => line.trim().replace(/^[-*•]\s+/, "")).find((line) => line !== "") ?? "";
1035
- return firstLine.length > summaryLength ? `${firstLine.slice(0, 99).trimEnd()}…` : firstLine;
1036
- }
1037
- /**
1038
- * The number of top-level input properties, or undefined when the schema has none to count, such
1039
- * as a union beside empty `properties`.
1040
- */
1041
- function inputCount(parameters) {
1042
- if (!isRecord(parameters) || !isRecord(parameters.properties)) return;
1043
- const count = Object.keys(parameters.properties).length;
1044
- return count === 0 && (parameters.anyOf !== void 0 || parameters.oneOf !== void 0) ? void 0 : count;
1045
- }
1046
1125
 
1047
- // ../core/src/tui.ts
1126
+ // src/tui.ts
1048
1127
  const toastTitle = "Tool Inspector";
1049
- /** The plain-text fallback can't scroll, so long sections are cut short. */
1050
- const plainTextSectionLines = 20;
1051
- function errorText(error) {
1052
- if (error instanceof Error) return error.message;
1053
- if (typeof error === "object" && error !== null) {
1054
- const record = error;
1055
- if (typeof record.message === "string") return record.message;
1056
- if (typeof record.data?.message === "string") return record.data.message;
1057
- return JSON.stringify(error);
1058
- }
1059
- return String(error);
1060
- }
1061
1128
  /** Names of connected MCP servers, whose tools the host's tool list leaves out. */
1062
1129
  function connectedMcpServers(api) {
1063
1130
  try {
@@ -1066,9 +1133,9 @@ function connectedMcpServers(api) {
1066
1133
  return [];
1067
1134
  }
1068
1135
  }
1069
- function mcpNotice(host, servers) {
1136
+ function mcpNotice(servers) {
1070
1137
  if (servers.length === 0) return;
1071
- return `Tools from MCP servers (${servers.join(", ")}) aren't listed, because ${host.name} only adds them when it runs a prompt.`;
1138
+ return `Tools from MCP servers (${servers.join(", ")}) aren't listed, because ${kiloHost.name} only adds them when it runs a prompt.`;
1072
1139
  }
1073
1140
  function currentSessionId(api) {
1074
1141
  const route = api.route.current;
@@ -1095,8 +1162,8 @@ async function chooseModel(api, signal) {
1095
1162
  source: "provider default"
1096
1163
  };
1097
1164
  }
1098
- async function readAgents(host, api, signal) {
1099
- if (typeof api.client.app?.agents !== "function") throw new Error(`this ${host.name} doesn't list agents`);
1165
+ async function readAgents(api, signal) {
1166
+ if (typeof api.client.app?.agents !== "function") throw new Error(`this ${kiloHost.name} doesn't list agents`);
1100
1167
  const response = await api.client.app.agents({ directory: api.state.path.directory }, { signal });
1101
1168
  if (response.error !== void 0) throw new Error(errorText(response.error));
1102
1169
  const agents = response.data;
@@ -1139,7 +1206,7 @@ function accessByTool(api, tools, agents) {
1139
1206
  });
1140
1207
  return new Map(resolved.map((access) => [access.tool, access]));
1141
1208
  }
1142
- async function readToolList(host, api, signal) {
1209
+ async function readToolList(api, signal) {
1143
1210
  const directory = api.state.path.directory;
1144
1211
  let modelFailure;
1145
1212
  const model = await chooseModel(api, signal).catch((error) => {
@@ -1166,19 +1233,19 @@ async function readToolList(host, api, signal) {
1166
1233
  }
1167
1234
  const response = await api.client.tool.ids({ directory }, { signal });
1168
1235
  const tools = response.error === void 0 ? toolsFromIds(response.data) : void 0;
1169
- if (tools === void 0) throw new Error(listFailure ?? modelFailure ?? (response.error === void 0 ? `${host.name} did not return a readable tool list.` : errorText(response.error)));
1236
+ if (tools === void 0) throw new Error(listFailure ?? modelFailure ?? (response.error === void 0 ? `${kiloHost.name} did not return a readable tool list.` : errorText(response.error)));
1170
1237
  return {
1171
1238
  tools,
1172
1239
  model: void 0,
1173
- notice: model === void 0 ? modelFailure === void 0 ? `No model is selected, so this lists every registered tool without details. Pick a model to see what ${host.name} offers it.` : `Could not work out the current model (${modelFailure}), so this lists tool names only.` : `${host.name} did not return tool details for ${chosenModelLabel(model)} (${listFailure ?? "no reason given"}), so this lists tool names only.`
1240
+ notice: model === void 0 ? modelFailure === void 0 ? `No model is selected, so this lists every registered tool without details. Pick a model to see what ${kiloHost.name} offers it.` : `Could not work out the current model (${modelFailure}), so this lists tool names only.` : `${kiloHost.name} did not return tool details for ${chosenModelLabel(model)} (${listFailure ?? "no reason given"}), so this lists tool names only.`
1174
1241
  };
1175
1242
  }
1176
- async function readCatalog(host, api, signal) {
1243
+ async function readCatalog(api, signal) {
1177
1244
  let agentsFailure;
1178
- const agentsRead = readAgents(host, api, signal).catch((error) => {
1245
+ const agentsRead = readAgents(api, signal).catch((error) => {
1179
1246
  agentsFailure = errorText(error);
1180
1247
  });
1181
- const list = await readToolList(host, api, signal);
1248
+ const list = await readToolList(api, signal);
1182
1249
  const agents = await agentsRead;
1183
1250
  let access;
1184
1251
  if (agents !== void 0) try {
@@ -1189,15 +1256,10 @@ async function readCatalog(host, api, signal) {
1189
1256
  return {
1190
1257
  ...list,
1191
1258
  access,
1192
- agentsNotice: access === void 0 ? `Could not read ${host.name}'s agents (${agentsFailure ?? "no reason given"}), so tool details don't show which agents can use each tool.` : void 0
1259
+ agentsNotice: access === void 0 ? `Could not read ${kiloHost.name}'s agents (${agentsFailure ?? "no reason given"}), so tool details don't show which agents can use each tool.` : void 0
1193
1260
  };
1194
1261
  }
1195
- function inputCountLabel(tool) {
1196
- const count = inputCount(tool.parameters);
1197
- if (count === void 0) return;
1198
- return count === 1 ? "1 input" : `${count} inputs`;
1199
- }
1200
- function registerToolBrowser(host, api) {
1262
+ function registerToolBrowser(api) {
1201
1263
  const toast = (variant, message) => {
1202
1264
  api.ui.toast({
1203
1265
  variant,
@@ -1249,12 +1311,12 @@ function registerToolBrowser(host, api) {
1249
1311
  async detail(catalog, tool) {
1250
1312
  const listRevision = revision;
1251
1313
  const sameView = viewContext();
1252
- const detail = toolDetail(host, tool, catalog.model === void 0 ? void 0 : chosenModelLabel(catalog.model), catalog.access?.get(tool.id));
1314
+ const detail = toolDetail(kiloHost, tool, catalog.model === void 0 ? void 0 : `As offered to ${chosenModelLabel(catalog.model)}`, catalog.access?.get(tool.id));
1253
1315
  const render = await detailViewer();
1254
1316
  if (listRevision !== revision || !sameView()) return;
1255
1317
  display(render === void 0 ? () => api.ui.DialogAlert({
1256
1318
  title: detail.title,
1257
- message: detail.sections.map((section) => `${section.heading}\n${linesText(section.lines.slice(0, plainTextSectionLines))}${section.lines.length > plainTextSectionLines ? "\n…" : ""}`).join("\n\n")
1319
+ message: plainTextDetail(detail)
1258
1320
  }) : () => render(detail), "xlarge", () => {
1259
1321
  const closedRevision = revision;
1260
1322
  queueMicrotask(() => {
@@ -1299,12 +1361,12 @@ function registerToolBrowser(host, api) {
1299
1361
  api.lifecycle.signal.addEventListener("abort", abort, { once: true });
1300
1362
  const loading = display(() => api.ui.DialogAlert({
1301
1363
  title: "Loading tools",
1302
- message: `Reading the tools ${host.name} offers…`
1364
+ message: `Reading the tools ${kiloHost.name} offers…`
1303
1365
  }), "medium", abort);
1304
1366
  activeRead = controller;
1305
1367
  detailViewer().catch(() => void 0);
1306
1368
  try {
1307
- const catalog = await readCatalog(host, api, controller.signal);
1369
+ const catalog = await readCatalog(api, controller.signal);
1308
1370
  if (loading !== revision) return;
1309
1371
  if (!sameView()) {
1310
1372
  close();
@@ -1312,20 +1374,20 @@ function registerToolBrowser(host, api) {
1312
1374
  }
1313
1375
  if (catalog.tools.length === 0) {
1314
1376
  close();
1315
- toast("info", `${host.name} reported no tools.`);
1377
+ toast("info", `${kiloHost.name} reported no tools.`);
1316
1378
  return;
1317
1379
  }
1318
1380
  const notices = [
1319
1381
  catalog.notice,
1320
1382
  catalog.agentsNotice,
1321
- mcpNotice(host, connectedMcpServers(api))
1383
+ mcpNotice(connectedMcpServers(api))
1322
1384
  ].filter((notice) => notice !== void 0);
1323
1385
  if (notices.length > 0) toast(catalog.notice === void 0 && catalog.agentsNotice === void 0 ? "info" : "warning", notices.join(" "));
1324
1386
  views.list(catalog, void 0);
1325
1387
  } catch (error) {
1326
1388
  if (loading === revision) {
1327
1389
  close();
1328
- if (sameView()) toast("warning", `Could not read tools from ${host.name}: ${errorText(error)}`);
1390
+ if (sameView()) toast("warning", `Could not read tools from ${kiloHost.name}: ${errorText(error)}`);
1329
1391
  }
1330
1392
  } finally {
1331
1393
  api.lifecycle.signal.removeEventListener("abort", abort);
@@ -1349,46 +1411,13 @@ function registerToolBrowser(host, api) {
1349
1411
  stopWatching();
1350
1412
  });
1351
1413
  }
1352
- /** The Tool Inspector TUI plugin for one host, typed as the OpenCode package has always exported it. */
1353
- function createToolInspectorTui(host) {
1354
- const tui = (api) => {
1355
- registerToolBrowser(host, api);
1356
- return Promise.resolve();
1357
- };
1358
- return {
1359
- id: "tool-inspector",
1360
- tui
1361
- };
1362
- }
1363
-
1364
- // src/host.ts
1365
- const protectedConfigPaths = ["Kilo checks protected config paths separately; broad read grants do not automatically authorize sensitive .env files."];
1366
- /**
1367
- * Kilo applies call-time checks beyond the configured rules, so its notes distinguish the
1368
- * configured permissions from a final authorization decision.
1369
- */
1370
- const kiloHost = {
1371
- name: "Kilo",
1372
- actionLabels: {
1373
- allow: "Allow",
1374
- ask: "Ask",
1375
- deny: "Deny"
1376
- },
1377
- accessNotes: {
1378
- always: ["Configured rules only. Kilo can still ask or deny at call time; saved approvals, hard limits, skill commands and sandbox escalation are not resolved here."],
1379
- permission: {
1380
- read: protectedConfigPaths,
1381
- edit: protectedConfigPaths
1382
- },
1383
- tool: { agent_manager: ["Agent manager prompt, stop, move and answer actions need exact action rules; broad grants can still ask first."] }
1384
- }
1414
+ const tui = (api) => {
1415
+ registerToolBrowser(api);
1416
+ return Promise.resolve();
1385
1417
  };
1386
-
1387
- // src/tui.ts
1388
- const core = createToolInspectorTui(kiloHost);
1389
- const tui = (api, options, meta) => core.tui(api, options, meta);
1418
+ /** The Tool Inspector TUI plugin. */
1390
1419
  const plugin = {
1391
- id: core.id,
1420
+ id: "tool-inspector",
1392
1421
  tui
1393
1422
  };
1394
1423
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunchbox-labs/kilo-tool-inspector",
3
- "version": "0.3.2",
3
+ "version": "1.0.0",
4
4
  "description": "Inspect the tools available to Kilo agents from the TUI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,8 +29,8 @@
29
29
  "test:package": "node --experimental-strip-types --test tests/package.integration.ts"
30
30
  },
31
31
  "devDependencies": {
32
- "@kilocode/plugin": "7.8.32",
33
- "@kilocode/sdk": "7.8.32",
32
+ "@kilocode/plugin": "7.8.40",
33
+ "@kilocode/sdk": "7.8.40",
34
34
  "@opentui/core": "0.5.11",
35
35
  "@opentui/keymap": "0.5.11",
36
36
  "@opentui/solid": "0.5.11",