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

- **Query.** `--where` adds session keys `risk`, `risk.reason`, `proof.lang`, `proof.escapes`, `proof.oscillating` and `unverified.edits` (plus `risk`, `risk.reason` and `proof.lang` facets) across `sessions`, `dataset mine`, `export`, `usage`, `stats`, the viewer and MCP. [Query language](https://coding.sh/docs/query#session-keys)
- **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)
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ coding.sh sessions [options]
| `--where <QUERY>` | | Only sessions matching a query, e.g. 'agent:codex cost&gt;0.5 tool:Bash -flag:compaction' (keys: coding.sh sessions --help) |
| `--view <NAME>` | | Only sessions matching this saved view's query (coding.sh views list); with --where, both must hold. |
| `--fields <PATHS>` | | With --json: print only these fields, as a comma list of dotted paths (id,title,stats.usage.costUsd). A path through a list picks from each item. Repeatable. |
| `--facets [<KEYS>]` | | Count sessions per value instead of listing them: agent, model, provider, repo, launch, branch, flag, skill, hook, kind, tool, mcp (default: agent, model, repo, flag, skill, tool) |
| `--facets [<KEYS>]` | | Count sessions per value instead of listing them: agent, model, provider, repo, launch, branch, flag, skill, hook, risk, risk.reason, proof.lang, kind, tool, mcp (default: agent, model, repo, flag, skill, tool) |
| `--fresh` | | Wait for every pending capture to be ingested (default: answer after 1.5 s) |

```sh
Expand All @@ -572,7 +572,7 @@ coding.sh sessions --agent codex --since 7d
```

- --where: key:value clauses, AND by default; OR between clauses; ( ) to group; - to negate; a,b for either value; \* as a wildcard in text; &gt; &gt;= &lt; &lt;= and a..b on numbers. Bare words search prompts, replies, tool calls and errors (every word in one event).
- Session keys: agent, model, provider, repo, launch, branch, dir, title, id, run, parent, flag, skill, hook, hook.tokens, weights.edits, weights.changed, weights.checkpoint, since, until, duration, turns, tools, tool.errors, llm.errors, files, events, tests.passed, tests.failed, tokens, tokens.in, tokens.out, cost, cache.breaks, cache.lost, cache.cost, unapproved, has, is. Event keys (the session has a matching event; event keys in one group match the same event): kind, tool, ok, mcp, error, event.duration, user, env, release (user, env and release read the session's start event and match on their own). Also sort:-cost and limit:N. Full list with examples: https://coding.sh/docs/query.
- Session keys: agent, model, provider, repo, launch, branch, dir, title, id, run, parent, flag, skill, hook, hook.tokens, weights.edits, weights.changed, weights.checkpoint, since, until, duration, turns, tools, tool.errors, llm.errors, files, events, tests.passed, tests.failed, risk, risk.reason, proof.lang, proof.escapes, proof.oscillating, unverified.edits, tokens, tokens.in, tokens.out, cost, cache.breaks, cache.lost, cache.cost, unapproved, has, is. Event keys (the session has a matching event; event keys in one group match the same event): kind, tool, ok, mcp, error, event.duration, user, env, release (user, env and release read the session's start event and match on their own). Also sort:-cost and limit:N. Full list with examples: https://coding.sh/docs/query.
- --facets counts each key over the query without that key's own clauses, so every value of a picked key still shows. --limit sets the values per key (default 10).
- With --json each session is a digest: no stats.phases, no turn times in stats.turnsByModel, and each derail without the event it started at (eventId, index). show &lt;id&gt; --json has them all; --fields stats.phases, stats.turnsByModel or stats.derails prints them here.
- In --json, repo is the root of the checkout the session ran in. A session in a linked worktree also has repoMain, the main checkout's root.
Expand Down
8 changes: 7 additions & 1 deletion docs/reference/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ test each hit.
| `events` | session | Events captured | `events<10` |
| `tests.passed` | session | Passing tests seen | `tests.passed>0` |
| `tests.failed` | session | Failing tests seen | `tests.failed>0` |
| `risk` | session | Supervision risk level: `medium` or `high` | `risk:high` |
| `risk.reason` | session | Supervision risk reason (`unverified-edits`, `tactic-oscillation`, `post-compaction-repeats`, `dead-end-loop`, `compaction-churn`) | `risk.reason:tactic-oscillation` |
| `proof.lang` | session | Formal proof language: `lean`, `rocq`, `dafny`, `verus`, `isabelle`, `tla` or `tlc` | `proof.lang:lean` |
| `proof.escapes` | session | Remaining proof escape hatches (`sorry`, `Admitted`, …) in proof sessions | `proof.escapes>0` |
| `proof.oscillating` | session | Consecutive repeated failing proof checks in proof sessions | `proof.oscillating>=2` |
| `unverified.edits` | session | Longest streak of file edits with no mechanical check in between | `unverified.edits>=5` |

### Cost and token keys

Expand Down Expand Up @@ -307,7 +313,7 @@ no-verification 6

| Option | Default |
|---|---|
| Keys | `agent`, `model`, `provider`, `repo`, `launch`, `branch`, `flag`, `skill`, `hook`, `kind`, `tool`, `mcp` |
| Keys | `agent`, `model`, `provider`, `repo`, `launch`, `branch`, `flag`, `skill`, `hook`, `risk`, `risk.reason`, `proof.lang`, `kind`, `tool`, `mcp` |
| With no keys | `agent`, `model`, `repo`, `flag`, `skill`, `tool` |
| `--limit` | 10 values per key |

Expand Down
2 changes: 1 addition & 1 deletion packages/coding.sh/src/mcp/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const EXP_SESSION = { type: "string", description: "Default: the project's sessi
const WHERE = {
type: "string",
description:
"Filter query: key:value clauses ANDed; OR, ( ), - negates; a,b either; * wildcard; > >= < <= and a..b on numbers; bare words search text. Keys: agent model repo branch title flag skill cost tokens duration turns tools tool.errors since until has:tests|cost|error is:root|child|flagged; event keys tool kind ok mcp error. E.g. model:claude-* cost>0.5 tool:Bash ok:false",
"Query: key:value (AND; OR, (), - negates, a,b either, * wildcard, > >= < <= a..b on numbers; bare words search text). Keys: agent model repo branch title flag skill risk proof.lang cost tokens duration turns tools tool.errors since until has:tests|cost|error is:root|child|flagged; event: tool kind ok mcp error.",
};
const WHERE_SAME = (what: string) => ({ type: "string", description: `Filter query, same language as sessions_list where${what}.` });
const SESSION_ID = { type: "string", minLength: 1, description: 'Id, prefix or "latest".' };
Expand Down
99 changes: 92 additions & 7 deletions packages/coding.sh/src/query/where.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// every surface. This file imports no store, so the CLI registry can load the
// key docs for help without one.
import { CONTEXT_FLAGS, isFailureFlag } from "../core/failure-flags.ts";
import type { AgentEvent, Session } from "../schema/index.ts";
import type { AgentEvent, ProofLang, Session, SupervisionRisk } from "../schema/index.ts";
import { parseWhen } from "./time.ts";

export type Op = ":" | ">" | ">=" | "<" | "<=";
Expand Down Expand Up @@ -116,6 +116,8 @@ export interface KeyDef {
unit?: Unit;
/** Text keys: equals (default) or contains (case-insensitive substring). */
match?: "exact" | "contains";
/** Text keys with a fixed enum of allowed values (normalized to lowercase). */
choices?: readonly string[];
/** Text keys: the one spelling stored values have, applied to each typed value (repo: windowsSpelling). */
spell?: (raw: string) => string;
/** Time keys: since = at or after, until = before. */
Expand Down Expand Up @@ -265,6 +267,13 @@ const sqlGroupPath = (dir: string, main: string): string => `coalesce(${main}, C

const stat = (path: string) => `json_extract(s.stats, '$.${path}')`;
const num = (v: unknown): number | undefined => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
const RISK_LEVELS: readonly SupervisionRisk[] = ["medium", "high"];
const PROOF_LANGS: readonly ProofLang[] = ["lean", "rocq", "dafny", "verus", "isabelle", "tla", "tlc"];
const proofNum = (s: Session, field: "escapeRemaining" | "oscillatingChecks"): number | undefined => {
const p = s.stats?.verification?.proof;
if (!p) return undefined;
return num(p[field]) ?? 0;
};
const tokensTotal = (s: Session): number | undefined => {
const u = s.stats?.usage;
if (!u) return undefined;
Expand Down Expand Up @@ -346,6 +355,70 @@ const KEY_LIST: KeyDef[] = [
{ name: "events", level: "session", type: "number", unit: "count", doc: "Events captured", example: "events<10", sql: [stat("events")], get: (s) => [num(s.stats?.events)] },
{ name: "tests.passed", level: "session", type: "number", unit: "count", doc: "Passing tests seen", example: "tests.passed>0", sql: [stat("testsPassed")], get: (s) => [num(s.stats?.testsPassed)] },
{ name: "tests.failed", level: "session", type: "number", unit: "count", doc: "Failing tests seen", example: "tests.failed>0", sql: [stat("testsFailed")], get: (s) => [num(s.stats?.testsFailed)] },
{
name: "risk",
level: "session",
type: "text",
choices: RISK_LEVELS,
doc: "Supervision risk level: medium or high",
example: "risk:high",
sql: [stat("contextHygiene.supervisionRisk")],
get: (s) => [s.stats?.contextHygiene?.supervisionRisk],
facet: {},
},
{
name: "risk.reason",
level: "session",
type: "text",
doc: "Supervision risk reason (unverified-edits, tactic-oscillation, post-compaction-repeats, dead-end-loop, compaction-churn)",
example: "risk.reason:tactic-oscillation",
sql: ["j.value"],
multi: { from: stat("contextHygiene.riskReasons"), prefix: "" },
get: (s) => s.stats?.contextHygiene?.riskReasons ?? [],
facet: {},
},
{
name: "proof.lang",
level: "session",
type: "text",
choices: PROOF_LANGS,
doc: "Formal proof language (lean, rocq, dafny, verus, isabelle, tla, tlc)",
example: "proof.lang:lean",
sql: ["j.value"],
multi: { from: stat("verification.proof.langs"), prefix: "" },
get: (s) => s.stats?.verification?.proof?.langs ?? [],
facet: {},
},
{
name: "proof.escapes",
level: "session",
type: "number",
unit: "count",
doc: "Remaining proof escape hatches (sorry, Admitted, ...) in proof sessions",
example: "proof.escapes>0",
sql: [`CASE WHEN json_type(s.stats, '$.verification.proof') = 'object' THEN coalesce(${stat("verification.proof.escapeRemaining")}, 0) END`],
get: (s) => [proofNum(s, "escapeRemaining")],
},
{
name: "proof.oscillating",
level: "session",
type: "number",
unit: "count",
doc: "Consecutive repeated failing proof checks in proof sessions",
example: "proof.oscillating>=2",
sql: [`CASE WHEN json_type(s.stats, '$.verification.proof') = 'object' THEN coalesce(${stat("verification.proof.oscillatingChecks")}, 0) END`],
get: (s) => [proofNum(s, "oscillatingChecks")],
},
{
name: "unverified.edits",
level: "session",
type: "number",
unit: "count",
doc: "Longest consecutive streak of file edits with no mechanical check in between",
example: "unverified.edits>=5",
sql: [stat("verification.maxUnverifiedEdits")],
get: (s) => [num(s.stats?.verification?.maxUnverifiedEdits)],
},
{
name: "tokens",
level: "session",
Expand Down Expand Up @@ -446,12 +519,16 @@ export interface KeyGuide {
export function keyGuide(): KeyGuide[] {
const enumOf = (r: Record<string, HasDef>) => Object.entries(r).map(([value, d]) => ({ value, doc: d.doc }));
return [
...KEY_LIST.map((k): KeyGuide => ({
name: k.name, level: k.level, type: k.type, doc: k.doc, example: k.example,
...(k.facet ? { facet: true as const } : {}),
...(k.type === "bool" ? { values: [{ value: "true" }, { value: "false" }] } : {}),
...(k.type === "time" ? { values: ["1h", "24h", "7d", "30d"].map((value) => ({ value })) } : {}),
})),
...KEY_LIST.map((k): KeyGuide => {
const g: KeyGuide = {
name: k.name, level: k.level, type: k.type, doc: k.doc, example: k.example,
...(k.facet ? { facet: true as const } : {}),
...(k.type === "bool" ? { values: [{ value: "true" }, { value: "false" }] } : {}),
...(k.type === "time" ? { values: ["1h", "24h", "7d", "30d"].map((value) => ({ value })) } : {}),
};
if (k.choices) g.values = k.choices.map((value) => ({ value }));
return g;
}),
{ name: "is", level: "session", type: "enum", doc: "Is a kind of session", example: "is:root", values: enumOf(IS) },
{ name: "has", level: "session", type: "enum", doc: "Has a field", example: "has:tests", values: enumOf(HAS) },
{ name: "sort", level: "query", type: "enum", doc: "Order by; - for descending", example: "sort:-cost", values: SORT_KEYS.flatMap((k) => [{ value: `-${k}` }, { value: k }]) },
Expand Down Expand Up @@ -648,6 +725,14 @@ function resolveValue(def: KeyDef, op: Op, part: Part, now: number, tzOffsetMin?
if (text === "") throw bad("needs a value");
if (def.type === "text") {
if (op !== ":") throw bad(`compares text with ':' only, not '${op}'`);
if (def.choices) {
const lower = text.toLowerCase();
if (part.wild?.length || !def.choices.includes(lower)) {
throw bad(`must be one of ${def.choices.join(", ")}, got ${JSON.stringify(text)}`);
}
v.raw = lower;
return v;
}
// `*` is a wildcard, quoted or not; `\*` inside quotes is a literal star.
const wild = part.wild ?? starsIn(text);
if (wild.length) {
Expand Down
Loading
Loading