@h1v35/hivex 0.2.0 → 0.2.2

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 (39) hide show
  1. package/README.md +55 -163
  2. package/docs/CONTEXT.md +20 -36
  3. package/docs/README.md +6 -12
  4. package/docs/adr/0003-independent-bun-installation.md +5 -19
  5. package/docs/adr/0010-practical-knowledge-assistance.md +28 -81
  6. package/docs/adr/0011-shared-knowledge-and-selective-history.md +16 -43
  7. package/docs/guidelines/engineering.md +74 -0
  8. package/docs/procedures/self-hosted-runner.md +7 -0
  9. package/package.json +32 -11
  10. package/skills/hivex/SKILL.md +28 -92
  11. package/skills/hivex/references/markdown.md +12 -42
  12. package/src/cli/diagnostic.ts +21 -11
  13. package/src/cli.ts +46 -36
  14. package/src/documents.ts +502 -320
  15. package/src/errors.ts +8 -6
  16. package/src/implementation.ts +185 -87
  17. package/src/ingestion-units.ts +107 -64
  18. package/src/knowledge-maintenance.ts +35 -22
  19. package/src/knowledge-model.ts +386 -268
  20. package/src/knowledge-serialization.ts +239 -0
  21. package/src/knowledge-snapshot.ts +100 -77
  22. package/src/knowledge-store.ts +634 -453
  23. package/src/knowledge.ts +1001 -758
  24. package/src/markdown.ts +107 -45
  25. package/src/model/connection.ts +134 -76
  26. package/src/model/failure.ts +46 -23
  27. package/src/model/invoke.ts +346 -166
  28. package/src/model/profile.ts +201 -103
  29. package/src/model/rpc-error.ts +21 -0
  30. package/src/model/server.ts +151 -82
  31. package/src/model/thread.ts +24 -14
  32. package/src/model/transcript.ts +87 -46
  33. package/src/ordering.ts +9 -0
  34. package/src/retrieval/lexical.ts +64 -41
  35. package/src/review.ts +83 -55
  36. package/src/runtime.d.ts +4 -0
  37. package/src/snapshot-command.ts +82 -43
  38. package/src/source-relocation.ts +222 -0
  39. package/docs/engineering.md +0 -174
@@ -0,0 +1,222 @@
1
+ import { compareSerializedStrings } from './ordering.ts';
2
+ import { HivexError } from './errors.ts';
3
+ import { isMarkdownPath } from './markdown.ts';
4
+ import type { Project } from './documents.ts';
5
+ import type { Graph } from './knowledge-model.ts';
6
+
7
+ const protectedParts = new Set(['', '.', '..', '.git', '.hivex', 'node_modules']);
8
+
9
+ const isPortablePath = function isPortablePath(value: string) {
10
+ if (!isMarkdownPath(value) || value.startsWith('/')) {
11
+ return false;
12
+ }
13
+ if (value.includes('\\') || value.includes('\0')) {
14
+ return false;
15
+ }
16
+ return value.split('/').every((part) => !protectedParts.has(part));
17
+ };
18
+
19
+ const fail = function fail(code: string, message: string): never {
20
+ throw new HivexError({ code, message });
21
+ };
22
+
23
+ const relationshipVersions = function relationshipVersions(
24
+ relationship: Graph['relationships'][number],
25
+ document: string
26
+ ) {
27
+ return relationship.evidence
28
+ .filter((evidence) => evidence.document === document)
29
+ .flatMap((evidence) => (evidence.version === undefined ? [] : [evidence.version]));
30
+ };
31
+
32
+ const warningVersions = function warningVersions(
33
+ warning: Graph['warnings'][number],
34
+ document: string
35
+ ) {
36
+ if (typeof warning === 'string') {
37
+ return [];
38
+ }
39
+ return warning.scope.filter((scope) => scope.document === document).map((scope) => scope.version);
40
+ };
41
+
42
+ const sourceVersions = function sourceVersions(graph: Graph, document: string) {
43
+ const versions = [
44
+ graph.documents[document],
45
+ ...Object.values(graph.units)
46
+ .filter((unit) => unit.document === document)
47
+ .map((unit) => unit.version),
48
+ ...graph.decisions
49
+ .filter((decision) => decision.document === document)
50
+ .map((decision) => decision.version),
51
+ ...graph.relationships.flatMap((relationship) => relationshipVersions(relationship, document)),
52
+ ...graph.warnings.flatMap((warning) => warningVersions(warning, document)),
53
+ ].filter((version): version is string => version !== undefined);
54
+ return [...new Set(versions)].toSorted(compareSerializedStrings);
55
+ };
56
+
57
+ const hasKnowledge = function hasKnowledge(graph: Graph, document: string) {
58
+ if (graph.documents[document] !== undefined) {
59
+ return true;
60
+ }
61
+ if (Object.values(graph.units).some((unit) => unit.document === document)) {
62
+ return true;
63
+ }
64
+ if (graph.decisions.some((decision) => decision.document === document)) {
65
+ return true;
66
+ }
67
+ if (
68
+ graph.relationships.some((relationship) =>
69
+ relationship.evidence.some((evidence) => evidence.document === document)
70
+ )
71
+ ) {
72
+ return true;
73
+ }
74
+ return graph.warnings.some(
75
+ (warning) =>
76
+ typeof warning !== 'string' && warning.scope.some((scope) => scope.document === document)
77
+ );
78
+ };
79
+
80
+ const selectedDocument = function selectedDocument(project: Project, id: string) {
81
+ return project.documents.find((document) => document.id === id);
82
+ };
83
+
84
+ const mapCitation = function mapCitation<T extends { document: string }>(
85
+ citation: T,
86
+ from: string,
87
+ to: string
88
+ ) {
89
+ return citation.document === from ? { ...citation, document: to } : citation;
90
+ };
91
+
92
+ const mapUnitId = function mapUnitId(id: string, from: string, to: string) {
93
+ const prefix = `${from}:`;
94
+ return id.startsWith(prefix) ? `${to}${id.slice(from.length)}` : id;
95
+ };
96
+
97
+ const mapWarning = function mapWarning(
98
+ warning: Graph['warnings'][number],
99
+ from: string,
100
+ to: string
101
+ ): Graph['warnings'][number] {
102
+ return typeof warning === 'string'
103
+ ? warning
104
+ : { ...warning, scope: warning.scope.map((scope) => mapCitation(scope, from, to)) };
105
+ };
106
+
107
+ const mapDecision = function mapDecision(
108
+ decision: Graph['decisions'][number],
109
+ from: string,
110
+ to: string
111
+ ) {
112
+ return { ...decision, document: decision.document === from ? to : decision.document };
113
+ };
114
+
115
+ const mapRelationship = function mapRelationship(
116
+ relationship: Graph['relationships'][number],
117
+ from: string,
118
+ to: string
119
+ ) {
120
+ return {
121
+ ...relationship,
122
+ evidence: relationship.evidence.map((evidence) => mapCitation(evidence, from, to)),
123
+ };
124
+ };
125
+
126
+ const mapUnits = function mapUnits(
127
+ graph: Graph,
128
+ from: string,
129
+ to: string,
130
+ isCoverageRelocated: boolean
131
+ ) {
132
+ const entries = Object.entries(graph.units).flatMap(([id, unit]) => {
133
+ if (!isCoverageRelocated && (unit.document === from || unit.document === to)) {
134
+ return [];
135
+ }
136
+ if (unit.document !== from) {
137
+ return [[id, unit] as const];
138
+ }
139
+ const relocatedId = mapUnitId(id, from, to);
140
+ return [[relocatedId, { ...unit, document: to }] as const];
141
+ });
142
+ return Object.fromEntries(entries);
143
+ };
144
+
145
+ const mapDocuments = function mapDocuments(
146
+ graph: Graph,
147
+ from: string,
148
+ to: string,
149
+ options: { isCoverageRelocated: boolean; sourceVersion: string | undefined }
150
+ ) {
151
+ const entries = Object.entries(graph.documents).filter(([id]) => id !== from && id !== to);
152
+ if (options.isCoverageRelocated && options.sourceVersion !== undefined) {
153
+ entries.push([to, options.sourceVersion]);
154
+ }
155
+ return Object.fromEntries(entries);
156
+ };
157
+
158
+ export interface SourceRelocation {
159
+ destinationVersion: string;
160
+ from: string;
161
+ fromVersions: string[];
162
+ graph: Graph;
163
+ reused: boolean;
164
+ to: string;
165
+ }
166
+
167
+ export const relocateSource = function relocateSource(
168
+ graph: Graph,
169
+ project: Project,
170
+ from: string,
171
+ to: string
172
+ ): SourceRelocation {
173
+ if (from === to || !isPortablePath(from) || !isPortablePath(to)) {
174
+ fail(
175
+ 'INVALID_ARGUMENT',
176
+ 'Source relocation paths must be distinct project-local Markdown files'
177
+ );
178
+ }
179
+ if (!hasKnowledge(graph, from)) {
180
+ fail('SOURCE_NOT_FOUND', `Source is not present in knowledge: ${from}`);
181
+ }
182
+ if (selectedDocument(project, from) !== undefined) {
183
+ fail('INVALID_ARGUMENT', `Source must no longer be selected: ${from}`);
184
+ }
185
+ const destination = project.currentDocuments.find((document) => document.id === to);
186
+ if (destination === undefined) {
187
+ return fail('SOURCE_NOT_FOUND', `Destination is not a selected current Markdown source: ${to}`);
188
+ }
189
+ const versions = sourceVersions(graph, from);
190
+ const hasDestinationKnowledge = hasKnowledge(graph, to);
191
+ const hasUnversionedEvidence = graph.relationships
192
+ .flatMap((relationship) => relationship.evidence)
193
+ .some((evidence) => evidence.document === from && evidence.version === undefined);
194
+ const isReused =
195
+ !hasDestinationKnowledge &&
196
+ !hasUnversionedEvidence &&
197
+ versions.length > 0 &&
198
+ versions.every((version) => version === destination.hash);
199
+ const documents = mapDocuments(graph, from, to, {
200
+ isCoverageRelocated: isReused,
201
+ sourceVersion: graph.documents[from],
202
+ });
203
+ const units = mapUnits(graph, from, to, isReused);
204
+ const relocated: Graph = {
205
+ ...graph,
206
+ decisions: graph.decisions.map((decision) => mapDecision(decision, from, to)),
207
+ documents,
208
+ relationships: graph.relationships.map((relationship) =>
209
+ mapRelationship(relationship, from, to)
210
+ ),
211
+ units,
212
+ warnings: graph.warnings.map((warning) => mapWarning(warning, from, to)),
213
+ };
214
+ return {
215
+ destinationVersion: destination.hash,
216
+ from,
217
+ fromVersions: versions,
218
+ graph: relocated,
219
+ reused: isReused,
220
+ to,
221
+ };
222
+ };
@@ -1,174 +0,0 @@
1
- ---
2
- title: Engineering workflow
3
- status: accepted
4
- ---
5
-
6
- # Engineering workflow
7
-
8
- Hivex is a TypeScript/Bun product. Modules group behavior by domain responsibility and hide internal
9
- details behind small interfaces. Do not add a second development-session orchestrator or require
10
- an adopting project's layout, tracker or product packages. Codex, Git/GitHub and CI coordinate work.
11
-
12
- ## Development and verification
13
-
14
- Work is issue-first in `H1V35/hivex`. New vertical work follows discovery where decisions remain open,
15
- then an agreed spec, verifiable execution tickets, implementation and code review. Reuse settled scope
16
- instead of reopening an interview. The owning repository carries the execution ticket; a cross-repository
17
- parent supplies context and coordination, not a substitute for native tracking.
18
-
19
- Resolve the existing spec/ticket before changing code and link the PR and verification to it. Absorb
20
- review findings into the appropriate existing ticket whenever its scope permits. Open a separate issue
21
- only when strictly necessary to preserve independently actionable work, and record why it cannot be
22
- absorbed. Read-only retrieval does not need a new ticket. Specs and tickets track work and acceptance;
23
- resulting durable decisions also enter their repository authority.
24
-
25
- Use an existing issue for an already tracked requirement. Create a branch from the current remote
26
- main, keep each PR to one coherent change and preserve commit history when merging. Never push
27
- directly to main or force-push a shared branch. Apply review findings before acceptance; an invalid
28
- review can be rerun, while an adverse finding must be resolved on its merits. Current explicit owner
29
- authorization governs whether the agent may merge.
30
-
31
- Independent code reviewers use the coordinating agent's current model and reasoning effort. Pass
32
- that profile explicitly when the subagent default differs, and verify the effective configuration
33
- after dispatch. Do not substitute the cheaper knowledge model for code review. Routine implementation subtasks may use an
34
- explicitly authorized cheaper model; Hivex's internal knowledge extraction/checking uses the user's
35
- knowledge-model configuration independently of the development and code-review model.
36
-
37
- Choose verification for the affected surfaces. Code changes require typechecking, lint, formatting
38
- and relevant behavior tests; documentation-only changes need formatting and checks of affected
39
- references or declared sources. Record the exact revision and the checks actually completed. A later
40
- change invalidates the affected results. Do not claim an omitted, interrupted or truncated check passed.
41
-
42
- GitHub Actions runs the quality workflow on the owner's Mac through an official self-hosted runner,
43
- using `[self-hosted, macOS, ARM64, hivex]`. GitHub retains secrets, logs and PR checks; no hosted
44
- runner fallback is configured. No speed benchmark is required. A queued, skipped or interrupted
45
- run is not a pass. Local verification remains required when the runner is unavailable.
46
-
47
- Runner installation is repository administration, outside Hivex's product. Register the admitted
48
- macOS ARM64 release from GitHub's runner settings in its own directory, verify the official checksum,
49
- and use the generated `svc.sh install/start/status/stop` commands. Keep automatic updates enabled,
50
- a stable Homebrew/system PATH and the Mac awake and connected under the logged-in user. The
51
- runner work directory must be separate from the developer checkout and other repository runners.
52
- Only trusted code may run on this persistent host; review that boundary before public contributions.
53
- See [GitHub's runner reference](https://docs.github.com/en/actions/reference/runners/self-hosted-runners).
54
-
55
- During a host migration, disable Actions, register and confirm the runner is online, and merge all
56
- workflow routes before re-enabling Actions. Then dispatch Quality on that exact revision and check
57
- the assigned runner and completed result. The route change alone is not functional verification.
58
-
59
- Use `bun install` for development and `bun ci` for frozen installation. Bun owns dependency
60
- installation through its native configuration and lockfile; Hivex has no custom installer or
61
- registry verifier. See the [installation decision](adr/0003-independent-bun-installation.md).
62
-
63
- The lint configuration owns executable syntax/complexity constraints: cyclomatic complexity 20,
64
- cognitive complexity 15, at most four parameters, nesting depth three and no nested/chained
65
- ternaries. Refactor around meaningful responsibilities rather than adding tiny wrappers merely to
66
- make a number pass. Changes to those limits require a documented decision.
67
-
68
- ## Tests protect behavior
69
-
70
- TDD guides development through meaningful failing examples; it does not require a test for every
71
- function, component, wrapper or line. A test must identify a supported behavior, meaningful invariant
72
- or regression it protects. Prefer the caller's observable interface and results that survive an
73
- internal refactor.
74
-
75
- For UI, test visible content, accessibility, interactions and loading/error/empty-state behavior.
76
- Do not freeze arbitrary child arrays, wrapper counts or class/style arrangements. A visual dimension
77
- needs a test only when it is an intentional requirement worth maintaining. For example, displaying
78
- "2 of 4" is a behavior; representing it as exactly three React children is not.
79
-
80
- Mocks, call counts, ordering and exact bytes are not automatically wrong. They can protect an
81
- external protocol, idempotency, a query budget or faithful source reproduction. Their justification
82
- must be the contract, not the current arrangement of internal helpers. Expected results must be
83
- independent examples, not the implementation's own calculation repeated in the test.
84
-
85
- Review existing tests as retain, rewrite, consolidate or remove. Remove tests for retired behavior
86
- with that behavior; preserve still-needed guarantees at the replacement's actual interface. Do not
87
- port a legacy battery mechanically, chase a test-count target or retain duplicate suites indefinitely.
88
-
89
- ## Files and runtime data have a lifecycle
90
-
91
- Create a source file for a meaningful responsibility and a document for a distinct authoritative
92
- purpose. Do not create files for every helper, task, turn, attempt or handoff merely to satisfy a
93
- layout convention or a lint threshold.
94
-
95
- Before introducing persistent state, define its purpose, location, owner and retention. Prefer a small
96
- project-local data store to an unbounded tree of per-event files. A per-unit atomic checkpoint can be
97
- a database transaction; it does not require a separate file. Fewer filenames alone do not bound data
98
- growth: cached data, run history and diagnostics also need size/count/age limits and cleanup behavior.
99
-
100
- Normal read-only queries should leave no per-query artifacts. Clean up owned temporary resources
101
- on ordinary completion and handled failures. Interrupted work must remain recoverable without being
102
- silently retried or discarded. Export diagnostic bundles when needed rather than automatically
103
- writing a new report for every successful step. Retention must preserve the accepted state and the
104
- evidence needed by supported historical/recovery operations; it must not invent a successful cleanup.
105
-
106
- ## Documentation is maintained authority
107
-
108
- Code must be self-explanatory through clear names, structure and behavior. Repository Markdown is
109
- the source of truth for intent, constraints, decisions and reasons that code cannot explain. Do not
110
- write a parallel implementation manual or use documentation to compensate for unclear code.
111
- Accepted source history and Markdown retain authority; caches, model output and search hits do not.
112
- An accepted status alone does not settle amendments, exceptions or contradictions. Keep unresolved
113
- evidence explicit. Never promote a historical agent's description of an owner ruling without
114
- checking its provenance and applicability.
115
-
116
- Capture every decision worth preserving in its appropriate repository document as part of the work.
117
- Do not leave accepted knowledge only in a conversation, issue comment or runtime log. Update the
118
- existing canonical document when it already owns the topic and scope; create a new one only when
119
- it has a distinct purpose. An issue can track the work and preserve discussion, but it is not a
120
- substitute for incorporating the resulting doctrine into the documentation.
121
-
122
- Keep docs with the monorepo, workspace or module they describe. Link to common rules instead of
123
- copying them. Recommended new Markdown should state purpose/scope, use stable headings and suitable
124
- metadata, keep a rule with its conditions/exceptions, and link its sources and replacements. Accept
125
- compatible existing Markdown without forcing those authors to adopt our template. Do not generate
126
- empty documentation for every module or add non-Markdown readers to the current scope.
127
-
128
- Use repository decisions and review evidence for durable knowledge, not private agent memory.
129
- Checkpoints identify the exact commit, verified work and remaining work. Choose a context handoff
130
- when the task needs it; Hivex does not impose the retired machinery's fixed token thresholds.
131
- Knowledge-model operations use the admitted Luna/max profile and record actual usage, including
132
- failed or interrupted attempts. Deterministic retrieval and maintenance do not require a model.
133
-
134
- The replacement workflow follows [ADR 0010](adr/0010-practical-knowledge-assistance.md). It processes
135
- bounded document batches with one additional knowledge check, keeps partial knowledge usable and
136
- preserves a work budget across phases and resumption. A consultation maintains one pending batch
137
- before answering, and a source-based repair replaces interpretations without changing doctrine.
138
- Keep check warnings scoped and public evidence limited to source coordinates, version and text. Avoid a new abstraction or protocol unless it
139
- protects a concrete requirement. The owner-authorized implementation can replace the earlier
140
- cohort/admission pipeline; its historical evidence remains unchanged.
141
-
142
- Hivex assists the principal reviewer with decisions, dependencies, exceptions and possible conflicts.
143
- The reviewer verifies its findings. Missing context or uncertainty limits the conclusions it affects;
144
- a definitive finding must refer to the actual document and implementation versions reviewed.
145
-
146
- ## Retire mechanisms without losing knowledge
147
-
148
- Early use in Compi can support validation and recovery before full retirement. Necessary adoption
149
- and verification work belongs to Hivex completion. Alternative model integrations are evolutionary work;
150
- keep the current Codex/Luna route usable without spreading its assumptions into the knowledge model.
151
-
152
- After knowledge recovery, replacement validation and consumer migration, remove obsolete orchestration
153
- code, scripts, hooks, configuration, tests, dependencies and active instructions. Do not carry an unused
154
- legacy framework into Hivex under another name. Preserve useful decisions in their canonical docs and
155
- retain necessary historical evidence in Git or a bounded private archive outside the active worktree.
156
- Do not rewrite Git history or destroy the accepted Opus graph before its replacement is admitted.
157
-
158
- Early use can precede complete legacy recovery. Complete closure requires useful historical knowledge
159
- in Markdown, Hivex demonstrated in Compi and the old active machinery retired with its consumers.
160
- Validate the new workflow against bounded real cases, not identity with an old model's graph or an
161
- exhaustive replay prerequisite. Release packages exclude private project evidence and retired runtime.
162
-
163
- ## Distribution
164
-
165
- The owner selected `@h1v35/hivex` for the npm package on 2026-09-08, retaining `hivex` as the installed
166
- command, and approved the MIT license. The scoped name avoids the unrelated existing unscoped npm
167
- package. Use an authenticated account authorized for that scope; do not infer npm ownership from a
168
- matching GitHub name. Release preparation must verify the packed contents and exclude private project
169
- evidence and runtime stores. Compi adopts a pinned published version after the complete cycle is
170
- validated; this decision alone does not mean a package has been published.
171
-
172
- Before publication, inspect and scan the exact package archive for secrets and unintended private
173
- content. Record its hash and the completed scan result; a repack requires a fresh check. Publish the
174
- same verified artifact, not an unchecked reconstruction from a changed working tree.