@sublang/spex 6.0.0 → 7.0.0-beta.2

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.
Files changed (108) hide show
  1. package/README.md +419 -12
  2. package/dist/cli.js +12 -1
  3. package/dist/commands/add.d.ts +1 -1
  4. package/dist/commands/add.js +2 -2
  5. package/dist/commands/environment.d.ts +3 -3
  6. package/dist/commands/environment.js +5 -7
  7. package/dist/commands/export.js +2 -2
  8. package/dist/commands/home.d.ts +2 -2
  9. package/dist/commands/home.js +3 -3
  10. package/dist/commands/list.js +1 -1
  11. package/dist/commands/login.js +12 -7
  12. package/dist/commands/logout.js +2 -3
  13. package/dist/commands/publish.js +1 -1
  14. package/dist/commands/remove.js +1 -1
  15. package/dist/commands/run.d.ts +1 -1
  16. package/dist/commands/run.js +16 -0
  17. package/dist/commands/settle.d.ts +1 -1
  18. package/dist/commands/settle.js +1 -1
  19. package/dist/guards/approval.d.ts +56 -0
  20. package/dist/guards/approval.js +158 -0
  21. package/dist/guards/checks.d.ts +207 -0
  22. package/dist/guards/checks.js +681 -0
  23. package/dist/guards/commands.d.ts +15 -0
  24. package/dist/guards/commands.js +313 -0
  25. package/dist/guards/copy.d.ts +67 -0
  26. package/dist/guards/copy.js +306 -0
  27. package/dist/guards/declaration.d.ts +45 -0
  28. package/dist/guards/declaration.js +224 -0
  29. package/dist/guards/files.d.ts +137 -0
  30. package/dist/guards/files.js +544 -0
  31. package/dist/guards/harness.d.ts +58 -0
  32. package/dist/guards/harness.js +420 -0
  33. package/dist/guards/items.d.ts +61 -0
  34. package/dist/guards/items.js +161 -0
  35. package/dist/guards/patch.d.ts +55 -0
  36. package/dist/guards/patch.js +258 -0
  37. package/dist/guards/processes.d.ts +49 -0
  38. package/dist/guards/processes.js +233 -0
  39. package/dist/guards/proofs.d.ts +88 -0
  40. package/dist/guards/proofs.js +503 -0
  41. package/dist/guards/records.d.ts +176 -0
  42. package/dist/guards/records.js +513 -0
  43. package/dist/guards/report.d.ts +26 -0
  44. package/dist/guards/report.js +492 -0
  45. package/dist/guards/runner.d.ts +42 -0
  46. package/dist/guards/runner.js +167 -0
  47. package/dist/guards/tla.d.ts +51 -0
  48. package/dist/guards/tla.js +352 -0
  49. package/dist/guards/tlapm.d.ts +81 -0
  50. package/dist/guards/tlapm.js +172 -0
  51. package/dist/guards/tlc.d.ts +191 -0
  52. package/dist/guards/tlc.js +457 -0
  53. package/dist/guards/translation.d.ts +66 -0
  54. package/dist/guards/translation.js +202 -0
  55. package/dist/guards/types.d.ts +185 -0
  56. package/dist/guards/types.js +437 -0
  57. package/dist/guards/verify.d.ts +290 -0
  58. package/dist/guards/verify.js +1191 -0
  59. package/dist/guards/xml.d.ts +18 -0
  60. package/dist/guards/xml.js +105 -0
  61. package/dist/lib/environment/archive.d.ts +2 -2
  62. package/dist/lib/environment/archive.js +1 -1
  63. package/dist/lib/environment/builtins.d.ts +10 -12
  64. package/dist/lib/environment/builtins.js +17 -19
  65. package/dist/lib/environment/exports.d.ts +14 -13
  66. package/dist/lib/environment/exports.js +31 -16
  67. package/dist/lib/environment/format.d.ts +2 -2
  68. package/dist/lib/environment/format.js +3 -3
  69. package/dist/lib/environment/git-source.js +6 -3
  70. package/dist/lib/environment/install.d.ts +14 -16
  71. package/dist/lib/environment/install.js +66 -61
  72. package/dist/lib/environment/lock.d.ts +4 -3
  73. package/dist/lib/environment/lock.js +6 -5
  74. package/dist/lib/environment/marker.js +1 -2
  75. package/dist/lib/environment/own-paths.d.ts +7 -10
  76. package/dist/lib/environment/own-paths.js +10 -13
  77. package/dist/lib/environment/placed-record.d.ts +3 -2
  78. package/dist/lib/environment/placed-record.js +5 -4
  79. package/dist/lib/environment/registry.d.ts +1 -1
  80. package/dist/lib/environment/registry.js +1 -1
  81. package/dist/lib/environment/requests.d.ts +2 -2
  82. package/dist/lib/environment/requests.js +2 -2
  83. package/dist/lib/environment/resolve.d.ts +4 -4
  84. package/dist/lib/environment/resolve.js +3 -4
  85. package/dist/lib/environment/store.d.ts +34 -8
  86. package/dist/lib/environment/store.js +138 -43
  87. package/dist/lib/files.d.ts +72 -12
  88. package/dist/lib/files.js +200 -65
  89. package/dist/lib/git-host.d.ts +52 -258
  90. package/dist/lib/git-host.js +52 -265
  91. package/dist/lib/home-file.d.ts +13 -10
  92. package/dist/lib/home-file.js +28 -18
  93. package/dist/lib/instance.d.ts +1 -1
  94. package/dist/lib/instance.js +1 -1
  95. package/dist/lint.d.ts +22 -0
  96. package/dist/lint.js +36 -0
  97. package/dist/testing/standin-registry.js +1 -1
  98. package/package.json +7 -3
  99. package/scaffold/.file-history.json +14 -7
  100. package/scaffold/i18n/zh/source-pins.json +41 -0
  101. package/scaffold/i18n/zh/specs/decisions/000-spec-structure-format.md +0 -1
  102. package/scaffold/i18n/zh/specs/intents/000-spdx-headers.md +0 -1
  103. package/scaffold/i18n/zh/specs/map.md +0 -1
  104. package/scaffold/i18n/zh/specs/meta.md +18 -35
  105. package/scaffold/i18n/zh/specs/packages/git.md +0 -1
  106. package/scaffold/i18n/zh/specs/packages/licensing.md +0 -1
  107. package/scaffold/specs/meta.md +18 -3
  108. package/scripts/test-exit-guard.mjs +28 -0
@@ -0,0 +1,18 @@
1
+ /** One element: its name, its child elements in order and the text
2
+ * directly inside it, its entities read. */
3
+ export type XmlElement = {
4
+ tag: string;
5
+ children: XmlElement[];
6
+ text: string;
7
+ };
8
+ /**
9
+ * Read an XML document into its root element. Throws a GuardError
10
+ * where the text is not XML of this shape: an attribute on an
11
+ * element, a tag that does not close, or text outside the root.
12
+ */
13
+ export declare function parseXml(text: string): XmlElement;
14
+ /** The first child element named `tag`, or undefined. */
15
+ export declare function child(element: XmlElement | undefined, tag: string): XmlElement | undefined;
16
+ /** The text of the element at `path` under `element`, trimmed, or
17
+ * undefined where there is none. */
18
+ export declare function textAt(element: XmlElement | undefined, ...path: string[]): string | undefined;
@@ -0,0 +1,105 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ /*
4
+ * Guards package, DR-244 and DR-252: the smallest reader of the XML
5
+ * that TLC's parser writes of a module (`tla2sany.xml.XMLExporter`),
6
+ * enough to tell what a proof file holds. That XML has elements, text
7
+ * and the five predefined entities, and no attribute but in its
8
+ * declaration; this reads exactly that and refuses what it cannot
9
+ * read, so nothing it skips can hide a unit. It adds no dependency.
10
+ */
11
+ import { GuardError } from "./types.js";
12
+ const ENTITIES = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
13
+ /** Text with its entities read: the five named ones and numeric ones. */
14
+ function decoded(text, at) {
15
+ return text.replace(/&(#x[0-9A-Fa-f]+|#[0-9]+|[A-Za-z]+);|&/g, (whole, name) => {
16
+ if (name === undefined)
17
+ throw new GuardError(`the XML holds a lone & near character ${at}`);
18
+ if (name.startsWith("#x"))
19
+ return String.fromCodePoint(Number.parseInt(name.slice(2), 16));
20
+ if (name.startsWith("#"))
21
+ return String.fromCodePoint(Number.parseInt(name.slice(1), 10));
22
+ const named = ENTITIES[name];
23
+ if (named === undefined)
24
+ throw new GuardError(`the XML holds an unknown entity ${whole} near character ${at}`);
25
+ return named;
26
+ });
27
+ }
28
+ /**
29
+ * Read an XML document into its root element. Throws a GuardError
30
+ * where the text is not XML of this shape: an attribute on an
31
+ * element, a tag that does not close, or text outside the root.
32
+ */
33
+ export function parseXml(text) {
34
+ const markup = /<\?[\s\S]*?\?>|<!--[\s\S]*?-->|<!\[CDATA\[([\s\S]*?)\]\]>|<(\/?)([A-Za-z_][\w.:-]*)(\s*)(\/?)>|</g;
35
+ const open = [];
36
+ let root = null;
37
+ let last = 0;
38
+ const textUntil = (end) => {
39
+ const between = text.slice(last, end);
40
+ if (between === "")
41
+ return;
42
+ const top = open[open.length - 1];
43
+ if (top === undefined) {
44
+ if (between.trim() !== "")
45
+ throw new GuardError(`the XML holds text outside its root near character ${last}`);
46
+ return;
47
+ }
48
+ top.text += decoded(between, last);
49
+ };
50
+ for (const found of text.matchAll(markup)) {
51
+ const at = found.index;
52
+ textUntil(at);
53
+ last = at + found[0].length;
54
+ const [whole, cdata, closing, tag, , empty] = found;
55
+ if (whole.startsWith("<?") || whole.startsWith("<!--"))
56
+ continue;
57
+ if (cdata !== undefined) {
58
+ const top = open[open.length - 1];
59
+ if (top === undefined)
60
+ throw new GuardError(`the XML holds text outside its root near character ${at}`);
61
+ top.text += cdata;
62
+ continue;
63
+ }
64
+ if (tag === undefined)
65
+ throw new GuardError(`the XML holds a tag this reader does not take near character ${at}`);
66
+ if (closing === "/") {
67
+ const top = open.pop();
68
+ if (top === undefined || top.tag !== tag)
69
+ throw new GuardError(`the XML closes ${tag} where it is not open, near character ${at}`);
70
+ if (open.length === 0)
71
+ root = top;
72
+ continue;
73
+ }
74
+ if (open.length === 0 && root !== null) {
75
+ throw new GuardError(`the XML holds a second root near character ${at}`);
76
+ }
77
+ const element = { tag, children: [], text: "" };
78
+ open[open.length - 1]?.children.push(element);
79
+ if (empty === "/") {
80
+ if (open.length === 0)
81
+ root = element;
82
+ }
83
+ else
84
+ open.push(element);
85
+ }
86
+ textUntil(text.length);
87
+ if (open.length > 0)
88
+ throw new GuardError(`the XML leaves ${open[open.length - 1].tag} open`);
89
+ if (root === null)
90
+ throw new GuardError("the XML holds no element");
91
+ return root;
92
+ }
93
+ /** The first child element named `tag`, or undefined. */
94
+ export function child(element, tag) {
95
+ return element?.children.find((one) => one.tag === tag);
96
+ }
97
+ /** The text of the element at `path` under `element`, trimmed, or
98
+ * undefined where there is none. */
99
+ export function textAt(element, ...path) {
100
+ let at = element;
101
+ for (const tag of path)
102
+ at = child(at, tag);
103
+ return at?.text.trim();
104
+ }
105
+ //# sourceMappingURL=xml.js.map
@@ -17,7 +17,7 @@ export interface UnpackedRelease {
17
17
  /** Unpack and check a release archive as the registry does. */
18
18
  export declare function unpackRelease(tgz: Uint8Array, pkg: string): UnpackedRelease;
19
19
  /** Explicit metadata for a publication snapshot; the local package keeps
20
- * its own identity and license (environments-10). */
20
+ * its own identity and license (environments-59). */
21
21
  export interface PublicationFields {
22
22
  org: string;
23
23
  license: string;
@@ -30,7 +30,7 @@ export declare function preparePublication(dir: string, publication?: Publicatio
30
30
  files: ReleaseFile[];
31
31
  archive: Uint8Array;
32
32
  }>;
33
- /** Publish a release folder as it is (environments-10), uploading the
33
+ /** Publish a release folder as it is (environments-59), uploading the
34
34
  * same captured bytes that passed validation. */
35
35
  export declare function publishRelease(registry: RegistrySource, dir: string): Promise<{
36
36
  name: string;
@@ -111,7 +111,7 @@ export async function preparePublication(dir, publication) {
111
111
  throw new FormatError(issues, "publishing");
112
112
  return { source, manifest: checked.manifest, files: checked.files, archive };
113
113
  }
114
- /** Publish a release folder as it is (environments-10), uploading the
114
+ /** Publish a release folder as it is (environments-59), uploading the
115
115
  * same captured bytes that passed validation. */
116
116
  export async function publishRelease(registry, dir) {
117
117
  const { manifest, archive } = await preparePublication(dir);
@@ -24,8 +24,7 @@ export interface BuiltinRelease {
24
24
  /** The built-in spec package staged under `root`, where the app's build
25
25
  * stages it: the highest version staged. */
26
26
  export declare function stagedBuiltinPackage(root: string): BuiltinPackage;
27
- /** Seed a built-in release into the store and record its index
28
- * (environments-11). Idempotent; an older seeded release stays. */
27
+ /** Seed a built-in release into the store and record its index. Idempotent; an older seeded release stays. */
29
28
  export declare function seedBuiltinPackage(store: ContentStore, cacheDir: string, pkg: BuiltinPackage): Promise<BuiltinRelease>;
30
29
  export interface BuiltinSourceOptions {
31
30
  store: ContentStore;
@@ -36,12 +35,12 @@ export interface BuiltinSourceOptions {
36
35
  * none where omitted. */
37
36
  shipped?: BuiltinPackage | null;
38
37
  }
39
- /** The seeded built-in releases as a registry source (environments-11):
38
+ /** The seeded built-in releases as a registry source:
40
39
  * no network, `sublang/playbooks` only. */
41
40
  export declare function builtinRegistrySource(options: BuiltinSourceOptions): RegistrySource;
42
41
  /**
43
42
  * Whether this device's seed serves a lock's release of the built-in spec
44
- * package (environments-7, environments-11): it holds the locked version
43
+ * package (environments-7): it holds the locked version
45
44
  * and each locked file at the digest the lock records for it. The
46
45
  * archive's checksum is not compared: each device packs its own archive
47
46
  * from its seed, so another device's lock of the same files may record
@@ -58,8 +57,8 @@ export declare function seedServes(seed: RegistrySource, version: string, files:
58
57
  */
59
58
  export declare function builtinLock(pkg: BuiltinPackage, registryUrl: string, requestsText: string): Lock;
60
59
  /**
61
- * A new environment at its root (environments-11, storage-6): your own
62
- * group's clone, or a project's working folder at its pairing.
60
+ * A new environment at its root: the global
61
+ * records repository, or a project's working folder at its pairing.
63
62
  * `spex.yaml` requests the built-in spec package where it does not —
64
63
  * with `space` naming the environment's instance where one is given, the
65
64
  * caller giving the instance its spex repository is placed at wherever
@@ -70,7 +69,7 @@ export declare function builtinLock(pkg: BuiltinPackage, registryUrl: string, re
70
69
  export declare function prepareBuiltinEnvironment(root: string, pkg: BuiltinPackage, registryUrl: string, space?: string | null): boolean;
71
70
  /**
72
71
  * Move an environment's built-in lock to `registryUrl` where it is
73
- * still the one a pairing prepared (environments-11, DR-127): `spex.yaml`
72
+ * still the one a pairing prepared (DR-127): `spex.yaml`
74
73
  * requesting the built-in spec package alone, and `spex.lock` exactly
75
74
  * the built-in lock at the registry it records — another than
76
75
  * `registryUrl`, or that one while `spex.yaml` does not name `space`.
@@ -84,8 +83,7 @@ export declare function prepareBuiltinEnvironment(root: string, pkg: BuiltinPack
84
83
  export declare function rehomeBuiltinLock(root: string, pkg: BuiltinPackage, registryUrl: string, space?: string | null): boolean;
85
84
  /**
86
85
  * Request the built-in spec package at a caret requirement in an
87
- * environment's `spex.yaml` at its root where it is not requested
88
- * (environments-11, storage-6): written synchronously, so a clone's
86
+ * environment's `spex.yaml` at its root where it is not requested: written synchronously, so a clone's
89
87
  * first commit already holds it; comments and key order of an existing
90
88
  * file are kept, and the file is written under the version read, so a
91
89
  * file changed meanwhile is refused as a conflict (DR-111). Where `space` is given and the file
@@ -96,12 +94,12 @@ export declare function rehomeBuiltinLock(root: string, pkg: BuiltinPackage, reg
96
94
  */
97
95
  export declare function ensureBuiltinRequest(root: string, version: string, space?: string | null): boolean;
98
96
  /**
99
- * A new project's environment at its pairing (storage-6, DR-176): where
97
+ * A new project's environment at its pairing (DR-176): where
100
98
  * the working folder holds no `spex.yaml`, one naming the public
101
99
  * registry as every new file does (environments-38), `space` where the
102
- * project's spex repository is placed at an instance (DR-170), and
100
+ * project's spex repository is placed at an instance, and
103
101
  * requesting nothing — the built-in spec package is a global package,
104
- * never a project's request (environments-11). Created exclusively, so a
102
+ * never a project's request. Created exclusively, so a
105
103
  * file written meanwhile stands; a root that does not exist is left as
106
104
  * it is. Returns whether it wrote.
107
105
  */
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // The built-in spec package (environments-11, DR-104): the playbooks
3
+ // The built-in spec package (DR-104): the playbooks
4
4
  // Playbook ships, staged at build as `sublang/playbooks` at Playbook's
5
5
  // version under `assets/builtins/<version>/`, seeded into the store at
6
6
  // start with a release index under `cache/builtins/`, and served as a
@@ -31,22 +31,21 @@ export function stagedBuiltinPackage(root) {
31
31
  function recordFile(cacheDir, version) {
32
32
  return join(cacheDir, "builtins", `${version}.json`);
33
33
  }
34
- /** Seed a built-in release into the store and record its index
35
- * (environments-11). Idempotent; an older seeded release stays. */
34
+ /** Seed a built-in release into the store and record its index. Idempotent; an older seeded release stays. */
36
35
  export async function seedBuiltinPackage(store, cacheDir, pkg) {
37
36
  // Seeded already, its files whole in the store: nothing to do.
38
37
  const seeded = readRecord(recordFile(cacheDir, pkg.version));
39
- if (seeded && seeded.files.every((file) => store.has(file.sha256, file.executable)))
38
+ if (seeded && seeded.files.every((file) => store.has(file.sha256)))
40
39
  return seeded;
41
40
  const release = await shippedRecord(pkg);
42
41
  if (`${release.manifest.org}/${release.manifest.name}` !== BUILTIN_PACKAGE_NAME || release.manifest.version !== pkg.version) {
43
42
  throw new Error(`${pkg.dir} holds ${release.manifest.org}/${release.manifest.name} ${release.manifest.version}, not ${BUILTIN_PACKAGE_NAME} ${pkg.version}`);
44
43
  }
45
44
  for (const file of release.files) {
46
- if (store.has(file.sha256, file.executable))
45
+ if (store.has(file.sha256))
47
46
  continue;
48
47
  const bytes = await readFile(join(pkg.dir, ...file.path.split("/")));
49
- store.put(bytes, file.sha256, file.executable, `${BUILTIN_PACKAGE_NAME} ${file.path}`);
48
+ store.put(bytes, file.sha256, `${BUILTIN_PACKAGE_NAME} ${file.path}`);
50
49
  }
51
50
  const file = recordFile(cacheDir, pkg.version);
52
51
  await mkdir(dirname(file), { recursive: true });
@@ -80,7 +79,7 @@ function readRecord(file) {
80
79
  }
81
80
  }
82
81
  const PUBLISHED_AT = "1970-01-01T00:00:00.000Z";
83
- /** The seeded built-in releases as a registry source (environments-11):
82
+ /** The seeded built-in releases as a registry source:
84
83
  * no network, `sublang/playbooks` only. */
85
84
  export function builtinRegistrySource(options) {
86
85
  const { store, cacheDir } = options;
@@ -102,7 +101,7 @@ export function builtinRegistrySource(options) {
102
101
  continue;
103
102
  const record = readRecord(join(dir, name));
104
103
  // A seeded release serves only while the store holds its files.
105
- if (record && record.files.every((file) => store.has(file.sha256, file.executable)))
104
+ if (record && record.files.every((file) => store.has(file.sha256)))
106
105
  out.set(record.version, record);
107
106
  }
108
107
  }
@@ -133,8 +132,8 @@ export function builtinRegistrySource(options) {
133
132
  const file = release.files.find((item) => item.path === path);
134
133
  if (!file)
135
134
  throw new RegistryError("not_found", BUILTIN_PACKAGE_NAME, `${BUILTIN_PACKAGE_NAME} ${release.version} has no file ${path}`);
136
- if (store.has(file.sha256, file.executable))
137
- return new Uint8Array(await readFile(store.pathOf(file.sha256, file.executable)));
135
+ if (store.has(file.sha256))
136
+ return new Uint8Array(await readFile(store.pathOf(file.sha256)));
138
137
  const shipped = options.shipped ?? null;
139
138
  if (shipped && shipped.version === release.version)
140
139
  return new Uint8Array(await readFile(join(shipped.dir, ...path.split("/"))));
@@ -212,7 +211,7 @@ export function builtinRegistrySource(options) {
212
211
  }
213
212
  /**
214
213
  * Whether this device's seed serves a lock's release of the built-in spec
215
- * package (environments-7, environments-11): it holds the locked version
214
+ * package (environments-7): it holds the locked version
216
215
  * and each locked file at the digest the lock records for it. The
217
216
  * archive's checksum is not compared: each device packs its own archive
218
217
  * from its seed, so another device's lock of the same files may record
@@ -313,8 +312,8 @@ function builtinResolution(pkg, registryUrl) {
313
312
  };
314
313
  }
315
314
  /**
316
- * A new environment at its root (environments-11, storage-6): your own
317
- * group's clone, or a project's working folder at its pairing.
315
+ * A new environment at its root: the global
316
+ * records repository, or a project's working folder at its pairing.
318
317
  * `spex.yaml` requests the built-in spec package where it does not —
319
318
  * with `space` naming the environment's instance where one is given, the
320
319
  * caller giving the instance its spex repository is placed at wherever
@@ -352,7 +351,7 @@ export function prepareBuiltinEnvironment(root, pkg, registryUrl, space = null)
352
351
  }
353
352
  /**
354
353
  * Move an environment's built-in lock to `registryUrl` where it is
355
- * still the one a pairing prepared (environments-11, DR-127): `spex.yaml`
354
+ * still the one a pairing prepared (DR-127): `spex.yaml`
356
355
  * requesting the built-in spec package alone, and `spex.lock` exactly
357
356
  * the built-in lock at the registry it records — another than
358
357
  * `registryUrl`, or that one while `spex.yaml` does not name `space`.
@@ -422,8 +421,7 @@ export function rehomeBuiltinLock(root, pkg, registryUrl, space = null) {
422
421
  }
423
422
  /**
424
423
  * Request the built-in spec package at a caret requirement in an
425
- * environment's `spex.yaml` at its root where it is not requested
426
- * (environments-11, storage-6): written synchronously, so a clone's
424
+ * environment's `spex.yaml` at its root where it is not requested: written synchronously, so a clone's
427
425
  * first commit already holds it; comments and key order of an existing
428
426
  * file are kept, and the file is written under the version read, so a
429
427
  * file changed meanwhile is refused as a conflict (DR-111). Where `space` is given and the file
@@ -461,12 +459,12 @@ export function ensureBuiltinRequest(root, version, space = null) {
461
459
  return true;
462
460
  }
463
461
  /**
464
- * A new project's environment at its pairing (storage-6, DR-176): where
462
+ * A new project's environment at its pairing (DR-176): where
465
463
  * the working folder holds no `spex.yaml`, one naming the public
466
464
  * registry as every new file does (environments-38), `space` where the
467
- * project's spex repository is placed at an instance (DR-170), and
465
+ * project's spex repository is placed at an instance, and
468
466
  * requesting nothing — the built-in spec package is a global package,
469
- * never a project's request (environments-11). Created exclusively, so a
467
+ * never a project's request. Created exclusively, so a
470
468
  * file written meanwhile stands; a root that does not exist is left as
471
469
  * it is. Returns whether it wrote.
472
470
  */
@@ -1,10 +1,10 @@
1
1
  import { type Lock, type Resolution } from "./lock.js";
2
- /** The built-in spec package's name (environments-11). */
2
+ /** The built-in spec package's name. */
3
3
  export declare const BUILTIN_PACKAGE_NAME = "sublang/playbooks";
4
4
  /** The manifest an export leaves in each agent folder it writes. */
5
5
  export declare const EXPORTS_MANIFEST = ".spex-exports.json";
6
6
  /** A managed block of a working folder's `info/exclude`: the exports,
7
- * or the engine links a compile provisions (playbook-library-12). */
7
+ * or the engine links a compile provisions. */
8
8
  export type ExcludeBlock = "exports" | "engine links";
9
9
  export interface ExportOptions {
10
10
  /** The environment's root (environments-26): its `.spex/` holds the
@@ -15,9 +15,9 @@ export interface ExportOptions {
15
15
  * root's `.spex/` and the user's home. */
16
16
  workingFolder: string | null;
17
17
  /** The folder a path source's path is relative to (environments-2):
18
- * your own group's clone; the working folder where omitted. */
18
+ * the global records repository; the working folder where omitted. */
19
19
  pathRoot?: string | null;
20
- /** The user's home, for your own group's environment; else null. */
20
+ /** The user's home when exporting the global environment; otherwise null. */
21
21
  userHome: string | null;
22
22
  /** The agents this device has: only their user-level folders are
23
23
  * written, while every project-level folder is (environments-16). */
@@ -27,7 +27,7 @@ export interface ExportOptions {
27
27
  rename?: (from: string, to: string) => void;
28
28
  }
29
29
  /** Where a provided spec stands under a project's `specs/`
30
- * (environments-41, environments-14): placed at its path; edited there,
30
+ * (environments-41, environments-64): placed at its path; edited there,
31
31
  * the package's copy by its marker line or the record, so left as the
32
32
  * reader's — as is an edited copy its package no longer places, the
33
33
  * project's own now; blocked by a file of its basename under `specs/`
@@ -72,9 +72,10 @@ export interface ExportReport {
72
72
  /** Spec packages an exported artifact of which is not here: not
73
73
  * installed, or a path source missing where its path resolves. */
74
74
  missing: string[];
75
- /** Each provided spec of a project's root with where it stands, in
76
- * name order (environments-41); none where the root is no working
77
- * folder, as your own group's clone. */
75
+ /** Each provided spec of a project's root with where it stands
76
+ * (environments-41), by the whole `<org>/<pkg>` name as the lock
77
+ * lists its packages; none where the root is no working folder, as
78
+ * the global records repository. */
78
79
  specs: SpecPlacement[];
79
80
  }
80
81
  /** Where a spec package's files stand: its installed folder, or a path
@@ -136,7 +137,7 @@ export declare function placedSpecPath(id: string): string;
136
137
  /**
137
138
  * Where each provided spec of a lock stands under a project's root, read
138
139
  * from the files, their marker lines and the install record as a
139
- * placement finds them, writing nothing (environments-14,
140
+ * placement finds them, writing nothing (environments-64,
140
141
  * environments-41), so `spex list` and an install agree: waiting for
141
142
  * `specs/` where the root holds none; else placed, edited or blocked as
142
143
  * an install reports it. A spec whose package's files are not here as
@@ -161,7 +162,7 @@ export interface ModuleLocation {
161
162
  }
162
163
  /** The module candidates of a playbook artifact folder, preferred first. */
163
164
  export declare function playbookModuleCandidates(folder: string, id: string): string[];
164
- /** Each exported playbook's module location (environments-9): the
165
+ /** Each exported playbook's module location (environments-8): the
165
166
  * installed artifact under the root's `.spex/packages/`, or a path
166
167
  * source's where its path resolves, `pathRoot` being the folder its path
167
168
  * is relative to. Keyed by the exported name. */
@@ -183,8 +184,8 @@ export type LaunchModules = {
183
184
  repository: string;
184
185
  }[];
185
186
  };
186
- /** The modules a session hands the launcher (environments-9): each
187
- * enabled playbook from the project's environment, else your own
188
- * group's; one no environment exports is a config error naming the
187
+ /** The modules a session hands the launcher (environments-8): each
188
+ * enabled playbook from the project's environment, else the global
189
+ * environment; one no environment exports is a config error naming the
189
190
  * playbook and the spex repository whose environment lacks it. */
190
191
  export declare function launchModules(enabled: Iterable<string>, project: EnvironmentModules | null, own: EnvironmentModules): LaunchModules;
@@ -1,14 +1,12 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // Exports (environments-6, environments-8, environments-9,
4
- // environments-14, environments-16, environments-30, environments-41,
5
- // DR-104, DR-115, DR-124, DR-174). Only what a release provides is
3
+ // Exports (environments-6, environments-8, environments-64, environments-16, environments-30, environments-41, DR-104, DR-124, DR-174). Only what a release provides is
6
4
  // placed, a support artifact installed and placed nowhere: each provided
7
5
  // skill is copied — its `name` rewritten where aliased — and one skill
8
6
  // is generated per provided playbook, into `<root>/.spex/skills/<name>/`;
9
7
  // those are mirrored into the folder where each agent Spex drives reads
10
8
  // project-level skills in the working folder, kept out of Git there by
11
- // its `.git/info/exclude`, and, for your own group, into the user-level
9
+ // its `.git/info/exclude`, and, for the global environment, into the user-level
12
10
  // folders of the agents this device has. A playbook's skill goes only
13
11
  // where the table lets it. A manifest beside them records what Spex
14
12
  // wrote, so a re-export removes only its own and a skill the reader put
@@ -27,7 +25,7 @@
27
25
  // whose package no longer places it leaves unless edited; and a file of
28
26
  // its basename anywhere under `specs/` that is none of these blocks it.
29
27
  // A project not scaffolded yet, its root holding no `specs/`, places no
30
- // spec and reports it; your own group's clone, which is no project, has
28
+ // spec and reports it; the global records repository, which is no project, has
31
29
  // a generated skill hold the spec file instead.
32
30
  // Playbooks go to the launcher as module locations at launch, bound to
33
31
  // the environment whose lock exported them.
@@ -43,7 +41,7 @@ import { parseManifestText, providedArtifacts } from "./format.js";
43
41
  import { isPathSource, resolutionVersion } from "./lock.js";
44
42
  import { placedMarker, readPlacedMarker } from "./marker.js";
45
43
  import { placedRecordPath, readPlacedRecord, serializePlacedRecord, writePlacedRecord } from "./placed-record.js";
46
- /** The built-in spec package's name (environments-11). */
44
+ /** The built-in spec package's name. */
47
45
  export const BUILTIN_PACKAGE_NAME = "sublang/playbooks";
48
46
  /** The manifest an export leaves in each agent folder it writes. */
49
47
  export const EXPORTS_MANIFEST = ".spex-exports.json";
@@ -488,6 +486,16 @@ function specsByBasename(root) {
488
486
  walk(SPECS);
489
487
  return out;
490
488
  }
489
+ /** Two `<org>/<pkg>` names by `<org>`, then by `<pkg>`, each compared
490
+ * as a string: the order in which packages of one `<pkg>` claim its
491
+ * path (environments-41). */
492
+ function byOrgThenPkg(a, b) {
493
+ const [orgA, pkgA] = a.split("/");
494
+ const [orgB, pkgB] = b.split("/");
495
+ if (orgA !== orgB)
496
+ return orgA < orgB ? -1 : 1;
497
+ return pkgA < pkgB ? -1 : pkgA > pkgB ? 1 : 0;
498
+ }
491
499
  /** A record's waiting counts as a report lists them. */
492
500
  function waitingList(waiting) {
493
501
  return Object.keys(waiting).sort().map((name) => ({ name, count: waiting[name] }));
@@ -562,7 +570,7 @@ function deriveSpec(source, standing) {
562
570
  *
563
571
  * 1. each spec claims `specs/packages/<pkg>.md`: the package whose copy
564
572
  * stands there — by the record, or by the marker line, as on a fresh
565
- * clone — takes it, else the first in name order, and a later one is
573
+ * clone — takes it, else the first by `<org>`, and a later one is
566
574
  * blocked, as is one whose path a copy of a package whose files are
567
575
  * not here holds, by the record or the marker line alike;
568
576
  * 2. a recorded copy its package no longer places there — removed, no
@@ -590,7 +598,12 @@ function planSpecs(root, sources, unread, remove) {
590
598
  const record = {};
591
599
  const placements = [];
592
600
  const writes = [];
593
- const byName = (a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
601
+ // Name order for a claim is by `<org>`, then by `<pkg>` (environments-41),
602
+ // never by the whole name: `-` sorts before `/`, so `a-b/kit` would
603
+ // come before `a/kit`, though org `a` is before org `a-b`. The kept
604
+ // fault of the guard environments-55 patches the claim below as it
605
+ // is written.
606
+ const byName = (a, b) => byOrgThenPkg(a.name, b.name);
594
607
  const ordered = [...sources].sort(byName);
595
608
  const names = new Set(ordered.map((source) => source.name));
596
609
  // A copy `remove` took leaves nothing standing at its path.
@@ -701,7 +714,9 @@ function planSpecs(root, sources, unread, remove) {
701
714
  record[source.name] = { path, version: source.version, sha256: spec.sha256, waiting: spec.waiting };
702
715
  placements.push({ name: source.name, path, state: "placed", waiting: waitingList(spec.waiting) });
703
716
  }
704
- return { placements: placements.sort(byName), writes, record };
717
+ // The report lists names as the lock does, by the whole name.
718
+ placements.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
719
+ return { placements, writes, record };
705
720
  }
706
721
  /** Place the provided specs of a root holding `specs/` (environments-41)
707
722
  * as `planSpecs` decides: a copy that leaves removed while it holds the
@@ -774,7 +789,7 @@ function lockedSpecs(root, lock, pathRoot) {
774
789
  /**
775
790
  * Where each provided spec of a lock stands under a project's root, read
776
791
  * from the files, their marker lines and the install record as a
777
- * placement finds them, writing nothing (environments-14,
792
+ * placement finds them, writing nothing (environments-64,
778
793
  * environments-41), so `spex list` and an install agree: waiting for
779
794
  * `specs/` where the root holds none; else placed, edited or blocked as
780
795
  * an install reports it. A spec whose package's files are not here as
@@ -866,9 +881,9 @@ export async function exportEnvironment(options) {
866
881
  }
867
882
  // In a project's `specs/`, a file placed after the skills
868
883
  // (environments-41); in a project holding no `specs/`, nowhere,
869
- // reported waiting for it; else, your own group's, a generated
884
+ // reported waiting for it; for the global environment, a generated
870
885
  // skill, the spec file in its chosen language byte for byte
871
- // beside a SKILL.md saying what spec package it is (DR-115).
886
+ // beside a SKILL.md saying what spec package it is (DR-174).
872
887
  if (mode === "files") {
873
888
  specSources.push({ name, id, version, file });
874
889
  continue;
@@ -966,7 +981,7 @@ export function playbookModuleCandidates(folder, id) {
966
981
  join(folder, `${id}.registry.js`),
967
982
  ];
968
983
  }
969
- /** Each exported playbook's module location (environments-9): the
984
+ /** Each exported playbook's module location (environments-8): the
970
985
  * installed artifact under the root's `.spex/packages/`, or a path
971
986
  * source's where its path resolves, `pathRoot` being the folder its path
972
987
  * is relative to. Keyed by the exported name. */
@@ -1004,9 +1019,9 @@ export function moduleLocations(lock, root, pathRoot) {
1004
1019
  }
1005
1020
  return out;
1006
1021
  }
1007
- /** The modules a session hands the launcher (environments-9): each
1008
- * enabled playbook from the project's environment, else your own
1009
- * group's; one no environment exports is a config error naming the
1022
+ /** The modules a session hands the launcher (environments-8): each
1023
+ * enabled playbook from the project's environment, else the global
1024
+ * environment; one no environment exports is a config error naming the
1010
1025
  * playbook and the spex repository whose environment lacks it. */
1011
1026
  export function launchModules(enabled, project, own) {
1012
1027
  const modules = new Map();
@@ -126,8 +126,8 @@ export declare function readManifest(dir: string): Manifest;
126
126
  /** Read and check a release folder (environments-1). */
127
127
  export declare function readRelease(dir: string): Promise<Release>;
128
128
  /** Every field the registry requires to publish that the manifest
129
- * lacks, named as the registry names it (environments-10). */
129
+ * lacks, named as the registry names it (environments-59). */
130
130
  export declare function publishIssues(manifest: Manifest): Issue[];
131
- /** Read a release folder as publishing takes it (environments-10):
131
+ /** Read a release folder as publishing takes it (environments-59):
132
132
  * every release check, then the fields the registry requires. */
133
133
  export declare function readPublishableRelease(dir: string): Promise<Release>;
@@ -630,16 +630,16 @@ export async function readRelease(dir) {
630
630
  return { manifest, files: listed.files };
631
631
  }
632
632
  /** The manifest fields the registry requires of a release it takes,
633
- * which reading a release leaves optional (environments-10). */
633
+ * which reading a release leaves optional (environments-59). */
634
634
  const PUBLISH_FIELDS = ["description", "license"];
635
635
  /** Every field the registry requires to publish that the manifest
636
- * lacks, named as the registry names it (environments-10). */
636
+ * lacks, named as the registry names it (environments-59). */
637
637
  export function publishIssues(manifest) {
638
638
  return PUBLISH_FIELDS
639
639
  .filter((field) => manifest[field] === undefined)
640
640
  .map((field) => ({ path: "meta.yaml", rule: "field", message: `missing required field "${field}"` }));
641
641
  }
642
- /** Read a release folder as publishing takes it (environments-10):
642
+ /** Read a release folder as publishing takes it (environments-59):
643
643
  * every release check, then the fields the registry requires. */
644
644
  export async function readPublishableRelease(dir) {
645
645
  const release = await readRelease(dir);
@@ -13,6 +13,7 @@ import { spawn } from "node:child_process";
13
13
  import { randomUUID } from "node:crypto";
14
14
  import { existsSync, mkdirSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
15
15
  import { dirname, join } from "node:path";
16
+ import { discardTree, removeTree } from "../files.js";
16
17
  import { sha256Hex } from "./format.js";
17
18
  import { readTar } from "./tar.js";
18
19
  export class GitSourceError extends Error {
@@ -124,17 +125,19 @@ export function gitSource(cacheDir, options = {}) {
124
125
  if (!existsSync(join(mirror, "HEAD"))) {
125
126
  mkdirSync(mirrors, { recursive: true });
126
127
  const staging = `${mirror}.${randomUUID()}`;
128
+ // A staged mirror left over is garbage (environments-13).
127
129
  try {
128
130
  await git(repo, [...config, "clone", "--mirror", "--quiet", "--", repo, staging], env);
131
+ // A fetch that made the mirror meanwhile keeps its own.
129
132
  if (existsSync(join(mirror, "HEAD")))
130
- rmSync(staging, { recursive: true, force: true });
133
+ discardTree(staging, "a staged mirror");
131
134
  else {
132
- rmSync(mirror, { recursive: true, force: true });
135
+ removeTree(mirror);
133
136
  renameSync(staging, mirror);
134
137
  }
135
138
  }
136
139
  catch (error) {
137
- rmSync(staging, { recursive: true, force: true });
140
+ discardTree(staging, "a staged mirror");
138
141
  throw error;
139
142
  }
140
143
  }