all docs · north_os · DESIGN.mdJun 17, 2026

Artifact figure provenance - implementation plan

Status: Implemented - runtime gate, shared eval helper, regression tests, Codex review, Claude review, and live production evals passed on 2026-06-23
Author: Codex
Date: 2026-06-17
Repo: north-os
Related: docs/superpowers/specs/2026-06-17-artifact-figure-provenance-design.html, docs/superpowers/plans/2026-06-10-rag-eval-harness.html, packages/agent-runtime/scripts/eval-agent-tools.ts, packages/agent-runtime/src/agents/legal-assistant/graph.ts

Scope: Implement deterministic runtime gating for figure-bearing artifact writes and keep the production eval assertion on the same helper code. No database schema or migration work is expected. Do not edit existing migrations. Do not run db:push.

Goal

Close the spec-only gap by enforcing this invariant in the legal-assistant runtime: every dollar amount, percentage, day/month/year period, section reference, and 4+-digit number written into a figure-bearing artifact must already appear in a prior tool result or in a human message. If the figure is absent, the graph returns a synthetic error ToolMessage for that tool call and does not invoke the write tool.

Architecture

Implementation note, 2026-06-23: create_spreadsheet and create_tracker are pre-invocation scanned. tabular_review is intentionally omitted from the runtime registry because its current schema accepts source file ids, columns, and questions; final cells are produced inside the tool from reviewed documents rather than model-supplied artifact rows. This follows the plan's safe-scope decision and was reviewed as non-blocking by Claude.

Non-goals

Increment 1 - Shared provenance helper

Files: create packages/agent-runtime/src/artifacts/figure-provenance.ts and packages/agent-runtime/src/artifacts/figure-provenance.test.ts.

Green check: bun --filter=@workspace/agent-runtime test -- src/artifacts/figure-provenance.test.ts.

Increment 2 - Refactor the production eval to use the helper

Files: modify packages/agent-runtime/scripts/eval-agent-tools.ts. Modify exports only if the script import path needs a public barrel; prefer a relative source import from the script to avoid expanding the package API unnecessarily.

Green check: bun --filter=@workspace/agent-runtime typecheck.

Increment 3 - Add the legal-assistant runtime gate

Files: modify packages/agent-runtime/src/agents/legal-assistant/graph.ts; optionally add a tiny local helper near the existing context-budget helpers if it does not warrant a new graph-specific file.

Green check: covered by Increment 4 graph tests, then bun --filter=@workspace/agent-runtime typecheck.

Increment 4 - Graph regression tests

Files: modify packages/agent-runtime/src/agents/legal-assistant/graph.test.ts.

Green check: bun --filter=@workspace/agent-runtime test -- src/agents/legal-assistant/graph.test.ts src/artifacts/figure-provenance.test.ts.

Increment 5 - Production eval regression

Files: no code changes expected unless the eval output reveals a true runtime bug.

Eval evidence, 2026-06-23: bun --filter=@workspace/agent-runtime run eval:agent-production -- --task loan-figures-not-invented passed 100%; bun --filter=@workspace/agent-runtime run eval:agent-production -- --task spreadsheet-cure-periods passed 100%.

Commands:

bun --filter=@workspace/agent-runtime run eval:agent-production -- --task loan-figures-not-invented
bun --filter=@workspace/agent-runtime run eval:agent-production -- --task spreadsheet-cure-periods

Increment 6 - Final verification

Verification evidence, 2026-06-23: focused agent-runtime tests passed after rebase (24 tests); bun --filter=@workspace/agent-runtime typecheck, root bun run typecheck, root bun run lint, and git diff --check passed. No DB or migration files changed.

Acceptance criteria

Risks and decisions to resolve during implementation

Out of scope follow-ups