@weftlet/toolkit 0.5.0 → 0.6.1
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/README.md +139 -14
- package/dist/application/cache-adoption.d.ts +2 -1
- package/dist/application/cache-adoption.js +12 -5
- package/dist/application/document-coverage.d.ts +28 -0
- package/dist/application/document-coverage.js +58 -0
- package/dist/application/document-overlay.d.ts +14 -0
- package/dist/application/document-overlay.js +31 -0
- package/dist/application/extraction-identity.d.ts +2 -1
- package/dist/application/extraction-identity.js +7 -0
- package/dist/application/hydration-inputs.d.ts +15 -0
- package/dist/application/hydration-inputs.js +55 -0
- package/dist/application/hydration-plan.d.ts +7 -0
- package/dist/application/hydration-plan.js +18 -5
- package/dist/application/hydrator.js +26 -14
- package/dist/application/overlay.js +26 -8
- package/dist/application/saved-evidence.d.ts +2 -2
- package/dist/application/semantic-scope.d.ts +1 -1
- package/dist/application/semantic-scope.js +2 -2
- package/dist/configuration/cache.js +13 -1
- package/dist/configuration/config.d.ts +2 -0
- package/dist/configuration/config.js +5 -0
- package/dist/configuration/document-traversal.d.ts +7 -0
- package/dist/configuration/document-traversal.js +13 -0
- package/dist/extraction/canonical-document-links.d.ts +28 -0
- package/dist/extraction/canonical-document-links.js +95 -0
- package/dist/extraction/document-classification.d.ts +44 -0
- package/dist/extraction/document-classification.js +161 -0
- package/dist/extraction/document-evidence.d.ts +21 -0
- package/dist/extraction/document-evidence.js +83 -0
- package/dist/extraction/document-traversal.d.ts +76 -0
- package/dist/extraction/document-traversal.js +210 -0
- package/dist/extraction/document.d.ts +3 -1
- package/dist/extraction/document.js +3 -1
- package/dist/extraction/ontology.js +2 -2
- package/dist/extraction/static.js +25 -20
- package/dist/graph/authority.js +3 -0
- package/dist/graph/coverage.d.ts +8 -0
- package/dist/graph/coverage.js +96 -0
- package/dist/graph/document-role-description.d.ts +5 -0
- package/dist/graph/document-role-description.js +18 -0
- package/dist/graph/query.d.ts +2 -2
- package/dist/graph/query.js +22 -62
- package/dist/graph/rdf.js +11 -0
- package/dist/graph/shacl-shapes.js +26 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/infrastructure/artifact-paths.d.ts +4 -0
- package/dist/infrastructure/artifact-paths.js +14 -0
- package/dist/interfaces/cli.js +18 -1
- package/dist/interfaces/document-coverage.d.ts +9 -0
- package/dist/interfaces/document-coverage.js +117 -0
- package/dist/repository/git.d.ts +11 -0
- package/dist/repository/git.js +38 -0
- package/dist/storage/storage.js +41 -13
- package/dist/visualization/visualization.js +21 -6
- package/docs/ADR-017-shacl-validation-union.md +4 -0
- package/docs/ADR-021-identity-preflight-and-validation-timing.md +5 -2
- package/docs/ADR-022-release-documentation.md +44 -0
- package/docs/ADR-023-document-coverage-preview.md +64 -0
- package/docs/ADR-024-implementation-coverage.md +51 -0
- package/docs/ADR-025-document-classification.md +78 -0
- package/docs/ADR-026-traversal-hydration.md +94 -0
- package/docs/ADR-027-validation-closeout.md +155 -0
- package/docs/ADR-028-bounded-artifact-paths.md +58 -0
- package/docs/CONSUMER-TRIAL.md +7 -5
- package/docs/GRAPHIFY-EVALUATION.md +70 -0
- package/docs/MIGRATING-TO-WEFTLET.md +1 -1
- package/docs/PRE-1.0-BASELINE.md +94 -0
- package/docs/PROVIDERS.md +10 -1
- package/docs/RELEASE-1.0-PLAN.md +145 -23
- package/docs/RELEASING.md +46 -8
- package/docs/ROADMAP.md +48 -16
- package/docs/VALIDATION.md +390 -0
- package/docs/assessments/pre-1.0-2026-10-28.json +200 -0
- package/docs/benchmarks/validation-2026-10-28/README.md +25 -0
- package/docs/benchmarks/validation-2026-10-28/large.json +1 -0
- package/docs/benchmarks/validation-2026-10-28/lifecycle.json +1 -0
- package/docs/benchmarks/validation-2026-10-28/native.json +1 -0
- package/docs/benchmarks/validation-2026-10-28/rich.json +1 -0
- package/docs/extraction-manifest.json +78 -20
- package/examples/generic-typescript/document-policy.json +9 -0
- package/package.json +7 -4
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Modified for standalone extraction; see docs/extraction-manifest.json.
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
2
|
import { withCommittedTree } from "../repository/committed-tree.js";
|
|
4
|
-
import { copyFile, mkdir, readFile, rename, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { copyFile, mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
4
|
import { createRequire } from 'node:module';
|
|
6
5
|
import { dirname, join } from 'node:path';
|
|
7
6
|
import { pathToFileURL } from 'node:url';
|
|
@@ -13,6 +12,7 @@ import { moduleRequestNode } from './module-request.js';
|
|
|
13
12
|
import { matchesRepositoryGlob } from "../repository/glob.js";
|
|
14
13
|
import { runProcess } from "../infrastructure/process.js";
|
|
15
14
|
import { sha256, stableJson } from "../infrastructure/util.js";
|
|
15
|
+
import { physicalArtifactKey, temporaryArtifactPath } from '../infrastructure/artifact-paths.js';
|
|
16
16
|
export class ScipTypeScriptIndexer {
|
|
17
17
|
config;
|
|
18
18
|
storageRoot;
|
|
@@ -26,9 +26,9 @@ export class ScipTypeScriptIndexer {
|
|
|
26
26
|
assertSourceProjectInvocation(this.config.command, this.config.args);
|
|
27
27
|
}
|
|
28
28
|
const require = createRequire(import.meta.url);
|
|
29
|
-
const destination = join(this.storageRoot, 'scip', `${context.snapshotId}.scip`);
|
|
29
|
+
const destination = join(this.storageRoot, 'scip', `${physicalArtifactKey(context.snapshotId)}.scip`);
|
|
30
30
|
await mkdir(join(this.storageRoot, 'scip'), { recursive: true });
|
|
31
|
-
const temporary =
|
|
31
|
+
const temporary = temporaryArtifactPath(destination);
|
|
32
32
|
const command = this.config.command === 'bundled-scip-typescript' ? process.execPath : this.config.command;
|
|
33
33
|
const args = this.config.command === 'bundled-scip-typescript'
|
|
34
34
|
? [
|
|
@@ -38,23 +38,28 @@ export class ScipTypeScriptIndexer {
|
|
|
38
38
|
temporary,
|
|
39
39
|
]
|
|
40
40
|
: this.config.args;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
...
|
|
45
|
-
|
|
41
|
+
try {
|
|
42
|
+
await withCommittedTree(context.repositoryRoot, context.commitSha, async (worktreeRoot) => {
|
|
43
|
+
const project = this.config.sourceProject ? await prepareScipSourceProject(worktreeRoot, this.config.sourceProject, await new GitRepository(context.repositoryRoot).listAllFilesAt(context.commitSha)) : undefined;
|
|
44
|
+
await runProcess(command, project ? [...args, project] : args, worktreeRoot, {
|
|
45
|
+
...process.env,
|
|
46
|
+
NODE_OPTIONS: process.env.NODE_OPTIONS ?? '--max-old-space-size=8192',
|
|
47
|
+
});
|
|
48
|
+
const source = this.config.command === 'bundled-scip-typescript'
|
|
49
|
+
? temporary
|
|
50
|
+
: join(worktreeRoot, 'index.scip');
|
|
51
|
+
await stat(source);
|
|
52
|
+
if (source !== temporary)
|
|
53
|
+
await copyFile(source, temporary);
|
|
54
|
+
// SCIP embeds this disposable checkout in metadata and inferred-type hover text.
|
|
55
|
+
// Store the normalized artifact itself so its digest still authenticates its bytes.
|
|
56
|
+
await writeFile(temporary, normalizeScipCheckout(await readFile(temporary), worktreeRoot));
|
|
46
57
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
await
|
|
51
|
-
|
|
52
|
-
await copyFile(source, temporary);
|
|
53
|
-
// SCIP embeds this disposable checkout in metadata and inferred-type hover text.
|
|
54
|
-
// Store the normalized artifact itself so its digest still authenticates its bytes.
|
|
55
|
-
await writeFile(temporary, normalizeScipCheckout(await readFile(temporary), worktreeRoot));
|
|
56
|
-
});
|
|
57
|
-
await rename(temporary, destination);
|
|
58
|
+
await rename(temporary, destination);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
await rm(temporary, { force: true });
|
|
62
|
+
}
|
|
58
63
|
return {
|
|
59
64
|
path: destination,
|
|
60
65
|
digest: sha256(await readFile(destination)),
|
package/dist/graph/authority.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export function contextPackEvidenceAuthority(fact) {
|
|
2
2
|
if (fact.authority)
|
|
3
3
|
return fact.authority;
|
|
4
|
+
// A document's role describes its source, not whether its claims were checked.
|
|
5
|
+
if (fact.sourceRole !== undefined)
|
|
6
|
+
return 'inferred';
|
|
4
7
|
if (fact.extractor.id === 'otlp-runtime-evidence')
|
|
5
8
|
return 'observed';
|
|
6
9
|
if (fact.extractor.id.startsWith('codex-cli:'))
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ContextPackCoverage, type ContextPackLane, type GraphFact } from '@weftlet/core';
|
|
2
|
+
export declare const contextPackLanes: readonly ContextPackLane[];
|
|
3
|
+
export declare function isDeclaredFact(fact: GraphFact): boolean;
|
|
4
|
+
export declare function contextPackLaneForFact(fact: GraphFact): ContextPackLane | undefined;
|
|
5
|
+
export declare function coverageDescription(coverage: ContextPackCoverage): string;
|
|
6
|
+
/** Reporting only: never changes a fact's authority, identity, primary lane or stored bytes. */
|
|
7
|
+
export declare function isImplementationEvidence(fact: GraphFact): boolean;
|
|
8
|
+
export declare function coverageForFacts(facts: readonly GraphFact[]): ContextPackCoverage;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { repositoryFileNode } from '@weftlet/core';
|
|
2
|
+
import { contextPackEvidenceAuthority } from './authority.js';
|
|
3
|
+
export const contextPackLanes = [
|
|
4
|
+
'productIntent',
|
|
5
|
+
'contractsAndInvariants',
|
|
6
|
+
'implementationAndConsumers',
|
|
7
|
+
'validationEvidence',
|
|
8
|
+
];
|
|
9
|
+
function isValidationFact(fact) {
|
|
10
|
+
if (fact.sourceRole !== undefined) {
|
|
11
|
+
return fact.sourceRole === 'validation' || fact.subject.kind === 'Evidence' ||
|
|
12
|
+
fact.object.kind === 'Evidence' || fact.predicate === 'verifiedBy';
|
|
13
|
+
}
|
|
14
|
+
const path = fact.provenance.path.toLowerCase();
|
|
15
|
+
return (fact.subject.kind === 'Evidence' ||
|
|
16
|
+
fact.object.kind === 'Evidence' ||
|
|
17
|
+
fact.predicate === 'verifiedBy' ||
|
|
18
|
+
/(?:^|\/)(?:test|tests|testing|validation|evidence)(?:\/|$)/.test(path) ||
|
|
19
|
+
/\.(?:spec|test)\.[cm]?[jt]sx?$/.test(path));
|
|
20
|
+
}
|
|
21
|
+
export function isDeclaredFact(fact) {
|
|
22
|
+
if (fact.sourceRole !== undefined && fact.sourceRole !== 'intent')
|
|
23
|
+
return false;
|
|
24
|
+
if (fact.authority)
|
|
25
|
+
return fact.authority === 'declared' && !isValidationFact(fact);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
export function contextPackLaneForFact(fact) {
|
|
29
|
+
if (fact.sourceRole === 'validation')
|
|
30
|
+
return 'validationEvidence';
|
|
31
|
+
if (fact.extractor.id === 'otlp-runtime-evidence')
|
|
32
|
+
return undefined;
|
|
33
|
+
const kinds = new Set([fact.subject.kind, fact.object.kind]);
|
|
34
|
+
if (isValidationFact(fact)) {
|
|
35
|
+
return 'validationEvidence';
|
|
36
|
+
}
|
|
37
|
+
if (kinds.has('Contract') ||
|
|
38
|
+
kinds.has('Invariant') ||
|
|
39
|
+
kinds.has('PersistenceModel') ||
|
|
40
|
+
['governedBy', 'definedBy', 'persistsTo', 'authorizedBy'].includes(fact.predicate)) {
|
|
41
|
+
return 'contractsAndInvariants';
|
|
42
|
+
}
|
|
43
|
+
if ((fact.sourceRole === undefined || fact.sourceRole === 'intent') &&
|
|
44
|
+
(isDeclaredFact(fact) || fact.sourceAuthority === 'declared') &&
|
|
45
|
+
(kinds.has('Document') ||
|
|
46
|
+
kinds.has('Capability') ||
|
|
47
|
+
kinds.has('Workflow') ||
|
|
48
|
+
['decisionAuthority', 'operationallyOwnedBy', 'references'].includes(fact.predicate))) {
|
|
49
|
+
return 'productIntent';
|
|
50
|
+
}
|
|
51
|
+
return 'implementationAndConsumers';
|
|
52
|
+
}
|
|
53
|
+
export function coverageDescription(coverage) {
|
|
54
|
+
return coverage.scope === 'returned-page' && coverage.countsAreNonExclusive
|
|
55
|
+
? 'Counts describe evidence on this returned page and may overlap; a code relationship can also describe a contract. They are not a percentage, a count of display groups, or proof that behavior is correct.'
|
|
56
|
+
: 'Coverage scope and overlap metadata are unavailable for this Context Pack; re-query saved evidence for an explicit report.';
|
|
57
|
+
}
|
|
58
|
+
/** Reporting only: never changes a fact's authority, identity, primary lane or stored bytes. */
|
|
59
|
+
export function isImplementationEvidence(fact) {
|
|
60
|
+
if (fact.sourceRole !== undefined || isValidationFact(fact) || fact.extractor.id === 'otlp-runtime-evidence' ||
|
|
61
|
+
fact.extractionReview === 'unreviewed' || contextPackEvidenceAuthority(fact) !== 'implemented')
|
|
62
|
+
return false;
|
|
63
|
+
const path = fact.provenance.path;
|
|
64
|
+
if (!path || /(?:^|\/)(?:test|tests|testing|validation|evidence|__tests__|__mocks__)(?:\/|$)/i.test(path.replaceAll('\\', '/')))
|
|
65
|
+
return false;
|
|
66
|
+
const file = repositoryFileNode(path);
|
|
67
|
+
if (file.kind !== 'Component')
|
|
68
|
+
return false;
|
|
69
|
+
const nodes = [fact.subject, fact.object];
|
|
70
|
+
// Explicit adapter authority also supports logical component/provider identities.
|
|
71
|
+
if (fact.authority === 'implemented')
|
|
72
|
+
return nodes.some(node => ['Component', 'Provider'].includes(node.kind));
|
|
73
|
+
// Legacy deterministic adapters omitted authority. Require their cited physical file,
|
|
74
|
+
// rather than treating every fact in the implementation display group as code evidence.
|
|
75
|
+
return nodes.some(node => node.kind === 'Component' && node.id === file.id);
|
|
76
|
+
}
|
|
77
|
+
export function coverageForFacts(facts) {
|
|
78
|
+
const counts = {
|
|
79
|
+
productIntent: 0, contractsAndInvariants: 0, implementationAndConsumers: 0, validationEvidence: 0,
|
|
80
|
+
};
|
|
81
|
+
for (const fact of facts) {
|
|
82
|
+
const lane = contextPackLaneForFact(fact);
|
|
83
|
+
if (lane && lane !== 'implementationAndConsumers')
|
|
84
|
+
counts[lane]++;
|
|
85
|
+
if (isImplementationEvidence(fact))
|
|
86
|
+
counts.implementationAndConsumers++;
|
|
87
|
+
}
|
|
88
|
+
return { scope: 'returned-page', countsAreNonExclusive: true, counts,
|
|
89
|
+
gaps: [
|
|
90
|
+
...contextPackLanes.filter(lane => counts[lane] === 0)
|
|
91
|
+
.map(lane => `No ${lane} evidence appears on this returned page.`),
|
|
92
|
+
...(facts.some(fact => fact.sourceAuthority === 'declared' && fact.extractionReview === 'unreviewed')
|
|
93
|
+
? ['Approved-source extraction remains unreviewed; verify cited intent before using it as a rule or gate.'] : []),
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DocumentSelectionRecord, GraphFact } from '@weftlet/core';
|
|
2
|
+
/** Plain text for evidence details; the rendering context must escape it. */
|
|
3
|
+
export declare function sourceDocumentDescription(fact: GraphFact): string | undefined;
|
|
4
|
+
/** Completeness is scoped to the configured canonical links, not all product knowledge. */
|
|
5
|
+
export declare function documentSelectionDescription(selection?: DocumentSelectionRecord): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Plain text for evidence details; the rendering context must escape it. */
|
|
2
|
+
export function sourceDocumentDescription(fact) {
|
|
3
|
+
const parts = [];
|
|
4
|
+
if (fact.sourceRole !== undefined)
|
|
5
|
+
parts.push(`source role ${fact.sourceRole}`);
|
|
6
|
+
if (fact.sourceOwnership) {
|
|
7
|
+
parts.push(`ownership ${fact.sourceOwnership.status}`, `owner documents ${fact.sourceOwnership.ownerDocuments.join(', ') || '(none)'}`);
|
|
8
|
+
}
|
|
9
|
+
return parts.length ? parts.join('; ') : undefined;
|
|
10
|
+
}
|
|
11
|
+
/** Completeness is scoped to the configured canonical links, not all product knowledge. */
|
|
12
|
+
export function documentSelectionDescription(selection) {
|
|
13
|
+
if (!selection)
|
|
14
|
+
return '';
|
|
15
|
+
return `Document traversal: ${selection.complete ? 'complete within configured links' : 'INCOMPLETE'}; ` +
|
|
16
|
+
`${selection.documentPaths.length} discovered documents; ${selection.semanticPaths.length} semantic candidates; ` +
|
|
17
|
+
`${selection.excluded.length} excluded from semantic extraction. Ownership and assertion approval are separate.`;
|
|
18
|
+
}
|
package/dist/graph/query.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ContextPack,
|
|
1
|
+
import type { ContextPack, ContextPackRenderer, ImpactQueryService, ImpactScanRequest, SnapshotStore } from "@weftlet/core";
|
|
2
|
+
export { contextPackLaneForFact } from './coverage.js';
|
|
2
3
|
export declare const DEFAULT_CONTEXT_PACK_FACTS = 60;
|
|
3
4
|
export declare const MAX_CONTEXT_PACK_FACTS = 200;
|
|
4
|
-
export declare function contextPackLaneForFact(fact: GraphFact): ContextPackLane | undefined;
|
|
5
5
|
export { contextPackEvidenceAuthority } from "./authority.js";
|
|
6
6
|
export declare class MarkdownContextPackRenderer implements ContextPackRenderer {
|
|
7
7
|
render(pack: Omit<ContextPack, 'markdown'>): string;
|
package/dist/graph/query.js
CHANGED
|
@@ -4,49 +4,11 @@ import { RdfEvidenceGraph } from "./rdf.js";
|
|
|
4
4
|
import { sha256, stableJson } from "../infrastructure/util.js";
|
|
5
5
|
import { diagnosticSummary, selectDiagnostics } from "./diagnostics.js";
|
|
6
6
|
import { factSearchText, IMPACT_RANKING_VERSION, rankImpactFacts } from './ranking.js';
|
|
7
|
+
import { contextPackLanes, contextPackLaneForFact, isDeclaredFact, coverageForFacts, coverageDescription } from './coverage.js';
|
|
8
|
+
import { documentSelectionDescription, sourceDocumentDescription } from './document-role-description.js';
|
|
9
|
+
export { contextPackLaneForFact } from './coverage.js';
|
|
7
10
|
export const DEFAULT_CONTEXT_PACK_FACTS = 60;
|
|
8
11
|
export const MAX_CONTEXT_PACK_FACTS = 200;
|
|
9
|
-
const contextPackLanes = [
|
|
10
|
-
'productIntent',
|
|
11
|
-
'contractsAndInvariants',
|
|
12
|
-
'implementationAndConsumers',
|
|
13
|
-
'validationEvidence',
|
|
14
|
-
];
|
|
15
|
-
function isValidationFact(fact) {
|
|
16
|
-
const path = fact.provenance.path.toLowerCase();
|
|
17
|
-
return (fact.subject.kind === 'Evidence' ||
|
|
18
|
-
fact.object.kind === 'Evidence' ||
|
|
19
|
-
fact.predicate === 'verifiedBy' ||
|
|
20
|
-
/(?:^|\/)(?:test|tests|testing|validation|evidence)(?:\/|$)/.test(path) ||
|
|
21
|
-
/\.(?:spec|test)\.[cm]?[jt]sx?$/.test(path));
|
|
22
|
-
}
|
|
23
|
-
function isDeclaredFact(fact) {
|
|
24
|
-
if (fact.authority)
|
|
25
|
-
return fact.authority === 'declared' && !isValidationFact(fact);
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
export function contextPackLaneForFact(fact) {
|
|
29
|
-
if (fact.extractor.id === 'otlp-runtime-evidence')
|
|
30
|
-
return undefined;
|
|
31
|
-
const kinds = new Set([fact.subject.kind, fact.object.kind]);
|
|
32
|
-
if (isValidationFact(fact)) {
|
|
33
|
-
return 'validationEvidence';
|
|
34
|
-
}
|
|
35
|
-
if (kinds.has('Contract') ||
|
|
36
|
-
kinds.has('Invariant') ||
|
|
37
|
-
kinds.has('PersistenceModel') ||
|
|
38
|
-
['governedBy', 'definedBy', 'persistsTo', 'authorizedBy'].includes(fact.predicate)) {
|
|
39
|
-
return 'contractsAndInvariants';
|
|
40
|
-
}
|
|
41
|
-
if ((isDeclaredFact(fact) || fact.sourceAuthority === 'declared') &&
|
|
42
|
-
(kinds.has('Document') ||
|
|
43
|
-
kinds.has('Capability') ||
|
|
44
|
-
kinds.has('Workflow') ||
|
|
45
|
-
['decisionAuthority', 'operationallyOwnedBy', 'references'].includes(fact.predicate))) {
|
|
46
|
-
return 'productIntent';
|
|
47
|
-
}
|
|
48
|
-
return 'implementationAndConsumers';
|
|
49
|
-
}
|
|
50
12
|
export { contextPackEvidenceAuthority } from "./authority.js";
|
|
51
13
|
function selectBalancedFacts(ranked, maxFacts) {
|
|
52
14
|
const queues = Object.fromEntries(contextPackLanes.map((lane) => [
|
|
@@ -63,11 +25,7 @@ function selectBalancedFacts(ranked, maxFacts) {
|
|
|
63
25
|
break;
|
|
64
26
|
}
|
|
65
27
|
}
|
|
66
|
-
|
|
67
|
-
lane,
|
|
68
|
-
facts.filter((fact) => contextPackLaneForFact(fact) === lane).length,
|
|
69
|
-
]));
|
|
70
|
-
return { facts, counts };
|
|
28
|
+
return facts;
|
|
71
29
|
}
|
|
72
30
|
const searchStopWords = new Set([
|
|
73
31
|
'about',
|
|
@@ -99,6 +57,12 @@ function boundedFactLimit(value) {
|
|
|
99
57
|
}
|
|
100
58
|
return Math.min(value, MAX_CONTEXT_PACK_FACTS);
|
|
101
59
|
}
|
|
60
|
+
function markdownFactDetails(fact) {
|
|
61
|
+
const document = sourceDocumentDescription(fact)?.replace(/[\\`*_{}\[\]()<>!|]/g, '\\$&').replace(/[\r\n]/g, ' ');
|
|
62
|
+
return `confidence ${fact.confidence}` +
|
|
63
|
+
(fact.sourceAuthority ? `; source ${fact.sourceAuthority}; extraction ${fact.extractionReview ?? 'unknown'}` : '') +
|
|
64
|
+
(document ? `; ${document}` : '');
|
|
65
|
+
}
|
|
102
66
|
export class MarkdownContextPackRenderer {
|
|
103
67
|
render(pack) {
|
|
104
68
|
const lines = [
|
|
@@ -106,6 +70,7 @@ export class MarkdownContextPackRenderer {
|
|
|
106
70
|
'',
|
|
107
71
|
`Snapshot: \`${pack.snapshot.snapshotId}\` (${pack.snapshot.commitSha})`,
|
|
108
72
|
`Configuration: ${pack.snapshot.configurationDigest ?? 'legacy/unknown'}; scope: ${pack.snapshot.scope?.join(', ') ?? 'legacy/unknown'}`,
|
|
73
|
+
...[documentSelectionDescription(pack.snapshot.documentSelection)].filter(Boolean),
|
|
109
74
|
...(pack.exploration ? [
|
|
110
75
|
`Ranking: ${pack.exploration.rankingVersion ?? 'legacy/unknown'}`,
|
|
111
76
|
`Relationships returned: ${pack.exploration.returned}/${pack.exploration.reachableFacts}; truncated: ${pack.exploration.truncated}; depth limit reached: ${pack.exploration.depthLimitReached}`,
|
|
@@ -130,17 +95,18 @@ export class MarkdownContextPackRenderer {
|
|
|
130
95
|
...pack.invariants.map((item) => `- ${item.status}: ${item.message}`),
|
|
131
96
|
'',
|
|
132
97
|
'## Coverage',
|
|
98
|
+
coverageDescription(pack.coverage),
|
|
133
99
|
...contextPackLanes.map((lane) => `- ${lane}: ${pack.coverage.counts[lane]} relationships`),
|
|
134
100
|
...(pack.coverage.gaps.length
|
|
135
101
|
? pack.coverage.gaps.map((gap) => `- GAP: ${gap}`)
|
|
136
|
-
: ['- No
|
|
102
|
+
: ['- No coverage gaps detected on this returned page.']),
|
|
137
103
|
...contextPackLanes.flatMap((lane) => [
|
|
138
104
|
'',
|
|
139
105
|
`## ${lane}`,
|
|
140
106
|
...pack.facts
|
|
141
107
|
.filter((fact) => contextPackLaneForFact(fact) === lane)
|
|
142
108
|
.map((fact) => `- [${contextPackEvidenceAuthority(fact)}] ${fact.subject.label} —${fact.predicate}→ ${fact.object.label} ` +
|
|
143
|
-
`(\`${fact.provenance.path}:${fact.provenance.startLine}\`,
|
|
109
|
+
`(\`${fact.provenance.path}:${fact.provenance.startLine}\`, ${markdownFactDetails(fact)})`),
|
|
144
110
|
]),
|
|
145
111
|
'',
|
|
146
112
|
'## Runtime evidence',
|
|
@@ -226,7 +192,7 @@ export class SnapshotImpactQueryService {
|
|
|
226
192
|
}
|
|
227
193
|
// Balance evidence lanes among similarly ranked facts, not across unrelated distance tiers.
|
|
228
194
|
const allBalanced = [...tiers.values()].flatMap((tier) => [
|
|
229
|
-
...selectBalancedFacts(tier, tier.length)
|
|
195
|
+
...selectBalancedFacts(tier, tier.length),
|
|
230
196
|
...tier.filter((fact) => contextPackLaneForFact(fact) === undefined),
|
|
231
197
|
]);
|
|
232
198
|
const { continuation: _continuation, snapshotId: _snapshotId, ...query } = request;
|
|
@@ -249,7 +215,7 @@ export class SnapshotImpactQueryService {
|
|
|
249
215
|
offset = token.offset;
|
|
250
216
|
}
|
|
251
217
|
const facts = allBalanced.slice(offset, offset + maxFacts);
|
|
252
|
-
const
|
|
218
|
+
const coverage = coverageForFacts(facts);
|
|
253
219
|
const nextOffset = offset + facts.length;
|
|
254
220
|
const continuation = nextOffset < allBalanced.length ? Buffer.from(JSON.stringify({
|
|
255
221
|
snapshot: snapshot.manifest.snapshotId, digest: snapshot.manifest.contentDigest,
|
|
@@ -294,13 +260,13 @@ export class SnapshotImpactQueryService {
|
|
|
294
260
|
for (const [kind, missing, reason] of [
|
|
295
261
|
[
|
|
296
262
|
'missingIntent',
|
|
297
|
-
|
|
298
|
-
'No
|
|
263
|
+
coverage.counts.productIntent === 0,
|
|
264
|
+
'No product-intent relationships appear on this returned page. Inspect continuation, scope and owner sources before concluding a requirement is missing.',
|
|
299
265
|
],
|
|
300
266
|
[
|
|
301
267
|
'implementationGaps',
|
|
302
|
-
|
|
303
|
-
'No implementation
|
|
268
|
+
coverage.counts.implementationAndConsumers === 0,
|
|
269
|
+
'No production implementation evidence appears on this returned page. Inspect continuation, scope and code before concluding behavior is missing.',
|
|
304
270
|
],
|
|
305
271
|
[
|
|
306
272
|
'runtimeGaps',
|
|
@@ -329,20 +295,14 @@ export class SnapshotImpactQueryService {
|
|
|
329
295
|
overlayDigest: snapshot.manifest.overlayDigest,
|
|
330
296
|
overlayCapture: snapshot.manifest.overlayCapture,
|
|
331
297
|
extractorVersions: snapshot.manifest.extractorVersions,
|
|
298
|
+
...(snapshot.manifest.documentSelection ? { documentSelection: snapshot.manifest.documentSelection } : {}),
|
|
332
299
|
},
|
|
333
300
|
capabilities,
|
|
334
301
|
facts,
|
|
335
302
|
invariants: snapshot.invariants.filter((item) => item.provenance.some((span) => suggestedFiles.includes(span.path))),
|
|
336
303
|
runtimeEvidence,
|
|
337
304
|
suggestedFiles,
|
|
338
|
-
coverage
|
|
339
|
-
counts: balanced.counts,
|
|
340
|
-
gaps: [...contextPackLanes
|
|
341
|
-
.filter((lane) => balanced.counts[lane] === 0)
|
|
342
|
-
.map((lane) => `No ${lane} evidence matched this request.`),
|
|
343
|
-
...(facts.some((fact) => fact.sourceAuthority === 'declared' && fact.extractionReview === 'unreviewed')
|
|
344
|
-
? ['Approved-source extraction remains unreviewed; verify cited intent before using it as a rule or gate.'] : [])],
|
|
345
|
-
},
|
|
305
|
+
coverage,
|
|
346
306
|
diagnostics: selectDiagnostics(snapshot, request, facts, focus, queryDiagnostics),
|
|
347
307
|
exploration: {
|
|
348
308
|
rankingVersion: IMPACT_RANKING_VERSION,
|
package/dist/graph/rdf.js
CHANGED
|
@@ -36,8 +36,19 @@ export class RdfEvidenceGraph {
|
|
|
36
36
|
snapshotId: fact.snapshotId, record: stableJson(fact),
|
|
37
37
|
...(fact.sourceAuthority ? { sourceAuthority: fact.sourceAuthority } : {}),
|
|
38
38
|
...(fact.extractionReview ? { extractionReview: fact.extractionReview } : {}),
|
|
39
|
+
...(fact.sourceRole !== undefined ? { sourceRole: fact.sourceRole } : {}),
|
|
40
|
+
...(fact.sourcePolicyDigest !== undefined ? { sourcePolicyDigest: fact.sourcePolicyDigest } : {}),
|
|
39
41
|
}))
|
|
40
42
|
this.dataset.addQuad(record, iri(CG + p), literal(value));
|
|
43
|
+
if (fact.sourceOwnership !== undefined) {
|
|
44
|
+
this.dataset.addQuad(record, iri(CG + 'ownershipStatus'), literal(fact.sourceOwnership.status));
|
|
45
|
+
for (const ownerDocument of fact.sourceOwnership.ownerDocuments) {
|
|
46
|
+
this.dataset.addQuad(record, iri(CG + 'ownerDocument'), literal(ownerDocument));
|
|
47
|
+
}
|
|
48
|
+
for (const mappingId of fact.sourceOwnership.mappingIds) {
|
|
49
|
+
this.dataset.addQuad(record, iri(CG + 'ownershipMapping'), literal(mappingId));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
41
52
|
for (const [p, value] of [['startLine', fact.provenance.startLine], ['endLine', fact.provenance.endLine]]) {
|
|
42
53
|
this.dataset.addQuad(record, iri(CG + p), literal(String(value), iri(XSD + 'integer')));
|
|
43
54
|
}
|
|
@@ -24,4 +24,30 @@ cg:FactShape a sh:NodeShape; sh:targetClass rdf:Statement;
|
|
|
24
24
|
sh:property [ sh:path cg:extractor; sh:minCount 1; sh:datatype xsd:string; sh:minLength 1 ].
|
|
25
25
|
cg:NodeShape a sh:NodeShape; sh:targetClass cg:Node;
|
|
26
26
|
sh:property [ sh:path cg:kind; sh:minCount 1; sh:maxCount 1 ].
|
|
27
|
+
|
|
28
|
+
# Optional source metadata targets only assertions that carry those predicates.
|
|
29
|
+
# Legacy facts do not acquire additional property or ownership consistency checks.
|
|
30
|
+
cg:SourceRoleShape a sh:NodeShape; sh:targetSubjectsOf cg:sourceRole;
|
|
31
|
+
sh:property [ sh:path cg:sourceRole; sh:maxCount 1; sh:datatype xsd:string;
|
|
32
|
+
sh:in ("intent" "plan" "validation" "reference" "unclassified") ].
|
|
33
|
+
cg:SourcePolicyShape a sh:NodeShape; sh:targetSubjectsOf cg:sourcePolicyDigest;
|
|
34
|
+
sh:property [ sh:path cg:sourcePolicyDigest; sh:maxCount 1; sh:datatype xsd:string; sh:minLength 1 ].
|
|
35
|
+
cg:SourceOwnershipShape a sh:NodeShape;
|
|
36
|
+
sh:targetSubjectsOf cg:ownershipStatus, cg:ownerDocument, cg:ownershipMapping;
|
|
37
|
+
sh:property [ sh:path cg:ownershipStatus; sh:minCount 1; sh:maxCount 1; sh:datatype xsd:string;
|
|
38
|
+
sh:in ("resolved" "missing" "ambiguous" "unavailable" "unapproved" "ineligible" "not-required") ];
|
|
39
|
+
sh:property [ sh:path cg:ownerDocument; sh:datatype xsd:string; sh:minLength 1 ];
|
|
40
|
+
sh:property [ sh:path cg:ownershipMapping; sh:datatype xsd:string; sh:minLength 1 ];
|
|
41
|
+
# Structural consistency does not prove approval, ownership correctness or source availability.
|
|
42
|
+
sh:or (
|
|
43
|
+
[ sh:property [ sh:path cg:ownershipStatus; sh:in ("resolved" "unavailable" "unapproved" "ineligible") ];
|
|
44
|
+
sh:property [ sh:path cg:ownerDocument; sh:minCount 1; sh:maxCount 1 ];
|
|
45
|
+
sh:property [ sh:path cg:ownershipMapping; sh:minCount 1 ] ]
|
|
46
|
+
[ sh:property [ sh:path cg:ownershipStatus; sh:hasValue "ambiguous" ];
|
|
47
|
+
sh:property [ sh:path cg:ownerDocument; sh:minCount 2 ];
|
|
48
|
+
sh:property [ sh:path cg:ownershipMapping; sh:minCount 1 ] ]
|
|
49
|
+
[ sh:property [ sh:path cg:ownershipStatus; sh:in ("missing" "not-required") ];
|
|
50
|
+
sh:property [ sh:path cg:ownerDocument; sh:maxCount 0 ];
|
|
51
|
+
sh:property [ sh:path cg:ownershipMapping; sh:maxCount 0 ] ]
|
|
52
|
+
).
|
|
27
53
|
`);
|
package/dist/index.d.ts
CHANGED
|
@@ -15,3 +15,8 @@ export * from './application/hydration-failure.js';
|
|
|
15
15
|
export * from './extraction/semantic-diagnostics.js';
|
|
16
16
|
export * from './graph/identity-preflight.js';
|
|
17
17
|
export * from './graph/validation-progress.js';
|
|
18
|
+
export * from './application/document-coverage.js';
|
|
19
|
+
export * from './extraction/document-traversal.js';
|
|
20
|
+
export * from './extraction/document-classification.js';
|
|
21
|
+
export * from './extraction/document-evidence.js';
|
|
22
|
+
export type { DocumentTraversalConfig } from './configuration/document-traversal.js';
|
package/dist/index.js
CHANGED
|
@@ -16,3 +16,7 @@ export * from './application/hydration-failure.js';
|
|
|
16
16
|
export * from './extraction/semantic-diagnostics.js';
|
|
17
17
|
export * from './graph/identity-preflight.js';
|
|
18
18
|
export * from './graph/validation-progress.js';
|
|
19
|
+
export * from './application/document-coverage.js';
|
|
20
|
+
export * from './extraction/document-traversal.js';
|
|
21
|
+
export * from './extraction/document-classification.js';
|
|
22
|
+
export * from './extraction/document-evidence.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Physical names only. Logical identities and evidence must retain the original value. */
|
|
2
|
+
export declare function physicalArtifactKey(identity: string): string;
|
|
3
|
+
/** Same-directory staging preserves atomic rename/link without repeating a long basename. */
|
|
4
|
+
export declare function temporaryArtifactPath(destination: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
/** Physical names only. Logical identities and evidence must retain the original value. */
|
|
4
|
+
export function physicalArtifactKey(identity) {
|
|
5
|
+
if (/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(identity) &&
|
|
6
|
+
!/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(identity))
|
|
7
|
+
return identity;
|
|
8
|
+
// '~' is excluded from literal logical storage keys, so a digest cannot alias one.
|
|
9
|
+
return `~${createHash('sha256').update(identity).digest('hex')}`;
|
|
10
|
+
}
|
|
11
|
+
/** Same-directory staging preserves atomic rename/link without repeating a long basename. */
|
|
12
|
+
export function temporaryArtifactPath(destination) {
|
|
13
|
+
return join(dirname(destination), `.${randomUUID()}.tmp`);
|
|
14
|
+
}
|
package/dist/interfaces/cli.js
CHANGED
|
@@ -19,6 +19,7 @@ import { planHydration } from '../application/hydration-plan.js';
|
|
|
19
19
|
import { adoptSemanticCache } from '../application/cache-adoption.js';
|
|
20
20
|
import { SemanticHydrationError } from '../application/hydration-failure.js';
|
|
21
21
|
import { GraphIdentityConflictError } from '../graph/identity-preflight.js';
|
|
22
|
+
import { runDocumentCoverage } from './document-coverage.js';
|
|
22
23
|
function valueAfter(args, name) {
|
|
23
24
|
const index = args.indexOf(name);
|
|
24
25
|
return index >= 0 ? args[index + 1] : undefined;
|
|
@@ -61,9 +62,23 @@ function formatHydrationPlan(plan) {
|
|
|
61
62
|
`Expected cache reuse: ${plan.estimates.reusableArtifacts}; extractions: ${plan.estimates.extractions}; unknown cache entries: ${plan.estimates.unknownArtifacts}`,
|
|
62
63
|
`Source/cache/budget checks: ${readiness}`,
|
|
63
64
|
];
|
|
65
|
+
if (plan.documentSelection) {
|
|
66
|
+
const selection = plan.documentSelection;
|
|
67
|
+
lines.push(`Document traversal: ${selection.complete ? 'complete' : 'blocked'}; identity ${selection.digest}; policy ${selection.policyDigest}`);
|
|
68
|
+
lines.push(`Discovered: ${selection.documentPaths.length}; semantic candidates: ${selection.semanticPaths.length}`);
|
|
69
|
+
for (const excluded of selection.excluded)
|
|
70
|
+
lines.push(`Excluded from model extraction: ${JSON.stringify(excluded.path)} (${excluded.reason}); retained traversal/evidence reporting.`);
|
|
71
|
+
}
|
|
72
|
+
if (plan.documentCoverage) {
|
|
73
|
+
const { limits, counters } = plan.documentCoverage.traversal;
|
|
74
|
+
lines.push(`Traversal reads: ${counters.readDocuments}/${limits.maxReadDocuments} documents; ${counters.readBytes}/${limits.maxReadBytes} bytes; ${limits.maxDocumentBytes} bytes maximum per document`);
|
|
75
|
+
}
|
|
64
76
|
for (const document of plan.documents) {
|
|
65
77
|
lines.push(`- ${JSON.stringify(document.path)} [${document.sourceId}]: ${document.bytes} bytes, ${document.lines} lines; ${document.role}; source ${document.sourceAuthority}, extraction ${document.extractionReview}; cache ${document.cache.status}; selected by ${document.selectedBy.map((selector) => JSON.stringify(selector)).join(', ')}`);
|
|
66
78
|
}
|
|
79
|
+
for (const document of plan.documentCoverage?.classification.documents ?? []) {
|
|
80
|
+
lines.push(`Classification ${JSON.stringify(document.path)}: ${document.sourceRole}; owner ${document.ownership.status}; ${document.ownership.ownerDocuments.map(path => JSON.stringify(path)).join(', ')}`);
|
|
81
|
+
}
|
|
67
82
|
for (const selection of plan.selections.filter((item) => item.status !== 'matched')) {
|
|
68
83
|
lines.push(`Selection ${JSON.stringify(selection.selector)}: ${selection.status}`);
|
|
69
84
|
}
|
|
@@ -83,9 +98,11 @@ function formatHydrationPlan(plan) {
|
|
|
83
98
|
async function main() {
|
|
84
99
|
const args = process.argv.slice(2);
|
|
85
100
|
if (args.includes('--help') || !args.length) {
|
|
86
|
-
process.stdout.write('weftlet init|config show|config validate|doctor|hydrate|cache adopt|overlay|impact scan|sparql|validate|govern|visualize|diagnostics show|invariant check|clean-compare|ontology compile\nUse --config <file>; queries accept --snapshot <id>. impact scan accepts --changed-file, --capability, --max-facts, --max-depth, --continuation.\nhydrate --plan [--json] [--ref <commit>] [--force-semantic] previews scope, cache and budgets without model calls or graph writes.
|
|
101
|
+
process.stdout.write('weftlet documents plan|init|config show|config validate|doctor|hydrate|cache adopt|overlay|impact scan|sparql|validate|govern|visualize|diagnostics show|invariant check|clean-compare|ontology compile\nUse --config <file>; queries accept --snapshot <id>. impact scan accepts --changed-file, --capability, --max-facts, --max-depth, --continuation.\ndocuments plan --entry <document> [--entry <document>] [--root <path>] [--document-policy <json-file>] [--ref <commit>] [--json] previews prospective committed link coverage; it does not change hydration inputs or estimate model/cache work. Source classification/ownership completeness is separate from traversal readiness. The preview policy is an operation input. Set documentTraversal in configuration to activate traversal hydration; hydrate --plan describes its execution inputs. Safety limits: --max-read-documents, --max-read-bytes, --max-document-bytes.\nhydrate --plan [--json] [--ref <commit>] [--force-semantic] previews scope, cache and budgets without model calls or graph writes. Traversal coverage and role ambiguity block new model work; direct-source selection retains its existing behavior.\nhydrate --json --quiet emits structured semantic failures on stderr with no progress lines; failure stdout stays empty. hydrate --plan maps opaque source IDs to local document paths.\nhydrate|overlay --validation-details explicitly includes local node/fact identities, extractor names and source citations in identity-conflict errors; default reports use opaque references. This flag writes no diagnostic file. Use --json --quiet for structured identity-conflict stderr and empty failure stdout. Validation timings report phase boundaries, not a live heartbeat or percentage.\ncache adopt --from-config <previous.json> [--config <current.json>] [--ref <commit>] [--dry-run] returns JSON and copies only validated compatible artifacts, without model calls or snapshot writes. --dry-run performs no cache writes. Agent configurations accept the same --owner-doc, --task and --capability selection as hydrate.\ninit [--yes] [--directory <project>] [--config <file>] [--repository-id <id>] [--code-root <path>] [--semantic-source <path>] [--evidence-root <path>] [--model <name>] [--no-gitignore]\nSource flags may be repeated. init never overwrites an existing config. See README.md for examples.\n');
|
|
87
102
|
return;
|
|
88
103
|
}
|
|
104
|
+
if (await runDocumentCoverage(args, defaultConfigPath))
|
|
105
|
+
return;
|
|
89
106
|
if (args[0] === 'init') {
|
|
90
107
|
await runInit(args.slice(1));
|
|
91
108
|
return;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DocumentCoverageOptions, type DocumentCoveragePlan } from '../application/document-coverage.js';
|
|
2
|
+
export declare function parseDocumentCoverageArgs(args: readonly string[]): {
|
|
3
|
+
configPath?: string;
|
|
4
|
+
policyPath?: string;
|
|
5
|
+
json: boolean;
|
|
6
|
+
options: DocumentCoverageOptions;
|
|
7
|
+
} | undefined;
|
|
8
|
+
export declare function formatDocumentCoverage(plan: DocumentCoveragePlan): string;
|
|
9
|
+
export declare function runDocumentCoverage(args: readonly string[], defaultConfig: () => string): Promise<boolean>;
|