@northtek/overstory 0.1.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.
- package/LICENSE +201 -0
- package/README.md +115 -0
- package/dist/build/aggregate.d.ts +9 -0
- package/dist/build/aggregate.js +74 -0
- package/dist/build/builder.d.ts +52 -0
- package/dist/build/builder.js +223 -0
- package/dist/build/inmemory.d.ts +16 -0
- package/dist/build/inmemory.js +79 -0
- package/dist/build/pool.d.ts +3 -0
- package/dist/build/pool.js +16 -0
- package/dist/build/reflexion.d.ts +15 -0
- package/dist/build/reflexion.js +116 -0
- package/dist/build/summarize.d.ts +25 -0
- package/dist/build/summarize.js +146 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +323 -0
- package/dist/core/bm25.d.ts +19 -0
- package/dist/core/bm25.js +48 -0
- package/dist/core/chunk.d.ts +5 -0
- package/dist/core/chunk.js +91 -0
- package/dist/core/corpus.d.ts +21 -0
- package/dist/core/corpus.js +112 -0
- package/dist/core/gate.d.ts +25 -0
- package/dist/core/gate.js +155 -0
- package/dist/core/hash.d.ts +7 -0
- package/dist/core/hash.js +15 -0
- package/dist/core/store.d.ts +74 -0
- package/dist/core/store.js +66 -0
- package/dist/core/types.d.ts +96 -0
- package/dist/core/types.js +1 -0
- package/dist/fix/prompts.d.ts +4 -0
- package/dist/fix/prompts.js +124 -0
- package/dist/fix/scan.d.ts +18 -0
- package/dist/fix/scan.js +197 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +22 -0
- package/dist/llm/anthropic.d.ts +11 -0
- package/dist/llm/anthropic.js +46 -0
- package/dist/llm/mock.d.ts +5 -0
- package/dist/llm/mock.js +20 -0
- package/dist/llm/ollama.d.ts +11 -0
- package/dist/llm/ollama.js +49 -0
- package/dist/llm/provider.d.ts +16 -0
- package/dist/llm/provider.js +7 -0
- package/dist/llm/resolve.d.ts +14 -0
- package/dist/llm/resolve.js +24 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +136 -0
- package/dist/query/ask.d.ts +53 -0
- package/dist/query/ask.js +127 -0
- package/dist/query/notarize.d.ts +40 -0
- package/dist/query/notarize.js +31 -0
- package/dist/registry/github.d.ts +28 -0
- package/dist/registry/github.js +113 -0
- package/dist/registry/publishClient.d.ts +25 -0
- package/dist/registry/publishClient.js +39 -0
- package/dist/registry/registry.d.ts +35 -0
- package/dist/registry/registry.js +57 -0
- package/dist/registry/repoTree.d.ts +9 -0
- package/dist/registry/repoTree.js +32 -0
- package/dist/serve/app.d.ts +4 -0
- package/dist/serve/app.js +809 -0
- package/dist/serve/server.d.ts +9 -0
- package/dist/serve/server.js +180 -0
- package/dist/serve/threads.d.ts +31 -0
- package/dist/serve/threads.js +69 -0
- package/dist/site/data.d.ts +58 -0
- package/dist/site/data.js +88 -0
- package/dist/site/generate.d.ts +21 -0
- package/dist/site/generate.js +827 -0
- package/package.json +64 -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,115 @@
|
|
|
1
|
+
# OVERSTORY
|
|
2
|
+
|
|
3
|
+
**A knowledge tree of your codebase where every claim carries a receipt.**
|
|
4
|
+
|
|
5
|
+
> **30 seconds, no jargon:** AI tools sound exactly as confident when they're wrong as when
|
|
6
|
+
> they're right. OVERSTORY reads your codebase, writes it up as short statements, and then
|
|
7
|
+
> **checks every statement against the actual code** — click any one to see the exact lines
|
|
8
|
+
> it came from. When the code changes, the affected statements flip to "stale" instead of
|
|
9
|
+
> quietly becoming lies. Ask questions and get answers where every sentence carries a
|
|
10
|
+
> checkable receipt; statements that can't be verified are withheld and say so. All of it
|
|
11
|
+
> runs on your machine — your code never leaves.
|
|
12
|
+
>
|
|
13
|
+
> Try it: `npx @northtek/overstory build && npx @northtek/overstory serve`
|
|
14
|
+
|
|
15
|
+
OVERSTORY turns any repo or docs folder into an explorable, hierarchical map — file to module
|
|
16
|
+
to system — in which every statement is an atomic claim citing the exact source lines that
|
|
17
|
+
support it. Citations are verified mechanically, not displayed decoratively: a claim whose
|
|
18
|
+
evidence changed is marked stale, a claim whose evidence vanished is marked missing, and a
|
|
19
|
+
claim with no evidence is never presented as verified.
|
|
20
|
+
|
|
21
|
+
Local-first by default. With the local Ollama engine or the deterministic extractive engine
|
|
22
|
+
(no LLM at all), your code never leaves your machine — air-gapped works. The Anthropic API is
|
|
23
|
+
an explicit opt-in, and only then does source text leave the machine (to Anthropic, for
|
|
24
|
+
summarization). The gate itself is always local.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npx @northtek/overstory build # build the tree (resumable; reuses unchanged files)
|
|
28
|
+
npx @northtek/overstory serve # open the app: ask your codebase, answers notarized
|
|
29
|
+
npx @northtek/overstory verify # CI-friendly: exit 1 if any receipt fails
|
|
30
|
+
npx @northtek/overstory mcp # MCP tools for Claude Code / Cursor
|
|
31
|
+
npx @northtek/overstory site # shareable single-file explorer
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**The app** (`overstory serve`) is a local, frontier-lab-grade answer engine over your repo:
|
|
35
|
+
ask-first home, streamed phases (searching → writing → notarizing), answers with numbered
|
|
36
|
+
citation chips, and receipt cards that unfold into the exact cited lines with their hash and
|
|
37
|
+
verdict seal. Threads persist locally; light and dark themes; nothing leaves your machine.
|
|
38
|
+
|
|
39
|
+
## Why
|
|
40
|
+
|
|
41
|
+
AI tools that explain codebases have a trust problem: confident answers with citations that
|
|
42
|
+
are displayed but never checked, over docs that silently rot as the code moves on. OVERSTORY
|
|
43
|
+
inverts the contract:
|
|
44
|
+
|
|
45
|
+
- **Receipts by construction** — the unit of storage is the claim + its cited spans, hashed
|
|
46
|
+
over the span *text* (never file positions). Edits above a span heal its line numbers;
|
|
47
|
+
edits to the evidence itself flip the claim to `STALE`.
|
|
48
|
+
- **Fail-closed verdicts** — `VERIFIED` / `STALE` / `OUT_OF_CORPUS` / `UNGROUNDED`, computed
|
|
49
|
+
by a pure function against the live corpus. A forged receipt voids the claim.
|
|
50
|
+
- **Honest staleness** — `overstory verify` re-checks every receipt in milliseconds and exits
|
|
51
|
+
non-zero when docs and code disagree. Docs that know when they're lying.
|
|
52
|
+
- **Two disclosure tiers** — the mechanical verdict above, plus a build-time semantic
|
|
53
|
+
`faithfulness` tier from an adversarial critique pass (Reflexion-style). Claims the critic
|
|
54
|
+
rejects stay visible and flagged — abstention over confident prose, never silent deletion.
|
|
55
|
+
|
|
56
|
+
**The honesty boundary, stated plainly:** verification here proves *provenance and freshness*
|
|
57
|
+
(the cited lines exist and are unchanged), not truth. Semantic support is checked once at
|
|
58
|
+
build time and labeled. Every claim is one click from its evidence; judge it yourself.
|
|
59
|
+
|
|
60
|
+
## How it works
|
|
61
|
+
|
|
62
|
+
1. **Ingest** — gitignore-aware walk, structural chunking (headings / top-level declarations).
|
|
63
|
+
2. **Summarize** — each chunk becomes 3-8 atomic claims with line citations (Ollama local,
|
|
64
|
+
Anthropic API, or extractive fallback — malformed LLM output degrades per-chunk, a build
|
|
65
|
+
never dies on one bad response).
|
|
66
|
+
3. **Refine** — an adversarial critique pass fact-checks each claim against its cited lines
|
|
67
|
+
(supported / unsupported), revises what it can defend, and surfaces missing facts.
|
|
68
|
+
4. **Aggregate** — directory and root nodes roll up from child claims, every roll-up claim
|
|
69
|
+
citing the child claims that ground it, transitively down to source lines.
|
|
70
|
+
5. **Gate** — every claim in the tree is verified; freshness is a first-class number.
|
|
71
|
+
6. **Explore** — a single self-contained HTML explorer (works offline, shareable), a CLI,
|
|
72
|
+
and an MCP server.
|
|
73
|
+
|
|
74
|
+
Builds are incremental and resumable: every leaf checkpoints on completion, and unchanged
|
|
75
|
+
files are never re-summarized.
|
|
76
|
+
|
|
77
|
+
## Hosted registry (preview)
|
|
78
|
+
|
|
79
|
+
There's an experimental zero-storage registry that can show verified trees of public GitHub
|
|
80
|
+
repos and re-check published trees against the live code (the registry stores nothing —
|
|
81
|
+
your repo is the database). It's in quiet preview and not the point of v1: the product is
|
|
82
|
+
the local tool. `overstory publish` targets it if you want to try it; details in
|
|
83
|
+
docs/plans/2026-07-21-registry-design.md.
|
|
84
|
+
|
|
85
|
+
## MCP: notarize your agent's answers
|
|
86
|
+
|
|
87
|
+
`overstory mcp` exposes `overstory_map`, `overstory_search`, `overstory_node`, and the tool
|
|
88
|
+
the others exist for — **`overstory_verify`**: your agent (Claude Code, Cursor) drafts an
|
|
89
|
+
answer about the repo, submits its claims with file:line citations, and gets back per-claim
|
|
90
|
+
verdicts plus the receipt text for each citation. The host model does the thinking;
|
|
91
|
+
OVERSTORY checks the receipts.
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{ "mcpServers": { "overstory": { "command": "npx", "args": ["-y", "@northtek/overstory", "mcp"] } } }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Provenance of the ideas
|
|
98
|
+
|
|
99
|
+
OVERSTORY is the TypeScript synthesis of research shipped in
|
|
100
|
+
[FACTGATE](https://github.com/NORTHTEKDevs/factgate) (fail-closed claim gating),
|
|
101
|
+
[verified-memory](https://github.com/NORTHTEKDevs/verified-memory) (memory feeds context in,
|
|
102
|
+
a gate adjudicates claims out), [GENOME](https://github.com/NORTHTEKDevs/genome)
|
|
103
|
+
(hierarchical RAPTOR summarization — including the published null that tree retrieval is
|
|
104
|
+
accuracy-neutral: the tree's value is the explorable provenance artifact, which is exactly
|
|
105
|
+
what OVERSTORY ships), and RAIN's Reflexion loop discipline. BSHR
|
|
106
|
+
(brainstorm-search-hypothesize-refine) drives the `ask` engine.
|
|
107
|
+
|
|
108
|
+
## Roadmap (deliberately not in v1)
|
|
109
|
+
|
|
110
|
+
Embedding search, AST-precise chunking, watch mode, a CI bot that comments when merged code
|
|
111
|
+
stales the docs, team/shared trees, `claude -p` as a provider. v1 is the trustworthy core.
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
Apache-2.0 © Northtek (FrostByte LLC)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Claim, TreeNode } from '../core/types.js';
|
|
2
|
+
import type { ChatProvider } from '../llm/provider.js';
|
|
3
|
+
/** Deterministic roll-up: one claim per child, grounded in the child's first claim.
|
|
4
|
+
* Child detail is included only when it adds information — a child whose first claim is
|
|
5
|
+
* itself a roll-up ("Contains …") would produce noisy chains, so it is elided. */
|
|
6
|
+
export declare const extractiveAggregate: (children: TreeNode[]) => Omit<Claim, 'id'>[];
|
|
7
|
+
/** Interior-node claims. LLM path grounds every claim in child claim refs; invalid refs are
|
|
8
|
+
* dropped; unusable output falls back to extractive. */
|
|
9
|
+
export declare const aggregateClaims: (provider: ChatProvider | null, title: string, children: TreeNode[], idPrefix: string) => Promise<Claim[]>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const aggSchema = z.object({
|
|
3
|
+
claims: z
|
|
4
|
+
.array(z.object({ text: z.string().min(3), refs: z.array(z.string()).min(1) }))
|
|
5
|
+
.min(1)
|
|
6
|
+
.max(8),
|
|
7
|
+
});
|
|
8
|
+
const AGG_SYSTEM = `You are the roll-up layer of a provenance-gated knowledge tree. You describe what a directory/module IS from its children's verified claims. Every claim must reference the child claims that support it. Never introduce facts absent from the children.`;
|
|
9
|
+
const aggPrompt = (title, children) => {
|
|
10
|
+
const lines = [];
|
|
11
|
+
for (const child of children) {
|
|
12
|
+
lines.push(`CHILD ${child.id} (${child.title}):`);
|
|
13
|
+
for (const claim of child.claims.slice(0, 5))
|
|
14
|
+
lines.push(` [${claim.id}] ${claim.text}`);
|
|
15
|
+
}
|
|
16
|
+
return `Summarize what "${title}" is and does in 3-6 claims for a developer seeing it for the first time. Each claim cites the child claim ids that support it.
|
|
17
|
+
|
|
18
|
+
Return ONLY JSON: {"claims":[{"text":"...","refs":["<claim id>", ...]}]}
|
|
19
|
+
|
|
20
|
+
${lines.join('\n')}`;
|
|
21
|
+
};
|
|
22
|
+
/** Deterministic roll-up: one claim per child, grounded in the child's first claim.
|
|
23
|
+
* Child detail is included only when it adds information — a child whose first claim is
|
|
24
|
+
* itself a roll-up ("Contains …") would produce noisy chains, so it is elided. */
|
|
25
|
+
export const extractiveAggregate = (children) => children
|
|
26
|
+
.filter((c) => c.claims.length > 0)
|
|
27
|
+
.slice(0, 8)
|
|
28
|
+
.map((child) => {
|
|
29
|
+
const label = child.kind === 'leaf' ? child.path : `${child.title}/`;
|
|
30
|
+
const detail = child.claims[0].text;
|
|
31
|
+
const text = detail.startsWith('Contains ')
|
|
32
|
+
? `Contains ${label} (${child.claims.length} claim${child.claims.length === 1 ? '' : 's'}).`
|
|
33
|
+
: `Contains ${label} — ${detail}`;
|
|
34
|
+
return {
|
|
35
|
+
text,
|
|
36
|
+
citations: [{ kind: 'claim', ref: { nodeId: child.id, claimId: child.claims[0].id } }],
|
|
37
|
+
faithfulness: 'supported',
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
/** Interior-node claims. LLM path grounds every claim in child claim refs; invalid refs are
|
|
41
|
+
* dropped; unusable output falls back to extractive. */
|
|
42
|
+
export const aggregateClaims = async (provider, title, children, idPrefix) => {
|
|
43
|
+
const finish = (drafts) => drafts.map((c, i) => ({ ...c, id: `${idPrefix}#${i}` }));
|
|
44
|
+
const withClaims = children.filter((c) => c.claims.length > 0);
|
|
45
|
+
if (!provider || withClaims.length === 0)
|
|
46
|
+
return finish(extractiveAggregate(children));
|
|
47
|
+
const valid = new Map();
|
|
48
|
+
for (const child of withClaims)
|
|
49
|
+
for (const claim of child.claims)
|
|
50
|
+
valid.set(claim.id, { nodeId: child.id, claimId: claim.id });
|
|
51
|
+
try {
|
|
52
|
+
const raw = await provider.chat(aggPrompt(title, withClaims), { json: true, system: AGG_SYSTEM });
|
|
53
|
+
const first = raw.indexOf('{');
|
|
54
|
+
const last = raw.lastIndexOf('}');
|
|
55
|
+
const parsed = aggSchema.parse(JSON.parse(first >= 0 ? raw.slice(first, last + 1) : raw));
|
|
56
|
+
const drafts = [];
|
|
57
|
+
for (const d of parsed.claims) {
|
|
58
|
+
const refs = d.refs.filter((r) => valid.has(r));
|
|
59
|
+
if (refs.length === 0)
|
|
60
|
+
continue;
|
|
61
|
+
drafts.push({
|
|
62
|
+
text: d.text.trim(),
|
|
63
|
+
citations: refs.map((r) => ({ kind: 'claim', ref: valid.get(r) })),
|
|
64
|
+
faithfulness: 'unchecked',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (drafts.length === 0)
|
|
68
|
+
return finish(extractiveAggregate(children));
|
|
69
|
+
return finish(drafts);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return finish(extractiveAggregate(children));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LoadedCorpus } from '../core/corpus.js';
|
|
2
|
+
import type { Tree, TreeVerification } from '../core/types.js';
|
|
3
|
+
import type { ChatProvider } from '../llm/provider.js';
|
|
4
|
+
export interface ProgressEvent {
|
|
5
|
+
phase: 'scan' | 'leaves' | 'aggregate' | 'verify' | 'save' | 'warn';
|
|
6
|
+
done?: number;
|
|
7
|
+
total?: number;
|
|
8
|
+
file?: string;
|
|
9
|
+
reused?: boolean;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface BuildOptions {
|
|
13
|
+
/** null = pure extractive build (deterministic, instant, no LLM). */
|
|
14
|
+
provider?: ChatProvider | null;
|
|
15
|
+
/** Critique model for the Reflexion pass; defaults to `provider`. */
|
|
16
|
+
critic?: ChatProvider | null;
|
|
17
|
+
/** 0 disables Reflexion. Default 1 (local models) — callers may raise for API providers. */
|
|
18
|
+
reflexionRounds?: number;
|
|
19
|
+
include?: string[];
|
|
20
|
+
maxFiles?: number;
|
|
21
|
+
name?: string;
|
|
22
|
+
onProgress?: (e: ProgressEvent) => void;
|
|
23
|
+
generator?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface BuildResult {
|
|
26
|
+
tree: Tree;
|
|
27
|
+
verification: TreeVerification;
|
|
28
|
+
corpus: LoadedCorpus;
|
|
29
|
+
reusedLeaves: number;
|
|
30
|
+
rebuiltLeaves: number;
|
|
31
|
+
/** Non-zero means the resume guarantee was degraded during this run — surfaced, never silent. */
|
|
32
|
+
checkpointFailures: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const dirOf: (file: string) => string;
|
|
35
|
+
/** All ancestor dir paths for a set of files, deepest first (so children exist before
|
|
36
|
+
* their parent aggregates). */
|
|
37
|
+
export declare const dirPaths: (files: string[]) => string[];
|
|
38
|
+
/** Build (or refresh — same operation) the knowledge tree. Reuses any previous leaf whose
|
|
39
|
+
* source hash still matches, upgrades extractive leaves when an LLM provider is available,
|
|
40
|
+
* checkpoints progress after every leaf, and finishes with a full gate sweep. A killed
|
|
41
|
+
* build resumes from its partial checkpoint on the next run. */
|
|
42
|
+
export declare const buildTree: (root: string, opts?: BuildOptions) => Promise<BuildResult>;
|
|
43
|
+
export interface VerifyResult {
|
|
44
|
+
tree: Tree;
|
|
45
|
+
verification: TreeVerification;
|
|
46
|
+
staleFiles: string[];
|
|
47
|
+
}
|
|
48
|
+
/** Read-only verification of an existing tree against the live corpus. Applies verdicts and
|
|
49
|
+
* healed positions in-memory; never writes. Null when no tree exists. The corpus is loaded
|
|
50
|
+
* with the OPTIONS THE TREE WAS BUILT WITH (caller may override) — verifying against a
|
|
51
|
+
* differently-scoped corpus yields wrong verdicts. */
|
|
52
|
+
export declare const verifyExisting: (root: string, opts?: Pick<BuildOptions, 'include' | 'maxFiles'>) => Promise<VerifyResult | null>;
|