slicekit 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli/index.js +2 -0
- package/src/cli/models.js +90 -0
- package/src/config.js +20 -0
- package/src/render/entry.js +21 -2
- package/templates/claude-code/agents/auditor.md +1 -1
- package/templates/claude-code/agents/designer.md +1 -1
- package/templates/claude-code/agents/developer.md +1 -1
- package/templates/claude-code/agents/fixer.md +1 -1
- package/templates/claude-code/agents/ops.md +1 -1
- package/templates/claude-code/agents/reviewer.md +1 -1
- package/templates/claude-code/commands/slicekit-brief.md +1 -0
- package/templates/claude-code/commands/slicekit-intake.md +1 -0
- package/templates/claude-code/commands/slicekit-next.md +1 -0
- package/templates/claude-code/commands/slicekit-plan.md +1 -0
- package/templates/claude-code/commands/slicekit-specify.md +1 -0
package/package.json
CHANGED
package/src/cli/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { intakeCommand } from './intake.js';
|
|
|
21
21
|
import { prCommand } from './pr.js';
|
|
22
22
|
import { instructionsCommand } from './instructions.js';
|
|
23
23
|
import { journalCommand } from './journal.js';
|
|
24
|
+
import { modelsCommand } from './models.js';
|
|
24
25
|
import { nextCommand } from './next.js';
|
|
25
26
|
import { opsCommand } from './ops.js';
|
|
26
27
|
import { planCommand } from './plan.js';
|
|
@@ -59,6 +60,7 @@ export const COMMANDS = {
|
|
|
59
60
|
instructions: instructionsCommand,
|
|
60
61
|
hook: hookCommand,
|
|
61
62
|
journal: journalCommand,
|
|
63
|
+
models: modelsCommand,
|
|
62
64
|
next: nextCommand,
|
|
63
65
|
ops: opsCommand,
|
|
64
66
|
plan: planCommand,
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// `slicekit models apply` (REQ-6.7, D-109, D-115, D-130): renders the agent files and the main-session
|
|
2
|
+
// command files from the models map in .slicekit/config.json, and prints one line per file whose
|
|
3
|
+
// model: changed, as `<file> <old> -> <new>`, or `no change`. It writes no other file: a file whose
|
|
4
|
+
// fresh render differs in more than its model: line (a kit upgrade slicekit update has not applied
|
|
5
|
+
// yet), one edited since slicekit wrote it, or one that is missing, is left as it is and named, and
|
|
6
|
+
// so is a mapped role whose file the project's shape does not render; either exits 1.
|
|
7
|
+
// The change reaches the default branch in a pull request, as any other change does (D-109).
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { parseArgs } from 'node:util';
|
|
10
|
+
import { AGENT_ROLES, ConfigError, loadConfig } from '../config.js';
|
|
11
|
+
import { writeText } from '../fs.js';
|
|
12
|
+
import { RENDERED, installedVersion, kitVersion } from '../render/index.js';
|
|
13
|
+
import { modelFor } from '../render/entry.js';
|
|
14
|
+
import { entriesForShape } from '../render/manifest.js';
|
|
15
|
+
import { readSettings } from '../render/settings.js';
|
|
16
|
+
import { planUpdate } from '../render/update.js';
|
|
17
|
+
|
|
18
|
+
const USAGE = 'models apply';
|
|
19
|
+
|
|
20
|
+
// The value of model: in a file's front matter, or null when the file or the line is absent.
|
|
21
|
+
export function frontMatterModel(text) {
|
|
22
|
+
if (text === null) return null;
|
|
23
|
+
const lines = text.split('\n');
|
|
24
|
+
if (lines[0] !== '---') return null;
|
|
25
|
+
const end = lines.indexOf('---', 1);
|
|
26
|
+
const line = lines.slice(1, end < 0 ? 1 : end).find((l) => /^model:/.test(l));
|
|
27
|
+
return line === undefined ? null : line.slice('model:'.length).trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const withoutModel = (text) => text.replace(/^model:.*\n/m, '');
|
|
31
|
+
|
|
32
|
+
async function run(args, io) {
|
|
33
|
+
let positionals;
|
|
34
|
+
try {
|
|
35
|
+
({ positionals } = parseArgs({ args, options: {}, allowPositionals: true }));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
io.stderr(`slicekit: ${e.message}\nusage: slicekit ${USAGE}\n`);
|
|
38
|
+
return 2;
|
|
39
|
+
}
|
|
40
|
+
if (positionals.length !== 1 || positionals[0] !== 'apply') {
|
|
41
|
+
io.stderr(`usage: slicekit ${USAGE}\n`);
|
|
42
|
+
return 2;
|
|
43
|
+
}
|
|
44
|
+
const root = io.cwd;
|
|
45
|
+
let cfg;
|
|
46
|
+
try {
|
|
47
|
+
cfg = loadConfig(root);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (!(e instanceof ConfigError)) throw e;
|
|
50
|
+
io.stderr(`slicekit: ${e.message}\n`);
|
|
51
|
+
return 2;
|
|
52
|
+
}
|
|
53
|
+
// Rendered at the version whose reference copies the project holds, so the managed marker and
|
|
54
|
+
// every other reference copy stay as slicekit update left them.
|
|
55
|
+
const version = installedVersion(path.join(root, RENDERED), readSettings(root)) ?? kitVersion();
|
|
56
|
+
const entries = entriesForShape(cfg.shape).filter((e) => modelFor(cfg, e.dest) !== null);
|
|
57
|
+
const plan = planUpdate(root, cfg, { version, entries, settings: false });
|
|
58
|
+
|
|
59
|
+
const changed = [];
|
|
60
|
+
const left = [];
|
|
61
|
+
// A role the map names whose file the project's shape does not render (designer in a backend
|
|
62
|
+
// project) carries its model in no file; it is named so the exit is not 0.
|
|
63
|
+
const rendered = new Set(entries.map((e) => e.dest));
|
|
64
|
+
for (const role of Object.keys(cfg.models ?? {})) {
|
|
65
|
+
const dest = AGENT_ROLES.includes(role) ? `.claude/agents/${role}.md` : `.claude/commands/slicekit-${role}.md`;
|
|
66
|
+
if (!rendered.has(dest)) left.push(`models.${role}: the ${cfg.shape} shape renders no ${dest}; the model is written nowhere`);
|
|
67
|
+
}
|
|
68
|
+
for (const item of plan) {
|
|
69
|
+
if (item.status === 'same') continue;
|
|
70
|
+
if (item.status !== 'changed') {
|
|
71
|
+
left.push(`${item.dest} is ${item.status === 'missing' ? 'missing' : item.status === 'drifted' ? 'edited since slicekit wrote it' : 'not managed by slicekit'}; left as it is (slicekit update writes it)`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (withoutModel(item.next) !== withoutModel(item.current)) {
|
|
75
|
+
left.push(`${item.dest} differs from the kit's templates in more than its model: line; left as it is (run slicekit update first)`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
changed.push(item);
|
|
79
|
+
}
|
|
80
|
+
for (const item of changed) {
|
|
81
|
+
writeText(path.join(root, item.dest), item.next);
|
|
82
|
+
writeText(path.join(root, RENDERED, version, item.dest), item.refText);
|
|
83
|
+
io.stdout(`${item.dest} ${frontMatterModel(item.current) ?? 'none'} -> ${frontMatterModel(item.next) ?? 'none'}\n`);
|
|
84
|
+
}
|
|
85
|
+
if (changed.length === 0) io.stdout('no change\n');
|
|
86
|
+
for (const line of left) io.stderr(`slicekit: ${line}\n`);
|
|
87
|
+
return left.length > 0 ? 1 : 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const modelsCommand = { run, usage: USAGE, subcommands: ['apply'] };
|
package/src/config.js
CHANGED
|
@@ -281,6 +281,26 @@ export function validateConfig(cfg) {
|
|
|
281
281
|
errors.push(...testFilesErrors(cfg.testFiles));
|
|
282
282
|
errors.push(...agentsErrors(cfg.agents));
|
|
283
283
|
errors.push(...releaseErrors(cfg.release));
|
|
284
|
+
errors.push(...modelsErrors(cfg.models));
|
|
285
|
+
return errors;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// REQ-6.7, D-115, D-130: models is optional, a map from a role to the model ID it runs on. The agent
|
|
289
|
+
// roles are written into the model: field of .claude/agents/<role>.md, the main-session roles into
|
|
290
|
+
// the front matter of .claude/commands/slicekit-<role>.md.
|
|
291
|
+
export const AGENT_ROLES = ['auditor', 'designer', 'developer', 'fixer', 'ops', 'reviewer'];
|
|
292
|
+
export const COMMAND_ROLES = ['brief', 'intake', 'specify', 'plan', 'next'];
|
|
293
|
+
export const MODEL_ROLES = [...AGENT_ROLES, ...COMMAND_ROLES];
|
|
294
|
+
|
|
295
|
+
function modelsErrors(models) {
|
|
296
|
+
if (models === undefined) return [];
|
|
297
|
+
if (!isObject(models)) return ['models: must be an object from a role to a model ID'];
|
|
298
|
+
const errors = [];
|
|
299
|
+
for (const [role, model] of Object.entries(models)) {
|
|
300
|
+
if (!MODEL_ROLES.includes(role)) errors.push(`models.${role}: unknown role; use ${MODEL_ROLES.join(', ')}`);
|
|
301
|
+
// The value is written as is into a front matter line, so it holds no space or line break.
|
|
302
|
+
else if (typeof model !== 'string' || model === '' || /\s/.test(model)) errors.push(`models.${role}: must be a non-empty string with no spaces`);
|
|
303
|
+
}
|
|
284
304
|
return errors;
|
|
285
305
|
}
|
|
286
306
|
|
package/src/render/entry.js
CHANGED
|
@@ -5,13 +5,14 @@ import { exists, readText } from '../fs.js';
|
|
|
5
5
|
import { compareManaged } from './compare.js';
|
|
6
6
|
import { markerStyle, replaceManaged, wrapManaged } from './managed.js';
|
|
7
7
|
import { readSettings } from './settings.js';
|
|
8
|
+
import { AGENT_ROLES, COMMAND_ROLES } from '../config.js';
|
|
8
9
|
|
|
9
10
|
export const TEMPLATES = fileURLToPath(new URL('../../templates/claude-code/', import.meta.url));
|
|
10
11
|
export const SETTINGS = '.claude/settings.json';
|
|
11
12
|
export const RENDERED = '.slicekit/rendered';
|
|
12
13
|
const VERSION_RE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
13
14
|
|
|
14
|
-
const TEMPLATE_KEYS = ['version', 'name', 'docsRoot', 'cli'];
|
|
15
|
+
const TEMPLATE_KEYS = ['version', 'name', 'docsRoot', 'cli', 'model'];
|
|
15
16
|
|
|
16
17
|
// {{key}} for each key in keys; any other {{…}} (and GitHub's ${{ … }}) is left as written.
|
|
17
18
|
export function substitute(text, vars, keys = TEMPLATE_KEYS) {
|
|
@@ -20,6 +21,23 @@ export function substitute(text, vars, keys = TEMPLATE_KEYS) {
|
|
|
20
21
|
|
|
21
22
|
export const varsFor = (cfg, version) => ({ version, name: cfg.name, docsRoot: cfg.docsRoot, cli: cfg.cli });
|
|
22
23
|
|
|
24
|
+
// REQ-6.7, D-115, D-130: the model a rendered file names in its front matter, from the models map.
|
|
25
|
+
// An agent file (.claude/agents/<role>.md) gets inherit when the map names none; a main-session
|
|
26
|
+
// command file (.claude/commands/slicekit-<role>.md) gets '' and so no model: line; any other file null.
|
|
27
|
+
export function modelFor(cfg, dest) {
|
|
28
|
+
const agent = /^\.claude\/agents\/([a-z]+)\.md$/.exec(dest);
|
|
29
|
+
if (agent && AGENT_ROLES.includes(agent[1])) return cfg.models?.[agent[1]] ?? 'inherit';
|
|
30
|
+
const command = /^\.claude\/commands\/slicekit-([a-z]+)\.md$/.exec(dest);
|
|
31
|
+
if (command && COMMAND_ROLES.includes(command[1])) return cfg.models?.[command[1]] ?? '';
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The file's text with {{model}} filled; a `model: {{model}}` line with no model is dropped.
|
|
36
|
+
function fillModel(text, model) {
|
|
37
|
+
if (model === null) return text;
|
|
38
|
+
return model === '' ? text.replace(/^model: \{\{model\}\}\n/m, '') : text;
|
|
39
|
+
}
|
|
40
|
+
|
|
23
41
|
// hooks.json parsed first, then {{…}} filled inside each string, so a quote or backslash in a value
|
|
24
42
|
// (a Windows path in cli) stays a string and never breaks the JSON.
|
|
25
43
|
export function loadHooks(templates, vars) {
|
|
@@ -85,7 +103,8 @@ export function loadReference(root, dest) {
|
|
|
85
103
|
// The one place a manifest entry is rendered and judged; planUpdate and renderAll both come through here.
|
|
86
104
|
// next: the whole file as it would be written (null for an unmanaged file, which is never written).
|
|
87
105
|
export function renderEntry(root, cfg, { src, dest }, { version, templates = TEMPLATES }) {
|
|
88
|
-
const
|
|
106
|
+
const model = modelFor(cfg, dest);
|
|
107
|
+
const rendered = substitute(fillModel(readText(path.join(templates, src)), model), { ...varsFor(cfg, version), model: model ?? '' });
|
|
89
108
|
const style = markerStyle(dest, rendered);
|
|
90
109
|
const fresh = wrapManaged(rendered, { version, style });
|
|
91
110
|
const file = path.join(root, dest);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
name: auditor
|
|
3
3
|
description: Compares claims with evidence and writes a gaps file or audit report with a citation on both sides.
|
|
4
4
|
tools: Read, Grep, Glob, Write, Bash
|
|
5
|
-
model:
|
|
5
|
+
model: {{model}}
|
|
6
6
|
---
|
|
7
7
|
Brief: run `{{cli}} instructions auditor` and follow it. You never run a git command that commits, pushes or moves a branch; report and the command commits. End every reply with "Skipped:" and "Not checked:" lines.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
name: designer
|
|
3
3
|
description: Gives a verdict on a screen against the team's design rules; writes no code.
|
|
4
4
|
tools: Read, Grep, Glob, Write, Bash
|
|
5
|
-
model:
|
|
5
|
+
model: {{model}}
|
|
6
6
|
---
|
|
7
7
|
Brief: run `{{cli}} instructions designer` and follow it. You never run a git command that commits, pushes or moves a branch; report and the command commits. End every reply with "Skipped:" and "Not checked:" lines.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
name: developer
|
|
3
3
|
description: Writes the slice's tests, then the code that passes them, in the worktree.
|
|
4
4
|
tools: Read, Grep, Glob, Edit, Write, Bash
|
|
5
|
-
model:
|
|
5
|
+
model: {{model}}
|
|
6
6
|
---
|
|
7
7
|
Brief: run `{{cli}} instructions developer` and follow it. You never run a git command that commits, pushes or moves a branch; report and the command commits. End every reply with "Skipped:" and "Not checked:" lines.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
name: fixer
|
|
3
3
|
description: Changes code to answer named review findings and nothing else.
|
|
4
4
|
tools: Read, Grep, Glob, Edit, Write, Bash
|
|
5
|
-
model:
|
|
5
|
+
model: {{model}}
|
|
6
6
|
---
|
|
7
7
|
Brief: run `{{cli}} instructions fixer` and follow it. You never run a git command that commits, pushes or moves a branch; report and the command commits. End every reply with "Skipped:" and "Not checked:" lines.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
name: ops
|
|
3
3
|
description: Reads the runbook and history for a symptom and replies with a proposed-actions report; changes nothing.
|
|
4
4
|
tools: Read, Grep, Glob
|
|
5
|
-
model:
|
|
5
|
+
model: {{model}}
|
|
6
6
|
---
|
|
7
7
|
Brief: run `{{cli}} instructions ops` and follow it. The start hook gives you that brief, since you hold no tool that runs a command or writes a file. Your reply is the report; you take no action you propose. End every reply with "Skipped:" and "Not checked:" lines.
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
name: reviewer
|
|
3
3
|
description: Reviews a slice and writes a verdict file; writes no code.
|
|
4
4
|
tools: Read, Grep, Glob, Write, Bash
|
|
5
|
-
model:
|
|
5
|
+
model: {{model}}
|
|
6
6
|
---
|
|
7
7
|
Brief: run `{{cli}} instructions reviewer` and follow it. You never run a git command that commits, pushes or moves a branch; report and the command commits. End every reply with "Skipped:" and "Not checked:" lines.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Interview a person about an idea, one topic per question, and write the brief /slicekit intake takes as its source.
|
|
3
3
|
argument-hint: "[<slug>]"
|
|
4
|
+
model: {{model}}
|
|
4
5
|
---
|
|
5
6
|
Run `{{cli}} instructions --command brief $ARGUMENTS` and follow the procedure it prints. The procedure is the only source of this command's rules.
|
|
6
7
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Snapshot a requirement document and interview the human, writing one decision row per answer.
|
|
3
3
|
argument-hint: "<file or URL>"
|
|
4
|
+
model: {{model}}
|
|
4
5
|
---
|
|
5
6
|
Run `{{cli}} instructions --command intake $ARGUMENTS` and follow the procedure it prints. The procedure is the only source of this command's rules.
|
|
6
7
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Run the one next step of the program that slicekit next prints, then stop. Under /loop, one step per iteration.
|
|
3
3
|
argument-hint: ""
|
|
4
|
+
model: {{model}}
|
|
4
5
|
---
|
|
5
6
|
Run `{{cli}} instructions --command next $ARGUMENTS` and follow the procedure it prints. The procedure is the only source of this command's rules.
|
|
6
7
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Write the phases, slice files and BUILD.md, then open the plan pull request.
|
|
3
|
+
model: {{model}}
|
|
3
4
|
---
|
|
4
5
|
Run `{{cli}} instructions --command plan $ARGUMENTS` and follow the procedure it prints. The procedure is the only source of this command's rules.
|
|
5
6
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Write the spec files from the intake snapshots and decisions, then open the spec pull request.
|
|
3
|
+
model: {{model}}
|
|
3
4
|
---
|
|
4
5
|
Run `{{cli}} instructions --command specify $ARGUMENTS` and follow the procedure it prints. The procedure is the only source of this command's rules.
|
|
5
6
|
|