diffpilot 0.0.1__py3-none-any.whl

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.
diffpilot/verify.py ADDED
@@ -0,0 +1,352 @@
1
+ """verify: check numbers and counts the stores state against the project's data files (no LLM).
2
+
3
+ Values: a key next to a number in a section line (`cards: 4`, `goal 22`, `FORMAT is 9`, `16 kills`, `40%` = 0.4,
4
+ `1,000` = 1000). The value is read inside the block of an entry the line names: a backticked id, **bold** name, table
5
+ cell, a plain or parenthesized name that is a data identifier ("Aura (Orrery Ring)" -> `orrery_ring`), else the
6
+ heading. A key found only outside any named entry can confirm a value but never reports a mismatch.
7
+
8
+ Counts and groups: "Uncommon (33)" or "33 Uncommon" is compared with the number of data entries whose field has that
9
+ value (`rarity: Uncommon`); list items under such a group ("- Gnome") are checked to carry that value.
10
+ """
11
+
12
+ import bisect
13
+ import re
14
+ from collections import defaultdict
15
+ from dataclasses import dataclass
16
+ from pathlib import Path
17
+
18
+ from diffpilot.config import Config, DPError
19
+ from diffpilot.index import Index
20
+ from diffpilot.store import ANCHOR
21
+
22
+ NUM = r'(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?%?'
23
+ DOC_NUM = re.compile(rf'(?<![\w.,])-?({NUM})(?![\w%/-]|[.,]\d)')
24
+ LEFT = re.compile(r'`?\b([A-Za-z_]\w*(?:::\w+)*)`?\s*(:|=|\bis\b|\bof\b)?\s*`?$') # `cards: 4`, `goal 22`
25
+ RIGHT = re.compile(r'^`?\s+([A-Za-z_]\w*)') # `16 kills`
26
+ DATA_PAIR = re.compile(r'\b([A-Za-z_]\w*)\s*(?::\s*[\w<>&\[\]; ]+?\s*)?[:=]\s*(-?\d+(?:\.\d+)?)(?![\w.])')
27
+ DATA_SYM = re.compile(r'\b([A-Za-z_]\w*)\s*:\s*"?([A-Za-z_][\w ]*?)"?\s*(?=[,)}\]]|$)') # `rarity: Rare,`
28
+ FIELD = re.compile(r'\b([A-Za-z_]\w*)\s*:(?!:)')
29
+ TOKEN = re.compile(r'"([^"]+)"|([A-Za-z_]\w*)')
30
+ MARKUP = re.compile(r'`([A-Za-z_][\w:.-]*)`|\*\*([^*]+)\*\*|^\s*\|\s*([^|]+?)\s*\|')
31
+ WORD = re.compile(r"[A-Za-z][\w'-]*")
32
+ GROUP = re.compile(r'\b([A-Z][\w-]*(?: [A-Z][\w-]*)?)\s*\((\d+)\)|\b(\d+)\s+([A-Z][a-z][\w-]*)')
33
+ BULLET = re.compile(r'^\s*(?:[-*+]|\d+\.)\s+(.*)')
34
+ MAX_BLOCKS = 3 # an entry name found in more data blocks than this is a category value (`Rare`), not an id
35
+ STOP = set(
36
+ 'a an the and or to of in on at by for is are was be as it its with from into per than then when while every each'
37
+ ' after before until up down over under about around least most more less only also just meanwhile hit hits'
38
+ ' all any some no not one two this that these those which who has have had can may must will same other'
39
+ ' s ms sec secs second seconds min mins minute minutes h hr hrs hour hours px pt em rem fps hp x pct percent'
40
+ ' times kb mb gb k m km cm mm kg g'.split()
41
+ )
42
+
43
+
44
+ @dataclass
45
+ class Claim:
46
+ ref: str
47
+ line: str # file:line in the store
48
+ entry: str | None
49
+ key: str # the candidate the data resolved, else the first
50
+ value: str
51
+ keys: tuple[str, ...] = () # candidates: the word before the number, then (no `:`/`=`/is) the word after
52
+ entries: tuple[str, ...] = () # candidate entries, most specific first
53
+ status: str = 'unresolved' # match | mismatch | unresolved
54
+ data: str = '' # value found
55
+ where: str = '' # file:line in the data
56
+ note: str = ''
57
+
58
+
59
+ def norm(name: str) -> str:
60
+ return re.sub(r'[^a-z0-9]', '', name.lower())
61
+
62
+
63
+ def numbers(value: str) -> set[float]:
64
+ """Doc values `40%` and `0.4` mean the same; return every reading."""
65
+ v = value.replace(',', '')
66
+ if v.endswith('%'):
67
+ n = float(v[:-1])
68
+ return {n, n / 100}
69
+ return {float(v)}
70
+
71
+
72
+ def _same(a: float, b: float) -> bool:
73
+ return abs(a - b) <= 1e-9 * max(1.0, abs(a), abs(b))
74
+
75
+
76
+ def _scaled(doc: str, data: str) -> int | None:
77
+ """Return k when the doc value is the data value times 10**k (a derived value such as 10 x 1.6 = 16)."""
78
+ d = float(data)
79
+ for n in numbers(doc):
80
+ for k in (-3, -2, -1, 1, 2, 3):
81
+ if d and _same(n, d * 10**k):
82
+ return k
83
+ return None
84
+
85
+
86
+ class Data:
87
+ def __init__(self, cfg: Config) -> None: # noqa: C901 - one indexing pass over every data line
88
+ if not cfg.verify.data:
89
+ raise DPError('verify needs data files: set [verify].data = ["assets/data/**/*.ron"] in diffpilot.toml')
90
+ self.files: dict[str, list[str]] = {}
91
+ for g in cfg.verify.data: # glob each pattern: never walk build output such as target/
92
+ for p in sorted(cfg.root.glob(g)):
93
+ if p.is_file():
94
+ self.files[cfg.rel(p)] = p.read_text(encoding='utf-8', errors='replace').split('\n')
95
+ self.aliases = {norm(k): {norm(x) for x in v} for k, v in cfg.verify.aliases.items()}
96
+ self.nums: dict[str, list[tuple[str, int, str]]] = defaultdict(list) # key -> (file, line, value)
97
+ self.syms: dict[str, list[tuple[str, int, str, str]]] = defaultdict(list) # value -> (file, line, key, raw)
98
+ self.fields: set[str] = set()
99
+ names: dict[str, list[tuple[str, int]]] = defaultdict(list)
100
+ for f, lines in self.files.items():
101
+ for i, ln in enumerate(lines):
102
+ for m in DATA_PAIR.finditer(ln):
103
+ self.nums[norm(m.group(1))].append((f, i, m.group(2)))
104
+ for m in DATA_SYM.finditer(ln):
105
+ self.syms[norm(m.group(2))].append((f, i, norm(m.group(1)), m.group(2)))
106
+ self.fields |= {norm(x) for x in FIELD.findall(ln)}
107
+ for a, b in TOKEN.findall(ln):
108
+ names[norm(a or b)].append((f, i))
109
+ # an identifier used as a field name somewhere (`goal:`) is a key, not an entry
110
+ self.names = {n: locs for n, locs in names.items() if n not in self.fields and len(n) > 2 and n not in STOP}
111
+ self._blocks: dict[str, list[tuple[str, int, int]]] = {}
112
+ per_key: dict[str, list[str]] = defaultdict(list)
113
+ for v, locs in self.syms.items():
114
+ for _, _, k, _ in locs:
115
+ per_key[k].append(v)
116
+ # a field whose values never repeat (`id`, `name`) holds identifiers; `rarity` holds categories
117
+ self.id_keys = {k for k, vs in per_key.items() if len(vs) > 1 and len(set(vs)) == len(vs)}
118
+
119
+ def keys(self, key: str) -> set[str]:
120
+ k = norm(key)
121
+ return {k} | self.aliases.get(k, set())
122
+
123
+ def known(self, key: str) -> bool:
124
+ return any(k in self.nums for k in self.keys(key))
125
+
126
+ def blocks(self, entry: str) -> list[tuple[str, int, int]]:
127
+ """(file, first, end) of every block that names the entry."""
128
+ n = norm(entry)
129
+ if n not in self._blocks:
130
+ locs = self.names.get(n, []) + [(f, i) for f, i, _, _ in self.syms.get(n, [])]
131
+ blocks = sorted({(f, *_block(self.files[f], i)) for f, i in locs})
132
+ self._blocks[n] = blocks if len(blocks) <= MAX_BLOCKS else [] # named everywhere: a category, not an id
133
+ return self._blocks[n]
134
+
135
+ def lookup(self, key: str, blocks: list[tuple[str, int, int]] | None) -> list[tuple[str, int, str]]:
136
+ hits = sorted(x for k in self.keys(key) for x in self.nums.get(k, []))
137
+ if blocks is None:
138
+ return hits
139
+ out = []
140
+ for f, a, b in blocks:
141
+ lo, hi = bisect.bisect_left(hits, (f, a, '')), bisect.bisect_left(hits, (f, b, ''))
142
+ out += hits[lo:hi]
143
+ return out
144
+
145
+ def field_in(self, blocks: list[tuple[str, int, int]], key: str) -> list[tuple[str, int, str]]:
146
+ """Symbolic values of `key` inside the blocks: (file, line, raw value)."""
147
+ return [
148
+ (f, i, raw)
149
+ for locs in self.syms.values()
150
+ for f, i, k, raw in locs
151
+ if k == key and any(bf == f and a <= i < b for bf, a, b in blocks)
152
+ ]
153
+
154
+ def entries_in(self, text: str) -> list[str]:
155
+ """Return data identifiers named in prose, longest first ("Orrery Ring" -> orrery_ring, "Aura" -> kind: Aura)."""
156
+ words = WORD.findall(text)
157
+ out = []
158
+ for size in (3, 2, 1):
159
+ for i in range(len(words) - size + 1):
160
+ name = ' '.join(words[i : i + size])
161
+ n = norm(name)
162
+ if (n in self.names or (n in self.syms and n not in self.fields and len(n) > 2)) and self.blocks(name):
163
+ out.append(name)
164
+ return out
165
+
166
+
167
+ def _indent(line: str) -> int:
168
+ return len(line) - len(line.lstrip())
169
+
170
+
171
+ def _block(lines: list[str], i: int) -> tuple[int, int]:
172
+ """Return the entry's subtree when deeper lines follow, else its run of siblings (a struct with `id: "x"`)."""
173
+ ind = _indent(lines[i])
174
+ j = i + 1
175
+ while j < len(lines) and (not lines[j].strip() or _indent(lines[j]) > ind):
176
+ j += 1
177
+ if j > i + 1:
178
+ return i, j
179
+ a = i
180
+ while a > 0 and lines[a - 1].strip() and _indent(lines[a - 1]) >= ind:
181
+ a -= 1
182
+ b = i + 1
183
+ while b < len(lines) and lines[b].strip() and _indent(lines[b]) >= ind:
184
+ b += 1
185
+ return a, b
186
+
187
+
188
+ def _key_ok(k: str) -> bool:
189
+ return len(k) > 1 and k.lower() not in STOP
190
+
191
+
192
+ def claims(cfg: Config, idx: Index, data: Data, refs: list[str]) -> list[Claim]:
193
+ out = []
194
+ texts: dict[str, list[str]] = {}
195
+ for ref in refs:
196
+ v = idx.views[ref]
197
+ lines = texts.setdefault(v.file, (cfg.root / v.file).read_text(encoding='utf-8').split('\n'))
198
+ heading = data.entries_in(v.heading) + [v.heading]
199
+ fence = False
200
+ for n in range(v.lines[0] + 1, v.lines[1] + 1): # body lines (1-based), the heading excluded
201
+ ln = lines[n - 1] if n - 1 < len(lines) else ''
202
+ fence = fence != ln.lstrip().startswith(('```', '~~~'))
203
+ if fence or ln.lstrip().startswith('#'):
204
+ continue
205
+ found = []
206
+ for m in DOC_NUM.finditer(ln):
207
+ left, right = LEFT.search(ln[: m.start()]), RIGHT.match(ln[m.end() :])
208
+ keys = [left.group(1)] if left else []
209
+ if right and not (left and left.group(2)):
210
+ keys.append(right.group(1))
211
+ keys = [k.split('::')[-1] for k in keys if _key_ok(k.split('::')[-1])]
212
+ found.append((m.group(1), keys, {left.group(1)} if left else set()))
213
+ if not found:
214
+ continue
215
+ paths = set().union(*(p for _, _, p in found))
216
+ marked = [next(x for x in m.groups() if x) for m in MARKUP.finditer(ln)]
217
+ # `**goal 22**` is a claim, `replay::FORMAT` (in `FORMAT is 9`) a key, `BASE_RADIUS` a constant
218
+ marked = [
219
+ x for x in marked if not DOC_NUM.search(x) and x not in paths and not re.fullmatch(r'[A-Z0-9_]+', x)
220
+ ]
221
+ entries = tuple(dict.fromkeys(marked + data.entries_in(ln) + heading))
222
+ for value, keys, _ in found:
223
+ keys = [k for k in keys if all(norm(e) != norm(k) for e in entries)]
224
+ if keys:
225
+ out.append(
226
+ Claim(ref, f'{v.file}:{n}', entries[0], keys[0], value, keys=tuple(keys), entries=entries)
227
+ )
228
+ return out
229
+
230
+
231
+ def check(data: Data, c: Claim) -> Claim:
232
+ c.key = next((k for k in c.keys if data.known(k)), c.key)
233
+ if not data.known(c.key):
234
+ c.note = 'key not in data'
235
+ return c
236
+ for e in c.entries: # the most specific named entry whose block holds the key decides
237
+ if hits := data.lookup(c.key, data.blocks(e)):
238
+ c.entry = e
239
+ break
240
+ else:
241
+ hits = data.lookup(c.key, None)
242
+ vals = {v for _, _, v in hits}
243
+ f, i, val = hits[0]
244
+ if len(vals) == 1 and numbers(c.value) & numbers(val):
245
+ c.status, c.data, c.where, c.note = 'match', val, f'{f}:{i + 1}', 'global'
246
+ else: # outside a named entry a differing value proves nothing (`weapons: 1` on some creature)
247
+ c.note = f'no named entry holds it; {len(vals)} value(s) elsewhere'
248
+ return c
249
+ vals = {v for _, _, v in hits}
250
+ f, i, val = next(((f, i, v) for f, i, v in hits if numbers(c.value) & numbers(v)), hits[0])
251
+ c.data, c.where = val, f'{f}:{i + 1}'
252
+ if numbers(c.value) & numbers(val):
253
+ c.status, c.note = 'match', 'entry'
254
+ elif len(vals) > 1:
255
+ c.note = f'{len(vals)} different values in the entry'
256
+ elif (k := _scaled(c.value, val)) is not None:
257
+ c.note = f'data {val} (x{10**k:g} = {c.value}? derived)'
258
+ else:
259
+ c.status, c.note = 'mismatch', 'entry'
260
+ return c
261
+
262
+
263
+ def _item_name(text: str) -> str:
264
+ text = re.sub(r'[*`_\[\]]', '', text)
265
+ return re.split(r'\s+[—–-]\s+|:|\(|,', text, maxsplit=1)[0].strip()
266
+
267
+
268
+ def groups(cfg: Config, idx: Index, data: Data, refs: list[str]) -> list[Claim]: # noqa: C901 - one pass per line
269
+ """Check counts ("Uncommon (33)") against the data, and list items under the group against the group's value."""
270
+ out = []
271
+ texts: dict[str, list[str]] = {}
272
+ for ref in refs:
273
+ v = idx.views[ref]
274
+ lines = texts.setdefault(v.file, (cfg.root / v.file).read_text(encoding='utf-8').split('\n'))
275
+ rows = range(v.lines[0], v.lines[1] + 1) # heading line included: "### Uncommon (33)"
276
+ for n in rows:
277
+ ln = lines[n - 1] if n - 1 < len(lines) else ''
278
+ if BULLET.match(ln) and not ln.rstrip().endswith(':'):
279
+ continue # items are checked under their group line
280
+ for m in GROUP.finditer(ln):
281
+ word, count = (m.group(1), m.group(2)) if m.group(1) else (m.group(4), m.group(3))
282
+ by_key: dict[str, list[tuple[str, int]]] = defaultdict(list)
283
+ for f, i, k, _ in data.syms.get(norm(word), []):
284
+ if k not in data.id_keys:
285
+ by_key[k].append((f, i))
286
+ if not by_key:
287
+ continue
288
+ c = Claim(ref, f'{v.file}:{n}', word, 'count', count, keys=tuple(by_key))
289
+ hit = next((k for k, locs in by_key.items() if len(locs) == int(count)), None)
290
+ if hit:
291
+ c.status, c.key, c.data, c.note = 'match', f'count({hit}: {word})', count, 'count'
292
+ elif len(by_key) == 1:
293
+ ((k, locs),) = by_key.items()
294
+ f, i = locs[0]
295
+ c.status, c.key, c.data, c.where = 'mismatch', f'count({k}: {word})', str(len(locs)), f'{f}:{i + 1}'
296
+ c.note = 'count'
297
+ else:
298
+ c.note = f'{word} is a value of {len(by_key)} fields'
299
+ out.append(c)
300
+ if len(by_key) == 1:
301
+ out += _members(ref, v.file, lines, n, ln[m.end() :], word, next(iter(by_key)), data)
302
+ return out
303
+
304
+
305
+ def _members(ref: str, file: str, lines: list[str], n: int, rest: str, word: str, key: str, data: Data) -> list[Claim]:
306
+ """List items of a group (inline after ':' or the bullets below) whose data entry has another value of key."""
307
+ items = [(n, x) for x in rest.split(':', 1)[1].split(',')] if ':' in rest else []
308
+ j = n # 1-based line after the group line
309
+ while j < len(lines) and (not lines[j].strip() or BULLET.match(lines[j]) or ANCHOR.match(lines[j])):
310
+ if b := BULLET.match(lines[j]):
311
+ items.append((j + 1, b.group(1)))
312
+ j += 1
313
+ out = []
314
+ for ln, text in items:
315
+ name = _item_name(text)
316
+ blocks = data.blocks(name) if norm(name) in data.names else []
317
+ vals = data.field_in(blocks, key)
318
+ if not vals:
319
+ continue
320
+ hit = next(((f, i, v) for f, i, v in vals if norm(v) == norm(word)), None)
321
+ f, i, v = hit or vals[0]
322
+ c = Claim(ref, f'{file}:{ln}', name, key, word, data=v, where=f'{f}:{i + 1}', note='group member')
323
+ c.status = 'match' if hit else 'mismatch'
324
+ out.append(c)
325
+ return out
326
+
327
+
328
+ def verify(cfg: Config, idx: Index, targets: list[str]) -> dict:
329
+ refs = []
330
+ for t in targets or list(cfg.stores):
331
+ if t in cfg.stores or '.' in t and cfg.family(t):
332
+ refs += [r for r, v in idx.views.items() if v.store in cfg.family(t)]
333
+ elif len(m := idx.resolve(t)) == 1:
334
+ refs += [r for r in idx.views if r == m[0] or r.startswith(m[0] + '.')]
335
+ else:
336
+ raise DPError(f'{t}: not a store or a unique section ref')
337
+ refs = [r for r in dict.fromkeys(refs) if not idx.is_history(r)]
338
+ data = Data(cfg)
339
+ rows = [check(data, c) for c in claims(cfg, idx, data, refs)] + groups(cfg, idx, data, refs)
340
+ count = {s: sum(r.status == s for r in rows) for s in ('mismatch', 'match', 'unresolved')}
341
+ files = ', '.join(Path(f).name for f in data.files) if len(data.files) <= 5 else f'{len(data.files)} files'
342
+ lines = [
343
+ f'Verified {len(refs)} section(s) against {files}: {count["mismatch"]} mismatch, {count["match"]} match, '
344
+ f'{count["unresolved"]} unresolved (history sections skipped)'
345
+ ]
346
+ lines += [
347
+ f'- mismatch {r.ref} [{r.line}] {r.entry} {r.key} = {r.value}, data: {r.data} [{r.where}]'
348
+ for r in rows
349
+ if r.status == 'mismatch'
350
+ ]
351
+ claims_ = [{k: v for k, v in r.__dict__.items() if k not in ('keys', 'entries')} for r in rows]
352
+ return {'ok': True, 'counts': count, 'claims': claims_, 'lines': lines}
diffpilot/verify.pyi ADDED
@@ -0,0 +1,58 @@
1
+ from _typeshed import Incomplete
2
+ from dataclasses import dataclass
3
+ from diffpilot.config import Config as Config, DPError as DPError
4
+ from diffpilot.index import Index as Index
5
+ from diffpilot.store import ANCHOR as ANCHOR
6
+
7
+ NUM: str
8
+ DOC_NUM: Incomplete
9
+ LEFT: Incomplete
10
+ RIGHT: Incomplete
11
+ DATA_PAIR: Incomplete
12
+ DATA_SYM: Incomplete
13
+ FIELD: Incomplete
14
+ TOKEN: Incomplete
15
+ MARKUP: Incomplete
16
+ WORD: Incomplete
17
+ GROUP: Incomplete
18
+ BULLET: Incomplete
19
+ MAX_BLOCKS: int
20
+ STOP: Incomplete
21
+
22
+ @dataclass
23
+ class Claim:
24
+ ref: str
25
+ line: str
26
+ entry: str | None
27
+ key: str
28
+ value: str
29
+ keys: tuple[str, ...] = ...
30
+ entries: tuple[str, ...] = ...
31
+ status: str = ...
32
+ data: str = ...
33
+ where: str = ...
34
+ note: str = ...
35
+
36
+ def norm(name: str) -> str: ...
37
+ def numbers(value: str) -> set[float]: ...
38
+
39
+ class Data:
40
+ files: dict[str, list[str]]
41
+ aliases: Incomplete
42
+ nums: dict[str, list[tuple[str, int, str]]]
43
+ syms: dict[str, list[tuple[str, int, str, str]]]
44
+ fields: set[str]
45
+ names: Incomplete
46
+ id_keys: Incomplete
47
+ def __init__(self, cfg: Config) -> None: ...
48
+ def keys(self, key: str) -> set[str]: ...
49
+ def known(self, key: str) -> bool: ...
50
+ def blocks(self, entry: str) -> list[tuple[str, int, int]]: ...
51
+ def lookup(self, key: str, blocks: list[tuple[str, int, int]] | None) -> list[tuple[str, int, str]]: ...
52
+ def field_in(self, blocks: list[tuple[str, int, int]], key: str) -> list[tuple[str, int, str]]: ...
53
+ def entries_in(self, text: str) -> list[str]: ...
54
+
55
+ def claims(cfg: Config, idx: Index, data: Data, refs: list[str]) -> list[Claim]: ...
56
+ def check(data: Data, c: Claim) -> Claim: ...
57
+ def groups(cfg: Config, idx: Index, data: Data, refs: list[str]) -> list[Claim]: ...
58
+ def verify(cfg: Config, idx: Index, targets: list[str]) -> dict: ...
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: diffpilot
3
+ Version: 0.0.1
4
+ Summary: Project memory CLI for coding agents: requirements, rationale, instructions and changelog, powered by Codex
5
+ Author-email: Aleksei Marusich <aleksei.marusich@rocshers.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://projects.rocshers.com/open-source/diffpilot
8
+ Project-URL: Repository, https://gitlab.com/rocshers/python/diffpilot
9
+ Keywords: ai,development
10
+ Requires-Python: >=3.14
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: filelock>=3.16.1
13
+ Requires-Dist: pydantic>=2.14.3
14
+ Requires-Dist: pydantic-ai-slim[openai,typesafe]>=2.68.0
15
+ Requires-Dist: rich>=15.0.0
16
+ Requires-Dist: typer>=0.29.1
17
+
18
+ # diffpilot - project memory for coding agents
19
+
20
+ [![PyPI](https://img.shields.io/pypi/v/diffpilot)](https://pypi.org/project/diffpilot/)
21
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/diffpilot)](https://pypi.org/project/diffpilot/)
22
+
23
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=rocshers_diffpilot&metric=coverage)](https://sonarcloud.io/summary/new_code?id=rocshers_diffpilot)
24
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rocshers_diffpilot&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=rocshers_diffpilot)
25
+
26
+ [![Downloads](https://pypi.rocshers.com/badges/svg/packages/diffpilot/downloads/total)](https://clickpy.clickhouse.com/dashboard/diffpilot)
27
+ [![GitLab stars](https://img.shields.io/gitlab/stars/rocshers/python/diffpilot)](https://gitlab.com/rocshers/python/diffpilot)
28
+ [![GitLab last commit](https://img.shields.io/gitlab/last-commit/rocshers/python/diffpilot)](https://gitlab.com/rocshers/python/diffpilot)
29
+
30
+ Project memory for coding agents. The agent says *what changed and why*; diffpilot (its own small agent on a Codex
31
+ subscription) finds where it belongs in the docs, edits surgically, logs the change and keeps the changelog — and
32
+ answers questions about requirements and past decisions with citations, without bossing the calling agent around.
33
+
34
+ ## Features
35
+
36
+ - Three Markdown stores with stable section IDs: `docs/PRD.md` (current product vision), `docs/implementation.md`
37
+ (how and why), `docs/instructions.md` (project rules), plus `docs/CHANGELOG.md`.
38
+ - Optional PRD categories: `[prd_categories] mobs = "..."` keeps the details of an area in `docs/prd/mobs.md`, while
39
+ `PRD.md` holds the overview. An existing spec (a bestiary, a tower roster) is adopted in place, losslessly and
40
+ without bootstrap extraction: `mobs = { scope = "...", path = "docs/mobs.md" }`. A spec written as one big nested
41
+ bullet list is split into heading sections (one per top-level item with sub-items, recursively, while a section
42
+ is over 2000 characters), so each creature gets its own section and ID.
43
+ - Optional [Jev](https://openrouter.ai/typesafe) (TypeSafe's decision model, via OpenRouter) reranks retrieval and
44
+ routes input to stores: better context for fewer tokens. Falls back to BM25 without a key.
45
+ - `note` captures decisions instantly during work; `finish` integrates them (plus the git diff) at the end of the task.
46
+ - `record` writes immediately, routed to the right store(s); `prd` / `impl` / `instruct` force one. Edits are validated ops, never
47
+ free-form rewrites; every write becomes a change event with before/after text and the reason.
48
+ - `ask` and `brief` answer from the stores (and code) with citations; records are presented as context, not orders.
49
+ - `init --bootstrap` seeds the stores from existing docs, with quote verification and safe, incremental re-runs.
50
+ - `git_diff_changelog_summary` turns git diff + recorded changes into one clean changelog entry.
51
+ - `AGENTS.md` gets a `## diffpilot` section (how to use the tool) and, via `update_agentsmd`, a `## diffpilot - resume`
52
+ of project essentials that never repeats what the file already says.
53
+ - Free, instant lookups without an LLM: `outline`, `show`, `search`, `log`.
54
+
55
+ ## Quick start
56
+
57
+ Requires a Codex login (`codex login`, ChatGPT subscription) — credentials are read from `$CODEX_HOME/auth.json`.
58
+
59
+ ```bash
60
+ uvx diffpilot init --bootstrap # global + project config, stores (seeded from existing docs), ## diffpilot in AGENTS.md
61
+ uvx diffpilot brief "Add 6 cards to the shop"
62
+ uvx diffpilot note "Shop shows 6 cards instead of 4; 2 slots are seasonal offers (user request)." # instant
63
+ uvx diffpilot finish # end of task: notes + git diff → docs, reviewed
64
+ uvx diffpilot ask "What are the shop requirements?"
65
+ uvx diffpilot git_diff_changelog_summary --write --version 1.2.0
66
+ uvx diffpilot update_agentsmd
67
+ ```
68
+
69
+ Configuration: global `~/.diffpilot/diffpilot.toml` (auth — Codex home, OpenRouter key —, models, Jev; shared by all
70
+ projects) overridden key by key by the project's `diffpilot.toml` (paths, PRD categories, behavior).
71
+ Every command supports `--json`. Exit codes: 0 ok, 1 usage/config, 2 Codex auth, 3 LLM failure (input kept in the
72
+ inbox, retry with `diffpilot inbox --process`), 4 invalid model output (nothing written), 5 lock busy.
73
+
74
+ diffpilot documents itself: requirements, design rationale and project rules live in [docs/](docs/) and are
75
+ maintained with diffpilot.
76
+
77
+ ## Contribute
78
+
79
+ Issue Tracker: <https://gitlab.com/rocshers/python/diffpilot/-/issues>
80
+ Source Code: <https://gitlab.com/rocshers/python/diffpilot>
@@ -0,0 +1,42 @@
1
+ diffpilot/__init__.py,sha256=1CZ3JFogEV5nw-UGs9Fap1LRuJaif4qUfwJ6RJ4pnO8,320
2
+ diffpilot/__init__.pyi,sha256=End4swHQChAJGVB9GQffpBTIaefKA0GHbWtTwjXim0c,58
3
+ diffpilot/__main__.py,sha256=dz9O7VWqBDo0cWgIQRsAiANl8Wnv8O4RIndNS6hwhnc,39
4
+ diffpilot/__main__.pyi,sha256=tbiDJAwcOBz4ODDaLdZ2zeOsmAUG7FBBld5IvtAUBBw,39
5
+ diffpilot/agents.py,sha256=3bhKgvpHbOjmGvIiq3Cn29JrSYGb98G9h4FfQTkIcAU,17317
6
+ diffpilot/agents.pyi,sha256=kSsfsDK9oF8cq23jZ-ap08F2orwzglLZNZj44n5nVPs,3182
7
+ diffpilot/agentsmd.py,sha256=Wvme0CFhZ1VE_ZMgTIBPGlvsaro-ElF1XURqIwHr_YM,4127
8
+ diffpilot/agentsmd.pyi,sha256=m6DnbdVVD8DBrRTBYNQ91h57uHSGz8qSvKPD2T04AqM,433
9
+ diffpilot/bootstrap.py,sha256=3H9OUdhjOhlxX6BfVZWKILtf5fxEEb7ZPDU70fyXxHw,18938
10
+ diffpilot/bootstrap.pyi,sha256=7n4JUdV_IlJpTWBJmBkqIoniV51jNjYhU9VlZ8IkEd8,1679
11
+ diffpilot/cli.py,sha256=kA4EBOUzBASg9QdQwuAhWwe65NTR3Z4b2mO1b9i5hIQ,30185
12
+ diffpilot/cli.pyi,sha256=K6UuxWg9bFHo6nvuhsWCQZOv7VzQP6pcA9UjoJ_ZTQo,4059
13
+ diffpilot/config.py,sha256=QALCetFUDUM2BJmXRNNjUiocP625xHMcww2rc9wfols,14257
14
+ diffpilot/config.pyi,sha256=n_XxuUdMewjHZFctLHDVHKoY8qOLN_MSxFMZHgffS6k,2781
15
+ diffpilot/core.py,sha256=F8_jQ1ZDy4hWnMcD3Pzgg9cDJfJaUa3DNU4agnSmtks,14342
16
+ diffpilot/core.pyi,sha256=rGHbVQ3Vyq-vi9ByDAyan9g2Sqr_NQa2xF0dR2dJGHo,1608
17
+ diffpilot/events.py,sha256=195sr-OpdxBM6Q41RaPFvNpsG3n7zEsQYkgpWDVmSPw,5776
18
+ diffpilot/events.pyi,sha256=67rkdCZdKXcOyB767Iudqveb_WwANHypMsVIwfxTx2U,1267
19
+ diffpilot/gitdiff.py,sha256=w7KwjX5HZtGGwA6zlB_YzM4i67BOG5lZcxlojV4TBYs,6484
20
+ diffpilot/gitdiff.pyi,sha256=KEXmpfvXRwEBuTMJZKMbEP6LV33j1K4mZPHKteieWSc,703
21
+ diffpilot/index.py,sha256=t9WOdjpgWuTFkdpzu1q85TgLZu4f0Wn8-EJxnZSjC50,9191
22
+ diffpilot/index.pyi,sha256=gH2hxAbV5P6QOXQtf2AfXk-0Q0rCSxa2mheAKyfJ9w8,1694
23
+ diffpilot/jev.py,sha256=qaKCOqJo7P3GC_xdf8qfp5T6m1GXU1ClWGscNXEyW5U,9332
24
+ diffpilot/jev.pyi,sha256=XdnVIOhaEjD1pZcVEBAtxu8hKrkBZg9KjJK92BlF_xA,1473
25
+ diffpilot/llm.py,sha256=_wtRu9DJN2AO-1sUQwYKBAQT13Tne8H0kcYZdwxzCMk,5982
26
+ diffpilot/llm.pyi,sha256=hxZAMEkbIK6gnT-19HhkJ95Yh80M3uE8TZ8wJupdPX4,1029
27
+ diffpilot/ops.py,sha256=hyBxxNhI_19LthNXk-FBM7Lsd2-p_djrce6mJUCoHrk,12427
28
+ diffpilot/ops.pyi,sha256=wz4Ti_EpNwWCSNpJtpaCx1lI89PvtpUZPoK5XWGVZuo,1501
29
+ diffpilot/prompts.py,sha256=NC8kTLyBbrZwysBY3J83LU9n3mSejG_0tH2_yIG9PU4,19745
30
+ diffpilot/prompts.pyi,sha256=Cg8bbMjMAuNeqneCjiSSrSr_u-UyYcOfxHO2WZBtsms,470
31
+ diffpilot/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
+ diffpilot/schemas.py,sha256=VqG93cQ6ISpq2g3HCCgBaj2kL4iXFYBuzWimtTEuQz4,3902
33
+ diffpilot/schemas.pyi,sha256=TvskErsP4ketnkiA9O1B68KTRNfcAkxNq66ztqlHsow,1896
34
+ diffpilot/store.py,sha256=nBE1Dt5xz_Hm-ItpqQQ18A_vO7OsdPOy4VlrtSHXOj0,12494
35
+ diffpilot/store.pyi,sha256=MF3CyEE5mB1kuiTHUtc6g5po9s4zlM6DD5x9qKNZu_s,1267
36
+ diffpilot/verify.py,sha256=0ca0CFznDF5yUBwVuK3GC6daCb0qftxJpUW9Paxvgyw,16951
37
+ diffpilot/verify.pyi,sha256=xwYXjW87-F7GvCVctbsoGocuoEuYyFZmkwcnmQcdmYg,1795
38
+ diffpilot-0.0.1.dist-info/METADATA,sha256=blSlFvsnjy0QjWnFp1nntAB1XuHhbwsCDeenaMvJhNQ,5295
39
+ diffpilot-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
40
+ diffpilot-0.0.1.dist-info/entry_points.txt,sha256=RFU7zdQ5M1tZwCHa1Z2RaCL3YJm7bbcdXsbffSm9ycY,49
41
+ diffpilot-0.0.1.dist-info/top_level.txt,sha256=TI-mpEPJ5-NJ2HECRUVwjMHxxY2wV_CIVbEmppt741U,10
42
+ diffpilot-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ diffpilot = diffpilot.cli:main
@@ -0,0 +1 @@
1
+ diffpilot