@alizain/doublecheck 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile.guest +8 -2
- package/README.md +149 -28
- package/dist/cli.mjs +266 -63
- package/dist/cli.mjs.map +1 -1
- package/package.json +3 -1
package/Dockerfile.guest
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
#
|
|
4
4
|
# ./scripts/build-guest-image.sh
|
|
5
5
|
#
|
|
6
|
-
# Baking the
|
|
7
|
-
#
|
|
6
|
+
# Baking the agent CLIs here (instead of `npm i -g` at every guest boot) pins
|
|
7
|
+
# their versions and cuts ~30s off each check run. Rebuild to pick up newer
|
|
8
|
+
# CLIs. One image serves both --agent values.
|
|
8
9
|
# git is for check-authored scoping ("run `git diff main`" lives in check
|
|
9
10
|
# prose); ripgrep because inspectors grep; curl/wget because checks may fetch
|
|
10
11
|
# from the internet (node:*-slim ships none of these).
|
|
@@ -15,3 +16,8 @@ RUN apt-get update \
|
|
|
15
16
|
&& rm -rf /var/lib/apt/lists/*
|
|
16
17
|
|
|
17
18
|
RUN npm install -g @anthropic-ai/claude-code
|
|
19
|
+
|
|
20
|
+
# codex ships a static musl binary via platform optionalDependencies — never
|
|
21
|
+
# add --omit=optional here or npm silently installs the JS launcher with no
|
|
22
|
+
# binary in it.
|
|
23
|
+
RUN npm install -g @openai/codex
|
package/README.md
CHANGED
|
@@ -4,23 +4,56 @@ Runs self-authored LLM code-inspectors ("checks") against a project — one
|
|
|
4
4
|
sandboxed agent per check, in parallel — and writes one markdown report per
|
|
5
5
|
check.
|
|
6
6
|
|
|
7
|
-
**A check is a markdown file:**
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
**A check is a markdown file:** a timeless standard — no frontmatter, no
|
|
8
|
+
schema; the body is the inspector's instructions. Checks come from one or
|
|
9
|
+
more `--checks-dir` directories (default: `$TARGET/.agents/checks`), so a
|
|
10
|
+
shared check set can serve a whole folder of repos. Everything run-specific —
|
|
11
|
+
the intent of the work under review, known nuances, sanctioned exceptions,
|
|
12
|
+
scope ("these changed files vs main") — arrives per run via `--context`; the
|
|
10
13
|
harness computes no diffs and knows nothing about git. **A report is a
|
|
11
|
-
markdown file:** whatever the agent writes, no imposed structure
|
|
14
|
+
markdown file:** whatever the agent writes, no imposed structure — and the
|
|
15
|
+
operator's agent reads every line of it, which the prompt tells the inspector.
|
|
16
|
+
|
|
17
|
+
## Why this exists
|
|
18
|
+
|
|
19
|
+
Linters and type checkers catch what can be pattern-matched. The defects that
|
|
20
|
+
survive them are judgment calls: a silent fallback that swallows a config
|
|
21
|
+
error, an abstraction at the wrong layer, a "for now" that will outlive its
|
|
22
|
+
author. doublecheck encodes *your* judgment about those — each check is a
|
|
23
|
+
standard you actually hold, written as prose instructions to an inspector
|
|
24
|
+
agent that can read the whole tree and reason about it.
|
|
25
|
+
|
|
26
|
+
The division of labor is deliberate: everything that requires judgment lives
|
|
27
|
+
in the check body (what to flag, what to leave alone, where to look);
|
|
28
|
+
everything mechanical lives in the harness (sandboxing, parallelism, report
|
|
29
|
+
collection). The harness knows nothing about git, diffs, or languages, so it
|
|
30
|
+
never needs to change when your standards do.
|
|
31
|
+
|
|
32
|
+
## The loop
|
|
33
|
+
|
|
34
|
+
1. **`doublecheck mine`** distills your Claude Code history into durable
|
|
35
|
+
preference observations (`~/.doublecheck/catalog`) — evidence of standards
|
|
36
|
+
you have actually enforced in past conversations.
|
|
37
|
+
2. **A human and/or agent authors checks** from those observations. This step
|
|
38
|
+
is deliberately unproductized: going from "observed preference" to
|
|
39
|
+
"runnable standard" is judgment work.
|
|
40
|
+
3. **`doublecheck check`** runs every check against a project, one sandboxed
|
|
41
|
+
agent per check, and writes one report per check. Read the reports, fix
|
|
42
|
+
what is real, tighten any check that cried wolf.
|
|
12
43
|
|
|
13
44
|
## How it works
|
|
14
45
|
|
|
15
|
-
Per check: a scratch workdir gets `prompt.txt` (environment preamble +
|
|
16
|
-
body + report contract). A [microsandbox](https://github.com/superradcompany/microsandbox)
|
|
46
|
+
Per check: a scratch workdir gets `prompt.txt` (environment preamble +
|
|
47
|
+
operator run context, when given + check body + report contract). A [microsandbox](https://github.com/superradcompany/microsandbox)
|
|
17
48
|
microVM boots from a locally built image with the project bind-mounted
|
|
18
49
|
**read-only at its real host path** and the scratch dir mounted rw as the
|
|
19
|
-
guest cwd.
|
|
20
|
-
|
|
21
|
-
|
|
50
|
+
guest cwd. The selected agent CLI (`--agent`: headless `claude -p`, or
|
|
51
|
+
`codex exec`) runs inside with its full toolkit and no permission gates —
|
|
52
|
+
the microVM is the safety boundary, the ro mount is the "don't touch
|
|
22
53
|
my repo" guarantee. The agent writes `report.md`; the host copies it to
|
|
23
|
-
`$OUTPUT/<run-timestamp>/<check>.md
|
|
54
|
+
`$OUTPUT/<run-timestamp>/<check>.md` (with `--save-jsonl`, alongside
|
|
55
|
+
`<check>.stream.jsonl` — the inspector's raw stream, kept so a run can be
|
|
56
|
+
audited after the guest is gone).
|
|
24
57
|
|
|
25
58
|
The project is never copied — every guest shares the live host directory
|
|
26
59
|
(dirty files included) through the ro mount, so per-check cost is one temp dir
|
|
@@ -36,8 +69,9 @@ missing token / checks / image abort loudly up front.
|
|
|
36
69
|
npm install -g @alizain/doublecheck # installs the `doublecheck` command; or, from a clone: pnpm install
|
|
37
70
|
```
|
|
38
71
|
|
|
39
|
-
Guests boot from a locally built image
|
|
40
|
-
repo (needs a running Docker daemon; rebuild to
|
|
72
|
+
Guests boot from a locally built image with both agent CLIs baked in. Build
|
|
73
|
+
it once from a clone of this repo (needs a running Docker daemon; rebuild to
|
|
74
|
+
pick up newer CLIs):
|
|
41
75
|
|
|
42
76
|
```bash
|
|
43
77
|
./scripts/build-guest-image.sh
|
|
@@ -47,15 +81,29 @@ repo (needs a running Docker daemon; rebuild to pick up a newer claude CLI):
|
|
|
47
81
|
|
|
48
82
|
```bash
|
|
49
83
|
CLAUDE_CODE_OAUTH_TOKEN=... doublecheck check \
|
|
50
|
-
--
|
|
51
|
-
--
|
|
84
|
+
--target DIR # tree under inspection, mounted read-only; default: cwd
|
|
85
|
+
--checks-dir DIR # repeatable; default: $TARGET/.agents/checks
|
|
86
|
+
--context FILE # run brief: intent, nuances, sanctioned exceptions, scope
|
|
87
|
+
--agent NAME # claude (default) or codex
|
|
88
|
+
--model MODEL # default per agent: claude haiku, codex gpt-5.5
|
|
52
89
|
--parallel N # default: 4 concurrent guests
|
|
53
|
-
--output DIR # default: $
|
|
54
|
-
--check NAME # repeatable; default: every check in
|
|
90
|
+
--output DIR # default: $TARGET/.doublecheck
|
|
91
|
+
--check NAME # repeatable; default: every check in the checks dirs
|
|
92
|
+
--save-jsonl # persist each inspector's raw stream beside its report
|
|
55
93
|
```
|
|
56
94
|
|
|
57
|
-
|
|
58
|
-
|
|
95
|
+
Credentials per agent, gathered on the host before any guest boots:
|
|
96
|
+
|
|
97
|
+
- **claude**: `CLAUDE_CODE_OAUTH_TOKEN` is required in the environment and
|
|
98
|
+
injected into each guest; where it comes from is the operator's business.
|
|
99
|
+
- **codex**: no env var — each guest gets a fresh copy of the host's
|
|
100
|
+
`~/.codex/auth.json` (run `codex login` once). For ChatGPT-plan auth the
|
|
101
|
+
run **hard-fails if the tokens were last refreshed over 7 days ago**:
|
|
102
|
+
codex self-refreshes at ~8 days, refresh tokens are single-use, and a
|
|
103
|
+
refresh inside a throwaway guest would rotate the token family and force
|
|
104
|
+
the host to re-login. Running any codex command on the host refreshes.
|
|
105
|
+
Residual risk: a mid-run 401 can still trigger a guest-side refresh.
|
|
106
|
+
Guests never write auth state back.
|
|
59
107
|
|
|
60
108
|
### Mining your Claude history into an observation catalog
|
|
61
109
|
|
|
@@ -65,13 +113,19 @@ turns) to extract durable engineering preferences into
|
|
|
65
113
|
`~/.doublecheck/catalog`, mirroring the transcript tree — one
|
|
66
114
|
`<project>/<session>/observations.md` per conversation, frontmatter recording
|
|
67
115
|
the source hash so re-runs only mine new or grown sessions. Mining guests get
|
|
68
|
-
egress to
|
|
116
|
+
egress to the selected agent's own API domains only (`claude`:
|
|
117
|
+
`*.anthropic.com`; `codex`: `*.chatgpt.com` + `*.openai.com`) — the one
|
|
118
|
+
reachable destination is the service the agent already sends its context to.
|
|
119
|
+
Note what that means for `--agent codex`: your Claude Code transcript
|
|
120
|
+
content flows to OpenAI. Design: `docs/2026-07-05-mine-design.md`.
|
|
69
121
|
|
|
70
122
|
```bash
|
|
71
123
|
CLAUDE_CODE_OAUTH_TOKEN=... doublecheck mine \
|
|
72
124
|
--projects DIR # default: ~/.claude/projects
|
|
73
125
|
--catalog DIR # default: ~/.doublecheck/catalog
|
|
74
|
-
--
|
|
126
|
+
--agent NAME # claude (default) or codex
|
|
127
|
+
--model MODEL # default per agent: claude opus, codex gpt-5.5
|
|
128
|
+
# (a bad-model mine pollutes a durable asset)
|
|
75
129
|
--parallel N # default: 4
|
|
76
130
|
--min-turns N # default: 2
|
|
77
131
|
--limit N # mine at most N pending conversations
|
|
@@ -83,10 +137,42 @@ two legitimate defaults that must not be flagged) for exercising the tool
|
|
|
83
137
|
end-to-end:
|
|
84
138
|
|
|
85
139
|
```bash
|
|
86
|
-
CLAUDE_CODE_OAUTH_TOKEN=... doublecheck check --
|
|
140
|
+
CLAUDE_CODE_OAUTH_TOKEN=... doublecheck check --target fixtures/planted --model haiku
|
|
141
|
+
doublecheck check --target fixtures/planted --agent codex # auth from ~/.codex/auth.json
|
|
87
142
|
```
|
|
88
143
|
|
|
89
|
-
##
|
|
144
|
+
## What the inspector sees
|
|
145
|
+
|
|
146
|
+
The facts of the agent's world, so you can decide how to author checks:
|
|
147
|
+
|
|
148
|
+
- **The agent** is one headless CLI process per check, running inside its
|
|
149
|
+
own microVM with all approval/permission gates bypassed — the VM is the
|
|
150
|
+
boundary. Check agents have unrestricted internet egress.
|
|
151
|
+
- `--agent claude` (default): `claude -p` (model from `--model`, default
|
|
152
|
+
haiku) with the pinned toolkit Task (it can spawn subagents), Bash,
|
|
153
|
+
Read, Write, Edit, Glob, Grep, WebSearch, WebFetch.
|
|
154
|
+
- `--agent codex`: `codex exec` (default model gpt-5.5, reasoning effort
|
|
155
|
+
pinned to xhigh in the staged guest config) with codex's own toolset:
|
|
156
|
+
shell, apply_patch, plan/todo, subagent spawning (multi_agent), and
|
|
157
|
+
server-side web search. The staged config disables codex's ambient
|
|
158
|
+
inputs — no AGENTS.md pickup, no plugin/marketplace fetch — so the
|
|
159
|
+
piped prompt is its only input, same as claude.
|
|
160
|
+
- **Its only input is the prompt**: a short environment preamble (verbatim in
|
|
161
|
+
`src/contract.ts`) + the operator's run context, when `--context` was given
|
|
162
|
+
+ the check body + the report contract. No session, no conversation history
|
|
163
|
+
— the check body is the standard; the run context is everything about this
|
|
164
|
+
particular run (intent, sanctioned exceptions, scope). The report contract
|
|
165
|
+
also tells the inspector that every line of its report is read in full,
|
|
166
|
+
findings must be verified, and "no findings" is a perfectly good report.
|
|
167
|
+
- **The filesystem**: the project is bind-mounted read-only at its real host
|
|
168
|
+
path — the live working tree, dirty files and `.git` included, so `git
|
|
169
|
+
log`/`git diff`/`git blame` and `rg` work against the real repo; writes to
|
|
170
|
+
it fail. The guest image also has node 24, curl, and wget. The cwd is a
|
|
171
|
+
writable scratch dir private to the check; nothing in it survives except
|
|
172
|
+
`report.md`.
|
|
173
|
+
- **The output**: the prompt tells the agent its chat reply is discarded and
|
|
174
|
+
only `./report.md` is read back. The harness imposes no structure on the
|
|
175
|
+
report — it contains whatever the check body asks for.
|
|
90
176
|
|
|
91
177
|
```bash
|
|
92
178
|
pnpm doublecheck # run the CLI from source (tsx)
|
|
@@ -95,12 +181,47 @@ pnpm typecheck # tsc --noEmit
|
|
|
95
181
|
pnpm check # biome
|
|
96
182
|
```
|
|
97
183
|
|
|
98
|
-
Design
|
|
184
|
+
Design records: `docs/2026-07-05-doublecheck-design.md`, `docs/2026-07-05-run-context-and-decomposed-flags-design.md`, `docs/2026-07-06-codex-agent-design.md`. For how a driving agent should use this tool — above all, what a good `--context` brief contains — see `SKILL.md`.
|
|
99
185
|
|
|
100
186
|
## Releasing
|
|
101
187
|
|
|
102
|
-
Manual, via the `release` GitHub Actions workflow
|
|
103
|
-
Conventional Commits
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
188
|
+
Manual, via the `release` GitHub Actions workflow — semantic-release over
|
|
189
|
+
Conventional Commits, ported from pggit. Nothing releases as a side effect of
|
|
190
|
+
pushing to main.
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
gh workflow run release -f dry_run=true # preview next version + notes, publish nothing
|
|
194
|
+
gh workflow run release -f dry_run=false # ship: npm publish + GitHub Release + tag
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
- **Only `feat:` / `fix:` / `BREAKING CHANGE:` commits trigger a release** and
|
|
198
|
+
decide the bump (minor / patch / major). Other commit styles ride along
|
|
199
|
+
unreleased — use `docs:`/`chore:`/plain messages for work that shouldn't ship
|
|
200
|
+
a version.
|
|
201
|
+
- `version` in package.json stays `0.0.0-development` forever — semantic-release
|
|
202
|
+
derives the real version from git tags. Never hand-bump it.
|
|
203
|
+
- The pre-publish gate is biome + tsc + **unit tests only** (`test:unit`
|
|
204
|
+
excludes `*.integration.test.ts`, which boots real microsandbox guests CI
|
|
205
|
+
doesn't have) + tsdown build. Run the full `pnpm test` locally before
|
|
206
|
+
releasing.
|
|
207
|
+
- Needs the `NPM_TOKEN` repo secret: a token that can publish
|
|
208
|
+
`@alizain/doublecheck` without an OTP prompt — classic "Automation" type, or
|
|
209
|
+
a granular token with read/write package access (and 2FA bypass if the
|
|
210
|
+
account requires 2FA for writes).
|
|
211
|
+
|
|
212
|
+
Learned the hard way on the first release (2026-07-05):
|
|
213
|
+
|
|
214
|
+
- **A failed `npm publish` leaves a stale tag.** semantic-release pushes
|
|
215
|
+
`vX.Y.Z` *before* publishing to npm. If the publish step fails, delete the
|
|
216
|
+
tag (`git push origin :refs/tags/vX.Y.Z`) before retrying — otherwise the
|
|
217
|
+
retry sees the tag as the last release, finds no new conventional commits,
|
|
218
|
+
and releases nothing.
|
|
219
|
+
- **The package is scoped because npm forbids unscoped `doublecheck`.** The
|
|
220
|
+
name-similarity rule (`DoubleCheck` and `double-check` exist) rejects it with
|
|
221
|
+
a 403 at publish time only — registry lookups 404 as if the name were free.
|
|
222
|
+
The installed bin is still `doublecheck`; `publishConfig.access: public` is
|
|
223
|
+
what keeps a scoped package from defaulting to private.
|
|
224
|
+
- **npm provenance/OIDC is off on purpose** — the presence of `id-token: write`
|
|
225
|
+
makes npm 11.x prefer trusted publishing and 404 when none is configured
|
|
226
|
+
(npm/cli#8976). Details in the comment block of
|
|
227
|
+
`.github/workflows/release.yml`.
|
package/dist/cli.mjs
CHANGED
|
@@ -2,41 +2,69 @@
|
|
|
2
2
|
import { homedir, tmpdir } from "node:os";
|
|
3
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { appendFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import PQueue from "p-queue";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
|
|
9
9
|
//#region src/contract.ts
|
|
10
10
|
const PROMPT_FILE = "prompt.txt";
|
|
11
11
|
const REPORT_FILE = "report.md";
|
|
12
|
-
function reportContract(activity, deliverable) {
|
|
12
|
+
function reportContract(activity, deliverable, workdir, writeTool) {
|
|
13
|
+
const tool = writeTool ? ` ${writeTool}` : "";
|
|
13
14
|
return `## Report — the only output that counts
|
|
14
15
|
|
|
15
|
-
Your final chat reply is discarded. The only thing read back is the file
|
|
16
|
+
Your final chat reply is discarded. The only thing read back is the file \`${workdir}/${REPORT_FILE}\` — if it does not exist when you exit, this run FAILS. Always use that absolute path: if you \`cd\` elsewhere (into the inspected tree, say), a relative \`./${REPORT_FILE}\` lands in the wrong place, or in a read-only mount where the write fails.
|
|
16
17
|
|
|
17
|
-
So: create
|
|
18
|
+
So: create \`${workdir}/${REPORT_FILE}\`${tool} BEFORE you start ${activity} (a title line is enough), and update it as you work. The final state of the file when you finish is ${deliverable}.`;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function firstActionLine(workdir, writeTool) {
|
|
21
|
+
const tool = writeTool ? ` ${writeTool}` : "";
|
|
22
|
+
return `Your FIRST action, before anything else: create \`${workdir}/${REPORT_FILE}\`${tool} (a title line is enough). The full report contract is at the end of this prompt.`;
|
|
23
|
+
}
|
|
24
|
+
function composePrompt(opts) {
|
|
25
|
+
const contextSection = opts.runContext ? `## Run context (from the operator)
|
|
26
|
+
|
|
27
|
+
The operator's brief for this run: the intent behind the work under review, known nuances, sanctioned exceptions, and possibly a Scope naming exactly what is under review. Judge requestedness against it — what the brief explicitly sanctions is not a finding. If it names a Scope, the Scope defines the change under review: findings must concern that change, and the rest of the tree is reference for judgment — with one exception. For concepts the scoped change retires or renames, surviving references anywhere in the tree are reportable findings: the Scope bounds what counts as the change, not where survivors may hide.
|
|
28
|
+
|
|
29
|
+
${opts.runContext}
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
` : "";
|
|
20
34
|
return `## Environment
|
|
21
35
|
|
|
22
36
|
You are a code inspector running inside a sandboxed microVM with full permissions and unrestricted internet access.
|
|
23
37
|
|
|
24
|
-
- The
|
|
38
|
+
- The code under inspection is mounted read-only at \`${opts.target}\`. You cannot modify it — inspect, don't fix.
|
|
25
39
|
- \`git\` and \`rg\` are installed.
|
|
26
|
-
- Your current working directory is a writable scratch workspace.
|
|
40
|
+
- Your current working directory is a writable scratch workspace: \`${opts.workdir}\`.
|
|
41
|
+
|
|
42
|
+
${firstActionLine(opts.workdir, opts.writeTool)}
|
|
43
|
+
|
|
44
|
+
## Inspection discipline
|
|
45
|
+
|
|
46
|
+
Measured on real runs: inspectors that skip these rules produce reports whose verdicts are right but whose evidence is partly fabricated — which is worse than no report.
|
|
47
|
+
|
|
48
|
+
- Before inspecting, enumerate what is under review (the Run context's Scope list if one is given; otherwise your own enumeration of the target) and keep a ledger as you work: **examined** (content actually opened), **name-only**, **not examined**. End your report with that ledger, with a one-line reason for anything not examined.
|
|
49
|
+
- Use verification verbs — "verified", "confirmed", "checked", "read", "diffed", "grepped", "spot-checked" — ONLY for actions you actually performed in this session on content you actually opened. Everything else must be labeled as inference: "assumed identical by generation — not opened."
|
|
50
|
+
- Never truncate output you will base a claim on — no \`| head\` / \`| tail\` on a diff or search you intend to cite. Examine files one at a time instead.
|
|
27
51
|
|
|
28
52
|
---
|
|
29
53
|
|
|
30
|
-
${checkBody}
|
|
54
|
+
${contextSection}${opts.checkBody}
|
|
31
55
|
|
|
32
56
|
---
|
|
33
57
|
|
|
34
|
-
${reportContract("inspecting", "the check's report")}
|
|
58
|
+
${reportContract("inspecting", "the check's report", opts.workdir, opts.writeTool)}
|
|
59
|
+
|
|
60
|
+
Every single line of your report will be read in full by the operator's agent — nothing is skimmed, so every line costs attention. Verify each finding against the actual code before writing it down. A report that says "no findings" is a perfectly good report; an unverified finding is not.`;
|
|
35
61
|
}
|
|
36
|
-
function composeMinePrompt(digest) {
|
|
62
|
+
function composeMinePrompt(digest, workdir, writeTool) {
|
|
37
63
|
return `## Environment
|
|
38
64
|
|
|
39
|
-
You are running inside a sandboxed microVM with no network access. The machine's Claude Code transcripts are mounted read-only at their real paths; your current working directory is a writable scratch workspace
|
|
65
|
+
You are running inside a sandboxed microVM with no network access. The machine's Claude Code transcripts are mounted read-only at their real paths; your current working directory is a writable scratch workspace: \`${workdir}\`.
|
|
66
|
+
|
|
67
|
+
${firstActionLine(workdir, writeTool)}
|
|
40
68
|
|
|
41
69
|
## Task
|
|
42
70
|
|
|
@@ -80,29 +108,29 @@ If the conversation carries no durable preference signal, the report is exactly
|
|
|
80
108
|
No durable preference signal.
|
|
81
109
|
<one sentence: what the conversation was about instead>
|
|
82
110
|
|
|
83
|
-
${reportContract("mining", "the mined observations")}`;
|
|
111
|
+
${reportContract("mining", "the mined observations", workdir, writeTool)}`;
|
|
84
112
|
}
|
|
85
113
|
|
|
86
114
|
//#endregion
|
|
87
115
|
//#region src/claude.ts
|
|
88
|
-
const GUEST_HOME = "/root";
|
|
116
|
+
const GUEST_HOME$1 = "/root";
|
|
89
117
|
function claudeAgent(opts) {
|
|
90
118
|
return {
|
|
91
119
|
command: `claude -p --no-session-persistence --dangerously-skip-permissions --output-format stream-json --verbose --tools Task Bash Read Write Edit Glob Grep WebSearch WebFetch < ${PROMPT_FILE}`,
|
|
92
120
|
env: {
|
|
93
|
-
HOME: GUEST_HOME,
|
|
121
|
+
HOME: GUEST_HOME$1,
|
|
94
122
|
IS_SANDBOX: "1",
|
|
95
123
|
GIT_OPTIONAL_LOCKS: "0",
|
|
96
124
|
ANTHROPIC_MODEL: opts.model,
|
|
97
125
|
CLAUDE_CODE_OAUTH_TOKEN: opts.token
|
|
98
126
|
},
|
|
99
127
|
files: [{
|
|
100
|
-
path: `${GUEST_HOME}/.claude.json`,
|
|
128
|
+
path: `${GUEST_HOME$1}/.claude.json`,
|
|
101
129
|
content: `${JSON.stringify({ projects: { [opts.workdir]: { hasTrustDialogAccepted: true } } }, null, " ")}\n`
|
|
102
130
|
}]
|
|
103
131
|
};
|
|
104
132
|
}
|
|
105
|
-
function
|
|
133
|
+
function describeClaudeStreamLine(line) {
|
|
106
134
|
let obj;
|
|
107
135
|
try {
|
|
108
136
|
obj = JSON.parse(line);
|
|
@@ -120,13 +148,145 @@ function describeStreamLine(line) {
|
|
|
120
148
|
} else if (obj.type === "result") detail = ` ${obj.subtype}, ${((obj.duration_ms ?? 0) / 1e3).toFixed(1)}s`;
|
|
121
149
|
return `[${label}]${detail}`;
|
|
122
150
|
}
|
|
123
|
-
|
|
151
|
+
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/codex.ts
|
|
154
|
+
const GUEST_HOME = "/root";
|
|
155
|
+
function guestConfig(model) {
|
|
156
|
+
return `model = "${model}"
|
|
157
|
+
approval_policy = "never"
|
|
158
|
+
sandbox_mode = "danger-full-access"
|
|
159
|
+
model_reasoning_effort = "xhigh"
|
|
160
|
+
web_search = "live"
|
|
161
|
+
project_doc_max_bytes = 0
|
|
162
|
+
cli_auth_credentials_store = "file"
|
|
163
|
+
|
|
164
|
+
[features]
|
|
165
|
+
plugins = false
|
|
166
|
+
apps = false
|
|
167
|
+
`;
|
|
168
|
+
}
|
|
169
|
+
function codexAgent(opts) {
|
|
170
|
+
return {
|
|
171
|
+
command: `codex exec --json --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox --ephemeral - < ${PROMPT_FILE}`,
|
|
172
|
+
env: {
|
|
173
|
+
HOME: GUEST_HOME,
|
|
174
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
175
|
+
},
|
|
176
|
+
files: [{
|
|
177
|
+
path: `${GUEST_HOME}/.codex/auth.json`,
|
|
178
|
+
content: opts.authJson
|
|
179
|
+
}, {
|
|
180
|
+
path: `${GUEST_HOME}/.codex/config.toml`,
|
|
181
|
+
content: guestConfig(opts.model)
|
|
182
|
+
}]
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const CODEX_AUTH_MAX_AGE_DAYS = 7;
|
|
186
|
+
function validateCodexAuth(content, now, where) {
|
|
187
|
+
let auth;
|
|
188
|
+
try {
|
|
189
|
+
auth = JSON.parse(content);
|
|
190
|
+
} catch {
|
|
191
|
+
throw new Error(`${where} is not valid JSON — run \`codex login\` on the host`);
|
|
192
|
+
}
|
|
193
|
+
if (auth.tokens?.refresh_token) {
|
|
194
|
+
if (!((now.getTime() - Date.parse(auth.last_refresh ?? "")) / 864e5 <= 7)) throw new Error(`${where} tokens were last refreshed over ${7} days ago (codex refreshes at ~8 days, and a refresh inside a guest would rotate the single-use refresh token and poison this host's session) — run any codex command on the host to refresh, then retry`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (auth.OPENAI_API_KEY) return;
|
|
198
|
+
throw new Error(`${where} has neither ChatGPT tokens nor an API key — run \`codex login\` on the host`);
|
|
199
|
+
}
|
|
200
|
+
const clip = (s, max = 60) => s.length > max ? `${s.slice(0, max)}…` : s;
|
|
201
|
+
function describeCodexStreamLine(line) {
|
|
202
|
+
let obj;
|
|
203
|
+
try {
|
|
204
|
+
obj = JSON.parse(line);
|
|
205
|
+
} catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
const item = obj.item;
|
|
209
|
+
const label = (obj.type ?? "") + (item?.type ? `:${item.type}` : "");
|
|
210
|
+
let detail = "";
|
|
211
|
+
if (item?.type === "agent_message") detail = ` ${item.text?.length ?? 0} chars`;
|
|
212
|
+
else if (item?.type === "command_execution" && item.command) detail = ` ${clip(item.command)}`;
|
|
213
|
+
else if (item?.type === "file_change") detail = ` ${(item.changes ?? []).length} file(s)`;
|
|
214
|
+
else if (obj.type === "turn.completed") detail = ` ${obj.usage?.input_tokens ?? 0} in, ${obj.usage?.output_tokens ?? 0} out tokens`;
|
|
215
|
+
else if (obj.type === "turn.failed") detail = ` ${clip(obj.error?.message ?? "")}`;
|
|
216
|
+
else if (obj.type === "error") detail = ` ${clip(obj.message ?? "")}`;
|
|
217
|
+
return `[${label}]${detail}`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/agent-cli.ts
|
|
222
|
+
const AGENT_CLIS = {
|
|
223
|
+
claude: {
|
|
224
|
+
name: "claude",
|
|
225
|
+
defaultModel: {
|
|
226
|
+
check: "haiku",
|
|
227
|
+
mine: "opus"
|
|
228
|
+
},
|
|
229
|
+
writeToolPhrase: "with the Write tool",
|
|
230
|
+
egressDomains: ["anthropic.com"],
|
|
231
|
+
credentials: () => {
|
|
232
|
+
const token = process.env.CLAUDE_CODE_OAUTH_TOKEN;
|
|
233
|
+
if (!token) throw new Error("CLAUDE_CODE_OAUTH_TOKEN is required in the environment (it is injected into each agent's sandbox)");
|
|
234
|
+
return token;
|
|
235
|
+
},
|
|
236
|
+
agent: ({ credentials, model, workdir }) => claudeAgent({
|
|
237
|
+
token: credentials,
|
|
238
|
+
model,
|
|
239
|
+
workdir
|
|
240
|
+
}),
|
|
241
|
+
describeStreamLine: describeClaudeStreamLine
|
|
242
|
+
},
|
|
243
|
+
codex: {
|
|
244
|
+
name: "codex",
|
|
245
|
+
defaultModel: {
|
|
246
|
+
check: "gpt-5.5",
|
|
247
|
+
mine: "gpt-5.5"
|
|
248
|
+
},
|
|
249
|
+
writeToolPhrase: null,
|
|
250
|
+
egressDomains: ["chatgpt.com", "openai.com"],
|
|
251
|
+
credentials: () => {
|
|
252
|
+
const authPath = join(homedir(), ".codex", "auth.json");
|
|
253
|
+
let content;
|
|
254
|
+
try {
|
|
255
|
+
content = readFileSync(authPath, "utf-8");
|
|
256
|
+
} catch {
|
|
257
|
+
throw new Error(`no readable ${authPath} — run \`codex login\` on the host`);
|
|
258
|
+
}
|
|
259
|
+
validateCodexAuth(content, /* @__PURE__ */ new Date(), authPath);
|
|
260
|
+
return content;
|
|
261
|
+
},
|
|
262
|
+
agent: ({ credentials, model, workdir }) => codexAgent({
|
|
263
|
+
authJson: credentials,
|
|
264
|
+
model,
|
|
265
|
+
workdir
|
|
266
|
+
}),
|
|
267
|
+
describeStreamLine: describeCodexStreamLine
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
function resolveAgentCli(name) {
|
|
271
|
+
const cli = AGENT_CLIS[name];
|
|
272
|
+
if (!cli) throw new Error(`unknown agent "${name}" (have: ${Object.keys(AGENT_CLIS).join(", ")})`);
|
|
273
|
+
return cli;
|
|
274
|
+
}
|
|
275
|
+
function resolveAgentRun(name, model, workflow) {
|
|
276
|
+
const cli = resolveAgentCli(name);
|
|
277
|
+
return {
|
|
278
|
+
cli,
|
|
279
|
+
credentials: cli.credentials(),
|
|
280
|
+
model: model ?? cli.defaultModel[workflow]
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function progressSink(label, describe) {
|
|
124
284
|
return (kind, line) => {
|
|
125
285
|
if (kind === "stderr") {
|
|
126
286
|
process.stderr.write(`[${label}] ! ${line}\n`);
|
|
127
287
|
return;
|
|
128
288
|
}
|
|
129
|
-
const described =
|
|
289
|
+
const described = describe(line);
|
|
130
290
|
if (described) process.stderr.write(`[${label}] ${described}\n`);
|
|
131
291
|
};
|
|
132
292
|
}
|
|
@@ -162,7 +322,12 @@ function decideOutcome(exitCode, report, workdir) {
|
|
|
162
322
|
async function runAgent(opts) {
|
|
163
323
|
const microsandbox = await import("microsandbox");
|
|
164
324
|
const name = `doublecheck-${basename(opts.workdir)}`;
|
|
165
|
-
const
|
|
325
|
+
const network = opts.network;
|
|
326
|
+
const policy = network === "all" ? microsandbox.NetworkPolicy.allowAll() : microsandbox.NetworkPolicy.builder().defaultDeny().egress((rb) => {
|
|
327
|
+
let rules = rb;
|
|
328
|
+
for (const domain of network.onlyDomains) rules = rules.allow((d) => d.domainSuffix(domain));
|
|
329
|
+
return rules;
|
|
330
|
+
}).build();
|
|
166
331
|
let sandbox = null;
|
|
167
332
|
try {
|
|
168
333
|
try {
|
|
@@ -215,31 +380,43 @@ async function runAgent(opts) {
|
|
|
215
380
|
|
|
216
381
|
//#endregion
|
|
217
382
|
//#region src/check.ts
|
|
218
|
-
function selectChecks(all, only,
|
|
219
|
-
if (all.length === 0) throw new Error(`no checks (*.md) in ${
|
|
383
|
+
function selectChecks(all, only, where) {
|
|
384
|
+
if (all.length === 0) throw new Error(`no checks (*.md) in ${where}`);
|
|
220
385
|
if (only.length === 0) return all;
|
|
221
386
|
const byName = new Map(all.map((c) => [c.name, c]));
|
|
222
387
|
return only.map((name) => {
|
|
223
388
|
const check = byName.get(name);
|
|
224
389
|
if (!check) {
|
|
225
390
|
const have = all.map((c) => c.name).join(", ");
|
|
226
|
-
throw new Error(`no check named "${name}" in ${
|
|
391
|
+
throw new Error(`no check named "${name}" in ${where} (have: ${have})`);
|
|
227
392
|
}
|
|
228
393
|
return check;
|
|
229
394
|
});
|
|
230
395
|
}
|
|
231
|
-
function discoverChecks(
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
396
|
+
function discoverChecks(dirs, only) {
|
|
397
|
+
const all = [];
|
|
398
|
+
for (const dir of dirs) {
|
|
399
|
+
let entries;
|
|
400
|
+
try {
|
|
401
|
+
entries = readdirSync(dir);
|
|
402
|
+
} catch {
|
|
403
|
+
throw new Error(`no checks directory at ${dir}`);
|
|
404
|
+
}
|
|
405
|
+
for (const f of entries.filter((e) => e.endsWith(".md")).sort()) {
|
|
406
|
+
const name = f.slice(0, -3);
|
|
407
|
+
const clash = all.find((c) => c.name === name);
|
|
408
|
+
if (clash) throw new Error(`check "${name}" exists in both ${clash.dir} and ${dir} — rename one`);
|
|
409
|
+
all.push({
|
|
410
|
+
name,
|
|
411
|
+
body: readFileSync(join(dir, f), "utf-8"),
|
|
412
|
+
dir
|
|
413
|
+
});
|
|
414
|
+
}
|
|
238
415
|
}
|
|
239
|
-
return selectChecks(
|
|
240
|
-
name
|
|
241
|
-
body
|
|
242
|
-
})), only,
|
|
416
|
+
return selectChecks(all.map(({ name, body }) => ({
|
|
417
|
+
name,
|
|
418
|
+
body
|
|
419
|
+
})).sort((a, b) => a.name.localeCompare(b.name)), only, dirs.join(", "));
|
|
243
420
|
}
|
|
244
421
|
function runTimestamp(d) {
|
|
245
422
|
const p = (n) => String(n).padStart(2, "0");
|
|
@@ -248,20 +425,35 @@ function runTimestamp(d) {
|
|
|
248
425
|
function failureReport(reason, partialReport) {
|
|
249
426
|
return `# CHECK FAILED\n\n${reason}\n${partialReport ? `\n---\n\nPartial ${REPORT_FILE} left by the agent:\n\n${partialReport}` : ""}`;
|
|
250
427
|
}
|
|
251
|
-
async function runOneCheck(check, opts,
|
|
428
|
+
async function runOneCheck(check, opts, run, runContext, outDir) {
|
|
252
429
|
const workdir = mkdtempSync(join(tmpdir(), `doublecheck-${check.name}-`));
|
|
253
|
-
writeFileSync(join(workdir, PROMPT_FILE), composePrompt(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
430
|
+
writeFileSync(join(workdir, PROMPT_FILE), composePrompt({
|
|
431
|
+
checkBody: check.body,
|
|
432
|
+
target: opts.target,
|
|
433
|
+
workdir,
|
|
434
|
+
runContext,
|
|
435
|
+
writeTool: run.cli.writeToolPhrase
|
|
436
|
+
}));
|
|
437
|
+
const spec = run.cli.agent({
|
|
438
|
+
credentials: run.credentials,
|
|
439
|
+
model: run.model,
|
|
257
440
|
workdir
|
|
258
441
|
});
|
|
442
|
+
const sink = progressSink(check.name, run.cli.describeStreamLine);
|
|
443
|
+
let onLine = sink;
|
|
444
|
+
if (opts.saveJsonl) {
|
|
445
|
+
const streamPath = join(outDir, `${check.name}.stream.jsonl`);
|
|
446
|
+
onLine = (kind, line) => {
|
|
447
|
+
if (kind === "stdout") appendFileSync(streamPath, `${line}\n`);
|
|
448
|
+
sink(kind, line);
|
|
449
|
+
};
|
|
450
|
+
}
|
|
259
451
|
const outcome = await runAgent({
|
|
260
|
-
mount: opts.
|
|
452
|
+
mount: opts.target,
|
|
261
453
|
workdir,
|
|
262
454
|
spec,
|
|
263
455
|
network: "all",
|
|
264
|
-
onLine
|
|
456
|
+
onLine
|
|
265
457
|
});
|
|
266
458
|
const reportPath = join(outDir, `${check.name}.md`);
|
|
267
459
|
if (outcome.ok) {
|
|
@@ -274,14 +466,19 @@ async function runOneCheck(check, opts, token, outDir) {
|
|
|
274
466
|
return false;
|
|
275
467
|
}
|
|
276
468
|
async function runChecks(opts) {
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
469
|
+
const run = resolveAgentRun(opts.agent, opts.model, "check");
|
|
470
|
+
const checks = discoverChecks(opts.checksDirs, opts.only);
|
|
471
|
+
let runContext = null;
|
|
472
|
+
if (opts.contextFile) try {
|
|
473
|
+
runContext = readFileSync(opts.contextFile, "utf-8");
|
|
474
|
+
} catch (e) {
|
|
475
|
+
throw new Error(`--context file not readable: ${opts.contextFile} (${String(e)})`);
|
|
476
|
+
}
|
|
280
477
|
const outDir = join(opts.output, runTimestamp(/* @__PURE__ */ new Date()));
|
|
281
478
|
mkdirSync(outDir, { recursive: true });
|
|
282
|
-
process.stderr.write(`${checks.length} check(s) against ${opts.
|
|
479
|
+
process.stderr.write(`${checks.length} check(s) against ${opts.target} (agent ${run.cli.name}, model ${run.model}, parallel ${opts.parallel})\n`);
|
|
283
480
|
const queue = new PQueue({ concurrency: opts.parallel });
|
|
284
|
-
return (await Promise.all(checks.map((check) => queue.add(() => runOneCheck(check, opts,
|
|
481
|
+
return (await Promise.all(checks.map((check) => queue.add(() => runOneCheck(check, opts, run, runContext, outDir))))).every((ok) => ok === true);
|
|
285
482
|
}
|
|
286
483
|
|
|
287
484
|
//#endregion
|
|
@@ -418,13 +615,13 @@ function summarizeMinePlan(plan, minTurns) {
|
|
|
418
615
|
function dryRunRow({ unit, status }) {
|
|
419
616
|
return `${status.reason.padEnd(7)} ${status.turns.toString().padStart(4)} turns ${unit.project}/${unit.session}`;
|
|
420
617
|
}
|
|
421
|
-
async function mineOneUnit({ unit, status }, opts,
|
|
618
|
+
async function mineOneUnit({ unit, status }, opts, run) {
|
|
422
619
|
const tag = unit.session.slice(0, 8);
|
|
423
620
|
const workdir = mkdtempSync(join(tmpdir(), `doublecheck-mine-${tag}-`));
|
|
424
|
-
writeFileSync(join(workdir, PROMPT_FILE), composeMinePrompt(status.digest));
|
|
425
|
-
const spec =
|
|
426
|
-
|
|
427
|
-
model:
|
|
621
|
+
writeFileSync(join(workdir, PROMPT_FILE), composeMinePrompt(status.digest, workdir, run.cli.writeToolPhrase));
|
|
622
|
+
const spec = run.cli.agent({
|
|
623
|
+
credentials: run.credentials,
|
|
624
|
+
model: run.model,
|
|
428
625
|
workdir
|
|
429
626
|
});
|
|
430
627
|
process.stderr.write(`[${tag}] mining ${unit.project}/${unit.session} (${status.turns} turns, ${status.reason})\n`);
|
|
@@ -432,8 +629,8 @@ async function mineOneUnit({ unit, status }, opts, token) {
|
|
|
432
629
|
mount: opts.projects,
|
|
433
630
|
workdir,
|
|
434
631
|
spec,
|
|
435
|
-
network:
|
|
436
|
-
onLine: progressSink(tag)
|
|
632
|
+
network: { onlyDomains: run.cli.egressDomains },
|
|
633
|
+
onLine: progressSink(tag, run.cli.describeStreamLine)
|
|
437
634
|
});
|
|
438
635
|
if (!outcome.ok) {
|
|
439
636
|
process.stderr.write(`[${tag}] FAILED (${outcome.reason})\n`);
|
|
@@ -445,13 +642,14 @@ async function mineOneUnit({ unit, status }, opts, token) {
|
|
|
445
642
|
source: unit.jsonlPath,
|
|
446
643
|
sourceSha256: status.sourceSha256,
|
|
447
644
|
minedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
448
|
-
model:
|
|
645
|
+
model: run.model,
|
|
449
646
|
humanTurns: status.turns
|
|
450
647
|
}, outcome.report));
|
|
451
648
|
process.stderr.write(`[${tag}] observations: ${obsPath}\n`);
|
|
452
649
|
return true;
|
|
453
650
|
}
|
|
454
651
|
async function runMine(opts) {
|
|
652
|
+
resolveAgentCli(opts.agent);
|
|
455
653
|
const plan = planMine(enumerateUnits(opts.projects).map((unit) => ({
|
|
456
654
|
unit,
|
|
457
655
|
status: unitStatus(unit, opts.catalog, opts.minTurns)
|
|
@@ -463,10 +661,9 @@ async function runMine(opts) {
|
|
|
463
661
|
return true;
|
|
464
662
|
}
|
|
465
663
|
if (plan.todo.length === 0) return true;
|
|
466
|
-
const
|
|
467
|
-
if (!token) throw new Error("CLAUDE_CODE_OAUTH_TOKEN is required in the environment (it is injected into each miner's sandbox)");
|
|
664
|
+
const run = resolveAgentRun(opts.agent, opts.model, "mine");
|
|
468
665
|
const queue = new PQueue({ concurrency: opts.parallel });
|
|
469
|
-
const results = await Promise.all(plan.todo.map((p) => queue.add(() => mineOneUnit(p, opts,
|
|
666
|
+
const results = await Promise.all(plan.todo.map((p) => queue.add(() => mineOneUnit(p, opts, run))));
|
|
470
667
|
const failed = results.filter((ok) => ok !== true).length;
|
|
471
668
|
process.stderr.write(`mined ${results.length - failed}/${results.length}${failed ? `, ${failed} FAILED` : ""}\n`);
|
|
472
669
|
return failed === 0;
|
|
@@ -481,21 +678,27 @@ function parsePositiveInt(flag) {
|
|
|
481
678
|
return n;
|
|
482
679
|
};
|
|
483
680
|
}
|
|
484
|
-
const
|
|
485
|
-
program
|
|
486
|
-
|
|
681
|
+
const collect = (v, prev) => [...prev, v];
|
|
682
|
+
const program = new Command().name("doublecheck").description("Run self-authored LLM code-inspectors (checks) against a target tree, one sandboxed agent per check");
|
|
683
|
+
program.command("check").option("--target <dir>", "tree under inspection, mounted read-only", process.cwd()).option("--checks-dir <dir>", "checks directory (repeatable; default: $TARGET/.agents/checks)", collect, []).option("--context <file>", "run-context file spliced into every inspector's prompt (intent, nuances, sanctioned exceptions, scope)").option("--agent <name>", "agent CLI that runs the inspectors: claude or codex", "claude").option("--model <model>", "model for the inspector agents (default per agent: claude haiku, codex gpt-5.5)").option("--parallel <n>", "max concurrent checks", parsePositiveInt("--parallel"), 4).option("--output <dir>", "reports root (default: $TARGET/.doublecheck)").option("--check <name>", "run only this check (repeatable)", collect, []).option("--save-jsonl", "persist each inspector's raw stream-json beside its report (audit trail)").action(async (opts) => {
|
|
684
|
+
const target = resolve(opts.target);
|
|
487
685
|
if (!await runChecks({
|
|
488
|
-
|
|
686
|
+
target,
|
|
687
|
+
checksDirs: opts.checksDir.length > 0 ? opts.checksDir.map((d) => resolve(d)) : [join(target, ".agents", "checks")],
|
|
688
|
+
contextFile: opts.context ? resolve(opts.context) : null,
|
|
689
|
+
agent: opts.agent,
|
|
489
690
|
model: opts.model,
|
|
490
691
|
parallel: opts.parallel,
|
|
491
|
-
output: opts.output ? resolve(opts.output) : join(
|
|
492
|
-
only: opts.check
|
|
692
|
+
output: opts.output ? resolve(opts.output) : join(target, ".doublecheck"),
|
|
693
|
+
only: opts.check,
|
|
694
|
+
saveJsonl: !!opts.saveJsonl
|
|
493
695
|
})) process.exitCode = 1;
|
|
494
696
|
});
|
|
495
|
-
program.command("mine").option("--projects <dir>", "Claude Code transcripts root", join(homedir(), ".claude", "projects")).option("--catalog <dir>", "observation catalog root", join(homedir(), ".doublecheck", "catalog")).option("--model <model>", "model for the mining agents
|
|
697
|
+
program.command("mine").option("--projects <dir>", "Claude Code transcripts root", join(homedir(), ".claude", "projects")).option("--catalog <dir>", "observation catalog root", join(homedir(), ".doublecheck", "catalog")).option("--agent <name>", "agent CLI that runs the miners: claude or codex", "claude").option("--model <model>", "model for the mining agents (default per agent: claude opus, codex gpt-5.5 — a bad-model mine pollutes a durable asset)").option("--parallel <n>", "max concurrent miners", parsePositiveInt("--parallel"), 4).option("--min-turns <n>", "min genuine human turns for a real conversation", parsePositiveInt("--min-turns"), 2).option("--limit <n>", "mine at most N pending units", parsePositiveInt("--limit")).option("--dry-run", "list what would be mined without booting anything").action(async (opts) => {
|
|
496
698
|
if (!await runMine({
|
|
497
699
|
projects: resolve(opts.projects),
|
|
498
700
|
catalog: resolve(opts.catalog),
|
|
701
|
+
agent: opts.agent,
|
|
499
702
|
model: opts.model,
|
|
500
703
|
parallel: opts.parallel,
|
|
501
704
|
minTurns: opts.minTurns,
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":[],"sources":["../src/contract.ts","../src/claude.ts","../src/runner.ts","../src/check.ts","../src/transcript.ts","../src/catalog.ts","../src/mine.ts","../src/cli.ts"],"sourcesContent":["// The agent contract: what the harness stages for the agent and what the\n// agent must leave behind. Any adapter (claude today, codex someday) runs\n// under this same contract, which is what keeps the harness CLI-agnostic.\n\n// Staged into the scratch workdir before boot; the rw bind mount delivers it.\nexport const PROMPT_FILE = \"prompt.txt\"\n// The agent writes its findings here (relative to its cwd); the host reads it\n// back after exit. Missing report = failure.\nexport const REPORT_FILE = \"report.md\"\n\n// Weak models reliably skip a report contract stated once at the prompt's\n// tail unless it leads with the stakes and orders the file created first\n// (measured: haiku went from ~50% to 3/3 with this wording).\nfunction reportContract(activity: string, deliverable: string): string {\n\treturn `## Report — the only output that counts\n\nYour final chat reply is discarded. The only thing read back is the file \\`./${REPORT_FILE}\\` in your working directory — if it does not exist when you exit, this run FAILS.\n\nSo: create \\`./${REPORT_FILE}\\` with the Write tool BEFORE you start ${activity} (a title line is enough), and update it as you work. The final state of the file when you finish is ${deliverable}.`\n}\n\n// Environment preamble + check body + report contract. Scoping (diff vs tree)\n// is the check's own prose — the harness knows nothing about git.\nexport function composePrompt(checkBody: string, project: string): string {\n\treturn `## Environment\n\nYou are a code inspector running inside a sandboxed microVM with full permissions and unrestricted internet access.\n\n- The project under inspection is mounted read-only at \\`${project}\\`. You cannot modify it — inspect, don't fix.\n- \\`git\\` and \\`rg\\` are installed.\n- Your current working directory is a writable scratch workspace.\n\n---\n\n${checkBody}\n\n---\n\n${reportContract(\"inspecting\", \"the check's report\")}`\n}\n\n// The mining prompt: digest of one conversation + what counts as a durable\n// preference observation + the block format the catalog accumulates.\nexport function composeMinePrompt(digest: string): string {\n\treturn `## Environment\n\nYou are running inside a sandboxed microVM with no network access. The machine's Claude Code transcripts are mounted read-only at their real paths; your current working directory is a writable scratch workspace.\n\n## Task\n\nYou are mining ONE Claude Code conversation for the operator's durable preferences — how they want engineering done, in any conversation, not what they wanted built in this one.\n\nBelow is the conversation digest: every genuine human turn, numbered, in order. When a turn is a terse correction or interruption (\"no\", \"stop\", \"don't\", \"why did you…\", \"[Request interrupted]\"), recover its context: the \"# source:\" header names the full session transcript — Grep that turn's text in it to find its line, then Read the assistant turns IMMEDIATELY BEFORE it with offset/limit. The preference lives in the contrast between what the assistant did and what the operator demanded. NEVER read a transcript whole — some are tens of MB.\n\n---\n\n${digest}\n\n---\n\n## What counts as an observation (strict)\n\nA durable preference, backed by a verbatim quote from the digest or transcript:\n\n- **kind: code** — how code should be written/structured/shaped (\"no silent fallbacks\", \"reuse the existing helper instead of hand-rolling\").\n- **kind: workflow** — how work should proceed (\"verify before claiming done\", \"ask before making scope decisions\").\n- **kind: style** — how prose/output/docs should read.\n\nExclude task-of-the-moment directives with no durable signal (\"add a tab to home.tsx\", \"kill the dev server\"). Exclude anything you cannot quote. Be conservative: a weak or speculative observation is worse than none.\n\n## Observation format\n\nThe report is observation blocks and NOTHING else — no title, no preamble, no summary or conclusion sections. One block per observation:\n\n## <kebab-case-name>\n- **observation:** <one sentence: the durable preference>\n- **kind:** code | workflow | style\n- **evidence:** \"<verbatim quote>\" — turn <N>\n\nFor **code** observations that an LLM reviewer could check against a diff or file tree (a concrete change could flip PASS↔FAIL), and ONLY for those — never on workflow or style blocks — ALSO add:\n\n- **pass/fail:** PASS when <…>; FAIL when <…>\n- **why-LLM:** <why a deterministic linter cannot enforce this>\n- **scope:** diff-only | needs-tree\n\nIf the conversation carries no durable preference signal, the report is exactly these two lines and nothing more:\n\nNo durable preference signal.\n<one sentence: what the conversation was about instead>\n\n${reportContract(\"mining\", \"the mined observations\")}`\n}\n","import { PROMPT_FILE } from \"./contract.ts\"\nimport type { AgentSpec } from \"./runner.ts\"\n\nconst GUEST_HOME = \"/root\"\n\n// The claude adapter: produce the AgentSpec that runs `claude -p` in the guest.\nexport function claudeAgent(opts: {\n\ttoken: string\n\tmodel: string\n\tworkdir: string\n}): AgentSpec {\n\treturn {\n\t\t// Headless claude -p cannot answer permission prompts, so in \"default\"\n\t\t// mode every tool is auto-denied and the agent produces nothing. The\n\t\t// microVM is the safety boundary here, so bypass the per-tool gate;\n\t\t// IS_SANDBOX=1 is what lets that run as root without claude's refusal.\n\t\tcommand:\n\t\t\t\"claude -p --no-session-persistence \" +\n\t\t\t\"--dangerously-skip-permissions \" +\n\t\t\t// --verbose is required by claude -p with stream-json output; it only\n\t\t\t// widens what lands on stdout, which describeStreamLine already labels.\n\t\t\t\"--output-format stream-json --verbose \" +\n\t\t\t// Not a permission gate — a contract guard. The default headless tool\n\t\t\t// set omits Glob/Grep and includes harness tools (ReportFindings,\n\t\t\t// TaskCreate, …) that hijack the report: haiku \"reports findings\"\n\t\t\t// through them and never writes report.md (verified live). This pins\n\t\t\t// the inspector's full toolkit and nothing else.\n\t\t\t`--tools Task Bash Read Write Edit Glob Grep WebSearch WebFetch < ${PROMPT_FILE}`,\n\t\tenv: {\n\t\t\tHOME: GUEST_HOME,\n\t\t\tIS_SANDBOX: \"1\",\n\t\t\tGIT_OPTIONAL_LOCKS: \"0\",\n\t\t\tANTHROPIC_MODEL: opts.model,\n\t\t\tCLAUDE_CODE_OAUTH_TOKEN: opts.token,\n\t\t},\n\t\t// Minimal trust-accepted entry keyed to the guest cwd so headless claude\n\t\t// skips the trust prompt. Deliberately NOT a copy of any host .claude.json.\n\t\tfiles: [\n\t\t\t{\n\t\t\t\tpath: `${GUEST_HOME}/.claude.json`,\n\t\t\t\tcontent: `${JSON.stringify(\n\t\t\t\t\t{ projects: { [opts.workdir]: { hasTrustDialogAccepted: true } } },\n\t\t\t\t\tnull,\n\t\t\t\t\t\"\\t\",\n\t\t\t\t)}\\n`,\n\t\t\t},\n\t\t],\n\t}\n}\n\ninterface StreamLine {\n\ttype?: string\n\tsubtype?: string\n\tmessage?: { content?: Array<{ type?: string; text?: string; name?: string }> }\n\tduration_ms?: number\n}\n\n// One human-readable label per stream-json stdout line; null for lines that\n// aren't claude's JSON (dropped from the progress stream).\nexport function describeStreamLine(line: string): string | null {\n\tlet obj: StreamLine\n\ttry {\n\t\tobj = JSON.parse(line) as StreamLine\n\t} catch {\n\t\treturn null\n\t}\n\tconst label = (obj.type ?? \"\") + (obj.subtype ? `:${obj.subtype}` : \"\")\n\t// A once-per-second heartbeat with no content — pure noise in the stream.\n\tif (label === \"system:thinking_tokens\") return null\n\tlet detail = \"\"\n\tif (obj.type === \"assistant\") {\n\t\tconst content = obj.message?.content ?? []\n\t\tconst tools = content\n\t\t\t.filter((b) => b.type === \"tool_use\" && b.name)\n\t\t\t.map((b) => b.name)\n\t\tconst chars = content.reduce((n, b) => n + (b.text?.length ?? 0), 0)\n\t\tdetail = tools.length ? ` ${tools.join(\",\")}` : ` ${chars} chars`\n\t} else if (obj.type === \"result\") {\n\t\tdetail = ` ${obj.subtype}, ${((obj.duration_ms ?? 0) / 1000).toFixed(1)}s`\n\t}\n\treturn `[${label}]${detail}`\n}\n\n// The per-unit progress sink both workflow shells hang on runAgent: guest\n// stderr passes through as `[label] ! line`, stdout is claude's stream-json,\n// labelled by describeStreamLine (non-JSON and heartbeat lines dropped).\nexport function progressSink(\n\tlabel: string,\n): (kind: \"stdout\" | \"stderr\", line: string) => void {\n\treturn (kind, line) => {\n\t\tif (kind === \"stderr\") {\n\t\t\tprocess.stderr.write(`[${label}] ! ${line}\\n`)\n\t\t\treturn\n\t\t}\n\t\tconst described = describeStreamLine(line)\n\t\tif (described) process.stderr.write(`[${label}] ${described}\\n`)\n\t}\n}\n","import { existsSync, readFileSync } from \"node:fs\"\nimport { basename, join } from \"node:path\"\nimport type { ExecEvent } from \"microsandbox\"\nimport { REPORT_FILE } from \"./contract.ts\"\n\n// microsandbox exports its fluent builders as value-only consts; recover their\n// instance types via a type-only import (erased at build) so the native module\n// only loads behind the `await import` in runAgent.\ntype MountBuilder = InstanceType<typeof import(\"microsandbox\").MountBuilder>\ntype PatchBuilder = InstanceType<typeof import(\"microsandbox\").PatchBuilder>\ntype ExecOptionsBuilder = InstanceType<typeof import(\"microsandbox\").ExecOptionsBuilder>\n// The SDK types `.network(cb)` as `(b: any) => any`, and we call the JS-shim\n// `.policy(...)`, absent from the native builder's types.\n// biome-ignore lint/suspicious/noExplicitAny: SDK types this builder callback as any\ntype NetworkBuilder = any\n\n// Locally built (Dockerfile.guest): node 24 slim + git/ripgrep/curl/wget + the\n// claude CLI baked in. Side-loaded into the microsandbox cache by\n// ./scripts/build-guest-image.sh — it exists nowhere else, hence pullPolicy\n// \"never\": a cache miss means \"run the build script\", not \"try Docker Hub\".\nconst GUEST_IMAGE = \"doublecheck-guest:latest\"\nconst GUEST_MEMORY_MIB = 2048\n\n// Staged into the guest before boot (e.g. claude's trust-accepted config).\nexport interface GuestFile {\n\tpath: string\n\tcontent: string\n}\n\n// What it takes to run one agent in a booted guest: a bash command executed in\n// the scratch cwd that must leave REPORT_FILE there, the env it needs, and\n// files staged into the guest. Plain data — adapters produce it, this runner\n// consumes it, tests fake it.\nexport interface AgentSpec {\n\tcommand: string\n\tenv: Record<string, string>\n\tfiles: GuestFile[]\n}\n\nexport type AgentOutcome =\n\t| { ok: true; report: string }\n\t| { ok: false; reason: string; partialReport: string | null }\n\n// Pure line buffering: fold a chunk into the carry, emit complete non-blank\n// lines, keep the unterminated tail.\nexport function feedLines(\n\tcarry: string,\n\tchunk: string,\n): { lines: string[]; carry: string } {\n\tconst parts = (carry + chunk).split(\"\\n\")\n\tconst rest = parts.pop() ?? \"\"\n\treturn { lines: parts.filter((l) => l.trim()), carry: rest }\n}\n\n// Pure outcome decision: what the exec left behind → what it means.\nexport function decideOutcome(\n\texitCode: number | null,\n\treport: string | null,\n\tworkdir: string,\n): AgentOutcome {\n\tif (exitCode !== 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `agent process exited ${exitCode}`,\n\t\t\tpartialReport: report,\n\t\t}\n\t}\n\tif (report === null) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `agent exited 0 but wrote no ${REPORT_FILE} (work dir: ${workdir})`,\n\t\t\tpartialReport: null,\n\t\t}\n\t}\n\treturn { ok: true, report }\n}\n\nexport interface RunAgentOpts {\n\t// Host dir the agent inspects, bind-mounted READ-ONLY at its real host\n\t// path: the project for `check`, the transcripts corpus for `mine`.\n\tmount: string\n\t// Scratch dir with PROMPT_FILE already inside; bind-mounted rw as the guest\n\t// cwd at its identical host path, so the agent's report lands back on the host.\n\tworkdir: string\n\tspec: AgentSpec\n\t// \"all\" for checks (inspectors may research); \"anthropic-only\" for miners:\n\t// the personal corpus is mounted, so the only reachable destination is the\n\t// API the agent already sends its context to. NetworkPolicy.none() is not\n\t// an option here — it kills DNS entirely and the adapter can't reach its\n\t// own model API (measured: claude retries ~180s then exits 1).\n\tnetwork: \"all\" | \"anthropic-only\"\n\tonLine: (kind: \"stdout\" | \"stderr\", line: string) => void\n}\n\n// Boot a guest (ro mount + scratch rw as cwd), exec the agent command, stream\n// its output line-by-line, read the report back off the scratch dir, tear\n// down. Agent-level failures (exit ≠ 0, no report) return ok:false;\n// harness-level failures (image missing, boot error) throw.\nexport async function runAgent(opts: RunAgentOpts): Promise<AgentOutcome> {\n\tconst microsandbox = await import(\"microsandbox\")\n\tconst name = `doublecheck-${basename(opts.workdir)}`\n\tconst policy =\n\t\topts.network === \"all\"\n\t\t\t? microsandbox.NetworkPolicy.allowAll()\n\t\t\t: microsandbox.NetworkPolicy.builder()\n\t\t\t\t\t.defaultDeny()\n\t\t\t\t\t.egress((rb) => rb.allow((d) => d.domainSuffix(\"anthropic.com\")))\n\t\t\t\t\t.build()\n\tlet sandbox: InstanceType<typeof microsandbox.Sandbox> | null = null\n\ttry {\n\t\ttry {\n\t\t\tsandbox = await microsandbox.Sandbox.builder(name)\n\t\t\t\t.image(GUEST_IMAGE)\n\t\t\t\t.memory(GUEST_MEMORY_MIB)\n\t\t\t\t.pullPolicy(\"never\")\n\t\t\t\t.replace()\n\t\t\t\t.workdir(opts.workdir)\n\t\t\t\t.envs(opts.spec.env)\n\t\t\t\t.volume(opts.mount, (mb: MountBuilder) => mb.bind(opts.mount).readonly())\n\t\t\t\t.volume(opts.workdir, (mb: MountBuilder) => mb.bind(opts.workdir))\n\t\t\t\t.patch((pb: PatchBuilder) => {\n\t\t\t\t\tlet p = pb\n\t\t\t\t\tfor (const f of opts.spec.files) {\n\t\t\t\t\t\tp = p.text(f.path, f.content, { mode: 0o600, replace: true })\n\t\t\t\t\t}\n\t\t\t\t\treturn p\n\t\t\t\t})\n\t\t\t\t.network((nb: NetworkBuilder) => nb.policy(policy))\n\t\t\t\t.create()\n\t\t} catch (e) {\n\t\t\tif (String(e).includes(\"not cached\")) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`guest image ${GUEST_IMAGE} is not in the microsandbox cache — run scripts/build-guest-image.sh (${String(e)})`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\n\t\tconst handle = await sandbox.execStreamWith(\"bash\", (e: ExecOptionsBuilder) =>\n\t\t\te.args([\"-c\", opts.spec.command]),\n\t\t)\n\n\t\tconst carry: Record<\"stdout\" | \"stderr\", string> = { stdout: \"\", stderr: \"\" }\n\t\tlet exitCode: number | null = null\n\t\tfor (;;) {\n\t\t\tconst ev: ExecEvent | null = await handle.recv()\n\t\t\tif (ev === null) break\n\t\t\tif (ev.kind === \"stdout\" || ev.kind === \"stderr\") {\n\t\t\t\tconst fed = feedLines(carry[ev.kind], Buffer.from(ev.data).toString())\n\t\t\t\tcarry[ev.kind] = fed.carry\n\t\t\t\tfor (const line of fed.lines) opts.onLine(ev.kind, line)\n\t\t\t} else if (ev.kind === \"exited\") exitCode = ev.code\n\t\t}\n\t\tfor (const kind of [\"stdout\", \"stderr\"] as const) {\n\t\t\tif (carry[kind].trim()) opts.onLine(kind, carry[kind])\n\t\t}\n\n\t\tconst reportPath = join(opts.workdir, REPORT_FILE)\n\t\tconst report = existsSync(reportPath) ? readFileSync(reportPath, \"utf-8\") : null\n\t\treturn decideOutcome(exitCode, report, opts.workdir)\n\t} finally {\n\t\tif (sandbox) {\n\t\t\ttry {\n\t\t\t\tawait sandbox.stop()\n\t\t\t} catch (e) {\n\t\t\t\topts.onLine(\"stderr\", `sandbox stop failed: ${String(e)}`)\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait microsandbox.Sandbox.remove(name)\n\t\t\t} catch (e) {\n\t\t\t\topts.onLine(\"stderr\", `sandbox remove failed: ${String(e)}`)\n\t\t\t}\n\t\t}\n\t}\n}\n","import { mkdirSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\"\nimport { tmpdir } from \"node:os\"\nimport { join } from \"node:path\"\nimport PQueue from \"p-queue\"\nimport { claudeAgent, progressSink } from \"./claude.ts\"\nimport { composePrompt, PROMPT_FILE, REPORT_FILE } from \"./contract.ts\"\nimport { runAgent } from \"./runner.ts\"\n\n// A check is a plain markdown file in $PROJECT/.agents/checks — no\n// frontmatter, no schema. The body is the inspector's instructions; the name\n// is the filename minus .md.\nexport interface Check {\n\tname: string\n\tbody: string\n}\n\n// Pure selection: `only` (from repeated --check flags) filters, in the order\n// named; naming a check that doesn't exist is an error, not an empty run.\nexport function selectChecks(all: Check[], only: string[], dir: string): Check[] {\n\tif (all.length === 0) throw new Error(`no checks (*.md) in ${dir}`)\n\tif (only.length === 0) return all\n\tconst byName = new Map(all.map((c) => [c.name, c]))\n\treturn only.map((name) => {\n\t\tconst check = byName.get(name)\n\t\tif (!check) {\n\t\t\tconst have = all.map((c) => c.name).join(\", \")\n\t\t\tthrow new Error(`no check named \"${name}\" in ${dir} (have: ${have})`)\n\t\t}\n\t\treturn check\n\t})\n}\n\n// Shell: read every check file, then select purely.\nexport function discoverChecks(project: string, only: string[]): Check[] {\n\tconst dir = join(project, \".agents\", \"checks\")\n\tlet entries: string[]\n\ttry {\n\t\tentries = readdirSync(dir)\n\t} catch {\n\t\tthrow new Error(`no checks directory at ${dir}`)\n\t}\n\tconst all = entries\n\t\t.filter((f) => f.endsWith(\".md\"))\n\t\t.sort()\n\t\t.map((f) => ({\n\t\t\tname: f.slice(0, -\".md\".length),\n\t\t\tbody: readFileSync(join(dir, f), \"utf-8\"),\n\t\t}))\n\treturn selectChecks(all, only, dir)\n}\n\nexport interface CheckWorkflowOpts {\n\tproject: string\n\tmodel: string\n\tparallel: number\n\toutput: string\n\tonly: string[]\n}\n\n// fs-safe local timestamp, one dir per run shared by all its checks:\n// 2026-07-05-143000\nexport function runTimestamp(d: Date): string {\n\tconst p = (n: number) => String(n).padStart(2, \"0\")\n\treturn `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`\n}\n\n// The report written when the agent failed: the failure is the report, plus\n// whatever partial report the agent managed to leave.\nexport function failureReport(reason: string, partialReport: string | null): string {\n\tconst partial = partialReport\n\t\t? `\\n---\\n\\nPartial ${REPORT_FILE} left by the agent:\\n\\n${partialReport}`\n\t\t: \"\"\n\treturn `# CHECK FAILED\\n\\n${reason}\\n${partial}`\n}\n\nasync function runOneCheck(\n\tcheck: Check,\n\topts: CheckWorkflowOpts,\n\ttoken: string,\n\toutDir: string,\n): Promise<boolean> {\n\tconst workdir = mkdtempSync(join(tmpdir(), `doublecheck-${check.name}-`))\n\twriteFileSync(join(workdir, PROMPT_FILE), composePrompt(check.body, opts.project))\n\tconst spec = claudeAgent({ token, model: opts.model, workdir })\n\tconst outcome = await runAgent({\n\t\tmount: opts.project,\n\t\tworkdir,\n\t\tspec,\n\t\tnetwork: \"all\",\n\t\tonLine: progressSink(check.name),\n\t})\n\tconst reportPath = join(outDir, `${check.name}.md`)\n\tif (outcome.ok) {\n\t\twriteFileSync(reportPath, outcome.report)\n\t\tprocess.stderr.write(`[${check.name}] report: ${reportPath}\\n`)\n\t\treturn true\n\t}\n\twriteFileSync(reportPath, failureReport(outcome.reason, outcome.partialReport))\n\tprocess.stderr.write(`[${check.name}] FAILED (${outcome.reason}): ${reportPath}\\n`)\n\treturn false\n}\n\n// The check workflow: one sandboxed agent per check, at most `parallel`\n// guests at once. Returns true only when every check produced a report; agent\n// failures still write a failure-record report and flip the run to false.\nexport async function runChecks(opts: CheckWorkflowOpts): Promise<boolean> {\n\tconst token = process.env.CLAUDE_CODE_OAUTH_TOKEN\n\tif (!token) {\n\t\tthrow new Error(\n\t\t\t\"CLAUDE_CODE_OAUTH_TOKEN is required in the environment (it is injected into each check's sandbox)\",\n\t\t)\n\t}\n\tconst checks = discoverChecks(opts.project, opts.only)\n\tconst outDir = join(opts.output, runTimestamp(new Date()))\n\tmkdirSync(outDir, { recursive: true })\n\tprocess.stderr.write(\n\t\t`${checks.length} check(s) against ${opts.project} (model ${opts.model}, parallel ${opts.parallel})\\n`,\n\t)\n\tconst queue = new PQueue({ concurrency: opts.parallel })\n\tconst results = await Promise.all(\n\t\tchecks.map((check) => queue.add(() => runOneCheck(check, opts, token, outDir))),\n\t)\n\treturn results.every((ok) => ok === true)\n}\n","// Claude Code transcript (.jsonl) → the genuine human turns → a flat digest.\n// Port of the June-2026 jq extraction, verified against the same corpus: a\n// \"genuine human turn\" is type:user, not meta, not sidechain, text content\n// only — which excludes the three things that are also type:user in the JSONL\n// (tool_results, slash-command stdout wrappers, injected system-reminders).\n\n// Per-turn char cap in the digest; the mining agent greps the source jsonl\n// for full text when it needs context around a turn.\nconst TURN_CHAR_CAP = 2000\n\ninterface RawLine {\n\ttype?: string\n\tisMeta?: boolean\n\tisSidechain?: boolean\n\tmessage?: { content?: unknown }\n}\n\nconst NON_HUMAN_TEXT =\n\t/^\\s*<command-name>|<local-command-stdout>|^\\s*<local-command|^\\s*<system-reminder>|Caveat: The messages below/\n\n// Throws on an unparseable line — the caller decides what an unreadable\n// transcript means for its run (mine counts and reports them, visibly).\nexport function humanTurns(jsonl: string): string[] {\n\tconst turns: string[] = []\n\tfor (const line of jsonl.split(\"\\n\")) {\n\t\tif (!line.trim()) continue\n\t\tconst raw = JSON.parse(line) as RawLine\n\t\tif (raw.type !== \"user\" || raw.isMeta || raw.isSidechain) continue\n\t\tconst content = raw.message?.content\n\t\tconst text =\n\t\t\ttypeof content === \"string\"\n\t\t\t\t? content\n\t\t\t\t: Array.isArray(content)\n\t\t\t\t\t? content\n\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t(item): item is { type: \"text\"; text: string } =>\n\t\t\t\t\t\t\t\t\ttypeof item === \"object\" &&\n\t\t\t\t\t\t\t\t\titem !== null &&\n\t\t\t\t\t\t\t\t\t(item as { type?: string }).type === \"text\" &&\n\t\t\t\t\t\t\t\t\ttypeof (item as { text?: unknown }).text === \"string\",\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.map((item) => item.text)\n\t\t\t\t\t\t\t.join(\"\\n\")\n\t\t\t\t\t: \"\"\n\t\tif (!text) continue\n\t\tif (NON_HUMAN_TEXT.test(text)) continue\n\t\tturns.push(text.replace(/[\\n\\r]+/g, \" ⏎ \").slice(0, TURN_CHAR_CAP))\n\t}\n\treturn turns\n}\n\nexport interface DigestMeta {\n\tsource: string\n\tproject: string\n\tsession: string\n}\n\nexport function renderDigest(meta: DigestMeta, turns: string[]): string {\n\tconst numbered = turns\n\t\t.map((t, i) => `${String(i + 1).padStart(3, \" \")} | ${t}`)\n\t\t.join(\"\\n\")\n\treturn `# source: ${meta.source}\n# project: ${meta.project}\n# session: ${meta.session}\n# human_turns: ${turns.length}\n# To understand WHY a terse turn or interruption happened, grep its text in the\n# source file above and read the assistant turn(s) immediately before it.\n\n${numbered}\n`\n}\n","import { createHash } from \"node:crypto\"\nimport { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\"\nimport { basename, join } from \"node:path\"\nimport { humanTurns, renderDigest } from \"./transcript.ts\"\n\n// One minable unit = one top-level transcript $PROJECTS/<project>/<session>.jsonl.\n// Its catalog home mirrors that path: $CATALOG/<project>/<session>/observations.md.\nexport interface Unit {\n\tproject: string\n\tsession: string\n\tjsonlPath: string\n}\n\nexport function enumerateUnits(projectsDir: string): Unit[] {\n\tlet projects: string[]\n\ttry {\n\t\tprojects = readdirSync(projectsDir).sort()\n\t} catch {\n\t\tthrow new Error(`no transcripts directory at ${projectsDir}`)\n\t}\n\tconst units: Unit[] = []\n\tfor (const project of projects) {\n\t\tconst dir = join(projectsDir, project)\n\t\tif (!statSync(dir).isDirectory()) continue\n\t\tfor (const f of readdirSync(dir).sort()) {\n\t\t\tif (!f.endsWith(\".jsonl\")) continue\n\t\t\tunits.push({\n\t\t\t\tproject,\n\t\t\t\tsession: basename(f, \".jsonl\"),\n\t\t\t\tjsonlPath: join(dir, f),\n\t\t\t})\n\t\t}\n\t}\n\treturn units\n}\n\nexport function observationsPath(catalogDir: string, unit: Unit): string {\n\treturn join(catalogDir, unit.project, unit.session, \"observations.md\")\n}\n\nexport type UnitStatus =\n\t// hash matches the recorded source_sha256 — skipped without parsing\n\t| { kind: \"mined\" }\n\t| { kind: \"below-threshold\"; turns: number }\n\t| {\n\t\t\tkind: \"pending\"\n\t\t\treason: \"new\" | \"changed\"\n\t\t\tturns: number\n\t\t\tdigest: string\n\t\t\tsourceSha256: string\n\t }\n\t// transcript has an unparseable line; reported visibly, never mined\n\t| { kind: \"unreadable\"; error: string }\n\n// Pure decision core: everything already read, nothing left but judgment.\nexport function decideUnitStatus(input: {\n\tunit: Unit\n\tjsonl: Buffer\n\trecordedSha256: string | null\n\tminTurns: number\n}): UnitStatus {\n\tconst sourceSha256 = createHash(\"sha256\").update(input.jsonl).digest(\"hex\")\n\tif (input.recordedSha256 === sourceSha256) return { kind: \"mined\" }\n\tlet turns: string[]\n\ttry {\n\t\tturns = humanTurns(input.jsonl.toString(\"utf-8\"))\n\t} catch (e) {\n\t\treturn { kind: \"unreadable\", error: String(e) }\n\t}\n\tif (turns.length < input.minTurns)\n\t\treturn { kind: \"below-threshold\", turns: turns.length }\n\treturn {\n\t\tkind: \"pending\",\n\t\treason: input.recordedSha256 === null ? \"new\" : \"changed\",\n\t\tturns: turns.length,\n\t\tdigest: renderDigest(\n\t\t\t{\n\t\t\t\tsource: input.unit.jsonlPath,\n\t\t\t\tproject: input.unit.project,\n\t\t\t\tsession: input.unit.session,\n\t\t\t},\n\t\t\tturns,\n\t\t),\n\t\tsourceSha256,\n\t}\n}\n\n// Shell: read the unit's inputs, then decide purely.\nexport function unitStatus(unit: Unit, catalogDir: string, minTurns: number): UnitStatus {\n\tconst obsPath = observationsPath(catalogDir, unit)\n\treturn decideUnitStatus({\n\t\tunit,\n\t\tjsonl: readFileSync(unit.jsonlPath),\n\t\trecordedSha256: existsSync(obsPath)\n\t\t\t? readSourceSha256(readFileSync(obsPath, \"utf-8\"))\n\t\t\t: null,\n\t\tminTurns,\n\t})\n}\n\nexport interface ObservationsMeta {\n\tsource: string\n\tsourceSha256: string\n\tminedAt: string\n\tmodel: string\n\thumanTurns: number\n}\n\n// The host composes the final file: frontmatter it alone can vouch for, then\n// the agent's report verbatim.\nexport function composeObservationsFile(meta: ObservationsMeta, body: string): string {\n\treturn `---\nsource: ${meta.source}\nsource_sha256: ${meta.sourceSha256}\nmined_at: ${meta.minedAt}\nmodel: ${meta.model}\nhuman_turns: ${meta.humanTurns}\n---\n\n${body.trimEnd()}\n`\n}\n\nexport function readSourceSha256(observationsMd: string): string | null {\n\treturn observationsMd.match(/^source_sha256: ([0-9a-f]{64})$/m)?.[1] ?? null\n}\n","import { mkdirSync, mkdtempSync, writeFileSync } from \"node:fs\"\nimport { tmpdir } from \"node:os\"\nimport { dirname, join } from \"node:path\"\nimport PQueue from \"p-queue\"\nimport {\n\tcomposeObservationsFile,\n\tenumerateUnits,\n\tobservationsPath,\n\ttype Unit,\n\ttype UnitStatus,\n\tunitStatus,\n} from \"./catalog.ts\"\nimport { claudeAgent, progressSink } from \"./claude.ts\"\nimport { composeMinePrompt, PROMPT_FILE } from \"./contract.ts\"\nimport { runAgent } from \"./runner.ts\"\n\nexport interface MineOpts {\n\tprojects: string\n\tcatalog: string\n\tmodel: string\n\tparallel: number\n\tminTurns: number\n\tlimit?: number\n\tdryRun: boolean\n}\n\nexport interface Pending {\n\tunit: Unit\n\tstatus: Extract<UnitStatus, { kind: \"pending\" }>\n}\n\n// What one mine invocation will and won't do, decided purely from the\n// per-unit statuses.\nexport interface MinePlan {\n\ttodo: Pending[]\n\tpendingTotal: number\n\tmined: number\n\tbelowThreshold: number\n\tunreadable: { unit: Unit; error: string }[]\n}\n\nexport function planMine(\n\tentries: { unit: Unit; status: UnitStatus }[],\n\tlimit?: number,\n): MinePlan {\n\tconst pending = entries.filter((e): e is Pending => e.status.kind === \"pending\")\n\treturn {\n\t\ttodo: limit ? pending.slice(0, limit) : pending,\n\t\tpendingTotal: pending.length,\n\t\tmined: entries.filter((e) => e.status.kind === \"mined\").length,\n\t\tbelowThreshold: entries.filter((e) => e.status.kind === \"below-threshold\").length,\n\t\tunreadable: entries.flatMap((e) =>\n\t\t\te.status.kind === \"unreadable\"\n\t\t\t\t? [{ unit: e.unit, error: e.status.error }]\n\t\t\t\t: [],\n\t\t),\n\t}\n}\n\nexport function summarizeMinePlan(plan: MinePlan, minTurns: number): string {\n\tconst total =\n\t\tplan.pendingTotal + plan.mined + plan.belowThreshold + plan.unreadable.length\n\tconst limited =\n\t\tplan.todo.length !== plan.pendingTotal ? ` (mining ${plan.todo.length})` : \"\"\n\treturn `${total} transcripts: ${plan.pendingTotal} pending${limited}, ${plan.mined} mined, ${plan.belowThreshold} below ${minTurns} turns, ${plan.unreadable.length} unreadable`\n}\n\nexport function dryRunRow({ unit, status }: Pending): string {\n\treturn `${status.reason.padEnd(7)} ${status.turns.toString().padStart(4)} turns ${unit.project}/${unit.session}`\n}\n\nasync function mineOneUnit(\n\t{ unit, status }: Pending,\n\topts: MineOpts,\n\ttoken: string,\n): Promise<boolean> {\n\tconst tag = unit.session.slice(0, 8)\n\tconst workdir = mkdtempSync(join(tmpdir(), `doublecheck-mine-${tag}-`))\n\twriteFileSync(join(workdir, PROMPT_FILE), composeMinePrompt(status.digest))\n\tconst spec = claudeAgent({ token, model: opts.model, workdir })\n\tprocess.stderr.write(\n\t\t`[${tag}] mining ${unit.project}/${unit.session} (${status.turns} turns, ${status.reason})\\n`,\n\t)\n\tconst outcome = await runAgent({\n\t\tmount: opts.projects,\n\t\tworkdir,\n\t\tspec,\n\t\tnetwork: \"anthropic-only\",\n\t\tonLine: progressSink(tag),\n\t})\n\t// A failed mine writes NOTHING — the catalog is a durable asset; the next\n\t// run retries this unit because no hash gets recorded.\n\tif (!outcome.ok) {\n\t\tprocess.stderr.write(`[${tag}] FAILED (${outcome.reason})\\n`)\n\t\treturn false\n\t}\n\tconst obsPath = observationsPath(opts.catalog, unit)\n\tmkdirSync(dirname(obsPath), { recursive: true })\n\twriteFileSync(\n\t\tobsPath,\n\t\tcomposeObservationsFile(\n\t\t\t{\n\t\t\t\tsource: unit.jsonlPath,\n\t\t\t\tsourceSha256: status.sourceSha256,\n\t\t\t\tminedAt: new Date().toISOString(),\n\t\t\t\tmodel: opts.model,\n\t\t\t\thumanTurns: status.turns,\n\t\t\t},\n\t\t\toutcome.report,\n\t\t),\n\t)\n\tprocess.stderr.write(`[${tag}] observations: ${obsPath}\\n`)\n\treturn true\n}\n\n// The mine workflow shell: gather statuses (I/O), plan purely, then either\n// print the plan (dry-run) or run one sandboxed agent per pending unit.\n// Returns true when nothing it attempted failed.\nexport async function runMine(opts: MineOpts): Promise<boolean> {\n\tconst entries = enumerateUnits(opts.projects).map((unit) => ({\n\t\tunit,\n\t\tstatus: unitStatus(unit, opts.catalog, opts.minTurns),\n\t}))\n\tconst plan = planMine(entries, opts.limit)\n\tfor (const { unit, error } of plan.unreadable) {\n\t\tprocess.stderr.write(`UNREADABLE ${unit.project}/${unit.session}: ${error}\\n`)\n\t}\n\tprocess.stderr.write(`${summarizeMinePlan(plan, opts.minTurns)}\\n`)\n\n\tif (opts.dryRun) {\n\t\tfor (const pending of plan.todo) console.log(dryRunRow(pending))\n\t\treturn true\n\t}\n\tif (plan.todo.length === 0) return true\n\n\tconst token = process.env.CLAUDE_CODE_OAUTH_TOKEN\n\tif (!token) {\n\t\tthrow new Error(\n\t\t\t\"CLAUDE_CODE_OAUTH_TOKEN is required in the environment (it is injected into each miner's sandbox)\",\n\t\t)\n\t}\n\tconst queue = new PQueue({ concurrency: opts.parallel })\n\tconst results = await Promise.all(\n\t\tplan.todo.map((p) => queue.add(() => mineOneUnit(p, opts, token))),\n\t)\n\tconst failed = results.filter((ok) => ok !== true).length\n\tprocess.stderr.write(\n\t\t`mined ${results.length - failed}/${results.length}${failed ? `, ${failed} FAILED` : \"\"}\\n`,\n\t)\n\treturn failed === 0\n}\n","#!/usr/bin/env node\nimport { homedir } from \"node:os\"\nimport { join, resolve } from \"node:path\"\nimport { Command } from \"commander\"\nimport { runChecks } from \"./check.ts\"\nimport { runMine } from \"./mine.ts\"\n\nfunction parsePositiveInt(flag: string) {\n\treturn (v: string): number => {\n\t\tconst n = Number.parseInt(v, 10)\n\t\tif (!Number.isInteger(n) || n < 1)\n\t\t\tthrow new Error(`${flag} must be a positive integer, got \"${v}\"`)\n\t\treturn n\n\t}\n}\n\nconst program = new Command()\n\t.name(\"doublecheck\")\n\t.description(\n\t\t\"Run self-authored LLM code-inspectors (.agents/checks/*.md) against a project, one sandboxed agent per check\",\n\t)\n\nprogram\n\t.command(\"check\")\n\t.option(\"--project <dir>\", \"project to inspect\", process.cwd())\n\t.option(\"--model <model>\", \"model for the inspector agents\", \"haiku\")\n\t.option(\"--parallel <n>\", \"max concurrent checks\", parsePositiveInt(\"--parallel\"), 4)\n\t.option(\"--output <dir>\", \"reports root (default: $PROJECT/.doublecheck)\")\n\t.option(\n\t\t\"--check <name>\",\n\t\t\"run only this check (repeatable)\",\n\t\t(v: string, prev: string[]) => [...prev, v],\n\t\t[] as string[],\n\t)\n\t.action(async (opts) => {\n\t\tconst project = resolve(opts.project)\n\t\tconst ok = await runChecks({\n\t\t\tproject,\n\t\t\tmodel: opts.model,\n\t\t\tparallel: opts.parallel,\n\t\t\toutput: opts.output ? resolve(opts.output) : join(project, \".doublecheck\"),\n\t\t\tonly: opts.check,\n\t\t})\n\t\tif (!ok) process.exitCode = 1\n\t})\n\nprogram\n\t.command(\"mine\")\n\t.option(\n\t\t\"--projects <dir>\",\n\t\t\"Claude Code transcripts root\",\n\t\tjoin(homedir(), \".claude\", \"projects\"),\n\t)\n\t.option(\n\t\t\"--catalog <dir>\",\n\t\t\"observation catalog root\",\n\t\tjoin(homedir(), \".doublecheck\", \"catalog\"),\n\t)\n\t.option(\"--model <model>\", \"model for the mining agents\", \"opus\")\n\t.option(\"--parallel <n>\", \"max concurrent miners\", parsePositiveInt(\"--parallel\"), 4)\n\t.option(\n\t\t\"--min-turns <n>\",\n\t\t\"min genuine human turns for a real conversation\",\n\t\tparsePositiveInt(\"--min-turns\"),\n\t\t2,\n\t)\n\t.option(\"--limit <n>\", \"mine at most N pending units\", parsePositiveInt(\"--limit\"))\n\t.option(\"--dry-run\", \"list what would be mined without booting anything\")\n\t.action(async (opts) => {\n\t\tconst ok = await runMine({\n\t\t\tprojects: resolve(opts.projects),\n\t\t\tcatalog: resolve(opts.catalog),\n\t\t\tmodel: opts.model,\n\t\t\tparallel: opts.parallel,\n\t\t\tminTurns: opts.minTurns,\n\t\t\tlimit: opts.limit,\n\t\t\tdryRun: !!opts.dryRun,\n\t\t})\n\t\tif (!ok) process.exitCode = 1\n\t})\n\nprogram.parseAsync().catch((e: unknown) => {\n\tconsole.error(e instanceof Error ? e.message : String(e))\n\tprocess.exit(1)\n})\n"],"mappings":";;;;;;;;;AAKA,MAAa,cAAc;AAG3B,MAAa,cAAc;AAK3B,SAAS,eAAe,UAAkB,aAA6B;CACtE,OAAO;;+EAEuE,YAAY;;iBAE1E,YAAY,0CAA0C,SAAS,uGAAuG,YAAY;AACnM;AAIA,SAAgB,cAAc,WAAmB,SAAyB;CACzE,OAAO;;;;2DAImD,QAAQ;;;;;;EAMjE,UAAU;;;;EAIV,eAAe,cAAc,oBAAoB;AACnD;AAIA,SAAgB,kBAAkB,QAAwB;CACzD,OAAO;;;;;;;;;;;;EAYN,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCP,eAAe,UAAU,wBAAwB;AACnD;;;;ACxFA,MAAM,aAAa;AAGnB,SAAgB,YAAY,MAId;CACb,OAAO;EAKN,SACC,4KAUoE;EACrE,KAAK;GACJ,MAAM;GACN,YAAY;GACZ,oBAAoB;GACpB,iBAAiB,KAAK;GACtB,yBAAyB,KAAK;EAC/B;EAGA,OAAO,CACN;GACC,MAAM,GAAG,WAAW;GACpB,SAAS,GAAG,KAAK,UAChB,EAAE,UAAU,GAAG,KAAK,UAAU,EAAE,wBAAwB,KAAK,EAAE,EAAE,GACjE,MACA,GACD,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
+
{"version":3,"file":"cli.mjs","names":["GUEST_HOME"],"sources":["../src/contract.ts","../src/claude.ts","../src/codex.ts","../src/agent-cli.ts","../src/runner.ts","../src/check.ts","../src/transcript.ts","../src/catalog.ts","../src/mine.ts","../src/cli.ts"],"sourcesContent":["// The agent contract: what the harness stages for the agent and what the\n// agent must leave behind. Any adapter (claude, codex) runs under this same\n// contract, which is what keeps the harness CLI-agnostic. The one per-agent\n// piece is `writeTool`: the phrase naming how THIS agent creates a file\n// (claude has a literal Write tool; codex is just told to create the file —\n// naming a tool it doesn't have would invite it to distrust its brief).\n\n// Staged into the scratch workdir before boot; the rw bind mount delivers it.\nexport const PROMPT_FILE = \"prompt.txt\"\n// The agent writes its findings here (relative to its cwd); the host reads it\n// back after exit. Missing report = failure.\nexport const REPORT_FILE = \"report.md\"\n\n// Weak models reliably skip a report contract stated once at the prompt's\n// tail unless it leads with the stakes and orders the file created first\n// (measured: haiku went from ~50% to 3/3 with this wording). Two hard-won\n// additions (2026-07-05, all three cutover inspectors lost their reports):\n// the path is ABSOLUTE — agents cd into the inspected tree to run git, and a\n// relative ./report.md then lands in the read-only mount — and the\n// create-first order is repeated near the top of the prompt (see\n// firstActionLine), because on long prompts the tail alone loses its grip.\nfunction reportContract(\n\tactivity: string,\n\tdeliverable: string,\n\tworkdir: string,\n\twriteTool: string | null,\n): string {\n\tconst tool = writeTool ? ` ${writeTool}` : \"\"\n\treturn `## Report — the only output that counts\n\nYour final chat reply is discarded. The only thing read back is the file \\`${workdir}/${REPORT_FILE}\\` — if it does not exist when you exit, this run FAILS. Always use that absolute path: if you \\`cd\\` elsewhere (into the inspected tree, say), a relative \\`./${REPORT_FILE}\\` lands in the wrong place, or in a read-only mount where the write fails.\n\nSo: create \\`${workdir}/${REPORT_FILE}\\`${tool} BEFORE you start ${activity} (a title line is enough), and update it as you work. The final state of the file when you finish is ${deliverable}.`\n}\n\nfunction firstActionLine(workdir: string, writeTool: string | null): string {\n\tconst tool = writeTool ? ` ${writeTool}` : \"\"\n\treturn `Your FIRST action, before anything else: create \\`${workdir}/${REPORT_FILE}\\`${tool} (a title line is enough). The full report contract is at the end of this prompt.`\n}\n\n// Environment preamble + optional run context + check body + report\n// contract. Checks are timeless standards; everything run-specific (intent,\n// sanctioned exceptions, scope) arrives in the operator's run context — the\n// harness knows nothing about git.\nexport function composePrompt(opts: {\n\tcheckBody: string\n\ttarget: string\n\tworkdir: string\n\trunContext: string | null\n\twriteTool: string | null\n}): string {\n\tconst contextSection = opts.runContext\n\t\t? `## Run context (from the operator)\n\nThe operator's brief for this run: the intent behind the work under review, known nuances, sanctioned exceptions, and possibly a Scope naming exactly what is under review. Judge requestedness against it — what the brief explicitly sanctions is not a finding. If it names a Scope, the Scope defines the change under review: findings must concern that change, and the rest of the tree is reference for judgment — with one exception. For concepts the scoped change retires or renames, surviving references anywhere in the tree are reportable findings: the Scope bounds what counts as the change, not where survivors may hide.\n\n${opts.runContext}\n\n---\n\n`\n\t\t: \"\"\n\treturn `## Environment\n\nYou are a code inspector running inside a sandboxed microVM with full permissions and unrestricted internet access.\n\n- The code under inspection is mounted read-only at \\`${opts.target}\\`. You cannot modify it — inspect, don't fix.\n- \\`git\\` and \\`rg\\` are installed.\n- Your current working directory is a writable scratch workspace: \\`${opts.workdir}\\`.\n\n${firstActionLine(opts.workdir, opts.writeTool)}\n\n## Inspection discipline\n\nMeasured on real runs: inspectors that skip these rules produce reports whose verdicts are right but whose evidence is partly fabricated — which is worse than no report.\n\n- Before inspecting, enumerate what is under review (the Run context's Scope list if one is given; otherwise your own enumeration of the target) and keep a ledger as you work: **examined** (content actually opened), **name-only**, **not examined**. End your report with that ledger, with a one-line reason for anything not examined.\n- Use verification verbs — \"verified\", \"confirmed\", \"checked\", \"read\", \"diffed\", \"grepped\", \"spot-checked\" — ONLY for actions you actually performed in this session on content you actually opened. Everything else must be labeled as inference: \"assumed identical by generation — not opened.\"\n- Never truncate output you will base a claim on — no \\`| head\\` / \\`| tail\\` on a diff or search you intend to cite. Examine files one at a time instead.\n\n---\n\n${contextSection}${opts.checkBody}\n\n---\n\n${reportContract(\"inspecting\", \"the check's report\", opts.workdir, opts.writeTool)}\n\nEvery single line of your report will be read in full by the operator's agent — nothing is skimmed, so every line costs attention. Verify each finding against the actual code before writing it down. A report that says \"no findings\" is a perfectly good report; an unverified finding is not.`\n}\n\n// The mining prompt: digest of one conversation + what counts as a durable\n// preference observation + the block format the catalog accumulates.\nexport function composeMinePrompt(\n\tdigest: string,\n\tworkdir: string,\n\twriteTool: string | null,\n): string {\n\treturn `## Environment\n\nYou are running inside a sandboxed microVM with no network access. The machine's Claude Code transcripts are mounted read-only at their real paths; your current working directory is a writable scratch workspace: \\`${workdir}\\`.\n\n${firstActionLine(workdir, writeTool)}\n\n## Task\n\nYou are mining ONE Claude Code conversation for the operator's durable preferences — how they want engineering done, in any conversation, not what they wanted built in this one.\n\nBelow is the conversation digest: every genuine human turn, numbered, in order. When a turn is a terse correction or interruption (\"no\", \"stop\", \"don't\", \"why did you…\", \"[Request interrupted]\"), recover its context: the \"# source:\" header names the full session transcript — Grep that turn's text in it to find its line, then Read the assistant turns IMMEDIATELY BEFORE it with offset/limit. The preference lives in the contrast between what the assistant did and what the operator demanded. NEVER read a transcript whole — some are tens of MB.\n\n---\n\n${digest}\n\n---\n\n## What counts as an observation (strict)\n\nA durable preference, backed by a verbatim quote from the digest or transcript:\n\n- **kind: code** — how code should be written/structured/shaped (\"no silent fallbacks\", \"reuse the existing helper instead of hand-rolling\").\n- **kind: workflow** — how work should proceed (\"verify before claiming done\", \"ask before making scope decisions\").\n- **kind: style** — how prose/output/docs should read.\n\nExclude task-of-the-moment directives with no durable signal (\"add a tab to home.tsx\", \"kill the dev server\"). Exclude anything you cannot quote. Be conservative: a weak or speculative observation is worse than none.\n\n## Observation format\n\nThe report is observation blocks and NOTHING else — no title, no preamble, no summary or conclusion sections. One block per observation:\n\n## <kebab-case-name>\n- **observation:** <one sentence: the durable preference>\n- **kind:** code | workflow | style\n- **evidence:** \"<verbatim quote>\" — turn <N>\n\nFor **code** observations that an LLM reviewer could check against a diff or file tree (a concrete change could flip PASS↔FAIL), and ONLY for those — never on workflow or style blocks — ALSO add:\n\n- **pass/fail:** PASS when <…>; FAIL when <…>\n- **why-LLM:** <why a deterministic linter cannot enforce this>\n- **scope:** diff-only | needs-tree\n\nIf the conversation carries no durable preference signal, the report is exactly these two lines and nothing more:\n\nNo durable preference signal.\n<one sentence: what the conversation was about instead>\n\n${reportContract(\"mining\", \"the mined observations\", workdir, writeTool)}`\n}\n","import { PROMPT_FILE } from \"./contract.ts\"\nimport type { AgentSpec } from \"./runner.ts\"\n\nconst GUEST_HOME = \"/root\"\n\n// The claude adapter: produce the AgentSpec that runs `claude -p` in the guest.\nexport function claudeAgent(opts: {\n\ttoken: string\n\tmodel: string\n\tworkdir: string\n}): AgentSpec {\n\treturn {\n\t\t// Headless claude -p cannot answer permission prompts, so in \"default\"\n\t\t// mode every tool is auto-denied and the agent produces nothing. The\n\t\t// microVM is the safety boundary here, so bypass the per-tool gate;\n\t\t// IS_SANDBOX=1 is what lets that run as root without claude's refusal.\n\t\tcommand:\n\t\t\t\"claude -p --no-session-persistence \" +\n\t\t\t\"--dangerously-skip-permissions \" +\n\t\t\t// --verbose is required by claude -p with stream-json output; it only\n\t\t\t// widens what lands on stdout, which describeStreamLine already labels.\n\t\t\t\"--output-format stream-json --verbose \" +\n\t\t\t// Not a permission gate — a contract guard. The default headless tool\n\t\t\t// set omits Glob/Grep and includes harness tools (ReportFindings,\n\t\t\t// TaskCreate, …) that hijack the report: haiku \"reports findings\"\n\t\t\t// through them and never writes report.md (verified live). This pins\n\t\t\t// the inspector's full toolkit and nothing else.\n\t\t\t`--tools Task Bash Read Write Edit Glob Grep WebSearch WebFetch < ${PROMPT_FILE}`,\n\t\tenv: {\n\t\t\tHOME: GUEST_HOME,\n\t\t\tIS_SANDBOX: \"1\",\n\t\t\tGIT_OPTIONAL_LOCKS: \"0\",\n\t\t\tANTHROPIC_MODEL: opts.model,\n\t\t\tCLAUDE_CODE_OAUTH_TOKEN: opts.token,\n\t\t},\n\t\t// Minimal trust-accepted entry keyed to the guest cwd so headless claude\n\t\t// skips the trust prompt. Deliberately NOT a copy of any host .claude.json.\n\t\tfiles: [\n\t\t\t{\n\t\t\t\tpath: `${GUEST_HOME}/.claude.json`,\n\t\t\t\tcontent: `${JSON.stringify(\n\t\t\t\t\t{ projects: { [opts.workdir]: { hasTrustDialogAccepted: true } } },\n\t\t\t\t\tnull,\n\t\t\t\t\t\"\\t\",\n\t\t\t\t)}\\n`,\n\t\t\t},\n\t\t],\n\t}\n}\n\ninterface StreamLine {\n\ttype?: string\n\tsubtype?: string\n\tmessage?: { content?: Array<{ type?: string; text?: string; name?: string }> }\n\tduration_ms?: number\n}\n\n// One human-readable label per stream-json stdout line; null for lines that\n// aren't claude's JSON (dropped from the progress stream).\nexport function describeClaudeStreamLine(line: string): string | null {\n\tlet obj: StreamLine\n\ttry {\n\t\tobj = JSON.parse(line) as StreamLine\n\t} catch {\n\t\treturn null\n\t}\n\tconst label = (obj.type ?? \"\") + (obj.subtype ? `:${obj.subtype}` : \"\")\n\t// A once-per-second heartbeat with no content — pure noise in the stream.\n\tif (label === \"system:thinking_tokens\") return null\n\tlet detail = \"\"\n\tif (obj.type === \"assistant\") {\n\t\tconst content = obj.message?.content ?? []\n\t\tconst tools = content\n\t\t\t.filter((b) => b.type === \"tool_use\" && b.name)\n\t\t\t.map((b) => b.name)\n\t\tconst chars = content.reduce((n, b) => n + (b.text?.length ?? 0), 0)\n\t\tdetail = tools.length ? ` ${tools.join(\",\")}` : ` ${chars} chars`\n\t} else if (obj.type === \"result\") {\n\t\tdetail = ` ${obj.subtype}, ${((obj.duration_ms ?? 0) / 1000).toFixed(1)}s`\n\t}\n\treturn `[${label}]${detail}`\n}\n","import { PROMPT_FILE } from \"./contract.ts\"\nimport type { AgentSpec } from \"./runner.ts\"\n\nconst GUEST_HOME = \"/root\"\n\n// Guest-only codex config — deliberately NOT a copy of any host config.toml\n// (which carries MCP API keys, personality, plugins, a trust table). Each key\n// is load-bearing:\n// - model rides here rather than as a `-m` flag so nothing operator-supplied\n// is ever interpolated into the guest's bash command string.\n// - approval_policy/sandbox_mode double the bypass flag on the command line;\n// either alone is a documented trust-prompt suppressor, some builds leak\n// with only one (openai/codex#14547).\n// - model_reasoning_effort: operator decision — plan billing is flat-rate,\n// so there is no haiku-style cost gradient to encode in a cheaper setting.\n// - web_search is a server-side tool (the guest never fetches pages itself);\n// \"live\" pins it rather than relying on the full-access auto-upgrade.\n// - project_doc_max_bytes = 0 disables all AGENTS.md loading: the piped\n// prompt is the agent's only input.\n// - features.plugins/apps = false stop codex's boot-time marketplace clone\n// and apps fetch (verified live): under restricted egress they hang, and\n// under any egress they inject tools (e.g. a git-push skill) the contract\n// never sanctioned.\nfunction guestConfig(model: string): string {\n\treturn `model = \"${model}\"\napproval_policy = \"never\"\nsandbox_mode = \"danger-full-access\"\nmodel_reasoning_effort = \"xhigh\"\nweb_search = \"live\"\nproject_doc_max_bytes = 0\ncli_auth_credentials_store = \"file\"\n\n[features]\nplugins = false\napps = false\n`\n}\n\n// The codex adapter: produce the AgentSpec that runs `codex exec` in the guest.\nexport function codexAgent(opts: {\n\t// Byte-for-byte content of the operator's ~/.codex/auth.json; staleness is\n\t// the caller's preflight (a guest-side token refresh would rotate the\n\t// single-use refresh token and poison the host session).\n\tauthJson: string\n\tmodel: string\n\tworkdir: string\n}): AgentSpec {\n\treturn {\n\t\t// Headless codex cannot answer approval prompts, and its own bwrap\n\t\t// sandbox needs user namespaces the guest may not grant — the microVM is\n\t\t// the safety boundary, so bypass both (OpenAI's documented container\n\t\t// guidance). --ephemeral writes no session rollout files;\n\t\t// --skip-git-repo-check because the scratch cwd is not a git repo.\n\t\tcommand:\n\t\t\t\"codex exec --json --skip-git-repo-check \" +\n\t\t\t\"--dangerously-bypass-approvals-and-sandbox --ephemeral \" +\n\t\t\t`- < ${PROMPT_FILE}`,\n\t\tenv: {\n\t\t\t// CODEX_HOME defaults to $HOME/.codex, where both staged files land.\n\t\t\tHOME: GUEST_HOME,\n\t\t\tGIT_OPTIONAL_LOCKS: \"0\",\n\t\t},\n\t\tfiles: [\n\t\t\t{ path: `${GUEST_HOME}/.codex/auth.json`, content: opts.authJson },\n\t\t\t{\n\t\t\t\tpath: `${GUEST_HOME}/.codex/config.toml`,\n\t\t\t\tcontent: guestConfig(opts.model),\n\t\t\t},\n\t\t],\n\t}\n}\n\n// The freshness window for a staged ChatGPT-auth auth.json. Codex refreshes\n// tokens when last_refresh is ~8 days old (or on a 401), refresh tokens are\n// single-use, and a refresh performed INSIDE a guest rotates the token family\n// — the host's copy then dies with \"refresh token was already used\" (forced\n// re-login). 7 days leaves a day of margin below codex's own threshold.\nexport const CODEX_AUTH_MAX_AGE_DAYS = 7\n\ninterface CodexAuth {\n\ttokens?: { refresh_token?: string }\n\tlast_refresh?: string\n\tOPENAI_API_KEY?: string\n}\n\n// Pure preflight: throw (with the operator's next action) unless this\n// auth.json is safe to stage into guests. An api-key-mode auth.json (no\n// tokens, an OPENAI_API_KEY field) carries no refresh semantics, so no\n// staleness guard applies.\nexport function validateCodexAuth(content: string, now: Date, where: string): void {\n\tlet auth: CodexAuth\n\ttry {\n\t\tauth = JSON.parse(content) as CodexAuth\n\t} catch {\n\t\tthrow new Error(`${where} is not valid JSON — run \\`codex login\\` on the host`)\n\t}\n\tif (auth.tokens?.refresh_token) {\n\t\tconst ageDays = (now.getTime() - Date.parse(auth.last_refresh ?? \"\")) / 86_400_000\n\t\tif (!(ageDays <= CODEX_AUTH_MAX_AGE_DAYS)) {\n\t\t\tthrow new Error(\n\t\t\t\t`${where} tokens were last refreshed over ${CODEX_AUTH_MAX_AGE_DAYS} days ago (codex refreshes at ~8 days, and a refresh inside a guest would rotate the single-use refresh token and poison this host's session) — run any codex command on the host to refresh, then retry`,\n\t\t\t)\n\t\t}\n\t\treturn\n\t}\n\tif (auth.OPENAI_API_KEY) return\n\tthrow new Error(\n\t\t`${where} has neither ChatGPT tokens nor an API key — run \\`codex login\\` on the host`,\n\t)\n}\n\ninterface CodexStreamLine {\n\ttype?: string\n\titem?: {\n\t\ttype?: string\n\t\ttext?: string\n\t\tcommand?: string\n\t\tchanges?: Array<{ path?: string }>\n\t}\n\tusage?: { input_tokens?: number; output_tokens?: number }\n\terror?: { message?: string }\n\tmessage?: string\n}\n\nconst clip = (s: string, max = 60): string => (s.length > max ? `${s.slice(0, max)}…` : s)\n\n// One human-readable label per --json stdout line; null for lines that aren't\n// codex's JSON (dropped from the progress stream). Event taxonomy:\n// thread.started / turn.started / turn.completed / turn.failed /\n// item.{started,updated,completed} (item.type = agent_message,\n// command_execution, file_change, reasoning, web_search, todo_list,\n// mcp_tool_call, error) / error.\nexport function describeCodexStreamLine(line: string): string | null {\n\tlet obj: CodexStreamLine\n\ttry {\n\t\tobj = JSON.parse(line) as CodexStreamLine\n\t} catch {\n\t\treturn null\n\t}\n\tconst item = obj.item\n\tconst label = (obj.type ?? \"\") + (item?.type ? `:${item.type}` : \"\")\n\tlet detail = \"\"\n\tif (item?.type === \"agent_message\") {\n\t\tdetail = ` ${item.text?.length ?? 0} chars`\n\t} else if (item?.type === \"command_execution\" && item.command) {\n\t\tdetail = ` ${clip(item.command)}`\n\t} else if (item?.type === \"file_change\") {\n\t\tdetail = ` ${(item.changes ?? []).length} file(s)`\n\t} else if (obj.type === \"turn.completed\") {\n\t\tdetail = ` ${obj.usage?.input_tokens ?? 0} in, ${obj.usage?.output_tokens ?? 0} out tokens`\n\t} else if (obj.type === \"turn.failed\") {\n\t\tdetail = ` ${clip(obj.error?.message ?? \"\")}`\n\t} else if (obj.type === \"error\") {\n\t\tdetail = ` ${clip(obj.message ?? \"\")}`\n\t}\n\treturn `[${label}]${detail}`\n}\n","import { readFileSync } from \"node:fs\"\nimport { homedir } from \"node:os\"\nimport { join } from \"node:path\"\nimport { claudeAgent, describeClaudeStreamLine } from \"./claude.ts\"\nimport { codexAgent, describeCodexStreamLine, validateCodexAuth } from \"./codex.ts\"\nimport type { AgentSpec } from \"./runner.ts\"\n\n// The agent CLI: the brand of agent (claude, codex) the operator picks with\n// --agent, and everything the workflows need from it. Not to be confused with\n// the harness (doublecheck's own mechanics) or an agent (one running\n// inspector instance, described by an AgentSpec).\nexport interface AgentCli {\n\tname: string\n\t// Applied only when --model is absent.\n\tdefaultModel: { check: string; mine: string }\n\t// The phrase the report contract uses to tell this agent how to create a\n\t// file; null when the prompt should just say \"create <path>\".\n\twriteToolPhrase: string | null\n\t// Domain suffixes for restricted-egress workflows (mine): the CLI's own\n\t// API endpoints, so the only reachable destination is the service the\n\t// agent already sends its context to.\n\tegressDomains: string[]\n\t// Host-side preflight: the secret material staged into every guest, or an\n\t// actionable error. Runs once per invocation, before any guest boots.\n\tcredentials(): string\n\tagent(opts: { credentials: string; model: string; workdir: string }): AgentSpec\n\tdescribeStreamLine(line: string): string | null\n}\n\nconst claude: AgentCli = {\n\tname: \"claude\",\n\tdefaultModel: { check: \"haiku\", mine: \"opus\" },\n\twriteToolPhrase: \"with the Write tool\",\n\tegressDomains: [\"anthropic.com\"],\n\tcredentials: () => {\n\t\tconst token = process.env.CLAUDE_CODE_OAUTH_TOKEN\n\t\tif (!token) {\n\t\t\tthrow new Error(\n\t\t\t\t\"CLAUDE_CODE_OAUTH_TOKEN is required in the environment (it is injected into each agent's sandbox)\",\n\t\t\t)\n\t\t}\n\t\treturn token\n\t},\n\tagent: ({ credentials, model, workdir }) =>\n\t\tclaudeAgent({ token: credentials, model, workdir }),\n\tdescribeStreamLine: describeClaudeStreamLine,\n}\n\nconst codex: AgentCli = {\n\tname: \"codex\",\n\t// No haiku-style cheap default: plan billing is flat-rate, and the staged\n\t// guest config already pins xhigh reasoning effort (operator decision).\n\tdefaultModel: { check: \"gpt-5.5\", mine: \"gpt-5.5\" },\n\twriteToolPhrase: null,\n\t// ChatGPT-plan inference lives at chatgpt.com/backend-api/codex; the\n\t// openai.com suffix covers auth.openai.com, where a 401-forced token\n\t// refresh would have to go.\n\tegressDomains: [\"chatgpt.com\", \"openai.com\"],\n\tcredentials: () => {\n\t\tconst authPath = join(homedir(), \".codex\", \"auth.json\")\n\t\tlet content: string\n\t\ttry {\n\t\t\tcontent = readFileSync(authPath, \"utf-8\")\n\t\t} catch {\n\t\t\tthrow new Error(`no readable ${authPath} — run \\`codex login\\` on the host`)\n\t\t}\n\t\tvalidateCodexAuth(content, new Date(), authPath)\n\t\treturn content\n\t},\n\tagent: ({ credentials, model, workdir }) =>\n\t\tcodexAgent({ authJson: credentials, model, workdir }),\n\tdescribeStreamLine: describeCodexStreamLine,\n}\n\nconst AGENT_CLIS: Record<string, AgentCli> = { claude, codex }\n\nexport function resolveAgentCli(name: string): AgentCli {\n\tconst cli = AGENT_CLIS[name]\n\tif (!cli) {\n\t\tthrow new Error(\n\t\t\t`unknown agent \"${name}\" (have: ${Object.keys(AGENT_CLIS).join(\", \")})`,\n\t\t)\n\t}\n\treturn cli\n}\n\n// One resolved, preflighted agent selection, shared by every unit of a run.\nexport interface AgentRun {\n\tcli: AgentCli\n\tcredentials: string\n\tmodel: string\n}\n\n// Resolve --agent/--model into what a workflow's units consume: the CLI, its\n// preflighted credentials, and the model (explicit flag, else the CLI's\n// default for this workflow).\nexport function resolveAgentRun(\n\tname: string,\n\tmodel: string | undefined,\n\tworkflow: \"check\" | \"mine\",\n): AgentRun {\n\tconst cli = resolveAgentCli(name)\n\treturn {\n\t\tcli,\n\t\tcredentials: cli.credentials(),\n\t\tmodel: model ?? cli.defaultModel[workflow],\n\t}\n}\n\n// The per-unit progress sink both workflow shells hang on runAgent: guest\n// stderr passes through as `[label] ! line`, stdout is the agent CLI's JSON\n// stream, labelled by its describeStreamLine (non-JSON lines dropped).\nexport function progressSink(\n\tlabel: string,\n\tdescribe: (line: string) => string | null,\n): (kind: \"stdout\" | \"stderr\", line: string) => void {\n\treturn (kind, line) => {\n\t\tif (kind === \"stderr\") {\n\t\t\tprocess.stderr.write(`[${label}] ! ${line}\\n`)\n\t\t\treturn\n\t\t}\n\t\tconst described = describe(line)\n\t\tif (described) process.stderr.write(`[${label}] ${described}\\n`)\n\t}\n}\n","import { existsSync, readFileSync } from \"node:fs\"\nimport { basename, join } from \"node:path\"\nimport type { ExecEvent } from \"microsandbox\"\nimport { REPORT_FILE } from \"./contract.ts\"\n\n// microsandbox exports its fluent builders as value-only consts; recover their\n// instance types via a type-only import (erased at build) so the native module\n// only loads behind the `await import` in runAgent.\ntype MountBuilder = InstanceType<typeof import(\"microsandbox\").MountBuilder>\ntype PatchBuilder = InstanceType<typeof import(\"microsandbox\").PatchBuilder>\ntype ExecOptionsBuilder = InstanceType<typeof import(\"microsandbox\").ExecOptionsBuilder>\n// The SDK types `.network(cb)` as `(b: any) => any`, and we call the JS-shim\n// `.policy(...)`, absent from the native builder's types.\n// biome-ignore lint/suspicious/noExplicitAny: SDK types this builder callback as any\ntype NetworkBuilder = any\n\n// Locally built (Dockerfile.guest): node 24 slim + git/ripgrep/curl/wget + the\n// claude CLI baked in. Side-loaded into the microsandbox cache by\n// ./scripts/build-guest-image.sh — it exists nowhere else, hence pullPolicy\n// \"never\": a cache miss means \"run the build script\", not \"try Docker Hub\".\nconst GUEST_IMAGE = \"doublecheck-guest:latest\"\nconst GUEST_MEMORY_MIB = 2048\n\n// Staged into the guest before boot (e.g. claude's trust-accepted config).\nexport interface GuestFile {\n\tpath: string\n\tcontent: string\n}\n\n// What it takes to run one agent in a booted guest: a bash command executed in\n// the scratch cwd that must leave REPORT_FILE there, the env it needs, and\n// files staged into the guest. Plain data — adapters produce it, this runner\n// consumes it, tests fake it.\nexport interface AgentSpec {\n\tcommand: string\n\tenv: Record<string, string>\n\tfiles: GuestFile[]\n}\n\nexport type AgentOutcome =\n\t| { ok: true; report: string }\n\t| { ok: false; reason: string; partialReport: string | null }\n\n// Pure line buffering: fold a chunk into the carry, emit complete non-blank\n// lines, keep the unterminated tail.\nexport function feedLines(\n\tcarry: string,\n\tchunk: string,\n): { lines: string[]; carry: string } {\n\tconst parts = (carry + chunk).split(\"\\n\")\n\tconst rest = parts.pop() ?? \"\"\n\treturn { lines: parts.filter((l) => l.trim()), carry: rest }\n}\n\n// Pure outcome decision: what the exec left behind → what it means.\nexport function decideOutcome(\n\texitCode: number | null,\n\treport: string | null,\n\tworkdir: string,\n): AgentOutcome {\n\tif (exitCode !== 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `agent process exited ${exitCode}`,\n\t\t\tpartialReport: report,\n\t\t}\n\t}\n\tif (report === null) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `agent exited 0 but wrote no ${REPORT_FILE} (work dir: ${workdir})`,\n\t\t\tpartialReport: null,\n\t\t}\n\t}\n\treturn { ok: true, report }\n}\n\nexport interface RunAgentOpts {\n\t// Host dir the agent inspects, bind-mounted READ-ONLY at its real host\n\t// path: the target for `check`, the transcripts corpus for `mine`.\n\tmount: string\n\t// Scratch dir with PROMPT_FILE already inside; bind-mounted rw as the guest\n\t// cwd at its identical host path, so the agent's report lands back on the host.\n\tworkdir: string\n\tspec: AgentSpec\n\t// \"all\" for checks (inspectors may research); a domain-suffix allowlist for\n\t// miners: the personal corpus is mounted, so egress is pinned to the agent\n\t// CLI's own API domains — the only reachable destination is the service\n\t// the agent already sends its context to. NetworkPolicy.none() is not an\n\t// option here — it kills DNS entirely and the adapter can't reach its own\n\t// model API (measured: claude retries ~180s then exits 1).\n\tnetwork: \"all\" | { onlyDomains: string[] }\n\tonLine: (kind: \"stdout\" | \"stderr\", line: string) => void\n}\n\n// Boot a guest (ro mount + scratch rw as cwd), exec the agent command, stream\n// its output line-by-line, read the report back off the scratch dir, tear\n// down. Agent-level failures (exit ≠ 0, no report) return ok:false;\n// harness-level failures (image missing, boot error) throw.\nexport async function runAgent(opts: RunAgentOpts): Promise<AgentOutcome> {\n\tconst microsandbox = await import(\"microsandbox\")\n\tconst name = `doublecheck-${basename(opts.workdir)}`\n\tconst network = opts.network\n\tconst policy =\n\t\tnetwork === \"all\"\n\t\t\t? microsandbox.NetworkPolicy.allowAll()\n\t\t\t: microsandbox.NetworkPolicy.builder()\n\t\t\t\t\t.defaultDeny()\n\t\t\t\t\t.egress((rb) => {\n\t\t\t\t\t\tlet rules = rb\n\t\t\t\t\t\tfor (const domain of network.onlyDomains) {\n\t\t\t\t\t\t\trules = rules.allow((d) => d.domainSuffix(domain))\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn rules\n\t\t\t\t\t})\n\t\t\t\t\t.build()\n\tlet sandbox: InstanceType<typeof microsandbox.Sandbox> | null = null\n\ttry {\n\t\ttry {\n\t\t\tsandbox = await microsandbox.Sandbox.builder(name)\n\t\t\t\t.image(GUEST_IMAGE)\n\t\t\t\t.memory(GUEST_MEMORY_MIB)\n\t\t\t\t.pullPolicy(\"never\")\n\t\t\t\t.replace()\n\t\t\t\t.workdir(opts.workdir)\n\t\t\t\t.envs(opts.spec.env)\n\t\t\t\t.volume(opts.mount, (mb: MountBuilder) => mb.bind(opts.mount).readonly())\n\t\t\t\t.volume(opts.workdir, (mb: MountBuilder) => mb.bind(opts.workdir))\n\t\t\t\t.patch((pb: PatchBuilder) => {\n\t\t\t\t\tlet p = pb\n\t\t\t\t\tfor (const f of opts.spec.files) {\n\t\t\t\t\t\tp = p.text(f.path, f.content, { mode: 0o600, replace: true })\n\t\t\t\t\t}\n\t\t\t\t\treturn p\n\t\t\t\t})\n\t\t\t\t.network((nb: NetworkBuilder) => nb.policy(policy))\n\t\t\t\t.create()\n\t\t} catch (e) {\n\t\t\tif (String(e).includes(\"not cached\")) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`guest image ${GUEST_IMAGE} is not in the microsandbox cache — run scripts/build-guest-image.sh (${String(e)})`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\n\t\tconst handle = await sandbox.execStreamWith(\"bash\", (e: ExecOptionsBuilder) =>\n\t\t\te.args([\"-c\", opts.spec.command]),\n\t\t)\n\n\t\tconst carry: Record<\"stdout\" | \"stderr\", string> = { stdout: \"\", stderr: \"\" }\n\t\tlet exitCode: number | null = null\n\t\tfor (;;) {\n\t\t\tconst ev: ExecEvent | null = await handle.recv()\n\t\t\tif (ev === null) break\n\t\t\tif (ev.kind === \"stdout\" || ev.kind === \"stderr\") {\n\t\t\t\tconst fed = feedLines(carry[ev.kind], Buffer.from(ev.data).toString())\n\t\t\t\tcarry[ev.kind] = fed.carry\n\t\t\t\tfor (const line of fed.lines) opts.onLine(ev.kind, line)\n\t\t\t} else if (ev.kind === \"exited\") exitCode = ev.code\n\t\t}\n\t\tfor (const kind of [\"stdout\", \"stderr\"] as const) {\n\t\t\tif (carry[kind].trim()) opts.onLine(kind, carry[kind])\n\t\t}\n\n\t\tconst reportPath = join(opts.workdir, REPORT_FILE)\n\t\tconst report = existsSync(reportPath) ? readFileSync(reportPath, \"utf-8\") : null\n\t\treturn decideOutcome(exitCode, report, opts.workdir)\n\t} finally {\n\t\tif (sandbox) {\n\t\t\ttry {\n\t\t\t\tawait sandbox.stop()\n\t\t\t} catch (e) {\n\t\t\t\topts.onLine(\"stderr\", `sandbox stop failed: ${String(e)}`)\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait microsandbox.Sandbox.remove(name)\n\t\t\t} catch (e) {\n\t\t\t\topts.onLine(\"stderr\", `sandbox remove failed: ${String(e)}`)\n\t\t\t}\n\t\t}\n\t}\n}\n","import {\n\tappendFileSync,\n\tmkdirSync,\n\tmkdtempSync,\n\treaddirSync,\n\treadFileSync,\n\twriteFileSync,\n} from \"node:fs\"\nimport { tmpdir } from \"node:os\"\nimport { join } from \"node:path\"\nimport PQueue from \"p-queue\"\nimport { type AgentRun, progressSink, resolveAgentRun } from \"./agent-cli.ts\"\nimport { composePrompt, PROMPT_FILE, REPORT_FILE } from \"./contract.ts\"\nimport { runAgent } from \"./runner.ts\"\n\n// A check is a plain markdown file — no frontmatter, no schema. The body is\n// the inspector's instructions; the name is the filename minus .md. Checks\n// come from one or more --checks-dir directories (default:\n// $TARGET/.agents/checks).\nexport interface Check {\n\tname: string\n\tbody: string\n}\n\n// Pure selection: `only` (from repeated --check flags) filters, in the order\n// named; naming a check that doesn't exist is an error, not an empty run.\nexport function selectChecks(all: Check[], only: string[], where: string): Check[] {\n\tif (all.length === 0) throw new Error(`no checks (*.md) in ${where}`)\n\tif (only.length === 0) return all\n\tconst byName = new Map(all.map((c) => [c.name, c]))\n\treturn only.map((name) => {\n\t\tconst check = byName.get(name)\n\t\tif (!check) {\n\t\t\tconst have = all.map((c) => c.name).join(\", \")\n\t\t\tthrow new Error(`no check named \"${name}\" in ${where} (have: ${have})`)\n\t\t}\n\t\treturn check\n\t})\n}\n\n// Shell: read every check file from every checks dir, then select purely.\n// A missing dir is an error; the same check name in two dirs is an error —\n// no precedence rules, rename one.\nexport function discoverChecks(dirs: string[], only: string[]): Check[] {\n\tconst all: Array<Check & { dir: string }> = []\n\tfor (const dir of dirs) {\n\t\tlet entries: string[]\n\t\ttry {\n\t\t\tentries = readdirSync(dir)\n\t\t} catch {\n\t\t\tthrow new Error(`no checks directory at ${dir}`)\n\t\t}\n\t\tfor (const f of entries.filter((e) => e.endsWith(\".md\")).sort()) {\n\t\t\tconst name = f.slice(0, -\".md\".length)\n\t\t\tconst clash = all.find((c) => c.name === name)\n\t\t\tif (clash) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`check \"${name}\" exists in both ${clash.dir} and ${dir} — rename one`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tall.push({ name, body: readFileSync(join(dir, f), \"utf-8\"), dir })\n\t\t}\n\t}\n\tconst checks = all\n\t\t.map(({ name, body }) => ({ name, body }))\n\t\t.sort((a, b) => a.name.localeCompare(b.name))\n\treturn selectChecks(checks, only, dirs.join(\", \"))\n}\n\nexport interface CheckWorkflowOpts {\n\ttarget: string\n\tchecksDirs: string[]\n\tcontextFile: string | null\n\tagent: string\n\t// Absent = the agent CLI's default for checks.\n\tmodel?: string\n\tparallel: number\n\toutput: string\n\tonly: string[]\n\tsaveJsonl: boolean\n}\n\n// fs-safe local timestamp, one dir per run shared by all its checks:\n// 2026-07-05-143000\nexport function runTimestamp(d: Date): string {\n\tconst p = (n: number) => String(n).padStart(2, \"0\")\n\treturn `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`\n}\n\n// The report written when the agent failed: the failure is the report, plus\n// whatever partial report the agent managed to leave.\nexport function failureReport(reason: string, partialReport: string | null): string {\n\tconst partial = partialReport\n\t\t? `\\n---\\n\\nPartial ${REPORT_FILE} left by the agent:\\n\\n${partialReport}`\n\t\t: \"\"\n\treturn `# CHECK FAILED\\n\\n${reason}\\n${partial}`\n}\n\nasync function runOneCheck(\n\tcheck: Check,\n\topts: CheckWorkflowOpts,\n\trun: AgentRun,\n\trunContext: string | null,\n\toutDir: string,\n): Promise<boolean> {\n\tconst workdir = mkdtempSync(join(tmpdir(), `doublecheck-${check.name}-`))\n\twriteFileSync(\n\t\tjoin(workdir, PROMPT_FILE),\n\t\tcomposePrompt({\n\t\t\tcheckBody: check.body,\n\t\t\ttarget: opts.target,\n\t\t\tworkdir,\n\t\t\trunContext,\n\t\t\twriteTool: run.cli.writeToolPhrase,\n\t\t}),\n\t)\n\tconst spec = run.cli.agent({\n\t\tcredentials: run.credentials,\n\t\tmodel: run.model,\n\t\tworkdir,\n\t})\n\t// The report is the verdict; with --save-jsonl the raw stream is kept\n\t// beside it so a run can be audited after the ephemeral guest is gone\n\t// (which files the inspector read, what it skipped, whether report claims\n\t// trace to actual observations).\n\tconst sink = progressSink(check.name, run.cli.describeStreamLine)\n\tlet onLine = sink\n\tif (opts.saveJsonl) {\n\t\tconst streamPath = join(outDir, `${check.name}.stream.jsonl`)\n\t\tonLine = (kind, line) => {\n\t\t\tif (kind === \"stdout\") appendFileSync(streamPath, `${line}\\n`)\n\t\t\tsink(kind, line)\n\t\t}\n\t}\n\tconst outcome = await runAgent({\n\t\tmount: opts.target,\n\t\tworkdir,\n\t\tspec,\n\t\tnetwork: \"all\",\n\t\tonLine,\n\t})\n\tconst reportPath = join(outDir, `${check.name}.md`)\n\tif (outcome.ok) {\n\t\twriteFileSync(reportPath, outcome.report)\n\t\tprocess.stderr.write(`[${check.name}] report: ${reportPath}\\n`)\n\t\treturn true\n\t}\n\twriteFileSync(reportPath, failureReport(outcome.reason, outcome.partialReport))\n\tprocess.stderr.write(`[${check.name}] FAILED (${outcome.reason}): ${reportPath}\\n`)\n\treturn false\n}\n\n// The check workflow: one sandboxed agent per check, at most `parallel`\n// guests at once. Returns true only when every check produced a report; agent\n// failures still write a failure-record report and flip the run to false.\nexport async function runChecks(opts: CheckWorkflowOpts): Promise<boolean> {\n\tconst run = resolveAgentRun(opts.agent, opts.model, \"check\")\n\tconst checks = discoverChecks(opts.checksDirs, opts.only)\n\tlet runContext: string | null = null\n\tif (opts.contextFile) {\n\t\ttry {\n\t\t\trunContext = readFileSync(opts.contextFile, \"utf-8\")\n\t\t} catch (e) {\n\t\t\tthrow new Error(\n\t\t\t\t`--context file not readable: ${opts.contextFile} (${String(e)})`,\n\t\t\t)\n\t\t}\n\t}\n\tconst outDir = join(opts.output, runTimestamp(new Date()))\n\tmkdirSync(outDir, { recursive: true })\n\tprocess.stderr.write(\n\t\t`${checks.length} check(s) against ${opts.target} (agent ${run.cli.name}, model ${run.model}, parallel ${opts.parallel})\\n`,\n\t)\n\tconst queue = new PQueue({ concurrency: opts.parallel })\n\tconst results = await Promise.all(\n\t\tchecks.map((check) =>\n\t\t\tqueue.add(() => runOneCheck(check, opts, run, runContext, outDir)),\n\t\t),\n\t)\n\treturn results.every((ok) => ok === true)\n}\n","// Claude Code transcript (.jsonl) → the genuine human turns → a flat digest.\n// Port of the June-2026 jq extraction, verified against the same corpus: a\n// \"genuine human turn\" is type:user, not meta, not sidechain, text content\n// only — which excludes the three things that are also type:user in the JSONL\n// (tool_results, slash-command stdout wrappers, injected system-reminders).\n\n// Per-turn char cap in the digest; the mining agent greps the source jsonl\n// for full text when it needs context around a turn.\nconst TURN_CHAR_CAP = 2000\n\ninterface RawLine {\n\ttype?: string\n\tisMeta?: boolean\n\tisSidechain?: boolean\n\tmessage?: { content?: unknown }\n}\n\nconst NON_HUMAN_TEXT =\n\t/^\\s*<command-name>|<local-command-stdout>|^\\s*<local-command|^\\s*<system-reminder>|Caveat: The messages below/\n\n// Throws on an unparseable line — the caller decides what an unreadable\n// transcript means for its run (mine counts and reports them, visibly).\nexport function humanTurns(jsonl: string): string[] {\n\tconst turns: string[] = []\n\tfor (const line of jsonl.split(\"\\n\")) {\n\t\tif (!line.trim()) continue\n\t\tconst raw = JSON.parse(line) as RawLine\n\t\tif (raw.type !== \"user\" || raw.isMeta || raw.isSidechain) continue\n\t\tconst content = raw.message?.content\n\t\tconst text =\n\t\t\ttypeof content === \"string\"\n\t\t\t\t? content\n\t\t\t\t: Array.isArray(content)\n\t\t\t\t\t? content\n\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t(item): item is { type: \"text\"; text: string } =>\n\t\t\t\t\t\t\t\t\ttypeof item === \"object\" &&\n\t\t\t\t\t\t\t\t\titem !== null &&\n\t\t\t\t\t\t\t\t\t(item as { type?: string }).type === \"text\" &&\n\t\t\t\t\t\t\t\t\ttypeof (item as { text?: unknown }).text === \"string\",\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.map((item) => item.text)\n\t\t\t\t\t\t\t.join(\"\\n\")\n\t\t\t\t\t: \"\"\n\t\tif (!text) continue\n\t\tif (NON_HUMAN_TEXT.test(text)) continue\n\t\tturns.push(text.replace(/[\\n\\r]+/g, \" ⏎ \").slice(0, TURN_CHAR_CAP))\n\t}\n\treturn turns\n}\n\nexport interface DigestMeta {\n\tsource: string\n\tproject: string\n\tsession: string\n}\n\nexport function renderDigest(meta: DigestMeta, turns: string[]): string {\n\tconst numbered = turns\n\t\t.map((t, i) => `${String(i + 1).padStart(3, \" \")} | ${t}`)\n\t\t.join(\"\\n\")\n\treturn `# source: ${meta.source}\n# project: ${meta.project}\n# session: ${meta.session}\n# human_turns: ${turns.length}\n# To understand WHY a terse turn or interruption happened, grep its text in the\n# source file above and read the assistant turn(s) immediately before it.\n\n${numbered}\n`\n}\n","import { createHash } from \"node:crypto\"\nimport { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\"\nimport { basename, join } from \"node:path\"\nimport { humanTurns, renderDigest } from \"./transcript.ts\"\n\n// One minable unit = one top-level transcript $PROJECTS/<project>/<session>.jsonl.\n// Its catalog home mirrors that path: $CATALOG/<project>/<session>/observations.md.\nexport interface Unit {\n\tproject: string\n\tsession: string\n\tjsonlPath: string\n}\n\nexport function enumerateUnits(projectsDir: string): Unit[] {\n\tlet projects: string[]\n\ttry {\n\t\tprojects = readdirSync(projectsDir).sort()\n\t} catch {\n\t\tthrow new Error(`no transcripts directory at ${projectsDir}`)\n\t}\n\tconst units: Unit[] = []\n\tfor (const project of projects) {\n\t\tconst dir = join(projectsDir, project)\n\t\tif (!statSync(dir).isDirectory()) continue\n\t\tfor (const f of readdirSync(dir).sort()) {\n\t\t\tif (!f.endsWith(\".jsonl\")) continue\n\t\t\tunits.push({\n\t\t\t\tproject,\n\t\t\t\tsession: basename(f, \".jsonl\"),\n\t\t\t\tjsonlPath: join(dir, f),\n\t\t\t})\n\t\t}\n\t}\n\treturn units\n}\n\nexport function observationsPath(catalogDir: string, unit: Unit): string {\n\treturn join(catalogDir, unit.project, unit.session, \"observations.md\")\n}\n\nexport type UnitStatus =\n\t// hash matches the recorded source_sha256 — skipped without parsing\n\t| { kind: \"mined\" }\n\t| { kind: \"below-threshold\"; turns: number }\n\t| {\n\t\t\tkind: \"pending\"\n\t\t\treason: \"new\" | \"changed\"\n\t\t\tturns: number\n\t\t\tdigest: string\n\t\t\tsourceSha256: string\n\t }\n\t// transcript has an unparseable line; reported visibly, never mined\n\t| { kind: \"unreadable\"; error: string }\n\n// Pure decision core: everything already read, nothing left but judgment.\nexport function decideUnitStatus(input: {\n\tunit: Unit\n\tjsonl: Buffer\n\trecordedSha256: string | null\n\tminTurns: number\n}): UnitStatus {\n\tconst sourceSha256 = createHash(\"sha256\").update(input.jsonl).digest(\"hex\")\n\tif (input.recordedSha256 === sourceSha256) return { kind: \"mined\" }\n\tlet turns: string[]\n\ttry {\n\t\tturns = humanTurns(input.jsonl.toString(\"utf-8\"))\n\t} catch (e) {\n\t\treturn { kind: \"unreadable\", error: String(e) }\n\t}\n\tif (turns.length < input.minTurns)\n\t\treturn { kind: \"below-threshold\", turns: turns.length }\n\treturn {\n\t\tkind: \"pending\",\n\t\treason: input.recordedSha256 === null ? \"new\" : \"changed\",\n\t\tturns: turns.length,\n\t\tdigest: renderDigest(\n\t\t\t{\n\t\t\t\tsource: input.unit.jsonlPath,\n\t\t\t\tproject: input.unit.project,\n\t\t\t\tsession: input.unit.session,\n\t\t\t},\n\t\t\tturns,\n\t\t),\n\t\tsourceSha256,\n\t}\n}\n\n// Shell: read the unit's inputs, then decide purely.\nexport function unitStatus(unit: Unit, catalogDir: string, minTurns: number): UnitStatus {\n\tconst obsPath = observationsPath(catalogDir, unit)\n\treturn decideUnitStatus({\n\t\tunit,\n\t\tjsonl: readFileSync(unit.jsonlPath),\n\t\trecordedSha256: existsSync(obsPath)\n\t\t\t? readSourceSha256(readFileSync(obsPath, \"utf-8\"))\n\t\t\t: null,\n\t\tminTurns,\n\t})\n}\n\nexport interface ObservationsMeta {\n\tsource: string\n\tsourceSha256: string\n\tminedAt: string\n\tmodel: string\n\thumanTurns: number\n}\n\n// The host composes the final file: frontmatter it alone can vouch for, then\n// the agent's report verbatim.\nexport function composeObservationsFile(meta: ObservationsMeta, body: string): string {\n\treturn `---\nsource: ${meta.source}\nsource_sha256: ${meta.sourceSha256}\nmined_at: ${meta.minedAt}\nmodel: ${meta.model}\nhuman_turns: ${meta.humanTurns}\n---\n\n${body.trimEnd()}\n`\n}\n\nexport function readSourceSha256(observationsMd: string): string | null {\n\treturn observationsMd.match(/^source_sha256: ([0-9a-f]{64})$/m)?.[1] ?? null\n}\n","import { mkdirSync, mkdtempSync, writeFileSync } from \"node:fs\"\nimport { tmpdir } from \"node:os\"\nimport { dirname, join } from \"node:path\"\nimport PQueue from \"p-queue\"\nimport {\n\ttype AgentRun,\n\tprogressSink,\n\tresolveAgentCli,\n\tresolveAgentRun,\n} from \"./agent-cli.ts\"\nimport {\n\tcomposeObservationsFile,\n\tenumerateUnits,\n\tobservationsPath,\n\ttype Unit,\n\ttype UnitStatus,\n\tunitStatus,\n} from \"./catalog.ts\"\nimport { composeMinePrompt, PROMPT_FILE } from \"./contract.ts\"\nimport { runAgent } from \"./runner.ts\"\n\nexport interface MineOpts {\n\tprojects: string\n\tcatalog: string\n\tagent: string\n\t// Absent = the agent CLI's default for mining.\n\tmodel?: string\n\tparallel: number\n\tminTurns: number\n\tlimit?: number\n\tdryRun: boolean\n}\n\nexport interface Pending {\n\tunit: Unit\n\tstatus: Extract<UnitStatus, { kind: \"pending\" }>\n}\n\n// What one mine invocation will and won't do, decided purely from the\n// per-unit statuses.\nexport interface MinePlan {\n\ttodo: Pending[]\n\tpendingTotal: number\n\tmined: number\n\tbelowThreshold: number\n\tunreadable: { unit: Unit; error: string }[]\n}\n\nexport function planMine(\n\tentries: { unit: Unit; status: UnitStatus }[],\n\tlimit?: number,\n): MinePlan {\n\tconst pending = entries.filter((e): e is Pending => e.status.kind === \"pending\")\n\treturn {\n\t\ttodo: limit ? pending.slice(0, limit) : pending,\n\t\tpendingTotal: pending.length,\n\t\tmined: entries.filter((e) => e.status.kind === \"mined\").length,\n\t\tbelowThreshold: entries.filter((e) => e.status.kind === \"below-threshold\").length,\n\t\tunreadable: entries.flatMap((e) =>\n\t\t\te.status.kind === \"unreadable\"\n\t\t\t\t? [{ unit: e.unit, error: e.status.error }]\n\t\t\t\t: [],\n\t\t),\n\t}\n}\n\nexport function summarizeMinePlan(plan: MinePlan, minTurns: number): string {\n\tconst total =\n\t\tplan.pendingTotal + plan.mined + plan.belowThreshold + plan.unreadable.length\n\tconst limited =\n\t\tplan.todo.length !== plan.pendingTotal ? ` (mining ${plan.todo.length})` : \"\"\n\treturn `${total} transcripts: ${plan.pendingTotal} pending${limited}, ${plan.mined} mined, ${plan.belowThreshold} below ${minTurns} turns, ${plan.unreadable.length} unreadable`\n}\n\nexport function dryRunRow({ unit, status }: Pending): string {\n\treturn `${status.reason.padEnd(7)} ${status.turns.toString().padStart(4)} turns ${unit.project}/${unit.session}`\n}\n\nasync function mineOneUnit(\n\t{ unit, status }: Pending,\n\topts: MineOpts,\n\trun: AgentRun,\n): Promise<boolean> {\n\tconst tag = unit.session.slice(0, 8)\n\tconst workdir = mkdtempSync(join(tmpdir(), `doublecheck-mine-${tag}-`))\n\twriteFileSync(\n\t\tjoin(workdir, PROMPT_FILE),\n\t\tcomposeMinePrompt(status.digest, workdir, run.cli.writeToolPhrase),\n\t)\n\tconst spec = run.cli.agent({\n\t\tcredentials: run.credentials,\n\t\tmodel: run.model,\n\t\tworkdir,\n\t})\n\tprocess.stderr.write(\n\t\t`[${tag}] mining ${unit.project}/${unit.session} (${status.turns} turns, ${status.reason})\\n`,\n\t)\n\tconst outcome = await runAgent({\n\t\tmount: opts.projects,\n\t\tworkdir,\n\t\tspec,\n\t\tnetwork: { onlyDomains: run.cli.egressDomains },\n\t\tonLine: progressSink(tag, run.cli.describeStreamLine),\n\t})\n\t// A failed mine writes NOTHING — the catalog is a durable asset; the next\n\t// run retries this unit because no hash gets recorded.\n\tif (!outcome.ok) {\n\t\tprocess.stderr.write(`[${tag}] FAILED (${outcome.reason})\\n`)\n\t\treturn false\n\t}\n\tconst obsPath = observationsPath(opts.catalog, unit)\n\tmkdirSync(dirname(obsPath), { recursive: true })\n\twriteFileSync(\n\t\tobsPath,\n\t\tcomposeObservationsFile(\n\t\t\t{\n\t\t\t\tsource: unit.jsonlPath,\n\t\t\t\tsourceSha256: status.sourceSha256,\n\t\t\t\tminedAt: new Date().toISOString(),\n\t\t\t\tmodel: run.model,\n\t\t\t\thumanTurns: status.turns,\n\t\t\t},\n\t\t\toutcome.report,\n\t\t),\n\t)\n\tprocess.stderr.write(`[${tag}] observations: ${obsPath}\\n`)\n\treturn true\n}\n\n// The mine workflow shell: gather statuses (I/O), plan purely, then either\n// print the plan (dry-run) or run one sandboxed agent per pending unit.\n// Returns true when nothing it attempted failed.\nexport async function runMine(opts: MineOpts): Promise<boolean> {\n\t// Validate the agent name before the dry-run/nothing-pending short-circuits\n\t// so a bad --agent errors on every invocation; the credentials preflight\n\t// stays below them (a dry run must not require credentials).\n\tresolveAgentCli(opts.agent)\n\tconst entries = enumerateUnits(opts.projects).map((unit) => ({\n\t\tunit,\n\t\tstatus: unitStatus(unit, opts.catalog, opts.minTurns),\n\t}))\n\tconst plan = planMine(entries, opts.limit)\n\tfor (const { unit, error } of plan.unreadable) {\n\t\tprocess.stderr.write(`UNREADABLE ${unit.project}/${unit.session}: ${error}\\n`)\n\t}\n\tprocess.stderr.write(`${summarizeMinePlan(plan, opts.minTurns)}\\n`)\n\n\tif (opts.dryRun) {\n\t\tfor (const pending of plan.todo) console.log(dryRunRow(pending))\n\t\treturn true\n\t}\n\tif (plan.todo.length === 0) return true\n\n\tconst run = resolveAgentRun(opts.agent, opts.model, \"mine\")\n\tconst queue = new PQueue({ concurrency: opts.parallel })\n\tconst results = await Promise.all(\n\t\tplan.todo.map((p) => queue.add(() => mineOneUnit(p, opts, run))),\n\t)\n\tconst failed = results.filter((ok) => ok !== true).length\n\tprocess.stderr.write(\n\t\t`mined ${results.length - failed}/${results.length}${failed ? `, ${failed} FAILED` : \"\"}\\n`,\n\t)\n\treturn failed === 0\n}\n","#!/usr/bin/env node\nimport { homedir } from \"node:os\"\nimport { join, resolve } from \"node:path\"\nimport { Command } from \"commander\"\nimport { runChecks } from \"./check.ts\"\nimport { runMine } from \"./mine.ts\"\n\nfunction parsePositiveInt(flag: string) {\n\treturn (v: string): number => {\n\t\tconst n = Number.parseInt(v, 10)\n\t\tif (!Number.isInteger(n) || n < 1)\n\t\t\tthrow new Error(`${flag} must be a positive integer, got \"${v}\"`)\n\t\treturn n\n\t}\n}\n\nconst collect = (v: string, prev: string[]): string[] => [...prev, v]\n\nconst program = new Command()\n\t.name(\"doublecheck\")\n\t.description(\n\t\t\"Run self-authored LLM code-inspectors (checks) against a target tree, one sandboxed agent per check\",\n\t)\n\nprogram\n\t.command(\"check\")\n\t.option(\"--target <dir>\", \"tree under inspection, mounted read-only\", process.cwd())\n\t.option(\n\t\t\"--checks-dir <dir>\",\n\t\t\"checks directory (repeatable; default: $TARGET/.agents/checks)\",\n\t\tcollect,\n\t\t[] as string[],\n\t)\n\t.option(\n\t\t\"--context <file>\",\n\t\t\"run-context file spliced into every inspector's prompt (intent, nuances, sanctioned exceptions, scope)\",\n\t)\n\t.option(\n\t\t\"--agent <name>\",\n\t\t\"agent CLI that runs the inspectors: claude or codex\",\n\t\t\"claude\",\n\t)\n\t.option(\n\t\t\"--model <model>\",\n\t\t\"model for the inspector agents (default per agent: claude haiku, codex gpt-5.5)\",\n\t)\n\t.option(\"--parallel <n>\", \"max concurrent checks\", parsePositiveInt(\"--parallel\"), 4)\n\t.option(\"--output <dir>\", \"reports root (default: $TARGET/.doublecheck)\")\n\t.option(\"--check <name>\", \"run only this check (repeatable)\", collect, [] as string[])\n\t.option(\n\t\t\"--save-jsonl\",\n\t\t\"persist each inspector's raw stream-json beside its report (audit trail)\",\n\t)\n\t.action(async (opts) => {\n\t\tconst target = resolve(opts.target)\n\t\tconst checksDirs: string[] =\n\t\t\topts.checksDir.length > 0\n\t\t\t\t? opts.checksDir.map((d: string) => resolve(d))\n\t\t\t\t: [join(target, \".agents\", \"checks\")]\n\t\tconst ok = await runChecks({\n\t\t\ttarget,\n\t\t\tchecksDirs,\n\t\t\tcontextFile: opts.context ? resolve(opts.context) : null,\n\t\t\tagent: opts.agent,\n\t\t\tmodel: opts.model,\n\t\t\tparallel: opts.parallel,\n\t\t\toutput: opts.output ? resolve(opts.output) : join(target, \".doublecheck\"),\n\t\t\tonly: opts.check,\n\t\t\tsaveJsonl: !!opts.saveJsonl,\n\t\t})\n\t\tif (!ok) process.exitCode = 1\n\t})\n\nprogram\n\t.command(\"mine\")\n\t.option(\n\t\t\"--projects <dir>\",\n\t\t\"Claude Code transcripts root\",\n\t\tjoin(homedir(), \".claude\", \"projects\"),\n\t)\n\t.option(\n\t\t\"--catalog <dir>\",\n\t\t\"observation catalog root\",\n\t\tjoin(homedir(), \".doublecheck\", \"catalog\"),\n\t)\n\t.option(\"--agent <name>\", \"agent CLI that runs the miners: claude or codex\", \"claude\")\n\t.option(\n\t\t\"--model <model>\",\n\t\t\"model for the mining agents (default per agent: claude opus, codex gpt-5.5 — a bad-model mine pollutes a durable asset)\",\n\t)\n\t.option(\"--parallel <n>\", \"max concurrent miners\", parsePositiveInt(\"--parallel\"), 4)\n\t.option(\n\t\t\"--min-turns <n>\",\n\t\t\"min genuine human turns for a real conversation\",\n\t\tparsePositiveInt(\"--min-turns\"),\n\t\t2,\n\t)\n\t.option(\"--limit <n>\", \"mine at most N pending units\", parsePositiveInt(\"--limit\"))\n\t.option(\"--dry-run\", \"list what would be mined without booting anything\")\n\t.action(async (opts) => {\n\t\tconst ok = await runMine({\n\t\t\tprojects: resolve(opts.projects),\n\t\t\tcatalog: resolve(opts.catalog),\n\t\t\tagent: opts.agent,\n\t\t\tmodel: opts.model,\n\t\t\tparallel: opts.parallel,\n\t\t\tminTurns: opts.minTurns,\n\t\t\tlimit: opts.limit,\n\t\t\tdryRun: !!opts.dryRun,\n\t\t})\n\t\tif (!ok) process.exitCode = 1\n\t})\n\nprogram.parseAsync().catch((e: unknown) => {\n\tconsole.error(e instanceof Error ? e.message : String(e))\n\tprocess.exit(1)\n})\n"],"mappings":";;;;;;;;;AAQA,MAAa,cAAc;AAG3B,MAAa,cAAc;AAU3B,SAAS,eACR,UACA,aACA,SACA,WACS;CACT,MAAM,OAAO,YAAY,IAAI,cAAc;CAC3C,OAAO;;6EAEqE,QAAQ,GAAG,YAAY,iK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OAAO,KAAK;EACZ,UAAU,KAAK;EACf,UAAU,KAAK;EACf,OAAO,KAAK;EACZ,QAAQ,CAAC,CAAC,KAAK;CAChB,CAAC,GACQ,QAAQ,WAAW;AAC7B,CAAC;AAEF,QAAQ,WAAW,CAAC,CAAC,OAAO,MAAe;CAC1C,QAAQ,MAAM,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;CACxD,QAAQ,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alizain/doublecheck",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Run self-authored LLM code-inspectors against a project — one sandboxed microVM agent per check, one markdown report each",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.5.1",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"claude",
|
|
18
|
+
"codex",
|
|
19
|
+
"openai",
|
|
18
20
|
"code-review",
|
|
19
21
|
"llm",
|
|
20
22
|
"agent",
|