kc-cli 0.4.0__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.
Files changed (66) hide show
  1. kc_cli-0.4.0/.gitignore +8 -0
  2. kc_cli-0.4.0/CHANGELOG.md +64 -0
  3. kc_cli-0.4.0/LICENSE +21 -0
  4. kc_cli-0.4.0/PKG-INFO +522 -0
  5. kc_cli-0.4.0/README.md +489 -0
  6. kc_cli-0.4.0/pyproject.toml +77 -0
  7. kc_cli-0.4.0/src/kc/__init__.py +5 -0
  8. kc_cli-0.4.0/src/kc/__main__.py +11 -0
  9. kc_cli-0.4.0/src/kc/artifacts/__init__.py +1 -0
  10. kc_cli-0.4.0/src/kc/artifacts/diff.py +76 -0
  11. kc_cli-0.4.0/src/kc/artifacts/frontmatter.py +26 -0
  12. kc_cli-0.4.0/src/kc/artifacts/markdown.py +116 -0
  13. kc_cli-0.4.0/src/kc/atomic_write.py +33 -0
  14. kc_cli-0.4.0/src/kc/cli.py +284 -0
  15. kc_cli-0.4.0/src/kc/commands/__init__.py +1 -0
  16. kc_cli-0.4.0/src/kc/commands/artifact.py +1190 -0
  17. kc_cli-0.4.0/src/kc/commands/citation.py +231 -0
  18. kc_cli-0.4.0/src/kc/commands/common.py +346 -0
  19. kc_cli-0.4.0/src/kc/commands/conformance.py +293 -0
  20. kc_cli-0.4.0/src/kc/commands/context.py +190 -0
  21. kc_cli-0.4.0/src/kc/commands/doctor.py +81 -0
  22. kc_cli-0.4.0/src/kc/commands/eval.py +133 -0
  23. kc_cli-0.4.0/src/kc/commands/export.py +97 -0
  24. kc_cli-0.4.0/src/kc/commands/guide.py +571 -0
  25. kc_cli-0.4.0/src/kc/commands/index.py +54 -0
  26. kc_cli-0.4.0/src/kc/commands/init.py +207 -0
  27. kc_cli-0.4.0/src/kc/commands/lint.py +238 -0
  28. kc_cli-0.4.0/src/kc/commands/source.py +464 -0
  29. kc_cli-0.4.0/src/kc/commands/status.py +52 -0
  30. kc_cli-0.4.0/src/kc/commands/task.py +260 -0
  31. kc_cli-0.4.0/src/kc/config.py +127 -0
  32. kc_cli-0.4.0/src/kc/embedding_models/potion-base-8M/README.md +97 -0
  33. kc_cli-0.4.0/src/kc/embedding_models/potion-base-8M/config.json +13 -0
  34. kc_cli-0.4.0/src/kc/embedding_models/potion-base-8M/model.safetensors +0 -0
  35. kc_cli-0.4.0/src/kc/embedding_models/potion-base-8M/modules.json +14 -0
  36. kc_cli-0.4.0/src/kc/embedding_models/potion-base-8M/tokenizer.json +1 -0
  37. kc_cli-0.4.0/src/kc/errors.py +141 -0
  38. kc_cli-0.4.0/src/kc/fingerprints.py +35 -0
  39. kc_cli-0.4.0/src/kc/ids.py +23 -0
  40. kc_cli-0.4.0/src/kc/locks.py +65 -0
  41. kc_cli-0.4.0/src/kc/models/__init__.py +17 -0
  42. kc_cli-0.4.0/src/kc/models/artifact.py +34 -0
  43. kc_cli-0.4.0/src/kc/models/citation.py +60 -0
  44. kc_cli-0.4.0/src/kc/models/context.py +23 -0
  45. kc_cli-0.4.0/src/kc/models/eval.py +21 -0
  46. kc_cli-0.4.0/src/kc/models/plan.py +37 -0
  47. kc_cli-0.4.0/src/kc/models/source.py +37 -0
  48. kc_cli-0.4.0/src/kc/models/source_range.py +29 -0
  49. kc_cli-0.4.0/src/kc/models/source_revision.py +19 -0
  50. kc_cli-0.4.0/src/kc/models/task.py +35 -0
  51. kc_cli-0.4.0/src/kc/output.py +838 -0
  52. kc_cli-0.4.0/src/kc/paths.py +126 -0
  53. kc_cli-0.4.0/src/kc/provenance/__init__.py +1 -0
  54. kc_cli-0.4.0/src/kc/provenance/citations.py +296 -0
  55. kc_cli-0.4.0/src/kc/search/__init__.py +1 -0
  56. kc_cli-0.4.0/src/kc/search/extract.py +268 -0
  57. kc_cli-0.4.0/src/kc/search/fts.py +284 -0
  58. kc_cli-0.4.0/src/kc/search/semantic.py +346 -0
  59. kc_cli-0.4.0/src/kc/store/__init__.py +1 -0
  60. kc_cli-0.4.0/src/kc/store/jsonl.py +55 -0
  61. kc_cli-0.4.0/src/kc/store/sqlite.py +444 -0
  62. kc_cli-0.4.0/src/kc/store/transaction.py +67 -0
  63. kc_cli-0.4.0/src/kc/templates/agents/skills/kc/SKILL.md +282 -0
  64. kc_cli-0.4.0/src/kc/templates/agents/skills/kc/agents/openai.yaml +5 -0
  65. kc_cli-0.4.0/src/kc/templates/agents/skills/kc/scripts/resolve_query_citations.py +134 -0
  66. kc_cli-0.4.0/src/kc/workspace.py +98 -0
@@ -0,0 +1,8 @@
1
+ .kc/
2
+ .pytest_cache/
3
+ .ruff_cache/
4
+ __pycache__/
5
+ *.py[cod]
6
+ build/
7
+ dist/
8
+ *.egg-info/
@@ -0,0 +1,64 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This project uses Semantic Versioning for the Python package version exposed by
6
+ `src/kc/__init__.py`, the Hatch build metadata, `kc --version`, and `kc guide`.
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.4.0] - 2026-05-12
11
+
12
+ ### Changed
13
+
14
+ - Bumped the package version for the next minor release.
15
+
16
+ ## [0.3.0] - 2026-05-12
17
+
18
+ ### Added
19
+
20
+ - Workspace root discovery with `--root`, `KC_ROOT`, `kc.toml`, `.git`, and
21
+ current-directory fallback resolution.
22
+ - Source revisions, revision-aware range IDs, v2 range citation tokens, and
23
+ deterministic `kc citation rewrite` / `kc citation repair` workflows.
24
+ - Repo-level mutation transactions with `.kc/operations/` journals.
25
+ - Durable context packs via `kc context prepare --out`.
26
+ - `kc task next` and a state-specific task workflow through validation and
27
+ apply.
28
+ - Eval pack schema validation, expected range checks, recall/MRR metrics, and
29
+ `kc eval run --out`.
30
+ - Artifact diffs now use the last applied snapshot when available.
31
+ - `kc init` now creates and maintains a repo-local `.agents/skills/kc/` skill
32
+ so external agents can discover the local `kc` workflow, query-answering
33
+ guidance, remote-ingestion guidance, and original-source citation helper.
34
+ - Release discipline for future changes: update this changelog, bump
35
+ `src/kc/__init__.py::__version__`, run the published verification commands,
36
+ and tag releases as `vX.Y.Z`.
37
+
38
+ ### Changed
39
+
40
+ - Search and context preparation fall back to SQLite FTS with a structured
41
+ warning when semantic ranking is unavailable.
42
+ - `kc.toml` `data_dir` and `state_dir` settings are honored unless explicitly
43
+ overridden by global options.
44
+
45
+ ## [0.2.0] - 2026-05-11
46
+
47
+ ### Changed
48
+
49
+ - Made hybrid retrieval the default behavior for search and context preparation,
50
+ combining SQLite BM25 with bundled local semantic vectors.
51
+ - `kc index build` now rebuilds semantic embeddings by default.
52
+
53
+ ### Removed
54
+
55
+ - Removed public retrieval-selection switches: `--mode` on `source search` and
56
+ `context prepare`, and `--semantic` on `index build`.
57
+
58
+ ## [0.1.0] - 2026-05-11
59
+
60
+ ### Added
61
+
62
+ - Initial `kc` CLI package with deterministic source registration, search,
63
+ context preparation, citation validation, safe artifact apply, task state,
64
+ exports, and contract conformance checks.
kc_cli-0.4.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thomas Klok Rohde
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.
kc_cli-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,522 @@
1
+ Metadata-Version: 2.4
2
+ Name: kc-cli
3
+ Version: 0.4.0
4
+ Summary: Deterministic knowledge compiler harness for external agents
5
+ Project-URL: Homepage, https://github.com/ThomasRohde/kc-cli
6
+ Project-URL: Issues, https://github.com/ThomasRohde/kc-cli/issues
7
+ Project-URL: Changelog, https://github.com/ThomasRohde/kc-cli/blob/master/CHANGELOG.md
8
+ Author-email: Thomas Klok Rohde <rohde.thomas@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agent,citations,cli,knowledge,provenance,search
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: model2vec>=0.7
21
+ Requires-Dist: numpy>=1.26
22
+ Requires-Dist: orjson>=3.9
23
+ Requires-Dist: pydantic>=2.0
24
+ Requires-Dist: python-ulid>=3.0
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: rich>=13.0
27
+ Requires-Dist: typer>=0.12
28
+ Provides-Extra: dev
29
+ Requires-Dist: pyright>=1.1; extra == 'dev'
30
+ Requires-Dist: pytest>=8.0; extra == 'dev'
31
+ Requires-Dist: ruff>=0.4; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # kc-cli
35
+
36
+ [![PyPI](https://img.shields.io/pypi/v/kc-cli.svg)](https://pypi.org/project/kc-cli/)
37
+ [![Python](https://img.shields.io/pypi/pyversions/kc-cli.svg)](https://pypi.org/project/kc-cli/)
38
+ [![License](https://img.shields.io/pypi/l/kc-cli.svg)](https://pypi.org/project/kc-cli/)
39
+
40
+ `kc-cli` installs `kc`, a local-first knowledge compiler for people and agents
41
+ who need grounded project knowledge instead of another pile of loose notes.
42
+
43
+ Register the source material you trust. Ask `kc` for the relevant evidence.
44
+ Let a human or external agent write the semantic content. Then use `kc` to
45
+ validate citations, preview the change, apply it safely, and keep the knowledge
46
+ workspace searchable.
47
+
48
+ The `kc` CLI does not call an LLM, generate semantic content, or add a model
49
+ provider dependency to your project. It is the deterministic harness around
50
+ that work: source registration, hybrid search, context preparation, citation
51
+ validation, safe apply, task state, and exports. `kc init` also writes a
52
+ repo-local `.agents/skills/kc/` skill so external agents can learn the workflow
53
+ and answer knowledge queries from grounded evidence without moving reasoning
54
+ into the CLI.
55
+
56
+ ## Why use kc?
57
+
58
+ - **Give agents better inputs.** Prepare compact, cited evidence packs before an
59
+ agent writes a page, policy, ADR, runbook, or implementation note.
60
+ - **Keep knowledge auditable.** Material claims can point back to registered
61
+ source ranges such as Markdown lines, JSON pointers, or CSV rows.
62
+ - **Reduce drift.** `kc lint` can find stale sources, broken citations, orphaned
63
+ artifacts, duplicate records, and stale indexes.
64
+ - **Make changes safely.** Mutation commands are dry-run or explicit-apply by
65
+ default, with locks and snapshots around artifact application.
66
+ - **Stay local and provider-neutral.** Source data, indexes, artifacts, and task
67
+ state live in the repository. Agents remain external and interchangeable.
68
+ - **Carry the workflow with the repo.** `kc init` installs a managed `$kc` skill
69
+ that teaches compatible agent runtimes how to query, ingest, cite, validate,
70
+ and apply project knowledge.
71
+ - **Automate without scraping text output.** Commands emit stable structured
72
+ envelopes by default and expose deterministic next steps.
73
+
74
+ ## Good fits
75
+
76
+ | Use case | What kc gives you |
77
+ | --- | --- |
78
+ | Project implementation wiki | Pages grounded in code, ADRs, design notes, and existing docs. |
79
+ | Agent handoff packs | Search results and context bundles an external agent can use without guessing. |
80
+ | Compliance or policy knowledge | Traceable claims with citations back to local source material. |
81
+ | Onboarding material | Curated knowledge pages that can be refreshed as source files change. |
82
+ | Repository self-knowledge | A durable `knowledge/` workspace that future contributors and agents can query. |
83
+ | Retrieval evaluation | Deterministic eval packs for checking whether the right evidence is found. |
84
+ | Knowledge export | JSONL, Markdown bundle, or `llms.txt` exports from registered knowledge. |
85
+
86
+ ## Install
87
+
88
+ `kc-cli` requires Python 3.12 or newer. The recommended install path is
89
+ [uv](https://docs.astral.sh/uv/):
90
+
91
+ ```bash
92
+ uv tool install kc-cli
93
+ kc --help
94
+ kc --version
95
+ ```
96
+
97
+ Try it without installing a persistent tool:
98
+
99
+ ```bash
100
+ uvx --from kc-cli kc --help
101
+ ```
102
+
103
+ The Python package name is `kc-cli`; the console command is `kc`.
104
+
105
+ `pip` works too:
106
+
107
+ ```bash
108
+ python -m pip install kc-cli
109
+ ```
110
+
111
+ ## First workspace
112
+
113
+ A typical `kc` workflow has five steps:
114
+
115
+ 1. Initialize a repository-local knowledge workspace and generated agent skill.
116
+ 2. Register source files that should ground future knowledge.
117
+ 3. Search or prepare context for the question at hand.
118
+ 4. Write the artifact yourself or ask an external agent to write it.
119
+ 5. Validate, diff, and apply the artifact.
120
+
121
+ ```bash
122
+ kc init --yes
123
+ kc source add docs/policy.md --domain policy --yes
124
+ kc --format markdown source search "ownership responsibilities" --domain policy
125
+ kc context prepare --ask "Create an ownership page" --shape knowledge_page --grounding required --target knowledge/wiki/ownership.md --out .kc/context/ownership.json
126
+ kc artifact new --type knowledge_page --path knowledge/wiki/ownership.md --title "Ownership" --yes
127
+ ```
128
+
129
+ The generated `.agents/skills/kc/` skill is optional runtime guidance for
130
+ external agents. It is committed when you want the project itself to carry the
131
+ expected `kc` workflow.
132
+
133
+ Edit `knowledge/wiki/ownership.md` with citations from `kc source search` or
134
+ `kc context prepare`:
135
+
136
+ ```markdown
137
+ The policy owner reviews the document every quarter. [kc:src_01HX...:rng_01HX...:L12-L18]
138
+ ```
139
+
140
+ Then check and apply the result:
141
+
142
+ ```bash
143
+ kc artifact validate --file knowledge/wiki/ownership.md
144
+ kc artifact diff --file knowledge/wiki/ownership.md
145
+ kc artifact apply --file knowledge/wiki/ownership.md --dry-run
146
+ kc artifact apply --file knowledge/wiki/ownership.md --yes
147
+ kc lint
148
+ ```
149
+
150
+ ## How kc works with agents
151
+
152
+ `kc` is intentionally not the agent. It is the compiler harness around agentic
153
+ knowledge work.
154
+
155
+ ```text
156
+ trusted local sources
157
+ |
158
+ v
159
+ source registration and range extraction
160
+ |
161
+ v
162
+ search and context preparation
163
+ |
164
+ v
165
+ human or external agent writes semantic content
166
+ |
167
+ | optional repo-local .agents/skills/kc guidance
168
+ |
169
+ v
170
+ citation validation, diff, apply, lint, export
171
+ ```
172
+
173
+ That split keeps responsibilities clear: the agent writes and synthesizes;
174
+ `kc` tracks evidence, validates provenance, and mutates repository state in a
175
+ predictable way.
176
+
177
+ ## Core ideas
178
+
179
+ **Sources** are local files that ground future knowledge. Adding a source records
180
+ metadata, fingerprints, and extracted citation ranges in `knowledge/`.
181
+
182
+ ```bash
183
+ kc source add docs/policy.md --domain policy --dry-run
184
+ kc source add docs/policy.md --domain policy --yes
185
+ kc source inspect docs/policy.md --ranges
186
+ ```
187
+
188
+ **Ranges** are stable citation targets extracted from source revisions. Search
189
+ commands use default hybrid retrieval and return ready-to-use v2 citation
190
+ tokens with source and range IDs, plus legacy locator tokens for migration.
191
+
192
+ ```bash
193
+ kc source search "retention period" --domain policy --limit 5
194
+ ```
195
+
196
+ **Context** is the evidence package for a writing task. `kc context prepare`
197
+ gathers relevant ranges, policies, artifact matches, and next commands without
198
+ answering the question.
199
+
200
+ ```bash
201
+ kc context prepare --ask "Summarize retention obligations" --shape knowledge_page --grounding required --out .kc/context/retention.json
202
+ ```
203
+
204
+ **Artifacts** are durable outputs such as Markdown knowledge pages or typed
205
+ JSON/YAML documents. `kc` can create skeletons, validate citations, build a
206
+ diff plan, and apply registry updates.
207
+
208
+ ```bash
209
+ kc artifact new --type knowledge_page --path knowledge/wiki/retention.md --title "Retention" --yes
210
+ kc artifact validate --file knowledge/wiki/retention.md
211
+ kc artifact apply --file knowledge/wiki/retention.md --yes
212
+ ```
213
+
214
+ **Tasks** store durable state for longer external-agent workflows.
215
+
216
+ ```bash
217
+ kc task start --goal "Create retention page" --target knowledge/wiki/retention.md
218
+ kc task status --task-id task_01HX
219
+ kc task resume --task-id task_01HX --event artifact_created --input @event.json
220
+ ```
221
+
222
+ ## Workspace layout
223
+
224
+ `kc init --yes` creates a Git-friendly durable knowledge directory, a managed
225
+ repo-local agent skill, and local runtime state:
226
+
227
+ ```text
228
+ repo-root/
229
+ kc.toml
230
+ knowledge/
231
+ sources.jsonl
232
+ source_revisions.jsonl
233
+ source_ranges.jsonl
234
+ artifacts.jsonl
235
+ citation_edges.jsonl
236
+ wiki/
237
+ artifacts/
238
+ schemas/
239
+ evals/
240
+ exports/
241
+ .agents/
242
+ skills/
243
+ kc/
244
+ SKILL.md
245
+ agents/
246
+ openai.yaml
247
+ scripts/
248
+ resolve_query_citations.py
249
+ .kc/
250
+ state.sqlite
251
+ locks/
252
+ operations/
253
+ context/
254
+ snapshots/
255
+ plans/
256
+ tasks/
257
+ cache/
258
+ ```
259
+
260
+ Commit `knowledge/` and `.agents/` when they are part of the project record.
261
+ The `.agents/skills/kc/` skill gives external agents the local `kc` workflow.
262
+ Keep `.kc/` local unless you have a specific reason to share runtime state.
263
+
264
+ ## Common commands
265
+
266
+ `kc guide` is the authoritative command catalog. It is designed for humans,
267
+ agents, and tool integrations.
268
+
269
+ ```bash
270
+ kc guide
271
+ kc guide --section commands
272
+ kc guide --section workflows
273
+ kc guide --section errors
274
+ kc --format json guide --section commands
275
+ ```
276
+
277
+ | Command | Purpose |
278
+ | --- | --- |
279
+ | `kc init` | Create or update the workspace layout, config, stores, managed agent skill, and local state. |
280
+ | `kc status` | Show workspace status, counts, index health, and next commands. |
281
+ | `kc source add` | Register a source, fingerprint it, extract ranges, and update indexes. |
282
+ | `kc source inspect` | Show source metadata, fingerprint state, and optional ranges. |
283
+ | `kc source refresh` | Refresh a changed registered source. |
284
+ | `kc source search` | Search registered source ranges with default hybrid retrieval and return citation tokens. |
285
+ | `kc index build` | Rebuild BM25 and semantic search indexes. |
286
+ | `kc context prepare` | Gather evidence and instructions for an external writing or answering task. |
287
+ | `kc artifact new` | Create a deterministic artifact skeleton. |
288
+ | `kc artifact validate` | Validate schema, required sections, citations, and provenance. |
289
+ | `kc artifact diff` | Build a structured apply plan before mutation. |
290
+ | `kc artifact apply` | Validate, lock, snapshot, register, and apply an artifact. |
291
+ | `kc citation check` | Check citation tokens and provenance for one or all artifacts. |
292
+ | `kc citation rewrite/repair` | Rewrite legacy locator tokens or report deterministic repair candidates. |
293
+ | `kc lint` | Run repository integrity checks. |
294
+ | `kc task start/status/inspect/next/resume` | Track longer-running agent workflows. |
295
+ | `kc eval run` | Run deterministic retrieval eval packs with recall and MRR metrics. |
296
+ | `kc export` | Export registered knowledge as JSONL, Markdown bundle, or `llms.txt`. |
297
+ | `kc doctor` | Inspect config, state, locks, and semantic index health. |
298
+ | `kc conformance` | Run read-only CLI contract checks. |
299
+
300
+ ## Citations
301
+
302
+ Markdown artifacts use parseable citation tokens:
303
+
304
+ | Token | Meaning |
305
+ | --- | --- |
306
+ | `[kc:src_<id>:rng_<id>]` | Cite an extracted source range by stable range ID. |
307
+ | `[kc:src_<id>:rng_<id>:L<start>-L<end>]` | Cite a source line range with human locator context. |
308
+ | `[kc:src_<id>:rng_<id>:JP:<percent-encoded-json-pointer>]` | Cite a JSON/YAML/TOML pointer range. |
309
+ | `[kc:src_<id>:rng_<id>:CSV:R<start>-R<end>]` | Cite CSV rows. |
310
+
311
+ Legacy locator-only tokens remain parseable during migration. Prefer
312
+ `kc citation rewrite --file <artifact> --dry-run` and then `--yes` to convert
313
+ them to range-aware v2 tokens.
314
+
315
+ Special markers make intent explicit:
316
+
317
+ | Marker | Meaning |
318
+ | --- | --- |
319
+ | `[kc:inference]` | Synthesis or interpretation based on cited facts. |
320
+ | `[kc:todo]` | Unresolved work. Valid drafts warn so agents can detect placeholders. |
321
+ | `[kc:uncited]` | Uncited content. Validation fails unless explicitly allowed. |
322
+
323
+ JSON artifacts should use structured citation references:
324
+
325
+ ```json
326
+ {
327
+ "citations": [
328
+ {
329
+ "source_id": "src_01HX...",
330
+ "range_id": "rng_01HX..."
331
+ }
332
+ ]
333
+ }
334
+ ```
335
+
336
+ ## Output and automation
337
+
338
+ The default output format is JSON. Every successful or failed JSON response uses
339
+ the `kc.result.v1` envelope:
340
+
341
+ ```json
342
+ {
343
+ "schema_version": "kc.result.v1",
344
+ "request_id": "req_01HX...",
345
+ "ok": true,
346
+ "command": "source.search",
347
+ "target": {},
348
+ "result": {},
349
+ "warnings": [],
350
+ "errors": [],
351
+ "metrics": {
352
+ "duration_ms": 12
353
+ }
354
+ }
355
+ ```
356
+
357
+ Use `--format table` or `--format markdown` for human views when available.
358
+ Use JSON for integrations.
359
+
360
+ ```bash
361
+ kc --format markdown source search "retention period"
362
+ kc --format json guide --section commands
363
+ ```
364
+
365
+ `LLM=true` forces JSON output, quiet mode, no ANSI, and no prompts:
366
+
367
+ ```bash
368
+ LLM=true kc guide
369
+ ```
370
+
371
+ PowerShell:
372
+
373
+ ```powershell
374
+ $env:LLM='true'; kc guide
375
+ ```
376
+
377
+ ## Configuration
378
+
379
+ `kc.toml` controls local policy:
380
+
381
+ ```toml
382
+ schema_version = "kc.config.v1"
383
+ project_id = "my-project"
384
+ data_dir = "knowledge"
385
+ state_dir = ".kc"
386
+
387
+ [index]
388
+ fts_enabled = true
389
+ rrf_k = 60
390
+
391
+ [index.semantic]
392
+ provider = "model2vec"
393
+ model = "potion-base-8M"
394
+ dimension = 256
395
+ purpose = "ranking_only"
396
+
397
+ [mutation]
398
+ default_dry_run = true
399
+ require_yes_for_apply = true
400
+ atomic_writes = true
401
+ create_snapshots = true
402
+ ```
403
+
404
+ Built-in hybrid retrieval uses SQLite FTS5/BM25 and the bundled `model2vec`
405
+ `potion-base-8M` model for ranking only.
406
+
407
+ ## Safety model
408
+
409
+ - Read commands can run in parallel.
410
+ - Write commands use `.kc/locks`.
411
+ - Most mutation commands preview changes unless `--yes` is provided.
412
+ - `artifact apply` validates, locks, rechecks preconditions, snapshots relevant
413
+ state, then updates registries.
414
+ - Citation validation fails on missing ranges, stale sources, invalid tokens,
415
+ and uncited material unless explicitly allowed.
416
+ - `kc` never writes semantic content for you; it validates and applies content
417
+ written by a human or external agent.
418
+
419
+ ## Troubleshooting
420
+
421
+ Refresh a changed source:
422
+
423
+ ```bash
424
+ kc source inspect docs/policy.md --ranges
425
+ kc source refresh docs/policy.md --dry-run
426
+ kc source refresh docs/policy.md --yes
427
+ kc lint
428
+ ```
429
+
430
+ Rebuild indexes:
431
+
432
+ ```bash
433
+ kc index build
434
+ kc lint
435
+ ```
436
+
437
+ Inspect or clear stale locks:
438
+
439
+ ```bash
440
+ kc doctor locks
441
+ kc doctor locks --clear-stale --yes
442
+ ```
443
+
444
+ See the complete error taxonomy:
445
+
446
+ ```bash
447
+ kc guide --section errors
448
+ ```
449
+
450
+ ## Development
451
+
452
+ This repository uses a `src/` layout and targets Python 3.12+. Use uv for local
453
+ development:
454
+
455
+ ```bash
456
+ git clone <repo-url> kc-cli
457
+ cd kc-cli
458
+ uv sync --extra dev
459
+ uv run kc --help
460
+ ```
461
+
462
+ Run focused and broad checks:
463
+
464
+ ```bash
465
+ uv run pytest tests/test_cli_contract.py -q
466
+ uv run pytest
467
+ uv run ruff check .
468
+ uv run pyright
469
+ uv run kc lint
470
+ ```
471
+
472
+ When the package is not installed, run the CLI from the repository root:
473
+
474
+ ```powershell
475
+ $env:PYTHONPATH='src'; uv run python -m kc --help
476
+ $env:PYTHONPATH='src'; uv run python -m kc lint
477
+ ```
478
+
479
+ ## Publishing
480
+
481
+ The PyPI package name is `kc-cli`; the installed command remains `kc`.
482
+
483
+ Versioning follows a single-source package pattern:
484
+
485
+ - The release version lives in `src/kc/__init__.py` as `__version__`.
486
+ - `pyproject.toml` uses Hatch dynamic versioning from that file.
487
+ - `kc --version` and `kc guide` must report the same version.
488
+ - `CHANGELOG.md` keeps an `[Unreleased]` section and a section for the current
489
+ version.
490
+
491
+ Use Semantic Versioning:
492
+
493
+ - Patch: compatible fixes and documentation changes.
494
+ - Minor: backward-compatible commands, fields, options, schemas, or behavior.
495
+ - Major: breaking changes to command semantics, required envelope fields,
496
+ stable error codes, JSONL schemas, or stored artifact contracts.
497
+
498
+ Before publishing, update `CHANGELOG.md`, bump `src/kc/__init__.py`, and tag the
499
+ release as `vX.Y.Z`.
500
+
501
+ Build and check distributions:
502
+
503
+ ```bash
504
+ uv build
505
+ uvx twine check dist/*
506
+ ```
507
+
508
+ Publishing uses GitHub trusted publishing through `.github/workflows/publish.yml`
509
+ and the protected `pypi` environment. Push a `vX.Y.Z` tag to publish the checked
510
+ distribution artifacts to PyPI.
511
+
512
+ Before publishing, verify:
513
+
514
+ ```bash
515
+ uv run pytest
516
+ uv run ruff check .
517
+ uv run pyright
518
+ uv run kc --version
519
+ uv run kc guide --section compatibility
520
+ uv run kc conformance
521
+ uv run kc lint
522
+ ```