@codapult/guard 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +290 -0
  3. package/dist/adapters/agents/agent-integration.d.ts +9 -0
  4. package/dist/adapters/agents/agent-integration.js +62 -0
  5. package/dist/adapters/command.d.ts +21 -0
  6. package/dist/adapters/command.js +60 -0
  7. package/dist/adapters/project-checks.d.ts +37 -0
  8. package/dist/adapters/project-checks.js +149 -0
  9. package/dist/cli/commands/guard.d.ts +55 -0
  10. package/dist/cli/commands/guard.js +510 -0
  11. package/dist/cli/index.d.ts +2 -0
  12. package/dist/cli/index.js +75 -0
  13. package/dist/cli/ui.d.ts +6 -0
  14. package/dist/cli/ui.js +7 -0
  15. package/dist/commands/guard.d.ts +2 -0
  16. package/dist/commands/guard.js +2 -0
  17. package/dist/core/analysis/doctor.d.ts +12 -0
  18. package/dist/core/analysis/doctor.js +85 -0
  19. package/dist/core/analysis/packs.d.ts +21 -0
  20. package/dist/core/analysis/packs.js +251 -0
  21. package/dist/core/config.d.ts +6 -0
  22. package/dist/core/config.js +6 -0
  23. package/dist/core/discovery/discovery.d.ts +134 -0
  24. package/dist/core/discovery/discovery.js +816 -0
  25. package/dist/core/guard.d.ts +189 -0
  26. package/dist/core/guard.js +936 -0
  27. package/dist/core/history/history.d.ts +24 -0
  28. package/dist/core/history/history.js +65 -0
  29. package/dist/core/output/sarif.d.ts +35 -0
  30. package/dist/core/output/sarif.js +29 -0
  31. package/dist/core/policy/schemas.d.ts +272 -0
  32. package/dist/core/policy/schemas.js +72 -0
  33. package/dist/core/verification/verify.d.ts +29 -0
  34. package/dist/core/verification/verify.js +77 -0
  35. package/dist/index.d.ts +10 -0
  36. package/dist/index.js +9 -0
  37. package/dist/mcp/prompts.d.ts +2 -0
  38. package/dist/mcp/prompts.js +54 -0
  39. package/dist/mcp/resources.d.ts +2 -0
  40. package/dist/mcp/resources.js +64 -0
  41. package/dist/mcp/server.d.ts +1 -0
  42. package/dist/mcp/server.js +17 -0
  43. package/dist/mcp/tools/guard.d.ts +2 -0
  44. package/dist/mcp/tools/guard.js +375 -0
  45. package/package.json +117 -0
@@ -0,0 +1,189 @@
1
+ import type { ProjectModel } from './discovery/discovery.js';
2
+ import { discoverProject, discoverProjectWithMetrics, findGuardRoot } from './discovery/discovery.js';
3
+ export type GuardSeverity = 'error' | 'warning' | 'info';
4
+ export type GuardOutcomeStatus = 'pass' | 'fail' | 'warning' | 'needs-review' | 'not-configured';
5
+ export declare function classifyGuardOutcome(input: {
6
+ configured?: boolean;
7
+ errors?: number;
8
+ warnings?: number;
9
+ needsReview?: boolean;
10
+ }): GuardOutcomeStatus;
11
+ export type GuardRuleKind = 'forbidden-import' | 'client-forbidden-import';
12
+ export type GuardRuleStatus = 'active' | 'proposed';
13
+ export type GuardContractKind = 'guidance' | 'import-boundary' | 'required-call';
14
+ export interface GuardContract {
15
+ id: string;
16
+ statement: string;
17
+ kind?: GuardContractKind;
18
+ severity?: GuardSeverity;
19
+ scope?: string[];
20
+ entrypoints?: string[];
21
+ exclude?: string[];
22
+ guidance?: string[];
23
+ references?: string[];
24
+ mustImport?: string[];
25
+ mustNotImport?: string[];
26
+ mustCall?: string[];
27
+ status?: GuardRuleStatus;
28
+ confidence?: 'high' | 'medium' | 'low';
29
+ evidence?: string[];
30
+ }
31
+ export interface GuardRule {
32
+ id: string;
33
+ description: string;
34
+ severity: GuardSeverity;
35
+ kind: GuardRuleKind;
36
+ patterns: string[];
37
+ files?: string[];
38
+ status?: GuardRuleStatus;
39
+ confidence?: 'high' | 'medium' | 'low';
40
+ evidence?: string[];
41
+ }
42
+ export interface GuardConfig {
43
+ version: 1;
44
+ rules: GuardRule[];
45
+ contracts?: GuardContract[];
46
+ }
47
+ export interface GuardProposalFile {
48
+ version: 1;
49
+ generatedAt: string;
50
+ proposalId?: string;
51
+ projectFingerprint?: string;
52
+ revision?: number;
53
+ contentFingerprint?: string;
54
+ rules: GuardRule[];
55
+ contracts: GuardContract[];
56
+ questions: string[];
57
+ decisions?: GuardProposalDecision[];
58
+ }
59
+ export interface GuardProposalDecision {
60
+ id: string;
61
+ type: 'rule' | 'contract';
62
+ decision: 'approved' | 'rejected';
63
+ decidedAt: string;
64
+ proposalId?: string;
65
+ proposalFingerprint?: string;
66
+ revision?: number;
67
+ }
68
+ export type GuardProposalFreshness = 'current' | 'stale' | 'unknown';
69
+ export interface GuardAgentConfig {
70
+ version: 1;
71
+ tools: GuardToolMode;
72
+ tooling: Partial<Record<GuardAdapterName, {
73
+ script: string;
74
+ enabled: boolean;
75
+ }>>;
76
+ completionGate: {
77
+ enabled: boolean;
78
+ maxIterations: number;
79
+ projectChecks: boolean;
80
+ checks: ('lint' | 'typecheck' | 'test' | 'build')[];
81
+ };
82
+ }
83
+ export type GuardToolMode = 'auto' | 'on' | 'off';
84
+ export type GuardAdapterName = 'dependency-graph' | 'security' | 'dependency-hygiene';
85
+ export interface GuardFinding {
86
+ ruleId: string;
87
+ severity: GuardSeverity;
88
+ file: string;
89
+ line: number;
90
+ importPath: string;
91
+ message: string;
92
+ fingerprint: string;
93
+ }
94
+ export interface GuardContractIssue {
95
+ contractId: string;
96
+ field: 'scope' | 'reference' | 'definition';
97
+ value: string;
98
+ message: string;
99
+ }
100
+ export interface GuardReport {
101
+ configured: boolean;
102
+ findings: GuardFinding[];
103
+ suppressed: number;
104
+ scannedFiles: number;
105
+ }
106
+ interface ScanGuardOptions {
107
+ changedOnly?: boolean;
108
+ changedFiles?: Set<string>;
109
+ baseline?: Set<string>;
110
+ includeArchitectureInsights?: boolean;
111
+ }
112
+ export interface GuardReviewPacket {
113
+ version: 1;
114
+ outcome: GuardOutcomeStatus;
115
+ diffBase?: string;
116
+ changedFiles: string[];
117
+ diff: string;
118
+ truncated: boolean;
119
+ redacted: boolean;
120
+ diffError?: string;
121
+ project: ProjectModel;
122
+ contracts: GuardContract[];
123
+ requirement?: string;
124
+ deterministicFindings: GuardFinding[];
125
+ reviewInstructions: string[];
126
+ }
127
+ export declare const GUARD_DIR: string;
128
+ export declare const GUARD_RULES_FILE: string;
129
+ export declare const GUARD_BASELINE_FILE: string;
130
+ export declare const GUARD_BASELINE_META_FILE: string;
131
+ export declare const GUARD_PROJECT_FILE: string;
132
+ export declare const GUARD_HISTORY_DIR: string;
133
+ export declare const GUARD_ARCHITECTURE_FILE: string;
134
+ export declare const GUARD_CONVENTIONS_FILE: string;
135
+ export declare const GUARD_AGENT_FILE: string;
136
+ export declare const GUARD_CONTRACTS_FILE: string;
137
+ export declare const GUARD_PROPOSALS_FILE: string;
138
+ export declare const defaultGuardConfig: GuardConfig;
139
+ export declare const defaultGuardAgentConfig: GuardAgentConfig;
140
+ export declare class GuardAlreadyInitializedError extends Error {
141
+ constructor();
142
+ }
143
+ export declare function isGuardContractsFile(value: unknown): value is {
144
+ version: 1;
145
+ contracts: GuardContract[];
146
+ };
147
+ export declare function isGuardProposalFile(value: unknown): value is GuardProposalFile;
148
+ export declare function fingerprintProjectModel(model: ProjectModel): string;
149
+ export declare function getGuardProposalFreshness(model: ProjectModel, proposals: GuardProposalFile | undefined): GuardProposalFreshness;
150
+ export declare function loadGuardConfig(root: string): GuardConfig | undefined;
151
+ export declare function loadGuardProposals(root: string): GuardProposalFile | undefined;
152
+ export declare function isGuardAgentConfig(value: unknown): value is GuardAgentConfig;
153
+ export declare function loadGuardAgentConfig(root: string): GuardAgentConfig;
154
+ export declare function writeGuardAgentConfig(root: string, agentConfig?: GuardAgentConfig): void;
155
+ export declare function loadGuardArtifact(root: string, relativePath: string): unknown;
156
+ export declare function loadBaseline(root: string): Set<string>;
157
+ export declare function updateBaseline(root: string, options?: {
158
+ add?: string[];
159
+ remove?: string[];
160
+ reason?: string;
161
+ }): Set<string>;
162
+ export declare function writeGuardConfig(root: string, guardConfig: GuardConfig): void;
163
+ export declare function writeGuardProposals(root: string, proposals: GuardProposalFile): void;
164
+ export declare function recordGuardProposalDecision(root: string, decisions: Pick<GuardProposalDecision, 'id' | 'type' | 'decision'>[]): void;
165
+ export declare function buildGuardProposals(model: ProjectModel, guardConfig: GuardConfig): GuardProposalFile;
166
+ export declare function buildArchitectureMemory(model: ProjectModel): Record<string, unknown>;
167
+ export declare function buildConventionsMemory(model: ProjectModel): Record<string, unknown>;
168
+ export declare function buildGeneratedGuardConfig(model: ProjectModel): GuardConfig;
169
+ export declare function writeGuardMemory(root: string, model: ProjectModel): void;
170
+ export declare function writeBaseline(root: string, findings: GuardFinding[], model?: ProjectModel): void;
171
+ export declare function loadProjectModel(root: string): ProjectModel | undefined;
172
+ export declare function writeProjectModel(root: string, model: ProjectModel): void;
173
+ export declare function writeProjectSnapshot(root: string, model: ProjectModel): string;
174
+ export declare function validateGuardContracts(root: string, contracts?: GuardContract[]): GuardContractIssue[];
175
+ /** @internal Redacts common credential shapes before a diff enters an AI review packet. */
176
+ export declare function redactSensitiveText(value: string): {
177
+ value: string;
178
+ redacted: boolean;
179
+ redactionCount: number;
180
+ };
181
+ export declare function scanGuard(root: string, guardConfig: GuardConfig, options?: ScanGuardOptions): GuardReport;
182
+ export declare function buildGuardReviewPacket(root: string, guardConfig: GuardConfig, baseline?: Set<string>, maxDiffChars?: number, changedOnly?: boolean, requirement?: string, base?: string): GuardReviewPacket;
183
+ export declare function initializeGuard(root: string, options?: {
184
+ force?: boolean;
185
+ }): {
186
+ config: GuardConfig;
187
+ report: GuardReport;
188
+ };
189
+ export { discoverProject, discoverProjectWithMetrics, findGuardRoot };