@noppu-labs/opencode-permission-reviewer 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +130 -0
- package/MIGRATION.md +2 -1
- package/README.md +15 -6
- package/dist/explain.d.ts +3 -4
- package/dist/explain.js +9219 -5219
- package/dist/index.d.ts +1011 -863
- package/dist/index.js +17490 -12843
- package/dist/rpc.d.ts +38 -38
- package/dist/rpc.js +30 -21
- package/dist/tui/config/loader.ts +14 -1
- package/dist/tui/config/trust-boundary-keys.ts +2 -0
- package/dist/tui/config/trust-boundary.ts +13 -0
- package/dist/tui/config-fields.ts +21 -1
- package/dist/tui/config.ts +12 -2
- package/dist/tui/failure-kind.ts +28 -0
- package/dist/tui/system-one-routing.ts +110 -0
- package/dist/tui/tui.tsx +19 -9
- package/dist/tui/types.ts +39 -2
- package/dist/tui/ui/action-fit.ts +161 -0
- package/dist/tui/ui/action-spans.tsx +60 -0
- package/dist/tui/ui/attribution.ts +113 -0
- package/dist/tui/ui/components.tsx +41 -5
- package/dist/tui/ui/config-notices.ts +137 -0
- package/dist/tui/ui/fit-parts.ts +76 -0
- package/dist/tui/ui/manual-toast.ts +87 -0
- package/dist/tui/ui/review-feed.ts +30 -5
- package/dist/tui/ui/review-overlay.tsx +33 -5
- package/dist/tui/ui/review-result.tsx +23 -5
- package/dist/tui/ui/review-theme.ts +8 -1
- package/dist/tui/ui/v1-host.ts +37 -10
- package/dist/tui/ui/v2.tsx +17 -1
- package/dist/tui/ui-protocol.ts +63 -20
- package/dist/tui/ui-state.ts +16 -1
- package/dist/tui/ui-status-extras.ts +165 -0
- package/dist/tui/ui-status-parse.ts +60 -2
- package/dist/tui/ui-text-elide.ts +89 -0
- package/package.json +11 -11
package/dist/rpc.d.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
+
//#region src/ui/rpc.d.ts
|
|
1
2
|
/** Portable, read-only protocol. No UI message can approve a permission. */
|
|
2
|
-
declare const ReviewerRpc: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
readonly status: {
|
|
15
|
-
readonly input: {
|
|
16
|
-
readonly type: "object";
|
|
17
|
-
readonly additionalProperties: false;
|
|
18
|
-
};
|
|
19
|
-
readonly output: {
|
|
20
|
-
readonly type: "object";
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
readonly snapshot: {
|
|
24
|
-
readonly input: {
|
|
25
|
-
readonly type: "object";
|
|
26
|
-
readonly additionalProperties: false;
|
|
27
|
-
};
|
|
28
|
-
readonly output: {
|
|
29
|
-
readonly type: "object";
|
|
30
|
-
};
|
|
31
|
-
};
|
|
3
|
+
export declare const ReviewerRpc: {
|
|
4
|
+
readonly id: "opencode-permission-reviewer";
|
|
5
|
+
readonly methods: {
|
|
6
|
+
readonly identity: {
|
|
7
|
+
readonly input: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly additionalProperties: false;
|
|
10
|
+
};
|
|
11
|
+
readonly output: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
};
|
|
32
14
|
};
|
|
33
|
-
readonly
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
readonly status: {
|
|
16
|
+
readonly input: {
|
|
17
|
+
readonly type: "object";
|
|
18
|
+
readonly additionalProperties: false;
|
|
19
|
+
};
|
|
20
|
+
readonly output: {
|
|
21
|
+
readonly type: "object";
|
|
22
|
+
};
|
|
39
23
|
};
|
|
24
|
+
readonly snapshot: {
|
|
25
|
+
readonly input: {
|
|
26
|
+
readonly type: "object";
|
|
27
|
+
readonly additionalProperties: false;
|
|
28
|
+
};
|
|
29
|
+
readonly output: {
|
|
30
|
+
readonly type: "object";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
readonly events: {
|
|
35
|
+
readonly "review.updated": {
|
|
36
|
+
readonly schema: {
|
|
37
|
+
readonly type: "object";
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
-
export { ReviewerRpc };
|
|
42
|
+
//#endregion
|
package/dist/rpc.js
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
//#region src/ui/rpc.ts
|
|
2
|
+
/** Portable, read-only protocol. No UI message can approve a permission. */
|
|
3
|
+
const ReviewerRpc = {
|
|
4
|
+
id: "opencode-permission-reviewer",
|
|
5
|
+
methods: {
|
|
6
|
+
identity: {
|
|
7
|
+
input: {
|
|
8
|
+
type: "object",
|
|
9
|
+
additionalProperties: false
|
|
10
|
+
},
|
|
11
|
+
output: { type: "string" }
|
|
12
|
+
},
|
|
13
|
+
status: {
|
|
14
|
+
input: {
|
|
15
|
+
type: "object",
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
},
|
|
18
|
+
output: { type: "object" }
|
|
19
|
+
},
|
|
20
|
+
snapshot: {
|
|
21
|
+
input: {
|
|
22
|
+
type: "object",
|
|
23
|
+
additionalProperties: false
|
|
24
|
+
},
|
|
25
|
+
output: { type: "object" }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
events: { "review.updated": { schema: { type: "object" } } }
|
|
22
29
|
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ReviewerRpc };
|
|
@@ -34,6 +34,12 @@ export function projectConfigPath(directory: string): string {
|
|
|
34
34
|
return join(directory, ".opencode", "permission-reviewer.jsonc");
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export interface LoadOptions {
|
|
38
|
+
/** Off for a caller that shows `configWarnings` another way, such as the TUI
|
|
39
|
+
* from server statuses. */
|
|
40
|
+
printConfigWarnings?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
/** Load and merge config from global, project, and inline sources.
|
|
38
44
|
*
|
|
39
45
|
* Precedence (lowest to highest): builtin defaults → global → project → inline,
|
|
@@ -48,6 +54,7 @@ export function loadResolvedConfig(
|
|
|
48
54
|
inlineOptions: Record<string, unknown> | undefined,
|
|
49
55
|
directory?: string,
|
|
50
56
|
inlineTrust: InlineOptionsTrust = "trusted",
|
|
57
|
+
{ printConfigWarnings = true }: LoadOptions = {},
|
|
51
58
|
): ReviewerConfig {
|
|
52
59
|
const globalLayer = readConfigLayer(globalConfigPath());
|
|
53
60
|
const projectLayer: ConfigLayer =
|
|
@@ -79,7 +86,13 @@ export function loadResolvedConfig(
|
|
|
79
86
|
inlineTrust,
|
|
80
87
|
);
|
|
81
88
|
if (degraded.length > 0) out.configDegraded = degraded;
|
|
82
|
-
|
|
89
|
+
const config = resolveConfig(out);
|
|
90
|
+
if (printConfigWarnings) {
|
|
91
|
+
for (const warning of config.configWarnings ?? []) {
|
|
92
|
+
console.warn(`permission-reviewer: ${warning}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return config;
|
|
83
96
|
}
|
|
84
97
|
|
|
85
98
|
function mergeLayers(
|
|
@@ -33,6 +33,7 @@ export function mergeWithTrustBoundary(
|
|
|
33
33
|
clampEnforcementMode(clamped, trusted);
|
|
34
34
|
clampProjectRiskPolicy(clamped, trusted);
|
|
35
35
|
clampEscalationMode(clamped, trusted);
|
|
36
|
+
clampSystemOneRouting(clamped);
|
|
36
37
|
combinePolicyRules(clamped, trusted);
|
|
37
38
|
return { ...trusted, ...clamped };
|
|
38
39
|
}
|
|
@@ -107,6 +108,18 @@ function clampEscalationMode(
|
|
|
107
108
|
if (invalid || relaxes) delete clamped.escalationMode;
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
/** systemOneEscalation and systemOneDenialReview: a repository may keep Jev's
|
|
112
|
+
* escalations and denials with the human ("standard", false) but can never
|
|
113
|
+
* turn either hand-off on. Any other value, including null, is dropped. */
|
|
114
|
+
function clampSystemOneRouting(clamped: Record<string, unknown>): void {
|
|
115
|
+
if (clamped.systemOneEscalation !== "standard") {
|
|
116
|
+
delete clamped.systemOneEscalation;
|
|
117
|
+
}
|
|
118
|
+
if (clamped.systemOneDenialReview !== false) {
|
|
119
|
+
delete clamped.systemOneDenialReview;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
110
123
|
/** policyRules: the project layer ADDS rules (which can only tighten — its
|
|
111
124
|
* allow rules are filtered by the engine), it never erases trusted
|
|
112
125
|
* global/inline deny/manual rules. Combine instead of replace so a repo
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ACTOR_PROFILES } from "./config-rule-condition.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ActorProfile,
|
|
4
|
+
EscalationMode,
|
|
5
|
+
RepositoryTrust,
|
|
6
|
+
ReviewerConfig,
|
|
7
|
+
} from "./types.ts";
|
|
3
8
|
|
|
4
9
|
/** Parse a trusted name→profile mapping. Invalid entries are dropped. */
|
|
5
10
|
export function resolveActorProfiles(
|
|
@@ -24,6 +29,21 @@ export function resolveEscalationMode(value: unknown): EscalationMode {
|
|
|
24
29
|
return value === "deny" ? "deny" : "manual";
|
|
25
30
|
}
|
|
26
31
|
|
|
32
|
+
/** An invalid value falls back to the default, which adds no hand-off to the
|
|
33
|
+
* escalation reviewer, so system-one-routing.ts reports it as a config
|
|
34
|
+
* warning, never degradation. */
|
|
35
|
+
export function systemOneRoutingFields(
|
|
36
|
+
source: Record<string, unknown>,
|
|
37
|
+
): Pick<ReviewerConfig, "systemOneEscalation" | "systemOneDenialReview"> {
|
|
38
|
+
return {
|
|
39
|
+
systemOneEscalation:
|
|
40
|
+
source.systemOneEscalation === "reasoning-first"
|
|
41
|
+
? "reasoning-first"
|
|
42
|
+
: "standard",
|
|
43
|
+
systemOneDenialReview: source.systemOneDenialReview === true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
export function resolveRepositoryTrust(value: unknown): RepositoryTrust {
|
|
28
48
|
if (value === "trusted") return "trusted";
|
|
29
49
|
if (value === "untrusted") return "untrusted";
|
package/dist/tui/config.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
resolveActorProfiles,
|
|
6
6
|
resolveEscalationMode,
|
|
7
7
|
resolveRepositoryTrust,
|
|
8
|
+
systemOneRoutingFields,
|
|
8
9
|
trimmedText,
|
|
9
10
|
} from "./config-fields.ts";
|
|
10
11
|
import {
|
|
@@ -25,6 +26,7 @@ import {
|
|
|
25
26
|
isProviderModelId,
|
|
26
27
|
resolveEscalationReviewer,
|
|
27
28
|
} from "./reviewer-model.ts";
|
|
29
|
+
import { withSystemOneRoutingWarnings } from "./system-one-routing.ts";
|
|
28
30
|
import type { ReviewerConfig } from "./types.ts";
|
|
29
31
|
|
|
30
32
|
export const DEFAULT_CONFIG: ReviewerConfig = {
|
|
@@ -42,6 +44,8 @@ export const DEFAULT_CONFIG: ReviewerConfig = {
|
|
|
42
44
|
confidenceThreshold: 0.7,
|
|
43
45
|
systemOneConfidenceThreshold: 0.4,
|
|
44
46
|
systemOneReasoningThreshold: 0.38,
|
|
47
|
+
systemOneEscalation: "standard",
|
|
48
|
+
systemOneDenialReview: false,
|
|
45
49
|
retainReviewSessions: false,
|
|
46
50
|
audit: true,
|
|
47
51
|
debug: false,
|
|
@@ -58,7 +62,11 @@ export const DEFAULT_CONFIG: ReviewerConfig = {
|
|
|
58
62
|
|
|
59
63
|
/** Total deadline for a review, shared by the server and TUI watchdog. */
|
|
60
64
|
export function reviewBudgetMs(config: ReviewerConfig): number {
|
|
61
|
-
|
|
65
|
+
const escalationMs = config.escalationReviewer?.timeoutMs ?? config.timeoutMs;
|
|
66
|
+
return (
|
|
67
|
+
config.reviewBudgetMs ??
|
|
68
|
+
config.timeoutMs + Math.max(config.timeoutMs, escalationMs) + 60_000
|
|
69
|
+
);
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
type FlagKey = "retainReviewSessions" | "audit" | "debug" | "askDecisions";
|
|
@@ -73,7 +81,7 @@ export function resolveConfig(
|
|
|
73
81
|
): ReviewerConfig {
|
|
74
82
|
const source = options ?? {};
|
|
75
83
|
// Key order is part of the output: the server hashes the serialized config.
|
|
76
|
-
|
|
84
|
+
const resolved: ReviewerConfig = {
|
|
77
85
|
model: isProviderModelId(source.model)
|
|
78
86
|
? source.model
|
|
79
87
|
: DEFAULT_CONFIG.model,
|
|
@@ -87,6 +95,7 @@ export function resolveConfig(
|
|
|
87
95
|
...reviewBudgetKnob(source),
|
|
88
96
|
...integerKnobs(source, CONTEXT_BUDGETS, DEFAULT_CONFIG),
|
|
89
97
|
...numberKnobs(source, CONFIDENCE_FLOORS, DEFAULT_CONFIG),
|
|
98
|
+
...systemOneRoutingFields(source),
|
|
90
99
|
retainReviewSessions: flag(source, "retainReviewSessions"),
|
|
91
100
|
audit: flag(source, "audit"),
|
|
92
101
|
...optional("auditPath", trimmedText(source.auditPath)),
|
|
@@ -107,4 +116,5 @@ export function resolveConfig(
|
|
|
107
116
|
? { configDegraded: source.configDegraded }
|
|
108
117
|
: {}),
|
|
109
118
|
};
|
|
119
|
+
return withSystemOneRoutingWarnings(resolved, source);
|
|
110
120
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Reads back the error name that formatFailureReason ("<phase> failed
|
|
2
|
+
// (<Name>…): …") puts in a failure-safe reason, as a short word to show.
|
|
3
|
+
|
|
4
|
+
const FAILED_NAME = /\bfailed \(([A-Za-z]+)/;
|
|
5
|
+
const TIMED_OUT = /\btimed out\b/i;
|
|
6
|
+
/** The TypeSafe SDK errors Jev's invoker throws, as the short words the TUI shows. */
|
|
7
|
+
const SDK_KINDS = new Map([
|
|
8
|
+
["APIConnectionError", "transport"],
|
|
9
|
+
["APIUserAbortError", "abort"],
|
|
10
|
+
["AuthenticationError", "auth"],
|
|
11
|
+
["PermissionDeniedError", "auth"],
|
|
12
|
+
["RateLimitError", "rate-limit"],
|
|
13
|
+
["InternalServerError", "server"],
|
|
14
|
+
["BadRequestError", "bad-request"],
|
|
15
|
+
["UnprocessableEntityError", "bad-request"],
|
|
16
|
+
["NotFoundError", "not-found"],
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
/** "timeout" for a timeout, a short word for a known SDK error, else the
|
|
20
|
+
* error name without its "Error" suffix in lower case ("error" for a bare
|
|
21
|
+
* Error); undefined when `reason` names no failure. */
|
|
22
|
+
export function failureKind(reason: string): string | undefined {
|
|
23
|
+
const name = FAILED_NAME.exec(reason)?.[1];
|
|
24
|
+
if (name === undefined) return;
|
|
25
|
+
if (name === "TimeoutError" || TIMED_OUT.test(reason)) return "timeout";
|
|
26
|
+
if (name === "Error") return "error";
|
|
27
|
+
return SDK_KINDS.get(name) ?? name.replace(/Error$/, "").toLowerCase();
|
|
28
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { isSystemOneReviewerModel } from "./reviewer-model.ts";
|
|
2
|
+
import type { ReviewerConfig } from "./types.ts";
|
|
3
|
+
|
|
4
|
+
/** The least review time a hand-off needs; with less the request escalates. */
|
|
5
|
+
export const HANDOFF_BUDGET_FLOOR_MS = 15_000;
|
|
6
|
+
|
|
7
|
+
export interface SystemOneRouting {
|
|
8
|
+
/** reasoning-first is configured AND active (Jev model + valid escalationReviewer). */
|
|
9
|
+
reasoningFirst: boolean;
|
|
10
|
+
/** denial review is configured AND active (same conditions). */
|
|
11
|
+
denialReview: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A non-Jev model is reported first: no escalationReviewer fixes that. */
|
|
15
|
+
function inertCause(
|
|
16
|
+
config: ReviewerConfig,
|
|
17
|
+
): "not-jev" | "no-reviewer" | undefined {
|
|
18
|
+
if (!isSystemOneReviewerModel(config.model)) return "not-jev";
|
|
19
|
+
if (config.escalationReviewer === undefined) return "no-reviewer";
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function resolveSystemOneRouting(
|
|
24
|
+
config: ReviewerConfig,
|
|
25
|
+
): SystemOneRouting {
|
|
26
|
+
const active = inertCause(config) === undefined;
|
|
27
|
+
return {
|
|
28
|
+
reasoningFirst: active && config.systemOneEscalation === "reasoning-first",
|
|
29
|
+
denialReview: active && config.systemOneDenialReview,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Warnings for settings that are on but inert. */
|
|
34
|
+
export function systemOneRoutingWarnings(config: ReviewerConfig): string[] {
|
|
35
|
+
const cause = inertCause(config);
|
|
36
|
+
if (cause === undefined) return [];
|
|
37
|
+
const warnings: string[] = [];
|
|
38
|
+
if (config.systemOneEscalation === "reasoning-first") {
|
|
39
|
+
warnings.push(
|
|
40
|
+
cause === "not-jev"
|
|
41
|
+
? 'systemOneEscalation "reasoning-first" is inactive: the reviewer model is not Jev'
|
|
42
|
+
: 'systemOneEscalation "reasoning-first" is inactive: no escalationReviewer is configured; Jev escalations still go to you',
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (config.systemOneDenialReview) {
|
|
46
|
+
warnings.push(
|
|
47
|
+
cause === "not-jev"
|
|
48
|
+
? "systemOneDenialReview is inactive: the reviewer model is not Jev"
|
|
49
|
+
: "systemOneDenialReview is inactive: no escalationReviewer is configured; Jev denials stay final",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return warnings;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Standard routing hands off too, so neither routing key gates this. The
|
|
56
|
+
* default budget always leaves the floor, so only an explicit one can warn. */
|
|
57
|
+
function budgetFloorWarnings(config: ReviewerConfig): string[] {
|
|
58
|
+
const budget = config.reviewBudgetMs;
|
|
59
|
+
if (budget === undefined || inertCause(config) !== undefined) return [];
|
|
60
|
+
if (budget - config.timeoutMs >= HANDOFF_BUDGET_FLOOR_MS) return [];
|
|
61
|
+
return [
|
|
62
|
+
`reviewBudgetMs ${budget} leaves less than ${HANDOFF_BUDGET_FLOOR_MS} ms after timeoutMs; hand-offs to the reasoning reviewer will escalate to you instead`,
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const PREVIEW_CHARS = 80;
|
|
67
|
+
|
|
68
|
+
/** A warning names the value; it does not reproduce it. */
|
|
69
|
+
function preview(value: unknown): string {
|
|
70
|
+
const json = JSON.stringify(value) ?? String(value);
|
|
71
|
+
return json.length > PREVIEW_CHARS
|
|
72
|
+
? `${json.slice(0, PREVIEW_CHARS)}…`
|
|
73
|
+
: json;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A present source value the resolver did not keep was invalid. */
|
|
77
|
+
function invalidValueWarnings(
|
|
78
|
+
config: ReviewerConfig,
|
|
79
|
+
source: Record<string, unknown>,
|
|
80
|
+
): string[] {
|
|
81
|
+
const warnings: string[] = [];
|
|
82
|
+
const { systemOneEscalation: escalation, systemOneDenialReview: denial } =
|
|
83
|
+
source;
|
|
84
|
+
if (escalation !== undefined && escalation !== config.systemOneEscalation) {
|
|
85
|
+
warnings.push(
|
|
86
|
+
`systemOneEscalation ${preview(escalation)} is not "standard" or "reasoning-first"; using "standard"`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (denial !== undefined && denial !== config.systemOneDenialReview) {
|
|
90
|
+
warnings.push(
|
|
91
|
+
`systemOneDenialReview ${preview(denial)} is not a boolean; using false`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return warnings;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** configWarnings goes last, after configDegraded: resolveConfig's key order is part of its output. */
|
|
98
|
+
export function withSystemOneRoutingWarnings(
|
|
99
|
+
config: ReviewerConfig,
|
|
100
|
+
source: Record<string, unknown>,
|
|
101
|
+
): ReviewerConfig {
|
|
102
|
+
const warnings = [
|
|
103
|
+
...invalidValueWarnings(config, source),
|
|
104
|
+
...systemOneRoutingWarnings(config),
|
|
105
|
+
...budgetFloorWarnings(config),
|
|
106
|
+
];
|
|
107
|
+
return warnings.length === 0
|
|
108
|
+
? config
|
|
109
|
+
: { ...config, configWarnings: warnings };
|
|
110
|
+
}
|
package/dist/tui/tui.tsx
CHANGED
|
@@ -9,12 +9,12 @@ import { reviewBudgetMs } from "./config.ts";
|
|
|
9
9
|
// would evaluate the whole server engine (git/ssh evidence, `node:child_process`)
|
|
10
10
|
// inside the TUI process.
|
|
11
11
|
import { extractPermissionRequest } from "./opencode/event-normalizer.ts";
|
|
12
|
-
import { SPINNER } from "./ui/components.tsx";
|
|
12
|
+
import { ConfigNoticeSlot, SPINNER } from "./ui/components.tsx";
|
|
13
13
|
import { ReviewOverlay } from "./ui/review-overlay.tsx";
|
|
14
14
|
import { ReviewResult } from "./ui/review-result.tsx";
|
|
15
|
-
import { activeStatus,
|
|
15
|
+
import { activeStatus, createV1Host } from "./ui/v1-host.ts";
|
|
16
16
|
import { setupTuiV2 } from "./ui/v2.tsx";
|
|
17
|
-
import {
|
|
17
|
+
import type { ReviewUiStatus } from "./ui-protocol.ts";
|
|
18
18
|
import { ReviewUiState } from "./ui-state.ts";
|
|
19
19
|
|
|
20
20
|
const REVIEW_MODE = "permission-reviewer";
|
|
@@ -23,12 +23,17 @@ export const tui: TuiPlugin = async (
|
|
|
23
23
|
api: TuiPluginApi,
|
|
24
24
|
options: PluginOptions | undefined,
|
|
25
25
|
) => {
|
|
26
|
-
|
|
26
|
+
// Load inline options as `unknown`, as the server does, so inline routing keys and an inline `escalationReviewer` are dropped here too.
|
|
27
|
+
// Config warnings reach this TUI through server statuses, not this load.
|
|
28
|
+
const config = loadResolvedConfig(options, undefined, "unknown", {
|
|
29
|
+
printConfigWarnings: false,
|
|
30
|
+
});
|
|
27
31
|
const state = new ReviewUiState({
|
|
28
32
|
model: config.model,
|
|
29
33
|
variant: config.variant,
|
|
30
34
|
timeoutMs: reviewBudgetMs(config),
|
|
31
35
|
});
|
|
36
|
+
const host = createV1Host(api, state, config.escalationReviewer?.model);
|
|
32
37
|
|
|
33
38
|
// Signal bumps whenever the UI state changes. Both slot factories read it
|
|
34
39
|
// directly in their bodies, which makes the host re-render each panel:
|
|
@@ -70,11 +75,7 @@ export const tui: TuiPlugin = async (
|
|
|
70
75
|
touch();
|
|
71
76
|
});
|
|
72
77
|
api.event.on("tui.command.execute", (event) => {
|
|
73
|
-
|
|
74
|
-
if (!status) return;
|
|
75
|
-
if (!state.apply(status)) return;
|
|
76
|
-
if (status.phase === "manual") notifyManual(api, status);
|
|
77
|
-
touch();
|
|
78
|
+
if (host.apply(event.properties.command)) touch();
|
|
78
79
|
});
|
|
79
80
|
|
|
80
81
|
// Keep watchdog and result expiry running even when the UI is hidden.
|
|
@@ -137,6 +138,15 @@ export const tui: TuiPlugin = async (
|
|
|
137
138
|
</Show>
|
|
138
139
|
);
|
|
139
140
|
},
|
|
141
|
+
sidebar_content(): JSX.Element {
|
|
142
|
+
revision();
|
|
143
|
+
return (
|
|
144
|
+
<ConfigNoticeSlot
|
|
145
|
+
theme={() => api.theme.current}
|
|
146
|
+
line={host.sidebar()}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
},
|
|
140
150
|
},
|
|
141
151
|
});
|
|
142
152
|
};
|
package/dist/tui/types.ts
CHANGED
|
@@ -26,6 +26,8 @@ export type EvidenceSufficiency =
|
|
|
26
26
|
export type EscalationMode = "manual" | "deny";
|
|
27
27
|
/** Effective disposition applied to an internal escalate result. */
|
|
28
28
|
export type EscalationDisposition = "manual" | "deny";
|
|
29
|
+
/** Where an escalation that starts at Jev goes; `reasoning-first` sends every one to the escalation reviewer. */
|
|
30
|
+
export type SystemOneEscalationMode = "standard" | "reasoning-first";
|
|
29
31
|
|
|
30
32
|
export interface ReviewDecision {
|
|
31
33
|
/** Structured-decision schema version. Always 2 for the current schema. */
|
|
@@ -165,6 +167,10 @@ export interface ReviewerConfig {
|
|
|
165
167
|
/** Minimum combined non-escalate probability for routing an explicit
|
|
166
168
|
* System One escalation to the optional reasoning reviewer. */
|
|
167
169
|
systemOneReasoningThreshold: number;
|
|
170
|
+
/** Read through resolveSystemOneRouting, which applies the Jev and escalationReviewer conditions. */
|
|
171
|
+
systemOneEscalation: SystemOneEscalationMode;
|
|
172
|
+
/** Send uncertain Jev denials to the escalation reviewer. Read through resolveSystemOneRouting. */
|
|
173
|
+
systemOneDenialReview: boolean;
|
|
168
174
|
timeoutMs: number;
|
|
169
175
|
/** Total review budget, including context, queueing, and retries. */
|
|
170
176
|
reviewBudgetMs?: number;
|
|
@@ -213,6 +219,9 @@ export interface ReviewerConfig {
|
|
|
213
219
|
* or rules dropped by validation). Degraded configs block automatic
|
|
214
220
|
* approval: restrictions may have been lost, so requests escalate instead. */
|
|
215
221
|
configDegraded?: string[];
|
|
222
|
+
/** Non-empty when a setting was invalid and fell back to its default, or is
|
|
223
|
+
* on but inert. Informational only: never affects a decision. */
|
|
224
|
+
configWarnings?: string[];
|
|
216
225
|
}
|
|
217
226
|
|
|
218
227
|
export interface ReviewEnvelope {
|
|
@@ -267,6 +276,30 @@ export interface ApprovedAnnotation {
|
|
|
267
276
|
decision: ReviewDecision;
|
|
268
277
|
}
|
|
269
278
|
|
|
279
|
+
/** Why a System One (Jev) result was handed to the reasoning reviewer. */
|
|
280
|
+
export type HandoffTrigger =
|
|
281
|
+
| "jev-escalate"
|
|
282
|
+
| "jev-uncertain-allow"
|
|
283
|
+
| "jev-gate"
|
|
284
|
+
| "jev-invalid"
|
|
285
|
+
| "jev-failure"
|
|
286
|
+
| "jev-uncertain-deny";
|
|
287
|
+
|
|
288
|
+
/** The primary model, routing reason and hand-off trigger of a review a
|
|
289
|
+
* second reviewer decided. */
|
|
290
|
+
export interface EscalatedFrom {
|
|
291
|
+
model: string;
|
|
292
|
+
reason: string;
|
|
293
|
+
trigger?: HandoffTrigger;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** How an escalation that left the System One backend was reached. */
|
|
297
|
+
export type ManualResolution =
|
|
298
|
+
| "reviewer"
|
|
299
|
+
| "reasoning-escalated"
|
|
300
|
+
| "reasoning-unavailable"
|
|
301
|
+
| "budget-exhausted";
|
|
302
|
+
|
|
270
303
|
export interface ReviewExecutionResult {
|
|
271
304
|
kind: "allow" | "deny" | "escalate";
|
|
272
305
|
decision?: ReviewDecision;
|
|
@@ -276,8 +309,9 @@ export interface ReviewExecutionResult {
|
|
|
276
309
|
decisionSource?: DecisionSource;
|
|
277
310
|
/** Actual model that produced the final reviewer decision. */
|
|
278
311
|
reviewerModel?: string;
|
|
279
|
-
/** Primary model
|
|
280
|
-
|
|
312
|
+
/** Primary model, routing reason and hand-off trigger when a second
|
|
313
|
+
* reviewer was used. */
|
|
314
|
+
reviewerEscalatedFrom?: EscalatedFrom;
|
|
281
315
|
/** Jev's scores whenever it returned a parsed decision. */
|
|
282
316
|
systemOne?: SystemOneScores;
|
|
283
317
|
/**
|
|
@@ -291,6 +325,9 @@ export interface ReviewExecutionResult {
|
|
|
291
325
|
* the request was already answered manually (`manual-superseded`).
|
|
292
326
|
*/
|
|
293
327
|
escalationDisposition?: EscalationDisposition;
|
|
328
|
+
/** Set only by the System One backend, on escalations; kept when a
|
|
329
|
+
* disposition turns one into a deny. */
|
|
330
|
+
resolution?: ManualResolution;
|
|
294
331
|
}
|
|
295
332
|
|
|
296
333
|
/** Generic policy templates, NOT automatic trust levels. */
|