@sublang/spex 0.2.1 → 0.2.3

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.
@@ -1,4 +1,12 @@
1
1
  export type PristineState = "pristine" | "modified" | "missing";
2
+ export type LegacyItemLayoutResult = {
3
+ status: "migrated" | "conflict";
4
+ targetRelPath: string;
5
+ legacyRelPath: string;
6
+ };
7
+ type RefreshPristineSeedsOptions = {
8
+ migratedFrom?: ReadonlyMap<string, string>;
9
+ };
2
10
  /**
3
11
  * Copy bundled template files from scaffold/specs/ to target specs/.
4
12
  *
@@ -8,16 +16,10 @@ export type PristineState = "pristine" | "modified" | "missing";
8
16
  export declare function copyTemplates(basePath: string): void;
9
17
  export declare function getFrameworkSpecFiles(): readonly string[];
10
18
  export declare function getSeedSpecFiles(): readonly string[];
11
- export declare function migrateLegacyItemLayout(basePath: string): {
12
- migrated: string[];
13
- conflicts: string[];
14
- };
19
+ export declare function migrateLegacyItemLayout(basePath: string): LegacyItemLayoutResult[];
15
20
  export declare function getFileHistory(relPath: string): string[];
16
21
  export declare function canonicalContentHash(data: Buffer): string;
17
22
  export declare function isPristine(basePath: string, relPath: string): PristineState;
18
23
  export declare function overwriteFrameworkSpecFiles(basePath: string): void;
19
- export declare function refreshPristineSeeds(basePath: string): {
20
- refreshed: string[];
21
- unchanged: string[];
22
- modified: string[];
23
- };
24
+ export declare function refreshPristineSeeds(basePath: string, options?: RefreshPristineSeedsOptions): void;
25
+ export {};
@@ -101,8 +101,7 @@ function removeEmptyDirectories(dir) {
101
101
  }
102
102
  // SCAF-26.
103
103
  export function migrateLegacyItemLayout(basePath) {
104
- const migrated = [];
105
- const conflicts = [];
104
+ const results = [];
106
105
  for (const [legacyRootRel, targetRootRel] of LEGACY_ITEM_DIRS) {
107
106
  const legacyRoot = join(basePath, legacyRootRel);
108
107
  if (!existsSync(legacyRoot))
@@ -113,18 +112,24 @@ export function migrateLegacyItemLayout(basePath) {
113
112
  const targetRelPath = posix.join(targetRootRel, suffix);
114
113
  const target = join(basePath, targetRelPath);
115
114
  if (existsSync(target)) {
116
- console.log(` ${legacyRelPath} (kept — target exists at ${targetRelPath})`);
117
- conflicts.push(legacyRelPath);
115
+ results.push({
116
+ status: "conflict",
117
+ targetRelPath,
118
+ legacyRelPath,
119
+ });
118
120
  continue;
119
121
  }
120
122
  mkdirSync(dirname(target), { recursive: true });
121
123
  renameSync(source, target);
122
- console.log(` ${targetRelPath} (migrated from ${legacyRelPath})`);
123
- migrated.push(targetRelPath);
124
+ results.push({
125
+ status: "migrated",
126
+ targetRelPath,
127
+ legacyRelPath,
128
+ });
124
129
  }
125
130
  }
126
131
  removeEmptyDirectories(join(basePath, "specs", "items"));
127
- return { migrated, conflicts };
132
+ return results;
128
133
  }
129
134
  // SCAF-21.
130
135
  export function getFileHistory(relPath) {
@@ -173,30 +178,34 @@ export function overwriteFrameworkSpecFiles(basePath) {
173
178
  }
174
179
  }
175
180
  // SCAF-23.
176
- export function refreshPristineSeeds(basePath) {
181
+ function formatSeedIndicator(relPath, indicator, migratedFrom) {
182
+ const legacyRelPath = migratedFrom?.get(relPath);
183
+ if (legacyRelPath === undefined)
184
+ return indicator;
185
+ if (indicator === "unchanged")
186
+ return `migrated from ${legacyRelPath}`;
187
+ return `migrated from ${legacyRelPath}; ${indicator}`;
188
+ }
189
+ export function refreshPristineSeeds(basePath, options = {}) {
177
190
  const scaffoldDir = getScaffoldDir();
178
- const refreshed = [];
179
- const unchanged = [];
180
- const modified = [];
181
191
  for (const relPath of SEED_FILES) {
182
192
  const state = isPristine(basePath, relPath);
183
193
  if (state === "modified") {
184
- console.log(` ${relPath} (kept — user-modified)`);
185
- modified.push(relPath);
194
+ const indicator = formatSeedIndicator(relPath, "kept — user-modified", options.migratedFrom);
195
+ console.log(` ${relPath} (${indicator})`);
186
196
  continue;
187
197
  }
188
198
  const target = join(basePath, relPath);
189
199
  const source = join(scaffoldDir, relPath);
190
200
  if (state === "pristine" && hashFile(target) === hashFile(source)) {
191
- console.log(` ${relPath} (unchanged)`);
192
- unchanged.push(relPath);
201
+ const indicator = formatSeedIndicator(relPath, "unchanged", options.migratedFrom);
202
+ console.log(` ${relPath} (${indicator})`);
193
203
  continue;
194
204
  }
195
205
  mkdirSync(dirname(target), { recursive: true });
196
206
  copyFileSync(source, target);
197
- console.log(` ${relPath} (updated)`);
198
- refreshed.push(relPath);
207
+ const indicator = state === "missing" ? "created" : "updated";
208
+ console.log(` ${relPath} (${formatSeedIndicator(relPath, indicator, options.migratedFrom)})`);
199
209
  }
200
- return { refreshed, unchanged, modified };
201
210
  }
202
211
  //# sourceMappingURL=copy-templates.js.map
package/dist/scaffold.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import { execFileSync } from "node:child_process";
4
4
  import { appendAgentSpecs } from "./append-agent-specs.js";
5
5
  import { readBundledMarkdown } from "./bundled-scaffold.js";
6
- import { copyTemplates, migrateLegacyItemLayout, overwriteFrameworkSpecFiles, refreshPristineSeeds, } from "./copy-templates.js";
6
+ import { copyTemplates, getSeedSpecFiles, migrateLegacyItemLayout, overwriteFrameworkSpecFiles, refreshPristineSeeds, } from "./copy-templates.js";
7
7
  import { createSpecsStructure } from "./create-specs-structure.js";
8
8
  import { resolveBase } from "./resolve-base.js";
9
9
  function parseArgs(args) {
@@ -46,9 +46,24 @@ function readUpdateMergePrompt() {
46
46
  function updateScaffoldTemplates() {
47
47
  const basePath = getGitRoot();
48
48
  assertCleanSpecsTree(basePath);
49
- const legacyReport = migrateLegacyItemLayout(basePath);
49
+ const legacyResults = migrateLegacyItemLayout(basePath);
50
+ const seedPaths = new Set(getSeedSpecFiles());
51
+ const migratedSeedSources = new Map();
52
+ for (const result of legacyResults) {
53
+ if (result.status === "migrated" && seedPaths.has(result.targetRelPath)) {
54
+ migratedSeedSources.set(result.targetRelPath, result.legacyRelPath);
55
+ }
56
+ }
57
+ for (const result of legacyResults) {
58
+ if (result.status === "conflict") {
59
+ console.log(` ${result.legacyRelPath} (kept — target exists at ${result.targetRelPath})`);
60
+ }
61
+ else if (!seedPaths.has(result.targetRelPath)) {
62
+ console.log(` ${result.targetRelPath} (migrated from ${result.legacyRelPath})`);
63
+ }
64
+ }
50
65
  overwriteFrameworkSpecFiles(basePath);
51
- const seedReport = refreshPristineSeeds(basePath);
66
+ refreshPristineSeeds(basePath, { migratedFrom: migratedSeedSources });
52
67
  console.log("");
53
68
  console.log("spex scaffold --update completed.");
54
69
  console.log("Review the file indicators above and inspect changes (e.g., `git diff -- specs`).");
@@ -57,27 +72,6 @@ function updateScaffoldTemplates() {
57
72
  console.log("```");
58
73
  console.log(readUpdateMergePrompt());
59
74
  console.log("```");
60
- if (legacyReport.migrated.length > 0) {
61
- console.log("");
62
- console.log("Legacy specs/items layout migrated:");
63
- for (const relPath of legacyReport.migrated) {
64
- console.log(`- ${relPath}`);
65
- }
66
- }
67
- if (legacyReport.conflicts.length > 0) {
68
- console.log("");
69
- console.log("Legacy paths left in place because flat targets already exist:");
70
- for (const relPath of legacyReport.conflicts) {
71
- console.log(`- ${relPath}`);
72
- }
73
- }
74
- if (seedReport.refreshed.length > 0) {
75
- console.log("");
76
- console.log("Seeds written from bundled templates (absent or pristine):");
77
- for (const relPath of seedReport.refreshed) {
78
- console.log(`- ${relPath}`);
79
- }
80
- }
81
75
  }
82
76
  /**
83
77
  * Entry point for the scaffold subcommand.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sublang/spex",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "The essential spec layer AI agents need to build software reliably",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -7,12 +7,14 @@
7
7
  "sha256-1b194304866d05580de8b2d0caa3454aa772e876fb3dee1f6c5d637c9e9a42b2"
8
8
  ],
9
9
  "specs/dev/licensing.md": [
10
- "sha256-ff6ce317bf51fb2f4a20dde8790a79f2a1237f6b5835c74e619f6e3d1647ab50"
10
+ "sha256-ff6ce317bf51fb2f4a20dde8790a79f2a1237f6b5835c74e619f6e3d1647ab50",
11
+ "sha256-f0690fbe5613097f3d0d1196fec5323a21a6b62bc3875068c38d09c74c5658c4"
11
12
  ],
12
13
  "specs/iterations/000-spdx-headers.md": [
13
14
  "sha256-a5ae7e8e31e4292a9364ba7947b2fbf27836e9f88dc80436557191550fe1bd34",
14
15
  "sha256-3b7d95e80a9ca42b81510d4fac5515fdeeb80d842f7aeb91fef76bafccc01b1a",
15
- "sha256-f9914497c46f9bfa05d12dfa9190c2d53d20cffd1af3eb3e44f0f0a4b20830f2"
16
+ "sha256-f9914497c46f9bfa05d12dfa9190c2d53d20cffd1af3eb3e44f0f0a4b20830f2",
17
+ "sha256-4fac8c7fee1fec71297c50ee605f0417c3ae2b27e8aa37b03e409f08db976516"
16
18
  ],
17
19
  "specs/map.md": [
18
20
  "sha256-a1d6bc4a23fa58d8ccdcf7cd0570fc05face0aae8b6947367298dad3cde0af75",
@@ -36,3 +36,9 @@ Where the file has comment syntax and is not excluded by [Exclusions](#exclusion
36
36
  ### LIC-2
37
37
 
38
38
  Where the file has comment syntax, is not excluded by [Exclusions](#exclusions), and one or more project-root license files match [License File Detection](#license-file-detection), while the file is git-tracked or `git add`-able, when preparing the file for inclusion in the repo, the file shall include `SPDX-License-Identifier` in its first comment block after any shebang.
39
+
40
+ ### LIC-5
41
+
42
+ Where a file's first comment block already contains `SPDX-FileCopyrightText` or `SPDX-License-Identifier` from an upstream source (e.g., a template or vendored file copied from another project), when preparing the file for inclusion in the repo, those existing SPDX lines shall be preserved unmodified, even when the project root carries a different license.
43
+
44
+ [LIC-1](#lic-1) and [LIC-2](#lic-2) are satisfied by the preserved upstream headers; no project-license header shall be appended or substituted.
@@ -5,51 +5,31 @@
5
5
 
6
6
  ## Goal
7
7
 
8
- Add SPDX headers (license and copyright info) to applicable files.
8
+ Apply [LIC-1](../dev/licensing.md#lic-1), [LIC-2](../dev/licensing.md#lic-2), [LIC-5](../dev/licensing.md#lic-5) to in-scope files and pin the project's header format.
9
9
 
10
10
  ## Deliverables
11
11
 
12
- - [ ] Add SPDX headers to applicable files missing them
13
- - [ ] Document header format in a dev spec
12
+ - [ ] Add SPDX headers to in-scope files missing them
13
+ - [ ] Add a `## Format` section to [`dev/licensing.md`](../dev/licensing.md) with the project's actual license and copyright
14
14
 
15
15
  ## Tasks
16
16
 
17
- 1. **Detect license file(s)** at project root; skip license line if absent
18
- - Single license: `LICENSE`, `LICENSE.txt`, `LICENSE.md`, `COPYING`
19
- - Named variants: `LICENSE-CONTENT`, `LICENSE-APACHE`, etc.
20
- - British spelling: `LICENCE`, `LICENCE.txt`
21
- - Multiple licenses: `LICENSES/` folder (REUSE convention)
22
-
23
- 2. **Identify applicable files** according to the license(s): git-tracked or `git add`-able files with comment syntax. Excludes:
24
- - No comment syntax: e.g., JSON, binaries
25
- - Config: e.g., `.gitignore`, `.editorconfig`, `**/settings.json`, `AGENTS.md`, `.github/workflows/ci.yml`, lock files
26
- - Generated/vendor: e.g., `dist/`, `node_modules/`
27
- - License/legal documents
28
-
29
- 3. **Add headers** in the first comment block (after shebang if present), using appropriate comment syntax per file type
30
-
31
- 4. **Document format** in a dev spec according to the license(s). E.g.:
32
-
33
- > **Source code** (including specs):
34
- >
35
- > ```typescript
36
- > // SPDX-License-Identifier: Apache-2.0
37
- > // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
38
- > ```
39
- >
40
- > ```markdown
41
- > <!-- SPDX-License-Identifier: Apache-2.0 -->
42
- > <!-- SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai> -->
43
- > ```
44
- >
45
- > **Contents** (README, docs, blogs, etc.):
46
- >
47
- > ```markdown
48
- > <!-- SPDX-License-Identifier: CC-BY-SA-4.0 -->
49
- > <!-- SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai> -->
50
- > ```
17
+ 1. Resolve scope: detect a project-root license file per [License File Detection](../dev/licensing.md#license-file-detection); enumerate in-scope files per [Exclusions](../dev/licensing.md#exclusions).
18
+
19
+ 2. Insert SPDX lines in each file's first comment block (after any shebang), using the file's native comment syntax.
20
+
21
+ 3. Append a `## Format` section to [`dev/licensing.md`](../dev/licensing.md) showing the concrete header per comment style. Example for a single Apache-2.0 `LICENSE`:
22
+
23
+ ```markdown
24
+ <!-- SPDX-License-Identifier: Apache-2.0 -->
25
+ <!-- SPDX-FileCopyrightText: <year> <holder> -->
26
+ ```
27
+
28
+ ```typescript
29
+ // SPDX-License-Identifier: Apache-2.0
30
+ // SPDX-FileCopyrightText: <year> <holder>
31
+ ```
51
32
 
52
33
  ## Acceptance criteria
53
34
 
54
- - All source files have SPDX-FileCopyrightText header ([LIC-3](../test/licensing.md#lic-3))
55
- - Files have SPDX-License-Identifier if a license file exists ([LIC-4](../test/licensing.md#lic-4))
35
+ - [LIC-3](../test/licensing.md#lic-3), [LIC-4](../test/licensing.md#lic-4) pass on all in-scope files.