@fungi.computer/inkcap 0.12.0 → 0.13.1

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.
@@ -27,6 +27,8 @@ import {
27
27
  readBytesInputSchema,
28
28
  writeOutputSchema,
29
29
  mkdirOutputSchema,
30
+ gitChangesInputSchema,
31
+ gitChangesOutputSchema,
30
32
  } from "@fungi.computer/computer-contract";
31
33
  export type InkcapBackendContext = {
32
34
  activity: DocumentActivityStore;
@@ -38,6 +40,9 @@ export type InkcapBackendContext = {
38
40
  read(input: z.output<typeof readInput>): Promise<WhistleJsonValue>;
39
41
  write(input: z.output<typeof writeInput>): Promise<WhistleJsonValue>;
40
42
  mkdir(input: { path: string }): Promise<WhistleJsonValue>;
43
+ gitChanges(
44
+ input: z.output<typeof gitChangesInput>,
45
+ ): Promise<WhistleJsonValue>;
41
46
  };
42
47
  };
43
48
  };
@@ -61,6 +66,9 @@ const readInput = readBytesInputSchema.extend({
61
66
  .max(128 * 1024)
62
67
  .default(128 * 1024),
63
68
  });
69
+ const gitChangesInput = gitChangesInputSchema.extend({
70
+ path: computerPath.default("/"),
71
+ });
64
72
  const text = z.string().max(48 * 1024);
65
73
  const writeInput = z
66
74
  .strictObject({
@@ -114,6 +122,7 @@ const listReply = z.union([listOutputSchema, refusal]);
114
122
  const readReply = z.union([readOutput, refusal]);
115
123
  const writeReply = z.union([writeOutputSchema, refusal]);
116
124
  const mkdirReply = z.union([mkdirOutputSchema, refusal]);
125
+ const gitChangesReply = z.union([gitChangesOutputSchema, refusal]);
117
126
  // The host always supplies callable bindings; admission is checked on invocation.
118
127
  const bindingNotGranted = z.object({ code: z.literal("binding_not_granted") });
119
128
  // The Computer's file system names an absent file or parent folder ENOENT. It is
@@ -215,6 +224,20 @@ export const appBackend = defineAppBackend({
215
224
  await computerCall(() => context.env.COMPUTER.list(input)),
216
225
  ),
217
226
  }),
227
+ gitChanges: defineAppMethod({
228
+ description:
229
+ "Read everything changed in the Git repository holding one folder on the attached Computer, for review before commit or push: changed files and one unified diff against the last commit, untracked files as additions. Read-only; no Computer selector is accepted.",
230
+ effect: "read",
231
+ requires: ["computer.readFile"],
232
+ input: gitChangesInput,
233
+ output: gitChangesReply,
234
+ handler: async (input, context: InkcapBackendContext, caller) =>
235
+ caller.computerId === null
236
+ ? refusal.parse({ error: "not_granted" })
237
+ : gitChangesReply.parse(
238
+ await computerCall(() => context.env.COMPUTER.gitChanges(input)),
239
+ ),
240
+ }),
218
241
  readFile: defineAppMethod({
219
242
  description:
220
243
  "Read up to 128 KiB of a file on the attached Computer as base64. Use byteOffset for the next chunk.",
@@ -32,6 +32,7 @@ it("projects the saved Recent Files source with stable identities and its own cu
32
32
  read: unavailable,
33
33
  write: unavailable,
34
34
  mkdir: unavailable,
35
+ gitChanges: unavailable,
35
36
  },
36
37
  },
37
38
  };
@@ -42,6 +42,7 @@ const unrelated = {
42
42
  read: unavailable,
43
43
  write: unavailable,
44
44
  mkdir: unavailable,
45
+ gitChanges: unavailable,
45
46
  },
46
47
  };
47
48
  const emptyMarker = () =>
@@ -89,6 +90,61 @@ it("lists files only through the admitted pinned Computer binding", async () =>
89
90
  expect(calls).toEqual([{ path: "/", limit: 100, offset: 0 }]);
90
91
  });
91
92
 
93
+ it("reads repository changes only through the admitted pinned Computer binding", async () => {
94
+ const calls: unknown[] = [];
95
+ const reply = {
96
+ kind: "changes" as const,
97
+ root: "/work",
98
+ branch: "main",
99
+ files: [{ path: "a.txt", status: "modified" as const }],
100
+ patch: "diff --git a/a.txt b/a.txt\n",
101
+ truncated: false,
102
+ };
103
+ const context = (gitChanges: ComputerBinding["gitChanges"]) => ({
104
+ activity,
105
+ documentsChanged,
106
+ env: { ...unrelated, COMPUTER: { ...unrelated.COMPUTER, gitChanges } },
107
+ });
108
+ await expect(
109
+ appBackend.call(
110
+ "gitChanges",
111
+ { path: "/work" },
112
+ context((input) => {
113
+ calls.push(input);
114
+ return Promise.resolve(reply);
115
+ }),
116
+ caller,
117
+ ),
118
+ ).resolves.toEqual(reply);
119
+ expect(calls).toEqual([{ path: "/work" }]);
120
+ await expect(
121
+ appBackend.call(
122
+ "gitChanges",
123
+ {},
124
+ context((input) => {
125
+ calls.push(input);
126
+ return Promise.resolve({ kind: "not_repository" });
127
+ }),
128
+ caller,
129
+ ),
130
+ ).resolves.toEqual({ kind: "not_repository" });
131
+ expect(calls[1]).toEqual({ path: "/" });
132
+ await expect(
133
+ appBackend.call(
134
+ "gitChanges",
135
+ { path: "/work/../etc" },
136
+ context(unavailable),
137
+ caller,
138
+ ),
139
+ ).rejects.toThrow();
140
+ await expect(
141
+ appBackend.call("gitChanges", { path: "/work" }, context(unavailable), {
142
+ ...caller,
143
+ computerId: null,
144
+ }),
145
+ ).resolves.toEqual({ error: "not_granted" });
146
+ });
147
+
92
148
  it("does not dispatch when the caller has no pinned Computer", async () => {
93
149
  let calls = 0;
94
150
  const result = await appBackend.call(
@@ -199,6 +255,7 @@ it.each([
199
255
  read: invoke,
200
256
  write: invoke,
201
257
  mkdir: invoke,
258
+ gitChanges: invoke,
202
259
  },
203
260
  },
204
261
  },
@@ -211,7 +268,12 @@ it.each([
211
268
  it("edits repositories only through Bonsai, never through its own Git methods", () => {
212
269
  const methods = Object.keys(buildAppApi(appBackend).methods);
213
270
  expect(methods).toEqual(
214
- expect.arrayContaining(["listFiles", "readFile", "writeFile"]),
271
+ expect.arrayContaining([
272
+ "listFiles",
273
+ "readFile",
274
+ "writeFile",
275
+ "gitChanges",
276
+ ]),
215
277
  );
216
278
  for (const retired of [
217
279
  "snapshot",
@@ -278,6 +340,7 @@ it.each([
278
340
  read: denied,
279
341
  write: denied,
280
342
  mkdir: denied,
343
+ gitChanges: denied,
281
344
  },
282
345
  },
283
346
  },
@@ -322,6 +385,7 @@ it.each([
322
385
  read: failed,
323
386
  write: failed,
324
387
  mkdir: failed,
388
+ gitChanges: failed,
325
389
  },
326
390
  },
327
391
  },