@fungi.computer/inkcap 0.8.7 → 0.8.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.
- package/backend/methods.ts +47 -8
- package/backend/test/methods.test.ts +83 -0
- package/dist/assets/{FileTab-DV6u0rec.js → FileTab-B6VHOcFH.js} +2 -2
- package/dist/assets/{InkcapFileTree-BFg3D0YN.js → InkcapFileTree-CwypCDIG.js} +1 -1
- package/dist/assets/{InkcapRepositoryApp-D5DYHud2.js → InkcapRepositoryApp-JQKfc9Cx.js} +1 -1
- package/dist/assets/{folder-open-vITejO7G.js → folder-open-CvN8pdnj.js} +1 -1
- package/dist/assets/index-8frW2hxP.js +2 -0
- package/dist/assets/index-BKqOQvZ-.css +2 -0
- package/dist/assets/{refresh-cw-BRt_5ZtY.js → refresh-cw-DmzmzhHF.js} +1 -1
- package/dist/assets/{tree-path-D47zLaQq.js → tree-path-C6dPmEG1.js} +2 -2
- package/dist/assets/{useFileTree-Cj1d2pkx.js → useFileTree-C8TMdLib.js} +1 -1
- package/dist/assets/{useForm-DmUv5JjG.js → useForm-Cj_w9cA2.js} +1 -1
- package/dist/index.html +4 -4
- package/package.json +4 -4
- package/dist/assets/index-BVzEVOIH.css +0 -2
- package/dist/assets/index-CCQdYVlj.js +0 -2
package/backend/methods.ts
CHANGED
|
@@ -94,6 +94,14 @@ const refusal = z.union([
|
|
|
94
94
|
"not_found",
|
|
95
95
|
]),
|
|
96
96
|
}),
|
|
97
|
+
z.strictObject({
|
|
98
|
+
error: z.literal("not_found"),
|
|
99
|
+
message: z.string(),
|
|
100
|
+
}),
|
|
101
|
+
z.strictObject({
|
|
102
|
+
error: z.literal("parent_not_found"),
|
|
103
|
+
message: z.string(),
|
|
104
|
+
}),
|
|
97
105
|
z.strictObject({
|
|
98
106
|
error: z.literal("attachment_budget_exceeded"),
|
|
99
107
|
kind: z.literal("write"),
|
|
@@ -105,14 +113,33 @@ const readReply = z.union([readOutput, refusal]);
|
|
|
105
113
|
const writeReply = z.union([writeOutputSchema, refusal]);
|
|
106
114
|
// The host always supplies callable bindings; admission is checked on invocation.
|
|
107
115
|
const bindingNotGranted = z.object({ code: z.literal("binding_not_granted") });
|
|
116
|
+
// The Computer's file system names an absent file or parent folder ENOENT. It is
|
|
117
|
+
// a domain answer, so it must reach the Agent as a refusal; thrown, the sandbox
|
|
118
|
+
// reports only "failed for an unrecognized reason".
|
|
119
|
+
const pathAbsent = z.object({ code: z.literal("ENOENT") });
|
|
120
|
+
function parentNotFound(path: string) {
|
|
121
|
+
const folder = path.slice(0, path.lastIndexOf("/")) || "/";
|
|
122
|
+
return {
|
|
123
|
+
error: "parent_not_found" as const,
|
|
124
|
+
message: `The folder ${folder} does not exist; Inkcap can't create folders yet. Save into an existing folder (for example /notes.md at the top level), or list folders with listFiles.`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function fileGone(path: string) {
|
|
128
|
+
return {
|
|
129
|
+
error: "not_found" as const,
|
|
130
|
+
message: `The file ${path} no longer exists on the Computer. Read its directory again, or write it as a new file without expectedContent.`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
108
133
|
async function computerCall(
|
|
109
134
|
call: () => Promise<WhistleJsonValue>,
|
|
135
|
+
absent: WhistleJsonValue = { error: "not_found" },
|
|
110
136
|
): Promise<WhistleJsonValue> {
|
|
111
137
|
try {
|
|
112
138
|
return await call();
|
|
113
139
|
} catch (cause) {
|
|
114
140
|
if (bindingNotGranted.safeParse(cause).success)
|
|
115
141
|
return { error: "not_granted" };
|
|
142
|
+
if (pathAbsent.safeParse(cause).success) return absent;
|
|
116
143
|
throw cause;
|
|
117
144
|
}
|
|
118
145
|
}
|
|
@@ -199,7 +226,7 @@ export const appBackend = defineAppBackend({
|
|
|
199
226
|
}),
|
|
200
227
|
writeFile: defineAppMethod({
|
|
201
228
|
description:
|
|
202
|
-
"Write UTF-8 text on the attached Computer. Supply expectedContent for a compare-and-swap; combined content is limited to 48 KiB. The host owns attribution and the attachment write budget.",
|
|
229
|
+
"Write UTF-8 text on the attached Computer. The folder must already exist (Inkcap cannot create folders): a missing folder is refused as parent_not_found, and the path is on the Computer, not the host machine. Supply expectedContent for a compare-and-swap; combined content is limited to 48 KiB. The host owns attribution and the attachment write budget.",
|
|
203
230
|
effect: "write",
|
|
204
231
|
requires: ["computer.writeFile"],
|
|
205
232
|
input: writeInput,
|
|
@@ -212,7 +239,10 @@ export const appBackend = defineAppBackend({
|
|
|
212
239
|
? {
|
|
213
240
|
id: "refused",
|
|
214
241
|
title: "Inkcap could not write the file",
|
|
215
|
-
detail:
|
|
242
|
+
detail:
|
|
243
|
+
output.error === "parent_not_found"
|
|
244
|
+
? "That folder does not exist on the Computer"
|
|
245
|
+
: output.error,
|
|
216
246
|
tone: "error",
|
|
217
247
|
}
|
|
218
248
|
: {
|
|
@@ -224,12 +254,21 @@ export const appBackend = defineAppBackend({
|
|
|
224
254
|
},
|
|
225
255
|
},
|
|
226
256
|
},
|
|
227
|
-
handler: async (input, context: InkcapBackendContext, caller) =>
|
|
228
|
-
caller.computerId === null
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
257
|
+
handler: async (input, context: InkcapBackendContext, caller) => {
|
|
258
|
+
if (caller.computerId === null)
|
|
259
|
+
return refusal.parse({ error: "not_granted" });
|
|
260
|
+
// An edit of an existing file (expectedContent) that is missing means
|
|
261
|
+
// the file is gone; only a new path can lack its folder.
|
|
262
|
+
const absent =
|
|
263
|
+
input.expectedContent === undefined
|
|
264
|
+
? parentNotFound(input.path)
|
|
265
|
+
: fileGone(input.path);
|
|
266
|
+
const reply = writeReply.parse(
|
|
267
|
+
await computerCall(() => context.env.COMPUTER.write(input), absent),
|
|
268
|
+
);
|
|
269
|
+
// Hosts answer a missing path as plain not_found.
|
|
270
|
+
return "error" in reply && reply.error === "not_found" ? absent : reply;
|
|
271
|
+
},
|
|
233
272
|
}),
|
|
234
273
|
},
|
|
235
274
|
});
|
|
@@ -520,3 +520,86 @@ it("preserves the original marker failure without any provider or retry", async
|
|
|
520
520
|
).rejects.toBe(failure);
|
|
521
521
|
expect(writes).toBe(1);
|
|
522
522
|
});
|
|
523
|
+
|
|
524
|
+
it("refuses a missing folder or file as not_found instead of throwing an opaque failure", async () => {
|
|
525
|
+
const absent = () =>
|
|
526
|
+
Promise.reject(
|
|
527
|
+
Object.assign(new Error("parent directory missing: /home/a/b.md"), {
|
|
528
|
+
code: "ENOENT",
|
|
529
|
+
}),
|
|
530
|
+
);
|
|
531
|
+
const context = {
|
|
532
|
+
activity,
|
|
533
|
+
documentsChanged,
|
|
534
|
+
env: {
|
|
535
|
+
...unrelated,
|
|
536
|
+
COMPUTER: { ...unrelated.COMPUTER, read: absent, write: absent },
|
|
537
|
+
},
|
|
538
|
+
};
|
|
539
|
+
const refused = await appBackend.call(
|
|
540
|
+
"writeFile",
|
|
541
|
+
{ path: "/home/a/b.md", content: "hi" },
|
|
542
|
+
context,
|
|
543
|
+
caller,
|
|
544
|
+
);
|
|
545
|
+
expect(refused).toMatchObject({ error: "parent_not_found" });
|
|
546
|
+
expect(JSON.stringify(refused)).toContain(
|
|
547
|
+
"The folder /home/a does not exist; Inkcap can't create folders yet.",
|
|
548
|
+
);
|
|
549
|
+
// Hosts that answer in-band (not by throwing) get the same refusal.
|
|
550
|
+
const inBand = await appBackend.call(
|
|
551
|
+
"writeFile",
|
|
552
|
+
{ path: "/x/y.md", content: "hi" },
|
|
553
|
+
{
|
|
554
|
+
...context,
|
|
555
|
+
env: {
|
|
556
|
+
...unrelated,
|
|
557
|
+
COMPUTER: {
|
|
558
|
+
...unrelated.COMPUTER,
|
|
559
|
+
write: () => Promise.resolve({ error: "not_found" }),
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
caller,
|
|
564
|
+
);
|
|
565
|
+
expect(inBand).toMatchObject({ error: "parent_not_found" });
|
|
566
|
+
expect(JSON.stringify(inBand)).toContain("The folder /x does not exist");
|
|
567
|
+
expect(JSON.stringify(inBand)).toContain("for example /notes.md");
|
|
568
|
+
// An edit of a file that was deleted is not a folder problem.
|
|
569
|
+
const gone = await appBackend.call(
|
|
570
|
+
"writeFile",
|
|
571
|
+
{ path: "/x/y.md", content: "new", expectedContent: "old" },
|
|
572
|
+
{
|
|
573
|
+
...context,
|
|
574
|
+
env: {
|
|
575
|
+
...unrelated,
|
|
576
|
+
COMPUTER: {
|
|
577
|
+
...unrelated.COMPUTER,
|
|
578
|
+
write: () => Promise.resolve({ error: "not_found" }),
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
caller,
|
|
583
|
+
);
|
|
584
|
+
expect(gone).toMatchObject({ error: "not_found" });
|
|
585
|
+
expect(JSON.stringify(gone)).toContain("/x/y.md no longer exists");
|
|
586
|
+
expect(JSON.stringify(gone)).not.toContain("folder");
|
|
587
|
+
await expect(
|
|
588
|
+
appBackend.call("readFile", { path: "/home/a/b.md" }, context, caller),
|
|
589
|
+
).resolves.toEqual({ error: "not_found" });
|
|
590
|
+
const broken = () => Promise.reject(new Error("disk on fire"));
|
|
591
|
+
await expect(
|
|
592
|
+
appBackend.call(
|
|
593
|
+
"writeFile",
|
|
594
|
+
{ path: "/a", content: "hi" },
|
|
595
|
+
{
|
|
596
|
+
...context,
|
|
597
|
+
env: {
|
|
598
|
+
...unrelated,
|
|
599
|
+
COMPUTER: { ...unrelated.COMPUTER, write: broken },
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
caller,
|
|
603
|
+
),
|
|
604
|
+
).rejects.toThrow("disk on fire");
|
|
605
|
+
});
|