@neurcode-ai/cli 0.9.64 → 0.9.65
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/dist/commands/brain.d.ts.map +1 -1
- package/dist/commands/brain.js +273 -0
- package/dist/commands/brain.js.map +1 -1
- package/dist/commands/pilot-report.d.ts +9 -0
- package/dist/commands/pilot-report.d.ts.map +1 -0
- package/dist/commands/pilot-report.js +176 -0
- package/dist/commands/pilot-report.js.map +1 -0
- package/dist/commands/remediate-governance.d.ts +54 -0
- package/dist/commands/remediate-governance.d.ts.map +1 -0
- package/dist/commands/remediate-governance.js +375 -0
- package/dist/commands/remediate-governance.js.map +1 -0
- package/dist/commands/remediate.d.ts.map +1 -1
- package/dist/commands/remediate.js.map +1 -1
- package/dist/commands/replay.d.ts.map +1 -1
- package/dist/commands/replay.js +30 -0
- package/dist/commands/replay.js.map +1 -1
- package/dist/commands/verify.d.ts.map +1 -1
- package/dist/commands/verify.js +307 -24
- package/dist/commands/verify.js.map +1 -1
- package/dist/daemon/server.d.ts.map +1 -1
- package/dist/daemon/server.js +1078 -0
- package/dist/daemon/server.js.map +1 -1
- package/dist/explainability/DeterminismClassifier.d.ts +34 -0
- package/dist/explainability/DeterminismClassifier.d.ts.map +1 -0
- package/dist/explainability/DeterminismClassifier.js +104 -0
- package/dist/explainability/DeterminismClassifier.js.map +1 -0
- package/dist/explainability/ViolationFormatter.d.ts +32 -0
- package/dist/explainability/ViolationFormatter.d.ts.map +1 -0
- package/dist/explainability/ViolationFormatter.js +252 -0
- package/dist/explainability/ViolationFormatter.js.map +1 -0
- package/dist/explainability/index.d.ts +15 -0
- package/dist/explainability/index.d.ts.map +1 -0
- package/dist/explainability/index.js +94 -0
- package/dist/explainability/index.js.map +1 -0
- package/dist/explainability/types.d.ts +37 -0
- package/dist/explainability/types.d.ts.map +1 -0
- package/dist/explainability/types.js +3 -0
- package/dist/explainability/types.js.map +1 -0
- package/dist/governance/canonical-pipeline.d.ts +38 -0
- package/dist/governance/canonical-pipeline.d.ts.map +1 -0
- package/dist/governance/canonical-pipeline.js +448 -0
- package/dist/governance/canonical-pipeline.js.map +1 -0
- package/dist/governance/structural-on-diff.d.ts +13 -0
- package/dist/governance/structural-on-diff.d.ts.map +1 -0
- package/dist/governance/structural-on-diff.js +35 -0
- package/dist/governance/structural-on-diff.js.map +1 -0
- package/dist/governance/structural-policy-merge.d.ts +14 -0
- package/dist/governance/structural-policy-merge.d.ts.map +1 -0
- package/dist/governance/structural-policy-merge.js +25 -0
- package/dist/governance/structural-policy-merge.js.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/review-compression/index.d.ts +50 -0
- package/dist/integrations/review-compression/index.d.ts.map +1 -0
- package/dist/integrations/review-compression/index.js +158 -0
- package/dist/integrations/review-compression/index.js.map +1 -0
- package/dist/intent-engine/domain-taxonomy.d.ts +42 -0
- package/dist/intent-engine/domain-taxonomy.d.ts.map +1 -0
- package/dist/intent-engine/domain-taxonomy.js +534 -0
- package/dist/intent-engine/domain-taxonomy.js.map +1 -0
- package/dist/intent-engine/index.d.ts +1 -0
- package/dist/intent-engine/index.d.ts.map +1 -1
- package/dist/intent-engine/index.js +6 -1
- package/dist/intent-engine/index.js.map +1 -1
- package/dist/intent-engine/parser.d.ts.map +1 -1
- package/dist/intent-engine/parser.js +47 -0
- package/dist/intent-engine/parser.js.map +1 -1
- package/dist/intent-engine/semantic-expander.d.ts +104 -0
- package/dist/intent-engine/semantic-expander.d.ts.map +1 -0
- package/dist/intent-engine/semantic-expander.js +480 -0
- package/dist/intent-engine/semantic-expander.js.map +1 -0
- package/dist/patch-engine/patterns.d.ts.map +1 -1
- package/dist/patch-engine/patterns.js +8 -4
- package/dist/patch-engine/patterns.js.map +1 -1
- package/dist/semantic/index.d.ts +14 -0
- package/dist/semantic/index.d.ts.map +1 -0
- package/dist/semantic/index.js +30 -0
- package/dist/semantic/index.js.map +1 -0
- package/dist/semantic/tfidf-engine.d.ts +81 -0
- package/dist/semantic/tfidf-engine.d.ts.map +1 -0
- package/dist/semantic/tfidf-engine.js +278 -0
- package/dist/semantic/tfidf-engine.js.map +1 -0
- package/dist/semantic/vector-store.d.ts +108 -0
- package/dist/semantic/vector-store.d.ts.map +1 -0
- package/dist/semantic/vector-store.js +321 -0
- package/dist/semantic/vector-store.js.map +1 -0
- package/dist/structural-rules/context-severity.d.ts +46 -0
- package/dist/structural-rules/context-severity.d.ts.map +1 -0
- package/dist/structural-rules/context-severity.js +115 -0
- package/dist/structural-rules/context-severity.js.map +1 -0
- package/dist/structural-rules/distributed/DS001-saga-rollback-absence.d.ts +11 -0
- package/dist/structural-rules/distributed/DS001-saga-rollback-absence.d.ts.map +1 -0
- package/dist/structural-rules/distributed/DS001-saga-rollback-absence.js +212 -0
- package/dist/structural-rules/distributed/DS001-saga-rollback-absence.js.map +1 -0
- package/dist/structural-rules/distributed/DS002-missing-correlation-id.d.ts +11 -0
- package/dist/structural-rules/distributed/DS002-missing-correlation-id.d.ts.map +1 -0
- package/dist/structural-rules/distributed/DS002-missing-correlation-id.js +213 -0
- package/dist/structural-rules/distributed/DS002-missing-correlation-id.js.map +1 -0
- package/dist/structural-rules/distributed/index.d.ts +3 -0
- package/dist/structural-rules/distributed/index.d.ts.map +1 -0
- package/dist/structural-rules/distributed/index.js +8 -0
- package/dist/structural-rules/distributed/index.js.map +1 -0
- package/dist/structural-rules/engine.d.ts +25 -0
- package/dist/structural-rules/engine.d.ts.map +1 -0
- package/dist/structural-rules/engine.js +90 -0
- package/dist/structural-rules/engine.js.map +1 -0
- package/dist/structural-rules/index.d.ts +41 -0
- package/dist/structural-rules/index.d.ts.map +1 -0
- package/dist/structural-rules/index.js +141 -0
- package/dist/structural-rules/index.js.map +1 -0
- package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.d.ts +11 -0
- package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.d.ts.map +1 -0
- package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.js +66 -0
- package/dist/structural-rules/python/PY001-asyncio-task-without-cancel.js.map +1 -0
- package/dist/structural-rules/python/PY002-unbounded-dict-singleton.d.ts +11 -0
- package/dist/structural-rules/python/PY002-unbounded-dict-singleton.d.ts.map +1 -0
- package/dist/structural-rules/python/PY002-unbounded-dict-singleton.js +135 -0
- package/dist/structural-rules/python/PY002-unbounded-dict-singleton.js.map +1 -0
- package/dist/structural-rules/python/PY003-broad-except-clause.d.ts +11 -0
- package/dist/structural-rules/python/PY003-broad-except-clause.d.ts.map +1 -0
- package/dist/structural-rules/python/PY003-broad-except-clause.js +86 -0
- package/dist/structural-rules/python/PY003-broad-except-clause.js.map +1 -0
- package/dist/structural-rules/python/PY004-swallowed-async-exception.d.ts +11 -0
- package/dist/structural-rules/python/PY004-swallowed-async-exception.d.ts.map +1 -0
- package/dist/structural-rules/python/PY004-swallowed-async-exception.js +167 -0
- package/dist/structural-rules/python/PY004-swallowed-async-exception.js.map +1 -0
- package/dist/structural-rules/python/PY005-fastapi-without-pydantic.d.ts +11 -0
- package/dist/structural-rules/python/PY005-fastapi-without-pydantic.d.ts.map +1 -0
- package/dist/structural-rules/python/PY005-fastapi-without-pydantic.js +154 -0
- package/dist/structural-rules/python/PY005-fastapi-without-pydantic.js.map +1 -0
- package/dist/structural-rules/python/PY006-blocking-io-in-async.d.ts +11 -0
- package/dist/structural-rules/python/PY006-blocking-io-in-async.d.ts.map +1 -0
- package/dist/structural-rules/python/PY006-blocking-io-in-async.js +130 -0
- package/dist/structural-rules/python/PY006-blocking-io-in-async.js.map +1 -0
- package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.d.ts +11 -0
- package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.d.ts.map +1 -0
- package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.js +93 -0
- package/dist/structural-rules/python/PY007-sqlalchemy-session-leak.js.map +1 -0
- package/dist/structural-rules/python/PY008-celery-task-without-retry.d.ts +11 -0
- package/dist/structural-rules/python/PY008-celery-task-without-retry.d.ts.map +1 -0
- package/dist/structural-rules/python/PY008-celery-task-without-retry.js +154 -0
- package/dist/structural-rules/python/PY008-celery-task-without-retry.js.map +1 -0
- package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.d.ts +11 -0
- package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.d.ts.map +1 -0
- package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.js +133 -0
- package/dist/structural-rules/python/PY009-unsafe-pickle-deserialization.js.map +1 -0
- package/dist/structural-rules/python/PY010-leaked-aiohttp-session.d.ts +11 -0
- package/dist/structural-rules/python/PY010-leaked-aiohttp-session.d.ts.map +1 -0
- package/dist/structural-rules/python/PY010-leaked-aiohttp-session.js +80 -0
- package/dist/structural-rules/python/PY010-leaked-aiohttp-session.js.map +1 -0
- package/dist/structural-rules/rules/SR001-swallowed-async-rejection.d.ts +11 -0
- package/dist/structural-rules/rules/SR001-swallowed-async-rejection.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR001-swallowed-async-rejection.js +145 -0
- package/dist/structural-rules/rules/SR001-swallowed-async-rejection.js.map +1 -0
- package/dist/structural-rules/rules/SR002-unbounded-collection.d.ts +11 -0
- package/dist/structural-rules/rules/SR002-unbounded-collection.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR002-unbounded-collection.js +196 -0
- package/dist/structural-rules/rules/SR002-unbounded-collection.js.map +1 -0
- package/dist/structural-rules/rules/SR003-timer-without-cleanup.d.ts +11 -0
- package/dist/structural-rules/rules/SR003-timer-without-cleanup.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR003-timer-without-cleanup.js +148 -0
- package/dist/structural-rules/rules/SR003-timer-without-cleanup.js.map +1 -0
- package/dist/structural-rules/rules/SR004-request-boundary-no-validation.d.ts +11 -0
- package/dist/structural-rules/rules/SR004-request-boundary-no-validation.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR004-request-boundary-no-validation.js +162 -0
- package/dist/structural-rules/rules/SR004-request-boundary-no-validation.js.map +1 -0
- package/dist/structural-rules/rules/SR005-halfopen-probe-gate.d.ts +11 -0
- package/dist/structural-rules/rules/SR005-halfopen-probe-gate.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR005-halfopen-probe-gate.js +150 -0
- package/dist/structural-rules/rules/SR005-halfopen-probe-gate.js.map +1 -0
- package/dist/structural-rules/rules/SR006-fanout-error-sanitization.d.ts +11 -0
- package/dist/structural-rules/rules/SR006-fanout-error-sanitization.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR006-fanout-error-sanitization.js +161 -0
- package/dist/structural-rules/rules/SR006-fanout-error-sanitization.js.map +1 -0
- package/dist/structural-rules/rules/SR007-cross-request-error.d.ts +11 -0
- package/dist/structural-rules/rules/SR007-cross-request-error.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR007-cross-request-error.js +175 -0
- package/dist/structural-rules/rules/SR007-cross-request-error.js.map +1 -0
- package/dist/structural-rules/rules/SR008-background-task-orphan.d.ts +11 -0
- package/dist/structural-rules/rules/SR008-background-task-orphan.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR008-background-task-orphan.js +176 -0
- package/dist/structural-rules/rules/SR008-background-task-orphan.js.map +1 -0
- package/dist/structural-rules/rules/SR009-missing-retry-backoff.d.ts +11 -0
- package/dist/structural-rules/rules/SR009-missing-retry-backoff.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR009-missing-retry-backoff.js +168 -0
- package/dist/structural-rules/rules/SR009-missing-retry-backoff.js.map +1 -0
- package/dist/structural-rules/rules/SR010-retry-storm.d.ts +11 -0
- package/dist/structural-rules/rules/SR010-retry-storm.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR010-retry-storm.js +181 -0
- package/dist/structural-rules/rules/SR010-retry-storm.js.map +1 -0
- package/dist/structural-rules/rules/SR011-event-listener-leak.d.ts +11 -0
- package/dist/structural-rules/rules/SR011-event-listener-leak.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR011-event-listener-leak.js +208 -0
- package/dist/structural-rules/rules/SR011-event-listener-leak.js.map +1 -0
- package/dist/structural-rules/rules/SR012-promise-race-leak.d.ts +11 -0
- package/dist/structural-rules/rules/SR012-promise-race-leak.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR012-promise-race-leak.js +191 -0
- package/dist/structural-rules/rules/SR012-promise-race-leak.js.map +1 -0
- package/dist/structural-rules/rules/SR013-missing-idempotency-key.d.ts +11 -0
- package/dist/structural-rules/rules/SR013-missing-idempotency-key.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR013-missing-idempotency-key.js +219 -0
- package/dist/structural-rules/rules/SR013-missing-idempotency-key.js.map +1 -0
- package/dist/structural-rules/rules/SR014-mutable-closure-async.d.ts +11 -0
- package/dist/structural-rules/rules/SR014-mutable-closure-async.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR014-mutable-closure-async.js +208 -0
- package/dist/structural-rules/rules/SR014-mutable-closure-async.js.map +1 -0
- package/dist/structural-rules/rules/SR015-dangling-abort-controller.d.ts +11 -0
- package/dist/structural-rules/rules/SR015-dangling-abort-controller.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR015-dangling-abort-controller.js +190 -0
- package/dist/structural-rules/rules/SR015-dangling-abort-controller.js.map +1 -0
- package/dist/structural-rules/rules/SR016-unsafe-json-parse.d.ts +11 -0
- package/dist/structural-rules/rules/SR016-unsafe-json-parse.d.ts.map +1 -0
- package/dist/structural-rules/rules/SR016-unsafe-json-parse.js +187 -0
- package/dist/structural-rules/rules/SR016-unsafe-json-parse.js.map +1 -0
- package/dist/structural-rules/suppressions.d.ts +43 -0
- package/dist/structural-rules/suppressions.d.ts.map +1 -0
- package/dist/structural-rules/suppressions.js +115 -0
- package/dist/structural-rules/suppressions.js.map +1 -0
- package/dist/structural-rules/types.d.ts +43 -0
- package/dist/structural-rules/types.d.ts.map +1 -0
- package/dist/structural-rules/types.js +3 -0
- package/dist/structural-rules/types.js.map +1 -0
- package/dist/utils/brain-cache.d.ts +100 -0
- package/dist/utils/brain-cache.d.ts.map +1 -0
- package/dist/utils/brain-cache.js +346 -0
- package/dist/utils/brain-cache.js.map +1 -0
- package/dist/utils/governance-provenance.d.ts +95 -0
- package/dist/utils/governance-provenance.d.ts.map +1 -0
- package/dist/utils/governance-provenance.js +187 -0
- package/dist/utils/governance-provenance.js.map +1 -0
- package/dist/utils/pilot-metrics.d.ts +46 -0
- package/dist/utils/pilot-metrics.d.ts.map +1 -0
- package/dist/utils/pilot-metrics.js +240 -0
- package/dist/utils/pilot-metrics.js.map +1 -0
- package/dist/utils/replay-runtime.d.ts +34 -0
- package/dist/utils/replay-runtime.d.ts.map +1 -1
- package/dist/utils/replay-runtime.js +207 -0
- package/dist/utils/replay-runtime.js.map +1 -1
- package/dist/workspace/cross-repo-graph.d.ts +111 -0
- package/dist/workspace/cross-repo-graph.d.ts.map +1 -0
- package/dist/workspace/cross-repo-graph.js +450 -0
- package/dist/workspace/cross-repo-graph.js.map +1 -0
- package/dist/workspace/federated-context.d.ts +144 -0
- package/dist/workspace/federated-context.d.ts.map +1 -0
- package/dist/workspace/federated-context.js +347 -0
- package/dist/workspace/federated-context.js.map +1 -0
- package/dist/workspace/index.d.ts +38 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +48 -0
- package/dist/workspace/index.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent deterministic brain cache infrastructure.
|
|
3
|
+
*
|
|
4
|
+
* Design principles:
|
|
5
|
+
* - Content-hash invalidation: files are only re-indexed when content changes
|
|
6
|
+
* - Replay-safe: cache manifest is deterministic and serializable
|
|
7
|
+
* - CI-restorable: manifest + index can be archived and restored across runs
|
|
8
|
+
* - Governance-neutral: cache accelerates indexing, never affects correctness
|
|
9
|
+
* - Append-only manifest entries (no silent deletion of records)
|
|
10
|
+
*
|
|
11
|
+
* Cache location: <projectRoot>/.neurcode/brain/cache/
|
|
12
|
+
* Manifest: <projectRoot>/.neurcode/brain/cache/manifest.json
|
|
13
|
+
* Semantic index: <projectRoot>/.neurcode/brain/cache/semantic-index.json
|
|
14
|
+
*/
|
|
15
|
+
export declare const BRAIN_CACHE_SCHEMA_VERSION: "2026-05-11.1";
|
|
16
|
+
export interface BrainCacheFileEntry {
|
|
17
|
+
/** Repo-relative file path. */
|
|
18
|
+
filePath: string;
|
|
19
|
+
/** SHA-256 content hash (hex). */
|
|
20
|
+
contentHash: string;
|
|
21
|
+
/** Last-modified timestamp (Unix ms). */
|
|
22
|
+
lastModifiedMs: number;
|
|
23
|
+
/** File size in bytes. */
|
|
24
|
+
sizeBytes: number;
|
|
25
|
+
/** True when this file was included in the semantic index. */
|
|
26
|
+
indexed: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface BrainCacheManifest {
|
|
29
|
+
schemaVersion: typeof BRAIN_CACHE_SCHEMA_VERSION;
|
|
30
|
+
/** Repository root path at build time. */
|
|
31
|
+
repoRoot: string;
|
|
32
|
+
/** ISO 8601 build timestamp. */
|
|
33
|
+
builtAt: string;
|
|
34
|
+
/** SHA-256 of the manifest itself (for integrity checks). Populated after write. */
|
|
35
|
+
manifestHash: string;
|
|
36
|
+
/** Total files tracked. */
|
|
37
|
+
totalFiles: number;
|
|
38
|
+
/** Total files indexed in semantic index. */
|
|
39
|
+
indexedFiles: number;
|
|
40
|
+
/** Combined content hash of all tracked files (for CI cache key generation). */
|
|
41
|
+
contentFingerprint: string;
|
|
42
|
+
/** Per-file entries. */
|
|
43
|
+
files: BrainCacheFileEntry[];
|
|
44
|
+
}
|
|
45
|
+
export interface BrainCacheStatus {
|
|
46
|
+
exists: boolean;
|
|
47
|
+
manifest: BrainCacheManifest | null;
|
|
48
|
+
staleFiles: string[];
|
|
49
|
+
missingFiles: string[];
|
|
50
|
+
newFiles: string[];
|
|
51
|
+
totalFiles: number;
|
|
52
|
+
freshFiles: number;
|
|
53
|
+
stalePercent: number;
|
|
54
|
+
needsRebuild: boolean;
|
|
55
|
+
cacheDir: string;
|
|
56
|
+
manifestPath: string;
|
|
57
|
+
semanticIndexPath: string;
|
|
58
|
+
sizeBytes: number;
|
|
59
|
+
}
|
|
60
|
+
export declare function getBrainCacheDir(projectRoot: string): string;
|
|
61
|
+
export declare function getBrainCacheManifestPath(projectRoot: string): string;
|
|
62
|
+
export declare function getBrainCacheSemanticIndexPath(projectRoot: string): string;
|
|
63
|
+
export declare function hashFileContent(content: string): string;
|
|
64
|
+
export declare function loadBrainCacheManifest(projectRoot: string): BrainCacheManifest | null;
|
|
65
|
+
export declare function saveBrainCacheManifest(projectRoot: string, manifest: Omit<BrainCacheManifest, 'manifestHash'>): BrainCacheManifest;
|
|
66
|
+
export interface BrainCacheBuildOptions {
|
|
67
|
+
projectRoot: string;
|
|
68
|
+
maxFiles?: number;
|
|
69
|
+
/** If true, force full rebuild ignoring existing manifest. */
|
|
70
|
+
force?: boolean;
|
|
71
|
+
onProgress?: (indexed: number, total: number) => void;
|
|
72
|
+
}
|
|
73
|
+
export interface BrainCacheBuildResult {
|
|
74
|
+
manifest: BrainCacheManifest;
|
|
75
|
+
builtFiles: number;
|
|
76
|
+
skippedFiles: number;
|
|
77
|
+
/** Files re-indexed because content changed. */
|
|
78
|
+
updatedFiles: number;
|
|
79
|
+
elapsedMs: number;
|
|
80
|
+
}
|
|
81
|
+
export declare function buildBrainCache(options: BrainCacheBuildOptions): BrainCacheBuildResult;
|
|
82
|
+
export declare function getBrainCacheStatus(projectRoot: string): BrainCacheStatus;
|
|
83
|
+
export interface BrainCacheRestoreOptions {
|
|
84
|
+
projectRoot: string;
|
|
85
|
+
/** Path to the CI cache artifact (JSON). */
|
|
86
|
+
artifactPath: string;
|
|
87
|
+
}
|
|
88
|
+
export interface BrainCacheRestoreResult {
|
|
89
|
+
success: boolean;
|
|
90
|
+
manifest: BrainCacheManifest | null;
|
|
91
|
+
message: string;
|
|
92
|
+
staleAfterRestore: number;
|
|
93
|
+
}
|
|
94
|
+
export declare function restoreBrainCache(options: BrainCacheRestoreOptions): BrainCacheRestoreResult;
|
|
95
|
+
/**
|
|
96
|
+
* Export the current cache manifest as a CI artifact.
|
|
97
|
+
* CI pipelines can cache this file and restore it on subsequent runs.
|
|
98
|
+
*/
|
|
99
|
+
export declare function exportBrainCacheArtifact(projectRoot: string, outputPath: string): boolean;
|
|
100
|
+
//# sourceMappingURL=brain-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brain-cache.d.ts","sourceRoot":"","sources":["../../src/utils/brain-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH,eAAO,MAAM,0BAA0B,EAAG,cAAuB,CAAC;AAIlE,MAAM,WAAW,mBAAmB;IAClC,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,OAAO,0BAA0B,CAAC;IACjD,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,YAAY,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,kBAAkB,EAAE,MAAM,CAAC;IAC3B,wBAAwB;IACxB,KAAK,EAAE,mBAAmB,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YA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gB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,qBAAqB,CAuEtF;AAID,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,gBAAgB,CA8EzE;AAID,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,uBAAuB,CAqD5F;AAID;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CASzF"}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Persistent deterministic brain cache infrastructure.
|
|
4
|
+
*
|
|
5
|
+
* Design principles:
|
|
6
|
+
* - Content-hash invalidation: files are only re-indexed when content changes
|
|
7
|
+
* - Replay-safe: cache manifest is deterministic and serializable
|
|
8
|
+
* - CI-restorable: manifest + index can be archived and restored across runs
|
|
9
|
+
* - Governance-neutral: cache accelerates indexing, never affects correctness
|
|
10
|
+
* - Append-only manifest entries (no silent deletion of records)
|
|
11
|
+
*
|
|
12
|
+
* Cache location: <projectRoot>/.neurcode/brain/cache/
|
|
13
|
+
* Manifest: <projectRoot>/.neurcode/brain/cache/manifest.json
|
|
14
|
+
* Semantic index: <projectRoot>/.neurcode/brain/cache/semantic-index.json
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.BRAIN_CACHE_SCHEMA_VERSION = void 0;
|
|
18
|
+
exports.getBrainCacheDir = getBrainCacheDir;
|
|
19
|
+
exports.getBrainCacheManifestPath = getBrainCacheManifestPath;
|
|
20
|
+
exports.getBrainCacheSemanticIndexPath = getBrainCacheSemanticIndexPath;
|
|
21
|
+
exports.hashFileContent = hashFileContent;
|
|
22
|
+
exports.loadBrainCacheManifest = loadBrainCacheManifest;
|
|
23
|
+
exports.saveBrainCacheManifest = saveBrainCacheManifest;
|
|
24
|
+
exports.buildBrainCache = buildBrainCache;
|
|
25
|
+
exports.getBrainCacheStatus = getBrainCacheStatus;
|
|
26
|
+
exports.restoreBrainCache = restoreBrainCache;
|
|
27
|
+
exports.exportBrainCacheArtifact = exportBrainCacheArtifact;
|
|
28
|
+
const crypto_1 = require("crypto");
|
|
29
|
+
const fs_1 = require("fs");
|
|
30
|
+
const path_1 = require("path");
|
|
31
|
+
// ── Schema version ─────────────────────────────────────────────────────────────
|
|
32
|
+
exports.BRAIN_CACHE_SCHEMA_VERSION = '2026-05-11.1';
|
|
33
|
+
// ── Cache paths ────────────────────────────────────────────────────────────────
|
|
34
|
+
function getBrainCacheDir(projectRoot) {
|
|
35
|
+
return (0, path_1.join)(projectRoot, '.neurcode', 'brain', 'cache');
|
|
36
|
+
}
|
|
37
|
+
function getBrainCacheManifestPath(projectRoot) {
|
|
38
|
+
return (0, path_1.join)(getBrainCacheDir(projectRoot), 'manifest.json');
|
|
39
|
+
}
|
|
40
|
+
function getBrainCacheSemanticIndexPath(projectRoot) {
|
|
41
|
+
return (0, path_1.join)(getBrainCacheDir(projectRoot), 'semantic-index.json');
|
|
42
|
+
}
|
|
43
|
+
// ── Content hashing ────────────────────────────────────────────────────────────
|
|
44
|
+
function hashFileContent(content) {
|
|
45
|
+
return (0, crypto_1.createHash)('sha256').update(content, 'utf-8').digest('hex');
|
|
46
|
+
}
|
|
47
|
+
function hashFileAtPath(filePath) {
|
|
48
|
+
try {
|
|
49
|
+
const content = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
50
|
+
return hashFileContent(content);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function contentFingerprint(files) {
|
|
57
|
+
const sorted = [...files]
|
|
58
|
+
.sort((a, b) => a.filePath.localeCompare(b.filePath))
|
|
59
|
+
.map((f) => `${f.filePath}:${f.contentHash}`)
|
|
60
|
+
.join('\n');
|
|
61
|
+
return (0, crypto_1.createHash)('sha256').update(sorted, 'utf-8').digest('hex').slice(0, 32);
|
|
62
|
+
}
|
|
63
|
+
// ── Manifest I/O ───────────────────────────────────────────────────────────────
|
|
64
|
+
function loadBrainCacheManifest(projectRoot) {
|
|
65
|
+
const path = getBrainCacheManifestPath(projectRoot);
|
|
66
|
+
if (!(0, fs_1.existsSync)(path))
|
|
67
|
+
return null;
|
|
68
|
+
try {
|
|
69
|
+
const raw = (0, fs_1.readFileSync)(path, 'utf-8');
|
|
70
|
+
const parsed = JSON.parse(raw);
|
|
71
|
+
if (parsed.schemaVersion !== exports.BRAIN_CACHE_SCHEMA_VERSION) {
|
|
72
|
+
return null; // incompatible schema, treat as cache miss
|
|
73
|
+
}
|
|
74
|
+
return parsed;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function saveBrainCacheManifest(projectRoot, manifest) {
|
|
81
|
+
const cacheDir = getBrainCacheDir(projectRoot);
|
|
82
|
+
(0, fs_1.mkdirSync)(cacheDir, { recursive: true });
|
|
83
|
+
const withoutHash = { ...manifest, manifestHash: '' };
|
|
84
|
+
const serialized = JSON.stringify(withoutHash, null, 2);
|
|
85
|
+
const hash = (0, crypto_1.createHash)('sha256').update(serialized, 'utf-8').digest('hex');
|
|
86
|
+
const final = { ...withoutHash, manifestHash: hash };
|
|
87
|
+
(0, fs_1.writeFileSync)(getBrainCacheManifestPath(projectRoot), JSON.stringify(final, null, 2), 'utf-8');
|
|
88
|
+
return final;
|
|
89
|
+
}
|
|
90
|
+
// ── Scan project files for indexable content ───────────────────────────────────
|
|
91
|
+
const INDEXABLE_EXTENSIONS = new Set([
|
|
92
|
+
'.ts', '.tsx', '.js', '.jsx', '.mts', '.mjs',
|
|
93
|
+
'.py', '.go', '.rs', '.java', '.rb', '.swift',
|
|
94
|
+
]);
|
|
95
|
+
const EXCLUDED_DIRS = new Set([
|
|
96
|
+
'node_modules', '.git', '.next', 'dist', 'build', 'out',
|
|
97
|
+
'.neurcode', '__pycache__', '.venv', 'venv', '.cache',
|
|
98
|
+
]);
|
|
99
|
+
function scanIndexableFiles(projectRoot, maxFiles = 5000) {
|
|
100
|
+
const results = [];
|
|
101
|
+
function traverse(dir, depth = 0) {
|
|
102
|
+
if (depth > 10)
|
|
103
|
+
return;
|
|
104
|
+
let entries = [];
|
|
105
|
+
try {
|
|
106
|
+
entries = (0, fs_1.readdirSync)(dir);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for (const entry of entries) {
|
|
112
|
+
if (EXCLUDED_DIRS.has(entry))
|
|
113
|
+
continue;
|
|
114
|
+
const fullPath = (0, path_1.join)(dir, entry);
|
|
115
|
+
let stat;
|
|
116
|
+
try {
|
|
117
|
+
stat = (0, fs_1.statSync)(fullPath);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (stat.isDirectory()) {
|
|
123
|
+
traverse(fullPath, depth + 1);
|
|
124
|
+
}
|
|
125
|
+
else if (stat.isFile()) {
|
|
126
|
+
const dotIdx = entry.lastIndexOf('.');
|
|
127
|
+
if (dotIdx > 0 && INDEXABLE_EXTENSIONS.has(entry.slice(dotIdx))) {
|
|
128
|
+
results.push(fullPath);
|
|
129
|
+
if (results.length >= maxFiles)
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
traverse(projectRoot);
|
|
136
|
+
return results;
|
|
137
|
+
}
|
|
138
|
+
function buildBrainCache(options) {
|
|
139
|
+
const { projectRoot, maxFiles = 5000, force = false } = options;
|
|
140
|
+
const start = Date.now();
|
|
141
|
+
const existing = force ? null : loadBrainCacheManifest(projectRoot);
|
|
142
|
+
const existingMap = new Map((existing?.files ?? []).map((f) => [f.filePath, f]));
|
|
143
|
+
const allFiles = scanIndexableFiles(projectRoot, maxFiles);
|
|
144
|
+
const entries = [];
|
|
145
|
+
let builtFiles = 0;
|
|
146
|
+
let skippedFiles = 0;
|
|
147
|
+
let updatedFiles = 0;
|
|
148
|
+
for (let i = 0; i < allFiles.length; i++) {
|
|
149
|
+
const fullPath = allFiles[i];
|
|
150
|
+
const relPath = (0, path_1.relative)(projectRoot, fullPath).split(path_1.sep).join('/');
|
|
151
|
+
let stat;
|
|
152
|
+
try {
|
|
153
|
+
stat = (0, fs_1.statSync)(fullPath);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const existing = existingMap.get(relPath);
|
|
159
|
+
const lastModifiedMs = stat.mtimeMs;
|
|
160
|
+
// Fast path: mtime unchanged → skip rehash
|
|
161
|
+
if (existing && Math.abs(existing.lastModifiedMs - lastModifiedMs) < 1000) {
|
|
162
|
+
entries.push(existing);
|
|
163
|
+
skippedFiles++;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const contentHash = hashFileAtPath(fullPath);
|
|
167
|
+
if (!contentHash)
|
|
168
|
+
continue;
|
|
169
|
+
const isUpdated = existing !== undefined && existing.contentHash !== contentHash;
|
|
170
|
+
if (isUpdated)
|
|
171
|
+
updatedFiles++;
|
|
172
|
+
entries.push({
|
|
173
|
+
filePath: relPath,
|
|
174
|
+
contentHash,
|
|
175
|
+
lastModifiedMs,
|
|
176
|
+
sizeBytes: stat.size,
|
|
177
|
+
indexed: true,
|
|
178
|
+
});
|
|
179
|
+
builtFiles++;
|
|
180
|
+
}
|
|
181
|
+
if (options.onProgress && (i % 100 === 0 || i === allFiles.length - 1)) {
|
|
182
|
+
options.onProgress(i + 1, allFiles.length);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const manifest = saveBrainCacheManifest(projectRoot, {
|
|
186
|
+
schemaVersion: exports.BRAIN_CACHE_SCHEMA_VERSION,
|
|
187
|
+
repoRoot: projectRoot,
|
|
188
|
+
builtAt: new Date().toISOString(),
|
|
189
|
+
totalFiles: entries.length,
|
|
190
|
+
indexedFiles: entries.filter((e) => e.indexed).length,
|
|
191
|
+
contentFingerprint: contentFingerprint(entries),
|
|
192
|
+
files: entries,
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
manifest,
|
|
196
|
+
builtFiles,
|
|
197
|
+
skippedFiles,
|
|
198
|
+
updatedFiles,
|
|
199
|
+
elapsedMs: Date.now() - start,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
// ── Cache status ───────────────────────────────────────────────────────────────
|
|
203
|
+
function getBrainCacheStatus(projectRoot) {
|
|
204
|
+
const cacheDir = getBrainCacheDir(projectRoot);
|
|
205
|
+
const manifestPath = getBrainCacheManifestPath(projectRoot);
|
|
206
|
+
const semanticIndexPath = getBrainCacheSemanticIndexPath(projectRoot);
|
|
207
|
+
const manifest = loadBrainCacheManifest(projectRoot);
|
|
208
|
+
if (!manifest) {
|
|
209
|
+
return {
|
|
210
|
+
exists: false,
|
|
211
|
+
manifest: null,
|
|
212
|
+
staleFiles: [],
|
|
213
|
+
missingFiles: [],
|
|
214
|
+
newFiles: [],
|
|
215
|
+
totalFiles: 0,
|
|
216
|
+
freshFiles: 0,
|
|
217
|
+
stalePercent: 0,
|
|
218
|
+
needsRebuild: true,
|
|
219
|
+
cacheDir,
|
|
220
|
+
manifestPath,
|
|
221
|
+
semanticIndexPath,
|
|
222
|
+
sizeBytes: 0,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
// Check staleness: compare manifest hashes against current files
|
|
226
|
+
const staleFiles = [];
|
|
227
|
+
const missingFiles = [];
|
|
228
|
+
for (const entry of manifest.files) {
|
|
229
|
+
const fullPath = (0, path_1.join)(projectRoot, entry.filePath);
|
|
230
|
+
if (!(0, fs_1.existsSync)(fullPath)) {
|
|
231
|
+
missingFiles.push(entry.filePath);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const currentHash = hashFileAtPath(fullPath);
|
|
235
|
+
if (currentHash !== entry.contentHash) {
|
|
236
|
+
staleFiles.push(entry.filePath);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// Detect new files not in manifest
|
|
240
|
+
const manifestFileSet = new Set(manifest.files.map((f) => f.filePath));
|
|
241
|
+
const currentFiles = scanIndexableFiles(projectRoot, 10_000);
|
|
242
|
+
const newFiles = [];
|
|
243
|
+
for (const f of currentFiles) {
|
|
244
|
+
const rel = (0, path_1.relative)(projectRoot, f).split(path_1.sep).join('/');
|
|
245
|
+
if (!manifestFileSet.has(rel))
|
|
246
|
+
newFiles.push(rel);
|
|
247
|
+
}
|
|
248
|
+
const totalFiles = manifest.totalFiles;
|
|
249
|
+
const changedFiles = staleFiles.length + missingFiles.length;
|
|
250
|
+
const freshFiles = totalFiles - changedFiles;
|
|
251
|
+
const stalePercent = totalFiles > 0 ? Math.round((changedFiles / totalFiles) * 100) : 0;
|
|
252
|
+
const needsRebuild = stalePercent > 20 || newFiles.length > 50;
|
|
253
|
+
let sizeBytes = 0;
|
|
254
|
+
for (const path of [manifestPath, semanticIndexPath]) {
|
|
255
|
+
try {
|
|
256
|
+
sizeBytes += (0, fs_1.statSync)(path).size;
|
|
257
|
+
}
|
|
258
|
+
catch { /* ignore */ }
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
exists: true,
|
|
262
|
+
manifest,
|
|
263
|
+
staleFiles,
|
|
264
|
+
missingFiles,
|
|
265
|
+
newFiles,
|
|
266
|
+
totalFiles,
|
|
267
|
+
freshFiles,
|
|
268
|
+
stalePercent,
|
|
269
|
+
needsRebuild,
|
|
270
|
+
cacheDir,
|
|
271
|
+
manifestPath,
|
|
272
|
+
semanticIndexPath,
|
|
273
|
+
sizeBytes,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function restoreBrainCache(options) {
|
|
277
|
+
const { projectRoot, artifactPath } = options;
|
|
278
|
+
if (!(0, fs_1.existsSync)(artifactPath)) {
|
|
279
|
+
return {
|
|
280
|
+
success: false,
|
|
281
|
+
manifest: null,
|
|
282
|
+
message: `Artifact not found: ${artifactPath}`,
|
|
283
|
+
staleAfterRestore: 0,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
let artifact;
|
|
287
|
+
try {
|
|
288
|
+
artifact = JSON.parse((0, fs_1.readFileSync)(artifactPath, 'utf-8'));
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
return {
|
|
292
|
+
success: false,
|
|
293
|
+
manifest: null,
|
|
294
|
+
message: `Failed to parse artifact: ${err instanceof Error ? err.message : String(err)}`,
|
|
295
|
+
staleAfterRestore: 0,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
if (artifact.schemaVersion !== exports.BRAIN_CACHE_SCHEMA_VERSION) {
|
|
299
|
+
return {
|
|
300
|
+
success: false,
|
|
301
|
+
manifest: null,
|
|
302
|
+
message: `Incompatible cache schema: ${artifact.schemaVersion} (expected ${exports.BRAIN_CACHE_SCHEMA_VERSION})`,
|
|
303
|
+
staleAfterRestore: 0,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// Write artifact to cache dir
|
|
307
|
+
const cacheDir = getBrainCacheDir(projectRoot);
|
|
308
|
+
(0, fs_1.mkdirSync)(cacheDir, { recursive: true });
|
|
309
|
+
(0, fs_1.writeFileSync)(getBrainCacheManifestPath(projectRoot), JSON.stringify(artifact, null, 2), 'utf-8');
|
|
310
|
+
// Quick staleness check on restore
|
|
311
|
+
let staleAfterRestore = 0;
|
|
312
|
+
for (const entry of artifact.files.slice(0, 200)) { // sample first 200
|
|
313
|
+
const fullPath = (0, path_1.join)(projectRoot, entry.filePath);
|
|
314
|
+
if (!(0, fs_1.existsSync)(fullPath)) {
|
|
315
|
+
staleAfterRestore++;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const hash = hashFileAtPath(fullPath);
|
|
319
|
+
if (hash !== entry.contentHash)
|
|
320
|
+
staleAfterRestore++;
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
success: true,
|
|
324
|
+
manifest: artifact,
|
|
325
|
+
message: `Cache restored from ${artifactPath} (${artifact.totalFiles} files, built ${artifact.builtAt})`,
|
|
326
|
+
staleAfterRestore,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
// ── CI artifact export ─────────────────────────────────────────────────────────
|
|
330
|
+
/**
|
|
331
|
+
* Export the current cache manifest as a CI artifact.
|
|
332
|
+
* CI pipelines can cache this file and restore it on subsequent runs.
|
|
333
|
+
*/
|
|
334
|
+
function exportBrainCacheArtifact(projectRoot, outputPath) {
|
|
335
|
+
const manifest = loadBrainCacheManifest(projectRoot);
|
|
336
|
+
if (!manifest)
|
|
337
|
+
return false;
|
|
338
|
+
try {
|
|
339
|
+
(0, fs_1.writeFileSync)(outputPath, JSON.stringify(manifest, null, 2), 'utf-8');
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
//# sourceMappingURL=brain-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brain-cache.js","sourceRoot":"","sources":["../../src/utils/brain-cache.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAoEH,4CAEC;AAED,8DAEC;AAED,wEAEC;AAID,0CAEC;AAqBD,wDAaC;AAED,wDAWC;AAqED,0CAuEC;AAID,kDA8EC;AAiBD,8CAqDC;AAQD,4DASC;AAtbD,mCAAoC;AACpC,2BAOY;AACZ,+BAA2C;AAE3C,kFAAkF;AAErE,QAAA,0B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AAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,mBAAmB;QACrE,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,CAAC,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE,CAAC;YAAC,iBAAiB,EAAE,CAAC;YAAC,SAAS;QAAC,CAAC;QAC7D,MAAM,IAAI,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,IAAI,KAAK,KAAK,CAAC,WAAW;YAAE,iBAAiB,EAAE,CAAC;IACtD,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE,uBAAuB,YAAY,KAAK,QAAQ,CAAC,UAAU,iBAAiB,QAAQ,CAAC,OAAO,GAAG;QACxG,iBAAiB;KAClB,CAAC;AACJ,CAAC;AAED,kFAAkF;AAElF;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,WAAmB,EAAE,UAAkB;IAC9E,MAAM,QAAQ,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,IAAI,CAAC;QACH,IAAA,kBAAa,EAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Governance Provenance Chain
|
|
3
|
+
*
|
|
4
|
+
* Every neurcode verify run persists a signed fingerprint record.
|
|
5
|
+
* The record proves exactly why a governance decision happened:
|
|
6
|
+
* which rules ran, what they found, what was suppressed, and why.
|
|
7
|
+
*
|
|
8
|
+
* Stored at: .neurcode/provenance/{runId}.json
|
|
9
|
+
* Index: .neurcode/provenance/index.json
|
|
10
|
+
*
|
|
11
|
+
* @process-local Provenance records are per-workstation/CI runner.
|
|
12
|
+
* For org-wide auditability, upload records to your SIEM or audit log system.
|
|
13
|
+
*/
|
|
14
|
+
export interface ProvenanceRecord {
|
|
15
|
+
runId: string;
|
|
16
|
+
runAt: string;
|
|
17
|
+
schemaVersion: 1;
|
|
18
|
+
repoRoot: string;
|
|
19
|
+
filesAnalyzed: number;
|
|
20
|
+
diffContext: string;
|
|
21
|
+
planId: string | null;
|
|
22
|
+
intentHash: string | null;
|
|
23
|
+
policyHash: string | null;
|
|
24
|
+
ruleIds: string[];
|
|
25
|
+
blockingCount: number;
|
|
26
|
+
advisoryCount: number;
|
|
27
|
+
suppressedCount: number;
|
|
28
|
+
structuralBlockingCount: number;
|
|
29
|
+
structuralAdvisoryCount: number;
|
|
30
|
+
deterministicSignals: number;
|
|
31
|
+
heuristicSignals: number;
|
|
32
|
+
overallTrustScore: number;
|
|
33
|
+
verdict: 'PASS' | 'FAIL' | 'WARN';
|
|
34
|
+
governanceDecision: string;
|
|
35
|
+
fingerprint: string;
|
|
36
|
+
signature: string | null;
|
|
37
|
+
signingKeyId: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface ProvenanceIndex {
|
|
40
|
+
schemaVersion: 1;
|
|
41
|
+
records: Array<{
|
|
42
|
+
runId: string;
|
|
43
|
+
runAt: string;
|
|
44
|
+
verdict: string;
|
|
45
|
+
planId: string | null;
|
|
46
|
+
fingerprint: string;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build a provenance record from verify run results.
|
|
51
|
+
* The fingerprint is SHA-256 of: runId + runAt + ruleIds.sort().join(',') + blockingCount + verdict
|
|
52
|
+
*/
|
|
53
|
+
export declare function buildProvenanceRecord(input: {
|
|
54
|
+
repoRoot: string;
|
|
55
|
+
filesAnalyzed: number;
|
|
56
|
+
diffContext: string;
|
|
57
|
+
planId: string | null;
|
|
58
|
+
intentHash: string | null;
|
|
59
|
+
policyHash: string | null;
|
|
60
|
+
ruleIds: string[];
|
|
61
|
+
blockingCount: number;
|
|
62
|
+
advisoryCount: number;
|
|
63
|
+
suppressedCount: number;
|
|
64
|
+
structuralBlockingCount: number;
|
|
65
|
+
structuralAdvisoryCount: number;
|
|
66
|
+
deterministicSignals: number;
|
|
67
|
+
heuristicSignals: number;
|
|
68
|
+
overallTrustScore: number;
|
|
69
|
+
verdict: 'PASS' | 'FAIL' | 'WARN';
|
|
70
|
+
governanceDecision: string;
|
|
71
|
+
}): ProvenanceRecord;
|
|
72
|
+
/**
|
|
73
|
+
* Persist a provenance record to .neurcode/provenance/.
|
|
74
|
+
* Updates the index file atomically.
|
|
75
|
+
* Index retains last 1000 records (trims oldest first).
|
|
76
|
+
*/
|
|
77
|
+
export declare function saveProvenanceRecord(repoRoot: string, record: ProvenanceRecord): void;
|
|
78
|
+
/**
|
|
79
|
+
* Load the provenance index.
|
|
80
|
+
*/
|
|
81
|
+
export declare function loadProvenanceIndex(repoRoot: string): ProvenanceIndex;
|
|
82
|
+
/**
|
|
83
|
+
* Load a specific provenance record by runId.
|
|
84
|
+
*/
|
|
85
|
+
export declare function loadProvenanceRecord(repoRoot: string, runId: string): ProvenanceRecord | null;
|
|
86
|
+
/**
|
|
87
|
+
* Get the last N provenance records (most recent first).
|
|
88
|
+
*/
|
|
89
|
+
export declare function getRecentProvenance(repoRoot: string, limit?: number): ProvenanceRecord[];
|
|
90
|
+
/**
|
|
91
|
+
* Verify the integrity fingerprint of a stored record.
|
|
92
|
+
* Returns true if fingerprint matches recomputed value.
|
|
93
|
+
*/
|
|
94
|
+
export declare function verifyProvenanceIntegrity(record: ProvenanceRecord): boolean;
|
|
95
|
+
//# sourceMappingURL=governance-provenance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"governance-provenance.d.ts","sourceRoot":"","sources":["../../src/utils/governance-provenance.ts"],"names":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