wiki-graph 0.3.0 → 0.4.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 (69) hide show
  1. package/README.md +10 -271
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.js +2983 -4
  4. package/dist/cli.js.map +1 -0
  5. package/{data → dist/data}/editor/text_compressor.jinja +17 -13
  6. package/{data → dist/data}/help/commands/archive/next.jinja +7 -2
  7. package/{data → dist/data}/help/commands/gc.jinja +2 -1
  8. package/{data → dist/data}/help/commands/legacy/migrate.jinja +6 -1
  9. package/{data → dist/data}/help/commands/legacy.jinja +3 -2
  10. package/dist/data/help/commands/library-predicate.jinja +296 -0
  11. package/dist/data/help/commands/library.jinja +235 -0
  12. package/{data → dist/data}/help/commands/maintenance/chapter/add.jinja +3 -3
  13. package/{data → dist/data}/help/commands/maintenance/chapter/list.jinja +4 -4
  14. package/{data → dist/data}/help/commands/maintenance/chapter/move.jinja +4 -4
  15. package/{data → dist/data}/help/commands/maintenance/chapter/remove.jinja +1 -1
  16. package/{data → dist/data}/help/commands/maintenance/chapter/reset.jinja +1 -1
  17. package/{data → dist/data}/help/commands/maintenance/chapter/set-source.jinja +2 -2
  18. package/{data → dist/data}/help/commands/maintenance/chapter/set-summary.jinja +1 -1
  19. package/{data → dist/data}/help/commands/maintenance/chapter/set-title.jinja +3 -3
  20. package/{data → dist/data}/help/commands/maintenance/chapter/tree.jinja +6 -6
  21. package/{data → dist/data}/help/commands/maintenance/chapter.jinja +10 -10
  22. package/{data → dist/data}/help/commands/maintenance/meta.jinja +7 -7
  23. package/dist/data/help/commands/maintenance/upgrade.jinja +35 -0
  24. package/dist/data/help/commands/maintenance.jinja +23 -0
  25. package/{data → dist/data}/help/commands/predicate.jinja +204 -28
  26. package/{data → dist/data}/help/commands/root.jinja +10 -3
  27. package/{data → dist/data}/help/commands/uri.jinja +165 -6
  28. package/{data → dist/data}/help/topics/config.jinja +10 -3
  29. package/dist/data/help/topics/library.jinja +87 -0
  30. package/{data → dist/data}/help/topics/readiness.jinja +32 -2
  31. package/{data → dist/data}/help/topics/recipe.jinja +42 -17
  32. package/{data → dist/data}/help/topics/runtime.jinja +20 -3
  33. package/{data → dist/data}/help/topics/uri.jinja +51 -25
  34. package/dist/gc-worker.d.ts +1 -0
  35. package/dist/gc-worker.js +548 -0
  36. package/dist/gc-worker.js.map +1 -0
  37. package/dist/index.cjs +12463 -19690
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +36 -842
  40. package/dist/index.d.ts +36 -842
  41. package/dist/index.js +13871 -9
  42. package/dist/index.js.map +1 -0
  43. package/dist/queue-worker.d.ts +1 -0
  44. package/dist/queue-worker.js +2110 -0
  45. package/dist/queue-worker.js.map +1 -0
  46. package/package.json +18 -45
  47. package/dist/cli.cjs +0 -41734
  48. package/dist/cli.cjs.map +0 -1
  49. package/docs/images/flowchart.excalidraw +0 -3293
  50. package/docs/images/flowchart.svg +0 -4
  51. package/docs/images/terminal-cn.png +0 -0
  52. package/docs/images/terminal-en.png +0 -0
  53. package/docs/wikispine-runtime.md +0 -143
  54. /package/{data → dist/data}/editor/clue_reviewer.jinja +0 -0
  55. /package/{data → dist/data}/editor/clue_reviewer_generator.jinja +0 -0
  56. /package/{data → dist/data}/editor/revision_feedback.jinja +0 -0
  57. /package/{data → dist/data}/guaranteed/response_intent_classifier.jinja +0 -0
  58. /package/{data → dist/data}/help/commands/maintenance/cover.jinja +0 -0
  59. /package/{data → dist/data}/help/commands/transform.jinja +0 -0
  60. /package/{data → dist/data}/help/topics/format.jinja +0 -0
  61. /package/{data → dist/data}/output/epub/cover.xhtml.jinja +0 -0
  62. /package/{data → dist/data}/output/epub/nav.xhtml.jinja +0 -0
  63. /package/{data → dist/data}/output/epub/package.opf.xml.jinja +0 -0
  64. /package/{data → dist/data}/output/epub/section.xhtml.jinja +0 -0
  65. /package/{data → dist/data}/topologization/book_coherence_extraction.jinja +0 -0
  66. /package/{data → dist/data}/topologization/chunk_extraction.jinja +0 -0
  67. /package/{data → dist/data}/topologization/evidence_choice.jinja +0 -0
  68. /package/{data → dist/data}/topologization/translate_chunks.jinja +0 -0
  69. /package/{data → dist/data}/topologization/user_focused_extraction.jinja +0 -0
package/README.md CHANGED
@@ -1,278 +1,17 @@
1
- ![](./docs/images/terminal-en.png)
1
+ # Wiki Graph CLI
2
2
 
3
- <div align="center">
4
- <h1>Wiki Graph</h1>
5
- <p>English | <a href="./README_zh-CN.md">中文</a></p>
6
- <p>
7
- <a href="https://www.npmjs.com/package/wiki-graph"><img alt="npm version" src="https://img.shields.io/npm/v/wiki-graph"></a>
8
- <a href="https://opensource.org/licenses/Apache-2.0"><img alt="License: Apache 2.0" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a>
9
- <a href="https://nodejs.org/"><img alt="Node >=22.12.0" src="https://img.shields.io/badge/node-%3E%3D22.12.0-brightgreen"></a>
10
- </p>
11
- </div>
3
+ `wiki-graph` is the command-line package for [Wiki Graph](https://github.com/oomol-lab/wiki-graph), a tool for managing long-text knowledge bases in `.wikg` archives.
12
4
 
13
- Wiki Graph is an open-source CLI for managing long-text knowledge bases, built toward [Andrej Karpathy](https://github.com/karpathy)'s [LLM Wiki](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f) idea and Google's [OKF](https://cloud.google.com/blog/products/data-analytics/how-the-open-knowledge-format-can-improve-data-sharing) direction.
14
-
15
- It writes plain text into `.wikg` archives and can generate searchable, source-traceable Knowledge Graphs on demand. In practice, it provides a runnable CLI for turning Karpathy's LLM Wiki idea into an executable knowledge production workflow.
16
-
17
- In agent workflows, PDFs, web pages, EPUBs, subtitles, meeting recordings, video courses, and internal documents can first be converted into plain text by external tools, then handed to Wiki Graph. Wiki Graph handles the second half: placing that long text into a knowledge base, extracting Entities and Triples, and preserving evidence that can be traced back to chapters and original sentences. When compressed reading is needed, it can also build a Reading Graph and generate a Summary from it.
18
-
19
- Karpathy's core point is that AI should not go back to raw material from scratch every time it answers a question; knowledge should be compiled into a maintainable Wiki. OKF pushes this kind of Wiki practice toward open, portable knowledge formats. Wiki Graph makes the OKF source layer concrete: it turns long text into knowledge material that a Wiki or OKF system can continue to consume, including entities, relations, and evidence that can point back to the source.
20
-
21
- ## Quick Start
22
-
23
- Requirement: Node.js `>=22.12.0`
24
-
25
- Install:
26
-
27
- ```bash
28
- $ npm install -g wiki-graph
29
- ```
30
-
31
- The primary command is `wg`; `wikigraph` is also available.
32
-
33
- Create an empty `.wikg` knowledge base:
34
-
35
- ```bash
36
- $ wg wikg://quickstart.wikg create
37
- ```
38
-
39
- Add text as two source chapters:
40
-
41
- ```bash
42
- $ printf "Alpha is connected to beta.\n" | wg wikg://quickstart.wikg/chapter add --title "First note" --input -
43
-
44
- $ printf "Beta mentions gamma.\n" > tmp.txt && wg wikg://quickstart.wikg/chapter add --title "Second note" --input ./tmp.txt
45
- ```
46
-
47
- Show the chapter tree:
48
-
49
- ```bash
50
- $ wg wikg://quickstart.wikg/chapter/tree
51
-
52
- ├─ First note wikg://chapter/1
53
- └─ Second note wikg://chapter/2
54
- ```
55
-
56
- Enable and build the FTS index. Full-text `--query` search is available after this step:
57
-
58
- ```bash
59
- $ wg wikg://quickstart.wikg/index enable
60
- ```
61
-
62
- Search the content:
63
-
64
- ```bash
65
- $ wg wikg://quickstart.wikg --query alpha
66
-
67
- @@ wikg://chapter/1/source#1 @@
68
- Alpha is connected to beta.
69
- ```
70
-
71
- ## Why We Built This
72
-
73
- This project started as SpineDigest, with a focus on compressing long text into shorter summaries that were easier to read and carry. That version was built around a reading problem: how can an LLM read a whole book more like a person, keep useful threads in limited working memory, and still return to the source when needed? It used the ideas behind [Miller's Law](https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two) and cognitive [chunking](<https://en.wikipedia.org/wiki/Chunking_(psychology)>) to organize long text into a Reading Graph, then generated summaries from that structure.
74
-
75
- The metaphor at the time was a dissertation defense: professors keep questioning the respondent, reminding them which claim has evidence, which concepts are connected, and which ideas should not be collapsed together. The diagram below describes that older reading-and-summary flow, but it also explains where Wiki Graph starts: long text should not only be flattened once; it should become a structure that can be re-entered, questioned, and verified.
76
-
77
- ![Reading flowchart](./docs/images/flowchart.svg)
78
-
79
- The center of gravity later changed. Summaries are still useful, but a summary is only one projection of long text. The more durable material is the entities, relations, and evidence inside the text. SpineDigest became Wiki Graph, and the main line moved from compressed reading to building maintainable Knowledge Graphs.
80
-
81
- Karpathy's LLM Wiki gives an important direction: knowledge should not be retrieved from raw material from scratch every time; it should be compiled into a maintainable Wiki. In that setup, besides raw sources and the Wiki itself, there is also a schema layer: a maintenance rulebook for the Agent, defining how the Wiki should be organized, how pages should be shaped, how cross-references work, and how new source material should be ingested. Because that rulebook evolves between a person and an LLM around their own domain, preferences, and material, it naturally becomes a private schema. When the Wiki also depends heavily on private entities, the Agent often has to read, extract, and revise repeatedly to find as many entities, relations, and structures as possible. In other words, extraction quality depends not only on model capability, but also on whether that rulebook stays clear and stable; once it drifts, information is easier to miss and hallucinations are easier to write into the knowledge base.
82
-
83
- Wiki Graph starts from a more determinate layer: public entities. Wikipedia / Wikidata acts like a shared public dictionary, already giving relatively stable semantic boundaries to many people, organizations, places, concepts, terms, statutes, and events. Wiki Graph uses [WikiSpine](https://github.com/moskize91/wikispine) to scan text, recall entities that may correspond to Wikipedia / Wikidata, and then use an LLM for disambiguation and filtering. This is closer to recalling candidate entities from a public dictionary and asking the model to disambiguate them, rather than asking the model to decide entity boundaries from scratch; public entity extraction also does not depend on a private schema jointly maintained by a person and an Agent.
84
-
85
- Because this route depends on what Wikipedia / Wikidata already covers, it cannot cover every private entity: internal code names in an employee handbook, ordinary names in a phone book, or non-notable characters in a newly written novel. That is an intentional tradeoff. Wiki Graph does not rush to cover every entity; it first gains stability and reuse for public entity extraction. Once an entity is aligned to the same QID, relations and evidence can accumulate onto the same knowledge object across chapters, books, and source collections.
86
-
87
- What Wiki Graph aims to do is sediment the public knowledge in long text that can be stably aligned into a source layer, so it can become a searchable, traceable, and extensible foundation for a knowledge base.
88
-
89
- ## Core Concepts
90
-
91
- ### `.wikg`
92
-
93
- `.wikg` is the archive file Wiki Graph uses to create, maintain, and share a knowledge base. It can store source text, a chapter tree, Knowledge Graphs, Reading Graphs, summaries, index policy, and metadata, while organizing knowledge base content through hierarchical chapters.
94
-
95
- In the LLM Wiki framing, a knowledge base often resembles a person's second brain: private, continuously growing, and mixed with many personal schemas. `.wikg` is a portable complement to that direction. It gives a knowledge base a clear scope, so it can be organized and delivered like a book, a website, a course, or a set of meeting records.
96
-
97
- It can be used as a personal knowledge base and gradually organized over time. It can also preserve the structure of the original material, such as book chapters, website sections, course units, or video segments. The producer and consumer of a knowledge base need not be the same person; a `.wikg` file can be copied, sent, uploaded, backed up, and shared.
98
-
99
- ### Knowledge Graph
100
-
101
- Knowledge Graph is Wiki Graph's main generated result. It extracts people, organizations, concepts, events, and relations scattered across long text, so the knowledge base is no longer only a searchable text collection. It becomes a structured knowledge network that can be followed through entities and relations.
102
-
103
- Relations are projected as triples: `subject --predicate--> object`. This makes it possible to start from one entity and continue asking what it is connected to, what kind of relation it has, and which source evidence supports that relation.
104
-
105
- This matters especially for long text. The same concept may appear across many chapters, and the same relation may be supported by multiple passages. Knowledge Graph collects those dispersed signals into the same knowledge object, making it easier to see "what is related to what", "where this claim came from", and "which chapters support the same knowledge point".
106
-
107
- Typical questions include:
108
-
109
- - Which important entities appear in the document?
110
- - What objects is a given entity related to?
111
- - Which source passages support a relation?
112
- - Which chapters or passages support the same knowledge point?
113
-
114
- Wiki Graph's Knowledge Graph is mainly composed of Entity, Triple, and Evidence. Entity is a normalized public entity, usually aligned by [WikiSpine](https://github.com/moskize91/wikispine) to a Wikipedia / Wikidata QID, such as a person, organization, place, concept, term, or statute. Private names, internal code names, and unpublished fictional settings are not its main coverage. Triple is an entity-level relation:
115
-
116
- ```text
117
- subject --predicate--> object
118
- ```
119
-
120
- Evidence is the source basis for an entity or relation. Wiki Graph's Knowledge Graph is not meant to only return conclusions; it should also be able to return to source text.
121
-
122
- ### Summary Generation
123
-
124
- Wiki Graph can also generate chapter summaries, compressing long text into shorter reading results that are easier to carry and reuse.
125
-
126
- The summary is not produced by flattening the whole text in one pass. Wiki Graph first builds a Reading Graph: following the idea of cognitive chunks in [Miller's Law](https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two), it breaks long text into traceable [chunks](<https://en.wikipedia.org/wiki/Chunking_(psychology)>), connects them by conceptual relevance, and then organizes them back into reading chains in source order. The Summary is generated from the Reading Graph, so the compressed text can still trace back to source evidence.
127
-
128
- ### Wiki Graph URI
129
-
130
- Wiki Graph uses URIs as stable handles for archives, scopes, and objects. A URI points to either a scope or an object: a scope enumerates or searches a collection of objects, while an object reads or operates on one concrete object.
131
-
132
- ```bash
133
- $ wg wikg://book.wikg/chapter
134
- $ wg wikg://book.wikg/chapter/3
135
- $ wg wikg://book.wikg/chapter/3/chunk
136
- $ wg wikg://book.wikg/entity
137
- $ wg wikg://book.wikg/triple/Q8018/discusses
138
- ```
139
-
140
- The examples above are scope URIs. Calling a scope URI directly lists objects. Adding `--query` searches within that scope. Adding `--limit` limits the number of returned results. Adding `--all` retrieves the full result set, which is suitable for intentional full export or inventory work.
141
-
142
- ```bash
143
- $ wg wikg://book.wikg/chapter/3 --query "memory"
144
- $ wg wikg://book.wikg/entity --query "neural network" --limit 5
145
- $ wg wikg://book.wikg/chapter --all --json
146
- ```
147
-
148
- Object URIs read one concrete object by default:
149
-
150
- ```bash
151
- $ wg wikg://book.wikg/chapter/3/title
152
- $ wg wikg://book.wikg/chapter/3/source#4..8
153
- $ wg wikg://book.wikg/chapter/3/chunk/12
154
- $ wg wikg://book.wikg/entity/Q8018
155
- $ wg wikg://book.wikg/triple/Q8018/discusses/Q123
156
- ```
157
-
158
- Most objects can be scoped to a chapter, such as `chapter/3/source#4..8`, `chapter/3/chunk/12`, or `chapter/3/entity/Q8018`. Some objects can also be accessed at archive scope, such as `entity/Q8018` and `triple/Q8018/discusses/Q123`; the same entity or relation may be supported by multiple chapters.
159
-
160
- The front part of a URI is the archive locator. Absolute paths, relative paths, and Windows paths must be written as Wiki Graph URIs instead of bare filesystem paths:
161
-
162
- ```bash
163
- $ wg wikg:///Users/me/books/book.wikg
164
- $ wg wikg://book.wikg
165
- $ wg wikg://C:/Users/me/books/book.wikg
166
- ```
167
-
168
- Command output often contains short URIs:
169
-
170
- ```text
171
- wikg://chapter/3/source#4..8
172
- wikg://entity/Q8018
173
- wikg://triple/Q8018/discusses/Q123
174
- ```
175
-
176
- These short URIs are archive-relative handles. They keep output readable, but they are not complete command targets. Add the archive locator before passing them back to the CLI:
177
-
178
- ```bash
179
- $ wg wikg://book.wikg/chapter/3/source#4..8
180
- $ wg wikg:///Users/me/books/book.wikg/entity/Q8018
181
- ```
182
-
183
- The common command shape is "URI + predicate". The URI appears first, but it is the object being operated on; the predicate says what to do with it. Without a predicate, a scope URI usually performs list, and an object URI usually performs read.
184
-
185
- ```bash
186
- $ wg wikg://book.wikg/entity/Q8018
187
- $ wg wikg://book.wikg/entity/Q8018 evidence
188
- $ wg wikg://book.wikg/entity/Q8018 related --query "memory"
189
- $ wg wikg://book.wikg/entity/Q8018 pack --budget 5000 --json
190
- ```
191
-
192
- For more URI rules and boundaries, use the CLI help. You can start from the URI topic, or ask for help on a specific URI or URI predicate:
193
-
194
- ```bash
195
- $ wg help uri
196
- $ wg wikg://book.wikg/entity/Q8018 --help
197
- $ wg wikg://book.wikg/entity/Q8018 evidence --help
198
- ```
199
-
200
- ## Common Workflows
201
-
202
- ### Create a Knowledge Base
203
-
204
- ```bash
205
- $ wg wikg://book.wikg create
206
- $ wg wikg://book.wikg create --import ./book.epub
207
- ```
208
-
209
- Without `--import`, this creates an empty `.wikg` knowledge base. `--import` accepts EPUB only; it creates the knowledge base and imports EPUB metadata, cover, chapter tree, and source text.
210
-
211
- ### Inspect Archive State
212
-
213
- ```bash
214
- $ wg wikg://book.wikg inspect
215
- $ wg wikg://book.wikg inspect --json
216
- ```
217
-
218
- `inspect` reports what the archive currently contains, which capabilities are not ready yet, and which help page or command should be used next.
219
-
220
- ### Generate Knowledge Graph
221
-
222
- ```bash
223
- $ wg wikg://local/job add --input wikg://book.wikg --task knowledge-graph --accept-cost
224
- $ wg wikg://local/job add --input wikg://book.wikg/chapter/3 --task knowledge-graph --accept-cost
225
- $ wg wikg://local/job/<job-id> watch --jsonl
226
- ```
227
-
228
- Generation jobs may call an LLM provider. Time and cost depend on material length, model, and configuration. Read `inspect` and job help before starting a job.
229
-
230
- ### Search Entities and Relations
231
-
232
- ```bash
233
- $ wg wikg://book.wikg/entity --query "neural network" --evidence 2
234
- $ wg wikg://book.wikg/triple --query "attention memory" --evidence 2
235
- $ wg wikg://book.wikg/chapter/3/entity --query "attention"
236
- $ wg wikg://book.wikg/chapter/3/triple --query "memory"
237
- ```
238
-
239
- Use the narrowest useful URI scope. If the chapter is known, search from the chapter scope. Use the archive scope when a whole-archive view is needed.
240
-
241
- ### Trace Source Evidence
242
-
243
- ```bash
244
- $ wg wikg://book.wikg/entity/Q8018 evidence
245
- $ wg wikg://book.wikg/triple/Q8018/discusses/Q123 evidence
246
- $ wg wikg://book.wikg/entity/Q8018 evidence --query "memory"
247
- ```
248
-
249
- Use `evidence` when a statement, entity, relation, or answer needs to be checked against source material.
250
-
251
- ### Expand Related Objects
252
-
253
- ```bash
254
- $ wg wikg://book.wikg/entity/Q8018 related --evidence 2
255
- $ wg wikg://book.wikg/entity/Q8018 related --query "memory" --evidence 2
256
- ```
257
-
258
- `related` expands from a selected object to nearby objects. For Entity, related results are mainly related triples.
259
-
260
- ### Prepare Context
261
-
262
- ```bash
263
- $ wg wikg://book.wikg/entity/Q8018 pack --budget 5000
264
- ```
265
-
266
- `pack` turns the surrounding context of a selected chunk or entity into portable text. Use `evidence` first when strict verification is needed.
267
-
268
- ## For AI Agents
269
-
270
- Wiki Graph treats CLI help as part of the product contract. After installation, start from the root help; commands, URIs, predicates, configuration, runtime behavior, and format constraints can be discovered by following the help network, without guessing command shapes from the README.
5
+ It installs the `wg` and `wikigraph` commands. Use it to create archives, import text, manage chapters, build/search indexes, generate knowledge structures, and inspect source-backed results.
271
6
 
272
7
  ```bash
273
- $ wg --help
8
+ npm install -g wiki-graph
9
+ # or
10
+ pnpm add --global wiki-graph
11
+ wg wikg://quickstart.wikg create
12
+ wg wikg://quickstart.wikg --help
274
13
  ```
275
14
 
276
- ## License
15
+ Requires Node.js `>=22.12.0`.
277
16
 
278
- Apache-2.0
17
+ For full documentation, examples, source code, and issue tracking, see the [GitHub repository](https://github.com/oomol-lab/wiki-graph).
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node