@sublang/spex 0.2.3 → 1.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/README.md +70 -17
- package/dist/append-agent-specs.d.ts +7 -1
- package/dist/append-agent-specs.js +7 -2
- package/dist/cli.js +8 -2
- package/dist/copy-templates.d.ts +28 -3
- package/dist/copy-templates.js +172 -54
- package/dist/create-specs-structure.js +2 -4
- package/dist/lint.d.ts +15 -0
- package/dist/lint.js +967 -0
- package/dist/markdown.d.ts +46 -0
- package/dist/markdown.js +130 -0
- package/dist/scaffold.js +171 -31
- package/package.json +15 -7
- package/scaffold/.file-history.json +32 -24
- package/scaffold/.legacy-file-history.json +48 -0
- package/scaffold/LICENSE +202 -0
- package/scaffold/agent-specs.txt +10 -2
- package/scaffold/i18n/zh/specs/map.md +44 -0
- package/scaffold/i18n/zh/specs/meta.md +208 -0
- package/scaffold/specs/decisions/000-spec-structure-format.md +40 -42
- package/scaffold/specs/intents/000-spdx-headers.md +39 -0
- package/scaffold/specs/map.md +14 -24
- package/scaffold/specs/meta.md +110 -72
- package/scaffold/specs/packages/git.md +46 -0
- package/scaffold/specs/packages/licensing.md +56 -0
- package/scaffold/update-merge-prompt.md +8 -1
- package/scaffold/specs/dev/git.md +0 -28
- package/scaffold/specs/dev/licensing.md +0 -44
- package/scaffold/specs/iterations/000-spdx-headers.md +0 -35
- package/scaffold/specs/test/licensing.md +0 -20
- package/scaffold/specs/user/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -32,21 +32,49 @@ spex scaffold
|
|
|
32
32
|
|
|
33
33
|
This creates:
|
|
34
34
|
|
|
35
|
-
- **`specs/`** —
|
|
36
|
-
specs,
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
- **`specs/`** — the spec tree and its law:
|
|
36
|
+
- `specs/packages/` holds one file per spec package: a self-contained `## Intent`, the behavior its users may rely on (`## External Behavior`), implementation hidden from them (`## Internal Behavior`), and the tests of its own claims (`## Verification`) — one read covers one package.
|
|
37
|
+
Behavior that emerges from several packages working together is itself a spec package citing the peers' External Behavior — there is no compositions directory.
|
|
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
|
+
- Two starter packages (`git.md`, `licensing.md`) and a sample intent record seed the tree.
|
|
40
|
+
- **`LICENSE`** — the verbatim Apache-2.0 text at the target root, written only when no `LICENSE` exists there.
|
|
41
|
+
- **`CLAUDE.md` / `AGENTS.md`** — instructions that tell AI agents (Claude, Codex, etc.) to read and follow the specs before writing code.
|
|
39
42
|
|
|
40
|
-
See `specs/decisions/000-spec-structure-format.md` for the spec format and naming conventions.
|
|
43
|
+
See `specs/decisions/000-spec-structure-format.md` and `specs/meta.md` for the spec format and naming conventions.
|
|
41
44
|
|
|
42
|
-
Idempotency:
|
|
45
|
+
Idempotency: rerunning `scaffold` is safe — it only adds missing files.
|
|
46
|
+
The one in-place edit it makes is to an existing `CLAUDE.md`/`AGENTS.md`, whose managed `## Specs (Source of Truth)` section is added or refreshed.
|
|
47
|
+
(`--update` edits more, mechanically; see below.)
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
### Linting
|
|
50
|
+
|
|
51
|
+
Check the specs tree at any time:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
spex lint
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
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
|
+
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 at the migration skill (see [Upgrading](#upgrading-from-a-previous-generation)).
|
|
60
|
+
Errors exit non-zero; warnings do not.
|
|
61
|
+
|
|
62
|
+
**Try it:** review the sample intent record `specs/intents/000-spdx-headers.md`, update the copyright text, then prompt your AI coding agent:
|
|
45
63
|
|
|
46
64
|
```text
|
|
47
|
-
Complete
|
|
65
|
+
Complete IR-000
|
|
48
66
|
```
|
|
49
67
|
|
|
68
|
+
### Localization
|
|
69
|
+
|
|
70
|
+
Specs are scaffolded in English by default. To scaffold in another language, pass `--lang`:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
spex scaffold --lang zh
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
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
|
+
|
|
50
78
|
### Updating templates
|
|
51
79
|
|
|
52
80
|
When a new release ships updated templates, refresh them with:
|
|
@@ -55,13 +83,38 @@ When a new release ships updated templates, refresh them with:
|
|
|
55
83
|
spex scaffold --update
|
|
56
84
|
```
|
|
57
85
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
-
|
|
86
|
+
It runs from within a git repository and requires a clean `specs/` working tree, so every edit stays reviewable.
|
|
87
|
+
|
|
88
|
+
- 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
|
+
- 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
|
+
- The managed specs section of an existing `CLAUDE.md`/`AGENTS.md` is refreshed; absent agent files are not created.
|
|
91
|
+
- Files you authored are never edited.
|
|
92
|
+
|
|
93
|
+
Review the changes with `git diff -- specs CLAUDE.md AGENTS.md` and run `spex lint`.
|
|
94
|
+
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
|
+
|
|
96
|
+
## Upgrading from a previous generation
|
|
97
|
+
|
|
98
|
+
Spex 1.0 rewrote the spec convention — the law in `specs/meta.md` and the spec-format decision record.
|
|
99
|
+
A tree scaffolded by any spex 0.x release carries a previous generation of that law; a future rewrite would be a 2.0.
|
|
100
|
+
What changed:
|
|
101
|
+
|
|
102
|
+
| | Previous generations (spex 0.x) | Current generation (spex 1.0) |
|
|
103
|
+
| --- | --- | --- |
|
|
104
|
+
| 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 | ordinary packages citing peers' External Behavior |
|
|
106
|
+
| Item IDs | ALLCAPS short form (`AUTH-3`) | lowercase file basename (`github-login-3`) |
|
|
107
|
+
| Item citations | `[AUTH-3](auth.md#auth-3)` | enclosed: `[[github-login-3](github-login.md#github-login-3)]` |
|
|
108
|
+
| Intent records | Goal, Deliverables, Tasks, Acceptance criteria | Status, Intent, Deliverables, Tasks, Verification |
|
|
109
|
+
|
|
110
|
+
The CLI detects but does not restructure a legacy tree:
|
|
111
|
+
|
|
112
|
+
- `spex scaffold --update` still refreshes the spex-owned law files, leaves all legacy content untouched, and prints migration guidance when it recognizes a legacy generation.
|
|
113
|
+
- Plain `spex scaffold` refuses a tree with a legacy directory — it writes nothing and points at `--update` — so two generations never entangle.
|
|
114
|
+
- `spex lint` reports legacy directories as errors pointing the same way.
|
|
61
115
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
clear next steps and a copy-paste-ready prompt you can hand to your AI agent for that review.
|
|
116
|
+
The structural migration itself — items reclassify, compositions fold into packages, intents get rewritten — is judgment work done by an AI agent following the **spec-structure-migration** skill shipped in the spex repo, not by a script (the scripted migration of earlier releases is retired).
|
|
117
|
+
Follow the walkthrough in [docs/spec-migration.md](https://github.com/sublang-ai/spex/blob/main/docs/spec-migration.md), install the skill per [its README](https://github.com/sublang-ai/spex/blob/main/skills/spec-structure-migration/README.md), and let the agent loop until its checker and `spex lint` — the mechanical gate — pass clean.
|
|
65
118
|
|
|
66
119
|
## Workflow
|
|
67
120
|
|
|
@@ -69,10 +122,10 @@ Spex does *not* enforce a heavyweight workflow.
|
|
|
69
122
|
We believe spec-driven development is a flexible combination of a few primitives.
|
|
70
123
|
|
|
71
124
|
1. **Make Decisions** — Discuss requirements, architecture, and design with AI agents. Let AI generate and review decision records in `specs/decisions/`.
|
|
72
|
-
2. **
|
|
73
|
-
3. **Agents Execute** — Let AI agents complete the tasks autonomously. They generate code and update `specs/
|
|
125
|
+
2. **Record Intents** — Break down work into tasks with AI agents. Let AI generate and review intent records in `specs/intents/`.
|
|
126
|
+
3. **Agents Execute** — Let AI agents complete the tasks autonomously. They generate code and update `specs/packages/`.
|
|
74
127
|
|
|
75
|
-
Then loop back to the next decision or
|
|
128
|
+
Then loop back to the next decision or intent.
|
|
76
129
|
|
|
77
130
|
## Requirements
|
|
78
131
|
|
|
@@ -6,5 +6,11 @@
|
|
|
6
6
|
* exists, only that file is updated. Section replacement uses
|
|
7
7
|
* case-sensitive match on "## Specs (Source of Truth)".
|
|
8
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.
|
|
9
13
|
*/
|
|
10
|
-
export declare function appendAgentSpecs(basePath: string
|
|
14
|
+
export declare function appendAgentSpecs(basePath: string, options?: {
|
|
15
|
+
createMissing?: boolean;
|
|
16
|
+
}): void;
|
|
@@ -75,8 +75,13 @@ function processFile(filePath, specsContent, fileExists, shouldCreate) {
|
|
|
75
75
|
* exists, only that file is updated. Section replacement uses
|
|
76
76
|
* case-sensitive match on "## Specs (Source of Truth)".
|
|
77
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.
|
|
78
82
|
*/
|
|
79
|
-
export function appendAgentSpecs(basePath) {
|
|
83
|
+
export function appendAgentSpecs(basePath, options = {}) {
|
|
84
|
+
const createMissing = options.createMissing ?? true;
|
|
80
85
|
const scaffoldDir = getScaffoldDir();
|
|
81
86
|
const specsContent = readFileSync(join(scaffoldDir, "agent-specs.txt"), "utf-8");
|
|
82
87
|
const presence = AGENT_FILES.map((f) => existsSync(join(basePath, f)));
|
|
@@ -85,7 +90,7 @@ export function appendAgentSpecs(basePath) {
|
|
|
85
90
|
const fileName = AGENT_FILES[i];
|
|
86
91
|
const filePath = join(basePath, fileName);
|
|
87
92
|
const fileExists = presence[i];
|
|
88
|
-
const shouldCreate = neitherExists;
|
|
93
|
+
const shouldCreate = createMissing && neitherExists;
|
|
89
94
|
const result = processFile(filePath, specsContent, fileExists, shouldCreate);
|
|
90
95
|
switch (result) {
|
|
91
96
|
case "created":
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
4
|
+
import { lint } from "./lint.js";
|
|
4
5
|
import { scaffold } from "./scaffold.js";
|
|
5
6
|
const USAGE = `Usage: spex <command> [options]
|
|
6
7
|
|
|
7
8
|
Commands:
|
|
8
|
-
scaffold [<path>] Create specs directory structure
|
|
9
|
-
scaffold --update
|
|
9
|
+
scaffold [--lang <code>] [<path>] Create specs directory structure
|
|
10
|
+
scaffold --update Refresh scaffold-provided specs templates
|
|
11
|
+
lint [<path>] Check the specs tree structure, item IDs,
|
|
12
|
+
and citations`;
|
|
10
13
|
function main() {
|
|
11
14
|
const args = process.argv.slice(2);
|
|
12
15
|
const command = args[0];
|
|
@@ -18,6 +21,9 @@ function main() {
|
|
|
18
21
|
case "scaffold":
|
|
19
22
|
scaffold(args.slice(1));
|
|
20
23
|
break;
|
|
24
|
+
case "lint":
|
|
25
|
+
lint(args.slice(1));
|
|
26
|
+
break;
|
|
21
27
|
default:
|
|
22
28
|
console.error(`Unknown command: ${command}\n`);
|
|
23
29
|
console.error(USAGE);
|
package/dist/copy-templates.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const SUPPORTED_LANGUAGES: readonly ["en", "zh"];
|
|
2
|
+
export type ScaffoldLanguage = (typeof SUPPORTED_LANGUAGES)[number];
|
|
1
3
|
export type PristineState = "pristine" | "modified" | "missing";
|
|
2
4
|
export type LegacyItemLayoutResult = {
|
|
3
5
|
status: "migrated" | "conflict";
|
|
@@ -6,20 +8,43 @@ export type LegacyItemLayoutResult = {
|
|
|
6
8
|
};
|
|
7
9
|
type RefreshPristineSeedsOptions = {
|
|
8
10
|
migratedFrom?: ReadonlyMap<string, string>;
|
|
11
|
+
language?: ScaffoldLanguage;
|
|
12
|
+
/**
|
|
13
|
+
* Replacement indicator text for user-modified seeds that this run
|
|
14
|
+
* transformed in place (e.g. a restructured map.md), so one line
|
|
15
|
+
* reports the seed's true outcome.
|
|
16
|
+
*/
|
|
17
|
+
indicatorOverrides?: ReadonlyMap<string, string>;
|
|
9
18
|
};
|
|
19
|
+
export declare function isSupportedLanguage(code: string): code is ScaffoldLanguage;
|
|
20
|
+
export declare function formatSupportedLanguages(): string;
|
|
21
|
+
export declare function listFiles(dir: string): string[];
|
|
22
|
+
export declare function getBundledSpecFilePath(relPath: string, language?: ScaffoldLanguage): string;
|
|
10
23
|
/**
|
|
11
24
|
* Copy bundled template files from scaffold/specs/ to target specs/.
|
|
12
25
|
*
|
|
13
26
|
* SCAF-8: recursively copies files; existing files are not overwritten.
|
|
14
27
|
* SCAF-9: resolves scaffold/ from the dist/ output directory.
|
|
15
28
|
*/
|
|
16
|
-
export declare function copyTemplates(basePath: string): void;
|
|
29
|
+
export declare function copyTemplates(basePath: string, language?: ScaffoldLanguage): void;
|
|
30
|
+
/**
|
|
31
|
+
* Copy the bundled top-level LICENSE to the target repository root.
|
|
32
|
+
*
|
|
33
|
+
* SCAF-37: writes scaffold/LICENSE (verbatim Apache-2.0) to
|
|
34
|
+
* <basePath>/LICENSE only when the target is absent, so an existing
|
|
35
|
+
* downstream license is never overwritten. Not localized.
|
|
36
|
+
*/
|
|
37
|
+
export declare function copyRootLicense(basePath: string): void;
|
|
17
38
|
export declare function getFrameworkSpecFiles(): readonly string[];
|
|
18
39
|
export declare function getSeedSpecFiles(): readonly string[];
|
|
19
40
|
export declare function migrateLegacyItemLayout(basePath: string): LegacyItemLayoutResult[];
|
|
41
|
+
export declare function migrateIterationsLayout(basePath: string): LegacyItemLayoutResult[];
|
|
20
42
|
export declare function getFileHistory(relPath: string): string[];
|
|
43
|
+
export declare function getLegacyFileHistory(relPath: string): string[];
|
|
44
|
+
/** isPristine over the legacy manifest (removed bundled paths). */
|
|
45
|
+
export declare function isLegacyPristine(basePath: string, relPath: string): PristineState;
|
|
21
46
|
export declare function canonicalContentHash(data: Buffer): string;
|
|
22
|
-
export declare function isPristine(basePath: string, relPath: string): PristineState;
|
|
23
|
-
export declare function overwriteFrameworkSpecFiles(basePath: string):
|
|
47
|
+
export declare function isPristine(basePath: string, relPath: string, language?: ScaffoldLanguage): PristineState;
|
|
48
|
+
export declare function overwriteFrameworkSpecFiles(basePath: string, language?: ScaffoldLanguage): string[];
|
|
24
49
|
export declare function refreshPristineSeeds(basePath: string, options?: RefreshPristineSeedsOptions): void;
|
|
25
50
|
export {};
|
package/dist/copy-templates.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmdirSync, statSync, } from "node:fs";
|
|
5
5
|
import { dirname, join, posix, relative } from "node:path";
|
|
6
6
|
import { getScaffoldDir } from "./bundled-scaffold.js";
|
|
7
|
+
export const SUPPORTED_LANGUAGES = ["en", "zh"];
|
|
7
8
|
// SCAF-19: framework vs seed classification.
|
|
8
9
|
const FRAMEWORK_FILES = [
|
|
9
10
|
"specs/meta.md",
|
|
@@ -11,43 +12,63 @@ const FRAMEWORK_FILES = [
|
|
|
11
12
|
];
|
|
12
13
|
const SEED_FILES = [
|
|
13
14
|
"specs/map.md",
|
|
14
|
-
"specs/
|
|
15
|
-
"specs/
|
|
16
|
-
"specs/
|
|
17
|
-
"specs/test/licensing.md",
|
|
18
|
-
"specs/user/.gitkeep",
|
|
15
|
+
"specs/intents/000-spdx-headers.md",
|
|
16
|
+
"specs/packages/git.md",
|
|
17
|
+
"specs/packages/licensing.md",
|
|
19
18
|
];
|
|
20
19
|
const LEGACY_ITEM_DIRS = [
|
|
21
20
|
["specs/items/user", "specs/user"],
|
|
22
21
|
["specs/items/dev", "specs/dev"],
|
|
23
22
|
["specs/items/test", "specs/test"],
|
|
24
23
|
];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
export function isSupportedLanguage(code) {
|
|
25
|
+
return SUPPORTED_LANGUAGES.includes(code);
|
|
26
|
+
}
|
|
27
|
+
export function formatSupportedLanguages() {
|
|
28
|
+
return SUPPORTED_LANGUAGES.join(", ");
|
|
29
|
+
}
|
|
30
|
+
function getOverlayRelPath(language, relPath) {
|
|
31
|
+
return posix.join("i18n", language, relPath);
|
|
32
|
+
}
|
|
33
|
+
function getOverlayBase(scaffoldDir, language) {
|
|
34
|
+
return join(scaffoldDir, "i18n", language);
|
|
35
|
+
}
|
|
36
|
+
export function listFiles(dir) {
|
|
37
|
+
const files = [];
|
|
38
|
+
for (const entry of readdirSync(dir)) {
|
|
33
39
|
if (entry === ".DS_Store")
|
|
34
40
|
continue;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (statSync(srcPath).isDirectory()) {
|
|
39
|
-
copyRecursive(srcPath, destPath, relPath);
|
|
41
|
+
const path = join(dir, entry);
|
|
42
|
+
if (statSync(path).isDirectory()) {
|
|
43
|
+
files.push(...listFiles(path));
|
|
40
44
|
}
|
|
41
45
|
else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
files.push(path);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return files;
|
|
50
|
+
}
|
|
51
|
+
function listBundledSpecRelPaths(scaffoldDir, language) {
|
|
52
|
+
const relPaths = new Set(listFiles(join(scaffoldDir, "specs")).map((path) => relative(scaffoldDir, path).replace(/\\/g, "/")));
|
|
53
|
+
if (language !== "en") {
|
|
54
|
+
const overlayBase = getOverlayBase(scaffoldDir, language);
|
|
55
|
+
const overlaySpecs = join(overlayBase, "specs");
|
|
56
|
+
if (existsSync(overlaySpecs)) {
|
|
57
|
+
for (const path of listFiles(overlaySpecs)) {
|
|
58
|
+
relPaths.add(relative(overlayBase, path).replace(/\\/g, "/"));
|
|
48
59
|
}
|
|
49
60
|
}
|
|
50
61
|
}
|
|
62
|
+
return [...relPaths].sort();
|
|
63
|
+
}
|
|
64
|
+
export function getBundledSpecFilePath(relPath, language = "en") {
|
|
65
|
+
const scaffoldDir = getScaffoldDir();
|
|
66
|
+
if (language !== "en") {
|
|
67
|
+
const overlayPath = join(scaffoldDir, getOverlayRelPath(language, relPath));
|
|
68
|
+
if (existsSync(overlayPath))
|
|
69
|
+
return overlayPath;
|
|
70
|
+
}
|
|
71
|
+
return join(scaffoldDir, relPath);
|
|
51
72
|
}
|
|
52
73
|
/**
|
|
53
74
|
* Copy bundled template files from scaffold/specs/ to target specs/.
|
|
@@ -55,14 +76,39 @@ function copyRecursive(srcDir, destDir, relRoot) {
|
|
|
55
76
|
* SCAF-8: recursively copies files; existing files are not overwritten.
|
|
56
77
|
* SCAF-9: resolves scaffold/ from the dist/ output directory.
|
|
57
78
|
*/
|
|
58
|
-
export function copyTemplates(basePath) {
|
|
79
|
+
export function copyTemplates(basePath, language = "en") {
|
|
59
80
|
const scaffoldDir = getScaffoldDir();
|
|
60
81
|
const srcSpecs = join(scaffoldDir, "specs");
|
|
61
|
-
const destSpecs = join(basePath, "specs");
|
|
62
82
|
if (!existsSync(srcSpecs)) {
|
|
63
83
|
throw new Error(`Bundled scaffold/specs/ not found: ${srcSpecs}`);
|
|
64
84
|
}
|
|
65
|
-
|
|
85
|
+
for (const relPath of listBundledSpecRelPaths(scaffoldDir, language)) {
|
|
86
|
+
const target = join(basePath, relPath);
|
|
87
|
+
if (existsSync(target)) {
|
|
88
|
+
console.log(` ${relPath} (already exists)`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
92
|
+
copyFileSync(getBundledSpecFilePath(relPath, language), target);
|
|
93
|
+
console.log(` ${relPath}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Copy the bundled top-level LICENSE to the target repository root.
|
|
98
|
+
*
|
|
99
|
+
* SCAF-37: writes scaffold/LICENSE (verbatim Apache-2.0) to
|
|
100
|
+
* <basePath>/LICENSE only when the target is absent, so an existing
|
|
101
|
+
* downstream license is never overwritten. Not localized.
|
|
102
|
+
*/
|
|
103
|
+
export function copyRootLicense(basePath) {
|
|
104
|
+
const source = join(getScaffoldDir(), "LICENSE");
|
|
105
|
+
const target = join(basePath, "LICENSE");
|
|
106
|
+
if (existsSync(target)) {
|
|
107
|
+
console.log(` LICENSE (already exists)`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
copyFileSync(source, target);
|
|
111
|
+
console.log(` LICENSE`);
|
|
66
112
|
}
|
|
67
113
|
// SCAF-13.
|
|
68
114
|
export function getFrameworkSpecFiles() {
|
|
@@ -72,21 +118,6 @@ export function getFrameworkSpecFiles() {
|
|
|
72
118
|
export function getSeedSpecFiles() {
|
|
73
119
|
return SEED_FILES;
|
|
74
120
|
}
|
|
75
|
-
function listFiles(dir) {
|
|
76
|
-
const files = [];
|
|
77
|
-
for (const entry of readdirSync(dir)) {
|
|
78
|
-
if (entry === ".DS_Store")
|
|
79
|
-
continue;
|
|
80
|
-
const path = join(dir, entry);
|
|
81
|
-
if (statSync(path).isDirectory()) {
|
|
82
|
-
files.push(...listFiles(path));
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
files.push(path);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return files;
|
|
89
|
-
}
|
|
90
121
|
function removeEmptyDirectories(dir) {
|
|
91
122
|
if (!existsSync(dir) || !statSync(dir).isDirectory())
|
|
92
123
|
return false;
|
|
@@ -131,6 +162,55 @@ export function migrateLegacyItemLayout(basePath) {
|
|
|
131
162
|
removeEmptyDirectories(join(basePath, "specs", "items"));
|
|
132
163
|
return results;
|
|
133
164
|
}
|
|
165
|
+
// SCAF-51: iteration records become intent records (DR-017).
|
|
166
|
+
export function migrateIterationsLayout(basePath) {
|
|
167
|
+
const results = [];
|
|
168
|
+
const legacyRoot = join(basePath, "specs", "iterations");
|
|
169
|
+
if (!existsSync(legacyRoot) || !statSync(legacyRoot).isDirectory()) {
|
|
170
|
+
return results;
|
|
171
|
+
}
|
|
172
|
+
// Record ids form from the leading number, so a move may collide
|
|
173
|
+
// with a differently named intents/ file on the same number; such
|
|
174
|
+
// a move is kept in place and reported against the id holder.
|
|
175
|
+
const numberTaken = new Map();
|
|
176
|
+
const targetRoot = join(basePath, "specs", "intents");
|
|
177
|
+
if (existsSync(targetRoot) && statSync(targetRoot).isDirectory()) {
|
|
178
|
+
for (const existing of listFiles(targetRoot)) {
|
|
179
|
+
const rel = relative(targetRoot, existing).replace(/\\/g, "/");
|
|
180
|
+
const digits = /^(\d+)/.exec(posix.basename(rel))?.[1];
|
|
181
|
+
if (digits !== undefined && !numberTaken.has(digits)) {
|
|
182
|
+
numberTaken.set(digits, posix.join("specs/intents", rel));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const source of listFiles(legacyRoot)) {
|
|
187
|
+
const suffix = relative(legacyRoot, source).replace(/\\/g, "/");
|
|
188
|
+
const legacyRelPath = posix.join("specs/iterations", suffix);
|
|
189
|
+
const targetRelPath = posix.join("specs/intents", suffix);
|
|
190
|
+
const target = join(basePath, targetRelPath);
|
|
191
|
+
if (existsSync(target)) {
|
|
192
|
+
results.push({ status: "conflict", targetRelPath, legacyRelPath });
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const digits = /^(\d+)/.exec(posix.basename(suffix))?.[1];
|
|
196
|
+
const idHolder = digits === undefined ? undefined : numberTaken.get(digits);
|
|
197
|
+
if (idHolder !== undefined) {
|
|
198
|
+
results.push({
|
|
199
|
+
status: "conflict",
|
|
200
|
+
targetRelPath: idHolder,
|
|
201
|
+
legacyRelPath,
|
|
202
|
+
});
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
206
|
+
renameSync(source, target);
|
|
207
|
+
if (digits !== undefined)
|
|
208
|
+
numberTaken.set(digits, targetRelPath);
|
|
209
|
+
results.push({ status: "migrated", targetRelPath, legacyRelPath });
|
|
210
|
+
}
|
|
211
|
+
removeEmptyDirectories(legacyRoot);
|
|
212
|
+
return results;
|
|
213
|
+
}
|
|
134
214
|
// SCAF-21.
|
|
135
215
|
export function getFileHistory(relPath) {
|
|
136
216
|
const manifestPath = join(getScaffoldDir(), ".file-history.json");
|
|
@@ -140,6 +220,34 @@ export function getFileHistory(relPath) {
|
|
|
140
220
|
const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
141
221
|
return manifest[relPath] ?? [];
|
|
142
222
|
}
|
|
223
|
+
// Hash histories of bundled files that no longer ship (the legacy
|
|
224
|
+
// user/dev/test seeds), so migration can tell an untouched old seed
|
|
225
|
+
// from user-authored content.
|
|
226
|
+
export function getLegacyFileHistory(relPath) {
|
|
227
|
+
const manifestPath = join(getScaffoldDir(), ".legacy-file-history.json");
|
|
228
|
+
if (!existsSync(manifestPath))
|
|
229
|
+
return [];
|
|
230
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
231
|
+
return manifest[relPath] ?? [];
|
|
232
|
+
}
|
|
233
|
+
/** isPristine over the legacy manifest (removed bundled paths). */
|
|
234
|
+
export function isLegacyPristine(basePath, relPath) {
|
|
235
|
+
const target = join(basePath, relPath);
|
|
236
|
+
if (!existsSync(target))
|
|
237
|
+
return "missing";
|
|
238
|
+
return getLegacyFileHistory(relPath).includes(hashFile(target))
|
|
239
|
+
? "pristine"
|
|
240
|
+
: "modified";
|
|
241
|
+
}
|
|
242
|
+
function getRecognizedFileHistory(relPath, language) {
|
|
243
|
+
const history = new Set(getFileHistory(relPath));
|
|
244
|
+
if (language !== "en") {
|
|
245
|
+
for (const hash of getFileHistory(getOverlayRelPath(language, relPath))) {
|
|
246
|
+
history.add(hash);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return [...history];
|
|
250
|
+
}
|
|
143
251
|
function hashFile(path) {
|
|
144
252
|
return canonicalContentHash(readFileSync(path));
|
|
145
253
|
}
|
|
@@ -154,28 +262,38 @@ function canonicalHashInput(data) {
|
|
|
154
262
|
return data.toString("utf-8").replace(/\r\n?/g, "\n");
|
|
155
263
|
}
|
|
156
264
|
// SCAF-22.
|
|
157
|
-
export function isPristine(basePath, relPath) {
|
|
265
|
+
export function isPristine(basePath, relPath, language = "en") {
|
|
158
266
|
const target = join(basePath, relPath);
|
|
159
267
|
if (!existsSync(target))
|
|
160
268
|
return "missing";
|
|
161
|
-
return
|
|
269
|
+
return getRecognizedFileHistory(relPath, language).includes(hashFile(target))
|
|
162
270
|
? "pristine"
|
|
163
271
|
: "modified";
|
|
164
272
|
}
|
|
165
|
-
// SCAF-14.
|
|
166
|
-
|
|
167
|
-
|
|
273
|
+
// SCAF-14. Returns the framework paths that were overwritten while
|
|
274
|
+
// carrying unrecognized (user-modified) content, so the caller can warn
|
|
275
|
+
// before the run completes (SCAF-18).
|
|
276
|
+
export function overwriteFrameworkSpecFiles(basePath, language = "en") {
|
|
277
|
+
const replacedUserModified = [];
|
|
168
278
|
for (const relPath of FRAMEWORK_FILES) {
|
|
279
|
+
const state = isPristine(basePath, relPath, language);
|
|
169
280
|
const target = join(basePath, relPath);
|
|
170
|
-
const source =
|
|
171
|
-
if (
|
|
281
|
+
const source = getBundledSpecFilePath(relPath, language);
|
|
282
|
+
if (state !== "missing" && hashFile(target) === hashFile(source)) {
|
|
172
283
|
console.log(` ${relPath} (unchanged)`);
|
|
173
284
|
continue;
|
|
174
285
|
}
|
|
175
286
|
mkdirSync(dirname(target), { recursive: true });
|
|
176
287
|
copyFileSync(source, target);
|
|
177
|
-
|
|
288
|
+
if (state === "modified") {
|
|
289
|
+
replacedUserModified.push(relPath);
|
|
290
|
+
console.log(` ${relPath} (overwritten — user-modified)`);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
console.log(` ${relPath} (updated)`);
|
|
294
|
+
}
|
|
178
295
|
}
|
|
296
|
+
return replacedUserModified;
|
|
179
297
|
}
|
|
180
298
|
// SCAF-23.
|
|
181
299
|
function formatSeedIndicator(relPath, indicator, migratedFrom) {
|
|
@@ -187,16 +305,16 @@ function formatSeedIndicator(relPath, indicator, migratedFrom) {
|
|
|
187
305
|
return `migrated from ${legacyRelPath}; ${indicator}`;
|
|
188
306
|
}
|
|
189
307
|
export function refreshPristineSeeds(basePath, options = {}) {
|
|
190
|
-
const
|
|
308
|
+
const language = options.language ?? "en";
|
|
191
309
|
for (const relPath of SEED_FILES) {
|
|
192
|
-
const state = isPristine(basePath, relPath);
|
|
310
|
+
const state = isPristine(basePath, relPath, language);
|
|
193
311
|
if (state === "modified") {
|
|
194
|
-
const indicator = formatSeedIndicator(relPath, "kept — user-modified", options.migratedFrom);
|
|
312
|
+
const indicator = formatSeedIndicator(relPath, options.indicatorOverrides?.get(relPath) ?? "kept — user-modified", options.migratedFrom);
|
|
195
313
|
console.log(` ${relPath} (${indicator})`);
|
|
196
314
|
continue;
|
|
197
315
|
}
|
|
198
316
|
const target = join(basePath, relPath);
|
|
199
|
-
const source =
|
|
317
|
+
const source = getBundledSpecFilePath(relPath, language);
|
|
200
318
|
if (state === "pristine" && hashFile(target) === hashFile(source)) {
|
|
201
319
|
const indicator = formatSeedIndicator(relPath, "unchanged", options.migratedFrom);
|
|
202
320
|
console.log(` ${relPath} (${indicator})`);
|
|
@@ -8,10 +8,8 @@ import { join } from "node:path";
|
|
|
8
8
|
const DIRS = [
|
|
9
9
|
"specs",
|
|
10
10
|
"specs/decisions",
|
|
11
|
-
"specs/
|
|
12
|
-
"specs/
|
|
13
|
-
"specs/dev",
|
|
14
|
-
"specs/test",
|
|
11
|
+
"specs/intents",
|
|
12
|
+
"specs/packages",
|
|
15
13
|
];
|
|
16
14
|
/**
|
|
17
15
|
* Create the specs directory structure under basePath.
|
package/dist/lint.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type LintSeverity = "error" | "warning";
|
|
2
|
+
export type LintFinding = {
|
|
3
|
+
path: string;
|
|
4
|
+
line: number;
|
|
5
|
+
severity: LintSeverity;
|
|
6
|
+
rule: string;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
/** Lint the specs tree under basePath (lint-10). */
|
|
10
|
+
export declare function lintSpecs(basePath: string): LintFinding[];
|
|
11
|
+
/**
|
|
12
|
+
* Entry point for the lint subcommand. Prints findings and exits
|
|
13
|
+
* non-zero when any error-severity finding exists (lint-1..3).
|
|
14
|
+
*/
|
|
15
|
+
export declare function lint(args?: string[]): void;
|