@pdxxxx/keel 1.1.0 → 2.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/ARCHITECTURE.md +52 -47
- package/CHANGELOG.md +20 -15
- package/LICENSE +21 -21
- package/README.md +46 -47
- package/README_CN.md +49 -50
- package/npm/bin/keel.js +25 -0
- package/npm/install.js +55 -0
- package/package.json +6 -27
- package/bin/keel.js +0 -4
- package/dist/cli.d.ts +0 -3
- package/dist/cli.js +0 -569
- package/dist/cli.js.map +0 -1
- package/dist/core/ablate.d.ts +0 -11
- package/dist/core/ablate.js +0 -54
- package/dist/core/ablate.js.map +0 -1
- package/dist/core/config.d.ts +0 -3
- package/dist/core/config.js +0 -60
- package/dist/core/config.js.map +0 -1
- package/dist/core/git.d.ts +0 -9
- package/dist/core/git.js +0 -48
- package/dist/core/git.js.map +0 -1
- package/dist/core/glob.d.ts +0 -8
- package/dist/core/glob.js +0 -61
- package/dist/core/glob.js.map +0 -1
- package/dist/core/hotspots.d.ts +0 -11
- package/dist/core/hotspots.js +0 -49
- package/dist/core/hotspots.js.map +0 -1
- package/dist/core/init.d.ts +0 -14
- package/dist/core/init.js +0 -117
- package/dist/core/init.js.map +0 -1
- package/dist/core/mcp.d.ts +0 -24
- package/dist/core/mcp.js +0 -323
- package/dist/core/mcp.js.map +0 -1
- package/dist/core/mem.d.ts +0 -21
- package/dist/core/mem.js +0 -337
- package/dist/core/mem.js.map +0 -1
- package/dist/core/migrate.d.ts +0 -21
- package/dist/core/migrate.js +0 -207
- package/dist/core/migrate.js.map +0 -1
- package/dist/core/paths.d.ts +0 -14
- package/dist/core/paths.js +0 -44
- package/dist/core/paths.js.map +0 -1
- package/dist/core/rules.d.ts +0 -22
- package/dist/core/rules.js +0 -262
- package/dist/core/rules.js.map +0 -1
- package/dist/core/snapshot.d.ts +0 -30
- package/dist/core/snapshot.js +0 -212
- package/dist/core/snapshot.js.map +0 -1
- package/dist/core/tasks.d.ts +0 -13
- package/dist/core/tasks.js +0 -180
- package/dist/core/tasks.js.map +0 -1
- package/dist/core/types.d.ts +0 -98
- package/dist/core/types.js +0 -2
- package/dist/core/types.js.map +0 -1
- package/dist/core/verify.d.ts +0 -8
- package/dist/core/verify.js +0 -66
- package/dist/core/verify.js.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -16
- package/dist/index.js.map +0 -1
- package/dist/templates/assets.d.ts +0 -11
- package/dist/templates/assets.js +0 -179
- package/dist/templates/assets.js.map +0 -1
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -2
- package/dist/version.js.map +0 -1
package/npm/install.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import { chmod, mkdir, readFile, rename, rm } from 'node:fs/promises';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { Readable, Transform } from 'node:stream';
|
|
6
|
+
import { pipeline } from 'node:stream/promises';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const assets = {
|
|
10
|
+
'win32/x64': 'keel-windows-x86_64.exe',
|
|
11
|
+
'darwin/arm64': 'keel-macos-arm64',
|
|
12
|
+
'darwin/x64': 'keel-macos-x86_64',
|
|
13
|
+
'linux/x64': 'keel-linux-x86_64',
|
|
14
|
+
'linux/arm64': 'keel-linux-aarch64',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
async function download(base, name) {
|
|
18
|
+
const url = new URL(name, base);
|
|
19
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(120_000) });
|
|
20
|
+
if (!response.ok || !response.body) {
|
|
21
|
+
await response.body?.cancel();
|
|
22
|
+
throw new Error(`Download failed: ${url} (HTTP ${response.status})`);
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function install() {
|
|
28
|
+
if (process.env.KEEL_SKIP_DOWNLOAD === '1') return;
|
|
29
|
+
const platform = `${process.platform}/${process.arch}`;
|
|
30
|
+
const asset = assets[platform];
|
|
31
|
+
if (!asset) throw new Error(`No prebuilt binary for ${platform}; build Keel using cargo install --git https://github.com/pdxxxx/keel`);
|
|
32
|
+
const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
33
|
+
const base = (process.env.KEEL_DOWNLOAD_BASE_URL || `https://github.com/pdxxxx/keel/releases/download/v${version}`).replace(/\/*$/, '/');
|
|
34
|
+
const manifest = await (await download(base, 'SHA256SUMS.txt')).text();
|
|
35
|
+
const hashes = manifest.split(/\r?\n/).map(line => /^([\da-f]{64})[ \t]+\*?(\S+)$/i.exec(line)).filter(match => match?.[2] === asset);
|
|
36
|
+
if (hashes.length !== 1) throw new Error(`Expected exactly one SHA-256 checksum for ${asset}`);
|
|
37
|
+
const native = join(dirname(fileURLToPath(import.meta.url)), 'native');
|
|
38
|
+
const dest = join(native, process.platform === 'win32' ? 'keel.exe' : 'keel');
|
|
39
|
+
await mkdir(native, { recursive: true });
|
|
40
|
+
const tmp = join(native, `.${randomUUID()}.tmp`);
|
|
41
|
+
try {
|
|
42
|
+
const binary = await download(base, asset);
|
|
43
|
+
const hash = createHash('sha256');
|
|
44
|
+
const verify = new Transform({ transform(chunk, encoding, callback) { hash.update(chunk); callback(null, chunk); } });
|
|
45
|
+
await pipeline(Readable.fromWeb(binary.body), verify, createWriteStream(tmp, { flags: 'wx', mode: 0o600 }));
|
|
46
|
+
if (hash.digest('hex') !== hashes[0][1].toLowerCase()) throw new Error(`SHA-256 mismatch for ${asset}; refusing to install`);
|
|
47
|
+
if (process.platform !== 'win32') await chmod(tmp, 0o755);
|
|
48
|
+
await rename(tmp, dest);
|
|
49
|
+
} finally {
|
|
50
|
+
await rm(tmp, { force: true });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try { await install(); }
|
|
55
|
+
catch (error) { console.error(`keel: ${error.message}`); process.exitCode = 1; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdxxxx/keel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Repo rules, task specs, session memory, and verification gates for coding agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,19 +30,11 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"bin": {
|
|
33
|
-
"keel": "bin/keel.js"
|
|
34
|
-
},
|
|
35
|
-
"main": "./dist/index.js",
|
|
36
|
-
"types": "./dist/index.d.ts",
|
|
37
|
-
"exports": {
|
|
38
|
-
".": {
|
|
39
|
-
"types": "./dist/index.d.ts",
|
|
40
|
-
"import": "./dist/index.js"
|
|
41
|
-
}
|
|
33
|
+
"keel": "npm/bin/keel.js"
|
|
42
34
|
},
|
|
43
35
|
"files": [
|
|
44
|
-
"bin",
|
|
45
|
-
"
|
|
36
|
+
"npm/bin",
|
|
37
|
+
"npm/install.js",
|
|
46
38
|
"README.md",
|
|
47
39
|
"README_CN.md",
|
|
48
40
|
"ARCHITECTURE.md",
|
|
@@ -50,20 +42,7 @@
|
|
|
50
42
|
"LICENSE"
|
|
51
43
|
],
|
|
52
44
|
"scripts": {
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"typecheck": "tsc --noEmit",
|
|
56
|
-
"test": "vitest run",
|
|
57
|
-
"test:watch": "vitest",
|
|
58
|
-
"prepublishOnly": "pnpm typecheck && pnpm build && pnpm test"
|
|
59
|
-
},
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"commander": "^13.1.0",
|
|
62
|
-
"yaml": "^2.7.0"
|
|
63
|
-
},
|
|
64
|
-
"devDependencies": {
|
|
65
|
-
"@types/node": "^22.13.0",
|
|
66
|
-
"typescript": "^5.8.2",
|
|
67
|
-
"vitest": "^3.0.8"
|
|
45
|
+
"postinstall": "node npm/install.js",
|
|
46
|
+
"test:npm": "node --test npm/test.mjs"
|
|
68
47
|
}
|
|
69
48
|
}
|
package/bin/keel.js
DELETED
package/dist/cli.d.ts
DELETED
package/dist/cli.js
DELETED
|
@@ -1,569 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import { ablateRepo, getAblateStatus, restoreRepo } from "./core/ablate.js";
|
|
5
|
-
import { getGitChangedFiles } from "./core/git.js";
|
|
6
|
-
import { gitHotspots } from "./core/hotspots.js";
|
|
7
|
-
import { initRepo } from "./core/init.js";
|
|
8
|
-
import { startMcpStdioServer } from "./core/mcp.js";
|
|
9
|
-
import { cleanupMigration, planMigration, rollbackMigration, scanMigration } from "./core/migrate.js";
|
|
10
|
-
import { getMemorySession, listMemorySessions, listMemorySources, searchMemory, } from "./core/mem.js";
|
|
11
|
-
import { resolveRepoRoot } from "./core/paths.js";
|
|
12
|
-
import { addRule, listRules, matchRules, validateRules } from "./core/rules.js";
|
|
13
|
-
import { archiveTask, createTask, getTask, listTasks, setTaskStatus, } from "./core/tasks.js";
|
|
14
|
-
import { runVerify } from "./core/verify.js";
|
|
15
|
-
import { KEEL_VERSION } from "./version.js";
|
|
16
|
-
function printJson(value) {
|
|
17
|
-
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
18
|
-
}
|
|
19
|
-
function parsePositiveInt(raw, fallback) {
|
|
20
|
-
if (!raw)
|
|
21
|
-
return fallback;
|
|
22
|
-
const parsed = Number.parseInt(raw, 10);
|
|
23
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
24
|
-
}
|
|
25
|
-
export function createProgram() {
|
|
26
|
-
const program = new Command();
|
|
27
|
-
program
|
|
28
|
-
.name("keel")
|
|
29
|
-
.description("Harness-agnostic engineering context, memory, and verification layer for AI coding.")
|
|
30
|
-
.version(KEEL_VERSION);
|
|
31
|
-
// keel init
|
|
32
|
-
program
|
|
33
|
-
.command("init")
|
|
34
|
-
.description("Initialize .keel/, managed AGENTS.md block, and standard .agents/skills/")
|
|
35
|
-
.option("-f, --force", "Overwrite existing Keel template files")
|
|
36
|
-
.option("--no-skills", "Skip installing standard .agents/skills/")
|
|
37
|
-
.option("--no-detect", "Skip auto-detecting verification gates")
|
|
38
|
-
.option("--json", "Output JSON")
|
|
39
|
-
.action((opts) => {
|
|
40
|
-
const root = process.cwd();
|
|
41
|
-
const result = initRepo(root, {
|
|
42
|
-
force: opts.force,
|
|
43
|
-
skipSkills: opts.skills === false,
|
|
44
|
-
detectGates: opts.detect !== false,
|
|
45
|
-
});
|
|
46
|
-
if (opts.json) {
|
|
47
|
-
printJson(result);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (result.created.length > 0) {
|
|
51
|
-
console.log("Created:");
|
|
52
|
-
for (const f of result.created)
|
|
53
|
-
console.log(` + ${f}`);
|
|
54
|
-
}
|
|
55
|
-
if (result.updated.length > 0) {
|
|
56
|
-
console.log("Updated:");
|
|
57
|
-
for (const f of result.updated)
|
|
58
|
-
console.log(` ~ ${f}`);
|
|
59
|
-
}
|
|
60
|
-
if (result.skipped.length > 0) {
|
|
61
|
-
console.log("Skipped (already exists):");
|
|
62
|
-
for (const f of result.skipped)
|
|
63
|
-
console.log(` - ${f}`);
|
|
64
|
-
}
|
|
65
|
-
if (result.detectedGates.length > 0) {
|
|
66
|
-
console.log("Detected verification gates:");
|
|
67
|
-
for (const g of result.detectedGates) {
|
|
68
|
-
console.log(` * ${g.name}: ${g.command}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
// keel rules
|
|
73
|
-
const rulesCmd = program
|
|
74
|
-
.command("rules")
|
|
75
|
-
.description("Discover, author, and validate scoped engineering invariants");
|
|
76
|
-
rulesCmd
|
|
77
|
-
.command("list")
|
|
78
|
-
.description("List all rules in .keel/rules/")
|
|
79
|
-
.option("--json", "Output JSON")
|
|
80
|
-
.action((opts) => {
|
|
81
|
-
const root = resolveRepoRoot();
|
|
82
|
-
const entries = listRules(root);
|
|
83
|
-
if (opts.json) {
|
|
84
|
-
printJson(entries);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (entries.length === 0) {
|
|
88
|
-
console.log("No rules found in .keel/rules/.");
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
for (const r of entries) {
|
|
92
|
-
const scope = r.global ? "global" : r.paths.join(", ");
|
|
93
|
-
console.log(`[${r.severity}] ${r.id} (${r.file})`);
|
|
94
|
-
if (r.summary)
|
|
95
|
-
console.log(` ${r.summary}`);
|
|
96
|
-
console.log(` scope: ${scope}`);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
rulesCmd
|
|
100
|
-
.command("match")
|
|
101
|
-
.description("Find rules matching file paths or current git changes (--git / --staged / --base)")
|
|
102
|
-
.argument("[paths...]", "Target file paths (relative to repo root)")
|
|
103
|
-
.option("--git", "Match against all uncommitted git changes")
|
|
104
|
-
.option("--staged", "Match against staged git changes")
|
|
105
|
-
.option("--base <ref>", "Match against files changed since git ref")
|
|
106
|
-
.option("--no-global", "Exclude global rules without path filters")
|
|
107
|
-
.option("--json", "Output JSON")
|
|
108
|
-
.action((targetPaths, opts) => {
|
|
109
|
-
const root = resolveRepoRoot();
|
|
110
|
-
const combined = new Set(targetPaths);
|
|
111
|
-
if (opts.git || opts.staged || opts.base) {
|
|
112
|
-
for (const f of getGitChangedFiles(root, {
|
|
113
|
-
staged: opts.staged,
|
|
114
|
-
baseRef: opts.base,
|
|
115
|
-
})) {
|
|
116
|
-
combined.add(f);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const targets = [...combined];
|
|
120
|
-
const matched = matchRules(root, targets, {
|
|
121
|
-
includeGlobal: opts.global !== false,
|
|
122
|
-
});
|
|
123
|
-
if (opts.json) {
|
|
124
|
-
printJson({ targets, matched });
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (matched.length === 0) {
|
|
128
|
-
console.log("No matching rules.");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
for (const r of matched) {
|
|
132
|
-
console.log(`[${r.severity}] ${r.id} -> ${r.file}`);
|
|
133
|
-
if (r.summary)
|
|
134
|
-
console.log(` ${r.summary}`);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
rulesCmd
|
|
138
|
-
.command("add")
|
|
139
|
-
.description("Create a scoped invariant, guideline, or ADR in .keel/rules/")
|
|
140
|
-
.argument("<id>", "Short kebab-case rule identifier")
|
|
141
|
-
.requiredOption("-s, --summary <text>", "One-line summary shown by match")
|
|
142
|
-
.option("--severity <level>", "Rule severity (invariant | guideline | adr)", "invariant")
|
|
143
|
-
.option("-p, --paths <glob...>", "POSIX glob pattern(s) scoping this rule")
|
|
144
|
-
.option("-f, --force", "Overwrite if rule file already exists")
|
|
145
|
-
.option("--json", "Output JSON")
|
|
146
|
-
.action((id, opts) => {
|
|
147
|
-
const root = resolveRepoRoot();
|
|
148
|
-
const entry = addRule(root, id, {
|
|
149
|
-
summary: opts.summary,
|
|
150
|
-
severity: opts.severity,
|
|
151
|
-
paths: opts.paths,
|
|
152
|
-
force: opts.force,
|
|
153
|
-
});
|
|
154
|
-
if (opts.json) {
|
|
155
|
-
printJson(entry);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
console.log(`Created rule [${entry.severity}] ${entry.id} -> ${entry.file}`);
|
|
159
|
-
});
|
|
160
|
-
rulesCmd
|
|
161
|
-
.command("check")
|
|
162
|
-
.description("Validate frontmatter, IDs, and schema of all .keel/rules/ files")
|
|
163
|
-
.option("--stale", "Warn about dead path globs, long rules and excess global rules")
|
|
164
|
-
.option("--strict", "Run stale checks and fail on warnings as well as errors")
|
|
165
|
-
.option("--json", "Output JSON")
|
|
166
|
-
.action((opts) => {
|
|
167
|
-
const root = resolveRepoRoot();
|
|
168
|
-
const report = validateRules(root, { stale: opts.stale || opts.strict });
|
|
169
|
-
if (opts.json) {
|
|
170
|
-
printJson(report);
|
|
171
|
-
}
|
|
172
|
-
else if (report.valid) {
|
|
173
|
-
console.log(`Rules OK (${report.checked} checked, 0 issues).`);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
console.log(`Rule validation failed (${report.issues.length} issue(s)):`);
|
|
177
|
-
for (const issue of report.issues) {
|
|
178
|
-
console.log(` - ${issue.file}: ${issue.message}`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (!opts.json)
|
|
182
|
-
for (const warning of report.warnings ?? [])
|
|
183
|
-
console.log(` [WARN] ${warning.file}: ${warning.message}`);
|
|
184
|
-
if (!report.valid || (opts.strict && report.warnings?.length)) {
|
|
185
|
-
process.exitCode = 1;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
// keel task
|
|
189
|
-
const taskCmd = program
|
|
190
|
-
.command("task")
|
|
191
|
-
.description("Manage lightweight task specs under .keel/tasks/");
|
|
192
|
-
taskCmd
|
|
193
|
-
.command("create")
|
|
194
|
-
.description("Create a new task directory with spec.md and meta.json")
|
|
195
|
-
.argument("<title>", "Task title")
|
|
196
|
-
.option("--slug <slug>", "Custom slug for the task folder")
|
|
197
|
-
.option("--json", "Output JSON")
|
|
198
|
-
.action((title, opts) => {
|
|
199
|
-
const root = resolveRepoRoot();
|
|
200
|
-
const record = createTask(root, title, { slug: opts.slug });
|
|
201
|
-
if (opts.json) {
|
|
202
|
-
printJson(record);
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
console.log(`Created task ${record.id}`);
|
|
206
|
-
console.log(` spec: ${record.specFile}`);
|
|
207
|
-
});
|
|
208
|
-
taskCmd
|
|
209
|
-
.command("list")
|
|
210
|
-
.description("List tasks under .keel/tasks/")
|
|
211
|
-
.option("--all", "Include archived tasks")
|
|
212
|
-
.option("--status <status>", "Filter by status (open | done)")
|
|
213
|
-
.option("--json", "Output JSON")
|
|
214
|
-
.action((opts) => {
|
|
215
|
-
const root = resolveRepoRoot();
|
|
216
|
-
const status = opts.status === "open" || opts.status === "done"
|
|
217
|
-
? opts.status
|
|
218
|
-
: undefined;
|
|
219
|
-
const records = listTasks(root, {
|
|
220
|
-
status,
|
|
221
|
-
includeArchived: Boolean(opts.all),
|
|
222
|
-
});
|
|
223
|
-
if (opts.json) {
|
|
224
|
-
printJson(records);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (records.length === 0) {
|
|
228
|
-
console.log("No tasks found.");
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
for (const t of records) {
|
|
232
|
-
console.log(`[${t.status}] ${t.id} — ${t.title} (${t.specFile})`);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
taskCmd
|
|
236
|
-
.command("show")
|
|
237
|
-
.description("Print a task's metadata and spec.md")
|
|
238
|
-
.argument("<id>", "Task ID")
|
|
239
|
-
.option("--json", "Output JSON")
|
|
240
|
-
.action((id, opts) => {
|
|
241
|
-
const root = resolveRepoRoot();
|
|
242
|
-
const record = getTask(root, id);
|
|
243
|
-
const specBody = fs.readFileSync(path.join(root, record.specFile), "utf-8");
|
|
244
|
-
if (opts.json) {
|
|
245
|
-
printJson({ ...record, spec: specBody });
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
console.log(specBody);
|
|
249
|
-
});
|
|
250
|
-
taskCmd
|
|
251
|
-
.command("done")
|
|
252
|
-
.description("Mark a task as done")
|
|
253
|
-
.argument("<id>", "Task ID")
|
|
254
|
-
.option("--json", "Output JSON")
|
|
255
|
-
.action((id, opts) => {
|
|
256
|
-
const root = resolveRepoRoot();
|
|
257
|
-
const record = setTaskStatus(root, id, "done");
|
|
258
|
-
if (opts.json) {
|
|
259
|
-
printJson(record);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
console.log(`Marked ${record.id} as done.`);
|
|
263
|
-
});
|
|
264
|
-
taskCmd
|
|
265
|
-
.command("reopen")
|
|
266
|
-
.description("Reopen a completed task")
|
|
267
|
-
.argument("<id>", "Task ID")
|
|
268
|
-
.option("--json", "Output JSON")
|
|
269
|
-
.action((id, opts) => {
|
|
270
|
-
const root = resolveRepoRoot();
|
|
271
|
-
const record = setTaskStatus(root, id, "open");
|
|
272
|
-
if (opts.json) {
|
|
273
|
-
printJson(record);
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
console.log(`Reopened ${record.id}.`);
|
|
277
|
-
});
|
|
278
|
-
taskCmd
|
|
279
|
-
.command("archive")
|
|
280
|
-
.description("Mark a task done and move it to .keel/tasks/archive/")
|
|
281
|
-
.argument("<id>", "Task ID")
|
|
282
|
-
.option("--json", "Output JSON")
|
|
283
|
-
.action((id, opts) => {
|
|
284
|
-
const root = resolveRepoRoot();
|
|
285
|
-
const record = archiveTask(root, id);
|
|
286
|
-
if (opts.json) {
|
|
287
|
-
printJson(record);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
console.log(`Archived ${record.id} -> ${record.dir}`);
|
|
291
|
-
});
|
|
292
|
-
// keel verify
|
|
293
|
-
program
|
|
294
|
-
.command("verify")
|
|
295
|
-
.description("Run deterministic verification gates from .keel/config.yaml")
|
|
296
|
-
.option("-g, --gate <name...>", "Run specific gate(s) by name")
|
|
297
|
-
.option("--git", "Run global gates and gates matching uncommitted files")
|
|
298
|
-
.option("--staged", "Scope gates to staged changes")
|
|
299
|
-
.option("--base <ref>", "Scope gates to changes since a Git ref")
|
|
300
|
-
.option("--fail-fast", "Stop running remaining gates after first failure")
|
|
301
|
-
.option("--json", "Output JSON")
|
|
302
|
-
.action((opts) => {
|
|
303
|
-
const root = resolveRepoRoot();
|
|
304
|
-
const report = runVerify(root, {
|
|
305
|
-
gateNames: opts.gate,
|
|
306
|
-
git: opts.git, staged: opts.staged, baseRef: opts.base,
|
|
307
|
-
failFast: opts.failFast,
|
|
308
|
-
});
|
|
309
|
-
if (opts.json) {
|
|
310
|
-
printJson(report);
|
|
311
|
-
}
|
|
312
|
-
else if (report.gates.length === 0) {
|
|
313
|
-
console.log(report.skipped?.length ? "No gates match the changed files." : "No verification gates configured in .keel/config.yaml yet.");
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
for (const g of report.gates) {
|
|
317
|
-
const icon = g.passed ? "PASS" : "FAIL";
|
|
318
|
-
console.log(`[${icon}] ${g.name} (${g.durationMs}ms) — ${g.command}`);
|
|
319
|
-
if (!g.passed && g.output) {
|
|
320
|
-
console.log(g.output);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
if (!opts.json && report.skipped?.length)
|
|
325
|
-
console.log(`Skipped by path: ${report.skipped.join(", ")}`);
|
|
326
|
-
if (!report.passed) {
|
|
327
|
-
process.exitCode = 1;
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
program.command("hotspots")
|
|
331
|
-
.description("Rank existing files by recent changes and bugfix commits")
|
|
332
|
-
.option("--commits <n>", "Number of recent commits to inspect", "100")
|
|
333
|
-
.option("--limit <n>", "Maximum files to return", "10")
|
|
334
|
-
.option("--json", "Output JSON")
|
|
335
|
-
.action((opts) => {
|
|
336
|
-
const hits = gitHotspots(resolveRepoRoot(), parsePositiveInt(opts.commits, 100), parsePositiveInt(opts.limit, 10));
|
|
337
|
-
if (opts.json)
|
|
338
|
-
return printJson(hits);
|
|
339
|
-
if (!hits.length)
|
|
340
|
-
console.log("No hotspots found in Git history.");
|
|
341
|
-
for (const hit of hits) {
|
|
342
|
-
console.log(`${hit.file}: score ${hit.score} (${hit.fixTouches} fix / ${hit.touches} total touches)`);
|
|
343
|
-
for (const fix of hit.recentFixes)
|
|
344
|
-
console.log(` ${fix.hash} ${fix.subject}`);
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
// keel mem
|
|
348
|
-
const memCmd = program
|
|
349
|
-
.command("mem")
|
|
350
|
-
.description("Search and inspect local AI coding sessions and repository specs");
|
|
351
|
-
memCmd
|
|
352
|
-
.command("sources")
|
|
353
|
-
.description("List discovered memory sources and session counts")
|
|
354
|
-
.option("--source <name>", "Filter to a specific source")
|
|
355
|
-
.option("--json", "Output JSON")
|
|
356
|
-
.action((opts) => {
|
|
357
|
-
const root = resolveRepoRoot();
|
|
358
|
-
const stats = listMemorySources(root, { source: opts.source });
|
|
359
|
-
if (opts.json) {
|
|
360
|
-
printJson(stats);
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
for (const s of stats) {
|
|
364
|
-
const locs = s.locations.length > 0 ? s.locations.join(", ") : "(none)";
|
|
365
|
-
console.log(`${s.source}: ${s.sessionCount} session(s) — ${locs}`);
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
memCmd
|
|
369
|
-
.command("sessions")
|
|
370
|
-
.description("List recent sessions across local AI tools and .keel/")
|
|
371
|
-
.option("--source <name>", "Filter by source (keel | claude | codex | opencode | custom)")
|
|
372
|
-
.option("-n, --limit <count>", "Max sessions to return", "20")
|
|
373
|
-
.option("--json", "Output JSON")
|
|
374
|
-
.action((opts) => {
|
|
375
|
-
const root = resolveRepoRoot();
|
|
376
|
-
const sessions = listMemorySessions(root, {
|
|
377
|
-
source: opts.source,
|
|
378
|
-
limit: parsePositiveInt(opts.limit, 20),
|
|
379
|
-
});
|
|
380
|
-
if (opts.json) {
|
|
381
|
-
printJson(sessions);
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (sessions.length === 0) {
|
|
385
|
-
console.log("No sessions found.");
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
for (const s of sessions) {
|
|
389
|
-
console.log(`[${s.source}] ${s.id} (${s.turnCount} turns) — ${s.title}`);
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
memCmd
|
|
393
|
-
.command("search")
|
|
394
|
-
.description("Search sessions and repo artifacts by keywords")
|
|
395
|
-
.argument("<query>", "Search query")
|
|
396
|
-
.option("--source <name>", "Filter by source")
|
|
397
|
-
.option("-n, --limit <count>", "Max hits to return", "15")
|
|
398
|
-
.option("--json", "Output JSON")
|
|
399
|
-
.action((query, opts) => {
|
|
400
|
-
const root = resolveRepoRoot();
|
|
401
|
-
const hits = searchMemory(root, query, {
|
|
402
|
-
source: opts.source,
|
|
403
|
-
limit: parsePositiveInt(opts.limit, 15),
|
|
404
|
-
});
|
|
405
|
-
if (opts.json) {
|
|
406
|
-
printJson(hits);
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
if (hits.length === 0) {
|
|
410
|
-
console.log("No matches found.");
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
for (const h of hits) {
|
|
414
|
-
console.log(`[${h.source}/${h.role}] ${h.sessionId} (score ${h.score})`);
|
|
415
|
-
console.log(` ${h.snippet}`);
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
memCmd
|
|
419
|
-
.command("show")
|
|
420
|
-
.description("Show turns from a specific memory session")
|
|
421
|
-
.argument("<sessionId>", "Session ID (full or suffix)")
|
|
422
|
-
.option("-n, --limit <count>", "Max turns to print", "30")
|
|
423
|
-
.option("--json", "Output JSON")
|
|
424
|
-
.action((sessionId, opts) => {
|
|
425
|
-
const root = resolveRepoRoot();
|
|
426
|
-
const detail = getMemorySession(root, sessionId);
|
|
427
|
-
const maxTurns = parsePositiveInt(opts.limit, 30);
|
|
428
|
-
const turns = detail.turns.slice(0, maxTurns);
|
|
429
|
-
if (opts.json) {
|
|
430
|
-
printJson({ summary: detail.summary, turns });
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
console.log(`# ${detail.summary.title} (${detail.summary.id})`);
|
|
434
|
-
for (const turn of turns) {
|
|
435
|
-
console.log(`\n[${turn.role}]`);
|
|
436
|
-
console.log(turn.text);
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
const migrate = program.command("migrate").description("Inspect legacy AI setups and safely retire conflicting files");
|
|
440
|
-
migrate.command("scan").description("Inventory legacy surfaces without writing files").option("--json", "Output JSON").action((opts) => {
|
|
441
|
-
const scan = scanMigration(resolveRepoRoot());
|
|
442
|
-
if (opts.json)
|
|
443
|
-
return printJson(scan);
|
|
444
|
-
if (!scan.items.length)
|
|
445
|
-
console.log("No migration surfaces found.");
|
|
446
|
-
for (const item of scan.items)
|
|
447
|
-
console.log(`[${item.category}] ${item.framework}: ${item.path}${item.globs ? ` (${item.globs.join(", ")})` : ""}`);
|
|
448
|
-
});
|
|
449
|
-
migrate.command("plan").description("Suggest conflicts, gates, memory sources and rules to distill").option("--json", "Output JSON").action((opts) => {
|
|
450
|
-
const plan = planMigration(resolveRepoRoot());
|
|
451
|
-
if (opts.json)
|
|
452
|
-
return printJson(plan);
|
|
453
|
-
for (const item of plan.conflicts)
|
|
454
|
-
console.log(`[conflict] ${item.path}`);
|
|
455
|
-
for (const gate of plan.suggestedGates)
|
|
456
|
-
console.log(`[gate] ${gate.name}: ${gate.command}`);
|
|
457
|
-
for (const dir of plan.suggestedMemorySources)
|
|
458
|
-
console.log(`[memory] ${dir}`);
|
|
459
|
-
for (const item of plan.ruleSources)
|
|
460
|
-
console.log(`[distill] ${item.path}`);
|
|
461
|
-
});
|
|
462
|
-
migrate.command("cleanup").description("Back up and remove only conflicting legacy surfaces")
|
|
463
|
-
.option("--dry-run", "Preview every affected file and directory; write nothing")
|
|
464
|
-
.option("--state-dir <dir>", "External backup directory").option("--json", "Output JSON").action((opts) => {
|
|
465
|
-
const result = cleanupMigration(resolveRepoRoot(), opts);
|
|
466
|
-
if (opts.json)
|
|
467
|
-
return printJson(result);
|
|
468
|
-
console.log(`${result.dryRun ? "Would clean" : "Cleaned"} ${result.entries.length} file(s); snapshot: ${result.snapshotDir}`);
|
|
469
|
-
for (const item of result.entries)
|
|
470
|
-
console.log(` ${item.relativePath}`);
|
|
471
|
-
for (const dir of result.directories ?? [])
|
|
472
|
-
console.log(` ${dir}/`);
|
|
473
|
-
});
|
|
474
|
-
migrate.command("rollback").description("Restore a verified migration snapshot")
|
|
475
|
-
.option("--state-dir <dir>", "External backup directory").option("--force", "Overwrite conflicting files")
|
|
476
|
-
.option("--json", "Output JSON").action((opts) => {
|
|
477
|
-
const result = rollbackMigration(resolveRepoRoot(), opts);
|
|
478
|
-
if (opts.json)
|
|
479
|
-
return printJson(result);
|
|
480
|
-
console.log(`Restored ${result.restored.length} file(s).`);
|
|
481
|
-
for (const file of result.restored)
|
|
482
|
-
console.log(` ${file}`);
|
|
483
|
-
});
|
|
484
|
-
// keel ablate & restore
|
|
485
|
-
const ablateCmd = program
|
|
486
|
-
.command("ablate")
|
|
487
|
-
.description("Temporarily remove Keel surfaces into a verified external snapshot for A/B testing")
|
|
488
|
-
.option("--dry-run", "Preview files that would be ablated without modifying disk")
|
|
489
|
-
.option("--state-dir <dir>", "Override external snapshot directory")
|
|
490
|
-
.option("--json", "Output JSON")
|
|
491
|
-
.action((opts) => {
|
|
492
|
-
const root = resolveRepoRoot();
|
|
493
|
-
const res = ablateRepo(root, {
|
|
494
|
-
dryRun: opts.dryRun,
|
|
495
|
-
stateDir: opts.stateDir,
|
|
496
|
-
});
|
|
497
|
-
if (opts.json) {
|
|
498
|
-
printJson(res);
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
const verb = res.dryRun ? "Would ablate" : "Ablated";
|
|
502
|
-
console.log(`${verb} ${res.entries.length} Keel surface(s):`);
|
|
503
|
-
for (const e of res.entries) {
|
|
504
|
-
console.log(` - ${e.relativePath} (${e.kind})`);
|
|
505
|
-
}
|
|
506
|
-
if (!res.dryRun) {
|
|
507
|
-
console.log(`Snapshot saved at: ${res.snapshotDir}`);
|
|
508
|
-
console.log("Run `keel restore` to recover the exact prior state.");
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
ablateCmd
|
|
512
|
-
.command("status")
|
|
513
|
-
.description("Check whether the current repository is ablated")
|
|
514
|
-
.option("--state-dir <dir>", "Override external snapshot directory")
|
|
515
|
-
.option("--json", "Output JSON")
|
|
516
|
-
.action((opts) => {
|
|
517
|
-
const root = resolveRepoRoot();
|
|
518
|
-
const status = getAblateStatus(root, opts.stateDir);
|
|
519
|
-
if (opts.json) {
|
|
520
|
-
printJson(status);
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
if (status.ablated) {
|
|
524
|
-
console.log(`Repository is ABLATED (${status.entryCount} entries, since ${status.createdAt}).`);
|
|
525
|
-
console.log(`Snapshot: ${status.snapshotDir}`);
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
console.log("Repository is not ablated.");
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
program
|
|
532
|
-
.command("restore")
|
|
533
|
-
.description("Restore Keel surfaces from the verified external ablation snapshot")
|
|
534
|
-
.option("--dry-run", "Preview restoration and check for conflicts without writing")
|
|
535
|
-
.option("-f, --force", "Overwrite paths even if modified while ablated")
|
|
536
|
-
.option("--state-dir <dir>", "Override external snapshot directory")
|
|
537
|
-
.option("--json", "Output JSON")
|
|
538
|
-
.action((opts) => {
|
|
539
|
-
const root = resolveRepoRoot();
|
|
540
|
-
const res = restoreRepo(root, {
|
|
541
|
-
dryRun: opts.dryRun,
|
|
542
|
-
force: opts.force,
|
|
543
|
-
stateDir: opts.stateDir,
|
|
544
|
-
});
|
|
545
|
-
if (opts.json) {
|
|
546
|
-
printJson(res);
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
const verb = res.dryRun ? "Would restore" : "Restored";
|
|
550
|
-
console.log(`${verb} ${res.restored.length} file(s):`);
|
|
551
|
-
for (const f of res.restored) {
|
|
552
|
-
console.log(` + ${f}`);
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
// keel mcp
|
|
556
|
-
program
|
|
557
|
-
.command("mcp")
|
|
558
|
-
.description("Start Keel's built-in stdio MCP server for the current repository")
|
|
559
|
-
.action(async () => {
|
|
560
|
-
const root = resolveRepoRoot();
|
|
561
|
-
await startMcpStdioServer(root);
|
|
562
|
-
});
|
|
563
|
-
return program;
|
|
564
|
-
}
|
|
565
|
-
export async function runCli(argv) {
|
|
566
|
-
const program = createProgram();
|
|
567
|
-
await program.parseAsync(argv);
|
|
568
|
-
}
|
|
569
|
-
//# sourceMappingURL=cli.js.map
|