feat(repos): register Repos and keep a jj clone of each #4

Merged babariviere.com
targeting main from feat/repos-register-repos-and-keep-a-jj-clone-of-each
Merged opened by babariviere.com
targeting main from feat/repos-register-repos-and-keep-a-jj-clone-of-each

Summary #

The Owner registers a GitHub repository as a Repo from the Repos page, and the Repo's page opens. Pilot keeps one jj clone of each Repo. The Repo's page shows the clone, edits the setup command and the "Allow Cyber tasks" switch, and has a Danger zone with "Remove this Repo".

registerRepo { id, name }reposChanged (clone: cloning)replied { id, error: null }repo view → clone URL (https or ssh, as gh's git_protocol says)git clone --colocate → repos/.cloning/owner/namemove into repos/owner/namereposChanged (clone: ready | failed + why)AppDaemonghjjAppDaemonghjj

The protocol gets its first commands. Each one has an id, and the Daemon replies to it once. The events it causes come first.

 type Repo = {
   name: string
+  setupCommand: string
+  allowCyber: boolean
+  clone: { state: "cloning" } | { state: "ready" } | { state: "failed"; why: string }
 }
 DaemonMessage
+  | reposChanged { repos }
+  | replied { id, error: string | null }
-AppCommand = never
+AppCommand = registerRepo | changeRepo | cloneRepo (Try again) | removeRepo
daemon/src/
├── repos.ts        # pilot_repos table in pilot.sqlite, the commands, the clones that run
├── workspaces.ts   # one jj clone per Repo: moved into place only once complete, deleted on remove
├── github.ts       # + cloneUrl()
└── server.ts       # + commands in, one reply each
app/
├── daemon.ts       # + send(command) → why it was refused, or null
├── Shell.tsx       # the trail holds { page, repo }: a Repo opens like a page
├── home.tsx        # Home, moved out of pages.tsx (it still builds its own rows until ticket 07)
└── pages.tsx       # Repos page and Repo page
ui/                 # CloneBadge, Row stacked, Dialog message, TextField verbatim, spin on Icon/Badge/Notice, trash-2
  • A stop or a crash during a clone leaves the Repo "cloning". The clone starts again when the Daemon starts.
  • Removing a Repo stops its clone if one runs and deletes Pilot's clone. The repository on GitHub stays.
  • The loader icon turns while a clone runs, and on the Building Stage badge.
  • The field takes "owner/name" or a GitHub link (https, ssh, .git, a page inside the repository). It and the setup command's field are verbatim: macOS adds no capitals and corrects nothing.
  • The setup command is only stored for now. The Task runner (ticket 19) runs it.

Also in this PR, from the retro:

  • just lint now checks that screens compose ui/: no styled Text, no Badge with a one-off look, and a loader icon always turns.
  • A scratch profile for checks by hand: just scratch-daemon, just scratch-send '<command>', just shot <place> [width] [repo]. Agents no longer touch the dev profile's data.
  • CODING_STANDARDS.md for reviews, and two DESIGN.md rules: Undo, and the Danger zone.
  • The scripted Daemon of the App's tests answers a command as the real one does: daemon.answer({ events, error }).
  • Ticket 29 records the follow-up: the gallery as an app of its own, with just gallery.

Evidence #

  • Before: nothing could register a Repo. AppCommand = never. After: just check passes (lint, Daemon types, nsh check). just test passes: 20 Daemon tests and 31 App tests.

Daemon tests (a real Daemon, real jj, throwaway local git repositories served by the fake GitHub):

register acme/api        → ready, no setup command, Cyber off, .jj and README in the clone, snapshot holds it
change both settings     → kept after a restart
restart mid-clone        → the clone starts again → ready
GitHub has no acme/apii  → failed: "GitHub has no repository acme/apii, or Pilot cannot see it."
jj cannot clone          → failed: "jj could not clone it: …" → Try again → ready
remove a cloned Repo     → gone from reposChanged, clone folder deleted, GitHub's copy stays
remove while cloning     → the clone stops, no folder left, no event after
a GitHub link           → registers acme/api; other link shapes → "a Repo already"
"acme", "Acme/API"       → refused in plain words

App tests (against the scripted Daemon):

paste a GitHub link → registerRepo acme/api, its page opens
Add Repo           → registerRepo sent, the Repo's page opens on "Pilot is cloning acme/api with jj."
refused            → "acme/api is a Repo already." shows, the field keeps the text
Repo page          → Save setup command and the switch send changeRepo
failed clone       → why shows, Try again sends cloneRepo
Remove this Repo   → asks first; "Keep the Repo" sends nothing; confirm sends removeRepo → back to the list
Daemon stops       → "Pilot could not load this Repo."

Checked by hand with the real gh and jj (scratch and dev Daemons): octocat/Hello-World cloned, a missing repository failed with GitHub's reason, microsoft/TypeScript was removed while it cloned, and the loader icon turns on macOS. Pictures: just shot Repos 1240 octocat/Hello-World.

Merge Danger #

Door: two-way

The new pilot_repos table sits beside Pi Durable's tables in the same SQLite file. A rollback leaves the table and the repos/ folder behind. Older code ignores both.

Blast Radius: Daemon

  • The Daemon now runs gh and jj. The launchd agent gets the PATH of the deploy, so deploy from a shell that has both.
  • A private Repo over HTTPS needs gh auth setup-git, or its clone fails with jj's reason.
  • Repo in the protocol has new fields. The App and the Daemon deploy together.
  • CI's daemon job now installs git and jujutsu.
  • The new lint rules fail on any screen that styles its own text or badges. Only app/home.tsx (until ticket 07), app/Shell.tsx and the gallery may.
Commits 1

feat(repos): register Repos and keep a jj clone of each
Sign up or Sign in to add to the discussion.