@sublang/spex 2.1.1 → 4.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 +15 -7
- package/dist/copy-templates.d.ts +5 -16
- package/dist/copy-templates.js +10 -104
- package/dist/lint.js +37 -26
- package/dist/pin-header-format.d.ts +26 -0
- package/dist/pin-header-format.js +81 -0
- package/dist/scaffold.js +8 -1
- package/package.json +4 -4
- package/scaffold/.file-history.json +30 -8
- package/scaffold/agent-specs.txt +2 -2
- package/scaffold/i18n/zh/specs/decisions/000-spec-structure-format.md +98 -0
- package/scaffold/i18n/zh/specs/intents/000-spdx-headers.md +31 -0
- package/scaffold/i18n/zh/specs/map.md +2 -8
- package/scaffold/i18n/zh/specs/meta.md +106 -74
- package/scaffold/i18n/zh/specs/packages/git.md +50 -0
- package/scaffold/i18n/zh/specs/packages/licensing.md +74 -0
- package/scaffold/spec-migration-prompt.md +2 -2
- package/scaffold/specs/decisions/000-spec-structure-format.md +2 -2
- package/scaffold/specs/intents/000-spdx-headers.md +6 -15
- package/scaffold/specs/map.md +1 -7
- package/scaffold/specs/meta.md +11 -4
- package/scaffold/specs/packages/git.md +6 -3
- package/scaffold/specs/packages/licensing.md +17 -0
- package/scaffold/update-merge-prompt.md +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ This creates:
|
|
|
35
35
|
- **`specs/`** — the spec tree and its law:
|
|
36
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
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
|
|
38
|
+
- `specs/decisions/` and `specs/intents/` hold decision records (DRs) and intent records (IRs); `specs/map.md` indexes decisions and packages 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
|
|
@@ -83,7 +83,7 @@ Relationship-metadata lines like `Verifies:` are errors — the citations woven
|
|
|
83
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)).
|
|
84
84
|
Errors exit non-zero; warnings do not.
|
|
85
85
|
|
|
86
|
-
**Try it:** review the sample intent record `specs/intents/000-spdx-headers.md
|
|
86
|
+
**Try it:** review the sample intent record `specs/intents/000-spdx-headers.md` and the header format the scaffold pinned in `licensing-9` of `specs/packages/licensing.md`, replacing any `<license>` or `<holder>` placeholder it left, then prompt your AI coding agent:
|
|
87
87
|
|
|
88
88
|
```text
|
|
89
89
|
Complete IR-000
|
|
@@ -118,7 +118,7 @@ spex scaffold --update
|
|
|
118
118
|
It runs from within a git repository and requires a clean `specs/` working tree, so every edit stays reviewable.
|
|
119
119
|
|
|
120
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.
|
|
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.
|
|
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. `licensing.md`, whose `licensing-9` the scaffold pins to your project, counts as customized and is kept. Customized starter files are kept as-is. Remove a starter file *after* `--update` if you do not want it.
|
|
122
122
|
- Agent instruction files are reconciled with the confirmed or explicit
|
|
123
123
|
selection; a non-interactive run infers existing managed targets and
|
|
124
124
|
defaults to all targets when none exist.
|
|
@@ -131,21 +131,29 @@ The command prints a per-file indicator for every framework and seed path, plus
|
|
|
131
131
|
|
|
132
132
|
## Upgrading from an earlier release
|
|
133
133
|
|
|
134
|
+
### From 2.x
|
|
135
|
+
|
|
136
|
+
Spex 3.0 makes intent records disposable planning artifacts: no other
|
|
137
|
+
spec may cite or name an IR, and `specs/map.md` indexes decisions and
|
|
138
|
+
packages only. Run `spex scaffold --update`, remove intent rows from a
|
|
139
|
+
customized map and references to IRs from other specs, then reconcile
|
|
140
|
+
until `spex lint` passes.
|
|
141
|
+
|
|
134
142
|
### From 1.x
|
|
135
143
|
|
|
136
144
|
Spex 2.0 tightens the packages-only law introduced in 1.0. Run
|
|
137
145
|
`spex scaffold --update`, review the refreshed law and printed merge prompt,
|
|
138
146
|
then reconcile your packages until `spex lint` passes. In particular,
|
|
139
147
|
every package now requires Verification of its own behavior, behavior
|
|
140
|
-
citations from Verification stay inside that package,
|
|
148
|
+
citations from Verification stay inside that package, DR citations
|
|
141
149
|
use their exact IDs, and every item-bearing basename is tree-wide unique.
|
|
142
150
|
|
|
143
151
|
### From 0.x
|
|
144
152
|
|
|
145
153
|
A tree scaffolded by a spex 0.x release carries the older structural
|
|
146
|
-
generation of the law. Spex 2.0
|
|
154
|
+
generation of the law. Spex 2.0 and later use the following structure:
|
|
147
155
|
|
|
148
|
-
| | Previous generations (spex 0.x) |
|
|
156
|
+
| | Previous generations (spex 0.x) | Packages generation (spex 2.0+) |
|
|
149
157
|
| --- | --- | --- |
|
|
150
158
|
| Layout | `specs/user`/`dev`/`test`, later `packages/` + `compositions/` | `packages/` only — composition is a package pattern |
|
|
151
159
|
| Cross-package behavior | binding and scenario items in composition files | behavior items binding inline to peers' External Behavior |
|
|
@@ -175,7 +183,7 @@ Then loop back to the next decision or intent.
|
|
|
175
183
|
|
|
176
184
|
## Requirements
|
|
177
185
|
|
|
178
|
-
- Node.js >=
|
|
186
|
+
- Node.js >= 22
|
|
179
187
|
- Git (optional, used for repo root detection)
|
|
180
188
|
|
|
181
189
|
## Contributing
|
package/dist/copy-templates.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
export declare const SUPPORTED_LANGUAGES: readonly ["en", "zh"];
|
|
2
2
|
export type ScaffoldLanguage = (typeof SUPPORTED_LANGUAGES)[number];
|
|
3
3
|
export type PristineState = "pristine" | "modified" | "missing";
|
|
4
|
-
export type LegacyItemLayoutResult = {
|
|
5
|
-
status: "migrated" | "conflict";
|
|
6
|
-
targetRelPath: string;
|
|
7
|
-
legacyRelPath: string;
|
|
8
|
-
};
|
|
9
4
|
type RefreshPristineSeedsOptions = {
|
|
10
|
-
migratedFrom?: ReadonlyMap<string, string>;
|
|
11
5
|
language?: ScaffoldLanguage;
|
|
12
6
|
/**
|
|
13
7
|
* A second language whose bundled versions also count as pristine.
|
|
@@ -16,12 +10,6 @@ type RefreshPristineSeedsOptions = {
|
|
|
16
10
|
* convertible bundled file, not a user customization.
|
|
17
11
|
*/
|
|
18
12
|
alsoRecognize?: readonly ScaffoldLanguage[];
|
|
19
|
-
/**
|
|
20
|
-
* Replacement indicator text for user-modified seeds that this run
|
|
21
|
-
* transformed in place (e.g. a restructured map.md), so one line
|
|
22
|
-
* reports the seed's true outcome.
|
|
23
|
-
*/
|
|
24
|
-
indicatorOverrides?: ReadonlyMap<string, string>;
|
|
25
13
|
};
|
|
26
14
|
export declare function isSupportedLanguage(code: string): code is ScaffoldLanguage;
|
|
27
15
|
export declare function formatSupportedLanguages(): string;
|
|
@@ -39,13 +27,14 @@ export declare function copyTemplates(basePath: string, language?: ScaffoldLangu
|
|
|
39
27
|
*
|
|
40
28
|
* SCAF-37: writes scaffold/LICENSE (verbatim Apache-2.0) to
|
|
41
29
|
* <basePath>/LICENSE only when the target is absent, so an existing
|
|
42
|
-
* downstream license is never overwritten. Not localized.
|
|
30
|
+
* downstream license is never overwritten. Not localized. Returns
|
|
31
|
+
* whether the root LICENSE now holds the bundled Apache-2.0 text —
|
|
32
|
+
* written by this run or already there — so the header format pinned
|
|
33
|
+
* in the licensing seed (SCAF-56) can name that license.
|
|
43
34
|
*/
|
|
44
|
-
export declare function copyRootLicense(basePath: string):
|
|
35
|
+
export declare function copyRootLicense(basePath: string): boolean;
|
|
45
36
|
export declare function getFrameworkSpecFiles(): readonly string[];
|
|
46
37
|
export declare function getSeedSpecFiles(): readonly string[];
|
|
47
|
-
export declare function migrateLegacyItemLayout(basePath: string): LegacyItemLayoutResult[];
|
|
48
|
-
export declare function migrateIterationsLayout(basePath: string): LegacyItemLayoutResult[];
|
|
49
38
|
export declare function getFileHistory(relPath: string): string[];
|
|
50
39
|
export declare function getLegacyFileHistory(relPath: string): string[];
|
|
51
40
|
/** isPristine over the legacy manifest (removed bundled paths). */
|
package/dist/copy-templates.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync,
|
|
4
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, statSync, } from "node:fs";
|
|
5
5
|
import { dirname, join, posix, relative } from "node:path";
|
|
6
6
|
import { getScaffoldDir } from "./bundled-scaffold.js";
|
|
7
7
|
export const SUPPORTED_LANGUAGES = ["en", "zh"];
|
|
@@ -16,11 +16,6 @@ const SEED_FILES = [
|
|
|
16
16
|
"specs/packages/git.md",
|
|
17
17
|
"specs/packages/licensing.md",
|
|
18
18
|
];
|
|
19
|
-
const LEGACY_ITEM_DIRS = [
|
|
20
|
-
["specs/items/user", "specs/user"],
|
|
21
|
-
["specs/items/dev", "specs/dev"],
|
|
22
|
-
["specs/items/test", "specs/test"],
|
|
23
|
-
];
|
|
24
19
|
export function isSupportedLanguage(code) {
|
|
25
20
|
return SUPPORTED_LANGUAGES.includes(code);
|
|
26
21
|
}
|
|
@@ -98,17 +93,21 @@ export function copyTemplates(basePath, language = "en") {
|
|
|
98
93
|
*
|
|
99
94
|
* SCAF-37: writes scaffold/LICENSE (verbatim Apache-2.0) to
|
|
100
95
|
* <basePath>/LICENSE only when the target is absent, so an existing
|
|
101
|
-
* downstream license is never overwritten. Not localized.
|
|
96
|
+
* downstream license is never overwritten. Not localized. Returns
|
|
97
|
+
* whether the root LICENSE now holds the bundled Apache-2.0 text —
|
|
98
|
+
* written by this run or already there — so the header format pinned
|
|
99
|
+
* in the licensing seed (SCAF-56) can name that license.
|
|
102
100
|
*/
|
|
103
101
|
export function copyRootLicense(basePath) {
|
|
104
102
|
const source = join(getScaffoldDir(), "LICENSE");
|
|
105
103
|
const target = join(basePath, "LICENSE");
|
|
106
104
|
if (existsSync(target)) {
|
|
107
105
|
console.log(` LICENSE (already exists)`);
|
|
108
|
-
return;
|
|
106
|
+
return hashFile(target) === hashFile(source);
|
|
109
107
|
}
|
|
110
108
|
copyFileSync(source, target);
|
|
111
109
|
console.log(` LICENSE`);
|
|
110
|
+
return true;
|
|
112
111
|
}
|
|
113
112
|
// SCAF-13.
|
|
114
113
|
export function getFrameworkSpecFiles() {
|
|
@@ -130,87 +129,6 @@ function removeEmptyDirectories(dir) {
|
|
|
130
129
|
}
|
|
131
130
|
return false;
|
|
132
131
|
}
|
|
133
|
-
// SCAF-26.
|
|
134
|
-
export function migrateLegacyItemLayout(basePath) {
|
|
135
|
-
const results = [];
|
|
136
|
-
for (const [legacyRootRel, targetRootRel] of LEGACY_ITEM_DIRS) {
|
|
137
|
-
const legacyRoot = join(basePath, legacyRootRel);
|
|
138
|
-
if (!existsSync(legacyRoot))
|
|
139
|
-
continue;
|
|
140
|
-
for (const source of listFiles(legacyRoot)) {
|
|
141
|
-
const suffix = relative(legacyRoot, source).replace(/\\/g, "/");
|
|
142
|
-
const legacyRelPath = posix.join(legacyRootRel, suffix);
|
|
143
|
-
const targetRelPath = posix.join(targetRootRel, suffix);
|
|
144
|
-
const target = join(basePath, targetRelPath);
|
|
145
|
-
if (existsSync(target)) {
|
|
146
|
-
results.push({
|
|
147
|
-
status: "conflict",
|
|
148
|
-
targetRelPath,
|
|
149
|
-
legacyRelPath,
|
|
150
|
-
});
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
mkdirSync(dirname(target), { recursive: true });
|
|
154
|
-
renameSync(source, target);
|
|
155
|
-
results.push({
|
|
156
|
-
status: "migrated",
|
|
157
|
-
targetRelPath,
|
|
158
|
-
legacyRelPath,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
removeEmptyDirectories(join(basePath, "specs", "items"));
|
|
163
|
-
return results;
|
|
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
|
-
}
|
|
214
132
|
// SCAF-21.
|
|
215
133
|
export function getFileHistory(relPath) {
|
|
216
134
|
const manifestPath = join(getScaffoldDir(), ".file-history.json");
|
|
@@ -297,35 +215,23 @@ export function overwriteFrameworkSpecFiles(basePath, language = "en", alsoRecog
|
|
|
297
215
|
}
|
|
298
216
|
return replacedUserModified;
|
|
299
217
|
}
|
|
300
|
-
// SCAF-23.
|
|
301
|
-
function formatSeedIndicator(relPath, indicator, migratedFrom) {
|
|
302
|
-
const legacyRelPath = migratedFrom?.get(relPath);
|
|
303
|
-
if (legacyRelPath === undefined)
|
|
304
|
-
return indicator;
|
|
305
|
-
if (indicator === "unchanged")
|
|
306
|
-
return `migrated from ${legacyRelPath}`;
|
|
307
|
-
return `migrated from ${legacyRelPath}; ${indicator}`;
|
|
308
|
-
}
|
|
309
218
|
export function refreshPristineSeeds(basePath, options = {}) {
|
|
310
219
|
const language = options.language ?? "en";
|
|
311
220
|
for (const relPath of SEED_FILES) {
|
|
312
221
|
const state = isPristine(basePath, relPath, language, options.alsoRecognize);
|
|
313
222
|
if (state === "modified") {
|
|
314
|
-
|
|
315
|
-
console.log(` ${relPath} (${indicator})`);
|
|
223
|
+
console.log(` ${relPath} (kept — user-modified)`);
|
|
316
224
|
continue;
|
|
317
225
|
}
|
|
318
226
|
const target = join(basePath, relPath);
|
|
319
227
|
const source = getBundledSpecFilePath(relPath, language);
|
|
320
228
|
if (state === "pristine" && hashFile(target) === hashFile(source)) {
|
|
321
|
-
|
|
322
|
-
console.log(` ${relPath} (${indicator})`);
|
|
229
|
+
console.log(` ${relPath} (unchanged)`);
|
|
323
230
|
continue;
|
|
324
231
|
}
|
|
325
232
|
mkdirSync(dirname(target), { recursive: true });
|
|
326
233
|
copyFileSync(source, target);
|
|
327
|
-
|
|
328
|
-
console.log(` ${relPath} (${formatSeedIndicator(relPath, indicator, options.migratedFrom)})`);
|
|
234
|
+
console.log(` ${relPath} (${state === "missing" ? "created" : "updated"})`);
|
|
329
235
|
}
|
|
330
236
|
}
|
|
331
237
|
//# sourceMappingURL=copy-templates.js.map
|
package/dist/lint.js
CHANGED
|
@@ -22,9 +22,8 @@ const PACKAGE_SECTION_ORDER = [
|
|
|
22
22
|
"References",
|
|
23
23
|
];
|
|
24
24
|
// Required record sections per meta-4 / meta-5, with the zh names
|
|
25
|
-
// of the bundled templates.
|
|
26
|
-
//
|
|
27
|
-
// external sources legitimately omits it — it is not required here.
|
|
25
|
+
// of the bundled templates. meta-4 makes a DR's References section
|
|
26
|
+
// conditional on citing an external source, so it is not listed.
|
|
28
27
|
const DR_SECTIONS = {
|
|
29
28
|
Status: ["Status", "状态"],
|
|
30
29
|
Context: ["Context", "背景"],
|
|
@@ -210,13 +209,16 @@ const SECTION_BY_NAME = aliasSet(SECTION_ALIASES);
|
|
|
210
209
|
function isUnder(relPath, dir) {
|
|
211
210
|
return relPath.startsWith(`specs/${dir}/`);
|
|
212
211
|
}
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
212
|
+
// meta-18 exempts one thing: the record naming itself, which every
|
|
213
|
+
// IR does in its H1. So a file may reference only its own id — a
|
|
214
|
+
// package, the map, and one IR naming another are all violations.
|
|
215
|
+
// Returns the id a file may name, or null when it may name none.
|
|
216
|
+
function ownIntentId(relPath) {
|
|
217
|
+
if (!isUnder(relPath, "intents") && !isUnder(relPath, "iterations")) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
const leading = basenameOf(relPath).match(/^(\d+)/);
|
|
221
|
+
return leading === null ? null : `IR-${leading[1]}`;
|
|
220
222
|
}
|
|
221
223
|
function basenameOf(relPath) {
|
|
222
224
|
return posix.basename(relPath, ".md");
|
|
@@ -623,17 +625,16 @@ function lintCitationDiscipline(ctx, items) {
|
|
|
623
625
|
function lintCitations(ctx, items) {
|
|
624
626
|
const bySlug = itemsBySlug(items);
|
|
625
627
|
for (const file of ctx.files.values()) {
|
|
626
|
-
// Naming an IR in prose is citing it, and no
|
|
627
|
-
// does either (meta-18)
|
|
628
|
-
// packages/, and meta.md alone; intent records and map.md sit
|
|
629
|
-
// outside the prohibition. Matched over parsed inline text, so
|
|
628
|
+
// Naming an IR in prose is citing it, and no spec but that IR
|
|
629
|
+
// does either (meta-18). Matched over parsed inline text, so
|
|
630
630
|
// inline code and code blocks cannot trip it (lint-10).
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
631
|
+
const ownId = ownIntentId(file.relPath);
|
|
632
|
+
for (const span of file.texts) {
|
|
633
|
+
for (const [offset, value] of span.value.split("\n").entries()) {
|
|
634
|
+
for (const match of value.matchAll(/\bIR-\d+\b/g)) {
|
|
635
|
+
if (match[0] === ownId)
|
|
636
|
+
continue;
|
|
637
|
+
report(ctx, file.relPath, span.line + offset, "error", "cite/intent", `no spec but that intent record names an IR in prose (meta-18): ${match[0]}`);
|
|
637
638
|
}
|
|
638
639
|
}
|
|
639
640
|
}
|
|
@@ -668,10 +669,12 @@ function lintCitations(ctx, items) {
|
|
|
668
669
|
report(ctx, file.relPath, link.line, "error", "cite/legacy-path", `link points into the legacy layout (${resolved}); cite the current layout of meta-1 instead`);
|
|
669
670
|
continue;
|
|
670
671
|
}
|
|
672
|
+
// A link into an intent record is a citation of it; only that
|
|
673
|
+
// record itself is exempt (meta-18).
|
|
671
674
|
if ((resolved.startsWith("specs/intents/") ||
|
|
672
675
|
resolved.startsWith("specs/iterations/")) &&
|
|
673
|
-
|
|
674
|
-
report(ctx, file.relPath, link.line, "error", "cite/intent", `no
|
|
676
|
+
resolved !== file.relPath) {
|
|
677
|
+
report(ctx, file.relPath, link.line, "error", "cite/intent", `no spec but that intent record cites an IR (meta-18)`);
|
|
675
678
|
}
|
|
676
679
|
if (!existsSync(join(ctx.basePath, resolved))) {
|
|
677
680
|
report(ctx, file.relPath, link.line, "error", "cite/broken-link", `link target ${resolved} does not exist`);
|
|
@@ -689,12 +692,17 @@ function lintCitations(ctx, items) {
|
|
|
689
692
|
}
|
|
690
693
|
}
|
|
691
694
|
}
|
|
692
|
-
/**
|
|
695
|
+
/**
|
|
696
|
+
* DR citations are plain links to the file, labeled by record ID.
|
|
697
|
+
* meta-16 states a form for spec items and DRs alone: no spec but an
|
|
698
|
+
* intent record itself may cite one (meta-18), and the form of that
|
|
699
|
+
* one link is unstated, so this rule leaves intent records alone.
|
|
700
|
+
*/
|
|
693
701
|
function lintRecordCitationForm(ctx, file, link, targetPath, fragment) {
|
|
694
|
-
const match = targetPath.match(/^specs\/
|
|
702
|
+
const match = targetPath.match(/^specs\/decisions\/(\d+)-[^/]+\.md$/);
|
|
695
703
|
if (match === null)
|
|
696
704
|
return;
|
|
697
|
-
const expected =
|
|
705
|
+
const expected = `DR-${match[1]}`;
|
|
698
706
|
if (!link.enclosed && link.text === expected && fragment === "")
|
|
699
707
|
return;
|
|
700
708
|
report(ctx, file.relPath, link.line, "error", "cite/record-link", `citation of ${expected} must be a plain relative link to its file with ${expected} as the link text (meta-16)`);
|
|
@@ -827,8 +835,11 @@ function lintMap(ctx) {
|
|
|
827
835
|
listed.add(posix.normalize(posix.join("specs", url.split("#")[0])));
|
|
828
836
|
}
|
|
829
837
|
for (const file of ctx.files.values()) {
|
|
830
|
-
|
|
838
|
+
// The map indexes decisions and packages (DR-000), so both are
|
|
839
|
+
// checked; intent records are outside it (meta-18).
|
|
840
|
+
if (!isUnder(file.relPath, "packages") && !isUnder(file.relPath, "decisions")) {
|
|
831
841
|
continue;
|
|
842
|
+
}
|
|
832
843
|
if (!listed.has(file.relPath)) {
|
|
833
844
|
report(ctx, file.relPath, 1, "warning", "map/unlisted", `${file.relPath} is not linked from specs/map.md`);
|
|
834
845
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const LICENSING_SEED_PATH = "specs/packages/licensing.md";
|
|
2
|
+
export interface PinHeaderFormatOptions {
|
|
3
|
+
/** Whether the target root `LICENSE` is the bundled Apache-2.0 text. */
|
|
4
|
+
apacheLicense: boolean;
|
|
5
|
+
/** Clock override for tests. */
|
|
6
|
+
now?: Date;
|
|
7
|
+
}
|
|
8
|
+
export interface PinnedHeaderFormat {
|
|
9
|
+
/** Placeholders left unresolved, in file order. */
|
|
10
|
+
unresolved: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Derive the project's copyright holder from the git identity the
|
|
14
|
+
* scaffold runs under: `user.name`, with ` <user.email>` appended when
|
|
15
|
+
* an email is configured. Undefined when no name is configured.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveCopyrightHolder(basePath: string): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Pin the project's own header format into the licensing seed just
|
|
20
|
+
* written: the current year, the git identity as the holder, and
|
|
21
|
+
* `Apache-2.0` when the root LICENSE is the bundled text. Whatever
|
|
22
|
+
* cannot be resolved keeps its placeholder and is reported.
|
|
23
|
+
*/
|
|
24
|
+
export declare function pinHeaderFormat(basePath: string, options: PinHeaderFormatOptions): PinnedHeaderFormat;
|
|
25
|
+
/** The stderr warning for each placeholder `pinHeaderFormat` left. */
|
|
26
|
+
export declare function warnUnresolvedHeaderFormat(unresolved: string[]): void;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
export const LICENSING_SEED_PATH = "specs/packages/licensing.md";
|
|
7
|
+
/**
|
|
8
|
+
* The placeholders the bundled licensing seed carries in `licensing-9`.
|
|
9
|
+
* A placeholder the scaffold cannot resolve stays in the file, so an
|
|
10
|
+
* agent reading it sees an unresolved value rather than a holder
|
|
11
|
+
* copied from the template's own upstream SPDX line.
|
|
12
|
+
*/
|
|
13
|
+
const HOLDER_PLACEHOLDER = "<holder>";
|
|
14
|
+
const LICENSE_PLACEHOLDER = "<license>";
|
|
15
|
+
const YEAR_PLACEHOLDER = "<year>";
|
|
16
|
+
function readGitConfig(basePath, key) {
|
|
17
|
+
try {
|
|
18
|
+
const value = execFileSync("git", ["config", "--get", key], {
|
|
19
|
+
cwd: basePath,
|
|
20
|
+
encoding: "utf-8",
|
|
21
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
22
|
+
}).trim();
|
|
23
|
+
return value === "" ? undefined : value;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Derive the project's copyright holder from the git identity the
|
|
31
|
+
* scaffold runs under: `user.name`, with ` <user.email>` appended when
|
|
32
|
+
* an email is configured. Undefined when no name is configured.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveCopyrightHolder(basePath) {
|
|
35
|
+
const name = readGitConfig(basePath, "user.name");
|
|
36
|
+
if (name === undefined)
|
|
37
|
+
return undefined;
|
|
38
|
+
const email = readGitConfig(basePath, "user.email");
|
|
39
|
+
return email === undefined ? name : `${name} <${email}>`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Pin the project's own header format into the licensing seed just
|
|
43
|
+
* written: the current year, the git identity as the holder, and
|
|
44
|
+
* `Apache-2.0` when the root LICENSE is the bundled text. Whatever
|
|
45
|
+
* cannot be resolved keeps its placeholder and is reported.
|
|
46
|
+
*/
|
|
47
|
+
export function pinHeaderFormat(basePath, options) {
|
|
48
|
+
const target = join(basePath, LICENSING_SEED_PATH);
|
|
49
|
+
if (!existsSync(target))
|
|
50
|
+
return { unresolved: [] };
|
|
51
|
+
const year = String((options.now ?? new Date()).getFullYear());
|
|
52
|
+
const holder = resolveCopyrightHolder(basePath);
|
|
53
|
+
const license = options.apacheLicense ? "Apache-2.0" : undefined;
|
|
54
|
+
let content = readFileSync(target, "utf-8").replaceAll(YEAR_PLACEHOLDER, year);
|
|
55
|
+
if (license !== undefined) {
|
|
56
|
+
content = content.replaceAll(LICENSE_PLACEHOLDER, license);
|
|
57
|
+
}
|
|
58
|
+
if (holder !== undefined) {
|
|
59
|
+
content = content.replaceAll(HOLDER_PLACEHOLDER, holder);
|
|
60
|
+
}
|
|
61
|
+
writeFileSync(target, content);
|
|
62
|
+
const unresolved = [];
|
|
63
|
+
if (license === undefined)
|
|
64
|
+
unresolved.push(LICENSE_PLACEHOLDER);
|
|
65
|
+
if (holder === undefined)
|
|
66
|
+
unresolved.push(HOLDER_PLACEHOLDER);
|
|
67
|
+
return { unresolved };
|
|
68
|
+
}
|
|
69
|
+
/** The stderr warning for each placeholder `pinHeaderFormat` left. */
|
|
70
|
+
export function warnUnresolvedHeaderFormat(unresolved) {
|
|
71
|
+
for (const placeholder of unresolved) {
|
|
72
|
+
const reason = placeholder === HOLDER_PLACEHOLDER
|
|
73
|
+
? "no git user.name is configured"
|
|
74
|
+
: "the root LICENSE is not the bundled Apache-2.0 text";
|
|
75
|
+
const value = placeholder === HOLDER_PLACEHOLDER
|
|
76
|
+
? "the project's copyright holder"
|
|
77
|
+
: "the project's SPDX license identifier";
|
|
78
|
+
console.warn(` warning: ${reason}, so licensing-9 in ${LICENSING_SEED_PATH} keeps its ${placeholder} placeholder; replace it with ${value}.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=pin-header-format.js.map
|
package/dist/scaffold.js
CHANGED
|
@@ -7,6 +7,7 @@ import { parseAgentNames, reconcileAgentSpecs, resolveAgentTargets, } from "./ap
|
|
|
7
7
|
import { getScaffoldDir, readBundledMarkdown } from "./bundled-scaffold.js";
|
|
8
8
|
import { canonicalContentHash, copyRootLicense, copyTemplates, formatSupportedLanguages, getFileHistory, SUPPORTED_LANGUAGES, isLegacyPristine, isPristine, isSupportedLanguage, overwriteFrameworkSpecFiles, refreshPristineSeeds, } from "./copy-templates.js";
|
|
9
9
|
import { createSpecsStructure } from "./create-specs-structure.js";
|
|
10
|
+
import { LICENSING_SEED_PATH, pinHeaderFormat, warnUnresolvedHeaderFormat, } from "./pin-header-format.js";
|
|
10
11
|
import { resolveBase } from "./resolve-base.js";
|
|
11
12
|
const AUTHORING_LANGUAGE_RE = /^Authoring language:\s*([A-Za-z0-9-]+)\s*$/m;
|
|
12
13
|
// SCAF-26 / SCAF-52: directories that mark a legacy spec generation.
|
|
@@ -310,9 +311,15 @@ export function scaffold(args = []) {
|
|
|
310
311
|
const language = resolveCreateLanguage(basePath, options.language);
|
|
311
312
|
assertNoLegacyLayout(basePath);
|
|
312
313
|
const agentTargets = resolveAgentTargets(basePath, options.agents);
|
|
314
|
+
// SCAF-56: only a licensing seed this run writes gets the project's
|
|
315
|
+
// header format pinned; an existing one is the project's own.
|
|
316
|
+
const licensingSeedExisted = existsSync(join(basePath, LICENSING_SEED_PATH));
|
|
313
317
|
createSpecsStructure(basePath);
|
|
314
318
|
copyTemplates(basePath, language);
|
|
315
|
-
copyRootLicense(basePath);
|
|
319
|
+
const apacheLicense = copyRootLicense(basePath);
|
|
320
|
+
if (!licensingSeedExisted) {
|
|
321
|
+
warnUnresolvedHeaderFormat(pinHeaderFormat(basePath, { apacheLicense }).unresolved);
|
|
322
|
+
}
|
|
316
323
|
reconcileAgentSpecs(basePath, agentTargets);
|
|
317
324
|
}
|
|
318
325
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sublang/spex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "The essential spec layer AI agents need to build software reliably",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"test:integration": "node scripts/stage-scaffold.mjs && node scripts/run-tests.cjs \"\\.integration\\.test\\.js$\""
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
38
|
+
"node": ">=22"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/mdast": "^4.0.4",
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"typescript": "^
|
|
42
|
+
"@types/node": "^26.4.0",
|
|
43
|
+
"typescript": "^7.0.2"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"github-slugger": "^2.0.0",
|
|
@@ -2,50 +2,72 @@
|
|
|
2
2
|
"i18n/zh/specs/map.md": [
|
|
3
3
|
"sha256-f1bcf636c567b830c5d6f625e10c8e4fe2c56b71fa7787106cd7b8701ad20efe",
|
|
4
4
|
"sha256-5da224028a738e3f8c50adbeb1f2bc9006beafe47050594a9a30b207d8ff0386",
|
|
5
|
-
"sha256-390e4beb58f88ffcdb63c9518634d31c07d61f71e09a3bfab0495a5da0c56244"
|
|
5
|
+
"sha256-390e4beb58f88ffcdb63c9518634d31c07d61f71e09a3bfab0495a5da0c56244",
|
|
6
|
+
"sha256-a1c6e3e3b6f41531da5959dd688d8c0049d1e64b19ecf708a944de987c987f83"
|
|
6
7
|
],
|
|
7
8
|
"i18n/zh/specs/meta.md": [
|
|
8
9
|
"sha256-ce07160cf8af1fb67f4f86c572aa182e92dff24a72b313a89914e058de894b56",
|
|
9
10
|
"sha256-78a34b62546391e16f27265399c62568882563cad97def3520d9f675a7b75cab",
|
|
10
11
|
"sha256-1d8a2507d30ef54b5d935a53b448ec74ea8a8556df5cae24e81dcfbd94f9b648",
|
|
11
12
|
"sha256-3c75823810863849ae302255d477749fc57e8e367a499240cde0dd47c479219a",
|
|
12
|
-
"sha256-b4feb754ffd405050d50efe9da527c9a81e7dec48f58a7ed29db3bd28617bbbb"
|
|
13
|
+
"sha256-b4feb754ffd405050d50efe9da527c9a81e7dec48f58a7ed29db3bd28617bbbb",
|
|
14
|
+
"sha256-78e528aee1d8f5b4946c53e119a81c7548df53bd09f8458152c2c2aaa386cd82",
|
|
15
|
+
"sha256-174cb27f6637f1b6ea9b163bd5d9a7f4dfe8b4aa52e4bca889c2da8bdb6862f1"
|
|
13
16
|
],
|
|
14
17
|
"specs/decisions/000-spec-structure-format.md": [
|
|
15
18
|
"sha256-28d0705311a8ede97c487a944efe99bed20863e246da0aa1a33286dd4f8864ca",
|
|
16
19
|
"sha256-a06e1b102d96c91f6ba36fd317426aae9c6a384a76c2dd5996275405d02d1883",
|
|
17
20
|
"sha256-e492c52ea2ff89ab7b5b87d151a1755fac094233524eb8e6718be43111321227",
|
|
18
21
|
"sha256-97041a244e1f1bef6c14b44a2805c214931c649faa523e49489ae7c42c9c11b5",
|
|
19
|
-
"sha256-456de62399db3a9d5d4ee9cfc722930112d677ee50660b4702d04837c9f5b1ea"
|
|
22
|
+
"sha256-456de62399db3a9d5d4ee9cfc722930112d677ee50660b4702d04837c9f5b1ea",
|
|
23
|
+
"sha256-4c32ec9e308762026c9ec184a03885f3cd58d1eb1ab97300d6c82600ae71de64"
|
|
20
24
|
],
|
|
21
25
|
"specs/map.md": [
|
|
22
26
|
"sha256-a1d6bc4a23fa58d8ccdcf7cd0570fc05face0aae8b6947367298dad3cde0af75",
|
|
23
27
|
"sha256-4f2772c2d268972c1d5b1e2f4efb604b304c285ef3d91def9c1bad59666b303d",
|
|
24
28
|
"sha256-aa12c658e84b8925b2981807a72edc9dbd274a78bd87f7186bb558afc42d8bc6",
|
|
25
|
-
"sha256-6d93bd3c2c2fc35e0806229f45c751429ae4ef7ae86ff9e9089b76b0edbf7461"
|
|
29
|
+
"sha256-6d93bd3c2c2fc35e0806229f45c751429ae4ef7ae86ff9e9089b76b0edbf7461",
|
|
30
|
+
"sha256-5dbf6d5bf1f09c74f8bf71209986eca460723957c6861f0a73654b88d9e522d9"
|
|
26
31
|
],
|
|
27
32
|
"specs/meta.md": [
|
|
28
33
|
"sha256-ce07160cf8af1fb67f4f86c572aa182e92dff24a72b313a89914e058de894b56",
|
|
29
34
|
"sha256-78a34b62546391e16f27265399c62568882563cad97def3520d9f675a7b75cab",
|
|
30
35
|
"sha256-6a23f014ccbbe871e811f2ef9bd39119b50f0ce65a10bd75045d5735cf5b70b3",
|
|
31
36
|
"sha256-ca67a077cfaecb51a85e98ec8f8508ce9d8a43dcb7355b9e16de611c38cdabfc",
|
|
32
|
-
"sha256-ba58b39de3537f06fbe4f13c9b1443a8a64cf090c9ba202a67263dfc054b78c8"
|
|
37
|
+
"sha256-ba58b39de3537f06fbe4f13c9b1443a8a64cf090c9ba202a67263dfc054b78c8",
|
|
38
|
+
"sha256-ed90e3e82e18d3893e52d18e80d795406bc9a0b5915416ee73295a4d7c7ff52a",
|
|
39
|
+
"sha256-d7fb96010dbcdc89fcea56dc1c4cf6db6b6b56d261aedaa7f6ee36fb9dd3c7f5"
|
|
33
40
|
],
|
|
34
41
|
"specs/packages/git.md": [
|
|
35
42
|
"sha256-1b194304866d05580de8b2d0caa3454aa772e876fb3dee1f6c5d637c9e9a42b2",
|
|
36
43
|
"sha256-77625a315ac14eb6fd5f3c0697f121646ba8c0d976a98c3b51f27f3422cd1afb",
|
|
37
|
-
"sha256-648eb12f6dd2dd5b9c9cebc14708de1a6d2184b698dfeacce93102995878e14a"
|
|
44
|
+
"sha256-648eb12f6dd2dd5b9c9cebc14708de1a6d2184b698dfeacce93102995878e14a",
|
|
45
|
+
"sha256-f4bdc7cf1ea7be17575fb189abb9fa3cfbc9eeb8a7bccefbbffdbea3d4210608"
|
|
38
46
|
],
|
|
39
47
|
"specs/packages/licensing.md": [
|
|
40
48
|
"sha256-ff6ce317bf51fb2f4a20dde8790a79f2a1237f6b5835c74e619f6e3d1647ab50",
|
|
41
49
|
"sha256-f0690fbe5613097f3d0d1196fec5323a21a6b62bc3875068c38d09c74c5658c4",
|
|
42
50
|
"sha256-3ea1ba444666c05895c05d7f33056137b5dab8f6cdbdb80eb057a338fdf8eb4b",
|
|
43
|
-
"sha256-7a08e109f0314e9b3297d2d791b635afb183c0815775690690497a9ac720a95b"
|
|
51
|
+
"sha256-7a08e109f0314e9b3297d2d791b635afb183c0815775690690497a9ac720a95b",
|
|
52
|
+
"sha256-0fdea7c594fe52e33c78f30afd2edc3e53414a8ee666a1a4acdaf64ee05487b0"
|
|
44
53
|
],
|
|
45
54
|
"specs/intents/000-spdx-headers.md": [
|
|
46
55
|
"sha256-a5ae7e8e31e4292a9364ba7947b2fbf27836e9f88dc80436557191550fe1bd34",
|
|
47
56
|
"sha256-f9914497c46f9bfa05d12dfa9190c2d53d20cffd1af3eb3e44f0f0a4b20830f2",
|
|
48
57
|
"sha256-4fac8c7fee1fec71297c50ee605f0417c3ae2b27e8aa37b03e409f08db976516",
|
|
49
|
-
"sha256-0bf92bee3c73d1f34da7039480d56b290e6e5a40a1314bc23a4be81507c80d3e"
|
|
58
|
+
"sha256-0bf92bee3c73d1f34da7039480d56b290e6e5a40a1314bc23a4be81507c80d3e",
|
|
59
|
+
"sha256-d2246bb72b8a1be75cf8dd293e80c51e5f5de6f810a8d1fbc71982a52d3fecc3"
|
|
60
|
+
],
|
|
61
|
+
"i18n/zh/specs/decisions/000-spec-structure-format.md": [
|
|
62
|
+
"sha256-061769e9a2a55ec6d1bcddd47c9aaacb0881a011106a34cb13fa78dc0bd099bf"
|
|
63
|
+
],
|
|
64
|
+
"i18n/zh/specs/intents/000-spdx-headers.md": [
|
|
65
|
+
"sha256-f661027e2af391b88458088534a57108ceaa8458bce7eb342702149c5b43c3a8"
|
|
66
|
+
],
|
|
67
|
+
"i18n/zh/specs/packages/git.md": [
|
|
68
|
+
"sha256-a22cc1cc543e0fa56cc42be4a96383b7866235d7b9bd1c27e2d4bb95e67b5667"
|
|
69
|
+
],
|
|
70
|
+
"i18n/zh/specs/packages/licensing.md": [
|
|
71
|
+
"sha256-b8219306bb5f6e33a548430c96301f0fa6b14bad36f3cb5ef72dc5338ea81aba"
|
|
50
72
|
]
|
|
51
73
|
}
|