@openclaw/copilot 2026.11.2 → 2026.11.4

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.
@@ -1,4 +1,4 @@
1
- import { a as createCopilotByokProxy, i as createPromptError, n as resolveCopilotProvider, o as createCopilotByokAuth, s as resolveCopilotAuth } from "./harness-Je_2Cj-D.mjs";
1
+ import { a as createCopilotByokProxy, i as createPromptError, n as resolveCopilotProvider, o as createCopilotByokAuth, s as resolveCopilotAuth } from "./harness-COUVzhZo.mjs";
2
2
  import { n as normalizeCopilotUsage, r as createCopilotIsolatedSessionRestrictions, t as buildCopilotAssistantUsage } from "./usage-bridge--rLPdCvV.mjs";
3
3
  import { asNonArrayRecord, asOptionalObjectRecord, asOptionalRecord, normalizeOptionalString, normalizeUniqueStringEntries, readNonBlankString, readNonEmptyStringPreservingWhitespace, readNonEmptyStringPreservingWhitespace as readNonEmptyString } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  import { SKILL_WORKSHOP_TOOL_NAME, applyEmbeddedAttemptToolsAllow, awaitAgentEndSideEffects, buildAgentHookContextChannelFields, buildCredentialSafetyPrompt, buildDelegationGuidanceSection, buildEmbeddedAttemptToolRunContext, buildEmbeddedForegroundPromptContext, buildHarnessVisibleReplyGuidance, buildSkillWorkshopPromptSection, cancelPendingAgentQuestionForSession, claimPendingAgentQuestionAnswer, clearActiveEmbeddedRun, detectAndLoadAgentHarnessPromptImages, embeddedAgentLog, emitAgentEvent, extractToolErrorMessage, getModelProviderRequestTransport, getPluginToolMeta, getPluginToolSideEffectOwnerKey, isHostScopedAgentToolActive, isSubagentSessionKey, isToolResultError, projectAgentHarnessTranscriptMessageForDisplay, projectAgentToolActivity, resolveAgentDir, resolveAgentHarnessBeforePromptBuildResult, resolveAttemptFsWorkspaceOnly, resolveAttemptSpawnWorkspaceDir, resolveBootstrapContextForRun, resolveCompactionTimeoutMs, resolveEmbeddedAttemptToolConstructionPlan, resolveMainSessionDelegationMode, resolveModelAuthModeAsync, resolveSandboxContext, resolveUserPath, restorePreparedUserTurnOperationalMetaForRuntime, runAgentEndSideEffectsAsync, runAgentHarnessAfterCompactionHook, runAgentHarnessAfterToolCallHook, runAgentHarnessBeforeCompactionHook, runAgentHarnessBeforeMessageWriteHook, runAgentHarnessGatewayQuestion, runAgentHarnessLlmInputHook, runAgentHarnessLlmOutputHook, sanitizeToolResult, setActiveEmbeddedRun } from "openclaw/plugin-sdk/agent-harness-runtime";
@@ -221,6 +221,7 @@ function createResult(params, state) {
221
221
  } : { kind: "ok" };
222
222
  return {
223
223
  terminal: promptError !== void 0 ? withPromptFailure(interruption, promptError) : interruption,
224
+ ...state.runtimeArtifact ? { runtimeArtifact: state.runtimeArtifact } : {},
224
225
  ...state.acceptedSessionSpawns?.length ? { acceptedSessionSpawns: state.acceptedSessionSpawns } : {},
225
226
  ...state.assistantTranscriptOwned ? {
226
227
  assistantTranscriptOwned: true,
@@ -1045,6 +1046,28 @@ function splitPlanText(text) {
1045
1046
  }
1046
1047
  //#endregion
1047
1048
  //#region extensions/copilot/src/attempt-cleanup.ts
1049
+ /** Deletion follows disconnect even when disconnect fails; the first cleanup failure wins. */
1050
+ async function disconnectCopilotSession(params) {
1051
+ let failure;
1052
+ try {
1053
+ await params.session.disconnect();
1054
+ } catch (error) {
1055
+ failure = toCopilotError(error);
1056
+ }
1057
+ if (params.deleteSessionId) try {
1058
+ await params.client.deleteSession(params.deleteSessionId);
1059
+ } catch (error) {
1060
+ failure ??= toCopilotError(error);
1061
+ }
1062
+ if (failure) throw failure;
1063
+ }
1064
+ function preserveCopilotAttemptCleanupError(primary, error) {
1065
+ if (primary) {
1066
+ console.warn("[copilot-attempt] detached session cleanup failed after primary error", error);
1067
+ return primary;
1068
+ }
1069
+ return toCopilotError(error);
1070
+ }
1048
1071
  async function finalizeCopilotAttempt(params, result, ctx, attemptStartedAt, now) {
1049
1072
  const failure = result.terminal.kind === "failed" ? { error: result.terminal.error } : result.terminal.kind === "ok" ? void 0 : result.terminal.failure;
1050
1073
  const aborted = result.terminal.kind === "aborted" && result.terminal.source !== "yield_cleanup";
@@ -1064,6 +1087,7 @@ async function finalizeCopilotAttempt(params, result, ctx, attemptStartedAt, now
1064
1087
  }
1065
1088
  async function deferBackgroundCompactionCleanup(params) {
1066
1089
  let outcome = "deadline";
1090
+ let cleanupError;
1067
1091
  try {
1068
1092
  outcome = await awaitDeferredCleanupBeforeDeadline({
1069
1093
  abortSignal: params.abortSignal,
@@ -1078,18 +1102,28 @@ async function deferBackgroundCompactionCleanup(params) {
1078
1102
  }
1079
1103
  params.bridge.detach();
1080
1104
  await params.bridge.awaitAgentEventChain();
1081
- try {
1082
- await params.session.disconnect();
1083
- } catch {}
1084
1105
  params.cleanupToolBridge?.();
1085
- await params.cleanupByokProxy?.();
1086
- if (outcome !== "completed" && params.deleteSessionOnIncompleteCleanup && params.sdkSessionId) try {
1087
- await params.handle.client.deleteSession(params.sdkSessionId);
1088
- } catch {}
1106
+ try {
1107
+ await params.cleanupByokProxy?.();
1108
+ } catch (error) {
1109
+ cleanupError ??= toCopilotError(error);
1110
+ }
1111
+ try {
1112
+ await disconnectCopilotSession({
1113
+ session: params.session,
1114
+ client: params.handle.client,
1115
+ deleteSessionId: params.deleteSessionOnCleanup || outcome !== "completed" && params.deleteSessionOnIncompleteCleanup ? params.sdkSessionId : void 0
1116
+ });
1117
+ } catch (error) {
1118
+ if (params.deleteSessionOnCleanup) cleanupError ??= toCopilotError(error);
1119
+ }
1089
1120
  try {
1090
1121
  await params.pool.release(params.handle);
1091
- } catch {}
1122
+ } catch (error) {
1123
+ if (params.deleteSessionOnCleanup) cleanupError ??= toCopilotError(error);
1124
+ }
1092
1125
  }
1126
+ if (cleanupError) throw cleanupError;
1093
1127
  return outcome;
1094
1128
  }
1095
1129
  async function cancelBackgroundCompactionBeforeTeardown(session) {
@@ -1285,6 +1319,7 @@ async function completeCopilotAttempt(params) {
1285
1319
  const currentRunUserKey = `${input.runId}:user`;
1286
1320
  const messagesSnapshot = transcript?.messagesSnapshot ?? (recorder?.isBlocked() ? removePreparedUser(messages, recorder.message, currentRunUserKey) : includePreparedUser(messages, recorder?.message, input.trigger === "memory", currentRunUserKey));
1287
1321
  const result = createResult(input, {
1322
+ runtimeArtifact: params.runtimeArtifact,
1288
1323
  acceptedSessionSpawns,
1289
1324
  aborted,
1290
1325
  assistantTexts,
@@ -1436,7 +1471,9 @@ async function createCopilotToolBridge(input) {
1436
1471
  const runInAttemptContext = AsyncLocalStorage.snapshot();
1437
1472
  let sequentialBarrier = Promise.resolve();
1438
1473
  const pendingCalls = /* @__PURE__ */ new Set();
1474
+ let acceptingCalls = true;
1439
1475
  const scheduleToolExecution = (executionMode, execute) => {
1476
+ if (!acceptingCalls) return Promise.reject(/* @__PURE__ */ new Error("[copilot-tool-bridge] attempt is closing"));
1440
1477
  const run = (executionMode === "sequential" ? Promise.all(pendingCalls) : sequentialBarrier).then(() => runInAttemptContext(execute));
1441
1478
  const settled = run.then(() => void 0, () => void 0);
1442
1479
  pendingCalls.add(settled);
@@ -1447,6 +1484,10 @@ async function createCopilotToolBridge(input) {
1447
1484
  const sdkTools = exposedTools.map((sourceTool) => convertOpenClawToolToSdkTool(sourceTool, input, scheduleToolExecution));
1448
1485
  return {
1449
1486
  cleanup: toolSurfaceRuntime.cleanup,
1487
+ settle: async () => {
1488
+ acceptingCalls = false;
1489
+ await Promise.all(pendingCalls);
1490
+ },
1450
1491
  codeModeEngaged: toolSurfaceRuntime.codeModeControlsEnabled,
1451
1492
  promptToolPolicy: {
1452
1493
  requireExplicitMessageTarget: toolOptions.requireExplicitMessageTarget,
@@ -2651,9 +2692,9 @@ async function runCopilotExecution(context) {
2651
2692
  let timedOut = false;
2652
2693
  let promptError;
2653
2694
  let sdkSessionId;
2695
+ let runtimeArtifact;
2654
2696
  let nativeSessionCreatedFresh = false;
2655
2697
  let nativeSessionHistoryValidated = false;
2656
- let disconnectError;
2657
2698
  let handle;
2658
2699
  let session;
2659
2700
  let bridge;
@@ -2662,6 +2703,8 @@ async function runCopilotExecution(context) {
2662
2703
  let activeRunHandleRef;
2663
2704
  let userInputBridgeRef;
2664
2705
  let cleanupToolBridge;
2706
+ let settleToolCalls;
2707
+ const detached = input.sessionPersistence === "detached";
2665
2708
  let releaseError;
2666
2709
  let downgradedFromResume = false;
2667
2710
  let resumeFailureRecovered = false;
@@ -2796,6 +2839,7 @@ async function runCopilotExecution(context) {
2796
2839
  }
2797
2840
  });
2798
2841
  cleanupToolBridge = toolBridge.cleanup;
2842
+ settleToolCalls = toolBridge.settle;
2799
2843
  codeModeEngaged = toolBridge.codeModeEngaged;
2800
2844
  promptToolPolicy = toolBridge.promptToolPolicy;
2801
2845
  resultContentSourceByToolName = new Map(toolBridge.sourceTools.flatMap((tool) => tool.resultContentSource ? [[tool.name, tool.resultContentSource]] : []));
@@ -2806,7 +2850,10 @@ async function runCopilotExecution(context) {
2806
2850
  sdkSessionId: void 0
2807
2851
  }));
2808
2852
  }
2809
- handle = await deps.pool.acquire(poolAcquire.key, poolAcquire.options);
2853
+ const artifactRequest = input.captureRuntimeArtifact || input.expectedRuntimeArtifact ? { expected: input.expectedRuntimeArtifact } : void 0;
2854
+ handle = artifactRequest ? await deps.pool.acquire(poolAcquire.key, poolAcquire.options, artifactRequest) : await deps.pool.acquire(poolAcquire.key, poolAcquire.options);
2855
+ runtimeArtifact = handle.runtimeArtifact;
2856
+ if (artifactRequest && !runtimeArtifact) throw new Error("[copilot] verified attempt requires a captured runtime artifact");
2810
2857
  const client = handle.client;
2811
2858
  const sessionSetup = await createCopilotSessionSetup({
2812
2859
  attempt: input,
@@ -2826,7 +2873,7 @@ async function runCopilotExecution(context) {
2826
2873
  });
2827
2874
  const { attemptInput, compactionSessionConfig, emitLlmInput, hasNativePromptHook, sessionConfig, userInputBridge } = sessionSetup;
2828
2875
  userInputBridgeRef = userInputBridge;
2829
- const previousSessionId = normalizeOptionalString(input.initialReplayState?.sdkSessionId);
2876
+ const previousSessionId = detached ? void 0 : normalizeOptionalString(input.initialReplayState?.sdkSessionId);
2830
2877
  downgradedFromResume = Boolean(previousSessionId && input.initialReplayState?.replayInvalid === true);
2831
2878
  const resumeSessionId = settledToolFinalization ? settledFinalizationSessionId : downgradedFromResume ? void 0 : previousSessionId;
2832
2879
  if (resumeSessionId) try {
@@ -2975,6 +3022,7 @@ async function runCopilotExecution(context) {
2975
3022
  }
2976
3023
  } finally {
2977
3024
  settled = true;
3025
+ if (detached) await settleToolCalls?.();
2978
3026
  try {
2979
3027
  bridge?.flushTranscriptProjection();
2980
3028
  await transcriptJournal?.barrier("bridge detach");
@@ -3000,16 +3048,22 @@ async function runCopilotExecution(context) {
3000
3048
  cleanupToolBridge,
3001
3049
  cleanupByokProxy,
3002
3050
  deleteSessionOnIncompleteCleanup: nativeSessionCreatedFresh && initialUserValidated,
3051
+ deleteSessionOnCleanup: detached && nativeSessionCreatedFresh,
3003
3052
  handle,
3004
3053
  pool: deps.pool,
3005
3054
  sdkSessionId,
3006
3055
  session,
3007
3056
  timeoutMs: resolveCompactionTimeoutMs(input.config)
3008
3057
  });
3058
+ if (detached) try {
3059
+ await cleanup;
3060
+ } catch (error) {
3061
+ promptError = preserveCopilotAttemptCleanupError(promptError, error);
3062
+ }
3009
3063
  cleanup.finally(() => {
3010
3064
  params.abortSignal?.removeEventListener("abort", abortCleanup);
3011
3065
  }).catch(() => void 0);
3012
- if (sdkSessionId && !settledToolFinalization) try {
3066
+ if (!detached && sdkSessionId && !settledToolFinalization) try {
3013
3067
  await deps.onDeferredCompaction?.({
3014
3068
  abort: () => cleanupAbort.abort(),
3015
3069
  cleanup,
@@ -3022,13 +3076,22 @@ async function runCopilotExecution(context) {
3022
3076
  bridge?.detach();
3023
3077
  await bridge?.awaitAgentEventChain();
3024
3078
  cleanupToolBridge?.();
3025
- await cleanupByokProxy?.();
3079
+ try {
3080
+ await cleanupByokProxy?.();
3081
+ } catch (error) {
3082
+ if (detached) promptError = preserveCopilotAttemptCleanupError(promptError, error);
3083
+ else releaseError = toCopilotError(error);
3084
+ }
3026
3085
  params.abortSignal?.removeEventListener("abort", abortActiveSession);
3027
- if (session) try {
3028
- await session.disconnect();
3086
+ if (session && handle) try {
3087
+ await disconnectCopilotSession({
3088
+ session,
3089
+ client: handle.client,
3090
+ deleteSessionId: detached && nativeSessionCreatedFresh ? sdkSessionId : void 0
3091
+ });
3029
3092
  } catch (error) {
3030
- disconnectError = toCopilotError(error);
3031
- if (!promptError && !timedOut) promptError = disconnectError;
3093
+ if (detached) promptError = preserveCopilotAttemptCleanupError(promptError, error);
3094
+ else if (!promptError && !timedOut) promptError = toCopilotError(error);
3032
3095
  }
3033
3096
  if (handle) try {
3034
3097
  await deps.pool.release(handle);
@@ -3059,6 +3122,7 @@ async function runCopilotExecution(context) {
3059
3122
  promptError,
3060
3123
  releaseError,
3061
3124
  resumeFailureRecovered,
3125
+ runtimeArtifact,
3062
3126
  sdkSessionId,
3063
3127
  sentTurnStarted,
3064
3128
  settledFinalizationAssistantCompleted,
@@ -784,7 +784,7 @@ function createCopilotAgentHarness(options) {
784
784
  async function getPool() {
785
785
  if (options?.pool) return options.pool;
786
786
  if (!poolPromise) poolPromise = (async () => {
787
- const { createCopilotClientPool } = await import("./runtime-C0R_TFVt.mjs");
787
+ const { createCopilotClientPool } = await import("./runtime-CR54khkB.mjs");
788
788
  createdPool = createCopilotClientPool(options?.poolOptions);
789
789
  return createdPool;
790
790
  })();
@@ -821,7 +821,7 @@ function createCopilotAgentHarness(options) {
821
821
  async function runHarnessAttempt(params, operation) {
822
822
  return trackOperation(async () => {
823
823
  if (disposed) throw new Error("[copilot] harness has been disposed; cannot start new attempts");
824
- const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-Bu_STDE0.mjs");
824
+ const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-p6z8f4uh.mjs");
825
825
  if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
826
826
  const pool = await getPool();
827
827
  if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
@@ -934,7 +934,7 @@ function createCopilotAgentHarness(options) {
934
934
  async function runIsolatedCompletionV2(params) {
935
935
  return trackOperation(async () => {
936
936
  if (disposed) throw new Error("[copilot] harness has been disposed; cannot start isolated completion");
937
- const { runCopilotIsolatedCompletion } = await import("./isolated-completion-CrN9i842.mjs");
937
+ const { runCopilotIsolatedCompletion } = await import("./isolated-completion-Fk-6HR_a.mjs");
938
938
  if (disposed) throw new Error("[copilot] harness was disposed while starting isolated completion");
939
939
  return await runCopilotIsolatedCompletion(params, async () => {
940
940
  const pool = await getPool();
@@ -948,6 +948,10 @@ function createCopilotAgentHarness(options) {
948
948
  label: options?.label ?? "GitHub Copilot agent runtime",
949
949
  autoSelection: { providerIds: [] },
950
950
  conversationToolPolicySupport: "exact",
951
+ runtimeArtifact: { async validate(binding) {
952
+ const { validateCopilotRuntimeArtifact } = await import("./runtime-artifact-CwEwkNDm.mjs");
953
+ return await validateCopilotRuntimeArtifact(binding);
954
+ } },
951
955
  supports(ctx) {
952
956
  if (String(ctx.requestedRuntime ?? "").trim().toLowerCase() !== "copilot") return {
953
957
  supported: false,
@@ -1027,7 +1031,7 @@ function createCopilotAgentHarness(options) {
1027
1031
  if (await bindingQueue.enqueue(openclawSessionId, () => hasPendingDeferredCompactionCleanup(openclawSessionId))) return failedCompaction("background-compaction-pending");
1028
1032
  const tracked = trackedSessions.get(openclawSessionId);
1029
1033
  const currentCompactKey = computeCompactRequestKey(params);
1030
- const { resolvePoolAcquire } = await import("./attempt-Bu_STDE0.mjs");
1034
+ const { resolvePoolAcquire } = await import("./attempt-p6z8f4uh.mjs");
1031
1035
  let resolvedPoolAcquire;
1032
1036
  try {
1033
1037
  resolvedPoolAcquire = resolvePoolAcquire(params);
@@ -1,4 +1,4 @@
1
- import { a as createCopilotByokProxy, c as tokenFingerprint, n as resolveCopilotProvider, r as createCopilotAbortError } from "./harness-Je_2Cj-D.mjs";
1
+ import { a as createCopilotByokProxy, c as tokenFingerprint, n as resolveCopilotProvider, r as createCopilotAbortError } from "./harness-COUVzhZo.mjs";
2
2
  import { r as createCopilotIsolatedSessionRestrictions, t as buildCopilotAssistantUsage } from "./usage-bridge--rLPdCvV.mjs";
3
3
  import { asNonArrayRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  import { resolve } from "node:path";
@@ -1,87 +1,6 @@
1
- import { createRequire } from "node:module";
2
- import path, { resolve, sep } from "node:path";
1
+ import { n as loadCopilotSdk } from "./sdk-loader-CrnyZ1P8.mjs";
2
+ import { resolve, sep } from "node:path";
3
3
  import { toStringifiedError } from "openclaw/plugin-sdk/error-runtime";
4
- import { existsSync } from "node:fs";
5
- import { pathToFileURL } from "node:url";
6
- import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
7
- //#region extensions/copilot/package.json
8
- var dependencies = { "@github/copilot-sdk": "1.0.16" };
9
- //#endregion
10
- //#region extensions/copilot/src/sdk-loader.ts
11
- function resolveCopilotSdkFallbackDir(env = process.env) {
12
- return path.join(resolveStateDir(env), "npm-runtime", "copilot");
13
- }
14
- const COPILOT_SDK_SPEC = `@github/copilot-sdk@${dependencies["@github/copilot-sdk"]}`;
15
- let cached;
16
- async function loadCopilotSdk(options = {}) {
17
- const useCache = options.cache !== false;
18
- if (useCache && cached) return cached;
19
- const promise = doLoad(options);
20
- if (useCache) {
21
- cached = promise.catch((err) => {
22
- cached = void 0;
23
- throw err;
24
- });
25
- return cached;
26
- }
27
- return promise;
28
- }
29
- async function doLoad(options) {
30
- const fallbackDir = options.fallbackDir ?? resolveCopilotSdkFallbackDir();
31
- const primaryImport = options.primaryImport ?? (async () => await import("@github/copilot-sdk"));
32
- let primaryErr;
33
- try {
34
- return await primaryImport();
35
- } catch (err) {
36
- primaryErr = err;
37
- }
38
- const fallbackPath = path.join(fallbackDir, "node_modules", "@github", "copilot-sdk");
39
- if (!existsSync(fallbackPath)) throw createMissingSdkError(primaryErr, void 0, fallbackPath);
40
- const fallbackImport = options.fallbackImport ?? (async () => {
41
- const entry = createRequire(path.join(fallbackDir, "package.json")).resolve("@github/copilot-sdk");
42
- return await import(pathToFileURL(entry).href);
43
- });
44
- try {
45
- return await fallbackImport(fallbackPath);
46
- } catch (fallbackErr) {
47
- throw createMissingSdkError(primaryErr, fallbackErr, fallbackPath);
48
- }
49
- }
50
- function createMissingSdkError(primaryErr, fallbackErr, fallbackPath) {
51
- const lines = [
52
- "[copilot] @github/copilot-sdk is not installed.",
53
- "",
54
- "The external @openclaw/copilot plugin depends on @github/copilot-sdk",
55
- "including its platform-specific Copilot runtime package.",
56
- "Reinstall the plugin once with:",
57
- "",
58
- " openclaw plugins install @openclaw/copilot",
59
- "",
60
- "For source checkouts or offline repair, install the SDK directly:",
61
- "",
62
- ` npm install ${COPILOT_SDK_SPEC}`,
63
- "",
64
- `The legacy fallback location is still checked at\n ${fallbackPath}`,
65
- "",
66
- "Primary resolution error:",
67
- ` ${summarizeError(primaryErr)}`
68
- ];
69
- if (fallbackErr !== void 0) lines.push("", "Fallback resolution error:", ` ${summarizeError(fallbackErr)}`);
70
- const err = new Error(lines.join("\n"));
71
- err.code = "COPILOT_SDK_MISSING";
72
- return err;
73
- }
74
- function summarizeError(value) {
75
- if (value === void 0 || value === null) return "(none)";
76
- if (value instanceof Error) return value.message || String(value);
77
- if (typeof value === "string") return value;
78
- try {
79
- return JSON.stringify(value);
80
- } catch {
81
- return Object.prototype.toString.call(value);
82
- }
83
- }
84
- //#endregion
85
4
  //#region extensions/copilot/src/runtime.ts
86
5
  const DEFAULT_IDLE_TTL_MS = 3e5;
87
6
  const POOL_DISPOSED_MESSAGE = "[copilot-pool] pool disposed";
@@ -111,14 +30,23 @@ function createCopilotClientPool(options = {}) {
111
30
  })();
112
31
  return entry.stopping;
113
32
  };
114
- const createEntry = (key, cacheKey, clientOptions) => {
33
+ const createEntry = (key, cacheKey, clientOptions, runtimeArtifact) => {
115
34
  const entry = {
116
35
  key,
117
36
  cacheKey,
118
37
  refCount: 0,
119
38
  client: Promise.resolve().then(async () => {
120
39
  try {
121
- return await sdkFactory(clientOptions);
40
+ const client = await sdkFactory(clientOptions);
41
+ if (runtimeArtifact) try {
42
+ await client.start();
43
+ const { validateCopilotRuntimeArtifact } = await import("./runtime-artifact-CwEwkNDm.mjs");
44
+ if (!await validateCopilotRuntimeArtifact(runtimeArtifact)) throw new Error("[copilot] runtime changed while starting; retry setup verification");
45
+ } catch (error) {
46
+ await client.stop().catch(() => void 0);
47
+ throw error;
48
+ }
49
+ return client;
122
50
  } catch (error) {
123
51
  maybeDeleteEntry(entry);
124
52
  throw toStringifiedError(error);
@@ -128,13 +56,27 @@ function createCopilotClientPool(options = {}) {
128
56
  entries.set(cacheKey, entry);
129
57
  return entry;
130
58
  };
131
- const acquire = async (inputKey, optionsForCreate) => {
132
- const key = normalizePoolKey(inputKey, optionsForCreate.copilotHome, optionsForCreate.mode);
59
+ const acquire = async (inputKey, optionsForCreate, runtimeArtifactRequest) => {
60
+ if (runtimeArtifactRequest && optionsForCreate.connection) throw new Error("[copilot] runtime verification requires the packaged stdio runtime");
61
+ const capture = runtimeArtifactRequest ? await (await import("./runtime-artifact-CwEwkNDm.mjs")).captureCopilotRuntimeArtifact(optionsForCreate.env) : void 0;
62
+ const expected = runtimeArtifactRequest?.expected;
63
+ if (expected && (!capture || capture.binding.id !== expected.id || capture.binding.fingerprint !== expected.fingerprint)) throw new Error("[copilot] verified runtime changed; rerun setup verification");
64
+ const runtimeArtifact = capture?.binding;
65
+ const key = {
66
+ ...normalizePoolKey(inputKey, optionsForCreate.copilotHome, optionsForCreate.mode),
67
+ ...runtimeArtifact ? { runtimeArtifactFingerprint: runtimeArtifact.fingerprint } : {}
68
+ };
133
69
  const cacheKey = JSON.stringify(key);
134
70
  const clientOptions = normalizeClientCreateOptions(optionsForCreate, key.copilotHome);
71
+ if (capture) clientOptions.connection = capture.connection;
72
+ const toHandle = (client) => ({
73
+ key,
74
+ client,
75
+ ...runtimeArtifact ? { runtimeArtifact } : {}
76
+ });
135
77
  while (true) {
136
78
  if (disposePromise) throw createDisposedError();
137
- const entry = entries.get(cacheKey) ?? createEntry(key, cacheKey, clientOptions);
79
+ const entry = entries.get(cacheKey) ?? createEntry(key, cacheKey, clientOptions, runtimeArtifact);
138
80
  if (entry.stopping) {
139
81
  await entry.stopping;
140
82
  continue;
@@ -146,10 +88,7 @@ function createCopilotClientPool(options = {}) {
146
88
  await stopEntry(entry);
147
89
  throw createDisposedError();
148
90
  }
149
- return {
150
- key: entry.key,
151
- client
152
- };
91
+ return toHandle(client);
153
92
  }
154
93
  };
155
94
  const release = async (handle) => {
@@ -0,0 +1,56 @@
1
+ import { r as loadCopilotSdkWithIdentity, t as fingerprintCopilotPackage } from "./sdk-loader-CrnyZ1P8.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
+ import { createHash } from "node:crypto";
5
+ import path from "node:path";
6
+ import fsp from "node:fs/promises";
7
+ import { existsSync } from "node:fs";
8
+ //#region extensions/copilot/src/runtime-artifact.ts
9
+ function runtimePlatform() {
10
+ if (process.arch !== "x64" && process.arch !== "arm64") throw new Error(`Copilot runtime artifacts do not support architecture ${process.arch}.`);
11
+ if (process.platform === "linux") {
12
+ const report = process.report?.getReport();
13
+ return `${(isRecord(report) && isRecord(report.header) ? report.header : void 0)?.glibcVersionRuntime ? "linux" : "linuxmusl"}-${process.arch}`;
14
+ }
15
+ if (process.platform === "darwin" || process.platform === "win32") return `${process.platform}-${process.arch}`;
16
+ throw new Error(`Copilot runtime artifacts do not support platform ${process.platform}.`);
17
+ }
18
+ async function resolveRuntimePackage(entryPath, packageName) {
19
+ const packageRoot = (createRequire(entryPath).resolve.paths(packageName) ?? []).map((lookupPath) => path.join(lookupPath, packageName)).find((candidate) => existsSync(path.join(candidate, "package.json")));
20
+ if (!packageRoot) throw new Error(`Copilot runtime package ${packageName} is not installed.`);
21
+ return await fsp.realpath(packageRoot);
22
+ }
23
+ async function captureCopilotRuntimeArtifact(env = process.env) {
24
+ const defaultConnection = process.env.COPILOT_SDK_DEFAULT_CONNECTION;
25
+ if (defaultConnection && defaultConnection.toLowerCase() !== "stdio") throw new Error("Copilot runtime artifact verification requires the stdio transport.");
26
+ const { sdk, identity } = await loadCopilotSdkWithIdentity();
27
+ if (await fingerprintCopilotPackage(identity.packageRoot) !== identity.fingerprint) throw new Error("Copilot SDK changed after loading. Restart OpenClaw before verifying inference.");
28
+ const platform = runtimePlatform();
29
+ const packageName = `@github/copilot-sdk-${platform}`;
30
+ const packageRoot = await resolveRuntimePackage(identity.entryPath, packageName);
31
+ const executable = await fsp.realpath(path.join(packageRoot, "prebuilds", platform, process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime"));
32
+ if (env.COPILOT_CLI_PATH && await fsp.realpath(env.COPILOT_CLI_PATH) !== executable) throw new Error("Copilot runtime artifact verification does not support a custom COPILOT_CLI_PATH.");
33
+ const runtimeFingerprint = await fingerprintCopilotPackage(packageRoot);
34
+ const id = `copilot-sdk:${platform}:${path.relative(identity.packageRoot, identity.entryPath).split(path.sep).join("/")}`;
35
+ return {
36
+ binding: {
37
+ id,
38
+ fingerprint: createHash("sha256").update(JSON.stringify([
39
+ id,
40
+ identity.fingerprint,
41
+ runtimeFingerprint
42
+ ])).digest("hex")
43
+ },
44
+ connection: sdk.RuntimeConnection.forStdio({ path: executable })
45
+ };
46
+ }
47
+ async function validateCopilotRuntimeArtifact(binding) {
48
+ try {
49
+ const current = await captureCopilotRuntimeArtifact();
50
+ return current.binding.id === binding.id && current.binding.fingerprint === binding.fingerprint;
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+ //#endregion
56
+ export { captureCopilotRuntimeArtifact, validateCopilotRuntimeArtifact };
@@ -0,0 +1,153 @@
1
+ import { createRequire } from "node:module";
2
+ import { createHash } from "node:crypto";
3
+ import path from "node:path";
4
+ import fsp from "node:fs/promises";
5
+ import { existsSync } from "node:fs";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { sha256File } from "openclaw/plugin-sdk/file-access-runtime";
8
+ import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
9
+ //#region extensions/copilot/package.json
10
+ var dependencies = { "@github/copilot-sdk": "1.0.16" };
11
+ //#endregion
12
+ //#region extensions/copilot/src/sdk-loader.ts
13
+ function resolveCopilotSdkFallbackDir(env = process.env) {
14
+ return path.join(resolveStateDir(env), "npm-runtime", "copilot");
15
+ }
16
+ const COPILOT_SDK_SPEC = `@github/copilot-sdk@${dependencies["@github/copilot-sdk"]}`;
17
+ let cached;
18
+ const installedImports = /* @__PURE__ */ new Map();
19
+ function unchanged(before, after) {
20
+ return before.dev === after.dev && before.ino === after.ino && before.mode === after.mode && before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs;
21
+ }
22
+ /** Installed package bytes, excluding separately resolved dependency installations. */
23
+ async function fingerprintCopilotPackage(packageRoot) {
24
+ const hash = createHash("sha256");
25
+ async function visit(directory) {
26
+ const entries = await fsp.readdir(directory, { withFileTypes: true });
27
+ entries.sort((left, right) => left.name.localeCompare(right.name));
28
+ for (const entry of entries) {
29
+ if (entry.name === "node_modules") continue;
30
+ const filePath = path.join(directory, entry.name);
31
+ if (entry.isDirectory()) await visit(filePath);
32
+ else if (entry.isFile() || entry.isSymbolicLink()) {
33
+ const target = await fsp.realpath(filePath);
34
+ const before = await fsp.stat(target, { bigint: true });
35
+ const contents = await sha256File(target, { maxBytes: Number(before.size) });
36
+ if (await fsp.realpath(filePath) !== target || !unchanged(before, await fsp.stat(target, { bigint: true })) || BigInt(contents.bytes) !== before.size) throw new Error("Copilot runtime package changed while fingerprinting.");
37
+ const relativePath = path.relative(packageRoot, filePath).split(path.sep).join("/");
38
+ hash.update(`${relativePath}\0${before.mode}\0${contents.digest}\0`);
39
+ } else throw new Error(`Copilot runtime package contains an unsupported file: ${filePath}`);
40
+ }
41
+ }
42
+ await visit(packageRoot);
43
+ return hash.digest("hex");
44
+ }
45
+ async function importInstalledSdk(selectedEntry) {
46
+ const entryPath = await fsp.realpath(selectedEntry);
47
+ const previous = installedImports.get(entryPath);
48
+ if (previous) return previous;
49
+ let packageRoot = path.dirname(entryPath);
50
+ while (true) {
51
+ const manifestPath = path.join(packageRoot, "package.json");
52
+ if (existsSync(manifestPath) && JSON.parse(await fsp.readFile(manifestPath, "utf8")).name === "@github/copilot-sdk") break;
53
+ const parent = path.dirname(packageRoot);
54
+ if (parent === packageRoot) throw new Error("Could not locate the installed Copilot SDK package.");
55
+ packageRoot = parent;
56
+ }
57
+ const fingerprint = await fingerprintCopilotPackage(packageRoot);
58
+ const loaded = (async () => {
59
+ const sdk = await import(pathToFileURL(entryPath).href).catch((error) => {
60
+ installedImports.delete(entryPath);
61
+ throw error;
62
+ });
63
+ if (await fingerprintCopilotPackage(packageRoot) !== fingerprint) throw new Error("Copilot SDK changed while loading. Restart OpenClaw before verifying inference.");
64
+ return {
65
+ sdk,
66
+ identity: {
67
+ entryPath,
68
+ packageRoot,
69
+ fingerprint
70
+ }
71
+ };
72
+ })();
73
+ installedImports.set(entryPath, loaded);
74
+ return loaded;
75
+ }
76
+ async function loadCopilotSdk(options = {}) {
77
+ return (await loadSdk(options)).sdk;
78
+ }
79
+ async function loadCopilotSdkWithIdentity() {
80
+ const loaded = await loadSdk({});
81
+ if (!loaded.identity) throw new Error("The loaded Copilot SDK has no installed implementation identity.");
82
+ return {
83
+ sdk: loaded.sdk,
84
+ identity: loaded.identity
85
+ };
86
+ }
87
+ async function loadSdk(options) {
88
+ const useCache = options.cache !== false;
89
+ if (useCache && cached) return cached;
90
+ const promise = doLoad(options);
91
+ if (useCache) {
92
+ cached = promise.catch((err) => {
93
+ cached = void 0;
94
+ throw err;
95
+ });
96
+ return cached;
97
+ }
98
+ return promise;
99
+ }
100
+ async function doLoad(options) {
101
+ const fallbackDir = options.fallbackDir ?? resolveCopilotSdkFallbackDir();
102
+ const primaryImport = options.primaryImport;
103
+ let primaryErr;
104
+ try {
105
+ return primaryImport ? { sdk: await primaryImport() } : await importInstalledSdk(fileURLToPath(import.meta.resolve("@github/copilot-sdk")));
106
+ } catch (err) {
107
+ primaryErr = err;
108
+ }
109
+ const fallbackPath = path.join(fallbackDir, "node_modules", "@github", "copilot-sdk");
110
+ if (!existsSync(fallbackPath)) throw createMissingSdkError(primaryErr, void 0, fallbackPath);
111
+ try {
112
+ if (options.fallbackImport) return { sdk: await options.fallbackImport(fallbackPath) };
113
+ return await importInstalledSdk(createRequire(path.join(fallbackDir, "package.json")).resolve("@github/copilot-sdk"));
114
+ } catch (fallbackErr) {
115
+ throw createMissingSdkError(primaryErr, fallbackErr, fallbackPath);
116
+ }
117
+ }
118
+ function createMissingSdkError(primaryErr, fallbackErr, fallbackPath) {
119
+ const lines = [
120
+ "[copilot] @github/copilot-sdk is not installed.",
121
+ "",
122
+ "The external @openclaw/copilot plugin depends on @github/copilot-sdk",
123
+ "including its platform-specific Copilot runtime package.",
124
+ "Reinstall the plugin once with:",
125
+ "",
126
+ " openclaw plugins install @openclaw/copilot",
127
+ "",
128
+ "For source checkouts or offline repair, install the SDK directly:",
129
+ "",
130
+ ` npm install ${COPILOT_SDK_SPEC}`,
131
+ "",
132
+ `The legacy fallback location is still checked at\n ${fallbackPath}`,
133
+ "",
134
+ "Primary resolution error:",
135
+ ` ${summarizeError(primaryErr)}`
136
+ ];
137
+ if (fallbackErr !== void 0) lines.push("", "Fallback resolution error:", ` ${summarizeError(fallbackErr)}`);
138
+ const err = new Error(lines.join("\n"));
139
+ err.code = "COPILOT_SDK_MISSING";
140
+ return err;
141
+ }
142
+ function summarizeError(value) {
143
+ if (value === void 0 || value === null) return "(none)";
144
+ if (value instanceof Error) return value.message || String(value);
145
+ if (typeof value === "string") return value;
146
+ try {
147
+ return JSON.stringify(value);
148
+ } catch {
149
+ return Object.prototype.toString.call(value);
150
+ }
151
+ }
152
+ //#endregion
153
+ export { loadCopilotSdk as n, loadCopilotSdkWithIdentity as r, fingerprintCopilotPackage as t };
package/dist/harness.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createCopilotAgentHarness } from "./.setup/harness-Je_2Cj-D.mjs";
1
+ import { t as createCopilotAgentHarness } from "./.setup/harness-COUVzhZo.mjs";
2
2
  export { createCopilotAgentHarness };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createCopilotAgentHarness } from "./.setup/harness-Je_2Cj-D.mjs";
1
+ import { t as createCopilotAgentHarness } from "./.setup/harness-COUVzhZo.mjs";
2
2
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
3
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  //#region extensions/copilot/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/copilot",
3
- "version": "2026.11.2",
3
+ "version": "2026.11.4",
4
4
  "description": "OpenClaw GitHub Copilot agent runtime plugin (registers a `github-copilot` AgentHarness backed by @github/copilot-sdk over JSON-RPC to the GitHub Copilot CLI)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,10 +24,10 @@
24
24
  "minHostVersion": ">=2026.5.28"
25
25
  },
26
26
  "compat": {
27
- "pluginApi": ">=2026.11.2"
27
+ "pluginApi": ">=2026.11.4"
28
28
  },
29
29
  "build": {
30
- "openclawVersion": "2026.11.2",
30
+ "openclawVersion": "2026.11.4",
31
31
  "bundledDist": false
32
32
  },
33
33
  "release": {
@@ -47,7 +47,7 @@
47
47
  "assets/activity.svg"
48
48
  ],
49
49
  "peerDependencies": {
50
- "openclaw": ">=2026.11.2"
50
+ "openclaw": ">=2026.11.4"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "openclaw": {