24 Commits
Author SHA1 Message Date
CatoandClaude 0281dce5cb fix(privacy): signed-out fleet register and health show only what /fleet shows (#1780)
* fix(privacy): signed-out fleet register and health show only what /fleet shows

/api/fleet/register returned the owner's whole register (hidden rows, internal
descriptions) to anyone. Signed out it now returns /fleet's listed rows with
/fleet's fields only and no description, via one loader shared with the page.
The full register needs the owner's session/token or the control bearer.
/api/health answers ok/status/app to strangers; detail needs the bearer. The
live-commit readers (auto-merge, deploy check, ship-report) move to the
public release receipt.

Co-Authored-By: Claude <noreply@anthropic.com>

* test(unit): quarantine the 12 browser tests an agent sandbox cannot run

Explicit tracked list (scripts/test/quarantine-browser.json), skipped off CI
only and printed as QUARANTINED (no Chromium in sandbox). CI runs all of them.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-02 07:45:38 +01:00
CatoandClaude d493876bb0 test(live): the OrangeCat rail's browser doors are driven on the live site, from the box (#1700)
orangecat-rail-check.yml (on demand) runs scripts/test/orangecat-rail-e2e.ts
on the box: it signs real requests with the rail's own secret, read there
and never printed, as the operator's linked OrangeCat actor, and drives what
a Cat Bot's walk_site and use_browser hands drive. A walk that must pass and
one that must fail with its picture; a browser session with open, numbered
elements, click, type, back, a password field refused, the box's own
network and the metadata address refused, close; and the doors' edges
(unsigned, stale, an actor with no account).


Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-13 08:44:03 +01:00
Cato 198d77e523 feat(auth): an agent's token opens a browser session, with the token's power and no more (#1679)
* feat(auth): an agent's token opens a browser session, with the token's power and no more

A browser cannot send a Bearer header on a page load, so a Viewer seat with a
ck_ token was sent to sign-in from /projects, /terminal, the workbench,
history and feedback.

- POST /api/token-session (Bearer ck_ only) mints a link that opens once,
  within two minutes. The link carries a random code; the server keeps its
  SHA-256 (token_sessions, migration 0138). The token is never in the link.
- GET /api/auth/loki/token-session (an AccountKit plugin endpoint) opens it:
  a session for the token's user that ends after an hour, is never
  refreshed, and is recorded as the token's before its cookie is set.
- Such a session reads like the user (pages, GET on the API) and writes only
  where a token is accepted: the proxy marks its writes and person-only
  routes read them as signed out. It never reaches tokens, a shell, the
  password, linked sign-ins or export, nor AccountKit's passkey and second
  factor endpoints. Revoking or expiring the token signs it out.

Tests: scripts/test/token-session.ts (landing paths, the refused routes, the
middleware decision, the wiring); scripts/test/token-session-db.ts in
test:db (single use, expiry, revoked and expired tokens, hash-only storage).

* style(drizzle): format the 0138 snapshot and journal
2026-11-12 22:24:41 +01:00
CatoandClaude Fable 5.2 54a7024cdc fix(queue, runs, chat, ops): an idle run is closed before the next task starts; a blocked pull request is said in the thread; an address to Loki is not the loki project; the builder can be given a memory ceiling (#1678)
* fix(check): the on-demand loop check signs in on the box, and is red when it cannot ask

The first run of loki-loop-check.yml (2026-11-12, run 43188095136) printed
"down: loki e2e could not mint a session on the box" two seconds in, and
the job was green. Three things were wrong:

- The deploy ships the runner a fixed list of scripts and nothing under
  scripts/test, so on the box there was no test to run and no token
  script. The workflow now carries the check's own files with it.
- The check minted an Auth.js session cookie. Sign-in moved to AccountKit
  on 2026-11-01, where that cookie is no session. It now signs in the way
  a runner does: scripts/test/mint-check-token.ts mints an agent token for
  the operator that expires in two hours, the check uses it as a bearer
  and removes it on exit. The cookie mint stays as the fallback.
- A check that could not sign in exited 0. With the verdict asked for, it
  exits 1, and it says why (long strings masked).

scripts/test/loop-check-signs-in.ts pins all of it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): what production showed after the first fix, and why the check could not sign in

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(check): the loop check prints Loki's own reason for a task that does not start

Its first full run on the live site (2026-11-12, run 43191224470) ended
"still queued (Queued) after 35 min" and then guessed at the builder's
sign-in. The run route already answers the track's sentence for an open
run (detail), and the chat's reply says where the task went: the check
prints both, right after the dispatch and again when it gives up.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the first full check on the live site, 4 of 5

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): why the probe did not start, in Loki's own words

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(chat): an address to Loki is not the loki project; the loop check reaches the project it was sent to

A project named in a message outranks the selected project, on purpose
(lib/loki-fleet-commands). The assistant is called Loki and so is one of
the projects, so "Loki, add a dark mode toggle" typed with orangecat
selected was sent to the loki project.

Found through the loop check on the live site (2026-11-12, run
43198552471): asked for project orangecat, it came back "Sent loki to the
cloud runner", because its marker was "[loki-e2e]". Three runs in a row
had waited behind the loki project's open run while reporting on a
project the probe never reached.

- project-mention: withoutAddressTo removes an address to the assistant
  before matching: the name at the start followed by punctuation, after a
  greeting, "@loki", or set off by a comma at the end. "Loki's sidebar",
  "in loki" and a bare "Loki fix the header" still name the project.
- loki-loop-e2e: the marker is "[e2e-probe]" and names no project, and the
  check fails at once when Loki dispatched to another project than the
  one it asked for.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the probe had been going to the loki project; the routing fix

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(queue): a run that has gone silent gives its project to the waiting message

A project's shared session takes one message at a time: the claim gate holds
the next one until the run ahead has closed. A run closes when its agent
reports. An agent that ended its turn without reporting still has a process
at its prompt, and the reaper shelters a run with a live process for up to
MAX_RUN_HOURS, so the next message could wait twelve hours behind a session
that was doing nothing. On the live site (2026-11-12) messages sent through
Loki's chat read "This project is still on an earlier task" and were still
queued 25 to 35 minutes later.

- lib/orchestration/quiet-lane: the rule, pure. The runner beats while the
  terminal prints and while the agent waits at a sign-in or an approval. No
  beat for 20 minutes (twice the window after which every surface says
  Stalled), not waiting for a person, no command outstanding, and still so
  90 seconds after it was first seen: release. The second look covers a
  runner that could not beat for a while and whose first request back is
  the claim.
- db/queries/quiet-lane: reads those facts for the run at the head of each
  lane a message waits in, through olderOpenRunSql, and closes it with the
  reaper's own verdict (partial with the handoff note, else timeout with the
  sentence), ended at its last beat. No escalation.
- claimNextPendingCommand calls it before the gate, so the message is
  claimed in the request that closed the run.
- The waiting sentence carries the bound.

A working agent prints, so its beat is seconds old at any age and it keeps
its lane. Nothing is closed when nobody is waiting.

scripts/test/quiet-lane.ts, and five scenarios in
scripts/test/lane-and-reaper.ts against a real Postgres (13 of 13 locally).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(runs): a pull request that cannot merge is said in the thread, with the message that repairs it

The fleet's sweep merges a green pull request and leaves a red or conflicted
one waiting. A task sent from the chat that ended at such a pull request read
"done, it merges on its own" until somebody opened GitHub.

- feedback/fix-shipping: PrBlocker, prBlockerFor (a conflict when GitHub says
  mergeable: false, else the names of the checks that failed; cancelled and
  still-running are not failures), prBlockerNews (once per commit and reason).
- feedback/fix-shipping-refresh: readBlockers on the refresh input; only then
  are the head commit's check runs and statuses read.
- run-follow-notify: the fifteen-minute follower asks, and on news writes one
  line into the thread the task came from and sends one push. The line ends
  with the message to send ("<project>: fix the failing checks on <pull
  request> and push to the same branch."): a message naming a project is a
  task for it.
- Loki does not send the repair itself: no agent run nobody asked for
  (lib/auto-dispatch).

scripts/test/run-follow-notify.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the 11:17 rehearsal failed on a slow box: sign-up 504, 96% memory, a 503 window

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): bots do not answer on the live site (502, 11:39 UTC); OrangeCat #1672; #1678 green

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(queue): only a run whose runner has reported output can be read as having stopped

A runner from before the beat existed reports nothing while its agent works.
Silence since delivery would have closed such a run after twenty minutes and
typed the waiting message into a working session. A run that has never
beaten now keeps its lane; one that truly never printed is the reaper's,
which closes it as never started from the runner's own unverified ack.

scripts/test/quiet-lane.ts, and a sixth scenario in
scripts/test/lane-and-reaper.ts (14 of 14 locally).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(ops): the box usage report prints the builder's memory budget and finishes on a slow box

On 2026-11-12 the box had 0.6 GiB available and no swap left, and the report
was cancelled at its 20-minute limit inside the first du. Each disk walk now
gets a minute. A new section prints what the runner unit holds, whether it
has a memory ceiling, and which cgroup the sandboxes' processes are in:
sandbox.ts relies on the unit's MemoryMax to bound sealed sessions.

Read-only, names and sizes only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): what holds the box's memory, measured; the builder has no ceiling

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(queue): an idle run is closed before the next task starts; the runner's six-hour stop and a turn answered in seconds are read correctly

Three faults in the idle rule (#1680), found by an independent review and
shown failing first in scripts/test/lane-and-reaper.ts against main (13
passed, 4 failed; 17 of 17 after):

- An idle run stopped holding its project but stayed open until the hourly
  reaper. The next task went into the same session, and its ready handoff
  closes every delivered open run of the project, so the idle run was
  recorded as done with the other run's summary. The claim now closes the
  idle run first, with the reaper's own function and sentence, and only when
  a task is waiting in that project (db/queries/idle-run-close).
- The runner stops beating six hours into a run. Half an hour later the run
  read as idle while it printed, and the next prompt went into a working
  session. A last working beat at that horizon is not read as silence
  (RUN_PROGRESS_HORIZON_SECONDS).
- A turn that ended before the runner began reporting on it never had a
  working beat, read as unknown and held its project for up to twelve hours.
  Every beat stamps lastBeatAt; a run the runner reports on that has printed
  no work since delivery is idle after the same half hour. A run with no
  beat of any size keeps its lane, as before.

scripts/test/idle-run-release.ts, scripts/test/lane-and-reaper.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(ops): the box usage report can be asked for memory alone

The disk walks took the whole 20 minutes twice on 2026-11-12, on a box that
was swapping, when only the memory was wanted. what=memory stops after the
memory sections.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* feat(ops): the builder can be given a memory ceiling, read and set from the Sealed builds workflow

Measured on the box, 2026-11-12 12:19 UTC: loki-box-runner.service held 6.3
GiB with MemoryHigh and MemoryMax at infinity, every sandbox process is in
that unit's cgroup, the box had no swap left, and the kernel had stopped 30
processes for memory since boot: the gateway 15 times, a live site 3 times,
a sandbox 3 times. Every site unit has a 1G ceiling; the builder had none,
though sandbox.ts relies on the unit's MemoryMax to bound sealed sessions.

sealed-builds-ctl.sh gains three modes, run from sealed-builds.yml:
- memory: read. What the builder holds, what bounds it, what the box has left.
- memory-set, runs="<GiB>": MemoryMax and MemoryHigh one below it, and the
  builder's processes are marked to give first when the whole box runs out.
  Refused when the ceiling is below what the builder holds now, because that
  stops sessions at once; "force" after the number sets it anyway. Nothing
  is restarted.
- memory-clear: undo.

Nothing is set by a deploy. It is a decision, applied by a person.

scripts/hetzner/test-sealed-builds-memory.sh, in test:ops.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(runs, chat): the blocked pull request notice is said once and its repair reaches the right project; an address to Loki is set off, and is the project when nothing else is

From the independent review of this branch, each finding confirmed by a
second agent told to refute it.

The notice:
- It would have repeated every tick. "Already said" lived in the ledger, the
  ledger is rebuilt on every refresh, and the dispatch card's own refresh
  does not read blockers. It is kept beside the ledger now
  (payload.prBlockerSaid, per reason), written once the line is in the thread.
- Its repair line named the pull request by link. The link carries the
  repository owner's name, and a project of that name won the match: the
  repair for loki went to Bitbaum. The line names the number, opens with
  "In <project>," and uses a verb the chat's own rule takes as a task, for a
  conflict as well. The test sends it through projectMentionedIn and
  looksLikeDispatchTask for four projects and both reasons.
- action_required and stale count as failed: neither turns green by waiting.

The address:
- "ok loki is broken, fix its header", "loki-loop-check is red" and "run the
  tests on @loki" lost the project; "Loki - add a toggle" kept it. An address
  is the name set off from the sentence (a comma, a colon, any dash with
  space around it, "please", "can you"), at the start of any sentence.
- "loki: fix the header" is read as an address, so a selected project gets
  the work; with nothing selected and no other project named, the name is
  the project (projectNamedByAddress, the last resort of both paths).

scripts/test/run-follow-notify.ts, scripts/test/project-mention.ts (114).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(ops): the builder's ceiling is a ceiling only; docs(handoff): the box's memory, the review's findings, what is ready and not applied

memory-set no longer sets MemoryHigh one below the ceiling: at the moment it
is set the builder holds close to the ceiling, and a mark under what it holds
would slow every session at once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the box's memory now holds up OrangeCat merges: Browser smoke is red on main

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 14:09:49 +01:00
CatoandClaude 69f2f11b22 test(unit): no test can reach the real repository from a push (#1684)
The pre-push hook runs the unit suite with git's hook environment, and from
a linked worktree GIT_DIR is absolute; an absolute GIT_DIR overrides
'git -C <sandbox>'. lane-base.ts (new on main today) made its throwaway repo
that way. Pushing from a worktree on 2026-11-12, its 'init' commit (author
test) replaced every file of the branch being pushed, and its git init and
git config set core.bare, core.hooksPath /dev/null and user.name test on the
real repository. The push's hook failed, so nothing reached GitHub.

worktree-workspace.ts and the shell fixtures each guarded themselves; a new
test did not. The runner now strips git's own repository variables
(git rev-parse --local-env-vars) from every test it spawns
(scripts/test/lib/test-env.ts). scripts/test/test-runner-git-env.ts replays
the hazard between two throwaway repositories and checks the guard; run
against lane-base.ts, an inherited GIT_DIR got its commit unguarded and
nothing guarded.


Claude-Session: https://claude.ai/code/session_019MDtmtCjm3CvrFm3kYaTgy

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 13:44:57 +01:00
CatoandClaude 7f8e731b08 feat(ux): say it on the first screen; a shorter homepage; a header that stays (#1675)
* feat(fields): sixteen text boxes get the microphone; chatkit 0.25

Fleet experience standard, step 9. The experience audit counted 34 hand-made
text areas with no microphone; it now counts 17, and package-plan.json sets
the ceiling at today's counts so the number can only fall.

- @bitbaum/chatkit 0.22.1 -> 0.25.0. Composer behaviour and the class names
  Loki overrides are unchanged; LOKI_VOICE keeps the transcribe route's own
  sentence (showServerDetail), which names the fix.
- <TextArea> (components/ui/text-area.tsx): Loki's one adapter over chatkit's
  DictationField, drawn to match ui-input. Sixteen files use it. One file is
  exempt with its reason on its first line (URL paths, one per line).
- Field takes htmlFor, so its label names the control and a press on it
  focuses the field.
- A signed-out visitor's microphone is the browser's own recogniser
  (VISITOR_VOICE): the server leg answers 401 without a session, so on
  /change the mic recorded a whole take and then failed.
- The widget chat bundle budget goes 40 -> 41 KB: 41,414 -> 41,614 bytes
  gzipped, the two new dictation problems a person can act on.

The other seventeen wait for props the shared field gains in
bitbaum/chatkit#85 (autoFocus, onKeyDown, onBlur/onFocus, name, inputProps).

The stylesheet in this commit also carries the public-site rules of the
next one.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* feat(public): say it on the first screen; a shorter homepage; a header that stays

The way in
- The homepage's one action is the shared composer. What a signed-out
  visitor says is kept in the tab (lib/first-words), shown back on sign-up
  and handed to the new-project form at the end of onboarding or sign-in.
  With a sentence carried, onboarding does not ask for a project name, a
  folder and a GitHub address first.

The homepage
- 10.66 -> 7.48 phone screens at 390x844, 6.6 -> 5.11 at 1440x900.
- Three figures for the three steps, drawn in tokens (LoopFigure).
- Three problems on the homepage, all twelve on /why. Where it runs is one
  sentence and two links. The closing block is the shared FinalCta.
- One label for sign-up everywhere: Start a project.

Header, menu, footer
- The header was sticky in name only: .ui-public-surface was overflow:
  hidden, which made it the sticky container. overflow-x: clip.
- The phone menu takes focus, keeps Tab inside and hands focus back.
- The Product menu opens on a press, not on hover.
- Navigation and Sign in show from 1120px (was 1280px).
- A 2px focus ring, on the public surface and as the app-wide fallback.
- A skip link. Four footer groups instead of five.

Corners
- An unknown address outside the app drew the framework's bare 404 with no
  way back; the in-app one said Back to Today and went to Loki; the error
  page printed the raw error; the loading placeholder drew cards on pages
  that are rows. The share image leads with the headline.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* fix(ux): dates render once; rows say the part that matters; a person's words

- APP_LOCALE is a server variable, so a client component formatted dates in
  the default locale while the server used the configured one: a hydration
  error on /approvals with APP_LOCALE=de-CH. next.config.ts hands the same
  value to the browser as NEXT_PUBLIC_APP_LOCALE.
- Home's running rows lead with the live step. A phone row holds about
  thirty characters and every row read 'Next best step · Editing src/app/pa…'.
- The workbench's three rows on a phone were each cut before the words that
  say what the row is for.
- Terminal without cloud access, Home's first-run row and the widget row use
  the person's words (computer, Loki button), not ours (runner, widget).

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* docs(ux): the November UX pass, the public surface map, the changelog

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* feat(fields): the remaining text boxes get the microphone; chatkit 0.27

The second step of the fleet's experience standard for Loki. The shared
field gained what a form's text area needs in bitbaum/chatkit#85 (0.27.0):
autoFocus, onKeyDown, a submit key, a field-level blur, name, inputProps.
Sixteen more files move onto <TextArea>; the experience audit goes
bareTextareas 17 -> 1 and the ceiling in package-plan.json follows.

Kept, file by file: Cmd/Ctrl+Enter saves where Cmd+Enter did (goal and
person notes, project description, the idea step), Escape still cancels,
Enter still sends an interview answer and confirms a queued prompt, notes
still save when focus leaves the field, and an inline editor no longer
closes when its microphone is pressed. The studio's forms still read their
text by name from the native form. The scheduled job's prompt keeps the
mono face and spell-check off. ProjectBriefFill's separate Speak button is
the field's own microphone now (the same transcribe route).

Left: control/prompt-input.tsx, a prompt box with its own attachments and
paste-to-attach. It is a composer, not a form field.

Checked: tsc, lint, the design gate, file inputs, 599 unit-test files; in a
browser, autofocus, both submit keys, Escape, save on blur and not on the
microphone, 44px microphone and 16px text at 390, and the chat and Home
composers after the bump.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* test: a git fixture cannot reach the real repository from a hook in a linked worktree

A hook run from a linked worktree exports an absolute GIT_DIR, which
overrides git -C <sandbox>. dispatch-launch-dir.ts ran its fixture commands
with that environment, so a pre-push from a second worktree wrote a
test@test init commit onto the branch being pushed and set core.bare = true,
a test identity and a hooks path of /dev/null in the real config. Nothing
reached the remote; the repository was repaired by hand.

worktree-workspace.ts already clears those variables for itself. The unit
runner now clears them once for every test, and dispatch-launch-dir.ts does
so for a direct run. Checked: with a bogus GIT_DIR inherited, the test
passes and the real repository is untouched.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* docs(ux): the text boxes' second step, and what is left

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* chore(deps): chatkit 0.28.1, where a dictated take respects a field's maxLength

bitbaum/chatkit#87, found while reviewing this branch's converted fields.
0.28 also draws a visible border on the composer while it has keyboard
focus and stops thread-following from scrolling the page up.

Checked on 0.28.1: the chat, Home and homepage boxes at 390px in both
themes (text goes in, send enables, no sideways scroll, no console
errors), tsc, lint, the design gate and the widget size test (41 KB
budget holds).

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* refactor(ux): the text boxes and the chatkit raise leave this pull request

The staged rollout gate holds any pull request that raises a shared
package until both chatkit canaries serve that exact version. On
2026-11-12 kivvi and causius served chatkit 0.25.0, the gate could not
match kivvi's deployment receipt to its current commit, and this pull
request raised Loki from 0.22.1 to 0.28.1, so it could not merge.

Everything else in the pass needs no package change. This commit undoes
the three text-box commits (3bae0c40, b210b7c8, 1228a37d) and keeps what
they carried that is not about text boxes:

- the public styles for the homepage, the header, the footer, the skip
  link and the carried sentence (they were committed with the first
  sixteen text boxes);
- the visitor's microphone: the composer adapter takes voice="visitor"
  (the browser's own recogniser), used on the homepage and on /change,
  where the server leg answers a signed-out request with 401;
- the homepage box's shorter placeholder, which fits a 320px phone.

package.json, pnpm-lock.yaml and package-plan.json are main's again.
The write-up says where the text boxes are and what they wait for; the
changelog entry no longer announces them.

The text-box work is unchanged at 1228a37d and follows as its own pull
request.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 13:33:44 +01:00
Cato dcc912e487 fix(auth): an agent's token reads its projects, its account and its conversations (#1677)
A Viewer seat sending its ck_ token got 401 from /api/user-projects, /api/me
and /api/projects/:id, and could not follow a conversation: the middleware
let the Bearer through, but each GET asked for a browser session only.

- GET /api/user-projects, /api/user-projects/:id, /api/me, /api/projects/:id
  resolve the caller with getApiUserId (cookie first, then the token).
- The transcript stream takes a token too (getApiActor); a plain shell stays a
  signed-in person's (mayPeekTab), and the stream stays keyed by the caller.
- Scope is the user's own: owned rows, or a project shared through a
  membership with its role. Writes that change the account or a project stay
  session-only.

Tests: scripts/test/token-session-routes.ts (which handler takes a token,
which does not); scripts/test/token-scope.ts in test:db (a seat's token
reads its shared project read-only, never the owner's other one; expired
and revoked tokens resolve to nobody).
2026-11-12 12:47:24 +01:00
Cato 694961287e test(unit): a machine where node-pty cannot load skips the PTY tests and says why; CI still runs them (#1654)
The terminal tests (executor, sandbox-executor, plain-shell,
terminal-run-view, claude-dialog-not-a-composer) drive a real PTY through
node-pty. Its native binary is built where pnpm install ran; an agent
sandbox that shares the box's node_modules on an older glibc cannot load it
("GLIBC_2.42 not found"). On 2026-11-12 every push from such a sandbox
failed those five in pre-push whatever the change, and the hook's only way
out is --no-verify, which also skips everything that did run.

Off CI only, the runner now probes node-pty once. When it cannot load, a
test that fails with exactly that load error is reported as skipped, with
the reason printed at the top and in the totals; any other failure in the
same file still fails. With CI set the probe never runs, so CI's run stays
the gate.
2026-11-12 08:08:42 +01:00
CatoandClaude 0a936f0023 fix(ux): Home and the Terminal say plainly whether anything is running (#1633)
* ops(hetzner): the disk cleanup reaches what actually fills the box

Its first complete run (2026-11-11, dry) would have freed nothing: every
app was already at two releases and the 127G in use was elsewhere. Six
tiers written from that day's usage report, each dry-run first:

- container logs over 200M are truncated (one was 2.2G), syslog rotated
- /opt/<app>/app-prev-* copies older than 14 days (kivvi kept seven from
  July), never the live app or the rollback target
- superseded browser downloads under ~/.cache: the newest of each is kept
- superseded agent CLI versions: the two newest are kept
- pnpm store prune
- node_modules and build output inside checkouts and agent worktrees idle
  for 14 days and not in use; source is never touched

The target percentage is an input (default 75). Database dumps and
Solon's 17G of places-snapshots are deliberately not here.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq

* fix(terminal): the empty screen says nothing is running

After a restart ended every session the page read 'Pick up where you left
off' over rows of project names, and the owner could not tell whether
anything was running (2026-11-11). The fact comes first now, as a status
line; the heading over the rows says what pressing one does.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq

* test: a failed test file shows the end of its output, not one line

The runner printed only the last line a failed file wrote. An uncaught
assertion ends in its stack and a closing brace, so CI named
terminal-idle-browser as failed three times on 2026-11-11 with '    }' and
never said why. It now prints the last 40 lines.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq

* fix(home): one sentence says whether anything is running, with a way to watch it

The foot of Home's status card read '0 working · 0 awaiting input · 32 idle'
over 'Counts only agents Loki started'. The owner, on a phone on 2026-11-11,
could not tell from it whether anything was running or where to see it.

- lib/running-now states it: 'Nothing Loki started is running right now',
  'N agents working now', or that something waits for a reply
- working agents get a Watch link to the Terminal; a waiting one gets Reply
- the idle count (every project doing nothing) is gone; the caveat about
  agents Loki did not start is in the sentence, not a second line

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-11 13:45:05 +01:00
CatoandClaude 51ca180fa2 feat(auth): Loki on AccountKit's own screens (#1576)
Closes #1566. Loki answered sign-in from AccountKit but drew its own forms;
its sign-up asked for a name and the password twice. On the AccountKit
runtime its sign-in, sign-up, recovery and account panel are now
AccountKit's SignInForm, SignUpForm, PasswordRecoveryForm and AccountPanel,
the same screens as every fleet app (screens: "accountkit").

- Sign-up asks for an email and a password, nothing else.
- Sign-in: OrangeCat, GitHub (Loki's own app, githubSignIn, AccountKit
  0.26.1), the passkey, the password, the sign-in link and recovery, in
  AccountKit's order and words; the demo and the site-widget hint stay
  around the card.
- Settings → Account: AccountKit's panel (ways to sign in, passkeys, the
  second factor). Loki keeps its own name, password change (through
  AccountKit's endpoint when the credential is AccountKit's) and its own
  deletion (DELETE /api/me, every table; accountDeletion: false).
- The sign-in hook's bootstrap (Loki row, personal org) is unchanged and
  runs for AccountKit's sign-up too; a note's tracking link is claimed
  before onboarding, as the old form did by hand.
- Auth.js (AUTH_RUNTIME unset) keeps Loki's old forms.

Journeys (real Postgres, test:db): AccountKit sign-up gives a Loki row
and a personal org; its password change works on an imported Loki hash
and ends the old one; its deletion answers 404 and Loki's row stays; the
GitHub-only / no Google, X or env owner key journey is kept. Browser
(scripts/test/accountkit-screens-browser.ts, 390 and 320px): sign-up
fields, sign-in order, the panel, adding a passkey and signing in with it.


Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-03 01:02:01 +01:00
CatoandClaude Opus 5.5 b495bedb95 feat(change): a new account's build goes to a person instead of a 403 (#1329)
* feat(change): a new account's build goes to a person instead of a 403

On /change, "Make it real" from any account but the operator's met
"Previews are built on Loki's own computers, which this account does not
have" and stopped. The cloud builder only claims the operator's commands,
and that boundary stays; what changes is that the request no longer dies.

- It is filed (build_requests, migration 0119) with the before/after the
  visitor just saw, once per brief however often it is sent, and the
  operator is told by push, Telegram and an alert.
- /approvals shows it (operator only): Approve builds it as the operator's
  client work; Decline sends their note. Exactly one decision wins, and an
  approval whose build cannot start goes back to waiting with the reason.
- The visitor follows it on /change/requests/<id> and gets an email.
- The preview opens with a code of its own (entities.metadata.previewCode,
  read by getProjectPreviewCode wherever a preview is opened or signed for),
  never the operator's code, which opens every preview they have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HyfPCAeTFi2sjpVY44Y1JJ

* docs(telegram): register the build-request notification

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HyfPCAeTFi2sjpVY44Y1JJ

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-19 17:21:51 +02:00
CatoandClaude 39fd13be34 feat(previews): the owner's door — the deployed app hands out a preview's access cookie (#1274)
GET /api/previews/<slug>/cookie, owner only: the cookie minted from the code
they set, set for Loki's /p/ path and named in the body. The owner-side check
(preview-check-on-box.sh) now mints the operator's session on the box, as the
create does, and asks the deployed app for the cookie — so it no longer
depends on how far behind main the box's Loki checkout is, which is what made
it fail twice today. The Set-Cookie attributes have one producer
(previewAccessSetCookie), shared with the gate.


Claude-Session: https://claude.ai/code/session_01Y9KbVEpxKLC9nhKhpWncU1

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-17 20:12:19 +02:00
CatoandClaude Fable 5.1 38a5b5654d feat(previews): before and after, photographed — the tour of what Loki changed on a live site (#1271)
* feat(previews): before and after, photographed — the tour of what Loki changed on a live site

A preview made from a live site (/change "Improve this site") used to end in
improvements.html, a page the build agent styled freehand that Loki could
neither check nor illustrate, and the owner still compared two sites from
memory. Now the build leaves improvements.json (one entry per change naming
the live page and the new file, plus the engineer's account under the
pull-request walkthrough's keys), and Loki shows it:

- `/p/<slug>/_loki/before-after`, behind the preview's own code: each change
  as the live page and the new page photographed on a phone, side by side,
  with the build's words, what was not brought over, the questions for the
  owner, and the account. Pictures are taken by lib/feedback/page-picture on
  first ask and kept in the folder's `.loki/pictures/`; "before" pictures are
  taken the moment the preview starts, while they still are the before; an
  "after" is Loki opening its own preview with the access cookie
  (`x-loki-picture: 1` keeps the widget out of the shot), keyed by content.
- Watch it work links the tour and shows the Walkthrough from the folder.
- The brief says a preview is a first impression, not a migration: the
  homepage and the pages a visitor uses, at the live site's own paths.

The consultation's tour now reads the pages a buyer reads: navigation before
footer, the biggest section (a shop's catalogue) first, one page per section
before the second, accounts and small print left out. center-com.ru's tour had
been the login page, the privacy policy and the bank details.

From the review of this flow: the consultation cache is keyed by the
normalized address (every "Build" click had re-read the whole site inside the
request); a create saves the access code and attaches a host only after every
check has passed; name and folder agree (a leftover folder no longer serves
<name> at <name>-2); the gate no longer names the client; the chat's
read_website reuses the crawl; one in-flight helper; the shared escaper; the
preview route memoizes its project lookup for a page load; stale comments.

Dogfood without a browser: the Previews workflow gets `website` (the exact
/change path, as the operator, on the deployed app) and `check` (open a
preview as its owner and report the site, the tour and its pictures — the
cookie is minted on the box and never printed).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y9KbVEpxKLC9nhKhpWncU1

* fix(watch): the preview walkthrough reads from a lib the shared-access test can bind

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y9KbVEpxKLC9nhKhpWncU1

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-17 19:30:21 +02:00
Cato b58f514ef6 Add scoped Bitbaum studio portal and keep Loki self-service free (#995)
* feat: start request-scoped Bitbaum portal and studio review

* test: prove scoped portal boundaries and restore studio record join

* fix: support canonical studio origin and readable partner review

* fix: support canonical studio origin and readable partner review
2026-09-30 14:49:38 -07:00
Cato 064cad655d fix(runs): one clock for the lane and the reaper — no second prompt into a live session (#896)
* wip: one clock for the lane and the reaper

* wip: database test for the lane and the reaper, wired into CI
2026-09-25 00:09:11 -07:00
CatoandClaude Opus 5 d42dbfed4d fix(ci): a test that never exits is a failure, not a 56-minute wait (#809)
groq-chain-fallback finished its assertions in two seconds, printed its check
mark, and then held every CI run open for FIFTY-SIX MINUTES. It read as "CI is
slow" rather than "a test is broken", so nobody looked.

Its refusal cases drive the vendor-error path, which fire-and-forgets a quota
write: recordRefusal -> persist -> lazy import of @/db -> postgres(url,{max:5}).
Nothing closes that pool, so its sockets hold the event loop open. The file now
ends with process.exit(0), as the other database-touching tests already do
(rag-retrieval, telegram-allowlist). Exiting is safe precisely because the
pending write is worthless: the readings come from a stubbed vendor answering a
fake key, so persisting them would put fiction in the quota table.

Reproduced both directions against a real database: without the exit the
process is still alive when killed at 45s; with it, 1s.

This was invisible locally, which is why it survived -- with no DATABASE_URL the
lazy import rejects and the process exits in two seconds. The hang exists only
where a database does, so test-unit.ts's own header claim that these tests
"behave identically on a laptop and in CI" was quietly false, in timing rather
than in pass/fail.

The runner is the real fix: it spawned every file with no timeout, so one wedged
test set the runtime of the whole suite. It now enforces a per-file deadline
(UNIT_TEST_TIMEOUT_MS, default 120s) and reports a timeout as a named failure
pointing at the likely cause. Proven by mutation: a planted file that wedges the
event loop goes red in 20s instead of running forever.


Claude-Session: https://claude.ai/code/session_01NLZ6vs1jsWw2kKbpWTZHf2

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-20 09:37:42 -07:00
CatoandClaude Fable 5.1 efeabdec64 test(e2e): does Loki work as intended — asked of the live site, on a clock (#712)
Three testable meanings, one script, no browser and no mocks
(scripts/test/loki-loop-e2e.ts, run as the signed-in operator through the
same API the /loki page uses):

1. knows the fleet — a fleet-shaped question is answered from the studio map
   (all three pillars named, fleet_map among the retrieved sources) and the
   reply is an answer, not the model's plan for one;
2. publishes the map — /api/fleet/map is public with the pillars live, and
   bitbaum's map.json is the same map, recently generated;
3. closes the loop (--dispatch) — a request typed into a thread comes back
   into that thread as an outcome turn. A run that never returns is aborted
   with a [loki-e2e] marker so no test leaves the operator's queue hanging.

Proven against production before commit: 3/3 without dispatch; with dispatch
and the builder unauthenticated, the loop failed honestly inside two minutes
with the runner's own diagnosis delivered into the thread.

Scheduled on the box every six hours (install-loki-e2e-watch.sh ->
loki-e2e-check.sh, alert on flip; the dispatch leg only when the builder-auth
probe last said ok). pnpm run test:e2e:loki runs it from a laptop.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 05:17:40 -07:00
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00
1647fe7987 fix(sweep): a test that rotted behind a wrong excuse, and a box spec off by 2x (#480)
Three follow-ups from sweeping the earlier findings. Two of the four I had
carried forward did NOT survive checking and are dropped: /api/control/dispatch
is a real route, so the docs referencing it are correct; and
scripts/test/push-notifications.ts exists. Verifying first is why this commit
is smaller than the list that prompted it.

1. THE TEST NOBODY RAN, FOR A REASON THAT WAS NEVER TRUE

scripts/test/push-notifications.ts read scripts/agent-hook-bridge.sh, which was
deleted on 2026-06-11 in 956ccf64 ("delete the bash daemon and bridge files").
It threw ENOENT and the suite exited 1. Its entry in test-unit.ts SKIP said
"needs push/web-push env — run manually". That was never the reason: every
check in the file is a static file read and it needs no environment at all.

A wrong skip reason is worse than no skip. It answers the question that would
have found the bug, so the red looked accounted for and nobody looked again for
three months.

Retargeted rather than deleted. The behaviour moved instead of going away — a
closing run reaches the operator through notify-close.ts → pushToUser →
push-fanout — and scripts/test/notify-close.ts covers that module without
mentioning push at all. So "an agent finished, tell the operator" was asserted
by nobody. Deleting the check would have quietly ratified that hole.

Removed from SKIP, so it now runs in test:unit (132/132) and therefore in CI.
Mutation-proven: renaming the pushToUser call fails with "notify-close must
call pushToUser" (exit 1); restored, exit 0.

2. THE BOX IS HALF THE MACHINE THE DOCS DESCRIBE

Measured 2026-09-04: nproc 4, 7746 MiB, 75 G disk, 4 GB swap. That is a CX33.
Three docs said CX43, 8 vCPU / 16 GB, 40 GB disk — every figure but the swap
wrong, in the direction that matters: planning against 16 GB on an 8 GB box is
how you meet the OOM killer.

src/app/api/system/hetzner/route.ts has said "the box is a cx33" all along, so
this was code and docs disagreeing with the code being right. Note the shape of
the drift: CPU and RAM went DOWN while disk went UP (40→75), which is what a
disk-inclusive rescale to a smaller tier looks like — plausibly to escape the
disk-full problem the old caveat describes. The June runbook entry is kept as
history and marked superseded rather than rewritten.

The docs now point at /api/system/hetzner instead of restating numbers. A
hardcoded spec is a second source of truth that rots silently, which is exactly
what happened here between June and September.

3. THE COMPOSER STATUS, FINISHED

#479 gave this line its own row below `sm` but kept `sm:truncate`, which left it
at 57% on a 1440 viewport — "Autopilot on: queue is empty, so FleetCr…". That is
the same defect as the phone's 14%, just less obvious, and there is no `title`
here so the remainder is unreachable at every width. It now wraps everywhere.
Costs one toolbar line when the sentence is long; truncating cost the half of
the sentence that says what will happen.

pnpm run verify passes (repo moved to pnpm in #478).


Claude-Session: https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 11:16:58 +00:00
GandClaude Opus 5 caa0e41c3b chore: add a formatter (#449)
* chore: add a formatter, matching the style this repo already writes

singleQuote=false was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier (1062 files)

Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: teach git blame to skip the reformat

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(lint): reattach two guards the reformat detached

Both effects were one-liners, so a trailing eslint-disable-line covered the
setState call:

  useEffect(() => { setSelected(new Set()); }, [q.length]); // eslint-disable-line ...

prettier expanded the block. The comment stayed on the closing line while the
call moved above it, so the guard protected nothing and the rule its author had
deliberately silenced failed the build.

This is the second shape of the same defect — hirnli had the eslint-disable-NEXT-line
variant. Both come from the same fact: an eslint directive binds to a line
number, so reformatting can silently unbind it, which makes 'mechanical, no
behaviour change' false for any bulk reformat.

* chore(desktop): bump the runner version the reformat requires

desktop-release-drift enforces that anything built into Fleet Runner which
differs from the last released tag must carry a version ahead of that tag —
main read 0.8.15 and fleet-runner-v0.8.15 already shipped.

A whole-repo reformat changes bytes under desktop/, so the gate fires. The
alternative was adding desktop/ to .prettierignore, which would buy a quiet PR
by carving a permanent hole in the formatter's coverage — the precise shape of
silent drift this test was written to catch. Bumping is what the rule asks for
and costs one patch release whose only content is whitespace.

* chore: merge main and re-format

A whole-repo reformat conflicts with any concurrent commit, and a conflicting PR
runs no checks at all while reporting nothing. Conflicts resolved to main,
which is correct because this branch changes formatting and nothing else.

* chore: leave desktop/ out of this reformat

desktop-release-drift is right to refuse this. Everything under desktop/ is
built into Fleet Runner, so changing it means shipping: bump the version AND add
a FLEET_RUNNER_RELEASES entry, whose stated audience is 'person who installed
Fleet Runner and wants to know what changed'. For a whitespace-only build the
honest answer is 'nothing', so that release should not exist — and I should not
write release notes claiming otherwise.

I had bumped to 0.8.16 to get the gate green. That was the wrong direction:
publishing a build to three OS runners to keep a formatting PR quiet. Reverted.

desktop/ is excluded in .prettierignore with the reasoning recorded there, to be
formatted alongside the next real runner change, where the bump and the notes are
true anyway.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 09:23:30 +00:00
Gandt a577014533 chore: clear the code-debt audit — gates, auth coverage, deps, CI database (#362)
* perf(gates): stop charging 8 minutes to push and 3 minutes to commit

Measured on main today: `npm run verify` took 490s and `.husky/pre-commit`
took 172s of it on EVERY commit. That is not a safety property, it is a tax on
committing and pushing — the two habits that keep work off a single disk. The
same fleet audit found 206 finished files stranded uncommitted for ten days.

Nothing here weakens a check. Every one still runs, on the same files:

  disk-gc /proc scan   110s -> 16s   in_use() forked a readlink per PID on
                                     every call. Hundreds of processes times
                                     several candidate dirs is thousands of
                                     forks per run. Now one `ls -l` pass,
                                     cached for the run. This is SHIPPED code,
                                     so bitbaum's hourly GC gets it too — and
                                     caching is the more correct reading
                                     anyway: "in use when the sweep started"
                                     should not flip between tiers.

  eslint               132s ->  7s   --cache. Cold is 150s (+18s to write it),
                                     paid once by CI; developers pay warm.

  test-disk-gc fixture              sparse files via truncate instead of
                                     dd-ing ~300MB of zeros nothing reads.
                                     The code under test only calls df, which
                                     the test already stubs, so it cannot tell.

  pre-commit           172s ->  ~0   lints STAGED files only. tsc cannot be
                                     scoped to a file set and moves to the
                                     push side, where the full bundle already
                                     runs. A commit is local and reversible; a
                                     push is shared. Gate them differently.

verify 490s -> 334s, still green. `npm run verify` remains the single
definition of verified and CI still calls it verbatim.

* fix(deps): clear every high-severity advisory (15 -> 4, 0 high)

`npm audit fix` took 9 of the 15. The two HIGH ones it left were both the same
root cause — ajv's advisory is *via* fast-uri — and the vulnerable range is
3.0.0-3.1.4 with 3.1.6 already published inside the same major. So an override
closes both with no breaking change:

  HIGH  fast-uri  host confusion via literal backslash authority delimiter
  HIGH  ajv       (inherits the above)

  before  1 low   7 moderate  7 high
  after   0 low   4 moderate  0 high

The remaining 4 moderates are deliberately NOT fixed. They are one chain —
drizzle-kit -> @esbuild-kit/* -> esbuild — and npm's offered remedy is
drizzle-kit@0.18.1, thirteen minor versions back, which would take the schema
tooling with it. The advisory is esbuild's DEV SERVER accepting cross-origin
requests; drizzle-kit is a devDependency, esbuild is not referenced by
next.config.ts, and neither reaches production. Downgrading working migration
tooling to silence a dev-server advisory that does not apply is a worse trade
than carrying it, so it is carried knowingly rather than silently.

verify green at 372s.

* test(api): make auth coverage checkable instead of archaeological

There is no middleware.ts — all 214 routes guard themselves, through ELEVEN
different mechanisms: four session getters, two private-zone wrappers, a cron
secret, a runner bearer, a widget token, an agent token, and signed webhook
secrets. Each is reasonable on its own. They are layers, not duplicates, and
collapsing them would be worse than leaving them.

The defect is that the SET is not knowable by inspection. Auditing it today
took seven passes. The first reported 44 unguarded routes including
/api/people and /api/memory — every one a false alarm from a helper the grep
had not met yet. Each later pass found another mechanism and shrank the list:

    44 -> 27 -> 18 -> 25 -> 18

Nothing was actually wrong. That is the problem: a property needing seven
attempts to verify is a property nobody verifies, and its failure mode is
silent — a new route with no guard looks exactly like the 18 that are public
on purpose.

So this asserts the checkable version of the rule: every route either names a
known mechanism, or appears on a PUBLIC list with a reason a human wrote. The
reasons are the real artifact; until now the answer to "why is this endpoint
open?" existed only in whoever wrote it.

The list is self-cleaning — it also fails when an entry names a route that now
guards itself, or one that no longer exists, so it cannot rot into exemptions
nobody re-examined. All three failures verified red before committing.

Current state: 214 routes, 196 guarded, 18 public with a recorded reason.
No unguarded route was found. Runs in verify via the unit glob; no DB, no
network, 1s.

* test(ci): give CI a database, so the billing test stops being skipped forever

Six suites sat on a permanent skip list for want of a Postgres. One of them
is the OrangeCat entitlement end-to-end — signature verification, actor
lookup, grant write, dedupe, expiry sweep. That is the billing boundary, and
it had never run in CI once. "Only passes locally via .env.local" means, in
practice, that nobody runs it.

It turns out it needs a MIGRATED database, not a seeded one, so CI can just
have one. It now runs green there.

Two things this surfaced that are worth writing down:

  * drizzle/*.sql does NOT replay from empty. 0001_canonical_project_identity
    references `user_projects`, which 0000 never creates; 51 of 56 migrations
    fail against a fresh database. The journal is history, not a rebuild
    recipe — so CI uses `drizzle-kit push`, and anyone reaching for those
    files to rebuild an environment should know they will not work.

  * push is only non-interactive because the CI database is EMPTY. Its
    truncate prompts fire for tables holding rows, and an empty database has
    none. The comment says so at the call site, because pointing this at a
    database with data would be a very bad afternoon.

pgvector/pgvector:pg16 rather than stock postgres — knowledge-embeddings
declares a `vector` column and push dies without the extension.

Skips are now conditional rather than permanent: SKIP_UNLESS_ENV keeps a test
out of the run only while its prerequisite is missing, instead of excluding it
on every machine forever because some machines lack a database. Verified both
ways — 103 tests with no DATABASE_URL, 104 with one, full verify green at 191s.

---------

Co-authored-by: t <t@t.t>
2026-08-25 19:55:23 +00:00
84a0edd70d fix(mobile): a dialog you cannot close, on pages nothing could test (#287)
* fix(deploy): a marker that can lie is worse than no marker

Two flaws in #279, found before its deploy ran.

1. The stamp preferred GITHUB_SHA over the checked-out commit. deploy.yml's
   workflow_run path checks out `workflow_run.head_sha`, which is not always the
   run's GITHUB_SHA, so the marker could name a commit that was never compiled.
   Since the deploy compares the live marker against the shipped ref, a lying
   marker manufactures a false alarm. Git HEAD is literally what was built, so
   it now comes first; GITHUB_SHA is the last resort for checkouts with no .git.

2. A mismatch rolled the box back. The realistic cause of a mismatch is a second
   deploy landing behind this one — and reverting to app.prev would discard the
   NEWER build, turning a benign race into exactly the incident the check exists
   to catch. It now reports loudly and leaves the running build alone. What was
   missing before was never the ability to revert; it was ever being TOLD that
   the box serves something else. That, plus /api/health, is the fix.

Both are pinned by tests, including one asserting the mismatch path does not
call rollback_box.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(mobile): a dialog you cannot close, on pages nothing could test

Testing prod in a real phone viewport turned up two defects and the reason
neither was ever going to be caught.

THE OVERLAYS

The mobile navigation sheet — the only route to half the app on a phone —
ignored Escape and let the page keep scrolling behind it. Checking the other
overlays found the same thing twice more: the floating Loki assistant could be
opened with a key (`?`) and not closed with one, and the sessions drawer and
command palette both cover the app while the page scrolls underneath.

The cause is structural. `useEscapeToClose` was a private helper inside
modal.tsx, so the behaviour was reachable only by using <Modal>/<Drawer>; every
hand-rolled overlay started from zero and had to remember. Some did. Three did
not — and CommandPalette already carries a comment about fixing "the user's
'Escape doesn't close' complaint", so this is the class's third appearance, not
its first.

The hook moves to hooks/use-escape-to-close.ts, and scripts/test/overlay-contract.ts
enforces the rule: anything claiming role="dialog" handles Escape, and the
overlays that cover the app lock what is behind them. Fixing the fourth instance
by hand would have cost more than that file.

THE BLIND HALF

/people, /money, /habits, /events, /goals and /memory sit behind the PIN, so the
prod smoke skipped them, the UI dogfood's flows failed as "skipped", and the
responsive audit's page list never included them. Three checks, one hole, in the
same place — and it read as coverage: 97 green probes, 84 green viewport checks.

The PIN was never the boundary. The unlock is an HMAC under AUTH_SECRET, and
anything holding AUTH_SECRET can already mint a session as any user — which is
exactly what print-session-token.ts does. So the format moves to a request-free
module and the tooling mints its own unlock. Nothing new is granted; the tests
just stop pretending a third of the product does not exist. The PIN keeps
guarding what it was built to guard: a person at a keyboard.

The smoke now proves the gate before walking through it — a session without the
unlock must be refused — so bypassing it adds an assertion instead of removing
one. 97 probes to 129, all green against production.

VERIFIED IN PROD

- 129/129 authenticated probes, including the private zone for the first time
- 84 viewport checks across 320/390/768/1440, no horizontal overflow, now
  including the six private pages
- new audit:mobile drives a touch Chromium: every page's last element is
  reachable above the floating nav at max scroll, and the menu sheet closes on
  the close button, a backdrop tap, and Escape

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 10:29:20 +00:00
192aedc807 test(orangecat): end-to-end proof for the BTC pass entitlement route (#246)
Only the HMAC helper was unit-tested; nothing exercised the real
/api/orangecat/entitlement route against the DB. This drives it live:
signature verify, actor lookup, idempotent grant insert, users.plan
write, dedupe on retry, and the expiry sweep. Zero real money — it's
the synthetic stand-in for a live sats payment, proving every piece
of the FleetCrown side is correct before attempting one for real.

Co-authored-by: Mao Nakamoto <maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-13 19:26:51 +00:00
Mao NakamotoandClaude Opus 4.8 f63315ace7 test(ci): glob-discover unit tests; converge CI and pre-push
Addresses the Test/Quality panel finding that only ~12 of ~32 test:* scripts
ran automatically and a newly-added test:* was born dead (never in CI):

- scripts/test-unit.ts globs scripts/test/*.ts and runs every pure test in
  parallel. New pure tests are picked up for free. Infra-dependent tests are
  skipped with an explicit reason (server/DB/Groq/embeddings). Classification
  was verified under true CI conditions (.env.local hidden + dead DATABASE_URL,
  since dotenvx otherwise injects a live DB and masks the dependency): 29/29
  pure tests green, 6 correctly skipped.
- ci.yml and .husky/pre-push both now run `npm run test:unit` (+ test:home), so
  a green push and a green CI run the same suite and can't diverge.
- Runner avoids top-level await (tsx→CJS rejects it), uses the local tsx bin at
  concurrency 2 (esbuild-friendly on a 2-core box), and handles spawn errors.

NOT done (needs your decision — flagged): required-status-checks branch
protection would REJECT direct pushes to main, breaking the push-to-main-deploy
flow, unless the deploy also moves into CI (needs the box SSH key as a GitHub
secret — your call). `next build` in CI still needs a Postgres service to
pre-render; deferred (deploy-time build + the new rollback already gate it).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-07 18:58:22 +02:00