@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/LICENSE +21 -0
- package/README.md +213 -0
- package/docs/CONTEXT.md +59 -0
- package/docs/README.md +14 -0
- package/docs/adr/0003-independent-bun-installation.md +37 -0
- package/docs/adr/0010-practical-knowledge-assistance.md +92 -0
- package/docs/engineering.md +174 -0
- package/package.json +64 -0
- package/skills/hivex/SKILL.md +108 -0
- package/skills/hivex/references/markdown.md +64 -0
- package/src/cli/diagnostic.ts +26 -0
- package/src/cli.ts +92 -0
- package/src/documents.ts +575 -0
- package/src/errors.ts +15 -0
- package/src/implementation.ts +191 -0
- package/src/ingestion-units.ts +155 -0
- package/src/knowledge-maintenance.ts +76 -0
- package/src/knowledge-model.ts +418 -0
- package/src/knowledge-store.ts +657 -0
- package/src/knowledge.ts +1184 -0
- package/src/markdown.ts +98 -0
- package/src/model/connection.ts +207 -0
- package/src/model/failure.ts +33 -0
- package/src/model/invoke.ts +265 -0
- package/src/model/profile.ts +211 -0
- package/src/model/server.ts +174 -0
- package/src/model/thread.ts +50 -0
- package/src/model/transcript.ts +114 -0
- package/src/retrieval/lexical.ts +92 -0
- package/src/review.ts +129 -0
package/src/review.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { loadProject, type Project } from './documents.ts';
|
|
6
|
+
import { captureImplementation, type Implementation } from './implementation.ts';
|
|
7
|
+
import {
|
|
8
|
+
citationSchema,
|
|
9
|
+
sourceEvidence,
|
|
10
|
+
suppliedCitation,
|
|
11
|
+
type SuppliedDocument,
|
|
12
|
+
} from './knowledge-model.ts';
|
|
13
|
+
import { HivexError } from './errors.ts';
|
|
14
|
+
|
|
15
|
+
const codeCitation = z.object({
|
|
16
|
+
path: z.string().min(1),
|
|
17
|
+
side: z.enum(['before', 'after']),
|
|
18
|
+
lineStart: z.number().int().positive(),
|
|
19
|
+
lineEnd: z.number().int().positive(),
|
|
20
|
+
});
|
|
21
|
+
export const reviewSchema = z.object({
|
|
22
|
+
findings: z
|
|
23
|
+
.array(
|
|
24
|
+
z.object({
|
|
25
|
+
assessment: z.enum(['conflict', 'exception', 'uncertain']),
|
|
26
|
+
explanation: z.string().min(1).max(4096),
|
|
27
|
+
documents: z.array(citationSchema).max(8),
|
|
28
|
+
code: z.array(codeCitation).max(8),
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
31
|
+
.max(12),
|
|
32
|
+
uncertainties: z.array(z.string().min(1).max(2048)).max(24),
|
|
33
|
+
});
|
|
34
|
+
export const reviewInstructions =
|
|
35
|
+
'Assist the principal reviewer with the task and implementation diff. Discover possible conflicts without requiring suspicions. Explain how documentary rules, direct/indirect dependencies, conditions and exceptions apply. Findings may identify a conflict, a valid exception, or uncertainty; do not turn missing context into approval or reject the entire change. Cite the supplied Markdown ranges and before/after code lines supporting each finding. Distinguish a rule violated by the change from behavior merely seen in context. The reviewer must verify each finding. This is knowledge assistance, not general code review, lint, tests or implementation approval.';
|
|
36
|
+
|
|
37
|
+
function codeEvidence(citation: z.infer<typeof codeCitation>, implementation: Implementation) {
|
|
38
|
+
const file = implementation.files.find((entry) => entry.path === citation.path)?.[citation.side];
|
|
39
|
+
if (!file || citation.lineEnd < citation.lineStart) return null;
|
|
40
|
+
const lines = file.lines.filter(
|
|
41
|
+
([number]) => number >= citation.lineStart && number <= citation.lineEnd,
|
|
42
|
+
);
|
|
43
|
+
if (lines.length !== citation.lineEnd - citation.lineStart + 1) return null;
|
|
44
|
+
return { ...citation, version: file.version, text: lines.map(([, text]) => text).join('\n') };
|
|
45
|
+
}
|
|
46
|
+
export function materializeReview(
|
|
47
|
+
project: Project,
|
|
48
|
+
implementation: Implementation,
|
|
49
|
+
value: unknown,
|
|
50
|
+
supplied: SuppliedDocument[],
|
|
51
|
+
) {
|
|
52
|
+
const response = reviewSchema.parse(value);
|
|
53
|
+
const findings = response.findings.map((finding) => {
|
|
54
|
+
const documents = finding.documents
|
|
55
|
+
.map((citation) =>
|
|
56
|
+
suppliedCitation(citation, supplied) ? sourceEvidence(citation, project) : null,
|
|
57
|
+
)
|
|
58
|
+
.filter((entry) => entry !== null);
|
|
59
|
+
const code = finding.code
|
|
60
|
+
.map((citation) => codeEvidence(citation, implementation))
|
|
61
|
+
.filter((entry) => entry !== null);
|
|
62
|
+
const referencesVerified =
|
|
63
|
+
documents.length > 0 &&
|
|
64
|
+
code.length > 0 &&
|
|
65
|
+
documents.length === finding.documents.length &&
|
|
66
|
+
code.length === finding.code.length;
|
|
67
|
+
return {
|
|
68
|
+
...finding,
|
|
69
|
+
assessment: referencesVerified ? finding.assessment : 'uncertain',
|
|
70
|
+
documents,
|
|
71
|
+
code,
|
|
72
|
+
referencesVerified,
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
findings,
|
|
77
|
+
uncertainties: response.uncertainties,
|
|
78
|
+
invalidReferences: findings.some((finding) => !finding.referencesVerified),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const bindingSchema = z.object({
|
|
83
|
+
baseCommit: z.string().regex(/^[a-f0-9]{40,64}$/),
|
|
84
|
+
implementation: z.string().regex(/^[a-f0-9]{64}$/),
|
|
85
|
+
documents: z.string().regex(/^[a-f0-9]{64}$/),
|
|
86
|
+
});
|
|
87
|
+
export function reviewBinding(project: Project, implementation: Implementation) {
|
|
88
|
+
return {
|
|
89
|
+
baseCommit: implementation.baseCommit,
|
|
90
|
+
implementation: implementation.fingerprint,
|
|
91
|
+
documents: project.snapshot,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function reviewFreshness(root: string, binding: z.infer<typeof bindingSchema>) {
|
|
95
|
+
const project = loadProject(root);
|
|
96
|
+
const implementation = captureImplementation(root, binding.baseCommit);
|
|
97
|
+
const documentsChanged = project.snapshot !== binding.documents;
|
|
98
|
+
const implementationChanged = implementation.fingerprint !== binding.implementation;
|
|
99
|
+
return {
|
|
100
|
+
status: documentsChanged || implementationChanged ? 'stale' : 'current',
|
|
101
|
+
documentsChanged,
|
|
102
|
+
implementationChanged,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function checkReview(args: string[]) {
|
|
106
|
+
const parsed = parseArgs({
|
|
107
|
+
args,
|
|
108
|
+
allowPositionals: true,
|
|
109
|
+
strict: true,
|
|
110
|
+
options: { root: { type: 'string' }, check: { type: 'string' } },
|
|
111
|
+
});
|
|
112
|
+
if (parsed.positionals.length !== 1 || parsed.positionals[0] !== 'review' || !parsed.values.check)
|
|
113
|
+
throw new HivexError({
|
|
114
|
+
code: 'INVALID_ARGUMENT',
|
|
115
|
+
message: 'Use review --check <saved-report.json> [--root <project>].',
|
|
116
|
+
});
|
|
117
|
+
const root = parsed.values.root ?? process.cwd();
|
|
118
|
+
const path = resolve(root, parsed.values.check);
|
|
119
|
+
if (statSync(path).size > 1048576)
|
|
120
|
+
throw new HivexError({ code: 'INVALID_REVIEW', message: 'Saved review exceeds 1 MiB.' });
|
|
121
|
+
const report = z
|
|
122
|
+
.object({ command: z.literal('review'), binding: bindingSchema })
|
|
123
|
+
.parse(JSON.parse(readFileSync(path, 'utf8')));
|
|
124
|
+
return {
|
|
125
|
+
command: 'review-check',
|
|
126
|
+
...reviewFreshness(root, report.binding),
|
|
127
|
+
guidance: 'Current means the versions still match, not that the implementation is approved.',
|
|
128
|
+
};
|
|
129
|
+
}
|