@noppu-labs/opencode-permission-reviewer 3.2.0 → 3.2.2

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 (48) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/NOTICE +2 -2
  3. package/dist/explain.js +2723 -2723
  4. package/dist/index.d.ts +639 -540
  5. package/dist/index.js +9756 -9741
  6. package/dist/rpc.d.ts +1 -1
  7. package/dist/rpc.js +1 -1
  8. package/dist/tui/{opencode → adapters/opencode}/event-normalizer.ts +2 -2
  9. package/dist/tui/{config-fields.ts → modules/config/models/config-fields.ts} +2 -2
  10. package/dist/tui/{config-knobs.ts → modules/config/models/config-knobs.ts} +1 -1
  11. package/dist/tui/{config-policy-rules.ts → modules/config/models/config-policy-rules.ts} +2 -2
  12. package/dist/tui/{config-risk-policy.ts → modules/config/models/config-risk-policy.ts} +2 -1
  13. package/dist/tui/{config.ts → modules/config/services/config.ts} +5 -5
  14. package/dist/tui/{config → modules/config/services}/layer-read.ts +4 -3
  15. package/dist/tui/{config → modules/config/services}/loader.ts +3 -3
  16. package/dist/tui/{reviewer-model.ts → modules/config/services/reviewer-model.ts} +6 -3
  17. package/dist/tui/{config → modules/config/services}/risk-policy-clamp.ts +2 -2
  18. package/dist/tui/{system-one-routing.ts → modules/config/services/system-one-routing.ts} +1 -1
  19. package/dist/tui/{config → modules/config/services}/trust-boundary.ts +4 -4
  20. package/dist/tui/{config → modules/config/services}/trusted-degradation.ts +2 -2
  21. package/dist/tui/{config-rule-condition.ts → modules/policy/config-rule-condition.ts} +1 -1
  22. package/dist/tui/{ui-protocol.ts → modules/status/models/ui-protocol.ts} +9 -9
  23. package/dist/tui/{ui-state.ts → modules/status/services/ui-state.ts} +2 -2
  24. package/dist/tui/{ui-status-extras.ts → modules/status/services/ui-status-extras.ts} +4 -2
  25. package/dist/tui/{ui-status-parse.ts → modules/status/services/ui-status-parse.ts} +5 -5
  26. package/dist/tui/tui.tsx +5 -5
  27. package/dist/tui/ui/action-fit.ts +10 -2
  28. package/dist/tui/ui/attribution.ts +4 -3
  29. package/dist/tui/ui/components.tsx +1 -1
  30. package/dist/tui/ui/config-notices.ts +1 -1
  31. package/dist/tui/ui/fit-parts.ts +1 -1
  32. package/dist/tui/ui/manual-toast.ts +3 -3
  33. package/dist/tui/ui/review-feed.ts +3 -3
  34. package/dist/tui/ui/review-overlay.tsx +1 -1
  35. package/dist/tui/ui/review-result.tsx +1 -1
  36. package/dist/tui/ui/review-store.ts +3 -3
  37. package/dist/tui/ui/review-theme.ts +1 -1
  38. package/dist/tui/ui/v1-host.ts +5 -2
  39. package/dist/tui/ui/v2.tsx +1 -1
  40. package/package.json +3 -3
  41. package/dist/tui/types.ts +0 -357
  42. /package/dist/tui/{config → modules/config/services}/jsonc.ts +0 -0
  43. /package/dist/tui/{config → modules/config/services}/trust-boundary-keys.ts +0 -0
  44. /package/dist/tui/{failure-kind.ts → modules/status/models/failure-kind.ts} +0 -0
  45. /package/dist/tui/{ui → modules/status/models}/rpc.ts +0 -0
  46. /package/dist/tui/{ui-text-elide.ts → modules/status/services/ui-text-elide.ts} +0 -0
  47. /package/dist/tui/{descriptor-io.ts → utils/descriptor-io.ts} +0 -0
  48. /package/dist/tui/{is-record.ts → utils/is-record.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,257 +1,13 @@
1
- import { TypeSafeClient } from "@typesafe-ai/sdk";
2
1
  import "@opencode/client";
3
2
  import { Plugin } from "@opencode-ai/plugin";
4
3
  import { Plugin as Plugin$1 } from "@opencode/plugin";
5
4
  import "@opencode/plugin/promise/permission";
6
- //#region src/verified-ssh-script.d.ts
7
- interface VerifiedScriptEvidence {
8
- sha256: string;
9
- destination: string;
10
- port?: number;
11
- shell: "bash" | "sh";
12
- bytes?: number;
13
- status: "full" | "reused" | "unavailable";
14
- text: string;
15
- cacheKey?: string;
16
- }
17
- //#endregion
18
- //#region src/shell-token.d.ts
19
- /** A run of a token's value that shares one quoting. `opaque` marks text the
20
- * lexer kept whole from a substitution (an unquoted backtick form): it is
21
- * the substitution's command, not the outer command's, so no operator in it
22
- * acts on the outer command. It stays unquoted otherwise: a glob character
23
- * in it reads as it did before. */
24
- interface TokenSpan {
25
- text: string;
26
- quoted: boolean;
27
- opaque?: true;
28
- }
29
- interface ShellToken {
30
- /** Original text including any surrounding quotes. */
31
- raw: string;
32
- /** Unquoted/normalized value used for comparisons. */
33
- value: string;
34
- /** Value split into spans by quoting: every character of `value` appears
35
- * in exactly one span, marked `quoted` when it came from inside quotes
36
- * or from a backslash escape. An operator character (`>`, `*`, …) only
37
- * acts as an operator while it sits in an UNQUOTED span: a glued, partly
38
- * quoted `>"/dev/sda"` still redirects, while `'>/dev/sda'` is data.
39
- * A zero-width quoted span can end a word: it marks an empty quote right
40
- * after text that ends like a redirection operator (`<<<''`), and holds no
41
- * character of `value`. */
42
- spans?: TokenSpan[];
43
- }
44
- interface ShellSegment {
45
- tokens: ShellToken[];
46
- /** Separator that terminated this segment (`;`, `|`, `||`, `&`, `&&`, `(`,
47
- * `)`). Newlines and carriage returns are reported as `;`. Absent for the
48
- * final segment when the command does not end with a separator. A segment
49
- * with no tokens and `endedBy` `(` or `)` is a paren marker: it exists so
50
- * grouping events are never lost, and carries no command of its own. */
51
- endedBy?: string;
52
- /** The last separator seen before this segment's first token, counting
53
- * separators whose (empty) segment was dropped: in `( a ) | b`, segment
54
- * `b` ended up after a dropped empty segment, so its separator lineage is
55
- * `)` and then `|`, and `precededBy` reports `|`. Absent for the first
56
- * segment. */
57
- precededBy?: string;
58
- }
59
- //#endregion
60
- //#region src/walk-sink.d.ts
61
- /** A command the walk resolves, wrapper or not: its basename, the words of
62
- * its level and its index among them, and whether it runs inside the
63
- * remote command of an ssh, mosh or autossh. */
64
- interface PeeledHead {
65
- head: string;
66
- tokens: readonly ShellToken[];
67
- index: number;
68
- remote: boolean;
69
- }
70
- //#endregion
71
- //#region src/capability/capability-types.d.ts
72
- /** How completely the command could be statically analyzed. */
73
- type ParserCompleteness =
74
- /** Fully parsed: no variables, globs, substitutions, or heredoc bodies. */
75
- "complete-for-supported-form" |
76
- /** Some constructs could not be resolved (variables, partial heredoc). */
77
- "partial" |
78
- /** Heavy dynamic constructs (command substitution, eval, dynamic heredoc). */
79
- "opaque";
80
- /** A redirection extracted from a parsed command segment. */
81
- interface Redirection {
82
- /** `>` `>>` `<` `2>` `&>` etc. */
83
- operator: string;
84
- /** Target path (file descriptor targets normalized to a path when possible). */
85
- target: string;
86
- /** Whether the target was quoted in the source (affects literal-ness). */
87
- quoted: boolean;
88
- }
89
- /** A heredoc extracted before lexing so its body never reaches the lexer/brake. */
90
- interface HeredocRecord {
91
- /** The literal delimiter token as it appeared (`EOF`, `END`, …). */
92
- delimiter: string;
93
- /** `<<` (expansion on) or `<<-` (tabs stripped) — normalized form. */
94
- operator: string;
95
- /** Whether the delimiter was quoted, disabling expansion (`<<'EOF'`). */
96
- expansionDisabled: boolean;
97
- /** Bounded + redacted body (truncated to a safe length). */
98
- bodyBounded: string;
99
- /** SHA-256 of the full, unredacted body (stable identity without leaking it). */
100
- bodySha256: string;
101
- /** Whether the body was truncated for storage. */
102
- truncated: boolean;
103
- /** Output path associated with the heredoc when a `> path` precedes it. */
104
- outputTarget?: string;
105
- /** Whether the body is dynamically constructed (unresolvable expansion). */
106
- dynamic: boolean;
107
- }
108
- /** A command parsed into a reusable structure. Wraps the existing lexer output
109
- * plus pre-extracted redirections and heredocs. */
110
- interface ParsedCommand {
111
- /** The command after heredoc bodies were replaced with placeholders. */
112
- sanitizedCommand: string;
113
- /** Lexed segments of the sanitized command. */
114
- segments: ShellSegment[];
115
- /** Effective commands (wrappers peeled) per segment. */
116
- effective: ShellToken[][];
117
- /** Redirections grouped by segment index. */
118
- redirections: Redirection[][];
119
- /** Heredocs extracted before lexing. */
120
- heredocs: HeredocRecord[];
121
- /** Whether the original command contained any dynamic constructs. */
122
- hasDynamicConstructs: boolean;
123
- /** True when the lexer's depth or expansion budget stopped command-string
124
- * resolution early; `effective` is then a prefix of the real structure and
125
- * deterministic facts do not cover the whole command. */
126
- analysisTruncated: boolean;
127
- /** The effective commands that run on the far side of an ssh with no
128
- * remote command, from the script it reads. They are among `effective`
129
- * too. */
130
- remoteCommands?: ShellToken[][];
131
- /** Every command the walk resolves, wrappers among them, at every level:
132
- * command strings, `env -S`, `watch` and ssh remote commands. */
133
- heads: readonly PeeledHead[];
134
- /** The redirections each walked segment and command string carries
135
- * itself, whether or not it yields an effective command: the shell
136
- * opens them before it runs anything (`>f ssh h`). */
137
- segmentRedirections: readonly (readonly Redirection[])[];
138
- /** An interpreter among the commands runs code from a heredoc or
139
- * here-string. */
140
- stdinCode?: boolean;
141
- }
142
- /** What the action can do, what it appears to do, and analysis confidence. */
143
- interface CapabilityAssessment {
144
- /** Best single-label summary of the dominant capability. */
145
- actionClass: Provenanced<CapabilityActionClass>;
146
- /** Human-readable summary of the detected surface. */
147
- summary: string;
148
- /** Executes an interpreter or runtime (sh, python, node, bun, …). */
149
- executesCode: Provenanced<boolean | "unknown">;
150
- /** Executes code that lives in the repository (scripts, test files). */
151
- executesRepositoryCode: Provenanced<boolean | "unknown">;
152
- /** Executes ad-hoc code generated by the agent (heredoc/inline). */
153
- createsAdHocCode: Provenanced<boolean | "unknown">;
154
- /** Invokes a known test runner (pytest, jest, bun test, …). */
155
- invokesExistingTestRunner: Provenanced<boolean | "unknown">;
156
- /** Runs a package manager that may execute lifecycle scripts. */
157
- invokesPackageLifecycleScripts: Provenanced<boolean | "unknown">;
158
- /** Reads literal credential material through a known file reader. */
159
- credentialRead: Provenanced<boolean | "unknown">;
160
- /** Detected file-write surface. */
161
- writeEffects: {
162
- temporaryWrite: Provenanced<boolean | "unknown">;
163
- workspaceWrite: Provenanced<boolean | "unknown">;
164
- externalWrite: Provenanced<boolean | "unknown">;
165
- deletion: Provenanced<boolean | "unknown">;
166
- };
167
- /** Detected network surface. */
168
- network: {
169
- observed: Provenanced<boolean | "unknown">;
170
- possible: Provenanced<boolean | "unknown">;
171
- /** Hosts/destinations observed literally in the command. */
172
- destinations: string[];
173
- observedAccess: Provenanced<boolean | "unknown">;
174
- possibleAccess: Provenanced<boolean | "unknown">;
175
- };
176
- /** Detected process side-effects. */
177
- process: {
178
- childProcesses: Provenanced<boolean | "unknown">;
179
- persistence: Provenanced<boolean | "unknown">;
180
- privilegeEscalation: Provenanced<boolean | "unknown">;
181
- };
182
- /** Detected remote-operation surface (ssh, etc.). */
183
- remote: {
184
- enabled: Provenanced<boolean | "unknown">;
185
- mutationHint: Provenanced<boolean | "unknown">;
186
- };
187
- /** Detected git mutation surface. */
188
- git: {
189
- observed: Provenanced<boolean | "unknown">;
190
- possible: Provenanced<boolean | "unknown">;
191
- observedAccess: Provenanced<boolean | "unknown">;
192
- possibleAccess: Provenanced<boolean | "unknown">;
193
- };
194
- /** How completely the command could be analyzed. */
195
- parserCompleteness: ParserCompleteness;
196
- /** Free-form warnings about analysis limitations. */
197
- analysisWarnings: string[];
198
- }
199
- //#endregion
200
- //#region src/system-one/system-one-types.d.ts
201
- declare const SYSTEM_ONE_BASES: readonly ["authorized_routine", "authorized_reversible_change", "insufficient_authorization", "scope_mismatch", "insufficient_evidence", "destructive_effect", "credential_or_private_data", "security_or_privilege_change", "external_or_remote_effect", "trusted_policy_restriction", "conflicting_evidence"];
202
- type SystemOnePrimaryBasis = (typeof SYSTEM_ONE_BASES)[number];
203
- interface SystemOneChoiceScore<T extends string> {
204
- choice: T;
205
- confidence: number;
206
- }
207
- /** Probability (0-1) that each safety question is true. */
208
- interface SystemOneSignals {
209
- materialAuthorization: number;
210
- withinIntentScope: number;
211
- unauthorizedDataLoss: number;
212
- untrustedSensitiveDisclosure: number;
213
- excessiveCredentialAccess: number;
214
- unauthorizedSecurityChange: number;
215
- unauthorizedExternalMutation: number;
216
- essentialEvidenceMissing: number;
217
- absolutePolicyDeny: number;
218
- }
219
- /**
220
- * Jev's own answer, kept apart from the final decision because a reasoning
221
- * reviewer may replace it. Numbers, enum choices, fixed contradiction strings,
222
- * and the provider-reported model ID only; never evidence text.
223
- */
224
- interface SystemOneScores {
225
- /** Versioned model ID the provider reported as having answered. */
226
- returnedModel: string;
227
- outcome: SystemOneChoiceScore<ReviewOutcome> & {
228
- probabilities: Record<ReviewOutcome, number>;
229
- };
230
- supporting: {
231
- riskLevel: SystemOneChoiceScore<RiskLevel>;
232
- userAuthorization: SystemOneChoiceScore<UserAuthorization>;
233
- scopeAlignment: SystemOneChoiceScore<ScopeAlignment>;
234
- evidenceCompleteness: SystemOneChoiceScore<EvidenceSufficiency>;
235
- primaryBasis: SystemOneChoiceScore<SystemOnePrimaryBasis>;
236
- };
237
- signals: SystemOneSignals;
238
- /** Consistency checks that failed; any one marks an allow or deny difficult. */
239
- contradictions: string[];
240
- reasoningRecommended: boolean;
241
- }
242
- //#endregion
243
- //#region src/types.d.ts
5
+ //#region src/kernel/review-decision.d.ts
244
6
  type RiskLevel = "low" | "medium" | "high" | "critical";
245
7
  type UserAuthorization = "high" | "medium" | "low" | "unknown";
246
8
  type ReviewOutcome = "allow" | "deny" | "escalate";
247
9
  type ScopeAlignment = "aligned" | "partial" | "misaligned" | "unknown";
248
10
  type EvidenceSufficiency = "sufficient" | "partial" | "insufficient" | "unknown";
249
- /** How final escalations are disposed after reviewer/policy/fail-safe produce them. */
250
- type EscalationMode = "manual" | "deny";
251
- /** Effective disposition applied to an internal escalate result. */
252
- type EscalationDisposition = "manual" | "deny";
253
- /** Where an escalation that starts at Jev goes; `reasoning-first` sends every one to the escalation reviewer. */
254
- type SystemOneEscalationMode = "standard" | "reasoning-first";
255
11
  interface ReviewDecision {
256
12
  /** Structured-decision schema version. Always 2 for the current schema. */
257
13
  version: 2;
@@ -267,27 +23,17 @@ interface ReviewDecision {
267
23
  /** Optional script-only semantic analysis. Never conveys authorization. */
268
24
  script_analysis?: string;
269
25
  }
270
- interface PermissionToolSource {
271
- messageID: string;
272
- callID: string;
273
- }
274
- interface PermissionRequest {
275
- id: string;
26
+ interface ApprovedAnnotation {
27
+ requestID: string;
276
28
  sessionID: string;
277
- permission: string;
278
- patterns: string[];
279
- metadata: Record<string, unknown>;
280
- always: string[];
281
- tool?: PermissionToolSource;
282
- }
283
- interface MessageWithParts {
284
- info: Record<string, unknown> & {
285
- id?: string;
286
- role?: string;
287
- structured?: unknown;
288
- };
289
- parts: Array<Record<string, unknown>>;
29
+ decision: ReviewDecision;
290
30
  }
31
+ //#endregion
32
+ //#region src/kernel/reviewer-config.d.ts
33
+ /** How final escalations are disposed after reviewer/policy/fail-safe produce them. */
34
+ type EscalationMode = "manual" | "deny";
35
+ /** Where an escalation that starts at Jev goes; `reasoning-first` sends every one to the escalation reviewer. */
36
+ type SystemOneEscalationMode = "standard" | "reasoning-first";
291
37
  /** Deterministic risk×authorization matrix that gates reviewer `allow`
292
38
  * outcomes. For each risk level, lists the authorization levels that permit an
293
39
  * auto-allow. An empty array means no authorization permits auto-allow at that
@@ -435,102 +181,16 @@ interface ReviewerConfig {
435
181
  * on but inert. Informational only: never affects a decision. */
436
182
  configWarnings?: string[];
437
183
  }
438
- interface ReviewEnvelope {
439
- request: PermissionRequest;
440
- directory: string;
441
- worktree: string;
442
- transcript: string;
443
- intentHistory: string;
444
- enrichment: string;
445
- verifiedScript?: VerifiedScriptEvidence;
446
- sshAudit: NonNullable<ReviewAuditRecord["ssh"]>;
447
- preflightDenial?: string;
448
- /** Agent-aware context (actor, lineage, intent). Observe-only: flows into the
449
- * reviewer prompt and audit as evidence, never into enforcement decisions.
450
- * Optional so older callers/tests still compile. */
451
- actor?: ActorContext;
452
- lineage?: SessionLineage;
453
- intent?: IntentContext;
454
- evidenceCompleteness?: EvidenceCompleteness;
455
- /** Structured capability facts derived from the bash command. Observe-only:
456
- * feeds the reviewer prompt and audit, never enforcement. */
457
- capability?: CapabilityAssessment;
458
- /** The policy trace produced for this request, surfaced to the reviewer prompt
459
- * as EFFECTIVE_POLICY_SUMMARY and to audit. Observe-only. */
460
- policyTrace?: PolicyTrace;
461
- /** Per-phase timing captured during evidence assembly (context/enrichment).
462
- * The reviewer and reply phases are timed in the coordinator. */
463
- timings?: {
464
- contextMs?: number;
465
- enrichmentMs?: number;
466
- reviewerMs?: number;
467
- replyMs?: number;
468
- };
469
- /** False when a material part of the action under review (e.g. an elided
470
- * command segment) never reached the rendered evidence. Blocking: the
471
- * coordinator must not auto-approve an action the reviewer could not see
472
- * in full, whatever confidence the model reports. */
473
- actionEvidenceComplete?: boolean;
474
- /** The parsed command reused across evidence providers. */
475
- parsedCommand?: ParsedCommand;
476
- /** Operational purpose of the pending action (evidence, never authorization). */
477
- actionPurpose?: ActionPurpose;
478
- /** User answers to agent ask dialogs in this session or its ancestors,
479
- * captured live from question events. Observe-only: flows into the reviewer
480
- * prompt (USER_ASK_DECISIONS) and audit, never into enforcement. */
481
- askDecisions?: AskDecision[];
482
- }
483
- interface ApprovedAnnotation {
484
- requestID: string;
485
- sessionID: string;
486
- decision: ReviewDecision;
487
- }
488
- /** Why a System One (Jev) result was handed to the reasoning reviewer. */
489
- type HandoffTrigger = "jev-escalate" | "jev-uncertain-allow" | "jev-gate" | "jev-invalid" | "jev-failure" | "jev-uncertain-deny";
490
- /** The primary model, routing reason and hand-off trigger of a review a
491
- * second reviewer decided. */
492
- interface EscalatedFrom {
493
- model: string;
494
- reason: string;
495
- trigger?: HandoffTrigger;
496
- }
497
- /** How an escalation that left the System One backend was reached. */
498
- type ManualResolution = "reviewer" | "reasoning-escalated" | "reasoning-unavailable" | "budget-exhausted";
499
- interface ReviewExecutionResult {
500
- kind: "allow" | "deny" | "escalate";
501
- decision?: ReviewDecision;
502
- reason: string;
503
- reviewSessionID?: string;
504
- /** Which layer produced this result; threaded into the audit record. */
505
- decisionSource?: DecisionSource;
506
- /** Actual model that produced the final reviewer decision. */
507
- reviewerModel?: string;
508
- /** Primary model, routing reason and hand-off trigger when a second
509
- * reviewer was used. */
510
- reviewerEscalatedFrom?: EscalatedFrom;
511
- /** Jev's scores whenever it returned a parsed decision. */
512
- systemOne?: SystemOneScores;
513
- /**
514
- * Structured outcome from the reviewer LLM before gates/disposition.
515
- * Absent when no valid structured decision was produced.
516
- */
517
- reviewerOutcome?: ReviewOutcome;
518
- /**
519
- * How an internal escalate was disposed at the enforcement boundary.
520
- * Absent when the result was never an escalate (explicit allow/deny) or when
521
- * the request was already answered manually (`manual-superseded`).
522
- */
523
- escalationDisposition?: EscalationDisposition;
524
- /** Set only by the System One backend, on escalations; kept when a
525
- * disposition turns one into a deny. */
526
- resolution?: ManualResolution;
527
- }
528
184
  /** Generic policy templates, NOT automatic trust levels. */
529
185
  type ActorProfile = "read-only" | "validation" | "workspace" | "operator" | "reviewer" | "unknown";
530
186
  /** High-level classification of what the action does. */
531
187
  type CapabilityActionClass = "read-only" | "workspace-write" | "temporary-write" | "external-write" | "destruction" | "code-execution" | "package-management" | "git-mutation" | "network" | "remote-operation" | "service-management" | "persistence" | "privilege-escalation" | "unknown";
532
188
  //#endregion
533
- //#region src/actor-context-types.d.ts
189
+ //#region src/utils/logger.d.ts
190
+ /** A diagnostic log sink: a message and optional structured details. */
191
+ type Logger = (message: string, details?: unknown) => void;
192
+ //#endregion
193
+ //#region src/kernel/actor-context-types.d.ts
534
194
  /** Reliability of a derived fact. */
535
195
  type EvidenceConfidence = "confirmed" | "high" | "medium" | "low" | "unknown";
536
196
  /** Every non-trivial derived fact carries provenance so the LLM and audit can
@@ -638,10 +298,95 @@ interface ActionPurpose {
638
298
  confidence: EvidenceConfidence;
639
299
  }
640
300
  //#endregion
641
- //#region src/audit-record.d.ts
301
+ //#region src/kernel/review-result.d.ts
302
+ /** Effective disposition applied to an internal escalate result. */
303
+ type EscalationDisposition = "manual" | "deny";
304
+ /** Why a System One (Jev) result was handed to the reasoning reviewer. */
305
+ type HandoffTrigger = "jev-escalate" | "jev-uncertain-allow" | "jev-gate" | "jev-invalid" | "jev-failure" | "jev-uncertain-deny";
306
+ /** The primary model, routing reason and hand-off trigger of a review a
307
+ * second reviewer decided. */
308
+ interface EscalatedFrom {
309
+ model: string;
310
+ reason: string;
311
+ trigger?: HandoffTrigger;
312
+ }
313
+ /** How an escalation that left the System One backend was reached. */
314
+ type ManualResolution = "reviewer" | "reasoning-escalated" | "reasoning-unavailable" | "budget-exhausted";
315
+ interface ReviewExecutionResult {
316
+ kind: "allow" | "deny" | "escalate";
317
+ decision?: ReviewDecision;
318
+ reason: string;
319
+ reviewSessionID?: string;
320
+ /** Which layer produced this result; threaded into the audit record. */
321
+ decisionSource?: DecisionSource;
322
+ /** Actual model that produced the final reviewer decision. */
323
+ reviewerModel?: string;
324
+ /** Primary model, routing reason and hand-off trigger when a second
325
+ * reviewer was used. */
326
+ reviewerEscalatedFrom?: EscalatedFrom;
327
+ /** Jev's scores whenever it returned a parsed decision. */
328
+ systemOne?: SystemOneScores;
329
+ /**
330
+ * Structured outcome from the reviewer LLM before gates/disposition.
331
+ * Absent when no valid structured decision was produced.
332
+ */
333
+ reviewerOutcome?: ReviewOutcome;
334
+ /**
335
+ * How an internal escalate was disposed at the enforcement boundary.
336
+ * Absent when the result was never an escalate (explicit allow/deny) or when
337
+ * the request was already answered manually (`manual-superseded`).
338
+ */
339
+ escalationDisposition?: EscalationDisposition;
340
+ /** Set only by the System One backend, on escalations; kept when a
341
+ * disposition turns one into a deny. */
342
+ resolution?: ManualResolution;
343
+ }
642
344
  /** Which layer produced the final decision for a request. Threaded into the
643
345
  * audit record so reports can split outcomes by source. */
644
346
  type DecisionSource = "emergency-brake" | "deterministic-policy" | "llm-reviewer" | "system-one-reviewer" | "manual-superseded" | "failure-safe";
347
+ declare const SYSTEM_ONE_BASES: readonly ["authorized_routine", "authorized_reversible_change", "insufficient_authorization", "scope_mismatch", "insufficient_evidence", "destructive_effect", "credential_or_private_data", "security_or_privilege_change", "external_or_remote_effect", "trusted_policy_restriction", "conflicting_evidence"];
348
+ type SystemOnePrimaryBasis = (typeof SYSTEM_ONE_BASES)[number];
349
+ interface SystemOneChoiceScore<T extends string> {
350
+ choice: T;
351
+ confidence: number;
352
+ }
353
+ /** Probability (0-1) that each safety question is true. */
354
+ interface SystemOneSignals {
355
+ materialAuthorization: number;
356
+ withinIntentScope: number;
357
+ unauthorizedDataLoss: number;
358
+ untrustedSensitiveDisclosure: number;
359
+ excessiveCredentialAccess: number;
360
+ unauthorizedSecurityChange: number;
361
+ unauthorizedExternalMutation: number;
362
+ essentialEvidenceMissing: number;
363
+ absolutePolicyDeny: number;
364
+ }
365
+ /**
366
+ * Jev's own answer, kept apart from the final decision because a reasoning
367
+ * reviewer may replace it. Numbers, enum choices, fixed contradiction strings,
368
+ * and the provider-reported model ID only; never evidence text.
369
+ */
370
+ interface SystemOneScores {
371
+ /** Versioned model ID the provider reported as having answered. */
372
+ returnedModel: string;
373
+ outcome: SystemOneChoiceScore<ReviewOutcome> & {
374
+ probabilities: Record<ReviewOutcome, number>;
375
+ };
376
+ supporting: {
377
+ riskLevel: SystemOneChoiceScore<RiskLevel>;
378
+ userAuthorization: SystemOneChoiceScore<UserAuthorization>;
379
+ scopeAlignment: SystemOneChoiceScore<ScopeAlignment>;
380
+ evidenceCompleteness: SystemOneChoiceScore<EvidenceSufficiency>;
381
+ primaryBasis: SystemOneChoiceScore<SystemOnePrimaryBasis>;
382
+ };
383
+ signals: SystemOneSignals;
384
+ /** Consistency checks that failed; any one marks an allow or deny difficult. */
385
+ contradictions: string[];
386
+ reasoningRecommended: boolean;
387
+ }
388
+ //#endregion
389
+ //#region src/modules/audit/models/audit-record.d.ts
645
390
  interface ReviewAuditRecord {
646
391
  /**
647
392
  * Audit schema version. Present on every record; readers default a missing
@@ -716,113 +461,430 @@ interface ReviewAuditRecord {
716
461
  reviewerMs?: number;
717
462
  replyMs?: number;
718
463
  };
719
- /** Non-fatal warnings accumulated during evidence collection/analysis. */
720
- warnings?: string[];
721
- reviewerSessionID?: string;
722
- /** Content identity and inspection mode only; never script text or local path. */
723
- verifiedScript?: {
724
- sha256: string;
725
- status: "full" | "reused" | "unavailable";
726
- bytes?: number;
727
- };
728
- /** Root session of the request's ancestry (additive; absent when lineage was
729
- * unavailable). */
730
- rootSessionID?: string;
731
- /** Overall evidence completeness for the request (additive). */
732
- evidenceCompleteness?: string;
733
- /** Resolved actor snapshot for audit (additive). Uses identityCompleteness
734
- * (not the decision's numeric confidence) to avoid field ambiguity; v2 also
735
- * carries identitySource + confidence. */
736
- actor?: {
737
- name?: string;
738
- mode?: string;
739
- profile: ActorProfile;
740
- identityCompleteness: "complete" | "partial" | "unknown";
741
- /** How the agent identity was established (tool-message, session-api,
742
- * unavailable, …). Absent on legacy v1 records. */
743
- identitySource?: string;
744
- /** Reliability of the identity claim. Absent on legacy v1 records. */
745
- confidence?: EvidenceConfidence;
746
- delegationDepth?: number;
747
- };
748
- ssh?: Array<{
749
- destination: string;
750
- port?: string;
751
- remoteCommandSha256?: string;
752
- stdinSource?: string;
753
- stdinStatus?: string;
754
- stdinReason?: string;
755
- }>;
756
- /** Additive capability snapshot for audit (observe-only). */
757
- capability?: {
758
- actionClass: string;
759
- summary: string;
760
- parserCompleteness: string;
761
- executesCode?: boolean;
762
- createsAdHocCode?: boolean;
763
- invokesPackageLifecycleScripts?: boolean;
764
- writeEffects?: {
765
- temporaryWrite?: boolean;
766
- workspaceWrite?: boolean;
767
- externalWrite?: boolean;
768
- deletion?: boolean;
769
- };
770
- networkObserved?: boolean;
771
- credentialRead?: boolean;
772
- privilegeEscalation?: boolean;
773
- persistence?: boolean;
774
- remoteEnabled?: boolean;
775
- gitMutation?: boolean;
776
- };
777
- /** Additive policy trace for audit (observe-only). */
778
- policyTrace?: {
779
- effectivePolicyHash: string;
780
- matchedRules: Array<{
781
- id: string;
782
- source: string;
783
- effect: string;
784
- reason: string;
785
- }>;
786
- finalRoute: string;
787
- mode: string;
788
- };
789
- /** Additive snapshot of the ask decisions surfaced to the reviewer prompt
790
- * (observe-only; capped to the most recent few). */
791
- askDecisions?: Array<{
792
- at: number;
793
- question: string;
794
- answer: string;
795
- }>;
464
+ /** Non-fatal warnings accumulated during evidence collection/analysis. */
465
+ warnings?: string[];
466
+ reviewerSessionID?: string;
467
+ /** Content identity and inspection mode only; never script text or local path. */
468
+ verifiedScript?: {
469
+ sha256: string;
470
+ status: "full" | "reused" | "unavailable";
471
+ bytes?: number;
472
+ };
473
+ /** Root session of the request's ancestry (additive; absent when lineage was
474
+ * unavailable). */
475
+ rootSessionID?: string;
476
+ /** Overall evidence completeness for the request (additive). */
477
+ evidenceCompleteness?: string;
478
+ /** Resolved actor snapshot for audit (additive). Uses identityCompleteness
479
+ * (not the decision's numeric confidence) to avoid field ambiguity; v2 also
480
+ * carries identitySource + confidence. */
481
+ actor?: {
482
+ name?: string;
483
+ mode?: string;
484
+ profile: ActorProfile;
485
+ identityCompleteness: "complete" | "partial" | "unknown";
486
+ /** How the agent identity was established (tool-message, session-api,
487
+ * unavailable, …). Absent on legacy v1 records. */
488
+ identitySource?: string;
489
+ /** Reliability of the identity claim. Absent on legacy v1 records. */
490
+ confidence?: EvidenceConfidence;
491
+ delegationDepth?: number;
492
+ };
493
+ ssh?: Array<{
494
+ destination: string;
495
+ port?: string;
496
+ remoteCommandSha256?: string;
497
+ stdinSource?: string;
498
+ stdinStatus?: string;
499
+ stdinReason?: string;
500
+ }>;
501
+ /** Additive capability snapshot for audit (observe-only). */
502
+ capability?: {
503
+ actionClass: string;
504
+ summary: string;
505
+ parserCompleteness: string;
506
+ executesCode?: boolean;
507
+ createsAdHocCode?: boolean;
508
+ invokesPackageLifecycleScripts?: boolean;
509
+ writeEffects?: {
510
+ temporaryWrite?: boolean;
511
+ workspaceWrite?: boolean;
512
+ externalWrite?: boolean;
513
+ deletion?: boolean;
514
+ };
515
+ networkObserved?: boolean;
516
+ credentialRead?: boolean;
517
+ privilegeEscalation?: boolean;
518
+ persistence?: boolean;
519
+ remoteEnabled?: boolean;
520
+ gitMutation?: boolean;
521
+ };
522
+ /** Additive policy trace for audit (observe-only). */
523
+ policyTrace?: {
524
+ effectivePolicyHash: string;
525
+ matchedRules: Array<{
526
+ id: string;
527
+ source: string;
528
+ effect: string;
529
+ reason: string;
530
+ }>;
531
+ finalRoute: string;
532
+ mode: string;
533
+ };
534
+ /** Additive snapshot of the ask decisions surfaced to the reviewer prompt
535
+ * (observe-only; capped to the most recent few). */
536
+ askDecisions?: Array<{
537
+ at: number;
538
+ question: string;
539
+ answer: string;
540
+ }>;
541
+ }
542
+ //#endregion
543
+ //#region src/modules/audit/services/audit.d.ts
544
+ export declare const DEFAULT_AUDIT_PATH = "~/.local/share/opencode/permission-reviewer-audit.jsonl";
545
+ export declare function createAuditWriter(config: ReviewerConfig, logger?: Logger): ((record: ReviewAuditRecord) => Promise<void>) | undefined;
546
+ //#endregion
547
+ //#region src/modules/config/services/sources.d.ts
548
+ /** The host passing an options object does not attest who authored it. */
549
+ type InlineOptionsTrust = "trusted" | "project" | "unknown";
550
+ //#endregion
551
+ //#region src/modules/config/services/loader.d.ts
552
+ interface LoadOptions {
553
+ /** Off for a caller that shows `configWarnings` another way, such as the TUI
554
+ * from server statuses. */
555
+ printConfigWarnings?: boolean;
556
+ }
557
+ /** Load and merge config from global, project, and inline sources.
558
+ *
559
+ * Precedence (lowest to highest): builtin defaults → global → project → inline,
560
+ * with one deliberate exception: security-sensitive fields cross a trust
561
+ * boundary where the untrusted project layer can only TIGHTEN the trusted
562
+ * baseline (see mergeWithTrustBoundary), and that hardening survives even
563
+ * when inline set the same field.
564
+ *
565
+ * When no global or project files exist (the common case), the result is
566
+ * byte-identical to calling `resolveConfig(inlineOptions)` directly. */
567
+ export declare function loadResolvedConfig(inlineOptions: Record<string, unknown> | undefined, directory?: string, inlineTrust?: InlineOptionsTrust, { printConfigWarnings }?: LoadOptions): ReviewerConfig;
568
+ //#endregion
569
+ //#region src/kernel/permission-request.d.ts
570
+ interface PermissionToolSource {
571
+ messageID: string;
572
+ callID: string;
573
+ }
574
+ interface PermissionRequest {
575
+ id: string;
576
+ sessionID: string;
577
+ permission: string;
578
+ patterns: string[];
579
+ metadata: Record<string, unknown>;
580
+ always: string[];
581
+ tool?: PermissionToolSource;
582
+ }
583
+ //#endregion
584
+ //#region src/modules/evidence/ssh/verified-ssh-script.d.ts
585
+ interface VerifiedScriptEvidence {
586
+ sha256: string;
587
+ destination: string;
588
+ port?: number;
589
+ shell: "bash" | "sh";
590
+ bytes?: number;
591
+ status: "full" | "reused" | "unavailable";
592
+ text: string;
593
+ cacheKey?: string;
594
+ }
595
+ //#endregion
596
+ //#region src/modules/analysis/shell/shell-token.d.ts
597
+ /** A run of a token's value that shares one quoting. `opaque` marks text the
598
+ * lexer kept whole from a substitution (an unquoted backtick form): it is
599
+ * the substitution's command, not the outer command's, so no operator in it
600
+ * acts on the outer command. It stays unquoted otherwise: a glob character
601
+ * in it reads as it did before. */
602
+ interface TokenSpan {
603
+ text: string;
604
+ quoted: boolean;
605
+ opaque?: true;
606
+ }
607
+ interface ShellToken {
608
+ /** Original text including any surrounding quotes. */
609
+ raw: string;
610
+ /** Unquoted/normalized value used for comparisons. */
611
+ value: string;
612
+ /** Value split into spans by quoting: every character of `value` appears
613
+ * in exactly one span, marked `quoted` when it came from inside quotes
614
+ * or from a backslash escape. An operator character (`>`, `*`, …) only
615
+ * acts as an operator while it sits in an UNQUOTED span: a glued, partly
616
+ * quoted `>"/dev/sda"` still redirects, while `'>/dev/sda'` is data.
617
+ * A zero-width quoted span can end a word: it marks an empty quote right
618
+ * after text that ends like a redirection operator (`<<<''`), and holds no
619
+ * character of `value`. */
620
+ spans?: TokenSpan[];
621
+ }
622
+ interface ShellSegment {
623
+ tokens: ShellToken[];
624
+ /** Separator that terminated this segment (`;`, `|`, `||`, `&`, `&&`, `(`,
625
+ * `)`). Newlines and carriage returns are reported as `;`. Absent for the
626
+ * final segment when the command does not end with a separator. A segment
627
+ * with no tokens and `endedBy` `(` or `)` is a paren marker: it exists so
628
+ * grouping events are never lost, and carries no command of its own. */
629
+ endedBy?: string;
630
+ /** The last separator seen before this segment's first token, counting
631
+ * separators whose (empty) segment was dropped: in `( a ) | b`, segment
632
+ * `b` ended up after a dropped empty segment, so its separator lineage is
633
+ * `)` and then `|`, and `precededBy` reports `|`. Absent for the first
634
+ * segment. */
635
+ precededBy?: string;
636
+ }
637
+ //#endregion
638
+ //#region src/modules/analysis/walk/walk-sink.d.ts
639
+ /** A command the walk resolves, wrapper or not: its basename, the words of
640
+ * its level and its index among them, and whether it runs inside the
641
+ * remote command of an ssh, mosh or autossh. */
642
+ interface PeeledHead {
643
+ head: string;
644
+ tokens: readonly ShellToken[];
645
+ index: number;
646
+ remote: boolean;
647
+ }
648
+ //#endregion
649
+ //#region src/modules/analysis/capability/models/capability-types.d.ts
650
+ /** How completely the command could be statically analyzed. */
651
+ type ParserCompleteness =
652
+ /** Fully parsed: no variables, globs, substitutions, or heredoc bodies. */
653
+ "complete-for-supported-form" |
654
+ /** Some constructs could not be resolved (variables, partial heredoc). */
655
+ "partial" |
656
+ /** Heavy dynamic constructs (command substitution, eval, dynamic heredoc). */
657
+ "opaque";
658
+ /** A redirection extracted from a parsed command segment. */
659
+ interface Redirection {
660
+ /** `>` `>>` `<` `2>` `&>` etc. */
661
+ operator: string;
662
+ /** Target path (file descriptor targets normalized to a path when possible). */
663
+ target: string;
664
+ /** Whether the target was quoted in the source (affects literal-ness). */
665
+ quoted: boolean;
666
+ }
667
+ /** A heredoc extracted before lexing so its body never reaches the lexer/brake. */
668
+ interface HeredocRecord {
669
+ /** The literal delimiter token as it appeared (`EOF`, `END`, …). */
670
+ delimiter: string;
671
+ /** `<<` (expansion on) or `<<-` (tabs stripped) — normalized form. */
672
+ operator: string;
673
+ /** Whether the delimiter was quoted, disabling expansion (`<<'EOF'`). */
674
+ expansionDisabled: boolean;
675
+ /** Bounded + redacted body (truncated to a safe length). */
676
+ bodyBounded: string;
677
+ /** SHA-256 of the full, unredacted body (stable identity without leaking it). */
678
+ bodySha256: string;
679
+ /** Whether the body was truncated for storage. */
680
+ truncated: boolean;
681
+ /** Output path associated with the heredoc when a `> path` precedes it. */
682
+ outputTarget?: string;
683
+ /** Whether the body is dynamically constructed (unresolvable expansion). */
684
+ dynamic: boolean;
685
+ }
686
+ /** A command parsed into a reusable structure. Wraps the existing lexer output
687
+ * plus pre-extracted redirections and heredocs. */
688
+ interface ParsedCommand {
689
+ /** The command after heredoc bodies were replaced with placeholders. */
690
+ sanitizedCommand: string;
691
+ /** Lexed segments of the sanitized command. */
692
+ segments: ShellSegment[];
693
+ /** Effective commands (wrappers peeled) per segment. */
694
+ effective: ShellToken[][];
695
+ /** Redirections grouped by segment index. */
696
+ redirections: Redirection[][];
697
+ /** Heredocs extracted before lexing. */
698
+ heredocs: HeredocRecord[];
699
+ /** Whether the original command contained any dynamic constructs. */
700
+ hasDynamicConstructs: boolean;
701
+ /** True when the lexer's depth or expansion budget stopped command-string
702
+ * resolution early; `effective` is then a prefix of the real structure and
703
+ * deterministic facts do not cover the whole command. */
704
+ analysisTruncated: boolean;
705
+ /** The effective commands that run on the far side of an ssh with no
706
+ * remote command, from the script it reads. They are among `effective`
707
+ * too. */
708
+ remoteCommands?: ShellToken[][];
709
+ /** Every command the walk resolves, wrappers among them, at every level:
710
+ * command strings, `env -S`, `watch` and ssh remote commands. */
711
+ heads: readonly PeeledHead[];
712
+ /** The redirections each walked segment and command string carries
713
+ * itself, whether or not it yields an effective command: the shell
714
+ * opens them before it runs anything (`>f ssh h`). */
715
+ segmentRedirections: readonly (readonly Redirection[])[];
716
+ /** An interpreter among the commands runs code from a heredoc or
717
+ * here-string. */
718
+ stdinCode?: boolean;
719
+ }
720
+ /** What the action can do, what it appears to do, and analysis confidence. */
721
+ interface CapabilityAssessment {
722
+ /** Best single-label summary of the dominant capability. */
723
+ actionClass: Provenanced<CapabilityActionClass>;
724
+ /** Human-readable summary of the detected surface. */
725
+ summary: string;
726
+ /** Executes an interpreter or runtime (sh, python, node, bun, …). */
727
+ executesCode: Provenanced<boolean | "unknown">;
728
+ /** Executes code that lives in the repository (scripts, test files). */
729
+ executesRepositoryCode: Provenanced<boolean | "unknown">;
730
+ /** Executes ad-hoc code generated by the agent (heredoc/inline). */
731
+ createsAdHocCode: Provenanced<boolean | "unknown">;
732
+ /** Invokes a known test runner (pytest, jest, bun test, …). */
733
+ invokesExistingTestRunner: Provenanced<boolean | "unknown">;
734
+ /** Runs a package manager that may execute lifecycle scripts. */
735
+ invokesPackageLifecycleScripts: Provenanced<boolean | "unknown">;
736
+ /** Reads literal credential material through a known file reader. */
737
+ credentialRead: Provenanced<boolean | "unknown">;
738
+ /** Detected file-write surface. */
739
+ writeEffects: {
740
+ temporaryWrite: Provenanced<boolean | "unknown">;
741
+ workspaceWrite: Provenanced<boolean | "unknown">;
742
+ externalWrite: Provenanced<boolean | "unknown">;
743
+ deletion: Provenanced<boolean | "unknown">;
744
+ };
745
+ /** Detected network surface. */
746
+ network: {
747
+ observed: Provenanced<boolean | "unknown">;
748
+ possible: Provenanced<boolean | "unknown">;
749
+ /** Hosts/destinations observed literally in the command. */
750
+ destinations: string[];
751
+ observedAccess: Provenanced<boolean | "unknown">;
752
+ possibleAccess: Provenanced<boolean | "unknown">;
753
+ };
754
+ /** Detected process side-effects. */
755
+ process: {
756
+ childProcesses: Provenanced<boolean | "unknown">;
757
+ persistence: Provenanced<boolean | "unknown">;
758
+ privilegeEscalation: Provenanced<boolean | "unknown">;
759
+ };
760
+ /** Detected remote-operation surface (ssh, etc.). */
761
+ remote: {
762
+ enabled: Provenanced<boolean | "unknown">;
763
+ mutationHint: Provenanced<boolean | "unknown">;
764
+ };
765
+ /** Detected git mutation surface. */
766
+ git: {
767
+ observed: Provenanced<boolean | "unknown">;
768
+ possible: Provenanced<boolean | "unknown">;
769
+ observedAccess: Provenanced<boolean | "unknown">;
770
+ possibleAccess: Provenanced<boolean | "unknown">;
771
+ };
772
+ /** How completely the command could be analyzed. */
773
+ parserCompleteness: ParserCompleteness;
774
+ /** Free-form warnings about analysis limitations. */
775
+ analysisWarnings: string[];
776
+ }
777
+ //#endregion
778
+ //#region src/modules/evidence/ssh/ssh-evidence.d.ts
779
+ interface SshAuditSummary {
780
+ destination: string;
781
+ port?: string;
782
+ remoteCommandSha256?: string;
783
+ stdinSource?: string;
784
+ stdinStatus?: string;
785
+ stdinReason?: string;
786
+ }
787
+ interface SshEnrichmentResult {
788
+ text: string;
789
+ audit: SshAuditSummary[];
790
+ preflightDenial?: string;
791
+ }
792
+ export declare function enrichSshEvidence(request: PermissionRequest, directory: string, worktree: string, maxChars: number): Promise<SshEnrichmentResult>;
793
+ //#endregion
794
+ //#region src/modules/context/models/review-envelope.d.ts
795
+ interface ReviewEnvelope {
796
+ request: PermissionRequest;
797
+ directory: string;
798
+ worktree: string;
799
+ transcript: string;
800
+ intentHistory: string;
801
+ enrichment: string;
802
+ verifiedScript?: VerifiedScriptEvidence;
803
+ sshAudit: SshAuditSummary[];
804
+ preflightDenial?: string;
805
+ /** Agent-aware context (actor, lineage, intent). Observe-only: flows into the
806
+ * reviewer prompt and audit as evidence, never into enforcement decisions.
807
+ * Optional so older callers/tests still compile. */
808
+ actor?: ActorContext;
809
+ lineage?: SessionLineage;
810
+ intent?: IntentContext;
811
+ evidenceCompleteness?: EvidenceCompleteness;
812
+ /** Structured capability facts derived from the bash command. Observe-only:
813
+ * feeds the reviewer prompt and audit, never enforcement. */
814
+ capability?: CapabilityAssessment;
815
+ /** The policy trace produced for this request, surfaced to the reviewer prompt
816
+ * as EFFECTIVE_POLICY_SUMMARY and to audit. Observe-only. */
817
+ policyTrace?: PolicyTrace;
818
+ /** Per-phase timing captured during evidence assembly (context/enrichment).
819
+ * The reviewer and reply phases are timed in the coordinator. */
820
+ timings?: {
821
+ contextMs?: number;
822
+ enrichmentMs?: number;
823
+ reviewerMs?: number;
824
+ replyMs?: number;
825
+ };
826
+ /** False when a material part of the action under review (e.g. an elided
827
+ * command segment) never reached the rendered evidence. Blocking: the
828
+ * coordinator must not auto-approve an action the reviewer could not see
829
+ * in full, whatever confidence the model reports. */
830
+ actionEvidenceComplete?: boolean;
831
+ /** The parsed command reused across evidence providers. */
832
+ parsedCommand?: ParsedCommand;
833
+ /** Operational purpose of the pending action (evidence, never authorization). */
834
+ actionPurpose?: ActionPurpose;
835
+ /** User answers to agent ask dialogs in this session or its ancestors,
836
+ * captured live from question events. Observe-only: flows into the reviewer
837
+ * prompt (USER_ASK_DECISIONS) and audit, never into enforcement. */
838
+ askDecisions?: AskDecision[];
796
839
  }
797
840
  //#endregion
798
- //#region src/audit.d.ts
799
- export declare const DEFAULT_AUDIT_PATH = "~/.local/share/opencode/permission-reviewer-audit.jsonl";
800
- type AuditLogger = (message: string, details?: unknown) => void;
801
- export declare function createAuditWriter(config: ReviewerConfig, logger?: AuditLogger): ((record: ReviewAuditRecord) => Promise<void>) | undefined;
841
+ //#region src/modules/review/models/contracts.d.ts
842
+ /** Receiving an approval does not prove that a tool executed. */
843
+ type ApplicationResult = "evaluation-returned" | "reply-accepted" | "human-pending" | "superseded" | "cancelled" | "unknown";
802
844
  //#endregion
803
- //#region src/config/sources.d.ts
804
- /** The host passing an options object does not attest who authored it. */
805
- type InlineOptionsTrust = "trusted" | "project" | "unknown";
845
+ //#region src/kernel/review-attempt.d.ts
846
+ /** What the reviewer needs from a review attempt: its cancellation, its
847
+ * remaining budget, and a wait that rejects once it is no longer active. */
848
+ interface ReviewAttemptView {
849
+ readonly signal: AbortSignal;
850
+ remainingMs(): number;
851
+ active(): boolean;
852
+ wait<T>(operation: Promise<T>): Promise<T>;
853
+ }
806
854
  //#endregion
807
- //#region src/config/loader.d.ts
808
- interface LoadOptions {
809
- /** Off for a caller that shows `configWarnings` another way, such as the TUI
810
- * from server statuses. */
811
- printConfigWarnings?: boolean;
855
+ //#region src/modules/review/services/review-attempt.d.ts
856
+ type AttemptState = "reviewing" | "finished" | "cancelled" | "expired";
857
+ /** One invocation owns its deadline, identity, and terminal transition. */
858
+ declare class ReviewAttempt implements ReviewAttemptView {
859
+ readonly generation: string;
860
+ private readonly now;
861
+ application: ApplicationResult;
862
+ readonly evidence: Partial<Pick<ReviewEnvelope, "sshAudit" | "actor" | "capability" | "policyTrace" | "askDecisions" | "evidenceCompleteness" | "verifiedScript">> & {
863
+ timings?: {
864
+ contextMs?: number;
865
+ enrichmentMs?: number;
866
+ reviewerMs?: number;
867
+ replyMs?: number;
868
+ };
869
+ };
870
+ readonly id: string;
871
+ readonly controller: AbortController;
872
+ readonly startedAt: number;
873
+ readonly deadline: number;
874
+ private stateValue;
875
+ private terminalReason;
876
+ private readonly timer;
877
+ constructor(generation: string, budgetMs: number, now?: () => number, newID?: () => string);
878
+ get state(): AttemptState;
879
+ get signal(): AbortSignal;
880
+ remainingMs(): number;
881
+ active(generation?: string): boolean;
882
+ close(state: Exclude<AttemptState, "reviewing">): boolean;
883
+ /** Abort the wait even if a host operation cannot cancel its transport. */
884
+ wait<T>(operation: Promise<T>): Promise<T>;
812
885
  }
813
- /** Load and merge config from global, project, and inline sources.
814
- *
815
- * Precedence (lowest to highest): builtin defaults → global → project → inline,
816
- * with one deliberate exception: security-sensitive fields cross a trust
817
- * boundary where the untrusted project layer can only TIGHTEN the trusted
818
- * baseline (see mergeWithTrustBoundary), and that hardening survives even
819
- * when inline set the same field.
820
- *
821
- * When no global or project files exist (the common case), the result is
822
- * byte-identical to calling `resolveConfig(inlineOptions)` directly. */
823
- export declare function loadResolvedConfig(inlineOptions: Record<string, unknown> | undefined, directory?: string, inlineTrust?: InlineOptionsTrust, { printConfigWarnings }?: LoadOptions): ReviewerConfig;
824
886
  //#endregion
825
- //#region src/system-one/backend.d.ts
887
+ //#region src/kernel/review-handoff.d.ts
826
888
  /** Jev's hand-off to the reasoning reviewer, on the second "reviewing" status
827
889
  * and on the result of a handed-off review. */
828
890
  interface HandoffInfo {
@@ -832,8 +894,11 @@ interface HandoffInfo {
832
894
  /** Jev's failure ("timeout"), only when `trigger` is `jev-failure`. */
833
895
  failureKind?: string;
834
896
  }
897
+ /** Called at most once per review, right before the reasoning reviewer is
898
+ * invoked; never on the budget-floor or inactive-attempt paths. */
899
+ type OnHandoff = (handoff: HandoffInfo) => void;
835
900
  //#endregion
836
- //#region src/ui-status-extras.d.ts
901
+ //#region src/modules/status/services/ui-status-extras.d.ts
837
902
  interface StatusExtrasOptions {
838
903
  handoff?: HandoffInfo;
839
904
  resolution?: ManualResolution;
@@ -842,10 +907,10 @@ interface StatusExtrasOptions {
842
907
  configDegraded?: readonly string[];
843
908
  }
844
909
  //#endregion
845
- //#region src/ui-protocol.d.ts
910
+ //#region src/modules/status/models/ui-protocol.d.ts
846
911
  type ReviewUiPhase = "reviewing" | "approved" | "denied" | "manual" | "unknown";
847
912
  /** One command of a shell action as the server split it, for the TUI to fit
848
- * to its width. Built by `src/ui-action-segments.ts`. */
913
+ * to its width. Built by `src/modules/status/services/ui-action-segments.ts`. */
849
914
  interface ActionSegment {
850
915
  /** The segment as typed in the command, heredoc bodies left out,
851
916
  * whitespace collapsed, at most 200 code points. */
@@ -912,7 +977,7 @@ export declare function createUiStatus(request: PermissionRequest, phase: Review
912
977
  export declare function encodeUiStatus(status: ReviewUiStatus): string;
913
978
  export declare function decodeUiStatus(command: string): ReviewUiStatus | undefined;
914
979
  //#endregion
915
- //#region src/context/ask-decisions.d.ts
980
+ //#region src/modules/context/services/ask-decisions.d.ts
916
981
  /**
917
982
  * Captures user answers to agent ask dialogs (the `question` tool) from the
918
983
  * OpenCode event stream and exposes them as compact, session-scoped
@@ -940,7 +1005,6 @@ export declare function decodeUiStatus(command: string): ReviewUiStatus | undefi
940
1005
  */
941
1006
  /** Marker recorded when the user dismisses an ask without answering. */
942
1007
  export declare const DISMISSED_ANSWER = "Dismissed by user";
943
- type Logger$1 = (message: string, details?: unknown) => void;
944
1008
  /** What the evidence assembler consumes: a bounded, lineage-scoped query. */
945
1009
  interface AskDecisionSource {
946
1010
  recentFor(sessionIDs: string[], limit?: number): AskDecision[];
@@ -950,7 +1014,7 @@ export declare class AskDecisionRegistry implements AskDecisionSource {
950
1014
  private readonly resolved;
951
1015
  private readonly log;
952
1016
  private readonly now;
953
- constructor(logger?: Logger$1, now?: () => number);
1017
+ constructor(logger?: Logger, now?: () => number);
954
1018
  /**
955
1019
  * Observe one raw event. Total: never throws; anything malformed or
956
1020
  * unrelated is dropped silently. Must be called synchronously from the event
@@ -973,32 +1037,23 @@ export declare class AskDecisionRegistry implements AskDecisionSource {
973
1037
  private store;
974
1038
  }
975
1039
  //#endregion
976
- //#region src/opencode/v2/server-state.d.ts
1040
+ //#region src/adapters/opencode/v2/server-state.d.ts
977
1041
  type Context = Parameters<Plugin$1.Plugin["setup"]>[0];
978
1042
  //#endregion
979
- //#region src/opencode/v2/server.d.ts
1043
+ //#region src/adapters/opencode/v2/server.d.ts
980
1044
  declare function setup(ctx: Context): Promise<() => Promise<void>>;
981
1045
  //#endregion
982
- //#region src/config.d.ts
983
- export declare function resolveConfig(options: Record<string, unknown> | undefined): ReviewerConfig;
984
- //#endregion
985
- //#region src/ssh-evidence.d.ts
986
- interface SshAuditSummary {
987
- destination: string;
988
- port?: string;
989
- remoteCommandSha256?: string;
990
- stdinSource?: string;
991
- stdinStatus?: string;
992
- stdinReason?: string;
993
- }
994
- interface SshEnrichmentResult {
995
- text: string;
996
- audit: SshAuditSummary[];
997
- preflightDenial?: string;
998
- }
999
- export declare function enrichSshEvidence(request: PermissionRequest, directory: string, worktree: string, maxChars: number): Promise<SshEnrichmentResult>;
1046
+ //#region src/adapters/opencode/event-normalizer.d.ts
1047
+ /**
1048
+ * Normalize a raw OpenCode event into a {@link PermissionRequest}.
1049
+ *
1050
+ * Returns `undefined` for anything that is not a well-formed
1051
+ * `permission.asked` event, so callers can ignore irrelevant events without
1052
+ * inspecting their shape.
1053
+ */
1054
+ export declare function extractPermissionRequest(event: unknown): PermissionRequest | undefined;
1000
1055
  //#endregion
1001
- //#region src/evidence/provider.d.ts
1056
+ //#region src/modules/evidence/providers/provider.d.ts
1002
1057
  /**
1003
1058
  * A single piece of evidence gathered about a permission request. The runtime
1004
1059
  * only consumes `text`, `audit`, and `preflightDenial` today; the remaining
@@ -1031,7 +1086,75 @@ interface EvidenceProvider {
1031
1086
  collect(input: EvidenceProviderInput): Promise<EvidenceFragment>;
1032
1087
  }
1033
1088
  //#endregion
1034
- //#region src/opencode/adapter.d.ts
1089
+ //#region src/modules/context/ports.d.ts
1090
+ /** Host-independent reads used to recover actor identity and intent. */
1091
+ interface ContextReader {
1092
+ messages(sessionID: string, directory: string, limit: number): Promise<unknown>;
1093
+ /** Literal user messages recovered independently of the operational window. */
1094
+ intentMessages?(sessionID: string, directory: string, limit: number): Promise<unknown>;
1095
+ session(sessionID: string, directory: string): Promise<unknown>;
1096
+ }
1097
+ //#endregion
1098
+ //#region src/modules/review/ports.d.ts
1099
+ /** A host call's outcome: failures arrive as `error`, not as a rejection. */
1100
+ interface HostResponse {
1101
+ error?: unknown;
1102
+ }
1103
+ /** The host members a review reads and calls. The coordinator keeps the
1104
+ * object it is given, so later changes to these members are seen. */
1105
+ interface ReviewHostContext {
1106
+ hostVersion?: string;
1107
+ directory: string;
1108
+ worktree: string;
1109
+ permissionReply(options: unknown): Promise<HostResponse>;
1110
+ publishUiStatus?(status: ReviewUiStatus): Promise<HostResponse>;
1111
+ writeAudit?(record: ReviewAuditRecord): Promise<void>;
1112
+ }
1113
+ interface ReviewerBackend {
1114
+ owns(sessionID: string): boolean;
1115
+ review(envelope: ReviewEnvelope, attempt: ReviewAttempt, onHandoff?: OnHandoff): Promise<ReviewExecutionResult>;
1116
+ waitForIdle(): Promise<void>;
1117
+ }
1118
+ /** What the review coordinator needs from the host. */
1119
+ interface ReviewHost {
1120
+ readonly context: ReviewHostContext;
1121
+ createReviewerBackend(config: ReviewerConfig, log: Logger, recordReviewerMs: (envelope: ReviewEnvelope, ms: number) => void): ReviewerBackend;
1122
+ createContextReader(signal?: AbortSignal): ContextReader;
1123
+ /** Whether a reply error means another source already resolved the request. */
1124
+ isAlreadyResolvedError(error: unknown): boolean;
1125
+ }
1126
+ //#endregion
1127
+ //#region src/modules/review/services/review-coordinator.d.ts
1128
+ /**
1129
+ * Owns the review lifecycle for permission requests: orchestration, the
1130
+ * supersede state machine, and the model call. The adapter (transport) and the
1131
+ * evidence providers are injected so this class stays focused on ordering and
1132
+ * races.
1133
+ */
1134
+ declare class ReviewCoordinator {
1135
+ private readonly state;
1136
+ private readonly limiter;
1137
+ private readonly pending;
1138
+ constructor(host: ReviewHost, config: ReviewerConfig, logger?: Logger, providers?: EvidenceProvider[], askDecisions?: AskDecisionSource);
1139
+ pendingCount(): number;
1140
+ waitForIdle(): Promise<void>;
1141
+ dispose(): Promise<void>;
1142
+ handle(request: PermissionRequest): void;
1143
+ process(request: PermissionRequest): Promise<ReviewExecutionResult>;
1144
+ handlePermissionReply(event: unknown): void;
1145
+ /**
1146
+ * @deprecated No-op. Approvals no longer annotate tool results so they do not
1147
+ * contaminate the primary agent context. Kept for public API compatibility;
1148
+ * the plugin no longer registers a host hook that calls this. Rationale
1149
+ * remains in audit, TUI, and debug.
1150
+ */
1151
+ annotateToolResult(callID: string, output: {
1152
+ output?: unknown;
1153
+ metadata?: unknown;
1154
+ }): void;
1155
+ }
1156
+ //#endregion
1157
+ //#region src/adapters/opencode/adapter.d.ts
1035
1158
  /** What the plugin learned about the host client at startup. */
1036
1159
  interface OpenCodeCapabilities {
1037
1160
  /** A public SDK method to answer a permission request exists. */
@@ -1054,7 +1177,7 @@ interface OpenCodeCapabilities {
1054
1177
  tuiPublish: boolean;
1055
1178
  }
1056
1179
  //#endregion
1057
- //#region src/opencode/types.d.ts
1180
+ //#region src/adapters/opencode/types.d.ts
1058
1181
  interface ClientResponse<T> {
1059
1182
  data?: T;
1060
1183
  error?: unknown;
@@ -1099,46 +1222,35 @@ interface RuntimeContext {
1099
1222
  reviewerDirectoryBase?: string;
1100
1223
  }
1101
1224
  //#endregion
1102
- //#region src/core/coordinator-state.d.ts
1103
- type Logger = (message: string, details?: unknown) => void;
1104
- //#endregion
1105
- //#region src/core/review-coordinator.d.ts
1106
- /**
1107
- * Owns the review lifecycle for permission requests: orchestration, the
1108
- * supersede state machine, and the model call. The adapter (transport) and the
1109
- * evidence providers are injected so this class stays focused on ordering and
1110
- * races.
1111
- */
1112
- declare class ReviewCoordinator {
1113
- private readonly state;
1114
- private readonly limiter;
1115
- private readonly pending;
1225
+ //#region src/adapters/opencode/v1/review-host.d.ts
1226
+ /** The review coordinator on a V1 host, built from the host's runtime context. */
1227
+ declare class V1ReviewCoordinator extends ReviewCoordinator {
1116
1228
  constructor(ctx: RuntimeContext, config: ReviewerConfig, logger?: Logger, providers?: EvidenceProvider[], askDecisions?: AskDecisionSource);
1117
- pendingCount(): number;
1118
- waitForIdle(): Promise<void>;
1119
- dispose(): Promise<void>;
1120
- handle(request: PermissionRequest): void;
1121
- process(request: PermissionRequest): Promise<ReviewExecutionResult>;
1122
- handlePermissionReply(event: unknown): void;
1123
- /**
1124
- * @deprecated No-op. Approvals no longer annotate tool results so they do not
1125
- * contaminate the primary agent context. Kept for public API compatibility;
1126
- * the plugin no longer registers a host hook that calls this. Rationale
1127
- * remains in audit, TUI, and debug.
1128
- */
1129
- annotateToolResult(callID: string, output: {
1130
- output?: unknown;
1131
- metadata?: unknown;
1132
- }): void;
1133
1229
  }
1134
1230
  //#endregion
1135
- //#region src/decision.d.ts
1231
+ //#region src/modules/analysis/brake/emergency-brake.d.ts
1232
+ export declare function emergencyBrakeReason(request: PermissionRequest): string | undefined;
1233
+ //#endregion
1234
+ //#region src/modules/config/services/config.d.ts
1235
+ export declare function resolveConfig(options: Record<string, unknown> | undefined): ReviewerConfig;
1236
+ //#endregion
1237
+ //#region src/modules/context/models/message.d.ts
1238
+ interface MessageWithParts {
1239
+ info: Record<string, unknown> & {
1240
+ id?: string;
1241
+ role?: string;
1242
+ structured?: unknown;
1243
+ };
1244
+ parts: Array<Record<string, unknown>>;
1245
+ }
1246
+ //#endregion
1247
+ //#region src/modules/decision/decision.d.ts
1136
1248
  export declare function parseDecision(value: unknown): ReviewDecision | undefined;
1137
1249
  //#endregion
1138
- //#region src/decision-gates.d.ts
1250
+ //#region src/modules/decision/decision-gates.d.ts
1139
1251
  export declare function enforceDecision(decision: ReviewDecision, config: ReviewerConfig): ReviewExecutionResult;
1140
1252
  //#endregion
1141
- //#region src/decision-schema.d.ts
1253
+ //#region src/modules/decision/decision-schema.d.ts
1142
1254
  export declare const DECISION_SCHEMA: {
1143
1255
  readonly type: "object";
1144
1256
  readonly additionalProperties: false;
@@ -1192,10 +1304,7 @@ export declare const DECISION_SCHEMA: {
1192
1304
  };
1193
1305
  };
1194
1306
  //#endregion
1195
- //#region src/emergency-brake.d.ts
1196
- export declare function emergencyBrakeReason(request: PermissionRequest): string | undefined;
1197
- //#endregion
1198
- //#region src/escalation.d.ts
1307
+ //#region src/modules/decision/escalation.d.ts
1199
1308
  /**
1200
1309
  * Categories that can be hardened independently of the global escalation mode
1201
1310
  * via `riskPolicy.onInvalidDecision` / `riskPolicy.onReviewerFailure`.
@@ -1228,13 +1337,13 @@ export declare function resolveEscalationDisposition(result: ReviewExecutionResu
1228
1337
  */
1229
1338
  export declare function applyEscalationDisposition(result: ReviewExecutionResult, config: ReviewerConfig, category?: EscalationCategory): ReviewExecutionResult;
1230
1339
  //#endregion
1231
- //#region src/git-evidence.d.ts
1340
+ //#region src/modules/evidence/git/git-evidence.d.ts
1232
1341
  interface GitEnrichmentResult {
1233
1342
  text: string;
1234
1343
  }
1235
1344
  export declare function enrichGitEvidence(request: PermissionRequest, directory: string, maxChars: number, worktree?: string): Promise<GitEnrichmentResult>;
1236
1345
  //#endregion
1237
- //#region src/local-script-evidence.d.ts
1346
+ //#region src/modules/evidence/local-script/local-script-evidence.d.ts
1238
1347
  interface LocalScriptEnrichmentResult {
1239
1348
  text: string;
1240
1349
  }
@@ -1242,20 +1351,7 @@ interface LocalScriptEnrichmentResult {
1242
1351
  * `directory` (package-script expansion passes the session directory). */
1243
1352
  export declare function enrichLocalScriptEvidence(request: PermissionRequest, directory: string, worktree: string, maxChars: number, rootDirectory?: string): Promise<LocalScriptEnrichmentResult>;
1244
1353
  //#endregion
1245
- //#region src/opencode/event-normalizer.d.ts
1246
- /**
1247
- * Normalize a raw OpenCode event into a {@link PermissionRequest}.
1248
- *
1249
- * Returns `undefined` for anything that is not a well-formed
1250
- * `permission.asked` event, so callers can ignore irrelevant events without
1251
- * inspecting their shape.
1252
- */
1253
- export declare function extractPermissionRequest(event: unknown): PermissionRequest | undefined;
1254
- //#endregion
1255
- //#region src/redact.d.ts
1256
- export declare function redactSecrets(input: string): string;
1257
- //#endregion
1258
- //#region src/ui-state.d.ts
1354
+ //#region src/modules/status/services/ui-state.d.ts
1259
1355
  interface UiStateOptions {
1260
1356
  model: string;
1261
1357
  variant: string;
@@ -1277,6 +1373,9 @@ export declare class ReviewUiState {
1277
1373
  dismissResults(now?: number): string[];
1278
1374
  }
1279
1375
  //#endregion
1376
+ //#region src/utils/redact.d.ts
1377
+ export declare function redactSecrets(input: string): string;
1378
+ //#endregion
1280
1379
  //#region src/index.d.ts
1281
1380
  export declare const server: Plugin;
1282
1381
  declare const module: {
@@ -1285,4 +1384,4 @@ declare const module: {
1285
1384
  setup: typeof setup;
1286
1385
  };
1287
1386
  //#endregion
1288
- export { type ActionPurpose, type ActorContext, type ActorProfile, ReviewCoordinator as ApprovalReviewerRuntime, type ApprovedAnnotation, type AskDecision, type CapabilityActionClass, type CapabilityAssessment, type DecisionSource, type EffectivePermissionSummary, type EscalatedFrom, type EscalationDisposition, type EscalationMode, type EscalationReviewerConfig, type EvidenceCompleteness, type EvidenceConfidence, type EvidenceSufficiency, type HandoffTrigger, type HeredocRecord, type IntentBlock, type IntentContext, type ManualResolution, type MessageWithParts, type ParsedCommand, type ParserCompleteness, type PermissionRequest, type PermissionToolSource, type PolicyCondition, type PolicyRule, type PolicyTrace, type Provenanced, type Redirection, type RepositoryTrust, type ReviewAuditRecord, type ReviewDecision, type ReviewEnvelope, type ReviewExecutionResult, type ReviewOutcome, type ReviewerConfig, type ReviewerOutputFormat, type RiskLevel, type RiskPolicy, type SYSTEM_ONE_BASES, type ScopeAlignment, type SessionLineage, type SessionNode, type SystemOneChoiceScore, type SystemOneEscalationMode, type SystemOnePrimaryBasis, type SystemOneScores, type SystemOneSignals, type UserAuthorization, module as default };
1387
+ export { type ActionPurpose, type ActorContext, type ActorProfile, V1ReviewCoordinator as ApprovalReviewerRuntime, type ApprovedAnnotation, type AskDecision, type CapabilityActionClass, type CapabilityAssessment, type DecisionSource, type EffectivePermissionSummary, type EscalatedFrom, type EscalationDisposition, type EscalationMode, type EscalationReviewerConfig, type EvidenceCompleteness, type EvidenceConfidence, type EvidenceSufficiency, type HandoffTrigger, type HeredocRecord, type IntentBlock, type IntentContext, type ManualResolution, type MessageWithParts, type ParsedCommand, type ParserCompleteness, type PermissionRequest, type PermissionToolSource, type PolicyCondition, type PolicyRule, type PolicyTrace, type Provenanced, type Redirection, type RepositoryTrust, type ReviewAuditRecord, type ReviewDecision, type ReviewEnvelope, type ReviewExecutionResult, type ReviewOutcome, type ReviewerConfig, type ReviewerOutputFormat, type RiskLevel, type RiskPolicy, type SYSTEM_ONE_BASES, type ScopeAlignment, type SessionLineage, type SessionNode, type SystemOneChoiceScore, type SystemOneEscalationMode, type SystemOnePrimaryBasis, type SystemOneScores, type SystemOneSignals, type UserAuthorization, module as default };