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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ grouped by area, with links to the docs for the details.

### Added

- **Datasets.** `coding.sh dataset mine <name> --proof-steps` mines redacted, deduplicated formal-verification proof-step cases (solved error-to-diff transitions and stuck proof goals) across Lean, Rocq, Dafny, Verus, Isabelle, and TLA+/TLC, with `--proof-lang` and `--proof-outcome` filters. ([docs](https://github.com/jackulau/coding.sh/blob/main/docs/guides/evals.md#mining-formal-proof-steps))
- **Work.** `coding.sh handoff --work <id>` builds a deterministic $0, secret-redacted multi-day handoff brief across every session in a work item, with direction pivots, timeline, changed files, passing checks, deduplicated dead ends, proof rollup, and context resets. `work show <id>` adds a `Timeline` (`timeline` in `--json`) and suggests `handoff --work` on multi-session high-risk items. ([docs](https://github.com/jackulau/coding.sh/blob/main/docs/guides/evals.md#resetting-context-with-a-handoff-brief))
- **Viewer.** At-risk sessions (`#/s/<id>`) show a collapsible Live Steer card (expanded on `intervene`, collapsed on `nudge`) with prioritized directives, a copyable `suggestedSteer` prompt, and a `coding.sh handoff` hint on context resets; blocked, failed, or at-risk work items (`#/w/<id>`) show the same advice for their cause session, while healthy items make zero `/steer` requests. [Evals](https://github.com/jackulau/coding.sh/blob/main/docs/guides/evals.md#live-session-steering)
- **Steer.** `coding.sh steer <session>` and `GET /api/sessions/{id}/steer` read live verification, proof loop, context hygiene, tamper and wait telemetry to return `continue`, `nudge` or `intervene` with prioritized directives and a paste-ready steer prompt (`--prompt`, `--strict`, `--fresh`, `--json`). [Evals](https://github.com/jackulau/coding.sh/blob/main/docs/guides/evals.md#live-session-steering)
Expand Down
13 changes: 13 additions & 0 deletions docs/guides/evals.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@ Mined cases carry deterministic `difficulty` (`easy`, `medium`, or `hard`), `tur

`coding.sh dataset stats <name>` reports version, case counts by split, kind, tag, and difficulty, input length min/median/max, and near-duplicate pair count at `--near-threshold` (default `0.8`). `coding.sh dataset filter <src> --out <dst>` writes a new immutable child dataset filtered by `--split`, `--tag`, `--difficulty`, `--min-chars`, `--max-chars`, `--dedupe-near`, and `--limit`.

#### Mining formal proof steps

`coding.sh dataset mine <name> --proof-steps` mines formal-verification proof-step cases from Lean, Rocq, Dafny, Verus, Isabelle, and TLA+/TLC checker runs instead of whole-session prompts.

```sh
coding.sh dataset mine proof-bench --proof-steps --proof-lang lean,rocq
coding.sh dataset mine stuck-proofs --proof-steps --proof-outcome stuck --dry-run
```

- **Solved transitions** (`outcome: "solved"`): a failing proof check followed by proof-file edits and a clean passing check with no net new escape hatches.
- **Stuck goals** (`outcome: "stuck"`): a failing proof check that repeats or remains unresolved at session end, giving eval suites a benchmark of real unresolved proof goals.
- **Filtering and safety**: pass `--proof-lang` to limit languages and `--proof-outcome solved|stuck|all` to pick outcomes. Every error, goal snippet, command, path, and winning diff is redacted and deduplicated before storage.

### Case kinds: bad, guard, control

When a dataset tests a change (a new prompt, new tool text, a new model), give its cases a `kind`.
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2002,13 +2002,18 @@ coding.sh dataset mine <NAME> [options]
| `--dedupe-near <0..1>` | | Drop near-duplicate inputs at or above this 5-shingle Jaccard similarity, e.g. 0.8 (in addition to exact dedup) |
| `--split <SPLIT>` | | Split for the mined cases (default: stable hash of the case id, 60/20/20) One of: `train`, `dev`, `test`. |
| `--tag <TAG>` | | Extra tag for every mined case (repeatable, or a comma list: a,b) |
| `--proof-steps` | | Mine formal-verification proof-step cases (failing proof goals with winning diffs or stuck goals) instead of whole-session cases. |
| `--proof-lang <LANG>` | | With --proof-steps: only these proof languages (repeatable, or a comma list: lean,rocq) One of: `lean`, `rocq`, `dafny`, `verus`, `isabelle`, `tla`, `tlc`. |
| `--proof-outcome <OUTCOME>` | `all` | With --proof-steps: mine only solved transitions, only stuck goals, or all. One of: `solved`, `stuck`, `all`. |
| `--note <TEXT>` | | Version note. |
| `--dry-run` | | Show the exact changes without writing anything. |
| `--fresh` | | Wait for every pending capture to be ingested (default: answer after 1.5 s) |

```sh
coding.sh dataset mine clean --where 'agent:claude-code' --min-turns 2 --exclude-flagged --dedupe-near 0.8
coding.sh dataset mine high-score --min-score quality>=0.8 --limit 50 --dry-run
coding.sh dataset mine proof-bench --proof-steps --proof-lang lean,rocq
coding.sh dataset mine stuck-proofs --proof-steps --proof-outcome stuck --dry-run
```

### `coding.sh dataset stats`
Expand Down
65 changes: 57 additions & 8 deletions packages/coding.sh/src/cli/commands/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { resolve } from "node:path";
import { setTimeout as delay } from "node:timers/promises";
import { scoreNumber } from "../../alerts/measure.ts";
import { isProofLang, PROOF_LANGS, type ProofLang } from "../../core/proof.ts";
import type { IndexStore, SessionFilter } from "../../core/types.ts";
import {
computeDatasetStats,
Expand All @@ -14,6 +15,7 @@ import {
type MinScoreFilter,
} from "../../datasets/curate.ts";
import { addCases, assignSplits, caseFromSession, createDataset, DatasetError, loadDatasetFile, slugify } from "../../datasets/dataset.ts";
import { isProofStepOutcomeFilter, mineProofSteps, PROOF_STEP_OUTCOMES, type ProofStepOutcomeFilter } from "../../datasets/proof-mine.ts";
import { FileEvalStore } from "../../datasets/store.ts";
import type { CaseKind, Dataset, Split } from "../../datasets/types.ts";
import { findSessions } from "../../query/run.ts";
Expand Down Expand Up @@ -150,6 +152,23 @@ export async function run(c: CommandContext): Promise<number> {
positiveInt(c.flags.limit, "limit");
nonNegativeInt(c.flags["min-turns"], "min-turns");
thresholdFlag(c.flags["dedupe-near"], "dedupe-near");
const proofSteps = c.flags["proof-steps"] === true;
const rawProofLangs = list(c.flags["proof-lang"]);
const rawProofOutcome = str(c.flags["proof-outcome"]);
if (rawProofLangs.length && !proofSteps) {
throw new UsageError("--proof-lang requires --proof-steps", { reason: "invalid_argument" });
}
if (rawProofOutcome !== undefined && !proofSteps) {
throw new UsageError("--proof-outcome requires --proof-steps", { reason: "invalid_argument" });
}
for (const lang of rawProofLangs) {
if (!isProofLang(lang)) {
throw new UsageError(`--proof-lang must be one of ${PROOF_LANGS.join(", ")}, got ${JSON.stringify(lang)}`, { reason: "invalid_argument" });
}
}
if (rawProofOutcome !== undefined && !isProofStepOutcomeFilter(rawProofOutcome)) {
throw new UsageError(`--proof-outcome must be one of ${PROOF_STEP_OUTCOMES.join(", ")}, got ${JSON.stringify(rawProofOutcome)}`, { reason: "invalid_argument" });
}
for (const raw of list(c.flags["min-score"])) {
try {
parseMinScore(raw);
Expand Down Expand Up @@ -278,6 +297,9 @@ export async function run(c: CommandContext): Promise<number> {
const dedupeNear = thresholdFlag(c.flags["dedupe-near"], "dedupe-near");
const split = str(c.flags.split) as Split | undefined;
const tags = list(c.flags.tag);
const proofSteps = c.flags["proof-steps"] === true;
const proofLangs = list(c.flags["proof-lang"]) as ProofLang[];
const proofOutcome = str(c.flags["proof-outcome"]) as ProofStepOutcomeFilter | undefined;
const dryRun = c.flags["dry-run"] === true;
const note = str(c.flags.note);

Expand Down Expand Up @@ -309,6 +331,24 @@ export async function run(c: CommandContext): Promise<number> {
};

const runMine = (existing: Dataset | undefined) => {
if (proofSteps) {
const proofOpts: Parameters<typeof mineProofSteps>[0] = {
sessions,
getEvents,
scores,
minScores,
excludeFlagged,
};
if (minTurns !== undefined) proofOpts.minTurns = minTurns;
if (dedupeNear !== undefined) proofOpts.dedupeNear = dedupeNear;
if (split) proofOpts.split = split;
if (tags.length) proofOpts.tags = tags;
if (limit !== undefined) proofOpts.limit = limit;
if (proofLangs.length) proofOpts.proofLangs = proofLangs;
if (proofOutcome !== undefined) proofOpts.outcome = proofOutcome;
if (existing) proofOpts.existing = existing.cases;
return mineProofSteps(proofOpts);
}
const mineOpts: Parameters<typeof mineDatasetSessions>[0] = {
sessions,
getEvents,
Expand All @@ -325,21 +365,26 @@ export async function run(c: CommandContext): Promise<number> {
return mineDatasetSessions(mineOpts);
};

const matchedLabel = (n: number) =>
proofSteps ? `${plural(n, "proof step")} across ${plural(sessions.length, "session")}` : plural(n, "session");

if (dryRun) {
const existing = await store.getDataset(id);
const report = await runMine(existing);
if (out.json) {
out.data({
const doc: Record<string, unknown> = {
outcome: "dry-run",
dataset: { id, name },
matched: report.matched,
kept: report.kept,
dropped: report.dropped,
droppedBy: report.droppedBy,
duplicates: report.duplicates.length,
});
};
if (proofSteps) doc.sessions = sessions.length;
out.data(doc);
} else {
out.print(`Matched ${plural(report.matched, "session")}: ${report.kept} kept, ${report.dropped} dropped`);
out.print(`Matched ${matchedLabel(report.matched)}: ${report.kept} kept, ${report.dropped} dropped`);
const detail = formatBreakdown(report.droppedBy);
if (detail) out.note(`Dropped: ${detail}`);
out.note("Dry run: nothing written");
Expand Down Expand Up @@ -385,17 +430,19 @@ export async function run(c: CommandContext): Promise<number> {
if (!saved) {
const outcome = existingWhenEmpty ? "unchanged" : "empty";
if (out.json) {
out.data({
const doc: Record<string, unknown> = {
outcome,
dataset: existingWhenEmpty ? summary(existingWhenEmpty) : null,
matched: report.matched,
kept: 0,
dropped: report.dropped,
droppedBy: report.droppedBy,
duplicates: report.duplicates.length,
});
};
if (proofSteps) doc.sessions = sessions.length;
out.data(doc);
} else {
out.note(`Matched ${plural(report.matched, "session")}: 0 kept, ${report.dropped} dropped`);
out.note(`Matched ${matchedLabel(report.matched)}: 0 kept, ${report.dropped} dropped`);
const detail = formatBreakdown(report.droppedBy);
if (detail) out.note(`Dropped: ${detail}`);
if (existingWhenEmpty) out.ok(`${existingWhenEmpty.name} is unchanged`);
Expand All @@ -404,15 +451,17 @@ export async function run(c: CommandContext): Promise<number> {
}

if (out.json) {
out.data({
const doc: Record<string, unknown> = {
outcome: saved.created ? "created" : "unchanged",
dataset: { ...summary(saved.ds), version: saved.version },
matched: report.matched,
kept: report.kept,
dropped: report.dropped,
droppedBy: report.droppedBy,
duplicates: report.duplicates.length,
});
};
if (proofSteps) doc.sessions = sessions.length;
out.data(doc);
} else {
const detail = formatBreakdown(report.droppedBy);
if (detail) out.note(`Dropped ${report.dropped} (${detail})`);
Expand Down
5 changes: 5 additions & 0 deletions packages/coding.sh/src/cli/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1266,13 +1266,18 @@ export const COMMANDS: CommandSpec[] = [
{ name: "dedupe-near", type: "number", value: "<0..1>", desc: "Drop near-duplicate inputs at or above this 5-shingle Jaccard similarity, e.g. 0.8 (in addition to exact dedup)" },
{ name: "split", type: "string", value: "<SPLIT>", choices: ["train", "dev", "test"], desc: "Split for the mined cases (default: stable hash of the case id, 60/20/20)" },
{ name: "tag", type: "list", commas: true, value: "<TAG>", desc: "Extra tag for every mined case (repeatable, or a comma list: a,b)" },
{ name: "proof-steps", type: "boolean", desc: "Mine formal-verification proof-step cases (failing proof goals with winning diffs or stuck goals) instead of whole-session cases" },
{ name: "proof-lang", type: "list", commas: true, value: "<LANG>", choices: ["lean", "rocq", "dafny", "verus", "isabelle", "tla", "tlc"], desc: "With --proof-steps: only these proof languages (repeatable, or a comma list: lean,rocq)" },
{ name: "proof-outcome", type: "string", value: "<OUTCOME>", choices: ["solved", "stuck", "all"], default: "all", desc: "With --proof-steps: mine only solved transitions, only stuck goals, or all" },
{ name: "note", type: "string", value: "<TEXT>", desc: "Version note" },
DRY_RUN,
FRESH,
],
examples: [
"coding.sh dataset mine clean --where 'agent:claude-code' --min-turns 2 --exclude-flagged --dedupe-near 0.8",
"coding.sh dataset mine high-score --min-score quality>=0.8 --limit 50 --dry-run",
"coding.sh dataset mine proof-bench --proof-steps --proof-lang lean,rocq",
"coding.sh dataset mine stuck-proofs --proof-steps --proof-outcome stuck --dry-run",
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/coding.sh/src/datasets/curate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ interface KeptEntry {
sh: Set<string>;
}

class CaseDeduper {
export class CaseDeduper {
private readonly threshold: number | undefined;
private readonly shingleSize: number;
private readonly byHash = new Map<string, KeptEntry>();
Expand Down
1 change: 1 addition & 0 deletions packages/coding.sh/src/datasets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export * from "./curate.ts";
export * from "./dataset.ts";
export * from "./hash.ts";
export * from "./kinds.ts";
export * from "./proof-mine.ts";
export * from "./store.ts";
export * from "./types.ts";
Loading
Loading