@sublang/spex 4.2.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +438 -89
  2. package/dist/cli.js +80 -42
  3. package/dist/commands/add.d.ts +12 -0
  4. package/dist/commands/add.js +138 -0
  5. package/dist/commands/auth-target.d.ts +12 -0
  6. package/dist/commands/auth-target.js +52 -0
  7. package/dist/commands/environment.d.ts +117 -0
  8. package/dist/commands/environment.js +399 -0
  9. package/dist/commands/export.d.ts +21 -0
  10. package/dist/commands/export.js +663 -0
  11. package/dist/commands/home.d.ts +56 -0
  12. package/dist/commands/home.js +215 -0
  13. package/dist/commands/install.d.ts +2 -0
  14. package/dist/commands/install.js +48 -0
  15. package/dist/commands/list.d.ts +2 -0
  16. package/dist/commands/list.js +87 -0
  17. package/dist/commands/login.d.ts +2 -0
  18. package/dist/commands/login.js +211 -0
  19. package/dist/commands/logout.d.ts +2 -0
  20. package/dist/commands/logout.js +74 -0
  21. package/dist/commands/publish.d.ts +2 -0
  22. package/dist/commands/publish.js +120 -0
  23. package/dist/commands/remove.d.ts +2 -0
  24. package/dist/commands/remove.js +34 -0
  25. package/dist/commands/run.d.ts +50 -0
  26. package/dist/commands/run.js +312 -0
  27. package/dist/commands/search.d.ts +2 -0
  28. package/dist/commands/search.js +34 -0
  29. package/dist/commands/settle.d.ts +124 -0
  30. package/dist/commands/settle.js +475 -0
  31. package/dist/commands/update.d.ts +2 -0
  32. package/dist/commands/update.js +37 -0
  33. package/dist/commands/whoami.d.ts +2 -0
  34. package/dist/commands/whoami.js +71 -0
  35. package/dist/lib/environment/agent-folders.d.ts +14 -0
  36. package/dist/lib/environment/agent-folders.js +11 -0
  37. package/dist/lib/environment/archive.d.ts +39 -0
  38. package/dist/lib/environment/archive.js +122 -0
  39. package/dist/lib/environment/builtins.d.ts +112 -0
  40. package/dist/lib/environment/builtins.js +539 -0
  41. package/dist/lib/environment/citations.d.ts +75 -0
  42. package/dist/lib/environment/citations.js +267 -0
  43. package/dist/lib/environment/exports.d.ts +190 -0
  44. package/dist/lib/environment/exports.js +1029 -0
  45. package/dist/lib/environment/format.d.ts +133 -0
  46. package/dist/lib/environment/format.js +651 -0
  47. package/dist/lib/environment/git-source.d.ts +41 -0
  48. package/dist/lib/environment/git-source.js +159 -0
  49. package/dist/lib/environment/index.d.ts +20 -0
  50. package/dist/lib/environment/index.js +27 -0
  51. package/dist/lib/environment/install.d.ts +140 -0
  52. package/dist/lib/environment/install.js +694 -0
  53. package/dist/lib/environment/layout.d.ts +15 -0
  54. package/dist/lib/environment/layout.js +50 -0
  55. package/dist/lib/environment/lock.d.ts +87 -0
  56. package/dist/lib/environment/lock.js +305 -0
  57. package/dist/lib/environment/marker.d.ts +15 -0
  58. package/dist/lib/environment/marker.js +31 -0
  59. package/dist/lib/environment/own-paths.d.ts +59 -0
  60. package/dist/lib/environment/own-paths.js +174 -0
  61. package/dist/lib/environment/placed-record.d.ts +32 -0
  62. package/dist/lib/environment/placed-record.js +72 -0
  63. package/dist/lib/environment/registries.d.ts +23 -0
  64. package/dist/lib/environment/registries.js +48 -0
  65. package/dist/lib/environment/registry.d.ts +172 -0
  66. package/dist/lib/environment/registry.js +390 -0
  67. package/dist/lib/environment/requests.d.ts +109 -0
  68. package/dist/lib/environment/requests.js +401 -0
  69. package/dist/lib/environment/resolve.d.ts +70 -0
  70. package/dist/lib/environment/resolve.js +451 -0
  71. package/dist/lib/environment/semver.d.ts +30 -0
  72. package/dist/lib/environment/semver.js +130 -0
  73. package/dist/lib/environment/store.d.ts +23 -0
  74. package/dist/lib/environment/store.js +123 -0
  75. package/dist/lib/environment/tar.d.ts +27 -0
  76. package/dist/lib/environment/tar.js +219 -0
  77. package/dist/lib/files.d.ts +66 -0
  78. package/dist/lib/files.js +233 -0
  79. package/dist/lib/git-host.d.ts +579 -0
  80. package/dist/lib/git-host.js +1363 -0
  81. package/dist/lib/home-file.d.ts +124 -0
  82. package/dist/lib/home-file.js +288 -0
  83. package/dist/lib/instance.d.ts +63 -0
  84. package/dist/lib/instance.js +130 -0
  85. package/dist/lib/words.d.ts +32 -0
  86. package/dist/lib/words.js +27 -0
  87. package/dist/lint.js +8 -0
  88. package/dist/testing/index.d.ts +1 -0
  89. package/dist/testing/index.js +7 -0
  90. package/dist/testing/standin-registry.d.ts +94 -0
  91. package/dist/testing/standin-registry.js +449 -0
  92. package/package.json +37 -3
  93. package/dist/attached-cli.d.ts +0 -13
  94. package/dist/attached-cli.js +0 -249
  95. package/dist/attached-client.d.ts +0 -53
  96. package/dist/attached-client.js +0 -237
  97. package/dist/generated-protocol.d.ts +0 -2
  98. package/dist/generated-protocol.js +0 -6
  99. package/dist/package-init.d.ts +0 -21
  100. package/dist/package-init.js +0 -442
package/dist/lint.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { existsSync, readdirSync, readFileSync, realpathSync, statSync, } from "node:fs";
4
4
  import { join, posix, relative, sep } from "node:path";
5
5
  import { baseHeadingSlugs, codeLineMap, headingSlugs, headingText, parseMarkdown, plainHeadingText, visit, } from "./markdown.js";
6
+ import { parsePlacedMarker } from "./lib/environment/marker.js";
6
7
  import { resolveBase } from "./resolve-base.js";
7
8
  // Localized section names accepted alongside the English ones,
8
9
  // matching the section names the bundled zh meta.md defines for
@@ -840,6 +841,13 @@ function lintMap(ctx) {
840
841
  if (!isUnder(file.relPath, "packages") && !isUnder(file.relPath, "decisions")) {
841
842
  continue;
842
843
  }
844
+ // A spec an install placed opens with the marker it writes
845
+ // (environments-41, DR-174), which a fresh clone carries without
846
+ // the install record: the map need not list it.
847
+ if (isUnder(file.relPath, "packages") &&
848
+ parsePlacedMarker(file.lines[0] ?? "") !== null) {
849
+ continue;
850
+ }
843
851
  if (!listed.has(file.relPath)) {
844
852
  report(ctx, file.relPath, 1, "warning", "map/unlisted", `${file.relPath} is not linked from specs/map.md`);
845
853
  }
@@ -0,0 +1 @@
1
+ export * from "./standin-registry.js";
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ // What the library ships for tests (environments-18, DR-165): the
4
+ // stand-in registry and the release fixtures it serves, for the
5
+ // library's own tests, the core's and the browser journeys.
6
+ export * from "./standin-registry.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,94 @@
1
+ export type ReleaseFixture = string | Uint8Array | {
2
+ data: string | Uint8Array;
3
+ executable?: boolean;
4
+ } | {
5
+ symlink: string;
6
+ };
7
+ /** Write a release folder: `meta.yaml` from the manifest — a value
8
+ * written as YAML exactly as given, or raw text — and each file. */
9
+ export declare function makeRelease(dir: string, manifest: Record<string, unknown> | string, files: Record<string, ReleaseFixture>): Promise<string>;
10
+ /** The headers a stand-in instance relaying a request to the registry
11
+ * sets (environments-18), every inbound one of these names dropped
12
+ * first: the instance by its origin, and its verdict on the bearer — the
13
+ * account it accepts it as, or the code it refuses it with. */
14
+ export declare const RELAY_HEADERS: {
15
+ readonly instance: "x-standin-instance";
16
+ readonly account: "x-standin-account";
17
+ readonly refused: "x-standin-refused";
18
+ };
19
+ /** One request as the registry received it (environments-18). */
20
+ export interface StandinRegistryRequest {
21
+ method: string;
22
+ /** The path without its query. */
23
+ path: string;
24
+ /** The stand-in instance that relayed it, by its origin; null for a
25
+ * request made to the registry directly. */
26
+ instance: string | null;
27
+ /** The account the relaying instance accepted the bearer as; null
28
+ * where it accepted none, or for a direct request. */
29
+ account: string | null;
30
+ /** Whether it presented a bearer. */
31
+ bearer: boolean;
32
+ }
33
+ /**
34
+ * A reader of a private org, a holder of orgs and a scripted refusal
35
+ * name the bearers they cover: a literal token presented as the bearer,
36
+ * as a direct caller presents one, or a stand-in instance's origin,
37
+ * standing for every bearer that instance relays as one it accepts.
38
+ */
39
+ export interface StandinRegistryScript {
40
+ /** Yank a version: caret and tilde stop picking it. */
41
+ yank(name: string, version: string): void;
42
+ /** Suppress a version as the operator: nothing picks or serves it. */
43
+ suppress(name: string, version: string): void;
44
+ /** Make an org private: a request without a bearer finds nothing
45
+ * (404), one whose bearer no reader covers is forbidden (403). */
46
+ setPrivate(org: string, readers: Iterable<string>): void;
47
+ /** The orgs the person presenting a bearer `reader` covers may publish
48
+ * to, which `GET /api/v1/account/orgs` lists sorted by name; any other
49
+ * bearer, or none, is answered 401. */
50
+ setOrgs(reader: string, orgs: {
51
+ name: string;
52
+ path: string;
53
+ role: string;
54
+ }[]): void;
55
+ /** The account a bearer `reader` covers stands for, which
56
+ * `GET /api/v1/whoami` names; any other bearer, or none, is answered
57
+ * 401. */
58
+ setAccount(reader: string, account: {
59
+ id: string;
60
+ login: string;
61
+ }): void;
62
+ /** Answer every request presenting a bearer `reader` covers 401 with
63
+ * `code`, `token_revoked` unless given, as Spex Space answers a device
64
+ * signed out; null lifts every such refusal. */
65
+ refuseTokens(reader: string | null, code?: string): void;
66
+ /** Hold each orgs answer `ms` before sending it. */
67
+ delayOrgs(ms: number): void;
68
+ /** Answer the next `count` requests 500, as an outage. */
69
+ unavailable(count: number): void;
70
+ /** Hold the next download — a release archive or a raw file — until
71
+ * `release` is called: `reached` resolves with its path once the
72
+ * request arrives. */
73
+ holdDownload(): {
74
+ reached: Promise<string>;
75
+ release(): void;
76
+ };
77
+ /** Every request as `<METHOD> <path>`, in order. */
78
+ readonly requests: string[];
79
+ /** Every request with the instance that relayed it and the account it
80
+ * came as, in order. */
81
+ readonly received: StandinRegistryRequest[];
82
+ /** Forget `requests` and `received`. */
83
+ clearRequests(): void;
84
+ }
85
+ export interface StandinRegistry {
86
+ url: string;
87
+ script: StandinRegistryScript;
88
+ close(): Promise<void>;
89
+ }
90
+ /** Start the stand-in over the releases stored under `dir`. */
91
+ export declare function startStandinRegistry(options: {
92
+ dir: string;
93
+ displayName?: string;
94
+ }): Promise<StandinRegistry>;
@@ -0,0 +1,449 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ // A stand-in for Spex Space (environments-18): an in-process HTTP server
4
+ // serving the format 2 interface (Spex Space DR-016, DR-017) — version
5
+ // index, version resources, raw files, release archives and search —
6
+ // from a directory of releases, with a publish endpoint that validates
7
+ // as the core's publishing does — the release checks and the fields the
8
+ // registry requires (environments-10) — and stores the archive.
9
+ // Scripted yank, suppression, private namespaces honouring app tokens,
10
+ // the orgs each app token's person may publish to, held as scripted,
11
+ // and outages let the core's tests and the browser journeys drive every
12
+ // registry answer. It describes itself by a display name at
13
+ // `/api/v1/registry` (environments-39) and names the account a scripted
14
+ // bearer stands for at `/api/v1/whoami`. It answers at each stand-in
15
+ // instance set to relay to it (DR-127): the instance names itself and
16
+ // its verdict on the bearer in the relay headers, so one registry stands
17
+ // behind several instances, honouring each one's tokens, and a scripted
18
+ // refusal answers one instance's tokens alone. A scripted hold keeps one download waiting
19
+ // until released, so a test can interrupt an install mid-download.
20
+ import { existsSync, mkdirSync, readdirSync, readFileSync, symlinkSync, writeFileSync, chmodSync } from "node:fs";
21
+ import { createServer } from "node:http";
22
+ import { dirname, join } from "node:path";
23
+ import { stringify } from "yaml";
24
+ import { unpackRelease } from "../lib/environment/archive.js";
25
+ import { artifactLanguages, publishIssues, sha256Hex } from "../lib/environment/format.js";
26
+ import { compareVersions, isVersion } from "../lib/environment/semver.js";
27
+ /** Write a release folder: `meta.yaml` from the manifest — a value
28
+ * written as YAML exactly as given, or raw text — and each file. */
29
+ export async function makeRelease(dir, manifest, files) {
30
+ mkdirSync(dir, { recursive: true });
31
+ writeFileSync(join(dir, "meta.yaml"), typeof manifest === "string" ? manifest : stringify(manifest, { lineWidth: 0 }));
32
+ for (const [path, fixture] of Object.entries(files)) {
33
+ const target = join(dir, ...path.split("/"));
34
+ mkdirSync(dirname(target), { recursive: true });
35
+ if (typeof fixture === "object" && "symlink" in fixture) {
36
+ symlinkSync(fixture.symlink, target);
37
+ continue;
38
+ }
39
+ const data = typeof fixture === "string" || fixture instanceof Uint8Array ? fixture : fixture.data;
40
+ writeFileSync(target, data);
41
+ const executable = typeof fixture === "object" && !(fixture instanceof Uint8Array) && "data" in fixture && fixture.executable === true;
42
+ chmodSync(target, executable ? 0o755 : 0o644);
43
+ }
44
+ return dir;
45
+ }
46
+ /** The headers a stand-in instance relaying a request to the registry
47
+ * sets (environments-18), every inbound one of these names dropped
48
+ * first: the instance by its origin, and its verdict on the bearer — the
49
+ * account it accepts it as, or the code it refuses it with. */
50
+ export const RELAY_HEADERS = {
51
+ instance: "x-standin-instance",
52
+ account: "x-standin-account",
53
+ refused: "x-standin-refused",
54
+ };
55
+ function sendJson(res, status, body) {
56
+ const text = JSON.stringify(body);
57
+ res.writeHead(status, { "content-type": "application/json", "cache-control": "no-store" });
58
+ res.end(text);
59
+ }
60
+ function sendError(res, status, code, message, details) {
61
+ sendJson(res, status, { error: { code, message, ...(details ? { details } : {}) } });
62
+ }
63
+ /** The words Spex Space answers a refused bearer with, by its code. */
64
+ const REFUSED_WORDS = {
65
+ invalid_token: "The token is not known.",
66
+ token_revoked: "This device was signed out.",
67
+ token_expired: "The access token expired.",
68
+ reauth_required: "Sign in again.",
69
+ };
70
+ function headerOf(req, name) {
71
+ const value = req.headers[name];
72
+ return typeof value === "string" && value.length > 0 ? value : null;
73
+ }
74
+ /** An origin as a reader names it, without a trailing slash. */
75
+ const readerKey = (reader) => reader.replace(/\/+$/, "");
76
+ async function readBody(req) {
77
+ const chunks = [];
78
+ for await (const chunk of req)
79
+ chunks.push(chunk);
80
+ return new Uint8Array(Buffer.concat(chunks));
81
+ }
82
+ /** Start the stand-in over the releases stored under `dir`. */
83
+ export async function startStandinRegistry(options) {
84
+ const { dir } = options;
85
+ const displayName = options.displayName ?? "Stand-in Registry";
86
+ mkdirSync(dir, { recursive: true });
87
+ const releases = new Map();
88
+ const privateOrgs = new Map();
89
+ const accountOrgs = new Map();
90
+ const accounts = new Map();
91
+ let origin = "";
92
+ const refusedReaders = new Map();
93
+ let orgsDelay = 0;
94
+ const requests = [];
95
+ const received = [];
96
+ let outages = 0;
97
+ let hold = null;
98
+ /** Wait while a scripted hold keeps this download. */
99
+ async function held(path) {
100
+ const current = hold;
101
+ if (current === null)
102
+ return;
103
+ hold = null;
104
+ current.reach(path);
105
+ await current.released;
106
+ }
107
+ /** Keep a release; a publish also holds it to the fields the
108
+ * registry requires, which a release already served may lack. */
109
+ function store(org, pkg, version, tgz, publishedAt, publishing = false) {
110
+ const unpacked = unpackRelease(tgz, pkg);
111
+ const issues = [...unpacked.issues];
112
+ const manifest = unpacked.manifest;
113
+ if (manifest && (manifest.org !== org || manifest.name !== pkg || manifest.version !== version)) {
114
+ issues.push({ path: "meta.yaml", rule: "identity", message: `the manifest names ${manifest.org}/${manifest.name} ${manifest.version}, not ${org}/${pkg} ${version}` });
115
+ }
116
+ if (manifest && publishing)
117
+ issues.push(...publishIssues(manifest));
118
+ if (!manifest || issues.length > 0)
119
+ return issues;
120
+ const name = `${org}/${pkg}`;
121
+ const versions = releases.get(name) ?? new Map();
122
+ const createdAt = [...versions.values()][0]?.createdAt ?? publishedAt;
123
+ versions.set(version, {
124
+ org, pkg, version, manifest, files: unpacked.files, data: unpacked.data, tgz,
125
+ checksum: sha256Hex(tgz), publishedAt, createdAt, yanked: false, suppressed: false,
126
+ });
127
+ releases.set(name, versions);
128
+ return [];
129
+ }
130
+ // Releases already in the directory are served from the start.
131
+ for (const org of existsSync(dir) ? readdirSync(dir) : []) {
132
+ const orgDir = join(dir, org);
133
+ for (const pkg of readdirSync(orgDir)) {
134
+ for (const version of readdirSync(join(orgDir, pkg))) {
135
+ const file = join(orgDir, pkg, version, "release.tgz");
136
+ if (existsSync(file))
137
+ store(org, pkg, version, new Uint8Array(readFileSync(file)), new Date().toISOString());
138
+ }
139
+ }
140
+ }
141
+ function callerOf(req) {
142
+ const header = req.headers.authorization;
143
+ const bearer = header?.startsWith("Bearer ") && header.length > 7 ? header.slice(7) : null;
144
+ const instance = headerOf(req, RELAY_HEADERS.instance);
145
+ return {
146
+ bearer,
147
+ instance: instance === null ? null : readerKey(instance),
148
+ account: instance === null || bearer === null ? null : headerOf(req, RELAY_HEADERS.account),
149
+ refused: instance === null || bearer === null ? null : headerOf(req, RELAY_HEADERS.refused),
150
+ };
151
+ }
152
+ /** The readers a caller's bearer is covered by: the token itself, and
153
+ * the relaying instance where it accepted the bearer. */
154
+ function readersOf(caller) {
155
+ if (caller.bearer === null)
156
+ return [];
157
+ return caller.account !== null && caller.instance !== null ? [caller.bearer, caller.instance] : [caller.bearer];
158
+ }
159
+ /** The 401 a bearer earns before any route: the relaying instance's
160
+ * refusal of it, or a refusal scripted for a reader covering it. */
161
+ function refusal(caller) {
162
+ if (caller.bearer === null)
163
+ return null;
164
+ if (caller.refused !== null)
165
+ return caller.refused;
166
+ for (const reader of readersOf(caller)) {
167
+ const code = refusedReaders.get(reader);
168
+ if (code !== undefined)
169
+ return code;
170
+ }
171
+ return null;
172
+ }
173
+ function access(org, caller, res) {
174
+ const readers = privateOrgs.get(org);
175
+ if (!readers)
176
+ return true;
177
+ if (caller.bearer === null) {
178
+ sendError(res, 404, "not_found", "not found");
179
+ return false;
180
+ }
181
+ if (!readersOf(caller).some((reader) => readers.has(reader))) {
182
+ sendError(res, 403, "forbidden", "this token may not read the namespace");
183
+ return false;
184
+ }
185
+ return true;
186
+ }
187
+ function artifactsIndex(stored) {
188
+ const languages = artifactLanguages(stored.manifest, stored.files);
189
+ const out = {};
190
+ for (const [id, artifact] of Object.entries(stored.manifest.artifacts)) {
191
+ out[id] = { kind: artifact.kind, ...(artifact.language ? { language: artifact.language } : {}), languages: languages[id] ?? [] };
192
+ }
193
+ return out;
194
+ }
195
+ function artifactsFull(stored) {
196
+ const index = artifactsIndex(stored);
197
+ const out = {};
198
+ for (const [id, artifact] of Object.entries(stored.manifest.artifacts)) {
199
+ out[id] = {
200
+ ...index[id],
201
+ ...(artifact.from ? { from: artifact.from } : {}),
202
+ requires: artifact.requires,
203
+ ...(artifact.generatedBy ? { "generated-by": artifact.generatedBy } : {}),
204
+ };
205
+ }
206
+ return out;
207
+ }
208
+ const active = (stored) => !stored.yanked && !stored.suppressed;
209
+ function packageResource(name, versions) {
210
+ const all = [...versions.values()].sort((a, b) => compareVersions(a.version, b.version));
211
+ const stable = all.filter((stored) => active(stored) && !stored.version.includes("-"));
212
+ const latest = (stable.length > 0 ? stable : all.filter(active)).at(-1);
213
+ const [org, pkg] = name.split("/");
214
+ return {
215
+ org, name: pkg,
216
+ created_at: all[0]?.createdAt,
217
+ latest: latest?.version ?? null,
218
+ ...(latest ? {
219
+ ...(latest.manifest.description ? { description: latest.manifest.description } : {}),
220
+ ...(latest.manifest.license ? { license: latest.manifest.license } : {}),
221
+ ...(latest.manifest.repository ? { repository: latest.manifest.repository } : {}),
222
+ languages: [...new Set(Object.values(artifactLanguages(latest.manifest, latest.files)).flat())].sort(),
223
+ } : {}),
224
+ versions: all.map((stored) => ({
225
+ version: stored.version,
226
+ format: 2,
227
+ published_at: stored.publishedAt,
228
+ checksum: stored.checksum,
229
+ yanked: stored.yanked,
230
+ suppressed: stored.suppressed,
231
+ dependencies: stored.manifest.dependencies,
232
+ artifacts: artifactsIndex(stored),
233
+ })),
234
+ };
235
+ }
236
+ function versionResource(stored) {
237
+ const { manifest } = stored;
238
+ return {
239
+ org: stored.org,
240
+ name: stored.pkg,
241
+ version: stored.version,
242
+ format: 2,
243
+ ...(manifest.description ? { description: manifest.description } : {}),
244
+ ...(manifest.license ? { license: manifest.license } : {}),
245
+ ...(manifest.repository ? { repository: manifest.repository } : {}),
246
+ languages: [...new Set(Object.values(artifactLanguages(manifest, stored.files)).flat())].sort(),
247
+ artifacts: artifactsFull(stored),
248
+ dependencies: manifest.dependencies,
249
+ checksum: stored.checksum,
250
+ size: stored.tgz.length,
251
+ published_at: stored.publishedAt,
252
+ yanked: stored.yanked,
253
+ suppressed: stored.suppressed,
254
+ ...(stored.suppressed ? {} : {
255
+ files: stored.files.map((file) => ({ path: file.path, size: file.size, sha256: file.sha256, executable: file.executable })),
256
+ dist: { tarball: `/api/v1/packages/${stored.org}/${stored.pkg}/${stored.version}/download`, sha256: stored.checksum },
257
+ }),
258
+ };
259
+ }
260
+ async function handle(req, res) {
261
+ const url = new URL(req.url ?? "/", "http://standin");
262
+ const method = req.method ?? "GET";
263
+ const caller = callerOf(req);
264
+ requests.push(`${method} ${url.pathname}`);
265
+ received.push({ method, path: url.pathname, instance: caller.instance, account: caller.account, bearer: caller.bearer !== null });
266
+ if (outages > 0) {
267
+ outages -= 1;
268
+ sendError(res, 500, "internal_error", "the stand-in registry is scripted to be unavailable");
269
+ return;
270
+ }
271
+ // A refused bearer is answered 401 on every route, whatever it names
272
+ // and whether it exists, as Spex Space answers it.
273
+ const refused = refusal(caller);
274
+ if (refused !== null) {
275
+ sendError(res, 401, refused, REFUSED_WORDS[refused] ?? "The token was refused.");
276
+ return;
277
+ }
278
+ const segments = url.pathname.split("/").filter(Boolean).map((segment) => decodeURIComponent(segment));
279
+ // The public descriptor, read with no credential (environments-39).
280
+ if (method === "GET" && url.pathname === "/api/v1/registry") {
281
+ sendJson(res, 200, { origin, display_name: displayName, providers: [] });
282
+ return;
283
+ }
284
+ if (method === "GET" && url.pathname === "/api/v1/whoami") {
285
+ const account = readersOf(caller).map((reader) => accounts.get(reader)).find((found) => found !== undefined);
286
+ if (!account) {
287
+ sendError(res, 401, "unauthenticated", "sign in to see your account");
288
+ return;
289
+ }
290
+ sendJson(res, 200, { id: account.id, login: account.login, display_name: null, can_create_group: false });
291
+ return;
292
+ }
293
+ if (method === "GET" && url.pathname === "/api/v1/account/orgs") {
294
+ if (orgsDelay > 0)
295
+ await new Promise((resolve) => setTimeout(resolve, orgsDelay));
296
+ const orgs = readersOf(caller).map((reader) => accountOrgs.get(reader)).find((found) => found !== undefined);
297
+ if (!orgs) {
298
+ sendError(res, 401, "unauthenticated", "sign in to list your orgs");
299
+ return;
300
+ }
301
+ sendJson(res, 200, { orgs: [...orgs].sort((a, b) => a.name.localeCompare(b.name)) });
302
+ return;
303
+ }
304
+ if (method === "GET" && url.pathname === "/api/v1/search") {
305
+ const q = (url.searchParams.get("q") ?? "").toLowerCase();
306
+ const results = [...releases.entries()]
307
+ .filter(([name]) => !privateOrgs.has(name.split("/")[0]))
308
+ .map(([name, versions]) => ({ name, latest: [...versions.values()].sort((a, b) => compareVersions(a.version, b.version)).at(-1) }))
309
+ .filter(({ name, latest }) => q === "" || name.includes(q) || (latest.manifest.description ?? "").toLowerCase().includes(q))
310
+ .map(({ name, latest }) => ({ org: name.split("/")[0], name: name.split("/")[1], description: latest.manifest.description ?? "" }));
311
+ sendJson(res, 200, { results });
312
+ return;
313
+ }
314
+ if (segments[0] === "api" && segments[1] === "v1" && segments[2] === "packages" && segments.length >= 5) {
315
+ const [org, pkg, version, tail] = [segments[3], segments[4], segments[5], segments[6]];
316
+ const name = `${org}/${pkg}`;
317
+ if (method === "PUT" && version && segments.length === 6) {
318
+ if (!access(org, caller, res))
319
+ return;
320
+ if (!isVersion(version)) {
321
+ sendError(res, 400, "bad_request", `${version} is not a version`);
322
+ return;
323
+ }
324
+ const body = await readBody(req);
325
+ if (releases.get(name)?.has(version)) {
326
+ sendError(res, 409, "version_exists", `${name} ${version} is already published`);
327
+ return;
328
+ }
329
+ const issues = store(org, pkg, version, body, new Date().toISOString(), true);
330
+ if (issues.length > 0) {
331
+ sendError(res, 422, "invalid_artifact", `${name} ${version} is not a valid release`, issues);
332
+ return;
333
+ }
334
+ const target = join(dir, org, pkg, version);
335
+ mkdirSync(target, { recursive: true });
336
+ writeFileSync(join(target, "release.tgz"), body);
337
+ sendJson(res, 201, { org, name: pkg, version, checksum: sha256Hex(body) });
338
+ return;
339
+ }
340
+ if (method !== "GET") {
341
+ sendError(res, 400, "bad_request", "unsupported method");
342
+ return;
343
+ }
344
+ if (!access(org, caller, res))
345
+ return;
346
+ const versions = releases.get(name);
347
+ if (!versions) {
348
+ sendError(res, 404, "not_found", `${name} is not published`);
349
+ return;
350
+ }
351
+ if (!version) {
352
+ sendJson(res, 200, packageResource(name, versions));
353
+ return;
354
+ }
355
+ const stored = versions.get(version);
356
+ if (!stored) {
357
+ sendError(res, 404, "not_found", `${name} ${version} is not published`);
358
+ return;
359
+ }
360
+ if (tail === undefined && segments.length === 6) {
361
+ sendJson(res, 200, versionResource(stored));
362
+ return;
363
+ }
364
+ if (tail === "download" && segments.length === 7) {
365
+ if (stored.suppressed) {
366
+ sendError(res, 410, "suppressed", `${name} ${version} is suppressed`);
367
+ return;
368
+ }
369
+ await held(url.pathname);
370
+ res.writeHead(200, { "content-type": "application/gzip" });
371
+ res.end(Buffer.from(stored.tgz));
372
+ return;
373
+ }
374
+ sendError(res, 404, "not_found", "not found");
375
+ return;
376
+ }
377
+ if (method === "GET" && segments.length >= 4 && segments[0] !== "api") {
378
+ const [org, pkg, version] = [segments[0], segments[1], segments[2]];
379
+ if (!access(org, caller, res))
380
+ return;
381
+ const stored = releases.get(`${org}/${pkg}`)?.get(version);
382
+ if (stored?.suppressed) {
383
+ sendError(res, 410, "suppressed", `${org}/${pkg} ${version} is suppressed`);
384
+ return;
385
+ }
386
+ const bytes = stored?.data.get(segments.slice(3).join("/"));
387
+ if (!bytes) {
388
+ sendError(res, 404, "not_found", "not found");
389
+ return;
390
+ }
391
+ await held(url.pathname);
392
+ res.writeHead(200, { "content-type": "application/octet-stream" });
393
+ res.end(Buffer.from(bytes));
394
+ return;
395
+ }
396
+ sendError(res, 404, "not_found", "not found");
397
+ }
398
+ const server = createServer((req, res) => {
399
+ handle(req, res).catch((error) => {
400
+ if (!res.headersSent)
401
+ sendError(res, 500, "internal_error", error.message);
402
+ else
403
+ res.end();
404
+ });
405
+ });
406
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
407
+ const { port } = server.address();
408
+ origin = `http://127.0.0.1:${port}`;
409
+ function find(name, version) {
410
+ const stored = releases.get(name)?.get(version);
411
+ if (!stored)
412
+ throw new Error(`the stand-in holds no ${name} ${version}`);
413
+ return stored;
414
+ }
415
+ return {
416
+ url: origin,
417
+ script: {
418
+ yank: (name, version) => { find(name, version).yanked = true; },
419
+ suppress: (name, version) => { find(name, version).suppressed = true; },
420
+ setPrivate: (org, readers) => { privateOrgs.set(org, new Set([...readers].map(readerKey))); },
421
+ setOrgs: (reader, orgs) => { accountOrgs.set(readerKey(reader), orgs.map((org) => ({ ...org }))); },
422
+ setAccount: (reader, account) => { accounts.set(readerKey(reader), { ...account }); },
423
+ refuseTokens: (reader, code = "token_revoked") => {
424
+ if (reader === null)
425
+ refusedReaders.clear();
426
+ else
427
+ refusedReaders.set(readerKey(reader), code);
428
+ },
429
+ delayOrgs: (ms) => { orgsDelay = ms; },
430
+ unavailable: (count) => { outages = count; },
431
+ holdDownload: () => {
432
+ let reach;
433
+ let release;
434
+ const reached = new Promise((resolve) => { reach = resolve; });
435
+ const released = new Promise((resolve) => { release = resolve; });
436
+ hold = { reach, released };
437
+ return { reached, release };
438
+ },
439
+ requests,
440
+ received,
441
+ clearRequests: () => { requests.length = 0; received.length = 0; },
442
+ },
443
+ close: () => new Promise((resolve) => {
444
+ server.closeAllConnections();
445
+ server.close(() => resolve());
446
+ }),
447
+ };
448
+ }
449
+ //# sourceMappingURL=standin-registry.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sublang/spex",
3
- "version": "4.2.0",
3
+ "version": "6.0.0",
4
4
  "description": "The essential spec layer AI agents need to build software reliably",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -21,6 +21,38 @@
21
21
  "bin": {
22
22
  "spex": "dist/cli.js"
23
23
  },
24
+ "exports": {
25
+ "./environment": {
26
+ "types": "./dist/lib/environment/index.d.ts",
27
+ "default": "./dist/lib/environment/index.js"
28
+ },
29
+ "./files": {
30
+ "types": "./dist/lib/files.d.ts",
31
+ "default": "./dist/lib/files.js"
32
+ },
33
+ "./instance": {
34
+ "types": "./dist/lib/instance.d.ts",
35
+ "default": "./dist/lib/instance.js"
36
+ },
37
+ "./git-host": {
38
+ "types": "./dist/lib/git-host.d.ts",
39
+ "default": "./dist/lib/git-host.js"
40
+ },
41
+ "./home-file": {
42
+ "types": "./dist/lib/home-file.d.ts",
43
+ "default": "./dist/lib/home-file.js"
44
+ },
45
+ "./words": {
46
+ "types": "./dist/lib/words.d.ts",
47
+ "default": "./dist/lib/words.js"
48
+ },
49
+ "./testing": {
50
+ "types": "./dist/testing/index.d.ts",
51
+ "default": "./dist/testing/index.js"
52
+ },
53
+ "./scaffold/*": "./scaffold/*",
54
+ "./package.json": "./package.json"
55
+ },
24
56
  "files": [
25
57
  "dist/**/*.js",
26
58
  "!dist/**/*.test.js",
@@ -29,7 +61,7 @@
29
61
  "scaffold/"
30
62
  ],
31
63
  "scripts": {
32
- "build": "node scripts/stage-protocol.mjs && node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc && node scripts/stage-scaffold.mjs",
64
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc && node scripts/stage-scaffold.mjs",
33
65
  "prepublishOnly": "npm run build && npm test",
34
66
  "test": "node scripts/stage-scaffold.mjs && node scripts/run-tests.cjs",
35
67
  "test:integration": "node scripts/stage-scaffold.mjs && node scripts/run-tests.cjs \"\\.integration\\.test\\.js$\""
@@ -46,6 +78,8 @@
46
78
  "github-slugger": "^2.0.0",
47
79
  "remark-gfm": "^4.0.1",
48
80
  "remark-parse": "^11.0.0",
49
- "unified": "^11.0.5"
81
+ "unified": "^11.0.5",
82
+ "yaml": "^2.8.0",
83
+ "@openclaw/fs-safe": "0.26.13"
50
84
  }
51
85
  }
@@ -1,13 +0,0 @@
1
- type Flags = Record<string, string | boolean>;
2
- type Invocation = {
3
- group: string;
4
- action: string;
5
- positional: string[];
6
- flags: Flags;
7
- timeoutMs: number;
8
- };
9
- export declare const ATTACHED_USAGE = "Attached commands (need the running Spex app, or a server named below):\n auth login --instance <origin> Sign in through the browser/device instructions\n auth status Show instance sign-in standing\n project list List registered projects\n project add <folder> Register a project working folder\n package search <query> Search the selected project's registry\n package status Show its requests and installed packages\n package add <org/name> --version <requirement>\n package add <org/name> --path <relative-folder>\n package remove <org/name>\n package install Install the locked selections\n package resolve Resolve requests and install\n package publish <relative-folder> [--dry-run]\n\nConnection: the running Spex app (desktop or server shell) is found through\n local/endpoint.json in SPEX_HOME or ~/.spex; --server <access-url> or\n SPEX_SERVER_URL names another server instead (literal loopback only).\nObservation: --timeout <positive seconds> (default 600); no reconnect or replay.\nPackages: --project <registered-folder>, otherwise the exact current directory.\nPublishing is explicit; --dry-run checks without uploading.";
10
- /** Parse the whole invocation before opening a connection or sending a command. */
11
- export declare function parseAttached(args: string[]): Invocation;
12
- export declare function runAttached(args: string[], env?: NodeJS.ProcessEnv): Promise<number>;
13
- export {};