@openclaw/copilot 2026.10.1 → 2026.10.5-beta.1

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-pIM2FFm8.mjs";
1
+ import { a as createCopilotByokProxy, i as createPromptError, n as resolveCopilotProvider, o as createCopilotByokAuth, s as resolveCopilotAuth } from "./harness-CAJKYXN0.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, resolveModelAuthMode, resolveSandboxContext, resolveUserPath, restorePreparedUserTurnOperationalMetaForRuntime, runAgentEndSideEffects, runAgentHarnessAfterCompactionHook, runAgentHarnessAfterToolCallHook, runAgentHarnessBeforeCompactionHook, runAgentHarnessBeforeMessageWriteHook, runAgentHarnessGatewayQuestion, runAgentHarnessLlmInputHook, runAgentHarnessLlmOutputHook, sanitizeToolResult, setActiveEmbeddedRun } from "openclaw/plugin-sdk/agent-harness-runtime";
@@ -133,29 +133,6 @@ function createPermissionBridge(policy = rejectAllPolicy) {
133
133
  }
134
134
  //#endregion
135
135
  //#region extensions/copilot/src/replay-shim.ts
136
- function decideReplayAction(input) {
137
- if (!input) return {
138
- action: "create",
139
- downgradedFromResume: false,
140
- downgradeReason: "no-replay-state"
141
- };
142
- const sdkSessionId = normalizeOptionalString(input.sdkSessionId);
143
- if (!sdkSessionId) return {
144
- action: "create",
145
- downgradedFromResume: false,
146
- downgradeReason: "no-sdk-session-id"
147
- };
148
- if (input.replayInvalid === true) return {
149
- action: "create",
150
- downgradedFromResume: true,
151
- downgradeReason: "replay-invalid"
152
- };
153
- return {
154
- action: "resume",
155
- sdkSessionId,
156
- downgradedFromResume: false
157
- };
158
- }
159
136
  const MISSING_SESSION_CODES = /* @__PURE__ */ new Set([
160
137
  "SESSION_NOT_FOUND",
161
138
  "session_not_found",
@@ -170,30 +147,12 @@ const MISSING_SESSION_MESSAGE_PATTERNS = [
170
147
  /\bsession .* does not exist\b/i,
171
148
  /\bno such session\b/i
172
149
  ];
173
- function classifyResumeFailure(error) {
150
+ function isMissingCopilotSessionError(error) {
174
151
  const record = asOptionalObjectRecord(error);
175
- if (record?.status === 404) return {
176
- recoverable: true,
177
- kind: "missing"
178
- };
179
- if (record?.statusCode === 404) return {
180
- recoverable: true,
181
- kind: "missing"
182
- };
152
+ if (record?.status === 404 || record?.statusCode === 404) return true;
183
153
  const code = record?.code;
184
- if (typeof code === "string" && MISSING_SESSION_CODES.has(code)) return {
185
- recoverable: true,
186
- kind: "missing"
187
- };
188
154
  const message = record?.message;
189
- if (typeof message === "string" && MISSING_SESSION_MESSAGE_PATTERNS.some((pattern) => pattern.test(message))) return {
190
- recoverable: true,
191
- kind: "missing"
192
- };
193
- return {
194
- recoverable: false,
195
- kind: "unknown"
196
- };
155
+ return typeof code === "string" && MISSING_SESSION_CODES.has(code) || typeof message === "string" && MISSING_SESSION_MESSAGE_PATTERNS.some((pattern) => pattern.test(message));
197
156
  }
198
157
  function computeReplayMetadata(input) {
199
158
  const priorReplayInvalid = input.priorReplayInvalid === true;
@@ -413,7 +372,6 @@ function resolvePoolAcquire(params) {
413
372
  const authContext = {
414
373
  agentId: readNonEmptyString(params.agentId),
415
374
  agentDir: readNonEmptyString(params.agentDir),
416
- workspaceDir: readNonEmptyString(params.workspaceDir),
417
375
  copilotHome: readNonEmptyString(params.copilotHome)
418
376
  };
419
377
  const auth = provider.mode === "byok" ? createCopilotByokAuth({
@@ -639,13 +597,15 @@ function attachEventBridge(session, options) {
639
597
  const sessionIdle = createDeferred();
640
598
  let firstDeltaError;
641
599
  let detached = false;
642
- let unconsumedDurableReasoning = false;
643
600
  const unsubscribeFns = [];
644
601
  const listen = (eventType, handler) => {
645
602
  unsubscribeFns.push(session.on(eventType, handler));
646
603
  };
647
- listen("user.message", (event) => {
648
- if (!isRootSessionEvent(event) || event.ephemeral === true) return;
604
+ const listenRoot = (eventType, handler) => listen(eventType, (event) => {
605
+ if (isRootSessionEvent(event)) handler(event);
606
+ });
607
+ listenRoot("user.message", (event) => {
608
+ if (event.ephemeral === true) return;
649
609
  flushPendingAssistantProjection();
650
610
  const projection = options.transcriptProjection;
651
611
  if (!projection) return;
@@ -668,29 +628,25 @@ function attachEventBridge(session, options) {
668
628
  }
669
629
  });
670
630
  });
671
- listen("system.message", (event) => {
672
- if (!isRootSessionEvent(event) || event.ephemeral === true) return;
673
- options.transcriptProjection?.journal.markReplayIncomplete();
674
- });
675
- listen("skill.invoked", (event) => {
676
- if (isRootSessionEvent(event) && event.ephemeral !== true) options.transcriptProjection?.journal.markReplayIncomplete();
677
- });
678
- listen("system.notification", (event) => {
679
- if (isRootSessionEvent(event) && event.ephemeral !== true) options.transcriptProjection?.journal.markReplayIncomplete();
631
+ for (const eventType of [
632
+ "system.message",
633
+ "skill.invoked",
634
+ "system.notification"
635
+ ]) listenRoot(eventType, (event) => {
636
+ if (event.ephemeral !== true) options.transcriptProjection?.journal.markReplayIncomplete();
680
637
  });
681
- listen("assistant.message_delta", (event) => {
682
- if (!isRootSessionEvent(event)) return;
638
+ listenRoot("assistant.message_delta", (event) => {
683
639
  const messageId = readNonEmptyStringPreservingWhitespace(event.data.messageId) ?? "assistant-message";
684
640
  const delta = event.data.deltaContent;
685
641
  if (!delta) return;
686
- const entry = ensureMessageAccumulator(messagesById, messageId);
687
- entry.text += delta;
642
+ const text = (messagesById.get(messageId) ?? "") + delta;
643
+ messagesById.set(messageId, text);
688
644
  const onAssistantDelta = options.onAssistantDelta;
689
645
  if (!onAssistantDelta) return;
690
646
  const payload = {
691
647
  delta,
692
648
  sessionId: options.getSdkSessionId(),
693
- text: entry.text,
649
+ text,
694
650
  usage
695
651
  };
696
652
  deltaQueue = deltaQueue.then(() => onAssistantDelta(payload), () => onAssistantDelta(payload)).catch((error) => {
@@ -701,32 +657,27 @@ function attachEventBridge(session, options) {
701
657
  });
702
658
  deltaChain.catch(() => void 0);
703
659
  });
704
- listen("assistant.reasoning_delta", (event) => {
705
- if (!isRootSessionEvent(event)) return;
660
+ listenRoot("assistant.reasoning_delta", (event) => {
706
661
  const reasoningId = readNonEmptyStringPreservingWhitespace(event.data.reasoningId) ?? "assistant-reasoning";
707
662
  const delta = event.data.deltaContent;
708
663
  if (!delta) return;
709
664
  reasoningById.set(reasoningId, `${reasoningById.get(reasoningId) ?? ""}${delta}`);
710
665
  });
711
- listen("assistant.reasoning", (event) => {
712
- if (!isRootSessionEvent(event) || event.ephemeral === true) return;
666
+ listenRoot("assistant.reasoning", (event) => {
667
+ if (event.ephemeral === true) return;
713
668
  reasoningById.set(event.data.reasoningId, event.data.content);
714
669
  durableReasoningById.set(event.data.reasoningId, event.data.content);
715
- unconsumedDurableReasoning = true;
716
- });
717
- listen("assistant.turn_start", (event) => {
718
- if (isRootSessionEvent(event)) markUnconsumedReasoningIncomplete();
719
670
  });
671
+ listenRoot("assistant.turn_start", markUnconsumedReasoningIncomplete);
720
672
  listen("assistant.message", handleAssistantMessage);
721
- listen("assistant.usage", (event) => {
722
- if (!isRootSessionEvent(event)) return;
673
+ listenRoot("assistant.usage", (event) => {
723
674
  usage = normalizeCopilotUsage(event.data);
724
675
  const apiCallId = readNonEmptyStringPreservingWhitespace(event.data.apiCallId);
725
676
  if (apiCallId && usage) usageByApiCallId.set(apiCallId, usage);
726
677
  if (apiCallId) flushPendingAssistantProjection(apiCallId);
727
678
  });
728
- listen("tool.user_requested", (event) => {
729
- if (isRootSessionEvent(event) && event.ephemeral !== true) {
679
+ listenRoot("tool.user_requested", (event) => {
680
+ if (event.ephemeral !== true) {
730
681
  userRequestedToolCallIds.add(event.data.toolCallId);
731
682
  options.transcriptProjection?.journal.markReplayIncomplete();
732
683
  }
@@ -857,8 +808,7 @@ function attachEventBridge(session, options) {
857
808
  }
858
809
  });
859
810
  });
860
- listen("session.compaction_start", (event) => {
861
- if (!isRootSessionEvent(event)) return;
811
+ listenRoot("session.compaction_start", () => {
862
812
  observedCompaction = true;
863
813
  if (activeCompactionCount === 0) compactionIdle = createDeferred();
864
814
  activeCompactionCount += 1;
@@ -879,8 +829,7 @@ function attachEventBridge(session, options) {
879
829
  compactionIdle = void 0;
880
830
  }
881
831
  });
882
- listen("session.idle", (event) => {
883
- if (!isRootSessionEvent(event)) return;
832
+ listenRoot("session.idle", () => {
884
833
  markUnconsumedReasoningIncomplete();
885
834
  flushPendingAssistantProjection();
886
835
  observedSessionIdle = true;
@@ -985,16 +934,15 @@ function attachEventBridge(session, options) {
985
934
  if (handledAssistantEventIds.has(event.id)) return;
986
935
  handledAssistantEventIds.add(event.id);
987
936
  for (const request of event.data.toolRequests ?? []) projectedToolNamesByCallId.set(request.toolCallId, request.name);
988
- const entry = ensureMessageAccumulator(messagesById, event.data.messageId);
989
- if (typeof event.data.content === "string" && event.data.content.length >= entry.text.length) entry.text = event.data.content;
937
+ const previousText = messagesById.get(event.data.messageId) ?? "";
938
+ messagesById.set(event.data.messageId, typeof event.data.content === "string" && event.data.content.length >= previousText.length ? event.data.content : previousText);
990
939
  lastAssistantReasoningText = event.data.reasoningText ?? ([...reasoningById.values()].join("") || void 0);
991
940
  const transcriptReasoningText = event.data.reasoningText ?? ([...durableReasoningById.values()].join("") || void 0);
992
941
  reasoningById.clear();
993
942
  durableReasoningById.clear();
994
- unconsumedDurableReasoning = false;
995
943
  const chunk = {
996
944
  event,
997
- assistantTexts: [messagesById.get(event.data.messageId)?.text ?? ""],
945
+ assistantTexts: [messagesById.get(event.data.messageId) ?? ""],
998
946
  ...lastAssistantReasoningText ? { reasoningText: lastAssistantReasoningText } : {},
999
947
  transcriptAssistantTexts: [event.data.content ?? ""],
1000
948
  ...transcriptReasoningText ? { transcriptReasoningText } : {}
@@ -1032,10 +980,9 @@ function attachEventBridge(session, options) {
1032
980
  recordAssistantProjection(group);
1033
981
  }
1034
982
  function markUnconsumedReasoningIncomplete() {
1035
- if (unconsumedDurableReasoning) options.transcriptProjection?.journal.markReplayIncomplete();
983
+ if (durableReasoningById.size > 0) options.transcriptProjection?.journal.markReplayIncomplete();
1036
984
  reasoningById.clear();
1037
985
  durableReasoningById.clear();
1038
- unconsumedDurableReasoning = false;
1039
986
  }
1040
987
  function flushPendingAssistantProjectionForToolCall(toolCallId) {
1041
988
  if (pendingAssistantProjection?.chunks.some((chunk) => chunk.event.data.toolRequests?.some((request) => request.toolCallId === toolCallId))) flushPendingAssistantProjection();
@@ -1081,16 +1028,8 @@ function attachEventBridge(session, options) {
1081
1028
  if (activeCompactionCount > 0 || compactionChain !== callbacks) await awaitStableCompaction();
1082
1029
  }
1083
1030
  }
1084
- function ensureMessageAccumulator(messagesById, messageId) {
1085
- let entry = messagesById.get(messageId);
1086
- if (!entry) {
1087
- entry = { text: "" };
1088
- messagesById.set(messageId, entry);
1089
- }
1090
- return entry;
1091
- }
1092
1031
  function finalizeAssistantTexts(messagesById, event) {
1093
- const texts = [...messagesById.values()].map((message) => message.text).filter((text) => text.length > 0);
1032
+ const texts = [...messagesById.values()].filter((text) => text.length > 0);
1094
1033
  if (texts.length > 0) return texts;
1095
1034
  if (event?.data.content) return [event.data.content];
1096
1035
  return [];
@@ -1165,16 +1104,10 @@ async function awaitDeferredCleanupBeforeDeadline(params) {
1165
1104
  await params.bridge.awaitCompactionCompletion();
1166
1105
  return "completed";
1167
1106
  })();
1168
- let resolveAbort = () => void 0;
1169
- const aborted = new Promise((resolve) => {
1170
- resolveAbort = () => resolve("aborted");
1171
- params.abortSignal?.addEventListener("abort", resolveAbort, { once: true });
1107
+ return await raceWithTimeout(completion, params.timeoutMs, () => "deadline", {
1108
+ signal: params.abortSignal,
1109
+ onAbort: () => "aborted"
1172
1110
  });
1173
- try {
1174
- return await raceWithTimeout(Promise.race([completion, aborted]), params.timeoutMs, () => "deadline");
1175
- } finally {
1176
- params.abortSignal?.removeEventListener("abort", resolveAbort);
1177
- }
1178
1111
  }
1179
1112
  //#endregion
1180
1113
  //#region extensions/copilot/src/attempt-active-run.ts
@@ -1482,9 +1415,9 @@ async function createCopilotToolBridge(input) {
1482
1415
  if (!hostCapabilities) throw new Error("Copilot attempt tools require host-bound capabilities.");
1483
1416
  const bindingCwd = toolOptions.cwd ?? toolOptions.workspaceDir;
1484
1417
  const bindingOptions = bindingCwd ? { cwd: bindingCwd } : void 0;
1485
- const createToolSurface = hostCapabilities.createToolSurface;
1486
- if (!createToolSurface) throw new Error("Copilot tool construction requires a current host capability");
1487
- const sourceTools = createToolSurface(toolOptions, bindingOptions);
1418
+ const createToolSurfaceAsync = hostCapabilities.createToolSurfaceAsync;
1419
+ if (!createToolSurfaceAsync) throw new Error("Copilot tool construction requires a current host capability");
1420
+ const sourceTools = await createToolSurfaceAsync(toolOptions, bindingOptions);
1488
1421
  const boundSourceTools = new Set(sourceTools);
1489
1422
  const allowedSourceTools = applyEmbeddedAttemptToolsAllow(sourceTools, toolSurfaceRuntime.runtimeToolAllowlist, { toolMeta: getPluginToolMeta });
1490
1423
  const compactedTools = toolSurfaceRuntime.compactTools(allowedSourceTools, { localModelLeanApplied: true });
@@ -2038,41 +1971,29 @@ const COPILOT_BOOTSTRAP_CONTEXT_ORDER = /* @__PURE__ */ new Map([
2038
1971
  ["user.md", 60],
2039
1972
  ["memory.md", 70]
2040
1973
  ]);
2041
- async function resolveCopilotWorkspaceBootstrapContext(params) {
1974
+ async function loadCopilotWorkspaceInstructions(params) {
2042
1975
  const { attempt } = params;
2043
1976
  const workspaceDir = readResolvedWorkspacePath(attempt.workspaceDir);
2044
- if (!workspaceDir) return {
2045
- bootstrapFiles: [],
2046
- contextFiles: []
2047
- };
1977
+ if (!workspaceDir) return;
2048
1978
  try {
2049
- const bootstrapContext = await resolveBootstrapContextForRun({
2050
- workspaceDir,
2051
- config: attempt.config,
2052
- sessionKey: readNonBlankString(attempt.sessionKey),
2053
- sessionId: readNonBlankString(attempt.sessionId),
2054
- chatType: attempt.chatType,
2055
- agentId: readNonBlankString(attempt.agentId),
2056
- warn: params.warn,
2057
- contextMode: attempt.bootstrapContextMode,
2058
- runKind: attempt.bootstrapContextRunKind
2059
- });
2060
- const contextFiles = remapCopilotBootstrapContextFiles({
2061
- files: bootstrapContext.contextFiles,
1979
+ return renderCopilotWorkspaceBootstrapInstructions(remapCopilotBootstrapContextFiles({
1980
+ files: (await resolveBootstrapContextForRun({
1981
+ workspaceDir,
1982
+ config: attempt.config,
1983
+ sessionKey: readNonBlankString(attempt.sessionKey),
1984
+ sessionId: readNonBlankString(attempt.sessionId),
1985
+ chatType: attempt.chatType,
1986
+ agentId: readNonBlankString(attempt.agentId),
1987
+ warn: params.warn,
1988
+ contextMode: attempt.bootstrapContextMode,
1989
+ runKind: attempt.bootstrapContextRunKind
1990
+ })).contextFiles,
2062
1991
  sourceWorkspaceDir: workspaceDir,
2063
1992
  targetWorkspaceDir: readResolvedWorkspacePath(params.effectiveWorkspaceDir) ?? workspaceDir
2064
- });
2065
- return {
2066
- bootstrapFiles: bootstrapContext.bootstrapFiles,
2067
- contextFiles,
2068
- instructions: renderCopilotWorkspaceBootstrapInstructions(contextFiles)
2069
- };
1993
+ }));
2070
1994
  } catch (error) {
2071
1995
  params.warn?.(`[copilot-attempt] failed to load workspace bootstrap instructions: ${error instanceof Error ? error.message : String(error)}`);
2072
- return {
2073
- bootstrapFiles: [],
2074
- contextFiles: []
2075
- };
1996
+ return;
2076
1997
  }
2077
1998
  }
2078
1999
  function remapCopilotBootstrapContextFiles(params) {
@@ -2140,11 +2061,11 @@ async function createCopilotSessionSetup(params) {
2140
2061
  assertCopilotAttemptHostCapabilities(input);
2141
2062
  return input;
2142
2063
  })();
2143
- const workspaceBootstrap = ordinaryAttemptInput ? await resolveCopilotWorkspaceBootstrapContext({
2064
+ const workspaceBootstrapInstructions = ordinaryAttemptInput ? await loadCopilotWorkspaceInstructions({
2144
2065
  attempt: ordinaryAttemptInput,
2145
2066
  effectiveWorkspaceDir,
2146
2067
  warn: (message) => console.warn(message)
2147
- }) : { instructions: void 0 };
2068
+ }) : void 0;
2148
2069
  const forceToolNames = ordinaryAttemptInput && shouldForceCopilotMessageTool(ordinaryAttemptInput) ? ["message"] : void 0;
2149
2070
  let promptPolicyResult;
2150
2071
  let promptBuild;
@@ -2173,7 +2094,7 @@ async function createCopilotSessionSetup(params) {
2173
2094
  callableToolNames: promptPolicyResult.callableToolNames,
2174
2095
  toolSchemaDirectoryPrompt: promptPolicyResult.toolSchemaDirectoryPrompt,
2175
2096
  requireExplicitMessageTarget: promptToolPolicy.requireExplicitMessageTarget,
2176
- workspaceBootstrapInstructions: workspaceBootstrap.instructions
2097
+ workspaceBootstrapInstructions
2177
2098
  });
2178
2099
  } },
2179
2100
  messages,
@@ -2368,7 +2289,7 @@ function createAttemptTranscriptJournal(params) {
2368
2289
  ...write.eventId ? { eventId: write.eventId } : {},
2369
2290
  idempotencyLookup: "scan",
2370
2291
  message: write.message,
2371
- prepareMessageAfterIdempotencyCheck: () => prepare(write, { singleton: true })
2292
+ preparation: { prepareMessage: async () => prepare(write, { singleton: true }) }
2372
2293
  });
2373
2294
  if (outcome.kind === "suppressed") {
2374
2295
  write.recorder?.markBlocked();
@@ -2846,12 +2767,9 @@ async function runCopilotExecution(context) {
2846
2767
  });
2847
2768
  const { attemptInput, compactionSessionConfig, emitLlmInput, hasNativePromptHook, sessionConfig, userInputBridge } = sessionSetup;
2848
2769
  userInputBridgeRef = userInputBridge;
2849
- const replayDecision = decideReplayAction({
2850
- sdkSessionId: input.initialReplayState?.sdkSessionId,
2851
- replayInvalid: input.initialReplayState?.replayInvalid
2852
- });
2853
- downgradedFromResume = replayDecision.downgradedFromResume;
2854
- const resumeSessionId = settledToolFinalization ? settledFinalizationSessionId : replayDecision.action === "resume" ? replayDecision.sdkSessionId : void 0;
2770
+ const previousSessionId = normalizeOptionalString(input.initialReplayState?.sdkSessionId);
2771
+ downgradedFromResume = Boolean(previousSessionId && input.initialReplayState?.replayInvalid === true);
2772
+ const resumeSessionId = settledToolFinalization ? settledFinalizationSessionId : downgradedFromResume ? void 0 : previousSessionId;
2855
2773
  if (resumeSessionId) try {
2856
2774
  session = await client.resumeSession(resumeSessionId, {
2857
2775
  ...sessionConfig,
@@ -2861,7 +2779,7 @@ async function runCopilotExecution(context) {
2861
2779
  nativeSessionHistoryValidated = input.initialReplayState?.journalValidated === true;
2862
2780
  } catch (error) {
2863
2781
  if (settledToolFinalization) throw createPromptError("settled_finalization_resume_failed", `[copilot-attempt] settled tool finalization could not resume the existing Copilot SDK session: ${toCopilotError(error).message}`, error);
2864
- if (!classifyResumeFailure(error).recoverable) throw error;
2782
+ if (!isMissingCopilotSessionError(error)) throw error;
2865
2783
  resumeFailureRecovered = true;
2866
2784
  }
2867
2785
  if (!session) {
@@ -17,7 +17,6 @@ function createCopilotByokAuth(input) {
17
17
  ...resolveCopilotAuth({
18
18
  agentId: input.agentId,
19
19
  agentDir: input.agentDir,
20
- workspaceDir: input.workspaceDir,
21
20
  copilotHome: input.copilotHome,
22
21
  env: input.env,
23
22
  homeDir: input.homeDir,
@@ -593,8 +592,17 @@ async function lookupStoredBinding(store, key) {
593
592
  }
594
593
  }
595
594
  async function registerStoredBinding(store, key, binding) {
595
+ const stored = {
596
+ schemaVersion: 2,
597
+ ...binding.journalVersion === 1 ? { journalVersion: 1 } : {},
598
+ sdkSessionId: binding.sdkSessionId,
599
+ compatKey: binding.compatKey,
600
+ compactKey: binding.compactKey,
601
+ ...sessionAuthFields(binding),
602
+ updatedAt: Date.now()
603
+ };
596
604
  try {
597
- await store?.register(key, binding);
605
+ await store?.register(key, stored);
598
606
  } catch {
599
607
  await deleteStoredBinding(store, key);
600
608
  }
@@ -652,7 +660,6 @@ function computeSessionKey(input, options) {
652
660
  const authContext = {
653
661
  agentId: input.params.agentId ?? readAgentIdFromSessionKey(input.params.sessionKey),
654
662
  agentDir: input.params.agentDir,
655
- workspaceDir: input.params.workspaceDir,
656
663
  copilotHome: input.params.copilotHome
657
664
  };
658
665
  const resolved = !options.includeAuth ? resolveCopilotAuth({
@@ -744,6 +751,17 @@ function computeCompactRequestKey(params) {
744
751
  includeAuth: false
745
752
  });
746
753
  }
754
+ function failedCompaction(reason, rawError) {
755
+ return {
756
+ ok: false,
757
+ compacted: false,
758
+ reason,
759
+ failure: {
760
+ reason,
761
+ ...rawError === void 0 ? {} : { rawError }
762
+ }
763
+ };
764
+ }
747
765
  function createCopilotAgentHarness(options) {
748
766
  let poolPromise;
749
767
  let createdPool;
@@ -766,7 +784,7 @@ function createCopilotAgentHarness(options) {
766
784
  async function getPool() {
767
785
  if (options?.pool) return options.pool;
768
786
  if (!poolPromise) poolPromise = (async () => {
769
- const { createCopilotClientPool } = await import("./runtime-BiH-FQBm.mjs");
787
+ const { createCopilotClientPool } = await import("./runtime-BgRSM1VR.mjs");
770
788
  createdPool = createCopilotClientPool(options?.poolOptions);
771
789
  return createdPool;
772
790
  })();
@@ -803,7 +821,7 @@ function createCopilotAgentHarness(options) {
803
821
  async function runHarnessAttempt(params, operation) {
804
822
  return trackOperation(async () => {
805
823
  if (disposed) throw new Error("[copilot] harness has been disposed; cannot start new attempts");
806
- const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-xgkehY1T.mjs");
824
+ const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-BTNvSiix.mjs");
807
825
  if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
808
826
  const pool = await getPool();
809
827
  if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
@@ -862,14 +880,7 @@ function createCopilotAgentHarness(options) {
862
880
  sessionConfig: compactionSessionConfig ?? sessionConfig,
863
881
  ...sessionAuthFields(poolAcquire.auth)
864
882
  };
865
- await registerStoredBinding(options?.sessionStore, openclawSessionId, {
866
- schemaVersion: 2,
867
- sdkSessionId,
868
- compatKey: currentCompatKey,
869
- compactKey: currentCompactKey,
870
- ...sessionAuthFields(poolAcquire.auth),
871
- updatedAt: Date.now()
872
- });
883
+ await registerStoredBinding(options?.sessionStore, openclawSessionId, tracked);
873
884
  trackedSessions.set(openclawSessionId, tracked);
874
885
  resetBlockedStoredSessions.delete(openclawSessionId);
875
886
  }) : void 0,
@@ -912,15 +923,7 @@ function createCopilotAgentHarness(options) {
912
923
  ...baseTracked,
913
924
  ...attemptResult.journalValidated ? { journalVersion: 1 } : {}
914
925
  };
915
- await registerStoredBinding(options?.sessionStore, openclawSessionId, {
916
- schemaVersion: 2,
917
- ...attemptResult.journalValidated ? { journalVersion: 1 } : {},
918
- sdkSessionId,
919
- compatKey: nextTracked.compatKey,
920
- compactKey: nextTracked.compactKey,
921
- ...sessionAuthFields(nextTracked),
922
- updatedAt: Date.now()
923
- });
926
+ await registerStoredBinding(options?.sessionStore, openclawSessionId, nextTracked);
924
927
  trackedSessions.set(openclawSessionId, nextTracked);
925
928
  }
926
929
  });
@@ -931,7 +934,7 @@ function createCopilotAgentHarness(options) {
931
934
  async function runIsolatedCompletionV2(params) {
932
935
  return trackOperation(async () => {
933
936
  if (disposed) throw new Error("[copilot] harness has been disposed; cannot start isolated completion");
934
- const { runCopilotIsolatedCompletion } = await import("./isolated-completion-D0FvdmXD.mjs");
937
+ const { runCopilotIsolatedCompletion } = await import("./isolated-completion-DWrGtYCY.mjs");
935
938
  if (disposed) throw new Error("[copilot] harness was disposed while starting isolated completion");
936
939
  return await runCopilotIsolatedCompletion(params, async () => {
937
940
  const pool = await getPool();
@@ -1021,35 +1024,20 @@ function createCopilotAgentHarness(options) {
1021
1024
  compacted: false,
1022
1025
  reason: "missing-required-params"
1023
1026
  };
1024
- if (await bindingQueue.enqueue(openclawSessionId, () => hasPendingDeferredCompactionCleanup(openclawSessionId))) return {
1025
- ok: false,
1026
- compacted: false,
1027
- reason: "background-compaction-pending",
1028
- failure: { reason: "background-compaction-pending" }
1029
- };
1027
+ if (await bindingQueue.enqueue(openclawSessionId, () => hasPendingDeferredCompactionCleanup(openclawSessionId))) return failedCompaction("background-compaction-pending");
1030
1028
  const tracked = trackedSessions.get(openclawSessionId);
1031
1029
  const currentCompactKey = computeCompactRequestKey(params);
1032
- const { resolvePoolAcquire } = await import("./attempt-xgkehY1T.mjs");
1030
+ const { resolvePoolAcquire } = await import("./attempt-BTNvSiix.mjs");
1033
1031
  let resolvedPoolAcquire;
1034
1032
  try {
1035
1033
  resolvedPoolAcquire = resolvePoolAcquire(params);
1036
1034
  } catch (error) {
1037
- if (isCopilotByokUnsupportedProviderError(error)) return {
1038
- ok: false,
1039
- compacted: false,
1040
- reason: "missing_thread_binding",
1041
- failure: { reason: "missing_thread_binding" }
1042
- };
1035
+ if (isCopilotByokUnsupportedProviderError(error)) return failedCompaction("missing_thread_binding");
1043
1036
  throw error;
1044
1037
  }
1045
1038
  const currentAuth = sessionAuthFields(resolvedPoolAcquire.auth);
1046
1039
  const compatibleTracked = tracked?.compactKey === currentCompactKey && sessionAuthMatches(tracked, currentAuth) ? tracked : void 0;
1047
- if (!compatibleTracked) return {
1048
- ok: false,
1049
- compacted: false,
1050
- reason: "missing_thread_binding",
1051
- failure: { reason: "missing_thread_binding" }
1052
- };
1040
+ if (!compatibleTracked) return failedCompaction("missing_thread_binding");
1053
1041
  const poolAcquire = {
1054
1042
  key: compatibleTracked.poolKey,
1055
1043
  options: compatibleTracked.clientOptions
@@ -1103,37 +1091,16 @@ function createCopilotAgentHarness(options) {
1103
1091
  trackedSessions.delete(openclawSessionId);
1104
1092
  }
1105
1093
  });
1106
- return {
1107
- ok: false,
1108
- compacted: false,
1109
- reason: "stale_thread_binding",
1110
- failure: {
1111
- reason: "stale_thread_binding",
1112
- rawError
1113
- }
1114
- };
1094
+ return failedCompaction("stale_thread_binding", rawError);
1115
1095
  }
1116
- return {
1117
- ok: false,
1118
- compacted: false,
1119
- reason: "copilot-sdk-history-compact-failed",
1120
- failure: {
1121
- reason: "copilot-sdk-history-compact-failed",
1122
- rawError
1123
- }
1124
- };
1096
+ return failedCompaction("copilot-sdk-history-compact-failed", rawError);
1125
1097
  } finally {
1126
1098
  await cleanupByokProxy?.();
1127
1099
  if (pool && handle) try {
1128
1100
  await pool.release(handle);
1129
1101
  } catch {}
1130
1102
  }
1131
- if (!compactResult.success) return {
1132
- ok: false,
1133
- compacted: false,
1134
- reason: "copilot-sdk-history-compact-failed",
1135
- failure: { reason: "copilot-sdk-history-compact-failed" }
1136
- };
1103
+ if (!compactResult.success) return failedCompaction("copilot-sdk-history-compact-failed");
1137
1104
  const compacted = compactResult.tokensRemoved > 0 || compactResult.messagesRemoved > 0;
1138
1105
  if (compacted) await runAgentHarnessAfterCompactionHook({
1139
1106
  sessionFile: params.sessionFile,
@@ -1,7 +1,8 @@
1
- import { a as createCopilotByokProxy, c as tokenFingerprint, n as resolveCopilotProvider, r as createCopilotAbortError } from "./harness-pIM2FFm8.mjs";
1
+ import { a as createCopilotByokProxy, c as tokenFingerprint, n as resolveCopilotProvider, r as createCopilotAbortError } from "./harness-CAJKYXN0.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";
5
+ import { raceWithTimeout } from "openclaw/plugin-sdk/time-runtime";
5
6
  //#region extensions/copilot/src/isolated-completion.ts
6
7
  function startBestEffortCleanup(cleanup) {
7
8
  try {
@@ -22,27 +23,18 @@ async function awaitWithinCompletionBoundary(params) {
22
23
  const remainingMs = params.boundary.deadlineMs - Date.now();
23
24
  if (remainingMs <= 0) throw createTimeoutError(params.boundary.timeoutMs);
24
25
  let boundaryError;
25
- let timer;
26
- let onAbort;
27
- const boundary = new Promise((_resolve, reject) => {
28
- const rejectBoundary = (error) => {
29
- if (boundaryError) return;
26
+ const rejectBoundary = (error) => {
27
+ if (!boundaryError) {
30
28
  boundaryError = error;
31
29
  params.onBoundary?.();
32
- reject(error);
33
- };
34
- timer = setTimeout(() => rejectBoundary(createTimeoutError(params.boundary.timeoutMs)), remainingMs);
35
- if (signal) {
36
- onAbort = () => rejectBoundary(createCopilotAbortError(signal.reason));
37
- signal.addEventListener("abort", onAbort, { once: true });
38
- if (signal.aborted) onAbort();
39
30
  }
40
- });
31
+ throw boundaryError;
32
+ };
41
33
  const assertCurrent = () => {
42
34
  if (boundaryError) throw boundaryError;
43
35
  params.boundary.assertCurrent?.();
44
36
  };
45
- const operation = Promise.resolve().then(() => {
37
+ const operation = () => Promise.resolve().then(() => {
46
38
  assertCurrent();
47
39
  return params.start(remainingMs);
48
40
  }).then((value) => {
@@ -55,13 +47,13 @@ async function awaitWithinCompletionBoundary(params) {
55
47
  }
56
48
  });
57
49
  try {
58
- return await Promise.race([operation, boundary]);
50
+ return await raceWithTimeout(operation, remainingMs, () => rejectBoundary(createTimeoutError(params.boundary.timeoutMs)), {
51
+ signal,
52
+ onAbort: (aborted) => rejectBoundary(createCopilotAbortError(aborted.reason))
53
+ });
59
54
  } catch (error) {
60
55
  params.boundary.assertCurrent?.();
61
56
  throw error;
62
- } finally {
63
- if (timer) clearTimeout(timer);
64
- if (signal && onAbort) signal.removeEventListener("abort", onAbort);
65
57
  }
66
58
  }
67
59
  async function runCopilotIsolatedCompletion(params, getPool) {
@@ -5,7 +5,7 @@ import { existsSync } from "node:fs";
5
5
  import { pathToFileURL } from "node:url";
6
6
  import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
7
7
  //#region extensions/copilot/package.json
8
- var dependencies = { "@github/copilot-sdk": "1.0.14" };
8
+ var dependencies = { "@github/copilot-sdk": "1.0.16" };
9
9
  //#endregion
10
10
  //#region extensions/copilot/src/sdk-loader.ts
11
11
  function resolveCopilotSdkFallbackDir(env = process.env) {
@@ -61,7 +61,7 @@ function createMissingSdkError(primaryErr, fallbackErr, fallbackPath) {
61
61
  "",
62
62
  ` npm install ${COPILOT_SDK_SPEC}`,
63
63
  "",
64
- `The legacy fallback location is still probed at\n ${fallbackPath}`,
64
+ `The legacy fallback location is still checked at\n ${fallbackPath}`,
65
65
  "",
66
66
  "Primary resolution error:",
67
67
  ` ${summarizeError(primaryErr)}`
package/dist/harness.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createCopilotAgentHarness } from "./.setup/harness-pIM2FFm8.mjs";
1
+ import { t as createCopilotAgentHarness } from "./.setup/harness-CAJKYXN0.mjs";
2
2
  export { createCopilotAgentHarness };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createCopilotAgentHarness } from "./.setup/harness-pIM2FFm8.mjs";
1
+ import { t as createCopilotAgentHarness } from "./.setup/harness-CAJKYXN0.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.10.1",
3
+ "version": "2026.10.5-beta.1",
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",
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "type": "module",
10
10
  "dependencies": {
11
- "@github/copilot-sdk": "1.0.14"
11
+ "@github/copilot-sdk": "1.0.16"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@openclaw/plugin-sdk": "workspace:*"
@@ -24,10 +24,10 @@
24
24
  "minHostVersion": ">=2026.5.28"
25
25
  },
26
26
  "compat": {
27
- "pluginApi": ">=2026.10.1"
27
+ "pluginApi": ">=2026.10.5-beta.1"
28
28
  },
29
29
  "build": {
30
- "openclawVersion": "2026.10.1",
30
+ "openclawVersion": "2026.10.5-beta.1",
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.10.1"
50
+ "openclaw": ">=2026.10.5-beta.1"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "openclaw": {