@neurcode-ai/contracts 0.1.2 → 0.1.3
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/admission/framing.d.ts +38 -0
- package/dist/admission/framing.d.ts.map +1 -0
- package/dist/admission/framing.js +78 -0
- package/dist/admission/framing.js.map +1 -0
- package/dist/admission/index.d.ts +4 -0
- package/dist/admission/index.d.ts.map +1 -0
- package/dist/admission/index.js +37 -0
- package/dist/admission/index.js.map +1 -0
- package/dist/admission/privacy.d.ts +23 -0
- package/dist/admission/privacy.d.ts.map +1 -0
- package/dist/admission/privacy.js +99 -0
- package/dist/admission/privacy.js.map +1 -0
- package/dist/admission/schema.d.ts +277 -0
- package/dist/admission/schema.d.ts.map +1 -0
- package/dist/admission/schema.js +156 -0
- package/dist/admission/schema.js.map +1 -0
- package/dist/index.d.ts +91 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +182 -17
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +522 -0
- package/dist/intelligence.d.ts.map +1 -0
- package/dist/intelligence.js +5 -0
- package/dist/intelligence.js.map +1 -0
- package/dist/remediation/capabilities.d.ts +36 -0
- package/dist/remediation/capabilities.d.ts.map +1 -0
- package/dist/remediation/capabilities.js +7 -0
- package/dist/remediation/capabilities.js.map +1 -0
- package/dist/remediation/index.d.ts +5 -0
- package/dist/remediation/index.d.ts.map +1 -0
- package/dist/remediation/index.js +3 -0
- package/dist/remediation/index.js.map +1 -0
- package/dist/remediation/request.d.ts +183 -0
- package/dist/remediation/request.d.ts.map +1 -0
- package/dist/remediation/request.js +15 -0
- package/dist/remediation/request.js.map +1 -0
- package/dist/remediation/response.d.ts +100 -0
- package/dist/remediation/response.d.ts.map +1 -0
- package/dist/remediation/response.js +11 -0
- package/dist/remediation/response.js.map +1 -0
- package/dist/remediation/validation.d.ts +87 -0
- package/dist/remediation/validation.d.ts.map +1 -0
- package/dist/remediation/validation.js +15 -0
- package/dist/remediation/validation.js.map +1 -0
- package/dist/status-vocabulary.d.ts +45 -0
- package/dist/status-vocabulary.d.ts.map +1 -0
- package/dist/status-vocabulary.js +101 -0
- package/dist/status-vocabulary.js.map +1 -0
- package/dist/verification/canonical-finding.d.ts +171 -0
- package/dist/verification/canonical-finding.d.ts.map +1 -0
- package/dist/verification/canonical-finding.js +3 -0
- package/dist/verification/canonical-finding.js.map +1 -0
- package/dist/verification/index.d.ts +6 -0
- package/dist/verification/index.d.ts.map +1 -0
- package/dist/verification/index.js +11 -0
- package/dist/verification/index.js.map +1 -0
- package/dist/verification/pipeline.d.ts +134 -0
- package/dist/verification/pipeline.d.ts.map +1 -0
- package/dist/verification/pipeline.js +57 -0
- package/dist/verification/pipeline.js.map +1 -0
- package/dist/verification/taxonomy.d.ts +10 -0
- package/dist/verification/taxonomy.d.ts.map +1 -0
- package/dist/verification/taxonomy.js +16 -0
- package/dist/verification/taxonomy.js.map +1 -0
- package/package.json +1 -1
- package/src/admission/admission-framing.test.ts +93 -0
- package/src/admission/framing.ts +78 -0
- package/src/admission/index.ts +58 -0
- package/src/admission/privacy.ts +93 -0
- package/src/admission/schema.ts +392 -0
- package/src/index.ts +266 -26
- package/src/intelligence.ts +698 -0
- package/src/remediation/capabilities.ts +53 -0
- package/src/remediation/index.ts +29 -0
- package/src/remediation/request.ts +236 -0
- package/src/remediation/response.ts +129 -0
- package/src/remediation/validation.ts +109 -0
- package/src/status-vocabulary.ts +125 -0
- package/src/verification/canonical-finding.ts +196 -0
- package/src/verification/index.ts +41 -0
- package/src/verification/pipeline.ts +199 -0
- package/src/verification/taxonomy.ts +46 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RemediationProviderCapabilities — describes what an adapter can and cannot do.
|
|
3
|
+
* Used by the registry for capability negotiation before dispatching requests.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { GovernanceFindingCategory } from '../verification/taxonomy';
|
|
7
|
+
|
|
8
|
+
export type RemediationExecutionMode = 'export' | 'assisted' | 'apply';
|
|
9
|
+
|
|
10
|
+
export type RemediationTransport =
|
|
11
|
+
| 'stdin-stdout' // local process: write prompt to stdin, read patch from stdout
|
|
12
|
+
| 'json-file' // write request JSON to file, adapter reads and writes response JSON
|
|
13
|
+
| 'http-local' // local HTTP (e.g. Cursor MCP server on localhost)
|
|
14
|
+
| 'http-remote'; // remote HTTP API (e.g. Anthropic Claude, OpenAI)
|
|
15
|
+
|
|
16
|
+
export interface RemediationProviderCapabilities {
|
|
17
|
+
/** Stable provider ID (e.g. "cursor", "claude", "codex", "openai-compatible"). */
|
|
18
|
+
providerId: string;
|
|
19
|
+
|
|
20
|
+
/** Human-readable display name. */
|
|
21
|
+
providerName: string;
|
|
22
|
+
|
|
23
|
+
/** Supported execution modes. All providers must support 'export'. */
|
|
24
|
+
supportedModes: RemediationExecutionMode[];
|
|
25
|
+
|
|
26
|
+
/** Supported transport mechanisms. */
|
|
27
|
+
supportedTransports: RemediationTransport[];
|
|
28
|
+
|
|
29
|
+
/** Finding categories this provider handles well. */
|
|
30
|
+
supportedCategories: GovernanceFindingCategory[];
|
|
31
|
+
|
|
32
|
+
/** Structural rule IDs this provider has been validated against (e.g. ["SR001", "DS001"]). */
|
|
33
|
+
validatedRuleIds: string[];
|
|
34
|
+
|
|
35
|
+
/** Maximum context length the provider can accept (characters). */
|
|
36
|
+
maxContextChars: number;
|
|
37
|
+
|
|
38
|
+
/** True when the provider can run without network access (air-gapped). */
|
|
39
|
+
supportsOffline: boolean;
|
|
40
|
+
|
|
41
|
+
/** True when the provider requires network access to function. */
|
|
42
|
+
requiresNetwork: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* True when the provider is deterministic given identical inputs.
|
|
46
|
+
* Currently false for all LLM-backed providers.
|
|
47
|
+
* True only for future AST-based adapters.
|
|
48
|
+
*/
|
|
49
|
+
isDeterministic: boolean;
|
|
50
|
+
|
|
51
|
+
/** Provider schema version for capability negotiation. */
|
|
52
|
+
capabilitiesVersion: string;
|
|
53
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
GovernanceRemediationContext,
|
|
3
|
+
GovernanceRemediationRequest,
|
|
4
|
+
ModificationBoundary,
|
|
5
|
+
RemediationCodeSpan,
|
|
6
|
+
RemediationReplayMetadata,
|
|
7
|
+
RemediationTrustBoundary,
|
|
8
|
+
} from './request';
|
|
9
|
+
|
|
10
|
+
export type {
|
|
11
|
+
GovernanceRemediationResponse,
|
|
12
|
+
RemediationPostcondition,
|
|
13
|
+
RemediationProviderMetadata,
|
|
14
|
+
} from './response';
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
RemediationExecutionMode,
|
|
18
|
+
RemediationProviderCapabilities,
|
|
19
|
+
RemediationTransport,
|
|
20
|
+
} from './capabilities';
|
|
21
|
+
|
|
22
|
+
export type {
|
|
23
|
+
RemediationGovernanceCheckResult,
|
|
24
|
+
RemediationPostconditionCheckResult,
|
|
25
|
+
RemediationScopeCheckResult,
|
|
26
|
+
RemediationSyntaxCheckResult,
|
|
27
|
+
RemediationValidationReceipt,
|
|
28
|
+
RemediationValidationResult,
|
|
29
|
+
} from './validation';
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GovernanceRemediationRequest — deterministic input to probabilistic remediation.
|
|
3
|
+
*
|
|
4
|
+
* This contract is:
|
|
5
|
+
* - replayable: stable serialization, content-hashed
|
|
6
|
+
* - auditable: provenance + plan linkage required
|
|
7
|
+
* - bounded: allowed modification scope is explicit
|
|
8
|
+
* - provider-agnostic: no provider SDK references
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: This contract is governance infrastructure, not AI infrastructure.
|
|
11
|
+
* The finding it encodes is deterministic. The remediation it requests is optional and advisory.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { DeterminismClassification, GovernanceFindingCategory, GovernanceSeverity } from '../verification';
|
|
15
|
+
import type { GOVERNANCE_FINDINGS_SCHEMA_VERSION } from '../verification/taxonomy';
|
|
16
|
+
|
|
17
|
+
// ── Span and location ──────────────────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
export interface RemediationCodeSpan {
|
|
20
|
+
/** 1-indexed start line (inclusive). */
|
|
21
|
+
startLine: number;
|
|
22
|
+
/** 1-indexed end line (inclusive). */
|
|
23
|
+
endLine: number;
|
|
24
|
+
/** 0-indexed start column (optional, when AST provides it). */
|
|
25
|
+
startColumn?: number;
|
|
26
|
+
/** 0-indexed end column (optional). */
|
|
27
|
+
endColumn?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ── Modification boundary ──────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Explicit scope of changes the remediation is allowed to make.
|
|
34
|
+
* Adapters MUST communicate this to the external tool.
|
|
35
|
+
* The validation pipeline enforces it on the response.
|
|
36
|
+
*/
|
|
37
|
+
export interface ModificationBoundary {
|
|
38
|
+
/** Repo-relative file paths the remediation may touch. Must be non-empty. */
|
|
39
|
+
allowedFiles: string[];
|
|
40
|
+
/** If set, mutation is restricted to this span within the primary file. */
|
|
41
|
+
restrictToSpan?: RemediationCodeSpan;
|
|
42
|
+
/** Max lines the patch may add across all allowed files. */
|
|
43
|
+
maxLinesAdded?: number;
|
|
44
|
+
/** Max lines the patch may remove across all allowed files. */
|
|
45
|
+
maxLinesRemoved?: number;
|
|
46
|
+
/** When true, the remediation must not introduce new imports not already present. */
|
|
47
|
+
noNewImports?: boolean;
|
|
48
|
+
/** When true, the remediation must not rename symbols. */
|
|
49
|
+
noSymbolRename?: boolean;
|
|
50
|
+
/** Human-readable constraint summary for prompt injection. */
|
|
51
|
+
constraintSummary: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ── Trust boundary ─────────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Declares what Neurcode can assert about this finding and what it cannot.
|
|
58
|
+
* Adapters must surface this to engineers — never hide trust boundaries.
|
|
59
|
+
*/
|
|
60
|
+
export interface RemediationTrustBoundary {
|
|
61
|
+
/** The finding itself is deterministic and reproducible. */
|
|
62
|
+
findingIsDeterministic: boolean;
|
|
63
|
+
/** The remediation is advisory — engineer must approve before application. */
|
|
64
|
+
remediationIsAdvisory: true;
|
|
65
|
+
/** Governance verdict is never determined by LLM output. */
|
|
66
|
+
governanceIsLlmFree: true;
|
|
67
|
+
/**
|
|
68
|
+
* The DeterminismClassification of the original finding.
|
|
69
|
+
* 'deterministic-structural' = AST-verified, highest trust.
|
|
70
|
+
* 'heuristic-advisory' = pattern match, lower confidence.
|
|
71
|
+
*/
|
|
72
|
+
findingDeterminism: DeterminismClassification;
|
|
73
|
+
/** Confidence score of the original finding (0–1). */
|
|
74
|
+
findingConfidence: number;
|
|
75
|
+
/**
|
|
76
|
+
* Human-readable trust statement for display in remediation UIs.
|
|
77
|
+
* Example: "Finding is AST-verified (confidence 0.92). Fix is advisory and must be reviewed."
|
|
78
|
+
*/
|
|
79
|
+
trustStatement: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ── Replay metadata ────────────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
export interface RemediationReplayMetadata {
|
|
85
|
+
/** SHA-256 of the request payload excluding this field. Used for de-duplication and replay. */
|
|
86
|
+
requestHash: string;
|
|
87
|
+
/** The verify run that produced this finding. Links to ProvenanceRecord.runId. */
|
|
88
|
+
sourceRunId: string;
|
|
89
|
+
/** When the source verify run executed (ISO 8601). */
|
|
90
|
+
sourceRunAt: string;
|
|
91
|
+
/** Schema version of the governance findings that produced this request. */
|
|
92
|
+
sourceSchemaVersion: typeof GOVERNANCE_FINDINGS_SCHEMA_VERSION;
|
|
93
|
+
/** True when the request was re-generated from a replay artifact (not a live run). */
|
|
94
|
+
isReplay: boolean;
|
|
95
|
+
/** If replayed, the original request ID this was derived from. */
|
|
96
|
+
replayedFromRequestId?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── Code context ───────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Deterministic code context extracted from the repository at verify time.
|
|
103
|
+
* Frozen at request creation — not re-read at remediation time.
|
|
104
|
+
*/
|
|
105
|
+
export interface GovernanceRemediationContext {
|
|
106
|
+
/** Exact flagged code snippet (as found by the structural rule). */
|
|
107
|
+
codeExcerpt: string;
|
|
108
|
+
/** Lines surrounding the violation for LLM context (before + after). */
|
|
109
|
+
surroundingContext: string;
|
|
110
|
+
/** Relevant import lines from the file header. */
|
|
111
|
+
fileImports: string[];
|
|
112
|
+
/** Containing function/method signature if detectable. */
|
|
113
|
+
containingFunctionSignature?: string;
|
|
114
|
+
/** TypeScript/Python language of the file. */
|
|
115
|
+
language: 'typescript' | 'python' | 'javascript';
|
|
116
|
+
/**
|
|
117
|
+
* Structural explanation: why this specific AST pattern violates the rule.
|
|
118
|
+
* Generated by the structural rule, not by an LLM.
|
|
119
|
+
*/
|
|
120
|
+
structuralExplanation: string;
|
|
121
|
+
/**
|
|
122
|
+
* Governance-level reasoning: what operational risk this creates.
|
|
123
|
+
* From the structural rule's operationalRisk field.
|
|
124
|
+
*/
|
|
125
|
+
governanceReasoning: string;
|
|
126
|
+
/**
|
|
127
|
+
* Optional semantic hints: related symbols, patterns, or service names
|
|
128
|
+
* that may help the external tool understand system context.
|
|
129
|
+
* These are heuristic — never used for governance verdicts.
|
|
130
|
+
*/
|
|
131
|
+
semanticHints?: string[];
|
|
132
|
+
/**
|
|
133
|
+
* PatternKind from the patch engine, if classified.
|
|
134
|
+
* Used to select the best adapter prompt template.
|
|
135
|
+
*/
|
|
136
|
+
patternKind?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Postconditions the fix must satisfy for governance re-verification to pass.
|
|
139
|
+
* Deterministic — derived from the rule's remediation instruction.
|
|
140
|
+
*/
|
|
141
|
+
requiredPostconditions: string[];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ── Main request ───────────────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* GovernanceRemediationRequest — the canonical deterministic handoff from
|
|
148
|
+
* Neurcode governance to an external remediation provider.
|
|
149
|
+
*
|
|
150
|
+
* Invariants:
|
|
151
|
+
* 1. This object is fully serializable and content-addressable.
|
|
152
|
+
* 2. It must never be modified after creation (immutable input to remediation).
|
|
153
|
+
* 3. Its existence does not imply that remediation will occur — export mode
|
|
154
|
+
* generates this without invoking any provider.
|
|
155
|
+
*/
|
|
156
|
+
export interface GovernanceRemediationRequest {
|
|
157
|
+
/** Schema version — matches GOVERNANCE_FINDINGS_SCHEMA_VERSION for traceability. */
|
|
158
|
+
schemaVersion: '2026-05-11.1';
|
|
159
|
+
|
|
160
|
+
/** Deterministic request ID: sha256-128 of (findingId + sourceRunId + filePath + line). */
|
|
161
|
+
requestId: string;
|
|
162
|
+
|
|
163
|
+
/** ISO 8601 creation timestamp. */
|
|
164
|
+
createdAt: string;
|
|
165
|
+
|
|
166
|
+
// ── Finding linkage ──────────────────────────────────────────────────────────
|
|
167
|
+
|
|
168
|
+
/** GovernanceFinding.id from the canonical governance envelope. */
|
|
169
|
+
findingId: string;
|
|
170
|
+
|
|
171
|
+
/** StructuralViolation.ruleId (e.g. "SR001") or policy rule ID. */
|
|
172
|
+
ruleId: string;
|
|
173
|
+
|
|
174
|
+
/** Human-readable rule name (e.g. "Swallowed async rejection"). */
|
|
175
|
+
ruleName: string;
|
|
176
|
+
|
|
177
|
+
/** GovernanceFindingCategory from taxonomy. */
|
|
178
|
+
category: GovernanceFindingCategory;
|
|
179
|
+
|
|
180
|
+
severity: GovernanceSeverity;
|
|
181
|
+
|
|
182
|
+
determinismClassification: DeterminismClassification;
|
|
183
|
+
|
|
184
|
+
/** 0–1 confidence of the underlying finding. */
|
|
185
|
+
confidence: number;
|
|
186
|
+
|
|
187
|
+
/** Human-readable finding title. */
|
|
188
|
+
title: string;
|
|
189
|
+
|
|
190
|
+
// ── Location ─────────────────────────────────────────────────────────────────
|
|
191
|
+
|
|
192
|
+
/** Repo-relative file path (e.g. "src/services/auth/auth-service.ts"). */
|
|
193
|
+
filePath: string;
|
|
194
|
+
|
|
195
|
+
/** 1-indexed line number of the violation. */
|
|
196
|
+
line: number;
|
|
197
|
+
|
|
198
|
+
/** 0-indexed column of the violation. */
|
|
199
|
+
column: number;
|
|
200
|
+
|
|
201
|
+
/** Precise span when the rule provides it. */
|
|
202
|
+
span?: RemediationCodeSpan;
|
|
203
|
+
|
|
204
|
+
// ── Operational context ───────────────────────────────────────────────────────
|
|
205
|
+
|
|
206
|
+
/** What breaks in production if this is not fixed. */
|
|
207
|
+
operationalImplication: string;
|
|
208
|
+
|
|
209
|
+
/** The structural rule's built-in fix instruction (deterministic). */
|
|
210
|
+
remediationHint: string;
|
|
211
|
+
|
|
212
|
+
/** Code context frozen at verify time. */
|
|
213
|
+
context: GovernanceRemediationContext;
|
|
214
|
+
|
|
215
|
+
// ── Governance constraints ────────────────────────────────────────────────────
|
|
216
|
+
|
|
217
|
+
/** Explicit scope of allowed changes. Adapters must enforce this. */
|
|
218
|
+
allowedModificationBoundaries: ModificationBoundary;
|
|
219
|
+
|
|
220
|
+
// ── Provenance linkage ────────────────────────────────────────────────────────
|
|
221
|
+
|
|
222
|
+
/** Links to ProvenanceRecord.runId. */
|
|
223
|
+
provenanceRunId: string;
|
|
224
|
+
|
|
225
|
+
/** The plan ID active during the verify run (if any). */
|
|
226
|
+
planId?: string;
|
|
227
|
+
|
|
228
|
+
/** Schema version of the governance findings that produced this request. */
|
|
229
|
+
verifySchemaVersion: typeof GOVERNANCE_FINDINGS_SCHEMA_VERSION;
|
|
230
|
+
|
|
231
|
+
// ── Replay and trust ─────────────────────────────────────────────────────────
|
|
232
|
+
|
|
233
|
+
replayMetadata: RemediationReplayMetadata;
|
|
234
|
+
|
|
235
|
+
trustBoundary: RemediationTrustBoundary;
|
|
236
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GovernanceRemediationResponse — the structured output from an external remediation provider.
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT:
|
|
5
|
+
* - This is ADVISORY. It must never be applied without engineer approval.
|
|
6
|
+
* - Governance re-verification (neurcode verify) is required after application.
|
|
7
|
+
* - The response is not a governance verdict — it is a suggestion.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// ── Postcondition ──────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A verifiable condition the patch must satisfy for the finding to be resolved.
|
|
14
|
+
* Generated deterministically from the structural rule — not by an LLM.
|
|
15
|
+
*/
|
|
16
|
+
export interface RemediationPostcondition {
|
|
17
|
+
/** Unique identifier for this postcondition. */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Human-readable description. */
|
|
20
|
+
description: string;
|
|
21
|
+
/**
|
|
22
|
+
* Verification method:
|
|
23
|
+
* structural-re-run → re-run the original structural rule; violation must be absent
|
|
24
|
+
* pattern-absent → the violating pattern must not appear in the patched file
|
|
25
|
+
* pattern-present → a required pattern must appear (e.g. "throw err")
|
|
26
|
+
* syntax-valid → file must parse without TypeScript/Python syntax errors
|
|
27
|
+
* scope-within-boundary → all changes must be within allowed modification boundary
|
|
28
|
+
*/
|
|
29
|
+
verificationMethod:
|
|
30
|
+
| 'structural-re-run'
|
|
31
|
+
| 'pattern-absent'
|
|
32
|
+
| 'pattern-present'
|
|
33
|
+
| 'syntax-valid'
|
|
34
|
+
| 'scope-within-boundary';
|
|
35
|
+
/** For pattern-based methods: the pattern to check (regex string). */
|
|
36
|
+
pattern?: string;
|
|
37
|
+
/** Whether failing this postcondition is blocking (true) or advisory (false). */
|
|
38
|
+
blocking: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ── Provider metadata ──────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
export interface RemediationProviderMetadata {
|
|
44
|
+
/** Stable provider identifier (e.g. "cursor", "claude-3-5-sonnet", "codex"). */
|
|
45
|
+
providerId: string;
|
|
46
|
+
/** Human-readable provider name. */
|
|
47
|
+
providerName: string;
|
|
48
|
+
/** Model version if applicable. */
|
|
49
|
+
modelVersion?: string;
|
|
50
|
+
/** Total input tokens used (for cost tracking). */
|
|
51
|
+
inputTokens?: number;
|
|
52
|
+
/** Total output tokens generated. */
|
|
53
|
+
outputTokens?: number;
|
|
54
|
+
/** Wall-clock time from prompt send to response receive (ms). */
|
|
55
|
+
latencyMs?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ── Main response ──────────────────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* GovernanceRemediationResponse — structured output from remediation provider.
|
|
62
|
+
*
|
|
63
|
+
* Invariants:
|
|
64
|
+
* 1. requestId must match the GovernanceRemediationRequest this responds to.
|
|
65
|
+
* 2. patchDiff must be a valid unified diff (--- a/... +++ b/... format).
|
|
66
|
+
* 3. This object is not applied automatically — engineer approval required.
|
|
67
|
+
* 4. Governance re-verification must run after any application.
|
|
68
|
+
*/
|
|
69
|
+
export interface GovernanceRemediationResponse {
|
|
70
|
+
/** Fixed schema version. */
|
|
71
|
+
schemaVersion: '2026-05-11.1';
|
|
72
|
+
|
|
73
|
+
/** Unique ID for this response. */
|
|
74
|
+
responseId: string;
|
|
75
|
+
|
|
76
|
+
/** Links to GovernanceRemediationRequest.requestId. */
|
|
77
|
+
requestId: string;
|
|
78
|
+
|
|
79
|
+
/** ISO 8601 generation timestamp. */
|
|
80
|
+
createdAt: string;
|
|
81
|
+
|
|
82
|
+
/** Provider that generated this response. */
|
|
83
|
+
provider: RemediationProviderMetadata;
|
|
84
|
+
|
|
85
|
+
// ── Generated patch ──────────────────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Unified diff of the proposed fix.
|
|
89
|
+
* Format: git-compatible unified diff (--- a/... +++ b/...).
|
|
90
|
+
* Empty when no patch could be generated (see status).
|
|
91
|
+
*/
|
|
92
|
+
patchDiff: string;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Full patched file content (after applying patchDiff).
|
|
96
|
+
* Included when the provider returns full content.
|
|
97
|
+
* Optional — validation can work from patchDiff alone.
|
|
98
|
+
*/
|
|
99
|
+
patchedContent?: string;
|
|
100
|
+
|
|
101
|
+
// ── Response metadata ─────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Response status:
|
|
105
|
+
* generated → patch successfully produced
|
|
106
|
+
* no-fix-needed → provider determined no change required
|
|
107
|
+
* unable-to-fix → provider could not generate a valid fix
|
|
108
|
+
* out-of-scope → provider declined (change would exceed modification boundary)
|
|
109
|
+
*/
|
|
110
|
+
status: 'generated' | 'no-fix-needed' | 'unable-to-fix' | 'out-of-scope';
|
|
111
|
+
|
|
112
|
+
/** Provider's explanation of the fix (or why no fix was generated). */
|
|
113
|
+
explanation: string;
|
|
114
|
+
|
|
115
|
+
/** Provider's self-reported confidence (0–1). Advisory — not used for governance. */
|
|
116
|
+
providerConfidence: number;
|
|
117
|
+
|
|
118
|
+
/** True when the provider flags this for mandatory human review. */
|
|
119
|
+
requiresManualReview: boolean;
|
|
120
|
+
|
|
121
|
+
/** Postconditions the patch should satisfy (copied from request, for validation reference). */
|
|
122
|
+
postconditions: RemediationPostcondition[];
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Raw prompt used to generate this response.
|
|
126
|
+
* Included for auditability — engineers can inspect exactly what was sent.
|
|
127
|
+
*/
|
|
128
|
+
promptUsed?: string;
|
|
129
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RemediationValidationResult — output of the deterministic patch validation pipeline.
|
|
3
|
+
*
|
|
4
|
+
* The validation pipeline is always deterministic:
|
|
5
|
+
* - syntax validation uses the TypeScript/Python parser
|
|
6
|
+
* - scope validation checks file paths and line counts
|
|
7
|
+
* - governance validation re-runs the original structural rule
|
|
8
|
+
* - postcondition validation checks regex patterns
|
|
9
|
+
*
|
|
10
|
+
* LLM output is NEVER trusted without passing this pipeline.
|
|
11
|
+
* A failed validation does not modify any files.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// ── Individual check results ───────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
export interface RemediationSyntaxCheckResult {
|
|
17
|
+
valid: boolean;
|
|
18
|
+
errors: string[];
|
|
19
|
+
/** True when the parser was available; false when check was skipped. */
|
|
20
|
+
checkerAvailable: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RemediationScopeCheckResult {
|
|
24
|
+
valid: boolean;
|
|
25
|
+
/** Files in the patch that are outside ModificationBoundary.allowedFiles. */
|
|
26
|
+
outOfScopeFiles: string[];
|
|
27
|
+
/** True when line count changes exceed boundary limits. */
|
|
28
|
+
lineLimitExceeded: boolean;
|
|
29
|
+
/** True when new imports were added in violation of noNewImports boundary. */
|
|
30
|
+
newImportsAdded: boolean;
|
|
31
|
+
details: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface RemediationGovernanceCheckResult {
|
|
35
|
+
/**
|
|
36
|
+
* True when re-running the original structural rule on the patched file
|
|
37
|
+
* produces zero violations for the specific ruleId.
|
|
38
|
+
*/
|
|
39
|
+
originalFindingResolved: boolean;
|
|
40
|
+
/** Any new structural violations introduced by the patch. */
|
|
41
|
+
newViolationsIntroduced: string[];
|
|
42
|
+
/** True when re-running governance found no regressions. */
|
|
43
|
+
noRegressions: boolean;
|
|
44
|
+
details: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface RemediationPostconditionCheckResult {
|
|
48
|
+
postconditionId: string;
|
|
49
|
+
passed: boolean;
|
|
50
|
+
verificationMethod: string;
|
|
51
|
+
detail: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ── Validation receipt ─────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Immutable receipt created by the validation pipeline.
|
|
58
|
+
* Stored as a governance artifact — append-only.
|
|
59
|
+
*/
|
|
60
|
+
export interface RemediationValidationReceipt {
|
|
61
|
+
schemaVersion: '2026-05-11.1';
|
|
62
|
+
receiptId: string;
|
|
63
|
+
/** Links to GovernanceRemediationRequest.requestId. */
|
|
64
|
+
requestId: string;
|
|
65
|
+
/** Links to GovernanceRemediationResponse.responseId. */
|
|
66
|
+
responseId: string;
|
|
67
|
+
validatedAt: string;
|
|
68
|
+
/** SHA-256 of the response patchDiff (for replay integrity). */
|
|
69
|
+
patchDiffHash: string;
|
|
70
|
+
/** SHA-256 of the patched file content (after applying diff). */
|
|
71
|
+
patchedContentHash?: string;
|
|
72
|
+
/** Overall validation verdict. */
|
|
73
|
+
verdict: 'approved' | 'rejected' | 'requires-review';
|
|
74
|
+
/** Human-readable summary of the validation result. */
|
|
75
|
+
summary: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ── Main validation result ─────────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
export interface RemediationValidationResult {
|
|
81
|
+
schemaVersion: '2026-05-11.1';
|
|
82
|
+
|
|
83
|
+
/** Overall: true only when all blocking checks pass. */
|
|
84
|
+
valid: boolean;
|
|
85
|
+
|
|
86
|
+
/** Whether the patch can be applied safely (valid + no new governance violations). */
|
|
87
|
+
safeToApply: boolean;
|
|
88
|
+
|
|
89
|
+
/** True when the original governance finding is resolved by the patch. */
|
|
90
|
+
findingResolved: boolean;
|
|
91
|
+
|
|
92
|
+
// ── Individual check results ───────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
syntax: RemediationSyntaxCheckResult;
|
|
95
|
+
scope: RemediationScopeCheckResult;
|
|
96
|
+
governance: RemediationGovernanceCheckResult;
|
|
97
|
+
postconditions: RemediationPostconditionCheckResult[];
|
|
98
|
+
|
|
99
|
+
// ── Summary ────────────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/** All blocking errors that prevent application. */
|
|
102
|
+
blockingErrors: string[];
|
|
103
|
+
|
|
104
|
+
/** Non-blocking warnings for engineer review. */
|
|
105
|
+
warnings: string[];
|
|
106
|
+
|
|
107
|
+
/** Immutable audit receipt. */
|
|
108
|
+
receipt: RemediationValidationReceipt;
|
|
109
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export const STATUS_VOCABULARY_VERSION = 'neurcode.status.v1';
|
|
2
|
+
|
|
3
|
+
export const STATUS_TERMS = {
|
|
4
|
+
verificationComplete: 'Verification Complete',
|
|
5
|
+
safePatchApplied: 'Safe Patch Applied',
|
|
6
|
+
patchRejected: 'Patch Rejected',
|
|
7
|
+
rollbackAvailable: 'Rollback Available',
|
|
8
|
+
rollbackApplied: 'Rollback Applied',
|
|
9
|
+
replayAvailable: 'Replay Available',
|
|
10
|
+
evidenceGenerated: 'Evidence Generated',
|
|
11
|
+
manualReviewRecommended: 'Manual Review Recommended',
|
|
12
|
+
filesystemChangedSincePreview: 'Filesystem Changed Since Preview',
|
|
13
|
+
transactionVerified: 'Transaction Verified',
|
|
14
|
+
retrySafe: 'Retry Safe',
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
export type StatusTermKey = keyof typeof STATUS_TERMS;
|
|
18
|
+
export type SeverityLabel =
|
|
19
|
+
| 'critical'
|
|
20
|
+
| 'blocking'
|
|
21
|
+
| 'high'
|
|
22
|
+
| 'advisory'
|
|
23
|
+
| 'medium'
|
|
24
|
+
| 'warning'
|
|
25
|
+
| 'low'
|
|
26
|
+
| 'info';
|
|
27
|
+
|
|
28
|
+
export const SEVERITY_LABELS: Record<SeverityLabel, string> = {
|
|
29
|
+
critical: 'Critical',
|
|
30
|
+
blocking: 'Blocking',
|
|
31
|
+
high: 'High',
|
|
32
|
+
advisory: 'Advisory',
|
|
33
|
+
medium: 'Medium',
|
|
34
|
+
warning: 'Warning',
|
|
35
|
+
low: 'Low',
|
|
36
|
+
info: 'Info',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type VerificationSummaryState = 'clean' | 'issues' | 'partial' | 'failed';
|
|
40
|
+
|
|
41
|
+
export const VERIFICATION_SUMMARY_LABELS: Record<VerificationSummaryState, string> = {
|
|
42
|
+
clean: STATUS_TERMS.verificationComplete,
|
|
43
|
+
issues: 'Verification Findings Detected',
|
|
44
|
+
partial: 'Verification Partially Complete',
|
|
45
|
+
failed: 'Verification Failed',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type PatchState =
|
|
49
|
+
| 'applied'
|
|
50
|
+
| 'partial'
|
|
51
|
+
| 'rejected'
|
|
52
|
+
| 'stale_preview'
|
|
53
|
+
| 'filesystem_changed_since_preview'
|
|
54
|
+
| 'rollback_applied'
|
|
55
|
+
| 'rollback_stale'
|
|
56
|
+
| 'rollback_rejected';
|
|
57
|
+
|
|
58
|
+
export type ConfidenceLabel = 'HIGH' | 'MEDIUM' | 'LOW';
|
|
59
|
+
|
|
60
|
+
export const CONFIDENCE_LABELS: Record<ConfidenceLabel, string> = {
|
|
61
|
+
HIGH: 'HIGH confidence',
|
|
62
|
+
MEDIUM: 'MEDIUM confidence',
|
|
63
|
+
LOW: 'LOW confidence',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export function statusTerm(key: StatusTermKey): string {
|
|
67
|
+
return STATUS_TERMS[key];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function severityLabel(severity: SeverityLabel): string {
|
|
71
|
+
return SEVERITY_LABELS[severity];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function toPatchStateLabel(state: PatchState): string {
|
|
75
|
+
if (state === 'applied') return STATUS_TERMS.safePatchApplied;
|
|
76
|
+
if (state === 'partial') return `${STATUS_TERMS.safePatchApplied} · ${STATUS_TERMS.manualReviewRecommended}`;
|
|
77
|
+
if (state === 'stale_preview' || state === 'filesystem_changed_since_preview') {
|
|
78
|
+
return STATUS_TERMS.filesystemChangedSincePreview;
|
|
79
|
+
}
|
|
80
|
+
if (state === 'rollback_applied') return STATUS_TERMS.rollbackApplied;
|
|
81
|
+
if (state === 'rollback_stale') return `${STATUS_TERMS.patchRejected} · ${STATUS_TERMS.filesystemChangedSincePreview}`;
|
|
82
|
+
if (state === 'rollback_rejected') return STATUS_TERMS.patchRejected;
|
|
83
|
+
return STATUS_TERMS.patchRejected;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function toRetrySafeMessage(context: string): string {
|
|
87
|
+
return `${context}. ${STATUS_TERMS.retrySafe}.`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function toManualReviewMessage(context: string): string {
|
|
91
|
+
return `${STATUS_TERMS.manualReviewRecommended}: ${context}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function toVerificationCompleteTitle(confidenceSuffix = ''): string {
|
|
95
|
+
return `${STATUS_TERMS.verificationComplete}${confidenceSuffix}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function toVerificationSummaryLabel(state: VerificationSummaryState): string {
|
|
99
|
+
return VERIFICATION_SUMMARY_LABELS[state];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const DAEMON_ERROR_CODES = {
|
|
103
|
+
badRequest: 'daemon.bad_request',
|
|
104
|
+
unauthorized: 'daemon.unauthorized',
|
|
105
|
+
forbidden: 'daemon.forbidden',
|
|
106
|
+
notFound: 'daemon.not_found',
|
|
107
|
+
routeNotFound: 'daemon.route_not_found',
|
|
108
|
+
timeout: 'daemon.timeout',
|
|
109
|
+
conflict: 'daemon.conflict',
|
|
110
|
+
validationFailed: 'daemon.validation_failed',
|
|
111
|
+
rateLimited: 'daemon.rate_limited',
|
|
112
|
+
internalError: 'daemon.internal_error',
|
|
113
|
+
unknown: 'daemon.error',
|
|
114
|
+
} as const;
|
|
115
|
+
|
|
116
|
+
export type DaemonErrorCode = typeof DAEMON_ERROR_CODES[keyof typeof DAEMON_ERROR_CODES];
|
|
117
|
+
|
|
118
|
+
export const ONBOARDING_HINTS = [
|
|
119
|
+
'Run your first verification',
|
|
120
|
+
'Review findings',
|
|
121
|
+
'Preview deterministic patch',
|
|
122
|
+
'Apply safe patch',
|
|
123
|
+
'View evidence',
|
|
124
|
+
'Replay execution history',
|
|
125
|
+
] as const;
|