@sublang/spex 1.0.0 → 2.1.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/README.md +63 -17
- package/dist/append-agent-specs.d.ts +26 -14
- package/dist/append-agent-specs.js +173 -48
- package/dist/cli.js +7 -3
- package/dist/copy-templates.d.ts +9 -2
- package/dist/copy-templates.js +10 -8
- package/dist/lint.js +35 -43
- package/dist/scaffold.js +130 -44
- package/package.json +1 -1
- package/scaffold/.file-history.json +12 -6
- package/scaffold/agent-specs.txt +3 -7
- package/scaffold/i18n/zh/specs/map.md +4 -6
- package/scaffold/i18n/zh/specs/meta.md +54 -41
- package/scaffold/language-switch-prompt.md +12 -0
- package/scaffold/spec-migration-prompt.md +28 -0
- package/scaffold/specs/decisions/000-spec-structure-format.md +17 -17
- package/scaffold/specs/map.md +2 -5
- package/scaffold/specs/meta.md +36 -23
- package/scaffold/specs/packages/git.md +1 -1
- package/scaffold/update-merge-prompt.md +5 -5
package/README.md
CHANGED
|
@@ -38,14 +38,38 @@ This creates:
|
|
|
38
38
|
- `specs/decisions/` and `specs/intents/` hold decision records (DRs) and intent records (IRs); `specs/map.md` indexes the tree and `specs/meta.md` is the spec of specs.
|
|
39
39
|
- Two starter packages (`git.md`, `licensing.md`) and a sample intent record seed the tree.
|
|
40
40
|
- **`LICENSE`** — the verbatim Apache-2.0 text at the target root, written only when no `LICENSE` exists there.
|
|
41
|
-
-
|
|
41
|
+
- **Agent instruction files** — a managed section that tells coding
|
|
42
|
+
agents to read relevant specs, resolve conflicts there first, and keep
|
|
43
|
+
specs and code aligned: `CLAUDE.md` for Claude Code, `AGENTS.md` for
|
|
44
|
+
Codex, Kimi Code, and OpenCode, and `GEMINI.md` for Gemini CLI.
|
|
42
45
|
|
|
43
46
|
See `specs/decisions/000-spec-structure-format.md` and `specs/meta.md` for the spec format and naming conventions.
|
|
44
47
|
|
|
45
|
-
Idempotency: rerunning `scaffold` is safe —
|
|
46
|
-
|
|
48
|
+
Idempotency: rerunning `scaffold` is safe — authored specs and content
|
|
49
|
+
outside Spex's managed `## Specs (Source of Truth)` sections stay
|
|
50
|
+
untouched. Agent instruction files are reconciled as described below.
|
|
47
51
|
(`--update` edits more, mechanically; see below.)
|
|
48
52
|
|
|
53
|
+
### Agent instructions
|
|
54
|
+
|
|
55
|
+
Interactive scaffold and update runs infer the current instruction
|
|
56
|
+
targets and ask for a quick default-yes confirmation. If you have
|
|
57
|
+
changed agents, decline and select the agents you use now. A fresh
|
|
58
|
+
project defaults to all supported targets.
|
|
59
|
+
|
|
60
|
+
For a non-interactive run, or to select directly, pass agent names:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
spex scaffold --agents=claude,codex
|
|
64
|
+
spex scaffold --update --agents=gemini,kimi
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Supported names are `claude`, `codex`, `gemini`, `kimi`, and
|
|
68
|
+
`opencode`; `all` selects all of them. The selection is the desired
|
|
69
|
+
state: Spex adds or refreshes selected managed sections and removes its
|
|
70
|
+
managed section from deselected targets, preserving all other content.
|
|
71
|
+
An otherwise empty deselected instruction file is removed.
|
|
72
|
+
|
|
49
73
|
### Linting
|
|
50
74
|
|
|
51
75
|
Check the specs tree at any time:
|
|
@@ -56,7 +80,7 @@ spex lint
|
|
|
56
80
|
|
|
57
81
|
The linter validates the layout, package file sections and their order, item IDs — lowercase `<pack>-<N>` matching the file's basename, unique across the tree — citations (enclosed inline links like `[[pack-3](pack.md#pack-3)]` whose files and anchors exist), Verification items citing the behaviors they check, reference markers, record sections, and the `map.md` index.
|
|
58
82
|
Relationship-metadata lines like `Verifies:` are errors — the citations woven into an item's statement are the single source of its relationships.
|
|
59
|
-
Directories of previous spec generations (`specs/compositions/`, `specs/user/`, …) are errors pointing
|
|
83
|
+
Directories of previous spec generations (`specs/compositions/`, `specs/user/`, …) are errors pointing to `spex scaffold --update` for the migration prompt (see [Upgrading](#upgrading-from-an-earlier-release)).
|
|
60
84
|
Errors exit non-zero; warnings do not.
|
|
61
85
|
|
|
62
86
|
**Try it:** review the sample intent record `specs/intents/000-spdx-headers.md`, update the copyright text, then prompt your AI coding agent:
|
|
@@ -75,6 +99,14 @@ spex scaffold --lang zh
|
|
|
75
99
|
|
|
76
100
|
Chinese (`zh`) is currently bundled. Any file without a localized template falls back to English, so the tree is always complete. The chosen language is recorded in `specs/meta.md` and reused automatically on `spex scaffold --update`.
|
|
77
101
|
|
|
102
|
+
To switch an existing tree to another language:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
spex scaffold --update --lang zh
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
This rewrites the bundled specs in the target language and prints a prompt you can hand an AI agent to translate the project's own specs; passing the language the tree already uses is just an ordinary update.
|
|
109
|
+
|
|
78
110
|
### Updating templates
|
|
79
111
|
|
|
80
112
|
When a new release ships updated templates, refresh them with:
|
|
@@ -87,34 +119,48 @@ It runs from within a git repository and requires a clean `specs/` working tree,
|
|
|
87
119
|
|
|
88
120
|
- Spex-authoritative *framework* files (`specs/meta.md` and the spec-format decision record) are refreshed unconditionally, including when they are absent. If you had modified one of these, `--update` warns and names it so you can reapply your changes from git history.
|
|
89
121
|
- Starter *seed* files (`map.md`, the sample intent record, the starter packages) are refreshed when you have not customized them, and written from the bundled template when they are absent. Customized starter files are kept as-is. Remove a starter file *after* `--update` if you do not want it.
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
|
|
93
|
-
|
|
122
|
+
- Agent instruction files are reconciled with the confirmed or explicit
|
|
123
|
+
selection; a non-interactive run infers existing managed targets and
|
|
124
|
+
defaults to all targets when none exist.
|
|
125
|
+
- Files outside the framework and seed sets and the supported agent
|
|
126
|
+
instruction targets are never edited.
|
|
127
|
+
|
|
128
|
+
Review the changes with
|
|
129
|
+
`git diff -- specs CLAUDE.md AGENTS.md GEMINI.md` and run `spex lint`.
|
|
94
130
|
The command prints a per-file indicator for every framework and seed path, plus a copy-paste-ready prompt for your AI agent to reconcile citations and local extensions with the refreshed law.
|
|
95
131
|
|
|
96
|
-
## Upgrading from
|
|
132
|
+
## Upgrading from an earlier release
|
|
133
|
+
|
|
134
|
+
### From 1.x
|
|
135
|
+
|
|
136
|
+
Spex 2.0 tightens the packages-only law introduced in 1.0. Run
|
|
137
|
+
`spex scaffold --update`, review the refreshed law and printed merge prompt,
|
|
138
|
+
then reconcile your packages until `spex lint` passes. In particular,
|
|
139
|
+
every package now requires Verification of its own behavior, behavior
|
|
140
|
+
citations from Verification stay inside that package, record citations
|
|
141
|
+
use their exact IDs, and every item-bearing basename is tree-wide unique.
|
|
142
|
+
|
|
143
|
+
### From 0.x
|
|
97
144
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
What changed:
|
|
145
|
+
A tree scaffolded by a spex 0.x release carries the older structural
|
|
146
|
+
generation of the law. Spex 2.0 uses the following structure:
|
|
101
147
|
|
|
102
|
-
| | Previous generations (spex 0.x) | Current generation (spex
|
|
148
|
+
| | Previous generations (spex 0.x) | Current generation (spex 2.0) |
|
|
103
149
|
| --- | --- | --- |
|
|
104
150
|
| Layout | `specs/user`/`dev`/`test`, later `packages/` + `compositions/` | `packages/` only — composition is a package pattern |
|
|
105
|
-
| Cross-package behavior | binding and scenario items in composition files |
|
|
151
|
+
| Cross-package behavior | binding and scenario items in composition files | behavior items binding inline to peers' External Behavior |
|
|
106
152
|
| Item IDs | ALLCAPS short form (`AUTH-3`) | lowercase file basename (`github-login-3`) |
|
|
107
153
|
| Item citations | `[AUTH-3](auth.md#auth-3)` | enclosed: `[[github-login-3](github-login.md#github-login-3)]` |
|
|
108
154
|
| Intent records | Goal, Deliverables, Tasks, Acceptance criteria | Status, Intent, Deliverables, Tasks, Verification |
|
|
109
155
|
|
|
110
156
|
The CLI detects but does not restructure a legacy tree:
|
|
111
157
|
|
|
112
|
-
- `spex scaffold --update` still refreshes the spex-owned law files, leaves all legacy content untouched, and prints migration
|
|
158
|
+
- `spex scaffold --update` still refreshes the spex-owned law files, leaves all legacy content untouched, and prints a self-contained migration prompt instead of the ordinary update prompt when it recognizes a legacy generation.
|
|
113
159
|
- Plain `spex scaffold` refuses a tree with a legacy directory — it writes nothing and points at `--update` — so two generations never entangle.
|
|
114
160
|
- `spex lint` reports legacy directories as errors pointing the same way.
|
|
115
161
|
|
|
116
|
-
The structural migration itself — items reclassify, compositions fold into packages, intents get rewritten — is judgment work
|
|
117
|
-
|
|
162
|
+
The structural migration itself — items reclassify, compositions fold into packages, intents get rewritten — is judgment work, not a script.
|
|
163
|
+
Give the printed prompt to any capable AI agent, let it loop until `spex lint` passes, and review the resulting diff.
|
|
118
164
|
|
|
119
165
|
## Workflow
|
|
120
166
|
|
|
@@ -1,16 +1,28 @@
|
|
|
1
|
+
export declare const AGENT_TARGETS: readonly [{
|
|
2
|
+
readonly file: "CLAUDE.md";
|
|
3
|
+
readonly agents: readonly ["claude"];
|
|
4
|
+
readonly label: "Claude Code";
|
|
5
|
+
}, {
|
|
6
|
+
readonly file: "AGENTS.md";
|
|
7
|
+
readonly agents: readonly ["codex", "kimi", "opencode"];
|
|
8
|
+
readonly label: "Codex / Kimi Code / OpenCode";
|
|
9
|
+
}, {
|
|
10
|
+
readonly file: "GEMINI.md";
|
|
11
|
+
readonly agents: readonly ["gemini"];
|
|
12
|
+
readonly label: "Gemini CLI";
|
|
13
|
+
}];
|
|
14
|
+
export type AgentName = (typeof AGENT_TARGETS)[number]["agents"][number];
|
|
15
|
+
export type AgentTargetFile = (typeof AGENT_TARGETS)[number]["file"];
|
|
16
|
+
export interface AgentInteraction {
|
|
17
|
+
interactive: boolean;
|
|
18
|
+
ask(prompt: string): string | null;
|
|
19
|
+
}
|
|
20
|
+
export declare function parseAgentNames(value: string): AgentName[];
|
|
21
|
+
/** Resolve the desired instruction targets without writing the project. */
|
|
22
|
+
export declare function resolveAgentTargets(basePath: string, explicitAgents?: readonly AgentName[], interaction?: AgentInteraction): AgentTargetFile[];
|
|
1
23
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* SCAF-10: when neither exists, both are created; when only one
|
|
6
|
-
* exists, only that file is updated. Section replacement uses
|
|
7
|
-
* case-sensitive match on "## Specs (Source of Truth)".
|
|
8
|
-
* SCAF-5: replace in place or skip when identical.
|
|
9
|
-
*
|
|
10
|
-
* With `createMissing: false` (the --update flow), absent files stay
|
|
11
|
-
* absent; only existing agent files get their managed section
|
|
12
|
-
* refreshed.
|
|
24
|
+
* Reconcile the selected native agent files with the managed section
|
|
25
|
+
* from scaffold/agent-specs.txt. Unselected files lose only that
|
|
26
|
+
* section; unrelated content is never removed.
|
|
13
27
|
*/
|
|
14
|
-
export declare function
|
|
15
|
-
createMissing?: boolean;
|
|
16
|
-
}): void;
|
|
28
|
+
export declare function reconcileAgentSpecs(basePath: string, selectedTargets: readonly AgentTargetFile[]): void;
|
|
@@ -1,39 +1,140 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync, readSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { getScaffoldDir } from "./bundled-scaffold.js";
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import { headingText, parseMarkdown, startOffset } from "./markdown.js";
|
|
7
|
+
const SECTION_TITLE = "Specs (Source of Truth)";
|
|
8
|
+
export const AGENT_TARGETS = [
|
|
9
|
+
{
|
|
10
|
+
file: "CLAUDE.md",
|
|
11
|
+
agents: ["claude"],
|
|
12
|
+
label: "Claude Code",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
file: "AGENTS.md",
|
|
16
|
+
agents: ["codex", "kimi", "opencode"],
|
|
17
|
+
label: "Codex / Kimi Code / OpenCode",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
file: "GEMINI.md",
|
|
21
|
+
agents: ["gemini"],
|
|
22
|
+
label: "Gemini CLI",
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
const AGENT_NAMES = AGENT_TARGETS.flatMap((target) => target.agents);
|
|
26
|
+
const AGENT_FILES = AGENT_TARGETS.map((target) => target.file);
|
|
27
|
+
const terminalInteraction = {
|
|
28
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
29
|
+
ask(prompt) {
|
|
30
|
+
process.stderr.write(prompt);
|
|
31
|
+
const buffer = Buffer.alloc(1024);
|
|
32
|
+
const bytes = readSync(0, buffer, 0, buffer.length, null);
|
|
33
|
+
if (bytes === 0)
|
|
34
|
+
return null;
|
|
35
|
+
return buffer.toString("utf-8", 0, bytes).trim();
|
|
36
|
+
},
|
|
37
|
+
};
|
|
11
38
|
/**
|
|
12
|
-
* Extract the specs section from content: from the heading to
|
|
13
|
-
* next h2 heading or end of file.
|
|
39
|
+
* Extract the specs section from content: from the managed heading to
|
|
40
|
+
* the next h2 heading or end of file. The content is parsed as
|
|
41
|
+
* Markdown, so only a real heading matches — a lookalike line inside a
|
|
42
|
+
* fenced code block neither starts the section nor terminates it.
|
|
14
43
|
* Returns [start, end] character offsets, or null if not found.
|
|
15
44
|
*/
|
|
16
45
|
function findSection(content) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const match = pattern.exec(content);
|
|
21
|
-
if (!match)
|
|
46
|
+
const headings = parseMarkdown(content).children.filter((node) => node.type === "heading" && node.depth === 2);
|
|
47
|
+
const managed = headings.find((heading) => headingText(content, heading) === SECTION_TITLE);
|
|
48
|
+
if (managed === undefined)
|
|
22
49
|
return null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
const next = headings.find((heading) => startOffset(heading) > startOffset(managed));
|
|
51
|
+
if (next === undefined)
|
|
52
|
+
return [startOffset(managed), content.length];
|
|
53
|
+
// End before the line ending that precedes the next heading, so the
|
|
54
|
+
// separator between sections stays outside the replaced range.
|
|
55
|
+
let end = startOffset(next);
|
|
56
|
+
if (content[end - 1] === "\n")
|
|
57
|
+
end -= content[end - 2] === "\r" ? 2 : 1;
|
|
58
|
+
return [startOffset(managed), end];
|
|
59
|
+
}
|
|
60
|
+
function hasManagedSection(filePath) {
|
|
61
|
+
return (existsSync(filePath) &&
|
|
62
|
+
findSection(readFileSync(filePath, "utf-8")) !== null);
|
|
63
|
+
}
|
|
64
|
+
function targetsForAgents(agents) {
|
|
65
|
+
const selected = new Set(agents);
|
|
66
|
+
return AGENT_TARGETS.filter((target) => target.agents.some((agent) => selected.has(agent))).map((target) => target.file);
|
|
67
|
+
}
|
|
68
|
+
export function parseAgentNames(value) {
|
|
69
|
+
const tokens = value
|
|
70
|
+
.split(",")
|
|
71
|
+
.map((token) => token.trim().toLowerCase())
|
|
72
|
+
.filter(Boolean);
|
|
73
|
+
if (tokens.length === 0) {
|
|
74
|
+
throw new Error("--agents requires a comma-separated agent list");
|
|
75
|
+
}
|
|
76
|
+
if (tokens.includes("all")) {
|
|
77
|
+
if (tokens.length !== 1) {
|
|
78
|
+
throw new Error("--agents=all cannot be combined with other agents");
|
|
79
|
+
}
|
|
80
|
+
return [...AGENT_NAMES];
|
|
81
|
+
}
|
|
82
|
+
const unknown = tokens.filter((token) => !AGENT_NAMES.includes(token));
|
|
83
|
+
if (unknown.length > 0) {
|
|
84
|
+
throw new Error(`Unknown agent${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}. Supported agents: ${AGENT_NAMES.join(", ")}, all`);
|
|
85
|
+
}
|
|
86
|
+
return [...new Set(tokens)];
|
|
87
|
+
}
|
|
88
|
+
function detectCurrentTargets(basePath) {
|
|
89
|
+
const managed = AGENT_FILES.filter((file) => hasManagedSection(join(basePath, file)));
|
|
90
|
+
if (managed.length > 0)
|
|
91
|
+
return managed;
|
|
92
|
+
return AGENT_FILES.filter((file) => existsSync(join(basePath, file)));
|
|
93
|
+
}
|
|
94
|
+
function targetSummary(files) {
|
|
95
|
+
const selected = new Set(files);
|
|
96
|
+
return AGENT_TARGETS.filter((target) => selected.has(target.file))
|
|
97
|
+
.map((target) => ` ${AGENT_TARGETS.indexOf(target) + 1}. ${target.label} (${target.file})`)
|
|
98
|
+
.join("\n");
|
|
99
|
+
}
|
|
100
|
+
function promptForTargets(interaction) {
|
|
101
|
+
const response = interaction.ask("Select the coding agents that should receive Spex instructions:\n" +
|
|
102
|
+
targetSummary(AGENT_FILES) +
|
|
103
|
+
"\nEnter numbers separated by commas [all]: ");
|
|
104
|
+
if (response === null)
|
|
105
|
+
throw new Error("agent selection canceled");
|
|
106
|
+
if (response === "" || response.toLowerCase() === "all") {
|
|
107
|
+
return [...AGENT_FILES];
|
|
108
|
+
}
|
|
109
|
+
const numbers = response.split(",").map((token) => token.trim());
|
|
110
|
+
if (numbers.some((token) => !/^[1-3]$/.test(token)) ||
|
|
111
|
+
numbers.length === 0) {
|
|
112
|
+
throw new Error("agent selection must be all or comma-separated numbers 1-3");
|
|
113
|
+
}
|
|
114
|
+
return [
|
|
115
|
+
...new Set(numbers.map((number) => AGENT_FILES[Number(number) - 1])),
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
/** Resolve the desired instruction targets without writing the project. */
|
|
119
|
+
export function resolveAgentTargets(basePath, explicitAgents, interaction = terminalInteraction) {
|
|
120
|
+
if (explicitAgents !== undefined)
|
|
121
|
+
return targetsForAgents(explicitAgents);
|
|
122
|
+
const current = detectCurrentTargets(basePath);
|
|
123
|
+
if (!interaction.interactive) {
|
|
124
|
+
return current.length > 0 ? current : [...AGENT_FILES];
|
|
125
|
+
}
|
|
126
|
+
if (current.length === 0)
|
|
127
|
+
return promptForTargets(interaction);
|
|
128
|
+
const response = interaction.ask("Spex agent instructions currently target:\n" +
|
|
129
|
+
targetSummary(current) +
|
|
130
|
+
"\nKeep this selection? [Y/n] ");
|
|
131
|
+
if (response === null)
|
|
132
|
+
throw new Error("agent selection canceled");
|
|
133
|
+
if (response === "" || /^y(?:es)?$/i.test(response))
|
|
134
|
+
return current;
|
|
135
|
+
if (/^n(?:o)?$/i.test(response))
|
|
136
|
+
return promptForTargets(interaction);
|
|
137
|
+
throw new Error("answer y or n when confirming agent instructions");
|
|
37
138
|
}
|
|
38
139
|
/**
|
|
39
140
|
* Process a single agent file: replace section in place, append,
|
|
@@ -67,31 +168,52 @@ function processFile(filePath, specsContent, fileExists, shouldCreate) {
|
|
|
67
168
|
writeFileSync(filePath, existing + separator + specsContent);
|
|
68
169
|
return "updated";
|
|
69
170
|
}
|
|
171
|
+
function removeManagedSection(filePath) {
|
|
172
|
+
if (!existsSync(filePath))
|
|
173
|
+
return null;
|
|
174
|
+
const existing = readFileSync(filePath, "utf-8");
|
|
175
|
+
const section = findSection(existing);
|
|
176
|
+
if (section === null)
|
|
177
|
+
return null;
|
|
178
|
+
const [start, end] = section;
|
|
179
|
+
const before = existing.slice(0, start).trimEnd();
|
|
180
|
+
const after = existing.slice(end).trimStart();
|
|
181
|
+
if (before === "" && after === "") {
|
|
182
|
+
unlinkSync(filePath);
|
|
183
|
+
return "removed";
|
|
184
|
+
}
|
|
185
|
+
// Infer the seam from the content that survives, never from the
|
|
186
|
+
// whole file: the managed section carries the bundle's line endings
|
|
187
|
+
// (CRLF where git checked agent-specs.txt out on Windows), and a
|
|
188
|
+
// section being deleted must not impose them on what remains.
|
|
189
|
+
const surviving = before !== "" ? before : after;
|
|
190
|
+
const lineEnding = surviving.includes("\r\n") ? "\r\n" : "\n";
|
|
191
|
+
const updated = before !== "" && after !== ""
|
|
192
|
+
? `${before}${lineEnding}${lineEnding}${after}`
|
|
193
|
+
: before !== ""
|
|
194
|
+
? `${before}${lineEnding}`
|
|
195
|
+
: after;
|
|
196
|
+
writeFileSync(filePath, updated);
|
|
197
|
+
return "removed";
|
|
198
|
+
}
|
|
70
199
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* SCAF-10: when neither exists, both are created; when only one
|
|
75
|
-
* exists, only that file is updated. Section replacement uses
|
|
76
|
-
* case-sensitive match on "## Specs (Source of Truth)".
|
|
77
|
-
* SCAF-5: replace in place or skip when identical.
|
|
78
|
-
*
|
|
79
|
-
* With `createMissing: false` (the --update flow), absent files stay
|
|
80
|
-
* absent; only existing agent files get their managed section
|
|
81
|
-
* refreshed.
|
|
200
|
+
* Reconcile the selected native agent files with the managed section
|
|
201
|
+
* from scaffold/agent-specs.txt. Unselected files lose only that
|
|
202
|
+
* section; unrelated content is never removed.
|
|
82
203
|
*/
|
|
83
|
-
export function
|
|
84
|
-
|
|
204
|
+
export function reconcileAgentSpecs(basePath, selectedTargets) {
|
|
205
|
+
if (selectedTargets.length === 0) {
|
|
206
|
+
throw new Error("at least one agent instruction target must be selected");
|
|
207
|
+
}
|
|
85
208
|
const scaffoldDir = getScaffoldDir();
|
|
86
209
|
const specsContent = readFileSync(join(scaffoldDir, "agent-specs.txt"), "utf-8");
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
for (let i = 0; i < AGENT_FILES.length; i++) {
|
|
90
|
-
const fileName = AGENT_FILES[i];
|
|
210
|
+
const selected = new Set(selectedTargets);
|
|
211
|
+
for (const fileName of AGENT_FILES) {
|
|
91
212
|
const filePath = join(basePath, fileName);
|
|
92
|
-
const fileExists =
|
|
93
|
-
const
|
|
94
|
-
|
|
213
|
+
const fileExists = existsSync(filePath);
|
|
214
|
+
const result = selected.has(fileName)
|
|
215
|
+
? processFile(filePath, specsContent, fileExists, true)
|
|
216
|
+
: removeManagedSection(filePath);
|
|
95
217
|
switch (result) {
|
|
96
218
|
case "created":
|
|
97
219
|
console.log(` ${fileName} (created)`);
|
|
@@ -102,8 +224,11 @@ export function appendAgentSpecs(basePath, options = {}) {
|
|
|
102
224
|
case "skipped":
|
|
103
225
|
console.log(` ${fileName} (skipped)`);
|
|
104
226
|
break;
|
|
227
|
+
case "removed":
|
|
228
|
+
console.log(` ${fileName} (removed)`);
|
|
229
|
+
break;
|
|
105
230
|
case null:
|
|
106
|
-
//
|
|
231
|
+
// Unselected and unmanaged — no output.
|
|
107
232
|
break;
|
|
108
233
|
}
|
|
109
234
|
}
|
package/dist/cli.js
CHANGED
|
@@ -6,10 +6,14 @@ import { scaffold } from "./scaffold.js";
|
|
|
6
6
|
const USAGE = `Usage: spex <command> [options]
|
|
7
7
|
|
|
8
8
|
Commands:
|
|
9
|
-
scaffold [--lang <code>] [<path>]
|
|
10
|
-
|
|
9
|
+
scaffold [--lang <code>] [--agents <names>] [<path>]
|
|
10
|
+
Create specs directory structure
|
|
11
|
+
scaffold --update [--lang <code>] [--agents <names>]
|
|
12
|
+
Refresh scaffold-provided specs templates
|
|
11
13
|
lint [<path>] Check the specs tree structure, item IDs,
|
|
12
|
-
and citations
|
|
14
|
+
and citations
|
|
15
|
+
|
|
16
|
+
Agent names: claude, codex, gemini, kimi, opencode, or all`;
|
|
13
17
|
function main() {
|
|
14
18
|
const args = process.argv.slice(2);
|
|
15
19
|
const command = args[0];
|
package/dist/copy-templates.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export type LegacyItemLayoutResult = {
|
|
|
9
9
|
type RefreshPristineSeedsOptions = {
|
|
10
10
|
migratedFrom?: ReadonlyMap<string, string>;
|
|
11
11
|
language?: ScaffoldLanguage;
|
|
12
|
+
/**
|
|
13
|
+
* A second language whose bundled versions also count as pristine.
|
|
14
|
+
* A language switch reads the tree in its old language and writes
|
|
15
|
+
* the new one, so a seed pristine in the old language is a
|
|
16
|
+
* convertible bundled file, not a user customization.
|
|
17
|
+
*/
|
|
18
|
+
alsoRecognize?: readonly ScaffoldLanguage[];
|
|
12
19
|
/**
|
|
13
20
|
* Replacement indicator text for user-modified seeds that this run
|
|
14
21
|
* transformed in place (e.g. a restructured map.md), so one line
|
|
@@ -44,7 +51,7 @@ export declare function getLegacyFileHistory(relPath: string): string[];
|
|
|
44
51
|
/** isPristine over the legacy manifest (removed bundled paths). */
|
|
45
52
|
export declare function isLegacyPristine(basePath: string, relPath: string): PristineState;
|
|
46
53
|
export declare function canonicalContentHash(data: Buffer): string;
|
|
47
|
-
export declare function isPristine(basePath: string, relPath: string, language?: ScaffoldLanguage): PristineState;
|
|
48
|
-
export declare function overwriteFrameworkSpecFiles(basePath: string, language?: ScaffoldLanguage): string[];
|
|
54
|
+
export declare function isPristine(basePath: string, relPath: string, language?: ScaffoldLanguage, alsoRecognize?: readonly ScaffoldLanguage[]): PristineState;
|
|
55
|
+
export declare function overwriteFrameworkSpecFiles(basePath: string, language?: ScaffoldLanguage, alsoRecognize?: readonly ScaffoldLanguage[]): string[];
|
|
49
56
|
export declare function refreshPristineSeeds(basePath: string, options?: RefreshPristineSeedsOptions): void;
|
|
50
57
|
export {};
|
package/dist/copy-templates.js
CHANGED
|
@@ -239,10 +239,12 @@ export function isLegacyPristine(basePath, relPath) {
|
|
|
239
239
|
? "pristine"
|
|
240
240
|
: "modified";
|
|
241
241
|
}
|
|
242
|
-
function getRecognizedFileHistory(relPath, language) {
|
|
242
|
+
function getRecognizedFileHistory(relPath, language, alsoRecognize = []) {
|
|
243
243
|
const history = new Set(getFileHistory(relPath));
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
for (const lang of [language, ...alsoRecognize]) {
|
|
245
|
+
if (lang === "en")
|
|
246
|
+
continue;
|
|
247
|
+
for (const hash of getFileHistory(getOverlayRelPath(lang, relPath))) {
|
|
246
248
|
history.add(hash);
|
|
247
249
|
}
|
|
248
250
|
}
|
|
@@ -262,21 +264,21 @@ function canonicalHashInput(data) {
|
|
|
262
264
|
return data.toString("utf-8").replace(/\r\n?/g, "\n");
|
|
263
265
|
}
|
|
264
266
|
// SCAF-22.
|
|
265
|
-
export function isPristine(basePath, relPath, language = "en") {
|
|
267
|
+
export function isPristine(basePath, relPath, language = "en", alsoRecognize = []) {
|
|
266
268
|
const target = join(basePath, relPath);
|
|
267
269
|
if (!existsSync(target))
|
|
268
270
|
return "missing";
|
|
269
|
-
return getRecognizedFileHistory(relPath, language).includes(hashFile(target))
|
|
271
|
+
return getRecognizedFileHistory(relPath, language, alsoRecognize).includes(hashFile(target))
|
|
270
272
|
? "pristine"
|
|
271
273
|
: "modified";
|
|
272
274
|
}
|
|
273
275
|
// SCAF-14. Returns the framework paths that were overwritten while
|
|
274
276
|
// carrying unrecognized (user-modified) content, so the caller can warn
|
|
275
277
|
// before the run completes (SCAF-18).
|
|
276
|
-
export function overwriteFrameworkSpecFiles(basePath, language = "en") {
|
|
278
|
+
export function overwriteFrameworkSpecFiles(basePath, language = "en", alsoRecognize = []) {
|
|
277
279
|
const replacedUserModified = [];
|
|
278
280
|
for (const relPath of FRAMEWORK_FILES) {
|
|
279
|
-
const state = isPristine(basePath, relPath, language);
|
|
281
|
+
const state = isPristine(basePath, relPath, language, alsoRecognize);
|
|
280
282
|
const target = join(basePath, relPath);
|
|
281
283
|
const source = getBundledSpecFilePath(relPath, language);
|
|
282
284
|
if (state !== "missing" && hashFile(target) === hashFile(source)) {
|
|
@@ -307,7 +309,7 @@ function formatSeedIndicator(relPath, indicator, migratedFrom) {
|
|
|
307
309
|
export function refreshPristineSeeds(basePath, options = {}) {
|
|
308
310
|
const language = options.language ?? "en";
|
|
309
311
|
for (const relPath of SEED_FILES) {
|
|
310
|
-
const state = isPristine(basePath, relPath, language);
|
|
312
|
+
const state = isPristine(basePath, relPath, language, options.alsoRecognize);
|
|
311
313
|
if (state === "modified") {
|
|
312
314
|
const indicator = formatSeedIndicator(relPath, options.indicatorOverrides?.get(relPath) ?? "kept — user-modified", options.migratedFrom);
|
|
313
315
|
console.log(` ${relPath} (${indicator})`);
|