zelio-cli 0.0.0-stage → 0.1.0-beta.3
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 +185 -2
- package/dist/attachments.js +121 -0
- package/dist/attachments.js.map +1 -0
- package/dist/cli.js +496 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud/board.js +311 -0
- package/dist/cloud/board.js.map +1 -0
- package/dist/cloud/command.js +281 -0
- package/dist/cloud/command.js.map +1 -0
- package/dist/cloud/config.js +132 -0
- package/dist/cloud/config.js.map +1 -0
- package/dist/cloud/credentials.js +134 -0
- package/dist/cloud/credentials.js.map +1 -0
- package/dist/cloud/login.js +165 -0
- package/dist/cloud/login.js.map +1 -0
- package/dist/cloud/pair.js +110 -0
- package/dist/cloud/pair.js.map +1 -0
- package/dist/cloud/pkce.js +16 -0
- package/dist/cloud/pkce.js.map +1 -0
- package/dist/cloud/push-nudge.js +65 -0
- package/dist/cloud/push-nudge.js.map +1 -0
- package/dist/cloud/relay.js +134 -0
- package/dist/cloud/relay.js.map +1 -0
- package/dist/cloud/token.js +66 -0
- package/dist/cloud/token.js.map +1 -0
- package/dist/cloud/tunnel.js +474 -0
- package/dist/cloud/tunnel.js.map +1 -0
- package/dist/db/db.js +1741 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/lifecycle.js +146 -0
- package/dist/db/lifecycle.js.map +1 -0
- package/dist/limits.js +35 -0
- package/dist/limits.js.map +1 -0
- package/dist/metrics.js +30 -0
- package/dist/metrics.js.map +1 -0
- package/dist/orchestrator/claude-session.js +208 -0
- package/dist/orchestrator/claude-session.js.map +1 -0
- package/dist/orchestrator/codex-session.js +326 -0
- package/dist/orchestrator/codex-session.js.map +1 -0
- package/dist/orchestrator/contract.js +184 -0
- package/dist/orchestrator/contract.js.map +1 -0
- package/dist/orchestrator/explore.js +176 -0
- package/dist/orchestrator/explore.js.map +1 -0
- package/dist/orchestrator/new-task-prompt.js +51 -0
- package/dist/orchestrator/new-task-prompt.js.map +1 -0
- package/dist/orchestrator/pi-session.js +228 -0
- package/dist/orchestrator/pi-session.js.map +1 -0
- package/dist/orchestrator/prompt.js +110 -0
- package/dist/orchestrator/prompt.js.map +1 -0
- package/dist/orchestrator/research.js +178 -0
- package/dist/orchestrator/research.js.map +1 -0
- package/dist/orchestrator/runtime.js +1207 -0
- package/dist/orchestrator/runtime.js.map +1 -0
- package/dist/orchestrator/session.js +2 -0
- package/dist/orchestrator/session.js.map +1 -0
- package/dist/orchestrator/types.js +2 -0
- package/dist/orchestrator/types.js.map +1 -0
- package/dist/orchestrator/web.js +276 -0
- package/dist/orchestrator/web.js.map +1 -0
- package/dist/repo/index.js +188 -0
- package/dist/repo/index.js.map +1 -0
- package/dist/repo/instructions.js +58 -0
- package/dist/repo/instructions.js.map +1 -0
- package/dist/repo/linked-boards.js +137 -0
- package/dist/repo/linked-boards.js.map +1 -0
- package/dist/repo/project-repos.js +78 -0
- package/dist/repo/project-repos.js.map +1 -0
- package/dist/run/actions.js +257 -0
- package/dist/run/actions.js.map +1 -0
- package/dist/run/auto-review.js +102 -0
- package/dist/run/auto-review.js.map +1 -0
- package/dist/run/bash-guard.js +183 -0
- package/dist/run/bash-guard.js.map +1 -0
- package/dist/run/claude-runtime.js +270 -0
- package/dist/run/claude-runtime.js.map +1 -0
- package/dist/run/claude-stream.js +306 -0
- package/dist/run/claude-stream.js.map +1 -0
- package/dist/run/codex-client.js +202 -0
- package/dist/run/codex-client.js.map +1 -0
- package/dist/run/codex-runtime.js +460 -0
- package/dist/run/codex-runtime.js.map +1 -0
- package/dist/run/consult.js +105 -0
- package/dist/run/consult.js.map +1 -0
- package/dist/run/context.js +87 -0
- package/dist/run/context.js.map +1 -0
- package/dist/run/diff.js +238 -0
- package/dist/run/diff.js.map +1 -0
- package/dist/run/evidence.js +48 -0
- package/dist/run/evidence.js.map +1 -0
- package/dist/run/finish.js +408 -0
- package/dist/run/finish.js.map +1 -0
- package/dist/run/handoff.js +51 -0
- package/dist/run/handoff.js.map +1 -0
- package/dist/run/harness-runtime.js +31 -0
- package/dist/run/harness-runtime.js.map +1 -0
- package/dist/run/harnesses.js +273 -0
- package/dist/run/harnesses.js.map +1 -0
- package/dist/run/issue.js +79 -0
- package/dist/run/issue.js.map +1 -0
- package/dist/run/keep-awake.js +58 -0
- package/dist/run/keep-awake.js.map +1 -0
- package/dist/run/lead.js +159 -0
- package/dist/run/lead.js.map +1 -0
- package/dist/run/manager.js +2546 -0
- package/dist/run/manager.js.map +1 -0
- package/dist/run/mentions.js +35 -0
- package/dist/run/mentions.js.map +1 -0
- package/dist/run/merge-watch.js +425 -0
- package/dist/run/merge-watch.js.map +1 -0
- package/dist/run/models.js +88 -0
- package/dist/run/models.js.map +1 -0
- package/dist/run/phases.js +23 -0
- package/dist/run/phases.js.map +1 -0
- package/dist/run/pi-rpc.js +439 -0
- package/dist/run/pi-rpc.js.map +1 -0
- package/dist/run/piped-check.js +56 -0
- package/dist/run/piped-check.js.map +1 -0
- package/dist/run/pr-checks.js +67 -0
- package/dist/run/pr-checks.js.map +1 -0
- package/dist/run/pr-merge.js +121 -0
- package/dist/run/pr-merge.js.map +1 -0
- package/dist/run/profiles.js +43 -0
- package/dist/run/profiles.js.map +1 -0
- package/dist/run/prompt.js +388 -0
- package/dist/run/prompt.js.map +1 -0
- package/dist/run/pull-request.js +23 -0
- package/dist/run/pull-request.js.map +1 -0
- package/dist/run/red-check.js +130 -0
- package/dist/run/red-check.js.map +1 -0
- package/dist/run/result-tool.js +93 -0
- package/dist/run/result-tool.js.map +1 -0
- package/dist/run/result.js +113 -0
- package/dist/run/result.js.map +1 -0
- package/dist/run/retro.js +346 -0
- package/dist/run/retro.js.map +1 -0
- package/dist/run/settings.js +27 -0
- package/dist/run/settings.js.map +1 -0
- package/dist/run/skills.js +146 -0
- package/dist/run/skills.js.map +1 -0
- package/dist/run/tests-first.js +146 -0
- package/dist/run/tests-first.js.map +1 -0
- package/dist/run/thinking.js +41 -0
- package/dist/run/thinking.js.map +1 -0
- package/dist/run/types.js +2 -0
- package/dist/run/types.js.map +1 -0
- package/dist/run/watchdog.js +259 -0
- package/dist/run/watchdog.js.map +1 -0
- package/dist/run/workflow.js +277 -0
- package/dist/run/workflow.js.map +1 -0
- package/dist/run/worktree.js +354 -0
- package/dist/run/worktree.js.map +1 -0
- package/dist/server/app.js +2946 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/auth.js +93 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/demo.js +96 -0
- package/dist/server/demo.js.map +1 -0
- package/dist/server/idempotency.js +104 -0
- package/dist/server/idempotency.js.map +1 -0
- package/dist/server/port.js +36 -0
- package/dist/server/port.js.map +1 -0
- package/dist/server/principal.js +93 -0
- package/dist/server/principal.js.map +1 -0
- package/dist/server/repo-picker.js +18 -0
- package/dist/server/repo-picker.js.map +1 -0
- package/dist/server/terminal.js +285 -0
- package/dist/server/terminal.js.map +1 -0
- package/dist/setup/components.js +98 -0
- package/dist/setup/components.js.map +1 -0
- package/dist/setup/config.js +102 -0
- package/dist/setup/config.js.map +1 -0
- package/dist/setup/ink-ui.js +189 -0
- package/dist/setup/ink-ui.js.map +1 -0
- package/dist/setup/onboarding.js +167 -0
- package/dist/setup/onboarding.js.map +1 -0
- package/dist/setup/run.js +70 -0
- package/dist/setup/run.js.map +1 -0
- package/dist/skills.js +151 -0
- package/dist/skills.js.map +1 -0
- package/dist/ticket-cli.js +157 -0
- package/dist/ticket-cli.js.map +1 -0
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/dist/voice/index.js +69 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/moonshine.js +247 -0
- package/dist/voice/moonshine.js.map +1 -0
- package/dist/voice/wav.js +54 -0
- package/dist/voice/wav.js.map +1 -0
- package/dist/voice/whisper.js +491 -0
- package/dist/voice/whisper.js.map +1 -0
- package/dist/web/assets/index-CCQMrUIF.js +255 -0
- package/dist/web/assets/index-lzGSgTRQ.css +1 -0
- package/dist/web/icons/apple-touch-icon.png +0 -0
- package/dist/web/icons/icon-192.png +0 -0
- package/dist/web/icons/icon-512.png +0 -0
- package/dist/web/icons/maskable-512.png +0 -0
- package/dist/web/index.html +21 -0
- package/dist/web/manifest.webmanifest +30 -0
- package/dist/web/sw.js +185 -0
- package/package.json +96 -4
package/README.md
CHANGED
|
@@ -1,3 +1,186 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Zelio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Supervise a crew of coding agents from a kanban board instead of a chat window.
|
|
4
|
+
|
|
5
|
+
> **Status: beta.** Published on npm as [`zelio-cli`](https://www.npmjs.com/package/zelio-cli); the command it installs is `zelio`. Expect rough edges, and parts of this README (Autopilot, the roadmap) describe where Zelio is going rather than what ships today.
|
|
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-cli
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or install it once and run `zelio` from any repo:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install -g zelio-cli
|
|
51
|
+
zelio
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
A board opens in your browser. Everything stays on your machine — your repo, your keys, your harness, your model.
|
|
55
|
+
|
|
56
|
+
On a new machine, the terminal setup takes a minute: pick the **harness**
|
|
57
|
+
(pi, Codex or Claude Code), then the **planner model**, then the **developer model**. It
|
|
58
|
+
installs the selected CLI if it is missing. Each model list starts with
|
|
59
|
+
**Harness default**. There is no thinking-effort question: the planner picks the
|
|
60
|
+
effort for each ticket. The same harness runs the planner and profiles without
|
|
61
|
+
an explicit harness. Run `zelio setup` any time to choose or check again.
|
|
62
|
+
|
|
63
|
+
Claude Code runs with your own sign-in, a subscription login or an API key,
|
|
64
|
+
and Zelio never runs it in `--bare` mode, which would ignore a subscription login.
|
|
65
|
+
|
|
66
|
+
Codex must already have a stored sign-in from `codex login` or
|
|
67
|
+
`codex login --with-api-key`. Zelio checks that sign-in and never accepts an
|
|
68
|
+
API key from an environment variable as Codex app-server authentication.
|
|
69
|
+
|
|
70
|
+
**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.
|
|
71
|
+
|
|
72
|
+
**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.
|
|
73
|
+
|
|
74
|
+
**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.
|
|
75
|
+
|
|
76
|
+
**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.
|
|
77
|
+
|
|
78
|
+
**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.
|
|
79
|
+
|
|
80
|
+
**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.
|
|
81
|
+
|
|
82
|
+
**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.
|
|
83
|
+
|
|
84
|
+
**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.
|
|
85
|
+
|
|
86
|
+
### Autopilot (planned)
|
|
87
|
+
|
|
88
|
+
Manual mode is the default. Later, the same loop with a planner in front:
|
|
89
|
+
|
|
90
|
+
1. Describe the goal in the side panel.
|
|
91
|
+
2. The orchestrator reads the repo, asks a few questions, and drafts a **plan**: tickets, descriptions, dependencies, and who does what.
|
|
92
|
+
3. You edit the plan — cut, reorder, rewrite.
|
|
93
|
+
4. Approve, and agents start.
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
|
|
97
|
+
## Design rules
|
|
98
|
+
|
|
99
|
+
- **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.
|
|
100
|
+
- **Assign ≠ run.** Assigning picks who, starting begins work. Accidental runs are how people stop trusting a tool that touches their repo.
|
|
101
|
+
- **One agent per ticket.** Reassigning replaces; it never stacks.
|
|
102
|
+
- **A worktree per ticket.** Parallel work stays mergeable, and a failed attempt retries without polluting `main`.
|
|
103
|
+
- **The human merges.** Agents propose; you approve.
|
|
104
|
+
- **Typed comments, not chat.** Decision, blocker, done. Free-form threads are the thing we're replacing.
|
|
105
|
+
- **The board is the record.** Agent output lands on the ticket, so a crashed agent loses nothing.
|
|
106
|
+
|
|
107
|
+
## Agent profiles
|
|
108
|
+
|
|
109
|
+
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`.
|
|
110
|
+
|
|
111
|
+
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.
|
|
112
|
+
|
|
113
|
+
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.
|
|
114
|
+
|
|
115
|
+
Instances spawn on demand rather than idling. Concurrency is capped, because spawning is cheap and running in parallel is not:
|
|
116
|
+
|
|
117
|
+
- one board-wide cap, editable in Settings from 2 to 6; it defaults to 2
|
|
118
|
+
- the allocator reads it on every pass, so raising it lets the queued cards start without a restart
|
|
119
|
+
- reviewers and comment runs count against the same cap, because they share the machine and the provider
|
|
120
|
+
|
|
121
|
+
The cap is a product decision, not a technical one: nobody can review ten diffs at once.
|
|
122
|
+
|
|
123
|
+
## Comments
|
|
124
|
+
|
|
125
|
+
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.
|
|
126
|
+
|
|
127
|
+
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.
|
|
128
|
+
|
|
129
|
+
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.
|
|
130
|
+
|
|
131
|
+
## Dictation
|
|
132
|
+
|
|
133
|
+
The new-task box takes a microphone, and the words follow you as you speak —
|
|
134
|
+
no service, no key, and the audio never leaves the machine. It is opt-in,
|
|
135
|
+
because a speech model is larger than the rest of Zelio.
|
|
136
|
+
|
|
137
|
+
The fast path is [Moonshine](https://github.com/usefulsensors/moonshine): a
|
|
138
|
+
~30M-parameter model built for short utterances, so a phrase comes back in tens
|
|
139
|
+
of milliseconds instead of a second. It is fetched on first use (~100 MB) and
|
|
140
|
+
needs nothing else — no Homebrew, no key. Its trade is punctuation and repo
|
|
141
|
+
jargon, so [whisper.cpp](https://github.com/ggml-org/whisper.cpp) remains the
|
|
142
|
+
fallback, and the better choice if you want the cleanest text:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
brew install whisper-cpp # optional; Zelio fetches that model too (~150 MB)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`ZELIO_VOICE_ENGINE=whisper` forces whisper, `ZELIO_MOONSHINE_MODEL=base` uses
|
|
149
|
+
Moonshine's larger model.
|
|
150
|
+
|
|
151
|
+
Press **Dictate** below the description and talk: the words follow you as you
|
|
152
|
+
speak, and settle when you pause. Press it again to stop. Words land in the
|
|
153
|
+
field and never start the turn, so a misheard sentence is something you edit
|
|
154
|
+
rather than something that runs. `docs/voice-notes.md` has the tradeoffs and
|
|
155
|
+
the environment overrides.
|
|
156
|
+
|
|
157
|
+
## Harnesses
|
|
158
|
+
|
|
159
|
+
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.
|
|
160
|
+
|
|
161
|
+
## Requirements
|
|
162
|
+
|
|
163
|
+
- Node.js 22+
|
|
164
|
+
- git
|
|
165
|
+
- pi, Codex or Claude Code CLI; Codex and Claude Code require a stored sign-in (`codex login`, `claude auth login`)
|
|
166
|
+
|
|
167
|
+
## Non-goals
|
|
168
|
+
|
|
169
|
+
- Hosted execution. Your machine, your keys, your data.
|
|
170
|
+
- A general-purpose chat UI.
|
|
171
|
+
- Autonomous swarms, or agents talking to each other. Coordination happens through tickets.
|
|
172
|
+
- Replacing your editor or your git host.
|
|
173
|
+
|
|
174
|
+
## Roadmap
|
|
175
|
+
|
|
176
|
+
- [ ] Board, tickets, typed comments
|
|
177
|
+
- [ ] One profile, one harness (pi), sequential execution
|
|
178
|
+
- [ ] Worktrees, diff review, send-back
|
|
179
|
+
- [ ] Blocked state and notifications
|
|
180
|
+
- [ ] Multiple profiles, concurrency caps
|
|
181
|
+
- [x] Second harness (Codex)
|
|
182
|
+
- [ ] Orchestrator and plan artifacts
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
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;AA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