@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.
- package/CHANGELOG.md +64 -1
- package/LICENSE +21 -201
- package/LICENSE-APACHE +201 -0
- package/NOTICE +14 -6
- package/README.md +100 -750
- package/SECURITY.md +41 -22
- package/dist/explain.js +4932 -3522
- package/dist/index.d.ts +520 -513
- package/dist/index.js +12595 -9115
- package/dist/rpc.js +4 -1
- package/dist/tui/config/jsonc.ts +71 -63
- package/dist/tui/config/layer-read.ts +120 -0
- package/dist/tui/config/loader.ts +61 -513
- package/dist/tui/config/risk-policy-clamp.ts +80 -0
- package/dist/tui/config/trust-boundary-keys.ts +100 -0
- package/dist/tui/config/trust-boundary.ts +135 -0
- package/dist/tui/config/trusted-degradation.ts +97 -0
- package/dist/tui/config-fields.ts +55 -0
- package/dist/tui/config-knobs.ts +119 -0
- package/dist/tui/config-policy-rules.ts +86 -0
- package/dist/tui/config-risk-policy.ts +59 -0
- package/dist/tui/config-rule-condition.ts +150 -0
- package/dist/tui/config.ts +61 -430
- package/dist/tui/descriptor-io.ts +42 -0
- package/dist/tui/is-record.ts +13 -0
- package/dist/tui/opencode/event-normalizer.ts +41 -31
- package/dist/tui/reviewer-model.ts +87 -0
- package/dist/tui/tui.tsx +87 -99
- package/dist/tui/types.ts +171 -538
- package/dist/tui/ui/components.tsx +32 -136
- package/dist/tui/ui/review-connection.ts +32 -0
- package/dist/tui/ui/review-feed.ts +131 -0
- package/dist/tui/ui/review-overlay.tsx +83 -0
- package/dist/tui/ui/review-result.tsx +56 -0
- package/dist/tui/ui/review-store.ts +88 -0
- package/dist/tui/ui/review-theme.ts +63 -0
- package/dist/tui/ui/rpc.ts +5 -2
- package/dist/tui/ui/v1-host.ts +39 -0
- package/dist/tui/ui/v2.tsx +66 -220
- package/dist/tui/ui-protocol.ts +63 -118
- package/dist/tui/ui-state.ts +71 -64
- package/dist/tui/ui-status-parse.ts +74 -0
- package/package.json +18 -17
- package/rpc.js +2 -1
- package/server.js +2 -2
- package/tui.tsx +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { Plugin as Plugin$1 } from '@opencode-ai/plugin';
|
|
2
2
|
import { Plugin } from '@opencode/plugin';
|
|
3
3
|
|
|
4
|
+
interface VerifiedScriptEvidence {
|
|
5
|
+
sha256: string;
|
|
6
|
+
destination: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
shell: "bash" | "sh";
|
|
9
|
+
bytes?: number;
|
|
10
|
+
status: "full" | "reused" | "unavailable";
|
|
11
|
+
text: string;
|
|
12
|
+
cacheKey?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
interface ShellToken {
|
|
5
16
|
/** Original text including any surrounding quotes. */
|
|
6
17
|
raw: string;
|
|
@@ -32,15 +43,160 @@ interface ShellSegment {
|
|
|
32
43
|
precededBy?: string;
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
/** How completely the command could be statically analyzed. */
|
|
47
|
+
type ParserCompleteness =
|
|
48
|
+
/** Fully parsed: no variables, globs, substitutions, or heredoc bodies. */
|
|
49
|
+
"complete-for-supported-form"
|
|
50
|
+
/** Some constructs could not be resolved (variables, partial heredoc). */
|
|
51
|
+
| "partial"
|
|
52
|
+
/** Heavy dynamic constructs (command substitution, eval, dynamic heredoc). */
|
|
53
|
+
| "opaque";
|
|
54
|
+
/** A redirection extracted from a parsed command segment. */
|
|
55
|
+
interface Redirection {
|
|
56
|
+
/** `>` `>>` `<` `2>` `&>` etc. */
|
|
57
|
+
operator: string;
|
|
58
|
+
/** Target path (file descriptor targets normalized to a path when possible). */
|
|
59
|
+
target: string;
|
|
60
|
+
/** Whether the target was quoted in the source (affects literal-ness). */
|
|
61
|
+
quoted: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** A heredoc extracted before lexing so its body never reaches the lexer/brake. */
|
|
64
|
+
interface HeredocRecord {
|
|
65
|
+
/** The literal delimiter token as it appeared (`EOF`, `END`, …). */
|
|
66
|
+
delimiter: string;
|
|
67
|
+
/** `<<` (expansion on) or `<<-` (tabs stripped) — normalized form. */
|
|
68
|
+
operator: string;
|
|
69
|
+
/** Whether the delimiter was quoted, disabling expansion (`<<'EOF'`). */
|
|
70
|
+
expansionDisabled: boolean;
|
|
71
|
+
/** Bounded + redacted body (truncated to a safe length). */
|
|
72
|
+
bodyBounded: string;
|
|
73
|
+
/** SHA-256 of the full, unredacted body (stable identity without leaking it). */
|
|
74
|
+
bodySha256: string;
|
|
75
|
+
/** Whether the body was truncated for storage. */
|
|
76
|
+
truncated: boolean;
|
|
77
|
+
/** Output path associated with the heredoc when a `> path` precedes it. */
|
|
78
|
+
outputTarget?: string;
|
|
79
|
+
/** Whether the body is dynamically constructed (unresolvable expansion). */
|
|
80
|
+
dynamic: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** A command parsed into a reusable structure. Wraps the existing lexer output
|
|
83
|
+
* plus pre-extracted redirections and heredocs. */
|
|
84
|
+
interface ParsedCommand {
|
|
85
|
+
/** The command after heredoc bodies were replaced with placeholders. */
|
|
86
|
+
sanitizedCommand: string;
|
|
87
|
+
/** Lexed segments of the sanitized command. */
|
|
88
|
+
segments: ShellSegment[];
|
|
89
|
+
/** Effective commands (wrappers peeled) per segment. */
|
|
90
|
+
effective: ShellToken[][];
|
|
91
|
+
/** Redirections grouped by segment index. */
|
|
92
|
+
redirections: Redirection[][];
|
|
93
|
+
/** Heredocs extracted before lexing. */
|
|
94
|
+
heredocs: HeredocRecord[];
|
|
95
|
+
/** Whether the original command contained any dynamic constructs. */
|
|
96
|
+
hasDynamicConstructs: boolean;
|
|
97
|
+
/** True when the lexer's depth or expansion budget stopped command-string
|
|
98
|
+
* resolution early; `effective` is then a prefix of the real structure and
|
|
99
|
+
* deterministic facts do not cover the whole command. */
|
|
100
|
+
analysisTruncated: boolean;
|
|
101
|
+
}
|
|
102
|
+
/** What the action can do, what it appears to do, and analysis confidence. */
|
|
103
|
+
interface CapabilityAssessment {
|
|
104
|
+
/** Best single-label summary of the dominant capability. */
|
|
105
|
+
actionClass: Provenanced<CapabilityActionClass>;
|
|
106
|
+
/** Human-readable summary of the detected surface. */
|
|
107
|
+
summary: string;
|
|
108
|
+
/** Executes an interpreter or runtime (sh, python, node, bun, …). */
|
|
109
|
+
executesCode: Provenanced<boolean | "unknown">;
|
|
110
|
+
/** Executes code that lives in the repository (scripts, test files). */
|
|
111
|
+
executesRepositoryCode: Provenanced<boolean | "unknown">;
|
|
112
|
+
/** Executes ad-hoc code generated by the agent (heredoc/inline). */
|
|
113
|
+
createsAdHocCode: Provenanced<boolean | "unknown">;
|
|
114
|
+
/** Invokes a known test runner (pytest, jest, bun test, …). */
|
|
115
|
+
invokesExistingTestRunner: Provenanced<boolean | "unknown">;
|
|
116
|
+
/** Runs a package manager that may execute lifecycle scripts. */
|
|
117
|
+
invokesPackageLifecycleScripts: Provenanced<boolean | "unknown">;
|
|
118
|
+
/** Reads literal credential material through a known file reader. */
|
|
119
|
+
credentialRead: Provenanced<boolean | "unknown">;
|
|
120
|
+
/** Detected file-write surface. */
|
|
121
|
+
writeEffects: {
|
|
122
|
+
temporaryWrite: Provenanced<boolean | "unknown">;
|
|
123
|
+
workspaceWrite: Provenanced<boolean | "unknown">;
|
|
124
|
+
externalWrite: Provenanced<boolean | "unknown">;
|
|
125
|
+
deletion: Provenanced<boolean | "unknown">;
|
|
126
|
+
};
|
|
127
|
+
/** Detected network surface. */
|
|
128
|
+
network: {
|
|
129
|
+
observed: Provenanced<boolean | "unknown">;
|
|
130
|
+
possible: Provenanced<boolean | "unknown">;
|
|
131
|
+
/** Hosts/destinations observed literally in the command. */
|
|
132
|
+
destinations: string[];
|
|
133
|
+
observedAccess: Provenanced<boolean | "unknown">;
|
|
134
|
+
possibleAccess: Provenanced<boolean | "unknown">;
|
|
135
|
+
};
|
|
136
|
+
/** Detected process side-effects. */
|
|
137
|
+
process: {
|
|
138
|
+
childProcesses: Provenanced<boolean | "unknown">;
|
|
139
|
+
persistence: Provenanced<boolean | "unknown">;
|
|
140
|
+
privilegeEscalation: Provenanced<boolean | "unknown">;
|
|
141
|
+
};
|
|
142
|
+
/** Detected remote-operation surface (ssh, etc.). */
|
|
143
|
+
remote: {
|
|
144
|
+
enabled: Provenanced<boolean | "unknown">;
|
|
145
|
+
mutationHint: Provenanced<boolean | "unknown">;
|
|
146
|
+
};
|
|
147
|
+
/** Detected git mutation surface. */
|
|
148
|
+
git: {
|
|
149
|
+
observed: Provenanced<boolean | "unknown">;
|
|
150
|
+
possible: Provenanced<boolean | "unknown">;
|
|
151
|
+
observedAccess: Provenanced<boolean | "unknown">;
|
|
152
|
+
possibleAccess: Provenanced<boolean | "unknown">;
|
|
153
|
+
};
|
|
154
|
+
/** How completely the command could be analyzed. */
|
|
155
|
+
parserCompleteness: ParserCompleteness;
|
|
156
|
+
/** Free-form warnings about analysis limitations. */
|
|
157
|
+
analysisWarnings: string[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
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"];
|
|
161
|
+
type SystemOnePrimaryBasis = (typeof SYSTEM_ONE_BASES)[number];
|
|
162
|
+
interface SystemOneChoiceScore<T extends string> {
|
|
163
|
+
choice: T;
|
|
164
|
+
confidence: number;
|
|
165
|
+
}
|
|
166
|
+
/** Probability (0-1) that each safety question is true. */
|
|
167
|
+
interface SystemOneSignals {
|
|
168
|
+
materialAuthorization: number;
|
|
169
|
+
withinIntentScope: number;
|
|
170
|
+
unauthorizedDataLoss: number;
|
|
171
|
+
untrustedSensitiveDisclosure: number;
|
|
172
|
+
excessiveCredentialAccess: number;
|
|
173
|
+
unauthorizedSecurityChange: number;
|
|
174
|
+
unauthorizedExternalMutation: number;
|
|
175
|
+
essentialEvidenceMissing: number;
|
|
176
|
+
absolutePolicyDeny: number;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Jev's own answer, kept apart from the final decision because a reasoning
|
|
180
|
+
* reviewer may replace it. Numbers, enum choices, fixed contradiction strings,
|
|
181
|
+
* and the provider-reported model ID only; never evidence text.
|
|
182
|
+
*/
|
|
183
|
+
interface SystemOneScores {
|
|
184
|
+
/** Versioned model ID the provider reported as having answered. */
|
|
185
|
+
returnedModel: string;
|
|
186
|
+
outcome: SystemOneChoiceScore<ReviewOutcome> & {
|
|
187
|
+
probabilities: Record<ReviewOutcome, number>;
|
|
188
|
+
};
|
|
189
|
+
supporting: {
|
|
190
|
+
riskLevel: SystemOneChoiceScore<RiskLevel>;
|
|
191
|
+
userAuthorization: SystemOneChoiceScore<UserAuthorization>;
|
|
192
|
+
scopeAlignment: SystemOneChoiceScore<ScopeAlignment>;
|
|
193
|
+
evidenceCompleteness: SystemOneChoiceScore<EvidenceSufficiency>;
|
|
194
|
+
primaryBasis: SystemOneChoiceScore<SystemOnePrimaryBasis>;
|
|
195
|
+
};
|
|
196
|
+
signals: SystemOneSignals;
|
|
197
|
+
/** Consistency checks that failed; any one marks an allow or deny difficult. */
|
|
198
|
+
contradictions: string[];
|
|
199
|
+
reasoningRecommended: boolean;
|
|
44
200
|
}
|
|
45
201
|
|
|
46
202
|
type RiskLevel = "low" | "medium" | "high" | "critical";
|
|
@@ -273,186 +429,44 @@ interface ReviewEnvelope {
|
|
|
273
429
|
* prompt (USER_ASK_DECISIONS) and audit, never into enforcement. */
|
|
274
430
|
askDecisions?: AskDecision[];
|
|
275
431
|
}
|
|
276
|
-
|
|
277
|
-
* audit record so reports can split outcomes by source. */
|
|
278
|
-
type DecisionSource = "emergency-brake" | "deterministic-policy" | "llm-reviewer" | "system-one-reviewer" | "manual-superseded" | "failure-safe";
|
|
279
|
-
interface ReviewAuditRecord {
|
|
280
|
-
/**
|
|
281
|
-
* Audit schema version. Present on every record; readers default a missing
|
|
282
|
-
* field to `1` (additive — old records are still valid).
|
|
283
|
-
* Bump only on a breaking change to the record shape.
|
|
284
|
-
*/
|
|
285
|
-
schemaVersion?: number;
|
|
286
|
-
reviewID?: string;
|
|
287
|
-
hostRequestID?: string;
|
|
288
|
-
hostGeneration?: "v1" | "v2";
|
|
289
|
-
hostVersion?: string;
|
|
290
|
-
generation?: string;
|
|
291
|
-
nativeAction?: string;
|
|
292
|
-
directory?: string;
|
|
293
|
-
application?: "evaluation-returned" | "reply-accepted" | "human-pending" | "superseded" | "cancelled" | "unknown";
|
|
294
|
-
pluginVersion?: string;
|
|
295
|
-
effectiveConfigHash?: string;
|
|
296
|
-
actionFingerprint?: string;
|
|
297
|
-
/** Version of the structured-decision schema the reviewer was asked to emit. */
|
|
298
|
-
decisionSchemaVersion?: number;
|
|
299
|
-
/** Version of the reviewer system prompt used for this decision. */
|
|
300
|
-
promptVersion?: string;
|
|
301
|
-
/** Which layer produced the outcome (brake, policy, reviewer, supersede,
|
|
302
|
-
* failure-safe). Absent on legacy v1 records. */
|
|
303
|
-
decisionSource?: DecisionSource;
|
|
304
|
-
timestamp: string;
|
|
305
|
-
durationMs: number;
|
|
432
|
+
interface ApprovedAnnotation {
|
|
306
433
|
requestID: string;
|
|
307
434
|
sessionID: string;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
435
|
+
decision: ReviewDecision;
|
|
436
|
+
}
|
|
437
|
+
interface ReviewExecutionResult {
|
|
438
|
+
kind: "allow" | "deny" | "escalate";
|
|
439
|
+
decision?: ReviewDecision;
|
|
313
440
|
reason: string;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
441
|
+
reviewSessionID?: string;
|
|
442
|
+
/** Which layer produced this result; threaded into the audit record. */
|
|
443
|
+
decisionSource?: DecisionSource;
|
|
444
|
+
/** Actual model that produced the final reviewer decision. */
|
|
445
|
+
reviewerModel?: string;
|
|
446
|
+
/** Primary model and routing reason when a second reviewer was used. */
|
|
447
|
+
reviewerEscalatedFrom?: {
|
|
448
|
+
model: string;
|
|
449
|
+
reason: string;
|
|
450
|
+
};
|
|
451
|
+
/** Jev's scores whenever it returned a parsed decision. */
|
|
452
|
+
systemOne?: SystemOneScores;
|
|
320
453
|
/**
|
|
321
|
-
* Structured outcome
|
|
322
|
-
* Absent when no valid structured decision was produced
|
|
323
|
-
* failure-safe, supersede).
|
|
454
|
+
* Structured outcome from the reviewer LLM before gates/disposition.
|
|
455
|
+
* Absent when no valid structured decision was produced.
|
|
324
456
|
*/
|
|
325
457
|
reviewerOutcome?: ReviewOutcome;
|
|
326
458
|
/**
|
|
327
|
-
* How an internal escalate was disposed
|
|
328
|
-
* was escalate (
|
|
329
|
-
*
|
|
330
|
-
*/
|
|
331
|
-
escalationDisposition?: EscalationDisposition;
|
|
332
|
-
/** The model that produced the final reviewer decision. */
|
|
333
|
-
reviewerModel?: string;
|
|
334
|
-
/** Present when a System One result was handed to a reasoning reviewer. */
|
|
335
|
-
reviewerEscalatedFrom?: {
|
|
336
|
-
model: string;
|
|
337
|
-
reason: string;
|
|
338
|
-
};
|
|
339
|
-
/** Per-phase timings. Absent on legacy v1 records and on deterministic paths
|
|
340
|
-
* that never reach that phase. */
|
|
341
|
-
timings?: {
|
|
342
|
-
contextMs?: number;
|
|
343
|
-
enrichmentMs?: number;
|
|
344
|
-
reviewerMs?: number;
|
|
345
|
-
replyMs?: number;
|
|
346
|
-
};
|
|
347
|
-
/** Non-fatal warnings accumulated during evidence collection/analysis. */
|
|
348
|
-
warnings?: string[];
|
|
349
|
-
reviewerSessionID?: string;
|
|
350
|
-
/** Content identity and inspection mode only; never script text or local path. */
|
|
351
|
-
verifiedScript?: {
|
|
352
|
-
sha256: string;
|
|
353
|
-
status: "full" | "reused" | "unavailable";
|
|
354
|
-
bytes?: number;
|
|
355
|
-
};
|
|
356
|
-
/** Root session of the request's ancestry (additive; absent when lineage was
|
|
357
|
-
* unavailable). */
|
|
358
|
-
rootSessionID?: string;
|
|
359
|
-
/** Overall evidence completeness for the request (additive). */
|
|
360
|
-
evidenceCompleteness?: string;
|
|
361
|
-
/** Resolved actor snapshot for audit (additive). Uses identityCompleteness
|
|
362
|
-
* (not the decision's numeric confidence) to avoid field ambiguity; v2 also
|
|
363
|
-
* carries identitySource + confidence. */
|
|
364
|
-
actor?: {
|
|
365
|
-
name?: string;
|
|
366
|
-
mode?: string;
|
|
367
|
-
profile: ActorProfile;
|
|
368
|
-
identityCompleteness: "complete" | "partial" | "unknown";
|
|
369
|
-
/** How the agent identity was established (tool-message, session-api,
|
|
370
|
-
* unavailable, …). Absent on legacy v1 records. */
|
|
371
|
-
identitySource?: string;
|
|
372
|
-
/** Reliability of the identity claim. Absent on legacy v1 records. */
|
|
373
|
-
confidence?: EvidenceConfidence;
|
|
374
|
-
delegationDepth?: number;
|
|
375
|
-
};
|
|
376
|
-
ssh?: Array<{
|
|
377
|
-
destination: string;
|
|
378
|
-
port?: string;
|
|
379
|
-
remoteCommandSha256?: string;
|
|
380
|
-
stdinSource?: string;
|
|
381
|
-
stdinStatus?: string;
|
|
382
|
-
stdinReason?: string;
|
|
383
|
-
}>;
|
|
384
|
-
/** Additive capability snapshot for audit (observe-only). */
|
|
385
|
-
capability?: {
|
|
386
|
-
actionClass: string;
|
|
387
|
-
summary: string;
|
|
388
|
-
parserCompleteness: string;
|
|
389
|
-
executesCode?: boolean;
|
|
390
|
-
createsAdHocCode?: boolean;
|
|
391
|
-
invokesPackageLifecycleScripts?: boolean;
|
|
392
|
-
writeEffects?: {
|
|
393
|
-
temporaryWrite?: boolean;
|
|
394
|
-
workspaceWrite?: boolean;
|
|
395
|
-
externalWrite?: boolean;
|
|
396
|
-
deletion?: boolean;
|
|
397
|
-
};
|
|
398
|
-
networkObserved?: boolean;
|
|
399
|
-
credentialRead?: boolean;
|
|
400
|
-
privilegeEscalation?: boolean;
|
|
401
|
-
persistence?: boolean;
|
|
402
|
-
remoteEnabled?: boolean;
|
|
403
|
-
gitMutation?: boolean;
|
|
404
|
-
};
|
|
405
|
-
/** Additive policy trace for audit (observe-only). */
|
|
406
|
-
policyTrace?: {
|
|
407
|
-
effectivePolicyHash: string;
|
|
408
|
-
matchedRules: Array<{
|
|
409
|
-
id: string;
|
|
410
|
-
source: string;
|
|
411
|
-
effect: string;
|
|
412
|
-
reason: string;
|
|
413
|
-
}>;
|
|
414
|
-
finalRoute: string;
|
|
415
|
-
mode: string;
|
|
416
|
-
};
|
|
417
|
-
/** Additive snapshot of the ask decisions surfaced to the reviewer prompt
|
|
418
|
-
* (observe-only; capped to the most recent few). */
|
|
419
|
-
askDecisions?: Array<{
|
|
420
|
-
at: number;
|
|
421
|
-
question: string;
|
|
422
|
-
answer: string;
|
|
423
|
-
}>;
|
|
424
|
-
}
|
|
425
|
-
interface ApprovedAnnotation {
|
|
426
|
-
requestID: string;
|
|
427
|
-
sessionID: string;
|
|
428
|
-
decision: ReviewDecision;
|
|
429
|
-
}
|
|
430
|
-
interface ReviewExecutionResult {
|
|
431
|
-
kind: "allow" | "deny" | "escalate";
|
|
432
|
-
decision?: ReviewDecision;
|
|
433
|
-
reason: string;
|
|
434
|
-
reviewSessionID?: string;
|
|
435
|
-
/** Which layer produced this result; threaded into the audit record. */
|
|
436
|
-
decisionSource?: DecisionSource;
|
|
437
|
-
/** Actual model that produced the final reviewer decision. */
|
|
438
|
-
reviewerModel?: string;
|
|
439
|
-
/** Primary model and routing reason when a second reviewer was used. */
|
|
440
|
-
reviewerEscalatedFrom?: {
|
|
441
|
-
model: string;
|
|
442
|
-
reason: string;
|
|
443
|
-
};
|
|
444
|
-
/**
|
|
445
|
-
* Structured outcome from the reviewer LLM before gates/disposition.
|
|
446
|
-
* Absent when no valid structured decision was produced.
|
|
447
|
-
*/
|
|
448
|
-
reviewerOutcome?: ReviewOutcome;
|
|
449
|
-
/**
|
|
450
|
-
* How an internal escalate was disposed at the enforcement boundary.
|
|
451
|
-
* Absent when the result was never an escalate (explicit allow/deny) or when
|
|
452
|
-
* the request was already answered manually (`manual-superseded`).
|
|
459
|
+
* How an internal escalate was disposed at the enforcement boundary.
|
|
460
|
+
* Absent when the result was never an escalate (explicit allow/deny) or when
|
|
461
|
+
* the request was already answered manually (`manual-superseded`).
|
|
453
462
|
*/
|
|
454
463
|
escalationDisposition?: EscalationDisposition;
|
|
455
464
|
}
|
|
465
|
+
/** Generic policy templates, NOT automatic trust levels. */
|
|
466
|
+
type ActorProfile = "read-only" | "validation" | "workspace" | "operator" | "reviewer" | "unknown";
|
|
467
|
+
/** High-level classification of what the action does. */
|
|
468
|
+
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";
|
|
469
|
+
|
|
456
470
|
/** Reliability of a derived fact. */
|
|
457
471
|
type EvidenceConfidence = "confirmed" | "high" | "medium" | "low" | "unknown";
|
|
458
472
|
/** Every non-trivial derived fact carries provenance so the LLM and audit can
|
|
@@ -463,8 +477,6 @@ interface Provenanced<T> {
|
|
|
463
477
|
confidence: EvidenceConfidence;
|
|
464
478
|
notes?: string[];
|
|
465
479
|
}
|
|
466
|
-
/** Generic policy templates, NOT automatic trust levels. */
|
|
467
|
-
type ActorProfile = "read-only" | "validation" | "workspace" | "operator" | "reviewer" | "unknown";
|
|
468
480
|
/** Normalized effective-permission summary when the SDK exposes it.
|
|
469
481
|
* The v1 SDK does not expose effective rules, so this stays `undefined`. */
|
|
470
482
|
interface EffectivePermissionSummary {
|
|
@@ -561,122 +573,164 @@ interface ActionPurpose {
|
|
|
561
573
|
source: "agent-context" | "intent-derived" | "unavailable";
|
|
562
574
|
confidence: EvidenceConfidence;
|
|
563
575
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
"
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
summary: string;
|
|
628
|
-
/** Executes an interpreter or runtime (sh, python, node, bun, …). */
|
|
629
|
-
executesCode: Provenanced<boolean | "unknown">;
|
|
630
|
-
/** Executes code that lives in the repository (scripts, test files). */
|
|
631
|
-
executesRepositoryCode: Provenanced<boolean | "unknown">;
|
|
632
|
-
/** Executes ad-hoc code generated by the agent (heredoc/inline). */
|
|
633
|
-
createsAdHocCode: Provenanced<boolean | "unknown">;
|
|
634
|
-
/** Invokes a known test runner (pytest, jest, bun test, …). */
|
|
635
|
-
invokesExistingTestRunner: Provenanced<boolean | "unknown">;
|
|
636
|
-
/** Runs a package manager that may execute lifecycle scripts. */
|
|
637
|
-
invokesPackageLifecycleScripts: Provenanced<boolean | "unknown">;
|
|
638
|
-
/** Reads literal credential material through a known file reader. */
|
|
639
|
-
credentialRead: Provenanced<boolean | "unknown">;
|
|
640
|
-
/** Detected file-write surface. */
|
|
641
|
-
writeEffects: {
|
|
642
|
-
temporaryWrite: Provenanced<boolean | "unknown">;
|
|
643
|
-
workspaceWrite: Provenanced<boolean | "unknown">;
|
|
644
|
-
externalWrite: Provenanced<boolean | "unknown">;
|
|
645
|
-
deletion: Provenanced<boolean | "unknown">;
|
|
576
|
+
|
|
577
|
+
/** Which layer produced the final decision for a request. Threaded into the
|
|
578
|
+
* audit record so reports can split outcomes by source. */
|
|
579
|
+
type DecisionSource = "emergency-brake" | "deterministic-policy" | "llm-reviewer" | "system-one-reviewer" | "manual-superseded" | "failure-safe";
|
|
580
|
+
interface ReviewAuditRecord {
|
|
581
|
+
/**
|
|
582
|
+
* Audit schema version. Present on every record; readers default a missing
|
|
583
|
+
* field to `1` (additive — old records are still valid).
|
|
584
|
+
* Bump only on a breaking change to the record shape.
|
|
585
|
+
*/
|
|
586
|
+
schemaVersion?: number;
|
|
587
|
+
reviewID?: string;
|
|
588
|
+
hostRequestID?: string;
|
|
589
|
+
hostGeneration?: "v1" | "v2";
|
|
590
|
+
hostVersion?: string;
|
|
591
|
+
generation?: string;
|
|
592
|
+
nativeAction?: string;
|
|
593
|
+
directory?: string;
|
|
594
|
+
application?: "evaluation-returned" | "reply-accepted" | "human-pending" | "superseded" | "cancelled" | "unknown";
|
|
595
|
+
pluginVersion?: string;
|
|
596
|
+
effectiveConfigHash?: string;
|
|
597
|
+
actionFingerprint?: string;
|
|
598
|
+
/** Version of the structured-decision schema the reviewer was asked to emit. */
|
|
599
|
+
decisionSchemaVersion?: number;
|
|
600
|
+
/** Version of the reviewer system prompt used for this decision. */
|
|
601
|
+
promptVersion?: string;
|
|
602
|
+
/** Which layer produced the outcome (brake, policy, reviewer, supersede,
|
|
603
|
+
* failure-safe). Absent on legacy v1 records. */
|
|
604
|
+
decisionSource?: DecisionSource;
|
|
605
|
+
timestamp: string;
|
|
606
|
+
durationMs: number;
|
|
607
|
+
requestID: string;
|
|
608
|
+
sessionID: string;
|
|
609
|
+
permission: string;
|
|
610
|
+
/** Stable hash of the canonical request (permission, patterns, metadata,
|
|
611
|
+
* tool) for cross-record correlation. Absent on legacy v1 records. */
|
|
612
|
+
actionHash?: string;
|
|
613
|
+
outcome: ReviewExecutionResult["kind"];
|
|
614
|
+
reason: string;
|
|
615
|
+
riskLevel?: RiskLevel;
|
|
616
|
+
userAuthorization?: UserAuthorization;
|
|
617
|
+
/** How well the action aligned with the recovered intent (from the reviewer
|
|
618
|
+
* decision). Absent when no reviewer decision was reached. */
|
|
619
|
+
scopeAlignment?: ScopeAlignment;
|
|
620
|
+
confidence?: number;
|
|
621
|
+
/**
|
|
622
|
+
* Structured outcome emitted by the reviewer LLM before gates/disposition.
|
|
623
|
+
* Absent when no valid structured decision was produced (brake, policy,
|
|
624
|
+
* failure-safe, supersede).
|
|
625
|
+
*/
|
|
626
|
+
reviewerOutcome?: ReviewOutcome;
|
|
627
|
+
/**
|
|
628
|
+
* How an internal escalate was disposed. Present only when the logical result
|
|
629
|
+
* was escalate (or a gate converted allow→escalate) and enforcement chose
|
|
630
|
+
* manual or deny. Absent for explicit deny, allow, and manual-superseded.
|
|
631
|
+
*/
|
|
632
|
+
escalationDisposition?: EscalationDisposition;
|
|
633
|
+
/** The model that produced the final reviewer decision. */
|
|
634
|
+
reviewerModel?: string;
|
|
635
|
+
/** Present when a System One result was handed to a reasoning reviewer. */
|
|
636
|
+
reviewerEscalatedFrom?: {
|
|
637
|
+
model: string;
|
|
638
|
+
reason: string;
|
|
646
639
|
};
|
|
647
|
-
/**
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
640
|
+
/** Jev's scores whenever it returned a parsed decision, including when a
|
|
641
|
+
* reasoning reviewer made the final call. */
|
|
642
|
+
systemOne?: SystemOneScores;
|
|
643
|
+
/** Per-phase timings. Absent on legacy v1 records and on deterministic paths
|
|
644
|
+
* that never reach that phase. */
|
|
645
|
+
timings?: {
|
|
646
|
+
contextMs?: number;
|
|
647
|
+
enrichmentMs?: number;
|
|
648
|
+
reviewerMs?: number;
|
|
649
|
+
replyMs?: number;
|
|
655
650
|
};
|
|
656
|
-
/**
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
651
|
+
/** Non-fatal warnings accumulated during evidence collection/analysis. */
|
|
652
|
+
warnings?: string[];
|
|
653
|
+
reviewerSessionID?: string;
|
|
654
|
+
/** Content identity and inspection mode only; never script text or local path. */
|
|
655
|
+
verifiedScript?: {
|
|
656
|
+
sha256: string;
|
|
657
|
+
status: "full" | "reused" | "unavailable";
|
|
658
|
+
bytes?: number;
|
|
661
659
|
};
|
|
662
|
-
/**
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
660
|
+
/** Root session of the request's ancestry (additive; absent when lineage was
|
|
661
|
+
* unavailable). */
|
|
662
|
+
rootSessionID?: string;
|
|
663
|
+
/** Overall evidence completeness for the request (additive). */
|
|
664
|
+
evidenceCompleteness?: string;
|
|
665
|
+
/** Resolved actor snapshot for audit (additive). Uses identityCompleteness
|
|
666
|
+
* (not the decision's numeric confidence) to avoid field ambiguity; v2 also
|
|
667
|
+
* carries identitySource + confidence. */
|
|
668
|
+
actor?: {
|
|
669
|
+
name?: string;
|
|
670
|
+
mode?: string;
|
|
671
|
+
profile: ActorProfile;
|
|
672
|
+
identityCompleteness: "complete" | "partial" | "unknown";
|
|
673
|
+
/** How the agent identity was established (tool-message, session-api,
|
|
674
|
+
* unavailable, …). Absent on legacy v1 records. */
|
|
675
|
+
identitySource?: string;
|
|
676
|
+
/** Reliability of the identity claim. Absent on legacy v1 records. */
|
|
677
|
+
confidence?: EvidenceConfidence;
|
|
678
|
+
delegationDepth?: number;
|
|
666
679
|
};
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
680
|
+
ssh?: Array<{
|
|
681
|
+
destination: string;
|
|
682
|
+
port?: string;
|
|
683
|
+
remoteCommandSha256?: string;
|
|
684
|
+
stdinSource?: string;
|
|
685
|
+
stdinStatus?: string;
|
|
686
|
+
stdinReason?: string;
|
|
687
|
+
}>;
|
|
688
|
+
/** Additive capability snapshot for audit (observe-only). */
|
|
689
|
+
capability?: {
|
|
690
|
+
actionClass: string;
|
|
691
|
+
summary: string;
|
|
692
|
+
parserCompleteness: string;
|
|
693
|
+
executesCode?: boolean;
|
|
694
|
+
createsAdHocCode?: boolean;
|
|
695
|
+
invokesPackageLifecycleScripts?: boolean;
|
|
696
|
+
writeEffects?: {
|
|
697
|
+
temporaryWrite?: boolean;
|
|
698
|
+
workspaceWrite?: boolean;
|
|
699
|
+
externalWrite?: boolean;
|
|
700
|
+
deletion?: boolean;
|
|
701
|
+
};
|
|
702
|
+
networkObserved?: boolean;
|
|
703
|
+
credentialRead?: boolean;
|
|
704
|
+
privilegeEscalation?: boolean;
|
|
705
|
+
persistence?: boolean;
|
|
706
|
+
remoteEnabled?: boolean;
|
|
707
|
+
gitMutation?: boolean;
|
|
673
708
|
};
|
|
674
|
-
/**
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
709
|
+
/** Additive policy trace for audit (observe-only). */
|
|
710
|
+
policyTrace?: {
|
|
711
|
+
effectivePolicyHash: string;
|
|
712
|
+
matchedRules: Array<{
|
|
713
|
+
id: string;
|
|
714
|
+
source: string;
|
|
715
|
+
effect: string;
|
|
716
|
+
reason: string;
|
|
717
|
+
}>;
|
|
718
|
+
finalRoute: string;
|
|
719
|
+
mode: string;
|
|
720
|
+
};
|
|
721
|
+
/** Additive snapshot of the ask decisions surfaced to the reviewer prompt
|
|
722
|
+
* (observe-only; capped to the most recent few). */
|
|
723
|
+
askDecisions?: Array<{
|
|
724
|
+
at: number;
|
|
725
|
+
question: string;
|
|
726
|
+
answer: string;
|
|
727
|
+
}>;
|
|
678
728
|
}
|
|
679
729
|
|
|
730
|
+
declare const DEFAULT_AUDIT_PATH = "~/.local/share/opencode/permission-reviewer-audit.jsonl";
|
|
731
|
+
type AuditLogger = (message: string, details?: unknown) => void;
|
|
732
|
+
declare function createAuditWriter(config: ReviewerConfig, logger?: AuditLogger): ((record: ReviewAuditRecord) => Promise<void>) | undefined;
|
|
733
|
+
|
|
680
734
|
/** The host passing an options object does not attest who authored it. */
|
|
681
735
|
type InlineOptionsTrust = "trusted" | "project" | "unknown";
|
|
682
736
|
|
|
@@ -692,9 +746,158 @@ type InlineOptionsTrust = "trusted" | "project" | "unknown";
|
|
|
692
746
|
* byte-identical to calling `resolveConfig(inlineOptions)` directly. */
|
|
693
747
|
declare function loadResolvedConfig(inlineOptions: Record<string, unknown> | undefined, directory?: string, inlineTrust?: InlineOptionsTrust): ReviewerConfig;
|
|
694
748
|
|
|
749
|
+
type ReviewUiPhase = "reviewing" | "approved" | "denied" | "manual" | "unknown";
|
|
750
|
+
interface ReviewUiStatus {
|
|
751
|
+
version: 1;
|
|
752
|
+
requestID: string;
|
|
753
|
+
sessionID: string;
|
|
754
|
+
phase: ReviewUiPhase;
|
|
755
|
+
permission: string;
|
|
756
|
+
action: string;
|
|
757
|
+
model: string;
|
|
758
|
+
variant: string;
|
|
759
|
+
emittedAt: number;
|
|
760
|
+
timeoutMs: number;
|
|
761
|
+
reason?: string;
|
|
762
|
+
decision?: ReviewDecision;
|
|
763
|
+
/**
|
|
764
|
+
* When phase is `denied` and this is `"deny"`, the block came from fail-closed
|
|
765
|
+
* escalation disposition rather than an explicit reviewer/policy deny.
|
|
766
|
+
*/
|
|
767
|
+
escalationDisposition?: EscalationDisposition;
|
|
768
|
+
/** Resolved actor (absent on the initial "reviewing" phase, before context
|
|
769
|
+
* collection completes). */
|
|
770
|
+
actorName?: string;
|
|
771
|
+
actorProfile?: ActorProfile;
|
|
772
|
+
}
|
|
773
|
+
declare function permissionAction(request: PermissionRequest): string;
|
|
774
|
+
declare function createUiStatus(request: PermissionRequest, phase: ReviewUiPhase, options: {
|
|
775
|
+
model: string;
|
|
776
|
+
variant: string;
|
|
777
|
+
timeoutMs: number;
|
|
778
|
+
reason?: string;
|
|
779
|
+
decision?: ReviewDecision;
|
|
780
|
+
escalationDisposition?: EscalationDisposition;
|
|
781
|
+
emittedAt?: number;
|
|
782
|
+
actorName?: string;
|
|
783
|
+
actorProfile?: ActorProfile;
|
|
784
|
+
}): ReviewUiStatus;
|
|
785
|
+
declare function encodeUiStatus(status: ReviewUiStatus): string;
|
|
786
|
+
declare function decodeUiStatus(command: string): ReviewUiStatus | undefined;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Captures user answers to agent ask dialogs (the `question` tool) from the
|
|
790
|
+
* OpenCode event stream and exposes them as compact, session-scoped
|
|
791
|
+
* authorization evidence for the reviewer prompt.
|
|
792
|
+
*
|
|
793
|
+
* The host runs questions through a dedicated service (`question.asked` /
|
|
794
|
+
* `question.replied` / `question.rejected` events) that never touches the
|
|
795
|
+
* permission pipeline, so these decisions are invisible to a permission-only
|
|
796
|
+
* observer. This registry is the counterpart capture layer: it is
|
|
797
|
+
* enrichment-only — question events never trigger, supersede, or enforce
|
|
798
|
+
* anything — and it is total (malformed events are dropped, never thrown).
|
|
799
|
+
*
|
|
800
|
+
* Robustness rules:
|
|
801
|
+
* - One logical ask = one record, keyed by the per-ask request ID. The v1 and
|
|
802
|
+
* v2 event spellings of the same ask upsert into the same entry, and a
|
|
803
|
+
* replayed reply or rejection is ignored.
|
|
804
|
+
* - A reply or rejection without a matching pending ask is dropped (the
|
|
805
|
+
* question text is unknowable after the fact).
|
|
806
|
+
* - Pending asks expire (TTL) so a very late reply cannot pair with a stale
|
|
807
|
+
* question from another context.
|
|
808
|
+
* - Resolved decisions are FIFO-bounded globally; the per-review limit is
|
|
809
|
+
* applied at query time, not storage time.
|
|
810
|
+
* - Question and answer text is redacted before storage; a credential pasted
|
|
811
|
+
* as a custom answer must never land in the registry, prompt, or audit.
|
|
812
|
+
*/
|
|
813
|
+
/** Marker recorded when the user dismisses an ask without answering. */
|
|
814
|
+
declare const DISMISSED_ANSWER = "Dismissed by user";
|
|
815
|
+
type Logger$1 = (message: string, details?: unknown) => void;
|
|
816
|
+
/** What the evidence assembler consumes: a bounded, lineage-scoped query. */
|
|
817
|
+
interface AskDecisionSource {
|
|
818
|
+
recentFor(sessionIDs: string[], limit?: number): AskDecision[];
|
|
819
|
+
}
|
|
820
|
+
declare class AskDecisionRegistry implements AskDecisionSource {
|
|
821
|
+
private readonly pending;
|
|
822
|
+
private readonly resolved;
|
|
823
|
+
private readonly log;
|
|
824
|
+
private readonly now;
|
|
825
|
+
constructor(logger?: Logger$1, now?: () => number);
|
|
826
|
+
/**
|
|
827
|
+
* Observe one raw event. Total: never throws; anything malformed or
|
|
828
|
+
* unrelated is dropped silently. Must be called synchronously from the event
|
|
829
|
+
* hook so registry mutations are visible to reviews started later.
|
|
830
|
+
*/
|
|
831
|
+
observe(event: unknown): void;
|
|
832
|
+
/**
|
|
833
|
+
* Decisions visible to a review running in `sessionIDs` (the requesting
|
|
834
|
+
* session plus its resolved ancestors), oldest first, bounded to the most
|
|
835
|
+
* recent `limit`. Sibling and unrelated sessions are never visible.
|
|
836
|
+
*/
|
|
837
|
+
recentFor(sessionIDs: string[], limit?: number): AskDecision[];
|
|
838
|
+
/** Observed-but-unresolved asks (diagnostics only). */
|
|
839
|
+
pendingCount(): number;
|
|
840
|
+
/** Resolved decisions retained (diagnostics only). */
|
|
841
|
+
resolvedCount(): number;
|
|
842
|
+
private onAsked;
|
|
843
|
+
private onReplied;
|
|
844
|
+
private onRejected;
|
|
845
|
+
private store;
|
|
846
|
+
}
|
|
847
|
+
|
|
695
848
|
type Context = Parameters<Plugin.Plugin["setup"]>[0];
|
|
849
|
+
|
|
696
850
|
declare function setup(ctx: Context): Promise<() => Promise<void>>;
|
|
697
851
|
|
|
852
|
+
declare function resolveConfig(options: Record<string, unknown> | undefined): ReviewerConfig;
|
|
853
|
+
|
|
854
|
+
interface SshAuditSummary {
|
|
855
|
+
destination: string;
|
|
856
|
+
port?: string;
|
|
857
|
+
remoteCommandSha256?: string;
|
|
858
|
+
stdinSource?: string;
|
|
859
|
+
stdinStatus?: string;
|
|
860
|
+
stdinReason?: string;
|
|
861
|
+
}
|
|
862
|
+
interface SshEnrichmentResult {
|
|
863
|
+
text: string;
|
|
864
|
+
audit: SshAuditSummary[];
|
|
865
|
+
preflightDenial?: string;
|
|
866
|
+
}
|
|
867
|
+
declare function enrichSshEvidence(request: PermissionRequest, directory: string, worktree: string, maxChars: number): Promise<SshEnrichmentResult>;
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* A single piece of evidence gathered about a permission request. The runtime
|
|
871
|
+
* only consumes `text`, `audit`, and `preflightDenial` today; the remaining
|
|
872
|
+
* fields give future providers room to surface warnings and cost without
|
|
873
|
+
* changing the interface.
|
|
874
|
+
*/
|
|
875
|
+
interface EvidenceFragment {
|
|
876
|
+
kind: "ssh" | "local_script" | "git";
|
|
877
|
+
text: string;
|
|
878
|
+
audit?: SshAuditSummary[];
|
|
879
|
+
preflightDenial?: string;
|
|
880
|
+
warnings?: string[];
|
|
881
|
+
durationMs?: number;
|
|
882
|
+
}
|
|
883
|
+
interface EvidenceScope {
|
|
884
|
+
directory: string;
|
|
885
|
+
worktree: string;
|
|
886
|
+
maxChars: number;
|
|
887
|
+
}
|
|
888
|
+
interface EvidenceProviderInput extends EvidenceScope {
|
|
889
|
+
request: PermissionRequest;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Enriches a permission request with one category of evidence (SSH analysis,
|
|
893
|
+
* local script inspection, Git state, …). Providers run concurrently and their
|
|
894
|
+
* fragments are assembled into a single review envelope.
|
|
895
|
+
*/
|
|
896
|
+
interface EvidenceProvider {
|
|
897
|
+
readonly id: string;
|
|
898
|
+
collect(input: EvidenceProviderInput): Promise<EvidenceFragment>;
|
|
899
|
+
}
|
|
900
|
+
|
|
698
901
|
/** What the plugin learned about the host client at startup. */
|
|
699
902
|
interface OpenCodeCapabilities {
|
|
700
903
|
/** A public SDK method to answer a permission request exists. */
|
|
@@ -717,45 +920,6 @@ interface OpenCodeCapabilities {
|
|
|
717
920
|
tuiPublish: boolean;
|
|
718
921
|
}
|
|
719
922
|
|
|
720
|
-
type ReviewUiPhase = "reviewing" | "approved" | "denied" | "manual" | "unknown";
|
|
721
|
-
interface ReviewUiStatus {
|
|
722
|
-
version: 1;
|
|
723
|
-
requestID: string;
|
|
724
|
-
sessionID: string;
|
|
725
|
-
phase: ReviewUiPhase;
|
|
726
|
-
permission: string;
|
|
727
|
-
action: string;
|
|
728
|
-
model: string;
|
|
729
|
-
variant: string;
|
|
730
|
-
emittedAt: number;
|
|
731
|
-
timeoutMs: number;
|
|
732
|
-
reason?: string;
|
|
733
|
-
decision?: ReviewDecision;
|
|
734
|
-
/**
|
|
735
|
-
* When phase is `denied` and this is `"deny"`, the block came from fail-closed
|
|
736
|
-
* escalation disposition rather than an explicit reviewer/policy deny.
|
|
737
|
-
*/
|
|
738
|
-
escalationDisposition?: EscalationDisposition;
|
|
739
|
-
/** Resolved actor (absent on the initial "reviewing" phase, before context
|
|
740
|
-
* collection completes). */
|
|
741
|
-
actorName?: string;
|
|
742
|
-
actorProfile?: ActorProfile;
|
|
743
|
-
}
|
|
744
|
-
declare function permissionAction(request: PermissionRequest): string;
|
|
745
|
-
declare function createUiStatus(request: PermissionRequest, phase: ReviewUiPhase, options: {
|
|
746
|
-
model: string;
|
|
747
|
-
variant: string;
|
|
748
|
-
timeoutMs: number;
|
|
749
|
-
reason?: string;
|
|
750
|
-
decision?: ReviewDecision;
|
|
751
|
-
escalationDisposition?: EscalationDisposition;
|
|
752
|
-
emittedAt?: number;
|
|
753
|
-
actorName?: string;
|
|
754
|
-
actorProfile?: ActorProfile;
|
|
755
|
-
}): ReviewUiStatus;
|
|
756
|
-
declare function encodeUiStatus(status: ReviewUiStatus): string;
|
|
757
|
-
declare function decodeUiStatus(command: string): ReviewUiStatus | undefined;
|
|
758
|
-
|
|
759
923
|
interface ClientResponse<T> {
|
|
760
924
|
data?: T;
|
|
761
925
|
error?: unknown;
|
|
@@ -800,114 +964,8 @@ interface RuntimeContext {
|
|
|
800
964
|
reviewerDirectoryBase?: string;
|
|
801
965
|
}
|
|
802
966
|
|
|
803
|
-
interface SshAuditSummary {
|
|
804
|
-
destination: string;
|
|
805
|
-
port?: string;
|
|
806
|
-
remoteCommandSha256?: string;
|
|
807
|
-
stdinSource?: string;
|
|
808
|
-
stdinStatus?: string;
|
|
809
|
-
stdinReason?: string;
|
|
810
|
-
}
|
|
811
|
-
interface SshEnrichmentResult {
|
|
812
|
-
text: string;
|
|
813
|
-
audit: SshAuditSummary[];
|
|
814
|
-
preflightDenial?: string;
|
|
815
|
-
}
|
|
816
|
-
declare function enrichSshEvidence(request: PermissionRequest, directory: string, worktree: string, maxChars: number): Promise<SshEnrichmentResult>;
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* A single piece of evidence gathered about a permission request. The runtime
|
|
820
|
-
* only consumes `text`, `audit`, and `preflightDenial` today; the remaining
|
|
821
|
-
* fields give future providers room to surface warnings and cost without
|
|
822
|
-
* changing the interface.
|
|
823
|
-
*/
|
|
824
|
-
interface EvidenceFragment {
|
|
825
|
-
kind: "ssh" | "local_script" | "git";
|
|
826
|
-
text: string;
|
|
827
|
-
audit?: SshAuditSummary[];
|
|
828
|
-
preflightDenial?: string;
|
|
829
|
-
warnings?: string[];
|
|
830
|
-
durationMs?: number;
|
|
831
|
-
}
|
|
832
|
-
interface EvidenceProviderInput {
|
|
833
|
-
request: PermissionRequest;
|
|
834
|
-
directory: string;
|
|
835
|
-
worktree: string;
|
|
836
|
-
maxChars: number;
|
|
837
|
-
}
|
|
838
|
-
/**
|
|
839
|
-
* Enriches a permission request with one category of evidence (SSH analysis,
|
|
840
|
-
* local script inspection, Git state, …). Providers run concurrently and their
|
|
841
|
-
* fragments are assembled into a single review envelope.
|
|
842
|
-
*/
|
|
843
|
-
interface EvidenceProvider {
|
|
844
|
-
readonly id: string;
|
|
845
|
-
collect(input: EvidenceProviderInput): Promise<EvidenceFragment>;
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* Captures user answers to agent ask dialogs (the `question` tool) from the
|
|
850
|
-
* OpenCode event stream and exposes them as compact, session-scoped
|
|
851
|
-
* authorization evidence for the reviewer prompt.
|
|
852
|
-
*
|
|
853
|
-
* The host runs questions through a dedicated service (`question.asked` /
|
|
854
|
-
* `question.replied` / `question.rejected` events) that never touches the
|
|
855
|
-
* permission pipeline, so these decisions are invisible to a permission-only
|
|
856
|
-
* observer. This registry is the counterpart capture layer: it is
|
|
857
|
-
* enrichment-only — question events never trigger, supersede, or enforce
|
|
858
|
-
* anything — and it is total (malformed events are dropped, never thrown).
|
|
859
|
-
*
|
|
860
|
-
* Robustness rules:
|
|
861
|
-
* - One logical ask = one record, keyed by the per-ask request ID. The v1 and
|
|
862
|
-
* v2 event spellings of the same ask upsert into the same entry, and a
|
|
863
|
-
* replayed reply or rejection is ignored.
|
|
864
|
-
* - A reply or rejection without a matching pending ask is dropped (the
|
|
865
|
-
* question text is unknowable after the fact).
|
|
866
|
-
* - Pending asks expire (TTL) so a very late reply cannot pair with a stale
|
|
867
|
-
* question from another context.
|
|
868
|
-
* - Resolved decisions are FIFO-bounded globally; the per-review limit is
|
|
869
|
-
* applied at query time, not storage time.
|
|
870
|
-
* - Question and answer text is redacted before storage; a credential pasted
|
|
871
|
-
* as a custom answer must never land in the registry, prompt, or audit.
|
|
872
|
-
*/
|
|
873
|
-
/** Marker recorded when the user dismisses an ask without answering. */
|
|
874
|
-
declare const DISMISSED_ANSWER = "Dismissed by user";
|
|
875
|
-
type Logger$1 = (message: string, details?: unknown) => void;
|
|
876
|
-
/** What the evidence assembler consumes: a bounded, lineage-scoped query. */
|
|
877
|
-
interface AskDecisionSource {
|
|
878
|
-
recentFor(sessionIDs: string[], limit?: number): AskDecision[];
|
|
879
|
-
}
|
|
880
|
-
declare class AskDecisionRegistry implements AskDecisionSource {
|
|
881
|
-
private readonly pending;
|
|
882
|
-
private readonly resolved;
|
|
883
|
-
private readonly log;
|
|
884
|
-
private readonly now;
|
|
885
|
-
constructor(logger?: Logger$1, now?: () => number);
|
|
886
|
-
/**
|
|
887
|
-
* Observe one raw event. Total: never throws; anything malformed or
|
|
888
|
-
* unrelated is dropped silently. Must be called synchronously from the event
|
|
889
|
-
* hook so registry mutations are visible to reviews started later.
|
|
890
|
-
*/
|
|
891
|
-
observe(event: unknown): void;
|
|
892
|
-
/**
|
|
893
|
-
* Decisions visible to a review running in `sessionIDs` (the requesting
|
|
894
|
-
* session plus its resolved ancestors), oldest first, bounded to the most
|
|
895
|
-
* recent `limit`. Sibling and unrelated sessions are never visible.
|
|
896
|
-
*/
|
|
897
|
-
recentFor(sessionIDs: string[], limit?: number): AskDecision[];
|
|
898
|
-
/** Observed-but-unresolved asks (diagnostics only). */
|
|
899
|
-
pendingCount(): number;
|
|
900
|
-
/** Resolved decisions retained (diagnostics only). */
|
|
901
|
-
resolvedCount(): number;
|
|
902
|
-
private takePending;
|
|
903
|
-
private store;
|
|
904
|
-
/** Enforce the pending cap and TTL. Map iteration order is insertion
|
|
905
|
-
* order, so `keys().next()` is the oldest entry. */
|
|
906
|
-
private prunePending;
|
|
907
|
-
private pruneExpired;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
967
|
type Logger = (message: string, details?: unknown) => void;
|
|
968
|
+
|
|
911
969
|
/**
|
|
912
970
|
* Owns the review lifecycle for permission requests: orchestration, the
|
|
913
971
|
* supersede state machine, and the model call. The adapter (transport) and the
|
|
@@ -915,51 +973,15 @@ type Logger = (message: string, details?: unknown) => void;
|
|
|
915
973
|
* races.
|
|
916
974
|
*/
|
|
917
975
|
declare class ReviewCoordinator {
|
|
918
|
-
private readonly
|
|
919
|
-
private readonly config;
|
|
920
|
-
private readonly generation;
|
|
921
|
-
private readonly attempts;
|
|
922
|
-
private stopped;
|
|
976
|
+
private readonly state;
|
|
923
977
|
private readonly limiter;
|
|
924
978
|
private readonly pending;
|
|
925
|
-
private readonly backend;
|
|
926
|
-
/**
|
|
927
|
-
* Request IDs that a human (or any other reply source) resolved while the
|
|
928
|
-
* automatic review was still in flight. The in-flight review must then give
|
|
929
|
-
* up silently: no `emit`, no `reply`. OpenCode resolves a request on a
|
|
930
|
-
* first-writer basis, so a late programmatic reply returns 404
|
|
931
|
-
* PermissionNotFoundError — we treat that the same way.
|
|
932
|
-
*/
|
|
933
|
-
private readonly resolvedManually;
|
|
934
|
-
private readonly log;
|
|
935
|
-
private readonly providers;
|
|
936
|
-
private readonly scriptRegistry;
|
|
937
|
-
/** Live ask-decision capture (enrichment-only; undefined when disabled). */
|
|
938
|
-
private readonly askDecisions;
|
|
939
|
-
/** Bound for metadata SDK calls (session create, tool listing, replies,
|
|
940
|
-
* status publishing): a hung call must never leave a review pending
|
|
941
|
-
* forever; the reviewer prompt keeps its own full timeout budget. */
|
|
942
|
-
private readonly metadataCallTimeoutMs;
|
|
943
979
|
constructor(ctx: RuntimeContext, config: ReviewerConfig, logger?: Logger, providers?: EvidenceProvider[], askDecisions?: AskDecisionSource);
|
|
944
980
|
pendingCount(): number;
|
|
945
981
|
waitForIdle(): Promise<void>;
|
|
946
982
|
dispose(): Promise<void>;
|
|
947
983
|
handle(request: PermissionRequest): void;
|
|
948
984
|
process(request: PermissionRequest): Promise<ReviewExecutionResult>;
|
|
949
|
-
private supersedeResult;
|
|
950
|
-
private isSuperseded;
|
|
951
|
-
/**
|
|
952
|
-
* Reject a request with `reject` while honoring supersede. Returns `undefined`
|
|
953
|
-
* when the rejection was applied, or the supersede result when the request had
|
|
954
|
-
* already been answered manually (so the caller returns it unchanged).
|
|
955
|
-
*/
|
|
956
|
-
private denyAndReply;
|
|
957
|
-
/**
|
|
958
|
-
* Apply a fully disposed result (allow / deny / escalate) to UI + reply.
|
|
959
|
-
* This is the single side-effect boundary after logical disposition.
|
|
960
|
-
*/
|
|
961
|
-
private applyDisposition;
|
|
962
|
-
private processRequest;
|
|
963
985
|
handlePermissionReply(event: unknown): void;
|
|
964
986
|
/**
|
|
965
987
|
* @deprecated No-op. Approvals no longer annotate tool results so they do not
|
|
@@ -971,35 +993,12 @@ declare class ReviewCoordinator {
|
|
|
971
993
|
output?: unknown;
|
|
972
994
|
metadata?: unknown;
|
|
973
995
|
}): void;
|
|
974
|
-
private collectEnvelope;
|
|
975
|
-
private audit;
|
|
976
|
-
private runReviewer;
|
|
977
|
-
private remember;
|
|
978
|
-
/** Fold the reviewer phase's elapsed time into the request's timing record. */
|
|
979
|
-
private recordReviewerMs;
|
|
980
|
-
/**
|
|
981
|
-
* Send a permission reply. Returns `true` on success, `false` when the
|
|
982
|
-
* request was already resolved by another source (human TUI, a duplicate
|
|
983
|
-
* event, etc.) so the caller can treat itself as superseded. Other errors
|
|
984
|
-
* (transport failure, malformed reply) are still thrown.
|
|
985
|
-
*/
|
|
986
|
-
private safeReply;
|
|
987
|
-
private emit;
|
|
988
996
|
}
|
|
989
997
|
|
|
990
|
-
/**
|
|
991
|
-
* Normalize a raw OpenCode event into a {@link PermissionRequest}.
|
|
992
|
-
*
|
|
993
|
-
* Returns `undefined` for anything that is not a well-formed
|
|
994
|
-
* `permission.asked` event, so callers can ignore irrelevant events without
|
|
995
|
-
* inspecting their shape.
|
|
996
|
-
*/
|
|
997
|
-
declare function extractPermissionRequest(event: unknown): PermissionRequest | undefined;
|
|
998
|
-
|
|
999
|
-
declare function resolveConfig(options: Record<string, unknown> | undefined): ReviewerConfig;
|
|
1000
|
-
|
|
1001
998
|
declare function parseDecision(value: unknown): ReviewDecision | undefined;
|
|
999
|
+
|
|
1002
1000
|
declare function enforceDecision(decision: ReviewDecision, config: ReviewerConfig): ReviewExecutionResult;
|
|
1001
|
+
|
|
1003
1002
|
declare const DECISION_SCHEMA: {
|
|
1004
1003
|
readonly type: "object";
|
|
1005
1004
|
readonly additionalProperties: false;
|
|
@@ -1053,6 +1052,8 @@ declare const DECISION_SCHEMA: {
|
|
|
1053
1052
|
};
|
|
1054
1053
|
};
|
|
1055
1054
|
|
|
1055
|
+
declare function emergencyBrakeReason(request: PermissionRequest): string | undefined;
|
|
1056
|
+
|
|
1056
1057
|
/**
|
|
1057
1058
|
* Categories that can be hardened independently of the global escalation mode
|
|
1058
1059
|
* via `riskPolicy.onInvalidDecision` / `riskPolicy.onReviewerFailure`.
|
|
@@ -1085,7 +1086,26 @@ declare function resolveEscalationDisposition(result: ReviewExecutionResult, con
|
|
|
1085
1086
|
*/
|
|
1086
1087
|
declare function applyEscalationDisposition(result: ReviewExecutionResult, config: ReviewerConfig, category?: EscalationCategory): ReviewExecutionResult;
|
|
1087
1088
|
|
|
1088
|
-
|
|
1089
|
+
interface GitEnrichmentResult {
|
|
1090
|
+
text: string;
|
|
1091
|
+
}
|
|
1092
|
+
declare function enrichGitEvidence(request: PermissionRequest, directory: string, maxChars: number, worktree?: string): Promise<GitEnrichmentResult>;
|
|
1093
|
+
|
|
1094
|
+
interface LocalScriptEnrichmentResult {
|
|
1095
|
+
text: string;
|
|
1096
|
+
}
|
|
1097
|
+
/** `rootDirectory` is the approved evidence root, which can sit above
|
|
1098
|
+
* `directory` (package-script expansion passes the session directory). */
|
|
1099
|
+
declare function enrichLocalScriptEvidence(request: PermissionRequest, directory: string, worktree: string, maxChars: number, rootDirectory?: string): Promise<LocalScriptEnrichmentResult>;
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* Normalize a raw OpenCode event into a {@link PermissionRequest}.
|
|
1103
|
+
*
|
|
1104
|
+
* Returns `undefined` for anything that is not a well-formed
|
|
1105
|
+
* `permission.asked` event, so callers can ignore irrelevant events without
|
|
1106
|
+
* inspecting their shape.
|
|
1107
|
+
*/
|
|
1108
|
+
declare function extractPermissionRequest(event: unknown): PermissionRequest | undefined;
|
|
1089
1109
|
|
|
1090
1110
|
declare function redactSecrets(input: string): string;
|
|
1091
1111
|
|
|
@@ -1110,19 +1130,6 @@ declare class ReviewUiState {
|
|
|
1110
1130
|
dismissResults(now?: number): string[];
|
|
1111
1131
|
}
|
|
1112
1132
|
|
|
1113
|
-
declare const DEFAULT_AUDIT_PATH = "~/.local/share/opencode/permission-reviewer-audit.jsonl";
|
|
1114
|
-
declare function createAuditWriter(config: ReviewerConfig, logger?: (message: string, details?: unknown) => void): ((record: ReviewAuditRecord) => Promise<void>) | undefined;
|
|
1115
|
-
|
|
1116
|
-
interface LocalScriptEnrichmentResult {
|
|
1117
|
-
text: string;
|
|
1118
|
-
}
|
|
1119
|
-
declare function enrichLocalScriptEvidence(request: PermissionRequest, directory: string, worktree: string, maxChars: number): Promise<LocalScriptEnrichmentResult>;
|
|
1120
|
-
|
|
1121
|
-
interface GitEnrichmentResult {
|
|
1122
|
-
text: string;
|
|
1123
|
-
}
|
|
1124
|
-
declare function enrichGitEvidence(request: PermissionRequest, directory: string, maxChars: number, worktree?: string): Promise<GitEnrichmentResult>;
|
|
1125
|
-
|
|
1126
1133
|
declare const server: Plugin$1;
|
|
1127
1134
|
declare const module$1: {
|
|
1128
1135
|
id: string;
|
|
@@ -1130,4 +1137,4 @@ declare const module$1: {
|
|
|
1130
1137
|
setup: typeof setup;
|
|
1131
1138
|
};
|
|
1132
1139
|
|
|
1133
|
-
export { type ActionPurpose, type ActorContext, type ActorProfile, ReviewCoordinator as ApprovalReviewerRuntime, type ApprovedAnnotation, type AskDecision, AskDecisionRegistry, type CapabilityActionClass, type CapabilityAssessment, DECISION_SCHEMA, DEFAULT_AUDIT_PATH, DISMISSED_ANSWER, type DecisionSource, type EffectivePermissionSummary, type EscalationDisposition, type EscalationMode, type EscalationReviewerConfig, type EvidenceCompleteness, type EvidenceConfidence, type EvidenceSufficiency, type HeredocRecord, type IntentBlock, type IntentContext, 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, ReviewUiState, type ReviewerConfig, type ReviewerOutputFormat, type RiskLevel, type RiskPolicy, type ScopeAlignment, type SessionLineage, type SessionNode, type UserAuthorization, applyEscalationDisposition, createAuditWriter, createUiStatus, decodeUiStatus, module$1 as default, emergencyBrakeReason, encodeUiStatus, enforceDecision, enrichGitEvidence, enrichLocalScriptEvidence, enrichSshEvidence, extractPermissionRequest, loadResolvedConfig, parseDecision, permissionAction, redactSecrets, resolveConfig, resolveEscalationDisposition, server };
|
|
1140
|
+
export { type ActionPurpose, type ActorContext, type ActorProfile, ReviewCoordinator as ApprovalReviewerRuntime, type ApprovedAnnotation, type AskDecision, AskDecisionRegistry, type CapabilityActionClass, type CapabilityAssessment, DECISION_SCHEMA, DEFAULT_AUDIT_PATH, DISMISSED_ANSWER, type DecisionSource, type EffectivePermissionSummary, type EscalationDisposition, type EscalationMode, type EscalationReviewerConfig, type EvidenceCompleteness, type EvidenceConfidence, type EvidenceSufficiency, type HeredocRecord, type IntentBlock, type IntentContext, 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, ReviewUiState, type ReviewerConfig, type ReviewerOutputFormat, type RiskLevel, type RiskPolicy, SYSTEM_ONE_BASES, type ScopeAlignment, type SessionLineage, type SessionNode, type SystemOneChoiceScore, type SystemOnePrimaryBasis, type SystemOneScores, type SystemOneSignals, type UserAuthorization, applyEscalationDisposition, createAuditWriter, createUiStatus, decodeUiStatus, module$1 as default, emergencyBrakeReason, encodeUiStatus, enforceDecision, enrichGitEvidence, enrichLocalScriptEvidence, enrichSshEvidence, extractPermissionRequest, loadResolvedConfig, parseDecision, permissionAction, redactSecrets, resolveConfig, resolveEscalationDisposition, server };
|