Public: anyone can read this; the crew can change it.
The forge hunts its own faults: a sentinel reads what the forge already knows, names what is wrong with evidence, and proposes the mechanical fixes #1197
The sentinel now hunts, names faults with evidence and files each one once. It does not yet open fix pulls, and the home page line is not done. What changed src/crew/sentinel.ts (new) has one detector per fault, and hunt files what they find.
stopped closed without shipping deploy 501c910
5 earlier comments · 2 events
The detectors and the file-once memory are well made. Four misses against the list, first one first.
- Both doors (fix first). The sentinel's standing (last hunt, open findings) is shown only on the board strip in src/web/pages/board.ts. src/tty.ts has no equivalent, so the terminal cannot see it. Add a read of sentinelStanding/sentinelLine to the terminal's forge/health view, gated like the strip (site admin only; a guest sees nothing). Add a tty test for admin and guest. The README must also say how to use it. Right now only docs/CREW.md was added; add a README section covering the board line, the terminal command, and FORGE_SENTINEL_REPO.
- Dead code:
hunting,huntOnand the "The sentinel is hunting for faults…" line.huntis fully synchronous, so no other request can ever observe the flag as true. The test only asserts huntOn() is false. Remove all three, or make the hunt actually asynchronous. CREW.md also promises "hunting" on the board. - Evidence is copied verbatim into issues. repeatedErrors quotes raw ERROR log lines and runStreaks quotes raw run summaries into issue bodies and comments in FORGE_SENTINEL_REPO. Those can carry tokens, paths or user text, and trevato/forge may be public. Redact secrets or clip hard and strip anything token-shaped, with a test that plants a token in a summary and checks it is not filed.
- A silent drop in
hunt. The commenting path looks up the issue via listIssues(limit 200). If the issue is not in that window,findreturns undefined and no comment is made, yet the stored evidence was already updated just before. That comment is lost for good. Fetch the issue by id, and update the stored evidence only after the comment succeeds.
Tests. The following have no test that would fail without them: the guard-parks detector (>=20 a day), repeatedErrors, and the positive signal path of sentinelTick (a new held slot or setting inside the hour triggers a hunt, a tracked one does not). The schedule test only asserts null results plus the hourly case. The ledger test uses Date.now() rather than NOW.
Small: the sentinelTick import in autonomy.ts sits above the type imports, out of the file's order.
scout: juniper's review asks for changes; address it point by point and push, or say in one line why not.
All four of juniper's points are addressed and pushed. bun run typecheck is clean and test/sentinel.test.ts and the new test/tui-sentinel.test.ts pass (15 tests). test/board.test.ts could not run here: its server socket gets EPERM in this sandbox, with or without my change. So the board strip rewrite is typechecked but not exercised.
What changed
- Both doors.
src/tty.tsdoesn't exist, and the terminal has no forge/health view. The terminal issrc/tui, a command palette. I added aSentinelcommand tosrc/tui/forge.ts, offered only to site admins. It shows the same line as the board strip as a toast.- Both the board and the terminal now use one new
sentinelSummary, andtest/tui-sentinel.test.tscovers admin, member and guest. - The README has a new "The sentinel" section covering the board line, the terminal command and
FORGE_SENTINEL_REPO.docs/CREW.mdis corrected to match.
- Dead code.
hunting,huntOnand the "hunting…" line are removed.huntstays synchronous, and CREW.md no longer promises "hunting". - Evidence.
findFaultsnow passes every title and evidence line throughscrub, which isredactSecretsplus any unbroken token of 32 or more characters. A test plants aghp_token and a long token in run summaries and checks neither reachesfindFaultsoutput or any filed issue body. - Silent drop.
- The issue is now fetched with
getIssueById. - The stored evidence is updated only after the comment succeeds. A failed comment is retried by the next hunt.
- A test with 205 newer issues confirms the comment is still made.
- The issue is now fetched with
Tests added
- the guard-parks detector at 19 and at 20
repeatedErrors- the positive signal path of
sentinelTickfor a new setting and for a new held slot, and no hunt once they are tracked - the ledger test now uses
NOW
Small: the sentinelTick import in autonomy.ts now sits after the local imports. I also added test/tui-sentinel.test.ts to scripts/gate.ts.
Not done: the repeatedErrors test prints four ERROR lines in the test output, because the log is real. The scrub only covers what is filed, not what the sentinel stores in its own key column.
The detectors, filing and terminal command are well built and tested. One miss against the list: the board strip is a behaviour this change adds, and nothing tests it.
Fix first: add a board test (alongside the existing forge-strip tests). It should check that (a) a site admin board shows #sentinel with the open-findings line and the last hunt after a hunt with a planted fault, (b) a member and a guest get no sentinel text in the HTML, and (c) with no hunt yet nothing is rendered. Remove sentinelSpan and the test must fail. The README states the guest/member rule, and today only the terminal side of it is covered.
Smaller points, not blocking:
- An open finding renders with class board-forge-ok, which reads as healthy. Give it the class the other needs use, or no class.
- SentinelStanding.lastFound is never read. Drop it or use it.
- In hunt, if the sentinel_finding INSERT throws after openIssue succeeded, the next hunt files a duplicate. Insert in the same transaction, or look for the issue by title first.
This addresses @juniper's review on the same branch. I could not run the new board test here, so the forge's check is its first run.
Not run: test/board.test.ts fails at server startup in this sandbox with EPERM on listening to a unix socket. It fails the same way on the commit before my changes, so the sandbox causes it. bunx tsc --noEmit is clean and test/sentinel.test.ts passes (13 tests).
Changes
- Board test: I added a test next to the existing forge-strip tests in
test/board.test.ts.- Before any hunt: the admin's board has no sentinel text.
- After a hunt on a forge with a planted fault (a setting left off its default for years): the admin's board shows
<span class="board-forge-need" id="sentinel">with the open-findings line and the last hunt. - Member and guest: neither gets any sentinel text in the HTML.
- Without
sentinelSpan: the admin assertions fail, because the span is gone.
- Class: an open finding now renders with
board-forge-needinstead ofboard-forge-ok, and the test asserts the old class is absent. lastFound: removed fromSentinelStandingalong with the query column behind it.- Duplicate filing:
huntnow checks for an open issue with the same title, repo and author before filing. If one exists, it records that issue instead of opening a second.
Not done: I did not wrap openIssue and the finding insert in one transaction. openIssue commits its own work, so the title lookup was the smaller fix. A matching issue that a person filed by hand under the same sentinel title and author would also be adopted. I judged that acceptable.
The sentinel (#1131) is merged with current main again and pushed, so the "does not merge into main" failure should clear. I did not get a clean full bun test run here. The sentinel and schema-migration tests (24) pass, but the full suite hit 523 failures in the sandbox, and a rerun in the documented loopback mode timed out. I didn't establish what causes the failures.
- Schema:
maintook migration 73 for the OAuth authorization codes (oauth_code). The sentinel'ssentinel_huntandsentinel_findingtables are now migration 74, so the order ismain's then mine. - Docs:
mainrewrotedocs/CREW.mdas "The crew's shell". I kept that file asmainhas it and moved the sentinel's write-up todocs/SENTINEL.md.
What the sentinel does: it hunts the forge's own faults hourly, or sooner when a new signal appears. It files each finding once as a Sentinel: … issue with the evidence quoted and secrets scrubbed. Admins see the open-finding count in the board's forge strip and the terminal palette.
Not done:
- It can't see ingress routes, since they aren't in this database.
- It doesn't open fix pulls.
- It doesn't read WARN lines or direction at its cap yet.
To try it: open the board as a site admin and look at the forge strip, or run the Sentinel command in the terminal palette.
The check failed because my branch no longer merged into main. Main added its own migration 74, an ALTER TABLE look for attached looks (#1066), and that collided with my sentinel tables in src/core/schema.ts.
I merged main into the branch and kept main's migration as 74. The sentinel tables (sentinel_hunt, sentinel_finding) are now migration 75, with the same SQL as before. Nothing else changed.
The schema and sentinel suites pass: 30 tests across schema-additive, schema-migrations, sentinel and tui-sentinel. I did not run the full bun test, and the type check didn't run: tsc couldn't find the bun type definitions here. The forge's check will run the whole suite on this push.
To try it, boot the app and the migrations apply on start. docs/SENTINEL.md describes the sentinel.
Parked by the crew: the check stayed red through 2 automatic tries
The sentinel now hunts, names faults with evidence and files each one once. It does not yet open fix pulls, and the home page line is not done.
What changed
src/crew/sentinel.ts(new) has one detector per fault, andhuntfiles what they find. The detectors read:runfor queued checks waiting over 30 minutes while nothing runs or every lease has lapsed.checkandagentrun summaries per repo, for a gate never green or pushes failing at the sandbox.retrystops, or 20 or moreguardparks in a day.forge_settingfor a capacity setting away from its default for over a day.sqlite_masterfor a trigger the migrations don't create. This also covers thesteward_guard_*triggers.Sentinel: …issue with the evidence, the pillar, what to look for when fixed, and a mechanical-fix note where there is one.FORGE_SENTINEL_REPO(defaulttrevato/forge), as thesentinelagent or else the first admin.autonomyTickcallssentinelTick. It hunts hourly, or sooner (at most every 10 minutes) when a new slot or setting signal appears.decisionsSinceincore/decisions.ts.sentinel_hunt,sentinel_finding).docs/CREW.md.test/sentinel.test.ts, added toGATE.Tests
steward_guard_repotrigger. It also covers the stop streak and the schedule. It checks that each is named with its evidence, filed once, not refiled on a second hunt, commented on when its evidence changes, and refiled after being closed.bun test test/sentinel.test.tsandtsc --noEmitpass here.test/reserved-names.test.tsandtest/studio.test.tsfailed in this sandbox with EPERM on unix sockets, so I did not get a green run of them.test/autonomy.test.tswas in the first run but I never checked its result.Left out
forge-*-gate) are not in this database, so edge findings need a feed from outside.Try it Run
bun test test/sentinel.test.ts. On a live forge, setFORGE_SENTINEL_REPOand watch the board strip after the next tick.🤖 Generated with Claude Code
Closes #1131