@ywldan/kiro 0.2.8 → 0.2.9
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/README.md +29 -3
- package/dist/agent/prompt.js +19 -13
- package/dist/agent/skills.js +294 -0
- package/dist/tools/index.js +2 -1
- package/dist/tools/skill.js +40 -0
- package/dist/ui/App.js +34 -3
- package/dist/ui/commands.js +2 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -332,6 +332,8 @@ Slash commands:
|
|
|
332
332
|
| `/model list --remote` | List models offered by the active endpoint's `GET /models` |
|
|
333
333
|
| `/context` | Show approximate context use by message role plus session token totals |
|
|
334
334
|
| `/usage` | Show or hide the Usage card, giving the transcript the full width |
|
|
335
|
+
| `/skills` | List installed skills, their source, and any skipped entries |
|
|
336
|
+
| `/skill <name>` | Load a skill and apply its instructions to your next request |
|
|
335
337
|
| `/compact` | Summarize older turns now, keeping the last four user turns verbatim |
|
|
336
338
|
| `/sessions` | List saved sessions for this working directory |
|
|
337
339
|
| `/resume <n\|id>` | Resume a session by list number or id (prefixes work) |
|
|
@@ -420,6 +422,30 @@ Checkpoints are best effort: if a snapshot cannot be taken, the tool still runs.
|
|
|
420
422
|
|
|
421
423
|
If an `AGENTS.md` file exists in the working directory, its contents are appended to the system prompt for every turn, so project-specific instructions apply immediately, including after edits.
|
|
422
424
|
|
|
425
|
+
## Skills
|
|
426
|
+
|
|
427
|
+
A skill is a folder of instructions that Kiro loads only when it is needed. Kiro looks in four places, in this order, and the first definition of a name wins:
|
|
428
|
+
|
|
429
|
+
1. `<cwd>/.kiro/skills/`
|
|
430
|
+
2. `<cwd>/.claude/skills/`, so skills installed for Claude Code work unchanged
|
|
431
|
+
3. `~/.kiro/skills/`
|
|
432
|
+
4. `~/.claude/skills/`
|
|
433
|
+
|
|
434
|
+
Each skill is a directory with a `SKILL.md`:
|
|
435
|
+
|
|
436
|
+
```md
|
|
437
|
+
---
|
|
438
|
+
name: anti-slop
|
|
439
|
+
description: Remove AI-slop patterns from prose before answering.
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
Delete "delve", "tapestry", and stacked em dashes. Prefer concrete nouns.
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Only the name and description reach the system prompt (up to 30 skills, descriptions clipped at 300 characters). When a request matches, the model calls `read_skill` to load the body, so twenty installed skills cost a few hundred tokens instead of their full text. `read_skill` is read-only: it needs no approval and can run alongside other reads. Supporting files in the skill directory can be opened with `read_file` or run with `run_command`, which still goes through the usual approval.
|
|
446
|
+
|
|
447
|
+
`/skills` lists what was found, whether it came from the project or the user, and any skipped entry with the reason (missing description, duplicate name, oversized file). `/skill anti-slop` loads a skill immediately: the transcript shows a compact `/skill anti-slop` line while the model receives the full instructions. The index is rebuilt every turn, so edits to `SKILL.md` apply on the next message. Set `KIRO_SKILLS_DIR` to replace both user roots. A skill is instructions, not code, so it cannot bypass approvals.
|
|
448
|
+
|
|
423
449
|
## How it works
|
|
424
450
|
|
|
425
451
|
- The OpenAI provider posts to `{baseUrl}/chat/completions` with `stream: true`, parses SSE incrementally, and assembles tool-call deltas by index. It also accepts a plain JSON response from servers that ignore streaming, and reads `usage` when the endpoint sends it.
|
|
@@ -454,7 +480,7 @@ The suite covers streaming, multiple tool calls per response, approvals and deni
|
|
|
454
480
|
|
|
455
481
|
Model workflow tests use a temp `$HOME` so the real `~/.kiro` is never touched. They cover atomic config saves that preserve unknown fields, profile-name and URL validation, corrupt-config backup/recovery, `.env` parsing and real-environment precedence, `0600` writes, masking, the exact preset list, discovery success/401/missing-`/models`/timeout, the connection test, and wizard add/edit/select/remove/last-profile refusal/cancel/manual-model fallback. Scripted `kiro model add`, `list`, `use`, `test`, and `remove` run through the real CLI against the in-process mock; a failed test saves nothing, keys never appear in `config.json`, and generated keys land in `.env`. The wizard screen renderer is unit-tested against a fake stream: alternate-screen enter/leave, a new menu replacing the previous one, the breadcrumb of answered prompts (menu title instead of `Choose`, the value kept by pressing Enter, confirmation of a `Y/n` default, and the reset on Escape or a return to the root menu), stale errors dropped at a step change, log trimming to the terminal height with the prompt always visible, keyboard scrolling of an over-long list (page, top, bottom, clamping, reset on new output), and replaying results after the screen is restored. `/model` groups profiles by endpoint so several models behind one base URL are listed as siblings.
|
|
456
482
|
|
|
457
|
-
The newer paths have their own coverage: `max_completion_tokens` selection for reasoning models and recovery from a `max_tokens` rejection, `reasoning_content` deltas reaching the agent and collapsing in the renderer, the stream idle timeout, checkpoint edit/create undo with backup files outside the manifest, and prompt-history dedupe/capping/redaction. A spawned `kiro -p` test runs a tool with `--yolo`, checks the reply and saved session, feeds a piped prompt through `-p -`, and verifies the non-TTY hint without `-p`.
|
|
483
|
+
The newer paths have their own coverage: `max_completion_tokens` selection for reasoning models and recovery from a `max_tokens` rejection, `reasoning_content` deltas reaching the agent and collapsing in the renderer, the stream idle timeout, checkpoint edit/create undo with backup files outside the manifest, and prompt-history dedupe/capping/redaction. Skills are covered from the file to the model: frontmatter with quoted and continued values, CRLF input, `.kiro` overriding `.claude`, duplicate and invalid entries, an index in the system prompt that excludes the body, and the read-only `read_skill` tool. A spawned `kiro -p` test runs a tool with `--yolo`, checks the reply and saved session, feeds a piped prompt through `-p -`, and verifies the non-TTY hint without `-p`.
|
|
458
484
|
|
|
459
485
|
## Project layout
|
|
460
486
|
|
|
@@ -468,8 +494,8 @@ src/
|
|
|
468
494
|
sessions.ts atomic session save/load/list
|
|
469
495
|
model/ presets, discovery/test, context-window inference, shared wizard, CLI + screen renderer
|
|
470
496
|
providers/ Provider interface, OpenAI-compatible implementation
|
|
471
|
-
agent/ system prompt, agent loop, token estimates, compaction
|
|
472
|
-
tools/ tool registry, fs/search/patch/shell tools, checkpoints, glob/gitignore matching
|
|
497
|
+
agent/ system prompt, skill discovery/parsing, agent loop, token estimates, compaction
|
|
498
|
+
tools/ tool registry, fs/search/patch/shell/skill tools, checkpoints, glob/gitignore matching
|
|
473
499
|
ui/ Ink app, markdown, command palette, prompt history, scrolling, approvals, status bar, export
|
|
474
500
|
test/
|
|
475
501
|
mock-server.ts scripted OpenAI-compatible SSE server + /models variants
|
package/dist/agent/prompt.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { platform, release } from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { formatSkillIndex, loadSkills } from './skills.js';
|
|
4
5
|
const MAX_AGENTS_MD_BYTES = 200_000;
|
|
5
6
|
function osName() {
|
|
6
7
|
switch (platform()) {
|
|
@@ -12,6 +13,21 @@ function osName() {
|
|
|
12
13
|
return `${platform()} (${release()})`;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
16
|
+
async function readAgentsSection(cwd) {
|
|
17
|
+
const agentsPath = path.join(cwd, 'AGENTS.md');
|
|
18
|
+
try {
|
|
19
|
+
const content = await readFile(agentsPath, 'utf8');
|
|
20
|
+
const clipped = content.length > MAX_AGENTS_MD_BYTES
|
|
21
|
+
? content.slice(0, MAX_AGENTS_MD_BYTES) + '\n\n[AGENTS.md truncated by Kiro]'
|
|
22
|
+
: content;
|
|
23
|
+
return `# Project instructions from AGENTS.md\n\n${clipped.trimEnd()}`;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
return '';
|
|
28
|
+
return `[Could not read AGENTS.md: ${error.message}]`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
15
31
|
export async function buildSystemPrompt(cwd) {
|
|
16
32
|
const base = [
|
|
17
33
|
'You are Kiro, a terminal-based coding agent working in the user\'s current directory.',
|
|
@@ -36,18 +52,8 @@ export async function buildSystemPrompt(cwd) {
|
|
|
36
52
|
'',
|
|
37
53
|
'You have these tools: read_file, write_file, edit_file, multi_edit, apply_patch, list_dir, glob, grep, run_command.',
|
|
38
54
|
].join('\n');
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const clipped = content.length > MAX_AGENTS_MD_BYTES
|
|
43
|
-
? content.slice(0, MAX_AGENTS_MD_BYTES) + '\n\n[AGENTS.md truncated by Kiro]'
|
|
44
|
-
: content;
|
|
45
|
-
return `${base}\n\n# Project instructions from AGENTS.md\n\n${clipped.trimEnd()}\n`;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (error.code === 'ENOENT')
|
|
49
|
-
return base;
|
|
50
|
-
return `${base}\n\n[Could not read AGENTS.md: ${error.message}]\n`;
|
|
51
|
-
}
|
|
55
|
+
const [agents, inventory] = await Promise.all([readAgentsSection(cwd), loadSkills(cwd)]);
|
|
56
|
+
const sections = [base, agents, formatSkillIndex(inventory.skills)].filter(Boolean);
|
|
57
|
+
return sections.length === 1 ? base : `${sections.join('\n\n')}\n`;
|
|
52
58
|
}
|
|
53
59
|
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export const MAX_SKILLS_IN_PROMPT = 30;
|
|
5
|
+
export const MAX_SKILL_DESCRIPTION_CHARS = 300;
|
|
6
|
+
export const MAX_SKILL_BODY_CHARS = 50_000;
|
|
7
|
+
export const MAX_SKILL_FILE_BYTES = 200_000;
|
|
8
|
+
export const MAX_SKILLS_INDEX_CHARS = 8_000;
|
|
9
|
+
const MAX_SKILL_NAME_CHARS = 64;
|
|
10
|
+
const SKILL_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
11
|
+
/** `.claude/skills` is read too, so skills installed for other CLIs work unchanged. */
|
|
12
|
+
export function skillRoots(cwd) {
|
|
13
|
+
const roots = [
|
|
14
|
+
{ root: path.join(cwd, '.kiro', 'skills'), source: 'project' },
|
|
15
|
+
{ root: path.join(cwd, '.claude', 'skills'), source: 'project' },
|
|
16
|
+
];
|
|
17
|
+
const override = process.env.KIRO_SKILLS_DIR?.trim();
|
|
18
|
+
if (override) {
|
|
19
|
+
roots.push({ root: path.resolve(override), source: 'user' });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const home = homedir();
|
|
23
|
+
roots.push({ root: path.join(home, '.kiro', 'skills'), source: 'user' });
|
|
24
|
+
roots.push({ root: path.join(home, '.claude', 'skills'), source: 'user' });
|
|
25
|
+
}
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
return roots.filter(({ root }) => {
|
|
28
|
+
if (seen.has(root))
|
|
29
|
+
return false;
|
|
30
|
+
seen.add(root);
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function cleanValue(raw) {
|
|
35
|
+
const value = raw.trim();
|
|
36
|
+
if (value.length >= 2) {
|
|
37
|
+
const first = value[0];
|
|
38
|
+
const last = value[value.length - 1];
|
|
39
|
+
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
|
40
|
+
return value.slice(1, -1).trim();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
/** Reads the simple `key: value` frontmatter skills use; nested YAML is ignored. */
|
|
46
|
+
function parseMeta(lines) {
|
|
47
|
+
const meta = new Map();
|
|
48
|
+
let key = null;
|
|
49
|
+
let continuation = [];
|
|
50
|
+
const commit = () => {
|
|
51
|
+
if (key !== null && continuation.length > 0)
|
|
52
|
+
meta.set(key, cleanValue(continuation.join(' ')));
|
|
53
|
+
key = null;
|
|
54
|
+
continuation = [];
|
|
55
|
+
};
|
|
56
|
+
for (const line of lines) {
|
|
57
|
+
const match = /^([A-Za-z][A-Za-z0-9_-]*)\s*:\s*(.*)$/.exec(line);
|
|
58
|
+
if (match) {
|
|
59
|
+
commit();
|
|
60
|
+
const name = match[1].toLowerCase();
|
|
61
|
+
const value = (match[2] ?? '').trim();
|
|
62
|
+
const quote = value[0];
|
|
63
|
+
const quotedOpen = (quote === '"' || quote === "'") &&
|
|
64
|
+
!(value.length > 1 && value.endsWith(quote));
|
|
65
|
+
if (value === '' || /^[>|][+-]?$/.test(value) || quotedOpen) {
|
|
66
|
+
key = name;
|
|
67
|
+
continuation = value === '' || /^[>|][+-]?$/.test(value) ? [] : [value];
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
meta.set(name, cleanValue(value));
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (key !== null && /^\s+\S/.test(line)) {
|
|
75
|
+
continuation.push(line.trim());
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
commit();
|
|
79
|
+
}
|
|
80
|
+
commit();
|
|
81
|
+
return meta;
|
|
82
|
+
}
|
|
83
|
+
export function parseSkillFile(raw) {
|
|
84
|
+
const text = raw.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n');
|
|
85
|
+
const lines = text.split('\n');
|
|
86
|
+
if (lines[0]?.trim() !== '---') {
|
|
87
|
+
return { ok: false, reason: 'missing frontmatter: the file must start with ---' };
|
|
88
|
+
}
|
|
89
|
+
let close = -1;
|
|
90
|
+
for (let index = 1; index < lines.length; index++) {
|
|
91
|
+
if (lines[index]?.trim() === '---') {
|
|
92
|
+
close = index;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (close === -1)
|
|
97
|
+
return { ok: false, reason: 'unterminated frontmatter block' };
|
|
98
|
+
const meta = parseMeta(lines.slice(1, close));
|
|
99
|
+
const description = (meta.get('description') ?? '').replace(/\s+/g, ' ').trim();
|
|
100
|
+
if (!description)
|
|
101
|
+
return { ok: false, reason: 'frontmatter is missing a description' };
|
|
102
|
+
const body = lines.slice(close + 1).join('\n').trim();
|
|
103
|
+
if (!body)
|
|
104
|
+
return { ok: false, reason: 'the skill has no instructions after the frontmatter' };
|
|
105
|
+
return {
|
|
106
|
+
ok: true,
|
|
107
|
+
value: { name: meta.get('name')?.trim() || undefined, description, body },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function readSkillDir(root, source, entry) {
|
|
111
|
+
const file = path.join(root, entry, 'SKILL.md');
|
|
112
|
+
let info;
|
|
113
|
+
try {
|
|
114
|
+
info = await stat(file);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
const code = error.code;
|
|
118
|
+
if (code === 'ENOENT' || code === 'ENOTDIR')
|
|
119
|
+
return {};
|
|
120
|
+
return { invalid: { name: entry, file, reason: error.message } };
|
|
121
|
+
}
|
|
122
|
+
if (!info.isFile())
|
|
123
|
+
return {};
|
|
124
|
+
if (info.size > MAX_SKILL_FILE_BYTES) {
|
|
125
|
+
return {
|
|
126
|
+
invalid: {
|
|
127
|
+
name: entry,
|
|
128
|
+
file,
|
|
129
|
+
reason: `SKILL.md is larger than ${MAX_SKILL_FILE_BYTES.toLocaleString()} bytes`,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
let raw;
|
|
134
|
+
try {
|
|
135
|
+
raw = await readFile(file, 'utf8');
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return { invalid: { name: entry, file, reason: error.message } };
|
|
139
|
+
}
|
|
140
|
+
const parsed = parseSkillFile(raw);
|
|
141
|
+
if (!parsed.ok)
|
|
142
|
+
return { invalid: { name: entry, file, reason: parsed.reason } };
|
|
143
|
+
const name = parsed.value.name ?? entry;
|
|
144
|
+
if (name.length > MAX_SKILL_NAME_CHARS || !SKILL_NAME_PATTERN.test(name)) {
|
|
145
|
+
return {
|
|
146
|
+
invalid: {
|
|
147
|
+
name,
|
|
148
|
+
file,
|
|
149
|
+
reason: 'the name may only contain letters, digits, dots, dashes, and underscores',
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
skill: {
|
|
155
|
+
name,
|
|
156
|
+
description: parsed.value.description,
|
|
157
|
+
body: parsed.value.body,
|
|
158
|
+
dir: path.join(root, entry),
|
|
159
|
+
file,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** Project roots win over user roots; the first definition of a name is kept. */
|
|
164
|
+
export async function loadSkills(cwd) {
|
|
165
|
+
const roots = skillRoots(cwd);
|
|
166
|
+
const skills = [];
|
|
167
|
+
const invalid = [];
|
|
168
|
+
const byName = new Map();
|
|
169
|
+
for (const { root, source } of roots) {
|
|
170
|
+
let entries;
|
|
171
|
+
try {
|
|
172
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
const code = error.code;
|
|
176
|
+
if (code !== 'ENOENT' && code !== 'ENOTDIR') {
|
|
177
|
+
invalid.push({
|
|
178
|
+
name: path.basename(root),
|
|
179
|
+
file: root,
|
|
180
|
+
source,
|
|
181
|
+
reason: `cannot read the directory: ${error.message}`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const names = entries
|
|
187
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))
|
|
188
|
+
.map((entry) => entry.name)
|
|
189
|
+
.sort((a, b) => a.localeCompare(b, 'en'));
|
|
190
|
+
for (const entryName of names) {
|
|
191
|
+
const result = await readSkillDir(root, source, entryName);
|
|
192
|
+
if (result.invalid) {
|
|
193
|
+
invalid.push({ ...result.invalid, source });
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const skill = result.skill;
|
|
197
|
+
if (!skill)
|
|
198
|
+
continue;
|
|
199
|
+
const existing = byName.get(skill.name.toLowerCase());
|
|
200
|
+
if (existing) {
|
|
201
|
+
invalid.push({
|
|
202
|
+
name: skill.name,
|
|
203
|
+
file: skill.file,
|
|
204
|
+
source,
|
|
205
|
+
reason: `duplicate name; ${existing.file} already defines it`,
|
|
206
|
+
});
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const complete = { ...skill, source };
|
|
210
|
+
skills.push(complete);
|
|
211
|
+
byName.set(skill.name.toLowerCase(), complete);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
skills.sort((a, b) => a.name.localeCompare(b.name, 'en'));
|
|
215
|
+
return { skills, invalid, roots: roots.map(({ root }) => root) };
|
|
216
|
+
}
|
|
217
|
+
export function findSkill(skills, name) {
|
|
218
|
+
const needle = name.trim().toLowerCase();
|
|
219
|
+
return skills.find((skill) => skill.name.toLowerCase() === needle);
|
|
220
|
+
}
|
|
221
|
+
export function shortPath(target, cwd) {
|
|
222
|
+
const relative = path.relative(cwd, target);
|
|
223
|
+
if (relative === '')
|
|
224
|
+
return '.';
|
|
225
|
+
if (!relative.startsWith('..') && !path.isAbsolute(relative))
|
|
226
|
+
return relative;
|
|
227
|
+
const home = homedir();
|
|
228
|
+
if (target === home)
|
|
229
|
+
return '~';
|
|
230
|
+
if (target.startsWith(`${home}${path.sep}`))
|
|
231
|
+
return `~${target.slice(home.length)}`;
|
|
232
|
+
return target;
|
|
233
|
+
}
|
|
234
|
+
function clipDescription(description, max) {
|
|
235
|
+
return description.length > max ? `${description.slice(0, max - 1)}…` : description;
|
|
236
|
+
}
|
|
237
|
+
/** Name and description only; the body stays on disk until read_skill loads it. */
|
|
238
|
+
export function formatSkillIndex(skills) {
|
|
239
|
+
if (skills.length === 0)
|
|
240
|
+
return '';
|
|
241
|
+
const lines = [
|
|
242
|
+
'# Skills',
|
|
243
|
+
'Installed skills extend how you work. When a request matches one, call the read_skill tool with the exact name first and follow the instructions it returns. Do not guess what a skill contains.',
|
|
244
|
+
];
|
|
245
|
+
let used = lines.join('\n').length;
|
|
246
|
+
let shown = 0;
|
|
247
|
+
for (const skill of skills.slice(0, MAX_SKILLS_IN_PROMPT)) {
|
|
248
|
+
const line = `- ${skill.name}: ${clipDescription(skill.description, MAX_SKILL_DESCRIPTION_CHARS)}`;
|
|
249
|
+
if (shown > 0 && used + line.length + 1 > MAX_SKILLS_INDEX_CHARS)
|
|
250
|
+
break;
|
|
251
|
+
lines.push(line);
|
|
252
|
+
used += line.length + 1;
|
|
253
|
+
shown++;
|
|
254
|
+
}
|
|
255
|
+
const hidden = skills.length - shown;
|
|
256
|
+
if (hidden > 0)
|
|
257
|
+
lines.push(`(${hidden} more installed; run /skills to list all.)`);
|
|
258
|
+
return lines.join('\n');
|
|
259
|
+
}
|
|
260
|
+
export function formatSkillList(inventory, cwd) {
|
|
261
|
+
const lines = [];
|
|
262
|
+
if (inventory.skills.length === 0) {
|
|
263
|
+
lines.push('No skills installed.');
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const project = inventory.skills.filter((skill) => skill.source === 'project').length;
|
|
267
|
+
const user = inventory.skills.length - project;
|
|
268
|
+
const counts = [project > 0 ? `${project} project` : '', user > 0 ? `${user} user` : '']
|
|
269
|
+
.filter(Boolean)
|
|
270
|
+
.join(', ');
|
|
271
|
+
lines.push(`Installed skills (${counts}):`);
|
|
272
|
+
const width = Math.min(28, Math.max(...inventory.skills.map((skill) => skill.name.length)));
|
|
273
|
+
for (const skill of inventory.skills) {
|
|
274
|
+
lines.push(` ${skill.name.padEnd(width)} ${clipDescription(skill.description, 80)} ` +
|
|
275
|
+
`[${skill.source}] (${shortPath(skill.dir, cwd)})`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
lines.push('', `Looked in: ${inventory.roots.map((root) => shortPath(root, cwd)).join(', ')}`);
|
|
279
|
+
if (inventory.invalid.length > 0) {
|
|
280
|
+
const label = inventory.invalid.length === 1 ? '1 entry' : `${inventory.invalid.length} entries`;
|
|
281
|
+
lines.push(`Skipped ${label}:`);
|
|
282
|
+
for (const bad of inventory.invalid.slice(0, 10)) {
|
|
283
|
+
lines.push(` ${bad.name}: ${bad.reason} (${shortPath(bad.file, cwd)})`);
|
|
284
|
+
}
|
|
285
|
+
if (inventory.invalid.length > 10) {
|
|
286
|
+
lines.push(` … and ${inventory.invalid.length - 10} more`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (inventory.skills.length === 0) {
|
|
290
|
+
lines.push('Add one at .kiro/skills/<name>/SKILL.md with name and description frontmatter.');
|
|
291
|
+
}
|
|
292
|
+
return lines.join('\n');
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=skills.js.map
|
package/dist/tools/index.js
CHANGED
|
@@ -3,9 +3,10 @@ import { fsTools } from './fs.js';
|
|
|
3
3
|
import { patchTools } from './patch.js';
|
|
4
4
|
import { searchTools } from './search.js';
|
|
5
5
|
import { runCommandTool } from './shell.js';
|
|
6
|
+
import { skillTools } from './skill.js';
|
|
6
7
|
import { toolError } from './types.js';
|
|
7
8
|
export const MAX_TOOL_RESULT_CHARS = 60_000;
|
|
8
|
-
export const tools = [...fsTools, ...searchTools, ...patchTools, runCommandTool];
|
|
9
|
+
export const tools = [...fsTools, ...searchTools, ...patchTools, runCommandTool, ...skillTools];
|
|
9
10
|
export const toolDefinitions = tools.map((tool) => tool.definition);
|
|
10
11
|
const byName = new Map(tools.map((tool) => [tool.definition.function.name, tool]));
|
|
11
12
|
export function isReadOnlyTool(name) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { findSkill, loadSkills, MAX_SKILL_BODY_CHARS } from '../agent/skills.js';
|
|
2
|
+
import { stringArg } from './paths.js';
|
|
3
|
+
import { ok, toolError } from './types.js';
|
|
4
|
+
const readSkillTool = {
|
|
5
|
+
readOnly: true,
|
|
6
|
+
definition: {
|
|
7
|
+
type: 'function',
|
|
8
|
+
function: {
|
|
9
|
+
name: 'read_skill',
|
|
10
|
+
description: 'Load the full instructions of an installed skill by name. Use it when a request matches a skill listed in the system prompt, then follow the returned instructions.',
|
|
11
|
+
parameters: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
name: { type: 'string', description: 'Exact skill name, e.g. "anti-slop".' },
|
|
15
|
+
},
|
|
16
|
+
required: ['name'],
|
|
17
|
+
additionalProperties: false,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
async run(input, ctx) {
|
|
22
|
+
const name = stringArg(input, 'name');
|
|
23
|
+
const inventory = await loadSkills(ctx.cwd);
|
|
24
|
+
if (inventory.skills.length === 0) {
|
|
25
|
+
return toolError('No skills are installed. Add one at .kiro/skills/<name>/SKILL.md or ~/.kiro/skills/<name>/SKILL.md.');
|
|
26
|
+
}
|
|
27
|
+
const skill = findSkill(inventory.skills, name);
|
|
28
|
+
if (!skill) {
|
|
29
|
+
return toolError(`Unknown skill "${name}". Available skills: ${inventory.skills.map((entry) => entry.name).join(', ')}.`);
|
|
30
|
+
}
|
|
31
|
+
const clipped = skill.body.length > MAX_SKILL_BODY_CHARS
|
|
32
|
+
? `${skill.body.slice(0, MAX_SKILL_BODY_CHARS)}\n\n… [skill truncated after ` +
|
|
33
|
+
`${MAX_SKILL_BODY_CHARS.toLocaleString()} characters; read the rest with read_file on ${skill.file}]`
|
|
34
|
+
: skill.body;
|
|
35
|
+
return ok(`# Skill: ${skill.name}\n\n${clipped}\n\n` +
|
|
36
|
+
`[Skill directory: ${skill.dir}. Read supporting files with read_file or run bundled scripts with run_command.]`, `read_skill ${skill.name}`);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export const skillTools = [readSkillTool];
|
|
40
|
+
//# sourceMappingURL=skill.js.map
|
package/dist/ui/App.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Box, useApp, useInput, useStdout } from 'ink';
|
|
|
4
4
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { buildSystemPrompt } from '../agent/prompt.js';
|
|
7
|
+
import { findSkill, formatSkillList, loadSkills, MAX_SKILL_BODY_CHARS, } from '../agent/skills.js';
|
|
7
8
|
import { runAgentTurn } from '../agent/loop.js';
|
|
8
9
|
import { COMPACT_KEEP_USER_TURNS, COMPACT_THRESHOLD, compactMessages, shouldCompact, } from '../agent/compact.js';
|
|
9
10
|
import { estimateMessagesTokens, formatPercent, formatTokens } from '../agent/tokens.js';
|
|
@@ -470,12 +471,13 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
470
471
|
approvalPolicy.clear();
|
|
471
472
|
setAutoAllowed([]);
|
|
472
473
|
}, [approvalPolicy]);
|
|
473
|
-
const sendTurn = useCallback(async (rawInput, alreadyDisplayed = false) => {
|
|
474
|
+
const sendTurn = useCallback(async (rawInput, alreadyDisplayed = false, displayText) => {
|
|
474
475
|
if (busyRef.current || transitioningRef.current)
|
|
475
476
|
return;
|
|
476
477
|
const text = rawInput.trim();
|
|
477
478
|
if (!text)
|
|
478
479
|
return;
|
|
480
|
+
const shown = displayText ?? text;
|
|
479
481
|
busyRef.current = true;
|
|
480
482
|
cancelRequestedRef.current = false;
|
|
481
483
|
setBusy(true);
|
|
@@ -489,11 +491,11 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
489
491
|
if (!alreadyDisplayed) {
|
|
490
492
|
setItems((current) => [
|
|
491
493
|
...current,
|
|
492
|
-
{ kind: 'user', id: nextItemIdRef.current++, text },
|
|
494
|
+
{ kind: 'user', id: nextItemIdRef.current++, text: shown },
|
|
493
495
|
]);
|
|
494
496
|
}
|
|
495
497
|
messagesRef.current.push({ role: 'user', content: text });
|
|
496
|
-
void recordPrompt(cwd,
|
|
498
|
+
void recordPrompt(cwd, shown).then(setPromptHistory);
|
|
497
499
|
recomputeContext();
|
|
498
500
|
void persistSession();
|
|
499
501
|
const controller = new AbortController();
|
|
@@ -868,6 +870,34 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
868
870
|
: 'Usage card hidden; the transcript gets the full width. Use /usage to show it again.');
|
|
869
871
|
return;
|
|
870
872
|
}
|
|
873
|
+
case '/skills': {
|
|
874
|
+
if (argument) {
|
|
875
|
+
addNotice('error', 'Usage: /skills');
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
const inventory = await loadSkills(cwd);
|
|
879
|
+
addNotice(inventory.skills.length === 0 && inventory.invalid.length === 0 ? 'muted' : 'info', formatSkillList(inventory, cwd));
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
case '/skill': {
|
|
883
|
+
if (!argument || rest[1]) {
|
|
884
|
+
addNotice('error', 'Usage: /skill <name>. Run /skills to list installed skills.');
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
const inventory = await loadSkills(cwd);
|
|
888
|
+
const skill = findSkill(inventory.skills, argument);
|
|
889
|
+
if (!skill) {
|
|
890
|
+
addNotice('error', inventory.skills.length === 0
|
|
891
|
+
? 'No skills installed. Add one at .kiro/skills/<name>/SKILL.md.'
|
|
892
|
+
: `Unknown skill "${argument}". Installed: ${inventory.skills.map((entry) => entry.name).join(', ')}.`);
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
const body = skill.body.length > MAX_SKILL_BODY_CHARS
|
|
896
|
+
? `${skill.body.slice(0, MAX_SKILL_BODY_CHARS)}\n\n[Skill truncated; the rest is in ${skill.file}]`
|
|
897
|
+
: skill.body;
|
|
898
|
+
void sendTurn(`Use the "${skill.name}" skill. Its instructions follow; apply them to what I ask next.\n\n${body}`, false, `/skill ${skill.name}`);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
871
901
|
case '/compact': {
|
|
872
902
|
if (messagesRef.current.length === 0) {
|
|
873
903
|
addNotice('muted', 'There is no conversation to compact yet.');
|
|
@@ -1137,6 +1167,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1137
1167
|
resetAutoAllowed,
|
|
1138
1168
|
runModelFlow,
|
|
1139
1169
|
runProfileTest,
|
|
1170
|
+
sendTurn,
|
|
1140
1171
|
updateContextTokens,
|
|
1141
1172
|
usageCardEnabled,
|
|
1142
1173
|
version,
|
package/dist/ui/commands.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const SLASH_COMMANDS = [
|
|
2
2
|
{ name: '/help', description: 'show this help' },
|
|
3
3
|
{ name: '/model', usage: '[name | add | edit | remove | test | list]', description: 'list or switch models' },
|
|
4
|
+
{ name: '/skills', description: 'list installed skills and where they were found' },
|
|
5
|
+
{ name: '/skill', usage: '<name>', description: 'load a skill and apply it to your next request' },
|
|
4
6
|
{ name: '/context', description: 'show approximate context usage' },
|
|
5
7
|
{ name: '/usage', description: 'show or hide the usage card' },
|
|
6
8
|
{ name: '/compact', description: 'summarize older turns to free context' },
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
1
|
+
export const VERSION = '0.2.9';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|