klyd 0.2.0__tar.gz → 0.2.2__tar.gz
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.
- {klyd-0.2.0/klyd.egg-info → klyd-0.2.2}/PKG-INFO +4 -2
- {klyd-0.2.0 → klyd-0.2.2}/README.md +403 -401
- {klyd-0.2.0 → klyd-0.2.2}/klyd/cli.py +11 -15
- {klyd-0.2.0 → klyd-0.2.2}/klyd/extractor.py +14 -6
- {klyd-0.2.0 → klyd-0.2.2/klyd.egg-info}/PKG-INFO +4 -2
- {klyd-0.2.0 → klyd-0.2.2}/pyproject.toml +1 -1
- {klyd-0.2.0 → klyd-0.2.2}/AGENTS.md.txt +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/LICENSE +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/MANIFEST.in +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/hooks/post-commit.sh +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/hooks/pre-commit.sh +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd/__init__.py +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd/config.py +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd/db.py +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd/hooks.py +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd/injector.py +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd.egg-info/SOURCES.txt +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd.egg-info/dependency_links.txt +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd.egg-info/entry_points.txt +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd.egg-info/requires.txt +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/klyd.egg-info/top_level.txt +0 -0
- {klyd-0.2.0 → klyd-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: klyd
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A CLI tool that wraps coding agents via git hooks to inject architectural memory.
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -14,14 +14,16 @@ Dynamic: license-file
|
|
|
14
14
|
|
|
15
15
|
<p align="center">
|
|
16
16
|
|
|
17
|
+
```
|
|
17
18
|
888 / 888 Y88b / 888~-_
|
|
18
19
|
888 / 888 Y88b / 888 \
|
|
19
20
|
888/\ 888 Y88b/ 888 |
|
|
20
21
|
888 \ 888 Y8Y 888 |
|
|
21
22
|
888 \ 888 Y 888 /
|
|
22
23
|
888 \ 888____ / 888_-~
|
|
24
|
+
```
|
|
23
25
|
|
|
24
|
-
*An open-source project, not affiliated with the Klyd SaaS*
|
|
26
|
+
#### *An open-source project, not affiliated with the Klyd SaaS*
|
|
25
27
|
|
|
26
28
|
</p>
|
|
27
29
|
|
|
@@ -1,401 +1,403 @@
|
|
|
1
|
-
# klyd
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
888
|
|
7
|
-
888
|
|
8
|
-
888
|
|
9
|
-
888
|
|
10
|
-
888
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- **
|
|
42
|
-
- **
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
-
|
|
141
|
-
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
- **
|
|
199
|
-
- **
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
- **
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
#
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
│ ├──
|
|
338
|
-
│
|
|
339
|
-
├── .
|
|
340
|
-
│
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
-
|
|
390
|
-
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
1
|
+
# klyd
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
888 / 888 Y88b / 888~-_
|
|
7
|
+
888 / 888 Y88b / 888 \
|
|
8
|
+
888/\ 888 Y88b/ 888 |
|
|
9
|
+
888 \ 888 Y8Y 888 |
|
|
10
|
+
888 \ 888 Y 888 /
|
|
11
|
+
888 \ 888____ / 888_-~
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
#### *An open-source project, not affiliated with the Klyd SaaS*
|
|
15
|
+
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## What is klyd?
|
|
21
|
+
|
|
22
|
+
klyd is a **decision memory harness** for terminal coding agents (aider, opencode, claude code). It wraps your agent workflow to inject persistent architectural memory into every session.
|
|
23
|
+
|
|
24
|
+
### The Problem
|
|
25
|
+
|
|
26
|
+
Agentic coding tools fail in a specific, reproducible way:
|
|
27
|
+
|
|
28
|
+
1. Agent writes a file
|
|
29
|
+
2. Something breaks (test, CI)
|
|
30
|
+
3. Agent patches the nearest thing to make the signal go green
|
|
31
|
+
4. It doesn't fix the root — it satisfies the metric
|
|
32
|
+
5. Next session: agent reads the patched code as ground truth, builds on top of it
|
|
33
|
+
6. After ~20 turns: **slop fortress** — a codebase that compiles but nobody understands
|
|
34
|
+
|
|
35
|
+
This is not a model quality problem. It's a **memory and context architecture problem**.
|
|
36
|
+
|
|
37
|
+
### The Solution
|
|
38
|
+
|
|
39
|
+
klyd extracts architectural decisions from every commit and injects them into your agent's context at the exact moment of file write — when architectural damage happens.
|
|
40
|
+
|
|
41
|
+
- **Two LLM calls per commit cycle maximum**
|
|
42
|
+
- **All state lives in `.klyd/`** (local to your repo)
|
|
43
|
+
- **BYOK** — bring your own API key
|
|
44
|
+
- **Zero infrastructure** — no cloud, no servers
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# From PyPI (recommended)
|
|
52
|
+
pip install klyd
|
|
53
|
+
|
|
54
|
+
# Or from source
|
|
55
|
+
pip install .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
After installation, verify:
|
|
59
|
+
```bash
|
|
60
|
+
kl --help
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Quickstart
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# 1. Initialize in your project repository
|
|
69
|
+
cd your-project
|
|
70
|
+
kl init
|
|
71
|
+
|
|
72
|
+
# 2. Configure your API key
|
|
73
|
+
kl config --api-key sk-ant-...
|
|
74
|
+
|
|
75
|
+
# 3. Make commits with architectural decisions
|
|
76
|
+
# (e.g., adding auth, changing DB, adopting a new library)
|
|
77
|
+
|
|
78
|
+
# 4. Check extracted decisions
|
|
79
|
+
kl status
|
|
80
|
+
|
|
81
|
+
# 5. Run your agent with injected memory
|
|
82
|
+
kl run aider
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
klyd supports multiple LLM providers via BYOK (Bring Your Own Key).
|
|
90
|
+
|
|
91
|
+
### Anthropic (Default)
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
kl config --api-key sk-ant-... --model claude-sonnet-4-6
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### OpenAI
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
kl config --openai-key sk-proj-... --model gpt-4o
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### OpenRouter
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
kl config --openrouter-key sk-or-... --model openrouter/free
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Google Gemini
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
kl config --gemini-key AIza... --model gemini-1.5-pro
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Groq
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
kl config --groq-key gsk_... --model llama3-8b-8192
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### View Current Configuration
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
kl config --show
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Commands
|
|
130
|
+
|
|
131
|
+
### `kl init`
|
|
132
|
+
|
|
133
|
+
Initialize klyd in the current git repository.
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
kl init
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
This:
|
|
140
|
+
- Creates `.klyd/` directory
|
|
141
|
+
- Initializes SQLite database at `.klyd/memory.db`
|
|
142
|
+
- Installs git hooks (post-commit, pre-commit)
|
|
143
|
+
- Creates default config at `.klyd/config.json`
|
|
144
|
+
|
|
145
|
+
### `kl config`
|
|
146
|
+
|
|
147
|
+
Configure klyd settings.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Set API key
|
|
151
|
+
kl config --api-key sk-ant-...
|
|
152
|
+
|
|
153
|
+
# Set model
|
|
154
|
+
kl config --model claude-sonnet-4-6
|
|
155
|
+
|
|
156
|
+
# Show current config
|
|
157
|
+
kl config --show
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### `kl status`
|
|
161
|
+
|
|
162
|
+
View the current decision memory store.
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
kl status
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Shows:
|
|
169
|
+
- Active decisions (sorted by reinforcement count)
|
|
170
|
+
- Confidence levels (HIGH/MEDIUM/LOW)
|
|
171
|
+
- Event types (NEW/REINFORCE/CONTRADICT)
|
|
172
|
+
- Flagged conflicts requiring review
|
|
173
|
+
|
|
174
|
+
### `kl run <agent>`
|
|
175
|
+
|
|
176
|
+
Run a coding agent with injected architectural memory.
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
kl run aider --message "Add user authentication"
|
|
180
|
+
kl run opencode
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Options:
|
|
184
|
+
- `--no-inject` - Skip generating injection file
|
|
185
|
+
|
|
186
|
+
The agent receives your stored architectural decisions as context, preventing contradiction of established patterns.
|
|
187
|
+
|
|
188
|
+
### `kl review`
|
|
189
|
+
|
|
190
|
+
Review flagged conflicting decisions.
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
kl review
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
When klyd detects a CONTRADICT (a new decision that conflicts with existing memory), it flags it for human review. This interactive command lets you:
|
|
197
|
+
|
|
198
|
+
- **Accept** new decision (archive old)
|
|
199
|
+
- **Reject** new decision (keep old)
|
|
200
|
+
- **Edit** decision manually
|
|
201
|
+
- **Skip** for now
|
|
202
|
+
|
|
203
|
+
### `kl extract-commit`
|
|
204
|
+
|
|
205
|
+
Manually trigger decision extraction for the last commit.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
kl extract-commit
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Usually called automatically by the post-commit hook.
|
|
212
|
+
|
|
213
|
+
### `kl prepare-injection`
|
|
214
|
+
|
|
215
|
+
Generate the injection file for agent sessions.
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
kl prepare-injection
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Usually called automatically by the pre-commit hook. Outputs to `.klyd/injection.txt`.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## How It Works
|
|
226
|
+
|
|
227
|
+
### Git Hooks
|
|
228
|
+
|
|
229
|
+
klyd installs two git hooks:
|
|
230
|
+
|
|
231
|
+
**post-commit** (`hooks/post-commit.sh`):
|
|
232
|
+
```bash
|
|
233
|
+
#!/bin/sh
|
|
234
|
+
kl extract-commit >> .klyd/errors.log 2>&1 || true
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
After every commit, extracts architectural decisions via LLM and stores them in SQLite.
|
|
238
|
+
|
|
239
|
+
**pre-commit** (`hooks/pre-commit.sh`):
|
|
240
|
+
```bash
|
|
241
|
+
#!/bin/sh
|
|
242
|
+
kl prepare-injection >> .klyd/errors.log 2>&1 || true
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Before files are committed, queries relevant decisions and writes injection file.
|
|
246
|
+
|
|
247
|
+
### Extraction Flow
|
|
248
|
+
|
|
249
|
+
1. Get diff: `git diff HEAD~1 HEAD`
|
|
250
|
+
2. Get commit message: `git log -1 --format=%B`
|
|
251
|
+
3. Get touched files
|
|
252
|
+
4. Query existing decisions for those files
|
|
253
|
+
5. Call LLM with prompt
|
|
254
|
+
6. Store results:
|
|
255
|
+
- **NEW** → `store_decision()`
|
|
256
|
+
- **REINFORCE** → `reinforce_decision()` on matching existing
|
|
257
|
+
- **CONTRADICT** → `store_decision()` with `flagged=True`
|
|
258
|
+
|
|
259
|
+
### Injection Flow
|
|
260
|
+
|
|
261
|
+
1. Get staged files: `git diff --cached --name-only`
|
|
262
|
+
2. Query top-k decisions for those files (excludes flagged, archived)
|
|
263
|
+
3. Format as injection message
|
|
264
|
+
4. Write to `.klyd/injection.txt`
|
|
265
|
+
|
|
266
|
+
### Decision Schema
|
|
267
|
+
|
|
268
|
+
```sql
|
|
269
|
+
CREATE TABLE decisions (
|
|
270
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
271
|
+
decision TEXT NOT NULL,
|
|
272
|
+
module TEXT NOT NULL,
|
|
273
|
+
file_patterns TEXT NOT NULL,
|
|
274
|
+
confidence TEXT NOT NULL, -- LOW | MEDIUM | HIGH
|
|
275
|
+
event_type TEXT NOT NULL, -- NEW | REINFORCE | CONTRADICT
|
|
276
|
+
reinforcement_count INTEGER DEFAULT 1,
|
|
277
|
+
last_seen_commit TEXT,
|
|
278
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
279
|
+
flagged INTEGER DEFAULT 0, -- 1 = needs human review
|
|
280
|
+
archived INTEGER DEFAULT 0 -- 1 = soft-deleted
|
|
281
|
+
);
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Examples
|
|
287
|
+
|
|
288
|
+
### Example 1: First-Time Setup
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
$ cd my-project
|
|
292
|
+
$ kl init
|
|
293
|
+
|
|
294
|
+
# Configure with your API key
|
|
295
|
+
$ kl config --api-key sk-ant-...
|
|
296
|
+
|
|
297
|
+
# Make your first architectural commit
|
|
298
|
+
$ echo "import sqlite3" > db.py
|
|
299
|
+
$ git add db.py && git commit -m "feat: add sqlite for data storage"
|
|
300
|
+
|
|
301
|
+
# Check extracted decisions
|
|
302
|
+
$ kl status
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Example 2: Resolving Conflicts
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
# Make a commit that contradicts existing decision
|
|
309
|
+
$ echo "import mongoengine" > nosql.py
|
|
310
|
+
$ git add nosql.py && git commit -m "feat: switch to mongodb"
|
|
311
|
+
|
|
312
|
+
# LLM detects contradiction, flags for review
|
|
313
|
+
$ kl status
|
|
314
|
+
# Shows flagged decision in NEEDS REVIEW section
|
|
315
|
+
|
|
316
|
+
$ kl review
|
|
317
|
+
# Interactive resolution
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Example 3: Running Agent with Memory
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
# Inject memory and run aider
|
|
324
|
+
$ kl run aider --message "Add user login to the app"
|
|
325
|
+
|
|
326
|
+
# Agent receives your architectural decisions as context
|
|
327
|
+
# Won't contradict established patterns (e.g., "use SQLite, not sessions")
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## File Structure
|
|
333
|
+
|
|
334
|
+
```
|
|
335
|
+
your-project/
|
|
336
|
+
├── .klyd/ # klyd's working directory
|
|
337
|
+
│ ├── memory.db # SQLite decision store
|
|
338
|
+
│ ├── config.json # Your API keys & settings
|
|
339
|
+
│ ├── injection.txt # Generated for agent sessions
|
|
340
|
+
│ └── errors.log # Error logs
|
|
341
|
+
├── .git/hooks/
|
|
342
|
+
│ ├── post-commit # Installed by kl init
|
|
343
|
+
│ └── pre-commit # Installed by kl init
|
|
344
|
+
└── [your project files]
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## Troubleshooting
|
|
350
|
+
|
|
351
|
+
### "klyd is not initialized. Run `kl init`."
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
kl init
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### API Key Errors
|
|
358
|
+
|
|
359
|
+
Check your config:
|
|
360
|
+
```bash
|
|
361
|
+
kl config --show
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Ensure the key is correct. Errors are logged to `.klyd/errors.log`.
|
|
365
|
+
|
|
366
|
+
### No Decisions Extracted
|
|
367
|
+
|
|
368
|
+
- Make commits with clear architectural changes (not just style fixes)
|
|
369
|
+
- Ensure API key has credits/quota
|
|
370
|
+
- Check `.klyd/errors.log` for details
|
|
371
|
+
|
|
372
|
+
### Hook Not Firing
|
|
373
|
+
|
|
374
|
+
Verify hooks are installed:
|
|
375
|
+
```bash
|
|
376
|
+
ls -la .git/hooks/post-commit
|
|
377
|
+
ls -la .git/hooks/pre-commit
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
If missing, re-run:
|
|
381
|
+
```bash
|
|
382
|
+
kl init
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Requirements
|
|
388
|
+
|
|
389
|
+
- Python 3.11+
|
|
390
|
+
- click
|
|
391
|
+
- anthropic
|
|
392
|
+
- Git repository
|
|
393
|
+
|
|
394
|
+
## License
|
|
395
|
+
|
|
396
|
+
MIT License - see LICENSE file.
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Links
|
|
401
|
+
|
|
402
|
+
- PyPI: https://pypi.org/project/klyd/
|
|
403
|
+
- GitHub: https://github.com/getKlyd/klyd
|
|
@@ -159,24 +159,20 @@ def extract_commit():
|
|
|
159
159
|
klyd_dir = Path('.klyd')
|
|
160
160
|
if not (klyd_dir / 'memory.db').exists():
|
|
161
161
|
return
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
try:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
diff = subprocess.check_output(['git', 'show', 'HEAD'], text=True)
|
|
172
|
-
msg = subprocess.check_output(['git', 'log', '-1', '--format=%B'], text=True)
|
|
173
|
-
files_out = subprocess.check_output(['git', 'show', '--name-only', '--format=', 'HEAD'], text=True)
|
|
174
|
-
files = [f for f in files_out.strip().split('\n') if f]
|
|
175
|
-
commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip()
|
|
164
|
+
diff = subprocess.check_output(['git', 'show', 'HEAD'], text=True)
|
|
165
|
+
files_out = subprocess.check_output(['git', 'show', '--name-only', '--format=', 'HEAD'], text=True)
|
|
166
|
+
msg = subprocess.check_output(['git', 'log', '-1', '--format=%B'], text=True)
|
|
167
|
+
files = [f for f in files_out.strip().split('\n') if f]
|
|
168
|
+
commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip()
|
|
169
|
+
except subprocess.CalledProcessError:
|
|
170
|
+
return
|
|
176
171
|
|
|
177
|
-
|
|
178
|
-
|
|
172
|
+
if not files:
|
|
173
|
+
return
|
|
179
174
|
|
|
175
|
+
try:
|
|
180
176
|
with console.status("[bold cyan]Extracting architectural decisions via LLM...[/bold cyan]", spinner="dots12"):
|
|
181
177
|
db_path = str(klyd_dir / 'memory.db')
|
|
182
178
|
existing = get_decisions_for_files(db_path, files, top_k=20)
|
|
@@ -44,7 +44,8 @@ Rules:
|
|
|
44
44
|
- Only record if the diff explicitly introduces, changes, or contradicts a decision
|
|
45
45
|
- Do not guess. Do not infer. Only record what is clearly shown in the diff.
|
|
46
46
|
- If the commit is a style fix, test update, or minor refactor with no architectural significance: return []
|
|
47
|
-
-
|
|
47
|
+
- IMPORTANT: A NEW decision should be recorded when the commit introduces a different architectural choice than previously recorded, even if both are in the same project. For example: first commit uses Click, second commit adds SQLite - these are NEW decisions about different architectural choices (CLI framework, database). Only classify as REINFORCE if the commit explicitly confirms or repeats the SAME decision (e.g., adding another Click-based command).
|
|
48
|
+
- For each decision, classify as NEW (new architectural choice), REINFORCE (confirms SAME existing decision), or CONTRADICT (conflicts with an existing decision)
|
|
48
49
|
- Assign confidence: HIGH (unmistakable from diff), MEDIUM (clear but could have context), LOW (possible but uncertain)
|
|
49
50
|
- If this commit contradicts any of the listed invariants, set event_type to 'CONTRADICT' and add a note in the 'decision' field describing the violation. Otherwise, proceed with NEW or REINFORCE as before.
|
|
50
51
|
|
|
@@ -64,19 +65,26 @@ DIFF:
|
|
|
64
65
|
|
|
65
66
|
Existing architectural invariants (do not violate unless explicitly instructed):
|
|
66
67
|
{invariants_text}
|
|
67
|
-
"""
|
|
68
|
+
"""
|
|
68
69
|
try:
|
|
69
70
|
# Determine provider
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
is_anthropic_model = model.startswith('claude-') or model.startswith('anthropic/')
|
|
72
|
+
|
|
73
|
+
# Direct Anthropic API if we have api_key and no other keys
|
|
74
|
+
if is_anthropic_model and 'api_key' in config_data and not any(k in config_data for k in ['openai_key', 'openrouter_key', 'gemini_key', 'groq_key']):
|
|
73
75
|
client = Anthropic(api_key=config_data['api_key'])
|
|
76
|
+
# Strip anthropic/ prefix if present
|
|
77
|
+
actual_model = model.replace('anthropic/', '')
|
|
74
78
|
response = client.messages.create(
|
|
75
|
-
model=
|
|
79
|
+
model=actual_model,
|
|
76
80
|
max_tokens=1024,
|
|
77
81
|
messages=[{"role": "user", "content": prompt}]
|
|
78
82
|
)
|
|
79
83
|
content = response.content[0].text.strip()
|
|
84
|
+
# Use OpenRouter for Anthropic models if we have openrouter_key
|
|
85
|
+
elif is_anthropic_model and 'openrouter_key' in config_data:
|
|
86
|
+
url, key = "https://openrouter.ai/api/v1/chat/completions", config_data['openrouter_key']
|
|
87
|
+
content = _call_openai_compatible(url, key, model, prompt)
|
|
80
88
|
else:
|
|
81
89
|
# OpenAI compatible providers
|
|
82
90
|
if model.startswith('gpt-') or model.startswith('o1') or model.startswith('o3'):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: klyd
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A CLI tool that wraps coding agents via git hooks to inject architectural memory.
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -14,14 +14,16 @@ Dynamic: license-file
|
|
|
14
14
|
|
|
15
15
|
<p align="center">
|
|
16
16
|
|
|
17
|
+
```
|
|
17
18
|
888 / 888 Y88b / 888~-_
|
|
18
19
|
888 / 888 Y88b / 888 \
|
|
19
20
|
888/\ 888 Y88b/ 888 |
|
|
20
21
|
888 \ 888 Y8Y 888 |
|
|
21
22
|
888 \ 888 Y 888 /
|
|
22
23
|
888 \ 888____ / 888_-~
|
|
24
|
+
```
|
|
23
25
|
|
|
24
|
-
*An open-source project, not affiliated with the Klyd SaaS*
|
|
26
|
+
#### *An open-source project, not affiliated with the Klyd SaaS*
|
|
25
27
|
|
|
26
28
|
</p>
|
|
27
29
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|