xab 1.0.0 → 2.0.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/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # xab
2
+
3
+ AI-powered curated branch reconciliation engine. Merges the _intent_ of source branch commits into a target branch that may have diverged significantly — not a blind cherry-pick.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i -g xab
9
+ ```
10
+
11
+ Also requires:
12
+
13
+ ```bash
14
+ npm i -g @openai/codex # Codex CLI (analysis/apply)
15
+ npm i -g @anthropic-ai/claude-code # Claude Code CLI (review)
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```bash
21
+ # Interactive TUI — select branches interactively
22
+ xab /path/to/repo
23
+
24
+ # With explicit refs
25
+ xab /path/to/repo --source-ref origin/main --target-ref origin/testnet
26
+
27
+ # Persistent work branch (resumes if exists)
28
+ xab /path/to/repo \
29
+ --source-ref origin/main \
30
+ --target-ref origin/testnet \
31
+ --work-branch merged-testnet
32
+
33
+ # Dry-run — analyze only, no commits
34
+ xab /path/to/repo \
35
+ --source-ref origin/main --target-ref origin/testnet --dry-run --batch
36
+
37
+ # List candidates only
38
+ xab /path/to/repo \
39
+ --source-ref origin/main --target-ref origin/testnet --list-only
40
+
41
+ # Batch mode — unattended, JSONL output
42
+ xab /path/to/repo --batch \
43
+ --source-ref origin/main --target-ref origin/testnet \
44
+ --work-branch merged-testnet --fetch
45
+ ```
46
+
47
+ If `.backmerge.json` exists in the target repo, refs are loaded from config — no flags needed:
48
+
49
+ ```bash
50
+ xab /path/to/repo --list-only
51
+ xab /path/to/repo --batch
52
+ ```
53
+
54
+ ## Pipeline
55
+
56
+ For each source commit since the merge base:
57
+
58
+ 1. **Cherry-pick detection** — `git cherry` / patch-id comparison skips already-picked commits
59
+ 2. **Repo context** — discovers AGENTS.md, CLAUDE.md, ai-docs/\*, and routes relevant docs per commit
60
+ 3. **Analysis** (Codex, gpt-5.4 high) — determines if the commit is already present, partial, or missing
61
+ 4. **Auto-skip** — commits already in target are skipped by default
62
+ 5. **Apply** (Codex, gpt-5.4 high) — curated merge: adapts intent to target architecture
63
+ 6. **Validate** — exactly 1 new commit, clean worktree, no conflict markers
64
+ 7. **Review** (Claude, opus 4.6) — full code review of applied diff, can run tests
65
+ 8. **Fix loop** — if review rejects, objections sent back to Codex for correction (up to 2 rounds)
66
+ 9. **Advance** — persistent branch only moves forward after review approval (CAS-guarded)
67
+
68
+ ## Decision model
69
+
70
+ Every commit results in exactly one decision:
71
+
72
+ | Decision | Meaning | HEAD moves? |
73
+ | ----------------- | -------------------------------- | --------------- |
74
+ | `applied` | Applied and committed | Yes (+1 commit) |
75
+ | `would_apply` | Dry-run: would be applied | No |
76
+ | `already_applied` | Already present (patch-id or AI) | No |
77
+ | `skip` | User/config skipped | No |
78
+ | `failed` | Apply/validation/review failed | No (reset) |
79
+
80
+ ## Repo-local configuration
81
+
82
+ Place `.backmerge.json` in the target repo root:
83
+
84
+ ```json
85
+ {
86
+ "sourceRef": "origin/main",
87
+ "targetRef": "origin/testnet",
88
+ "workBranch": "merged-testnet",
89
+ "instructionFiles": ["AGENTS.md", "CLAUDE.md"],
90
+ "docRoutes": [
91
+ {
92
+ "pathGlobs": ["frontend/**"],
93
+ "keywords": ["frontend", "ui", "nuxt", "vue"],
94
+ "docs": ["ai-docs/frontend.md"]
95
+ },
96
+ {
97
+ "pathGlobs": ["matching-engine/**"],
98
+ "keywords": ["engine", "matcher", "orderbook"],
99
+ "docs": ["ai-docs/matching-engine.md"]
100
+ },
101
+ {
102
+ "pathGlobs": ["api/**"],
103
+ "docs": ["ai-docs/scripts.md", "ai-docs/fiat-ramp.md"]
104
+ },
105
+ {
106
+ "pathGlobs": ["contracts/**"],
107
+ "docs": ["ai-docs/fast-markets.md"]
108
+ }
109
+ ],
110
+ "promptHints": [
111
+ "This is a prediction market platform on Base Mainnet",
112
+ "frontend uses pt-BR locale, preserve Portuguese text",
113
+ "contracts/lib/ is vendored — do not modify"
114
+ ],
115
+ "reviewStrictness": "normal",
116
+ "maxAttempts": 2,
117
+ "commitPrefix": "backmerge:"
118
+ }
119
+ ```
120
+
121
+ The engine auto-discovers AGENTS.md, CLAUDE.md, ai-docs/\*, and docs/\* without config. Config adds precision for difficult repos.
122
+
123
+ ## CLI flags
124
+
125
+ ```
126
+ Ref selection:
127
+ --source-ref <ref> Source branch/ref
128
+ --target-ref <ref> Target branch/ref
129
+ --work-branch <name> Persistent work branch
130
+ --reset-work-branch Force-reset work branch to target
131
+
132
+ Modes:
133
+ --batch, -b Unattended JSONL mode
134
+ --dry-run Analyze only
135
+ --list-only List commits and exit
136
+
137
+ Filtering:
138
+ --start-after <sha> Skip commits up to this hash
139
+ --limit <n> Process at most n commits
140
+
141
+ Behavior:
142
+ --fetch, -f Fetch remotes first
143
+ --no-review Skip Claude review
144
+ --no-auto-skip Ask about every commit
145
+ --no-resume Don't resume interrupted runs
146
+ --max-attempts <n> Retries per commit (default: 2)
147
+ --config <path> Config file path
148
+ ```
149
+
150
+ ## Audit & artifacts
151
+
152
+ Each run creates:
153
+
154
+ ```
155
+ .backmerge/runs/<run-id>/
156
+ metadata.json # Run parameters
157
+ results.jsonl # Machine-readable event log
158
+ summary.json # Final summary + all decisions
159
+ progress.json # Resume state (deleted on completion)
160
+ commits/
161
+ <hash>/
162
+ source.patch # Original commit diff
163
+ attempt-1/
164
+ analysis.json # Codex analysis result
165
+ applied.patch # What was committed
166
+ review-context.json
167
+ review-result.json
168
+ relevant-docs.txt
169
+ target-diff.stat.txt
170
+ ```
171
+
172
+ ## Persistent work branch
173
+
174
+ With `--work-branch`, the engine:
175
+
176
+ - Creates the branch from `--target-ref` if it doesn't exist
177
+ - Resumes from it if it already exists (auto-resume by default)
178
+ - Operates in a **detached eval worktree** — the persistent branch is never checked out
179
+ - Only advances the branch via **compare-and-swap** after validation + review approval
180
+ - Use `--reset-work-branch` to force-reset to target
181
+
182
+ ## Exit codes (batch)
183
+
184
+ - `0` — all commits processed successfully
185
+ - `1` — fatal error (bad refs, missing CLI, etc.)
186
+ - `2` — some commits failed or were review-rejected
187
+
188
+ ## Architecture
189
+
190
+ ```
191
+ src/
192
+ config.ts Repo-local config (.backmerge.json)
193
+ context.ts Repo intelligence: doc discovery, per-commit context
194
+ decisions.ts Strict decision model with validation
195
+ engine.ts Core pipeline (used by both frontends)
196
+ codex.ts Codex SDK: analyze + apply (gpt-5.4)
197
+ review.ts Claude review: packets + execution (opus 4.6)
198
+ audit.ts Per-run logging + artifact storage
199
+ git.ts Git operations: worktree, cherry-pick, validation
200
+ app.tsx Interactive TUI (ink/React)
201
+ batch.ts Unattended batch runner
202
+ index.ts CLI entry point
203
+ ```
204
+
205
+ ## Adapting to a new repo
206
+
207
+ 1. `npm i -g xab` then run `xab /path/to/repo` — works without config
208
+ 2. If merges need tuning, add `.backmerge.json` with doc routes and prompt hints
209
+ 3. No engine code changes needed — everything is config-driven