kunibert
All repositories: gitoria
9.4 KB
# K6 posting to gitoria: reportBuilt against `apps-api.md` v1 plus the design consultant's points (a)–(e). Tested only against a local FAKE gitoria and a fake codex. No real gitoria, no real codex, no commits, no tickets.## Files- NEW `lib/gitoria-api.hl`: client. Every [OPEN] name (routes, `context = 'kunibert'`, page limit, retry caps) is at the top of this file. `connect(api, keyFile)` checks the key file has mode 600 (via `stat -c %a`) and reads its first line. `getToken(fresh)` POSTs `/apps/token`. The token is cached IN MEMORY only (nothing on disk) until 120 s before `expires`; ISO strings are compared as text. `call()` handles 401 (one new token, one retry) and 429 (waits Retry-After, capped at 60 s, up to 3 tries). Other answers come back as `{status, ok, body, code, message, details}`. `must()` turns a failure into an error. `scrub()` removes the key and token from any message. `listAll` reads every page.- NEW `lib/review-post.hl`: status (`startStatus`/`finishStatus`/`errorStatus`), `threadInput` (API threads -> local keys by `gid`, humans only, `comment.seq` as the watermark), `newSideRanges` (`git diff -M -U3 <merge-base>..<head>`, new-side hunks), the earlier reviewer's format (badges 🛑🔶🔹💬, `### Axis (N new, M still open)`, `_Not on changed lines:_`, `_Still open from earlier rounds:_`), `postReview`, `postReplies`, `statusFor`.- CHANGED `lib/review-memory.hl`: `threadUpdatesFrom(state, array)` (`threadUpdates(state, file)` is now a wrapper, so the local mode still works); a new thread gets `gid = null`; the default state gets `verdict = null`.- CHANGED `lib/runner.hl`: `runReview(..., hooks = null)` and new `reviewGitoria(data, api, keyFile, clone, pr, forced)`. `reviewPr` and `review` are untouched.- CHANGED `tools/runner.hl`: new `review-pr` form and a global error handler (see Commands).- `lib/gitcache.hl` is not changed.## Commands```cd /media/STORAGE/projects/kuniberthybriel tools/runner.hl review-pr <data> --api <url> --key-file <file> --clone <url> [--force] <pr-number># old forms unchanged: review-pr <data> <remote-url> <pr> <base> [--token-file f] [--threads f] [--force] | review ... | reset ...# proof (starts and stops its own fake gitoria on 127.0.0.1:8846):cd /media/STORAGE/claude-scratch/kunibert/K6 && python3 -I scripts/proof.py > proof-output.txtpython3 -I /media/STORAGE/claude-scratch/kunibert/K4/proof.py # ALL OK after my changes```## Flow1. `connect`, then `GET pulls/N`. If `state != open`, the run returns `{"skipped":"not_open"}`.2. The token goes into a 0600 temp file `<data>/.token-<ms>` and is passed as the existing `--token-file` path of `fetchRefs`. The file is removed right after the fetch; `cleanup()` removes it on any failure too. This is the temp-file option (gitcache untouched).3. `GET pulls/N/threads` (all pages) feeds the memory. Only comments with `author.type == user` count, and only those with `seq` above the stored watermark. Resolved flips come from `thread.resolved`.4. Skip check (same head, nothing new): no write call at all.5. Status `pending` is set only when a review will be posted (new head or `--force`). A wake-up for a thread reply on an unchanged head sets no status.6. The model runs. Then `getToken(true)`, a fresh token right before the write phase (a).7. `postReview` works on the reviewed head, not the PR's current head (b). It checks lines against the local `git diff -M -U3 <merge-base of that head>..<head>` and moves misses to the body. At most 100 inline comments; the rest go into the body. The body limit is ONE constant, `maxBody = 65536` in `lib/review-post.hl` (c); longer bodies are truncated with a note. A 422 with details moves those comments to the body and the review is sent once more. A 409 `stale_head` returns `{"skipped":"stale_head"}`: no further status call, state not advanced.8. The ids of the new threads are matched from the answer by path and line and stored as `gid`.9. The model's `replies` go to `POST threads/:gid/replies`, and `resolve:true` also to `POST threads/:gid/resolve`. These failures are warnings in the output, because the review is already posted.10. Final status: `failure` for request_changes, otherwise `success`. Summary: "<n> new finding(s), <m> thread replies".11. (d) The review POST is skipped when head, verdict and findings are unchanged and the run was not asked for (`--force`). Replies and resolves still go to their threads; there is no review POST and no status call.12. (e) ```` ```suggestion ```` fences are rewritten to plain code fences in comments and body.13. Any error: `cleanup()`, full text (scrubbed) to stderr and stdout JSON, status `error` with a first-line summary (<= 140 characters) only if a `pending` was sent, never a PR comment.## Proof (K6/proof-output.txt, ALL OK, fake gitoria stopped by PID)Fake gitoria: `K6/scripts/fake_gitoria.py`. It logs every request in `K6/fake.log` and has switches for 401 once, 429 once, 422 on one line and 409. It checks inline lines against the real diff of the local bare repo. Fake codex: `K6/bin/codex`. The fetch used `file://` (the clone URL passed with `--clone`), so Basic auth over git was NOT exercised against a server.- s0: key file mode 644 -> refused, no request.- s1: first run. Writes were exactly PUT pending, POST review, PUT failure. The review had one inline comment, a.txt:15, body `**🛑 Blocker · Correctness: Bad change**…`. The off-diff finding (a.txt:1) sits under `_Not on changed lines:_`. Headers read `Correctness (1 new, 0 still open)`. State: T1 gid `th1`, T2 gid null.- (a) 2 token requests per posting run: one at the start, a fresh one after the pending PUT and before the review POST.- s2: same head -> `{"skipped":true}`, no write request.- s3 (d): a human reply on an unchanged head. Writes were exactly one `POST threads/th1/replies`: no review, no status.- s4: 409 -> `{"skipped":"stale_head"}`. Writes were pending and the rejected review POST. Nothing stored and no status after it; local state head not advanced.- s5: human reply (seq above the watermark) plus a new commit, with 401 once. Only the NEW reply reached the prompt. Writes: pending, review, reply, resolve, success. The thread `th1` is resolved with the model's reply. 3 tokens (start, refresh after the 401, fresh before the write).- s6: 429 once -> 1.2 s wait, the same request repeated, success.- s7: forced 422 on a.txt:16. Two review POSTs (2 comments, then 1). Line 16 appears in the body under "Not on changed lines".- s8: threads read with `limit=100`, then `&cursor=1` (page size 1 in the fake).- s9: fake codex fails -> exit 1, writes were pending and `error` only. Status summary: `Review could not run: …codex failed (1):`. No review, no comment.- s10: 16 tokens and the key were grepped in 103 files: tool outputs, stderr, the data dir (state, git cache), codex call dirs, `**/*.log` under the project, and the fake log with its `auth` fields removed. Not one hit. The token is only in memory, the 0600 temp token file (removed) and the Authorization header.- K4 `proof.py` still ALL OK.## DOCS- HL strings have NO backslash escapes: `'\n'` is two characters. A real newline needs `JSON.parse('"\n"')` or a literal newline in the source. I found this by trying; the primer does not say it. NOTE: the existing `lib/gitcache.hl` `readToken` uses `split('\n')`; harmless for a one-line file, but it is the same trap.- `fetch` does not raise on non-2xx; it returns `ok = false` with the body. Only connection errors are raised (documented in fetch.readme.md).- hl:fs `stat` has no mode field; the mode check uses `stat -c %a`.- `console.error` exists (used for stderr).## GAP- GAP: objects are passed by value into functions, so a mutation inside `postReview` is not seen by the caller. I returned `gids` instead of mutating. Probably as designed, but the primer does not say it.- GAP: inside an object literal, a key named like an earlier variable shadows it for the later fields. Minimal repro: `rp = f()` then `{ replies = rp.sent, warnings = replies.warnings }` -> "reading 'warnings': the value is Number". I only renamed the variable.- No other framework gaps.## Open points- `suggestion` is only rewritten after the fact; the prompt files (`review-prompt.hl`, `review-wake.hl`) are outside my scope. The "no suggestion blocks, use a normal code block" line should go there.- The 409 skip leaves the codex session one turn ahead of the stored head/state (the model remembers findings that were never posted). The next event reviews a newer head anyway; no clean fix without resetting the session.- Findings moved to the body have `gid = null`: they cannot be replied to in a thread, and a model reply to them is only a warning. The "@bot" way (kunibert#1 lessons) is not built.- The `error` status summary starts with a file path (the HL error location). It is short and contains no secret; stripping the path prefix would be cosmetic.- Verdict-change rule (d) compares with the last verdict stored in state; the state of old runs has none, so the first run after the upgrade posts once.- `review_requested` / `@kunibert` notes: the caller must pass `--force` for them. The intake worker has to map those events to that flag.- Contract v1.2 (review on an earlier head, 409 only for a sha that was never a head) is not in the fake; the client already posts for the reviewed head and treats 409 as skip.- Basic auth for git over HTTPS was not tested against a real server (file:// in the proof).- The two runs of the same PR still need to be serialized by the caller (as in K4).
Branches
Latest commits
- bd3591c7conductor: gates run on the live day44 binarymre
- 47f747a7records: jukebox #9 fix livemre
- 0a3169fdMerge branch 'vendored-size' into mainKunibert
- e447bb09Vendored size fix: keep renames with an app side whole; type the filter parameter (L10)mre
- 99ccc742Vendored size fix: no renames in the app diff, filter the resumed delta toomre
- 1a52e100|||PR Diff size limit counts only app files when vendored paths are setmre
- 50a1867estatus: jukebox #9mre
- c57484e6log: jukebox #9 diff sizemre
- 795a20carecords: guard fix live (PR 8)mre
- 6981d96fMerge branch 'fresh-on-nocmd' into mainKunibert
- 37c47840runner: one shared prompt for both fresh-session fallbacks (L16)mre
- f945d2e1|||PR runner: a resumed run with no command on a new head gets one fresh session instead of a tool errormre
- 10b2a49estatus: PR 314, guard fix proposedmre
- e73995a3log: hycon PR 314 approved after fresh reviewmre
- f60427falog: hycon PR 314 false tool errormre
- 481974f7log: Hermes accepts PR 259 findingmre
- bb0976acrecords: hycon PR 259 design findingmre
- 5c637c24records: hycon PR 259 false tool errormre
- a344c406log: routger 132 reviewedmre
- 56e70dcbrecords: review time limit 1800 s (routger 132)mre