Files
labuh/docs/SPEC.md

136 lines
12 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Labuh — Spec
Status: v0.1, the MVP (milestones 0–3) in use by its first team since 2026-11-06.
Owner: senkensha. Works with gitlab.com (Free tier included).
This file is the single source of truth. Decisions in §3 are settled; changing one is recorded in §8 with the date.
## 1. Vision
**Problem.** Merge and deploy requests from many developers arrive through chat. Blocker discussions scatter between chat and MR comments, and at peak hour nobody can see which requests are waiting.
**Labuh** turns them into a harbour: every request is a boat. An agent reviewer, named by each install, checks each one and says why it may or may not sail, with evidence. A person gives the final **Gas**; Labuh merges, follows the deploy, and says when it docked.
- No request is forgotten or scattered.
- The review runs without waiting for the approver, so developers fix issues before the approver is free.
- A person's Gas stays the final gate.
Same flow as before, only structured. Labuh enforces nothing in GitLab: merge permission stays the gate, so if Labuh is down the manual flow still works.
### North-star test
Every feature must serve at least one:
1. **Nothing gets lost:** every request is visible, in one place, with its state.
2. **Evidence before Gas:** the approver decides on checked findings, not on trust.
3. **The approver stays in charge:** nothing merges, tags or closes without a person's action, and that action can be undone for a moment.
### v0.1 in one sentence
Label an MR `labuh`: the reviewer reviews it within minutes, the approver sees it as a boat on the board, taps Gas, and the boat sails and docks when the deploy is green.
## 2. How it fits together
```
developer ── MR + label "labuh" ──► gitlab.com ◄── polls, comments, merges, tags ── Hub
│ SQLite store
approver ── board (browser, phone) ── Gas / Tunda / Tolak / Rilis ──► store ◄────────┤
│
reviewer (Codex app-server, read-only) ◄───────┘
Telegram group ◄── notifications
```
- **Hub** (`npm run hub -- run`): polls GitLab, keeps the queue, runs the reviewer, validates its output, posts comments, carries out the approver's actions, follows deploys, sends notifications.
- **Reviewer:** Codex app-server in its own container (or, on a laptop, a child process in Codex's read-only sandbox). It holds no GitLab token; every command it asks to run is checked by the Hub's allowlist.
- **Board** (`npm run board`): the harbour. It reads the store and records decisions; it never talks to GitLab except for sign-in.
## 3. Decisions
### Intake
- An MR with the label `labuh` is an ajuan (request). Developers need no new tool.
- One reviewer per hub. Its name comes from `reviewer.json` and is its GitLab bot user, so `@name` mentions reach it.
### Reviewer and output contract
- Runtime: Codex app-server, model pinned in `reviewer.json`. One thread per ajuan for its whole life; each event (opened, new commit, mention) is a resumed turn.
- The reviewer never writes free-form verdicts. It returns schema JSON: `verdict` (`go` | `no_go` | `waiting`), a `reason` (≤ 80 characters), `findings[]` (`bad` | `ok` | `todo`, ≤ 80 characters) each with evidence, and `post_deploy[]` steps with evidence.
- Evidence is a file and line at the reviewed commit, a pipeline job of that commit, or a rubric rule. The Hub resolves every reference.
- Hard rules in code, which the model cannot override (`go` becomes `waiting`): a pipeline that is not green, or a head that moved past the reviewed commit.
- A malformed answer gets one retry in the same thread; a second failure marks the ajuan "reviewer error" and asks for a manual check.
- Mention replies are free text, length-capped, posted by the Hub, and never change the verdict.
- Budget per ajuan in tokens; past it, the ajuan asks for a manual review. The same commit is reviewed again only when the rubric version changes (`recheck`).
### Comments
- Rendered by the Hub from templates: one verdict comment per MR, updated in place, plus a short note after each re-review so the author is notified.
- Labuh ignores notes by its own bot user.
### Board
- One lane per dermaga (environment, from the target branch), three zones: **Dicek** (in review, held, waiting), **Siap gas** (GO), **Beres** (merged, sailing, docked).
- Each lane has two fixed rows of berths. Beres is a fixed berth of two boats per row; when it is full, the boat that docked first sails out (finished boats only). Dicek and Siap gas share the rest of the width and widen to their need; when even that is not enough, boats moor closer together. Boats glide between places; nothing jumps.
- GitLab OAuth sign-in (PKCE, `read_api`). The board keeps only which watched projects the user can read; the user's token is discarded. Approvers are listed in `board.json`; everyone else reads.
- Works on a phone (the detail opens as a sheet from the shore) and at 360 px.
### Gas, release and close
- Gas only for a GO whose reviewed commit is still the head. 15 seconds to undo (`gas.graceSeconds`), then the Hub checks GitLab again and merges with `sha=<reviewed commit>`.
- A refused or failed action clears the decision and notifies; it is never retried on its own. A new commit drops Tunda, Tolak and a Gas still in its grace period.
- After a merge the Hub follows the deploy pipeline: green docks, failed or over 3 hours is Deploy gagal, none after 15 minutes is reported.
- Branches that deploy from release tags (`deployBy: "tag"`): the Hub proposes the next patch tag after the latest `vX.Y.Z` with a changelog since it; the approver keeps or changes the number and presses Rilis; after the grace period the Hub checks again and creates the annotated tag.
- A rejected MR can be closed from the board (Tutup MR), with a comment, after the grace period.
- `gas.mode: dry` runs every check and merges, tags and closes nothing.
### Notifications
- Telegram, to one chat (a team group): ready to Gas, Gas refused or failed, deploy failed or never started, release proposal, reviewer error, reminder after 4 hours without a decision. Each sent once.
### Security
- Three GitLab identities: a reader, the reviewer's bot (comments only), and a separate merge account used only after an approver's action.
- Tokens come from environment variables (or the macOS Keychain locally). Labuh never stores, logs or prints them.
- The reviewer runs apart from the credentials. Hosted, it is its own container reached over a WebSocket with a capability token: no GitLab token, read-only root and checkouts, no capabilities. Codex's own sandbox (bubblewrap) cannot run inside a container, so there the container is the sandbox. Locally it runs as a child process in Codex's read-only sandbox without network.
- Every command the reviewer asks to run (approval policy `untrusted`) passes the Hub's allowlist: read-only programs only, and every path must resolve inside its checkout, its work folder or the configured knowledge folders, never `Credentials/` or `.git`. Checkouts use `core.symlinks=false`.
- MR content and team notes are untrusted data; verdicts are advisory.
### Hosting and stack
- TypeScript on Node ≥ 23.6 with type stripping, zero npm dependencies, SQLite via `node:sqlite`, GitLab through `glab`.
- One Docker image, three containers: Hub, reviewer and board. Configuration and state in `LABUH_HOME` (`/data`). One Hub per store.
- Polling, not webhooks: it only needs outbound access.
### Brand
Terms: ajuan (request), dermaga (environment), antrean (queue), berlabuh (docked). The reviewer has no built-in name: each install names it in `reviewer.json`, and examples use the brand, Labuh. Palette: paper `#F6F2EA`, ink `#172B33`, teal `#1F6F78`, buoy `#E8A33D`. UI text is Indonesian.
## 4. Non-goals
Reopen only after a real incident or an explicit request: a CI gate that blocks merges, trigger-only deploys, unauthorized-deploy alarms, several organisations per hub, GitHub or Gitea, MCP, a CLI for developer agents, break-glass paths, a metrics dashboard, a settings UI, in-app chat, a re-review button, a daily digest.
## 5. Milestones
Each milestone ends with a story the owner acts out; it is done when the story works.
| Milestone | Story | Status |
|---|---|---|
| **0. A review from the terminal** | Point the reviewer at a real MR from a terminal: a verdict that passes the output contract, evidence that opens, a follow-up in the same thread, a disallowed command refused. | Done |
| **1. Reviews on its own** | Label an MR: a verdict comment appears within minutes and updates on push; a mention gets an answer; a broken output ends in "reviewer error"; a restart loses nothing. | Done |
| **2. I see the harbour** | Sign in with GitLab and see the real ajuan as boats, on the laptop and the phone; open a finding's evidence; a developer sees the same board read-only. | Done |
| **3. Gas, and it berlabuh** | Gas from the phone: it merges, sails and docks when the deploy is green; Tunda and Tolak reach the MR; a failed deploy pings; releases are proposed and tagged. | Done |
| **4. Pairs and the whole team** | Linked MRs (frontend + backend): a NO-GO on one holds the other; every team sends deploy requests through Labuh for a week. | Next |
## 6. Milestone 4 — Pairs and the whole team
Detailed when it starts. Known shape: `depends_on` stored as data; a NO-GO propagates to dependents in code at once; a GO waits when its pair changed mid-review (`turn/steer` or the next turn).
## 7. Open questions
1. Where the reviewer's per-ajuan notes are written in the team's knowledge base.
2. Who owns the rubric content, and where it lives.
3. Post-deploy commands (for example `php artisan …`): proposed as manual CI jobs that Labuh starts after Gas, not commands the reviewer runs.
4. Webhooks once the board has a public route.
## 8. Decision changes
- 2026-11-06: plan v2 replaced an earlier gate-heavy design; the developer CLI was cut.
- 2026-11-06: Gas merges through the GitLab API with a separate merge account; notifications go to a Telegram group.
- 2026-11-06: branches that deploy from tags get release proposals with a changelog; the approver confirms the number.
- 2026-11-06: rejected MRs can be closed from the board.
- 2026-11-06: fixed two-row lanes; Beres keeps four boats first-in-first-out; only Dicek and Siap gas resize.
- 2026-11-06: v0.1 released as open source (AGPL-3.0); one Docker image, configuration in `LABUH_HOME`.
- 2026-11-06: the hosted reviewer runs in its own container without GitLab tokens, since Codex's sandbox cannot run inside Docker (Sen chose this over hosting without Docker).
- 2026-11-09: deploy setup (CI, Dockerfiles, compose, manifests) belongs to devops (rubric R13). Deploy findings tag the `devops` users from hub.json instead of asking the developer to change CI; the reviewer never suggests CI edits to the developer (Sen, after lti-api !1380).
- 2026-11-09: a turn the model provider fails (Codex `turn.status: failed`, e.g. 9router "high demand") is not a rejected verdict. The Hub throws `ReviewerUnavailable`, sends nothing back to the model, and the queue waits 2, 4, 8, 16 and 32 minutes before giving up with a comment that says the model could not be reached (lti-api !1388, lti-web-client !859).
- 2026-11-09: a `go` held at `waiting` only by the pipeline hard rule becomes `go` on the next poll once the reviewed commit's pipeline is `success` (same commit, no new review; verdict note edited, "siap gas" notified). A `waiting` the model chose itself is never promoted. The board's waiting label no longer claims "nunggu MR lain" (lti-api !1388).