guardrail-compliance 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/dist/audit/emitter.d.ts +97 -0
- package/dist/audit/emitter.d.ts.map +1 -0
- package/dist/audit/emitter.js +197 -0
- package/dist/audit/events.d.ts +304 -0
- package/dist/audit/events.d.ts.map +1 -0
- package/dist/audit/events.js +267 -0
- package/dist/audit/index.d.ts +11 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +51 -0
- package/dist/audit/storage.d.ts +93 -0
- package/dist/audit/storage.d.ts.map +1 -0
- package/dist/audit/storage.js +337 -0
- package/dist/automation/__tests__/compliance-scheduler.test.d.ts +2 -0
- package/dist/automation/__tests__/compliance-scheduler.test.d.ts.map +1 -0
- package/dist/automation/__tests__/compliance-scheduler.test.js +140 -0
- package/dist/automation/audit-logger.d.ts +129 -0
- package/dist/automation/audit-logger.d.ts.map +1 -0
- package/dist/automation/audit-logger.js +473 -0
- package/dist/automation/compliance-scheduler-fixed.d.ts +1 -0
- package/dist/automation/compliance-scheduler-fixed.d.ts.map +1 -0
- package/dist/automation/compliance-scheduler-fixed.js +1 -0
- package/dist/automation/compliance-scheduler.d.ts +83 -0
- package/dist/automation/compliance-scheduler.d.ts.map +1 -0
- package/dist/automation/compliance-scheduler.js +414 -0
- package/dist/automation/dashboard.d.ts +194 -0
- package/dist/automation/dashboard.d.ts.map +1 -0
- package/dist/automation/dashboard.js +768 -0
- package/dist/automation/email-service.d.ts +69 -0
- package/dist/automation/email-service.d.ts.map +1 -0
- package/dist/automation/email-service.js +218 -0
- package/dist/automation/evidence-collector.d.ts +140 -0
- package/dist/automation/evidence-collector.d.ts.map +1 -0
- package/dist/automation/evidence-collector.js +682 -0
- package/dist/automation/index.d.ts +8 -0
- package/dist/automation/index.d.ts.map +1 -0
- package/dist/automation/index.js +24 -0
- package/dist/automation/pdf-exporter.d.ts +90 -0
- package/dist/automation/pdf-exporter.d.ts.map +1 -0
- package/dist/automation/pdf-exporter.js +381 -0
- package/dist/automation/reporting-engine.d.ts +116 -0
- package/dist/automation/reporting-engine.d.ts.map +1 -0
- package/dist/automation/reporting-engine.js +329 -0
- package/dist/container/index.d.ts +4 -0
- package/dist/container/index.d.ts.map +1 -0
- package/dist/container/index.js +19 -0
- package/dist/container/kubernetes.d.ts +94 -0
- package/dist/container/kubernetes.d.ts.map +1 -0
- package/dist/container/kubernetes.js +268 -0
- package/dist/container/rules.d.ts +27 -0
- package/dist/container/rules.d.ts.map +1 -0
- package/dist/container/rules.js +216 -0
- package/dist/container/scanner.d.ts +50 -0
- package/dist/container/scanner.d.ts.map +1 -0
- package/dist/container/scanner.js +143 -0
- package/dist/frameworks/engine.d.ts +108 -0
- package/dist/frameworks/engine.d.ts.map +1 -0
- package/dist/frameworks/engine.js +206 -0
- package/dist/frameworks/gdpr.d.ts +6 -0
- package/dist/frameworks/gdpr.d.ts.map +1 -0
- package/dist/frameworks/gdpr.js +198 -0
- package/dist/frameworks/hipaa.d.ts +6 -0
- package/dist/frameworks/hipaa.d.ts.map +1 -0
- package/dist/frameworks/hipaa.js +183 -0
- package/dist/frameworks/index.d.ts +8 -0
- package/dist/frameworks/index.d.ts.map +1 -0
- package/dist/frameworks/index.js +30 -0
- package/dist/frameworks/iso27001.d.ts +63 -0
- package/dist/frameworks/iso27001.d.ts.map +1 -0
- package/dist/frameworks/iso27001.js +331 -0
- package/dist/frameworks/nist.d.ts +62 -0
- package/dist/frameworks/nist.d.ts.map +1 -0
- package/dist/frameworks/nist.js +424 -0
- package/dist/frameworks/pci.d.ts +6 -0
- package/dist/frameworks/pci.d.ts.map +1 -0
- package/dist/frameworks/pci.js +201 -0
- package/dist/frameworks/soc2.d.ts +7 -0
- package/dist/frameworks/soc2.d.ts.map +1 -0
- package/dist/frameworks/soc2.js +248 -0
- package/dist/iac/drift-detector.d.ts +64 -0
- package/dist/iac/drift-detector.d.ts.map +1 -0
- package/dist/iac/drift-detector.js +134 -0
- package/dist/iac/index.d.ts +4 -0
- package/dist/iac/index.d.ts.map +1 -0
- package/dist/iac/index.js +19 -0
- package/dist/iac/rules.d.ts +17 -0
- package/dist/iac/rules.d.ts.map +1 -0
- package/dist/iac/rules.js +385 -0
- package/dist/iac/scanner.d.ts +104 -0
- package/dist/iac/scanner.d.ts.map +1 -0
- package/dist/iac/scanner.js +343 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/pii/data-flow.d.ts +58 -0
- package/dist/pii/data-flow.d.ts.map +1 -0
- package/dist/pii/data-flow.js +154 -0
- package/dist/pii/detector.d.ts +60 -0
- package/dist/pii/detector.d.ts.map +1 -0
- package/dist/pii/detector.js +267 -0
- package/dist/pii/index.d.ts +4 -0
- package/dist/pii/index.d.ts.map +1 -0
- package/dist/pii/index.js +19 -0
- package/dist/pii/patterns.d.ts +36 -0
- package/dist/pii/patterns.d.ts.map +1 -0
- package/dist/pii/patterns.js +108 -0
- package/dist/policy/index.d.ts +5 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +20 -0
- package/dist/policy/opa-engine.d.ts +121 -0
- package/dist/policy/opa-engine.d.ts.map +1 -0
- package/dist/policy/opa-engine.js +423 -0
- package/package.json +31 -0
- package/src/audit/emitter.ts +383 -0
- package/src/audit/events.ts +351 -0
- package/src/audit/index.ts +35 -0
- package/src/audit/storage.ts +394 -0
- package/src/automation/__tests__/compliance-scheduler.test.ts +183 -0
- package/src/automation/audit-logger.ts +629 -0
- package/src/automation/compliance-scheduler-fixed.ts +0 -0
- package/src/automation/compliance-scheduler.ts +516 -0
- package/src/automation/dashboard.ts +947 -0
- package/src/automation/email-service.ts +230 -0
- package/src/automation/evidence-collector.ts +866 -0
- package/src/automation/index.ts +8 -0
- package/src/automation/pdf-exporter.ts +434 -0
- package/src/automation/reporting-engine.ts +462 -0
- package/src/container/index.ts +3 -0
- package/src/container/kubernetes.ts +379 -0
- package/src/container/rules.ts +244 -0
- package/src/container/scanner.ts +202 -0
- package/src/frameworks/engine.ts +298 -0
- package/src/frameworks/gdpr.ts +204 -0
- package/src/frameworks/hipaa.ts +209 -0
- package/src/frameworks/index.ts +23 -0
- package/src/frameworks/iso27001.ts +398 -0
- package/src/frameworks/nist.ts +518 -0
- package/src/frameworks/pci.ts +226 -0
- package/src/frameworks/soc2.ts +281 -0
- package/src/iac/drift-detector.ts +197 -0
- package/src/iac/index.ts +3 -0
- package/src/iac/rules.ts +420 -0
- package/src/iac/scanner.ts +445 -0
- package/src/index.ts +17 -0
- package/src/pii/data-flow.ts +216 -0
- package/src/pii/detector.ts +327 -0
- package/src/pii/index.ts +3 -0
- package/src/pii/patterns.ts +128 -0
- package/src/policy/index.ts +5 -0
- package/src/policy/opa-engine.ts +504 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Trail Emitter
|
|
3
|
+
*
|
|
4
|
+
* Central audit event emission with tier-gating.
|
|
5
|
+
* Usage: audit.emit(eventInput) from CLI, MCP, VS Code, etc.
|
|
6
|
+
*/
|
|
7
|
+
import { AuditEvent, AuditEventInput, AuditSurface, AuditActionCategory, AuditResult, AuditTier, AuditEventMetadata } from './events';
|
|
8
|
+
import { AuditStorageAdapter } from './storage';
|
|
9
|
+
interface AuditConfig {
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
tier: AuditTier;
|
|
12
|
+
basePath: string;
|
|
13
|
+
storageType: 'local' | 'server';
|
|
14
|
+
serverUrl?: string;
|
|
15
|
+
serverApiKey?: string;
|
|
16
|
+
actor?: {
|
|
17
|
+
id: string;
|
|
18
|
+
type: 'user' | 'system' | 'ci' | 'api';
|
|
19
|
+
name?: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configure the audit system
|
|
25
|
+
*/
|
|
26
|
+
export declare function configureAudit(config: Partial<AuditConfig>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get or create storage instance
|
|
29
|
+
*/
|
|
30
|
+
declare function getStorage(): AuditStorageAdapter;
|
|
31
|
+
/**
|
|
32
|
+
* Check if full audit trail is available (Compliance+ tier)
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasFullAuditAccess(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Emit an audit event
|
|
37
|
+
*/
|
|
38
|
+
export declare function emit(input: AuditEventInput): Promise<AuditEvent | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Helper to emit with common defaults
|
|
41
|
+
*/
|
|
42
|
+
export declare function emitAction(surface: AuditSurface, action: string, category: AuditActionCategory, target: AuditEvent['target'], result: AuditResult, metadata?: AuditEventMetadata): Promise<AuditEvent | null>;
|
|
43
|
+
export declare function emitScanStart(surface: AuditSurface, projectPath: string, args?: string[]): Promise<AuditEvent | null>;
|
|
44
|
+
export declare function emitScanComplete(surface: AuditSurface, projectPath: string, result: AuditResult, metadata?: {
|
|
45
|
+
score?: number;
|
|
46
|
+
grade?: string;
|
|
47
|
+
issueCount?: number;
|
|
48
|
+
durationMs?: number;
|
|
49
|
+
}): Promise<AuditEvent | null>;
|
|
50
|
+
export declare function emitShipCheck(surface: AuditSurface, projectPath: string, result: AuditResult, metadata?: {
|
|
51
|
+
score?: number;
|
|
52
|
+
grade?: string;
|
|
53
|
+
canShip?: boolean;
|
|
54
|
+
}): Promise<AuditEvent | null>;
|
|
55
|
+
export declare function emitRealityStart(surface: AuditSurface, url: string, flows?: string[]): Promise<AuditEvent | null>;
|
|
56
|
+
export declare function emitRealityComplete(surface: AuditSurface, url: string, result: AuditResult, metadata?: {
|
|
57
|
+
durationMs?: number;
|
|
58
|
+
testsPassed?: number;
|
|
59
|
+
testsFailed?: number;
|
|
60
|
+
}): Promise<AuditEvent | null>;
|
|
61
|
+
export declare function emitAutopilotAction(surface: AuditSurface, action: 'enable' | 'disable' | 'run' | 'report', projectPath: string, result: AuditResult, metadata?: AuditEventMetadata): Promise<AuditEvent | null>;
|
|
62
|
+
export declare function emitFixPlan(surface: AuditSurface, projectPath: string, result: AuditResult, metadata?: {
|
|
63
|
+
fixCount?: number;
|
|
64
|
+
scope?: string;
|
|
65
|
+
}): Promise<AuditEvent | null>;
|
|
66
|
+
export declare function emitFixApply(surface: AuditSurface, projectPath: string, result: AuditResult, metadata?: {
|
|
67
|
+
fixCount?: number;
|
|
68
|
+
filesModified?: number;
|
|
69
|
+
}): Promise<AuditEvent | null>;
|
|
70
|
+
export declare function emitGateCheck(surface: AuditSurface, projectPath: string, passed: boolean, metadata?: {
|
|
71
|
+
policy?: string;
|
|
72
|
+
score?: number;
|
|
73
|
+
}): Promise<AuditEvent | null>;
|
|
74
|
+
export declare function emitToolInvoke(surface: AuditSurface, toolName: string, args: Record<string, unknown>, result: AuditResult, metadata?: AuditEventMetadata): Promise<AuditEvent | null>;
|
|
75
|
+
export declare function emitAuth(surface: AuditSurface, action: 'login' | 'logout' | 'token_refresh', result: AuditResult, metadata?: {
|
|
76
|
+
method?: string;
|
|
77
|
+
}): Promise<AuditEvent | null>;
|
|
78
|
+
export declare const audit: {
|
|
79
|
+
configure: typeof configureAudit;
|
|
80
|
+
emit: typeof emit;
|
|
81
|
+
emitAction: typeof emitAction;
|
|
82
|
+
emitScanStart: typeof emitScanStart;
|
|
83
|
+
emitScanComplete: typeof emitScanComplete;
|
|
84
|
+
emitShipCheck: typeof emitShipCheck;
|
|
85
|
+
emitRealityStart: typeof emitRealityStart;
|
|
86
|
+
emitRealityComplete: typeof emitRealityComplete;
|
|
87
|
+
emitAutopilotAction: typeof emitAutopilotAction;
|
|
88
|
+
emitFixPlan: typeof emitFixPlan;
|
|
89
|
+
emitFixApply: typeof emitFixApply;
|
|
90
|
+
emitGateCheck: typeof emitGateCheck;
|
|
91
|
+
emitToolInvoke: typeof emitToolInvoke;
|
|
92
|
+
emitAuth: typeof emitAuth;
|
|
93
|
+
hasFullAccess: typeof hasFullAuditAccess;
|
|
94
|
+
getStorage: typeof getStorage;
|
|
95
|
+
};
|
|
96
|
+
export default audit;
|
|
97
|
+
//# sourceMappingURL=emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../../src/audit/emitter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,UAAU,EACV,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,SAAS,EACT,kBAAkB,EAGnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,mBAAmB,EAEpB,MAAM,WAAW,CAAC;AAMnB,UAAU,WAAW;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,GAAG,QAAQ,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE;QACN,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,GAAG,KAAK,CAAC;QACvC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAWD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAKjE;AAED;;GAEG;AACH,iBAAS,UAAU,IAAI,mBAAmB,CAUzC;AAaD;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAkCD;;GAEG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAiB7E;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,UAAU,CA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AE,kBAAkB,GAC5B,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAS5B;AAED,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,eAAe,EAC5C,MAAM,EAAE,WAAW,EACnB,QAAQ,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAe5B;AAGD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;CAiBjB,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Audit Trail Emitter
|
|
4
|
+
*
|
|
5
|
+
* Central audit event emission with tier-gating.
|
|
6
|
+
* Usage: audit.emit(eventInput) from CLI, MCP, VS Code, etc.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.audit = void 0;
|
|
10
|
+
exports.configureAudit = configureAudit;
|
|
11
|
+
exports.hasFullAuditAccess = hasFullAuditAccess;
|
|
12
|
+
exports.emit = emit;
|
|
13
|
+
exports.emitAction = emitAction;
|
|
14
|
+
exports.emitScanStart = emitScanStart;
|
|
15
|
+
exports.emitScanComplete = emitScanComplete;
|
|
16
|
+
exports.emitShipCheck = emitShipCheck;
|
|
17
|
+
exports.emitRealityStart = emitRealityStart;
|
|
18
|
+
exports.emitRealityComplete = emitRealityComplete;
|
|
19
|
+
exports.emitAutopilotAction = emitAutopilotAction;
|
|
20
|
+
exports.emitFixPlan = emitFixPlan;
|
|
21
|
+
exports.emitFixApply = emitFixApply;
|
|
22
|
+
exports.emitGateCheck = emitGateCheck;
|
|
23
|
+
exports.emitToolInvoke = emitToolInvoke;
|
|
24
|
+
exports.emitAuth = emitAuth;
|
|
25
|
+
const events_1 = require("./events");
|
|
26
|
+
const storage_1 = require("./storage");
|
|
27
|
+
// Singleton storage instance
|
|
28
|
+
let storageInstance = null;
|
|
29
|
+
const defaultConfig = {
|
|
30
|
+
enabled: true,
|
|
31
|
+
tier: 'free',
|
|
32
|
+
basePath: process.cwd(),
|
|
33
|
+
storageType: 'local',
|
|
34
|
+
};
|
|
35
|
+
let currentConfig = { ...defaultConfig };
|
|
36
|
+
/**
|
|
37
|
+
* Configure the audit system
|
|
38
|
+
*/
|
|
39
|
+
function configureAudit(config) {
|
|
40
|
+
currentConfig = { ...currentConfig, ...config };
|
|
41
|
+
// Reset storage instance if config changed
|
|
42
|
+
storageInstance = null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get or create storage instance
|
|
46
|
+
*/
|
|
47
|
+
function getStorage() {
|
|
48
|
+
if (!storageInstance) {
|
|
49
|
+
storageInstance = (0, storage_1.createStorageAdapter)({
|
|
50
|
+
type: currentConfig.storageType,
|
|
51
|
+
basePath: currentConfig.basePath,
|
|
52
|
+
apiUrl: currentConfig.serverUrl,
|
|
53
|
+
apiKey: currentConfig.serverApiKey,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return storageInstance;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if audit is enabled for the current tier
|
|
60
|
+
*/
|
|
61
|
+
function isAuditEnabled() {
|
|
62
|
+
if (!currentConfig.enabled)
|
|
63
|
+
return false;
|
|
64
|
+
// Minimal logging for free/starter (just basic events, no full trail)
|
|
65
|
+
// Full audit trail requires compliance+ tier
|
|
66
|
+
return true; // Always log something, tier controls detail level
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if full audit trail is available (Compliance+ tier)
|
|
70
|
+
*/
|
|
71
|
+
function hasFullAuditAccess() {
|
|
72
|
+
return ['compliance', 'enterprise', 'unlimited'].includes(currentConfig.tier);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get current actor from config or environment
|
|
76
|
+
*/
|
|
77
|
+
function getCurrentActor() {
|
|
78
|
+
if (currentConfig.actor) {
|
|
79
|
+
return currentConfig.actor;
|
|
80
|
+
}
|
|
81
|
+
const env = process.env;
|
|
82
|
+
// Try to detect from environment
|
|
83
|
+
const userId = env['GUARDRAIL_USER_ID'] || env['USER'] || 'anonymous';
|
|
84
|
+
const userName = env['GUARDRAIL_USER_NAME'] || env['USERNAME'];
|
|
85
|
+
const userEmail = env['GUARDRAIL_USER_EMAIL'];
|
|
86
|
+
// Detect CI environment
|
|
87
|
+
if (env['CI'] || env['GITHUB_ACTIONS'] || env['GITLAB_CI']) {
|
|
88
|
+
return {
|
|
89
|
+
id: env['GITHUB_ACTOR'] || env['GITLAB_USER_LOGIN'] || 'ci-system',
|
|
90
|
+
type: 'ci',
|
|
91
|
+
name: env['GITHUB_ACTOR'] || env['GITLAB_USER_NAME'],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
id: userId,
|
|
96
|
+
type: 'user',
|
|
97
|
+
name: userName,
|
|
98
|
+
email: userEmail,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Emit an audit event
|
|
103
|
+
*/
|
|
104
|
+
async function emit(input) {
|
|
105
|
+
if (!isAuditEnabled()) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const storage = getStorage();
|
|
109
|
+
const prevHash = await storage.getLastHash();
|
|
110
|
+
// Override tier with current config tier (for proper redaction)
|
|
111
|
+
const event = (0, events_1.createAuditEvent)({
|
|
112
|
+
...input,
|
|
113
|
+
tier: currentConfig.tier,
|
|
114
|
+
}, prevHash);
|
|
115
|
+
await storage.append(event);
|
|
116
|
+
return event;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Helper to emit with common defaults
|
|
120
|
+
*/
|
|
121
|
+
async function emitAction(surface, action, category, target, result, metadata) {
|
|
122
|
+
return emit({
|
|
123
|
+
actor: getCurrentActor(),
|
|
124
|
+
surface,
|
|
125
|
+
action,
|
|
126
|
+
category,
|
|
127
|
+
target,
|
|
128
|
+
tier: currentConfig.tier,
|
|
129
|
+
result,
|
|
130
|
+
metadata,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// Convenience methods for common CLI actions
|
|
134
|
+
async function emitScanStart(surface, projectPath, args) {
|
|
135
|
+
return emitAction(surface, events_1.AuditActions.SCAN_START, 'scan', { type: 'project', path: projectPath }, 'success', { command: 'scan', args, projectPath });
|
|
136
|
+
}
|
|
137
|
+
async function emitScanComplete(surface, projectPath, result, metadata) {
|
|
138
|
+
return emitAction(surface, events_1.AuditActions.SCAN_COMPLETE, 'scan', { type: 'project', path: projectPath }, result, { command: 'scan', projectPath, ...metadata });
|
|
139
|
+
}
|
|
140
|
+
async function emitShipCheck(surface, projectPath, result, metadata) {
|
|
141
|
+
return emitAction(surface, events_1.AuditActions.SHIP_CHECK, 'ship', { type: 'project', path: projectPath }, result, { command: 'ship', projectPath, custom: metadata });
|
|
142
|
+
}
|
|
143
|
+
async function emitRealityStart(surface, url, flows) {
|
|
144
|
+
return emitAction(surface, events_1.AuditActions.REALITY_START, 'reality', { type: 'url', path: url }, 'success', { command: 'reality', custom: { url, flows } });
|
|
145
|
+
}
|
|
146
|
+
async function emitRealityComplete(surface, url, result, metadata) {
|
|
147
|
+
return emitAction(surface, events_1.AuditActions.REALITY_COMPLETE, 'reality', { type: 'url', path: url }, result, { command: 'reality', ...metadata });
|
|
148
|
+
}
|
|
149
|
+
async function emitAutopilotAction(surface, action, projectPath, result, metadata) {
|
|
150
|
+
const actionMap = {
|
|
151
|
+
enable: events_1.AuditActions.AUTOPILOT_ENABLE,
|
|
152
|
+
disable: events_1.AuditActions.AUTOPILOT_DISABLE,
|
|
153
|
+
run: events_1.AuditActions.AUTOPILOT_RUN,
|
|
154
|
+
report: events_1.AuditActions.AUTOPILOT_REPORT,
|
|
155
|
+
};
|
|
156
|
+
return emitAction(surface, actionMap[action], 'autopilot', { type: 'project', path: projectPath }, result, { command: 'autopilot', projectPath, ...metadata });
|
|
157
|
+
}
|
|
158
|
+
async function emitFixPlan(surface, projectPath, result, metadata) {
|
|
159
|
+
return emitAction(surface, events_1.AuditActions.FIX_PLAN, 'fix', { type: 'project', path: projectPath }, result, { command: 'fix', projectPath, ...metadata });
|
|
160
|
+
}
|
|
161
|
+
async function emitFixApply(surface, projectPath, result, metadata) {
|
|
162
|
+
return emitAction(surface, events_1.AuditActions.FIX_APPLY, 'fix', { type: 'project', path: projectPath }, result, { command: 'fix', projectPath, ...metadata });
|
|
163
|
+
}
|
|
164
|
+
async function emitGateCheck(surface, projectPath, passed, metadata) {
|
|
165
|
+
return emitAction(surface, passed ? events_1.AuditActions.GATE_PASS : events_1.AuditActions.GATE_FAIL, 'gate', { type: 'project', path: projectPath }, passed ? 'success' : 'failure', { command: 'gate', projectPath, ...metadata });
|
|
166
|
+
}
|
|
167
|
+
async function emitToolInvoke(surface, toolName, args, result, metadata) {
|
|
168
|
+
return emitAction(surface, events_1.AuditActions.TOOL_INVOKE, 'tool', { type: 'tool', name: toolName }, result, { command: toolName, custom: { args }, ...metadata });
|
|
169
|
+
}
|
|
170
|
+
async function emitAuth(surface, action, result, metadata) {
|
|
171
|
+
const actionMap = {
|
|
172
|
+
login: events_1.AuditActions.AUTH_LOGIN,
|
|
173
|
+
logout: events_1.AuditActions.AUTH_LOGOUT,
|
|
174
|
+
token_refresh: events_1.AuditActions.AUTH_TOKEN_REFRESH,
|
|
175
|
+
};
|
|
176
|
+
return emitAction(surface, actionMap[action], 'auth', { type: 'auth' }, result, metadata);
|
|
177
|
+
}
|
|
178
|
+
// Export the audit object for convenient usage
|
|
179
|
+
exports.audit = {
|
|
180
|
+
configure: configureAudit,
|
|
181
|
+
emit,
|
|
182
|
+
emitAction,
|
|
183
|
+
emitScanStart,
|
|
184
|
+
emitScanComplete,
|
|
185
|
+
emitShipCheck,
|
|
186
|
+
emitRealityStart,
|
|
187
|
+
emitRealityComplete,
|
|
188
|
+
emitAutopilotAction,
|
|
189
|
+
emitFixPlan,
|
|
190
|
+
emitFixApply,
|
|
191
|
+
emitGateCheck,
|
|
192
|
+
emitToolInvoke,
|
|
193
|
+
emitAuth,
|
|
194
|
+
hasFullAccess: hasFullAuditAccess,
|
|
195
|
+
getStorage,
|
|
196
|
+
};
|
|
197
|
+
exports.default = exports.audit;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Trail Event Schema
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive audit logging for Compliance+ tier.
|
|
5
|
+
* All events are hash-chained for tamper evidence.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export type AuditSurface = 'cli' | 'vscode' | 'mcp' | 'web' | 'api' | 'ci';
|
|
9
|
+
export type AuditActionCategory = 'scan' | 'ship' | 'reality' | 'autopilot' | 'fix' | 'gate' | 'auth' | 'config' | 'export' | 'ai' | 'tool' | 'system';
|
|
10
|
+
export type AuditResult = 'success' | 'failure' | 'partial' | 'skipped' | 'error';
|
|
11
|
+
export type AuditTier = 'free' | 'starter' | 'pro' | 'compliance' | 'enterprise' | 'unlimited';
|
|
12
|
+
export declare const AuditEventMetadataSchema: z.ZodObject<{
|
|
13
|
+
command: z.ZodOptional<z.ZodString>;
|
|
14
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
15
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
16
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
18
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
21
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
22
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
23
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
25
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
26
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
27
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
28
|
+
command: z.ZodOptional<z.ZodString>;
|
|
29
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
30
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
31
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
33
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
36
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
37
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
38
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
40
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
41
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
42
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
43
|
+
command: z.ZodOptional<z.ZodString>;
|
|
44
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
45
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
46
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
47
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
48
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
51
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
52
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
53
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
54
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
55
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
56
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
57
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
58
|
+
export type AuditEventMetadata = z.infer<typeof AuditEventMetadataSchema>;
|
|
59
|
+
export declare const AuditEventSchema: z.ZodObject<{
|
|
60
|
+
id: z.ZodString;
|
|
61
|
+
timestamp: z.ZodString;
|
|
62
|
+
actor: z.ZodObject<{
|
|
63
|
+
id: z.ZodString;
|
|
64
|
+
type: z.ZodEnum<["user", "system", "ci", "api"]>;
|
|
65
|
+
name: z.ZodOptional<z.ZodString>;
|
|
66
|
+
email: z.ZodOptional<z.ZodString>;
|
|
67
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
type: "api" | "system" | "user" | "ci";
|
|
70
|
+
id: string;
|
|
71
|
+
name?: string | undefined;
|
|
72
|
+
email?: string | undefined;
|
|
73
|
+
ip?: string | undefined;
|
|
74
|
+
}, {
|
|
75
|
+
type: "api" | "system" | "user" | "ci";
|
|
76
|
+
id: string;
|
|
77
|
+
name?: string | undefined;
|
|
78
|
+
email?: string | undefined;
|
|
79
|
+
ip?: string | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
surface: z.ZodEnum<["cli", "vscode", "mcp", "web", "api", "ci"]>;
|
|
82
|
+
action: z.ZodString;
|
|
83
|
+
category: z.ZodEnum<["scan", "ship", "reality", "autopilot", "fix", "gate", "auth", "config", "export", "ai", "tool", "system"]>;
|
|
84
|
+
target: z.ZodObject<{
|
|
85
|
+
type: z.ZodString;
|
|
86
|
+
id: z.ZodOptional<z.ZodString>;
|
|
87
|
+
path: z.ZodOptional<z.ZodString>;
|
|
88
|
+
name: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
type: string;
|
|
91
|
+
name?: string | undefined;
|
|
92
|
+
id?: string | undefined;
|
|
93
|
+
path?: string | undefined;
|
|
94
|
+
}, {
|
|
95
|
+
type: string;
|
|
96
|
+
name?: string | undefined;
|
|
97
|
+
id?: string | undefined;
|
|
98
|
+
path?: string | undefined;
|
|
99
|
+
}>;
|
|
100
|
+
tier: z.ZodEnum<["free", "starter", "pro", "compliance", "enterprise", "unlimited"]>;
|
|
101
|
+
result: z.ZodEnum<["success", "failure", "partial", "skipped", "error"]>;
|
|
102
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
103
|
+
command: z.ZodOptional<z.ZodString>;
|
|
104
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
105
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
106
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
108
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
109
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
110
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
111
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
112
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
113
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
114
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
115
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
116
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
117
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
118
|
+
command: z.ZodOptional<z.ZodString>;
|
|
119
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
120
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
121
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
122
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
123
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
124
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
125
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
126
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
127
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
128
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
129
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
130
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
131
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
132
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
133
|
+
command: z.ZodOptional<z.ZodString>;
|
|
134
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
135
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
136
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
137
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
138
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
139
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
141
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
142
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
143
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
145
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
146
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
147
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
148
|
+
hash: z.ZodString;
|
|
149
|
+
prevHash: z.ZodString;
|
|
150
|
+
version: z.ZodLiteral<1>;
|
|
151
|
+
}, "strip", z.ZodTypeAny, {
|
|
152
|
+
timestamp: string;
|
|
153
|
+
id: string;
|
|
154
|
+
hash: string;
|
|
155
|
+
version: 1;
|
|
156
|
+
actor: {
|
|
157
|
+
type: "api" | "system" | "user" | "ci";
|
|
158
|
+
id: string;
|
|
159
|
+
name?: string | undefined;
|
|
160
|
+
email?: string | undefined;
|
|
161
|
+
ip?: string | undefined;
|
|
162
|
+
};
|
|
163
|
+
surface: "api" | "ci" | "cli" | "vscode" | "mcp" | "web";
|
|
164
|
+
action: string;
|
|
165
|
+
category: "config" | "system" | "auth" | "scan" | "ship" | "reality" | "autopilot" | "fix" | "gate" | "export" | "ai" | "tool";
|
|
166
|
+
target: {
|
|
167
|
+
type: string;
|
|
168
|
+
name?: string | undefined;
|
|
169
|
+
id?: string | undefined;
|
|
170
|
+
path?: string | undefined;
|
|
171
|
+
};
|
|
172
|
+
tier: "compliance" | "free" | "starter" | "pro" | "enterprise" | "unlimited";
|
|
173
|
+
result: "partial" | "error" | "success" | "failure" | "skipped";
|
|
174
|
+
prevHash: string;
|
|
175
|
+
metadata?: z.objectOutputType<{
|
|
176
|
+
command: z.ZodOptional<z.ZodString>;
|
|
177
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
178
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
179
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
180
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
181
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
182
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
183
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
184
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
185
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
186
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
187
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
188
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
189
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
190
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
191
|
+
}, {
|
|
192
|
+
timestamp: string;
|
|
193
|
+
id: string;
|
|
194
|
+
hash: string;
|
|
195
|
+
version: 1;
|
|
196
|
+
actor: {
|
|
197
|
+
type: "api" | "system" | "user" | "ci";
|
|
198
|
+
id: string;
|
|
199
|
+
name?: string | undefined;
|
|
200
|
+
email?: string | undefined;
|
|
201
|
+
ip?: string | undefined;
|
|
202
|
+
};
|
|
203
|
+
surface: "api" | "ci" | "cli" | "vscode" | "mcp" | "web";
|
|
204
|
+
action: string;
|
|
205
|
+
category: "config" | "system" | "auth" | "scan" | "ship" | "reality" | "autopilot" | "fix" | "gate" | "export" | "ai" | "tool";
|
|
206
|
+
target: {
|
|
207
|
+
type: string;
|
|
208
|
+
name?: string | undefined;
|
|
209
|
+
id?: string | undefined;
|
|
210
|
+
path?: string | undefined;
|
|
211
|
+
};
|
|
212
|
+
tier: "compliance" | "free" | "starter" | "pro" | "enterprise" | "unlimited";
|
|
213
|
+
result: "partial" | "error" | "success" | "failure" | "skipped";
|
|
214
|
+
prevHash: string;
|
|
215
|
+
metadata?: z.objectInputType<{
|
|
216
|
+
command: z.ZodOptional<z.ZodString>;
|
|
217
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
218
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
219
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
220
|
+
grade: z.ZodOptional<z.ZodString>;
|
|
221
|
+
issueCount: z.ZodOptional<z.ZodNumber>;
|
|
222
|
+
fixCount: z.ZodOptional<z.ZodNumber>;
|
|
223
|
+
projectPath: z.ZodOptional<z.ZodString>;
|
|
224
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
225
|
+
gitCommit: z.ZodOptional<z.ZodString>;
|
|
226
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
227
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
228
|
+
errorMessage: z.ZodOptional<z.ZodString>;
|
|
229
|
+
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
230
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
231
|
+
}>;
|
|
232
|
+
export type AuditEvent = z.infer<typeof AuditEventSchema>;
|
|
233
|
+
export interface AuditEventInput {
|
|
234
|
+
actor: AuditEvent['actor'];
|
|
235
|
+
surface: AuditSurface;
|
|
236
|
+
action: string;
|
|
237
|
+
category: AuditActionCategory;
|
|
238
|
+
target: AuditEvent['target'];
|
|
239
|
+
tier: AuditTier;
|
|
240
|
+
result: AuditResult;
|
|
241
|
+
metadata?: AuditEventMetadata;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Redact sensitive information from a string
|
|
245
|
+
*/
|
|
246
|
+
export declare function redactSensitive(input: string): string;
|
|
247
|
+
/**
|
|
248
|
+
* Redact metadata based on tier
|
|
249
|
+
* - Compliance+: Full metadata
|
|
250
|
+
* - Pro: Limited metadata (no prompt bodies)
|
|
251
|
+
* - Free/Starter: Minimal (action + result only)
|
|
252
|
+
*/
|
|
253
|
+
export declare function redactMetadataForTier(metadata: AuditEventMetadata | undefined, tier: AuditTier): AuditEventMetadata | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Compute SHA-256 hash of event for chain integrity
|
|
256
|
+
*/
|
|
257
|
+
export declare function computeEventHash(event: Omit<AuditEvent, 'hash'>): string;
|
|
258
|
+
/**
|
|
259
|
+
* Verify hash chain integrity
|
|
260
|
+
*/
|
|
261
|
+
export declare function verifyEventHash(event: AuditEvent): boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Create a new audit event with proper hash chaining
|
|
264
|
+
*/
|
|
265
|
+
export declare function createAuditEvent(input: AuditEventInput, prevHash?: string): AuditEvent;
|
|
266
|
+
export declare const AuditActions: {
|
|
267
|
+
readonly SCAN_START: "scan.start";
|
|
268
|
+
readonly SCAN_COMPLETE: "scan.complete";
|
|
269
|
+
readonly SCAN_ERROR: "scan.error";
|
|
270
|
+
readonly SHIP_CHECK: "ship.check";
|
|
271
|
+
readonly SHIP_APPROVE: "ship.approve";
|
|
272
|
+
readonly SHIP_REJECT: "ship.reject";
|
|
273
|
+
readonly REALITY_START: "reality.start";
|
|
274
|
+
readonly REALITY_COMPLETE: "reality.complete";
|
|
275
|
+
readonly REALITY_ERROR: "reality.error";
|
|
276
|
+
readonly AUTOPILOT_ENABLE: "autopilot.enable";
|
|
277
|
+
readonly AUTOPILOT_DISABLE: "autopilot.disable";
|
|
278
|
+
readonly AUTOPILOT_RUN: "autopilot.run";
|
|
279
|
+
readonly AUTOPILOT_REPORT: "autopilot.report";
|
|
280
|
+
readonly FIX_PLAN: "fix.plan";
|
|
281
|
+
readonly FIX_APPLY: "fix.apply";
|
|
282
|
+
readonly FIX_REVERT: "fix.revert";
|
|
283
|
+
readonly GATE_CHECK: "gate.check";
|
|
284
|
+
readonly GATE_PASS: "gate.pass";
|
|
285
|
+
readonly GATE_FAIL: "gate.fail";
|
|
286
|
+
readonly AUTH_LOGIN: "auth.login";
|
|
287
|
+
readonly AUTH_LOGOUT: "auth.logout";
|
|
288
|
+
readonly AUTH_TOKEN_REFRESH: "auth.token_refresh";
|
|
289
|
+
readonly CONFIG_UPDATE: "config.update";
|
|
290
|
+
readonly CONFIG_RESET: "config.reset";
|
|
291
|
+
readonly EXPORT_REPORT: "export.report";
|
|
292
|
+
readonly EXPORT_AUDIT: "export.audit";
|
|
293
|
+
readonly AI_VALIDATE: "ai.validate";
|
|
294
|
+
readonly AI_SUGGEST: "ai.suggest";
|
|
295
|
+
readonly AI_CHECKPOINT: "ai.checkpoint";
|
|
296
|
+
readonly TOOL_INVOKE: "tool.invoke";
|
|
297
|
+
readonly TOOL_COMPLETE: "tool.complete";
|
|
298
|
+
readonly TOOL_ERROR: "tool.error";
|
|
299
|
+
readonly SYSTEM_INIT: "system.init";
|
|
300
|
+
readonly SYSTEM_UPGRADE: "system.upgrade";
|
|
301
|
+
readonly SYSTEM_ERROR: "system.error";
|
|
302
|
+
};
|
|
303
|
+
export type AuditActionType = typeof AuditActions[keyof typeof AuditActions];
|
|
304
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/audit/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;AAG3E,MAAM,MAAM,mBAAmB,GAC3B,MAAM,GACN,MAAM,GACN,SAAS,GACT,WAAW,GACX,KAAK,GACL,MAAM,GACN,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,IAAI,GACJ,MAAM,GACN,QAAQ,CAAC;AAGb,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAGlF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;AAG/F,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCA0BrB,CAAC;AAEjB,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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