@openclaw/copilot 2026.10.1-beta.2 → 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-BeLT-JyA.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";
@@ -10,6 +10,7 @@ import { parseDateStringTimestampMs } from "openclaw/plugin-sdk/number-runtime";
10
10
  import { createAgentHarnessToolSurfaceRuntime, normalizeAcceptedSessionSpawnResult } from "openclaw/plugin-sdk/agent-harness-tool-runtime";
11
11
  import fsp from "node:fs/promises";
12
12
  import { resolveSessionAgentIdsStrict } from "openclaw/plugin-sdk/agent-scope-runtime";
13
+ import { AsyncLocalStorage } from "node:async_hooks";
13
14
  import { convertMcpCallToolResult } from "@github/copilot-sdk";
14
15
  import { textResult } from "openclaw/plugin-sdk/tool-results";
15
16
  import { isDeepStrictEqual } from "node:util";
@@ -132,29 +133,6 @@ function createPermissionBridge(policy = rejectAllPolicy) {
132
133
  }
133
134
  //#endregion
134
135
  //#region extensions/copilot/src/replay-shim.ts
135
- function decideReplayAction(input) {
136
- if (!input) return {
137
- action: "create",
138
- downgradedFromResume: false,
139
- downgradeReason: "no-replay-state"
140
- };
141
- const sdkSessionId = normalizeOptionalString(input.sdkSessionId);
142
- if (!sdkSessionId) return {
143
- action: "create",
144
- downgradedFromResume: false,
145
- downgradeReason: "no-sdk-session-id"
146
- };
147
- if (input.replayInvalid === true) return {
148
- action: "create",
149
- downgradedFromResume: true,
150
- downgradeReason: "replay-invalid"
151
- };
152
- return {
153
- action: "resume",
154
- sdkSessionId,
155
- downgradedFromResume: false
156
- };
157
- }
158
136
  const MISSING_SESSION_CODES = /* @__PURE__ */ new Set([
159
137
  "SESSION_NOT_FOUND",
160
138
  "session_not_found",
@@ -169,30 +147,12 @@ const MISSING_SESSION_MESSAGE_PATTERNS = [
169
147
  /\bsession .* does not exist\b/i,
170
148
  /\bno such session\b/i
171
149
  ];
172
- function classifyResumeFailure(error) {
150
+ function isMissingCopilotSessionError(error) {
173
151
  const record = asOptionalObjectRecord(error);
174
- if (record?.status === 404) return {
175
- recoverable: true,
176
- kind: "missing"
177
- };
178
- if (record?.statusCode === 404) return {
179
- recoverable: true,
180
- kind: "missing"
181
- };
152
+ if (record?.status === 404 || record?.statusCode === 404) return true;
182
153
  const code = record?.code;
183
- if (typeof code === "string" && MISSING_SESSION_CODES.has(code)) return {
184
- recoverable: true,
185
- kind: "missing"
186
- };
187
154
  const message = record?.message;
188
- if (typeof message === "string" && MISSING_SESSION_MESSAGE_PATTERNS.some((pattern) => pattern.test(message))) return {
189
- recoverable: true,
190
- kind: "missing"
191
- };
192
- return {
193
- recoverable: false,
194
- kind: "unknown"
195
- };
155
+ return typeof code === "string" && MISSING_SESSION_CODES.has(code) || typeof message === "string" && MISSING_SESSION_MESSAGE_PATTERNS.some((pattern) => pattern.test(message));
196
156
  }
197
157
  function computeReplayMetadata(input) {
198
158
  const priorReplayInvalid = input.priorReplayInvalid === true;
@@ -412,7 +372,6 @@ function resolvePoolAcquire(params) {
412
372
  const authContext = {
413
373
  agentId: readNonEmptyString(params.agentId),
414
374
  agentDir: readNonEmptyString(params.agentDir),
415
- workspaceDir: readNonEmptyString(params.workspaceDir),
416
375
  copilotHome: readNonEmptyString(params.copilotHome)
417
376
  };
418
377
  const auth = provider.mode === "byok" ? createCopilotByokAuth({
@@ -638,13 +597,15 @@ function attachEventBridge(session, options) {
638
597
  const sessionIdle = createDeferred();
639
598
  let firstDeltaError;
640
599
  let detached = false;
641
- let unconsumedDurableReasoning = false;
642
600
  const unsubscribeFns = [];
643
601
  const listen = (eventType, handler) => {
644
602
  unsubscribeFns.push(session.on(eventType, handler));
645
603
  };
646
- listen("user.message", (event) => {
647
- 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;
648
609
  flushPendingAssistantProjection();
649
610
  const projection = options.transcriptProjection;
650
611
  if (!projection) return;
@@ -667,29 +628,25 @@ function attachEventBridge(session, options) {
667
628
  }
668
629
  });
669
630
  });
670
- listen("system.message", (event) => {
671
- if (!isRootSessionEvent(event) || event.ephemeral === true) return;
672
- options.transcriptProjection?.journal.markReplayIncomplete();
673
- });
674
- listen("skill.invoked", (event) => {
675
- if (isRootSessionEvent(event) && event.ephemeral !== true) options.transcriptProjection?.journal.markReplayIncomplete();
676
- });
677
- listen("system.notification", (event) => {
678
- 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();
679
637
  });
680
- listen("assistant.message_delta", (event) => {
681
- if (!isRootSessionEvent(event)) return;
638
+ listenRoot("assistant.message_delta", (event) => {
682
639
  const messageId = readNonEmptyStringPreservingWhitespace(event.data.messageId) ?? "assistant-message";
683
640
  const delta = event.data.deltaContent;
684
641
  if (!delta) return;
685
- const entry = ensureMessageAccumulator(messagesById, messageId);
686
- entry.text += delta;
642
+ const text = (messagesById.get(messageId) ?? "") + delta;
643
+ messagesById.set(messageId, text);
687
644
  const onAssistantDelta = options.onAssistantDelta;
688
645
  if (!onAssistantDelta) return;
689
646
  const payload = {
690
647
  delta,
691
648
  sessionId: options.getSdkSessionId(),
692
- text: entry.text,
649
+ text,
693
650
  usage
694
651
  };
695
652
  deltaQueue = deltaQueue.then(() => onAssistantDelta(payload), () => onAssistantDelta(payload)).catch((error) => {
@@ -700,32 +657,27 @@ function attachEventBridge(session, options) {
700
657
  });
701
658
  deltaChain.catch(() => void 0);
702
659
  });
703
- listen("assistant.reasoning_delta", (event) => {
704
- if (!isRootSessionEvent(event)) return;
660
+ listenRoot("assistant.reasoning_delta", (event) => {
705
661
  const reasoningId = readNonEmptyStringPreservingWhitespace(event.data.reasoningId) ?? "assistant-reasoning";
706
662
  const delta = event.data.deltaContent;
707
663
  if (!delta) return;
708
664
  reasoningById.set(reasoningId, `${reasoningById.get(reasoningId) ?? ""}${delta}`);
709
665
  });
710
- listen("assistant.reasoning", (event) => {
711
- if (!isRootSessionEvent(event) || event.ephemeral === true) return;
666
+ listenRoot("assistant.reasoning", (event) => {
667
+ if (event.ephemeral === true) return;
712
668
  reasoningById.set(event.data.reasoningId, event.data.content);
713
669
  durableReasoningById.set(event.data.reasoningId, event.data.content);
714
- unconsumedDurableReasoning = true;
715
- });
716
- listen("assistant.turn_start", (event) => {
717
- if (isRootSessionEvent(event)) markUnconsumedReasoningIncomplete();
718
670
  });
671
+ listenRoot("assistant.turn_start", markUnconsumedReasoningIncomplete);
719
672
  listen("assistant.message", handleAssistantMessage);
720
- listen("assistant.usage", (event) => {
721
- if (!isRootSessionEvent(event)) return;
673
+ listenRoot("assistant.usage", (event) => {
722
674
  usage = normalizeCopilotUsage(event.data);
723
675
  const apiCallId = readNonEmptyStringPreservingWhitespace(event.data.apiCallId);
724
676
  if (apiCallId && usage) usageByApiCallId.set(apiCallId, usage);
725
677
  if (apiCallId) flushPendingAssistantProjection(apiCallId);
726
678
  });
727
- listen("tool.user_requested", (event) => {
728
- if (isRootSessionEvent(event) && event.ephemeral !== true) {
679
+ listenRoot("tool.user_requested", (event) => {
680
+ if (event.ephemeral !== true) {
729
681
  userRequestedToolCallIds.add(event.data.toolCallId);
730
682
  options.transcriptProjection?.journal.markReplayIncomplete();
731
683
  }
@@ -856,8 +808,7 @@ function attachEventBridge(session, options) {
856
808
  }
857
809
  });
858
810
  });
859
- listen("session.compaction_start", (event) => {
860
- if (!isRootSessionEvent(event)) return;
811
+ listenRoot("session.compaction_start", () => {
861
812
  observedCompaction = true;
862
813
  if (activeCompactionCount === 0) compactionIdle = createDeferred();
863
814
  activeCompactionCount += 1;
@@ -878,8 +829,7 @@ function attachEventBridge(session, options) {
878
829
  compactionIdle = void 0;
879
830
  }
880
831
  });
881
- listen("session.idle", (event) => {
882
- if (!isRootSessionEvent(event)) return;
832
+ listenRoot("session.idle", () => {
883
833
  markUnconsumedReasoningIncomplete();
884
834
  flushPendingAssistantProjection();
885
835
  observedSessionIdle = true;
@@ -984,16 +934,15 @@ function attachEventBridge(session, options) {
984
934
  if (handledAssistantEventIds.has(event.id)) return;
985
935
  handledAssistantEventIds.add(event.id);
986
936
  for (const request of event.data.toolRequests ?? []) projectedToolNamesByCallId.set(request.toolCallId, request.name);
987
- const entry = ensureMessageAccumulator(messagesById, event.data.messageId);
988
- 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);
989
939
  lastAssistantReasoningText = event.data.reasoningText ?? ([...reasoningById.values()].join("") || void 0);
990
940
  const transcriptReasoningText = event.data.reasoningText ?? ([...durableReasoningById.values()].join("") || void 0);
991
941
  reasoningById.clear();
992
942
  durableReasoningById.clear();
993
- unconsumedDurableReasoning = false;
994
943
  const chunk = {
995
944
  event,
996
- assistantTexts: [messagesById.get(event.data.messageId)?.text ?? ""],
945
+ assistantTexts: [messagesById.get(event.data.messageId) ?? ""],
997
946
  ...lastAssistantReasoningText ? { reasoningText: lastAssistantReasoningText } : {},
998
947
  transcriptAssistantTexts: [event.data.content ?? ""],
999
948
  ...transcriptReasoningText ? { transcriptReasoningText } : {}
@@ -1031,10 +980,9 @@ function attachEventBridge(session, options) {
1031
980
  recordAssistantProjection(group);
1032
981
  }
1033
982
  function markUnconsumedReasoningIncomplete() {
1034
- if (unconsumedDurableReasoning) options.transcriptProjection?.journal.markReplayIncomplete();
983
+ if (durableReasoningById.size > 0) options.transcriptProjection?.journal.markReplayIncomplete();
1035
984
  reasoningById.clear();
1036
985
  durableReasoningById.clear();
1037
- unconsumedDurableReasoning = false;
1038
986
  }
1039
987
  function flushPendingAssistantProjectionForToolCall(toolCallId) {
1040
988
  if (pendingAssistantProjection?.chunks.some((chunk) => chunk.event.data.toolRequests?.some((request) => request.toolCallId === toolCallId))) flushPendingAssistantProjection();
@@ -1080,16 +1028,8 @@ function attachEventBridge(session, options) {
1080
1028
  if (activeCompactionCount > 0 || compactionChain !== callbacks) await awaitStableCompaction();
1081
1029
  }
1082
1030
  }
1083
- function ensureMessageAccumulator(messagesById, messageId) {
1084
- let entry = messagesById.get(messageId);
1085
- if (!entry) {
1086
- entry = { text: "" };
1087
- messagesById.set(messageId, entry);
1088
- }
1089
- return entry;
1090
- }
1091
1031
  function finalizeAssistantTexts(messagesById, event) {
1092
- const texts = [...messagesById.values()].map((message) => message.text).filter((text) => text.length > 0);
1032
+ const texts = [...messagesById.values()].filter((text) => text.length > 0);
1093
1033
  if (texts.length > 0) return texts;
1094
1034
  if (event?.data.content) return [event.data.content];
1095
1035
  return [];
@@ -1164,16 +1104,10 @@ async function awaitDeferredCleanupBeforeDeadline(params) {
1164
1104
  await params.bridge.awaitCompactionCompletion();
1165
1105
  return "completed";
1166
1106
  })();
1167
- let resolveAbort = () => void 0;
1168
- const aborted = new Promise((resolve) => {
1169
- resolveAbort = () => resolve("aborted");
1170
- params.abortSignal?.addEventListener("abort", resolveAbort, { once: true });
1107
+ return await raceWithTimeout(completion, params.timeoutMs, () => "deadline", {
1108
+ signal: params.abortSignal,
1109
+ onAbort: () => "aborted"
1171
1110
  });
1172
- try {
1173
- return await raceWithTimeout(Promise.race([completion, aborted]), params.timeoutMs, () => "deadline");
1174
- } finally {
1175
- params.abortSignal?.removeEventListener("abort", resolveAbort);
1176
- }
1177
1111
  }
1178
1112
  //#endregion
1179
1113
  //#region extensions/copilot/src/attempt-active-run.ts
@@ -1470,7 +1404,8 @@ async function createCopilotToolBridge(input) {
1470
1404
  sessionKey: attemptParams.sessionKey,
1471
1405
  scheduledToolPolicy: attemptParams.scheduledToolPolicy,
1472
1406
  sourceReplyDeliveryMode: attemptParams.sourceReplyDeliveryMode,
1473
- toolsAllow: attemptParams.toolsAllow
1407
+ toolsAllow: attemptParams.toolsAllow,
1408
+ trigger: attemptParams.trigger
1474
1409
  });
1475
1410
  const toolOptions = buildOpenClawCodingToolsOptions(input, {
1476
1411
  ...toolPlan,
@@ -1480,9 +1415,9 @@ async function createCopilotToolBridge(input) {
1480
1415
  if (!hostCapabilities) throw new Error("Copilot attempt tools require host-bound capabilities.");
1481
1416
  const bindingCwd = toolOptions.cwd ?? toolOptions.workspaceDir;
1482
1417
  const bindingOptions = bindingCwd ? { cwd: bindingCwd } : void 0;
1483
- const createToolSurface = hostCapabilities.createToolSurface;
1484
- if (!createToolSurface) throw new Error("Copilot tool construction requires a current host capability");
1485
- 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);
1486
1421
  const boundSourceTools = new Set(sourceTools);
1487
1422
  const allowedSourceTools = applyEmbeddedAttemptToolsAllow(sourceTools, toolSurfaceRuntime.runtimeToolAllowlist, { toolMeta: getPluginToolMeta });
1488
1423
  const compactedTools = toolSurfaceRuntime.compactTools(allowedSourceTools, { localModelLeanApplied: true });
@@ -1494,10 +1429,11 @@ async function createCopilotToolBridge(input) {
1494
1429
  const exposedTools = compactedTools.tools.map((tool) => newlyBoundTools.get(tool) ?? tool);
1495
1430
  const duplicateNames = findDuplicateToolNames(exposedTools);
1496
1431
  if (duplicateNames.length > 0) throw new Error(`[copilot-tool-bridge] duplicate tool names: ${duplicateNames.join(", ")}`);
1432
+ const runInAttemptContext = AsyncLocalStorage.snapshot();
1497
1433
  let sequentialBarrier = Promise.resolve();
1498
1434
  const pendingCalls = /* @__PURE__ */ new Set();
1499
1435
  const scheduleToolExecution = (executionMode, execute) => {
1500
- const run = (executionMode === "sequential" ? Promise.all(pendingCalls) : sequentialBarrier).then(execute);
1436
+ const run = (executionMode === "sequential" ? Promise.all(pendingCalls) : sequentialBarrier).then(() => runInAttemptContext(execute));
1501
1437
  const settled = run.then(() => void 0, () => void 0);
1502
1438
  pendingCalls.add(settled);
1503
1439
  settled.then(() => pendingCalls.delete(settled));
@@ -2035,41 +1971,29 @@ const COPILOT_BOOTSTRAP_CONTEXT_ORDER = /* @__PURE__ */ new Map([
2035
1971
  ["user.md", 60],
2036
1972
  ["memory.md", 70]
2037
1973
  ]);
2038
- async function resolveCopilotWorkspaceBootstrapContext(params) {
1974
+ async function loadCopilotWorkspaceInstructions(params) {
2039
1975
  const { attempt } = params;
2040
1976
  const workspaceDir = readResolvedWorkspacePath(attempt.workspaceDir);
2041
- if (!workspaceDir) return {
2042
- bootstrapFiles: [],
2043
- contextFiles: []
2044
- };
1977
+ if (!workspaceDir) return;
2045
1978
  try {
2046
- const bootstrapContext = await resolveBootstrapContextForRun({
2047
- workspaceDir,
2048
- config: attempt.config,
2049
- sessionKey: readNonBlankString(attempt.sessionKey),
2050
- sessionId: readNonBlankString(attempt.sessionId),
2051
- chatType: attempt.chatType,
2052
- agentId: readNonBlankString(attempt.agentId),
2053
- warn: params.warn,
2054
- contextMode: attempt.bootstrapContextMode,
2055
- runKind: attempt.bootstrapContextRunKind
2056
- });
2057
- const contextFiles = remapCopilotBootstrapContextFiles({
2058
- 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,
2059
1991
  sourceWorkspaceDir: workspaceDir,
2060
1992
  targetWorkspaceDir: readResolvedWorkspacePath(params.effectiveWorkspaceDir) ?? workspaceDir
2061
- });
2062
- return {
2063
- bootstrapFiles: bootstrapContext.bootstrapFiles,
2064
- contextFiles,
2065
- instructions: renderCopilotWorkspaceBootstrapInstructions(contextFiles)
2066
- };
1993
+ }));
2067
1994
  } catch (error) {
2068
1995
  params.warn?.(`[copilot-attempt] failed to load workspace bootstrap instructions: ${error instanceof Error ? error.message : String(error)}`);
2069
- return {
2070
- bootstrapFiles: [],
2071
- contextFiles: []
2072
- };
1996
+ return;
2073
1997
  }
2074
1998
  }
2075
1999
  function remapCopilotBootstrapContextFiles(params) {
@@ -2137,11 +2061,11 @@ async function createCopilotSessionSetup(params) {
2137
2061
  assertCopilotAttemptHostCapabilities(input);
2138
2062
  return input;
2139
2063
  })();
2140
- const workspaceBootstrap = ordinaryAttemptInput ? await resolveCopilotWorkspaceBootstrapContext({
2064
+ const workspaceBootstrapInstructions = ordinaryAttemptInput ? await loadCopilotWorkspaceInstructions({
2141
2065
  attempt: ordinaryAttemptInput,
2142
2066
  effectiveWorkspaceDir,
2143
2067
  warn: (message) => console.warn(message)
2144
- }) : { instructions: void 0 };
2068
+ }) : void 0;
2145
2069
  const forceToolNames = ordinaryAttemptInput && shouldForceCopilotMessageTool(ordinaryAttemptInput) ? ["message"] : void 0;
2146
2070
  let promptPolicyResult;
2147
2071
  let promptBuild;
@@ -2170,7 +2094,7 @@ async function createCopilotSessionSetup(params) {
2170
2094
  callableToolNames: promptPolicyResult.callableToolNames,
2171
2095
  toolSchemaDirectoryPrompt: promptPolicyResult.toolSchemaDirectoryPrompt,
2172
2096
  requireExplicitMessageTarget: promptToolPolicy.requireExplicitMessageTarget,
2173
- workspaceBootstrapInstructions: workspaceBootstrap.instructions
2097
+ workspaceBootstrapInstructions
2174
2098
  });
2175
2099
  } },
2176
2100
  messages,
@@ -2365,7 +2289,7 @@ function createAttemptTranscriptJournal(params) {
2365
2289
  ...write.eventId ? { eventId: write.eventId } : {},
2366
2290
  idempotencyLookup: "scan",
2367
2291
  message: write.message,
2368
- prepareMessageAfterIdempotencyCheck: () => prepare(write, { singleton: true })
2292
+ preparation: { prepareMessage: async () => prepare(write, { singleton: true }) }
2369
2293
  });
2370
2294
  if (outcome.kind === "suppressed") {
2371
2295
  write.recorder?.markBlocked();
@@ -2843,12 +2767,9 @@ async function runCopilotExecution(context) {
2843
2767
  });
2844
2768
  const { attemptInput, compactionSessionConfig, emitLlmInput, hasNativePromptHook, sessionConfig, userInputBridge } = sessionSetup;
2845
2769
  userInputBridgeRef = userInputBridge;
2846
- const replayDecision = decideReplayAction({
2847
- sdkSessionId: input.initialReplayState?.sdkSessionId,
2848
- replayInvalid: input.initialReplayState?.replayInvalid
2849
- });
2850
- downgradedFromResume = replayDecision.downgradedFromResume;
2851
- 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;
2852
2773
  if (resumeSessionId) try {
2853
2774
  session = await client.resumeSession(resumeSessionId, {
2854
2775
  ...sessionConfig,
@@ -2858,7 +2779,7 @@ async function runCopilotExecution(context) {
2858
2779
  nativeSessionHistoryValidated = input.initialReplayState?.journalValidated === true;
2859
2780
  } catch (error) {
2860
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);
2861
- if (!classifyResumeFailure(error).recoverable) throw error;
2782
+ if (!isMissingCopilotSessionError(error)) throw error;
2862
2783
  resumeFailureRecovered = true;
2863
2784
  }
2864
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-Dr9LPO0j.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-B-WKqKY6.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-Dr9LPO0j.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-BeLT-JyA.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-BeLT-JyA.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-BeLT-JyA.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-beta.2",
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-beta.2"
27
+ "pluginApi": ">=2026.10.5-beta.1"
28
28
  },
29
29
  "build": {
30
- "openclawVersion": "2026.10.1-beta.2",
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-beta.2"
50
+ "openclaw": ">=2026.10.5-beta.1"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "openclaw": {