klyd 0.2.2__tar.gz → 0.2.3__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.3/MANIFEST.in ADDED
@@ -0,0 +1,4 @@
1
+ include README.md
2
+ include LICENSE
3
+ include klyd/hook_templates/*.sh
4
+ include klyd/schema/*.sql
klyd-0.2.3/PKG-INFO ADDED
@@ -0,0 +1,285 @@
1
+ Metadata-Version: 2.4
2
+ Name: klyd
3
+ Version: 0.2.3
4
+ Summary: A CLI tool that wraps coding agents via git hooks to inject architectural memory
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: click
9
+ Requires-Dist: anthropic
10
+ Requires-Dist: rich
11
+ Dynamic: license-file
12
+
13
+ <div align="center">
14
+ <img src="https://raw.githubusercontent.com/kaadipranav/kaadipranav/refs/heads/main/assets/klydnewposter.png" />
15
+ </div>
16
+
17
+ # KLYD
18
+
19
+ ### Decision memory for coding agents.
20
+
21
+ Coding agents can generate code quickly but often lose the architectural decisions that shaped a repository.
22
+
23
+ Klyd records, retrieves, and reintroduces those decisions so future agent sessions can work with the project's existing reasoning instead of repeatedly rediscovering it.
24
+
25
+ [PyPI: klyd](https://pypi.org/project/klyd/) · [GitHub](https://github.com/klyd-studio/klyd-harness) · [License: MIT](./LICENSE)
26
+
27
+ ---
28
+
29
+ ## The problem
30
+
31
+ A coding agent may know the current files but not the reasons behind them:
32
+
33
+ - why a database choice was made;
34
+ - why a workaround exists;
35
+ - why an API must remain stable;
36
+ - why a previous approach was rejected;
37
+ - which architectural constraints are non-negotiable.
38
+
39
+ Without that context, agents can produce locally plausible changes that violate the system's existing design. Over multiple sessions, a codebase accumulates conflicting architectural patterns, turning into a patchwork of fragmented decisions.
40
+
41
+ ---
42
+
43
+ ## The workflow
44
+
45
+ Klyd operates invisibly through standard Git hooks without requiring a background daemon or wrapping agent subprocesses with intrusive proxies:
46
+
47
+ ```mermaid
48
+ graph TD
49
+ A[Developer commits] --> B["post-commit hook
50
+ kl extract-commit"]
51
+ B --> C["LLM Extraction
52
+ classify: NEW / REINFORCE / CONTRADICT"]
53
+ C -->|NEW or REINFORCE| D[("SQLite Store
54
+ .klyd/memory.db")]
55
+ C -->|CONTRADICT| E["Flagged for Review
56
+ kl review"]
57
+ E -->|Resolve: Accept / Merge / Edit| D
58
+
59
+ F[Agent stages changes] --> G["pre-commit hook
60
+ kl prepare-injection"]
61
+ G --> H["Single-pass query:
62
+ glob match + cosine similarity"]
63
+ H --> D
64
+ H --> I[".klyd/injection.txt
65
+ formatted context"]
66
+ I --> J["kl run aider
67
+ context injected"]
68
+ ```
69
+
70
+ All state remains strictly local to `.klyd/` inside the target git repository.
71
+
72
+ ---
73
+
74
+ ## Example
75
+
76
+ A repository previously decided:
77
+
78
+ > Authentication must remain inside the existing WebCrypto-based boundary. External token libraries must not be introduced.
79
+
80
+ Months later, an autonomous agent tasked with fixing an auth endpoint proposes adding a third-party token parser.
81
+
82
+ Before the change is committed, Klyd inspects the staged files, retrieves the earlier decision and its rationale from `.klyd/memory.db`, and injects the constraint directly into the agent's context window. The agent refactors the code within the established WebCrypto pattern instead of introducing an incompatible dependency.
83
+
84
+ *(Note: This is an illustrative example of an architectural boundary constraint captured from commit history and reintroduced to guide subsequent agent turns).*
85
+
86
+ ---
87
+
88
+ ## Technical design
89
+
90
+ Klyd currently uses:
91
+
92
+ - **SQLite for persistent decision storage**: Embedded relational database maintaining schema versions, embeddings, and decision records.
93
+ - **Git hooks for repository lifecycle integration**: `post-commit` extracts decisions asynchronously from diffs; `pre-commit` prepares context from staged changes.
94
+ - **Semantic similarity for retrieval**: Optional vector embeddings paired with lexical glob matching for relevant context ranking.
95
+ - **Recursive decision ancestry**: Tracking parent-child relationships across decision versions using recursive Common Table Expressions.
96
+ - **Conflict resolution between related decisions**: Interactive terminal UI (`kl review`) supporting accept, reject, manual edit, and LLM-assisted decision merging.
97
+ - **Multiple model-provider integrations**: Bring-Your-Own-Key (BYOK) support for Anthropic, OpenAI, OpenRouter, Google Gemini, and Groq.
98
+ - **CLI-oriented workflow for coding-agent environments**: Direct compatibility flags for tools like `aider` and `opencode`.
99
+
100
+ ---
101
+
102
+ ## Design choice: SQLite
103
+
104
+ SQLite keeps the decision history:
105
+
106
+ - **local** to the repository or workspace;
107
+ - **inspectable** with standard SQL tools or CLI commands;
108
+ - **easy to back up** by copying `.klyd/`;
109
+ - **usable** without requiring any cloud service, daemon, or database server;
110
+ - **available** to low-latency command-line workflows and shell scripts.
111
+
112
+ The trade-off is that Klyd prioritizes local developer infrastructure and explicit Git workflow integration over centralized multi-user cloud coordination.
113
+
114
+ ---
115
+
116
+ ## Engineering details
117
+
118
+ ### In-database custom multi-glob matching
119
+
120
+ When staged files are evaluated (e.g. `auth/login.py`), Klyd must match them against comma-separated glob patterns (e.g. `auth/*, security/*`) stored in the `decisions` table. Standard SQL lacks native glob-list evaluation, and loading all rows into Python memory for full-table scanning creates unnecessary overhead.
121
+
122
+ Klyd solves this by registering a custom Python callback function (`match_files`) directly into the SQLite C-runtime using `sqlite3.Connection.create_function`:
123
+
124
+ ```python
125
+ def _match_any_file(file_patterns: str, file_list_str: str) -> int:
126
+ patterns = [p.strip() for p in file_patterns.split(",")]
127
+ files = file_list_str.split("|")
128
+ for f in files:
129
+ for p in patterns:
130
+ if fnmatch.fnmatch(f, p):
131
+ return 1
132
+ return 0
133
+
134
+ conn.create_function("match_files", 2, _match_any_file)
135
+ ```
136
+
137
+ This allows the SQLite query planner to filter rows atomically in a single pass at the database layer before sorting by relevance and recency.
138
+
139
+ ### Decision lineage with recursive CTEs
140
+
141
+ When conflicting decisions are merged or updated during human review, older decisions are soft-archived rather than overwritten. Lineage is tracked through `parent_decision_id`, allowing complete evolutionary trees to be reconstructed using recursive Common Table Expressions:
142
+
143
+ ```sql
144
+ WITH RECURSIVE ancestors(id, decision, parent_decision_id) AS (
145
+ SELECT id, decision, parent_decision_id FROM decisions WHERE id = ?
146
+ UNION ALL
147
+ SELECT d.id, d.decision, d.parent_decision_id
148
+ FROM decisions d JOIN ancestors a ON d.id = a.parent_decision_id
149
+ )
150
+ SELECT * FROM ancestors;
151
+ ```
152
+
153
+ ---
154
+
155
+ ## Quickstart
156
+
157
+ ### 1. Install Klyd
158
+
159
+ > **0.2.3 is not on PyPI yet.** The published 0.2.2 wheel is missing its hook
160
+ > templates and SQL schema, so `pip install klyd` installs a CLI that cannot
161
+ > initialise a repository. Until 0.2.3 ships, install from this branch:
162
+ >
163
+ > ```bash
164
+ > git clone -b fix/clean-install-audit https://github.com/klyd-studio/klyd-harness
165
+ > cd klyd-harness
166
+ > pip install .
167
+ > ```
168
+
169
+ Once 0.2.3 is released:
170
+
171
+ ```bash
172
+ pip install klyd
173
+ ```
174
+
175
+ ### 2. Initialize a repository
176
+
177
+ Run inside the root of your Git repository:
178
+
179
+ ```bash
180
+ kl init
181
+ ```
182
+
183
+ This creates `.klyd/memory.db`, initializes the configuration file, and installs the Git hooks into `.git/hooks/`.
184
+
185
+ ### 3. Configure a model provider
186
+
187
+ Set your preferred API key (BYOK):
188
+
189
+ ```bash
190
+ kl config --api-key sk-ant-...
191
+ # or: kl config --openai-key sk-...
192
+ # or: kl config --gemini-key ...
193
+ # or: kl config --groq-key ...
194
+ ```
195
+
196
+ Inspect active configuration:
197
+
198
+ ```bash
199
+ kl config --show
200
+ ```
201
+
202
+ ### 4. Record decisions from commits
203
+
204
+ Decisions are automatically extracted by the `post-commit` hook whenever you make a Git commit:
205
+
206
+ ```bash
207
+ git commit -m "refactor(db): use SQLite connection pooling instead of global instances"
208
+ ```
209
+
210
+ You can also trigger extraction manually for the latest commit:
211
+
212
+ ```bash
213
+ kl extract-commit
214
+ ```
215
+
216
+ ### 5. Retrieve relevant decisions
217
+
218
+ View stored architectural decisions in a table:
219
+
220
+ ```bash
221
+ kl status
222
+ ```
223
+
224
+ Filter decisions by search keyword:
225
+
226
+ ```bash
227
+ kl status --search "database"
228
+ ```
229
+
230
+ View decisions grouped by module hierarchy:
231
+
232
+ ```bash
233
+ kl status --tree
234
+ ```
235
+
236
+ ### 6. Run an agent with decision memory
237
+
238
+ Launch your coding agent wrapped with Klyd context:
239
+
240
+ ```bash
241
+ kl run aider
242
+ ```
243
+
244
+ For custom agent invocations, generate the injection context directly:
245
+
246
+ ```bash
247
+ kl prepare-injection
248
+ # Context is written to .klyd/injection.txt
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Commands reference
254
+
255
+ | Command | Description |
256
+ |---|---|
257
+ | `kl init` | Initialise `.klyd/` storage and install Git hooks. |
258
+ | `kl config` | Configure model API keys, templates, and extraction thresholds. |
259
+ | `kl extract-commit` | Extract architectural decisions from the latest Git commit. |
260
+ | `kl prepare-injection` | Query matching decisions for staged files and generate `.klyd/injection.txt`. |
261
+ | `kl preview-injection` | Preview the injection prompt without writing it to disk. |
262
+ | `kl status` | Display active decisions, conflict summaries, and drift statistics. |
263
+ | `kl review` | Interactive CLI to resolve flagged architectural conflicts (`accept`, `merge`, `edit`, `reject`). |
264
+ | `kl pin <id>` | Pin a non-negotiable architectural constraint so it is always injected. |
265
+ | `kl unpin <id>` | Remove a pinned decision constraint. |
266
+ | `kl run <agent>` | Execute a coding agent with memory injected via command-line arguments. |
267
+ | `kl metrics` | Display aggregated decision counts, average confidence, and conflict rates. |
268
+
269
+ ---
270
+
271
+ ## Current status
272
+
273
+ Klyd is an actively developed developer-tooling project (v0.2.2 distributed on PyPI).
274
+
275
+ The current implementation is focused on local decision persistence, retrieval, Git lifecycle integration, and terminal coding-agent workflows.
276
+
277
+ - **Local scope**: Designed for single-developer repository workspaces. Remote peer sync and multi-user concurrent locking are not included.
278
+ - **LLM extraction dependency**: Quality of extracted decisions correlates with commit message clarity and the reasoning capabilities of the configured model.
279
+ - **Agent support**: Native argument injection is configured for `aider` and `opencode`; other agents consume `.klyd/injection.txt` via their respective context-file arguments.
280
+
281
+ ---
282
+
283
+ ## License
284
+
285
+ MIT License — see [LICENSE](./LICENSE).
klyd-0.2.3/README.md ADDED
@@ -0,0 +1,273 @@
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/kaadipranav/kaadipranav/refs/heads/main/assets/klydnewposter.png" />
3
+ </div>
4
+
5
+ # KLYD
6
+
7
+ ### Decision memory for coding agents.
8
+
9
+ Coding agents can generate code quickly but often lose the architectural decisions that shaped a repository.
10
+
11
+ Klyd records, retrieves, and reintroduces those decisions so future agent sessions can work with the project's existing reasoning instead of repeatedly rediscovering it.
12
+
13
+ [PyPI: klyd](https://pypi.org/project/klyd/) · [GitHub](https://github.com/klyd-studio/klyd-harness) · [License: MIT](./LICENSE)
14
+
15
+ ---
16
+
17
+ ## The problem
18
+
19
+ A coding agent may know the current files but not the reasons behind them:
20
+
21
+ - why a database choice was made;
22
+ - why a workaround exists;
23
+ - why an API must remain stable;
24
+ - why a previous approach was rejected;
25
+ - which architectural constraints are non-negotiable.
26
+
27
+ Without that context, agents can produce locally plausible changes that violate the system's existing design. Over multiple sessions, a codebase accumulates conflicting architectural patterns, turning into a patchwork of fragmented decisions.
28
+
29
+ ---
30
+
31
+ ## The workflow
32
+
33
+ Klyd operates invisibly through standard Git hooks without requiring a background daemon or wrapping agent subprocesses with intrusive proxies:
34
+
35
+ ```mermaid
36
+ graph TD
37
+ A[Developer commits] --> B["post-commit hook
38
+ kl extract-commit"]
39
+ B --> C["LLM Extraction
40
+ classify: NEW / REINFORCE / CONTRADICT"]
41
+ C -->|NEW or REINFORCE| D[("SQLite Store
42
+ .klyd/memory.db")]
43
+ C -->|CONTRADICT| E["Flagged for Review
44
+ kl review"]
45
+ E -->|Resolve: Accept / Merge / Edit| D
46
+
47
+ F[Agent stages changes] --> G["pre-commit hook
48
+ kl prepare-injection"]
49
+ G --> H["Single-pass query:
50
+ glob match + cosine similarity"]
51
+ H --> D
52
+ H --> I[".klyd/injection.txt
53
+ formatted context"]
54
+ I --> J["kl run aider
55
+ context injected"]
56
+ ```
57
+
58
+ All state remains strictly local to `.klyd/` inside the target git repository.
59
+
60
+ ---
61
+
62
+ ## Example
63
+
64
+ A repository previously decided:
65
+
66
+ > Authentication must remain inside the existing WebCrypto-based boundary. External token libraries must not be introduced.
67
+
68
+ Months later, an autonomous agent tasked with fixing an auth endpoint proposes adding a third-party token parser.
69
+
70
+ Before the change is committed, Klyd inspects the staged files, retrieves the earlier decision and its rationale from `.klyd/memory.db`, and injects the constraint directly into the agent's context window. The agent refactors the code within the established WebCrypto pattern instead of introducing an incompatible dependency.
71
+
72
+ *(Note: This is an illustrative example of an architectural boundary constraint captured from commit history and reintroduced to guide subsequent agent turns).*
73
+
74
+ ---
75
+
76
+ ## Technical design
77
+
78
+ Klyd currently uses:
79
+
80
+ - **SQLite for persistent decision storage**: Embedded relational database maintaining schema versions, embeddings, and decision records.
81
+ - **Git hooks for repository lifecycle integration**: `post-commit` extracts decisions asynchronously from diffs; `pre-commit` prepares context from staged changes.
82
+ - **Semantic similarity for retrieval**: Optional vector embeddings paired with lexical glob matching for relevant context ranking.
83
+ - **Recursive decision ancestry**: Tracking parent-child relationships across decision versions using recursive Common Table Expressions.
84
+ - **Conflict resolution between related decisions**: Interactive terminal UI (`kl review`) supporting accept, reject, manual edit, and LLM-assisted decision merging.
85
+ - **Multiple model-provider integrations**: Bring-Your-Own-Key (BYOK) support for Anthropic, OpenAI, OpenRouter, Google Gemini, and Groq.
86
+ - **CLI-oriented workflow for coding-agent environments**: Direct compatibility flags for tools like `aider` and `opencode`.
87
+
88
+ ---
89
+
90
+ ## Design choice: SQLite
91
+
92
+ SQLite keeps the decision history:
93
+
94
+ - **local** to the repository or workspace;
95
+ - **inspectable** with standard SQL tools or CLI commands;
96
+ - **easy to back up** by copying `.klyd/`;
97
+ - **usable** without requiring any cloud service, daemon, or database server;
98
+ - **available** to low-latency command-line workflows and shell scripts.
99
+
100
+ The trade-off is that Klyd prioritizes local developer infrastructure and explicit Git workflow integration over centralized multi-user cloud coordination.
101
+
102
+ ---
103
+
104
+ ## Engineering details
105
+
106
+ ### In-database custom multi-glob matching
107
+
108
+ When staged files are evaluated (e.g. `auth/login.py`), Klyd must match them against comma-separated glob patterns (e.g. `auth/*, security/*`) stored in the `decisions` table. Standard SQL lacks native glob-list evaluation, and loading all rows into Python memory for full-table scanning creates unnecessary overhead.
109
+
110
+ Klyd solves this by registering a custom Python callback function (`match_files`) directly into the SQLite C-runtime using `sqlite3.Connection.create_function`:
111
+
112
+ ```python
113
+ def _match_any_file(file_patterns: str, file_list_str: str) -> int:
114
+ patterns = [p.strip() for p in file_patterns.split(",")]
115
+ files = file_list_str.split("|")
116
+ for f in files:
117
+ for p in patterns:
118
+ if fnmatch.fnmatch(f, p):
119
+ return 1
120
+ return 0
121
+
122
+ conn.create_function("match_files", 2, _match_any_file)
123
+ ```
124
+
125
+ This allows the SQLite query planner to filter rows atomically in a single pass at the database layer before sorting by relevance and recency.
126
+
127
+ ### Decision lineage with recursive CTEs
128
+
129
+ When conflicting decisions are merged or updated during human review, older decisions are soft-archived rather than overwritten. Lineage is tracked through `parent_decision_id`, allowing complete evolutionary trees to be reconstructed using recursive Common Table Expressions:
130
+
131
+ ```sql
132
+ WITH RECURSIVE ancestors(id, decision, parent_decision_id) AS (
133
+ SELECT id, decision, parent_decision_id FROM decisions WHERE id = ?
134
+ UNION ALL
135
+ SELECT d.id, d.decision, d.parent_decision_id
136
+ FROM decisions d JOIN ancestors a ON d.id = a.parent_decision_id
137
+ )
138
+ SELECT * FROM ancestors;
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Quickstart
144
+
145
+ ### 1. Install Klyd
146
+
147
+ > **0.2.3 is not on PyPI yet.** The published 0.2.2 wheel is missing its hook
148
+ > templates and SQL schema, so `pip install klyd` installs a CLI that cannot
149
+ > initialise a repository. Until 0.2.3 ships, install from this branch:
150
+ >
151
+ > ```bash
152
+ > git clone -b fix/clean-install-audit https://github.com/klyd-studio/klyd-harness
153
+ > cd klyd-harness
154
+ > pip install .
155
+ > ```
156
+
157
+ Once 0.2.3 is released:
158
+
159
+ ```bash
160
+ pip install klyd
161
+ ```
162
+
163
+ ### 2. Initialize a repository
164
+
165
+ Run inside the root of your Git repository:
166
+
167
+ ```bash
168
+ kl init
169
+ ```
170
+
171
+ This creates `.klyd/memory.db`, initializes the configuration file, and installs the Git hooks into `.git/hooks/`.
172
+
173
+ ### 3. Configure a model provider
174
+
175
+ Set your preferred API key (BYOK):
176
+
177
+ ```bash
178
+ kl config --api-key sk-ant-...
179
+ # or: kl config --openai-key sk-...
180
+ # or: kl config --gemini-key ...
181
+ # or: kl config --groq-key ...
182
+ ```
183
+
184
+ Inspect active configuration:
185
+
186
+ ```bash
187
+ kl config --show
188
+ ```
189
+
190
+ ### 4. Record decisions from commits
191
+
192
+ Decisions are automatically extracted by the `post-commit` hook whenever you make a Git commit:
193
+
194
+ ```bash
195
+ git commit -m "refactor(db): use SQLite connection pooling instead of global instances"
196
+ ```
197
+
198
+ You can also trigger extraction manually for the latest commit:
199
+
200
+ ```bash
201
+ kl extract-commit
202
+ ```
203
+
204
+ ### 5. Retrieve relevant decisions
205
+
206
+ View stored architectural decisions in a table:
207
+
208
+ ```bash
209
+ kl status
210
+ ```
211
+
212
+ Filter decisions by search keyword:
213
+
214
+ ```bash
215
+ kl status --search "database"
216
+ ```
217
+
218
+ View decisions grouped by module hierarchy:
219
+
220
+ ```bash
221
+ kl status --tree
222
+ ```
223
+
224
+ ### 6. Run an agent with decision memory
225
+
226
+ Launch your coding agent wrapped with Klyd context:
227
+
228
+ ```bash
229
+ kl run aider
230
+ ```
231
+
232
+ For custom agent invocations, generate the injection context directly:
233
+
234
+ ```bash
235
+ kl prepare-injection
236
+ # Context is written to .klyd/injection.txt
237
+ ```
238
+
239
+ ---
240
+
241
+ ## Commands reference
242
+
243
+ | Command | Description |
244
+ |---|---|
245
+ | `kl init` | Initialise `.klyd/` storage and install Git hooks. |
246
+ | `kl config` | Configure model API keys, templates, and extraction thresholds. |
247
+ | `kl extract-commit` | Extract architectural decisions from the latest Git commit. |
248
+ | `kl prepare-injection` | Query matching decisions for staged files and generate `.klyd/injection.txt`. |
249
+ | `kl preview-injection` | Preview the injection prompt without writing it to disk. |
250
+ | `kl status` | Display active decisions, conflict summaries, and drift statistics. |
251
+ | `kl review` | Interactive CLI to resolve flagged architectural conflicts (`accept`, `merge`, `edit`, `reject`). |
252
+ | `kl pin <id>` | Pin a non-negotiable architectural constraint so it is always injected. |
253
+ | `kl unpin <id>` | Remove a pinned decision constraint. |
254
+ | `kl run <agent>` | Execute a coding agent with memory injected via command-line arguments. |
255
+ | `kl metrics` | Display aggregated decision counts, average confidence, and conflict rates. |
256
+
257
+ ---
258
+
259
+ ## Current status
260
+
261
+ Klyd is an actively developed developer-tooling project (v0.2.2 distributed on PyPI).
262
+
263
+ The current implementation is focused on local decision persistence, retrieval, Git lifecycle integration, and terminal coding-agent workflows.
264
+
265
+ - **Local scope**: Designed for single-developer repository workspaces. Remote peer sync and multi-user concurrent locking are not included.
266
+ - **LLM extraction dependency**: Quality of extracted decisions correlates with commit message clarity and the reasoning capabilities of the configured model.
267
+ - **Agent support**: Native argument injection is configured for `aider` and `opencode`; other agents consume `.klyd/injection.txt` via their respective context-file arguments.
268
+
269
+ ---
270
+
271
+ ## License
272
+
273
+ MIT License — see [LICENSE](./LICENSE).
@@ -0,0 +1,8 @@
1
+ """klyd - architectural memory for coding agents."""
2
+
3
+ import sys
4
+
5
+ if __name__ == '__main__':
6
+ from klyd.cli import cli
7
+ sys.argv[0] = 'python -m klyd'
8
+ cli()