Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ The log comes from files on this machine, so it needs the board runner to have r
this worker did not run on this machine", and the rest of the board works as before. The log route accepts only a
`<board>/<label>` of the shape the runner makes, and never reads outside that board's `workers/` folder.

### Commits

A fact whose worker committed its work carries a `Commit: <sha> on <branch>` line. Its drawer then offers:

- **View on GitHub (if pushed)**, when the board's goal has a `Repo: owner/name` line. Set `repo = "owner/name"` in the
board file: `/blackboard start` writes the line into a new board's goal, and adds it to an existing goal that lacks
one. Board branches stay local until someone pushes them, so the link shows the commit only after a push (to the repo
or a fork).
- **A Diff tab**, from the board's workspace on this machine, so it needs no push. "This commit" shows `git show`, and
"All changes vs main" shows every commit on top of `origin/HEAD` (or `origin/main`, `main`, `master`) and their diff.
The board runner records the workspace in its `state.json`; a board whose runner has not been restarted since says
so. The `/diff/<board>/<sha>` route accepts only a board name and a hex SHA, runs `git` without a shell, external
diff tools or a pager, stops after 10 s and returns at most 2 MB.

### Later: hosting

The browser code calls `/api/...` only, so a login front door could replace the local proxy later. Worker logs would
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test:int": "deno test -A tests/integration",
"test:e2e": "deno test -A tests/e2e",
"test:db": "supabase test db",
"web": "deno run --allow-net --allow-read --allow-env --env-file=.env web/server.ts"
"web": "deno run --allow-net --allow-read --allow-env --allow-run=git --env-file=.env web/server.ts"
},
"fmt": {
"lineWidth": 120,
Expand Down
59 changes: 59 additions & 0 deletions docs/superpowers/plans/2026-11-27-commit-diff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Commit diffs in the web UI — Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Show a worker's commit as a GitHub link (from a `Repo:` goal line) and as a local diff in the drawer.

**Architecture:** The runner accepts `repo` and records its workspace in `state.json`; the skill's start recipe writes
`Repo:` into the goal; the local web server gains `GET /diff/<board>/<sha>`; the drawer gains the link and a Diff tab.

**Tech Stack:** Python 3.11 stdlib; Markdown skill; Deno server; plain ES modules.

**Spec:** `docs/superpowers/specs/2026-11-27-commit-diff-design.md`

## Global Constraints

- `repo` is `owner/name`: `^[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9._-]+$`, at most 100 characters.
- A commit is the first `^Commit: ([0-9a-f]{7,40})\b` line of a memory's content; `Commit: none` is no commit.
- Link: `https://github.com/<repo>/commit/<sha>`, text "View on GitHub (if pushed)", `rel="noopener noreferrer"`,
`target="_blank"`.
- `/diff`: board `^[a-z0-9]+(-[a-z0-9]+)*$`, SHA `^[0-9a-f]{7,40}$`, `view` `commit` (default) or `main`; git with no
shell, `--no-pager`, `-c core.pager=cat`, `--no-ext-diff --no-textconv`, `-C <workspace>`; 10 s timeout; output
capped at 2 MiB with `truncated: true`. GET only, like `/logs`. Errors: 400 bad shape, 404 no workspace recorded /
unknown board / not a commit, 504 timeout. `deno task web` adds `--allow-run=git` and nothing else.
- Browser text through `textContent` only; no `innerHTML`.

## Review Focus

1. A SHA or board that is not the exact shape never reaches `git`; `view` other than the two values is 400.
2. A huge diff is cut at 2 MiB without breaking a UTF-8 sequence, and says so.
3. A board whose state has no `workspace` (runner not restarted) shows a clear message, not an error.
4. `Commit: none on …` gives neither link nor tab.

### Task 1: Runner and skill

**Files:** `runner/board_runner/board_file.py` (optional `repo`, validated), `runner/board_runner/cli.py` (`state["workspace"] = str(bf.workspace)` when the state is saved at start), `skills/blackboard/start.md` (goal template `Repo:` line when the file has `repo`; step 4 adds a missing `Repo:` line only), `skills/blackboard/SKILL.md` if it lists goal lines, `runner/README.md` (board file table). Tests: `runner/tests/test_board_file.py`, `runner/tests/test_cli.py`.

- [ ] Tests: `repo = "springfall2008/batpred"` loads; absent → None; `"not a repo"` and a 101-character value → `BoardFileError` naming `repo`; after `run`, `state.json` has `workspace` equal to the board file's workspace.
- [ ] Run `cd runner && python3 -m unittest` — fail; implement; pass.
- [ ] Commit `feat(runner): repo key and the workspace in state.json`, then the skill edit as `feat(skill): Repo line in the goal`.

### Task 2: Local `/diff` route

**Files:** create `web/lib/diff.ts` (`serveDiff(url: URL, runnerHome: string, run?: GitRunner): Promise<Response>`, with `type GitRunner = (cwd: string, args: string[], timeoutMs: number) => Promise<{ code: number; out: Uint8Array; timedOut: boolean }>`), modify `web/server.ts` (route `/diff/`), `deno.json` (`--allow-run=git`). Tests: `tests/unit/web-server.test.ts`.

**Produces:** `GET /diff/<board>/<sha>?view=commit|main` → 200 `{ sha, view, base: string | null, text: string, truncated: boolean }`.

- [ ] Tests with a fake `GitRunner` and a temp runner home: bad board / SHA / view → 400 and the runner is never called; no state file or no `workspace` → 404 `{ error: 'No workspace recorded for this board: restart its board-runner' }`; `cat-file` not `commit` → 404; `view=commit` runs `show --stat --patch` with the safety flags; `view=main` resolves the first existing base and runs `diff --stat --patch <base>...<sha>` plus `log --oneline`; output over 2 MiB is cut at a UTF-8 boundary with `truncated: true`; a timeout → 504; POST → 405.
- [ ] One test against a real temp git repo (two commits) for both views.
- [ ] Run `deno task check && deno task test:unit` — fail; implement; pass.
- [ ] Commit `feat(web): local /diff route for a board's commits`.

### Task 3: Drawer link and Diff tab

**Files:** `web/public/commits.js` (pure: `commitOf(content): { sha: string; branch: string | null } | null`, `githubCommitUrl(repo, sha): string | null` (null unless `repo` matches the shape)), `web/public/status.js` (`parseStatus` gains `repo`), `web/public/drawer.js` (link under the content; a Diff tab with the two views), `web/public/style.css`, `README.md` (Web UI: the Diff tab and the `repo` key). Tests: `tests/unit/web-public.test.ts`.

- [ ] Tests: `commitOf` for `Commit: faf6fed5 on board/x/e98ecb9f`, a 40-char SHA, `Commit: none; branch …` → null, no line → null, uppercase → null; `githubCommitUrl('springfall2008/batpred', 'faf6fed5')`; a bad repo → null; `parseStatus` reads `Repo:`.
- [ ] Run `deno task test:unit` — fail; implement; pass; `deno task check`.
- [ ] Local smoke on the local server: a fact from a live board shows the link and both diff views.
- [ ] Commit `feat(web): GitHub link and local Diff tab for a fact's commit`.
43 changes: 43 additions & 0 deletions docs/superpowers/specs/2026-11-27-commit-diff-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Commit diffs in the web UI — design (small change)

Status: approved in conversation, 2026-11-27.

## Why

Board workers commit their work on local branches and write `Commit: <sha> on <branch>` into their facts. The person
wants to see those diffs from the web UI. The SHA is already in the database (in the fact). What a reader elsewhere
lacks is the repository it belongs to; and the commits stay local until someone pushes them.

## What

- **Repository in the database.** A board file may name its GitHub repository: `repo = "owner/name"` (optional). The
start recipe writes it into the goal as a `Repo: owner/name` line after `Ideas model:`. For an existing board whose
goal lacks a `Repo:` line, `start from=` adds that one line and changes nothing else: a second narrow exception to
"from= never edits an existing board", allowed because it is metadata that cannot change what the board does.
The runner accepts the key (it validates `owner/name`) and does nothing else with it.
- **View on GitHub.** A memory with a `Commit: <sha>` line shows a "View on GitHub (if pushed)" link to
`https://github.com/<repo>/commit/<sha>` when the board's goal has a `Repo:` line. Shown anywhere, to anyone. No
GitHub API call checks whether the commit exists.
- **Local Diff tab.** On the same memories, when the web UI runs on the machine with the board's workspace: a Diff tab
in the drawer with two views, "This commit" (`git show <sha>`, the default) and "All changes vs main"
(`git diff <base>...<sha>`, with its commit list; `<base>` is the first of `origin/HEAD`, `origin/main`, `main`,
`master` that exists). Added lines green, removed red, hunk headers blue.
- The runner records its board's workspace in `state.json` (`workspace`). The local web server reads it from
`~/.board-runner/<board>/state.json` (or `$BOARD_RUNNER_HOME`), as the worker logs already do. Without it the tab
says to restart the runner.
- `GET /diff/<board>/<sha>?view=commit|main` on the local server: the board name and SHA must match strict shapes,
the workspace must be a directory, the SHA must name a commit (`git cat-file -t`). `git` runs without a shell,
with `--no-ext-diff --no-textconv` and `-c core.pager=cat`, a 10 s timeout and at most 2 MB of output (marked as
cut short). `deno task web` gains `--allow-run=git` only.
- Nothing is pushed and nothing about pushing changes; `Commit: none` gets neither link nor tab.

## Approaches

A GitHub link alone needs the branches pushed, which the person does not want by default; a local diff alone is
invisible elsewhere. The person chose both: the repository in the database so the link works anywhere once pushed,
and the local diff for the machine that has the data.

## Left to the builder

Module boundaries (a pure `commitOf` / `githubCommitUrl` in the browser, a `web/lib/diff.ts` beside `logs.ts`), the
JSON shape of `/diff`, and the tab's layout.
5 changes: 3 additions & 2 deletions runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Runner state lives in `~/.board-runner/<board>/`, or under `$BOARD_RUNNER_HOME`:
- `workers/<slot>-<label>.jsonl` and `.err`, one pair per worker run: the `.jsonl` is the worker's `stream-json`
transcript, written live, and the newest 200 runs are kept;
- `measure/<n>.log`, one per measurement;
- `state.json`, the lead's session and label plus the running workers, used to resume after a restart (a finished worker
is removed from it);
- `state.json`, the lead's session and label, the board's workspace (the web UI shows commit diffs from it) and the
running workers, used to resume after a restart (a finished worker is removed from it);
- the `lead-settings.json` and `oneshot-settings.json` the runner generates.

## Board file
Expand All @@ -80,6 +80,7 @@ TOML. Unknown keys are errors, so a typo is never silently ignored. See `example
| `[measure] timeout_minutes` | 30 | A measurement that runs longer fails |
| `[measure] exclusive` | false | Let running workers finish, and start none, while measuring, for timings |
| `usage_env_file` | none | An env file with `AGENT_MEMORY_TOKEN` and `WEB_API_URL`, for token usage (`~`) |
| `repo` | none | The GitHub repository, `owner/name`; written into the goal so commits link to it |
| `[lead] model` | opus | Any `--model` value, or `ollama:<name>` |
| `[lead] round_every_minutes` | 20 | Heartbeat round interval; 1 to 29, since the lead claim lasts 30 |
| `[lead] ideas_model` | inherit | Model of the sub-agent the lead asks for ideas when stuck: inherit, name, none |
Expand Down
15 changes: 14 additions & 1 deletion runner/board_runner/board_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from typing import Any

PUSH_DENY = "Bash(git push*)"
# A GitHub repository, owner/name: the start recipe writes it into the goal so a commit links to GitHub.
_REPO = re.compile(r"^[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9._-]+$")
_BOARD_NAME = re.compile(r"^[a-z0-9]+(-[a-z0-9]+)*$")


Expand Down Expand Up @@ -57,11 +59,12 @@ class BoardFile:
worker_timeout_minutes: int
# An env file holding AGENT_MEMORY_TOKEN and WEB_API_URL for sending token usage; a path, never the secret.
usage_env_file: Path | None = None
repo: str | None = None


_TOP_KEYS = {
"board", "scope", "workspace", "goal", "done_when", "rules",
"max_open_intents", "claim_minutes", "max_intents", "measure", "lead", "worker", "permissions", "usage_env_file",
"max_open_intents", "claim_minutes", "max_intents", "measure", "lead", "worker", "permissions", "usage_env_file", "repo",
}
_MEASURE_KEYS = {"command", "pass_exit_code", "timeout_minutes", "exclusive"}
_LEAD_KEYS = {"model", "round_every_minutes", "ideas_model"}
Expand Down Expand Up @@ -196,4 +199,14 @@ def load_board_file(path: Path) -> BoardFile:
max_budget_usd=budget,
worker_timeout_minutes=worker_timeout,
usage_env_file=Path(_text(data, "usage_env_file")).expanduser() if "usage_env_file" in data else None,
repo=_repo(data),
)


def _repo(data: dict[str, Any]) -> str | None:
if "repo" not in data:
return None
value = _text(data, "repo")
if len(value) > 100 or not _REPO.match(value):
raise BoardFileError("repo must be a GitHub repository as owner/name, for example springfall2008/batpred")
return value
3 changes: 2 additions & 1 deletion runner/board_runner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def run(self, takeover: bool = False) -> int:
session_id = state.get("lead_session_id")
resume = bool(session_id)
session_id = session_id or str(uuid.uuid4())
state.update({"lead_label": label, "lead_session_id": session_id})
# The local web UI reads the workspace from here to show a fact's commit diff.
state.update({"lead_label": label, "lead_session_id": session_id, "workspace": str(self.bf.workspace)})
self.save_state(state)
self.lead_label = label

Expand Down
8 changes: 8 additions & 0 deletions runner/tests/test_board_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def test_full_example(self):
self.assertEqual(bf.max_budget_usd, 20)
self.assertEqual(bf.worker_timeout_minutes, 180)

def test_repo_is_optional_and_must_be_owner_slash_name(self):
self.assertIsNone(load_board_file(self.minimal()).repo)
add = lambda line: self.minimal(replace=('rules = "Compute only."', f'rules = "Compute only."\n{line}'))
self.assertEqual(load_board_file(add('repo = "springfall2008/batpred"')).repo, "springfall2008/batpred")
self.assertRejects(add('repo = "not a repo"'), "repo")
self.assertRejects(add(f'repo = "o/{"x" * 99}"'), "repo")
self.assertRejects(add("repo = 3"), "repo")

def test_usage_env_file_is_optional_and_expanded(self):
self.assertIsNone(load_board_file(self.minimal()).usage_env_file)
bf = load_board_file(self.minimal(replace=('rules = "Compute only."', 'rules = "Compute only."\nusage_env_file = "~/x.env"')))
Expand Down
7 changes: 7 additions & 0 deletions runner/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ def test_worker_stdout_file_is_jsonl(self):
self.assertTrue(logs)
self.assertEqual({Path(n).suffix for n in logs}, {".jsonl", ".err"})

def test_state_records_the_workspace(self):
h = self.harness()
h.at(5, lambda: h.lead_says("BOARD-LEAD done"))
h.runner.run(takeover=False)
state = json.loads((h.board_dir / "state.json").read_text())
self.assertEqual(state["workspace"], str(h.bf.workspace))

def test_finished_worker_leaves_state(self):
h = self.harness()
seen = {}
Expand Down
12 changes: 9 additions & 3 deletions skills/blackboard/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,23 @@ you read with the Read tool. The file is the person's approval: ask nothing.
- Take `max_open_intents` (default 4), `claim_minutes` (default 60) and `max_intents` (default none).
- `Measure` is `yes` when the file has a `[measure]` table, otherwise `no`.
- `Ideas model` is the `[lead]` table's `ideas_model` (default `inherit`).
- `Repo` is `repo`, when the file has it.
2. **Look for the board.** Call `graph` with `tags_all ["board:<project>", "kind:goal"]`, full detail. A `state:paused`
goal counts as `state:running` in step 4.
3. **No goal:** write the board as in step 4 above.
- The goal follows the goal template, with `Goal:` from `goal`, `Done when:` from `done_when`, and the numbers from
the file. `Started:` is today's date, `by board file <file name, without its directory>`.
- The rules memory holds `rules` exactly as written.
- End with `BOARD-START created <goal id>`.
4. **The goal is `state:running`:** write nothing. Compare the file's goal, Done when and rules with the memories. List
each one that differs, in a line or two. End with `BOARD-START exists`.
4. **The goal is `state:running`:** write nothing, with one exception. Compare the file's goal, Done when and rules with
the memories. List each one that differs, in a line or two. End with `BOARD-START exists`.
- The exception: when the file has `repo` and the goal has no `Repo:` line, `update` the goal with its content plus
one line, `Repo: <repo>`, after its `Ideas model:` line (or at the end when there is none). Change no other byte;
keep its tags. Say that you added it. A `Repo:` line that is already there is never changed.
5. **The goal is `state:stopped`, its conclusion contains `Stopped: intent limit`, and the file's `max_intents` is
higher than the goal's `Max intents`, or is absent:** follow SKILL.md's `resume` with that limit. End with
`BOARD-START resumed`. This is the only change `from=` ever makes to an existing board.
`BOARD-START resumed`. Apart from the `Repo:` line in step 4, this is the only change `from=` ever makes to an
existing board.
6. **Otherwise** (done, stopped for another reason, or a limit that isn't higher): say why, write nothing, and end with
`BOARD-START not-running`.

Expand All @@ -68,6 +73,7 @@ Max intents: <n, or none>
Claim minutes: <n>
Measure: <yes if a measurement must confirm the goal before it is concluded, otherwise no>
Ideas model: <the model of the sub-agent the lead asks for ideas when stuck: inherit, a model name, or none>
Repo: <the GitHub repository as owner/name; only when the board file names one>
Started: <ISO date> by <the person>
```

Expand Down
Loading
Loading