Files
loki/scripts
CatoandClaude Opus 5 e59f679289 chore(gates): a dead export is a lie about what the system does — gate it (#511)
markAgentMessageRead was the only writer of `read: true` and had no caller, so
the Control escalation banner was permanent by construction (#507). That was
found by hand. This is the check that finds the next one.

`scripts/test/dead-exports-ratchet.ts` fails when a NEW export in
src/db/queries, src/config or src/lib has no reference anywhere. Existing ones
are recorded with the consequence of being dead, so the list is worked down
rather than ignored — and a recorded entry that becomes referenced fails too,
so it cannot rot into a lie. It joins the 137-file unit suite by discovery.

49 dead exports found. 36 deleted, 1 wired up, 12 recorded.

The deletions were mostly aliases and shims whose consumers never existed:
PUBLIC_NAV_LINKS ("kept for backwards compatibility"), SITE_NAV_ITEMS ("kept
as a named export for any legacy import"), BEACON_SETTINGS_PATH ("kept for
runner fallback reads only"), ROBOT_ENTITY_TYPE ("used by tests" — no test
used it), BOOK_ACTION_TYPE (a second copy of values ACTION_TYPE owns), and
RESERVED_ACTION_PROPOSE_SOLON_CHANGE, reserved "so the name is stable when the
flow lands" — a name is stabilised by having consumers.

Two carry more weight. isRunnerRequest was a @deprecated legacy env-token auth
path that "always maps to the default user and is not multi-tenant safe";
deleting it removes that credential check from the codebase. closeStaleAgentTurns
is now called by the hourly reap-stale-runs janitor: its docblock promised
agent_sessions "does not accumulate rows that look open forever", a guarantee
nothing provided.

Two bugs in the gate itself, both caught by mutation:

  - It indexed its own file, so every name in BASELINE and in the docblock's
    worked examples looked referenced. It reported "0 dead" over five that
    were, and closeStaleAgentTurns — an example in its own docblock — was
    invisible to it.
  - It counted prose as a reference. Excluding .md surfaced three more,
    including renderPromptBody, which docs/AUDIT_REPORT_2026-07-13.md had
    already named as dead two months ago. A report is read once; a gate is
    read on every push.

OUTCOMES_MATCH_DB_SCHEMA is a compile-time drift assertion whose runtime value
is inert — no reader is what a working assertion looks like. Ratcheting it
would have pressured someone into deleting a real check, so
INTENTIONALLY_UNREFERENCED is a separate category from debt, with an assertion
that no name sits in both lists.

All four assertions proven falsifiable by mutation on a copy: a new dead export
fails, a revived BASELINE entry fails, a name in both lists fails, and removing
the exemption makes the compile-time assertion surface.

Recorded, not fixed — each with its consequence, three worth naming:

  - isAllowedTelegramTarget: sendTelegramMessage's docblock says the caller
    must run the self-only allowlist check, and none of the eight call sites
    does. What bounds the blast radius today is structural — every caller
    passes selfTelegramTarget(), so no attacker-chosen chat id is reachable.
    It must be wired the moment any flow lets a recipient be requested.
  - renderPromptBody: RunModal substitutes one variable via
    replaceAll("{{project_name}}", …), so every other {{var}} and every
    declared default reaches the agent as a literal placeholder. Fixing it
    means moving the function out of db/queries and changing what a run
    sends — its own change, not a deletion.
  - mailtoHref: reachChannels() returns {label, value} and builds no hrefs, so
    the People reach row is not clickable at all.

verify green (all 13 steps, exit 0).


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

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 21:39:56 +00:00
..
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00