Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,9 @@ zcode

## Official MCP Availability

When the bundled runtime has no official MCP trusted-origin registry, official
HTTP MCP services are reported as disabled with an `official_auth_unavailable`
diagnostic. Other plugin components remain available. This does not disable
certificate, origin, or permission checks, and does not suppress services when
the runtime provides the required registry. No user configuration is rewritten.
Official HTTP MCP services that use ZCode's trusted-origin authentication
require the runtime host to provide its trusted-origin registry and auth-header
port. If those host capabilities are unavailable, the runtime fails that
service connection and reports that the official MCP trusted-origin registry is
unavailable. Other MCP services remain available. No user configuration is
rewritten, and certificate, origin, and permission checks remain enabled.
9 changes: 1 addition & 8 deletions scripts/check-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { runtimeTestEnv } from "./runtime-test-env.ts";
import {
extractRuntimeCapabilities,
hasRuntimeAppServerStandaloneAuth,
hasRuntimeBigmodelOAuth,
hasRuntimeBrowserUrlOpening,
hasRuntimeConfigurationDiagnostics,
hasRuntimeCliSettingsFile,
Expand All @@ -33,12 +32,10 @@ import {
hasRuntimeStreamEofFinishGuard,
hasRuntimeTrackedDetachedAgentLifecycle,
patchRuntimeGoalFailurePause,
patchRuntimeHttpNoContent,
patchRuntimeHeadlessLifecycle,
patchRuntimeLoginModelDefaults,
hasRuntimeNativePollingOAuth,
patchRuntimeNetworkRetryClassification,
patchRuntimeOfficialMcpAvailability,
patchRuntimeSqliteBusyTimeout,
patchRuntimeSqliteWriteRecovery,
patchRuntimeStreamEofFinishGuard,
Expand Down Expand Up @@ -99,9 +96,7 @@ if (!metadataCapabilities
throw new Error("The extracted runtime capability manifest is missing or stale; run `bun run sync` again.");
}
if (patchRuntimeLoginModelDefaults(runtimeSource) !== runtimeSource
|| (patchEnabled("official-mcp-availability") && patchRuntimeOfficialMcpAvailability(runtimeSource) !== runtimeSource)
|| (patchEnabled("goal-failure-pause") && patchRuntimeGoalFailurePause(runtimeSource) !== runtimeSource)
|| patchRuntimeHttpNoContent(runtimeSource) !== runtimeSource
|| !hasRuntimeHttpNoContentGuard(runtimeSource)
|| patchRuntimeHeadlessLifecycle(runtimeSource) !== runtimeSource
|| !hasRuntimeHeadlessLifecycle(runtimeSource)
Expand All @@ -116,7 +111,6 @@ if (patchRuntimeLoginModelDefaults(runtimeSource) !== runtimeSource
|| !hasRuntimeStreamEofFinishGuard(runtimeSource)
|| (patchEnabled("cli-help-contract") && !hasRuntimeCliHelpContract(runtimeSource))
|| !hasRuntimeAppServerStandaloneAuth(runtimeSource)
|| !hasRuntimeBigmodelOAuth(runtimeSource)
|| !hasRuntimeBrowserUrlOpening(runtimeSource)
|| !hasRuntimeConfigurationDiagnostics(runtimeSource)
|| !hasRuntimeRecursiveWorkspacePaths(runtimeSource)
Expand Down Expand Up @@ -165,8 +159,7 @@ if (patchRuntimeLoginModelDefaults(runtimeSource) !== runtimeSource
|| (patchEnabled("agent-auto-background")
&& !runtimeSource.includes("autoBackgroundMs:this.config.subagents?.autoBackgroundMs??1e3,outputRootDir:"))
|| (patchEnabled("detached-agent-lifecycle")
&& !hasRuntimeTrackedDetachedAgentLifecycle(runtimeSource)
&& runtimeSource.split("Detached background agent lifecycle failed").length < 3)
&& !hasRuntimeTrackedDetachedAgentLifecycle(runtimeSource))
|| !runtimeSource.includes('e?.waitForIdle===!0&&t.runtime?.getActiveForegroundExecutionId')
|| (patchEnabled("terminal-tool-projection")
&& !runtimeSource.includes('status:"idle",currentTurnId:void 0,activeToolCalls:[],totalTokenCount:'))
Expand Down
118 changes: 0 additions & 118 deletions scripts/runtime-bigmodel-oauth-patches.ts

This file was deleted.

49 changes: 49 additions & 0 deletions scripts/runtime-oauth-polling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { parseExpressionAt, type FunctionExpression } from "acorn";

const identifier = "[A-Za-z_$][\\w$]*";

function unique<T>(values: T[], anchor: string): T {
if (values.length !== 1) throw new Error(`ZCode runtime is missing native OAuth polling support (${anchor}).`);
return values[0]!;
}

function symbol(runtime: string, label: string): string {
return unique(
[...runtime.matchAll(new RegExp(`${identifier}\\((${identifier}),"${label}"\\)`, "gu"))],
label
)[1]!;
}

function escape(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
}

function namedFunction(runtime: string, label: string): FunctionExpression {
const name = symbol(runtime, label);
const match = unique(
[...runtime.matchAll(new RegExp(`(?:async )?function ${name}\\(`, "gu"))],
`${label} function`
);
const fn = parseExpressionAt(runtime, match.index!, { ecmaVersion: "latest" });
if (fn.type !== "FunctionExpression" || fn.id?.name !== name) {
throw new Error(`ZCode runtime changed the native ${label} function.`);
}
return fn;
}

/** Verify the Z.AI and BigModel OAuth polling flow implemented by the pinned runtime. */
export function hasRuntimeNativePollingOAuth(runtime: string): boolean {
try {
const login = namedFunction(runtime, "loginZCodeCli");
const wrapper = namedFunction(runtime, "loginBigmodelCodingPlan");
const polling = symbol(runtime, "pollUntilReady");
const body = runtime.slice(login.body.start + 1, login.body.end - 1);
const delegation = runtime.slice(wrapper.body.start + 1, wrapper.body.end - 1);
return new RegExp(`${escape(login.id!.name)}\\(\\{\\.\\.\.${identifier},providerId:"bigmodel"\\}\\)`, "u").test(delegation)
&& body.includes(`${polling}({`)
&& body.includes('authSource:"oauth"')
&& /\[([A-Za-z_$][\w$]*)\.zcodeJwtToken\]:([A-Za-z_$][\w$]*)\.token,\[\1\.bigmodelAccessToken\]:\2\.accessToken,/u.test(body);
} catch {
return false;
}
}
Loading
Loading