wiki-graph 0.3.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 (56) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +278 -0
  3. package/data/editor/clue_reviewer.jinja +410 -0
  4. package/data/editor/clue_reviewer_generator.jinja +428 -0
  5. package/data/editor/revision_feedback.jinja +5 -0
  6. package/data/editor/text_compressor.jinja +127 -0
  7. package/data/guaranteed/response_intent_classifier.jinja +8 -0
  8. package/data/help/commands/archive/next.jinja +29 -0
  9. package/data/help/commands/gc.jinja +38 -0
  10. package/data/help/commands/legacy/migrate.jinja +20 -0
  11. package/data/help/commands/legacy.jinja +19 -0
  12. package/data/help/commands/maintenance/chapter/add.jinja +41 -0
  13. package/data/help/commands/maintenance/chapter/list.jinja +33 -0
  14. package/data/help/commands/maintenance/chapter/move.jinja +36 -0
  15. package/data/help/commands/maintenance/chapter/remove.jinja +26 -0
  16. package/data/help/commands/maintenance/chapter/reset.jinja +29 -0
  17. package/data/help/commands/maintenance/chapter/set-source.jinja +34 -0
  18. package/data/help/commands/maintenance/chapter/set-summary.jinja +31 -0
  19. package/data/help/commands/maintenance/chapter/set-title.jinja +29 -0
  20. package/data/help/commands/maintenance/chapter/tree.jinja +58 -0
  21. package/data/help/commands/maintenance/chapter.jinja +59 -0
  22. package/data/help/commands/maintenance/cover.jinja +28 -0
  23. package/data/help/commands/maintenance/meta.jinja +55 -0
  24. package/data/help/commands/predicate.jinja +460 -0
  25. package/data/help/commands/root.jinja +83 -0
  26. package/data/help/commands/transform.jinja +34 -0
  27. package/data/help/commands/uri.jinja +274 -0
  28. package/data/help/topics/config.jinja +88 -0
  29. package/data/help/topics/format.jinja +72 -0
  30. package/data/help/topics/readiness.jinja +99 -0
  31. package/data/help/topics/recipe.jinja +151 -0
  32. package/data/help/topics/runtime.jinja +62 -0
  33. package/data/help/topics/uri.jinja +178 -0
  34. package/data/output/epub/cover.xhtml.jinja +13 -0
  35. package/data/output/epub/nav.xhtml.jinja +12 -0
  36. package/data/output/epub/package.opf.xml.jinja +39 -0
  37. package/data/output/epub/section.xhtml.jinja +12 -0
  38. package/data/topologization/book_coherence_extraction.jinja +223 -0
  39. package/data/topologization/chunk_extraction.jinja +233 -0
  40. package/data/topologization/evidence_choice.jinja +38 -0
  41. package/data/topologization/translate_chunks.jinja +138 -0
  42. package/data/topologization/user_focused_extraction.jinja +378 -0
  43. package/dist/cli.cjs +41734 -0
  44. package/dist/cli.cjs.map +1 -0
  45. package/dist/cli.js +7 -0
  46. package/dist/index.cjs +20979 -0
  47. package/dist/index.cjs.map +1 -0
  48. package/dist/index.d.cts +842 -0
  49. package/dist/index.d.ts +842 -0
  50. package/dist/index.js +12 -0
  51. package/docs/images/flowchart.excalidraw +3293 -0
  52. package/docs/images/flowchart.svg +4 -0
  53. package/docs/images/terminal-cn.png +0 -0
  54. package/docs/images/terminal-en.png +0 -0
  55. package/docs/wikispine-runtime.md +143 -0
  56. package/package.json +109 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,278 @@
1
+ ![](./docs/images/terminal-en.png)
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>
12
+
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.
271
+
272
+ ```bash
273
+ $ wg --help
274
+ ```
275
+
276
+ ## License
277
+
278
+ Apache-2.0