zelio-cli 0.0.0-stage → 0.1.0-beta.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.
Files changed (175) hide show
  1. package/README.md +178 -2
  2. package/dist/attachments.js +121 -0
  3. package/dist/attachments.js.map +1 -0
  4. package/dist/cli.js +469 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/cloud/board.js +311 -0
  7. package/dist/cloud/board.js.map +1 -0
  8. package/dist/cloud/command.js +260 -0
  9. package/dist/cloud/command.js.map +1 -0
  10. package/dist/cloud/config.js +132 -0
  11. package/dist/cloud/config.js.map +1 -0
  12. package/dist/cloud/credentials.js +134 -0
  13. package/dist/cloud/credentials.js.map +1 -0
  14. package/dist/cloud/login.js +165 -0
  15. package/dist/cloud/login.js.map +1 -0
  16. package/dist/cloud/pair.js +110 -0
  17. package/dist/cloud/pair.js.map +1 -0
  18. package/dist/cloud/pkce.js +16 -0
  19. package/dist/cloud/pkce.js.map +1 -0
  20. package/dist/cloud/push-nudge.js +63 -0
  21. package/dist/cloud/push-nudge.js.map +1 -0
  22. package/dist/cloud/relay.js +129 -0
  23. package/dist/cloud/relay.js.map +1 -0
  24. package/dist/cloud/token.js +66 -0
  25. package/dist/cloud/token.js.map +1 -0
  26. package/dist/cloud/tunnel.js +410 -0
  27. package/dist/cloud/tunnel.js.map +1 -0
  28. package/dist/db/db.js +1614 -0
  29. package/dist/db/db.js.map +1 -0
  30. package/dist/db/lifecycle.js +133 -0
  31. package/dist/db/lifecycle.js.map +1 -0
  32. package/dist/limits.js +35 -0
  33. package/dist/limits.js.map +1 -0
  34. package/dist/metrics.js +30 -0
  35. package/dist/metrics.js.map +1 -0
  36. package/dist/orchestrator/claude-session.js +208 -0
  37. package/dist/orchestrator/claude-session.js.map +1 -0
  38. package/dist/orchestrator/codex-session.js +326 -0
  39. package/dist/orchestrator/codex-session.js.map +1 -0
  40. package/dist/orchestrator/contract.js +181 -0
  41. package/dist/orchestrator/contract.js.map +1 -0
  42. package/dist/orchestrator/explore.js +176 -0
  43. package/dist/orchestrator/explore.js.map +1 -0
  44. package/dist/orchestrator/new-task-prompt.js +51 -0
  45. package/dist/orchestrator/new-task-prompt.js.map +1 -0
  46. package/dist/orchestrator/pi-session.js +228 -0
  47. package/dist/orchestrator/pi-session.js.map +1 -0
  48. package/dist/orchestrator/prompt.js +110 -0
  49. package/dist/orchestrator/prompt.js.map +1 -0
  50. package/dist/orchestrator/research.js +178 -0
  51. package/dist/orchestrator/research.js.map +1 -0
  52. package/dist/orchestrator/runtime.js +1054 -0
  53. package/dist/orchestrator/runtime.js.map +1 -0
  54. package/dist/orchestrator/session.js +2 -0
  55. package/dist/orchestrator/session.js.map +1 -0
  56. package/dist/orchestrator/types.js +2 -0
  57. package/dist/orchestrator/types.js.map +1 -0
  58. package/dist/orchestrator/web.js +276 -0
  59. package/dist/orchestrator/web.js.map +1 -0
  60. package/dist/repo/index.js +188 -0
  61. package/dist/repo/index.js.map +1 -0
  62. package/dist/repo/instructions.js +52 -0
  63. package/dist/repo/instructions.js.map +1 -0
  64. package/dist/repo/linked-boards.js +252 -0
  65. package/dist/repo/linked-boards.js.map +1 -0
  66. package/dist/run/actions.js +233 -0
  67. package/dist/run/actions.js.map +1 -0
  68. package/dist/run/bash-guard.js +183 -0
  69. package/dist/run/bash-guard.js.map +1 -0
  70. package/dist/run/claude-runtime.js +242 -0
  71. package/dist/run/claude-runtime.js.map +1 -0
  72. package/dist/run/claude-stream.js +306 -0
  73. package/dist/run/claude-stream.js.map +1 -0
  74. package/dist/run/codex-client.js +200 -0
  75. package/dist/run/codex-client.js.map +1 -0
  76. package/dist/run/codex-runtime.js +366 -0
  77. package/dist/run/codex-runtime.js.map +1 -0
  78. package/dist/run/context.js +87 -0
  79. package/dist/run/context.js.map +1 -0
  80. package/dist/run/diff.js +196 -0
  81. package/dist/run/diff.js.map +1 -0
  82. package/dist/run/evidence.js +48 -0
  83. package/dist/run/evidence.js.map +1 -0
  84. package/dist/run/finish.js +393 -0
  85. package/dist/run/finish.js.map +1 -0
  86. package/dist/run/harness-runtime.js +28 -0
  87. package/dist/run/harness-runtime.js.map +1 -0
  88. package/dist/run/harnesses.js +273 -0
  89. package/dist/run/harnesses.js.map +1 -0
  90. package/dist/run/issue.js +79 -0
  91. package/dist/run/issue.js.map +1 -0
  92. package/dist/run/keep-awake.js +58 -0
  93. package/dist/run/keep-awake.js.map +1 -0
  94. package/dist/run/lead.js +200 -0
  95. package/dist/run/lead.js.map +1 -0
  96. package/dist/run/manager.js +1709 -0
  97. package/dist/run/manager.js.map +1 -0
  98. package/dist/run/mentions.js +35 -0
  99. package/dist/run/mentions.js.map +1 -0
  100. package/dist/run/merge-watch.js +394 -0
  101. package/dist/run/merge-watch.js.map +1 -0
  102. package/dist/run/models.js +88 -0
  103. package/dist/run/models.js.map +1 -0
  104. package/dist/run/phases.js +23 -0
  105. package/dist/run/phases.js.map +1 -0
  106. package/dist/run/pi-rpc.js +412 -0
  107. package/dist/run/pi-rpc.js.map +1 -0
  108. package/dist/run/pr-merge.js +121 -0
  109. package/dist/run/pr-merge.js.map +1 -0
  110. package/dist/run/profiles.js +43 -0
  111. package/dist/run/profiles.js.map +1 -0
  112. package/dist/run/prompt.js +345 -0
  113. package/dist/run/prompt.js.map +1 -0
  114. package/dist/run/pull-request.js +23 -0
  115. package/dist/run/pull-request.js.map +1 -0
  116. package/dist/run/result-tool.js +93 -0
  117. package/dist/run/result-tool.js.map +1 -0
  118. package/dist/run/result.js +113 -0
  119. package/dist/run/result.js.map +1 -0
  120. package/dist/run/retro.js +346 -0
  121. package/dist/run/retro.js.map +1 -0
  122. package/dist/run/settings.js +25 -0
  123. package/dist/run/settings.js.map +1 -0
  124. package/dist/run/thinking.js +41 -0
  125. package/dist/run/thinking.js.map +1 -0
  126. package/dist/run/types.js +2 -0
  127. package/dist/run/types.js.map +1 -0
  128. package/dist/run/workflow.js +266 -0
  129. package/dist/run/workflow.js.map +1 -0
  130. package/dist/run/worktree.js +354 -0
  131. package/dist/run/worktree.js.map +1 -0
  132. package/dist/server/app.js +2503 -0
  133. package/dist/server/app.js.map +1 -0
  134. package/dist/server/auth.js +93 -0
  135. package/dist/server/auth.js.map +1 -0
  136. package/dist/server/demo.js +96 -0
  137. package/dist/server/demo.js.map +1 -0
  138. package/dist/server/idempotency.js +104 -0
  139. package/dist/server/idempotency.js.map +1 -0
  140. package/dist/server/port.js +36 -0
  141. package/dist/server/port.js.map +1 -0
  142. package/dist/server/principal.js +90 -0
  143. package/dist/server/principal.js.map +1 -0
  144. package/dist/server/terminal.js +285 -0
  145. package/dist/server/terminal.js.map +1 -0
  146. package/dist/setup/components.js +98 -0
  147. package/dist/setup/components.js.map +1 -0
  148. package/dist/setup/config.js +102 -0
  149. package/dist/setup/config.js.map +1 -0
  150. package/dist/setup/ink-ui.js +188 -0
  151. package/dist/setup/ink-ui.js.map +1 -0
  152. package/dist/setup/onboarding.js +183 -0
  153. package/dist/setup/onboarding.js.map +1 -0
  154. package/dist/setup/run.js +70 -0
  155. package/dist/setup/run.js.map +1 -0
  156. package/dist/ticket-cli.js +116 -0
  157. package/dist/ticket-cli.js.map +1 -0
  158. package/dist/voice/index.js +69 -0
  159. package/dist/voice/index.js.map +1 -0
  160. package/dist/voice/moonshine.js +247 -0
  161. package/dist/voice/moonshine.js.map +1 -0
  162. package/dist/voice/wav.js +54 -0
  163. package/dist/voice/wav.js.map +1 -0
  164. package/dist/voice/whisper.js +491 -0
  165. package/dist/voice/whisper.js.map +1 -0
  166. package/dist/web/assets/index-ChuS3qKc.js +254 -0
  167. package/dist/web/assets/index-DR6WkmzI.css +1 -0
  168. package/dist/web/icons/apple-touch-icon.png +0 -0
  169. package/dist/web/icons/icon-192.png +0 -0
  170. package/dist/web/icons/icon-512.png +0 -0
  171. package/dist/web/icons/maskable-512.png +0 -0
  172. package/dist/web/index.html +21 -0
  173. package/dist/web/manifest.webmanifest +30 -0
  174. package/dist/web/sw.js +183 -0
  175. package/package.json +96 -4
package/README.md CHANGED
@@ -1,3 +1,179 @@
1
- # Temporary Holding Version
1
+ # Zelio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Supervise a crew of coding agents from a kanban board instead of a chat window.
4
+
5
+ > **Status: pre-alpha.** Nothing is published yet — no npm package, no release. This README describes what Zelio is meant to be, so the shape can be argued with before it's built.
6
+
7
+ ## The problem
8
+
9
+ Chat is a serial interface for parallel work.
10
+
11
+ One agent and one task at a time is fine in a chat window. The moment you have three things in flight it breaks, in three specific ways:
12
+
13
+ - **No state.** Scrollback is not a record. Come back an hour later and you can't tell what finished, what stalled, and what silently did something else.
14
+ - **No ownership.** Nothing says which agent is on which task. You hold that in your head, so you become the scheduler.
15
+ - **No review surface.** You approve work by reading a wall of text and hoping the diff was what you meant. Reviewing three of those in a row is how people stop reading.
16
+
17
+ So the work drifts toward writing longer and longer prompts, then reading longer and longer answers. You spend the day chatting about work instead of reviewing work.
18
+
19
+ The fix isn't a better chat. It's giving work _state_: somewhere it can sit, be owned, be blocked, and be reviewed. People solved this for human teams decades ago, and the answer was a board.
20
+
21
+ ## What Zelio is
22
+
23
+ A local board where every card is a unit of work an agent owns.
24
+
25
+ You capture intents, promote the real ones into tickets, assign an agent, and watch. The agent moves its own ticket as it works and leaves typed comments. You review the diff and decide. In five seconds the board tells you where everything stands; the ticket tells you why.
26
+
27
+ **Not a swarm.** Zelio runs a small crew of agents you chose, each on one ticket, each in its own worktree. Agents don't talk to each other, nothing self-organises, and nothing merges without you. The interesting problem isn't making agents autonomous — it's making them _supervisable_.
28
+
29
+ ### Chat vs. board
30
+
31
+ | | Chat | Zelio |
32
+ | ---------------------- | ----------------------- | ---------------------- |
33
+ | Where the record lives | scrollback | the ticket |
34
+ | Who owns the task | your memory | the agent, visibly |
35
+ | Parallel work | one thread, interleaved | one ticket each |
36
+ | Reviewing output | read the transcript | read the diff |
37
+ | When an agent stalls | you notice hours later | Blocked, with a reason |
38
+
39
+ ## The flow
40
+
41
+ Run it inside the repo you want to work on:
42
+
43
+ ```bash
44
+ npx zelio
45
+ ```
46
+
47
+ A board opens in your browser. Everything stays on your machine — your repo, your keys, your harness, your model.
48
+
49
+ On a new machine, the terminal setup takes a minute: pick the **harness**
50
+ (pi, Codex or Claude Code), then the **planner model**, then the **developer model**. It
51
+ installs the selected CLI if it is missing. Each model list starts with
52
+ **Harness default**. There is no thinking-effort question: the planner picks the
53
+ effort for each ticket. The same harness runs the planner and profiles without
54
+ an explicit harness. Run `zelio setup` any time to choose or check again.
55
+
56
+ Claude Code runs with your own sign-in, a subscription login or an API key,
57
+ and Zelio never runs it in `--bare` mode, which would ignore a subscription login.
58
+
59
+ Codex must already have a stored sign-in from `codex login` or
60
+ `codex login --with-api-key`. Zelio checks that sign-in and never accepts an
61
+ API key from an environment variable as Codex app-server authentication.
62
+
63
+ **1. Capture.** Describe the work: "emails should have digests." No form, no schema — a sentence, or a paragraph. The planner reads the repo and asks the few decisions it cannot make for you, one at a time, each option carrying what it costs. Wishes are free-form on purpose; the cost of capturing should be near zero.
64
+
65
+ **2. Promote.** The planner writes the ticket for you — goal, out of scope, acceptance criteria, likely files, and which profile should do it — and you confirm or discard it in the same dialog. Nothing is drafted from your taste alone, and no field is one you had to fill in.
66
+
67
+ **3. Assign.** Pick a profile from the right-hand panel. A `touches_repo` flag on the profile decides whether it competes for a slot with the other code agents. Assigning is not starting.
68
+
69
+ **4. Start.** The card moves to In Progress and locks — you can comment or cancel, but you can't drag a ticket that's in flight. The agent gets its own git worktree, so parallel tickets stay mergeable.
70
+
71
+ **5. Watch.** Comments arrive as the agent works, typed: `decision`, `blocker`, `done`. Not a chat thread — three kinds of event, each with a meaning the board can act on.
72
+
73
+ **6. Review.** The agent moves its own card to Review and attaches the diff. Code tickets get a diff; task tickets (email, research, docs) get an artifact instead. You're reading a change, not a transcript.
74
+
75
+ **7. Decide.** Approve and merge, or send it back with a note. Sending back re-prompts in the same worktree; nothing restarts from scratch and nothing lands on `main` without you.
76
+
77
+ **When an agent gets stuck** it moves its own card to Blocked, states what's blocking it and what would unblock it, and notifies you. It doesn't guess and it doesn't sit silently. No auto-resume in the first version — you decide.
78
+
79
+ ### Autopilot (planned)
80
+
81
+ Manual mode is the default. Later, the same loop with a planner in front:
82
+
83
+ 1. Describe the goal in the side panel.
84
+ 2. The orchestrator reads the repo, asks a few questions, and drafts a **plan**: tickets, descriptions, dependencies, and who does what.
85
+ 3. You edit the plan — cut, reorder, rewrite.
86
+ 4. Approve, and agents start.
87
+
88
+ The orchestrator plans. It never executes and never merges. The plan stays an editable artifact so you can see _why_ the work was split that way.
89
+
90
+ ## Design rules
91
+
92
+ - **Status can't lie.** The agent doing the work owns the ticket's status. A board that drifts from reality is worse than no board.
93
+ - **Assign ≠ run.** Assigning picks who, starting begins work. Accidental runs are how people stop trusting a tool that touches their repo.
94
+ - **One agent per ticket.** Reassigning replaces; it never stacks.
95
+ - **A worktree per ticket.** Parallel work stays mergeable, and a failed attempt retries without polluting `main`.
96
+ - **The human merges.** Agents propose; you approve.
97
+ - **Typed comments, not chat.** Decision, blocker, done. Free-form threads are the thing we're replacing.
98
+ - **The board is the record.** Agent output lands on the ticket, so a crashed agent loses nothing.
99
+
100
+ ## Agent profiles
101
+
102
+ A profile is a harness, a model, a system prompt, a tool scope, and a thinking level. That's the reusable asset: `developer`, `reviewer`, `tester`, `assistant`.
103
+
104
+ Thinking is part of the profile: `developer` and `tester` run at `low`, `reviewer` at `high`, and `assistant` at `low`. The planner defaults to `high` because the spec is the product. Change that default in Settings, or override it for one capture with the effort slider in the new-task dialog. `--planner-thinking` and `ZELIO_PLANNER_THINKING` still work for a process. On a model with no real `medium` level — DeepSeek Flash maps it to nothing — pi clamps upward to `high`, so `low` is the step below high that actually exists.
105
+
106
+ A planning turn also gets a scope, not just a level: the panel gets ten tool calls, the new-task dialog thirty, because a chat can read across turns and the wizard cannot. The number is said in the prompt and enforced by stopping the turn, at which point the planner writes the card from what it read and flags the rest in `assumed`. Override both with `--planner-budget`, or tune each door with `ZELIO_PLANNER_BUDGET` and `ZELIO_NEW_TASK_BUDGET`; zero turns it off.
107
+
108
+ Instances spawn on demand rather than idling. Concurrency is capped, because spawning is cheap and running in parallel is not:
109
+
110
+ - one board-wide cap, editable in Settings from 2 to 6; it defaults to 2
111
+ - the allocator reads it on every pass, so raising it lets the queued cards start without a restart
112
+ - reviewers and comment runs count against the same cap, because they share the machine and the provider
113
+
114
+ The cap is a product decision, not a technical one: nobody can review ten diffs at once.
115
+
116
+ ## Comments
117
+
118
+ A ticket's Activity tab has one comment field; typing `@` autocompletes the profiles. Mentioning `@reviewer` on a review ticket starts a read-only review in the worktree, keeps the card in Review, and posts the findings as a `review` comment addressed to `@user`. Mentioning `@developer` is a send-back: the card moves to In Progress, the agent works from the comment, replies, and reports back to Review when it is done.
119
+
120
+ A comment with no mention is just recorded. On a ticket that has not started yet it is saved for the next run, so an instruction written early is not lost.
121
+
122
+ Agents finish through a run-scoped result reporter, not a sequence of manual API calls. Zelio validates observed command evidence against the current worktree, records the report, and moves the ticket to Review or Blocked. Review reports retain the evidence, its limitations, and owners of any explicitly agreed later assurance gates. Passing tests is not a security guarantee, and Review never authorizes deployment. A required proof cannot be deferred as a later audit. A run that exhausts recovery without reporting is an execution that needs attention, not an inferred human blocker; its session and worktree remain available.
123
+
124
+ ## Dictation
125
+
126
+ The new-task box takes a microphone, and the words follow you as you speak —
127
+ no service, no key, and the audio never leaves the machine. It is opt-in,
128
+ because a speech model is larger than the rest of Zelio.
129
+
130
+ The fast path is [Moonshine](https://github.com/usefulsensors/moonshine): a
131
+ ~30M-parameter model built for short utterances, so a phrase comes back in tens
132
+ of milliseconds instead of a second. It is fetched on first use (~100 MB) and
133
+ needs nothing else — no Homebrew, no key. Its trade is punctuation and repo
134
+ jargon, so [whisper.cpp](https://github.com/ggml-org/whisper.cpp) remains the
135
+ fallback, and the better choice if you want the cleanest text:
136
+
137
+ ```bash
138
+ brew install whisper-cpp # optional; Zelio fetches that model too (~150 MB)
139
+ ```
140
+
141
+ `ZELIO_VOICE_ENGINE=whisper` forces whisper, `ZELIO_MOONSHINE_MODEL=base` uses
142
+ Moonshine's larger model.
143
+
144
+ Press **Dictate** below the description and talk: the words follow you as you
145
+ speak, and settle when you pause. Press it again to stop. Words land in the
146
+ field and never start the turn, so a misheard sentence is something you edit
147
+ rather than something that runs. `docs/voice-notes.md` has the tradeoffs and
148
+ the environment overrides.
149
+
150
+ ## Harnesses
151
+
152
+ Zelio doesn't bundle a model. It currently supports [pi](https://github.com/earendil-works/pi), [OpenAI Codex](https://github.com/openai/codex) and [Claude Code](https://docs.claude.com/en/docs/claude-code). You choose the harness and model; credentials stay with the harness. The adapter seam is ready for future harnesses, including ACP, but those are not supported yet.
153
+
154
+ ## Requirements
155
+
156
+ - Node.js 22+
157
+ - git
158
+ - pi, Codex or Claude Code CLI; Codex and Claude Code require a stored sign-in (`codex login`, `claude auth login`)
159
+
160
+ ## Non-goals
161
+
162
+ - Hosted execution. Your machine, your keys, your data.
163
+ - A general-purpose chat UI.
164
+ - Autonomous swarms, or agents talking to each other. Coordination happens through tickets.
165
+ - Replacing your editor or your git host.
166
+
167
+ ## Roadmap
168
+
169
+ - [ ] Board, tickets, typed comments
170
+ - [ ] One profile, one harness (pi), sequential execution
171
+ - [ ] Worktrees, diff review, send-back
172
+ - [ ] Blocked state and notifications
173
+ - [ ] Multiple profiles, concurrency caps
174
+ - [x] Second harness (Codex)
175
+ - [ ] Orchestrator and plan artifacts
176
+
177
+ ## License
178
+
179
+ Closed source for now. All rights reserved.
@@ -0,0 +1,121 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { join, resolve } from "node:path";
4
+ import { MAX_ATTACHMENTS, MAX_IMAGE_BYTES } from "./limits.js";
5
+ /**
6
+ * Screenshots live in the board's own state directory, beside the database and
7
+ * the worktrees. They are gitignored because `.zelio/` is, and they are not rows
8
+ * because a binary blob in SQLite is a backup problem. The path stored on a
9
+ * ticket is relative to the repo, so the board can be moved without rewriting
10
+ * every record; the prompt resolves it against the root at run time.
11
+ */
12
+ export const ATTACHMENT_DIR = ".zelio/attachments";
13
+ /** An attachment the client named is not on disk, or was never ours. */
14
+ export class AttachmentError extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = "AttachmentError";
18
+ }
19
+ }
20
+ const EXTENSIONS = {
21
+ "image/png": "png",
22
+ "image/jpeg": "jpg",
23
+ "image/webp": "webp",
24
+ "image/gif": "gif",
25
+ };
26
+ const MIMES = {
27
+ png: "image/png",
28
+ jpg: "image/jpeg",
29
+ webp: "image/webp",
30
+ gif: "image/gif",
31
+ };
32
+ /** The name the upload route writes: a fresh id and the extension the bytes are. */
33
+ const NAME = /^\.zelio\/attachments\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.(png|jpg|webp|gif)$/;
34
+ /** A typed content-type is a claim; the bytes are the answer. */
35
+ export function sniffImage(bytes) {
36
+ const at = (...values) => bytes.length >= values.length && values.every((value, index) => bytes[index] === value);
37
+ const text = (offset, value) => bytes.length >= offset + value.length &&
38
+ [...value].every((char, index) => bytes[offset + index] === char.charCodeAt(0));
39
+ if (at(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a))
40
+ return "image/png";
41
+ if (at(0xff, 0xd8, 0xff))
42
+ return "image/jpeg";
43
+ if (text(0, "GIF87a") || text(0, "GIF89a"))
44
+ return "image/gif";
45
+ if (text(0, "RIFF") && text(8, "WEBP"))
46
+ return "image/webp";
47
+ return null;
48
+ }
49
+ /** An `image/*` value this module can store, or null for everything else. */
50
+ export function imageMime(value) {
51
+ if (typeof value !== "string")
52
+ return null;
53
+ const type = value.split(";")[0].trim().toLowerCase();
54
+ return Object.values(MIMES).includes(type) ? type : null;
55
+ }
56
+ export function isAttachmentPath(value) {
57
+ return typeof value === "string" && NAME.test(value);
58
+ }
59
+ /**
60
+ * A list of attachment paths from the client, or null when any entry is not one
61
+ * of ours. Dropping a bad path silently would leave the person believing their
62
+ * screenshot is attached when it is not, which is worse than the error.
63
+ */
64
+ export function attachmentPaths(value) {
65
+ if (!Array.isArray(value))
66
+ return [];
67
+ const paths = [];
68
+ for (const raw of value) {
69
+ if (!isAttachmentPath(raw))
70
+ return null;
71
+ // The same screenshot named twice is still one picture; a strict refusal
72
+ // would turn a harmless double-send into a failed turn.
73
+ if (!paths.includes(raw))
74
+ paths.push(raw);
75
+ }
76
+ return paths.length > MAX_ATTACHMENTS ? null : paths;
77
+ }
78
+ /** Writes the bytes under a fresh name. The caller has already sniffed them. */
79
+ export async function saveAttachment(root, bytes, mimeType) {
80
+ if (bytes.byteLength === 0 || bytes.byteLength > MAX_IMAGE_BYTES) {
81
+ throw new RangeError("that image is not a size the board can store");
82
+ }
83
+ const path = `${ATTACHMENT_DIR}/${randomUUID()}.${EXTENSIONS[mimeType]}`;
84
+ const dir = join(root, ATTACHMENT_DIR);
85
+ await mkdir(dir, { recursive: true });
86
+ await writeFile(join(root, path), bytes);
87
+ return { path, mimeType, bytes: bytes.byteLength };
88
+ }
89
+ /** Absolute paths, for the prompt a process reads from its own worktree. */
90
+ export function absoluteAttachments(root, paths) {
91
+ return paths.filter(isAttachmentPath).map((path) => resolve(root, path));
92
+ }
93
+ /**
94
+ * Drops screenshots a person decided not to use. A file that is already gone is
95
+ * not an error: the only outcome anyone cares about is that it is not there.
96
+ */
97
+ export async function deleteAttachments(root, paths) {
98
+ await Promise.all(paths.filter(isAttachmentPath).map((path) => rm(join(root, path), { force: true })));
99
+ }
100
+ /**
101
+ * The images themselves, as pi's prompt record wants them. A file that vanished
102
+ * is an error rather than a silently text-only turn: the person attached a
103
+ * picture, and a planner that never saw it must not pretend otherwise.
104
+ */
105
+ export async function readAttachmentImages(root, paths) {
106
+ // Parallel reads keep the order: the array's index is the attachment's.
107
+ return Promise.all(paths.map(async (path) => {
108
+ if (!isAttachmentPath(path)) {
109
+ throw new AttachmentError("that attachment path is not the board's");
110
+ }
111
+ const ext = path.split(".").pop() ?? "";
112
+ const mimeType = MIMES[ext];
113
+ if (!mimeType)
114
+ throw new AttachmentError("that attachment path is not the board's");
115
+ const bytes = await readFile(join(root, path)).catch(() => null);
116
+ if (!bytes)
117
+ throw new AttachmentError(`the screenshot ${path} is gone`);
118
+ return { type: "image", data: bytes.toString("base64"), mimeType };
119
+ }));
120
+ }
121
+ //# sourceMappingURL=attachments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.js","sourceRoot":"","sources":["../src/attachments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAInD,wEAAwE;AACxE,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,UAAU,GAA8B;IAC5C,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,KAAK;CACnB,CAAC;AAEF,MAAM,KAAK,GAA8B;IACvC,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,YAAY;IACjB,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,WAAW;CACjB,CAAC;AAEF,oFAAoF;AACpF,MAAM,IAAI,GACR,0GAA0G,CAAC;AAS7G,iEAAiE;AACjE,MAAM,UAAU,UAAU,CAA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