@osovv/vv-opencode 2.1.6 → 2.2.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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.2.0 (2026-10-04)
2
+
3
+ ### Summary
4
+
5
+ Guardian now supports a provider-neutral System One decision backend alongside its existing default, letting teams route bounded low-risk permission assessments through a configurable endpoint that speaks the POST /v1/systemone protocol. A new optional systemone connection section and plugin toggle let you select any compliant base URL and model without vendor lock-in, while a guardian decisionBackend option lets you choose between the fast backend and systemone. A shadow-calibration mode lets you log and compare systemone verdicts before trusting them, an explicit low-risk threshold keeps auto-approval conservative, and apiKey values can be resolved from environment placeholders so secrets stay out of persisted config. The fast backend remains the default, no hosted endpoint is assumed, and any disabled, unreachable, timed-out, or malformed response falls closed to manual approval, so existing behavior is preserved unless you opt in.
6
+
7
+ * feat(guardian): add provider-neutral System One decision backend ([e8f3962](https://github.com/osovv/vv-opencode/commit/e8f3962))
8
+
1
9
  ## <small>2.1.6 (2026-10-04)</small>
2
10
 
3
11
  ### Summary
package/README.md CHANGED
@@ -173,7 +173,7 @@ Eleven server plugins run inside the OpenCode server process; the twelfth entry,
173
173
  |---|---|
174
174
  | **WorkflowPlugin** | A state machine over multi-agent work: explicit work items, required reviewers, bounded implementation/review rounds, and hard stops when more context is needed. |
175
175
  | **ModelRolesPlugin** | Semantic model roles (`vv-role:smart`, `vv-role:fast`, …) instead of hardcoded model IDs in agents, subagents, and commands — resolved from the effective vvoc role map plus the native `modelIntent` envelope each time a session family binds its snapshot. |
176
- | **GuardianPlugin** | Keeps long or AFK runs moving by auto-approving routine low-risk permission requests; anything risky stays in OpenCode's normal manual approval flow. |
176
+ | **GuardianPlugin** | Keeps long or AFK runs moving by auto-approving routine low-risk permission requests; anything risky stays in OpenCode's normal manual approval flow. The assessment uses the captured `fast` auxiliary model by default, or an opt-in provider-neutral System One decision provider. |
177
177
  | **HashlineEditPlugin** | Routes each model to exactly one native edit tool (host `edit` for GLM/Qwen/Kimi, host `apply_patch` for GPT, `str_replace_editor` for DeepSeek, `hashline_edit` for unmatched models) and hides the other edit tools per session. |
178
178
  | **SystemContextInjectionPlugin** | Injects universal guidance — including correctness obligations and evidence discipline for behavior changes — plus the work policy selected by the orchestration profile into vv-controller at startup; subagents stay unpolluted. Skill discovery is registered by `vvoc install`/`sync` through the native `skills` config, not by a plugin. |
179
179
  | **SecretsRedactionPlugin** | Redacts tokens, keys, emails, and other sensitive values before messages reach the model, restoring them only where local execution needs the originals. |
@@ -734,6 +734,34 @@ vvoc plugin disable web-tools
734
734
 
735
735
  Unrelated MCP search or reader tools are not removed automatically; disable those separately if you want only the two canonical tools visible.
736
736
 
737
+ ### System One decision backend
738
+
739
+ Guardian can derive its bounded low-risk assessment either from the captured `fast` auxiliary model (the default) or from a provider-neutral System One decision provider that speaks the de-facto `POST /v1/systemone` protocol (`noul`, `choice`, and `score` questions returning typed probabilities instead of generated text). The client is vendor-neutral: any compliant endpoint — a hosted provider, a gateway, or a local server — is selected by `baseUrl` and `model` alone, and no hosted endpoint is assumed.
740
+
741
+ ```json
742
+ "systemone": {
743
+ "enabled": true,
744
+ "baseUrl": "http://localhost:8790",
745
+ "model": "example",
746
+ "apiKey": "${SYSTEMONE_API_KEY}",
747
+ "timeoutMs": 5000,
748
+ "maxRetries": 1
749
+ },
750
+ "guardian": {
751
+ "decisionBackend": "systemone",
752
+ "systemone": { "shadow": true, "lowRiskThreshold": 0.95 }
753
+ }
754
+ ```
755
+
756
+ - `decisionBackend` is `"fast"` (default) or `"systemone"`; the default keeps today's behavior unchanged.
757
+ - With `"systemone"`, Guardian asks one `noul` ("the action is low-risk") and one `score` (risk rubric) over the same bounded review input and reuses the existing `risk_level === "low" && risk_score < approvalRiskThreshold` rule. `lowRiskThreshold` is the noul probability gate.
758
+ - `systemone.shadow` keeps the `fast` backend authoritative while evaluating and logging the System One decision, so thresholds can be calibrated against real decisions before opting in.
759
+ - Fail-closed: an unavailable, unreachable, timed-out, or malformed provider defers to manual approval and never auto-approves from a provider answer. A disabled section, a disabled `systemone` plugin toggle, or an unresolved `${VAR}` key keeps the `fast` backend.
760
+ - The `systemone` plugin toggle is a kill switch: `vvoc plugin disable systemone` constructs no provider and forces the fast backend.
761
+ - `apiKey` may be a literal or a `${VAR}` placeholder resolved from the OpenCode process environment at startup, like web provider credentials. The resolved value is never logged or written to persisted config snapshots.
762
+
763
+ Switching between a hosted endpoint and a local endpoint is a `baseUrl` and `model` change only, with no code change. OpenAI Decisions API and other vendor products that do not speak `/v1/systemone` are out of scope.
764
+
737
765
  ### `/context` inspector
738
766
 
739
767
  Run `/context` inside an active session. Its bounded host-owned dialog has three tabs: **Overview**, **Tools**, and **MCP**. Use left/right arrows or `1`, `2`, and `3` to switch tabs and up/down to scroll long detail; the measured header remains visible on every tab. Top-line used/remaining values come from the latest assistant turn's provider-reported input, cache-read, and output token counts when OpenCode exposes them.
@@ -1,4 +1,4 @@
1
- export declare const PLUGIN_TOGGLE_NAMES: readonly ["guardian", "hashline-edit", "model-roles", "system-context-injection", "workflow", "secrets-redaction", "context", "web-tools", "tool-history-compaction", "analytics", "peak-hours", "spec-guard"];
1
+ export declare const PLUGIN_TOGGLE_NAMES: readonly ["guardian", "hashline-edit", "model-roles", "system-context-injection", "workflow", "secrets-redaction", "context", "web-tools", "tool-history-compaction", "analytics", "peak-hours", "spec-guard", "systemone"];
2
2
  export type VvocPluginEntryConfig = {
3
3
  enabled?: boolean;
4
4
  routing?: Record<string, unknown>;
@@ -30,7 +30,7 @@
30
30
  // END_MODULE_MAP
31
31
  //
32
32
  // START_CHANGE_SUMMARY
33
- // LAST_CHANGE: [C-SPEC-IDENTITY-LINT - Added the spec-guard toggle name, warn-mode default entry, and conservative entry materialization.]
33
+ // LAST_CHANGE: [C-SYSTEMONE-DECISION-BACKEND T-003 - Added the systemone provider toggle name.]
34
34
  // END_CHANGE_SUMMARY
35
35
  // START_BLOCK_CONSTANTS
36
36
  export const PLUGIN_TOGGLE_NAMES = [
@@ -46,6 +46,7 @@ export const PLUGIN_TOGGLE_NAMES = [
46
46
  "analytics",
47
47
  "peak-hours",
48
48
  "spec-guard",
49
+ "systemone",
49
50
  ];
50
51
  // Default edit-routing table for the hashline-edit plugin. Materialized into vvoc.json
51
52
  // on sync/init so it is visible and editable; kept as a plain config-shape object
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-toggle-config.js","sourceRoot":"","sources":["../../src/lib/plugin-toggle-config.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,iBAAiB;AACjB,wBAAwB;AACxB,+IAA+I;AAC/I,kTAAkT;AAClT,oBAAoB;AACpB,+FAA+F;AAC/F,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,uEAAuE;AACvE,mGAAmG;AACnG,iHAAiH;AACjH,2FAA2F;AAC3F,yHAAyH;AACzH,4HAA4H;AAC5H,6GAA6G;AAC7G,oGAAoG;AACpG,4GAA4G;AAC5G,8FAA8F;AAC9F,8FAA8F;AAC9F,mIAAmI;AACnI,0JAA0J;AAC1J,qHAAqH;AACrH,4HAA4H;AAC5H,kGAAkG;AAClG,+EAA+E;AAC/E,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,6IAA6I;AAC7I,qBAAqB;AAErB,wBAAwB;AACxB,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,UAAU;IACV,eAAe;IACf,aAAa;IACb,0BAA0B;IAC1B,UAAU;IACV,mBAAmB;IACnB,SAAS;IACT,WAAW;IACX,yBAAyB;IACzB,WAAW;IACX,YAAY;IACZ,YAAY;CACJ,CAAC;AASX,uFAAuF;AACvF,kFAAkF;AAClF,iFAAiF;AACjF,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,OAAO,EAAE,eAAe;IACxB,KAAK,EAAE;QACL,QAAQ,EAAE,oBAAoB;QAC9B,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,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AAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,SAAS,EAAE,CAAC;QACrC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,GAAG,CACT,sEAAsE;gBACpE,UAAU;gBACV,YAAY;gBACZ,WAAW,CACd,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,mFAAmF;IACnF,OAAO,WAAW,CAAC,OAAO,KAAK,KAAK,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AACnD,8BAA8B"}
1
+ {"version":3,"file":"plugin-toggle-config.js","sourceRoot":"","sources":["../../src/lib/plugin-toggle-config.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,iBAAiB;AACjB,wBAAwB;AACxB,+IAA+I;AAC/I,kTAAkT;AAClT,oBAAoB;AACpB,+FAA+F;AAC/F,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,uEAAuE;AACvE,mGAAmG;AACnG,iHAAiH;AACjH,2FAA2F;AAC3F,yHAAyH;AACzH,4HAA4H;AAC5H,6GAA6G;AAC7G,oGAAoG;AACpG,4GAA4G;AAC5G,8FAA8F;AAC9F,8FAA8F;AAC9F,mIAAmI;AACnI,0JAA0J;AAC1J,qHAAqH;AACrH,4HAA4H;AAC5H,kGAAkG;AAClG,+EAA+E;AAC/E,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,kGAAkG;AAClG,qBAAqB;AAErB,wBAAwB;AACxB,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,UAAU;IACV,eAAe;IACf,aAAa;IACb,0BAA0B;IAC1B,UAAU;IACV,mBAAmB;IACnB,SAAS;IACT,WAAW;IACX,yBAAyB;IACzB,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,WAAW;CACH,CAAC;AAS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,EAC5C,UAAkB;IAElB,2BAA2B;IAC3B,gCAAgC;IAEhC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC;IACjD,2DAA2D;IAC3D,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,SAAS,EAAE,CAAC;QACrC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,GAAG,CACT,sEAAsE;gBACpE,UAAU;gBACV,YAAY;gBACZ,WAAW,CACd,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,mFAAmF;IACnF,OAAO,WAAW,CAAC,OAAO,KAAK,KAAK,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AACnD,8BAA8B"}
@@ -0,0 +1,84 @@
1
+ export declare const SYSTEMONE_PATH = "/v1/systemone";
2
+ export declare const MAX_CHOICE_OPTIONS = 255;
3
+ /** JSON value accepted as state, criteria, or instructions. */
4
+ export type SystemOneJson = string | number | boolean | null | SystemOneJson[] | {
5
+ [key: string]: SystemOneJson;
6
+ };
7
+ export type SystemOneNoulQuestion = {
8
+ type: "noul";
9
+ instructions: SystemOneJson;
10
+ criteria?: {
11
+ true?: SystemOneJson;
12
+ false?: SystemOneJson;
13
+ };
14
+ };
15
+ export type SystemOneChoiceQuestion = {
16
+ type: "choice";
17
+ instructions: SystemOneJson;
18
+ criteria: Record<string, SystemOneJson>;
19
+ };
20
+ export type SystemOneScoreQuestion = {
21
+ type: "score";
22
+ instructions: SystemOneJson;
23
+ criteria: SystemOneJson[];
24
+ };
25
+ export type SystemOneQuestion = SystemOneNoulQuestion | SystemOneChoiceQuestion | SystemOneScoreQuestion;
26
+ export type SystemOneNoulAnswer = {
27
+ type: "noul";
28
+ noul: number;
29
+ confidence?: number;
30
+ };
31
+ export type SystemOneChoiceAnswer = {
32
+ type: "choice";
33
+ choice: string;
34
+ probabilities: Record<string, number>;
35
+ confidence?: number;
36
+ };
37
+ export type SystemOneScoreAnswer = {
38
+ type: "score";
39
+ score: number;
40
+ probabilities: Record<string, number>;
41
+ legend?: Record<string, string>;
42
+ confidence?: number;
43
+ };
44
+ export type SystemOneAnswer = SystemOneNoulAnswer | SystemOneChoiceAnswer | SystemOneScoreAnswer;
45
+ /** Resolved connection settings for one System One provider. */
46
+ export type SystemOneConnection = {
47
+ baseUrl: string;
48
+ model: string;
49
+ apiKey?: string;
50
+ timeoutMs: number;
51
+ maxRetries: number;
52
+ };
53
+ export type SystemOneHttpRequest = {
54
+ url: string;
55
+ method: "POST";
56
+ headers: Record<string, string>;
57
+ body: string;
58
+ timeoutMs: number;
59
+ };
60
+ export type SystemOneHttpResponse = {
61
+ status: number;
62
+ body: string;
63
+ };
64
+ export type SystemOneTransport = (request: SystemOneHttpRequest) => Promise<SystemOneHttpResponse>;
65
+ export type SystemOneErrorCode = "INVALID_REQUEST" | "INVALID_RESPONSE" | "UNAUTHORIZED" | "RATE_LIMITED" | "TIMEOUT" | "REQUEST_FAILED";
66
+ /** Typed, credential-safe client error. Never carries the API key, state, or raw body. */
67
+ export declare class SystemOneError extends Error {
68
+ readonly code: SystemOneErrorCode;
69
+ readonly status?: number;
70
+ constructor(code: SystemOneErrorCode, message: string, status?: number);
71
+ }
72
+ /** Fetch-based transport with an abort timeout. Errors are normalized by the caller. */
73
+ export declare const defaultSystemOneTransport: SystemOneTransport;
74
+ export type SystemOneEvaluateInput = {
75
+ state: SystemOneJson;
76
+ questions: Record<string, SystemOneQuestion>;
77
+ connection: SystemOneConnection;
78
+ transport?: SystemOneTransport;
79
+ };
80
+ export type SystemOneEvaluation = {
81
+ model: string;
82
+ answers: Record<string, SystemOneAnswer>;
83
+ };
84
+ export declare function evaluateSystemOne(input: SystemOneEvaluateInput): Promise<SystemOneEvaluation>;
@@ -0,0 +1,266 @@
1
+ // FILE: src/lib/systemone.ts
2
+ // VERSION: 1.0.0
3
+ // START_MODULE_CONTRACT
4
+ // PURPOSE: Provide a provider-neutral client for the de-facto System One decision protocol (POST /v1/systemone) returning typed noul, choice, and score answers over an injectable transport.
5
+ // SCOPE: Request shaping (state, model, typed questions), typed answer decoding with unknown-field tolerance, a bounded timeout and retry policy, and credential-safe typed errors; no vendor-specific behavior, no default endpoint, no text generation.
6
+ // DEPENDS: [none]
7
+ // LINKS: [M-SYSTEMONE-PROVIDER, M-PLUGIN-GUARDIAN, M-ENV-SUBSTITUTION]
8
+ // ROLE: RUNTIME
9
+ // MAP_MODE: EXPORTS
10
+ // END_MODULE_CONTRACT
11
+ //
12
+ // START_MODULE_MAP
13
+ // SYSTEMONE_PATH - Canonical System One evaluate path appended to a configured base URL.
14
+ // MAX_CHOICE_OPTIONS - Protocol option ceiling for a choice question.
15
+ // SystemOneJson - JSON value accepted as state, criteria, or instructions.
16
+ // SystemOneNoulQuestion - Yes/no question shape.
17
+ // SystemOneChoiceQuestion - Single-choice question shape.
18
+ // SystemOneScoreQuestion - Ordered-rubric question shape.
19
+ // SystemOneQuestion - Union of the three supported question shapes.
20
+ // SystemOneNoulAnswer - Decoded noul answer.
21
+ // SystemOneChoiceAnswer - Decoded choice answer.
22
+ // SystemOneScoreAnswer - Decoded score answer.
23
+ // SystemOneAnswer - Union of decoded answer shapes.
24
+ // SystemOneConnection - Resolved connection settings for one provider.
25
+ // SystemOneHttpRequest - Transport request shape.
26
+ // SystemOneHttpResponse - Transport response shape.
27
+ // SystemOneTransport - Injectable HTTP transport.
28
+ // defaultSystemOneTransport - Fetch-based transport with an abort timeout.
29
+ // SystemOneErrorCode - Stable client error codes.
30
+ // SystemOneError - Typed, credential-safe client error.
31
+ // SystemOneEvaluateInput - Input to evaluateSystemOne.
32
+ // SystemOneEvaluation - Decoded evaluation result.
33
+ // evaluateSystemOne - Shape, send, retry, and decode one System One evaluate call.
34
+ // END_MODULE_MAP
35
+ //
36
+ // START_CHANGE_SUMMARY
37
+ // LAST_CHANGE: [C-SYSTEMONE-DECISION-BACKEND T-001 - Added the provider-neutral /v1/systemone client with typed noul/choice/score decoding, bounded timeout and retry, unknown-field tolerance, and credential-safe errors.]
38
+ // END_CHANGE_SUMMARY
39
+ export const SYSTEMONE_PATH = "/v1/systemone";
40
+ export const MAX_CHOICE_OPTIONS = 255;
41
+ /** Typed, credential-safe client error. Never carries the API key, state, or raw body. */
42
+ export class SystemOneError extends Error {
43
+ code;
44
+ status;
45
+ constructor(code, message, status) {
46
+ super(message);
47
+ this.name = "SystemOneError";
48
+ this.code = code;
49
+ if (status !== undefined) {
50
+ this.status = status;
51
+ }
52
+ }
53
+ }
54
+ // START_BLOCK_TRANSPORT
55
+ /** Fetch-based transport with an abort timeout. Errors are normalized by the caller. */
56
+ export const defaultSystemOneTransport = async (request) => {
57
+ const controller = new AbortController();
58
+ const timer = setTimeout(() => controller.abort(), request.timeoutMs);
59
+ try {
60
+ const response = await fetch(request.url, {
61
+ method: request.method,
62
+ headers: request.headers,
63
+ body: request.body,
64
+ signal: controller.signal,
65
+ });
66
+ const body = await response.text();
67
+ return { status: response.status, body };
68
+ }
69
+ finally {
70
+ clearTimeout(timer);
71
+ }
72
+ };
73
+ // END_BLOCK_TRANSPORT
74
+ // START_BLOCK_SHAPING
75
+ function joinUrl(baseUrl) {
76
+ return `${baseUrl.replace(/\/+$/, "")}${SYSTEMONE_PATH}`;
77
+ }
78
+ function isPlainRecord(value) {
79
+ return typeof value === "object" && value !== null && !Array.isArray(value);
80
+ }
81
+ function isFiniteUnit(value) {
82
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
83
+ }
84
+ function validateQuestion(id, question) {
85
+ if (question.type === "choice") {
86
+ const count = Object.keys(question.criteria ?? {}).length;
87
+ if (count < 1 || count > MAX_CHOICE_OPTIONS) {
88
+ throw new SystemOneError("INVALID_REQUEST", `question ${id}: choice criteria must contain between 1 and ${MAX_CHOICE_OPTIONS} options`);
89
+ }
90
+ }
91
+ if (question.type === "score") {
92
+ const count = question.criteria?.length ?? 0;
93
+ if (count < 2) {
94
+ throw new SystemOneError("INVALID_REQUEST", `question ${id}: score criteria must contain at least 2 levels`);
95
+ }
96
+ }
97
+ }
98
+ // END_BLOCK_SHAPING
99
+ // START_BLOCK_DECODING
100
+ function decodeNoul(id, value) {
101
+ if (!isFiniteUnit(value.noul)) {
102
+ throw new SystemOneError("INVALID_RESPONSE", `answer ${id}: noul must be a probability`);
103
+ }
104
+ return {
105
+ type: "noul",
106
+ noul: value.noul,
107
+ ...(isFiniteUnit(value.confidence) ? { confidence: value.confidence } : {}),
108
+ };
109
+ }
110
+ function decodeProbabilities(id, value) {
111
+ if (!isPlainRecord(value)) {
112
+ throw new SystemOneError("INVALID_RESPONSE", `answer ${id}: probabilities must be an object`);
113
+ }
114
+ const decoded = {};
115
+ for (const [key, probability] of Object.entries(value)) {
116
+ if (!isFiniteUnit(probability)) {
117
+ throw new SystemOneError("INVALID_RESPONSE", `answer ${id}: probability ${key} must be between 0 and 1`);
118
+ }
119
+ decoded[key] = probability;
120
+ }
121
+ return decoded;
122
+ }
123
+ function decodeChoice(id, value) {
124
+ const probabilities = decodeProbabilities(id, value.probabilities);
125
+ if (typeof value.choice !== "string" || !Object.hasOwn(probabilities, value.choice)) {
126
+ throw new SystemOneError("INVALID_RESPONSE", `answer ${id}: choice must match a probability key`);
127
+ }
128
+ return {
129
+ type: "choice",
130
+ choice: value.choice,
131
+ probabilities,
132
+ ...(isFiniteUnit(value.confidence) ? { confidence: value.confidence } : {}),
133
+ };
134
+ }
135
+ function decodeScore(id, value) {
136
+ const probabilities = decodeProbabilities(id, value.probabilities);
137
+ if (typeof value.score !== "number" || !Number.isFinite(value.score) || value.score < 0) {
138
+ throw new SystemOneError("INVALID_RESPONSE", `answer ${id}: score must be a finite number`);
139
+ }
140
+ const legend = isPlainRecord(value.legend)
141
+ ? Object.fromEntries(Object.entries(value.legend).filter((entry) => {
142
+ return typeof entry[1] === "string";
143
+ }))
144
+ : undefined;
145
+ return {
146
+ type: "score",
147
+ score: value.score,
148
+ probabilities,
149
+ ...(legend ? { legend } : {}),
150
+ ...(isFiniteUnit(value.confidence) ? { confidence: value.confidence } : {}),
151
+ };
152
+ }
153
+ function decodeAnswer(id, value) {
154
+ if (!isPlainRecord(value)) {
155
+ throw new SystemOneError("INVALID_RESPONSE", `answer ${id}: expected an object`);
156
+ }
157
+ switch (value.type) {
158
+ case "noul":
159
+ return decodeNoul(id, value);
160
+ case "choice":
161
+ return decodeChoice(id, value);
162
+ case "score":
163
+ return decodeScore(id, value);
164
+ default:
165
+ throw new SystemOneError("INVALID_RESPONSE", `answer ${id}: unknown answer type`);
166
+ }
167
+ }
168
+ // END_BLOCK_DECODING
169
+ // START_BLOCK_REQUEST
170
+ function buildRequest(connection, state, questions) {
171
+ const headers = { "content-type": "application/json" };
172
+ if (connection.apiKey !== undefined && connection.apiKey !== "") {
173
+ headers.authorization = `Bearer ${connection.apiKey}`;
174
+ }
175
+ return {
176
+ url: joinUrl(connection.baseUrl),
177
+ method: "POST",
178
+ headers,
179
+ body: JSON.stringify({ state, model: connection.model, questions }),
180
+ timeoutMs: connection.timeoutMs,
181
+ };
182
+ }
183
+ function normalizeConnection(connection) {
184
+ if (!connection.baseUrl.trim() || !connection.model.trim()) {
185
+ throw new SystemOneError("INVALID_REQUEST", "baseUrl and model are required");
186
+ }
187
+ return {
188
+ ...connection,
189
+ baseUrl: connection.baseUrl.trim(),
190
+ model: connection.model.trim(),
191
+ timeoutMs: Math.max(1, Math.floor(connection.timeoutMs)),
192
+ maxRetries: Math.min(5, Math.max(0, Math.floor(connection.maxRetries))),
193
+ };
194
+ }
195
+ function statusError(status, retryable) {
196
+ if (status === 401 || status === 403) {
197
+ return new SystemOneError("UNAUTHORIZED", "System One credential was rejected", status);
198
+ }
199
+ if (status === 429) {
200
+ return new SystemOneError("RATE_LIMITED", "System One rate limit reached", status);
201
+ }
202
+ return new SystemOneError("REQUEST_FAILED", `System One request failed with status ${status}${retryable ? " (retried)" : ""}`, status);
203
+ }
204
+ function isRetryableStatus(status) {
205
+ return status === 429 || status >= 500;
206
+ }
207
+ async function delay(ms) {
208
+ await new Promise((resolve) => setTimeout(resolve, ms));
209
+ }
210
+ export async function evaluateSystemOne(input) {
211
+ const connection = normalizeConnection(input.connection);
212
+ const questionIds = Object.keys(input.questions);
213
+ if (questionIds.length === 0) {
214
+ throw new SystemOneError("INVALID_REQUEST", "at least one question is required");
215
+ }
216
+ for (const [id, question] of Object.entries(input.questions)) {
217
+ validateQuestion(id, question);
218
+ }
219
+ const transport = input.transport ?? defaultSystemOneTransport;
220
+ const request = buildRequest(connection, input.state, input.questions);
221
+ const attempts = connection.maxRetries + 1;
222
+ let lastError;
223
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
224
+ if (attempt > 0) {
225
+ await delay(Math.min(100 * 2 ** (attempt - 1), 1000));
226
+ }
227
+ let response;
228
+ try {
229
+ response = await transport(request);
230
+ }
231
+ catch (error) {
232
+ lastError = new SystemOneError(error instanceof Error && error.name === "AbortError" ? "TIMEOUT" : "REQUEST_FAILED", "System One request did not complete");
233
+ continue;
234
+ }
235
+ if (response.status < 200 || response.status >= 300) {
236
+ const error = statusError(response.status, attempt + 1 < attempts);
237
+ if (!isRetryableStatus(response.status)) {
238
+ throw error;
239
+ }
240
+ lastError = error;
241
+ continue;
242
+ }
243
+ return decodeEvaluation(response.body);
244
+ }
245
+ throw lastError ?? new SystemOneError("REQUEST_FAILED", "System One request failed");
246
+ }
247
+ // END_BLOCK_EVALUATE
248
+ function decodeEvaluation(body) {
249
+ let parsed;
250
+ try {
251
+ parsed = JSON.parse(body);
252
+ }
253
+ catch {
254
+ throw new SystemOneError("INVALID_RESPONSE", "System One response was not valid JSON");
255
+ }
256
+ if (!isPlainRecord(parsed) || !isPlainRecord(parsed.answers)) {
257
+ throw new SystemOneError("INVALID_RESPONSE", "System One response is missing answers");
258
+ }
259
+ const answers = {};
260
+ for (const [id, answer] of Object.entries(parsed.answers)) {
261
+ answers[id] = decodeAnswer(id, answer);
262
+ }
263
+ const model = typeof parsed.model === "string" && parsed.model !== "" ? parsed.model : "";
264
+ return { model, answers };
265
+ }
266
+ //# sourceMappingURL=systemone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"systemone.js","sourceRoot":"","sources":["../../src/lib/systemone.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,iBAAiB;AACjB,wBAAwB;AACxB,gMAAgM;AAChM,4PAA4P;AAC5P,oBAAoB;AACpB,yEAAyE;AACzE,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,2FAA2F;AAC3F,wEAAwE;AACxE,6EAA6E;AAC7E,mDAAmD;AACnD,4DAA4D;AAC5D,4DAA4D;AAC5D,sEAAsE;AACtE,+CAA+C;AAC/C,mDAAmD;AACnD,iDAAiD;AACjD,sDAAsD;AACtD,yEAAyE;AACzE,oDAAoD;AACpD,sDAAsD;AACtD,oDAAoD;AACpD,6EAA6E;AAC7E,oDAAoD;AACpD,0DAA0D;AAC1D,yDAAyD;AACzD,qDAAqD;AACrD,qFAAqF;AACrF,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,+NAA+N;AAC/N,qBAAqB;AAErB,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAyFtC,0FAA0F;AAC1F,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAqB;IACzB,MAAM,CAAU;IAEzB,YAAY,IAAwB,EAAE,OAAe,EAAE,MAAe;QACpE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,MAAM,KAAK,SAAS,EAAE,C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MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1F,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC"}
@@ -16,8 +16,26 @@ export type GuardianConfig = {
16
16
  timeoutMs: number;
17
17
  approvalRiskThreshold: number;
18
18
  reviewToastDurationMs: number;
19
+ decisionBackend?: GuardianDecisionBackend;
20
+ systemone?: GuardianSystemOneConfig;
19
21
  };
20
22
  export type GuardianConfigOverrides = Partial<GuardianConfig>;
23
+ /** Selected Guardian assessment backend. Fast is the default; systemone is explicit opt-in. */
24
+ export type GuardianDecisionBackend = "fast" | "systemone";
25
+ /** Guardian-specific System One policy: observational shadow mode and the low-risk probability gate. */
26
+ export type GuardianSystemOneConfig = {
27
+ shadow: boolean;
28
+ lowRiskThreshold: number;
29
+ };
30
+ /** Resolved connection settings for the optional provider-neutral System One section. */
31
+ export type SystemOneConfig = {
32
+ enabled: boolean;
33
+ baseUrl: string;
34
+ model: string;
35
+ apiKey?: string;
36
+ timeoutMs: number;
37
+ maxRetries: number;
38
+ };
21
39
  export type SecretsRedactionKeywordRule = {
22
40
  value: string;
23
41
  category?: string;
@@ -71,6 +89,7 @@ export type VvocConfig = {
71
89
  presets: VvocPresets;
72
90
  plugins: VvocPluginToggleConfig;
73
91
  web?: VvocWebConfig;
92
+ systemone?: SystemOneConfig;
74
93
  };
75
94
  export type ParsedVvocConfig = {
76
95
  sourceSchema: string;
@@ -140,6 +159,25 @@ export declare const VVOC_CONFIG_SCHEMA: {
140
159
  type: string;
141
160
  minimum: number;
142
161
  };
162
+ decisionBackend: {
163
+ type: string;
164
+ enum: string[];
165
+ };
166
+ systemone: {
167
+ type: string;
168
+ additionalProperties: boolean;
169
+ required: string[];
170
+ properties: {
171
+ shadow: {
172
+ type: string;
173
+ };
174
+ lowRiskThreshold: {
175
+ type: string;
176
+ minimum: number;
177
+ maximum: number;
178
+ };
179
+ };
180
+ };
143
181
  };
144
182
  };
145
183
  secretsRedaction: {
@@ -536,13 +574,51 @@ export declare const VVOC_CONFIG_SCHEMA: {
536
574
  };
537
575
  };
538
576
  };
577
+ systemone: {
578
+ type: string;
579
+ description: string;
580
+ additionalProperties: boolean;
581
+ required: string[];
582
+ properties: {
583
+ enabled: {
584
+ type: string;
585
+ };
586
+ baseUrl: {
587
+ type: string;
588
+ minLength: number;
589
+ };
590
+ model: {
591
+ type: string;
592
+ minLength: number;
593
+ };
594
+ apiKey: {
595
+ type: string;
596
+ minLength: number;
597
+ description: string;
598
+ };
599
+ timeoutMs: {
600
+ type: string;
601
+ minimum: number;
602
+ };
603
+ maxRetries: {
604
+ type: string;
605
+ minimum: number;
606
+ maximum: number;
607
+ };
608
+ };
609
+ };
539
610
  };
540
611
  };
541
612
  export declare function createGuardianConfig(overrides?: GuardianConfigOverrides): GuardianConfig;
613
+ export declare function createGuardianSystemOneConfig(overrides?: Partial<GuardianSystemOneConfig>): GuardianSystemOneConfig;
614
+ /** Normalize the optional top-level systemone section, returning undefined when absent. */
615
+ export declare function createSystemOneConfig(value: unknown): SystemOneConfig | undefined;
542
616
  export declare function createDefaultSecretsRedactionConfig(): SecretsRedactionConfig;
543
617
  export declare function createDefaultVvocPresets(): VvocPresets;
544
618
  export declare function createDefaultVvocConfig(): VvocConfig;
545
619
  export declare function parseGuardianConfigText(text: string, label: string): GuardianConfigOverrides;
620
+ export declare function parseSystemOneConfigText(text: string, label: string): SystemOneConfig;
621
+ export declare function renderSystemOneConfig(overrides?: Partial<SystemOneConfig>): string;
546
622
  export declare function renderGuardianConfig(overrides?: GuardianConfigOverrides): string;
547
623
  export declare function parseVersionedVvocConfigText(text: string, label: string): ParsedVvocConfig;
548
624
  export declare function parseVvocConfigText(text: string, label: string): VvocConfig;