@h1v35/hivex 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/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@h1v35/hivex",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Versioned project knowledge for people and agents.",
6
+ "scripts": {
7
+ "hivex": "bun src/cli.ts",
8
+ "test": "bun test --timeout 15000 ./src",
9
+ "typecheck": "node_modules/typescript-native/bin/tsc --noEmit",
10
+ "lint": "eslint src test tooling eslint.config.js eslint.base.config.js",
11
+ "format:check": "prettier --check ."
12
+ },
13
+ "dependencies": {
14
+ "mdast-util-from-markdown": "2.0.3",
15
+ "mdast-util-frontmatter": "2.0.1",
16
+ "mdast-util-gfm": "3.1.0",
17
+ "mdast-util-to-string": "4.0.0",
18
+ "micromark-extension-frontmatter": "2.0.0",
19
+ "micromark-extension-gfm": "3.0.0",
20
+ "micromark-util-normalize-identifier": "2.0.1",
21
+ "yaml": "2.9.0",
22
+ "zod": "4.4.3"
23
+ },
24
+ "devDependencies": {
25
+ "@eslint/js": "10.0.1",
26
+ "typescript-native": "npm:typescript@7.0.2",
27
+ "@types/bun": "1.3.14",
28
+ "eslint": "10.7.0",
29
+ "eslint-plugin-sonarjs": "1.0.4",
30
+ "globals": "16.5.0",
31
+ "typescript": "npm:@typescript/typescript6@6.0.2",
32
+ "typescript-eslint": "8.64.0",
33
+ "prettier": "3.8.4"
34
+ },
35
+ "trustedDependencies": [],
36
+ "packageManager": "bun@1.4.2",
37
+ "engines": {
38
+ "bun": "1.4.2"
39
+ },
40
+ "license": "MIT",
41
+ "bin": {
42
+ "hivex": "src/cli.ts"
43
+ },
44
+ "files": [
45
+ "src/**/*.ts",
46
+ "!src/**/*.test.ts",
47
+ "docs/README.md",
48
+ "docs/CONTEXT.md",
49
+ "docs/engineering.md",
50
+ "docs/adr/0003-independent-bun-installation.md",
51
+ "docs/adr/0010-practical-knowledge-assistance.md",
52
+ "skills/",
53
+ "README.md",
54
+ "LICENSE"
55
+ ],
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/H1V35/hivex.git"
59
+ },
60
+ "publishConfig": {
61
+ "access": "public",
62
+ "registry": "https://registry.npmjs.org/"
63
+ }
64
+ }
@@ -0,0 +1,108 @@
1
+ ---
2
+ name: hivex
3
+ description: Retrieve project decisions and their dependencies and exceptions with Hivex, support implementation and review, and maintain useful Markdown knowledge. Use when Hivex is requested or configured for a project.
4
+ ---
5
+
6
+ # Hivex
7
+
8
+ Hivex gives the implementing and reviewing agents project context. Markdown is documentary
9
+ authority; the graph is derived assistance. The principal agent remains responsible for the work.
10
+ Recover settled decisions before asking the owner to decide them again.
11
+
12
+ ## Start with the installed interface
13
+
14
+ Read the project's agent instructions and source configuration. Run `hivex --help` when the installed
15
+ interface is unfamiliar. In a Bun project, `bun hivex` resolves the installed CLI. The package is
16
+ `@h1v35/hivex`; do not fetch the unrelated unscoped package.
17
+
18
+ Use the capabilities advertised by that version. Do not invent commands, silently switch models or
19
+ pretend a planned capability exists. Hivex's current validated knowledge profile is Luna/max through
20
+ native Codex; the principal agent's model is independent of that choice.
21
+
22
+ Native Codex must be able to write its own local state. When the host sandbox prevents that,
23
+ use its normal execution-approval mechanism within the existing authorized scope. Keep a failed
24
+ launch in the same work history when resuming; an initialization failure is not a model verdict.
25
+
26
+ ## Before implementation
27
+
28
+ For a coherent feature or behavior change, ask about the intended task and recover the relevant
29
+ decisions. Read their evidence and follow relevant dependencies, exceptions and replacements,
30
+ including indirect relationships. A search preview or accepted label alone does not settle scope.
31
+
32
+ Use Hivex's source/version references. Keep conditions with their rules; a partial exception does
33
+ not revoke an entire document. If the evidence answers the question, apply it without asking the
34
+ owner again. Ask only when information is missing, sources cannot resolve a real ambiguity or a
35
+ new decision requires the owner's involvement. Present the sources, impact and your recommendation.
36
+
37
+ Queries should be focused. Reuse context that remains current rather than asking again per file or
38
+ implementation step. Respect declared incomplete exploration and unavailable evidence.
39
+
40
+ ## During review
41
+
42
+ The principal reviewer directs the review. Run `hivex review "<task>" --base <git-ref>` from the
43
+ Git project root. It examines tracked and untracked working changes, recovers relevant documentary
44
+ context and makes one review call after at most one update/check batch. The default total budget is
45
+ three calls; resume the same task/base with the intended total limit to continue retained work.
46
+ Expanding a partial report keeps its work identity and consumed budget; a larger context does not
47
+ create another allowance.
48
+
49
+ Check each finding against its cited before/after code and Markdown versions, including dependencies,
50
+ conditions and exceptions. Resolve a demonstrated contradiction before closing the change, by
51
+ correcting the implementation or recording an approved decision change. Uncertainty calls for focused
52
+ investigation; absence of a finding is not implementation approval. Missing context may be addressed
53
+ with a focused task, explicit `--source` or an appropriate context limit, not automatic semantic retries.
54
+
55
+ Save a report outside the reviewed project or in an ignored path when it must survive the session.
56
+ `hivex review --check <saved-report.json> --root <project>` checks documentary and implementation
57
+ freshness without a model. A current report is not proof of correct code; a stale report does not
58
+ cover subsequent changes. Review output never replaces general code review, lint or tests.
59
+
60
+ ## Maintain knowledge
61
+
62
+ The implementing agent maintains the documents as part of the change. Hivex may identify affected
63
+ documents or suggest a correction, but does not rewrite project decisions on its own. Correct an
64
+ incorrect graph interpretation against its source; do not alter doctrine to satisfy the model.
65
+
66
+ Keep documents at their monorepo, package or module authority. Follow the project's existing layout
67
+ and format. When establishing or improving documentation, use the optional
68
+ [Markdown convention](references/markdown.md); it is guidance, not an installation prerequisite.
69
+
70
+ Detect new, changed or removed documents before relying on the graph. Use the installed update
71
+ workflow within the same work budget. Working documents may be queried without a commit, but that
72
+ state is not approval; preserve the exact versions used by a review. Pending or uncertain knowledge
73
+ limits the conclusions that depend on it, without making unrelated context unusable.
74
+
75
+ `ask` updates at most one relevant pending batch before answering, under the same total call/input
76
+ budget. Its default is three calls. Omitted limits preserve a resumed work item's budget. Repeat the same task to resume; changing its budget changes the
77
+ total ceiling, never the consumed count. Pending corpus coverage is explicit; use `update` when more
78
+ rounds are needed, rather than issuing repeated identical questions to force indexing.
79
+
80
+ Repair a demonstrably wrong interpretation with `update --repair <document> --reason <correction>`.
81
+ Check the Markdown first. This revises derived knowledge and its relationships without changing the
82
+ document or authorizing new policy. Do not use it to suppress a genuine contradiction. Review source-local
83
+ warnings in their stated scope and inspect `unavailableDocuments` for changed or removed dependencies.
84
+
85
+ ## Control consumption
86
+
87
+ Large Markdown is ingested in bounded rounds. Inspect pending units and coverage, and resume the
88
+ same work; do not wipe the store or resend the whole corpus when only a later round remains.
89
+
90
+ A budget covers the complete work item, its phases and attempts. Resume retained progress with its
91
+ original accounting; do not start a fresh counter to bypass an exhausted limit. Separate initial
92
+ indexing, maintenance, consultation and review costs and report actual usage and unknown consumption.
93
+ Deterministic reads do not require another model call, although the caller consumes context tokens.
94
+
95
+ Do not automatically retry semantic disagreements or keep correcting until the model says green.
96
+ After a crash, use `recover` to inspect retained work. It must not alter live owners or processes.
97
+ An explicit `--acknowledge-uncertain` preserves uncertainty and cost; it does not certify a remote
98
+ outcome or authorize an automatic retry. Resume only the intended work with its existing budget.
99
+ Use `prune` for obsolete completed work and cached responses when needed; keep unfinished work and
100
+ export evidence that must outlive cache retention.
101
+
102
+ Preserve useful results and their limits. At a budget boundary, explain what remains and obtain an
103
+ authorized extension before spending more. Existing user authorization remains valid; the skill does
104
+ not require another permission question for already authorized work.
105
+
106
+ If maintenance reports `context-limit`, inspect `work.contextLimit` for required documents and bytes.
107
+ Restore missing evidence or adjust the context bound, then resume the same task. No extraction call
108
+ is spent while its known relationship evidence is unavailable or exceeds that bound.
@@ -0,0 +1,64 @@
1
+ # Optional Markdown convention
2
+
3
+ Use the project's existing Markdown as it is. Hivex must not require this convention, frontmatter,
4
+ numbered ADRs or a particular directory structure. Recommend these practices when adopting Hivex or
5
+ writing documentation, without repeatedly proposing a migration of an established project.
6
+
7
+ These practices draw on Compi's authority map and documentation layout and the domain-modeling
8
+ skill. They preserve the useful documentation discipline, not Compi's retired machinery.
9
+
10
+ ## Give knowledge one authoritative home
11
+
12
+ Keep shared decisions at project or monorepo level. Package-specific or module-specific knowledge
13
+ can stay with that package or module. Link shared rules instead of copying them into each area.
14
+ Folders and files appear only when there is useful content to put in them.
15
+
16
+ A useful catalogue distinguishes:
17
+
18
+ - An authority map explaining where each kind of knowledge belongs.
19
+ - A domain glossary defining the project's terms, with avoided synonyms where useful.
20
+ - Decisions and their reasons, often kept as ADRs.
21
+ - Guidelines containing design invariants and lessons worth applying again.
22
+ - Process documents explaining the working method.
23
+ - Procedures for concrete operational or recovery tasks.
24
+ - Research and evidence identified as dated support, not automatically current decisions.
25
+
26
+ For example, a project may use `docs/README.md`, `docs/CONTEXT.md`, `docs/adr/`,
27
+ `docs/guidelines/`, `docs/process/`, `docs/procedures/` and `docs/research/`. These are examples,
28
+ not required paths. Multiple bounded contexts may have their own glossary and decisions with a
29
+ small context map linking them; a monorepo need not duplicate one shared product glossary.
30
+
31
+ ## Write decisions for the next reader
32
+
33
+ State what was decided and why. Include the scope, conditions and exceptions that change how the
34
+ rule is applied. Link the source or decision it depends on or replaces. A short paragraph can be
35
+ enough; optional sections should carry information rather than serve as boxes to fill in.
36
+
37
+ For a consequential architectural trade-off, an ADR might be:
38
+
39
+ ```markdown
40
+ # Remove private cached data when access is revoked
41
+
42
+ Cached private data is removed immediately when access is revoked. The normal cache lifetime
43
+ still applies while access remains valid. This prevents stale local access after a permission
44
+ change. See the cache policy for the general retention rule.
45
+ ```
46
+
47
+ A title, truthful status and decision date can improve cataloguing. Tags are optional. If a rule is
48
+ replaced, identify the replacement and whether the change is partial. Keep the historical reasoning
49
+ readable; do not silently rewrite the past. A missing status means uncertainty to resolve from the
50
+ content, not permission to assume acceptance.
51
+
52
+ Use an ADR when the choice is consequential, reflects a real trade-off and would be surprising
53
+ without its rationale. Do not create one for every routine edit or dependency. Sequential names
54
+ such as `0001-short-decision.md` are convenient if the project adopts that convention.
55
+
56
+ ## Keep the glossary focused
57
+
58
+ Define each project-specific concept briefly and use that term consistently. A glossary explains
59
+ what a concept is; it is not an implementation manual, task plan or collection of general programming
60
+ terms. Group related concepts when it helps and link context-specific definitions instead of copying.
61
+
62
+ Code and executable contracts explain mechanics. Markdown preserves the intent, constraints,
63
+ decisions and reasons that code cannot explain. Update that knowledge alongside the change rather
64
+ than leaving the only explanation in a conversation or private agent memory.
@@ -0,0 +1,26 @@
1
+ import { HivexError } from '../errors.ts';
2
+
3
+ function bounded(text: string) {
4
+ let result = '';
5
+ for (const char of text) {
6
+ if (Buffer.byteLength(JSON.stringify(result + char)) > 256) break;
7
+ result += char;
8
+ }
9
+ return result;
10
+ }
11
+
12
+ export function diagnostic(error: unknown) {
13
+ let failure = new HivexError({
14
+ code: 'READ_FAILED',
15
+ message: 'Unable to read project knowledge',
16
+ });
17
+ if (error instanceof HivexError) failure = error;
18
+ else if (error instanceof Error)
19
+ failure = new HivexError({ code: 'READ_FAILED', message: error.message });
20
+ let details = failure.details;
21
+ if (details && Buffer.byteLength(JSON.stringify(details)) > 384) details = { omitted: true };
22
+ const message = bounded(failure.message);
23
+ return {
24
+ error: { code: failure.code, message, messageTruncated: message !== failure.message, details },
25
+ };
26
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env bun
2
+ import { checkReview } from './review.ts';
3
+ import { documentCommand } from './documents.ts';
4
+ import { knowledgeMaintenance } from './knowledge-maintenance.ts';
5
+ import { knowledgeCommand } from './knowledge.ts';
6
+ import { diagnostic } from './cli/diagnostic.ts';
7
+
8
+ async function main(args: string[]) {
9
+ if (!args.length || args.includes('--help'))
10
+ return {
11
+ application: 'hivex',
12
+ purpose: 'Project decisions, dependencies and exceptions for the responsible agent.',
13
+ commands: [
14
+ {
15
+ name: 'sources',
16
+ usage:
17
+ 'sources [--root <project>] [--limit <count>] [--cursor <continuation>] [--max-bytes <bytes>]',
18
+ modelCalls: 0,
19
+ },
20
+ {
21
+ name: 'read',
22
+ usage:
23
+ 'read <document> [--root <project>] [--from <line>] [--to <line>] [--max-bytes <bytes>]',
24
+ modelCalls: 0,
25
+ },
26
+ {
27
+ name: 'update',
28
+ usage:
29
+ 'update [--root <project>] [--max-calls <total>] [--max-input-bytes <total>] [--repair <document> --reason <correction>]',
30
+ modelCalls:
31
+ 'One extraction and one check per batch; retained work resumes within the same budget.',
32
+ },
33
+ {
34
+ name: 'search',
35
+ usage: 'search <query> [--root <project>] [--limit <count>]',
36
+ modelCalls: 0,
37
+ },
38
+ {
39
+ name: 'neighbors',
40
+ usage: 'neighbors <decision-id> [--root <project>] [--limit <count>]',
41
+ modelCalls: 0,
42
+ },
43
+ {
44
+ name: 'ask',
45
+ usage:
46
+ 'ask <task> [--root <project>] [--source <document>] [--max-calls <total>] [--max-input-bytes <total>] [--max-context-bytes <bytes>]',
47
+ modelCalls:
48
+ 'One bounded automatic update/check batch and Luna/max assistance share a total budget; identical retained answers are reused.',
49
+ },
50
+ {
51
+ name: 'review',
52
+ usage:
53
+ 'review <task> --base <git-ref> [--root <project>] [--source <document>] [--max-calls <total>] [--max-context-bytes <bytes>] | review --check <saved-report.json> [--root <project>]',
54
+ modelCalls:
55
+ 'One automatic update/check batch and a review share one budget. Checking saved versions needs no model.',
56
+ },
57
+ {
58
+ name: 'recover',
59
+ usage: 'recover [--root <project>] [--acknowledge-uncertain]',
60
+ modelCalls: 0,
61
+ },
62
+ {
63
+ name: 'prune',
64
+ usage: 'prune [--root <project>] [--keep-completed <count>] [--keep-caches <count>]',
65
+ modelCalls: 0,
66
+ },
67
+ { name: 'status', usage: 'status [--root <project>]', modelCalls: 0 },
68
+ ],
69
+ modelOptions: '--codex <native-binary> --deadline-ms <100..1800000> --retry-failed',
70
+ configuration: 'Optional hivex.json with include/exclude relative Markdown globs.',
71
+ stage: 'Incremental project knowledge and task/diff assistance for the principal agent.',
72
+ };
73
+ if (args[0] === 'review' && args.includes('--check')) return checkReview(args);
74
+ if (args[0] === 'sources' || args[0] === 'read') return documentCommand(args);
75
+ if (args[0] === 'recover' || args[0] === 'prune') return knowledgeMaintenance(args);
76
+ return knowledgeCommand(args);
77
+ }
78
+
79
+ try {
80
+ const result = await main(process.argv.slice(2));
81
+ process.stdout.write(JSON.stringify(result) + '\n');
82
+ if (
83
+ result &&
84
+ typeof result === 'object' &&
85
+ 'status' in result &&
86
+ (result.status === 'failed' || result.status === 'blocked')
87
+ )
88
+ process.exitCode = 1;
89
+ } catch (error) {
90
+ process.stderr.write(JSON.stringify(diagnostic(error)) + '\n');
91
+ process.exitCode = 1;
92
+ }