@red-codes/agentguard 1.0.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 +190 -0
- package/README.md +298 -0
- package/dist/adapters/claude-code.d.ts +24 -0
- package/dist/adapters/claude-code.d.ts.map +1 -0
- package/dist/adapters/claude-code.js +99 -0
- package/dist/adapters/claude-code.js.map +1 -0
- package/dist/adapters/file.d.ts +3 -0
- package/dist/adapters/file.d.ts.map +1 -0
- package/dist/adapters/file.js +35 -0
- package/dist/adapters/file.js.map +1 -0
- package/dist/adapters/git.d.ts +3 -0
- package/dist/adapters/git.d.ts.map +1 -0
- package/dist/adapters/git.js +61 -0
- package/dist/adapters/git.js.map +1 -0
- package/dist/adapters/registry.d.ts +5 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +15 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/shell.d.ts +8 -0
- package/dist/adapters/shell.d.ts.map +1 -0
- package/dist/adapters/shell.js +27 -0
- package/dist/adapters/shell.js.map +1 -0
- package/dist/cli/args.d.ts +25 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +63 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +5769 -0
- package/dist/cli/bin.js.map +7 -0
- package/dist/cli/colors.d.ts +11 -0
- package/dist/cli/colors.d.ts.map +1 -0
- package/dist/cli/colors.js +44 -0
- package/dist/cli/colors.js.map +1 -0
- package/dist/cli/commands/claude-hook.d.ts +2 -0
- package/dist/cli/commands/claude-hook.d.ts.map +1 -0
- package/dist/cli/commands/claude-hook.js +110 -0
- package/dist/cli/commands/claude-hook.js.map +1 -0
- package/dist/cli/commands/claude-init.d.ts +2 -0
- package/dist/cli/commands/claude-init.d.ts.map +1 -0
- package/dist/cli/commands/claude-init.js +150 -0
- package/dist/cli/commands/claude-init.js.map +1 -0
- package/dist/cli/commands/export.d.ts +11 -0
- package/dist/cli/commands/export.d.ts.map +1 -0
- package/dist/cli/commands/export.js +113 -0
- package/dist/cli/commands/export.js.map +1 -0
- package/dist/cli/commands/guard.d.ts +12 -0
- package/dist/cli/commands/guard.d.ts.map +1 -0
- package/dist/cli/commands/guard.js +145 -0
- package/dist/cli/commands/guard.js.map +1 -0
- package/dist/cli/commands/import.d.ts +2 -0
- package/dist/cli/commands/import.d.ts.map +1 -0
- package/dist/cli/commands/import.js +115 -0
- package/dist/cli/commands/import.js.map +1 -0
- package/dist/cli/commands/inspect.d.ts +3 -0
- package/dist/cli/commands/inspect.d.ts.map +1 -0
- package/dist/cli/commands/inspect.js +185 -0
- package/dist/cli/commands/inspect.js.map +1 -0
- package/dist/cli/commands/plugin.d.ts +7 -0
- package/dist/cli/commands/plugin.d.ts.map +1 -0
- package/dist/cli/commands/plugin.js +234 -0
- package/dist/cli/commands/plugin.js.map +1 -0
- package/dist/cli/commands/replay.d.ts +12 -0
- package/dist/cli/commands/replay.d.ts.map +1 -0
- package/dist/cli/commands/replay.js +208 -0
- package/dist/cli/commands/replay.js.map +1 -0
- package/dist/cli/file-event-store.d.ts +41 -0
- package/dist/cli/file-event-store.d.ts.map +1 -0
- package/dist/cli/file-event-store.js +219 -0
- package/dist/cli/file-event-store.js.map +1 -0
- package/dist/cli/policy-resolver.d.ts +4 -0
- package/dist/cli/policy-resolver.d.ts.map +1 -0
- package/dist/cli/policy-resolver.js +62 -0
- package/dist/cli/policy-resolver.js.map +1 -0
- package/dist/cli/recorder.d.ts +36 -0
- package/dist/cli/recorder.d.ts.map +1 -0
- package/dist/cli/recorder.js +85 -0
- package/dist/cli/recorder.js.map +1 -0
- package/dist/cli/replay.d.ts +2 -0
- package/dist/cli/replay.d.ts.map +1 -0
- package/dist/cli/replay.js +310 -0
- package/dist/cli/replay.js.map +1 -0
- package/dist/cli/session-store.d.ts +41 -0
- package/dist/cli/session-store.d.ts.map +1 -0
- package/dist/cli/session-store.js +95 -0
- package/dist/cli/session-store.js.map +1 -0
- package/dist/cli/tui.d.ts +24 -0
- package/dist/cli/tui.d.ts.map +1 -0
- package/dist/cli/tui.js +197 -0
- package/dist/cli/tui.js.map +1 -0
- package/dist/core/actions.d.ts +11 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +112 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/adapters.d.ts +19 -0
- package/dist/core/adapters.d.ts.map +1 -0
- package/dist/core/adapters.js +85 -0
- package/dist/core/adapters.js.map +1 -0
- package/dist/core/execution-log/bridge.d.ts +12 -0
- package/dist/core/execution-log/bridge.d.ts.map +1 -0
- package/dist/core/execution-log/bridge.js +112 -0
- package/dist/core/execution-log/bridge.js.map +1 -0
- package/dist/core/execution-log/event-log.d.ts +7 -0
- package/dist/core/execution-log/event-log.d.ts.map +1 -0
- package/dist/core/execution-log/event-log.js +103 -0
- package/dist/core/execution-log/event-log.js.map +1 -0
- package/dist/core/execution-log/event-projections.d.ts +28 -0
- package/dist/core/execution-log/event-projections.d.ts.map +1 -0
- package/dist/core/execution-log/event-projections.js +272 -0
- package/dist/core/execution-log/event-projections.js.map +1 -0
- package/dist/core/execution-log/event-schema.d.ts +56 -0
- package/dist/core/execution-log/event-schema.d.ts.map +1 -0
- package/dist/core/execution-log/event-schema.js +160 -0
- package/dist/core/execution-log/event-schema.js.map +1 -0
- package/dist/core/execution-log/index.d.ts +7 -0
- package/dist/core/execution-log/index.d.ts.map +1 -0
- package/dist/core/execution-log/index.js +13 -0
- package/dist/core/execution-log/index.js.map +1 -0
- package/dist/core/hash.d.ts +5 -0
- package/dist/core/hash.d.ts.map +1 -0
- package/dist/core/hash.js +13 -0
- package/dist/core/hash.js.map +1 -0
- package/dist/core/rng.d.ts +29 -0
- package/dist/core/rng.d.ts.map +1 -0
- package/dist/core/rng.js +48 -0
- package/dist/core/rng.js.map +1 -0
- package/dist/core/types.d.ts +746 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +8 -0
- package/dist/core/types.js.map +1 -0
- package/dist/events/bus.d.ts +24 -0
- package/dist/events/bus.d.ts.map +1 -0
- package/dist/events/bus.js +64 -0
- package/dist/events/bus.js.map +1 -0
- package/dist/events/decision-jsonl.d.ts +8 -0
- package/dist/events/decision-jsonl.d.ts.map +1 -0
- package/dist/events/decision-jsonl.js +44 -0
- package/dist/events/decision-jsonl.js.map +1 -0
- package/dist/events/jsonl.d.ts +8 -0
- package/dist/events/jsonl.d.ts.map +1 -0
- package/dist/events/jsonl.js +46 -0
- package/dist/events/jsonl.js.map +1 -0
- package/dist/events/schema.d.ts +59 -0
- package/dist/events/schema.d.ts.map +1 -0
- package/dist/events/schema.js +296 -0
- package/dist/events/schema.js.map +1 -0
- package/dist/events/store.d.ts +7 -0
- package/dist/events/store.d.ts.map +1 -0
- package/dist/events/store.js +64 -0
- package/dist/events/store.js.map +1 -0
- package/dist/invariants/checker.d.ts +15 -0
- package/dist/invariants/checker.d.ts.map +1 -0
- package/dist/invariants/checker.js +52 -0
- package/dist/invariants/checker.js.map +1 -0
- package/dist/invariants/definitions.d.ts +33 -0
- package/dist/invariants/definitions.d.ts.map +1 -0
- package/dist/invariants/definitions.js +168 -0
- package/dist/invariants/definitions.js.map +1 -0
- package/dist/kernel/aab.d.ts +26 -0
- package/dist/kernel/aab.d.ts.map +1 -0
- package/dist/kernel/aab.js +149 -0
- package/dist/kernel/aab.js.map +1 -0
- package/dist/kernel/blast-radius.d.ts +60 -0
- package/dist/kernel/blast-radius.d.ts.map +1 -0
- package/dist/kernel/blast-radius.js +146 -0
- package/dist/kernel/blast-radius.js.map +1 -0
- package/dist/kernel/decision.d.ts +40 -0
- package/dist/kernel/decision.d.ts.map +1 -0
- package/dist/kernel/decision.js +92 -0
- package/dist/kernel/decision.js.map +1 -0
- package/dist/kernel/decisions/factory.d.ts +12 -0
- package/dist/kernel/decisions/factory.d.ts.map +1 -0
- package/dist/kernel/decisions/factory.js +56 -0
- package/dist/kernel/decisions/factory.js.map +1 -0
- package/dist/kernel/decisions/types.d.ts +70 -0
- package/dist/kernel/decisions/types.d.ts.map +1 -0
- package/dist/kernel/decisions/types.js +5 -0
- package/dist/kernel/decisions/types.js.map +1 -0
- package/dist/kernel/evidence.d.ts +29 -0
- package/dist/kernel/evidence.d.ts.map +1 -0
- package/dist/kernel/evidence.js +61 -0
- package/dist/kernel/evidence.js.map +1 -0
- package/dist/kernel/kernel.d.ts +47 -0
- package/dist/kernel/kernel.d.ts.map +1 -0
- package/dist/kernel/kernel.js +377 -0
- package/dist/kernel/kernel.js.map +1 -0
- package/dist/kernel/monitor.d.ts +35 -0
- package/dist/kernel/monitor.d.ts.map +1 -0
- package/dist/kernel/monitor.js +144 -0
- package/dist/kernel/monitor.js.map +1 -0
- package/dist/kernel/replay-comparator.d.ts +72 -0
- package/dist/kernel/replay-comparator.d.ts.map +1 -0
- package/dist/kernel/replay-comparator.js +251 -0
- package/dist/kernel/replay-comparator.js.map +1 -0
- package/dist/kernel/replay-engine.d.ts +108 -0
- package/dist/kernel/replay-engine.d.ts.map +1 -0
- package/dist/kernel/replay-engine.js +241 -0
- package/dist/kernel/replay-engine.js.map +1 -0
- package/dist/kernel/replay-processor.d.ts +109 -0
- package/dist/kernel/replay-processor.d.ts.map +1 -0
- package/dist/kernel/replay-processor.js +118 -0
- package/dist/kernel/replay-processor.js.map +1 -0
- package/dist/kernel/simulation/filesystem-simulator.d.ts +3 -0
- package/dist/kernel/simulation/filesystem-simulator.d.ts.map +1 -0
- package/dist/kernel/simulation/filesystem-simulator.js +81 -0
- package/dist/kernel/simulation/filesystem-simulator.js.map +1 -0
- package/dist/kernel/simulation/git-simulator.d.ts +5 -0
- package/dist/kernel/simulation/git-simulator.d.ts.map +1 -0
- package/dist/kernel/simulation/git-simulator.js +115 -0
- package/dist/kernel/simulation/git-simulator.js.map +1 -0
- package/dist/kernel/simulation/package-simulator.d.ts +5 -0
- package/dist/kernel/simulation/package-simulator.d.ts.map +1 -0
- package/dist/kernel/simulation/package-simulator.js +164 -0
- package/dist/kernel/simulation/package-simulator.js.map +1 -0
- package/dist/kernel/simulation/registry.d.ts +3 -0
- package/dist/kernel/simulation/registry.d.ts.map +1 -0
- package/dist/kernel/simulation/registry.js +24 -0
- package/dist/kernel/simulation/registry.js.map +1 -0
- package/dist/kernel/simulation/types.d.ts +35 -0
- package/dist/kernel/simulation/types.d.ts.map +1 -0
- package/dist/kernel/simulation/types.js +4 -0
- package/dist/kernel/simulation/types.js.map +1 -0
- package/dist/plugins/discovery.d.ts +45 -0
- package/dist/plugins/discovery.d.ts.map +1 -0
- package/dist/plugins/discovery.js +89 -0
- package/dist/plugins/discovery.js.map +1 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +7 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/registry.d.ts +52 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +148 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/sandbox.d.ts +87 -0
- package/dist/plugins/sandbox.d.ts.map +1 -0
- package/dist/plugins/sandbox.js +122 -0
- package/dist/plugins/sandbox.js.map +1 -0
- package/dist/plugins/types.d.ts +61 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +16 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/validator.d.ts +36 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +276 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/policy/evaluator.d.ts +41 -0
- package/dist/policy/evaluator.d.ts.map +1 -0
- package/dist/policy/evaluator.js +111 -0
- package/dist/policy/evaluator.js.map +1 -0
- package/dist/policy/loader.d.ts +13 -0
- package/dist/policy/loader.d.ts.map +1 -0
- package/dist/policy/loader.js +118 -0
- package/dist/policy/loader.js.map +1 -0
- package/dist/policy/pack-loader.d.ts +40 -0
- package/dist/policy/pack-loader.d.ts.map +1 -0
- package/dist/policy/pack-loader.js +138 -0
- package/dist/policy/pack-loader.js.map +1 -0
- package/dist/policy/yaml-loader.d.ts +23 -0
- package/dist/policy/yaml-loader.d.ts.map +1 -0
- package/dist/policy/yaml-loader.js +222 -0
- package/dist/policy/yaml-loader.js.map +1 -0
- package/dist/renderers/index.d.ts +6 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/index.js +4 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/registry.d.ts +39 -0
- package/dist/renderers/registry.d.ts.map +1 -0
- package/dist/renderers/registry.js +97 -0
- package/dist/renderers/registry.js.map +1 -0
- package/dist/renderers/tui-renderer.d.ts +18 -0
- package/dist/renderers/tui-renderer.d.ts.map +1 -0
- package/dist/renderers/tui-renderer.js +57 -0
- package/dist/renderers/tui-renderer.js.map +1 -0
- package/dist/renderers/types.d.ts +52 -0
- package/dist/renderers/types.d.ts.map +1 -0
- package/dist/renderers/types.js +4 -0
- package/dist/renderers/types.js.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/runtimeLogger.d.ts +9 -0
- package/dist/telemetry/runtimeLogger.d.ts.map +1 -0
- package/dist/telemetry/runtimeLogger.js +68 -0
- package/dist/telemetry/runtimeLogger.js.map +1 -0
- package/dist/telemetry/types.d.ts +22 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +4 -0
- package/dist/telemetry/types.js.map +1 -0
- package/hooks/post-commit +57 -0
- package/hooks/post-merge +33 -0
- package/hooks/pre-commit +28 -0
- package/package.json +72 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Policy pack loader — resolves, loads, validates, and merges policy packs.
|
|
2
|
+
// Supports local directory packs and npm-style package references.
|
|
3
|
+
//
|
|
4
|
+
// A policy pack is a YAML or JSON policy file that can be referenced via the
|
|
5
|
+
// `extends` key in a policy definition. Packs are loaded and their rules are
|
|
6
|
+
// merged with the local policy, with local rules taking precedence.
|
|
7
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
8
|
+
import { resolve, join } from 'node:path';
|
|
9
|
+
import { loadYamlPolicy } from './yaml-loader.js';
|
|
10
|
+
import { validatePolicy } from './loader.js';
|
|
11
|
+
/** Candidate filenames when resolving a pack directory */
|
|
12
|
+
const PACK_MANIFEST_CANDIDATES = [
|
|
13
|
+
'agentguard-pack.yaml',
|
|
14
|
+
'agentguard-pack.yml',
|
|
15
|
+
'agentguard-pack.json',
|
|
16
|
+
'agentguard.yaml',
|
|
17
|
+
'agentguard.yml',
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Resolve a single pack reference to an absolute file path.
|
|
21
|
+
*
|
|
22
|
+
* Supports three reference styles:
|
|
23
|
+
* 1. Relative path — `"./packs/strict"` or `"./packs/strict.yaml"`
|
|
24
|
+
* 2. Absolute path — `"/home/user/packs/strict.yaml"`
|
|
25
|
+
* 3. npm package — `"@agentguard/security-pack"` resolved from node_modules
|
|
26
|
+
*/
|
|
27
|
+
export function resolvePackPath(ref, baseDir) {
|
|
28
|
+
// 1. Direct file reference (relative or absolute)
|
|
29
|
+
const directPath = resolve(baseDir, ref);
|
|
30
|
+
if (existsSync(directPath)) {
|
|
31
|
+
// If it's a file, use it directly
|
|
32
|
+
if (directPath.endsWith('.yaml') ||
|
|
33
|
+
directPath.endsWith('.yml') ||
|
|
34
|
+
directPath.endsWith('.json')) {
|
|
35
|
+
return directPath;
|
|
36
|
+
}
|
|
37
|
+
// If it's a directory, look for manifest files
|
|
38
|
+
for (const candidate of PACK_MANIFEST_CANDIDATES) {
|
|
39
|
+
const candidatePath = join(directPath, candidate);
|
|
40
|
+
if (existsSync(candidatePath)) {
|
|
41
|
+
return candidatePath;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Try with common extensions if the direct path didn't work
|
|
46
|
+
for (const ext of ['.yaml', '.yml', '.json']) {
|
|
47
|
+
const withExt = directPath + ext;
|
|
48
|
+
if (existsSync(withExt)) {
|
|
49
|
+
return withExt;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// 2. npm package reference — search node_modules
|
|
53
|
+
const nodeModulesPath = join(baseDir, 'node_modules', ref);
|
|
54
|
+
if (existsSync(nodeModulesPath)) {
|
|
55
|
+
for (const candidate of PACK_MANIFEST_CANDIDATES) {
|
|
56
|
+
const candidatePath = join(nodeModulesPath, candidate);
|
|
57
|
+
if (existsSync(candidatePath)) {
|
|
58
|
+
return candidatePath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Load a single policy pack from a resolved file path.
|
|
66
|
+
*/
|
|
67
|
+
export function loadPackFile(filePath) {
|
|
68
|
+
const content = readFileSync(filePath, 'utf8');
|
|
69
|
+
if (filePath.endsWith('.yaml') || filePath.endsWith('.yml')) {
|
|
70
|
+
return loadYamlPolicy(content, `pack:${filePath}`);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const parsed = JSON.parse(content);
|
|
74
|
+
const result = validatePolicy(parsed);
|
|
75
|
+
if (!result.valid) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
id: parsed.id || `pack:${filePath}`,
|
|
80
|
+
name: parsed.name || 'JSON Pack',
|
|
81
|
+
description: parsed.description,
|
|
82
|
+
rules: parsed.rules,
|
|
83
|
+
severity: parsed.severity ?? 3,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve and load all policy packs from an `extends` list.
|
|
92
|
+
*
|
|
93
|
+
* @param extends_ - Array of pack references (paths or npm package names)
|
|
94
|
+
* @param baseDir - Directory to resolve relative paths from
|
|
95
|
+
* @returns Loaded pack policies and any errors encountered
|
|
96
|
+
*/
|
|
97
|
+
export function resolveExtends(extends_, baseDir) {
|
|
98
|
+
const policies = [];
|
|
99
|
+
const errors = [];
|
|
100
|
+
const seenIds = new Set();
|
|
101
|
+
for (const ref of extends_) {
|
|
102
|
+
const resolvedPath = resolvePackPath(ref, baseDir);
|
|
103
|
+
if (!resolvedPath) {
|
|
104
|
+
errors.push(`Pack not found: "${ref}" (searched from ${baseDir})`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const pack = loadPackFile(resolvedPath);
|
|
108
|
+
if (!pack) {
|
|
109
|
+
errors.push(`Failed to load pack: "${ref}" (${resolvedPath})`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (seenIds.has(pack.id)) {
|
|
113
|
+
errors.push(`Duplicate pack ID: "${pack.id}" from "${ref}"`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
seenIds.add(pack.id);
|
|
117
|
+
policies.push(pack);
|
|
118
|
+
}
|
|
119
|
+
return { policies, errors };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Merge pack policies with a local policy.
|
|
123
|
+
*
|
|
124
|
+
* Precedence: local rules override pack rules. Within packs, earlier entries
|
|
125
|
+
* in the `extends` list take precedence over later entries.
|
|
126
|
+
*
|
|
127
|
+
* The merge strategy is:
|
|
128
|
+
* 1. Collect all rules from packs (in extends order)
|
|
129
|
+
* 2. Append local rules (which take precedence during evaluation since
|
|
130
|
+
* the evaluator checks deny rules first, then allow rules)
|
|
131
|
+
* 3. Return a single merged policy array
|
|
132
|
+
*/
|
|
133
|
+
export function mergePolicies(localPolicy, packPolicies) {
|
|
134
|
+
// Pack policies come first (lower precedence in evaluation order)
|
|
135
|
+
// Local policy comes last (highest precedence)
|
|
136
|
+
return [...packPolicies, localPolicy];
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=pack-loader.js.map
|
|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G;AACH,MAAM,UAAU,aAAa,CAC3B,WAAyB,EACzB,YAA4B;IAE5B,kEAAkE;IAClE,+CAA+C;IAC/C,OAAO,CAAC,GAAG,YAAY,EAAE,WAAW,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LoadedPolicy } from './evaluator.js';
|
|
2
|
+
export interface YamlPolicyDef {
|
|
3
|
+
id?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
severity?: number;
|
|
7
|
+
extends?: string[];
|
|
8
|
+
rules?: YamlRule[];
|
|
9
|
+
}
|
|
10
|
+
interface YamlRule {
|
|
11
|
+
action?: string;
|
|
12
|
+
effect?: string;
|
|
13
|
+
target?: string;
|
|
14
|
+
branches?: string[];
|
|
15
|
+
reason?: string;
|
|
16
|
+
limit?: number;
|
|
17
|
+
requireTests?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function parseYamlPolicy(yaml: string): YamlPolicyDef;
|
|
20
|
+
export declare function loadYamlPolicy(yaml: string, defaultId?: string): LoadedPolicy;
|
|
21
|
+
export declare function loadYamlPolicies(yaml: string): LoadedPolicy[];
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=yaml-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-loader.d.ts","sourceRoot":"","sources":["../../src/policy/yaml-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,UAAU,QAAQ;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAkCD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CA2H3D;AAgED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CAU7E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAE7D"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// YAML policy loader — parses simple YAML policy files into LoadedPolicy format.
|
|
2
|
+
// Supports the subset of YAML needed for AgentGuard policy definitions.
|
|
3
|
+
// No external dependencies — minimal line-based parser for constrained format.
|
|
4
|
+
function trimQuotes(s) {
|
|
5
|
+
if ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'"))) {
|
|
6
|
+
return s.slice(1, -1);
|
|
7
|
+
}
|
|
8
|
+
return s;
|
|
9
|
+
}
|
|
10
|
+
function parseValue(raw) {
|
|
11
|
+
const s = raw.trim();
|
|
12
|
+
if (s === 'true')
|
|
13
|
+
return true;
|
|
14
|
+
if (s === 'false')
|
|
15
|
+
return false;
|
|
16
|
+
if (s === 'null' || s === '~')
|
|
17
|
+
return '';
|
|
18
|
+
if (/^-?\d+$/.test(s))
|
|
19
|
+
return parseInt(s, 10);
|
|
20
|
+
if (/^-?\d+\.\d+$/.test(s))
|
|
21
|
+
return parseFloat(s);
|
|
22
|
+
return trimQuotes(s);
|
|
23
|
+
}
|
|
24
|
+
function parseInlineArray(raw) {
|
|
25
|
+
const trimmed = raw.trim();
|
|
26
|
+
if (!trimmed.startsWith('[') || !trimmed.endsWith(']'))
|
|
27
|
+
return [];
|
|
28
|
+
const inner = trimmed.slice(1, -1);
|
|
29
|
+
return inner
|
|
30
|
+
.split(',')
|
|
31
|
+
.map((s) => trimQuotes(s.trim()))
|
|
32
|
+
.filter((s) => s.length > 0);
|
|
33
|
+
}
|
|
34
|
+
function indentLevel(line) {
|
|
35
|
+
const match = line.match(/^(\s*)/);
|
|
36
|
+
return match ? match[1].length : 0;
|
|
37
|
+
}
|
|
38
|
+
export function parseYamlPolicy(yaml) {
|
|
39
|
+
const lines = yaml.split('\n');
|
|
40
|
+
const result = {};
|
|
41
|
+
const rules = [];
|
|
42
|
+
let currentRule = null;
|
|
43
|
+
let inRules = false;
|
|
44
|
+
let inBranches = false;
|
|
45
|
+
let inExtends = false;
|
|
46
|
+
for (const rawLine of lines) {
|
|
47
|
+
const line = rawLine.replace(/\r$/, '');
|
|
48
|
+
// Skip blank lines and comments
|
|
49
|
+
if (!line.trim() || line.trim().startsWith('#'))
|
|
50
|
+
continue;
|
|
51
|
+
const indent = indentLevel(line);
|
|
52
|
+
const trimmed = line.trim();
|
|
53
|
+
// Top-level keys (indent 0)
|
|
54
|
+
if (indent === 0) {
|
|
55
|
+
inRules = false;
|
|
56
|
+
inBranches = false;
|
|
57
|
+
inExtends = false;
|
|
58
|
+
if (currentRule) {
|
|
59
|
+
rules.push(currentRule);
|
|
60
|
+
currentRule = null;
|
|
61
|
+
}
|
|
62
|
+
const colonIdx = trimmed.indexOf(':');
|
|
63
|
+
if (colonIdx === -1)
|
|
64
|
+
continue;
|
|
65
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
66
|
+
const val = trimmed.slice(colonIdx + 1).trim();
|
|
67
|
+
switch (key) {
|
|
68
|
+
case 'id':
|
|
69
|
+
result.id = trimQuotes(val);
|
|
70
|
+
break;
|
|
71
|
+
case 'name':
|
|
72
|
+
result.name = trimQuotes(val);
|
|
73
|
+
break;
|
|
74
|
+
case 'description':
|
|
75
|
+
result.description = trimQuotes(val);
|
|
76
|
+
break;
|
|
77
|
+
case 'severity':
|
|
78
|
+
result.severity = parseInt(val, 10);
|
|
79
|
+
break;
|
|
80
|
+
case 'extends':
|
|
81
|
+
if (val) {
|
|
82
|
+
// Inline array: extends: ["@agentguard/security-pack", "./custom"]
|
|
83
|
+
const arr = parseInlineArray(val);
|
|
84
|
+
if (arr.length > 0) {
|
|
85
|
+
result.extends = arr;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Multi-line array follows
|
|
90
|
+
inExtends = true;
|
|
91
|
+
result.extends = [];
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case 'rules':
|
|
95
|
+
inRules = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// Inside extends array (multi-line)
|
|
101
|
+
if (inExtends && trimmed.startsWith('- ')) {
|
|
102
|
+
result.extends = result.extends || [];
|
|
103
|
+
result.extends.push(trimQuotes(trimmed.slice(2).trim()));
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// Inside rules array
|
|
107
|
+
if (inRules) {
|
|
108
|
+
// New rule entry (- action: ...)
|
|
109
|
+
if (trimmed.startsWith('- ')) {
|
|
110
|
+
if (currentRule)
|
|
111
|
+
rules.push(currentRule);
|
|
112
|
+
currentRule = {};
|
|
113
|
+
inBranches = false;
|
|
114
|
+
const rest = trimmed.slice(2).trim();
|
|
115
|
+
const colonIdx = rest.indexOf(':');
|
|
116
|
+
if (colonIdx !== -1) {
|
|
117
|
+
const key = rest.slice(0, colonIdx).trim();
|
|
118
|
+
const val = rest.slice(colonIdx + 1).trim();
|
|
119
|
+
applyRuleField(currentRule, key, val);
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// Continuation of branches array
|
|
124
|
+
if (inBranches && trimmed.startsWith('- ') && currentRule) {
|
|
125
|
+
currentRule.branches = currentRule.branches || [];
|
|
126
|
+
currentRule.branches.push(trimQuotes(trimmed.slice(2).trim()));
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
// Rule property
|
|
130
|
+
if (currentRule) {
|
|
131
|
+
inBranches = false;
|
|
132
|
+
const colonIdx = trimmed.indexOf(':');
|
|
133
|
+
if (colonIdx !== -1) {
|
|
134
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
135
|
+
const val = trimmed.slice(colonIdx + 1).trim();
|
|
136
|
+
if (key === 'branches' && !val) {
|
|
137
|
+
inBranches = true;
|
|
138
|
+
currentRule.branches = [];
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
applyRuleField(currentRule, key, val);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (currentRule)
|
|
147
|
+
rules.push(currentRule);
|
|
148
|
+
if (rules.length > 0)
|
|
149
|
+
result.rules = rules;
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function applyRuleField(rule, key, val) {
|
|
153
|
+
switch (key) {
|
|
154
|
+
case 'action':
|
|
155
|
+
rule.action = trimQuotes(val);
|
|
156
|
+
break;
|
|
157
|
+
case 'effect':
|
|
158
|
+
rule.effect = trimQuotes(val);
|
|
159
|
+
break;
|
|
160
|
+
case 'target':
|
|
161
|
+
rule.target = trimQuotes(val);
|
|
162
|
+
break;
|
|
163
|
+
case 'reason':
|
|
164
|
+
rule.reason = trimQuotes(val);
|
|
165
|
+
break;
|
|
166
|
+
case 'limit': {
|
|
167
|
+
const n = parseValue(val);
|
|
168
|
+
if (typeof n === 'number')
|
|
169
|
+
rule.limit = n;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case 'requireTests':
|
|
173
|
+
rule.requireTests = val === 'true';
|
|
174
|
+
break;
|
|
175
|
+
case 'branches': {
|
|
176
|
+
const arr = parseInlineArray(val);
|
|
177
|
+
if (arr.length > 0)
|
|
178
|
+
rule.branches = arr;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function convertRule(yamlRule) {
|
|
184
|
+
const conditions = {};
|
|
185
|
+
let hasConditions = false;
|
|
186
|
+
if (yamlRule.target) {
|
|
187
|
+
conditions.scope = [yamlRule.target];
|
|
188
|
+
hasConditions = true;
|
|
189
|
+
}
|
|
190
|
+
if (yamlRule.branches) {
|
|
191
|
+
conditions.branches = yamlRule.branches;
|
|
192
|
+
hasConditions = true;
|
|
193
|
+
}
|
|
194
|
+
if (yamlRule.limit !== undefined) {
|
|
195
|
+
conditions.limit = yamlRule.limit;
|
|
196
|
+
hasConditions = true;
|
|
197
|
+
}
|
|
198
|
+
if (yamlRule.requireTests !== undefined) {
|
|
199
|
+
conditions.requireTests = yamlRule.requireTests;
|
|
200
|
+
hasConditions = true;
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
action: yamlRule.action || '*',
|
|
204
|
+
effect: yamlRule.effect || 'deny',
|
|
205
|
+
conditions: hasConditions ? conditions : undefined,
|
|
206
|
+
reason: yamlRule.reason,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export function loadYamlPolicy(yaml, defaultId) {
|
|
210
|
+
const def = parseYamlPolicy(yaml);
|
|
211
|
+
return {
|
|
212
|
+
id: def.id || defaultId || 'yaml-policy',
|
|
213
|
+
name: def.name || 'YAML Policy',
|
|
214
|
+
description: def.description,
|
|
215
|
+
rules: (def.rules || []).map(convertRule),
|
|
216
|
+
severity: def.severity ?? 3,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export function loadYamlPolicies(yaml) {
|
|
220
|
+
return [loadYamlPolicy(yaml)];
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=yaml-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-loader.js","sourceRoot":"","sources":["../../src/policy/yaml-loader.ts"],"names":[],"mappings":"AAAA,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AI,CAAC;IACvB,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACjC,UAAU,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAClC,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACxC,UAAU,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;QAChD,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,GAAG;QAC9B,MAAM,EAAG,QAAQ,CAAC,MAA2B,IAAI,MAAM;QACvD,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;QAClD,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,SAAkB;IAC7D,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,SAAS,IAAI,aAAa;QACxC,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,aAAa;QAC/B,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC;QACzC,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,CAAC;KAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { GovernanceRenderer, RendererConfig, RunSummary } from './types.js';
|
|
2
|
+
export { createRendererRegistry } from './registry.js';
|
|
3
|
+
export type { RendererRegistry } from './registry.js';
|
|
4
|
+
export { createTuiRenderer } from './tui-renderer.js';
|
|
5
|
+
export type { TuiRendererOptions } from './tui-renderer.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderers/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/renderers/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAItD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { GovernanceRenderer, RendererConfig, RunSummary } from './types.js';
|
|
2
|
+
import type { KernelResult } from '../kernel/kernel.js';
|
|
3
|
+
import type { MonitorDecision } from '../kernel/monitor.js';
|
|
4
|
+
import type { GovernanceDecisionRecord } from '../kernel/decisions/types.js';
|
|
5
|
+
import type { SimulationResult } from '../kernel/simulation/types.js';
|
|
6
|
+
export interface RendererRegistry {
|
|
7
|
+
/** Register a renderer. Throws if a renderer with the same ID already exists. */
|
|
8
|
+
register(renderer: GovernanceRenderer): void;
|
|
9
|
+
/** Unregister a renderer by ID. Calls dispose() if available. Returns true if found. */
|
|
10
|
+
unregister(id: string): boolean;
|
|
11
|
+
/** Get a registered renderer by ID */
|
|
12
|
+
get(id: string): GovernanceRenderer | undefined;
|
|
13
|
+
/** List all registered renderer IDs */
|
|
14
|
+
list(): string[];
|
|
15
|
+
/** Number of registered renderers */
|
|
16
|
+
count(): number;
|
|
17
|
+
/** Dispatch: run started */
|
|
18
|
+
notifyRunStarted(config: RendererConfig): void;
|
|
19
|
+
/** Dispatch: action result */
|
|
20
|
+
notifyActionResult(result: KernelResult): void;
|
|
21
|
+
/** Dispatch: monitor status */
|
|
22
|
+
notifyMonitorStatus(decision: MonitorDecision): void;
|
|
23
|
+
/** Dispatch: simulation completed */
|
|
24
|
+
notifySimulation(simulation: SimulationResult): void;
|
|
25
|
+
/** Dispatch: decision record */
|
|
26
|
+
notifyDecisionRecord(record: GovernanceDecisionRecord): void;
|
|
27
|
+
/** Dispatch: run ended */
|
|
28
|
+
notifyRunEnded(summary: RunSummary): void;
|
|
29
|
+
/** Dispose all renderers and clear the registry */
|
|
30
|
+
disposeAll(): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a new renderer registry.
|
|
34
|
+
*
|
|
35
|
+
* Renderers are dispatched in registration order.
|
|
36
|
+
* Errors in one renderer do not prevent other renderers from receiving events.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createRendererRegistry(): RendererRegistry;
|
|
39
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/renderers/registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE7C,wFAAwF;IACxF,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAEhC,sCAAsC;IACtC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAAC;IAEhD,uCAAuC;IACvC,IAAI,IAAI,MAAM,EAAE,CAAC;IAEjB,qCAAqC;IACrC,KAAK,IAAI,MAAM,CAAC;IAEhB,4BAA4B;IAC5B,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAE/C,8BAA8B;IAC9B,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAE/C,+BAA+B;IAC/B,mBAAmB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAErD,qCAAqC;IACrC,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAErD,gCAAgC;IAChC,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAE7D,0BAA0B;IAC1B,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IAE1C,mDAAmD;IACnD,UAAU,IAAI,IAAI,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAkGzD"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Renderer registry — manages multiple governance renderers.
|
|
2
|
+
// Dispatches lifecycle events to all registered renderers.
|
|
3
|
+
/**
|
|
4
|
+
* Create a new renderer registry.
|
|
5
|
+
*
|
|
6
|
+
* Renderers are dispatched in registration order.
|
|
7
|
+
* Errors in one renderer do not prevent other renderers from receiving events.
|
|
8
|
+
*/
|
|
9
|
+
export function createRendererRegistry() {
|
|
10
|
+
const renderers = new Map();
|
|
11
|
+
const safeCall = (fn) => {
|
|
12
|
+
try {
|
|
13
|
+
fn();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// Renderer errors are non-fatal — isolate failures
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
register(renderer) {
|
|
21
|
+
if (renderers.has(renderer.id)) {
|
|
22
|
+
throw new Error(`Renderer already registered: "${renderer.id}"`);
|
|
23
|
+
}
|
|
24
|
+
renderers.set(renderer.id, renderer);
|
|
25
|
+
},
|
|
26
|
+
unregister(id) {
|
|
27
|
+
const renderer = renderers.get(id);
|
|
28
|
+
if (!renderer)
|
|
29
|
+
return false;
|
|
30
|
+
if (renderer.dispose) {
|
|
31
|
+
safeCall(() => renderer.dispose());
|
|
32
|
+
}
|
|
33
|
+
renderers.delete(id);
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
get(id) {
|
|
37
|
+
return renderers.get(id);
|
|
38
|
+
},
|
|
39
|
+
list() {
|
|
40
|
+
return [...renderers.keys()];
|
|
41
|
+
},
|
|
42
|
+
count() {
|
|
43
|
+
return renderers.size;
|
|
44
|
+
},
|
|
45
|
+
notifyRunStarted(config) {
|
|
46
|
+
for (const renderer of renderers.values()) {
|
|
47
|
+
if (renderer.onRunStarted) {
|
|
48
|
+
safeCall(() => renderer.onRunStarted(config));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
notifyActionResult(result) {
|
|
53
|
+
for (const renderer of renderers.values()) {
|
|
54
|
+
if (renderer.onActionResult) {
|
|
55
|
+
safeCall(() => renderer.onActionResult(result));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
notifyMonitorStatus(decision) {
|
|
60
|
+
for (const renderer of renderers.values()) {
|
|
61
|
+
if (renderer.onMonitorStatus) {
|
|
62
|
+
safeCall(() => renderer.onMonitorStatus(decision));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
notifySimulation(simulation) {
|
|
67
|
+
for (const renderer of renderers.values()) {
|
|
68
|
+
if (renderer.onSimulation) {
|
|
69
|
+
safeCall(() => renderer.onSimulation(simulation));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
notifyDecisionRecord(record) {
|
|
74
|
+
for (const renderer of renderers.values()) {
|
|
75
|
+
if (renderer.onDecisionRecord) {
|
|
76
|
+
safeCall(() => renderer.onDecisionRecord(record));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
notifyRunEnded(summary) {
|
|
81
|
+
for (const renderer of renderers.values()) {
|
|
82
|
+
if (renderer.onRunEnded) {
|
|
83
|
+
safeCall(() => renderer.onRunEnded(summary));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
disposeAll() {
|
|
88
|
+
for (const renderer of renderers.values()) {
|
|
89
|
+
if (renderer.dispose) {
|
|
90
|
+
safeCall(() => renderer.dispose());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
renderers.clear();
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/renderers/registry.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,2DAA2D;AA8C3D;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,SAAS,GAAG,IAAI,GAAG,EAA8B,CAAC;IAExD,MAAM,QAAQ,GAAG,CAAC,EAAc,EAAQ,EAAE;QACxC,IAAI,CAAC;YACH,EAAE,EAAE,CAAC;QACP,CAAC;QAAC,MAAM,CAAC;YACP,mDAAmD;QACrD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,QAAQ,CAAC,QAAQ;YACf,IAAI,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC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B,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAQ,EAAE,CAAC,CAAC;gBACtC,CAAC;YACH,CAAC;YACD,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GovernanceRenderer } from './types.js';
|
|
2
|
+
export interface TuiRendererOptions {
|
|
3
|
+
/** Output stream — defaults to process.stderr */
|
|
4
|
+
output?: {
|
|
5
|
+
write(s: string): boolean;
|
|
6
|
+
};
|
|
7
|
+
/** Show verbose output (decision records, reasons) */
|
|
8
|
+
verbose?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a TUI governance renderer.
|
|
12
|
+
*
|
|
13
|
+
* This is the reference implementation of GovernanceRenderer. It adapts
|
|
14
|
+
* the existing tui.ts render functions into the plugin interface, writing
|
|
15
|
+
* ANSI-colored output to the configured stream (stderr by default).
|
|
16
|
+
*/
|
|
17
|
+
export declare function createTuiRenderer(options?: TuiRendererOptions): GovernanceRenderer;
|
|
18
|
+
//# sourceMappingURL=tui-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tui-renderer.d.ts","sourceRoot":"","sources":["../../src/renderers/tui-renderer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAA8B,MAAM,YAAY,CAAC;AAajF,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACvC,sDAAsD;IACtD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,kBAAuB,GAAG,kBAAkB,CAwDtF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// TUI governance renderer — wraps the existing tui.ts render functions
|
|
2
|
+
// into a GovernanceRenderer plugin. Writes ANSI-colored output to a stream.
|
|
3
|
+
import { renderBanner, renderKernelResult, renderMonitorStatus, renderDecisionRecord, renderSimulation, } from '../cli/tui.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a TUI governance renderer.
|
|
6
|
+
*
|
|
7
|
+
* This is the reference implementation of GovernanceRenderer. It adapts
|
|
8
|
+
* the existing tui.ts render functions into the plugin interface, writing
|
|
9
|
+
* ANSI-colored output to the configured stream (stderr by default).
|
|
10
|
+
*/
|
|
11
|
+
export function createTuiRenderer(options = {}) {
|
|
12
|
+
const output = options.output ?? process.stderr;
|
|
13
|
+
const verbose = options.verbose ?? false;
|
|
14
|
+
return {
|
|
15
|
+
id: 'tui',
|
|
16
|
+
name: 'Terminal UI Renderer',
|
|
17
|
+
onRunStarted(config) {
|
|
18
|
+
output.write(renderBanner({
|
|
19
|
+
policyName: config.policyName,
|
|
20
|
+
invariantCount: config.invariantCount,
|
|
21
|
+
verbose: config.verbose ?? verbose,
|
|
22
|
+
}));
|
|
23
|
+
output.write(` \x1b[2mrun: ${config.runId}\x1b[0m\n`);
|
|
24
|
+
if (config.simulatorCount && config.simulatorCount > 0) {
|
|
25
|
+
output.write(` \x1b[2msimulators: ${config.simulatorCount} active\x1b[0m\n`);
|
|
26
|
+
}
|
|
27
|
+
output.write('\n');
|
|
28
|
+
},
|
|
29
|
+
onActionResult(result) {
|
|
30
|
+
output.write(renderKernelResult(result, verbose) + '\n');
|
|
31
|
+
if (result.decision.violations.length > 0 || !result.allowed) {
|
|
32
|
+
output.write(renderMonitorStatus(result.decision) + '\n');
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
onMonitorStatus(decision) {
|
|
36
|
+
output.write(renderMonitorStatus(decision) + '\n');
|
|
37
|
+
},
|
|
38
|
+
onSimulation(simulation) {
|
|
39
|
+
output.write(renderSimulation(simulation) + '\n');
|
|
40
|
+
},
|
|
41
|
+
onDecisionRecord(record) {
|
|
42
|
+
if (verbose) {
|
|
43
|
+
output.write(renderDecisionRecord(record) + '\n');
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
onRunEnded(summary) {
|
|
47
|
+
const lines = [];
|
|
48
|
+
lines.push('');
|
|
49
|
+
lines.push(` \x1b[1m\x1b[36mRun Complete\x1b[0m \x1b[2m${summary.runId}\x1b[0m`);
|
|
50
|
+
lines.push(` \x1b[2mactions: ${summary.totalActions} | allowed: ${summary.allowed} | denied: ${summary.denied} | violations: ${summary.violations}\x1b[0m`);
|
|
51
|
+
lines.push(` \x1b[2mduration: ${summary.durationMs}ms\x1b[0m`);
|
|
52
|
+
lines.push('');
|
|
53
|
+
output.write(lines.join('\n'));
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=tui-renderer.js.map
|