@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
@@ -5,7 +5,7 @@ import { type OwnPathIssue } from "./own-paths.js";
5
5
  import { type RegistrySource } from "./registry.js";
6
6
  import { type ContentStore } from "./store.js";
7
7
  /** Where a working folder's Git is told to ignore every playbook
8
- * artifact folder's engine links (playbook-library-12): a release-layout
8
+ * artifact folder's engine links: a release-layout
9
9
  * `playbooks/<language>/<id>/` folder anywhere in it. */
10
10
  export declare const ENGINE_LINKS_EXCLUDE = "**/playbooks/*/*/node_modules/";
11
11
  /** A host's engine (DR-165): how an installed playbook artifact's folder
@@ -35,7 +35,7 @@ export interface InstallOptions {
35
35
  * (environments-7): the first serving its release at the locked
36
36
  * version and checksum serves them. `[registry]` where omitted. */
37
37
  registries?: (source: RegistrySourceLock) => readonly RegistrySource[];
38
- /** This device's seed of the built-in spec package (environments-11),
38
+ /** This device's seed of the built-in spec package,
39
39
  * asked first for its locked release: it serves where it holds the
40
40
  * locked version with each locked file at the lock's digest, whatever
41
41
  * archive checksum the lock records (environments-7). */
@@ -48,11 +48,11 @@ export interface InstallOptions {
48
48
  git: GitSource;
49
49
  gitCredential?: (repo: string) => Promise<GitCredential | undefined>;
50
50
  /** The folder a path source's path is relative to (environments-2):
51
- * the paired working folder's root, or your own group's clone's; null
51
+ * the paired working folder's root, or the global records repository's; null
52
52
  * where this device has none. */
53
53
  pathRoot: string | null;
54
- /** Whether `pathRoot` is your own group's clone, whose path sources
55
- * hold only what its sync carries (environments-32). */
54
+ /** Whether `pathRoot` is the global records repository, whose path sources
55
+ * hold only what its sync carries. */
56
56
  confined?: boolean;
57
57
  /** `spex.yaml`'s text; read from the root when omitted. */
58
58
  requestsText?: string | null;
@@ -72,7 +72,7 @@ export interface InstallReport {
72
72
  /** True when the installed files already matched the lock. */
73
73
  unchanged: boolean;
74
74
  /** Registry modules left carrying the engine they were bundled with,
75
- * each with why (playbook-library-46). */
75
+ * each with why. */
76
76
  engineKept: {
77
77
  module: string;
78
78
  reason: string;
@@ -85,15 +85,15 @@ export interface InstallReport {
85
85
  export declare class InstallError extends Error {
86
86
  readonly packageName: string | undefined;
87
87
  readonly cause?: unknown;
88
- /** The folder your own group's clone refuses, with its reason, for a
89
- * host to phrase (environments-32). */
88
+ /** The folder the global records repository refuses, with its reason, for a
89
+ * host to phrase. */
90
90
  readonly confined?: {
91
91
  path: string;
92
92
  issue: OwnPathIssue;
93
93
  } | undefined;
94
94
  constructor(packageName: string | undefined, message: string, cause?: unknown,
95
- /** The folder your own group's clone refuses, with its reason, for a
96
- * host to phrase (environments-32). */
95
+ /** The folder the global records repository refuses, with its reason, for a
96
+ * host to phrase. */
97
97
  confined?: {
98
98
  path: string;
99
99
  issue: OwnPathIssue;
@@ -106,7 +106,7 @@ export declare const INSTALL_RECORD = ".spex-install.json";
106
106
  export declare function missingPathSources(lock: Lock, pathRoot: string | null): string[];
107
107
  /** The registry and Git packages the install record holds as the lock
108
108
  * locks them, whether or not every file still stands: one recorded here
109
- * that `installedPackages` lacks has files missing (environments-14). */
109
+ * that `installedPackages` lacks has files missing (environments-64). */
110
110
  export declare function recordedPackages(root: string, lock: Lock): Set<string>;
111
111
  /** The registry and Git sources of a lock whose files stand installed
112
112
  * under the root's `.spex/` as the lock locks them: recorded by the
@@ -115,26 +115,24 @@ export declare function recordedPackages(root: string, lock: Lock): Set<string>;
115
115
  export declare function installedPackages(root: string, lock: Lock): Set<string>;
116
116
  /** Install a lock's selected files (environments-7). */
117
117
  export declare function install(options: InstallOptions): Promise<InstallReport>;
118
- /** Remove every installed file of an environment (one emptied). */
119
- export declare function removeInstalled(root: string): void;
120
118
  export interface PrepareOptions {
121
119
  root: string;
122
120
  lock: Lock;
123
121
  /** The folder a path source's path is relative to (environments-2). */
124
122
  pathRoot: string | null;
125
- /** Whether `pathRoot` is your own group's clone (environments-32). */
123
+ /** Whether `pathRoot` is the global records repository. */
126
124
  confined?: boolean;
127
125
  engine: InstallEngine;
128
126
  }
129
127
  /**
130
128
  * Prepare an environment's playbook artifact folders to run on the
131
129
  * host's engine at a use that hands the launcher module locations
132
- * (environments-7, environments-9, playbook-library-46): each installed
130
+ * (environments-7, environments-8): each installed
133
131
  * as the lock locks it, and each path source's where its path resolves,
134
132
  * so a playbook another host installed — the command line prepares
135
133
  * none — runs. Nothing here fails the use: a folder that cannot be
136
134
  * prepared is logged and left; a path source's links are made only once
137
- * its Git lists them, your own group's clone otherwise taking none.
135
+ * its Git lists them, the global records repository otherwise taking none.
138
136
  * Returns the registry modules kept carrying their own engine.
139
137
  */
140
138
  export declare function prepareEnvironment(options: PrepareOptions): Promise<InstallReport["engineKept"]>;
@@ -1,15 +1,15 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // Installing a locked environment (environments-7, DR-104, DR-165): the
4
- // lock's selected files, verified by digest into the store, are linked
3
+ // Installing a locked environment (environments-7, DR-104, DR-165,
4
+ // DR-251): the lock's selected files, verified by digest into the store,
5
+ // are copied out of it, checked again, as ordinary writable files
5
6
  // under `<root>/.spex/packages/<org>/<pkg>/` at their release paths, the
6
7
  // environment's root holding `.spex/` with a `.gitignore` of `*`, so Git
7
8
  // ignores the installed tree (environments-26). A registry
8
9
  // package is fetched from the first of the registries asked that serves
9
10
  // its release at the locked version and checksum (DR-127); the built-in
10
11
  // spec package is served first from this device's seed where its files
11
- // carry the lock's digests, whatever archive checksum the lock records
12
- // (environments-11). Where no seed and no registry serves the built-in,
12
+ // carry the lock's digests, whatever archive checksum the lock records. Where no seed and no registry serves the built-in,
13
13
  // a host shipping no seed, as the command line, may leave it out as not
14
14
  // installed, absent from the tree and its record, for the app's next use
15
15
  // to install from its seed, while the rest installs; any other spec
@@ -19,23 +19,22 @@
19
19
  // stands on disk at the version read and still matches `spex.yaml` and
20
20
  // its path sources: an install overtaken meanwhile publishes nothing
21
21
  // (DR-111). A path source copies nothing and is reported missing where
22
- // the folder its path resolves to lacks it; your own group's path source
22
+ // the folder its path resolves to lacks it; the global environment's path source
23
23
  // must hold only what its clone's sync carries, checked before anything
24
- // is installed or linked (environments-32); a stale lock installs
24
+ // is installed or linked; a stale lock installs
25
25
  // nothing new.
26
26
  // No code runs: what an install adds to the release files is the host's
27
27
  // engine preparation where the host supplies an engine — the app's core
28
28
  // gives each playbook artifact folder its engine links, a path source's
29
29
  // in the working folder too, and bundles again a registry module bundled
30
- // carrying its own engine, so every playbook runs on the app's engine
31
- // (playbook-library-46). With no engine, as from the command line,
30
+ // carrying its own engine, so every playbook runs on the app's engine. With no engine, as from the command line,
32
31
  // nothing is prepared and nothing is linked (DR-165).
33
32
  import { randomUUID } from "node:crypto";
34
- import { chmodSync, copyFileSync, cpSync, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
33
+ import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
35
34
  import { mkdir, readFile, writeFile } from "node:fs/promises";
36
35
  import { dirname, join, relative } from "node:path";
37
36
  import { seedServes } from "./builtins.js";
38
- import { fileVersion, VersionConflictError } from "../files.js";
37
+ import { fileVersion, removeTree, VersionConflictError } from "../files.js";
39
38
  import { instanceFolder, parseOrigin } from "../instance.js";
40
39
  import { BUILTIN_PACKAGE_NAME, writeExcludeBlock } from "./exports.js";
41
40
  import { listReleaseFiles, parseManifestText, portablePathIssues, sha256Hex } from "./format.js";
@@ -47,7 +46,7 @@ import { DigestError } from "./store.js";
47
46
  import { gunzip, readTar } from "./tar.js";
48
47
  import { ensureSpexDir, installedDir } from "./layout.js";
49
48
  /** Where a working folder's Git is told to ignore every playbook
50
- * artifact folder's engine links (playbook-library-12): a release-layout
49
+ * artifact folder's engine links: a release-layout
51
50
  * `playbooks/<language>/<id>/` folder anywhere in it. */
52
51
  export const ENGINE_LINKS_EXCLUDE = "**/playbooks/*/*/node_modules/";
53
52
  export class InstallError extends Error {
@@ -55,8 +54,8 @@ export class InstallError extends Error {
55
54
  cause;
56
55
  confined;
57
56
  constructor(packageName, message, cause,
58
- /** The folder your own group's clone refuses, with its reason, for a
59
- * host to phrase (environments-32). */
57
+ /** The folder the global records repository refuses, with its reason, for a
58
+ * host to phrase. */
60
59
  confined) {
61
60
  super(message);
62
61
  this.packageName = packageName;
@@ -112,6 +111,11 @@ function recordEntry(resolution) {
112
111
  function lockWithout(lock, names) {
113
112
  return { ...lock, packages: Object.fromEntries(Object.entries(lock.packages).filter(([name]) => !names.includes(name))) };
114
113
  }
114
+ /** The install record's format (environments-7, DR-251): `2` says the
115
+ * tree's files are copies. A tree under the former `1`, hard links into
116
+ * the store, matches no lock an install installs, so the next install
117
+ * replaces it whole; it reads installed meanwhile. */
118
+ const INSTALL_RECORD_FORMAT = 2;
115
119
  function installRecord(lock) {
116
120
  const packages = {};
117
121
  for (const name of Object.keys(lock.packages).sort()) {
@@ -120,7 +124,7 @@ function installRecord(lock) {
120
124
  continue;
121
125
  packages[name] = recordEntry(resolution);
122
126
  }
123
- return { format: 1, packages };
127
+ return { format: INSTALL_RECORD_FORMAT, packages };
124
128
  }
125
129
  function readInstallRecord(target) {
126
130
  try {
@@ -142,7 +146,7 @@ function treeMatches(target, lock, record) {
142
146
  }
143
147
  /** The registry and Git packages the install record holds as the lock
144
148
  * locks them, whether or not every file still stands: one recorded here
145
- * that `installedPackages` lacks has files missing (environments-14). */
149
+ * that `installedPackages` lacks has files missing (environments-64). */
146
150
  export function recordedPackages(root, lock) {
147
151
  const record = readInstallRecord(installedDir(root));
148
152
  const out = new Set();
@@ -261,7 +265,7 @@ async function cachedArchive(cache, registry, name, source) {
261
265
  }
262
266
  function putVerified(store, name, file, bytes) {
263
267
  try {
264
- store.put(bytes, file.sha256, file.executable, `${name} ${file.path}`);
268
+ store.put(bytes, file.sha256, `${name} ${file.path}`);
265
269
  }
266
270
  catch (error) {
267
271
  if (error instanceof DigestError)
@@ -274,17 +278,9 @@ function putVerified(store, name, file, bytes) {
274
278
  * no registry serving it (environments-7). */
275
279
  async function fetchMissing(options, name, resolution) {
276
280
  const { store } = options;
277
- const missing = [];
278
- for (const file of resolution.files) {
279
- if (store.has(file.sha256, file.executable))
280
- continue;
281
- // The same bytes in the other mode need no fetch.
282
- if (store.has(file.sha256, !file.executable)) {
283
- putVerified(store, name, file, readFileSync(store.pathOf(file.sha256, !file.executable)));
284
- continue;
285
- }
286
- missing.push(file);
287
- }
281
+ // A former copy apart serves where the store lacks the file, in
282
+ // either mode, so a former tree is replaced with nothing fetched.
283
+ const missing = resolution.files.filter((file) => !store.adoptFormer(file.sha256));
288
284
  if (missing.length === 0)
289
285
  return true;
290
286
  const source = resolution.source;
@@ -299,7 +295,7 @@ async function fetchMissing(options, name, resolution) {
299
295
  // The first registry's refusal, for a host to phrase by its kind.
300
296
  let refusal;
301
297
  for (const registry of options.registries ? options.registries(source) : [options.registry]) {
302
- const left = missing.filter((file) => !store.has(file.sha256, file.executable));
298
+ const left = missing.filter((file) => !store.has(file.sha256));
303
299
  if (left.length === 0)
304
300
  return true;
305
301
  try {
@@ -347,7 +343,7 @@ async function fetchSeeded(seed, store, name, source, resolution) {
347
343
  if (!(await seedServes(seed, source.version, resolution.files)))
348
344
  return false;
349
345
  for (const file of resolution.files) {
350
- if (store.has(file.sha256, file.executable))
346
+ if (store.has(file.sha256))
351
347
  continue;
352
348
  let bytes;
353
349
  try {
@@ -405,15 +401,6 @@ async function fetchFrom(options, registry, name, source, resolution, missing) {
405
401
  putVerified(store, name, file, await registry.file(name, source.version, file.path));
406
402
  return true;
407
403
  }
408
- function linkOrCopy(from, to, executable) {
409
- try {
410
- linkSync(from, to);
411
- }
412
- catch {
413
- copyFileSync(from, to);
414
- chmodSync(to, executable ? 0o555 : 0o444);
415
- }
416
- }
417
404
  /** The playbook artifact folders of a spec package's selected
418
405
  * artifacts under `root`, with their ids. */
419
406
  function playbookFolders(root, resolution) {
@@ -428,7 +415,7 @@ function playbookFolders(root, resolution) {
428
415
  return out;
429
416
  }
430
417
  /** Prepare every playbook artifact folder under `target` to run on the
431
- * app's engine (playbook-library-46), collecting the modules kept as
418
+ * app's engine, collecting the modules kept as
432
419
  * they are; each is named at `named`'s spelling of its folder. A tree
433
420
  * standing installed already is `tolerant`: a folder it cannot prepare
434
421
  * is logged and left, since the install itself places nothing. */
@@ -470,9 +457,8 @@ function pathSourcePlaybooks(lock, pathRoot) {
470
457
  return folders;
471
458
  }
472
459
  /** The engine links of a path source's playbook folders are ignored by
473
- * the Git of the working folder or of your own group's clone holding
474
- * them before any is made, so a sync never carries one
475
- * (playbook-library-46, DR-125): your own group's clone failing to list
460
+ * the Git of the working folder or of the global records repository holding
461
+ * them before any is made, so a sync never carries one: the global records repository failing to list
476
462
  * them fails the install, which makes none; a working folder's failure
477
463
  * is logged and its folders are linked anyway, its Git being the
478
464
  * reader's alone. */
@@ -501,8 +487,8 @@ function linkPathSources(folders, engine) {
501
487
  }
502
488
  }
503
489
  }
504
- /** Refuse your own group's path source holding what its clone's sync
505
- * drops or refuses (environments-32), before anything is installed or
490
+ /** Refuse the global environment's path source holding what its clone's sync
491
+ * drops or refuses, before anything is installed or
506
492
  * linked: a folder this device lacks is reported missing instead. */
507
493
  async function assertConfined(lock, pathRoot) {
508
494
  for (const name of Object.keys(lock.packages).sort()) {
@@ -588,7 +574,14 @@ export async function install(options) {
588
574
  for (const file of resolution.files) {
589
575
  const to = join(root, ...file.path.split("/"));
590
576
  mkdirSync(dirname(to), { recursive: true });
591
- linkOrCopy(store.pathOf(file.sha256, file.executable), to, file.executable);
577
+ try {
578
+ store.copy(file.sha256, file.executable, to, `${name} ${file.path}`);
579
+ }
580
+ catch (error) {
581
+ if (error instanceof DigestError)
582
+ throw new InstallError(name, `${name}: the stored copy of ${file.path} no longer matched spex.lock and was removed; nothing was installed — install again to fetch it`, error);
583
+ throw error;
584
+ }
592
585
  }
593
586
  }
594
587
  engineKept = await prepareInstalled(staging, placed, lock, engine, (folder) => join(target, relative(staging, folder)));
@@ -600,7 +593,13 @@ export async function install(options) {
600
593
  replaceTree(staging, target, join(options.cache, "trash", id));
601
594
  }
602
595
  catch (error) {
603
- rmSync(staging, { recursive: true, force: true });
596
+ // The failure's own cause is reported, never a cleanup's.
597
+ try {
598
+ removeTree(staging);
599
+ }
600
+ catch (cleanup) {
601
+ console.error(`spex: the staged tree ${staging} could not be removed: ${String(cleanup)}`);
602
+ }
604
603
  if (error instanceof InstallError || error instanceof VersionConflictError)
605
604
  throw error;
606
605
  throw new InstallError(undefined, `installing failed; the last files stay: ${error.message}`, error);
@@ -609,7 +608,6 @@ export async function install(options) {
609
608
  }
610
609
  /** Swap a complete staged tree in for the installed one. */
611
610
  function replaceTree(staging, target, trash) {
612
- let source = staging;
613
611
  const hadOld = existsSync(target);
614
612
  if (hadOld) {
615
613
  mkdirSync(dirname(trash), { recursive: true });
@@ -627,16 +625,27 @@ function replaceTree(staging, target, trash) {
627
625
  }
628
626
  try {
629
627
  try {
630
- renameSync(source, target);
628
+ renameSync(staging, target);
631
629
  }
632
630
  catch (error) {
633
631
  if (error.code !== "EXDEV")
634
632
  throw error;
635
633
  const near = `${target}.new-${randomUUID()}`;
636
- cpSync(source, near, { recursive: true, verbatimSymlinks: true });
637
- rmSync(source, { recursive: true, force: true });
638
- source = near;
639
- renameSync(source, target);
634
+ try {
635
+ cpSync(staging, near, { recursive: true, verbatimSymlinks: true });
636
+ removeTree(staging);
637
+ renameSync(near, target);
638
+ }
639
+ catch (failure) {
640
+ // The copy beside the tree is a staged tree too: none stays.
641
+ try {
642
+ removeTree(near);
643
+ }
644
+ catch (cleanup) {
645
+ console.error(`spex: the staged tree ${near} could not be removed: ${String(cleanup)}`);
646
+ }
647
+ throw failure;
648
+ }
640
649
  }
641
650
  }
642
651
  catch (error) {
@@ -649,26 +658,22 @@ function replaceTree(staging, target, trash) {
649
658
  // which would skip exports and falsely claim the old files still stand.
650
659
  if (hadOld) {
651
660
  try {
652
- rmSync(trash, { recursive: true, force: true });
661
+ removeTree(trash);
653
662
  }
654
663
  catch (error) {
655
664
  console.error(`spex: installed files stand; obsolete tree ${trash} could not be removed: ${String(error)}`);
656
665
  }
657
666
  }
658
667
  }
659
- /** Remove every installed file of an environment (one emptied). */
660
- export function removeInstalled(root) {
661
- rmSync(installedDir(root), { recursive: true, force: true });
662
- }
663
668
  /**
664
669
  * Prepare an environment's playbook artifact folders to run on the
665
670
  * host's engine at a use that hands the launcher module locations
666
- * (environments-7, environments-9, playbook-library-46): each installed
671
+ * (environments-7, environments-8): each installed
667
672
  * as the lock locks it, and each path source's where its path resolves,
668
673
  * so a playbook another host installed — the command line prepares
669
674
  * none — runs. Nothing here fails the use: a folder that cannot be
670
675
  * prepared is logged and left; a path source's links are made only once
671
- * its Git lists them, your own group's clone otherwise taking none.
676
+ * its Git lists them, the global records repository otherwise taking none.
672
677
  * Returns the registry modules kept carrying their own engine.
673
678
  */
674
679
  export async function prepareEnvironment(options) {
@@ -678,8 +683,8 @@ export async function prepareEnvironment(options) {
678
683
  const kept = await prepareInstalled(installedDir(root), names, lock, engine, (folder) => folder, true);
679
684
  const playbooks = pathSourcePlaybooks(lock, pathRoot);
680
685
  try {
681
- // Your own group's path sources are confined as an install confines
682
- // them (environments-32): one refused takes no link, nothing linked
686
+ // The global environment's path sources are confined as an install confines
687
+ // them: one refused takes no link, nothing linked
683
688
  // outside what the clone syncs.
684
689
  if (options.confined === true && pathRoot !== null)
685
690
  await assertConfined(lock, pathRoot);
@@ -63,9 +63,10 @@ export declare function parseLockValue(raw: unknown): Lock;
63
63
  export declare function parseLock(text: string): Lock;
64
64
  /** Read `spex.lock`; null where there is none. */
65
65
  export declare function readLock(file: string): Promise<Lock | null>;
66
- /** Write `spex.lock` atomically, no folder made; returns the bytes
67
- * written. Given the version the writer read, the write is refused as a
68
- * conflict where the lock changed meanwhile (DR-111). */
66
+ /** Write `spex.lock` atomically as an ordinary file of its folder
67
+ * (environments-49), no folder made; returns the bytes written. Given
68
+ * the version the writer read, the write is refused as a conflict where
69
+ * the lock changed meanwhile (DR-111). */
69
70
  export declare function writeLock(file: string, lock: Lock, expected?: FileVersion): Promise<string>;
70
71
  /** The `requires` a path source's manifest states, as the lock keeps it. */
71
72
  export declare function manifestRequires(manifest: Manifest): Record<string, string[]>;
@@ -10,7 +10,7 @@
10
10
  import { existsSync } from "node:fs";
11
11
  import { readFile } from "node:fs/promises";
12
12
  import { Document, isMap, isSeq, parseDocument } from "yaml";
13
- import { writeApplicationBytes, writeVersionedBytes } from "../files.js";
13
+ import { writeVersionedBytes, writeWorkingBytes } from "../files.js";
14
14
  import { isPackageName, sha256Hex } from "./format.js";
15
15
  import { requestsDigest } from "./requests.js";
16
16
  export class LockError extends Error {
@@ -233,13 +233,14 @@ export async function readLock(file) {
233
233
  return null;
234
234
  return parseLock(await readFile(file, "utf8"));
235
235
  }
236
- /** Write `spex.lock` atomically, no folder made; returns the bytes
237
- * written. Given the version the writer read, the write is refused as a
238
- * conflict where the lock changed meanwhile (DR-111). */
236
+ /** Write `spex.lock` atomically as an ordinary file of its folder
237
+ * (environments-49), no folder made; returns the bytes written. Given
238
+ * the version the writer read, the write is refused as a conflict where
239
+ * the lock changed meanwhile (DR-111). */
239
240
  export async function writeLock(file, lock, expected) {
240
241
  const text = serializeLock(lock);
241
242
  if (expected === undefined)
242
- writeApplicationBytes(file, text);
243
+ writeWorkingBytes(file, text);
243
244
  else
244
245
  writeVersionedBytes(file, text, expected);
245
246
  return text;
@@ -1,7 +1,6 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // The marker a placed spec opens with (environments-41, lint-9,
4
- // spec-view-10, DR-174): one comment line naming the spec package and
3
+ // The marker a placed spec opens with (environments-41, lint-9, DR-174): one comment line naming the spec package and
5
4
  // the version the install derived the file from, so a reader, the
6
5
  // linter and the spec view know a placed spec from the project's own
7
6
  // without the install record, which a fresh clone lacks.
@@ -1,4 +1,4 @@
1
- /** Why a folder of your own group's clone cannot be a path source; an
1
+ /** Why a folder of the global records repository cannot be a path source; an
2
2
  * `entry` or a `file` is its path in the clone. */
3
3
  export type OwnPathIssue = {
4
4
  reason: "root";
@@ -35,25 +35,22 @@ export type OwnPathIssue = {
35
35
  * yet ignores nothing. */
36
36
  export declare function ignoredInClone(clone: string, paths: readonly string[]): string[];
37
37
  /**
38
- * The first reason `path` cannot name a path source of your own group's
39
- * clone by what its path shows (environments-32): below the root,
38
+ * The first reason `path` cannot name a path source in the global
39
+ * records repository by what its path shows: below the root,
40
40
  * outside Spex's own paths, not ignored, reached through no link and in
41
41
  * no Git repository of its own. Null where none: a folder not made yet
42
42
  * is checked by these alone.
43
43
  */
44
44
  export declare function ownPathIssue(clone: string, path: string): OwnPathIssue | null;
45
45
  /**
46
- * The first reason the folder at `path`, standing in your own group's
47
- * clone, holds what its sync drops or refuses (environments-32): a file
46
+ * The first reason the folder at `path`, in the global records
47
+ * repository, holds what its sync drops or refuses: a file
48
48
  * of its release, `files` relative to the folder, the clone's Git rules
49
- * ignore or of an ignored family a Save refuses to share (space-15); or,
49
+ * ignore or of an ignored family a Save refuses to share; or,
50
50
  * at any depth and where those rules do not ignore it, a Git repository
51
51
  * of its own, a link, or an entry that is no regular file or folder.
52
52
  * Null where none, or where the folder does not stand.
53
53
  */
54
54
  export declare function ownFolderIssue(clone: string, path: string, files: readonly string[]): OwnPathIssue | null;
55
- /** A path your own group's clone refuses, in the library's words
56
- * (environments-32), after the spec package's name: your own group is
57
- * Personal and its clone your Personal records on every surface
58
- * (DR-172); a host phrases the reason with what to do from the issue. */
55
+ /** A path source refusal for the global records repository in CLI wording. The app phrases the guidance from the issue. */
59
56
  export declare function ownPathMessage(name: string, path: string, issue: OwnPathIssue): string;
@@ -1,18 +1,18 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // Your own group's requests by path (environments-32, DR-125): the path
3
+ // Global environment requests by path: the path
4
4
  // is relative to its clone's root, and names a folder below it that lies
5
5
  // outside Spex's own paths, is reached through no link, lies in no Git
6
6
  // repository of its own, and holds nothing the clone's sync drops or
7
7
  // refuses — so the folder syncs with the clone to every device, and a
8
- // sync takes it whole (storage-11).
8
+ // sync takes it whole.
9
9
  import { spawnSync } from "node:child_process";
10
10
  import { existsSync, lstatSync, readdirSync } from "node:fs";
11
11
  import { join, posix } from "node:path";
12
12
  import { portable } from "../files.js";
13
13
  import { isInsidePath } from "./requests.js";
14
- /** The first segments of the paths Spex keeps in a clone (storage-1):
15
- * its records, its settings, its placement files (DR-128), its
14
+ /** The first segments of the paths Spex keeps in a clone:
15
+ * its records, its settings, its placement files, its
16
16
  * installed and exported files under `.spex/` (DR-165) and the former
17
17
  * `packages/` and `skills/`, its device-local files and its root
18
18
  * files. */
@@ -60,8 +60,8 @@ export function ignoredInClone(clone, paths) {
60
60
  return run.stdout.split("\0").filter(Boolean);
61
61
  }
62
62
  /**
63
- * The first reason `path` cannot name a path source of your own group's
64
- * clone by what its path shows (environments-32): below the root,
63
+ * The first reason `path` cannot name a path source in the global
64
+ * records repository by what its path shows: below the root,
65
65
  * outside Spex's own paths, not ignored, reached through no link and in
66
66
  * no Git repository of its own. Null where none: a folder not made yet
67
67
  * is checked by these alone.
@@ -100,10 +100,10 @@ export function ownPathIssue(clone, path) {
100
100
  return null;
101
101
  }
102
102
  /**
103
- * The first reason the folder at `path`, standing in your own group's
104
- * clone, holds what its sync drops or refuses (environments-32): a file
103
+ * The first reason the folder at `path`, in the global records
104
+ * repository, holds what its sync drops or refuses: a file
105
105
  * of its release, `files` relative to the folder, the clone's Git rules
106
- * ignore or of an ignored family a Save refuses to share (space-15); or,
106
+ * ignore or of an ignored family a Save refuses to share; or,
107
107
  * at any depth and where those rules do not ignore it, a Git repository
108
108
  * of its own, a link, or an entry that is no regular file or folder.
109
109
  * Null where none, or where the folder does not stand.
@@ -153,10 +153,7 @@ export function ownFolderIssue(clone, path, files) {
153
153
  const kept = new Set(ignoredInClone(clone, found.map((item) => item.probe)));
154
154
  return found.find((item) => !kept.has(item.probe))?.issue ?? null;
155
155
  }
156
- /** A path your own group's clone refuses, in the library's words
157
- * (environments-32), after the spec package's name: your own group is
158
- * Personal and its clone your Personal records on every surface
159
- * (DR-172); a host phrases the reason with what to do from the issue. */
156
+ /** A path source refusal for the global records repository in CLI wording. The app phrases the guidance from the issue. */
160
157
  export function ownPathMessage(name, path, issue) {
161
158
  switch (issue.reason) {
162
159
  case "root": return `${name}: ${path} is not a folder inside your Personal records`;
@@ -27,6 +27,7 @@ export declare function readPlacedRecord(root: string): PlacedRecord | null;
27
27
  * specs in name order. */
28
28
  export declare function serializePlacedRecord(record: PlacedRecord): string;
29
29
  /** Write the root's record of placed specs whole, through a temporary
30
- * file renamed into place, so a reader never finds it half-written.
31
- * `<root>/.spex/` must stand. */
30
+ * file renamed into place, so a reader never finds it half-written, as
31
+ * an ordinary file of its folder (environments-49). `<root>/.spex/` must
32
+ * stand. */
32
33
  export declare function writePlacedRecord(root: string, record: PlacedRecord): void;
@@ -9,7 +9,7 @@
9
9
  // own. An install writes it whole, atomically, as compact JSON.
10
10
  import { readFileSync } from "node:fs";
11
11
  import { join } from "node:path";
12
- import { writeApplicationBytes } from "../files.js";
12
+ import { writeWorkingBytes } from "../files.js";
13
13
  import { SPEX_DIR } from "./layout.js";
14
14
  /** The placed specs' record, beside the installed packages under
15
15
  * `<root>/.spex/` (environments-26). */
@@ -64,9 +64,10 @@ export function serializePlacedRecord(record) {
64
64
  return JSON.stringify({ format: 1, specs: Object.fromEntries(specs) });
65
65
  }
66
66
  /** Write the root's record of placed specs whole, through a temporary
67
- * file renamed into place, so a reader never finds it half-written.
68
- * `<root>/.spex/` must stand. */
67
+ * file renamed into place, so a reader never finds it half-written, as
68
+ * an ordinary file of its folder (environments-49). `<root>/.spex/` must
69
+ * stand. */
69
70
  export function writePlacedRecord(root, record) {
70
- writeApplicationBytes(placedRecordPath(root), serializePlacedRecord(record));
71
+ writeWorkingBytes(placedRecordPath(root), serializePlacedRecord(record));
71
72
  }
72
73
  //# sourceMappingURL=placed-record.js.map
@@ -134,7 +134,7 @@ export interface RegistryClientOptions {
134
134
  /** Told the token a call presented when the registry refused it with
135
135
  * one of `SIGN_OUT_CODES`, before that call fails (environments-12):
136
136
  * awaited; where it throws — the token no longer the registry's stored
137
- * one (git-host-4) — the call fails with what it threw in place of the
137
+ * one — the call fails with what it threw in place of the
138
138
  * registry's words, still `unauthenticated`. */
139
139
  refused?: (token: string, code: string) => void | Promise<void>;
140
140
  fetch?: typeof fetch;
@@ -247,7 +247,7 @@ export class RegistryClient {
247
247
  if (response.status === 410)
248
248
  throw new RegistryError("not_found", name, `${about}withdrawn at ${host}`, code ?? "suppressed", undefined, answered);
249
249
  if (response.status === 401) {
250
- // A refusal answers the token this call presented (git-host-4); a
250
+ // A refusal answers the token this call presented; a
251
251
  // hook that throws says why the call fails instead.
252
252
  if (token && code !== undefined && SIGN_OUT_CODES.includes(code) && this.refused) {
253
253
  try {
@@ -47,7 +47,7 @@ export declare function packageNameRefusal(name: string): string;
47
47
  /** Whether a request path stays inside the working folder. */
48
48
  export declare function isInsidePath(path: string): boolean;
49
49
  /** Every reason a request for a name is refused (environments-2,
50
- * environments-15): a bad name, no or several sources, a malformed
50
+ * environments-65): a bad name, no or several sources, a malformed
51
51
  * requirement, a path that is not relative or leads out of the folder
52
52
  * it is relative to, a bad select or alias. */
53
53
  export declare function requestIssues(name: string, request: unknown): Issue[];
@@ -100,7 +100,7 @@ export declare function editRequests(file: string, edit: (doc: Document) => void
100
100
  text: string;
101
101
  digest: string;
102
102
  }>;
103
- /** Set one package's request, or remove it with null (environments-15). */
103
+ /** Set one package's request, or remove it with null (environments-65). */
104
104
  export declare function setRequest(file: string, name: string, request: Request | null): Promise<{
105
105
  requests: Requests;
106
106
  text: string;