@noppu-labs/opencode-permission-reviewer 2.4.1 → 3.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +64 -1
  2. package/LICENSE +21 -201
  3. package/LICENSE-APACHE +201 -0
  4. package/NOTICE +14 -6
  5. package/README.md +100 -750
  6. package/SECURITY.md +41 -22
  7. package/dist/explain.js +4932 -3522
  8. package/dist/index.d.ts +520 -513
  9. package/dist/index.js +12595 -9115
  10. package/dist/rpc.js +4 -1
  11. package/dist/tui/config/jsonc.ts +71 -63
  12. package/dist/tui/config/layer-read.ts +120 -0
  13. package/dist/tui/config/loader.ts +61 -513
  14. package/dist/tui/config/risk-policy-clamp.ts +80 -0
  15. package/dist/tui/config/trust-boundary-keys.ts +100 -0
  16. package/dist/tui/config/trust-boundary.ts +135 -0
  17. package/dist/tui/config/trusted-degradation.ts +97 -0
  18. package/dist/tui/config-fields.ts +55 -0
  19. package/dist/tui/config-knobs.ts +119 -0
  20. package/dist/tui/config-policy-rules.ts +86 -0
  21. package/dist/tui/config-risk-policy.ts +59 -0
  22. package/dist/tui/config-rule-condition.ts +150 -0
  23. package/dist/tui/config.ts +61 -430
  24. package/dist/tui/descriptor-io.ts +42 -0
  25. package/dist/tui/is-record.ts +13 -0
  26. package/dist/tui/opencode/event-normalizer.ts +41 -31
  27. package/dist/tui/reviewer-model.ts +87 -0
  28. package/dist/tui/tui.tsx +87 -99
  29. package/dist/tui/types.ts +171 -538
  30. package/dist/tui/ui/components.tsx +32 -136
  31. package/dist/tui/ui/review-connection.ts +32 -0
  32. package/dist/tui/ui/review-feed.ts +131 -0
  33. package/dist/tui/ui/review-overlay.tsx +83 -0
  34. package/dist/tui/ui/review-result.tsx +56 -0
  35. package/dist/tui/ui/review-store.ts +88 -0
  36. package/dist/tui/ui/review-theme.ts +63 -0
  37. package/dist/tui/ui/rpc.ts +5 -2
  38. package/dist/tui/ui/v1-host.ts +39 -0
  39. package/dist/tui/ui/v2.tsx +66 -220
  40. package/dist/tui/ui-protocol.ts +63 -118
  41. package/dist/tui/ui-state.ts +71 -64
  42. package/dist/tui/ui-status-parse.ts +74 -0
  43. package/package.json +18 -17
  44. package/rpc.js +2 -1
  45. package/server.js +2 -2
  46. package/tui.tsx +2 -1
package/dist/tui/types.ts CHANGED
@@ -1,51 +1,70 @@
1
- export type RiskLevel = "low" | "medium" | "high" | "critical"
2
- export type UserAuthorization = "high" | "medium" | "low" | "unknown"
3
- export type ReviewOutcome = "allow" | "deny" | "escalate"
4
- export type ScopeAlignment = "aligned" | "partial" | "misaligned" | "unknown"
5
- export type EvidenceSufficiency = "sufficient" | "partial" | "insufficient" | "unknown"
1
+ import type {
2
+ ActionPurpose,
3
+ ActorContext,
4
+ AskDecision,
5
+ EvidenceCompleteness,
6
+ IntentContext,
7
+ SessionLineage,
8
+ } from "./actor-context-types.ts";
9
+ import type { DecisionSource, ReviewAuditRecord } from "./audit-record.ts";
10
+ import type {
11
+ CapabilityAssessment,
12
+ ParsedCommand,
13
+ } from "./capability/capability-types.ts";
14
+ import type { SystemOneScores } from "./system-one/system-one-types.ts";
15
+
16
+ export type RiskLevel = "low" | "medium" | "high" | "critical";
17
+ export type UserAuthorization = "high" | "medium" | "low" | "unknown";
18
+ export type ReviewOutcome = "allow" | "deny" | "escalate";
19
+ export type ScopeAlignment = "aligned" | "partial" | "misaligned" | "unknown";
20
+ export type EvidenceSufficiency =
21
+ | "sufficient"
22
+ | "partial"
23
+ | "insufficient"
24
+ | "unknown";
6
25
  /** How final escalations are disposed after reviewer/policy/fail-safe produce them. */
7
- export type EscalationMode = "manual" | "deny"
26
+ export type EscalationMode = "manual" | "deny";
8
27
  /** Effective disposition applied to an internal escalate result. */
9
- export type EscalationDisposition = "manual" | "deny"
28
+ export type EscalationDisposition = "manual" | "deny";
10
29
 
11
30
  export interface ReviewDecision {
12
31
  /** Structured-decision schema version. Always 2 for the current schema. */
13
- version: 2
14
- outcome: ReviewOutcome
15
- risk_level: RiskLevel
16
- user_authorization: UserAuthorization
32
+ version: 2;
33
+ outcome: ReviewOutcome;
34
+ risk_level: RiskLevel;
35
+ user_authorization: UserAuthorization;
17
36
  /** How well the request aligns with the recovered user/delegated intent. */
18
- scope_alignment: ScopeAlignment
37
+ scope_alignment: ScopeAlignment;
19
38
  /** Whether the evidence was sufficient to decide confidently. */
20
- evidence_completeness: EvidenceSufficiency
21
- rationale: string
22
- confidence: number
39
+ evidence_completeness: EvidenceSufficiency;
40
+ rationale: string;
41
+ confidence: number;
23
42
  /** Optional script-only semantic analysis. Never conveys authorization. */
24
- script_analysis?: string
43
+ script_analysis?: string;
25
44
  }
26
45
 
27
46
  export interface PermissionToolSource {
28
- messageID: string
29
- callID: string
47
+ messageID: string;
48
+ callID: string;
30
49
  }
31
50
 
32
51
  export interface PermissionRequest {
33
- id: string
34
- sessionID: string
35
- permission: string
36
- patterns: string[]
37
- metadata: Record<string, unknown>
38
- always: string[]
39
- tool?: PermissionToolSource
52
+ id: string;
53
+ sessionID: string;
54
+ permission: string;
55
+ patterns: string[];
56
+ metadata: Record<string, unknown>;
57
+ always: string[];
58
+ tool?: PermissionToolSource;
40
59
  }
41
60
 
42
61
  export interface MessageWithParts {
43
62
  info: Record<string, unknown> & {
44
- id?: string
45
- role?: string
46
- structured?: unknown
47
- }
48
- parts: Array<Record<string, unknown>>
63
+ id?: string;
64
+ role?: string;
65
+ structured?: unknown;
66
+ };
67
+ parts: Array<Record<string, unknown>>;
49
68
  }
50
69
 
51
70
  /** Deterministic risk×authorization matrix that gates reviewer `allow`
@@ -55,561 +74,233 @@ export interface MessageWithParts {
55
74
  * preserved. */
56
75
  export interface RiskPolicy {
57
76
  allow: {
58
- low: UserAuthorization[]
59
- medium: UserAuthorization[]
60
- high: UserAuthorization[]
61
- critical: UserAuthorization[]
62
- }
63
- minimumConfidence: number
64
- onInvalidDecision: "manual" | "deny"
65
- onReviewerFailure: "manual" | "deny"
77
+ low: UserAuthorization[];
78
+ medium: UserAuthorization[];
79
+ high: UserAuthorization[];
80
+ critical: UserAuthorization[];
81
+ };
82
+ minimumConfidence: number;
83
+ onInvalidDecision: "manual" | "deny";
84
+ onReviewerFailure: "manual" | "deny";
66
85
  }
67
86
 
68
87
  /** Conservative repository trust model. A repository cannot mark itself trusted
69
88
  * through project configuration alone — trust comes from global config or an
70
89
  * interactive decision stored outside the repo. */
71
- export type RepositoryTrust = "trusted" | "untrusted" | "unknown"
90
+ export type RepositoryTrust = "trusted" | "untrusted" | "unknown";
72
91
 
73
92
  /** A declarative policy condition: matches capability/actor facts. Every field
74
93
  * is optional; the rule matches when ALL specified fields match. A missing
75
94
  * `when` (or `{ always: true }`) makes the rule universal. */
76
95
  export interface PolicyCondition {
77
96
  /** Explicit catch-all: valid only as the sole key. */
78
- always?: true
79
- actionClass?: CapabilityActionClass[]
80
- actorProfile?: ActorProfile[]
81
- writesWorkspace?: boolean
82
- writesExternal?: boolean
83
- writesTemporary?: boolean
84
- deletion?: boolean
85
- executesCode?: boolean
86
- createsAdHocCode?: boolean
87
- packageManagement?: boolean
88
- gitMutation?: boolean
89
- networkObserved?: boolean
90
- credentialRead?: boolean
91
- privilegeEscalation?: boolean
92
- remoteEnabled?: boolean
93
- persistence?: boolean
94
- repositoryTrust?: RepositoryTrust[]
97
+ always?: true;
98
+ actionClass?: CapabilityActionClass[];
99
+ actorProfile?: ActorProfile[];
100
+ writesWorkspace?: boolean;
101
+ writesExternal?: boolean;
102
+ writesTemporary?: boolean;
103
+ deletion?: boolean;
104
+ executesCode?: boolean;
105
+ createsAdHocCode?: boolean;
106
+ packageManagement?: boolean;
107
+ gitMutation?: boolean;
108
+ networkObserved?: boolean;
109
+ credentialRead?: boolean;
110
+ privilegeEscalation?: boolean;
111
+ remoteEnabled?: boolean;
112
+ persistence?: boolean;
113
+ repositoryTrust?: RepositoryTrust[];
95
114
  }
96
115
 
97
116
  /** A declarative rule that routes a request based on capability+actor facts.
98
117
  * `when` is optional: omitting it (or `{ always: true }`) matches every
99
118
  * request. An explicitly empty `when: {}` is rejected at load. */
100
119
  export interface PolicyRule {
101
- id: string
102
- source: "builtin" | "global" | "project" | "inline"
103
- when?: PolicyCondition
104
- effect: "review" | "manual" | "deny" | "allow"
105
- reason: string
120
+ id: string;
121
+ source: "builtin" | "global" | "project" | "inline";
122
+ when?: PolicyCondition;
123
+ effect: "review" | "manual" | "deny" | "allow";
124
+ reason: string;
106
125
  }
107
126
 
108
127
  /** The result of evaluating the declarative policy. */
109
128
  export interface PolicyTrace {
110
129
  /** Stable hash of the effective rule set (not the matched rules) for audit
111
130
  * reproducibility. */
112
- effectivePolicyHash: string
113
- matchedRules: Array<{ id: string; source: string; effect: string; reason: string }>
131
+ effectivePolicyHash: string;
132
+ matchedRules: Array<{
133
+ id: string;
134
+ source: string;
135
+ effect: string;
136
+ reason: string;
137
+ }>;
114
138
  /** The route the engine computed (counterfactual in observe mode: what enforce
115
139
  * mode WOULD have done with the same facts and rules). */
116
- finalRoute: "review" | "manual" | "deny" | "allow"
117
- mode: "observe" | "enforce"
140
+ finalRoute: "review" | "manual" | "deny" | "allow";
141
+ mode: "observe" | "enforce";
118
142
  }
119
143
 
120
- export type ReviewerOutputFormat = "json_schema" | "text"
144
+ export type ReviewerOutputFormat = "json_schema" | "text";
121
145
 
122
146
  export interface EscalationReviewerConfig {
123
- model: string
124
- variant: string
125
- outputFormat: ReviewerOutputFormat
126
- timeoutMs: number
147
+ model: string;
148
+ variant: string;
149
+ outputFormat: ReviewerOutputFormat;
150
+ timeoutMs: number;
127
151
  }
128
152
 
129
153
  export interface ReviewerConfig {
130
- model: string
131
- variant: string
154
+ model: string;
155
+ variant: string;
132
156
  /** How the reviewer model returns its decision. `json_schema` requests
133
157
  * OpenCode's structured-output format (requires provider support); `text`
134
158
  * asks the model to emit JSON in plain text and parses it locally. */
135
- outputFormat: ReviewerOutputFormat
159
+ outputFormat: ReviewerOutputFormat;
136
160
  /** Optional reasoning reviewer for valid System One decisions that remain
137
161
  * uncertain or conflict with deterministic review gates. */
138
- escalationReviewer?: EscalationReviewerConfig
162
+ escalationReviewer?: EscalationReviewerConfig;
139
163
  /** Calibrated outcome-confidence floor for System One decisions. */
140
- systemOneConfidenceThreshold: number
164
+ systemOneConfidenceThreshold: number;
141
165
  /** Minimum combined non-escalate probability for routing an explicit
142
166
  * System One escalation to the optional reasoning reviewer. */
143
- systemOneReasoningThreshold: number
144
- timeoutMs: number
167
+ systemOneReasoningThreshold: number;
168
+ timeoutMs: number;
145
169
  /** Total review budget, including context, queueing, and retries. */
146
- reviewBudgetMs?: number
147
- maxContextChars: number
148
- maxPartChars: number
149
- maxEnrichmentChars: number
150
- maxIntentChars: number
151
- transcriptMessages: number
152
- intentMessages: number
153
- historyMessages: number
154
- confidenceThreshold: number
155
- retainReviewSessions: boolean
156
- audit: boolean
157
- auditPath?: string
158
- policy?: string
159
- debug: boolean
170
+ reviewBudgetMs?: number;
171
+ maxContextChars: number;
172
+ maxPartChars: number;
173
+ maxEnrichmentChars: number;
174
+ maxIntentChars: number;
175
+ transcriptMessages: number;
176
+ intentMessages: number;
177
+ historyMessages: number;
178
+ confidenceThreshold: number;
179
+ retainReviewSessions: boolean;
180
+ audit: boolean;
181
+ auditPath?: string;
182
+ policy?: string;
183
+ debug: boolean;
160
184
  /** When "observe", actor evidence is collected and audited but never enforces
161
185
  * new gates; "enforce" applies declarative policy routes. */
162
- enforcementMode: "observe" | "enforce"
186
+ enforcementMode: "observe" | "enforce";
163
187
  /**
164
188
  * How internal `escalate` results are disposed before UI/reply.
165
189
  * - `manual` (default): leave the request for a human (interactive mode).
166
190
  * - `deny`: convert every final escalation into a reject with rationale
167
191
  * (non-interactive fail-closed). Never relaxes an explicit deny.
168
192
  */
169
- escalationMode: EscalationMode
193
+ escalationMode: EscalationMode;
170
194
  /** Max hops when walking session parents (default 8). */
171
- maxSessionDepth: number
195
+ maxSessionDepth: number;
172
196
  /** Max parent sessions fetched during lineage traversal. */
173
- maxParentSessions: number
197
+ maxParentSessions: number;
174
198
  /** Trusted name→profile mappings (empty by default; no mappings shipped). */
175
- actorProfiles: Record<string, ActorProfile>
199
+ actorProfiles: Record<string, ActorProfile>;
176
200
  /** Deterministic risk×authorization gate, configurable but defaults reproduce
177
201
  * the previous hard-coded matrix exactly. */
178
- riskPolicy: RiskPolicy
202
+ riskPolicy: RiskPolicy;
179
203
  /** Repository trust level derived from global config (never from project). */
180
- repositoryTrust: RepositoryTrust
204
+ repositoryTrust: RepositoryTrust;
181
205
  /** Declarative policy rules (empty by default; observe mode audits the trace
182
206
  * without enforcing). Project-sourced allow rules are rejected. */
183
- policyRules: PolicyRule[]
207
+ policyRules: PolicyRule[];
184
208
  /** Capture user answers to agent ask dialogs (question tool) and surface
185
209
  * them to the reviewer as scoped authorization evidence. */
186
- askDecisions: boolean
210
+ askDecisions: boolean;
187
211
  /** Non-empty when a TRUSTED config source (global file, inline options)
188
212
  * existed but could not be fully honored (malformed file, unreadable file,
189
213
  * or rules dropped by validation). Degraded configs block automatic
190
214
  * approval: restrictions may have been lost, so requests escalate instead. */
191
- configDegraded?: string[]
215
+ configDegraded?: string[];
192
216
  }
193
217
 
194
218
  export interface ReviewEnvelope {
195
- request: PermissionRequest
196
- directory: string
197
- worktree: string
198
- transcript: string
199
- intentHistory: string
200
- enrichment: string
201
- verifiedScript?: import("./verified-ssh-script.ts").VerifiedScriptEvidence
202
- sshAudit: NonNullable<ReviewAuditRecord["ssh"]>
203
- preflightDenial?: string
219
+ request: PermissionRequest;
220
+ directory: string;
221
+ worktree: string;
222
+ transcript: string;
223
+ intentHistory: string;
224
+ enrichment: string;
225
+ verifiedScript?: import("./verified-ssh-script.ts").VerifiedScriptEvidence;
226
+ sshAudit: NonNullable<ReviewAuditRecord["ssh"]>;
227
+ preflightDenial?: string;
204
228
  /** Agent-aware context (actor, lineage, intent). Observe-only: flows into the
205
229
  * reviewer prompt and audit as evidence, never into enforcement decisions.
206
230
  * Optional so older callers/tests still compile. */
207
- actor?: ActorContext
208
- lineage?: SessionLineage
209
- intent?: IntentContext
210
- evidenceCompleteness?: EvidenceCompleteness
231
+ actor?: ActorContext;
232
+ lineage?: SessionLineage;
233
+ intent?: IntentContext;
234
+ evidenceCompleteness?: EvidenceCompleteness;
211
235
  /** Structured capability facts derived from the bash command. Observe-only:
212
236
  * feeds the reviewer prompt and audit, never enforcement. */
213
- capability?: CapabilityAssessment
237
+ capability?: CapabilityAssessment;
214
238
  /** The policy trace produced for this request, surfaced to the reviewer prompt
215
239
  * as EFFECTIVE_POLICY_SUMMARY and to audit. Observe-only. */
216
- policyTrace?: PolicyTrace
240
+ policyTrace?: PolicyTrace;
217
241
  /** Per-phase timing captured during evidence assembly (context/enrichment).
218
242
  * The reviewer and reply phases are timed in the coordinator. */
219
- timings?: { contextMs?: number; enrichmentMs?: number; reviewerMs?: number; replyMs?: number }
243
+ timings?: {
244
+ contextMs?: number;
245
+ enrichmentMs?: number;
246
+ reviewerMs?: number;
247
+ replyMs?: number;
248
+ };
220
249
  /** False when a material part of the action under review (e.g. an elided
221
250
  * command segment) never reached the rendered evidence. Blocking: the
222
251
  * coordinator must not auto-approve an action the reviewer could not see
223
252
  * in full, whatever confidence the model reports. */
224
- actionEvidenceComplete?: boolean
253
+ actionEvidenceComplete?: boolean;
225
254
  /** The parsed command reused across evidence providers. */
226
- parsedCommand?: ParsedCommand
255
+ parsedCommand?: ParsedCommand;
227
256
  /** Operational purpose of the pending action (evidence, never authorization). */
228
- actionPurpose?: ActionPurpose
257
+ actionPurpose?: ActionPurpose;
229
258
  /** User answers to agent ask dialogs in this session or its ancestors,
230
259
  * captured live from question events. Observe-only: flows into the reviewer
231
260
  * prompt (USER_ASK_DECISIONS) and audit, never into enforcement. */
232
- askDecisions?: AskDecision[]
233
- }
234
-
235
- /** Which layer produced the final decision for a request. Threaded into the
236
- * audit record so reports can split outcomes by source. */
237
- export type DecisionSource =
238
- | "emergency-brake"
239
- | "deterministic-policy"
240
- | "llm-reviewer"
241
- | "system-one-reviewer"
242
- | "manual-superseded"
243
- | "failure-safe"
244
-
245
- export interface ReviewAuditRecord {
246
- /**
247
- * Audit schema version. Present on every record; readers default a missing
248
- * field to `1` (additive — old records are still valid).
249
- * Bump only on a breaking change to the record shape.
250
- */
251
- schemaVersion?: number
252
- reviewID?: string
253
- hostRequestID?: string
254
- hostGeneration?: "v1" | "v2"
255
- hostVersion?: string
256
- generation?: string
257
- nativeAction?: string
258
- directory?: string
259
- application?:
260
- | "evaluation-returned"
261
- | "reply-accepted"
262
- | "human-pending"
263
- | "superseded"
264
- | "cancelled"
265
- | "unknown"
266
- pluginVersion?: string
267
- effectiveConfigHash?: string
268
- actionFingerprint?: string
269
- /** Version of the structured-decision schema the reviewer was asked to emit. */
270
- decisionSchemaVersion?: number
271
- /** Version of the reviewer system prompt used for this decision. */
272
- promptVersion?: string
273
- /** Which layer produced the outcome (brake, policy, reviewer, supersede,
274
- * failure-safe). Absent on legacy v1 records. */
275
- decisionSource?: DecisionSource
276
- timestamp: string
277
- durationMs: number
278
- requestID: string
279
- sessionID: string
280
- permission: string
281
- /** Stable hash of the canonical request (permission, patterns, metadata,
282
- * tool) for cross-record correlation. Absent on legacy v1 records. */
283
- actionHash?: string
284
- outcome: ReviewExecutionResult["kind"]
285
- reason: string
286
- riskLevel?: RiskLevel
287
- userAuthorization?: UserAuthorization
288
- /** How well the action aligned with the recovered intent (from the reviewer
289
- * decision). Absent when no reviewer decision was reached. */
290
- scopeAlignment?: ScopeAlignment
291
- confidence?: number
292
- /**
293
- * Structured outcome emitted by the reviewer LLM before gates/disposition.
294
- * Absent when no valid structured decision was produced (brake, policy,
295
- * failure-safe, supersede).
296
- */
297
- reviewerOutcome?: ReviewOutcome
298
- /**
299
- * How an internal escalate was disposed. Present only when the logical result
300
- * was escalate (or a gate converted allow→escalate) and enforcement chose
301
- * manual or deny. Absent for explicit deny, allow, and manual-superseded.
302
- */
303
- escalationDisposition?: EscalationDisposition
304
- /** The model that produced the final reviewer decision. */
305
- reviewerModel?: string
306
- /** Present when a System One result was handed to a reasoning reviewer. */
307
- reviewerEscalatedFrom?: { model: string; reason: string }
308
- /** Per-phase timings. Absent on legacy v1 records and on deterministic paths
309
- * that never reach that phase. */
310
- timings?: { contextMs?: number; enrichmentMs?: number; reviewerMs?: number; replyMs?: number }
311
- /** Non-fatal warnings accumulated during evidence collection/analysis. */
312
- warnings?: string[]
313
- reviewerSessionID?: string
314
- /** Content identity and inspection mode only; never script text or local path. */
315
- verifiedScript?: { sha256: string; status: "full" | "reused" | "unavailable"; bytes?: number }
316
- /** Root session of the request's ancestry (additive; absent when lineage was
317
- * unavailable). */
318
- rootSessionID?: string
319
- /** Overall evidence completeness for the request (additive). */
320
- evidenceCompleteness?: string
321
- /** Resolved actor snapshot for audit (additive). Uses identityCompleteness
322
- * (not the decision's numeric confidence) to avoid field ambiguity; v2 also
323
- * carries identitySource + confidence. */
324
- actor?: {
325
- name?: string
326
- mode?: string
327
- profile: ActorProfile
328
- identityCompleteness: "complete" | "partial" | "unknown"
329
- /** How the agent identity was established (tool-message, session-api,
330
- * unavailable, …). Absent on legacy v1 records. */
331
- identitySource?: string
332
- /** Reliability of the identity claim. Absent on legacy v1 records. */
333
- confidence?: EvidenceConfidence
334
- delegationDepth?: number
335
- }
336
- ssh?: Array<{
337
- destination: string
338
- port?: string
339
- remoteCommandSha256?: string
340
- stdinSource?: string
341
- stdinStatus?: string
342
- stdinReason?: string
343
- }>
344
- /** Additive capability snapshot for audit (observe-only). */
345
- capability?: {
346
- actionClass: string
347
- summary: string
348
- parserCompleteness: string
349
- executesCode?: boolean
350
- createsAdHocCode?: boolean
351
- invokesPackageLifecycleScripts?: boolean
352
- writeEffects?: {
353
- temporaryWrite?: boolean
354
- workspaceWrite?: boolean
355
- externalWrite?: boolean
356
- deletion?: boolean
357
- }
358
- networkObserved?: boolean
359
- credentialRead?: boolean
360
- privilegeEscalation?: boolean
361
- persistence?: boolean
362
- remoteEnabled?: boolean
363
- gitMutation?: boolean
364
- }
365
- /** Additive policy trace for audit (observe-only). */
366
- policyTrace?: {
367
- effectivePolicyHash: string
368
- matchedRules: Array<{ id: string; source: string; effect: string; reason: string }>
369
- finalRoute: string
370
- mode: string
371
- }
372
- /** Additive snapshot of the ask decisions surfaced to the reviewer prompt
373
- * (observe-only; capped to the most recent few). */
374
- askDecisions?: Array<{ at: number; question: string; answer: string }>
261
+ askDecisions?: AskDecision[];
375
262
  }
376
263
 
377
264
  export interface ApprovedAnnotation {
378
- requestID: string
379
- sessionID: string
380
- decision: ReviewDecision
265
+ requestID: string;
266
+ sessionID: string;
267
+ decision: ReviewDecision;
381
268
  }
382
269
 
383
270
  export interface ReviewExecutionResult {
384
- kind: "allow" | "deny" | "escalate"
385
- decision?: ReviewDecision
386
- reason: string
387
- reviewSessionID?: string
271
+ kind: "allow" | "deny" | "escalate";
272
+ decision?: ReviewDecision;
273
+ reason: string;
274
+ reviewSessionID?: string;
388
275
  /** Which layer produced this result; threaded into the audit record. */
389
- decisionSource?: DecisionSource
276
+ decisionSource?: DecisionSource;
390
277
  /** Actual model that produced the final reviewer decision. */
391
- reviewerModel?: string
278
+ reviewerModel?: string;
392
279
  /** Primary model and routing reason when a second reviewer was used. */
393
- reviewerEscalatedFrom?: { model: string; reason: string }
280
+ reviewerEscalatedFrom?: { model: string; reason: string };
281
+ /** Jev's scores whenever it returned a parsed decision. */
282
+ systemOne?: SystemOneScores;
394
283
  /**
395
284
  * Structured outcome from the reviewer LLM before gates/disposition.
396
285
  * Absent when no valid structured decision was produced.
397
286
  */
398
- reviewerOutcome?: ReviewOutcome
287
+ reviewerOutcome?: ReviewOutcome;
399
288
  /**
400
289
  * How an internal escalate was disposed at the enforcement boundary.
401
290
  * Absent when the result was never an escalate (explicit allow/deny) or when
402
291
  * the request was already answered manually (`manual-superseded`).
403
292
  */
404
- escalationDisposition?: EscalationDisposition
405
- }
406
-
407
- // ---------------------------------------------------------------------------
408
- // Agent-aware context data model.
409
- //
410
- // These types carry actor/lineage/intent evidence alongside a permission
411
- // request. They flow into the reviewer prompt (as evidence sections) and the
412
- // audit record (additive fields) WITHOUT changing enforcement: the v1 decision
413
- // schema and enforceDecision are untouched (observe-only by default).
414
- // ---------------------------------------------------------------------------
415
-
416
- /** Reliability of a derived fact. */
417
- export type EvidenceConfidence = "confirmed" | "high" | "medium" | "low" | "unknown"
418
-
419
- /** Every non-trivial derived fact carries provenance so the LLM and audit can
420
- * weigh claims by how reliably they were established. */
421
- export interface Provenanced<T> {
422
- value: T
423
- source:
424
- | "permission-event"
425
- | "tool-message"
426
- | "session-api"
427
- | "parent-session"
428
- | "global-config"
429
- | "project-config"
430
- | "effective-permissions"
431
- | "static-analysis"
432
- | "heuristic"
433
- | "unavailable"
434
- confidence: EvidenceConfidence
435
- notes?: string[]
293
+ escalationDisposition?: EscalationDisposition;
436
294
  }
437
295
 
438
296
  /** Generic policy templates, NOT automatic trust levels. */
439
297
  export type ActorProfile =
440
- "read-only" | "validation" | "workspace" | "operator" | "reviewer" | "unknown"
441
-
442
- /** Normalized effective-permission summary when the SDK exposes it.
443
- * The v1 SDK does not expose effective rules, so this stays `undefined`. */
444
- export interface EffectivePermissionSummary {
445
- edit: "allow" | "ask" | "deny" | "mixed" | "unknown"
446
- bash: "allow" | "ask" | "deny" | "mixed" | "unknown"
447
- task: "allow" | "ask" | "deny" | "mixed" | "unknown"
448
- externalDirectory: "allow" | "ask" | "deny" | "mixed" | "unknown"
449
- source: "session" | "agent-config" | "derived" | "unknown"
450
- }
451
-
452
- /** Who is requesting the permission. */
453
- export interface ActorContext {
454
- agentName: Provenanced<string | undefined>
455
- mode: Provenanced<string | undefined>
456
- profile: Provenanced<ActorProfile>
457
- sessionID: string
458
- parentSessionID: Provenanced<string | undefined>
459
- rootSessionID: Provenanced<string>
460
- delegationDepth: Provenanced<number>
461
- effectivePermissions?: EffectivePermissionSummary
462
- identityCompleteness: "complete" | "partial" | "unknown"
463
- }
464
-
465
- /** A node in the session ancestry chain. */
466
- export interface SessionNode {
467
- sessionID: string
468
- parentID?: string
469
- title?: string
470
- version?: string
471
- actorName?: string
472
- mode?: string
473
- createdAt?: number
474
- }
475
-
476
- /** The resolved session ancestry with failure modes made explicit. */
477
- export interface SessionLineage {
478
- origin?: "human-root" | "delegated" | "unknown"
479
- nodes: SessionNode[]
480
- rootSessionID: string
481
- depth: number
482
- cycleDetected: boolean
483
- truncated: boolean
484
- missingParents: string[]
485
- }
486
-
487
- /** A single authorization/intent statement. */
488
- export interface IntentBlock {
489
- sessionID: string
490
- messageID: string
491
- actor: "user" | "assistant" | "system" | "unknown"
492
- text: string
493
- synthetic: boolean
494
- createdAt?: number
495
- provenance: Provenanced<"intent">
496
- }
497
-
498
- /** One user decision on an agent-initiated ask dialog (question tool). The
499
- * question text is agent-generated and untrusted; only the answer is a user
500
- * authorization signal, scoped to the subject and time of the ask. */
501
- export interface AskDecision {
502
- /** Epoch ms when the reply (or dismissal) was observed. */
503
- at: number
504
- /** What the agent asked, already redacted and truncated. */
505
- question: string
506
- /** The option labels the user selected, or a dismissal marker. */
507
- answer: string
508
- }
509
-
510
- /** Direct user intent kept separate from delegated task. */
511
- export interface IntentContext {
512
- directUserIntent: IntentBlock[]
513
- delegatedTask: IntentBlock[]
514
- localSessionIntent: IntentBlock[]
515
- conflictingInstructions: string[]
516
- latestExplicitAuthorization?: IntentBlock
517
- completeness: "complete" | "partial" | "insufficient"
518
- }
519
-
520
- /** Meta-summary of what evidence was available. */
521
- export interface EvidenceCompleteness {
522
- permission: boolean
523
- actor: boolean
524
- lineage: boolean
525
- directUserIntent: boolean
526
- delegatedTask: boolean
527
- /** Whether a non-unavailable ACTION_PURPOSE was recovered. */
528
- purpose: boolean
529
- capability: boolean
530
- repositoryState: boolean
531
- referencedCode: boolean
532
- reasons: string[]
533
- overall: "sufficient" | "partial" | "insufficient"
534
- }
535
-
536
- /**
537
- * Operational purpose of the pending action — what the agent appears to be
538
- * trying to accomplish. This is untrusted evidence: it never demonstrates
539
- * user authorization by itself.
540
- */
541
- export interface ActionPurpose {
542
- text?: string
543
- source: "agent-context" | "intent-derived" | "unavailable"
544
- confidence: EvidenceConfidence
545
- }
546
-
547
- // ---------------------------------------------------------------------------
548
- // Capability analysis. The analyzer produces these facts from the bash
549
- // command using the existing shell lexer; each fact is evidence for the reviewer
550
- // prompt, never a final safety decision. Fields default to "unknown" when no
551
- // detector covers them yet.
552
- // ---------------------------------------------------------------------------
553
-
554
- /** How completely the command could be statically analyzed. */
555
- export type ParserCompleteness =
556
- /** Fully parsed: no variables, globs, substitutions, or heredoc bodies. */
557
- | "complete-for-supported-form"
558
- /** Some constructs could not be resolved (variables, partial heredoc). */
559
- | "partial"
560
- /** Heavy dynamic constructs (command substitution, eval, dynamic heredoc). */
561
- | "opaque"
562
-
563
- /** A redirection extracted from a parsed command segment. */
564
- export interface Redirection {
565
- /** `>` `>>` `<` `2>` `&>` etc. */
566
- operator: string
567
- /** Target path (file descriptor targets normalized to a path when possible). */
568
- target: string
569
- /** Whether the target was quoted in the source (affects literal-ness). */
570
- quoted: boolean
571
- }
572
-
573
- /** A heredoc extracted before lexing so its body never reaches the lexer/brake. */
574
- export interface HeredocRecord {
575
- /** The literal delimiter token as it appeared (`EOF`, `END`, …). */
576
- delimiter: string
577
- /** `<<` (expansion on) or `<<-` (tabs stripped) — normalized form. */
578
- operator: string
579
- /** Whether the delimiter was quoted, disabling expansion (`<<'EOF'`). */
580
- expansionDisabled: boolean
581
- /** Bounded + redacted body (truncated to a safe length). */
582
- bodyBounded: string
583
- /** SHA-256 of the full, unredacted body (stable identity without leaking it). */
584
- bodySha256: string
585
- /** Whether the body was truncated for storage. */
586
- truncated: boolean
587
- /** Output path associated with the heredoc when a `> path` precedes it. */
588
- outputTarget?: string
589
- /** Whether the body is dynamically constructed (unresolvable expansion). */
590
- dynamic: boolean
591
- }
592
-
593
- /** A command parsed into a reusable structure. Wraps the existing lexer output
594
- * plus pre-extracted redirections and heredocs. */
595
- export interface ParsedCommand {
596
- /** The command after heredoc bodies were replaced with placeholders. */
597
- sanitizedCommand: string
598
- /** Lexed segments of the sanitized command. */
599
- segments: import("./shell-lexer.ts").ShellSegment[]
600
- /** Effective commands (wrappers peeled) per segment. */
601
- effective: import("./shell-lexer.ts").ShellToken[][]
602
- /** Redirections grouped by segment index. */
603
- redirections: Redirection[][]
604
- /** Heredocs extracted before lexing. */
605
- heredocs: HeredocRecord[]
606
- /** Whether the original command contained any dynamic constructs. */
607
- hasDynamicConstructs: boolean
608
- /** True when the lexer's depth or expansion budget stopped command-string
609
- * resolution early; `effective` is then a prefix of the real structure and
610
- * deterministic facts do not cover the whole command. */
611
- analysisTruncated: boolean
612
- }
298
+ | "read-only"
299
+ | "validation"
300
+ | "workspace"
301
+ | "operator"
302
+ | "reviewer"
303
+ | "unknown";
613
304
 
614
305
  /** High-level classification of what the action does. */
615
306
  export type CapabilityActionClass =
@@ -626,62 +317,4 @@ export type CapabilityActionClass =
626
317
  | "service-management"
627
318
  | "persistence"
628
319
  | "privilege-escalation"
629
- | "unknown"
630
-
631
- /** What the action can do, what it appears to do, and analysis confidence. */
632
- export interface CapabilityAssessment {
633
- /** Best single-label summary of the dominant capability. */
634
- actionClass: Provenanced<CapabilityActionClass>
635
- /** Human-readable summary of the detected surface. */
636
- summary: string
637
- /** Executes an interpreter or runtime (sh, python, node, bun, …). */
638
- executesCode: Provenanced<boolean | "unknown">
639
- /** Executes code that lives in the repository (scripts, test files). */
640
- executesRepositoryCode: Provenanced<boolean | "unknown">
641
- /** Executes ad-hoc code generated by the agent (heredoc/inline). */
642
- createsAdHocCode: Provenanced<boolean | "unknown">
643
- /** Invokes a known test runner (pytest, jest, bun test, …). */
644
- invokesExistingTestRunner: Provenanced<boolean | "unknown">
645
- /** Runs a package manager that may execute lifecycle scripts. */
646
- invokesPackageLifecycleScripts: Provenanced<boolean | "unknown">
647
- /** Reads literal credential material through a known file reader. */
648
- credentialRead: Provenanced<boolean | "unknown">
649
- /** Detected file-write surface. */
650
- writeEffects: {
651
- temporaryWrite: Provenanced<boolean | "unknown">
652
- workspaceWrite: Provenanced<boolean | "unknown">
653
- externalWrite: Provenanced<boolean | "unknown">
654
- deletion: Provenanced<boolean | "unknown">
655
- }
656
- /** Detected network surface. */
657
- network: {
658
- observed: Provenanced<boolean | "unknown">
659
- possible: Provenanced<boolean | "unknown">
660
- /** Hosts/destinations observed literally in the command. */
661
- destinations: string[]
662
- observedAccess: Provenanced<boolean | "unknown">
663
- possibleAccess: Provenanced<boolean | "unknown">
664
- }
665
- /** Detected process side-effects. */
666
- process: {
667
- childProcesses: Provenanced<boolean | "unknown">
668
- persistence: Provenanced<boolean | "unknown">
669
- privilegeEscalation: Provenanced<boolean | "unknown">
670
- }
671
- /** Detected remote-operation surface (ssh, etc.). */
672
- remote: {
673
- enabled: Provenanced<boolean | "unknown">
674
- mutationHint: Provenanced<boolean | "unknown">
675
- }
676
- /** Detected git mutation surface. */
677
- git: {
678
- observed: Provenanced<boolean | "unknown">
679
- possible: Provenanced<boolean | "unknown">
680
- observedAccess: Provenanced<boolean | "unknown">
681
- possibleAccess: Provenanced<boolean | "unknown">
682
- }
683
- /** How completely the command could be analyzed. */
684
- parserCompleteness: ParserCompleteness
685
- /** Free-form warnings about analysis limitations. */
686
- analysisWarnings: string[]
687
- }
320
+ | "unknown";