@fungi.computer/bonsai 0.6.18 → 0.6.20

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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @fungi.computer/bonsai
2
2
 
3
+ ## 0.6.20
4
+
5
+ ### Patch Changes
6
+
7
+ - Changes since 0.6.19:
8
+
9
+ - fix(bonsai): write the first issue in the file editor
10
+ - fix(bonsai): keep phone clone popover inside viewport
11
+ - fix(bonsai): make issue navigation callback explicit
12
+ - fix(bonsai): give empty issues a repository next step
13
+
14
+ - Updated dependencies
15
+ - @fungi.computer/oyster@0.19.17
16
+
17
+ ## 0.6.19
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+ - Updated dependencies
23
+ - @fungi.computer/oyster@0.19.16
24
+ - @fungi.computer/trellis@0.10.3
25
+
3
26
  ## 0.6.18
4
27
 
5
28
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/bonsai",
3
- "version": "0.6.18",
3
+ "version": "0.6.20",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "type": "module",
6
6
  "description": "Bonsai: a git platform for many agents working at once, on Workers and Artifacts",
@@ -8,7 +8,7 @@
8
8
  "@fungi.computer/agar": "0.9.1",
9
9
  "@fungi.computer/caps": "0.10.1",
10
10
  "@fungi.computer/issues": "0.2.0",
11
- "@fungi.computer/oyster": "0.19.15",
11
+ "@fungi.computer/oyster": "0.19.17",
12
12
  "@fungi.computer/puffball": "0.5.5",
13
13
  "@fungi.computer/sigils": "0.3.0",
14
14
  "@fungi.computer/stipe": "0.1.1",
@@ -30,7 +30,7 @@
30
30
  "@visx/hierarchy": "3.12.0",
31
31
  "@fungi.computer/gills": "0.3.0",
32
32
  "@fungi.computer/nacre": "0.4.4",
33
- "@fungi.computer/trellis": "0.10.2",
33
+ "@fungi.computer/trellis": "0.10.3",
34
34
  "@fungi.computer/braid": "0.4.8",
35
35
  "@fungi.computer/workflows-wire": "0.4.8"
36
36
  },
@@ -0,0 +1,120 @@
1
+ import { afterEach, expect, it, vi } from "vitest";
2
+ import { createCapabilityRegistry } from "@fungi.computer/agar";
3
+ import { appsOpen, type AppOpenInput } from "@fungi.computer/agar/apps";
4
+ import { appMethods } from "@fungi.computer/agar/backend";
5
+ import {
6
+ fileSaveInput,
7
+ readFilesLocation,
8
+ type FileContent,
9
+ type FileSaveResult,
10
+ } from "@fungi.computer/agar/roles/files";
11
+ import { inspectIssueTree } from "@fungi.computer/issues";
12
+ import { jsonValue } from "../shared/contract.js";
13
+ import { connect } from "../web/transport.js";
14
+ import { writeFirstIssue } from "../web/first-issue.js";
15
+
16
+ const path = "issues/general/01-first-issue.md";
17
+ const empty: FileContent = {
18
+ ref: "main",
19
+ path,
20
+ commit: "a".repeat(40),
21
+ blob: null,
22
+ text: null,
23
+ size: 0,
24
+ binary: false,
25
+ version: null,
26
+ };
27
+ afterEach(() => {
28
+ connect(null);
29
+ });
30
+
31
+ function fixture(
32
+ file = empty,
33
+ result: FileSaveResult = { kind: "saved", revision: 1, state: "pending" },
34
+ editor = true,
35
+ ) {
36
+ const capabilities = createCapabilityRegistry();
37
+ const open = vi.fn<(input: AppOpenInput) => Promise<void>>(() =>
38
+ Promise.resolve(),
39
+ );
40
+ const saves: ReturnType<typeof fileSaveInput.parse>[] = [];
41
+ capabilities.provide(appsOpen, {
42
+ open,
43
+ role: () => Promise.resolve(editor ? { displayName: "Inkcap" } : null),
44
+ });
45
+ capabilities.provide(appMethods, {
46
+ call: (method, input) => {
47
+ if (method === "files.read")
48
+ return Promise.resolve(jsonValue.parse(file));
49
+ if (method !== "files.save") throw new Error("Unexpected method");
50
+ saves.push(fileSaveInput.parse(JSON.parse(input)));
51
+ return Promise.resolve(jsonValue.parse(result));
52
+ },
53
+ });
54
+ connect({ capabilities });
55
+ return { open, saves };
56
+ }
57
+
58
+ it("creates a valid issue at the selected repository branch and opens that file in Inkcap", async () => {
59
+ const f = fixture();
60
+ await writeFirstIssue("pond", "feature");
61
+ const saved = fileSaveInput.parse(f.saves[0]);
62
+ expect(saved).toMatchObject({
63
+ repo: "pond",
64
+ branch: "feature",
65
+ path,
66
+ baseBlob: null,
67
+ baseCommit: empty.commit,
68
+ revision: null,
69
+ });
70
+ expect(
71
+ inspectIssueTree({ "general/01-first-issue.md": saved.text }).diagnostics,
72
+ ).toEqual([]);
73
+ const opened = f.open.mock.calls[0]?.[0];
74
+ expect(opened).toMatchObject({ role: "files" });
75
+ expect(
76
+ opened?.intent.kind === "navigate" &&
77
+ readFilesLocation(opened.intent.params),
78
+ ).toEqual({ repository: "pond", branch: "feature", path });
79
+ });
80
+
81
+ it.each([
82
+ { ...empty, blob: "b".repeat(40), text: "Existing issue" },
83
+ {
84
+ ...empty,
85
+ version: 1,
86
+ pending: {
87
+ text: "Unfinished draft",
88
+ revision: 1,
89
+ state: "pending" as const,
90
+ },
91
+ },
92
+ ])("opens existing work without overwriting it", async (file) => {
93
+ const f = fixture(file);
94
+ await writeFirstIssue("pond", "main");
95
+ expect(f.saves).toHaveLength(0);
96
+ expect(f.open).toHaveBeenCalledOnce();
97
+ });
98
+
99
+ it.each<FileSaveResult>([
100
+ { kind: "conflict", revision: 1 },
101
+ { kind: "refused", reason: "not-source-writer" },
102
+ { kind: "failed", revision: 1, reason: "sync_failed" },
103
+ ])(
104
+ "does not report an editor handoff after a refused creation",
105
+ async (result) => {
106
+ const f = fixture(empty, result);
107
+ await expect(writeFirstIssue("pond", "main")).rejects.toThrow(
108
+ "could not be created",
109
+ );
110
+ expect(f.open).not.toHaveBeenCalled();
111
+ },
112
+ );
113
+
114
+ it("does not create a file when no editor can open it", async () => {
115
+ const f = fixture(empty, undefined, false);
116
+ await expect(writeFirstIssue("pond", "main")).rejects.toThrow(
117
+ "Choose a file editor",
118
+ );
119
+ expect(f.saves).toHaveLength(0);
120
+ });
@@ -0,0 +1,63 @@
1
+ import { fileContent, fileSaveResult } from "@fungi.computer/agar/roles/files";
2
+ import { callMethod, editInFilesEditor, filesEditor } from "./transport.js";
3
+
4
+ const path = "issues/general/01-first-issue.md";
5
+
6
+ /** Create the first issue through the editor's save door, then open it there. */
7
+ export async function writeFirstIssue(repo: string, branch: string) {
8
+ if ((await filesEditor()) === null)
9
+ throw new Error("Choose a file editor in your App settings first.");
10
+ const file = await callMethod(
11
+ "files.read",
12
+ { repo, ref: branch, path },
13
+ fileContent,
14
+ );
15
+ // A repeated click or an earlier editor draft must never replace someone's text.
16
+ if (file.blob === null && file.pending === undefined) {
17
+ const result = await callMethod(
18
+ "files.save",
19
+ {
20
+ repo,
21
+ branch,
22
+ path,
23
+ baseBlob: null,
24
+ baseCommit: file.commit,
25
+ revision: file.version,
26
+ text: `---
27
+ id: general-01
28
+ title: "First issue"
29
+ type: task
30
+ status: needs-triage
31
+ priority: p2
32
+ created: ${new Date().toISOString().slice(0, 10)}
33
+ assignee: null
34
+ areas: [general]
35
+ blocked_by: []
36
+ ---
37
+
38
+ # First issue
39
+
40
+ ## Outcome
41
+
42
+ Describe what you want to change.
43
+
44
+ ## Context
45
+
46
+ Add any details that will help someone understand the issue.
47
+
48
+ ## Acceptance criteria
49
+
50
+ - [ ] Describe what success looks like.
51
+
52
+ ## Verification
53
+
54
+ - [ ] Describe how to check the result.
55
+ `,
56
+ },
57
+ fileSaveResult,
58
+ );
59
+ if (result.kind !== "saved" && result.kind !== "synced")
60
+ throw new Error("The issue could not be created. Try again.");
61
+ }
62
+ await editInFilesEditor(repo, branch, path);
63
+ }
@@ -20,7 +20,8 @@ import {
20
20
  type IssueIndexRecord,
21
21
  type IssueStatus,
22
22
  } from "@fungi.computer/issues";
23
- import { useMemo } from "react";
23
+ import { useMemo, useState } from "react";
24
+ import { writeFirstIssue } from "./first-issue.js";
24
25
  import { useIssueFiles } from "./api.js";
25
26
  import { Failure, Loading } from "./parts.js";
26
27
  import { href, Link } from "./router.js";
@@ -143,6 +144,8 @@ export function IssuesPanel({
143
144
  refName: string;
144
145
  open: string | null;
145
146
  }) {
147
+ const [creating, setCreating] = useState(false);
148
+ const [creationError, setCreationError] = useState<string | null>(null);
146
149
  const files = useIssueFiles(repo, refName);
147
150
  const report = useMemo(
148
151
  () => (files.data ? inspectIssueTree(files.data.files) : null),
@@ -160,12 +163,34 @@ export function IssuesPanel({
160
163
  );
161
164
  if (report === null || Object.keys(files.data.files).length === 0)
162
165
  return (
163
- <EmptyState
164
- variant="panel"
165
- headingLevel={3}
166
- title="No issues yet"
167
- description="Issues live in the repository as Markdown under issues/<effort>/<NN>-<slug>.md, so agents read and update them with git."
168
- />
166
+ <div>
167
+ <EmptyState
168
+ variant="panel"
169
+ headingLevel={3}
170
+ title="No issues yet"
171
+ description="Issues are Markdown files in your repo. Write the first one."
172
+ primaryAction={{
173
+ label: "Write the first issue",
174
+ pending: creating,
175
+ onSelect: () => {
176
+ setCreating(true);
177
+ setCreationError(null);
178
+ void writeFirstIssue(repo, refName)
179
+ .catch((error: unknown) => {
180
+ setCreationError(
181
+ error instanceof Error
182
+ ? error.message
183
+ : "The editor could not open",
184
+ );
185
+ })
186
+ .finally(() => {
187
+ setCreating(false);
188
+ });
189
+ },
190
+ }}
191
+ />
192
+ {creationError === null ? null : <p role="alert">{creationError}</p>}
193
+ </div>
169
194
  );
170
195
  const opened = open === null ? undefined : files.data.files[open];
171
196
  if (open !== null && opened !== undefined)
@@ -154,7 +154,10 @@ export function RepoNavigation({
154
154
  </span>
155
155
  ) : null}
156
156
  </div>
157
- <div className="flex min-w-0 flex-wrap items-center gap-2">
157
+ <PopoverAnchor
158
+ className="flex min-w-0 flex-wrap items-center gap-2"
159
+ ref={anchor}
160
+ >
158
161
  {working > 0 ? (
159
162
  <Status
160
163
  aria-label="Recent repository pushes"
@@ -191,9 +194,16 @@ export function RepoNavigation({
191
194
  </Select>
192
195
  </div>
193
196
  <div className="hidden max-w-sm md:block" ref={desktopClone}>
194
- <CopyField value={clone} label="Clone" />
197
+ <CopyField
198
+ value={clone}
199
+ fieldLabel="Clone repository"
200
+ displayValue={detail.cloneUrl}
201
+ />
202
+ <p className="mt-1 text-sm text-[var(--stipe-fg-muted)]">
203
+ Run from my-oyster.
204
+ </p>
195
205
  </div>
196
- <PopoverAnchor className="md:hidden" ref={anchor}>
206
+ <div className="md:hidden">
197
207
  <Button
198
208
  ref={cloneButton}
199
209
  variant="outline"
@@ -210,16 +220,23 @@ export function RepoNavigation({
210
220
  open={cloneOpen}
211
221
  side="bottom"
212
222
  id="repo-clone"
213
- className="w-72 max-w-[calc(100vw-2rem)]"
223
+ className="z-20 w-72 max-w-[calc(100vw-2rem)]"
214
224
  role="region"
215
225
  aria-label="Clone repository"
216
226
  >
217
227
  <div ref={phoneClone}>
218
- <CopyField value={clone} />
228
+ <CopyField
229
+ value={clone}
230
+ fieldLabel="Clone repository"
231
+ displayValue={detail.cloneUrl}
232
+ />
233
+ <p className="mt-1 text-sm text-[var(--stipe-fg-muted)]">
234
+ Run from my-oyster.
235
+ </p>
219
236
  </div>
220
237
  </Popover>
221
- </PopoverAnchor>
222
- </div>
238
+ </div>
239
+ </PopoverAnchor>
223
240
  </header>
224
241
  <div className="flex min-w-0 flex-col items-stretch gap-2 sm:flex-row sm:items-center sm:justify-between">
225
242
  <NavigationRail