@bitkyc08/opencodex 2.100.1 → 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-nr3ziR-T.js → brand-mark-DU-0Vdkr.js} +1 -1
- 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-DKCVUUTi.js → segment-thumb-features-e9A_FogJ.js} +1 -1
- package/gui/dist/classic/assets/{App-CgPBKUP-.js → App-BrIlUiLc.js} +18 -18
- package/gui/dist/classic/assets/{Tray-BedmOsE7.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/client-fingerprint.ts +5 -3
- 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/tool-schema.ts +9 -0
- 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 +213 -121
- package/src/lib/catalog-etag.ts +10 -0
- package/src/lib/client-error-body.ts +15 -0
- 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/index.ts +1 -0
- 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-usage-state.ts +11 -6
- package/src/providers/claude-cli-usage.ts +27 -9
- 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-usage-windows.ts +19 -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 +25 -0
- package/src/providers/quota.ts +22 -22
- package/src/providers/reasoning-metadata.ts +1051 -12
- 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/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 +16 -5
- 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 +21 -2
- package/gui/dist/assets/App-g3Cm2xhZ.js +0 -59
- package/gui/dist/assets/Tray-BMDkAiXy.js +0 -1
- package/gui/dist/assets/index-Bziu8gTy.css +0 -2
- package/gui/dist/assets/index-OYzhQUNP.js +0 -94
- package/gui/dist/classic/assets/index-BR-HhNrp.js +0 -94
- package/gui/dist/classic/assets/quota-summary-CXKhvSmQ.js +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { parseStrictSemver } from "../lib/strict-semver";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Home's own copy of the Child's update.orchestrated/1 contract (src/update/orchestrated-plan.ts,
|
|
5
|
+
* orchestrated-outcome.mjs, orchestrated-admission.mjs, orchestrated-entry.ts). Pure and strict: a document with another
|
|
6
|
+
* schema, another key set or an out-of-range field never parses, so remote text never becomes a verdict by accident.
|
|
7
|
+
*/
|
|
8
|
+
export const UPDATE_PLAN_SCHEMA = "ocx.update.plan/1";
|
|
9
|
+
export const UPDATE_RESULT_SCHEMA = "ocx.update.result/1";
|
|
10
|
+
export const UPDATE_OUTPUT_MAX_BYTES = 65_536;
|
|
11
|
+
export type PlanInstaller = "npm" | "pnpm" | "bun" | "mise" | "desktop-app" | "source" | "unknown";
|
|
12
|
+
export type PlanRuntimeOwner = "service" | "desktop-app" | "unmanaged" | "none" | "unknown";
|
|
13
|
+
export type PlanReason = "desktop-app-owned" | "source-checkout" | "mise-managed" | "installer-unknown" | "plan-unavailable"
|
|
14
|
+
| "serving-install-unknown" | "cli-not-serving-install" | "runtime-ownership-refused" | "target-unresolved" | "downgrade-refused" | "up-to-date";
|
|
15
|
+
export interface ChildUpdatePlan {
|
|
16
|
+
schema: typeof UPDATE_PLAN_SCHEMA; currentVersion: string; targetVersion: string | null; installer: PlanInstaller;
|
|
17
|
+
runtimeOwner: PlanRuntimeOwner; servingPath: string | null; cliPath: string; canApply: boolean; reason?: PlanReason;
|
|
18
|
+
restartRequired: boolean; planToken: string; updateInFlight: boolean; mutationBoundMs: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ChildUpdateResult {
|
|
21
|
+
schema: typeof UPDATE_RESULT_SCHEMA; applied: boolean; fromVersion: string; toVersion: string | null; installer: PlanInstaller;
|
|
22
|
+
restarted: boolean; healthy: boolean; rolledBack: boolean; error?: string;
|
|
23
|
+
}
|
|
24
|
+
export type ContractParse<T> = { ok: true; value: T } | { ok: false; reason: "contract-unknown" | "contract-output-invalid" | "contract-output-too-large" };
|
|
25
|
+
export type InstallKind = "npm" | "pnpm" | "bun" | "source" | "mise" | "desktop-app" | "goat" | "standalone" | "ocx-child" | "unknown";
|
|
26
|
+
export type UpdateRoute = "orchestrated" | "desktop-request" | "owner-action" | "replant" | "none";
|
|
27
|
+
export interface PlanClassification {
|
|
28
|
+
installKind: InstallKind; updateRoute: UpdateRoute; updateReason: string | null; installedVersion: string | null;
|
|
29
|
+
targetVersion: string | null; runtimeOwner: PlanRuntimeOwner; planToken: string | null; updateInFlight: boolean; mutationBoundMs: number;
|
|
30
|
+
}
|
|
31
|
+
export type ApplyState = "succeeded" | "up-to-date" | "busy" | "refused" | "failed" | "uncertain" | "owner-action" | "unsupported";
|
|
32
|
+
export interface UpdateApplyVerdict { state: ApplyState; reason: string | null; fromVersion?: string; toVersion?: string; suppressTarget: boolean; reobserve: boolean }
|
|
33
|
+
|
|
34
|
+
export const PLAN_INSTALLERS: ReadonlySet<string> = new Set<PlanInstaller>(["npm", "pnpm", "bun", "mise", "desktop-app", "source", "unknown"]);
|
|
35
|
+
export const PLAN_RUNTIME_OWNERS: ReadonlySet<string> = new Set<PlanRuntimeOwner>(["service", "desktop-app", "unmanaged", "none", "unknown"]);
|
|
36
|
+
const PLAN_REASONS: ReadonlySet<string> = new Set<PlanReason>(["desktop-app-owned", "source-checkout", "mise-managed", "installer-unknown",
|
|
37
|
+
"plan-unavailable", "serving-install-unknown", "cli-not-serving-install", "runtime-ownership-refused", "target-unresolved", "downgrade-refused", "up-to-date"]);
|
|
38
|
+
const PLAN_KEYS = ["schema", "currentVersion", "targetVersion", "installer", "runtimeOwner", "servingPath", "cliPath", "canApply",
|
|
39
|
+
"restartRequired", "planToken", "updateInFlight", "mutationBoundMs"] as const;
|
|
40
|
+
const RESULT_KEYS = ["schema", "applied", "fromVersion", "toVersion", "installer", "restarted", "healthy", "rolledBack"] as const;
|
|
41
|
+
const APPLYING_INSTALLERS: ReadonlySet<string> = new Set(["npm", "pnpm", "bun"]);
|
|
42
|
+
export const PLAN_TOKEN_PATTERN = /^[A-Za-z0-9_-]{16,128}$/;
|
|
43
|
+
const ERROR_TOKEN = /^[a-z][a-z0-9-]{0,63}$/;
|
|
44
|
+
const MAX_MUTATION_BOUND_MS = 3_600_000;
|
|
45
|
+
|
|
46
|
+
type Invalid = { ok: false; reason: "contract-output-invalid" };
|
|
47
|
+
const invalid: Invalid = { ok: false, reason: "contract-output-invalid" };
|
|
48
|
+
const isVersion = (value: unknown): value is string => typeof value === "string" && value.length <= 128 && parseStrictSemver(value) !== null;
|
|
49
|
+
const isPath = (value: unknown): value is string => typeof value === "string" && value.length >= 1 && value.length <= 4096 && !value.includes("\0");
|
|
50
|
+
const hasExactKeys = (raw: Record<string, unknown>, required: readonly string[], optional: string): boolean => {
|
|
51
|
+
const keys = Object.keys(raw);
|
|
52
|
+
const expected = required.length + (Object.hasOwn(raw, optional) ? 1 : 0);
|
|
53
|
+
return keys.length === expected && required.every(key => Object.hasOwn(raw, key));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type Refusal = Extract<ContractParse<never>, { ok: false }>;
|
|
57
|
+
/** Size, single line, one JSON object, then the schema; returns the object or the refusal. */
|
|
58
|
+
function readDocument(payload: string, schema: string): { raw: Record<string, unknown> } | Refusal {
|
|
59
|
+
if (Buffer.byteLength(payload, "utf8") > UPDATE_OUTPUT_MAX_BYTES) return { ok: false, reason: "contract-output-too-large" };
|
|
60
|
+
const text = payload.trim();
|
|
61
|
+
if (text.length === 0 || /[\r\n]/.test(text)) return invalid;
|
|
62
|
+
let value: unknown;
|
|
63
|
+
try { value = JSON.parse(text); } catch { return invalid; }
|
|
64
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return invalid;
|
|
65
|
+
const raw = value as Record<string, unknown>;
|
|
66
|
+
if (typeof raw.schema === "string" && raw.schema !== schema) return { ok: false, reason: "contract-unknown" };
|
|
67
|
+
if (raw.schema !== schema) return invalid;
|
|
68
|
+
return { raw };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function parseChildUpdatePlan(payload: string): ContractParse<ChildUpdatePlan> {
|
|
72
|
+
const document = readDocument(payload, UPDATE_PLAN_SCHEMA);
|
|
73
|
+
if (!("raw" in document)) return document;
|
|
74
|
+
const { raw } = document;
|
|
75
|
+
if (!hasExactKeys(raw, PLAN_KEYS, "reason")) return invalid;
|
|
76
|
+
const current = raw.currentVersion;
|
|
77
|
+
if (!(current === "unknown" || isVersion(current))) return invalid;
|
|
78
|
+
if (!(raw.targetVersion === null || isVersion(raw.targetVersion))) return invalid;
|
|
79
|
+
if (typeof raw.installer !== "string" || !PLAN_INSTALLERS.has(raw.installer)) return invalid;
|
|
80
|
+
if (typeof raw.runtimeOwner !== "string" || !PLAN_RUNTIME_OWNERS.has(raw.runtimeOwner)) return invalid;
|
|
81
|
+
if (!(raw.servingPath === null || isPath(raw.servingPath)) || !isPath(raw.cliPath)) return invalid;
|
|
82
|
+
if (typeof raw.canApply !== "boolean" || typeof raw.restartRequired !== "boolean" || typeof raw.updateInFlight !== "boolean") return invalid;
|
|
83
|
+
if (raw.reason !== undefined && (typeof raw.reason !== "string" || !PLAN_REASONS.has(raw.reason))) return invalid;
|
|
84
|
+
if (typeof raw.planToken !== "string" || !PLAN_TOKEN_PATTERN.test(raw.planToken)) return invalid;
|
|
85
|
+
const bound = raw.mutationBoundMs;
|
|
86
|
+
if (typeof bound !== "number" || !Number.isSafeInteger(bound) || bound < 1 || bound > MAX_MUTATION_BOUND_MS) return invalid;
|
|
87
|
+
if (raw.canApply !== (raw.reason === undefined)) return invalid;
|
|
88
|
+
if (raw.canApply && (!APPLYING_INSTALLERS.has(raw.installer) || raw.targetVersion === null)) return invalid;
|
|
89
|
+
return { ok: true, value: {
|
|
90
|
+
schema: UPDATE_PLAN_SCHEMA, currentVersion: current as string, targetVersion: raw.targetVersion as string | null,
|
|
91
|
+
installer: raw.installer as PlanInstaller, runtimeOwner: raw.runtimeOwner as PlanRuntimeOwner, servingPath: raw.servingPath as string | null,
|
|
92
|
+
cliPath: raw.cliPath as string, canApply: raw.canApply, ...(raw.reason === undefined ? {} : { reason: raw.reason as PlanReason }),
|
|
93
|
+
restartRequired: raw.restartRequired, planToken: raw.planToken, updateInFlight: raw.updateInFlight, mutationBoundMs: bound,
|
|
94
|
+
} };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function parseChildUpdateResult(payload: string): ContractParse<ChildUpdateResult> {
|
|
98
|
+
const document = readDocument(payload, UPDATE_RESULT_SCHEMA);
|
|
99
|
+
if (!("raw" in document)) return document;
|
|
100
|
+
const { raw } = document;
|
|
101
|
+
if (!hasExactKeys(raw, RESULT_KEYS, "error")) return invalid;
|
|
102
|
+
// fromVersion is the plan's currentVersion, which is "unknown" when the Child could not read its own version.
|
|
103
|
+
if (!(raw.fromVersion === "unknown" || isVersion(raw.fromVersion))) return invalid;
|
|
104
|
+
if (!(raw.toVersion === null || isVersion(raw.toVersion))) return invalid;
|
|
105
|
+
if (typeof raw.installer !== "string" || !PLAN_INSTALLERS.has(raw.installer)) return invalid;
|
|
106
|
+
if (typeof raw.applied !== "boolean" || typeof raw.restarted !== "boolean" || typeof raw.healthy !== "boolean" || typeof raw.rolledBack !== "boolean") return invalid;
|
|
107
|
+
if (raw.error !== undefined && (typeof raw.error !== "string" || !ERROR_TOKEN.test(raw.error))) return invalid;
|
|
108
|
+
return { ok: true, value: {
|
|
109
|
+
schema: UPDATE_RESULT_SCHEMA, applied: raw.applied, fromVersion: raw.fromVersion as string, toVersion: raw.toVersion as string | null,
|
|
110
|
+
installer: raw.installer as PlanInstaller, restarted: raw.restarted, healthy: raw.healthy, rolledBack: raw.rolledBack,
|
|
111
|
+
...(raw.error === undefined ? {} : { error: raw.error }),
|
|
112
|
+
} };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const GOAT_PATHS = ["/.local/share/goat/opencodex/", "\\.local\\share\\goat\\opencodex\\"];
|
|
116
|
+
|
|
117
|
+
/** First matching row wins (010 "classifyChildUpdatePlan"). */
|
|
118
|
+
export function classifyChildUpdatePlan(plan: ChildUpdatePlan, ctx: { homeVersion: string; desktopUpdateRequest: boolean; entry: "pair" | "binary" | null }): PlanClassification {
|
|
119
|
+
const row = (installKind: InstallKind, updateRoute: UpdateRoute, updateReason: string | null): PlanClassification => ({
|
|
120
|
+
installKind, updateRoute, updateReason, installedVersion: plan.currentVersion === "unknown" ? null : plan.currentVersion,
|
|
121
|
+
targetVersion: plan.targetVersion, runtimeOwner: plan.runtimeOwner, planToken: plan.planToken, updateInFlight: plan.updateInFlight,
|
|
122
|
+
mutationBoundMs: plan.mutationBoundMs,
|
|
123
|
+
});
|
|
124
|
+
const installer: InstallKind = plan.installer;
|
|
125
|
+
const path = plan.cliPath ?? plan.servingPath ?? "";
|
|
126
|
+
if (plan.installer === "unknown" && GOAT_PATHS.some(marker => path.includes(marker))) return row("goat", "owner-action", "goat");
|
|
127
|
+
if (plan.reason === "up-to-date") return row(installer, "none", "up-to-date");
|
|
128
|
+
if (plan.canApply && plan.targetVersion !== ctx.homeVersion) return row(installer, "none", "target-mismatch");
|
|
129
|
+
if (plan.canApply && (plan.installer === "npm" || plan.installer === "pnpm") && ctx.entry === "pair") return row(installer, "owner-action", "launcher-bypassed");
|
|
130
|
+
if (plan.canApply) return row(installer, "orchestrated", null);
|
|
131
|
+
if (plan.reason === "desktop-app-owned") return row("desktop-app", ctx.desktopUpdateRequest ? "desktop-request" : "owner-action", "desktop-app-owned");
|
|
132
|
+
if (plan.reason === "mise-managed") return row("mise", "owner-action", "mise-managed");
|
|
133
|
+
if (plan.reason === "source-checkout") return row("source", "owner-action", "source-checkout");
|
|
134
|
+
if (plan.reason === "installer-unknown") return row("unknown", "owner-action", "installer-unknown");
|
|
135
|
+
return row(installer, "none", `refused:${plan.reason ?? "plan-unavailable"}`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const verdict = (state: ApplyState, reason: string | null, extra: Partial<UpdateApplyVerdict> = {}): UpdateApplyVerdict =>
|
|
139
|
+
({ state, reason, ...extra, suppressTarget: extra.suppressTarget ?? false, reobserve: extra.reobserve ?? false });
|
|
140
|
+
|
|
141
|
+
/** D12 step 5: map the apply exit and its ocx.update.result/1 document to a closed verdict. */
|
|
142
|
+
export function mapUpdateApplyExit(code: number, payload: string): UpdateApplyVerdict {
|
|
143
|
+
const parsed = parseChildUpdateResult(payload);
|
|
144
|
+
const result = parsed.ok ? parsed.value : null;
|
|
145
|
+
switch (code) {
|
|
146
|
+
case 0:
|
|
147
|
+
if (result?.applied && result.healthy) return verdict("succeeded", null, { fromVersion: result.fromVersion, ...(result.toVersion === null ? {} : { toVersion: result.toVersion }) });
|
|
148
|
+
if (result && !result.applied && result.error === undefined) return verdict("up-to-date", null, { fromVersion: result.fromVersion, ...(result.toVersion === null ? {} : { toVersion: result.toVersion }) });
|
|
149
|
+
return verdict("uncertain", "contract-output-invalid", { reobserve: true });
|
|
150
|
+
case 10:
|
|
151
|
+
if (!result) return verdict("refused", "contract-output-invalid");
|
|
152
|
+
if (result.error === "update-in-flight") return verdict("busy", "update-in-flight");
|
|
153
|
+
return verdict("refused", result.error ?? "contract-output-invalid");
|
|
154
|
+
case 11:
|
|
155
|
+
return verdict("failed", result?.rolledBack ? "rolled-back" : "update-failed", { suppressTarget: true });
|
|
156
|
+
case 12:
|
|
157
|
+
return verdict("uncertain", result?.error ?? "outcome-unverified", { reobserve: true });
|
|
158
|
+
case 64:
|
|
159
|
+
return verdict("refused", "contract-usage");
|
|
160
|
+
default:
|
|
161
|
+
// An apply may have started: never assume it did not.
|
|
162
|
+
return verdict("uncertain", "unexpected-exit", { reobserve: true });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
package/src/link/paths.ts
CHANGED
|
@@ -17,3 +17,8 @@ export function linkStorePath(configDir?: string): string {
|
|
|
17
17
|
export function linkKnownHostsPath(configDir?: string): string {
|
|
18
18
|
return join(linkDir(configDir), "known_hosts");
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
/** Tolerant per-link observation cache (src/link/child-observations.ts); never a trust boundary. */
|
|
22
|
+
export function childObservationsPath(configDir?: string): string {
|
|
23
|
+
return join(linkDir(configDir), "child-observations.json");
|
|
24
|
+
}
|
|
@@ -7,10 +7,18 @@ import { deflateRawSync, inflateRawSync } from "node:zlib";
|
|
|
7
7
|
*/
|
|
8
8
|
export const POWERSHELL_ENCODED_MAX = 8_000;
|
|
9
9
|
|
|
10
|
+
/** The encoded command would not fit cmd.exe's command line; callers that build gated commands rename it. */
|
|
11
|
+
export class PowerShellCommandTooLongError extends Error {
|
|
12
|
+
constructor(readonly encodedLength: number) {
|
|
13
|
+
super(`Remote PowerShell command exceeds the cmd.exe-compatible command-line budget (${encodedLength})`);
|
|
14
|
+
this.name = "PowerShellCommandTooLongError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
export function powershellArgv(script: string): string[] {
|
|
11
19
|
// Module preparation otherwise writes a CLIXML progress record to stderr, which Home would see.
|
|
12
20
|
const encoded = Buffer.from("$ProgressPreference='SilentlyContinue'\n" + script, "utf16le").toString("base64");
|
|
13
|
-
if (encoded.length > POWERSHELL_ENCODED_MAX) throw new
|
|
21
|
+
if (encoded.length > POWERSHELL_ENCODED_MAX) throw new PowerShellCommandTooLongError(encoded.length);
|
|
14
22
|
return ["powershell.exe", "-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", encoded];
|
|
15
23
|
}
|
|
16
24
|
|
|
@@ -210,21 +218,49 @@ Get-ChildItem -LiteralPath $dir -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{
|
|
|
210
218
|
`);
|
|
211
219
|
}
|
|
212
220
|
|
|
213
|
-
export
|
|
214
|
-
|
|
221
|
+
export interface WindowsGatedCommand {
|
|
222
|
+
versionParts: readonly [string, string, string];
|
|
223
|
+
lacksMarker: "child-ocx-lacks-expect-link" | "child-ocx-lacks-orchestrated-update";
|
|
224
|
+
acceptEphemeral: boolean;
|
|
225
|
+
/** Prints ocx-fanout:child-now:<epoch-ms> from [DateTimeOffset]::Now (Unix milliseconds do not depend on the offset). */
|
|
226
|
+
reportClock: boolean;
|
|
227
|
+
args: readonly string[];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The gated Windows command: select a candidate, refuse below the minimum, optionally refuse ocx-child, then run it
|
|
232
|
+
* contained. OCX_NO_DESKTOP_HANDOFF=1 makes a launcher answer --version and run the command itself. Windows never
|
|
233
|
+
* sends a restart, so the selected-kind report is not built here. Windows reads no served-runtime census, so the
|
|
234
|
+
* selected entry is always a binary: the script prints no entry marker and the Home infers "binary", which keeps the
|
|
235
|
+
* plan probe inside the command-line budget for long preview Home versions.
|
|
236
|
+
*/
|
|
237
|
+
export function windowsGatedOcxArgv(cmd: WindowsGatedCommand): string[] {
|
|
238
|
+
if (!cmd.versionParts.every(part => /^(0|[1-9][0-9]{0,3})$/.test(part))) throw new Error("invalid gate version");
|
|
239
|
+
if (!/^child-ocx-lacks-(expect-link|orchestrated-update)$/.test(cmd.lacksMarker)) throw new Error("invalid gate marker");
|
|
240
|
+
const b = cmd.versionParts.map(part => "'" + part + "'").join(",");
|
|
241
|
+
// -match is case-insensitive; the pattern reads the file name the way [IO.Path]::GetFileName does (either separator).
|
|
242
|
+
const ephemeral = cmd.acceptEphemeral ? "" : String.raw`if($x -match '(^|[\\/])ocx-child[^\\/]*$'){[Console]::Error.WriteLine('ocx-fanout:child-ocx-ephemeral');exit 121};`;
|
|
243
|
+
const clock = cmd.reportClock ? String.raw`[Console]::Error.WriteLine('ocx-fanout:child-now:'+[DateTimeOffset]::Now.ToUnixTimeMilliseconds());` : "";
|
|
244
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: cmd.args }) + OCX_CANDIDATES + String.raw`$env:OCX_NO_DESKTOP_HANDOFF='1'
|
|
215
245
|
foreach($x in ($c|select -Unique)){
|
|
216
246
|
if(![IO.File]::Exists($x)){continue};$v=[OcxJob]::V($x);if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
217
247
|
$m=[regex]::Match($v,'^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$')
|
|
218
248
|
$bad=(!$m.Success -or $v.Length -gt 128);if(!$bad -and $m.Groups[4].Success){foreach($p in $m.Groups[4].Value.Split('.')){if(!$p -or ($p -match '^\d+$' -and $p.Length -gt 1 -and $p[0] -eq '0')){$bad=$true}}}
|
|
219
249
|
if($bad){[Console]::Error.WriteLine('ocx-fanout:child-ocx-version-unknown');exit 121}
|
|
220
|
-
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(
|
|
250
|
+
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(` + b + String.raw`);$cmp=0
|
|
221
251
|
for($i=0;$i -lt 3;$i++){if($a[$i].Length -ne $b[$i].Length){$cmp=$a[$i].Length-$b[$i].Length;break};$cmp=[string]::CompareOrdinal($a[$i],$b[$i]);if($cmp -ne 0){break}}
|
|
222
|
-
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('ocx-fanout
|
|
223
|
-
[Console]::Error.WriteLine('ocx-fanout:selected:'+$v)
|
|
252
|
+
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('ocx-fanout:` + cmd.lacksMarker + String.raw`');exit 121}
|
|
253
|
+
` + ephemeral + String.raw`[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);` + clock + String.raw`[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x @($d.args)
|
|
224
254
|
};exit 127
|
|
225
255
|
`);
|
|
226
256
|
}
|
|
227
257
|
|
|
258
|
+
/** The 2.93.0 sync gate; kept as a named entry because discovery tests import it. */
|
|
259
|
+
export function windowsPinnedSyncArgv(linkId: string): string[] {
|
|
260
|
+
return windowsGatedOcxArgv({ versionParts: ["2", "93", "0"], lacksMarker: "child-ocx-lacks-expect-link", acceptEphemeral: true,
|
|
261
|
+
reportClock: false, args: ["sync", "--expect-link", linkId, "--json"] });
|
|
262
|
+
}
|
|
263
|
+
|
|
228
264
|
/** Credential-free loopback probe of the Child; no proxy, no redirect, bounded body and deadline. */
|
|
229
265
|
export function windowsChildHttpArgv(port: number, path: "healthz" | "v1/catalog", timeoutMs: number): string[] {
|
|
230
266
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("invalid Child port");
|
package/src/link/ssh-argv.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import { isAbsolute } from "node:path";
|
|
22
|
-
import { POWERSHELL_ENCODED_MAX,
|
|
22
|
+
import { POWERSHELL_ENCODED_MAX, PowerShellCommandTooLongError, windowsGatedOcxArgv, windowsOcxArgv } from "./remote-windows";
|
|
23
23
|
|
|
24
24
|
export type TunnelDirection = "R" | "L";
|
|
25
25
|
|
|
@@ -141,40 +141,47 @@ export const REMOTE_COMMAND_NOT_FOUND = 127;
|
|
|
141
141
|
export const REMOTE_PLATFORM_UNSUPPORTED = 125;
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* `command`, one or two absolute paths without quotes or backslashes, is read; any other shape
|
|
151
|
-
* falls through. Desktop binaries then precede PATH candidates; each candidate must run --version
|
|
152
|
-
* successfully. A missing runnable ocx exits 127.
|
|
153
|
-
*/
|
|
154
|
-
/**
|
|
155
|
-
* Reads the first \`command\` of \`serving-runtimes.json\` (#8359): one or two absolute paths without
|
|
156
|
-
* quotes or backslashes, printed one per line, from a file of at most 64 KiB. Any other shape fails.
|
|
144
|
+
* Reads the first record's \`command\` of \`serving-runtimes.json\` (#8359): one or two absolute paths
|
|
145
|
+
* without quotes or backslashes, printed one per line, from a file of at most 64 KiB. The file must
|
|
146
|
+
* be the complete document in the layout its only writer produces (\`JSON.stringify(_, null, 2)\` in
|
|
147
|
+
* src/config/serving-runtimes.ts): a first record without \`command\` never borrows a later record's,
|
|
148
|
+
* and a file cut off anywhere before its closing brace prints nothing. Any other shape fails, and an
|
|
149
|
+
* unreadable file or a missing awk fails without writing to stderr.
|
|
157
150
|
* Shared by the ocx discovery, pinned sync and runtime inspection scripts.
|
|
158
151
|
*/
|
|
159
152
|
export const REMOTE_SERVED_RUNTIME = `served_runtime() {
|
|
160
|
-
|
|
161
|
-
|
|
153
|
+
# The count below reports wc's status, never dd's: a missing dd or an unreadable file ends here,
|
|
154
|
+
# and a dd that fails anyway counts zero bytes, which is refused like an oversized census.
|
|
155
|
+
[ -f "$1" ] && [ -r "$1" ] && command -v dd >/dev/null 2>&1 || return 1
|
|
156
|
+
served_size=$( { dd if="$1" bs=65537 count=1 2>/dev/null | wc -c; } 2>/dev/null ) || return 1
|
|
157
|
+
[ "$served_size" -gt 0 ] 2>/dev/null && [ "$served_size" -le 65536 ] 2>/dev/null || return 1
|
|
162
158
|
awk '
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
{ prev = last; last = $0 }
|
|
160
|
+
bad || done { next }
|
|
161
|
+
NR == 1 { if ($0 != "{") bad = 1; next }
|
|
162
|
+
NR == 2 { if ($0 != " \\"runtimes\\": [") bad = 1; next }
|
|
163
|
+
NR == 3 { if ($0 != " {") bad = 1; next }
|
|
164
|
+
inside {
|
|
165
|
+
if ($0 == " ]" || $0 == " ],") { inside = 0; closed = 1; next }
|
|
166
|
+
line = $0; sub(/,$/, "", line)
|
|
167
|
+
if (line !~ /^ "\\/[^"\\\\]*"$/ || ++count > 2) { bad = 1; next }
|
|
168
|
+
path[count] = substr(line, 10, length(line) - 10); next
|
|
169
|
+
}
|
|
170
|
+
$0 == " \\"command\\": [" { if (closed) bad = 1; else inside = 1; next }
|
|
171
|
+
$0 == " }" || $0 == " }," { done = 1 }
|
|
172
|
+
END {
|
|
173
|
+
if (bad || !done || !closed || !count || prev != " ]" || last != "}") exit 1
|
|
174
|
+
for (i = 1; i <= count; i++) print path[i]
|
|
169
175
|
}
|
|
170
|
-
|
|
171
|
-
' "$1"
|
|
176
|
+
' "$1" 2>/dev/null
|
|
172
177
|
}
|
|
173
178
|
`;
|
|
174
179
|
|
|
175
180
|
/**
|
|
176
181
|
* Tries the served install with \`attempt\`, which must read \`$served_bin\` and honour \`$ocx_entry\`:
|
|
177
182
|
* a compiled binary runs alone, and a package pair runs as \`bun <entry>\` only while the entry exists.
|
|
183
|
+
* The unquoted \`OCX_SERVED\` heredoc is safe only because \`served_runtime\` prints paths without
|
|
184
|
+
* quotes, backslashes or newlines; relaxing that character class would let a path expand or split.
|
|
178
185
|
*/
|
|
179
186
|
export function remoteServedRuntimeAttempt(attempt: string): string {
|
|
180
187
|
return `served_bin= served_entry=
|
|
@@ -192,6 +199,17 @@ OCX_SERVED
|
|
|
192
199
|
fi`;
|
|
193
200
|
}
|
|
194
201
|
|
|
202
|
+
/**
|
|
203
|
+
* The remote sh script for every ocx call. `quoteRemote` single-quotes it, so the login shell
|
|
204
|
+
* passes it through untouched and `$HOME`/`$PATH` expand in the remote `sh`; the arguments reach
|
|
205
|
+
* ocx as `"$@"` without another round of parsing. After an ephemeral ocx-child, the install that
|
|
206
|
+
* last started serving this home comes first, whatever its version (#8359): every `ocx start` that binds records its own
|
|
207
|
+
* relaunch argv at the front of `serving-runtimes.json` (src/config/serving-runtimes.ts), `[ocx]`
|
|
208
|
+
* for a compiled binary or `[bun, cli/index.ts]` for a package install. Only the first entry's
|
|
209
|
+
* `command`, one or two absolute paths without quotes or backslashes, is read; any other shape
|
|
210
|
+
* falls through. Desktop binaries then precede PATH candidates; each candidate must run --version
|
|
211
|
+
* successfully. A missing runnable ocx exits 127.
|
|
212
|
+
*/
|
|
195
213
|
const REMOTE_OCX_CANDIDATES = `ocx_entry=
|
|
196
214
|
${REMOTE_SERVED_RUNTIME}run_ocx_child() {
|
|
197
215
|
for candidate in "$HOME/.local/bin/ocx-child" "$HOME/.cache/opencodex/bin/ocx-child"; do
|
|
@@ -304,7 +322,55 @@ export function quoteRemote(argv: readonly string[]): string {
|
|
|
304
322
|
}).join(" ");
|
|
305
323
|
}
|
|
306
324
|
|
|
307
|
-
|
|
325
|
+
/** Minimum served ocx for a gated command. Closed set: the literals are spliced into awk and PowerShell. */
|
|
326
|
+
export type GatedMinVersion = "2.93.0" | "2.97.0";
|
|
327
|
+
export type GatedLacksMarker = "child-ocx-lacks-expect-link" | "child-ocx-lacks-orchestrated-update";
|
|
328
|
+
export interface GatedOcxCommand {
|
|
329
|
+
minVersion: GatedMinVersion;
|
|
330
|
+
lacksMarker: GatedLacksMarker;
|
|
331
|
+
/** false: a selected ocx-child exits 121 with ocx-fanout:child-ocx-ephemeral before args run. */
|
|
332
|
+
acceptEphemeral: boolean;
|
|
333
|
+
/** true: print ocx-fanout:entry:pair|binary on stderr right after the selection marker. */
|
|
334
|
+
reportEntry: boolean;
|
|
335
|
+
/** true: print ocx-fanout:child-now:<epoch-ms> (the Child's own clock) after the entry marker. Plan probe only. */
|
|
336
|
+
reportClock: boolean;
|
|
337
|
+
/** With acceptEphemeral, print ocx-fanout:selected-kind:ocx-child when the selected candidate is ocx-child.
|
|
338
|
+
* Set only by remotePinnedSyncArgv when a restart is requested (ocx-child ignores the restart flags). */
|
|
339
|
+
reportSelectedKind?: boolean;
|
|
340
|
+
args: readonly string[];
|
|
341
|
+
}
|
|
342
|
+
export const GATED_VERSION_PARTS: Readonly<Record<GatedMinVersion, readonly [string, string, string]>> = {
|
|
343
|
+
"2.93.0": ["2", "93", "0"], "2.97.0": ["2", "97", "0"],
|
|
344
|
+
};
|
|
345
|
+
const LACKS_MARKERS: ReadonlySet<string> = new Set(["child-ocx-lacks-expect-link", "child-ocx-lacks-orchestrated-update"]);
|
|
346
|
+
export const LINK_ID_PATTERN = /^lnk_[0-9a-f]{16}$/;
|
|
347
|
+
|
|
348
|
+
function assertGated(cmd: GatedOcxCommand): readonly [string, string, string] {
|
|
349
|
+
const parts = Object.hasOwn(GATED_VERSION_PARTS, cmd.minVersion) ? GATED_VERSION_PARTS[cmd.minVersion] : undefined;
|
|
350
|
+
if (!parts || !LACKS_MARKERS.has(cmd.lacksMarker)) throw new LinkSshArgumentError("invalid gated ocx command");
|
|
351
|
+
if (cmd.args.length === 0 || cmd.args.some(arg => arg.includes("\0"))) throw new LinkSshArgumentError("invalid gated ocx arguments");
|
|
352
|
+
return parts;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The pinned script for one gate: select a candidate, read its version inside the remote script, refuse below the
|
|
357
|
+
* minimum, then exec it with "$@". OCX_NO_DESKTOP_HANDOFF=1 makes a package launcher answer --version for itself and
|
|
358
|
+
* run the command itself, so a Desktop handoff can never pass the gate on behalf of an older launcher.
|
|
359
|
+
*/
|
|
360
|
+
function remoteGatedScript(cmd: GatedOcxCommand): string {
|
|
361
|
+
const [major, minor, patch] = assertGated(cmd);
|
|
362
|
+
const ephemeral = cmd.acceptEphemeral ? "" : `
|
|
363
|
+
case "\${c##*/}" in ocx-child*) printf '%s\\n' 'ocx-fanout:child-ocx-ephemeral' >&2; exit 121;; esac`;
|
|
364
|
+
// Only a pinned sync that carries a restart asks for this, so the plain sync's stderr stays exact.
|
|
365
|
+
const kind = cmd.acceptEphemeral && cmd.reportSelectedKind ? `
|
|
366
|
+
case "\${c##*/}" in ocx-child*) printf '%s\\n' 'ocx-fanout:selected-kind:ocx-child' >&2;; esac` : "";
|
|
367
|
+
const entry = cmd.reportEntry ? `
|
|
368
|
+
if [ -n "$ocx_entry" ]; then printf '%s\\n' 'ocx-fanout:entry:pair' >&2; else printf '%s\\n' 'ocx-fanout:entry:binary' >&2; fi` : "";
|
|
369
|
+
// Seconds resolution is enough for a 120 s window; a date(1) that prints nothing numeric prints no marker.
|
|
370
|
+
const clock = cmd.reportClock ? `
|
|
371
|
+
now=$(date +%s 2>/dev/null); case "$now" in ''|*[!0-9]*) ;; *) printf 'ocx-fanout:child-now:%s000\\n' "$now" >&2;; esac` : "";
|
|
372
|
+
return `export PATH="$PATH:$HOME/.bun/bin:$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin"
|
|
373
|
+
export OCX_NO_DESKTOP_HANDOFF=1
|
|
308
374
|
case "$(uname -s 2>/dev/null)" in Windows*|MSYS*|MINGW*|CYGWIN*) exit ${REMOTE_PLATFORM_UNSUPPORTED};; esac
|
|
309
375
|
umask 077
|
|
310
376
|
dir=$(mktemp -d "\${TMPDIR:-/tmp}/ocx-fanout.XXXXXXXX") || exit 127
|
|
@@ -335,22 +401,50 @@ try_ocx() {
|
|
|
335
401
|
dash=index(v,"-"); if(dash) { pre=substr(v,dash+1); v=substr(v,1,dash-1); if(!idlist(pre,1)) {result=2; next} }
|
|
336
402
|
if(split(v,a,/\\./)!=3) { result=2; next }
|
|
337
403
|
for(i=1;i<=3;i++) if(a[i] !~ /^(0|[1-9][0-9]*)$/) { result=2; next }
|
|
338
|
-
c=cmp(a[1],"
|
|
404
|
+
c=cmp(a[1],"${major}"); if(!c)c=cmp(a[2],"${minor}"); if(!c)c=cmp(a[3],"${patch}"); if(c<0 || (!c && dash))result=1
|
|
339
405
|
}
|
|
340
406
|
NR>1 {result=2}
|
|
341
407
|
END {exit result}
|
|
342
408
|
' 2>/dev/null
|
|
343
409
|
status=$?
|
|
344
|
-
if [ "$status" -eq 1 ]; then printf '%s\\n' 'ocx-fanout
|
|
345
|
-
if [ "$status" -ne 0 ]; then printf '%s\\n' 'ocx-fanout:child-ocx-version-unknown' >&2; exit 121; fi
|
|
410
|
+
if [ "$status" -eq 1 ]; then printf '%s\\n' 'ocx-fanout:${cmd.lacksMarker}' >&2; exit 121; fi
|
|
411
|
+
if [ "$status" -ne 0 ]; then printf '%s\\n' 'ocx-fanout:child-ocx-version-unknown' >&2; exit 121; fi${ephemeral}
|
|
346
412
|
rm -rf "$dir"; trap - EXIT HUP INT TERM
|
|
347
|
-
printf 'ocx-fanout:selected:%s\\n' "$version" >&2
|
|
413
|
+
printf 'ocx-fanout:selected:%s\\n' "$version" >&2${kind}${entry}${clock}
|
|
348
414
|
printf '%s\\n' 'ocx-fanout:stdout-begin'
|
|
349
|
-
exec "$c" \${ocx_entry:+"$ocx_entry"}
|
|
415
|
+
exec "$c" \${ocx_entry:+"$ocx_entry"} "$@"
|
|
350
416
|
}
|
|
351
417
|
${REMOTE_OCX_CANDIDATES}
|
|
352
418
|
exit ${REMOTE_COMMAND_NOT_FOUND}`;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function remoteGatedOcxArgv(cmd: GatedOcxCommand, platform: "posix" | "windows" = "posix"): string[] {
|
|
422
|
+
const versionParts = assertGated(cmd);
|
|
423
|
+
if (platform === "windows") {
|
|
424
|
+
// A dropped channel kills the orchestrating parent with the Job, so no Windows apply is ever built (D20).
|
|
425
|
+
if (cmd.args[0] === "update" && cmd.args.includes("--yes")) throw new LinkSshArgumentError("unsupported:windows-apply");
|
|
426
|
+
try {
|
|
427
|
+
return windowsGatedOcxArgv({ ...cmd, versionParts });
|
|
428
|
+
} catch (error) {
|
|
429
|
+
if (error instanceof PowerShellCommandTooLongError) throw new LinkSshArgumentError("windows-command-too-long");
|
|
430
|
+
throw error;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return ["sh", "-c", remoteGatedScript(cmd), "ocx", ...cmd.args];
|
|
434
|
+
}
|
|
353
435
|
|
|
354
|
-
export
|
|
355
|
-
|
|
436
|
+
export type ChildRestartRequest = "app-server" | "codex";
|
|
437
|
+
export interface PinnedSyncOptions { restart?: ChildRestartRequest }
|
|
438
|
+
const RESTART_FLAG: Readonly<Record<ChildRestartRequest, string>> = { "app-server": "--restart-app-server-only", codex: "--restart-codex" };
|
|
439
|
+
|
|
440
|
+
export function remotePinnedSyncArgv(linkId: string, platform: "posix" | "windows" = "posix", opts: PinnedSyncOptions = {}): string[] {
|
|
441
|
+
if (!LINK_ID_PATTERN.test(linkId)) throw new LinkSshArgumentError("invalid link id");
|
|
442
|
+
if (opts.restart !== undefined && !Object.hasOwn(RESTART_FLAG, opts.restart)) throw new LinkSshArgumentError("invalid restart request");
|
|
443
|
+
// D20: the Home never sends a restart to a Windows Child.
|
|
444
|
+
if (opts.restart !== undefined && platform === "windows") throw new LinkSshArgumentError("unsupported:windows-restart");
|
|
445
|
+
const restart = opts.restart === undefined ? [] : [RESTART_FLAG[opts.restart]];
|
|
446
|
+
return remoteGatedOcxArgv({ minVersion: "2.93.0", lacksMarker: "child-ocx-lacks-expect-link", acceptEphemeral: true,
|
|
447
|
+
reportEntry: false, reportClock: false, reportSelectedKind: restart.length > 0,
|
|
448
|
+
args: ["sync", "--expect-link", linkId, "--json", ...restart] }, platform);
|
|
356
449
|
}
|
|
450
|
+
|
|
@@ -6,6 +6,11 @@ import { EMPTY_LINK_CHILD_PARITY, type LinkChildParity } from "./child-parity";
|
|
|
6
6
|
import { linkPeerStatus, type LinkLocalPeer, type LinkPeerStatus } from "./compatibility";
|
|
7
7
|
import type { LinkPeerEntry } from "./peer-report";
|
|
8
8
|
import type { OcxClientConnectionConfig } from "../types";
|
|
9
|
+
import { isLinkIdle, type LinkActivitySnapshot } from "./child-activity";
|
|
10
|
+
import { catalogVerdict, type CatalogPull, type CatalogRevision, type CatalogState } from "./child-catalog-freshness";
|
|
11
|
+
import type { ChildObservation, ChildOp, ChildOperationSummary } from "./child-observations";
|
|
12
|
+
import type { InstallKind, UpdateRoute } from "./child-update-contract";
|
|
13
|
+
import { compareStrictSemver, parseStrictSemver } from "../lib/strict-semver";
|
|
9
14
|
|
|
10
15
|
export type LinkWireState = "connecting" | "connected" | "reconnecting" | "failed" | "idle";
|
|
11
16
|
|
|
@@ -25,6 +30,8 @@ export interface LinkStatusDto {
|
|
|
25
30
|
peer?: LinkPeerStatus;
|
|
26
31
|
/** Home-initiated links on request (`?diagnostics=1`): retry progress and the last failure. */
|
|
27
32
|
tunnel?: LinkTunnelDiagnostics;
|
|
33
|
+
/** Home rows on request (`?children=1`): versions, update route, catalog freshness, activity and operations. */
|
|
34
|
+
child?: LinkChildOpsStatus;
|
|
28
35
|
}>;
|
|
29
36
|
child: null | {
|
|
30
37
|
alias: string;
|
|
@@ -82,6 +89,72 @@ export function attachLinkPeers(dto: LinkStatusDto, local: LinkLocalPeer, observ
|
|
|
82
89
|
return dto;
|
|
83
90
|
}
|
|
84
91
|
|
|
92
|
+
/** One Home row's `child` block. `codex` stays null until the Child reports its Codex state (wp8). */
|
|
93
|
+
export interface LinkChildOpsStatus {
|
|
94
|
+
homeVersion: string; runningVersion: string | null; installedVersion: string | null; installKind: InstallKind | null;
|
|
95
|
+
versionSkew: "same" | "behind" | "ahead" | "unknown";
|
|
96
|
+
update: { route: UpdateRoute | null; reason: string | null; observedAt: string | null };
|
|
97
|
+
catalog: { state: CatalogState; pulledAt: number | null; homeChangedAt: number | null };
|
|
98
|
+
codex: null;
|
|
99
|
+
activity: { idle: boolean; inFlight: number; lastDataEndAt: number | null };
|
|
100
|
+
activeJob: { jobId: string; op: ChildOp; state: "queued" | "running" } | null;
|
|
101
|
+
lastOperation: ChildOperationSummary | null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface LinkChildOpsSources {
|
|
105
|
+
homeVersion: string; now: number; idleAfterMs: number;
|
|
106
|
+
peerVersion(linkId: string): string | null; observation(linkId: string): ChildObservation | null;
|
|
107
|
+
activity(linkId: string): LinkActivitySnapshot | null; catalogPull(linkId: string): CatalogPull | null;
|
|
108
|
+
revision: CatalogRevision | null; activeJob(linkId: string): LinkChildOpsStatus["activeJob"];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function versionSkew(version: string | null, homeVersion: string): LinkChildOpsStatus["versionSkew"] {
|
|
112
|
+
const child = parseStrictSemver(version);
|
|
113
|
+
const home = parseStrictSemver(homeVersion);
|
|
114
|
+
if (!child || !home) return "unknown";
|
|
115
|
+
const order = compareStrictSemver(child, home);
|
|
116
|
+
return order === 0 ? "same" : order < 0 ? "behind" : "ahead";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The newer of the relay's in-memory pull and the cached one. */
|
|
120
|
+
function latestPull(memory: CatalogPull | null, cached: ChildObservation | null): CatalogPull | null {
|
|
121
|
+
const stored = cached?.catalogPulledAt != null && cached.catalogPulledEtag != null ? { at: cached.catalogPulledAt, etag: cached.catalogPulledEtag } : null;
|
|
122
|
+
if (!memory) return stored;
|
|
123
|
+
return stored && stored.at > memory.at ? stored : memory;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Home rows only. Skew compares installed ?? running with homeVersion; ocx-child and unparsable versions are "unknown".
|
|
128
|
+
* An entry observe never wrote (source "inspect" with route "none", the default a carried-only write creates) reads as
|
|
129
|
+
* not observed. Missing activity reads busy, never idle.
|
|
130
|
+
*/
|
|
131
|
+
export function attachLinkChildOps(dto: LinkStatusDto, sources: LinkChildOpsSources): LinkStatusDto {
|
|
132
|
+
if (dto.role !== "home") return dto;
|
|
133
|
+
for (const link of dto.links) {
|
|
134
|
+
const cached = sources.observation(link.id);
|
|
135
|
+
const observed = cached && !(cached.source === "inspect" && cached.updateRoute === "none") ? cached : null;
|
|
136
|
+
const runningVersion = parseStrictSemver(sources.peerVersion(link.id)) ? sources.peerVersion(link.id) : null;
|
|
137
|
+
const installedVersion = observed?.installedVersion ?? null;
|
|
138
|
+
const installKind = observed?.installKind ?? null;
|
|
139
|
+
const ocxChild = installKind === "ocx-child" || link.childKind === "ephemeral";
|
|
140
|
+
const pull = latestPull(sources.catalogPull(link.id), cached);
|
|
141
|
+
const snapshot = sources.activity(link.id);
|
|
142
|
+
link.child = {
|
|
143
|
+
homeVersion: sources.homeVersion, runningVersion, installedVersion, installKind,
|
|
144
|
+
versionSkew: ocxChild ? "unknown" : versionSkew(installedVersion ?? runningVersion, sources.homeVersion),
|
|
145
|
+
update: observed ? { route: observed.updateRoute, reason: observed.updateReason, observedAt: observed.observedAt } : { route: null, reason: null, observedAt: null },
|
|
146
|
+
catalog: { state: catalogVerdict(pull?.etag ?? null, cached?.catalogSyncedEtag ?? null, sources.revision), pulledAt: pull?.at ?? null,
|
|
147
|
+
homeChangedAt: sources.revision?.changedAt ?? null },
|
|
148
|
+
codex: null,
|
|
149
|
+
activity: snapshot ? { idle: isLinkIdle(snapshot, sources.now, sources.idleAfterMs), inFlight: snapshot.inFlight, lastDataEndAt: snapshot.lastDataEndAt }
|
|
150
|
+
: { idle: false, inFlight: 0, lastDataEndAt: null },
|
|
151
|
+
activeJob: sources.activeJob(link.id),
|
|
152
|
+
lastOperation: cached?.lastOperation ?? null,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return dto;
|
|
156
|
+
}
|
|
157
|
+
|
|
85
158
|
export interface ClientLinkIdentity { direction: "hub-initiated" | "client-initiated"; alias?: string }
|
|
86
159
|
|
|
87
160
|
export interface LinkListenerStatusProjection {
|