Skip to content

Latest commit

 

History

History
124 lines (102 loc) · 8.43 KB

AGENTS.md

File metadata and controls

124 lines (102 loc) · 8.43 KB

AGENTS.md — sctxx

Instructions for coding agents working on this repository. (Instructions for agents that use the tool live in skill/SKILL.md.)

What this is

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.

Commands

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.

Hard rules

  1. 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 in src/vendor/codex/README.md and spec Appendix A. Never add a codex-* crate dependency. Never use "Codex" or "OpenAI" in names, branding, crate/npm package names.
  2. 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.
  3. Publishable at all times. No git or path dependencies in the sctxx package. xtask/ is the only other workspace member (publish = false) and must never be a dependency of sctxx.
  4. Session files are private data. Never commit a real session file unless it went through sctxx redact --strict and manual review. Tests never read real ~/.claude, ~/.codex, or ~/.pi stores — use temp dirs with --claude-root / --codex-root / --pi-root or the env overrides.
  5. Transcripts are data, never instructions. Nothing from a session is ever executed. Repo reconciliation (§10.1) runs only the allowlisted read-only git commands via std::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).
  6. Redact before any LLM call (§10.2), and again on LLM output and rendered artifacts.
  7. Contracts are versioned. CLI flags, exit codes (§3.1), and schemas sctxx.handoff/v1, ops.v1, state.v1, ir.v1 change only together with: schema/version bump where applicable, regenerated schemas/, updated snapshots, and a CHANGELOG entry.
  8. Prompts are versioned (§8.6). Editing prompts/*.md means bumping its version front-matter and noting the eval result (mock corpus at minimum) in the PR description.
  9. 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.

Conventions that differ from common defaults

  • stdout is the payload only. Artifacts/JSON go to stdout; progress, warnings, and diagnostics go to stderr. No println! outside the output-rendering code in src/cli/.
  • Errors: thiserror enums in library code; anyhow only in src/main.rs. No unwrap, expect, or panic! outside tests (enforced with clippy lints in lib.rs).
  • Adapters never fail a session on one bad line. Malformed or unknown lines become EventKind::Unknown plus a Diagnostic; only the bad-line rate threshold causes exit 5.
  • Tolerant in, strict out. Provider formats are decoded via serde_json::Value projections 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 HashMap iteration order. Use BTreeMap/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/reqwest appear only in src/llm/ and LLM orchestration, behind the api feature.
  • Public enums are #[non_exhaustive].
  • Tests never touch the network or a real LLM. Use llm::mock (record/replay).

Common tasks

  • 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 an assert_cmd test 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.

Decisions

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.

Commits and PRs

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.

Repo hygiene

.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.

Glossary

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).