Skip to content

feat(analyst): priorFindings context wiring + cross-run prompt rendering#58

Merged
drewstone merged 2 commits into
mainfrom
feat/analyst-prior-findings
May 19, 2026
Merged

feat(analyst): priorFindings context wiring + cross-run prompt rendering#58
drewstone merged 2 commits into
mainfrom
feat/analyst-prior-findings

Conversation

@drewstone
Copy link
Copy Markdown
Contributor

Closes piece 1/3 of the self-improvement loop (substrate side).

What this adds

Analysts now read the previous run's findings as retrieval context, so the loop has memory:

  • A failure-mode that reappears without remediation gets caught and re-promoted
  • A knowledge gap the wiki failed to close stays on the report
  • The cross-run diff stays stable because kinds carry the prior finding_id via id_basis

Shape

  • AnalystContext.priorFindings?: ReadonlyArray<AnalystFinding> — analysts read these directly
  • RegistryRunOpts.priorFindings accepts two forms:
    • Array → registry filters per analyst by analyst_id (per-kind history)
    • Record { '<id>': [...], '*': [...] } → '*' fans out to all analysts (for cross-kind chaining, e.g. improvement consuming upstream failure / gap / poisoning)
  • renderPriorFindings(prior) exported helper — emits a compact PRIOR FINDINGS prompt block (1 line per finding, 40-row cap with overflow line). The actor is instructed to (a) reuse the prior finding_id via id_basis so diffs stay stable, and (b) raise severity / confidence when a finding reappears with no remediation evidence.

7 added tests; 1153 total pass; typecheck clean.

Coordinated PRs

  • agent-knowledge: proposeFromFinding bridge (this PR's findings → wiki proposals)
  • agent-runtime: runAnalystLoop orchestrator (one call closes the loop)

Analysts now read the previous run's findings as retrieval context, so
the self-improvement loop has memory: a failure-mode that reappears
without remediation gets caught and re-promoted; a knowledge gap that
the wiki failed to close stays on the report; the cross-run diff stays
stable because kinds carry forward the prior `finding_id` via id_basis.

Changes:

- `AnalystContext` gains a `priorFindings?: ReadonlyArray<AnalystFinding>`
  field. Filtering is the operator's job: pass the slice that matches
  this analyst, or pass everything and let the kind decide.

- `RegistryRunOpts.priorFindings` accepts two shapes:
    - Array — each analyst sees only findings whose `analyst_id`
      matches its own (per-kind history).
    - Record — `{ '<id>': [...], '*': [...] }` so the wildcard fans
      out for cross-kind chaining (the improvement analyst consumes
      upstream failure / gap / poisoning findings via '*').

  Analysts that get no matching slice see `undefined`, not an empty
  array — the kind-factory's renderer treats `undefined` as "no prior
  context" and emits no prompt block.

- `kind-factory.ts` exports `renderPriorFindings(prior)`. Caps at 40
  rows (~2KB) and appends an overflow line when truncated. The actor
  prompt now ends with:
    PRIOR FINDINGS (from a previous run on related data):
    When the work you do now matches a row below, REUSE the
    `finding_id` (pass it as `id_basis`) so the cross-run diff stays
    stable.
    A finding that reappears with no remediation evidence SHOULD
    raise its `confidence` and may justify a higher `severity`.
      - id=<sha> <severity> [<subject>] <claim-truncated>
      ...

Tests (7 added, 1153 total pass):
  - registry array form filters by analyst_id
  - registry record form merges per-id with '*' wildcard
  - undefined when no matching prior (not empty array)
  - renderPriorFindings empty-input / typical / overflow paths
@drewstone drewstone force-pushed the feat/analyst-prior-findings branch from 777668b to 2aa7550 Compare May 19, 2026 11:54
@drewstone drewstone merged commit 66ad5fd into main May 19, 2026
1 check passed
drewstone added a commit that referenced this pull request May 19, 2026
… priorFindings

Wraps two unreleased features into a single minor:
- PR #57: kind-factory + 4 trace-analyst kinds (failure-mode,
  knowledge-gap, knowledge-poisoning, improvement) via Ax structured
  output + Zod-validated `RawAnalystFinding`.
- PR #58: priorFindings context wiring so kinds chain across runs
  ('improvement' sees what 'failure-mode' surfaced).

createTraceAnalystAdapter retains @deprecated marker pointing at the
new kinds; kept for one minor while consumers migrate.

1153/1153 tests green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant