@bitkyc08/opencodex 2.100.0 → 2.100.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gui/dist/assets/App-BpJOzw4F.js +59 -0
- package/gui/dist/assets/Tray-BcaI-VCr.js +1 -0
- package/gui/dist/assets/brand-mark-DU-0Vdkr.js +1 -0
- package/gui/dist/assets/index-Bbor_y80.js +94 -0
- package/gui/dist/assets/index-DJEkIDAi.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-CcxZBnxv.js → segment-thumb-features-e9A_FogJ.js} +1 -1
- package/gui/dist/classic/assets/{App-aYgIQMxI.js → App-BrIlUiLc.js} +18 -18
- package/gui/dist/classic/assets/{Tray-D8jfUXpQ.js → Tray-DT146AhS.js} +1 -1
- package/gui/dist/classic/assets/index-DyJHagvT.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CakPe9Ni.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +2 -2
- package/src/adapters/anthropic-image-normalize.ts +1 -1
- package/src/adapters/client-fingerprint.ts +6 -4
- package/src/adapters/cursor/native-exec.ts +3 -2
- package/src/adapters/cursor/tool-guidance.ts +3 -3
- package/src/adapters/cursor/tool-wording.ts +10 -1
- package/src/adapters/devin/cloud-direct/tool-schema.ts +20 -2
- package/src/adapters/google-antigravity-wire.ts +13 -6
- package/src/adapters/google-truncation.ts +4 -2
- package/src/adapters/google.ts +8 -2
- package/src/adapters/openai-chat/mistral-image-limit.ts +28 -15
- package/src/adapters/openai-chat/tool-schema.ts +9 -0
- package/src/adapters/openai-chat-images.ts +100 -0
- package/src/adapters/openai-chat.ts +6 -9
- package/src/adapters/openai-responses/tool-schema.ts +18 -4
- package/src/adapters/run-turn-queue.ts +139 -5
- package/src/adapters/upstream-http-error.ts +4 -2
- package/src/bridge/sse.ts +8 -1
- package/src/claude/chat-tool-dispatch.ts +233 -0
- package/src/claude/inbound-tool-loading.ts +42 -17
- package/src/cli/account-api.ts +6 -0
- package/src/cli/account-extended.ts +60 -6
- package/src/cli/account-key-quota.ts +22 -2
- package/src/cli/account.ts +1 -1
- package/src/cli/capabilities-access-remote.ts +10 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +2 -2
- package/src/cli/claude.ts +19 -14
- package/src/cli/config-command.ts +24 -1
- package/src/cli/connect.ts +36 -3
- package/src/cli/gui-pair-client.ts +23 -2
- package/src/cli/help.ts +1 -1
- package/src/cli/hub.ts +18 -1
- package/src/cli/link-child-ops.ts +136 -0
- package/src/cli/link-status-child.ts +94 -0
- package/src/cli/link.ts +22 -9
- package/src/cli/registry.ts +3 -2
- package/src/cli/sync-command.ts +3 -1
- package/src/cli/sync-fanout.ts +8 -81
- package/src/client/link-readiness.ts +16 -6
- package/src/client/link-tunnel-status.ts +76 -0
- package/src/clients/config-export.ts +14 -1
- package/src/codex/account-resume-health.ts +41 -0
- package/src/codex/auth-api/login-flow.ts +6 -0
- package/src/codex/auth-api/routes.ts +35 -2
- package/src/codex/catalog/gather-capture.ts +2 -0
- package/src/codex/catalog/provider-models.ts +13 -8
- package/src/codex/convergence-types.ts +2 -0
- package/src/codex/quota.ts +111 -6
- package/src/combos/cooldown-store.ts +208 -0
- package/src/combos/failover.ts +432 -35
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +6 -3
- package/src/config/schema/leaf-validators.ts +34 -12
- package/src/generated/compatibility-version.json +227 -135
- package/src/lib/catalog-etag.ts +10 -0
- package/src/lib/client-error-body.ts +15 -0
- package/src/lib/config-ownership.ts +9 -2
- package/src/lib/context-overflow-verdict.ts +266 -9
- package/src/lib/failure-detail.ts +72 -3
- package/src/lib/hard-refusal.ts +259 -0
- package/src/link/child-activity.ts +57 -0
- package/src/link/child-catalog-freshness.ts +149 -0
- package/src/link/child-gated-ocx.ts +117 -0
- package/src/link/child-observations.ts +205 -0
- package/src/link/child-observe.ts +121 -0
- package/src/link/child-ops-engine.ts +162 -0
- package/src/link/child-update-contract.ts +165 -0
- package/src/link/paths.ts +5 -0
- package/src/link/remote-windows.ts +42 -6
- package/src/link/ssh-argv.ts +126 -32
- package/src/link/status-projection.ts +73 -0
- package/src/link/sync-fanout-classify.ts +98 -0
- package/src/link/tunnel-state.ts +10 -4
- package/src/messaging/mcp-queue-rpc.ts +2 -1
- package/src/messaging/mcp-queue-server.ts +5 -0
- package/src/messaging/mcp-reply-tools.ts +24 -9
- package/src/messaging/mcp-reply-wait.ts +70 -0
- package/src/oauth/account-resume-health.ts +60 -0
- package/src/oauth/anthropic-model-quota.ts +12 -0
- package/src/oauth/anthropic-routing.ts +11 -4
- package/src/oauth/index.ts +1 -0
- package/src/oauth/kiro-iam-identity-center.ts +4 -1
- package/src/oauth/store.ts +44 -1
- package/src/providers/api-key-pause-state.ts +23 -0
- package/src/providers/api-key-pause.ts +68 -10
- package/src/providers/api-key-selection-capture.ts +3 -1
- package/src/providers/api-key-selection.ts +3 -2
- package/src/providers/api-keys.ts +18 -5
- package/src/providers/claude-cli-identity.ts +9 -3
- package/src/providers/claude-cli-usage-state.ts +11 -6
- package/src/providers/claude-cli-usage.ts +27 -8
- package/src/providers/codex-capacity.ts +11 -2
- package/src/providers/key-failover.ts +13 -6
- package/src/providers/model-discovery-config.ts +31 -0
- package/src/providers/model-discovery-diagnostic.ts +34 -3
- package/src/providers/model-discovery.ts +43 -7
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/openai-sidecar.ts +15 -2
- package/src/providers/provider-id-rewrite.ts +3 -0
- package/src/providers/quota/account-cache.ts +52 -34
- package/src/providers/quota/anthropic-family-headers.ts +8 -1
- package/src/providers/quota/anthropic-usage-windows.ts +66 -9
- package/src/providers/quota/report-cache.ts +53 -5
- package/src/providers/quota/vendor-probes-key.ts +73 -0
- package/src/providers/quota/vendor-probes-oauth.ts +57 -3
- package/src/providers/quota-key-accounts.ts +12 -5
- package/src/providers/quota-mistral-budget.ts +18 -0
- package/src/providers/quota-types.ts +32 -0
- package/src/providers/quota.ts +22 -22
- package/src/providers/reasoning-metadata.ts +1051 -12
- package/src/providers/registry/entries-extended.ts +3 -1
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/types.ts +6 -0
- package/src/quota/reset-observer.ts +4 -2
- package/src/quota/reset-seen-store.ts +9 -0
- package/src/quota/window-mapping.ts +1 -0
- package/src/quota-pool/assemble.ts +4 -1
- package/src/responses/hosted-tool-policy.ts +56 -12
- package/src/responses/retained-compaction.ts +31 -5
- package/src/router.ts +2 -0
- package/src/server/auth-cors.ts +11 -8
- package/src/server/catalog-download.ts +3 -5
- package/src/server/chat-native.ts +11 -2
- package/src/server/claude-messages.ts +2 -1
- package/src/server/images.ts +41 -13
- package/src/server/index/link-listener.ts +16 -2
- package/src/server/index/link-relay-sessions.ts +43 -2
- package/src/server/index/optional-listeners.ts +18 -0
- package/src/server/management/config-routes.ts +7 -1
- package/src/server/management/context.ts +1 -1
- package/src/server/management/link-child-ops-routes.ts +116 -0
- package/src/server/management/link-route-state.ts +10 -0
- package/src/server/management/link-routes.ts +10 -0
- package/src/server/management/oauth-account-routes.ts +33 -4
- package/src/server/management/provider-overwrite-carry.ts +28 -3
- package/src/server/management/provider-routes.ts +16 -11
- package/src/server/management/route-registry.ts +3 -0
- package/src/server/messages-native.ts +5 -0
- package/src/server/request-log-failure-detail.ts +59 -1
- package/src/server/responses/adapter-dispatch.ts +35 -44
- package/src/server/responses/combo-stream-preflight.ts +146 -29
- package/src/server/responses/compact.ts +27 -4
- package/src/server/responses/context-overflow.ts +58 -2
- package/src/server/responses/core-combo-failure.ts +29 -4
- package/src/server/responses/core-combo-native.ts +3 -1
- package/src/server/responses/core-combo.ts +30 -3
- package/src/server/responses/core-errors.ts +3 -1
- package/src/server/responses/core-opaque-recovery.ts +45 -2
- package/src/server/responses/core-options.ts +12 -0
- package/src/server/responses/passthrough-dispatch.ts +30 -38
- package/src/server/responses/request-transport.ts +43 -14
- package/src/server/responses/reset-replay.ts +58 -2
- package/src/server/responses/run-turn-execution.ts +56 -30
- package/src/types/claude-tool-loading.ts +48 -0
- package/src/types/config.ts +5 -35
- package/src/types/provider.ts +21 -0
- package/src/types.ts +1 -0
- package/src/web-search/parse.ts +44 -4
- package/gui/dist/assets/App-CitvEefy.js +0 -59
- package/gui/dist/assets/Tray-CeKVWQyB.js +0 -1
- package/gui/dist/assets/brand-mark-M92UnxX2.js +0 -1
- package/gui/dist/assets/index-BP47do6-.js +0 -94
- package/gui/dist/assets/index-DmDooSAG.css +0 -2
- package/gui/dist/classic/assets/index-CfGqHooN.js +0 -94
- package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +0 -1
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isCyberPolicyCode,
|
|
3
|
+
isCyberPolicyMessage,
|
|
4
|
+
isTerminalRefusalCode,
|
|
5
|
+
safetyRefusalCodeFromMessage,
|
|
6
|
+
} from "./errors";
|
|
7
|
+
import { isNonReplayableUpstreamCode } from "./upstream-retry";
|
|
8
|
+
|
|
9
|
+
const SERIALIZED_HARD_CODE =
|
|
10
|
+
/\bcode\s*[:=]\s*["']?(?:cyber_policy|origin_rejected|bio_policy|misalignment_policy_violation|invalid_prompt|upstream_no_response|upstream_closed_before_response|upstream_reset_replay_refused)\b/i;
|
|
11
|
+
|
|
12
|
+
export interface ExtractedJsonEnvelope {
|
|
13
|
+
value: unknown;
|
|
14
|
+
prefix: string;
|
|
15
|
+
suffix: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const HARD_REFUSAL_TOKEN =
|
|
19
|
+
/\b(?:cyber_policy|origin_rejected|bio_policy|misalignment_policy_violation|invalid_prompt)\b/i;
|
|
20
|
+
|
|
21
|
+
function isAuthoritativeHardRefusalProse(str: string | undefined): boolean {
|
|
22
|
+
if (!str) return false;
|
|
23
|
+
const s = str.trim();
|
|
24
|
+
if (!s) return false;
|
|
25
|
+
if (isCyberPolicyMessage(s)) return true;
|
|
26
|
+
if (/origin_rejected/i.test(s)) return true;
|
|
27
|
+
if (HARD_REFUSAL_TOKEN.test(s)) return true;
|
|
28
|
+
if (SERIALIZED_HARD_CODE.test(s)) return true;
|
|
29
|
+
if (safetyRefusalCodeFromMessage(s)) return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Extract a balanced or prefixed JSON object/array envelope from error text,
|
|
35
|
+
* capturing any authoritative diagnostic prefix and suffix outside the JSON delimiters.
|
|
36
|
+
*/
|
|
37
|
+
export function extractJsonEnvelopeWithContext(text: string): ExtractedJsonEnvelope | undefined {
|
|
38
|
+
let s = text.trim();
|
|
39
|
+
let strippedPrefix = "";
|
|
40
|
+
for (let d = 0; d < 3; d += 1) {
|
|
41
|
+
if (s.startsWith("Provider error 400: ")) {
|
|
42
|
+
strippedPrefix += s.slice(0, "Provider error 400: ".length);
|
|
43
|
+
s = s.slice("Provider error 400: ".length).trim();
|
|
44
|
+
} else if (s.startsWith("Provider error: ")) {
|
|
45
|
+
strippedPrefix += s.slice(0, "Provider error: ".length);
|
|
46
|
+
s = s.slice("Provider error: ".length).trim();
|
|
47
|
+
} else if (s.startsWith("Gateway error 400: ")) {
|
|
48
|
+
strippedPrefix += s.slice(0, "Gateway error 400: ".length);
|
|
49
|
+
s = s.slice("Gateway error 400: ".length).trim();
|
|
50
|
+
} else if (s.startsWith("Gateway error: ")) {
|
|
51
|
+
strippedPrefix += s.slice(0, "Gateway error: ".length);
|
|
52
|
+
s = s.slice("Gateway error: ".length).trim();
|
|
53
|
+
}
|
|
54
|
+
if (s.startsWith("data:") && !s.includes("\n")) {
|
|
55
|
+
strippedPrefix += s.slice(0, "data:".length);
|
|
56
|
+
s = s.slice("data:".length).trim();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const firstBrace = s.indexOf("{");
|
|
60
|
+
const lastBrace = s.lastIndexOf("}");
|
|
61
|
+
if (firstBrace !== -1 && lastBrace > firstBrace) {
|
|
62
|
+
try {
|
|
63
|
+
const value = JSON.parse(s.slice(firstBrace, lastBrace + 1));
|
|
64
|
+
return {
|
|
65
|
+
value,
|
|
66
|
+
prefix: (strippedPrefix + " " + s.slice(0, firstBrace)).trim(),
|
|
67
|
+
suffix: s.slice(lastBrace + 1).trim(),
|
|
68
|
+
};
|
|
69
|
+
} catch {
|
|
70
|
+
// ignore
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const firstBracket = s.indexOf("[");
|
|
74
|
+
const lastBracket = s.lastIndexOf("]");
|
|
75
|
+
if (firstBracket !== -1 && lastBracket > firstBracket) {
|
|
76
|
+
try {
|
|
77
|
+
const value = JSON.parse(s.slice(firstBracket, lastBracket + 1));
|
|
78
|
+
return {
|
|
79
|
+
value,
|
|
80
|
+
prefix: (strippedPrefix + " " + s.slice(0, firstBracket)).trim(),
|
|
81
|
+
suffix: s.slice(lastBracket + 1).trim(),
|
|
82
|
+
};
|
|
83
|
+
} catch {
|
|
84
|
+
// ignore
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Extract a balanced or prefixed JSON object/array envelope from error text.
|
|
92
|
+
* Strips common gateway prefixes and extracts content between the outermost JSON delimiters.
|
|
93
|
+
*/
|
|
94
|
+
export function extractJsonEnvelope(text: string): unknown | undefined {
|
|
95
|
+
return extractJsonEnvelopeWithContext(text)?.value;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Detect a hard policy or origin refusal across known upstream envelope shapes and diagnostic text.
|
|
100
|
+
* When an error is a hard refusal (e.g. cyber_policy, origin_rejected, bio_policy), recovery must
|
|
101
|
+
* stop immediately without retrying or walking any parameter ladders (#8173).
|
|
102
|
+
*
|
|
103
|
+
* Traverses bounded nested wrappers (e.g. Provider error 400, data:, nested error JSON) so wrapped
|
|
104
|
+
* policy refusals are recognized rather than treated as prose.
|
|
105
|
+
*/
|
|
106
|
+
export function isHardPolicyOrOriginRefusal(text: string | undefined, depth = 0): boolean {
|
|
107
|
+
if (!text || depth > 4) return false;
|
|
108
|
+
|
|
109
|
+
let unescaped = text.trim();
|
|
110
|
+
for (let d = 0; d < 3; d += 1) {
|
|
111
|
+
if (unescaped.startsWith("Provider error 400: ")) {
|
|
112
|
+
unescaped = unescaped.slice("Provider error 400: ".length).trim();
|
|
113
|
+
} else if (unescaped.startsWith("Provider error: ")) {
|
|
114
|
+
unescaped = unescaped.slice("Provider error: ".length).trim();
|
|
115
|
+
} else if (unescaped.startsWith("Gateway error 400: ")) {
|
|
116
|
+
unescaped = unescaped.slice("Gateway error 400: ".length).trim();
|
|
117
|
+
} else if (unescaped.startsWith("Gateway error: ")) {
|
|
118
|
+
unescaped = unescaped.slice("Gateway error: ".length).trim();
|
|
119
|
+
}
|
|
120
|
+
if (unescaped.startsWith("data:") && !unescaped.includes("\n")) {
|
|
121
|
+
unescaped = unescaped.slice("data:".length).trim();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Restrict structured policy/origin checks to authoritative diagnostic carriers
|
|
126
|
+
// so echoed user request content (e.g. request.input, prompt, echoed body) does not
|
|
127
|
+
// suppress valid recoveries (#8173).
|
|
128
|
+
let parsed: unknown;
|
|
129
|
+
let hasOuterRefusal = false;
|
|
130
|
+
try {
|
|
131
|
+
parsed = JSON.parse(unescaped);
|
|
132
|
+
} catch {
|
|
133
|
+
const extracted = extractJsonEnvelopeWithContext(unescaped);
|
|
134
|
+
if (extracted) {
|
|
135
|
+
parsed = extracted.value;
|
|
136
|
+
if (
|
|
137
|
+
isAuthoritativeHardRefusalProse(extracted.prefix)
|
|
138
|
+
|| isAuthoritativeHardRefusalProse(extracted.suffix)
|
|
139
|
+
) {
|
|
140
|
+
hasOuterRefusal = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (hasOuterRefusal) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (parsed && typeof parsed === "object") {
|
|
150
|
+
const queue: unknown[] = [parsed];
|
|
151
|
+
let examined = 0;
|
|
152
|
+
while (queue.length > 0 && examined < 32) {
|
|
153
|
+
const candidate = queue.shift();
|
|
154
|
+
examined += 1;
|
|
155
|
+
if (!candidate || typeof candidate !== "object") continue;
|
|
156
|
+
if (Array.isArray(candidate)) {
|
|
157
|
+
if (candidate.length > 32) return true;
|
|
158
|
+
for (const item of candidate) {
|
|
159
|
+
if (item && typeof item === "object") {
|
|
160
|
+
queue.push(item);
|
|
161
|
+
} else if (typeof item === "string") {
|
|
162
|
+
let itemParsed: unknown;
|
|
163
|
+
let itemHasOuterRefusal = false;
|
|
164
|
+
try {
|
|
165
|
+
itemParsed = JSON.parse(item);
|
|
166
|
+
} catch {
|
|
167
|
+
const itemExtracted = extractJsonEnvelopeWithContext(item);
|
|
168
|
+
if (itemExtracted) {
|
|
169
|
+
itemParsed = itemExtracted.value;
|
|
170
|
+
if (
|
|
171
|
+
isAuthoritativeHardRefusalProse(itemExtracted.prefix)
|
|
172
|
+
|| isAuthoritativeHardRefusalProse(itemExtracted.suffix)
|
|
173
|
+
) {
|
|
174
|
+
itemHasOuterRefusal = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (itemHasOuterRefusal) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (itemParsed && typeof itemParsed === "object") {
|
|
184
|
+
queue.push(itemParsed);
|
|
185
|
+
} else if (isAuthoritativeHardRefusalProse(item)) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const rec = candidate as Record<string, unknown>;
|
|
193
|
+
|
|
194
|
+
const code = typeof rec.code === "string" ? rec.code.trim().toLowerCase().replaceAll("-", "_") : undefined;
|
|
195
|
+
if (code) {
|
|
196
|
+
if (
|
|
197
|
+
isCyberPolicyCode(code)
|
|
198
|
+
|| code === "origin_rejected"
|
|
199
|
+
|| isTerminalRefusalCode(code)
|
|
200
|
+
|| isNonReplayableUpstreamCode(code)
|
|
201
|
+
) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const type = typeof rec.type === "string" ? rec.type.trim().toLowerCase().replaceAll("-", "_") : undefined;
|
|
207
|
+
if (type) {
|
|
208
|
+
if (
|
|
209
|
+
isCyberPolicyCode(type)
|
|
210
|
+
|| type === "origin_rejected"
|
|
211
|
+
|| isTerminalRefusalCode(type)
|
|
212
|
+
) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Authoritative diagnostic carriers only (avoid request echo fields like input, prompt, request, body, reason).
|
|
218
|
+
// Parse structured diagnostic strings first so nested request echo is not matched by prose rules (#8173).
|
|
219
|
+
for (const field of ["message", "error", "details", "detail", "last_error", "response", "errors"] as const) {
|
|
220
|
+
const val = rec[field];
|
|
221
|
+
if (typeof val === "string") {
|
|
222
|
+
let innerParsed: unknown;
|
|
223
|
+
let innerHasOuterRefusal = false;
|
|
224
|
+
try {
|
|
225
|
+
innerParsed = JSON.parse(val);
|
|
226
|
+
} catch {
|
|
227
|
+
const innerExtracted = extractJsonEnvelopeWithContext(val);
|
|
228
|
+
if (innerExtracted) {
|
|
229
|
+
innerParsed = innerExtracted.value;
|
|
230
|
+
if (
|
|
231
|
+
isAuthoritativeHardRefusalProse(innerExtracted.prefix)
|
|
232
|
+
|| isAuthoritativeHardRefusalProse(innerExtracted.suffix)
|
|
233
|
+
) {
|
|
234
|
+
innerHasOuterRefusal = true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (innerHasOuterRefusal) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (innerParsed && typeof innerParsed === "object") {
|
|
244
|
+
queue.push(innerParsed);
|
|
245
|
+
} else if (isAuthoritativeHardRefusalProse(val)) {
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
} else if (val && typeof val === "object") {
|
|
249
|
+
queue.push(val);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (isAuthoritativeHardRefusalProse(unescaped)) return true;
|
|
257
|
+
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { linkRouteAllowed } from "./routes";
|
|
2
|
+
|
|
3
|
+
/** A link with no relayed model turn for this long reads as idle (D5). */
|
|
4
|
+
export const DEFAULT_IDLE_AFTER_MS = 600_000;
|
|
5
|
+
|
|
6
|
+
export interface LinkActivitySnapshot { inFlight: number; lastDataEndAt: number | null; observedSince: number }
|
|
7
|
+
|
|
8
|
+
export interface LinkActivity {
|
|
9
|
+
/**
|
|
10
|
+
* Start one relayed model request. null = a legacy key admission without a relay session; it counts against every
|
|
11
|
+
* link. The returned end is idempotent and stamps lastDataEndAt.
|
|
12
|
+
*/
|
|
13
|
+
begin(linkId: string | null): () => void;
|
|
14
|
+
snapshot(linkId: string, now: number): LinkActivitySnapshot;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Model traffic only: a POST the data-plane table admits, except token counting. */
|
|
18
|
+
export function linkActivityCounts(url: URL, req: Request): boolean {
|
|
19
|
+
return req.method === "POST" && url.pathname !== "/v1/messages/count_tokens" && linkRouteAllowed(url, req);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isLinkIdle(snapshot: LinkActivitySnapshot, now: number, idleAfterMs = DEFAULT_IDLE_AFTER_MS): boolean {
|
|
23
|
+
return snapshot.inFlight === 0 && now - (snapshot.lastDataEndAt ?? snapshot.observedSince) >= idleAfterMs;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ActivityEntry { inFlight: number; lastDataEndAt: number | null }
|
|
27
|
+
|
|
28
|
+
/** In memory, no timers. One small entry per link id that ever relayed; links are bounded by links.json. */
|
|
29
|
+
export function createLinkActivity(deps: { now?: () => number } = {}): LinkActivity {
|
|
30
|
+
const now = deps.now ?? Date.now;
|
|
31
|
+
const observedSince = now();
|
|
32
|
+
const perLink = new Map<string, ActivityEntry>();
|
|
33
|
+
const legacy: ActivityEntry = { inFlight: 0, lastDataEndAt: null };
|
|
34
|
+
const entryFor = (linkId: string): ActivityEntry => {
|
|
35
|
+
let entry = perLink.get(linkId);
|
|
36
|
+
if (!entry) { entry = { inFlight: 0, lastDataEndAt: null }; perLink.set(linkId, entry); }
|
|
37
|
+
return entry;
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
begin(linkId) {
|
|
41
|
+
const entry = linkId === null ? legacy : entryFor(linkId);
|
|
42
|
+
entry.inFlight += 1;
|
|
43
|
+
let ended = false;
|
|
44
|
+
return () => {
|
|
45
|
+
if (ended) return;
|
|
46
|
+
ended = true;
|
|
47
|
+
entry.inFlight -= 1;
|
|
48
|
+
entry.lastDataEndAt = now();
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
snapshot(linkId) {
|
|
52
|
+
const entry = perLink.get(linkId);
|
|
53
|
+
const ends = [entry?.lastDataEndAt ?? null, legacy.lastDataEndAt].filter((value): value is number => value !== null);
|
|
54
|
+
return { inFlight: (entry?.inFlight ?? 0) + legacy.inFlight, lastDataEndAt: ends.length ? Math.max(...ends) : null, observedSince };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { catalogEtag } from "../lib/catalog-etag";
|
|
4
|
+
import { patchChildObservation, updateChildObservations } from "./child-observations";
|
|
5
|
+
import { linkStorePath } from "./paths";
|
|
6
|
+
import { readLinkStore, type LinkStore } from "./store";
|
|
7
|
+
|
|
8
|
+
/** One completed `/v1/catalog` fetch by a Child: when, and the etag of the bytes served. Proves a fetch only. */
|
|
9
|
+
export interface CatalogPull { at: number; etag: string }
|
|
10
|
+
|
|
11
|
+
export interface CatalogPullRecorder {
|
|
12
|
+
/** From the relay's onCatalogServed; keyId resolves through links.json when linkId is null. */
|
|
13
|
+
record(served: { linkId: string | null; keyId: string | null; etag: string }): void;
|
|
14
|
+
pulled(linkId: string): CatalogPull | null;
|
|
15
|
+
/** Equals pulled(linkId)?.at ?? null. */
|
|
16
|
+
pulledAt(linkId: string): number | null;
|
|
17
|
+
/** Write every pull not yet persisted, ignoring the per-link interval. */
|
|
18
|
+
flush(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const CATALOG_PULL_WRITE_INTERVAL_MS = 30_000;
|
|
22
|
+
|
|
23
|
+
const errorName = (error: unknown): string => error instanceof Error ? error.name : "unknown";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A linkId absent from links.json, or a keyId no link holds, records nothing. Memory is updated synchronously; the file
|
|
27
|
+
* write is deferred to a microtask (no timer) and happens at most once per link per 30 s. A later pull inside that
|
|
28
|
+
* window stays in memory and is written by the next pull after the window or by flush(). A failed write (for example
|
|
29
|
+
* ConfigMutationLockError under contention) keeps the memory value and is retried on the next write attempt.
|
|
30
|
+
*/
|
|
31
|
+
export function createCatalogPullRecorder(deps: {
|
|
32
|
+
storePath?: string; readStore?: () => LinkStore; now?: () => number; debounceMs?: number;
|
|
33
|
+
write?: (linkId: string, pull: CatalogPull) => void;
|
|
34
|
+
} = {}): CatalogPullRecorder {
|
|
35
|
+
const now = deps.now ?? Date.now;
|
|
36
|
+
const debounceMs = deps.debounceMs ?? CATALOG_PULL_WRITE_INTERVAL_MS;
|
|
37
|
+
const readStore = deps.readStore ?? (() => readLinkStore(deps.storePath ?? linkStorePath()));
|
|
38
|
+
const write = deps.write ?? ((linkId: string, pull: CatalogPull) => {
|
|
39
|
+
updateChildObservations(file => patchChildObservation(file, linkId, { catalogPulledAt: pull.at, catalogPulledEtag: pull.etag }, new Date(pull.at)),
|
|
40
|
+
deps.storePath ? { storePath: deps.storePath, path: join(dirname(deps.storePath), "child-observations.json") } : {});
|
|
41
|
+
});
|
|
42
|
+
const pulls = new Map<string, CatalogPull>();
|
|
43
|
+
const lastWrite = new Map<string, number>();
|
|
44
|
+
const dirty = new Set<string>();
|
|
45
|
+
let scheduled = false;
|
|
46
|
+
const writeOne = (linkId: string): void => {
|
|
47
|
+
const pull = pulls.get(linkId);
|
|
48
|
+
if (!pull) { dirty.delete(linkId); return; }
|
|
49
|
+
try {
|
|
50
|
+
write(linkId, pull);
|
|
51
|
+
dirty.delete(linkId);
|
|
52
|
+
lastWrite.set(linkId, now());
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.warn(`[link] catalog pull write failed linkId=${linkId} error=${errorName(error)}`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const writeDue = (): void => {
|
|
58
|
+
scheduled = false;
|
|
59
|
+
for (const linkId of [...dirty]) {
|
|
60
|
+
const last = lastWrite.get(linkId);
|
|
61
|
+
if (last === undefined || now() - last >= debounceMs) writeOne(linkId);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
record(served) {
|
|
66
|
+
let store: LinkStore;
|
|
67
|
+
try { store = readStore(); } catch { return; }
|
|
68
|
+
const link = served.linkId !== null
|
|
69
|
+
? store.links.find(candidate => candidate.id === served.linkId)
|
|
70
|
+
: served.keyId !== null ? store.links.find(candidate => candidate.apiKeyId === served.keyId) : undefined;
|
|
71
|
+
if (!link) return;
|
|
72
|
+
pulls.set(link.id, { at: now(), etag: served.etag });
|
|
73
|
+
dirty.add(link.id);
|
|
74
|
+
if (!scheduled) { scheduled = true; queueMicrotask(writeDue); }
|
|
75
|
+
},
|
|
76
|
+
pulled: linkId => pulls.get(linkId) ?? null,
|
|
77
|
+
pulledAt: linkId => pulls.get(linkId)?.at ?? null,
|
|
78
|
+
flush() { for (const linkId of [...dirty]) writeOne(linkId); },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The Home catalog's identity. changedAt is display only: no verdict compares times. */
|
|
83
|
+
export interface CatalogRevision { etag: string; changedAt: number }
|
|
84
|
+
export interface CatalogRevisionMonitor { current(): CatalogRevision | null }
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Checked on each read, never on a timer: stat the catalog file, hash only when its size or mtime changed, persist
|
|
88
|
+
* `homeCatalog` only when the etag moved. changedAt = min(now, mtimeMs). A persist failure (lock contention) keeps the
|
|
89
|
+
* revision in memory and is retried on the next read, so a status read never fails on it. An unreadable file is null.
|
|
90
|
+
*/
|
|
91
|
+
export function createCatalogRevisionMonitor(deps: {
|
|
92
|
+
catalogPath: () => string; read: (path: string) => string | null; load: () => CatalogRevision | null;
|
|
93
|
+
persist: (revision: CatalogRevision) => void; now?: () => number;
|
|
94
|
+
stat?: (path: string) => { size: number; mtimeMs: number };
|
|
95
|
+
}): CatalogRevisionMonitor {
|
|
96
|
+
const now = deps.now ?? Date.now;
|
|
97
|
+
const stat = deps.stat ?? ((path: string) => statSync(path));
|
|
98
|
+
let cache: { path: string; size: number; mtimeMs: number; revision: CatalogRevision | null } | null = null;
|
|
99
|
+
let known: CatalogRevision | null | undefined;
|
|
100
|
+
let pending: CatalogRevision | null = null;
|
|
101
|
+
const persistPending = (): void => {
|
|
102
|
+
if (!pending) return;
|
|
103
|
+
try {
|
|
104
|
+
deps.persist(pending);
|
|
105
|
+
pending = null;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.warn(`[link] catalog revision save deferred error=${errorName(error)}`);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
current() {
|
|
112
|
+
let path: string;
|
|
113
|
+
let info: { size: number; mtimeMs: number };
|
|
114
|
+
try {
|
|
115
|
+
path = deps.catalogPath();
|
|
116
|
+
info = stat(path);
|
|
117
|
+
} catch { cache = null; return null; }
|
|
118
|
+
if (cache && cache.path === path && cache.size === info.size && cache.mtimeMs === info.mtimeMs) {
|
|
119
|
+
persistPending();
|
|
120
|
+
return cache.revision;
|
|
121
|
+
}
|
|
122
|
+
let body: string | null;
|
|
123
|
+
try { body = deps.read(path); } catch { body = null; }
|
|
124
|
+
if (body === null) { cache = { path, size: info.size, mtimeMs: info.mtimeMs, revision: null }; return null; }
|
|
125
|
+
const etag = catalogEtag(body);
|
|
126
|
+
if (known === undefined) {
|
|
127
|
+
try { known = deps.load(); } catch { known = null; }
|
|
128
|
+
}
|
|
129
|
+
let revision: CatalogRevision;
|
|
130
|
+
if (known && known.etag === etag) revision = known;
|
|
131
|
+
else {
|
|
132
|
+
revision = { etag, changedAt: Math.min(now(), Math.floor(info.mtimeMs)) };
|
|
133
|
+
known = revision;
|
|
134
|
+
pending = revision;
|
|
135
|
+
}
|
|
136
|
+
cache = { path, size: info.size, mtimeMs: info.mtimeMs, revision };
|
|
137
|
+
persistPending();
|
|
138
|
+
return revision;
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type CatalogState = "current" | "behind" | "unknown";
|
|
144
|
+
|
|
145
|
+
/** Etag equality, never time order. syncedEtag is 030's catalogSyncedEtag (a Home-run sync that synced). */
|
|
146
|
+
export function catalogVerdict(pulledEtag: string | null, syncedEtag: string | null, revision: CatalogRevision | null): CatalogState {
|
|
147
|
+
if (revision === null || (pulledEtag === null && syncedEtag === null)) return "unknown";
|
|
148
|
+
return pulledEtag === revision.etag || syncedEtag === revision.etag ? "current" : "behind";
|
|
149
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { LinkSshArgumentError, remoteGatedOcxArgv } from "./ssh-argv";
|
|
2
|
+
import { parseStrictSemver } from "../lib/strict-semver";
|
|
3
|
+
import { classifyChildUpdatePlan, mapUpdateApplyExit, parseChildUpdatePlan, PLAN_TOKEN_PATTERN, type PlanClassification,
|
|
4
|
+
type UpdateApplyVerdict } from "./child-update-contract";
|
|
5
|
+
|
|
6
|
+
export type SshResult = { code: number; stdout: string; stderr: string };
|
|
7
|
+
export type GatedRefusal = "child-ocx-lacks-expect-link" | "child-ocx-lacks-orchestrated-update" | "child-ocx-version-unknown" | "child-ocx-ephemeral" | "child-gate-failed";
|
|
8
|
+
export type GatedFraming =
|
|
9
|
+
| { kind: "transport"; reason: "ssh-failed" | "child-ocx-not-found" | "child-ocx-not-contained" | "child-platform-unsupported" }
|
|
10
|
+
| { kind: "refused"; reason: GatedRefusal }
|
|
11
|
+
| { kind: "ran"; code: number; selectedVersion: string; entry: "pair" | "binary" | null; childNowMs: number | null; payload: string; lastStderrLine: string | undefined }
|
|
12
|
+
| { kind: "invalid" };
|
|
13
|
+
|
|
14
|
+
function assertHomeVersion(version: string): void {
|
|
15
|
+
if (version.length > 128 || !parseStrictSemver(version)) throw new LinkSshArgumentError("invalid Home version");
|
|
16
|
+
}
|
|
17
|
+
const UPDATE_GATE = { minVersion: "2.97.0", lacksMarker: "child-ocx-lacks-orchestrated-update", acceptEphemeral: false, reportEntry: true, reportClock: false } as const;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Never mutates an install: below 2.97.0 the gate exits 121 before update runs, and update --plan only computes.
|
|
21
|
+
* Not free of side effects on every Child: without a census pair (an npm/pnpm Child whose service never recorded one)
|
|
22
|
+
* the script execs the ocx shim, so the Node launcher's ordinary bootstrap runs first (sync-guard bookkeeping, Bun
|
|
23
|
+
* resolution; the Desktop handoff is disabled), exactly as for every pinned sync already sent to that Child. The probe
|
|
24
|
+
* prints the Child's clock so the apply deadline can be set in the Child's time.
|
|
25
|
+
*/
|
|
26
|
+
export function remoteUpdatePlanArgv(homeVersion: string, platform: "posix" | "windows"): string[] {
|
|
27
|
+
assertHomeVersion(homeVersion);
|
|
28
|
+
return remoteGatedOcxArgv({ ...UPDATE_GATE, reportClock: true, args: ["update", "--plan", "--json", "--version", homeVersion] }, platform);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The shipped builders refuse Windows apply: a dropped channel kills the orchestrating parent with the Job.
|
|
33
|
+
* A token starting with "-" cannot pass the Child's --expect-plan parser (orchestrated-arguments.mjs refuses a value
|
|
34
|
+
* that looks like a flag), so it is omitted; the apply stays pinned by --version, bounded by --not-after, serialized
|
|
35
|
+
* by the Child's update mutex and refused on downgrade. Only the plan-consistency check is lost for that token.
|
|
36
|
+
*/
|
|
37
|
+
export function remoteUpdateApplyArgv(input: { homeVersion: string; planToken: string; notAfter: number }, platform: "posix" | "windows"): string[] {
|
|
38
|
+
if (platform === "windows") throw new LinkSshArgumentError("unsupported:windows-apply");
|
|
39
|
+
assertHomeVersion(input.homeVersion);
|
|
40
|
+
if (!PLAN_TOKEN_PATTERN.test(input.planToken)) throw new LinkSshArgumentError("invalid plan token");
|
|
41
|
+
if (!Number.isSafeInteger(input.notAfter) || input.notAfter <= 0) throw new LinkSshArgumentError("invalid deadline");
|
|
42
|
+
const expectPlan = input.planToken.startsWith("-") ? [] : ["--expect-plan", input.planToken];
|
|
43
|
+
return remoteGatedOcxArgv({ ...UPDATE_GATE, args: ["update", "--yes", "--json", "--version", input.homeVersion,
|
|
44
|
+
...expectPlan, "--not-after", String(input.notAfter)] }, platform);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const REFUSAL = /^ocx-fanout:(child-ocx-lacks-expect-link|child-ocx-lacks-orchestrated-update|child-ocx-version-unknown|child-ocx-ephemeral)$/;
|
|
48
|
+
const CHILD_NOW = "ocx-fanout:child-now:";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The framing classifySyncResult applies, generalised to every gated command. A run is recognised by exactly one
|
|
52
|
+
* selection marker and one stdout delimiter before the exit code is read, so an exit the selected ocx itself returns
|
|
53
|
+
* after selection (even 121, 126, 127 or 255) is a run, never a transport failure or a gate refusal.
|
|
54
|
+
*/
|
|
55
|
+
export function readGatedFraming(result: SshResult): GatedFraming {
|
|
56
|
+
const { code, stdout, stderr } = result;
|
|
57
|
+
const lines = stderr.split(/\r?\n/);
|
|
58
|
+
const last = stderr.trimEnd().split(/\r?\n/).at(-1);
|
|
59
|
+
const selected = lines.map(line => /^ocx-fanout:selected:(.+)$/.exec(line)).filter(match => match !== null);
|
|
60
|
+
const out = stdout.split(/\r?\n/);
|
|
61
|
+
const delimiters = out.flatMap((line, index) => line === "ocx-fanout:stdout-begin" ? [index] : []);
|
|
62
|
+
if (selected.length !== 1 || delimiters.length !== 1) {
|
|
63
|
+
if (code === 255) return { kind: "transport", reason: "ssh-failed" };
|
|
64
|
+
if (code === 127) return { kind: "transport", reason: "child-ocx-not-found" };
|
|
65
|
+
if (code === 126) return { kind: "transport", reason: "child-ocx-not-contained" };
|
|
66
|
+
if (code === 125) return { kind: "transport", reason: "child-platform-unsupported" };
|
|
67
|
+
if (code === 121) return { kind: "refused", reason: (REFUSAL.exec(last ?? "")?.[1] ?? "child-gate-failed") as GatedRefusal };
|
|
68
|
+
return { kind: "invalid" };
|
|
69
|
+
}
|
|
70
|
+
if (!parseStrictSemver(selected[0]![1]!)) return { kind: "invalid" };
|
|
71
|
+
const entries = lines.filter(line => /^ocx-fanout:entry:(pair|binary)$/.test(line));
|
|
72
|
+
if (entries.length > 1) return { kind: "invalid" };
|
|
73
|
+
// Capture any value and validate it afterwards, so a malformed clock makes the framing invalid instead of absent.
|
|
74
|
+
const clocks = lines.filter(line => line.startsWith(CHILD_NOW)).map(line => line.slice(CHILD_NOW.length));
|
|
75
|
+
if (clocks.length > 1 || (clocks.length === 1 && (!/^[0-9]{10,16}$/.test(clocks[0]!) || !Number.isSafeInteger(Number(clocks[0]))))) return { kind: "invalid" };
|
|
76
|
+
return { kind: "ran", code, selectedVersion: selected[0]![1]!, entry: entries.length ? (entries[0]!.slice("ocx-fanout:entry:".length) as "pair" | "binary") : null,
|
|
77
|
+
childNowMs: clocks.length ? Number(clocks[0]) : null, payload: out.slice(delimiters[0]! + 1).join("\n").trim(), lastStderrLine: last };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type PlanProbeVerdict =
|
|
81
|
+
| { kind: "plan"; selectedVersion: string; classification: PlanClassification; childNowMs: number | null }
|
|
82
|
+
| { kind: "legacy"; reason: "child-ocx-lacks-orchestrated-update" | "child-ocx-version-unknown" }
|
|
83
|
+
| { kind: "ephemeral" }
|
|
84
|
+
| { kind: "offline"; reason: "ssh-failed" }
|
|
85
|
+
| { kind: "failed"; reason: string };
|
|
86
|
+
|
|
87
|
+
/** platform "windows": the Windows script prints no entry marker because it reads no census, so the entry is "binary". */
|
|
88
|
+
export function classifyUpdatePlanProbe(result: SshResult, ctx: { homeVersion: string; desktopUpdateRequest: boolean; platform?: "posix" | "windows" }): PlanProbeVerdict {
|
|
89
|
+
const framing = readGatedFraming(result);
|
|
90
|
+
if (framing.kind === "transport") return framing.reason === "ssh-failed" ? { kind: "offline", reason: "ssh-failed" } : { kind: "failed", reason: framing.reason };
|
|
91
|
+
if (framing.kind === "refused") {
|
|
92
|
+
if (framing.reason === "child-ocx-ephemeral") return { kind: "ephemeral" };
|
|
93
|
+
if (framing.reason === "child-ocx-lacks-orchestrated-update" || framing.reason === "child-ocx-version-unknown") return { kind: "legacy", reason: framing.reason };
|
|
94
|
+
return { kind: "failed", reason: framing.reason };
|
|
95
|
+
}
|
|
96
|
+
if (framing.kind === "invalid") return { kind: "failed", reason: "child-output-invalid" };
|
|
97
|
+
if (framing.code !== 0) return { kind: "failed", reason: framing.code === 64 ? "contract-usage" : "child-plan-failed" };
|
|
98
|
+
const parsed = parseChildUpdatePlan(framing.payload);
|
|
99
|
+
if (!parsed.ok) return { kind: "failed", reason: parsed.reason };
|
|
100
|
+
const entry = framing.entry ?? (ctx.platform === "windows" ? "binary" : null);
|
|
101
|
+
return { kind: "plan", selectedVersion: framing.selectedVersion, childNowMs: framing.childNowMs,
|
|
102
|
+
classification: classifyChildUpdatePlan(parsed.value, { homeVersion: ctx.homeVersion, desktopUpdateRequest: ctx.desktopUpdateRequest, entry }) };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function classifyUpdateApply(result: SshResult): UpdateApplyVerdict {
|
|
106
|
+
const framing = readGatedFraming(result);
|
|
107
|
+
if (framing.kind === "transport") return framing.reason === "ssh-failed"
|
|
108
|
+
? { state: "uncertain", reason: "ssh-failed", suppressTarget: false, reobserve: true }
|
|
109
|
+
: { state: "failed", reason: framing.reason, suppressTarget: false, reobserve: false };
|
|
110
|
+
if (framing.kind === "refused") return framing.reason === "child-ocx-ephemeral"
|
|
111
|
+
? { state: "unsupported", reason: "ephemeral", suppressTarget: false, reobserve: false }
|
|
112
|
+
: { state: "owner-action", reason: framing.reason === "child-gate-failed" ? "child-gate-failed" : "legacy-ocx", suppressTarget: false, reobserve: false };
|
|
113
|
+
// Framing broken after a command may have run: never assume it did not.
|
|
114
|
+
if (framing.kind === "invalid") return { state: "uncertain", reason: "child-output-invalid", suppressTarget: false, reobserve: true };
|
|
115
|
+
return mapUpdateApplyExit(framing.code, framing.payload);
|
|
116
|
+
}
|
|
117
|
+
|