@ipab/cli 0.1.0-rc.7 → 0.1.0-rc.9

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 (120) hide show
  1. package/README.md +70 -30
  2. package/dist/app-authoring.d.ts.map +1 -1
  3. package/dist/app-authoring.js +2 -44
  4. package/dist/app-authoring.js.map +1 -1
  5. package/dist/app-prebuild.d.ts +18 -0
  6. package/dist/app-prebuild.d.ts.map +1 -1
  7. package/dist/app-prebuild.js +46 -0
  8. package/dist/app-prebuild.js.map +1 -1
  9. package/dist/builtins/skill.ipab.car +0 -0
  10. package/dist/bundled-skills.d.ts +14 -0
  11. package/dist/bundled-skills.d.ts.map +1 -0
  12. package/dist/bundled-skills.js +34 -0
  13. package/dist/bundled-skills.js.map +1 -0
  14. package/dist/cli.d.ts.map +1 -1
  15. package/dist/cli.js +309 -157
  16. package/dist/cli.js.map +1 -1
  17. package/dist/config.d.ts +1 -1
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/config.js +9 -4
  20. package/dist/config.js.map +1 -1
  21. package/dist/context.d.ts +4 -0
  22. package/dist/context.d.ts.map +1 -1
  23. package/dist/context.js +11 -2
  24. package/dist/context.js.map +1 -1
  25. package/dist/daemon.d.ts +4 -0
  26. package/dist/daemon.d.ts.map +1 -0
  27. package/dist/daemon.js +200 -0
  28. package/dist/daemon.js.map +1 -0
  29. package/dist/doctor.d.ts +2 -0
  30. package/dist/doctor.d.ts.map +1 -1
  31. package/dist/doctor.js +18 -4
  32. package/dist/doctor.js.map +1 -1
  33. package/dist/errors.d.ts +1 -8
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +1 -20
  36. package/dist/errors.js.map +1 -1
  37. package/dist/host-error.d.ts +9 -0
  38. package/dist/host-error.d.ts.map +1 -0
  39. package/dist/host-error.js +21 -0
  40. package/dist/host-error.js.map +1 -0
  41. package/dist/ipc.d.ts.map +1 -1
  42. package/dist/ipc.js +17 -0
  43. package/dist/ipc.js.map +1 -1
  44. package/dist/kubo-install.js +1 -1
  45. package/dist/kubo-install.js.map +1 -1
  46. package/dist/kubo-peers.d.ts.map +1 -1
  47. package/dist/kubo-peers.js +2 -1
  48. package/dist/kubo-peers.js.map +1 -1
  49. package/dist/kubo-topology.d.ts +19 -0
  50. package/dist/kubo-topology.d.ts.map +1 -0
  51. package/dist/kubo-topology.js +105 -0
  52. package/dist/kubo-topology.js.map +1 -0
  53. package/dist/kubo.d.ts +10 -0
  54. package/dist/kubo.d.ts.map +1 -1
  55. package/dist/kubo.js +96 -15
  56. package/dist/kubo.js.map +1 -1
  57. package/dist/skill-source.d.ts +4 -0
  58. package/dist/skill-source.d.ts.map +1 -1
  59. package/dist/skill-source.js +14 -2
  60. package/dist/skill-source.js.map +1 -1
  61. package/dist/skills.d.ts +18 -1
  62. package/dist/skills.d.ts.map +1 -1
  63. package/dist/skills.js +137 -39
  64. package/dist/skills.js.map +1 -1
  65. package/dist/space-path.d.ts +3 -0
  66. package/dist/space-path.d.ts.map +1 -0
  67. package/dist/space-path.js +17 -0
  68. package/dist/space-path.js.map +1 -0
  69. package/dist/space.d.ts +1 -2
  70. package/dist/space.d.ts.map +1 -1
  71. package/dist/space.js +2 -15
  72. package/dist/space.js.map +1 -1
  73. package/dist/state-storage.js +1 -1
  74. package/dist/state-storage.js.map +1 -1
  75. package/dist/state.d.ts +2 -0
  76. package/dist/state.d.ts.map +1 -1
  77. package/dist/state.js +31 -12
  78. package/dist/state.js.map +1 -1
  79. package/dist/swarm-files.d.ts +1 -1
  80. package/dist/swarm-files.d.ts.map +1 -1
  81. package/dist/swarm-files.js +10 -4
  82. package/dist/swarm-files.js.map +1 -1
  83. package/dist/swarm-meta.d.ts +1 -4
  84. package/dist/swarm-meta.d.ts.map +1 -1
  85. package/dist/swarm-meta.js +3 -34
  86. package/dist/swarm-meta.js.map +1 -1
  87. package/dist/swarm-observations.d.ts +40 -0
  88. package/dist/swarm-observations.d.ts.map +1 -0
  89. package/dist/swarm-observations.js +262 -0
  90. package/dist/swarm-observations.js.map +1 -0
  91. package/dist/swarm.d.ts +121 -6
  92. package/dist/swarm.d.ts.map +1 -1
  93. package/dist/swarm.js +672 -81
  94. package/dist/swarm.js.map +1 -1
  95. package/package.json +4 -4
  96. package/src/app-authoring.ts +12 -53
  97. package/src/app-prebuild.ts +61 -0
  98. package/src/bundled-skills.ts +60 -0
  99. package/src/cli.ts +398 -195
  100. package/src/config.ts +12 -4
  101. package/src/context.ts +15 -2
  102. package/src/daemon.ts +237 -0
  103. package/src/doctor.ts +42 -5
  104. package/src/errors.ts +1 -25
  105. package/src/host-error.ts +26 -0
  106. package/src/ipc.ts +19 -0
  107. package/src/kubo-install.ts +1 -1
  108. package/src/kubo-peers.ts +2 -3
  109. package/src/kubo-topology.ts +135 -0
  110. package/src/kubo.ts +134 -25
  111. package/src/skill-source.ts +16 -2
  112. package/src/skills.ts +195 -53
  113. package/src/space-path.ts +30 -0
  114. package/src/space.ts +2 -28
  115. package/src/state-storage.ts +1 -1
  116. package/src/state.ts +37 -12
  117. package/src/swarm-files.ts +8 -3
  118. package/src/swarm-meta.ts +15 -34
  119. package/src/swarm-observations.ts +374 -0
  120. package/src/swarm.ts +953 -92
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ipab/cli",
3
- "version": "0.1.0-rc.7",
3
+ "version": "0.1.0-rc.9",
4
4
  "private": false,
5
5
  "description": "Node subprocess IPAB host.",
6
6
  "type": "module",
@@ -44,11 +44,11 @@
44
44
  "liquidjs": "10.30.1",
45
45
  "@ipab/web-app": "0.1.0-rc.4",
46
46
  "esbuild": "0.28.2",
47
- "@ipab/bundle-builder": "0.1.0-rc.7",
47
+ "@ipab/bundle-builder": "0.1.0-rc.8",
48
48
  "@ipld/car": "5.4.6",
49
49
  "@ipld/dag-pb": "4.2.0",
50
- "@ipab/bundle": "0.1.0-rc.7",
51
- "@ipab/ipfs-store": "0.1.0-rc.3",
50
+ "@ipab/bundle": "0.1.0-rc.8",
51
+ "@ipab/ipfs-store": "0.1.0-rc.4",
52
52
  "ipfs-unixfs": "13.1.2",
53
53
  "ipfs-unixfs-importer": "17.1.1",
54
54
  "multiformats": "14.0.5",
@@ -1,6 +1,5 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { lstat, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
3
- import { isBuiltin } from "node:module";
4
3
  import {
5
4
  basename,
6
5
  dirname,
@@ -11,7 +10,6 @@ import {
11
10
  sep,
12
11
  } from "node:path";
13
12
  import { StringDecoder } from "node:string_decoder";
14
- import { compileFunction } from "node:vm";
15
13
  import { stringify } from "yaml";
16
14
  import { parseData, type BundleType } from "@ipab/bundle";
17
15
  import { filesystemTree } from "@ipab/bundle-builder/node";
@@ -37,7 +35,12 @@ import {
37
35
  builtinAppSchema,
38
36
  } from "./app-definition.js";
39
37
  import { appTemplate } from "./app-templates.js";
40
- import { buildChain, projectBuild, runPrebuild } from "./app-prebuild.js";
38
+ import {
39
+ buildChain,
40
+ compileAppProgram,
41
+ projectBuild,
42
+ runPrebuild,
43
+ } from "./app-prebuild.js";
41
44
  import { captureSource, sourceFingerprint } from "./source-bundle.js";
42
45
  export { appSchema } from "./app-definition.js";
43
46
 
@@ -439,7 +442,6 @@ export async function buildApp(
439
442
  options.signal?.throwIfAborted();
440
443
  const stage = await mkdtemp(join(root, ".ipab-app-"));
441
444
  try {
442
- const { build } = await import("esbuild");
443
445
  const bundleStage = join(stage, "bundle");
444
446
  const input = prebuild ? join(stage, "input") : root;
445
447
  if (prebuild) {
@@ -450,56 +452,13 @@ export async function buildApp(
450
452
  const prebuiltSource = prebuild
451
453
  ? await readBytes(inputTree, entry, 8 * 1024 * 1024, options)
452
454
  : undefined;
453
- if (prebuiltSource) {
454
- try {
455
- const source = new TextDecoder("utf-8", { fatal: true }).decode(
456
- prebuiltSource,
457
- );
458
- compileFunction(source.replace(/^#![^\r\n]*/, ""), [
459
- "exports",
460
- "require",
461
- "module",
462
- "__filename",
463
- "__dirname",
464
- ]);
465
- } catch (cause) {
466
- const error = new HostError(
467
- "Prebuilt App entry must be valid Node CommonJS; it is packaged without transformation.",
468
- );
469
- error.cause = cause;
470
- throw error;
471
- }
472
- }
473
455
  await mkdir(join(bundleStage, "resources"), { recursive: true });
474
- const program = await build({
475
- absWorkingDir: input,
476
- entryPoints: [entry],
477
- outfile: join(bundleStage, "resources", "app.cjs"),
478
- bundle: true,
479
- platform: "node",
480
- format: "cjs",
481
- target: "node22.15",
482
- packages: prebuild ? "external" : "bundle",
483
- metafile: true,
484
- write: false,
485
- logLevel: "silent",
486
- logOverride: {
487
- "unsupported-dynamic-import": "error",
488
- "unsupported-require-call": "error",
489
- "indirect-require": "error",
490
- },
491
- });
492
- if (
493
- program.outputFiles.length !== 1 ||
494
- program.outputFiles[0]!.contents.length > 8 * 1024 * 1024 ||
495
- (prebuild && Object.keys(program.metafile.inputs).length !== 1) ||
496
- Object.values(program.metafile.outputs).some((file) =>
497
- file.imports.some((item) => item.external && !isBuiltin(item.path)),
498
- )
499
- )
500
- throw new HostError(
501
- "App must bundle into one self-contained .cjs of at most 8 MiB; only Node builtins may remain external.",
502
- );
456
+ const program = await compileAppProgram(
457
+ input,
458
+ entry,
459
+ join(bundleStage, "resources", "app.cjs"),
460
+ prebuiltSource,
461
+ );
503
462
  if (sourceFiles && !prebuild)
504
463
  for (const path of Object.keys(program.metafile.inputs))
505
464
  if (
@@ -3,10 +3,71 @@ import { lstat, readFile, realpath } from "node:fs/promises";
3
3
  import { basename, delimiter, dirname, join, resolve } from "node:path";
4
4
  import { promisify } from "node:util";
5
5
  import { StringDecoder } from "node:string_decoder";
6
+ import { isBuiltin } from "node:module";
7
+ import { compileFunction } from "node:vm";
6
8
  import { HostError, object } from "./errors.js";
7
9
  import { nodeError, type AuthoringOptions } from "./authoring.js";
8
10
  import { relativePath } from "./space.js";
9
11
 
12
+ export async function compileAppProgram(
13
+ input: string,
14
+ entry: string,
15
+ outfile: string,
16
+ prebuiltSource?: Uint8Array,
17
+ ) {
18
+ if (prebuiltSource) {
19
+ try {
20
+ const source = new TextDecoder("utf-8", { fatal: true }).decode(
21
+ prebuiltSource,
22
+ );
23
+ compileFunction(source.replace(/^#![^\r\n]*/, ""), [
24
+ "exports",
25
+ "require",
26
+ "module",
27
+ "__filename",
28
+ "__dirname",
29
+ ]);
30
+ } catch (cause) {
31
+ const error = new HostError(
32
+ "Prebuilt App entry must be valid Node CommonJS; it is packaged without transformation.",
33
+ );
34
+ error.cause = cause;
35
+ throw error;
36
+ }
37
+ }
38
+ const { build } = await import("esbuild");
39
+ const program = await build({
40
+ absWorkingDir: input,
41
+ entryPoints: [entry],
42
+ outfile,
43
+ bundle: true,
44
+ platform: "node",
45
+ format: "cjs",
46
+ target: "node22.15",
47
+ packages: prebuiltSource ? "external" : "bundle",
48
+ metafile: true,
49
+ write: false,
50
+ logLevel: "silent",
51
+ logOverride: {
52
+ "unsupported-dynamic-import": "error",
53
+ "unsupported-require-call": "error",
54
+ "indirect-require": "error",
55
+ },
56
+ });
57
+ if (
58
+ program.outputFiles.length !== 1 ||
59
+ program.outputFiles[0]!.contents.length > 8 * 1024 * 1024 ||
60
+ (prebuiltSource && Object.keys(program.metafile.inputs).length !== 1) ||
61
+ Object.values(program.metafile.outputs).some((file) =>
62
+ file.imports.some((item) => item.external && !isBuiltin(item.path)),
63
+ )
64
+ )
65
+ throw new HostError(
66
+ "App must bundle into one self-contained .cjs of at most 8 MiB; only Node builtins may remain external.",
67
+ );
68
+ return program;
69
+ }
70
+
10
71
  export interface ProjectBuild {
11
72
  strategy: "ipab-prebuild";
12
73
  typecheck: { config: string; entry: string }[];
@@ -0,0 +1,60 @@
1
+ import { join } from "node:path";
2
+ import { bundledSkillSource } from "./skill-source.js";
3
+ import {
4
+ inspectBundledSkill,
5
+ manageSkills,
6
+ officialSkillsPort,
7
+ bundledSkillOrigin,
8
+ type SkillsPort,
9
+ } from "./skills.js";
10
+ import { HostError } from "./errors.js";
11
+
12
+ export async function inspectBundledSkills(
13
+ port: SkillsPort = officialSkillsPort,
14
+ ) {
15
+ return inspectBundledSkill(await bundledSkillSource(), port);
16
+ }
17
+
18
+ export async function installBundledSkills(
19
+ env: NodeJS.ProcessEnv,
20
+ preview: (text: string) => void,
21
+ port: SkillsPort = officialSkillsPort,
22
+ ) {
23
+ const catalog = await port.catalog();
24
+ const agents = catalog.detected
25
+ .filter((agent) =>
26
+ catalog.supported.some(
27
+ (entry) => entry.id === agent.id && entry.globalSkillsDir !== null,
28
+ ),
29
+ )
30
+ .map((agent) => agent.id);
31
+ if (!agents.length)
32
+ throw new HostError(
33
+ "No globally supported agents detected. Install an Agent, then retry ipab doctor --fix.",
34
+ );
35
+ const result = await manageSkills(
36
+ { env, bundledSkill: await bundledSkillSource() },
37
+ bundledSkillOrigin,
38
+ {
39
+ sync: true,
40
+ names: [],
41
+ agents,
42
+ overrideExisting: false,
43
+ dryRun: false,
44
+ yes: true,
45
+ tty: false,
46
+ confirm: () => Promise.resolve(false),
47
+ preview,
48
+ },
49
+ port,
50
+ );
51
+ if (!result.ok)
52
+ throw new HostError(
53
+ [
54
+ "Bundled IPAB Skill installation failed; existing custom content was preserved.",
55
+ ...result.items.flatMap((item) => item.problems),
56
+ ...result.results.flatMap((item) => (item.error ? [item.error] : [])),
57
+ `Inspect ${join(port.home, ".ipab", "skills", "installations.json")} and retry ipab doctor --fix.`,
58
+ ].join("\n"),
59
+ );
60
+ }