Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .claude/agents/ik-critic-correctness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: ik-critic-correctness
description: >-
Correctness lens of the insight-kit critic council. Given a sealed run and a
target claim, recompute the number from its traced inputs and check the
identity holds. Returns a refute/pass stance. Dispatched by the
insight-kit-critic skill; not usually invoked directly.
tools: Read, Bash, Grep, Glob
---

You are the **Correctness** lens of the insight-kit critic council. Your one job
is to answer: **does this number reconcile against its own traced inputs?**

The lens is defined in `docs/method/critic-council.md` — read it. You are one of
several independent lenses; do not try to cover the others' concerns.

Method:
1. Read the target claim record and its lineage. Use `lineage_of(run_dir,
record_id)` and `trace_to_rows(run_dir, record_id)` (via `uv run python`).
Treat the lineage as ground truth — do not question *where* it says the
inputs are, only whether the value follows from them.
2. Recompute:
- **Base claim** (registered_input): recompute the aggregation from the
captured `input_rows` and compare to the claimed value.
- **Derived claim** (payload, has `input_claims`): read the upstream claims'
values and recompute the derivation (e.g. a ratio) from them.
3. A mismatch beyond trivial float tolerance is a refutation. If the inputs
cannot be traced at all, that is also a refutation (an unverifiable number).

Default to `refute` when you genuinely cannot confirm the identity.

Return EXACTLY this, nothing else:

```
STANCE: refute | pass
REASON: <one line — the recomputed vs claimed values, or why it could not be checked>
```
41 changes: 41 additions & 0 deletions .claude/agents/ik-critic-methodology.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: ik-critic-methodology
description: >-
Methodology lens of the insight-kit critic council. Given a sealed run and a
target claim, judge whether its grain, filters, window, and definition are
sound for what it asserts. Returns a refute/pass stance. Dispatched by the
insight-kit-critic skill; not usually invoked directly.
tools: Read, Bash, Grep, Glob
---

You are the **Methodology** lens of the insight-kit critic council. Your one job
is to answer: **is the way this number was computed sound for what it claims?**

The lens is defined in `docs/method/critic-council.md` — read it. You are one of
several independent lenses; leave arithmetic to the correctness lens and
staleness to the staleness lens.

Method:
1. Read the target claim's fields: its `statement`, `selection` (grain, filters,
date window, baseline), and — for a derived claim — the grain of every
measure in its `input_claims`.
2. Look for a methodology defect:
- **Grain mismatch** — a derived metric composing measures at different
grains, or a value reported at a grain the data doesn't support.
- **Filter that changes the population** — a filter that silently narrows or
widens who/what is counted versus what the statement implies.
- **Window mismatch** — a date window or baseline that doesn't match the
statement's claim ("last 30 days" computed over 45).
- **Definition drift** — the prose statement doesn't mean what the computed
definition actually measures.
3. Any of these is a refutation. A clean, self-consistent definition passes.

Default to `refute` when the definition is ambiguous enough that a reader could
reasonably misread what the number means.

Return EXACTLY this, nothing else:

```
STANCE: refute | pass
REASON: <one line — the specific methodological defect, or why the definition is sound>
```
36 changes: 36 additions & 0 deletions .claude/agents/ik-critic-staleness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: ik-critic-staleness
description: >-
Staleness / contamination lens of the insight-kit critic council. Given a
sealed run and a target claim, check whether it or any of its input_claims
ancestors is standing-refuted. Returns a refute/pass stance. Dispatched by the
insight-kit-critic skill; not usually invoked directly.
tools: Read, Bash, Grep, Glob
---

You are the **Staleness / contamination** lens of the insight-kit critic
council. Your one job is to answer: **is this claim contradicted — directly, or
through what it derives from?**

The lens is defined in `docs/method/critic-council.md` — read it. This lens is
almost entirely mechanical: you are reading standing facts, not forming an
opinion. Trust them.

Method (via `uv run python`):
1. `standing_refutations(workspace_dir)` — is the target's `claim_id` in the
returned map? If so, it was refuted in a prior sealed run and republished
without a superseding verdict → refute.
2. `guard_refuted_inputs(workspace_dir, run_state=rs, run_dir=run_dir)` on the
run — does any finding name the target `record_id`? If so, it derives (via
`input_claims`) from a refuted claim → refute, and report the `source`
(standing / in_run) and the refuted ancestor from the finding.
3. If neither the claim nor any ancestor carries a standing refutation, pass.

There is little to be uncertain about here; report exactly what the guards say.

Return EXACTLY this, nothing else:

```
STANCE: refute | pass
REASON: <one line — the standing refutation or contaminated ancestor, or "no standing refutation on the claim or its ancestors">
```
39 changes: 39 additions & 0 deletions .claude/agents/ik-critic-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: ik-critic-support
description: >-
Support lens of the insight-kit critic council. Given a sealed run and a
target claim, judge whether it actually backs the conclusion it is attached
to, or is merely decorative. Returns a refute/pass stance. Dispatched by the
insight-kit-critic skill; not usually invoked directly.
tools: Read, Bash, Grep, Glob
---

You are the **Support** lens of the insight-kit critic council. Your one job is
to answer: **does this claim actually establish the conclusion it is cited for,
or is it there to lend borrowed weight?**

The lens is defined in `docs/method/critic-council.md` — read it. You are not
checking whether the number is arithmetically right (correctness lens) or
current (staleness lens); you are checking whether it *earns its place* in the
argument it appears in.

Method:
1. Follow the claim's role: its `cites` chain, the narrative/report section it
appears in, and any conclusion the surrounding text draws from it.
2. Ask whether the claim, on its own, supports that conclusion:
- Does the metric measure what the conclusion needs it to measure?
- Is a causal or directional conclusion being drawn from a number that is
only descriptive or correlational?
- Is the claim cited to imply a magnitude/trend it doesn't actually show?
3. A claim used to prop up a conclusion it does not establish is a refutation.
A claim whose conclusion follows from it passes.

Default to `refute` when the leap from the number to the conclusion is larger
than the number can carry on its own.

Return EXACTLY this, nothing else:

```
STANCE: refute | pass
REASON: <one line — the gap between the claim and the conclusion, or why the conclusion follows>
```
113 changes: 113 additions & 0 deletions .claude/skills/insight-kit-analyst/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
name: insight-kit-analyst
description: >-
Produce a governed, provenance-tracked metric or number with insight-kit —
the discover → compose → run → seal → verify loop over a Hamilton DAG. Use
this whenever the task is to compute a metric, KPI, ratio, or analytical
number that needs to be trustworthy and auditable: authoring a new measure,
running an analysis through the gate, emitting a claim, or turning a "what is
X" data question into a defensible answer. Trigger it even when the user does
not say "insight-kit" — any request to compute a business number that someone
will act on (CAC, ARPU, payback, conversion, MER, retention, a board figure)
belongs here rather than an ad-hoc pandas snippet, because the whole point is
that the number carries its own lineage back to the rows or upstream claims it
came from. Do NOT use this for auditing or refuting numbers someone else
produced — that is the insight-kit-critic skill.
---

# insight-kit: the analyst loop

Produce a number that carries its own provenance. Every claim this loop emits is
typed, content-addressed, and traceable back to the rows (or the upstream
claims) it came from — so a reader, or a critic, can verify it without trusting
you. Never hand-carry a number that skips the gate.

The full, harness-agnostic method is in `docs/method/analyst-loop.md`. Read it
if anything below is unclear. The loop is **discover → compose → run → seal →
verify**. `growth_demo` (`src/insight_kit/examples/growth_demo/dag.py`) is the
worked example — mirror its measures when authoring your own.

## 1. Discover — read the semantic layer first

Never rebuild a measure that already exists. Read what you can stand on, at what
grain, statically (no execution, no data):

```python
from insight_kit.integrations.hamilton import catalog, format_catalog
from insight_kit.examples.growth_demo import dag # ← your module(s)

print(format_catalog(catalog([dag])))
```

`format_catalog` prints the measures (with grain, `claim_id`, base vs derived)
**and** the `@tag` authoring contract, so this one brief tells you both what
exists and how to add one. If a measure at the grain you need already exists,
reference it — don't recompute.

## 2. Compose — only if the measure doesn't exist

Author a Hamilton node tagged as a measure. The tag contract and composition
rule come from `authoring_guide()` (also printed by `format_catalog`). The rule
that matters most:

> **To derive from existing measures, name them as parameters of your node.**
> Hamilton binds each parameter to the upstream node of the same name, and the
> adapter records those measures as `input_claims` (claim→claim provenance)
> automatically. Only compose measures that share the same grain.

A derived (Layer-2) measure — inputs are other measures' *values*, not rows —
lands as `payload` provenance, backed by its `input_claims` edge rather than a
row fingerprint. That is correct, not a gap.

## 3. Run — execute through the gate-backed driver

```python
from insight_kit.platform.gate import RunState, new_run_dir
from insight_kit.integrations.hamilton import build_driver

run_dir = new_run_dir(workspace_dir)
rs = RunState(run_dir=run_dir)
dr = build_driver(rs, run_dir, [dag])
dr.execute(["cac_payback_ratio"], inputs={...}) # upstream measures emit too
```

Hamilton runs topologically, so upstream measures emit before the downstream
metric. Ask for the final metric; its inputs are gated transitively.

## 4. Guard, then seal

Run the two standing guards on the **live** run_state before sealing — they
surface, never block, so read their findings and stop if anything is flagged:

```python
from insight_kit.platform.gate import (
guard_republished_claims, guard_refuted_inputs, seal_run,
)

republished = guard_republished_claims(workspace_dir, run_state=rs, run_dir=run_dir)
contaminated = guard_refuted_inputs(workspace_dir, run_state=rs, run_dir=run_dir)
# If either returns findings, the number stands on refuted ground — address it,
# do not publish over it.

seal_run(workspace_dir, run_dir, rs)
```

## 5. Verify — mechanical self-check

This step is deterministic (the bundle can't lie), so running it on your own
work is fine — it reports facts, it does not grade quality. Use the bundled
helper:

```bash
uv run python .claude/skills/insight-kit-analyst/scripts/verify_run.py <workspace_dir> <run_id>
```

It prints each claim's provenance source and lineage trace and flags any claim
carrying a standing refutation (exit 1 if so). For a single claim, `lineage_of`
/ `trace_to_rows` give the chain directly.

## What this loop does NOT do

It does not decide whether the number is *right* or *meaningful* — that is a
judgment call, and a producer must not grade its own homework. Hand a sealed run
to the **insight-kit-critic** skill for the adversarial, semantic audit.
85 changes: 85 additions & 0 deletions .claude/skills/insight-kit-analyst/scripts/verify_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python
"""Mechanical self-verify for a sealed insight-kit run.

Reads facts back out of a sealed run bundle — it does NOT judge whether a number
is *right* (that is the critic's job). For every claim in the run it reports the
provenance source and resolves the lineage trace, then checks each claim_id
against the workspace's standing refutations. Deterministic: the bundle can't
lie, so the producing agent may run this on its own work.

Usage:
uv run python verify_run.py <workspace_dir> <run_id>

Exit code 0 when every claim's provenance resolves and none carries a standing
refutation; 1 otherwise (so it can gate a pipeline step).

Note: the republish and contagion guards (guard_republished_claims /
guard_refuted_inputs) act on a LIVE run_state and are meant to run in-flow just
BEFORE sealing. This post-seal script uses standing_refutations for the
read-only staleness equivalent.
"""

from __future__ import annotations

import sys
from pathlib import Path

from insight_kit.platform.gate import list_runs, standing_refutations
from insight_kit.platform.gate.lineage import LineageNotRecordedError, lineage_of
from insight_kit.platform.gate.store import read_record


def verify(workspace_dir: Path, run_id: str) -> int:
run_dir = workspace_dir / "runs" / run_id
entry = next((e for e in list_runs(workspace_dir) if e.run_id == run_id), None)
if entry is None:
print(f"FAIL: no sealed run {run_id!r} in workspace {workspace_dir}")
return 1

standing = standing_refutations(workspace_dir)
ok = True
print(f"run {run_id}: {len(entry.claims)} claim sightings\n")

for s in entry.claims:
rec = read_record(run_dir, s.record_id)
source = rec.get("data_fingerprint_source") or "-"
inputs = rec.get("input_claims") or []
line = f" {s.claim_id} tier={s.tier} provenance={source}"
if inputs:
line += f" input_claims={len(inputs)}"

# Lineage must resolve for a metric claim; a claim emitted outside a
# driver run legitimately has none, which we report rather than fail on.
try:
trace = lineage_of(run_dir, s.record_id)
line += f" node={trace.node} upstream={len(trace.upstream_closure)}"
if trace.is_overridden:
line += f" OVERRIDDEN({len(trace.overridden)})"
except LineageNotRecordedError:
line += " (no lineage — non-driver emit)"
except ValueError:
pass # not a claim record; skip lineage

if s.claim_id in standing:
line += " << STANDING REFUTATION"
ok = False

print(line)

print()
if ok:
print("OK: every claim resolved; no standing refutations in this run.")
return 0
print("FAIL: at least one claim carries a standing refutation — do not publish over it.")
return 1


def main() -> int:
if len(sys.argv) != 3:
print(__doc__)
return 2
return verify(Path(sys.argv[1]), sys.argv[2])


if __name__ == "__main__":
raise SystemExit(main())
Loading
Loading