@lunchbox-labs/kilo-tool-inspector 0.3.3 → 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.
- package/dist/tui.d.ts +1 -0
- package/dist/tui.js +579 -547
- package/package.json +1 -1
package/dist/tui.d.ts
CHANGED
package/dist/tui.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
// ../core/src/
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
66
|
+
|
|
67
|
+
// ../core/src/agent-text.ts
|
|
68
|
+
function muted$2(text) {
|
|
124
69
|
return {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
action: "deny"
|
|
70
|
+
text,
|
|
71
|
+
tone: "muted"
|
|
128
72
|
};
|
|
129
73
|
}
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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(-.5, "viewport")
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
key: "pagedown",
|
|
287
|
-
cmd: () => scroll.scrollBy(.5, "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$
|
|
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.
|
|
449
|
-
*
|
|
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);
|
|
@@ -733,7 +554,7 @@ function writeProperties(rendering, objectSchema, visiting, depth, path) {
|
|
|
733
554
|
*/
|
|
734
555
|
const writeListedAt = (listing) => {
|
|
735
556
|
if (listing === void 0) return false;
|
|
736
|
-
write(rendering, [plain(indentText(depth + 1)), muted$
|
|
557
|
+
write(rendering, [plain(indentText(depth + 1)), muted$1(`Same fields as ${listing.path}.`)]);
|
|
737
558
|
return true;
|
|
738
559
|
};
|
|
739
560
|
const listingOf = (definition) => definition === void 0 ? void 0 : rendering.listedDefinitions.get(definition);
|
|
@@ -774,183 +595,459 @@ function writeProperties(rendering, objectSchema, visiting, depth, path) {
|
|
|
774
595
|
write(rendering, [
|
|
775
596
|
plain(indentText(depth)),
|
|
776
597
|
{
|
|
777
|
-
text: name,
|
|
778
|
-
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")
|
|
779
1001
|
},
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
function rawSchemaLines(hostName, schema) {
|
|
803
|
-
return [[muted$2(`${hostName} reported this input schema:`)], ...JSON.stringify(schema, void 0, indentWidth).split("\n").map((line) => [muted$2(line)])];
|
|
804
|
-
}
|
|
805
|
-
function capped(lines) {
|
|
806
|
-
if (lines.length <= maximumLines) return lines;
|
|
807
|
-
return [...lines.slice(0, maximumLines), [muted$2(`… ${lines.length - maximumLines} more lines not shown.`)]];
|
|
808
|
-
}
|
|
809
|
-
function rootLines(rendering, schema) {
|
|
810
|
-
const noneVisiting = /* @__PURE__ */ new Set();
|
|
811
|
-
const nested = nestedObject(schema, rendering, noneVisiting);
|
|
812
|
-
if (nested !== void 0) {
|
|
813
|
-
writeProperties(rendering, nested.node, nested.visiting, 0, "");
|
|
814
|
-
if (rendering.lines.length > 0) return rendering.lines;
|
|
815
|
-
}
|
|
816
|
-
const resolved = resolveReference(schema, rendering, noneVisiting).node;
|
|
817
|
-
const merged = mergedAllOf(resolved, rendering, noneVisiting);
|
|
818
|
-
if (variants(merged)?.some((variant) => informativeVariant(variant, rendering, noneVisiting)) === true) {
|
|
819
|
-
write(rendering, [muted$2("Takes one of these inputs:")]);
|
|
820
|
-
writeProperties(rendering, merged, noneVisiting, 0, "");
|
|
821
|
-
return rendering.lines;
|
|
822
|
-
}
|
|
823
|
-
const type = typeName(schema, rendering, noneVisiting, 0);
|
|
824
|
-
if (type === "object" || type === "any") return hasCombinators(resolved) ? capped(rawSchemaLines(rendering.hostName, schema)) : [[muted$2("Takes no input.")]];
|
|
825
|
-
return [[plain("Input is "), {
|
|
826
|
-
text: type,
|
|
827
|
-
tone: "name"
|
|
828
|
-
}]];
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* Renders a tool's input JSON schema as indented, readable lines. A shared definition's fields
|
|
832
|
-
* are listed once, and a schema too large to show is cut short with a note. `hostName` names the
|
|
833
|
-
* host in notes about what it reported.
|
|
834
|
-
*/
|
|
835
|
-
function schemaLines(schema, hostName) {
|
|
836
|
-
if (!isObject(schema)) return [[muted$2(`${hostName} did not report an input schema.`)]];
|
|
837
|
-
const rendering = {
|
|
838
|
-
hostName,
|
|
839
|
-
root: schema,
|
|
840
|
-
lines: [],
|
|
841
|
-
remainingLookups: maximumReferenceLookups,
|
|
842
|
-
remainingCharacters: maximumCharacters,
|
|
843
|
-
listedDefinitions: /* @__PURE__ */ new Map(),
|
|
844
|
-
depthCutoffs: 0,
|
|
845
|
-
typedFields: /* @__PURE__ */ new Map(),
|
|
846
|
-
cutMerges: /* @__PURE__ */ new WeakSet()
|
|
847
|
-
};
|
|
848
|
-
try {
|
|
849
|
-
return rootLines(rendering, schema);
|
|
850
|
-
} catch (error) {
|
|
851
|
-
if (error instanceof SchemaTooLarge && rendering.lines.length > 0) return [...rendering.lines, [muted$2("… Schema too large to show in full.")]];
|
|
852
|
-
return capped(rawSchemaLines(rendering.hostName, schema));
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
function linesText(lines) {
|
|
856
|
-
return lines.map((line) => line.map((segment) => segment.text).join("")).join("\n");
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
// ../core/src/agent-text.ts
|
|
860
|
-
function muted$1(text) {
|
|
861
|
-
return {
|
|
862
|
-
text,
|
|
863
|
-
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;
|
|
864
1024
|
};
|
|
865
1025
|
}
|
|
866
|
-
function decisionSummary(decision, actionLabels) {
|
|
867
|
-
if (decision.access === "unknown") return "Unknown";
|
|
868
|
-
if (decision.offeredToModel === false) return actionLabels.deny;
|
|
869
|
-
return actionLabels[decision.access];
|
|
870
|
-
}
|
|
871
|
-
function exceptionLines(decision, actionLabels) {
|
|
872
|
-
if (decision.offeredToModel === false) return [];
|
|
873
|
-
return decision.exceptions.map((exception) => [{
|
|
874
|
-
text: ` ${exception.pattern}`,
|
|
875
|
-
tone: "name"
|
|
876
|
-
}, muted$1(`: ${actionLabels[exception.access]}`)]);
|
|
877
|
-
}
|
|
878
|
-
function agentLines(agent, actionLabels) {
|
|
879
|
-
return [[{
|
|
880
|
-
text: agent.agent,
|
|
881
|
-
tone: "name"
|
|
882
|
-
}, muted$1(` ${decisionSummary(agent, actionLabels)}`)], ...exceptionLines(agent, actionLabels)];
|
|
883
|
-
}
|
|
884
|
-
/** The host's own hidden agents, such as `compaction` and `title`, never take tool calls. */
|
|
885
|
-
function listed(agent) {
|
|
886
|
-
return !(agent.native && agent.hidden);
|
|
887
|
-
}
|
|
888
|
-
function primaryFirst(left, right) {
|
|
889
|
-
const rank = (agent) => agent.mode === "subagent" ? 1 : 0;
|
|
890
|
-
return rank(left) - rank(right);
|
|
891
|
-
}
|
|
892
|
-
function notesFor(notes, key) {
|
|
893
|
-
return notes !== void 0 && Object.hasOwn(notes, key) ? notes[key] : [];
|
|
894
|
-
}
|
|
895
|
-
function accessNoteLines(notes, access) {
|
|
896
|
-
return [
|
|
897
|
-
...notes.always ?? [],
|
|
898
|
-
...notesFor(notes.permission, access.permission),
|
|
899
|
-
...notesFor(notes.tool, access.tool)
|
|
900
|
-
].map((note) => [muted$1(note)]);
|
|
901
|
-
}
|
|
902
|
-
/** Renders which agents can use a tool, primary agents first. */
|
|
903
|
-
function agentAccessLines(access, host) {
|
|
904
|
-
const { actionLabels } = host;
|
|
905
|
-
const agents = access.agents.filter(listed).sort(primaryFirst);
|
|
906
|
-
if (agents.length === 0) return [[muted$1(`${host.name} reported no agents that use tools.`)]];
|
|
907
|
-
return [
|
|
908
|
-
...access.permission === access.tool ? [] : [[muted$1(`Checked as the ${access.permission} permission.`)]],
|
|
909
|
-
...accessNoteLines(host.accessNotes, access),
|
|
910
|
-
...agents.flatMap((agent) => agentLines(agent, actionLabels))
|
|
911
|
-
];
|
|
912
|
-
}
|
|
913
1026
|
|
|
914
|
-
//
|
|
915
|
-
|
|
916
|
-
return [[{
|
|
917
|
-
text,
|
|
918
|
-
tone: "muted"
|
|
919
|
-
}]];
|
|
920
|
-
}
|
|
921
|
-
function textLines(text) {
|
|
922
|
-
return text.trim().split(/\r?\n/).map((line) => [{
|
|
923
|
-
text: line,
|
|
924
|
-
tone: "plain"
|
|
925
|
-
}]);
|
|
926
|
-
}
|
|
1027
|
+
// src/host.ts
|
|
1028
|
+
const protectedConfigPaths = ["Kilo checks protected config paths separately; broad read grants do not automatically authorize sensitive .env files."];
|
|
927
1029
|
/**
|
|
928
|
-
*
|
|
929
|
-
*
|
|
1030
|
+
* Kilo applies call-time checks beyond the configured rules, so its notes distinguish the
|
|
1031
|
+
* configured permissions from a final authorization decision.
|
|
930
1032
|
*/
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
lines: tool.description === void 0 ? muted(detailsMissing) : tool.description.trim() === "" ? muted("No description.") : textLines(tool.description)
|
|
948
|
-
}
|
|
949
|
-
]
|
|
950
|
-
};
|
|
951
|
-
}
|
|
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
|
+
};
|
|
952
1049
|
|
|
953
|
-
//
|
|
1050
|
+
// src/tool-list.ts
|
|
954
1051
|
const sourceLabels = {
|
|
955
1052
|
session: "this session's model",
|
|
956
1053
|
configured: "configured model",
|
|
@@ -1025,36 +1122,9 @@ function toolsFromIds(response) {
|
|
|
1025
1122
|
parameters: void 0
|
|
1026
1123
|
})).sort(byId);
|
|
1027
1124
|
}
|
|
1028
|
-
const summaryLength = 100;
|
|
1029
|
-
/** The first line of a description without its list marker, short enough for one list row. */
|
|
1030
|
-
function descriptionSummary(description) {
|
|
1031
|
-
const firstLine = description?.split(/\r?\n/).map((line) => line.trim().replace(/^[-*•]\s+/, "")).find((line) => line !== "") ?? "";
|
|
1032
|
-
return firstLine.length > summaryLength ? `${firstLine.slice(0, 99).trimEnd()}…` : firstLine;
|
|
1033
|
-
}
|
|
1034
|
-
/**
|
|
1035
|
-
* The number of top-level input properties, or undefined when the schema has none to count, such
|
|
1036
|
-
* as a union beside empty `properties`.
|
|
1037
|
-
*/
|
|
1038
|
-
function inputCount(parameters) {
|
|
1039
|
-
if (!isRecord(parameters) || !isRecord(parameters.properties)) return;
|
|
1040
|
-
const count = Object.keys(parameters.properties).length;
|
|
1041
|
-
return count === 0 && (parameters.anyOf !== void 0 || parameters.oneOf !== void 0) ? void 0 : count;
|
|
1042
|
-
}
|
|
1043
1125
|
|
|
1044
|
-
//
|
|
1126
|
+
// src/tui.ts
|
|
1045
1127
|
const toastTitle = "Tool Inspector";
|
|
1046
|
-
/** The plain-text fallback can't scroll, so long sections are cut short. */
|
|
1047
|
-
const plainTextSectionLines = 20;
|
|
1048
|
-
function errorText(error) {
|
|
1049
|
-
if (error instanceof Error) return error.message;
|
|
1050
|
-
if (typeof error === "object" && error !== null) {
|
|
1051
|
-
const record = error;
|
|
1052
|
-
if (typeof record.message === "string") return record.message;
|
|
1053
|
-
if (typeof record.data?.message === "string") return record.data.message;
|
|
1054
|
-
return JSON.stringify(error);
|
|
1055
|
-
}
|
|
1056
|
-
return String(error);
|
|
1057
|
-
}
|
|
1058
1128
|
/** Names of connected MCP servers, whose tools the host's tool list leaves out. */
|
|
1059
1129
|
function connectedMcpServers(api) {
|
|
1060
1130
|
try {
|
|
@@ -1063,9 +1133,9 @@ function connectedMcpServers(api) {
|
|
|
1063
1133
|
return [];
|
|
1064
1134
|
}
|
|
1065
1135
|
}
|
|
1066
|
-
function mcpNotice(
|
|
1136
|
+
function mcpNotice(servers) {
|
|
1067
1137
|
if (servers.length === 0) return;
|
|
1068
|
-
return `Tools from MCP servers (${servers.join(", ")}) aren't listed, because ${
|
|
1138
|
+
return `Tools from MCP servers (${servers.join(", ")}) aren't listed, because ${kiloHost.name} only adds them when it runs a prompt.`;
|
|
1069
1139
|
}
|
|
1070
1140
|
function currentSessionId(api) {
|
|
1071
1141
|
const route = api.route.current;
|
|
@@ -1092,8 +1162,8 @@ async function chooseModel(api, signal) {
|
|
|
1092
1162
|
source: "provider default"
|
|
1093
1163
|
};
|
|
1094
1164
|
}
|
|
1095
|
-
async function readAgents(
|
|
1096
|
-
if (typeof api.client.app?.agents !== "function") throw new Error(`this ${
|
|
1165
|
+
async function readAgents(api, signal) {
|
|
1166
|
+
if (typeof api.client.app?.agents !== "function") throw new Error(`this ${kiloHost.name} doesn't list agents`);
|
|
1097
1167
|
const response = await api.client.app.agents({ directory: api.state.path.directory }, { signal });
|
|
1098
1168
|
if (response.error !== void 0) throw new Error(errorText(response.error));
|
|
1099
1169
|
const agents = response.data;
|
|
@@ -1136,7 +1206,7 @@ function accessByTool(api, tools, agents) {
|
|
|
1136
1206
|
});
|
|
1137
1207
|
return new Map(resolved.map((access) => [access.tool, access]));
|
|
1138
1208
|
}
|
|
1139
|
-
async function readToolList(
|
|
1209
|
+
async function readToolList(api, signal) {
|
|
1140
1210
|
const directory = api.state.path.directory;
|
|
1141
1211
|
let modelFailure;
|
|
1142
1212
|
const model = await chooseModel(api, signal).catch((error) => {
|
|
@@ -1163,19 +1233,19 @@ async function readToolList(host, api, signal) {
|
|
|
1163
1233
|
}
|
|
1164
1234
|
const response = await api.client.tool.ids({ directory }, { signal });
|
|
1165
1235
|
const tools = response.error === void 0 ? toolsFromIds(response.data) : void 0;
|
|
1166
|
-
if (tools === void 0) throw new Error(listFailure ?? modelFailure ?? (response.error === void 0 ? `${
|
|
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)));
|
|
1167
1237
|
return {
|
|
1168
1238
|
tools,
|
|
1169
1239
|
model: void 0,
|
|
1170
|
-
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 ${
|
|
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.`
|
|
1171
1241
|
};
|
|
1172
1242
|
}
|
|
1173
|
-
async function readCatalog(
|
|
1243
|
+
async function readCatalog(api, signal) {
|
|
1174
1244
|
let agentsFailure;
|
|
1175
|
-
const agentsRead = readAgents(
|
|
1245
|
+
const agentsRead = readAgents(api, signal).catch((error) => {
|
|
1176
1246
|
agentsFailure = errorText(error);
|
|
1177
1247
|
});
|
|
1178
|
-
const list = await readToolList(
|
|
1248
|
+
const list = await readToolList(api, signal);
|
|
1179
1249
|
const agents = await agentsRead;
|
|
1180
1250
|
let access;
|
|
1181
1251
|
if (agents !== void 0) try {
|
|
@@ -1186,15 +1256,10 @@ async function readCatalog(host, api, signal) {
|
|
|
1186
1256
|
return {
|
|
1187
1257
|
...list,
|
|
1188
1258
|
access,
|
|
1189
|
-
agentsNotice: access === void 0 ? `Could not read ${
|
|
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
|
|
1190
1260
|
};
|
|
1191
1261
|
}
|
|
1192
|
-
function
|
|
1193
|
-
const count = inputCount(tool.parameters);
|
|
1194
|
-
if (count === void 0) return;
|
|
1195
|
-
return count === 1 ? "1 input" : `${count} inputs`;
|
|
1196
|
-
}
|
|
1197
|
-
function registerToolBrowser(host, api) {
|
|
1262
|
+
function registerToolBrowser(api) {
|
|
1198
1263
|
const toast = (variant, message) => {
|
|
1199
1264
|
api.ui.toast({
|
|
1200
1265
|
variant,
|
|
@@ -1246,12 +1311,12 @@ function registerToolBrowser(host, api) {
|
|
|
1246
1311
|
async detail(catalog, tool) {
|
|
1247
1312
|
const listRevision = revision;
|
|
1248
1313
|
const sameView = viewContext();
|
|
1249
|
-
const detail = toolDetail(
|
|
1314
|
+
const detail = toolDetail(kiloHost, tool, catalog.model === void 0 ? void 0 : `As offered to ${chosenModelLabel(catalog.model)}`, catalog.access?.get(tool.id));
|
|
1250
1315
|
const render = await detailViewer();
|
|
1251
1316
|
if (listRevision !== revision || !sameView()) return;
|
|
1252
1317
|
display(render === void 0 ? () => api.ui.DialogAlert({
|
|
1253
1318
|
title: detail.title,
|
|
1254
|
-
message: detail
|
|
1319
|
+
message: plainTextDetail(detail)
|
|
1255
1320
|
}) : () => render(detail), "xlarge", () => {
|
|
1256
1321
|
const closedRevision = revision;
|
|
1257
1322
|
queueMicrotask(() => {
|
|
@@ -1296,12 +1361,12 @@ function registerToolBrowser(host, api) {
|
|
|
1296
1361
|
api.lifecycle.signal.addEventListener("abort", abort, { once: true });
|
|
1297
1362
|
const loading = display(() => api.ui.DialogAlert({
|
|
1298
1363
|
title: "Loading tools",
|
|
1299
|
-
message: `Reading the tools ${
|
|
1364
|
+
message: `Reading the tools ${kiloHost.name} offers…`
|
|
1300
1365
|
}), "medium", abort);
|
|
1301
1366
|
activeRead = controller;
|
|
1302
1367
|
detailViewer().catch(() => void 0);
|
|
1303
1368
|
try {
|
|
1304
|
-
const catalog = await readCatalog(
|
|
1369
|
+
const catalog = await readCatalog(api, controller.signal);
|
|
1305
1370
|
if (loading !== revision) return;
|
|
1306
1371
|
if (!sameView()) {
|
|
1307
1372
|
close();
|
|
@@ -1309,20 +1374,20 @@ function registerToolBrowser(host, api) {
|
|
|
1309
1374
|
}
|
|
1310
1375
|
if (catalog.tools.length === 0) {
|
|
1311
1376
|
close();
|
|
1312
|
-
toast("info", `${
|
|
1377
|
+
toast("info", `${kiloHost.name} reported no tools.`);
|
|
1313
1378
|
return;
|
|
1314
1379
|
}
|
|
1315
1380
|
const notices = [
|
|
1316
1381
|
catalog.notice,
|
|
1317
1382
|
catalog.agentsNotice,
|
|
1318
|
-
mcpNotice(
|
|
1383
|
+
mcpNotice(connectedMcpServers(api))
|
|
1319
1384
|
].filter((notice) => notice !== void 0);
|
|
1320
1385
|
if (notices.length > 0) toast(catalog.notice === void 0 && catalog.agentsNotice === void 0 ? "info" : "warning", notices.join(" "));
|
|
1321
1386
|
views.list(catalog, void 0);
|
|
1322
1387
|
} catch (error) {
|
|
1323
1388
|
if (loading === revision) {
|
|
1324
1389
|
close();
|
|
1325
|
-
if (sameView()) toast("warning", `Could not read tools from ${
|
|
1390
|
+
if (sameView()) toast("warning", `Could not read tools from ${kiloHost.name}: ${errorText(error)}`);
|
|
1326
1391
|
}
|
|
1327
1392
|
} finally {
|
|
1328
1393
|
api.lifecycle.signal.removeEventListener("abort", abort);
|
|
@@ -1346,46 +1411,13 @@ function registerToolBrowser(host, api) {
|
|
|
1346
1411
|
stopWatching();
|
|
1347
1412
|
});
|
|
1348
1413
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
registerToolBrowser(host, api);
|
|
1353
|
-
return Promise.resolve();
|
|
1354
|
-
};
|
|
1355
|
-
return {
|
|
1356
|
-
id: "tool-inspector",
|
|
1357
|
-
tui
|
|
1358
|
-
};
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
// src/host.ts
|
|
1362
|
-
const protectedConfigPaths = ["Kilo checks protected config paths separately; broad read grants do not automatically authorize sensitive .env files."];
|
|
1363
|
-
/**
|
|
1364
|
-
* Kilo applies call-time checks beyond the configured rules, so its notes distinguish the
|
|
1365
|
-
* configured permissions from a final authorization decision.
|
|
1366
|
-
*/
|
|
1367
|
-
const kiloHost = {
|
|
1368
|
-
name: "Kilo",
|
|
1369
|
-
actionLabels: {
|
|
1370
|
-
allow: "Allow",
|
|
1371
|
-
ask: "Ask",
|
|
1372
|
-
deny: "Deny"
|
|
1373
|
-
},
|
|
1374
|
-
accessNotes: {
|
|
1375
|
-
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."],
|
|
1376
|
-
permission: {
|
|
1377
|
-
read: protectedConfigPaths,
|
|
1378
|
-
edit: protectedConfigPaths
|
|
1379
|
-
},
|
|
1380
|
-
tool: { agent_manager: ["Agent manager prompt, stop, move and answer actions need exact action rules; broad grants can still ask first."] }
|
|
1381
|
-
}
|
|
1414
|
+
const tui = (api) => {
|
|
1415
|
+
registerToolBrowser(api);
|
|
1416
|
+
return Promise.resolve();
|
|
1382
1417
|
};
|
|
1383
|
-
|
|
1384
|
-
// src/tui.ts
|
|
1385
|
-
const core = createToolInspectorTui(kiloHost);
|
|
1386
|
-
const tui = (api, options, meta) => core.tui(api, options, meta);
|
|
1418
|
+
/** The Tool Inspector TUI plugin. */
|
|
1387
1419
|
const plugin = {
|
|
1388
|
-
id:
|
|
1420
|
+
id: "tool-inspector",
|
|
1389
1421
|
tui
|
|
1390
1422
|
};
|
|
1391
1423
|
|