@sublang/spex 4.2.0 → 5.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 +433 -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 +11 -0
  6. package/dist/commands/auth-target.js +50 -0
  7. package/dist/commands/environment.d.ts +123 -0
  8. package/dist/commands/environment.js +411 -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 +309 -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 +75 -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 +26 -0
  38. package/dist/lib/environment/archive.js +91 -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 +25 -0
  64. package/dist/lib/environment/registries.js +75 -0
  65. package/dist/lib/environment/registry.d.ts +173 -0
  66. package/dist/lib/environment/registry.js +390 -0
  67. package/dist/lib/environment/requests.d.ts +108 -0
  68. package/dist/lib/environment/requests.js +403 -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
@@ -0,0 +1,75 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ // `spex whoami [--registry <url> | --space <url>]` (cli-12, DR-168,
4
+ // DR-172): this computer's sign-ins in one grammar, a line each — this
5
+ // folder's registry, then every Space the home lists — or, with a flag,
6
+ // the line of the registry or Space named alone: its kind, its name as
7
+ // cli-22 names it, and `@<login>` or `signed out`, the home's default
8
+ // Space marked `(default)`. A registry's login is read from its account
9
+ // API; a Space's from its home entry, asking no Space. No secret is
10
+ // printed.
11
+ import { authTarget } from "./auth-target.js";
12
+ import { HostError } from "../lib/git-host.js";
13
+ import { instanceAt } from "../lib/home-file.js";
14
+ import { clientOf, credentialsOf, defaultInstance, homeDir, hostCause, nameOf, namedInstance, readHome, registryName, signedIn } from "./home.js";
15
+ import { options, Refusal } from "./run.js";
16
+ /** The registry's line: its name and the login its account API names,
17
+ * or signed out; a registry that cannot say leaves its cause. */
18
+ async function registryLine(dir, origin) {
19
+ const name = await registryName(dir, origin);
20
+ const client = clientOf(origin, credentialsOf(dir, origin, "registry"), undefined, "registry");
21
+ let held;
22
+ try {
23
+ held = await client.signedIn();
24
+ }
25
+ catch (error) {
26
+ return { row: ["Registry", name, "sign-in unreadable"], cause: `your sign-in at ${name} cannot be read: ${error.message} — spex logout, then spex login` };
27
+ }
28
+ if (!held)
29
+ return { row: ["Registry", name, "signed out"] };
30
+ try {
31
+ return { row: ["Registry", name, `@${(await client.me()).login}`] };
32
+ }
33
+ catch (error) {
34
+ // A sign-in the registry refused is gone: signed out.
35
+ if (error instanceof HostError && error.kind === "reauth")
36
+ return { row: ["Registry", name, "signed out"] };
37
+ if (!(await client.signedIn().catch(() => true)))
38
+ return { row: ["Registry", name, "signed out"] };
39
+ return { row: ["Registry", name, "signed in"], cause: hostCause(error, name) };
40
+ }
41
+ }
42
+ /** A Space's line, read from its home entry alone. */
43
+ function spaceLine(home, entry, defaultOrigin) {
44
+ const listedEntry = home ? instanceAt(home, entry.origin) : undefined;
45
+ const who = signedIn(listedEntry) ? `@${listedEntry.account.login}` : "signed out";
46
+ return ["Space", nameOf(listedEntry ?? entry), entry.origin === defaultOrigin ? `${who} (default)` : who];
47
+ }
48
+ export const whoami = async (args) => {
49
+ const values = options("whoami", args, { space: { type: "string" }, registry: { type: "string" } });
50
+ const dir = homeDir();
51
+ const home = readHome(dir);
52
+ const defaultOrigin = defaultInstance(home).origin;
53
+ const rows = [];
54
+ let cause;
55
+ if (values.space !== undefined) {
56
+ if (values.registry !== undefined)
57
+ authTarget(home, values);
58
+ rows.push(spaceLine(home, namedInstance(home, values.space), defaultOrigin));
59
+ }
60
+ else {
61
+ const { target } = authTarget(home, values);
62
+ const line = await registryLine(dir, target.origin);
63
+ rows.push(line.row);
64
+ cause = line.cause;
65
+ if (values.registry === undefined)
66
+ for (const entry of home?.instances ?? [])
67
+ rows.push(spaceLine(home, entry, defaultOrigin));
68
+ }
69
+ // Columns aligned, two spaces apart.
70
+ const widths = rows.reduce((out, row) => row.map((cell, at) => Math.max(out[at] ?? 0, cell.length)), []);
71
+ console.log(rows.map((row) => row.map((cell, at) => (at === row.length - 1 ? cell : cell.padEnd(widths[at]))).join(" ")).join("\n"));
72
+ if (cause !== undefined)
73
+ throw new Refusal(cause);
74
+ };
75
+ //# sourceMappingURL=whoami.js.map
@@ -0,0 +1,14 @@
1
+ export interface AgentFolders {
2
+ /** Relative to the user's home, each written with a leading `~/`:
3
+ * any one standing shows this device has the agent. */
4
+ homes: readonly string[];
5
+ /** Relative to a working folder. */
6
+ project: string;
7
+ /** Relative to the user's home, written with a leading `~/`. */
8
+ user: string;
9
+ /** Whether the skill generated for a playbook goes here. It is for a
10
+ * person's own agent, so it stays from runtimes that invoke a skill
11
+ * unasked or read it in a Captain's decisions. */
12
+ playbooks: boolean;
13
+ }
14
+ export declare const AGENT_FOLDERS: Readonly<Record<string, Readonly<AgentFolders>>>;
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ const TABLE = {
4
+ claude: { homes: ["~/.claude"], project: ".claude/skills", user: "~/.claude/skills", playbooks: true },
5
+ codex: { homes: ["~/.codex"], project: ".agents/skills", user: "~/.agents/skills", playbooks: false },
6
+ gemini: { homes: ["~/.gemini"], project: ".agents/skills", user: "~/.agents/skills", playbooks: false },
7
+ kimi: { homes: ["~/.kimi-code"], project: ".agents/skills", user: "~/.agents/skills", playbooks: false },
8
+ opencode: { homes: ["~/.config/opencode", "~/.local/share/opencode"], project: ".agents/skills", user: "~/.agents/skills", playbooks: false },
9
+ };
10
+ export const AGENT_FOLDERS = Object.freeze(Object.fromEntries(Object.entries(TABLE).map(([agent, folders]) => [agent, Object.freeze({ ...folders, homes: Object.freeze([...folders.homes]) })])));
11
+ //# sourceMappingURL=agent-folders.js.map
@@ -0,0 +1,26 @@
1
+ import { type Issue, type Manifest, type ReleaseFile } from "./format.js";
2
+ import type { RegistrySource } from "./registry.js";
3
+ /** Pack files into a release archive rooted at `<pkg>/`. */
4
+ export declare function packFiles(pkg: string, files: readonly {
5
+ path: string;
6
+ executable: boolean;
7
+ data: Uint8Array;
8
+ }[]): Uint8Array;
9
+ /** Pack a release folder's declared files. */
10
+ export declare function packRelease(dir: string, manifest: Manifest, files: readonly ReleaseFile[]): Uint8Array;
11
+ export interface UnpackedRelease {
12
+ manifest: Manifest | null;
13
+ files: ReleaseFile[];
14
+ data: Map<string, Uint8Array>;
15
+ issues: Issue[];
16
+ }
17
+ /** Unpack and check a release archive as the registry does. */
18
+ export declare function unpackRelease(tgz: Uint8Array, pkg: string): UnpackedRelease;
19
+ /** Publish a release folder as it is (environments-10): read and check
20
+ * it as the core reads any release, with the fields the registry
21
+ * requires, pack its declared files, upload. */
22
+ export declare function publishRelease(registry: RegistrySource, dir: string): Promise<{
23
+ name: string;
24
+ version: string;
25
+ checksum: string;
26
+ }>;
@@ -0,0 +1,91 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ // Release archives (Spex Space DR-016): a gzipped tarball rooted at
4
+ // `<pkg>/` holding the declared release files and nothing else, each
5
+ // with its owner-execute bit. Packing is deterministic, so one release
6
+ // always packs to the same checksum; unpacking refuses a link or a
7
+ // special entry and anything outside the root.
8
+ import { readFileSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ import { checkRelease, parseManifestText, portablePathIssues, readPublishableRelease, sha256Hex } from "./format.js";
11
+ import { gunzip, gzip, readTar, writeTar } from "./tar.js";
12
+ /** Pack files into a release archive rooted at `<pkg>/`. */
13
+ export function packFiles(pkg, files) {
14
+ const sorted = [...files].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
15
+ return gzip(writeTar(sorted.map((file) => ({
16
+ path: `${pkg}/${file.path}`,
17
+ type: "file",
18
+ mode: file.executable ? 0o755 : 0o644,
19
+ data: file.data,
20
+ }))));
21
+ }
22
+ /** Pack a release folder's declared files. */
23
+ export function packRelease(dir, manifest, files) {
24
+ return packFiles(manifest.name, files.map((file) => ({
25
+ path: file.path,
26
+ executable: file.executable,
27
+ data: readFileSync(join(dir, ...file.path.split("/"))),
28
+ })));
29
+ }
30
+ /** Unpack and check a release archive as the registry does. */
31
+ export function unpackRelease(tgz, pkg) {
32
+ const issues = [];
33
+ const data = new Map();
34
+ const files = [];
35
+ let entries;
36
+ try {
37
+ entries = readTar(gunzip(tgz));
38
+ }
39
+ catch (error) {
40
+ return { manifest: null, files, data, issues: [{ rule: "archive", message: `not a gzipped tarball: ${error.message}` }] };
41
+ }
42
+ const root = `${pkg}/`;
43
+ for (const entry of entries) {
44
+ if (entry.path === pkg && entry.type === "directory")
45
+ continue;
46
+ if (!entry.path.startsWith(root)) {
47
+ issues.push({ path: entry.path, rule: "archive", message: `lies outside the archive's root ${root}` });
48
+ continue;
49
+ }
50
+ const path = entry.path.slice(root.length);
51
+ if (entry.type === "directory")
52
+ continue;
53
+ if (entry.type === "symlink" || entry.type === "hardlink") {
54
+ issues.push({ path, rule: "link", message: "is a link; a release holds files only" });
55
+ continue;
56
+ }
57
+ if (entry.type !== "file") {
58
+ issues.push({ path, rule: "special", message: "is a special file; a release holds files only" });
59
+ continue;
60
+ }
61
+ if (data.has(path)) {
62
+ issues.push({ path, rule: "path", message: "appears twice in the archive" });
63
+ continue;
64
+ }
65
+ data.set(path, entry.data);
66
+ files.push({ path, size: entry.data.length, sha256: sha256Hex(entry.data), executable: (entry.mode & 0o100) !== 0 });
67
+ }
68
+ files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
69
+ issues.push(...portablePathIssues(files.map((file) => file.path)).filter((issue) => !issues.some((other) => other.path === issue.path)));
70
+ const meta = data.get("meta.yaml");
71
+ if (!meta) {
72
+ issues.push({ path: "meta.yaml", rule: "manifest", message: "the folder has no meta.yaml" });
73
+ return { manifest: null, files, data, issues };
74
+ }
75
+ const parsed = parseManifestText(Buffer.from(meta).toString("utf8"));
76
+ issues.push(...parsed.issues);
77
+ if (parsed.manifest)
78
+ issues.push(...checkRelease((path) => data.get(path), parsed.manifest, files));
79
+ return { manifest: parsed.manifest, files, data, issues };
80
+ }
81
+ /** Publish a release folder as it is (environments-10): read and check
82
+ * it as the core reads any release, with the fields the registry
83
+ * requires, pack its declared files, upload. */
84
+ export async function publishRelease(registry, dir) {
85
+ const { manifest, files } = await readPublishableRelease(dir);
86
+ const tgz = packRelease(dir, manifest, files);
87
+ const name = `${manifest.org}/${manifest.name}`;
88
+ await registry.publish(name, manifest.version, tgz);
89
+ return { name, version: manifest.version, checksum: sha256Hex(tgz) };
90
+ }
91
+ //# sourceMappingURL=archive.js.map
@@ -0,0 +1,112 @@
1
+ import { BUILTIN_PACKAGE_NAME } from "./exports.js";
2
+ import { type Manifest, type ReleaseFile } from "./format.js";
3
+ import { type Lock, type LockedFile } from "./lock.js";
4
+ import { type RegistrySource } from "./registry.js";
5
+ import type { ContentStore } from "./store.js";
6
+ export { BUILTIN_PACKAGE_NAME };
7
+ export interface BuiltinPackage {
8
+ name: typeof BUILTIN_PACKAGE_NAME;
9
+ version: string;
10
+ /** The staged release folder. */
11
+ dir: string;
12
+ }
13
+ /** A seeded release, as `cache/builtins/<version>.json` records it. */
14
+ export interface BuiltinRelease {
15
+ format: 1;
16
+ name: typeof BUILTIN_PACKAGE_NAME;
17
+ version: string;
18
+ manifest: Manifest;
19
+ files: ReleaseFile[];
20
+ /** SHA-256 of the release archive this source serves. */
21
+ checksum: string;
22
+ size: number;
23
+ }
24
+ /** The built-in spec package staged under `root`, where the app's build
25
+ * stages it: the highest version staged. */
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. */
29
+ export declare function seedBuiltinPackage(store: ContentStore, cacheDir: string, pkg: BuiltinPackage): Promise<BuiltinRelease>;
30
+ export interface BuiltinSourceOptions {
31
+ store: ContentStore;
32
+ cacheDir: string;
33
+ /** The registry the lock names for the built-in spec package. */
34
+ url?: string;
35
+ /** The staged release this app ships, served even before seeding;
36
+ * none where omitted. */
37
+ shipped?: BuiltinPackage | null;
38
+ }
39
+ /** The seeded built-in releases as a registry source (environments-11):
40
+ * no network, `sublang/playbooks` only. */
41
+ export declare function builtinRegistrySource(options: BuiltinSourceOptions): RegistrySource;
42
+ /**
43
+ * 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
45
+ * and each locked file at the digest the lock records for it. The
46
+ * archive's checksum is not compared: each device packs its own archive
47
+ * from its seed, so another device's lock of the same files may record
48
+ * another.
49
+ */
50
+ export declare function seedServes(seed: RegistrySource, version: string, files: readonly LockedFile[]): Promise<boolean>;
51
+ /**
52
+ * The lock an environment requesting only the built-in spec package
53
+ * resolves to, computed from the release this app ships without any
54
+ * source or network (environments-3, environments-6): every artifact in
55
+ * its original language, every file of theirs, each playbook it
56
+ * provides exported under its id. A clone the store makes holds it from
57
+ * its first commit.
58
+ */
59
+ export declare function builtinLock(pkg: BuiltinPackage, registryUrl: string, requestsText: string): Lock;
60
+ /**
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.
63
+ * `spex.yaml` requests the built-in spec package where it does not —
64
+ * with `space` naming the environment's instance where one is given, the
65
+ * caller giving the instance its spex repository is placed at wherever
66
+ * it has one — and, where that is all it requests and no lock stands,
67
+ * its lock, so the first commit holding either holds both. Returns
68
+ * whether `spex.yaml` was written.
69
+ */
70
+ export declare function prepareBuiltinEnvironment(root: string, pkg: BuiltinPackage, registryUrl: string, space?: string | null): boolean;
71
+ /**
72
+ * 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`
74
+ * requesting the built-in spec package alone, and `spex.lock` exactly
75
+ * the built-in lock at the registry it records — another than
76
+ * `registryUrl`, or that one while `spex.yaml` does not name `space`.
77
+ * A lock holding anything else — another release, another package, a
78
+ * resolution of the reader's — is left as it is. Where `space` is given
79
+ * — the instance placed at — `spex.yaml` names it first, and the lock
80
+ * follows its bytes (DR-165).
81
+ * Written under the versions read, a file changed meanwhile left
82
+ * standing (DR-111). Returns whether it wrote.
83
+ */
84
+ export declare function rehomeBuiltinLock(root: string, pkg: BuiltinPackage, registryUrl: string, space?: string | null): boolean;
85
+ /**
86
+ * 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
89
+ * first commit already holds it; comments and key order of an existing
90
+ * file are kept, and the file is written under the version read, so a
91
+ * file changed meanwhile is refused as a conflict (DR-111). Where `space` is given and the file
92
+ * names none, the request names it as the environment's instance
93
+ * (environments-2, DR-165). A file that does not read, or a root that
94
+ * does not exist — a working folder removed meanwhile — is left as it
95
+ * is, nothing created. Returns whether it wrote.
96
+ */
97
+ export declare function ensureBuiltinRequest(root: string, version: string, space?: string | null): boolean;
98
+ /**
99
+ * A new project's environment at its pairing (storage-6, DR-176): where
100
+ * the working folder holds no `spex.yaml`, one naming the public
101
+ * registry as every new file does (environments-38), `space` where the
102
+ * project's spex repository is placed at an instance (DR-170), and
103
+ * requesting nothing — the built-in spec package is a global package,
104
+ * never a project's request (environments-11). Created exclusively, so a
105
+ * file written meanwhile stands; a root that does not exist is left as
106
+ * it is. Returns whether it wrote.
107
+ */
108
+ export declare function prepareProjectEnvironment(root: string, space?: string | null): boolean;
109
+ /** A registry that answers `sublang/playbooks` from the built-in source
110
+ * first — offline, from what this device seeded — and everything else
111
+ * from the remote registry, whose URL the lock records. */
112
+ export declare function compositeRegistry(builtin: RegistrySource, remote: RegistrySource): RegistrySource;