@rivet-dev/agentos-toolchain 0.0.0-nathan-agentos-package-resolution.efc374f → 0.2.5-rc.4

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.
package/dist/cli.js CHANGED
@@ -1,76 +1,182 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- pack
4
- } from "./chunk-CSSRRHDX.js";
3
+ build,
4
+ pack,
5
+ packAospkgFromTar,
6
+ publish,
7
+ stage
8
+ } from "./chunk-YTYFSDXW.js";
5
9
 
6
10
  // src/cli.ts
7
11
  import { existsSync, statSync } from "fs";
8
12
  import { basename, resolve } from "path";
9
- var USAGE = `agentos-toolchain \u2014 build agentOS packages
13
+ var USAGE = `agentos-toolchain \u2014 build, stage, and publish agentOS packages
10
14
 
11
15
  Usage:
12
16
  agentos-toolchain pack <npm-pkg | ./local-dir> [options]
17
+ Pack an npm package or local script dir into a self-contained agentOS
18
+ package tar (JS agents / node closures).
19
+ --agent <command> mark a bin command as the package's ACP entrypoint
20
+ --out <tar> output tar (default: ./<input-name>-package.tar)
21
+ --prune-native delete unreachable native .node addons
22
+
23
+ agentos-toolchain stage [<packageDir>] --commands-dir <dir> [--if-missing skip|error]
24
+ Populate <packageDir>/bin/ from a compiled commands directory, per the
25
+ commands/aliases/stubs lists in agentos-package.json. --if-missing skip
26
+ leaves a valid empty placeholder when binaries are absent (default: error).
27
+
28
+ agentos-toolchain build [<packageDir>]
29
+ Assemble the clean runtime tar dist/package.tar (bin/ + share/ +
30
+ agentos-package.json) from <packageDir> (default: cwd).
31
+
32
+ agentos-toolchain publish [<packageDir>] [--tag <t> | --latest] [--dry-run] [--set-version <v>]
33
+ Publish the built package to npm. Default dist-tag is "dev"; the latest
34
+ pointer only moves with an explicit --latest.
13
35
 
14
- Options:
15
- --agent <command> mark a bin command as the package's ACP entrypoint
16
- --out <dir> output dir for the package itself (FLAT;
17
- default: ./<input-name>-package)
18
- --prune-native delete unreachable native .node addons from the flat closure
19
36
  -h, --help show this help
20
37
  `;
21
38
  function defaultOutName(source) {
22
39
  if (existsSync(source) && statSync(source).isDirectory()) {
23
- return `./${basename(resolve(source))}-package`;
40
+ return `./${basename(resolve(source))}-package.tar`;
24
41
  }
25
42
  const at = source.lastIndexOf("@");
26
43
  const name = at > 0 ? source.slice(0, at) : source;
27
- return `./${name.replace(/^@[^/]+\//, "")}-package`;
44
+ return `./${name.replace(/^@[^/]+\//, "")}-package.tar`;
28
45
  }
46
+ var VALUE_FLAGS = /* @__PURE__ */ new Set([
47
+ "--agent",
48
+ "--out",
49
+ "--commands-dir",
50
+ "--if-missing",
51
+ "--tag",
52
+ "--set-version"
53
+ ]);
29
54
  function parseArgs(argv) {
30
- const [cmd, ...rest] = argv;
31
- let source;
32
- let agent;
33
- let out;
34
- let pruneNative = false;
35
- for (let i = 0; i < rest.length; i++) {
36
- const a = rest[i];
37
- if (a === "--agent") agent = rest[++i];
38
- else if (a === "--out") out = rest[++i];
39
- else if (a === "--prune-native") pruneNative = true;
40
- else if (a === "-h" || a === "--help") {
55
+ const positional = [];
56
+ const flags = /* @__PURE__ */ new Map();
57
+ for (let i = 0; i < argv.length; i++) {
58
+ const a = argv[i];
59
+ if (a === "-h" || a === "--help") {
41
60
  process.stdout.write(USAGE);
42
61
  process.exit(0);
43
- } else if (!a.startsWith("-") && source === void 0) source = a;
44
- else throw new Error(`unexpected argument: ${a}`);
62
+ } else if (VALUE_FLAGS.has(a)) {
63
+ const value = argv[++i];
64
+ if (value === void 0) throw new Error(`${a} requires a value`);
65
+ flags.set(a, value);
66
+ } else if (a.startsWith("-")) {
67
+ flags.set(a, true);
68
+ } else {
69
+ positional.push(a);
70
+ }
71
+ }
72
+ return { positional, flags };
73
+ }
74
+ function requireKnownFlags(args, known) {
75
+ for (const flag of args.flags.keys()) {
76
+ if (!known.includes(flag)) throw new Error(`unexpected argument: ${flag}`);
45
77
  }
46
- return { cmd, source, agent, out, pruneNative };
47
78
  }
48
79
  function main() {
49
- const args = parseArgs(process.argv.slice(2));
50
- if (args.cmd === void 0 || args.cmd === "-h" || args.cmd === "--help") {
80
+ const [cmd, ...rest] = process.argv.slice(2);
81
+ if (cmd === void 0) {
51
82
  process.stdout.write(USAGE);
52
- process.exit(args.cmd === void 0 ? 1 : 0);
83
+ process.exit(1);
53
84
  }
54
- if (args.cmd !== "pack") {
55
- throw new Error(`unknown command "${args.cmd}" (only "pack" is supported)`);
85
+ if (cmd === "-h" || cmd === "--help") {
86
+ process.stdout.write(USAGE);
87
+ process.exit(0);
56
88
  }
57
- if (!args.source) throw new Error("pack requires a <npm-pkg | ./local-dir> argument");
58
- const result = pack({
59
- source: args.source,
60
- out: resolve(args.out ?? defaultOutName(args.source)),
61
- agent: args.agent,
62
- pruneNative: args.pruneNative
63
- });
64
- process.stdout.write(
65
- `packed ${result.name}@${result.version} \u2192 ${result.packageDir}
89
+ const args = parseArgs(rest);
90
+ switch (cmd) {
91
+ case "pack-aospkg": {
92
+ requireKnownFlags(args, []);
93
+ const sourceTar = args.positional[0];
94
+ const dest = args.positional[1];
95
+ if (!sourceTar || !dest) {
96
+ throw new Error("pack-aospkg requires <source-tar> <dest-aospkg> arguments");
97
+ }
98
+ const summary = packAospkgFromTar(resolve(sourceTar), resolve(dest));
99
+ process.stdout.write(
100
+ `packed ${summary.name}@${summary.version} \u2192 ${dest}
101
+ `
102
+ );
103
+ return;
104
+ }
105
+ case "pack": {
106
+ requireKnownFlags(args, ["--agent", "--out", "--prune-native"]);
107
+ const source = args.positional[0];
108
+ if (!source) {
109
+ throw new Error("pack requires a <npm-pkg | ./local-dir> argument");
110
+ }
111
+ const result = pack({
112
+ source,
113
+ out: resolve(
114
+ args.flags.get("--out") ?? defaultOutName(source)
115
+ ),
116
+ agent: args.flags.get("--agent"),
117
+ pruneNative: args.flags.get("--prune-native") === true
118
+ });
119
+ process.stdout.write(
120
+ `packed ${result.name}@${result.version} \u2192 ${result.packageTar}
66
121
  commands: ${result.commands.join(", ")}
67
122
  `
68
- );
123
+ );
124
+ return;
125
+ }
126
+ case "stage": {
127
+ requireKnownFlags(args, ["--commands-dir", "--if-missing"]);
128
+ const commandsDir = args.flags.get("--commands-dir");
129
+ if (!commandsDir) throw new Error("stage requires --commands-dir <dir>");
130
+ const ifMissing = args.flags.get("--if-missing") ?? "error";
131
+ if (ifMissing !== "error" && ifMissing !== "skip") {
132
+ throw new Error(
133
+ `--if-missing must be "skip" or "error", got "${ifMissing}"`
134
+ );
135
+ }
136
+ stage({
137
+ packageDir: args.positional[0] ?? process.cwd(),
138
+ commandsDir,
139
+ ifMissing
140
+ });
141
+ return;
142
+ }
143
+ case "build": {
144
+ requireKnownFlags(args, []);
145
+ build(args.positional[0]);
146
+ return;
147
+ }
148
+ case "publish": {
149
+ requireKnownFlags(args, [
150
+ "--tag",
151
+ "--latest",
152
+ "--dry-run",
153
+ "--set-version"
154
+ ]);
155
+ const result = publish({
156
+ packageDir: args.positional[0] ?? process.cwd(),
157
+ tag: args.flags.get("--tag"),
158
+ latest: args.flags.get("--latest") === true,
159
+ dryRun: args.flags.get("--dry-run") === true,
160
+ setVersion: args.flags.get("--set-version")
161
+ });
162
+ process.stdout.write(
163
+ `published ${result.name}@${result.version} (dist-tag: ${result.tag})
164
+ `
165
+ );
166
+ return;
167
+ }
168
+ default:
169
+ throw new Error(
170
+ `unknown command "${cmd}" (expected pack, stage, build, or publish)`
171
+ );
172
+ }
69
173
  }
70
174
  try {
71
175
  main();
72
176
  } catch (error) {
73
- process.stderr.write(`error: ${error instanceof Error ? error.message : String(error)}
74
- `);
177
+ process.stderr.write(
178
+ `error: ${error instanceof Error ? error.message : String(error)}
179
+ `
180
+ );
75
181
  process.exit(1);
76
182
  }
package/dist/index.d.ts CHANGED
@@ -2,10 +2,10 @@ interface PackOptions {
2
2
  /** npm package spec (`name`, `name@version`) or a local directory path. */
3
3
  source: string;
4
4
  /**
5
- * Output dir for the package itself (FLAT): the package lands directly at
6
- * `<out>/{bin/, node_modules/, package.json}`. The versioned
5
+ * Output tar for the package itself. The tar contains
6
+ * `{bin/, node_modules/, agentos-package.json}` at its root. The versioned
7
7
  * `/opt/agentos/<name>/<version>` + `current` layout is the sidecar
8
- * projection's job (name from the descriptor, version from this package.json).
8
+ * projection's job (name/version from `agentos-package.json`).
9
9
  */
10
10
  out: string;
11
11
  /** Mark a bin command as the package's ACP entrypoint (validated against bin/). */
@@ -23,7 +23,9 @@ interface PackOptions {
23
23
  interface PackResult {
24
24
  name: string;
25
25
  version: string;
26
- packageDir: string;
26
+ packageTar: string;
27
+ /** The packed `.aospkg` runtime artifact (empty when `out` was a directory). */
28
+ packageAospkg?: string;
27
29
  commands: string[];
28
30
  }
29
31
  /**
@@ -47,4 +49,154 @@ declare function isNativeKind(kind: ExecutableKind): boolean;
47
49
  /** The interpreter named on a shebang line, taken literally (no PATH search). */
48
50
  declare function parseShebangInterpreter(head: Buffer): string | null;
49
51
 
50
- export { type ExecutableKind, type PackOptions, type PackResult, detectExecutableKind, isNativeKind, pack, parseShebangInterpreter, verifyPackageDir };
52
+ interface StageOptions {
53
+ /** Package root holding `agentos-package.json`; `bin/` is (re)created here. */
54
+ packageDir: string;
55
+ /** Directory of compiled command binaries (e.g. the native wasm build output). */
56
+ commandsDir: string;
57
+ /**
58
+ * What to do when the commands dir or a declared binary is absent.
59
+ * `"error"` (default) fails the stage; `"skip"` warns and leaves the package
60
+ * a valid empty placeholder — used by in-repo builds so `pnpm build` works
61
+ * on checkouts that have not run the native build.
62
+ */
63
+ ifMissing?: "error" | "skip";
64
+ }
65
+ interface StageResult {
66
+ staged: string[];
67
+ missing: string[];
68
+ }
69
+ /**
70
+ * Populate a package's `bin/` from a commands directory, per the `commands` /
71
+ * `aliases` / `stubs` lists declared in its `agentos-package.json`.
72
+ *
73
+ * `bin/` is wiped and rebuilt on every run. Sources are copied dereferenced
74
+ * (`copyFileSync` follows symlinks), so alias/stub symlink farms in the
75
+ * commands dir land as real files that survive npm packing.
76
+ */
77
+ declare function stage(options: StageOptions): StageResult;
78
+
79
+ interface BuildResult {
80
+ name: string;
81
+ version: string;
82
+ commands: string[];
83
+ outDir: string;
84
+ outTar: string;
85
+ /** The packed `.aospkg` (header + vbare manifest + mount index + mount tar). */
86
+ outAospkg: string;
87
+ }
88
+ /**
89
+ * Assemble a clean `dist/package/` for a WASM / command registry package.
90
+ *
91
+ * Why this exists: a package's `src/index.ts` sets the descriptor `dir` that the
92
+ * sidecar projects read-only under `/opt/agentos/<name>/<version>`. The sidecar
93
+ * copies that WHOLE directory verbatim. If `dir` pointed at the package source
94
+ * root it would drag `src/`, dev `node_modules/`, `tsconfig.json`, `.turbo/`
95
+ * into every VM. The descriptor must instead point at a CLEAN runtime dir that
96
+ * holds ONLY what the package ships at runtime:
97
+ *
98
+ * dist/package/
99
+ * agentos-package.json pack-time manifest input (name, version, agent,
100
+ * provides) — consumed by the `.aospkg` packer and
101
+ * STRIPPED from the packed mount tar; the vbare
102
+ * chunk1 manifest is the single runtime manifest
103
+ * bin/<cmd> the compiled command binaries (copied verbatim)
104
+ * share/... (optional) man pages, if the source package ships them
105
+ *
106
+ * The runtime artifact is `dist/package.aospkg` (see aospkg.ts); the plain
107
+ * `dist/package.tar` is kept as the pack intermediate.
108
+ *
109
+ * Commands are derived from the source `bin/` directory's files (populate it
110
+ * with `stage`); `name`/`version` come from the source `package.json`. A package
111
+ * with NO (or an empty) `bin/` ships a valid, empty placeholder — it picks up
112
+ * its commands automatically once `stage` can populate `bin/`.
113
+ *
114
+ * This handles the COMMON case (compiled command packages). JS agent packages
115
+ * whose `dist/package` is a self-contained node runtime closure use `pack`
116
+ * instead; meta packages that default-export an ARRAY of descriptors have no
117
+ * `dir`/`bin` and never run this.
118
+ *
119
+ * Idempotent: `dist/package/` is removed and rebuilt on every run.
120
+ */
121
+ declare function build(packageDirInput?: string): BuildResult;
122
+
123
+ interface PublishOptions {
124
+ packageDir: string;
125
+ /** npm dist-tag. Defaults to `dev` so a publish NEVER moves `latest`. */
126
+ tag?: string;
127
+ /** Explicit opt-in to the `latest` dist-tag. */
128
+ latest?: boolean;
129
+ dryRun?: boolean;
130
+ /** Rewrite package.json `version` before publishing. */
131
+ setVersion?: string;
132
+ }
133
+ interface PublishResult {
134
+ name: string;
135
+ version: string;
136
+ tag: string;
137
+ }
138
+ /**
139
+ * `latest` is opt-in only: consumers installing `@agentos-software/<x>` with no
140
+ * tag must keep resolving a deliberate release, never whatever was published
141
+ * last from a dev machine or CI branch.
142
+ */
143
+ declare function resolveTag(options: Pick<PublishOptions, "tag" | "latest">): string;
144
+ /**
145
+ * Publish a built agentOS package to npm.
146
+ *
147
+ * Uses `pnpm publish` when the package lives in a pnpm workspace (so any
148
+ * `workspace:*` deps are rewritten to real versions), plain `npm publish`
149
+ * otherwise — 3rd-party repos need no pnpm.
150
+ */
151
+ declare function publish(options: PublishOptions): PublishResult;
152
+
153
+ /**
154
+ * The agentOS package manifest (`agentos-package.json`) at a package root.
155
+ *
156
+ * `name` / `agent` / `provides` describe the package to the runtime (they are
157
+ * copied into `dist/package/agentos-package.json` by `build`). `commands` /
158
+ * `aliases` / `stubs` describe how `stage` populates `bin/` from a compiled
159
+ * commands directory.
160
+ */
161
+ interface AgentosPackageManifest {
162
+ name?: string;
163
+ agent?: unknown;
164
+ provides?: unknown;
165
+ /** Command binaries copied from the commands dir into `bin/<name>`. */
166
+ commands?: string[];
167
+ /** alias -> command: staged as a copy of an already-staged `bin/<command>`. */
168
+ aliases?: Record<string, string>;
169
+ /** Commands staged as copies of the commands dir's `_stubs` binary. */
170
+ stubs?: string[];
171
+ }
172
+ declare function readManifest(packageDir: string): AgentosPackageManifest | undefined;
173
+
174
+ /**
175
+ * `.aospkg` packer — the toolchain half of the canonical packer in
176
+ * `crates/vfs/src/package_format/pack.rs` (both encode the schema in
177
+ * `crates/vfs/package-format/v1.bare`; the TS codecs are generated from it by
178
+ * `pnpm --dir packages/build-tools build:package-format`).
179
+ *
180
+ * Container layout: `16-byte header + vbare PackageManifest + vbare MountIndex
181
+ * + mount.tar` where each vbare chunk is `[u16 LE schema version] ++ BARE`.
182
+ *
183
+ * `agentos-package.json` is a pack-time INPUT only: it is parsed to build the
184
+ * chunk1 vbare manifest and stripped from the packed mount tar. The vbare
185
+ * manifest is the single runtime manifest; nothing re-materializes JSON into
186
+ * the guest. A root `package.json` stays in the mount tar (Node module
187
+ * resolution may need it) and its `bin` map is consulted for command targets.
188
+ */
189
+ interface AospkgSummary {
190
+ name: string;
191
+ version: string;
192
+ commands: string[];
193
+ }
194
+ /** Pack `sourceTar` into a `.aospkg` at `dest`. The source
195
+ * `agentos-package.json` must carry `name` and `version`. */
196
+ declare function packAospkgFromTar(sourceTar: string, dest: string): AospkgSummary;
197
+ declare function packAospkgFromTarBytes(source: Buffer): {
198
+ bytes: Buffer;
199
+ summary: AospkgSummary;
200
+ };
201
+
202
+ export { type AgentosPackageManifest, type AospkgSummary, type BuildResult, type ExecutableKind, type PackOptions, type PackResult, type PublishOptions, type PublishResult, type StageOptions, type StageResult, build, detectExecutableKind, isNativeKind, pack, packAospkgFromTar, packAospkgFromTarBytes, parseShebangInterpreter, publish, readManifest, resolveTag, stage, verifyPackageDir };
package/dist/index.js CHANGED
@@ -1,14 +1,28 @@
1
1
  import {
2
+ build,
2
3
  detectExecutableKind,
3
4
  isNativeKind,
4
5
  pack,
6
+ packAospkgFromTar,
7
+ packAospkgFromTarBytes,
5
8
  parseShebangInterpreter,
9
+ publish,
10
+ readManifest,
11
+ resolveTag,
12
+ stage,
6
13
  verifyPackageDir
7
- } from "./chunk-CSSRRHDX.js";
14
+ } from "./chunk-YTYFSDXW.js";
8
15
  export {
16
+ build,
9
17
  detectExecutableKind,
10
18
  isNativeKind,
11
19
  pack,
20
+ packAospkgFromTar,
21
+ packAospkgFromTarBytes,
12
22
  parseShebangInterpreter,
23
+ publish,
24
+ readManifest,
25
+ resolveTag,
26
+ stage,
13
27
  verifyPackageDir
14
28
  };
package/package.json CHANGED
@@ -1,34 +1,38 @@
1
1
  {
2
- "name": "@rivet-dev/agentos-toolchain",
3
- "version": "0.0.0-nathan-agentos-package-resolution.efc374f",
4
- "description": "Build toolchain for agentOS packages (pack npm packages/scripts into self-contained agentOS packages).",
5
- "type": "module",
6
- "license": "Apache-2.0",
7
- "bin": {
8
- "agentos-toolchain": "./dist/cli.js"
9
- },
10
- "exports": {
11
- ".": {
12
- "import": {
13
- "types": "./dist/index.d.ts",
14
- "default": "./dist/index.js"
15
- }
16
- }
17
- },
18
- "files": [
19
- "dist",
20
- "package.json",
21
- "README.md"
22
- ],
23
- "devDependencies": {
24
- "@types/node": "^22.10.2",
25
- "tsup": "^8.3.5",
26
- "typescript": "^5.7.2",
27
- "vitest": "^2.1.9"
28
- },
29
- "scripts": {
30
- "build": "tsup src/index.ts src/cli.ts --format esm --dts",
31
- "check-types": "tsc --noEmit",
32
- "test": "vitest run"
33
- }
34
- }
2
+ "name": "@rivet-dev/agentos-toolchain",
3
+ "version": "0.2.5-rc.4",
4
+ "description": "Build toolchain for agentOS packages (pack npm packages/scripts into self-contained agentOS packages).",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "bin": {
8
+ "agentos-toolchain": "./bin/agentos-toolchain.mjs"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ }
17
+ },
18
+ "files": [
19
+ "bin",
20
+ "dist",
21
+ "package.json",
22
+ "README.md"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup src/index.ts src/cli.ts --format esm --dts",
26
+ "check-types": "tsc --noEmit",
27
+ "test": "vitest run"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.10.2",
31
+ "tsup": "^8.3.5",
32
+ "typescript": "^5.7.2",
33
+ "vitest": "^2.1.9"
34
+ },
35
+ "dependencies": {
36
+ "@rivetkit/bare-ts": "^0.6.2"
37
+ }
38
+ }