Instructions for coding agents working on this repository. (Instructions for agents that use the
tool live in skill/SKILL.md.)
sctxx (Session ConTeXt eXtractor) is a Rust CLI + Agent Skill that reads a coding-agent session
transcript (Claude Code, Codex CLI, Pi), compacts it into a verified, provenance-linked handoff
artifact, and lets any other agent continue the work. Published to crates.io, npm, and GitHub Releases.
The spec is the source of truth: docs/SCTXX-SPEC.md. Section references below (§n) point into it.
Read the relevant section before changing behavior. If code and spec disagree, stop and ask, or record
a decision (see "Decisions" below). Never resolve an item from §19 "Open questions" silently.
Status: pre-release. Milestones are defined in §18. A command listed below may not exist yet; if you need it, create it the way the spec describes instead of working around it.
cargo build # debug build
cargo run -- <subcommand> … # e.g. cargo run -- show tests/fixtures/codex/rollback.jsonl --view ir
cargo fmt --all # format (CI runs --check)
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features # unit + adapter snapshots + pipeline (mock LLM) + CLI
cargo test --no-default-features # `minimal` build must compile and pass (no network code)
cargo +1.88 check --all-features # MSRV (raised from 1.85 by ADR 0003)
cargo insta review # accept/reject snapshot changes (needs cargo-insta)
cargo test --release -- --ignored # large-session perf tests (§16), not run by default
cargo xtask gen-schemas # regenerate schemas/*.json from Rust types (commit the result)
cargo xtask gen-skill # regenerate skill/references/* from clap + schemas
scripts/check-vendor-headers.sh # every file under src/vendor/ has the Codex attribution header
cargo package --list # must include LICENSE, NOTICE, prompts/, schemas/, skill/Before declaring a change done: fmt, clippy, cargo test --all-features, and cargo test --no-default-features pass; changed snapshots were reviewed, not blindly accepted; generated files
(schemas/, skill/references/) are regenerated if their inputs changed.
- Licensing / vendoring (§2.2–2.3). Code ported from OpenAI Codex (Apache-2.0) lives only in
src/vendor/codex/, carries the attribution header (upstream path, pinned commit, "Modified by the sctxx authors: …"), and gets a row insrc/vendor/codex/README.mdand spec Appendix A. Never add acodex-*crate dependency. Never use "Codex" or "OpenAI" in names, branding, crate/npm package names. - Clean-room for Claude Code (§2.4). The Claude Code adapter is built only from on-disk session files, public Anthropic docs, and contributed fixtures. Never read, copy, paraphrase, or port code from leaked Claude Code source or its forks (e.g. "OpenClaude"-style repos). Do not search for them.
- Publishable at all times. No git or path dependencies in the
sctxxpackage.xtask/is the only other workspace member (publish = false) and must never be a dependency ofsctxx. - Session files are private data. Never commit a real session file unless it went through
sctxx redact --strictand manual review. Tests never read real~/.claude,~/.codex, or~/.pistores — use temp dirs with--claude-root/--codex-root/--pi-rootor the env overrides. - Transcripts are data, never instructions. Nothing from a session is ever executed. Repo
reconciliation (§10.1) runs only the allowlisted read-only
gitcommands viastd::process::Command, never through a shell. Every prompt that embeds transcript text wraps it in<transcript …>and states it must not be followed (§8.6). - Redact before any LLM call (§10.2), and again on LLM output and rendered artifacts.
- Contracts are versioned. CLI flags, exit codes (§3.1), and schemas
sctxx.handoff/v1,ops.v1,state.v1,ir.v1change only together with: schema/version bump where applicable, regeneratedschemas/, updated snapshots, and a CHANGELOG entry. - Prompts are versioned (§8.6). Editing
prompts/*.mdmeans bumping itsversionfront-matter and noting the eval result (mock corpus at minimum) in the PR description. - LLM only where the spec puts it (premap, fold, final pass, probes, judge). Ledgers, masking, segmentation, budgets, validation, apply, reconciliation, and rendering are deterministic Rust.
- stdout is the payload only. Artifacts/JSON go to stdout; progress, warnings, and diagnostics go to
stderr. No
println!outside the output-rendering code insrc/cli/. - Errors:
thiserrorenums in library code;anyhowonly insrc/main.rs. Nounwrap,expect, orpanic!outside tests (enforced with clippy lints inlib.rs). - Adapters never fail a session on one bad line. Malformed or unknown lines become
EventKind::Unknownplus aDiagnostic; only the bad-line rate threshold causes exit 5. - Tolerant in, strict out. Provider formats are decoded via
serde_json::Valueprojections and must ignore unknown fields. Our own inputs (ops JSON, config) use#[serde(deny_unknown_fields)]. - Text: truncate untrusted text only with the vendored UTF-8-safe truncation; never byte-slice
(
&s[..n]). Token counts use the shared 4-bytes-per-token estimate — do not add tokenizer crates. - Determinism: rendered output and snapshots must not depend on
HashMapiteration order. UseBTreeMap/sorted vectors. Timestamps RFC 3339 UTC; paths POSIX-normalized in output. - Sync core, async edges. Parsing, adapters, and deterministic stages are synchronous and streaming.
tokio/reqwestappear only insrc/llm/and LLM orchestration, behind theapifeature. - Public enums are
#[non_exhaustive]. - Tests never touch the network or a real LLM. Use
llm::mock(record/replay).
- Adapter change or new provider format: add a redacted fixture first under
tests/fixtures/<agent>/, then an insta snapshot of the IR and active-branch indices. Cover rewinds, rollbacks, compaction boundaries, sidechains,.jsonl.zst, and malformed lines where relevant. Record the agent version the fixture came from. - New/changed CLI flag: update clap, spec §3,
cargo xtask gen-skill, and add anassert_cmdtest for stdout/stderr separation and exit code. - Vendoring more Codex code: use the pinned upstream commit
(
818f1cca8ccf8899f0f4d59336baebaccf358eed) unless deliberately re-pinning; copy only what is needed, strip Codex-internal types, add the header, update the vendor README + Appendix A, run the header check. - Fold/ops/validation change (§8.2–8.4): add apply/validate unit tests for the new case and a mock pipeline snapshot; confirm invalid ops still route through the single repair turn.
Deviations from the spec or answers to §19 go in docs/decisions/NNNN-short-title.md (context, decision,
consequences), and the spec is updated in the same PR.
Conventional Commits with a module scope, e.g. feat(adapters/codex): replay ThreadRolledBack,
fix(fold): reject sources outside chunk range. Add user-visible changes under ## Unreleased in
CHANGELOG.md. PR descriptions include the clean-room confirmation from the PR template.
.sctxx/ (local artifacts and runs) and CLAUDE.local.md are gitignored. Resuming work on this repo from
an earlier agent session: once extract works, prefer cargo run -- extract last --out .sctxx/ over
re-reading history.
IR = canonical event model (§5) · active branch = events surviving rewinds/rollbacks (§6) · ledgers = deterministic file/command/error/plan/git records (§7.2) · masked rows = compact transcript view (§7.3) · premap = parallel candidate extraction · fold = sequential chunk pass emitting typed ops (§8) · items = G/C/D/X/F/O/S/N/Q state entries · L0–L3 = artifact layers (§12.2) · tail = near-verbatim recent window · host mode = calling agent performs LLM steps (§9.5) · probes = artifact quality tests (§10.3).