@rahmantech/knl-view 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +483 -2
  3. package/bin/knl-view.js +1320 -0
  4. package/dist/assets/abnfDiagram-WEYOIA3C-hoSbsMOz.js +1 -0
  5. package/dist/assets/arc-g87Np6E5.js +1 -0
  6. package/dist/assets/architecture-WOLXFQ4H-DOIq-0IA.js +1 -0
  7. package/dist/assets/architectureDiagram-ZHVYKT53-Dxwe8n7m.js +36 -0
  8. package/dist/assets/array-BifhSqXX.js +1 -0
  9. package/dist/assets/blockDiagram-RJAE7QA3-BnGng59Z.js +140 -0
  10. package/dist/assets/c4Diagram-XDPPPE54-C5LjqIIo.js +38 -0
  11. package/dist/assets/channel-BVWkRFBw.js +1 -0
  12. package/dist/assets/chunk-2E7WHVMD-BJ1dyGLq.js +88 -0
  13. package/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  14. package/dist/assets/chunk-4EMNKR2T-DXF02Sgw.js +1 -0
  15. package/dist/assets/chunk-55XCU76K-CM1akAbu.js +1 -0
  16. package/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
  17. package/dist/assets/chunk-7S6XSTFO-BOUjqldL.js +2 -0
  18. package/dist/assets/chunk-AQDTSKZB-C4isdNLA.js +72 -0
  19. package/dist/assets/chunk-DSNLSHJZ-CbOTkSVM.js +129 -0
  20. package/dist/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
  21. package/dist/assets/chunk-HAGFOTED-CRfnketR.js +62 -0
  22. package/dist/assets/chunk-HNE4Q36P-rxlpGUU8.js +1 -0
  23. package/dist/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
  24. package/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  25. package/dist/assets/chunk-NGNAAXSQ-C2Wy9Xmz.js +136 -0
  26. package/dist/assets/chunk-NQOKRVIF-BOYCgTmV.js +213 -0
  27. package/dist/assets/chunk-UHW7PFBP-Cnogp1Fb.js +1 -0
  28. package/dist/assets/chunk-VQ5W62QI-Cu1WY5Uo.js +1 -0
  29. package/dist/assets/chunk-WQQL4CDK-BJc3FPE2.js +10 -0
  30. package/dist/assets/chunk-XXDRQBXY-BlPj4H7s.js +1 -0
  31. package/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  32. package/dist/assets/chunk-YZO67HFG-V85H31x4.js +1 -0
  33. package/dist/assets/chunk-ZAUX2LTX-C3XKXW09.js +1 -0
  34. package/dist/assets/chunk-ZCHMQSOR-B0mmpEgW.js +2 -0
  35. package/dist/assets/classDiagram-v2-4MYWR3UA-oMd7YaHP.js +217 -0
  36. package/dist/assets/cose-bilkent-JH36ORCC-J0kSVsDf.js +1 -0
  37. package/dist/assets/cynefin-EF2NZ3EQ-DK2TNhel.js +1 -0
  38. package/dist/assets/cynefinDiagram-WF24UDRP-DDvKgieA.js +62 -0
  39. package/dist/assets/cytoscape.esm-BegBNzOV.js +321 -0
  40. package/dist/assets/dagre-NK4GIZVX-Ca2Fe-i-.js +4 -0
  41. package/dist/assets/defaultLocale-BFoDCU3G.js +1 -0
  42. package/dist/assets/diagram-CBK3MWTC-L6dmeQ2V.js +24 -0
  43. package/dist/assets/diagram-I5XIIV2D-DhG8R-v5.js +24 -0
  44. package/dist/assets/diagram-ODIL2UCW-BpYYbYBT.js +30 -0
  45. package/dist/assets/diagram-PFBEJUXE-DKQpHSsC.js +3 -0
  46. package/dist/assets/diagram-RJA3I4VV-DP7Dsnya.js +41 -0
  47. package/dist/assets/diagram-TYUNFSNR-CfSFewUS.js +200 -0
  48. package/dist/assets/dist-CQNjnrld.js +1 -0
  49. package/dist/assets/ebnfDiagram-V4P3TTPT-DE3MZoJO.js +1 -0
  50. package/dist/assets/elk-QONTBCTQ-p_aAQPHU.js +27 -0
  51. package/dist/assets/erDiagram-KYQIGQAA-DZO3vQrk.js +99 -0
  52. package/dist/assets/eventmodeling-K75KTNOO-BII9EPl5.js +1 -0
  53. package/dist/assets/flowDiagram-IUGLLWBU-D9uPno39.js +1 -0
  54. package/dist/assets/ganttDiagram-R7GPNTJY-BKiH3v2r.js +292 -0
  55. package/dist/assets/gitGraph-VSP46ZUC-oHL6cr73.js +1 -0
  56. package/dist/assets/gitGraphDiagram-PDYL7XHY-CqPVIEeo.js +106 -0
  57. package/dist/assets/graphlib-DS17s2tU.js +1 -0
  58. package/dist/assets/index-CSpirV16.js +76 -0
  59. package/dist/assets/index-DLgMsUs2.css +1 -0
  60. package/dist/assets/info-OHQRW6UA-Drrbnhpd.js +1 -0
  61. package/dist/assets/infoDiagram-MVDRKAX5-DnQQFMAd.js +2 -0
  62. package/dist/assets/init-C-OQMol4.js +1 -0
  63. package/dist/assets/ishikawaDiagram-HPEHV2GE-DIpQlxRh.js +70 -0
  64. package/dist/assets/journeyDiagram-BOSHW7O7-EBR9I5h1.js +139 -0
  65. package/dist/assets/kanban-definition-FNSA4HC5-CdvNsjik.js +89 -0
  66. package/dist/assets/katex-B_JcIwqj.js +257 -0
  67. package/dist/assets/line-CDLzgxDc.js +1 -0
  68. package/dist/assets/linear-DfXKql9u.js +1 -0
  69. package/dist/assets/mermaid-parser.core-DnXGphT2.js +7 -0
  70. package/dist/assets/mermaid.core-h6fiCaSZ.js +44 -0
  71. package/dist/assets/mindmap-definition-6OY57UG3-BiNfio-j.js +98 -0
  72. package/dist/assets/ordinal-BDEzSJ7C.js +1 -0
  73. package/dist/assets/packet-JDAUHWVQ-D76byv1S.js +1 -0
  74. package/dist/assets/path-fybaL0A-.js +1 -0
  75. package/dist/assets/pegDiagram-ECIUJNBX-Drs8Pxdt.js +1 -0
  76. package/dist/assets/pie-XZMESJXO-D_83z1lM.js +1 -0
  77. package/dist/assets/pieDiagram-GNMPY74T-wvzIphSf.js +39 -0
  78. package/dist/assets/quadrantDiagram-D57K4MC3-B7EfMRWb.js +7 -0
  79. package/dist/assets/radar-ABXABTNO-Bs6dVdAR.js +1 -0
  80. package/dist/assets/railroad-I3PHUGI6-lKaN4miw.js +1 -0
  81. package/dist/assets/railroad-abnf-LNEFI6M7-Bhh16b7Z.js +1 -0
  82. package/dist/assets/railroad-ebnf-DWYD2UWJ-m6ybW-Y_.js +1 -0
  83. package/dist/assets/railroad-peg-JR7BVNR7-DNn72e7r.js +1 -0
  84. package/dist/assets/railroadDiagram-Y72NRBL7-DNeop1iZ.js +1 -0
  85. package/dist/assets/requirementDiagram-EQYSW5RA-BVYZ2XYJ.js +84 -0
  86. package/dist/assets/rough.esm-Dy-Kn_BL.js +1 -0
  87. package/dist/assets/sankeyDiagram-SY24JHO5-B2MP51on.js +40 -0
  88. package/dist/assets/sequenceDiagram-BLEHNHQU-BUvxstXG.js +169 -0
  89. package/dist/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
  90. package/dist/assets/src-BrR0lqlG.js +1 -0
  91. package/dist/assets/stateDiagram-v2-A6IESKWZ-Ba84OGKE.js +291 -0
  92. package/dist/assets/swimlanes-B3ENRKFQ-BMSl2PNA.js +1 -0
  93. package/dist/assets/swimlanesDiagram-AYQRV4AK-M1dmvq7m.js +8 -0
  94. package/dist/assets/timeline-definition-JXYKGLGB-DOdW-dxq.js +120 -0
  95. package/dist/assets/treeView-D4JQ5SDB-DZ9KQyn5.js +1 -0
  96. package/dist/assets/treemap-SAJKECNS-WEC5wtDV.js +1 -0
  97. package/dist/assets/usecaseDiagram-WPOLBNNX-cldTztFL.js +328 -0
  98. package/dist/assets/vennDiagram-Q3Y3IDCW-c41KySoY.js +34 -0
  99. package/dist/assets/wardley-7MLQ67FV-Bf9_aSSZ.js +1 -0
  100. package/dist/assets/wardleyDiagram-IVAIDKWA-BeKEvEBG.js +78 -0
  101. package/dist/assets/xychartDiagram-4URNHDU4-tNkAxTxG.js +7 -0
  102. package/dist/index.html +22 -0
  103. package/package.json +50 -4
  104. package/server/config.js +389 -0
  105. package/server/consensus.js +180 -0
  106. package/server/graph/anchordb_client.js +253 -0
  107. package/server/graph/model.js +157 -0
  108. package/server/graph/parser.js +327 -0
  109. package/server/graph/sources.js +801 -0
  110. package/server/graph/syntax.js +437 -0
  111. package/server/index.js +742 -0
  112. package/server/install.js +437 -0
  113. package/server/map.js +126 -0
  114. package/server/models_registry.js +109 -0
  115. package/server/scaffold.js +466 -0
package/README.md CHANGED
@@ -1,3 +1,484 @@
1
- # Temporary Holding Version
1
+ # knl-view
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A local viewer for `.knowledges` knowledge bases: a CLI that serves a small web
4
+ app over a plain folder of Markdown files. The disk is the source of truth;
5
+ `map.json` is optional decoration.
6
+
7
+ ```
8
+ knl-view --port 8086 --path=.knowledges
9
+ ```
10
+
11
+ ## What it does
12
+
13
+ - Serves a web viewer over any folder of Markdown files. No database, no build
14
+ step for your content, no account.
15
+ - Sidebar tree with a fixed `index` entry (the root `README.md`) and a
16
+ `contents` entry that lists the whole base on one page.
17
+ - Folders open their own `README.md`, rendered the same way as a normal document.
18
+ - `map.json` (optional) relabels, reorders, or hides entries in the menu. It
19
+ never creates, moves, or deletes files. Entries pointing at paths that are not
20
+ on disk are ignored silently.
21
+ - Markdown with GFM tables, and triple-backtick fences tagged `mermaid` rendered
22
+ as diagrams. The mermaid bundle is served locally and loaded only when a
23
+ document contains a diagram; nothing is fetched from a CDN.
24
+ - Per-diagram controls: toggle between diagram and source, and a zoom modal
25
+ (wheel zoom, drag to pan, +/−/Reset, Esc to close).
26
+ - Table of contents per document, breadcrumb, and a filter box in the sidebar
27
+ that narrows the index by file title or path.
28
+ - Interface in English or Indonesian, switchable in the top bar. English is the
29
+ default.
30
+ - Whole-project dependency and symbol call graph extraction via WebAssembly
31
+ Tree-Sitter for JavaScript, TypeScript, Go, Python, and Rust.
32
+
33
+ ## Requirements
34
+
35
+ - Node.js 20.19 or newer.
36
+ - A built frontend. `dist/` is committed to this repository, so an install from
37
+ GitHub already has it. The CLI refuses to start without it and tells you so.
38
+
39
+ ## Install
40
+
41
+ ```sh
42
+ npm install -g @rahmantech/knl-view
43
+ ```
44
+
45
+ That puts the `knl-view` command into Node's global bin,
46
+ `$(npm prefix -g)/bin`. If that directory is not on your PATH, link the
47
+ command somewhere that is:
48
+
49
+ ```sh
50
+ ln -s "$(npm prefix -g)/bin/knl-view" ~/.local/bin/knl-view
51
+ ```
52
+
53
+ The published tarball ships the built `dist/`, so the install compiles
54
+ nothing.
55
+
56
+ Run it once without installing:
57
+
58
+ ```sh
59
+ npx @rahmantech/knl-view
60
+ ```
61
+
62
+ Or install from source, for a local checkout or an unreleased commit:
63
+
64
+ ```sh
65
+ git clone https://github.com/rachmanzz/knl-view.git
66
+ cd knl-view
67
+ npm install
68
+ npm run build
69
+ npm link
70
+ ```
71
+
72
+ `npm link` puts `knl-view` on your PATH from the checkout. To install a
73
+ GitHub commit without cloning, run
74
+ `npm install -g github:rachmanzz/knl-view --install-links`; without
75
+ `--install-links`, npm 11 links against a temporary clone it deletes
76
+ afterwards, which leaves a broken install.
77
+
78
+ ## How to Set Up
79
+
80
+ Setting up a project takes a single command:
81
+
82
+ ```sh
83
+ knl-view setup
84
+ ```
85
+
86
+ Or run directly without installing:
87
+
88
+ ```sh
89
+ npx @rahmantech/knl-view setup
90
+ ```
91
+
92
+ ### What `knl-view setup` Does Automatically
93
+ 1. **Scaffolds `.knowledges/`**: Creates the documentation directory with a starter `README.md` index and template folders (or custom folders via `--folders`).
94
+ 2. **Installs Agent Skills**: Automatically places the `knl-view` skill into `.agents/skills/knl-view/` so coding agents (Antigravity, Claude, Codex, OpenCode) can read and manage your knowledge base.
95
+ 3. **Integrates Decision History**: Audits and offers to install the `decision-history` skill ([decisionskills](https://github.com/rachmanzz/decisionskills)) for append-only architecture decision tracking.
96
+ 4. **Protects Configuration**: Ensures `.gitignore` includes `knl-config.json` and temporary artifacts.
97
+ 5. **Auto-maps AnchorDB Models**: Configures `knowledges` and `sources` model identifiers in `knl-config.json` and records them in the machine-wide registry.
98
+ 6. **Provisions AnchorDB**: Prompts to start or provision an AnchorDB instance (native binary on Linux, Podman/Docker container on Windows & macOS).
99
+ 7. **Seeds Agent Rules**: Configures standardized KNL-View instructions in `AGENTS.md`, `GEMINI.md`, and `CLAUDE.md`.
100
+
101
+ After setup, start the viewer immediately:
102
+
103
+ ```sh
104
+ knl-view
105
+ ```
106
+
107
+ ## Usage
108
+
109
+ ```sh
110
+ knl-view setup # bootstrap project (scaffold base, skill, gitignore, models)
111
+ knl-view # serve ./.knowledges on 127.0.0.1:8085
112
+ knl-view --path=../other-project/.knowledges
113
+ knl-view --port 8086 --host 0.0.0.0 # expose on the network
114
+ knl-view graph trace --target=README.md # query on-demand subgraph for AI
115
+ knl-view graph trace --target=DEC-20261030-135001 --hops=1
116
+ knl-view --init # scaffold a new base (wizard, no server)
117
+ knl-view --seed-skill=knl-view --dir=global --yes
118
+ ```
119
+
120
+ | Flag | Default | What it does |
121
+ | --- | --- | --- |
122
+ | `--port`, `-p` | `8085` | HTTP port |
123
+ | `--path` | `.knowledges` | Folder to serve, relative to the working directory |
124
+ | `--host` | `127.0.0.1` | Bind address |
125
+ | `--anchordb` | none | AnchorWire URL (`wire://host:port?token=...`) for this session; overrides the global config block |
126
+ | `--target` | none | Target node ID for CLI subgraph trace (`knl-view graph trace`) |
127
+ | `--hops` | `2` | Traversal depth radius for subgraph extraction |
128
+ | `--method` | auto | Install method for `install anchordb`: `binary` or `container` |
129
+ | `--runtime` | auto | Container runtime for `install anchordb`: `docker` or `podman` |
130
+ | `--init` | off | Scaffold a new base interactively; does not start the server |
131
+ | `--structure` | `standard` | Layout for a non-interactive `--init`: `standard`, `empty`, or `custom` |
132
+ | `--folders` | none | Comma-separated folder names for `--structure=custom` |
133
+ | `--seed-skill=knl-view` | off | Write the `knl-view` skill for coding agents; skipped if it already exists |
134
+ | `--dir` | `project` | Skill location: `project` (`.agents/skills`) or `global` (`~/.config/opencode/skills`) |
135
+ | `--yes`, `-y` | off | Accept every default in `--init` / `--seed-skill`, no questions asked |
136
+ | `--help`, `-h` | | Show help |
137
+ | `--version`, `-v` | | Show version |
138
+
139
+ The server binds to `127.0.0.1` by default, so it is reachable only from your
140
+ machine unless you pass `--host` yourself. There is no authentication; treat
141
+ `--host 0.0.0.0` as a decision you are making on purpose.
142
+
143
+ ## Configuration
144
+
145
+ Two optional config files. A missing file is never an error; a broken file is
146
+ ignored with one warning on stderr. CLI flags always win over config values.
147
+
148
+ **Global (`~/.knlview/knl-config.json`)**: shared by every project on the
149
+ machine. Holds the `anchordb` block. Without it, AnchorDB stays completely
150
+ off and the viewer runs fully local:
151
+
152
+ ```json
153
+ {
154
+ "anchordb": {
155
+ "url": "wire://127.0.0.1:17448",
156
+ "token": "your-token",
157
+ "sync": true,
158
+ "deamon": "podman",
159
+ "container_name": "anchordb-knlview",
160
+ "container_id": "56519e7acbaa...",
161
+ "container_created_on": "2026-10-31 14:08:48..."
162
+ }
163
+ }
164
+ ```
165
+
166
+ **Per project: `knl-config.json` at the project root** (gitignored):
167
+ `path`, `port`, `host`, `models`, and optional `include` / `exclude` patterns:
168
+
169
+ ```json
170
+ {
171
+ "port": 8091,
172
+ "models": {
173
+ "knowledges": "vez0vqrp",
174
+ "consensus": "n0qrnmsz"
175
+ },
176
+ "include": ["dist/bundle.js"],
177
+ "exclude": ["legacy/**", "*.tmp"]
178
+ }
179
+ ```
180
+
181
+ - `exclude`: Hard exclude that strictly filters files and folders from graph analysis and knowledge tree. Always takes precedence over defaults and includes.
182
+ - `include`: Whitelists files and folders. Overrides default directory exclusions (e.g. including files from `dist/` or dot-folders).
183
+
184
+ Model names are owned by the `models` map: role → name, and the name can
185
+ be anything (random names are fine; the map records what each name is
186
+ *for*). Names stay stable even if the project folder is renamed. knl-view
187
+ never invents names by itself: create them with
188
+ `knl-view model new <role>` (writes the map and the global registry), and
189
+ inspect ownership with `knl-view model check`.
190
+
191
+ The global registry `~/.knlview/models.json` records every name's owner
192
+ (project, role, path) and warns when two projects claim the same name. A
193
+ project whose map has no entry for a role runs fully local: AnchorDB is
194
+ touched only once the role is mapped.
195
+
196
+ ## Operating System Support & Installing AnchorDB
197
+
198
+ ### Operating System Support
199
+
200
+ | OS | Core Viewer (`knl-view`) | Global Config Location | AnchorDB Backend |
201
+ | --- | --- | --- | --- |
202
+ | **Linux** | Native (Node.js >= 20.19) | `~/.knlview/knl-config.json` | **Native Binary** (`amd64`, `arm64`) or Container |
203
+ | **macOS** | Native (Node.js >= 20.19) | `~/.knlview/knl-config.json` | **Container**: **Podman (Recommended)** or Docker |
204
+ | **Windows** | Native (Node.js >= 20.19) | `%APPDATA%\knlview\knl-config.json` | **Container**: **Podman (Recommended)** or Docker |
205
+
206
+ ---
207
+
208
+ ### Installing AnchorDB (Optional)
209
+
210
+ AnchorDB is an optional layer. Without it, the viewer runs 100% locally with zero external dependencies: document browsing, full-text search, the Markdown graph engine, and `knl-view graph trace` all work immediately. Installing AnchorDB adds persistent multi-hop causal tracing across sessions, whole-project source code dependency syncing, and shared multi-machine graphs.
211
+
212
+ Run `knl-view install anchordb` to install AnchorDB and write the `anchordb` block into your global configuration:
213
+
214
+ #### 1. Linux (Native Standalone Binary)
215
+ - Native binaries are published on [GitHub Releases](https://github.com/rachmanzz/anchordb/releases) for Linux architectures:
216
+ - `linux_amd64` (x86_64)
217
+ - `linux_arm64` (aarch64)
218
+ - On Linux, `knl-view install anchordb` automatically:
219
+ - Fetches the latest release asset and verifies it against the official `SHA256SUMS.txt`.
220
+ - Installs `anchordb-server` and `anchordb` into `~/.knlview/bin/` with secure file permissions (`0o700` / `0o755`).
221
+ - Starts `anchordb-server` detached as a background process daemon (logs in `~/.knlview/anchordb.log`, data in `~/.knlview/anchordb-data`).
222
+ - You can also explicitly opt for containers on Linux using `--method=container`.
223
+
224
+ #### 2. Windows & macOS (Container via Podman or Docker)
225
+ - AnchorDB relies on Linux kernel primitives (`mmap` memory mapping and POSIX file locking). Native binaries are not yet published for Windows or macOS.
226
+ - For Windows and macOS, AnchorDB is currently deployed via a lightweight container image (`ghcr.io/rachmanzz/anchordb`):
227
+ - **Podman (Recommended)**: Rootless, daemonless, lightweight, and requires no administrative privileges or background daemons.
228
+ - **Docker**: Supported via Docker Desktop or Docker Engine (`--runtime=docker`).
229
+ - `knl-view install anchordb` automatically detects installed container runtimes. If both are found, it prompts you to select **Podman (Recommended)** or **Docker**. If neither is installed, it halts with clear installation guidance.
230
+
231
+ #### Flags & Automation (CI / Scripts)
232
+ - Non-interactive mode: add `--yes` (accepts all defaults).
233
+ - Force install method: `--method=binary` or `--method=container`.
234
+ - Specify container engine: `--runtime=podman` (recommended) or `--runtime=docker`.
235
+ - Custom token: `--token=<text>` (default: cryptographic 32-byte hex token).
236
+ - Port conflict handling: automatically detects if port 17448 is occupied and suggests alternative free ports.
237
+ - Data safety: if a container named `anchordb-knlview` already exists, the installer stops rather than overwriting existing data.
238
+
239
+ ## How a base is read
240
+
241
+ A base is an ordinary folder:
242
+
243
+ ```
244
+ .knowledges/
245
+ README.md # the index document
246
+ map.json # optional
247
+ roadmap/
248
+ README.md
249
+ q1.md
250
+ features/
251
+ auth.md
252
+ ```
253
+
254
+ Reading order: the root `README.md`, then `map.json` when present, then the
255
+ structure on disk. Without `map.json`, menu labels fall back to the first
256
+ `# heading` of each file, then to the plain file name (files before folders).
257
+
258
+ ### map.json
259
+
260
+ Every entry is decoration. Nothing in it can invent a file that is not on disk.
261
+
262
+ ```json
263
+ {
264
+ "title": "Base title shown in the masthead",
265
+ "sections": {
266
+ "roadmap": { "title": "Roadmap", "order": 1, "meta": "Where this is going" }
267
+ },
268
+ "docs": {
269
+ "coding-rules.md": { "title": "Coding rules", "order": 1 }
270
+ },
271
+ "files": {
272
+ "secret.md": { "ignore": true }
273
+ },
274
+ "dirs": {
275
+ "old-drafts": { "ignore": true }
276
+ }
277
+ }
278
+ ```
279
+
280
+ | Field | Applies to | Effect |
281
+ | --- | --- | --- |
282
+ | `title` | the whole file | Masthead title; wins over the README heading |
283
+ | `sections.<dir>` / `dirs.<path>` | a directory | `title` is the menu label, `meta` is a short note |
284
+ | `docs.<file>` / `files.<path>` | a file | `title` is the menu label |
285
+ | `order` | any entry | Ascending menu order; entries without `order` follow, files before folders |
286
+ | `ignore` (or `hidden`) | any entry | `true` hides it from the menu, lists, search, home, and contents |
287
+
288
+ Paths are relative to the `.knowledges` root, use `/` separators, and must
289
+ match the on-disk path exactly, for example `features/auth.md`. `ignore` is
290
+ view-only: the file stays on disk. Remove the flag to bring it back.
291
+
292
+ The full field reference lives in the bundled skill:
293
+ `.agents/skills/knl-view/SKILL.md`.
294
+
295
+ ## AI Graph & Decision Tracing
296
+
297
+ `knl-view` includes an AI-native directed acyclic graph (DAG) engine built directly into the CLI and server. It connects knowledge documents (`.knowledges/*.md`) and architectural decision records (`.knowledges/decisions/*.md`) into a unified graph:
298
+
299
+ - **Zero Intermediary File**: Fully on-the-fly in-memory processing. Markdown files remain the sole source of truth without generating out-of-sync `graph.json` cache files.
300
+ - **Decision Lineage Tracking**: Automatically discovers `supersedes`, `related_to`, and `affects_knowledge` edges from `decisionskills` decision blocks.
301
+ - **Low-Token Subgraphs for AI**: Instead of loading an entire knowledge base into LLM context, query exact $N$-hop subgraphs in sub-milliseconds (< 1 ms).
302
+
303
+ This engine is fully local: it needs no AnchorDB and no network. AnchorDB
304
+ (see the optional install above) adds persistence on top: edges survive
305
+ across sessions, are synced incrementally, and can be traced from any
306
+ machine pointing at the same server.
307
+
308
+ ### Two-way lineage
309
+
310
+ Traces walk in a mechanically defined direction relative to the edges,
311
+ never interpreted as cause and effect (`depends_on` edges *leave* a
312
+ decision while pointing at its upstream, so up/down labels would lie):
313
+
314
+ - `direction=out`: edges leaving the target: what it supersedes,
315
+ `depends_on`, or affects.
316
+ - `direction=in`: edges entering the target: what references or
317
+ replaces it.
318
+ - `direction=both`: the default for the local graph trace; the full
319
+ neighborhood.
320
+
321
+ Every returned node carries `via` (`center`, `in`, `out`, or `in+out`)
322
+ telling how it connects to the trace center.
323
+
324
+ CLI: `knl-view graph trace --target=<id> --direction=out`
325
+ HTTP: `GET /api/graph/trace?target=<id>&direction=in`
326
+
327
+ The AnchorDB endpoint adds the same parameter,
328
+ `GET /api/anchordb/trace?target=<id>&direction=in|out|both` (default
329
+ `out`): `out` is scored server-side via `causalChain`; `in` is walked
330
+ backwards from the local sync mirror; the wire protocol has no reverse
331
+ query, and the mirror holds every edge this project ever linked, so it
332
+ is exactly the inbound map for this project's model. Mirror results
333
+ carry score 1 and the response reports `mirrored: true`/`false` so
334
+ consumers know which half came from where.
335
+
336
+ ### Consensus (claims)
337
+
338
+ A second AnchorDB model, the `consensus` role in the project's models map,
339
+ holds agreement and conflict between *claims*: short statements that are
340
+ content-addressed (`c-` + 16 hex chars of the statement's hash), so the same
341
+ text is the same claim on every machine. Claims relate only to other claims,
342
+ through two fixed relation types: `agrees_with` and `contradicts`. The
343
+ consensus structure lives purely in AnchorDB; the local artifacts (claim
344
+ index in `~/.knlview/claims/`, edge mirror in `~/.knlview/sync-state/`) are
345
+ caches that degrade convenience, never the data.
346
+
347
+ A claim's status is derived from who points at it: any incoming `contradicts`
348
+ makes it `disputed`, otherwise any incoming `agrees_with` makes it
349
+ `consensus`, otherwise it is `uncontested`.
350
+
351
+ ```sh
352
+ knl-view consensus claim "We use bcrypt for password hashing"
353
+ knl-view consensus agree c-a1b2c3d4e5f6a1b2 c-437ff9f10f83edde
354
+ knl-view consensus contradict c-a1b2c3d4e5f6a1b2 c-437ff9f10f83edde
355
+ knl-view consensus retract c-a1b2c3d4e5f6a1b2 c-437ff9f10f83edde
356
+ knl-view consensus status c-437ff9f10f83edde
357
+ knl-view consensus list
358
+ ```
359
+
360
+ Mutations are CLI-only on purpose: one write path, one mirror kept honest.
361
+ The read-only HTTP endpoint answers "is this claim settled?":
362
+
363
+ `GET /api/consensus?target=<claimId>` returns the claim's `status`,
364
+ `supporters`, `objectors`, its own `stance`, `mirrored` (whether a valid
365
+ local mirror backs the inbound half), and a `statements` map of the
366
+ claim texts involved. Returns `503` when AnchorDB is off or the
367
+ `consensus` role is not mapped.
368
+
369
+ ### Sources graph (whole project)
370
+
371
+ A third AnchorDB model, the `sources` role in the models map, holds the
372
+ dependency graph of the whole project, not just `.knowledges`. Every file
373
+ becomes a node (id = repo-relative path; hidden folders are skipped except
374
+ `.github`, and `node_modules`, `dist`, and `.gitignore` patterns are
375
+ ignored). Import edges are extracted with tree-sitter syntax parsing
376
+ (JavaScript, TypeScript/TSX, Go, Python, and Rust, one grammar package per
377
+ language family) and stored in both directions (`imports`, `imported_by`) so
378
+ lineage works without any local mirror: sync is server-authoritative, enumerating
379
+ the server's own records and edges before applying the difference from a fresh
380
+ disk scan.
381
+
382
+ Each file also defines **symbol nodes**, extracted from the same parse:
383
+
384
+ - Symbol ids are `<path>#<name>`; class methods are `Class.method`. A name
385
+ defined more than once in one file gets a line suffix
386
+ (`<path>#<name>@<line>`), so duplicate helpers stay distinct records.
387
+ - Kinds: `function`, `class`, `method`, `type`, `interface`, `enum`, `struct`, `trait`.
388
+ - Edges: `defines`/`defined_in` (file → symbol) and `calls`/`called_by`
389
+ (symbol → symbol), each stored in both directions because causalChain
390
+ walks forward only.
391
+ - Call resolution is conservative: a call belongs to its innermost
392
+ enclosing symbol, and the callee must match exactly one definition
393
+ project-wide (same package directory preferred in Go). A receiver-qualified
394
+ call (`obj.Method()`) resolves only when the receiver is an import
395
+ binding of the file, otherwise it is skipped, never guessed.
396
+ - Label text (symbol names and kinds; AnchorDB attributes are
397
+ numeric-only) is written to `.knowledges/.knl-data/<path>.md`, one file
398
+ per source file that has symbols; override the location with `labelDir`
399
+ in the project config. Labels are regenerated and pruned on every sync.
400
+
401
+ #### Supported Languages (v0.2.0)
402
+
403
+ Tree-sitter WASM grammars run in-memory within Node.js without requiring host compilers:
404
+
405
+ | Language | Extensions | Extracted Symbols | Import Resolution |
406
+ | :--- | :--- | :--- | :--- |
407
+ | **JavaScript** | `.js`, `.mjs`, `.cjs`, `.jsx` | `function`, `class`, `method` | ESM (`import`/`export`), dynamic `import()`, CJS `require()` |
408
+ | **TypeScript** | `.ts`, `.mts`, `.cts`, `.tsx` | `function`, `class`, `method`, `interface`, `type`, `enum` | ESM/CJS, automatic resolution of `.js` specifiers to `.ts`/`.tsx` on disk |
409
+ | **Go** | `.go` | `function`, `method` (receiver-qualified), `type` | `go.mod` module-internal packages |
410
+ | **Python** | `.py` | `function`, `class`, `method` | Relative imports (`.local`, `..pkg`) and dot-separated package paths |
411
+ | **Rust** | `.rs` | `function`, `method` (`impl`), `struct`, `enum`, `trait`, `type` | `mod <name>;`, `use crate::`, `use super::`, `use self::` |
412
+
413
+ #### Upcoming Languages (Planned for Next Versions)
414
+
415
+ Support for additional languages via WebAssembly Tree-Sitter grammars will be added in upcoming releases:
416
+
417
+ - **Java** (`.java`): Class, interface, record, method extraction, package imports
418
+ - **C / C++** (`.c`, `.h`, `.cpp`, `.hpp`): Functions, structs, classes, `#include` resolution
419
+ - **C#** (`.cs`): Classes, structs, interfaces, methods, namespaces/using
420
+ - **Ruby** (`.rb`): Modules, classes, methods, `require_relative`
421
+ - **PHP** (`.php`): Classes, interfaces, traits, functions, namespaces/use
422
+
423
+ ```sh
424
+ knl-view model new sources
425
+ knl-view sources sync
426
+ knl-view sources collect
427
+ knl-view sources trace --target=server/index.js --direction=out --hops=2
428
+ knl-view sources trace --target=server/index.js#handleTrace --direction=in
429
+ ```
430
+
431
+ `sync` is idempotent: run it again after refactoring and only the
432
+ difference is applied. A target containing `#` traces symbol lineage over
433
+ `calls`/`called_by`; a plain path traces file lineage over
434
+ `imports`/`imported_by`. Records the disk no longer has are archived with
435
+ the native lifecycle opcode 2 (TOMBSTONE: the server hides them from list
436
+ and lookups) after their edges are unlinked, and the `tombstone = 2`
437
+ attribute stays as a marker for servers that predate opcode support.
438
+ `sync` then asks the REST collector to purge those records physically
439
+ (scoped to the model); run `knl-view sources collect` by hand if the REST
440
+ endpoint was unreachable at that moment. A reappearing file revives the
441
+ record with a normal save and relinks its edges. Sync reports
442
+ `ORPHAN EDGES` when an edge endpoint failed to save, so a broken sync is
443
+ never silent. The read-only HTTP endpoint answers the same queries:
444
+ `GET /api/sources/trace?target=<id>&direction=in|out|both&hops=N`.
445
+
446
+ ### CLI Query
447
+
448
+ ```sh
449
+ knl-view graph trace --target=DEC-20261030-135001 --hops=1
450
+ ```
451
+
452
+ Outputs a compact JSON subgraph to `stdout` containing the focal node and all direct dependencies/impacted components.
453
+
454
+ ### HTTP Endpoints
455
+
456
+ When `knl-view` is running as a local server:
457
+ - `GET /api/graph`: Returns the entire knowledge and decision graph structure.
458
+ - `GET /api/graph/trace?target=<id>&hops=2`: Returns an isolated $N$-hop neighborhood subgraph for AI agents or interactive visualization.
459
+ - `GET /api/anchordb/trace?target=<id>&hops=2`: Returns a causal chain traced on the AnchorDB server (requires the global `anchordb` config block). Returns `503` when AnchorDB is off or unreachable.
460
+ - `GET /api/consensus?target=<claimId>`: Read-only consensus status for one claim (requires AnchorDB and a mapped `consensus` role). Returns `503` when AnchorDB is off or the role is unmapped, `400` without a target.
461
+ - `GET /api/sources/trace?target=<path>&direction=in|out&hops=2`: Read-only file lineage over the whole-project sources graph (requires AnchorDB and a mapped `sources` role). Returns `503` when unavailable, `400` without a target or with a bad direction.
462
+
463
+ ## Development
464
+
465
+ ```sh
466
+ npm run dev
467
+ ```
468
+
469
+ Starts the API on port 8085 (override with `PORT`) and the Vite dev server on
470
+ 5173 (override with `WEB_PORT`). Pass a base folder as the first argument:
471
+
472
+ ```sh
473
+ npm run dev -- ../some-project/.knowledges
474
+ ```
475
+
476
+ `dist/` is committed to this repository so that installs straight from GitHub
477
+ keep working, because npm runs no build step for a git install without a
478
+ `prepare` script. After changing the frontend, run `npm run build` and commit
479
+ the result together with the source, or those installs stay on the previous
480
+ build.
481
+
482
+ ## License
483
+
484
+ Apache-2.0. See [LICENSE](LICENSE).