@ipab/cli 0.1.0-rc.5 → 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.
- package/README.md +128 -22
- package/dist/app-authoring.d.ts +5 -0
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +4 -1
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-templates.d.ts +0 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +6 -45
- package/dist/app-templates.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +1 -39
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts +4 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +934 -336
- package/dist/cli.js.map +1 -1
- package/dist/content-provider.d.ts +1 -1
- package/dist/content-provider.d.ts.map +1 -1
- package/dist/content-provider.js +4 -3
- package/dist/content-provider.js.map +1 -1
- package/dist/context.d.ts +16 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +20 -10
- package/dist/context.js.map +1 -1
- package/dist/doctor.d.ts +29 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +576 -0
- package/dist/doctor.js.map +1 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +9 -9
- package/dist/identity.js.map +1 -1
- package/dist/ipc.d.ts +2 -2
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +44 -12
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +18 -1
- package/dist/kubo-install.d.ts.map +1 -1
- package/dist/kubo-install.js +424 -61
- package/dist/kubo-install.js.map +1 -1
- package/dist/kubo-release.d.ts +19 -0
- package/dist/kubo-release.d.ts.map +1 -1
- package/dist/kubo-release.js +164 -0
- package/dist/kubo-release.js.map +1 -1
- package/dist/kubo.d.ts +1 -0
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +102 -96
- package/dist/kubo.js.map +1 -1
- package/dist/pins.d.ts +15 -17
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +144 -106
- package/dist/pins.js.map +1 -1
- package/dist/publish-source.d.ts +3 -0
- package/dist/publish-source.d.ts.map +1 -0
- package/dist/publish-source.js +85 -0
- package/dist/publish-source.js.map +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +6 -5
- package/dist/runtime.js.map +1 -1
- package/dist/skill-definition.d.ts +6 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +38 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/skill-source.d.ts +5 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +12 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +84 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +736 -0
- package/dist/skills.js.map +1 -0
- package/dist/space.d.ts +15 -2
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +153 -3
- package/dist/space.js.map +1 -1
- package/dist/state-storage-windows.js +1 -1
- package/dist/state-storage.d.ts +3 -1
- package/dist/state-storage.d.ts.map +1 -1
- package/dist/state-storage.js +38 -7
- package/dist/state-storage.js.map +1 -1
- package/dist/state.d.ts +40 -6
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +208 -82
- package/dist/state.js.map +1 -1
- package/dist/swarm-envelope.d.ts +1 -0
- package/dist/swarm-envelope.d.ts.map +1 -1
- package/dist/swarm-envelope.js +12 -0
- package/dist/swarm-envelope.js.map +1 -1
- package/dist/swarm-files.d.ts +1 -1
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +2 -2
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm-meta.d.ts +17 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +96 -0
- package/dist/swarm-meta.js.map +1 -0
- package/dist/swarm.d.ts +117 -8
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1275 -131
- package/dist/swarm.js.map +1 -1
- package/dist/template-paths.d.ts +7 -0
- package/dist/template-paths.d.ts.map +1 -0
- package/dist/template-paths.js +23 -0
- package/dist/template-paths.js.map +1 -0
- package/dist/template-presentation.d.ts +20 -0
- package/dist/template-presentation.d.ts.map +1 -0
- package/dist/template-presentation.js +133 -0
- package/dist/template-presentation.js.map +1 -0
- package/dist/template-source.d.ts +2 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +7 -1
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +53 -0
- package/dist/templates.js.map +1 -0
- package/package.json +7 -6
- package/src/app-authoring.ts +18 -2
- package/src/app-templates.ts +8 -72
- package/src/builtins.ts +2 -48
- package/src/cli.ts +1154 -387
- package/src/content-provider.ts +4 -2
- package/src/context.ts +45 -10
- package/src/doctor.ts +902 -0
- package/src/identity.ts +10 -10
- package/src/ipc.ts +63 -10
- package/src/kubo-install.ts +562 -78
- package/src/kubo-release.ts +213 -0
- package/src/kubo.ts +134 -106
- package/src/pins.ts +188 -126
- package/src/publish-source.ts +103 -0
- package/src/runtime.ts +6 -5
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +15 -0
- package/src/skills.ts +1005 -0
- package/src/space.ts +214 -5
- package/src/state-storage-windows.ts +1 -1
- package/src/state-storage.ts +53 -7
- package/src/state.ts +357 -98
- package/src/swarm-envelope.ts +14 -0
- package/src/swarm-files.ts +2 -1
- package/src/swarm-meta.ts +109 -0
- package/src/swarm.ts +1877 -175
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +9 -2
- package/src/templates.ts +77 -0
- package/dist/setup.d.ts +0 -8
- package/dist/setup.d.ts.map +0 -1
- package/dist/setup.js +0 -27
- package/dist/setup.js.map +0 -1
- package/src/setup.ts +0 -34
package/src/pins.ts
CHANGED
|
@@ -5,19 +5,14 @@ import { openBundle } from "@ipab/bundle";
|
|
|
5
5
|
import { HostError, message } from "./errors.js";
|
|
6
6
|
import { alive, type StoreFactory } from "./history.js";
|
|
7
7
|
import {
|
|
8
|
-
exactCid,
|
|
9
|
-
pinName,
|
|
10
8
|
bundlePinMetadata,
|
|
9
|
+
exactCid,
|
|
10
|
+
type ContentPin,
|
|
11
11
|
type NamedPin,
|
|
12
|
-
type PinMetadata,
|
|
13
12
|
type State,
|
|
14
13
|
} from "./state.js";
|
|
15
14
|
|
|
16
15
|
export function pinDetails(pin: NamedPin) {
|
|
17
|
-
if (pin.status !== "ready" || !pin.metadata)
|
|
18
|
-
throw new HostError(
|
|
19
|
-
`Pin "${pin.name}" is ${pin.status}. Retry ipab pin add ${pin.name} ${pin.cid}, or ipab pin delete ${pin.name}.`,
|
|
20
|
-
);
|
|
21
16
|
return {
|
|
22
17
|
name: pin.name,
|
|
23
18
|
cid: pin.cid,
|
|
@@ -26,15 +21,7 @@ export function pinDetails(pin: NamedPin) {
|
|
|
26
21
|
};
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
function
|
|
30
|
-
pinName(name);
|
|
31
|
-
const pin = state.pin(name);
|
|
32
|
-
if (!pin)
|
|
33
|
-
throw new HostError(`Pin "${name}" does not exist. Run ipab pin list.`);
|
|
34
|
-
return pin;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function idleHold(state: State, pin: NamedPin) {
|
|
24
|
+
function claim(state: State, pin: ContentPin) {
|
|
38
25
|
const hold = state.hold(pin.owner);
|
|
39
26
|
if (!hold)
|
|
40
27
|
throw new HostError(
|
|
@@ -42,159 +29,234 @@ function idleHold(state: State, pin: NamedPin) {
|
|
|
42
29
|
);
|
|
43
30
|
if (hold.pid !== null && alive(hold.pid))
|
|
44
31
|
throw new HostError(
|
|
45
|
-
`Pin
|
|
32
|
+
`Pin ${pin.reference} has an active operation; retry after it finishes.`,
|
|
46
33
|
);
|
|
47
|
-
|
|
34
|
+
state.saveHold({ ...hold, pid: process.pid });
|
|
48
35
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
36
|
+
export function refreshPinClaim(
|
|
37
|
+
state: State,
|
|
38
|
+
saved: ContentPin,
|
|
39
|
+
): ContentPin | undefined {
|
|
40
|
+
return state.transaction(() => {
|
|
41
|
+
const current = state.contentPin(saved.reference);
|
|
42
|
+
if (
|
|
43
|
+
!current ||
|
|
44
|
+
current.owner !== saved.owner ||
|
|
45
|
+
current.status === "deleting"
|
|
46
|
+
)
|
|
47
|
+
return undefined;
|
|
48
|
+
claim(state, current);
|
|
49
|
+
return current;
|
|
50
|
+
});
|
|
63
51
|
}
|
|
64
52
|
|
|
65
|
-
export
|
|
53
|
+
export function reservePin(
|
|
66
54
|
state: State,
|
|
67
|
-
|
|
68
|
-
input: string,
|
|
55
|
+
reference: string,
|
|
69
56
|
configuration: IpfsStore["configuration"],
|
|
70
|
-
|
|
71
|
-
) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const pin = state.transaction(() => {
|
|
75
|
-
const old = state.pin(name);
|
|
57
|
+
shared?: { swarm: string; name: string },
|
|
58
|
+
): ContentPin {
|
|
59
|
+
return state.transaction(() => {
|
|
60
|
+
const old = state.contentPin(reference);
|
|
76
61
|
if (old) {
|
|
77
|
-
if (old.status
|
|
78
|
-
throw new HostError(
|
|
79
|
-
|
|
80
|
-
);
|
|
81
|
-
const hold = idleHold(state, old);
|
|
82
|
-
state.saveHold({ ...hold, pid: process.pid });
|
|
62
|
+
if (old.status === "deleting")
|
|
63
|
+
throw new HostError("Pin deletion is incomplete; retry unpin first.");
|
|
64
|
+
claim(state, old);
|
|
83
65
|
return old;
|
|
84
66
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
cid,
|
|
89
|
-
|
|
67
|
+
const pin: ContentPin = {
|
|
68
|
+
reference,
|
|
69
|
+
owner: `ipab:${state.identity}:pin:${randomUUID()}`,
|
|
70
|
+
cid: null,
|
|
71
|
+
targetCid: null,
|
|
72
|
+
swarm: shared?.swarm ?? null,
|
|
73
|
+
name: shared?.name ?? null,
|
|
90
74
|
status: "pending",
|
|
91
|
-
|
|
75
|
+
freshness: "stale",
|
|
76
|
+
error: null,
|
|
92
77
|
};
|
|
93
|
-
state.
|
|
94
|
-
// Reserve the name and original backend before any Store side effect.
|
|
78
|
+
state.saveContentPin(pin);
|
|
95
79
|
state.saveHold({
|
|
96
|
-
owner,
|
|
80
|
+
owner: pin.owner,
|
|
97
81
|
backend: configuration,
|
|
98
82
|
roots: [],
|
|
99
83
|
pid: process.pid,
|
|
100
84
|
session: null,
|
|
101
85
|
recordId: null,
|
|
102
86
|
});
|
|
103
|
-
return
|
|
87
|
+
return pin;
|
|
104
88
|
});
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Confirm the complete new version before reducing this owner's saved roots. */
|
|
92
|
+
export async function retainPin(
|
|
93
|
+
state: State,
|
|
94
|
+
pin: ContentPin,
|
|
95
|
+
store: IpfsStore,
|
|
96
|
+
version: { cid: string; targetCid: string; roots: readonly string[] },
|
|
97
|
+
): Promise<ContentPin> {
|
|
98
|
+
const backend = state.hold(pin.owner)!.backend;
|
|
99
|
+
let base: IpfsStore | undefined;
|
|
100
|
+
let original: IpfsStore | undefined;
|
|
107
101
|
try {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
if (JSON.stringify(backend) !== JSON.stringify(store.configuration)) {
|
|
103
|
+
base = new IpfsStore(backend);
|
|
104
|
+
original = base.withLocalSource({
|
|
105
|
+
block: { get: (cid, options) => store.block.get(cid, options) },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const retainedStore = original ?? store;
|
|
109
|
+
await base?.close();
|
|
110
|
+
await retainedStore.recoverOwner(
|
|
111
|
+
pin.owner,
|
|
112
|
+
() => state.hold(pin.owner)!.roots,
|
|
113
|
+
);
|
|
114
|
+
await openBundle(CID.parse(version.cid), {
|
|
115
|
+
resolveCid: (cid) => retainedStore.block.get(cid.toString()),
|
|
115
116
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
const roots = [...new Set(version.roots.map((root) => exactCid(root)))];
|
|
118
|
+
if (
|
|
119
|
+
!roots.includes(exactCid(version.cid)) ||
|
|
120
|
+
!roots.includes(exactCid(version.targetCid))
|
|
121
|
+
)
|
|
122
|
+
throw new HostError(
|
|
123
|
+
"Pin roots must include its exact payload and target version.",
|
|
124
|
+
);
|
|
125
|
+
await retainedStore.retain(pin.owner, roots);
|
|
126
|
+
const hold = state.hold(pin.owner)!;
|
|
127
|
+
state.saveHold({ ...hold, roots: [...new Set([...hold.roots, ...roots])] });
|
|
128
|
+
await retainedStore.confirmRetained(pin.owner, roots);
|
|
129
|
+
const ready: ContentPin = {
|
|
130
|
+
...pin,
|
|
131
|
+
cid: version.cid,
|
|
132
|
+
targetCid: version.targetCid,
|
|
133
|
+
status: "ready",
|
|
134
|
+
freshness: "current",
|
|
135
|
+
error: null,
|
|
136
|
+
};
|
|
120
137
|
state.transaction(() => {
|
|
121
|
-
state.
|
|
122
|
-
state.saveHold({ ...state.hold(pin.owner)!,
|
|
138
|
+
state.saveContentPin(ready);
|
|
139
|
+
state.saveHold({ ...state.hold(pin.owner)!, roots });
|
|
123
140
|
});
|
|
124
|
-
|
|
125
|
-
|
|
141
|
+
await retainedStore.reconcile(
|
|
142
|
+
pin.owner,
|
|
143
|
+
() => state.hold(pin.owner)!.roots,
|
|
144
|
+
);
|
|
145
|
+
return ready;
|
|
126
146
|
} catch (cause) {
|
|
147
|
+
const current = state.contentPin(pin.reference)!;
|
|
148
|
+
state.saveContentPin({
|
|
149
|
+
...current,
|
|
150
|
+
freshness: "stale",
|
|
151
|
+
error: message(cause),
|
|
152
|
+
});
|
|
127
153
|
throw new HostError(
|
|
128
|
-
`Pin
|
|
154
|
+
`Pin ${pin.reference} is stale: ${message(cause)}. Its last verified version and durable recovery data are preserved; retry pin or unpin.`,
|
|
129
155
|
1,
|
|
130
156
|
"PIN_INCOMPLETE",
|
|
131
157
|
);
|
|
132
158
|
} finally {
|
|
133
159
|
try {
|
|
134
|
-
await
|
|
160
|
+
await original?.close();
|
|
161
|
+
await base?.close();
|
|
135
162
|
} finally {
|
|
136
163
|
const hold = state.hold(pin.owner);
|
|
137
|
-
if (hold
|
|
164
|
+
if (hold) state.saveHold({ ...hold, pid: null });
|
|
138
165
|
}
|
|
139
166
|
}
|
|
140
167
|
}
|
|
141
168
|
|
|
142
|
-
export async function
|
|
169
|
+
export async function pinCid(
|
|
143
170
|
state: State,
|
|
144
|
-
|
|
145
|
-
|
|
171
|
+
input: string,
|
|
172
|
+
store: IpfsStore,
|
|
173
|
+
roots: readonly string[] = [input],
|
|
146
174
|
) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
175
|
+
const cid = exactCid(input);
|
|
176
|
+
const pin = reservePin(state, cid, store.configuration);
|
|
177
|
+
return retainPin(state, pin, store, { cid, targetCid: cid, roots });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function failedPin(
|
|
181
|
+
state: State,
|
|
182
|
+
reference: string,
|
|
183
|
+
cause: unknown,
|
|
184
|
+
missing = false,
|
|
185
|
+
) {
|
|
186
|
+
const pin = state.contentPin(reference);
|
|
187
|
+
if (!pin) return;
|
|
188
|
+
state.saveContentPin({
|
|
189
|
+
...pin,
|
|
190
|
+
freshness: missing ? "missing" : "stale",
|
|
191
|
+
error: message(cause),
|
|
153
192
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
193
|
+
const hold = state.hold(pin.owner);
|
|
194
|
+
if (hold && !missing) state.saveHold({ ...hold, pid: null });
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export async function unpin(
|
|
198
|
+
state: State,
|
|
199
|
+
reference: string,
|
|
200
|
+
factory: StoreFactory = (config) => new IpfsStore(config),
|
|
201
|
+
) {
|
|
202
|
+
const pin = state.contentPin(reference);
|
|
203
|
+
const archived = state.archivedPins().filter((pin) => pin.cid === reference);
|
|
204
|
+
const owners = [...(pin ? [pin] : []), ...archived];
|
|
205
|
+
for (const record of owners) {
|
|
161
206
|
state.transaction(() => {
|
|
162
|
-
|
|
163
|
-
|
|
207
|
+
if ("reference" in record) claim(state, record);
|
|
208
|
+
else {
|
|
209
|
+
const hold = state.hold(record.owner);
|
|
210
|
+
if (!hold)
|
|
211
|
+
throw new HostError(
|
|
212
|
+
"Archived pin retention metadata is missing; recovery is blocked.",
|
|
213
|
+
);
|
|
214
|
+
if (hold.pid !== null && alive(hold.pid))
|
|
215
|
+
throw new HostError("Archived pin has an active operation.");
|
|
216
|
+
state.saveHold({ ...hold, pid: process.pid });
|
|
217
|
+
}
|
|
218
|
+
if ("reference" in record)
|
|
219
|
+
state.saveContentPin({ ...record, status: "deleting" });
|
|
220
|
+
state.saveHold({ ...state.hold(record.owner)!, roots: [] });
|
|
164
221
|
});
|
|
165
|
-
|
|
166
|
-
removed: [name],
|
|
167
|
-
retentionClaimsReleased: true,
|
|
168
|
-
garbageCollectionGuaranteed: false,
|
|
169
|
-
};
|
|
170
|
-
} catch (cause) {
|
|
171
|
-
throw new HostError(
|
|
172
|
-
`Pin deletion incomplete for "${name}": ${message(cause)}. Retry ipab pin delete ${name}; original backend and recovery data are preserved. No GC requested.`,
|
|
173
|
-
1,
|
|
174
|
-
"RELEASE_FAILED",
|
|
175
|
-
"cleanup",
|
|
176
|
-
);
|
|
177
|
-
} finally {
|
|
222
|
+
let store: IpfsStore | undefined;
|
|
178
223
|
try {
|
|
179
|
-
|
|
224
|
+
store = factory(state.hold(record.owner)!.backend);
|
|
225
|
+
await store.recoverOwner(
|
|
226
|
+
record.owner,
|
|
227
|
+
() => state.hold(record.owner)!.roots,
|
|
228
|
+
);
|
|
229
|
+
await store.reconcile(
|
|
230
|
+
record.owner,
|
|
231
|
+
() => state.hold(record.owner)!.roots,
|
|
232
|
+
);
|
|
233
|
+
await store.close();
|
|
234
|
+
store = undefined;
|
|
235
|
+
state.transaction(() => {
|
|
236
|
+
if ("reference" in record) state.deleteContentPin(record.reference);
|
|
237
|
+
else state.deletePin(record.name);
|
|
238
|
+
state.deleteHold(record.owner);
|
|
239
|
+
});
|
|
240
|
+
} catch (cause) {
|
|
241
|
+
throw new HostError(
|
|
242
|
+
`Unpin incomplete for ${reference}: ${message(cause)}. Retry the same unpin; original Store ownership and recovery data are preserved. No GC requested.`,
|
|
243
|
+
1,
|
|
244
|
+
"RELEASE_FAILED",
|
|
245
|
+
"cleanup",
|
|
246
|
+
);
|
|
180
247
|
} finally {
|
|
181
|
-
|
|
182
|
-
|
|
248
|
+
try {
|
|
249
|
+
await store?.close();
|
|
250
|
+
} finally {
|
|
251
|
+
const hold = state.hold(record.owner);
|
|
252
|
+
if (hold) state.saveHold({ ...hold, pid: null });
|
|
253
|
+
}
|
|
183
254
|
}
|
|
184
255
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const details = pinDetails(pin);
|
|
192
|
-
idleHold(state, pin);
|
|
193
|
-
if (oldName === newName) return details;
|
|
194
|
-
if (state.pin(newName))
|
|
195
|
-
throw new HostError(`Pin name "${newName}" is occupied.`);
|
|
196
|
-
state.deletePin(oldName);
|
|
197
|
-
state.savePin({ ...pin, name: newName });
|
|
198
|
-
return { ...details, name: newName };
|
|
199
|
-
});
|
|
256
|
+
return {
|
|
257
|
+
reference,
|
|
258
|
+
releasedOwners: owners.map((record) => record.owner),
|
|
259
|
+
retentionClaimsReleased: true,
|
|
260
|
+
garbageCollectionGuaranteed: false,
|
|
261
|
+
};
|
|
200
262
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, extname, resolve } from "node:path";
|
|
3
|
+
import { CID } from "multiformats/cid";
|
|
4
|
+
import { CarBlockIterator } from "@ipld/car/iterator";
|
|
5
|
+
import { encodeBundleCar, memoryTree, readBytes } from "@ipab/bundle-builder";
|
|
6
|
+
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
7
|
+
import { bundleLimits } from "@ipab/bundle";
|
|
8
|
+
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
9
|
+
import { HostError } from "./errors.js";
|
|
10
|
+
import { importBundle, nodeError, selectedTree } from "./authoring.js";
|
|
11
|
+
import { captureSource, sourceFingerprint } from "./source-bundle.js";
|
|
12
|
+
import { exactCid } from "./state.js";
|
|
13
|
+
|
|
14
|
+
export async function publicationSource(
|
|
15
|
+
input: string,
|
|
16
|
+
store: IpfsStore,
|
|
17
|
+
): Promise<string> {
|
|
18
|
+
try {
|
|
19
|
+
CID.parse(input);
|
|
20
|
+
return exactCid(input);
|
|
21
|
+
} catch {
|
|
22
|
+
// Non-CID inputs must be explicit existing local sources.
|
|
23
|
+
}
|
|
24
|
+
const path = resolve(input);
|
|
25
|
+
let stat;
|
|
26
|
+
try {
|
|
27
|
+
stat = await lstat(path);
|
|
28
|
+
} catch (cause) {
|
|
29
|
+
if (nodeError(cause, "ENOENT"))
|
|
30
|
+
throw new HostError(
|
|
31
|
+
"Publication SOURCE must be an exact CID, a CAR, a regular file or a directory.",
|
|
32
|
+
);
|
|
33
|
+
throw cause;
|
|
34
|
+
}
|
|
35
|
+
if (stat.isSymbolicLink() || (!stat.isFile() && !stat.isDirectory()))
|
|
36
|
+
throw new HostError(
|
|
37
|
+
"Publication SOURCE must be a regular file or directory, never a symlink.",
|
|
38
|
+
);
|
|
39
|
+
if (stat.isFile() && extname(path).toLowerCase() === ".car")
|
|
40
|
+
return (await importBundle(path, () => Promise.resolve(store))).cid;
|
|
41
|
+
let tree;
|
|
42
|
+
let snapshot: Map<string, Uint8Array> | undefined;
|
|
43
|
+
if (stat.isDirectory()) {
|
|
44
|
+
try {
|
|
45
|
+
await lstat(resolve(path, ".bundle.yaml"));
|
|
46
|
+
tree = await selectedTree(path, undefined, resolve(path, "dist"), {});
|
|
47
|
+
} catch (cause) {
|
|
48
|
+
if (!nodeError(cause, "ENOENT")) throw cause;
|
|
49
|
+
snapshot = await captureSource(path, []);
|
|
50
|
+
tree = memoryTree(snapshot);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const name = basename(path);
|
|
54
|
+
const types: Record<string, string> = {
|
|
55
|
+
".json": "application/json",
|
|
56
|
+
".yaml": "application/yaml",
|
|
57
|
+
".yml": "application/yaml",
|
|
58
|
+
".md": "text/markdown",
|
|
59
|
+
".txt": "text/plain",
|
|
60
|
+
};
|
|
61
|
+
const contentType = types[extname(path).toLowerCase()];
|
|
62
|
+
if (!contentType || name.startsWith("."))
|
|
63
|
+
throw new HostError(
|
|
64
|
+
"File entry/type is ambiguous. Put the file in a directory with an explicit .bundle.yaml and referenced type file; standalone .json, .yaml, .yml, .md and .txt files are supported.",
|
|
65
|
+
);
|
|
66
|
+
const data = await readBytes(
|
|
67
|
+
await filesystemTree(dirname(path)),
|
|
68
|
+
name,
|
|
69
|
+
bundleLimits.bytes,
|
|
70
|
+
{},
|
|
71
|
+
);
|
|
72
|
+
const bytes = (value: unknown) =>
|
|
73
|
+
new TextEncoder().encode(JSON.stringify(value));
|
|
74
|
+
tree = memoryTree(
|
|
75
|
+
new Map([
|
|
76
|
+
[
|
|
77
|
+
".bundle.yaml",
|
|
78
|
+
bytes({ title: name, entry: name, type: ".bundle-type.yaml" }),
|
|
79
|
+
],
|
|
80
|
+
[".bundle-type.yaml", bytes({ contentType })],
|
|
81
|
+
[name, data],
|
|
82
|
+
]),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const encoded = await encodeBundleCar(tree);
|
|
86
|
+
try {
|
|
87
|
+
for await (const block of await CarBlockIterator.fromIterable(
|
|
88
|
+
encoded.stream,
|
|
89
|
+
))
|
|
90
|
+
await store.put(block.cid, block.bytes);
|
|
91
|
+
if (
|
|
92
|
+
snapshot &&
|
|
93
|
+
sourceFingerprint(snapshot) !==
|
|
94
|
+
sourceFingerprint(await captureSource(path, []))
|
|
95
|
+
)
|
|
96
|
+
throw new HostError(
|
|
97
|
+
"Publication source changed while capturing its Bundle; retry.",
|
|
98
|
+
);
|
|
99
|
+
return encoded.cid.toString();
|
|
100
|
+
} finally {
|
|
101
|
+
await encoded.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
package/src/runtime.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { ContextServer } from "./ipc.js";
|
|
|
10
10
|
import { loadApp, OutputSpace } from "./space.js";
|
|
11
11
|
import type { RunRecord, State } from "./state.js";
|
|
12
12
|
import { ExecutionLogs } from "./logs.js";
|
|
13
|
-
import { verifyStateStorage } from "./state-storage.js";
|
|
14
13
|
import type { BundleInspection } from "./context.js";
|
|
15
14
|
|
|
16
15
|
export interface Invocation {
|
|
@@ -122,7 +121,6 @@ export async function execute(
|
|
|
122
121
|
);
|
|
123
122
|
phase = "startup";
|
|
124
123
|
const runtime = join(state.directory, "runtime");
|
|
125
|
-
verifyStateStorage(state.directory);
|
|
126
124
|
await mkdir(runtime, { recursive: true, mode: 0o700 });
|
|
127
125
|
await mkdir(directory, { mode: 0o700 });
|
|
128
126
|
directoryCreated = true;
|
|
@@ -171,8 +169,8 @@ export async function execute(
|
|
|
171
169
|
stop(error);
|
|
172
170
|
},
|
|
173
171
|
invocation.appCid,
|
|
174
|
-
(name) => state.resolvePin(name),
|
|
175
172
|
options.resolveBundleReference,
|
|
173
|
+
app.supportedSchemas,
|
|
176
174
|
);
|
|
177
175
|
const result = await new Promise<{
|
|
178
176
|
code: number | null;
|
|
@@ -220,7 +218,9 @@ export async function execute(
|
|
|
220
218
|
"execution",
|
|
221
219
|
);
|
|
222
220
|
phase = "commit";
|
|
223
|
-
|
|
221
|
+
const outputCid = await output.finalize();
|
|
222
|
+
controller.signal.throwIfAborted();
|
|
223
|
+
record.outputCid = outputCid;
|
|
224
224
|
record.status = "succeeded";
|
|
225
225
|
exitCode = 0;
|
|
226
226
|
} catch (error) {
|
|
@@ -228,7 +228,8 @@ export async function execute(
|
|
|
228
228
|
error instanceof HostError
|
|
229
229
|
? error
|
|
230
230
|
: new HostError(message(error), 1, "EXECUTION_FAILED", phase);
|
|
231
|
-
record.status =
|
|
231
|
+
record.status =
|
|
232
|
+
cancellation || failure.code === "CANCELLED" ? "cancelled" : "failed";
|
|
232
233
|
record.error = {
|
|
233
234
|
phase: failure.phase === "state" ? phase : failure.phase,
|
|
234
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
|
+
}
|