backlog-drift 0.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -0
  3. package/dist/index.js +22831 -0
  4. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ReliableGenius
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # backlog-drift
2
+
3
+ AI-powered drift detection for [Backlog.md](https://github.com/MrLesk/Backlog.md). Detects when code changes make your backlog tasks stale, inaccurate, or silently resolved.
4
+
5
+ ## The Problem
6
+
7
+ Backlog.md keeps issues alongside your code, but it doesn't detect when tasks become outdated as code evolves:
8
+
9
+ - A task references `src/auth/oauth.ts` but that file was deleted in a refactor
10
+ - Acceptance criteria say "implement rate limiting" but it already exists
11
+ - A completed task's referenced files have been modified since completion
12
+ - All of a task's referenced files are gone, but the task is still open
13
+
14
+ For AI agents consuming the backlog as context, stale tasks produce stale plans.
15
+
16
+ ## How It Works
17
+
18
+ **Layer 1 — Structural Drift (deterministic, fast, zero false positives)**
19
+
20
+ | Check | What it detects |
21
+ |-------|----------------|
22
+ | Dead references | A `ref` file has been deleted or renamed |
23
+ | Dependency state | A dependency task has been completed or archived |
24
+ | Stale completion | A Done task's ref was modified after completion |
25
+ | Orphaned task | All ref files deleted, task still active |
26
+
27
+ **Layer 2 — Semantic Drift (AI-powered, opt-in)**
28
+
29
+ Uses an LLM to analyze whether task descriptions and acceptance criteria still match the referenced code. Supports Anthropic, OpenAI, and Ollama (local models).
30
+
31
+ ## Quick Start
32
+
33
+ ```bash
34
+ # Install
35
+ bun add -g backlog-drift # or: npm i -g backlog-drift
36
+
37
+ # Initialize (creates config + installs pre-commit hook)
38
+ backlog-drift init
39
+
40
+ # Discover file references for existing tasks
41
+ backlog-drift scan --apply
42
+
43
+ # Run drift checks
44
+ backlog-drift check
45
+ ```
46
+
47
+ ## Commands
48
+
49
+ ```
50
+ backlog-drift check [options] Run drift checks on backlog tasks
51
+ -t, --task <id> Check a specific task
52
+ -s, --since <ref> Only check changes since a git ref
53
+ --semantic Also run AI-powered semantic checks
54
+ --json Output as JSON
55
+
56
+ backlog-drift fix [options] Auto-fix structural drift issues
57
+ -t, --task <id> Fix a specific task
58
+ --dry-run Show proposed changes without applying
59
+ --semantic Also apply AI-suggested updates
60
+ -y, --yes Apply without confirmation
61
+
62
+ backlog-drift scan [options] Discover file refs from descriptions & git history
63
+ -t, --task <id> Scan a specific task
64
+ --apply Auto-add discovered refs to tasks
65
+ --json Output as JSON
66
+
67
+ backlog-drift report [--json] Generate a drift health report
68
+ backlog-drift init Create config and install pre-commit hook
69
+ backlog-drift config Show current configuration
70
+ backlog-drift hook install Install pre-commit hook
71
+ backlog-drift hook remove Remove pre-commit hook
72
+ backlog-drift hook status Show hook installation status
73
+ ```
74
+
75
+ ## Pre-Commit Hook
76
+
77
+ When installed (automatically via `backlog-drift init`), the pre-commit hook runs on every commit:
78
+
79
+ 1. Checks staged files against task refs for structural drift
80
+ 2. Discovers untracked refs from staged files mentioned in task descriptions
81
+ 3. Reports findings based on `hook.mode`:
82
+ - **warn** (default): print warnings, allow commit
83
+ - **block**: print warnings, abort commit if drift detected
84
+ - **silent**: log only
85
+
86
+ Example output:
87
+
88
+ ```
89
+ ⚠ backlog-drift: 2 tasks affected by this commit
90
+
91
+ DRIFT-42 "Add rate limiting"
92
+ ⚠ ref src/middleware/rateLimit.ts was modified
93
+
94
+ DRIFT-19 "OAuth integration" [Done]
95
+ ✗ ref src/auth/oauth.ts no longer exists
96
+
97
+ ℹ backlog-drift: discovered new refs from staged files
98
+
99
+ DRIFT-31 "Add social login"
100
+ + src/auth/jwt.ts (not yet tracked)
101
+
102
+ Run `backlog-drift scan --apply` to add these references.
103
+ ```
104
+
105
+ ## Configuration
106
+
107
+ `backlog-drift init` creates `.backlog-drift.yml`:
108
+
109
+ ```yaml
110
+ structural:
111
+ enabled: true
112
+ check_dead_refs: true
113
+ check_dependency_state: true
114
+ check_stale_completions: true
115
+ check_orphaned_tasks: true
116
+ stale_completion_days: 14
117
+
118
+ semantic:
119
+ enabled: false
120
+ provider: anthropic # anthropic | openai | ollama
121
+ model: claude-sonnet-4-20250514
122
+ # API key via BACKLOG_DRIFT_API_KEY env var
123
+
124
+ hook:
125
+ mode: warn # warn | block | silent
126
+ structural_only: true
127
+
128
+ scope:
129
+ statuses:
130
+ - To Do
131
+ - In Progress
132
+ - Review
133
+ check_completed: true
134
+ check_archived: false
135
+ ignore_tasks: []
136
+ ignore_refs: [] # e.g., "*.test.ts"
137
+ ```
138
+
139
+ ## How Tasks Get File References
140
+
141
+ backlog-drift uses Backlog.md's existing `--ref` field to know which files each task cares about:
142
+
143
+ ```bash
144
+ backlog task create "Add auth" --ref src/auth.ts --ref src/middleware.ts
145
+ ```
146
+
147
+ For tasks without refs, `backlog-drift scan` discovers them:
148
+ - Parses task descriptions for file paths
149
+ - Searches git history for commits mentioning the task ID
150
+ - Suggests adding them: `backlog-drift scan --apply`
151
+
152
+ ## Upstream Contribution Path
153
+
154
+ backlog-drift is designed to eventually merge into Backlog.md as a native `backlog drift` subcommand:
155
+
156
+ - Same stack: Bun + TypeScript + Commander.js + gray-matter + Biome
157
+ - Same code conventions and formatting
158
+ - Additive-only changes to task frontmatter (`drift_status`, `drift_checked`, `drift_log`)
159
+ - No new dependencies beyond what Backlog.md already uses
160
+
161
+ ## Development
162
+
163
+ ```bash
164
+ # Install dependencies
165
+ bun install
166
+
167
+ # Run tests (121 tests, ~99% coverage)
168
+ bun test
169
+
170
+ # Type check
171
+ bun run check:types
172
+
173
+ # Lint & format
174
+ bun run check
175
+ bun run check:fix
176
+
177
+ # Run CLI locally
178
+ bun run src/index.ts check
179
+ ```
180
+
181
+ ## License
182
+
183
+ [MIT](LICENSE)