@kyuki3rain/cupola 0.0.0-stage → 0.2.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/CHANGELOG.md +184 -0
- package/LICENSE +202 -0
- package/README.md +41 -2
- package/dist/adr.js +106 -0
- package/dist/branch-store.js +73 -0
- package/dist/catalog.js +137 -0
- package/dist/check.js +192 -0
- package/dist/cli.js +8 -0
- package/dist/code.js +216 -0
- package/dist/commands/change.js +728 -0
- package/dist/commands/epic.js +311 -0
- package/dist/commands/execution.js +482 -0
- package/dist/commands/install.js +109 -0
- package/dist/commands/locks.js +243 -0
- package/dist/commands/reaction.js +185 -0
- package/dist/commands/revision.js +139 -0
- package/dist/commands/run.js +1021 -0
- package/dist/commands/setup.js +414 -0
- package/dist/commands/spec.js +80 -0
- package/dist/commands/status.js +1457 -0
- package/dist/commands/trace.js +474 -0
- package/dist/commands/wait.js +105 -0
- package/dist/commands/work.js +126 -0
- package/dist/commands/workspace.js +137 -0
- package/dist/commands/worktree.js +422 -0
- package/dist/config.js +353 -0
- package/dist/day.js +29 -0
- package/dist/e2e-project.js +62 -0
- package/dist/e2e.js +207 -0
- package/dist/engine/cc-sdd.js +164 -0
- package/dist/epic.js +379 -0
- package/dist/execution.js +272 -0
- package/dist/feedback.js +20 -0
- package/dist/frontmatter.js +20 -0
- package/dist/git.js +365 -0
- package/dist/host/git.js +224 -0
- package/dist/host/github.js +387 -0
- package/dist/host/host.js +3 -0
- package/dist/host/index.js +63 -0
- package/dist/install.js +182 -0
- package/dist/io.js +46 -0
- package/dist/main.js +866 -0
- package/dist/method/v1.js +56 -0
- package/dist/reaction.js +110 -0
- package/dist/record.js +507 -0
- package/dist/release.js +84 -0
- package/dist/repo.js +13 -0
- package/dist/runbook.js +132 -0
- package/dist/safe-write.js +80 -0
- package/dist/spec.js +171 -0
- package/dist/status.js +321 -0
- package/dist/templates.js +50 -0
- package/dist/trace.js +275 -0
- package/dist/tracker/files.js +99 -0
- package/dist/tracker/github-issues.js +217 -0
- package/dist/tracker/index.js +34 -0
- package/dist/tracker/tracker.js +69 -0
- package/dist/tree.js +59 -0
- package/dist/trust.js +13 -0
- package/dist/version.js +5 -0
- package/dist/work.js +170 -0
- package/dist/workspace.js +324 -0
- package/npm-shrinkwrap.json +2014 -0
- package/package.json +41 -4
- package/skills/cupola-abort/SKILL.md +51 -0
- package/skills/cupola-adr/SKILL.md +54 -0
- package/skills/cupola-ask/SKILL.md +42 -0
- package/skills/cupola-catalog/SKILL.md +41 -0
- package/skills/cupola-catalog-draft/SKILL.md +116 -0
- package/skills/cupola-complete/SKILL.md +107 -0
- package/skills/cupola-decide/SKILL.md +99 -0
- package/skills/cupola-doc/SKILL.md +52 -0
- package/skills/cupola-e2e-setup/SKILL.md +78 -0
- package/skills/cupola-e2e-test/SKILL.md +115 -0
- package/skills/cupola-epic-accept/SKILL.md +166 -0
- package/skills/cupola-epic-create/SKILL.md +160 -0
- package/skills/cupola-epic-revise/SKILL.md +92 -0
- package/skills/cupola-epic-run/SKILL.md +166 -0
- package/skills/cupola-fix/SKILL.md +117 -0
- package/skills/cupola-init/SKILL.md +143 -0
- package/skills/cupola-intake/SKILL.md +95 -0
- package/skills/cupola-operate/SKILL.md +81 -0
- package/skills/cupola-resolve/SKILL.md +93 -0
- package/skills/cupola-respond/SKILL.md +73 -0
- package/skills/cupola-review/SKILL.md +131 -0
- package/skills/cupola-spec-design/SKILL.md +169 -0
- package/skills/cupola-spec-impl/SKILL.md +137 -0
- package/skills/cupola-spec-run/SKILL.md +137 -0
- package/skills/cupola-steering/SKILL.md +53 -0
- package/skills/cupola-try/SKILL.md +38 -0
- package/templates/install/.kiro/steering/e2e.md +48 -0
- package/templates/install/.kiro/steering/operations.md +109 -0
- package/templates/install/.kiro/steering/principles.md +25 -0
- package/templates/install/CLAUDE.md +19 -0
- package/templates/install/adr/TEMPLATE.md +38 -0
- package/templates/install/cc-sdd/patches.json +31 -0
- package/templates/method-1/behavior-area.md +43 -0
- package/templates/method-1/behavior-index.md +16 -0
- package/templates/method-1/card.md +49 -0
- package/templates/method-1/case-draft.md +25 -0
- package/templates/method-1/case.md +38 -0
- package/templates/method-1/catalog-spec.md +33 -0
- package/templates/method-1/changes/adr.md +4 -0
- package/templates/method-1/changes/catalog.md +29 -0
- package/templates/method-1/changes/doc.md +5 -0
- package/templates/method-1/changes/e2e.md +7 -0
- package/templates/method-1/changes/epic.md +30 -0
- package/templates/method-1/changes/fix.md +21 -0
- package/templates/method-1/changes/release.md +23 -0
- package/templates/method-1/changes/spec.md +55 -0
- package/templates/method-1/changes/system.md +13 -0
- package/templates/method-1/cupola-issue-draft.md +17 -0
- package/templates/method-1/epic.md +147 -0
- package/templates/method-1/execution.md +55 -0
- package/templates/method-1/fix-spec.md +34 -0
- package/templates/method-1/fix.md +39 -0
- package/templates/method-1/lock.json +13 -0
- package/templates/method-1/no-go.md +28 -0
- package/templates/method-1/phase-outcome.json +29 -0
- package/templates/method-1/reaction.md +17 -0
- package/templates/method-1/record.json +63 -0
- package/templates/method-1/report.md +27 -0
- package/templates/method-1/runbook.md +45 -0
- package/templates/method-1/runner-result.json +6 -0
- package/templates/methods.json +13 -0
package/dist/install.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
4
|
+
import { join, sep } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { DEFAULT_PATHS } from "./config.js";
|
|
7
|
+
import { applyPatch, CC_SDD_VERSION, PatchError, Patches, runCcSdd, } from "./engine/cc-sdd.js";
|
|
8
|
+
import { METHOD } from "./method/v1.js";
|
|
9
|
+
import { writeInside } from "./safe-write.js";
|
|
10
|
+
import { version } from "./version.js";
|
|
11
|
+
export const MANIFEST = join(".cupola", "manifest.json");
|
|
12
|
+
const BEGIN = "<!-- cupola:begin";
|
|
13
|
+
const END = "<!-- cupola:end -->";
|
|
14
|
+
const pkg = (path) => fileURLToPath(new URL(`../${path}`, import.meta.url));
|
|
15
|
+
const sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
16
|
+
/** cc-sdd's files with Cupola's patches applied. */
|
|
17
|
+
async function engineFiles(engine, language) {
|
|
18
|
+
const { patches } = Patches.parse(JSON.parse(await readFile(pkg("templates/install/cc-sdd/patches.json"), "utf8")));
|
|
19
|
+
const files = await engine(language);
|
|
20
|
+
for (const p of patches) {
|
|
21
|
+
if (!files.some((f) => f.path === p.file)) {
|
|
22
|
+
throw new PatchError(`patch ${p.id}: cc-sdd ${CC_SDD_VERSION} wrote no ${p.file}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return files.map((f) => {
|
|
26
|
+
const mine = patches.filter((p) => p.file === f.path);
|
|
27
|
+
return {
|
|
28
|
+
path: f.path,
|
|
29
|
+
owner: "engine-patched",
|
|
30
|
+
content: mine.reduce(applyPatch, f.content),
|
|
31
|
+
pristine: f.content,
|
|
32
|
+
patches: mine.map((p) => p.id),
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** What the package installs: path in the project → content and owner. */
|
|
37
|
+
async function payload(engine, adr) {
|
|
38
|
+
const files = [];
|
|
39
|
+
if (engine)
|
|
40
|
+
files.push(...(await engineFiles(engine.generate, engine.language)));
|
|
41
|
+
for (const skill of (await readdir(pkg("skills"))).sort()) {
|
|
42
|
+
const content = await readFile(pkg(join("skills", skill, "SKILL.md")), "utf8");
|
|
43
|
+
files.push({ path: join(".claude", "skills", skill, "SKILL.md"), owner: "cupola", content });
|
|
44
|
+
}
|
|
45
|
+
// Decision records are the project's, kept in the hub only.
|
|
46
|
+
if (adr)
|
|
47
|
+
files.push({
|
|
48
|
+
path: join(adr, "TEMPLATE.md"),
|
|
49
|
+
owner: "cupola",
|
|
50
|
+
content: await readFile(pkg("templates/install/adr/TEMPLATE.md"), "utf8"),
|
|
51
|
+
});
|
|
52
|
+
files.push({
|
|
53
|
+
path: "CLAUDE.md",
|
|
54
|
+
owner: "cupola-section",
|
|
55
|
+
content: await readFile(pkg("templates/install/CLAUDE.md"), "utf8"),
|
|
56
|
+
});
|
|
57
|
+
files.push({
|
|
58
|
+
path: join(".kiro", "steering", "principles.md"),
|
|
59
|
+
owner: "project",
|
|
60
|
+
content: await readFile(pkg("templates/install/.kiro/steering/principles.md"), "utf8"),
|
|
61
|
+
});
|
|
62
|
+
return files;
|
|
63
|
+
}
|
|
64
|
+
/** Whether a path was chosen: named itself, or a directory holding it (`.claude/skills/`). */
|
|
65
|
+
function chosen(paths, path) {
|
|
66
|
+
const p = path.split(sep).join("/");
|
|
67
|
+
return (paths ?? []).some((c) => {
|
|
68
|
+
const d = c.split(sep).join("/").replace(/\/+$/, "");
|
|
69
|
+
return p === d || d === "." || p.startsWith(`${d}/`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** The marked section of CLAUDE.md, or undefined when there is none. */
|
|
73
|
+
function section(text) {
|
|
74
|
+
const start = text.indexOf(BEGIN);
|
|
75
|
+
const end = text.indexOf(END, start);
|
|
76
|
+
return start < 0 || end < 0 ? undefined : text.slice(start, end + END.length);
|
|
77
|
+
}
|
|
78
|
+
export async function readManifest(root) {
|
|
79
|
+
const path = join(root, MANIFEST);
|
|
80
|
+
return existsSync(path) ? JSON.parse(await readFile(path, "utf8")) : undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Installs or updates Cupola's files. A file is overwritten only when it is
|
|
84
|
+
* as Cupola installed it; one edited locally is kept when the package did not
|
|
85
|
+
* change it, and is a conflict when both changed, unless the human chose.
|
|
86
|
+
*/
|
|
87
|
+
export async function update(root, choice = {},
|
|
88
|
+
/** The spec engine to install; without it, the engine's files are left as they are. */
|
|
89
|
+
engine,
|
|
90
|
+
/** The hub's directory of decision records; the ADR template goes only there (none: not the hub). */
|
|
91
|
+
adr = DEFAULT_PATHS.adr) {
|
|
92
|
+
const manifest = (await readManifest(root)) ?? {
|
|
93
|
+
manifest: 1,
|
|
94
|
+
package: version(),
|
|
95
|
+
method: METHOD,
|
|
96
|
+
migrations: [],
|
|
97
|
+
files: {},
|
|
98
|
+
};
|
|
99
|
+
const result = { written: [], kept: [], conflicts: [] };
|
|
100
|
+
const plan = [];
|
|
101
|
+
const files = await payload(engine ? { language: engine.language, generate: engine.generate ?? runCcSdd } : undefined, adr);
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
const full = join(root, file.path);
|
|
104
|
+
const before = manifest.files[file.path];
|
|
105
|
+
const exists = existsSync(full);
|
|
106
|
+
const current = exists ? await readFile(full, "utf8") : undefined;
|
|
107
|
+
if (file.owner === "project") {
|
|
108
|
+
if (!exists)
|
|
109
|
+
plan.push({
|
|
110
|
+
path: file.path,
|
|
111
|
+
text: file.content,
|
|
112
|
+
record: { owner: "project", sha256: sha(file.content) },
|
|
113
|
+
});
|
|
114
|
+
else
|
|
115
|
+
result.kept.push(file.path);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const mine = file.owner === "cupola-section"
|
|
119
|
+
? current === undefined
|
|
120
|
+
? undefined
|
|
121
|
+
: section(current)
|
|
122
|
+
: current;
|
|
123
|
+
const upstream = file.owner === "cupola-section" ? (section(file.content) ?? file.content) : file.content;
|
|
124
|
+
const record = {
|
|
125
|
+
owner: file.owner,
|
|
126
|
+
sha256: sha(upstream),
|
|
127
|
+
...(file.patches?.length ? { patches: file.patches } : {}),
|
|
128
|
+
};
|
|
129
|
+
const write = () => {
|
|
130
|
+
let text = upstream;
|
|
131
|
+
if (file.owner === "cupola-section") {
|
|
132
|
+
text =
|
|
133
|
+
current === undefined
|
|
134
|
+
? `${upstream}\n`
|
|
135
|
+
: mine === undefined
|
|
136
|
+
? `${current.trimEnd()}\n\n${upstream}\n`
|
|
137
|
+
: current.replace(mine, upstream);
|
|
138
|
+
}
|
|
139
|
+
plan.push({ path: file.path, text, record });
|
|
140
|
+
};
|
|
141
|
+
if (mine === undefined || mine === upstream) {
|
|
142
|
+
if (mine === undefined)
|
|
143
|
+
write();
|
|
144
|
+
else
|
|
145
|
+
manifest.files[file.path] = record;
|
|
146
|
+
if (mine === upstream)
|
|
147
|
+
result.kept.push(file.path);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
// A file the engine wrote itself (installed by hand, before Cupola) is not a local edit.
|
|
151
|
+
const editedLocally = before === undefined ? mine !== file.pristine : sha(mine) !== before.sha256;
|
|
152
|
+
if (!editedLocally || chosen(choice.takeNew, file.path)) {
|
|
153
|
+
write();
|
|
154
|
+
}
|
|
155
|
+
else if (before && before.sha256 === record.sha256) {
|
|
156
|
+
result.kept.push(file.path); // only the local edit: keep it
|
|
157
|
+
}
|
|
158
|
+
else if (chosen(choice.keep, file.path)) {
|
|
159
|
+
result.kept.push(file.path);
|
|
160
|
+
// The upstream it was kept against, so later updates keep it too; Cupola's patches are not
|
|
161
|
+
// in it.
|
|
162
|
+
const { patches: _applied, ...kept } = record;
|
|
163
|
+
manifest.files[file.path] = kept;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
result.conflicts.push(file.path);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (result.conflicts.length > 0)
|
|
170
|
+
return result; // nothing is written until every conflict is chosen
|
|
171
|
+
for (const p of plan) {
|
|
172
|
+
await writeInside(root, p.path, p.text);
|
|
173
|
+
manifest.files[p.path] = p.record;
|
|
174
|
+
result.written.push(p.path);
|
|
175
|
+
}
|
|
176
|
+
manifest.package = version();
|
|
177
|
+
manifest.method = METHOD;
|
|
178
|
+
if (engine)
|
|
179
|
+
manifest.engine = { kind: "cc-sdd", version: CC_SDD_VERSION, language: engine.language };
|
|
180
|
+
await writeInside(root, MANIFEST, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
181
|
+
return result;
|
|
182
|
+
}
|
package/dist/io.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text made safe for a terminal: escape sequences and control characters
|
|
3
|
+
* other than tab and newline are dropped, so text from others (a comment, a
|
|
4
|
+
* title, git's messages) cannot move the cursor, recolor, or rewrite what is
|
|
5
|
+
* shown.
|
|
6
|
+
*/
|
|
7
|
+
export function printable(text) {
|
|
8
|
+
const ESC = 0x1b;
|
|
9
|
+
const BEL = 0x07;
|
|
10
|
+
let out = "";
|
|
11
|
+
for (let i = 0; i < text.length; i++) {
|
|
12
|
+
const c = text.charCodeAt(i);
|
|
13
|
+
if (c === ESC) {
|
|
14
|
+
const next = text[i + 1];
|
|
15
|
+
if (next === "[") {
|
|
16
|
+
// A control sequence: parameters and intermediates, up to a final byte.
|
|
17
|
+
i += 2;
|
|
18
|
+
while (i < text.length && !(text.charCodeAt(i) >= 0x40 && text.charCodeAt(i) <= 0x7e))
|
|
19
|
+
i++;
|
|
20
|
+
}
|
|
21
|
+
else if (next === "]") {
|
|
22
|
+
// An operating system command: up to BEL or ESC \.
|
|
23
|
+
i += 2;
|
|
24
|
+
while (i < text.length && text.charCodeAt(i) !== BEL) {
|
|
25
|
+
if (text.charCodeAt(i) === ESC && text[i + 1] === "\\") {
|
|
26
|
+
i++;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
i++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
i++; // ESC and the one character it introduces
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if ((c < 0x20 && c !== 0x09 && c !== 0x0a) || (c >= 0x7f && c <= 0x9f))
|
|
38
|
+
continue;
|
|
39
|
+
out += text[i];
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** Io for a person at a terminal: what is printed is made printable; machine output is not. */
|
|
44
|
+
export function terminalIo(io) {
|
|
45
|
+
return { ...io, out: (l) => io.out(printable(l)), err: (l) => io.err(printable(l)) };
|
|
46
|
+
}
|