|
| 1 | +# Agent Guide |
| 2 | + |
| 3 | +Repository guidance for AI coding assistants and maintainers working on |
| 4 | +Threadmark. |
| 5 | + |
| 6 | +**Last updated:** 2026-05-19 |
| 7 | + |
| 8 | +## 1. Project Contract |
| 9 | + |
| 10 | +Threadmark is a shared continuity layer for software developers who hand work |
| 11 | +off between Claude Code and Codex in the same repository. It runs beside those |
| 12 | +harnesses, observes hook events, writes short perspectival journal entries at |
| 13 | +useful boundaries, and gives future sessions a compact startup packet for the |
| 14 | +same project. |
| 15 | + |
| 16 | +Threadmark is intentionally narrow. It is not a transcript archive, semantic |
| 17 | +search layer, sync service, or general-purpose memory system. Its job is to |
| 18 | +preserve enough situated context for independent agents to stay on the same |
| 19 | +line of work without inheriting one another's entire sessions. |
| 20 | + |
| 21 | +## 2. Reading Order |
| 22 | + |
| 23 | +Use the public repository files as the source of truth: |
| 24 | + |
| 25 | +1. `README.md` - project summary and user-facing flow. |
| 26 | +2. `HOW_IT_WORKS.md` - implementation mechanics and architecture. |
| 27 | +3. `QUICKSTART.md` - first-use path and common workflows. |
| 28 | +4. `INSTALL.md` - install, upgrade, uninstall, and health checks. |
| 29 | +5. Source under `cmd/`, `internal/`, `adapters/`, `prompts/`, and `config/`. |
| 30 | +6. Tests near the packages they validate. |
| 31 | + |
| 32 | +If behavior and docs disagree, inspect the implementation and tests, then update |
| 33 | +the docs as part of the same change when appropriate. |
| 34 | + |
| 35 | +## 3. Architecture Map |
| 36 | + |
| 37 | +- `cmd/threadmark` - user CLI, hook bridge, install, activation, status, doctor, |
| 38 | + daemon lifecycle, privacy controls, and startup packet surfacing. |
| 39 | +- `cmd/threadmarkd` - per-user daemon process. |
| 40 | +- `internal/adapters/claudecode` - Claude Code hook translation. |
| 41 | +- `internal/adapters/codex` - Codex hook translation. |
| 42 | +- `internal/core` - neutral event schema, thread boundaries, trigger |
| 43 | + classification, priority debounce, and checkpoint decisions. |
| 44 | +- `internal/daemon` - per-project state, event handling, checkpoint excerpts, |
| 45 | + retry behavior, and daemon-side orchestration. |
| 46 | +- `internal/ipc` - Unix-socket newline-delimited JSON transport. |
| 47 | +- `internal/journal` - project storage, journal frontmatter, append/read logic, |
| 48 | + and project ID resolution. |
| 49 | +- `internal/reflector` - prompt loading, redaction, Claude CLI subprocess calls, |
| 50 | + and reflector recursion guard. |
| 51 | +- `adapters/claudecode/hooks` and `adapters/codex/hooks` - shell shims used by |
| 52 | + harness hook configuration. |
| 53 | +- `prompts/reflector.md` - default reflector prompt. |
| 54 | +- `config/triggers.example.yml` - example trigger configuration. |
| 55 | + |
| 56 | +Runtime shape: |
| 57 | + |
| 58 | +```text |
| 59 | +coding session -> threadmark hook -> Unix socket -> threadmarkd |
| 60 | +threadmarkd -> core engine -> reflector -> journal store |
| 61 | +future SessionStart -> startup packet |
| 62 | +``` |
| 63 | + |
| 64 | +## 4. Product Vocabulary |
| 65 | + |
| 66 | +Use these terms consistently: |
| 67 | + |
| 68 | +- **sidecar** - Threadmark running beside an agent harness. |
| 69 | +- **startup packet** - the complete context artifact surfaced on `SessionStart`. |
| 70 | +- **Workspace Snapshot** - generated current git/workspace facts inside the |
| 71 | + startup packet. |
| 72 | +- **Project Card** - optional durable project-authored context inside the |
| 73 | + startup packet. |
| 74 | +- **Entry N** - selected reflector-written journal entries inside the startup |
| 75 | + packet. |
| 76 | + |
| 77 | +Do not introduce `startup card` or `orientation packet` as product primitives. |
| 78 | +Orientation is the goal; `startup packet` is the artifact. |
| 79 | + |
| 80 | +## 5. Scope Boundaries |
| 81 | + |
| 82 | +Implemented scope: |
| 83 | + |
| 84 | +- Go module: `github.com/thinkwright/threadmark`. |
| 85 | +- Commands: `threadmark` and `threadmarkd`. |
| 86 | +- Supported adapters: Claude Code and Codex. |
| 87 | +- Hook events include session start, user prompt, tool use, stop, pre-compact, |
| 88 | + and post-compact surfaces where supported by the harness. |
| 89 | +- Reflector backend: Claude CLI subprocess (`claude -p` by default; bare mode is |
| 90 | + available when explicitly configured). |
| 91 | +- Startup packets include workspace facts, optional Project Card content, and |
| 92 | + selected recent journal entries. |
| 93 | + |
| 94 | +Out of scope for v0: |
| 95 | + |
| 96 | +- OpenCode and Pi adapters. |
| 97 | +- Journal sync across machines. |
| 98 | +- Semantic retrieval over the journal. |
| 99 | +- Raw transcript or raw tool-output persistence. |
| 100 | +- Direct Anthropic SDK integration. |
| 101 | +- Durable spooling of checkpoint excerpts. |
| 102 | + |
| 103 | +## 6. Engineering Rules |
| 104 | + |
| 105 | +- Preserve the core/adapter split. Adapter packages translate harness payloads |
| 106 | + into neutral events; shared behavior belongs in `internal/core`, |
| 107 | + `internal/daemon`, `internal/journal`, `internal/ipc`, or |
| 108 | + `internal/reflector`. |
| 109 | +- Keep hook shims small and fast. Stateful work belongs in `threadmarkd`. |
| 110 | +- Do not turn the CLI into the hot path. Normal continuity should flow through |
| 111 | + hooks, daemon auto-start, checkpoint triggers, journal writes, and |
| 112 | + `SessionStart` startup packets. |
| 113 | +- Do not persist raw transcripts, raw tool outputs, or raw hook payloads. |
| 114 | +- Redact before reflector calls. Treat redaction as best effort, not a security |
| 115 | + guarantee. |
| 116 | +- Do not adopt credential scraping, credential pooling, or programmatic loops |
| 117 | + through interactive-priced subscription auth. |
| 118 | +- Do not add the Anthropic SDK or npm/Node dependencies for v0. |
| 119 | +- Keep product examples based on a `threadmark` command available on `PATH`, not |
| 120 | + on a maintainer-specific checkout path. |
| 121 | +- Do not modify global git config. |
| 122 | +- Do not add remotes, change repository visibility, rewrite history, or |
| 123 | + force-push unless a maintainer explicitly asks for that operation. |
| 124 | + |
| 125 | +## 7. Editing Workflow |
| 126 | + |
| 127 | +Before editing: |
| 128 | + |
| 129 | +```sh |
| 130 | +git status --short --branch |
| 131 | +git log --oneline -10 |
| 132 | +``` |
| 133 | + |
| 134 | +Prefer focused changes that match existing package boundaries. Use `rg` for |
| 135 | +search. Respect `.gitignore`; generated artifacts, build output, and |
| 136 | +machine-local configuration are not source. |
| 137 | + |
| 138 | +When behavior changes, update the relevant public docs in the same unit of work |
| 139 | +when user-facing behavior or contributor expectations change. When shared |
| 140 | +behavior changes, add or update tests near the package that owns the contract. |
| 141 | + |
| 142 | +When changing public docs, check for: |
| 143 | + |
| 144 | +- first-user clarity |
| 145 | +- sidecar/startup-packet vocabulary consistency |
| 146 | +- privacy and model-call boundaries |
| 147 | +- install and activation steps that match the current implementation |
| 148 | + |
| 149 | +## 8. Validation |
| 150 | + |
| 151 | +Common checks: |
| 152 | + |
| 153 | +```sh |
| 154 | +go test ./... |
| 155 | +go vet ./... |
| 156 | +git diff --check |
| 157 | +``` |
| 158 | + |
| 159 | +Use broader checks when risk warrants it: |
| 160 | + |
| 161 | +```sh |
| 162 | +go test -race ./... |
| 163 | +``` |
| 164 | + |
| 165 | +For installed workflows: |
| 166 | + |
| 167 | +```sh |
| 168 | +threadmark doctor |
| 169 | +threadmark status --last 10 |
| 170 | +``` |
| 171 | + |
| 172 | +Do not rely on `codex exec` to validate Codex hooks; configured project hooks |
| 173 | +are validated through the interactive Codex workflow. |
| 174 | + |
| 175 | +## 9. Privacy And Continuity Posture |
| 176 | + |
| 177 | +Threadmark's journal entries are perspectival orientation, not ground truth. |
| 178 | +The Workspace Snapshot and Project Card are factual/durable context; journal |
| 179 | +entries should be verified against code, tests, git history, and public docs. |
| 180 | + |
| 181 | +Journal mode sends a redacted checkpoint excerpt to the configured reflector |
| 182 | +model. Use no-journal mode for sensitive sessions. |
| 183 | + |
| 184 | +Threadmark should remain ambient after setup. Diagnostic, lifecycle, disable, |
| 185 | +enable, purge, and status commands are control-plane tools; they should not |
| 186 | +become the ordinary user workflow. |
0 commit comments