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

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 (97) hide show
  1. package/README.md +72 -33
  2. package/dist/app-authoring.d.ts +5 -0
  3. package/dist/app-authoring.d.ts.map +1 -1
  4. package/dist/app-authoring.js +4 -1
  5. package/dist/app-authoring.js.map +1 -1
  6. package/dist/app-templates.d.ts +0 -1
  7. package/dist/app-templates.d.ts.map +1 -1
  8. package/dist/app-templates.js +6 -45
  9. package/dist/app-templates.js.map +1 -1
  10. package/dist/builtins/skill.ipab.car +0 -0
  11. package/dist/builtins/template.bundle-viewer.car +0 -0
  12. package/dist/builtins/template.check.car +0 -0
  13. package/dist/builtins/template.node.car +0 -0
  14. package/dist/builtins/template.web-app.car +0 -0
  15. package/dist/builtins.d.ts.map +1 -1
  16. package/dist/builtins.js +1 -39
  17. package/dist/builtins.js.map +1 -1
  18. package/dist/cli.d.ts +1 -0
  19. package/dist/cli.d.ts.map +1 -1
  20. package/dist/cli.js +395 -86
  21. package/dist/cli.js.map +1 -1
  22. package/dist/context.d.ts +16 -0
  23. package/dist/context.d.ts.map +1 -1
  24. package/dist/context.js +20 -0
  25. package/dist/context.js.map +1 -1
  26. package/dist/ipc.d.ts +2 -1
  27. package/dist/ipc.d.ts.map +1 -1
  28. package/dist/ipc.js +44 -3
  29. package/dist/ipc.js.map +1 -1
  30. package/dist/runtime.d.ts.map +1 -1
  31. package/dist/runtime.js +6 -3
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/skill-definition.d.ts +6 -0
  34. package/dist/skill-definition.d.ts.map +1 -0
  35. package/dist/skill-definition.js +38 -0
  36. package/dist/skill-definition.js.map +1 -0
  37. package/dist/skill-source.d.ts +5 -0
  38. package/dist/skill-source.d.ts.map +1 -0
  39. package/dist/skill-source.js +12 -0
  40. package/dist/skill-source.js.map +1 -0
  41. package/dist/skills.d.ts +84 -0
  42. package/dist/skills.d.ts.map +1 -0
  43. package/dist/skills.js +736 -0
  44. package/dist/skills.js.map +1 -0
  45. package/dist/space.d.ts +15 -2
  46. package/dist/space.d.ts.map +1 -1
  47. package/dist/space.js +153 -3
  48. package/dist/space.js.map +1 -1
  49. package/dist/state.js +1 -1
  50. package/dist/swarm-files.d.ts +1 -1
  51. package/dist/swarm-files.d.ts.map +1 -1
  52. package/dist/swarm-files.js +2 -2
  53. package/dist/swarm-files.js.map +1 -1
  54. package/dist/swarm-meta.d.ts +17 -0
  55. package/dist/swarm-meta.d.ts.map +1 -0
  56. package/dist/swarm-meta.js +96 -0
  57. package/dist/swarm-meta.js.map +1 -0
  58. package/dist/swarm.d.ts +53 -0
  59. package/dist/swarm.d.ts.map +1 -1
  60. package/dist/swarm.js +465 -73
  61. package/dist/swarm.js.map +1 -1
  62. package/dist/template-paths.d.ts +7 -0
  63. package/dist/template-paths.d.ts.map +1 -0
  64. package/dist/template-paths.js +23 -0
  65. package/dist/template-paths.js.map +1 -0
  66. package/dist/template-presentation.d.ts +20 -0
  67. package/dist/template-presentation.d.ts.map +1 -0
  68. package/dist/template-presentation.js +133 -0
  69. package/dist/template-presentation.js.map +1 -0
  70. package/dist/template-source.d.ts +2 -1
  71. package/dist/template-source.d.ts.map +1 -1
  72. package/dist/template-source.js +7 -1
  73. package/dist/template-source.js.map +1 -1
  74. package/dist/templates.d.ts +11 -0
  75. package/dist/templates.d.ts.map +1 -0
  76. package/dist/templates.js +53 -0
  77. package/dist/templates.js.map +1 -0
  78. package/package.json +7 -6
  79. package/src/app-authoring.ts +18 -2
  80. package/src/app-templates.ts +8 -72
  81. package/src/builtins.ts +2 -48
  82. package/src/cli.ts +474 -71
  83. package/src/context.ts +45 -0
  84. package/src/ipc.ts +63 -2
  85. package/src/runtime.ts +6 -2
  86. package/src/skill-definition.ts +53 -0
  87. package/src/skill-source.ts +15 -0
  88. package/src/skills.ts +1005 -0
  89. package/src/space.ts +214 -5
  90. package/src/state.ts +1 -1
  91. package/src/swarm-files.ts +2 -1
  92. package/src/swarm-meta.ts +109 -0
  93. package/src/swarm.ts +721 -128
  94. package/src/template-paths.ts +43 -0
  95. package/src/template-presentation.ts +151 -0
  96. package/src/template-source.ts +9 -2
  97. package/src/templates.ts +77 -0
package/src/context.ts CHANGED
@@ -6,6 +6,23 @@ export type { BundleInspection } from "./context-types.js";
6
6
 
7
7
  export interface AppContext {
8
8
  readonly appCid: string;
9
+ /** Opt into explicit Bundle results; exiting without submission cancels the session. */
10
+ beginOpenSession(
11
+ inputCid: string,
12
+ options?: { signal?: AbortSignal; supportedTypes?: readonly string[] },
13
+ ): Promise<void>;
14
+ cancelOpenSession(options?: { signal?: AbortSignal }): Promise<void>;
15
+ /** Retained until execution ends; unchanged files retain their exact UnixFS CIDs. */
16
+ deriveBundle(
17
+ inputCid: string,
18
+ replacements: Record<string, Uint8Array>,
19
+ options?: { signal?: AbortSignal },
20
+ ): Promise<string>;
21
+ /** Select an existing valid Bundle; only a successful process exit commits it. */
22
+ submitBundleResult(
23
+ cid: string,
24
+ options?: { signal?: AbortSignal },
25
+ ): Promise<void>;
9
26
  inspectBundle(
10
27
  reference: string,
11
28
  options?: { signal?: AbortSignal; swarm?: string },
@@ -133,6 +150,34 @@ export function createContext(port: Port): {
133
150
  }
134
151
  };
135
152
  const context: AppContext = {
153
+ async beginOpenSession(inputCid, options = {}) {
154
+ await rpc(
155
+ "beginOpenSession",
156
+ {
157
+ inputCid,
158
+ ...(options.supportedTypes === undefined
159
+ ? {}
160
+ : { supportedTypes: options.supportedTypes }),
161
+ },
162
+ options.signal,
163
+ );
164
+ },
165
+ async cancelOpenSession(options = {}) {
166
+ await rpc("cancelOpenSession", null, options.signal);
167
+ },
168
+ async deriveBundle(inputCid, replacements, options = {}) {
169
+ const result = await rpc(
170
+ "deriveBundle",
171
+ { inputCid, replacements },
172
+ options.signal,
173
+ );
174
+ if (typeof result !== "string" || !result)
175
+ throw new HostError("Invalid derived Bundle response.");
176
+ return result;
177
+ },
178
+ async submitBundleResult(cid, options = {}) {
179
+ await rpc("submitBundleResult", { cid }, options.signal);
180
+ },
136
181
  async inspectBundle(reference, options = {}) {
137
182
  if (!reference || reference.length > 2048)
138
183
  throw new HostError(
package/src/ipc.ts CHANGED
@@ -4,7 +4,12 @@ import { openBundle } from "@ipab/bundle";
4
4
  import { CID } from "multiformats/cid";
5
5
  import { HostError, message, object } from "./errors.js";
6
6
  import { requestFrame, type BundleInspection, type Reply } from "./context.js";
7
- import { CHUNK_BYTES, type OutputSpace, relativePath } from "./space.js";
7
+ import {
8
+ CHUNK_BYTES,
9
+ deriveBundle,
10
+ type OutputSpace,
11
+ relativePath,
12
+ } from "./space.js";
8
13
  import type { Ownership } from "./history.js";
9
14
 
10
15
  class ByteQueue implements AsyncIterable<Uint8Array> {
@@ -81,6 +86,7 @@ export class ContextServer {
81
86
  signal: AbortSignal,
82
87
  swarm?: string,
83
88
  ) => Promise<Pick<BundleInspection, "cid" | "targetCid" | "swarm">>,
89
+ readonly supportedTypes?: ReadonlySet<string>,
84
90
  ) {
85
91
  child.on("message", this.receive);
86
92
  }
@@ -122,8 +128,14 @@ export class ContextServer {
122
128
  if (controller.signal.aborted) {
123
129
  if (frame.operation === "read")
124
130
  await this.cancelRead(Number(result), controller.signal.reason);
125
- if (frame.operation === "link")
131
+ if (
132
+ ["link", "beginOpenSession", "cancelOpenSession"].includes(
133
+ frame.operation,
134
+ )
135
+ )
126
136
  this.output.fail(controller.signal.reason);
137
+ if (frame.operation === "submitBundleResult")
138
+ this.output.discardBundleResult();
127
139
  controller.signal.throwIfAborted();
128
140
  }
129
141
  return result;
@@ -159,6 +171,55 @@ export class ContextServer {
159
171
  ): Promise<unknown> {
160
172
  signal.throwIfAborted();
161
173
  if (operation === "identity") return this.appCid;
174
+ if (operation === "deriveBundle") {
175
+ const data = object(args, "Bundle derivation request");
176
+ if (typeof data.inputCid !== "string")
177
+ throw new HostError("Bundle derivation requires an exact input CID.");
178
+ return deriveBundle(
179
+ data.inputCid,
180
+ data.replacements,
181
+ this.store,
182
+ this.owner,
183
+ signal,
184
+ );
185
+ }
186
+ if (
187
+ ["beginOpenSession", "submitBundleResult", "cancelOpenSession"].includes(
188
+ operation,
189
+ )
190
+ ) {
191
+ let validSubmission = false;
192
+ try {
193
+ if (operation === "cancelOpenSession") this.output.cancelOpenSession();
194
+ else {
195
+ const data = object(args, "Bundle result request");
196
+ const cid =
197
+ operation === "beginOpenSession" ? data.inputCid : data.cid;
198
+ if (typeof cid !== "string") {
199
+ const error = new HostError("Bundle result requires an exact CID.");
200
+ this.output.fail(error);
201
+ throw error;
202
+ }
203
+ if (operation === "beginOpenSession")
204
+ await this.output.beginOpenSession(
205
+ cid,
206
+ signal,
207
+ this.supportedTypes,
208
+ data.supportedTypes,
209
+ );
210
+ else {
211
+ validSubmission = true;
212
+ await this.output.submitBundleResult(cid, signal);
213
+ }
214
+ }
215
+ signal.throwIfAborted();
216
+ return null;
217
+ } catch (error) {
218
+ if (!validSubmission) this.output.fail(error);
219
+ else if (signal.aborted) this.output.discardBundleResult();
220
+ throw error;
221
+ }
222
+ }
162
223
  if (operation === "inspectBundle") {
163
224
  const request = object(args, "Bundle inspection request");
164
225
  if (
package/src/runtime.ts CHANGED
@@ -170,6 +170,7 @@ export async function execute(
170
170
  },
171
171
  invocation.appCid,
172
172
  options.resolveBundleReference,
173
+ app.supportedSchemas,
173
174
  );
174
175
  const result = await new Promise<{
175
176
  code: number | null;
@@ -217,7 +218,9 @@ export async function execute(
217
218
  "execution",
218
219
  );
219
220
  phase = "commit";
220
- record.outputCid = await output.finalize();
221
+ const outputCid = await output.finalize();
222
+ controller.signal.throwIfAborted();
223
+ record.outputCid = outputCid;
221
224
  record.status = "succeeded";
222
225
  exitCode = 0;
223
226
  } catch (error) {
@@ -225,7 +228,8 @@ export async function execute(
225
228
  error instanceof HostError
226
229
  ? error
227
230
  : new HostError(message(error), 1, "EXECUTION_FAILED", phase);
228
- record.status = cancellation ? "cancelled" : "failed";
231
+ record.status =
232
+ cancellation || failure.code === "CANCELLED" ? "cancelled" : "failed";
229
233
  record.error = {
230
234
  phase: failure.phase === "state" ? phase : failure.phase,
231
235
  code: failure.code,
@@ -0,0 +1,53 @@
1
+ import type { openBundle } from "@ipab/bundle";
2
+ import { encodeSchema, parseData, type BundleType } from "@ipab/bundle";
3
+ import { bytes } from "./space.js";
4
+ import { HostError, object } from "./errors.js";
5
+
6
+ export const skillType: BundleType = {
7
+ contentType: "text/markdown",
8
+ schema: {
9
+ type: "object",
10
+ additionalProperties: false,
11
+ required: ["name", "description"],
12
+ properties: {
13
+ name: {
14
+ type: "string",
15
+ minLength: 1,
16
+ maxLength: 64,
17
+ pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$",
18
+ },
19
+ description: { type: "string", minLength: 1, maxLength: 1024 },
20
+ license: { type: "string" },
21
+ compatibility: { type: "string", minLength: 1, maxLength: 500 },
22
+ metadata: { type: "object", additionalProperties: { type: "string" } },
23
+ "allowed-tools": { type: "string" },
24
+ },
25
+ },
26
+ };
27
+ export const skillSchema = await encodeSchema(skillType);
28
+ export async function skillIdentity(
29
+ bundle: Awaited<ReturnType<typeof openBundle>>,
30
+ ): Promise<string> {
31
+ if (
32
+ bundle.schemaKey !== skillSchema.cid.toString() ||
33
+ bundle.manifest.entry !== "SKILL.md" ||
34
+ bundle.validation.status !== "validated"
35
+ )
36
+ throw new HostError(
37
+ "Skill must use the exact Skill type and a validated root SKILL.md entry.",
38
+ );
39
+ const metadata = object(
40
+ parseData(
41
+ await bytes(await bundle.readFile("SKILL.md"), 8 * 1024 * 1024),
42
+ "text/markdown",
43
+ ),
44
+ "Skill frontmatter",
45
+ );
46
+ if (
47
+ typeof metadata.name !== "string" ||
48
+ !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(metadata.name) ||
49
+ metadata.name.length > 64
50
+ )
51
+ throw new HostError("Invalid Skill frontmatter name.");
52
+ return metadata.name;
53
+ }
@@ -0,0 +1,15 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { openBundle } from "@ipab/bundle";
3
+ import { readCar } from "./authoring.js";
4
+ import { skillIdentity } from "./skill-definition.js";
5
+
6
+ export async function seedSkillSource() {
7
+ const car = await readCar(
8
+ fileURLToPath(new URL("../dist/builtins/skill.ipab.car", import.meta.url)),
9
+ {},
10
+ );
11
+ const bundle = await openBundle(car.root, { resolveCid: car.resolveCid });
12
+ if ((await skillIdentity(bundle)) !== "ipab")
13
+ throw new Error("IPAB Skill seed identity must be ipab.");
14
+ return { cid: car.root.toString(), blocks: car.blocks };
15
+ }