@eddacraft/anvil-runtime 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 +14 -0
- package/dist/cache/cache-key.d.ts +45 -0
- package/dist/cache/cache-key.d.ts.map +1 -0
- package/dist/cache/cache-key.js +135 -0
- package/dist/cache/index.d.ts +27 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +38 -0
- package/dist/cache/providers/file-cache.d.ts +63 -0
- package/dist/cache/providers/file-cache.d.ts.map +1 -0
- package/dist/cache/providers/file-cache.js +369 -0
- package/dist/cache/providers/memory-cache.d.ts +52 -0
- package/dist/cache/providers/memory-cache.d.ts.map +1 -0
- package/dist/cache/providers/memory-cache.js +197 -0
- package/dist/cache/providers/null-cache.d.ts +26 -0
- package/dist/cache/providers/null-cache.d.ts.map +1 -0
- package/dist/cache/providers/null-cache.js +50 -0
- package/dist/cache/types.d.ts +114 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +4 -0
- package/dist/concurrency/agent.d.ts +137 -0
- package/dist/concurrency/agent.d.ts.map +1 -0
- package/dist/concurrency/agent.js +440 -0
- package/dist/concurrency/atomic.d.ts +93 -0
- package/dist/concurrency/atomic.d.ts.map +1 -0
- package/dist/concurrency/atomic.js +281 -0
- package/dist/concurrency/git-agent.d.ts +114 -0
- package/dist/concurrency/git-agent.d.ts.map +1 -0
- package/dist/concurrency/git-agent.js +313 -0
- package/dist/concurrency/index.d.ts +95 -0
- package/dist/concurrency/index.d.ts.map +1 -0
- package/dist/concurrency/index.js +127 -0
- package/dist/concurrency/lock-manager.d.ts +170 -0
- package/dist/concurrency/lock-manager.d.ts.map +1 -0
- package/dist/concurrency/lock-manager.js +525 -0
- package/dist/concurrency/queue-manager.d.ts +166 -0
- package/dist/concurrency/queue-manager.d.ts.map +1 -0
- package/dist/concurrency/queue-manager.js +442 -0
- package/dist/concurrency/types.d.ts +382 -0
- package/dist/concurrency/types.d.ts.map +1 -0
- package/dist/concurrency/types.js +204 -0
- package/dist/export/constraint-collector.d.ts +175 -0
- package/dist/export/constraint-collector.d.ts.map +1 -0
- package/dist/export/constraint-collector.js +203 -0
- package/dist/export/formatters/llms-txt-formatter.d.ts +89 -0
- package/dist/export/formatters/llms-txt-formatter.d.ts.map +1 -0
- package/dist/export/formatters/llms-txt-formatter.js +249 -0
- package/dist/export/formatters/mcp-resource-formatter.d.ts +186 -0
- package/dist/export/formatters/mcp-resource-formatter.d.ts.map +1 -0
- package/dist/export/formatters/mcp-resource-formatter.js +139 -0
- package/dist/export/formatters/prompt-formatter.d.ts +83 -0
- package/dist/export/formatters/prompt-formatter.d.ts.map +1 -0
- package/dist/export/formatters/prompt-formatter.js +256 -0
- package/dist/export/index.d.ts +10 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +9 -0
- package/dist/gate/check.interface.d.ts +15 -0
- package/dist/gate/check.interface.d.ts.map +1 -0
- package/dist/gate/check.interface.js +18 -0
- package/dist/gate/checks/antipattern.check.d.ts +27 -0
- package/dist/gate/checks/antipattern.check.d.ts.map +1 -0
- package/dist/gate/checks/antipattern.check.js +140 -0
- package/dist/gate/checks/architecture/circular-detector.d.ts +33 -0
- package/dist/gate/checks/architecture/circular-detector.d.ts.map +1 -0
- package/dist/gate/checks/architecture/circular-detector.js +71 -0
- package/dist/gate/checks/architecture/dependency-analyzer.d.ts +81 -0
- package/dist/gate/checks/architecture/dependency-analyzer.d.ts.map +1 -0
- package/dist/gate/checks/architecture/dependency-analyzer.js +136 -0
- package/dist/gate/checks/architecture/layer-validator.d.ts +75 -0
- package/dist/gate/checks/architecture/layer-validator.d.ts.map +1 -0
- package/dist/gate/checks/architecture/layer-validator.js +193 -0
- package/dist/gate/checks/architecture.check.d.ts +56 -0
- package/dist/gate/checks/architecture.check.d.ts.map +1 -0
- package/dist/gate/checks/architecture.check.js +394 -0
- package/dist/gate/checks/command-safety.check.d.ts +12 -0
- package/dist/gate/checks/command-safety.check.d.ts.map +1 -0
- package/dist/gate/checks/command-safety.check.js +230 -0
- package/dist/gate/checks/coverage.check.d.ts +9 -0
- package/dist/gate/checks/coverage.check.d.ts.map +1 -0
- package/dist/gate/checks/coverage.check.js +81 -0
- package/dist/gate/checks/dependency.check.d.ts +17 -0
- package/dist/gate/checks/dependency.check.d.ts.map +1 -0
- package/dist/gate/checks/dependency.check.js +342 -0
- package/dist/gate/checks/eslint.check.d.ts +14 -0
- package/dist/gate/checks/eslint.check.d.ts.map +1 -0
- package/dist/gate/checks/eslint.check.js +79 -0
- package/dist/gate/checks/policy.check.d.ts +78 -0
- package/dist/gate/checks/policy.check.d.ts.map +1 -0
- package/dist/gate/checks/policy.check.js +457 -0
- package/dist/gate/checks/secret/entropy-detector.d.ts +44 -0
- package/dist/gate/checks/secret/entropy-detector.d.ts.map +1 -0
- package/dist/gate/checks/secret/entropy-detector.js +76 -0
- package/dist/gate/checks/secret/git-scanner.d.ts +36 -0
- package/dist/gate/checks/secret/git-scanner.d.ts.map +1 -0
- package/dist/gate/checks/secret/git-scanner.js +90 -0
- package/dist/gate/checks/secret/secret-patterns.d.ts +42 -0
- package/dist/gate/checks/secret/secret-patterns.d.ts.map +1 -0
- package/dist/gate/checks/secret/secret-patterns.js +137 -0
- package/dist/gate/checks/secret.check.d.ts +56 -0
- package/dist/gate/checks/secret.check.d.ts.map +1 -0
- package/dist/gate/checks/secret.check.js +245 -0
- package/dist/gate/config/command-safety-config.d.ts +5 -0
- package/dist/gate/config/command-safety-config.d.ts.map +1 -0
- package/dist/gate/config/command-safety-config.js +69 -0
- package/dist/gate/config/index.d.ts +2 -0
- package/dist/gate/config/index.d.ts.map +1 -0
- package/dist/gate/config/index.js +1 -0
- package/dist/gate/formatters/command-safety-formatter.d.ts +10 -0
- package/dist/gate/formatters/command-safety-formatter.d.ts.map +1 -0
- package/dist/gate/formatters/command-safety-formatter.js +64 -0
- package/dist/gate/formatters/index.d.ts +2 -0
- package/dist/gate/formatters/index.d.ts.map +1 -0
- package/dist/gate/formatters/index.js +1 -0
- package/dist/gate/gate-config.d.ts +44 -0
- package/dist/gate/gate-config.d.ts.map +1 -0
- package/dist/gate/gate-config.js +334 -0
- package/dist/gate/gate-runner.d.ts +160 -0
- package/dist/gate/gate-runner.d.ts.map +1 -0
- package/dist/gate/gate-runner.js +531 -0
- package/dist/gate/index.d.ts +20 -0
- package/dist/gate/index.d.ts.map +1 -0
- package/dist/gate/index.js +14 -0
- package/dist/gate/parsers/command-parser.d.ts +18 -0
- package/dist/gate/parsers/command-parser.d.ts.map +1 -0
- package/dist/gate/parsers/command-parser.js +363 -0
- package/dist/gate/parsers/index.d.ts +2 -0
- package/dist/gate/parsers/index.d.ts.map +1 -0
- package/dist/gate/parsers/index.js +1 -0
- package/dist/gate/policy/index.d.ts +12 -0
- package/dist/gate/policy/index.d.ts.map +1 -0
- package/dist/gate/policy/index.js +10 -0
- package/dist/gate/rules/default-filesystem-rules.d.ts +3 -0
- package/dist/gate/rules/default-filesystem-rules.d.ts.map +1 -0
- package/dist/gate/rules/default-filesystem-rules.js +201 -0
- package/dist/gate/rules/default-git-rules.d.ts +3 -0
- package/dist/gate/rules/default-git-rules.d.ts.map +1 -0
- package/dist/gate/rules/default-git-rules.js +192 -0
- package/dist/gate/rules/index.d.ts +5 -0
- package/dist/gate/rules/index.d.ts.map +1 -0
- package/dist/gate/rules/index.js +3 -0
- package/dist/gate/rules/rule-matcher.d.ts +27 -0
- package/dist/gate/rules/rule-matcher.d.ts.map +1 -0
- package/dist/gate/rules/rule-matcher.js +228 -0
- package/dist/gate/rules/types.d.ts +250 -0
- package/dist/gate/rules/types.d.ts.map +1 -0
- package/dist/gate/rules/types.js +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/types/gate.types.d.ts +42 -0
- package/dist/types/gate.types.d.ts.map +1 -0
- package/dist/types/gate.types.js +94 -0
- package/dist/watch/debouncer.d.ts +90 -0
- package/dist/watch/debouncer.d.ts.map +1 -0
- package/dist/watch/debouncer.js +135 -0
- package/dist/watch/file-watcher.d.ts +73 -0
- package/dist/watch/file-watcher.d.ts.map +1 -0
- package/dist/watch/file-watcher.js +121 -0
- package/dist/watch/git-status.d.ts +98 -0
- package/dist/watch/git-status.d.ts.map +1 -0
- package/dist/watch/git-status.js +266 -0
- package/dist/watch/index.d.ts +16 -0
- package/dist/watch/index.d.ts.map +1 -0
- package/dist/watch/index.js +15 -0
- package/dist/watch/orchestrator.d.ts +113 -0
- package/dist/watch/orchestrator.d.ts.map +1 -0
- package/dist/watch/orchestrator.js +409 -0
- package/dist/watch/types.d.ts +190 -0
- package/dist/watch/types.d.ts.map +1 -0
- package/dist/watch/types.js +76 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) 2026 EddaCraft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
PROPRIETARY AND CONFIDENTIAL
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are the
|
|
6
|
+
exclusive property of EddaCraft. Unauthorised copying, modification,
|
|
7
|
+
distribution, or use of this Software, via any medium, is strictly prohibited
|
|
8
|
+
without the express written permission of EddaCraft.
|
|
9
|
+
|
|
10
|
+
The Software is provided for evaluation and testing purposes only to authorised
|
|
11
|
+
beta testers. No licence is granted to use, copy, modify, or distribute the
|
|
12
|
+
Software for any other purpose.
|
|
13
|
+
|
|
14
|
+
For licensing enquiries, contact: legal@eddacraft.com
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache key generation utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { GateCacheKeyInput } from './types.js';
|
|
5
|
+
import type { GateCheck } from '../types/gate.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generate a deterministic cache key for gate check results
|
|
8
|
+
*
|
|
9
|
+
* Key format: gate:check:{check_name}:{combined_hash}
|
|
10
|
+
* Where combined_hash = SHA256(plan_hash + config_hash + workspace_root + extra)
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateCacheKey(input: GateCacheKeyInput): string;
|
|
13
|
+
/**
|
|
14
|
+
* Generate a hash for check configuration
|
|
15
|
+
* Used to invalidate cache when config changes
|
|
16
|
+
*/
|
|
17
|
+
export declare function hashCheckConfig(config: Record<string, unknown>): string;
|
|
18
|
+
/**
|
|
19
|
+
* Generate a hash for the full gate configuration
|
|
20
|
+
* Used to invalidate all caches when global config changes
|
|
21
|
+
*/
|
|
22
|
+
export declare function hashGateConfig(checks: GateCheck[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Generate an input hash for cache validation
|
|
25
|
+
* This hash captures all inputs that affect the cache result
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateInputHash(input: GateCacheKeyInput): string;
|
|
28
|
+
/**
|
|
29
|
+
* Parse a cache key into its components
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseCacheKey(key: string): {
|
|
32
|
+
type: string;
|
|
33
|
+
subtype: string;
|
|
34
|
+
name: string;
|
|
35
|
+
hash: string;
|
|
36
|
+
} | null;
|
|
37
|
+
/**
|
|
38
|
+
* Generate a pattern for invalidating all cache entries for a check
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkInvalidationPattern(checkName: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Generate a pattern for invalidating all gate cache entries
|
|
43
|
+
*/
|
|
44
|
+
export declare function allGateInvalidationPattern(): string;
|
|
45
|
+
//# sourceMappingURL=cache-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-key.d.ts","sourceRoot":"","sources":["../../src/cache/cache-key.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAKxD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAqBjE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAOvE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAgB1D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAIlE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,IAAI,CAaP;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAEnD"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache key generation utilities
|
|
3
|
+
*/
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { createDebugger } from '@eddacraft/anvil-core';
|
|
6
|
+
const debug = createDebugger('cache');
|
|
7
|
+
/**
|
|
8
|
+
* Generate a deterministic cache key for gate check results
|
|
9
|
+
*
|
|
10
|
+
* Key format: gate:check:{check_name}:{combined_hash}
|
|
11
|
+
* Where combined_hash = SHA256(plan_hash + config_hash + workspace_root + extra)
|
|
12
|
+
*/
|
|
13
|
+
export function generateCacheKey(input) {
|
|
14
|
+
debug(`generateCacheKey: check=${input.check_name} plan_hash=${input.plan_hash}`);
|
|
15
|
+
const hash = createHash('sha256');
|
|
16
|
+
// Add all inputs in deterministic order
|
|
17
|
+
hash.update(input.plan_hash);
|
|
18
|
+
hash.update(input.config_hash);
|
|
19
|
+
hash.update(normaliseWorkspacePath(input.workspace_root));
|
|
20
|
+
// Add extra discriminators in sorted order
|
|
21
|
+
if (input.extra) {
|
|
22
|
+
const sortedKeys = Object.keys(input.extra).sort();
|
|
23
|
+
for (const key of sortedKeys) {
|
|
24
|
+
hash.update(`${key}:${input.extra[key]}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const combinedHash = hash.digest('hex').slice(0, 16);
|
|
28
|
+
const key = `gate:check:${input.check_name}:${combinedHash}`;
|
|
29
|
+
debug(`generateCacheKey: result=${key}`);
|
|
30
|
+
return key;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate a hash for check configuration
|
|
34
|
+
* Used to invalidate cache when config changes
|
|
35
|
+
*/
|
|
36
|
+
export function hashCheckConfig(config) {
|
|
37
|
+
const hash = createHash('sha256');
|
|
38
|
+
// Canonicalise JSON for deterministic hashing
|
|
39
|
+
hash.update(JSON.stringify(sortObjectKeys(config)));
|
|
40
|
+
const result = hash.digest('hex').slice(0, 16);
|
|
41
|
+
debug('hashCheckConfig', { keys: Object.keys(config), hash: result });
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generate a hash for the full gate configuration
|
|
46
|
+
* Used to invalidate all caches when global config changes
|
|
47
|
+
*/
|
|
48
|
+
export function hashGateConfig(checks) {
|
|
49
|
+
const hash = createHash('sha256');
|
|
50
|
+
// Only hash enabled checks and their configs
|
|
51
|
+
const enabledChecks = checks
|
|
52
|
+
.filter((c) => c.enabled)
|
|
53
|
+
.map((c) => ({
|
|
54
|
+
name: c.name,
|
|
55
|
+
config: c.config || {},
|
|
56
|
+
}))
|
|
57
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
58
|
+
hash.update(JSON.stringify(enabledChecks));
|
|
59
|
+
const result = hash.digest('hex').slice(0, 16);
|
|
60
|
+
debug(`hashGateConfig: enabledChecks=${enabledChecks.length} hash=${result}`);
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Generate an input hash for cache validation
|
|
65
|
+
* This hash captures all inputs that affect the cache result
|
|
66
|
+
*/
|
|
67
|
+
export function generateInputHash(input) {
|
|
68
|
+
const hash = createHash('sha256');
|
|
69
|
+
hash.update(JSON.stringify(sortObjectKeys(input)));
|
|
70
|
+
return hash.digest('hex');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Parse a cache key into its components
|
|
74
|
+
*/
|
|
75
|
+
export function parseCacheKey(key) {
|
|
76
|
+
const parts = key.split(':');
|
|
77
|
+
if (parts.length !== 4) {
|
|
78
|
+
debug(`parseCacheKey: invalid key format (expected 4 parts, got ${parts.length})`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
debug(`parseCacheKey: type=${parts[0]} name=${parts[2]}`);
|
|
82
|
+
return {
|
|
83
|
+
type: parts[0],
|
|
84
|
+
subtype: parts[1],
|
|
85
|
+
name: parts[2],
|
|
86
|
+
hash: parts[3],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generate a pattern for invalidating all cache entries for a check
|
|
91
|
+
*/
|
|
92
|
+
export function checkInvalidationPattern(checkName) {
|
|
93
|
+
return `gate:check:${checkName}:*`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Generate a pattern for invalidating all gate cache entries
|
|
97
|
+
*/
|
|
98
|
+
export function allGateInvalidationPattern() {
|
|
99
|
+
return 'gate:*';
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Normalise workspace path for consistent cache keys
|
|
103
|
+
* - Removes trailing slashes
|
|
104
|
+
* - Converts backslashes to forward slashes (Windows)
|
|
105
|
+
* - Lowercases drive letters (Windows)
|
|
106
|
+
*/
|
|
107
|
+
function normaliseWorkspacePath(path) {
|
|
108
|
+
let normalised = path
|
|
109
|
+
// Convert backslashes to forward slashes
|
|
110
|
+
.replace(/\\/g, '/')
|
|
111
|
+
// Remove trailing slashes
|
|
112
|
+
.replace(/\/+$/, '');
|
|
113
|
+
// Lowercase Windows drive letters (C: -> c:)
|
|
114
|
+
if (/^[A-Z]:/.test(normalised)) {
|
|
115
|
+
normalised = normalised[0].toLowerCase() + normalised.slice(1);
|
|
116
|
+
}
|
|
117
|
+
return normalised;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Recursively sort object keys for deterministic JSON stringification
|
|
121
|
+
*/
|
|
122
|
+
function sortObjectKeys(obj) {
|
|
123
|
+
if (obj === null || typeof obj !== 'object') {
|
|
124
|
+
return obj;
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(obj)) {
|
|
127
|
+
return obj.map(sortObjectKeys);
|
|
128
|
+
}
|
|
129
|
+
const sorted = {};
|
|
130
|
+
const keys = Object.keys(obj).sort();
|
|
131
|
+
for (const key of keys) {
|
|
132
|
+
sorted[key] = sortObjectKeys(obj[key]);
|
|
133
|
+
}
|
|
134
|
+
return sorted;
|
|
135
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache module exports
|
|
3
|
+
*/
|
|
4
|
+
export type { CacheProvider, CacheEntry, CacheSetOptions, CacheStats, GateCacheKeyInput, CachedGateResult, } from './types.js';
|
|
5
|
+
export { FileCacheProvider, type FileCacheConfig } from './providers/file-cache.js';
|
|
6
|
+
export { MemoryCacheProvider, type MemoryCacheConfig } from './providers/memory-cache.js';
|
|
7
|
+
export { NullCacheProvider } from './providers/null-cache.js';
|
|
8
|
+
export { generateCacheKey, hashCheckConfig, hashGateConfig, generateInputHash, parseCacheKey, checkInvalidationPattern, allGateInvalidationPattern, } from './cache-key.js';
|
|
9
|
+
import type { CacheProvider } from './types.js';
|
|
10
|
+
export type CacheProviderType = 'file' | 'memory' | 'null';
|
|
11
|
+
export interface CreateCacheOptions {
|
|
12
|
+
/** Provider type */
|
|
13
|
+
type: CacheProviderType;
|
|
14
|
+
/** Workspace root (required for file cache) */
|
|
15
|
+
workspaceRoot?: string;
|
|
16
|
+
/** Whether to disable caching */
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** Use global cache in home directory */
|
|
19
|
+
useGlobalCache?: boolean;
|
|
20
|
+
/** Default TTL in milliseconds */
|
|
21
|
+
defaultTtl?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a cache provider based on options
|
|
25
|
+
*/
|
|
26
|
+
export declare function createCacheProvider(options: CreateCacheOptions): CacheProvider;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,aAAa,EACb,UAAU,EACV,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAKhD,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,oBAAoB;IACpB,IAAI,EAAE,iBAAiB,CAAC;IACxB,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yCAAyC;IACzC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,aAAa,CA0B9E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache module exports
|
|
3
|
+
*/
|
|
4
|
+
// Providers
|
|
5
|
+
export { FileCacheProvider } from './providers/file-cache.js';
|
|
6
|
+
export { MemoryCacheProvider } from './providers/memory-cache.js';
|
|
7
|
+
export { NullCacheProvider } from './providers/null-cache.js';
|
|
8
|
+
// Cache key utilities
|
|
9
|
+
export { generateCacheKey, hashCheckConfig, hashGateConfig, generateInputHash, parseCacheKey, checkInvalidationPattern, allGateInvalidationPattern, } from './cache-key.js';
|
|
10
|
+
import { FileCacheProvider } from './providers/file-cache.js';
|
|
11
|
+
import { MemoryCacheProvider } from './providers/memory-cache.js';
|
|
12
|
+
import { NullCacheProvider } from './providers/null-cache.js';
|
|
13
|
+
/**
|
|
14
|
+
* Create a cache provider based on options
|
|
15
|
+
*/
|
|
16
|
+
export function createCacheProvider(options) {
|
|
17
|
+
if (options.disabled) {
|
|
18
|
+
return new NullCacheProvider();
|
|
19
|
+
}
|
|
20
|
+
switch (options.type) {
|
|
21
|
+
case 'file':
|
|
22
|
+
if (!options.workspaceRoot) {
|
|
23
|
+
throw new Error('workspaceRoot is required for file cache provider');
|
|
24
|
+
}
|
|
25
|
+
return new FileCacheProvider(options.workspaceRoot, {
|
|
26
|
+
useGlobalCache: options.useGlobalCache,
|
|
27
|
+
defaultTtl: options.defaultTtl,
|
|
28
|
+
});
|
|
29
|
+
case 'memory':
|
|
30
|
+
return new MemoryCacheProvider({
|
|
31
|
+
defaultTtl: options.defaultTtl,
|
|
32
|
+
});
|
|
33
|
+
case 'null':
|
|
34
|
+
return new NullCacheProvider();
|
|
35
|
+
default:
|
|
36
|
+
throw new Error(`Unknown cache provider type: ${options.type}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-based cache provider
|
|
3
|
+
* Stores cache entries as JSON files in .anvil/cache/
|
|
4
|
+
*/
|
|
5
|
+
import type { CacheProvider, CacheEntry, CacheSetOptions, CacheStats } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* File-based cache provider configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface FileCacheConfig {
|
|
10
|
+
/** Base directory for cache (default: .anvil/cache in workspace root) */
|
|
11
|
+
cacheDir?: string;
|
|
12
|
+
/** Default TTL in milliseconds (default: 24 hours) */
|
|
13
|
+
defaultTtl?: number;
|
|
14
|
+
/** Maximum cache size in bytes (default: 100MB) */
|
|
15
|
+
maxSizeBytes?: number;
|
|
16
|
+
/** Whether to use global cache in home directory */
|
|
17
|
+
useGlobalCache?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* File-based cache provider
|
|
21
|
+
*
|
|
22
|
+
* Storage structure:
|
|
23
|
+
* .anvil/cache/
|
|
24
|
+
* ├── index.json # Cache registry and stats
|
|
25
|
+
* └── entries/ # Cache entry files
|
|
26
|
+
* └── {key-hash}.json
|
|
27
|
+
*/
|
|
28
|
+
export declare class FileCacheProvider implements CacheProvider {
|
|
29
|
+
readonly name = "file";
|
|
30
|
+
private readonly cacheDir;
|
|
31
|
+
private readonly entriesDir;
|
|
32
|
+
private readonly indexPath;
|
|
33
|
+
private readonly defaultTtl;
|
|
34
|
+
private readonly maxSizeBytes;
|
|
35
|
+
private readonly hmacKey;
|
|
36
|
+
private index;
|
|
37
|
+
private indexDirty;
|
|
38
|
+
constructor(workspaceRoot: string, config?: FileCacheConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Load a persisted HMAC key from the cache dir, or generate and store one.
|
|
41
|
+
* The key is stored with 0o600 permissions so only the current user can read it.
|
|
42
|
+
*/
|
|
43
|
+
private loadOrCreateHmacKey;
|
|
44
|
+
get<T>(key: string): Promise<CacheEntry<T> | null>;
|
|
45
|
+
set<T>(key: string, value: T, options: CacheSetOptions): Promise<void>;
|
|
46
|
+
invalidate(key: string): Promise<boolean>;
|
|
47
|
+
invalidatePattern(pattern: string): Promise<number>;
|
|
48
|
+
getStats(): Promise<CacheStats>;
|
|
49
|
+
clear(): Promise<void>;
|
|
50
|
+
isAvailable(): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Clean up expired entries
|
|
53
|
+
*/
|
|
54
|
+
cleanup(): Promise<number>;
|
|
55
|
+
private ensureCacheDir;
|
|
56
|
+
private loadIndex;
|
|
57
|
+
private saveIndex;
|
|
58
|
+
private computeHmac;
|
|
59
|
+
private hashKey;
|
|
60
|
+
private patternToRegex;
|
|
61
|
+
private maybeEvict;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=file-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-cache.d.ts","sourceRoot":"","sources":["../../../src/cache/providers/file-cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA4D1F;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,QAAQ,CAAC,IAAI,UAAU;IAEvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,UAAU,CAAS;gBAEf,aAAa,EAAE,MAAM,EAAE,MAAM,GAAE,eAAoB;IAe/D;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAYrB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IA8ElD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA0CtE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BzC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAenD,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IAiB/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAUtB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAUrC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;YAiBlB,cAAc;YAMd,SAAS;YAgCT,SAAS;IAWvB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,cAAc;YAsBR,UAAU;CA0BzB"}
|