@openclaw/copilot 2026.7.2-beta.7 → 2026.8.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,24 +6,5 @@ function normalizeCompatibilityConfig({ cfg }) {
6
6
  changes: []
7
7
  };
8
8
  }
9
- /**
10
- * Session-state ownership claim for the copilot agent runtime.
11
- *
12
- * - id / label: Identify the extension in doctor output.
13
- * - providerIds: The subscription Copilot providers.
14
- * - runtimeIds: Our harness id (matches harness.ts `id` field).
15
- * - cliSessionKeys: Session keys this harness writes; doctor uses
16
- * this when pruning stale CLI session state.
17
- * - authProfilePrefixes: Conventional prefix for any auth profile
18
- * created/consumed by this extension.
19
- */
20
- const sessionRouteStateOwners = [{
21
- id: "copilot",
22
- label: "GitHub Copilot agent runtime",
23
- providerIds: ["github-copilot"],
24
- runtimeIds: ["copilot"],
25
- cliSessionKeys: ["copilot"],
26
- authProfilePrefixes: ["github-copilot:"]
27
- }];
28
9
  //#endregion
29
- export { legacyConfigRules, normalizeCompatibilityConfig, sessionRouteStateOwners };
10
+ export { legacyConfigRules, normalizeCompatibilityConfig };
@@ -1,3 +1,4 @@
1
+ import { filterStringRecord, normalizeOptionalString, readNonEmptyStringPreservingWhitespace } from "openclaw/plugin-sdk/string-coerce-runtime";
1
2
  import { buildAgentHookContextChannelFields, compactWithSafetyTimeout, getModelProviderRequestTransport, projectSettledTurnFinalizationAttemptResult, resolveCompactionTimeoutMs, runAgentHarnessAfterCompactionHook, runAgentHarnessBeforeCompactionHook } from "openclaw/plugin-sdk/agent-harness-runtime";
2
3
  import { createHash, randomBytes } from "node:crypto";
3
4
  import { homedir } from "node:os";
@@ -84,16 +85,16 @@ function resolveCopilotAuth(input) {
84
85
  const homeDir = input.homeDir ?? homedir;
85
86
  const agentId = sanitizeAgentId(input.agentId);
86
87
  const copilotHome = resolveCopilotHome({
87
- explicit: readString$1(input.copilotHome),
88
- agentDir: readString$1(input.agentDir),
89
- workspaceDir: readString$1(input.workspaceDir),
88
+ explicit: readNonEmptyStringPreservingWhitespace(input.copilotHome),
89
+ agentDir: readNonEmptyStringPreservingWhitespace(input.agentDir),
90
+ workspaceDir: readNonEmptyStringPreservingWhitespace(input.workspaceDir),
90
91
  agentId,
91
92
  env,
92
93
  homeDir
93
94
  });
94
- const explicitToken = readString$1(input.auth?.gitHubToken);
95
- const explicitProfileId = readString$1(input.auth?.profileId) ?? readString$1(input.authProfileId);
96
- const explicitProfileVersion = readString$1(input.auth?.profileVersion) ?? readString$1(input.profileVersion);
95
+ const explicitToken = readNonEmptyStringPreservingWhitespace(input.auth?.gitHubToken);
96
+ const explicitProfileId = readNonEmptyStringPreservingWhitespace(input.auth?.profileId) ?? readNonEmptyStringPreservingWhitespace(input.authProfileId);
97
+ const explicitProfileVersion = readNonEmptyStringPreservingWhitespace(input.auth?.profileVersion) ?? readNonEmptyStringPreservingWhitespace(input.profileVersion);
97
98
  if (input.auth?.useLoggedInUser === true) return {
98
99
  authMode: "useLoggedInUser",
99
100
  copilotHome,
@@ -110,11 +111,11 @@ function resolveCopilotAuth(input) {
110
111
  agentId
111
112
  };
112
113
  }
113
- const contractToken = readString$1(input.resolvedApiKey);
114
+ const contractToken = readNonEmptyStringPreservingWhitespace(input.resolvedApiKey);
114
115
  if (contractToken) return {
115
116
  authMode: "gitHubToken",
116
117
  gitHubToken: contractToken,
117
- authProfileId: readString$1(input.authProfileId) ?? "pi:resolved",
118
+ authProfileId: readNonEmptyStringPreservingWhitespace(input.authProfileId) ?? "pi:resolved",
118
119
  authProfileVersion: tokenFingerprint(contractToken),
119
120
  copilotHome,
120
121
  agentId
@@ -155,7 +156,7 @@ function sanitizeAgentId(value) {
155
156
  function resolveCopilotHome(args) {
156
157
  if (args.explicit) return resolve(args.explicit);
157
158
  if (args.agentDir) return resolve(join(args.agentDir, "copilot"));
158
- const openClawHome = readString$1(args.env.OPENCLAW_HOME);
159
+ const openClawHome = readNonEmptyStringPreservingWhitespace(args.env.OPENCLAW_HOME);
159
160
  return resolve(join(openClawHome ? resolve(openClawHome) : safeHomeDir(args.homeDir), ".openclaw", "agents", args.agentId, "copilot"));
160
161
  }
161
162
  function safeHomeDir(homeDir) {
@@ -169,19 +170,19 @@ function readEnvTokenFallback(env) {
169
170
  const candidates = [
170
171
  {
171
172
  name: "OPENCLAW_GITHUB_TOKEN",
172
- value: readString$1(env.OPENCLAW_GITHUB_TOKEN)
173
+ value: readNonEmptyStringPreservingWhitespace(env.OPENCLAW_GITHUB_TOKEN)
173
174
  },
174
175
  {
175
176
  name: "COPILOT_GITHUB_TOKEN",
176
- value: readString$1(env.COPILOT_GITHUB_TOKEN)
177
+ value: readNonEmptyStringPreservingWhitespace(env.COPILOT_GITHUB_TOKEN)
177
178
  },
178
179
  {
179
180
  name: "GH_TOKEN",
180
- value: readString$1(env.GH_TOKEN)
181
+ value: readNonEmptyStringPreservingWhitespace(env.GH_TOKEN)
181
182
  },
182
183
  {
183
184
  name: "GITHUB_TOKEN",
184
- value: readString$1(env.GITHUB_TOKEN)
185
+ value: readNonEmptyStringPreservingWhitespace(env.GITHUB_TOKEN)
185
186
  }
186
187
  ];
187
188
  for (const { name, value } of candidates) if (value) return {
@@ -201,9 +202,6 @@ function readEnvTokenFallback(env) {
201
202
  function tokenFingerprint(token) {
202
203
  return `sha256:${createHash("sha256").update(token).digest("hex").slice(0, 12)}`;
203
204
  }
204
- function readString$1(value) {
205
- return typeof value === "string" && value.length > 0 ? value : void 0;
206
- }
207
205
  //#endregion
208
206
  //#region extensions/copilot/src/byok-proxy.ts
209
207
  const LOOPBACK_HOST = "127.0.0.1";
@@ -441,15 +439,15 @@ const QUERY_PARAM_NAME_SEPARATOR_RE = /[\p{C}\p{Z}\u115F\u1160\u3164\uFFA0+]/gu;
441
439
  */
442
440
  function resolveCopilotProvider(params) {
443
441
  if (params.model.provider.trim().toLowerCase() === "github-copilot") return { mode: "github-copilot" };
444
- const baseUrl = readString(params.model.baseUrl);
442
+ const baseUrl = normalizeOptionalString(params.model.baseUrl);
445
443
  if (!baseUrl) throw new Error(COPILOT_BYOK_PROVIDER_ERROR);
446
444
  assertByokEndpointAllowed(baseUrl);
447
445
  if (hasUnsupportedTransportPolicy(params.model)) throw new Error(COPILOT_BYOK_TRANSPORT_POLICY_ERROR);
448
- const api = readString(params.model.api)?.toLowerCase() ?? "openai-responses";
446
+ const api = normalizeOptionalString(params.model.api)?.toLowerCase() ?? "openai-responses";
449
447
  const provider = resolveProviderType(api, baseUrl, params.model.azureApiVersion);
450
448
  const resolvedApiKey = resolveProviderCredential(params.resolvedApiKey);
451
- const headers = resolveProviderHeaders(params.model.headers);
452
- const requestAuthMode = readString(params.model.requestAuthMode)?.toLowerCase();
449
+ const headers = filterStringRecord(params.model.headers);
450
+ const requestAuthMode = normalizeOptionalString(params.model.requestAuthMode)?.toLowerCase();
453
451
  const usePreparedRequestAuth = requestAuthMode !== void 0 && requestAuthMode !== "provider-default";
454
452
  return {
455
453
  mode: "byok",
@@ -484,10 +482,10 @@ function isCopilotByokUnsupportedProviderError(error) {
484
482
  return error instanceof Error && (error.message === COPILOT_BYOK_PROVIDER_ERROR || error.message === COPILOT_BYOK_TRANSPORT_POLICY_ERROR || error.message === COPILOT_BYOK_ENDPOINT_POLICY_ERROR);
485
483
  }
486
484
  function supportsCopilotByokProviderShape(model) {
487
- if (!readString(model.baseUrl) || hasUnsupportedTransportPolicy(model)) return false;
485
+ if (!normalizeOptionalString(model.baseUrl) || hasUnsupportedTransportPolicy(model)) return false;
488
486
  try {
489
- resolveProviderType(readString(model.api)?.toLowerCase() ?? "openai-responses", readString(model.baseUrl), void 0);
490
- assertByokEndpointHostAllowed(readString(model.baseUrl));
487
+ resolveProviderType(normalizeOptionalString(model.api)?.toLowerCase() ?? "openai-responses", normalizeOptionalString(model.baseUrl), void 0);
488
+ assertByokEndpointHostAllowed(normalizeOptionalString(model.baseUrl));
491
489
  return true;
492
490
  } catch {
493
491
  return false;
@@ -556,7 +554,7 @@ function resolveAzureProviderType(baseUrl, apiVersion) {
556
554
  url.pathname = "";
557
555
  url.search = "";
558
556
  url.hash = "";
559
- const resolvedApiVersion = readString(apiVersion);
557
+ const resolvedApiVersion = normalizeOptionalString(apiVersion);
560
558
  return {
561
559
  type: "azure",
562
560
  wireApi: "responses",
@@ -579,18 +577,10 @@ function stableSerialize(value) {
579
577
  if (value && typeof value === "object") return `{${Object.entries(value).toSorted(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => `${JSON.stringify(key)}:${stableSerialize(entry)}`).join(",")}}`;
580
578
  return JSON.stringify(value) ?? "null";
581
579
  }
582
- function readString(value) {
583
- return typeof value === "string" && value.trim() ? value.trim() : void 0;
584
- }
585
580
  function resolveProviderCredential(value) {
586
- const credential = readString(value);
581
+ const credential = normalizeOptionalString(value);
587
582
  return credential && !isNonSecretApiKeyMarker(credential) ? credential : void 0;
588
583
  }
589
- function resolveProviderHeaders(headers) {
590
- if (!headers) return;
591
- const resolved = Object.fromEntries(Object.entries(headers).filter(([, value]) => typeof value === "string"));
592
- return Object.keys(resolved).length > 0 ? resolved : void 0;
593
- }
594
584
  //#endregion
595
585
  //#region extensions/copilot/harness.ts
596
586
  const COPILOT_PROVIDER_IDS = /* @__PURE__ */ new Set(["github-copilot"]);
@@ -703,8 +693,8 @@ function computeSessionKey(params, options) {
703
693
  const provider = modelObj.provider ?? (typeof p.provider === "string" ? p.provider : "");
704
694
  const modelId = modelObj.id ?? (typeof p.modelId === "string" ? p.modelId : void 0) ?? (typeof p.model === "string" ? p.model : "");
705
695
  const requestTransport = p.model && typeof p.model === "object" ? getModelProviderRequestTransport(p.model) : void 0;
706
- const requestAuthMode = readSessionString(requestTransport?.auth?.mode ?? modelObj.request?.auth?.mode);
707
- const azureApiVersion = readSessionString(modelObj.azureApiVersion ?? modelObj.params?.azureApiVersion);
696
+ const requestAuthMode = normalizeOptionalString(requestTransport?.auth?.mode ?? modelObj.request?.auth?.mode);
697
+ const azureApiVersion = normalizeOptionalString(modelObj.azureApiVersion ?? modelObj.params?.azureApiVersion);
708
698
  let authParts;
709
699
  let resolvedAgentId = "";
710
700
  let resolvedCopilotHome = "";
@@ -778,9 +768,6 @@ function computeSessionKey(params, options) {
778
768
  ...options.includeAuth ? authParts : []
779
769
  ].join("|");
780
770
  }
781
- function readSessionString(value) {
782
- return typeof value === "string" && value.trim() ? value.trim() : void 0;
783
- }
784
771
  function fingerprintSessionValue(value) {
785
772
  return typeof value === "string" && value ? tokenFingerprint(value) : "";
786
773
  }
@@ -821,7 +808,7 @@ function createCopilotAgentHarness(options) {
821
808
  async function getPool() {
822
809
  if (options?.pool) return options.pool;
823
810
  if (!poolPromise) poolPromise = (async () => {
824
- const { createCopilotClientPool } = await import("./runtime-BY2Yi3Dg.js");
811
+ const { createCopilotClientPool } = await import("./runtime-C2t8Iz5R.js");
825
812
  createdPool = createCopilotClientPool(options?.poolOptions);
826
813
  return createdPool;
827
814
  })();
@@ -858,7 +845,7 @@ function createCopilotAgentHarness(options) {
858
845
  async function runHarnessAttempt(params, operation) {
859
846
  const attemptPromise = (async () => {
860
847
  if (disposed) throw new Error("[copilot] harness has been disposed; cannot start new attempts");
861
- const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-D6tQnv01.js");
848
+ const { resolvePoolAcquire, runCopilotAttempt } = await import("./attempt-BNDq00ZS.js");
862
849
  if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
863
850
  const pool = await getPool();
864
851
  if (disposed) throw new Error("[copilot] harness was disposed while starting an attempt");
@@ -986,10 +973,29 @@ function createCopilotAgentHarness(options) {
986
973
  inFlight.delete(attemptPromise);
987
974
  }
988
975
  }
976
+ async function runIsolatedCompletionV2(params) {
977
+ const completionPromise = (async () => {
978
+ if (disposed) throw new Error("[copilot] harness has been disposed; cannot start isolated completion");
979
+ const { runCopilotIsolatedCompletion } = await import("./isolated-completion-CM4w2GCk.js");
980
+ if (disposed) throw new Error("[copilot] harness was disposed while starting isolated completion");
981
+ return await runCopilotIsolatedCompletion(params, async () => {
982
+ const pool = await getPool();
983
+ if (disposed) throw new Error("[copilot] harness was disposed while starting isolated completion");
984
+ return pool;
985
+ });
986
+ })();
987
+ inFlight.add(completionPromise);
988
+ try {
989
+ return await completionPromise;
990
+ } finally {
991
+ inFlight.delete(completionPromise);
992
+ }
993
+ }
989
994
  return {
990
995
  id: options?.id ?? "copilot",
991
996
  label: options?.label ?? "GitHub Copilot agent runtime",
992
997
  autoSelection: { providerIds: [] },
998
+ conversationToolPolicySupport: "exact",
993
999
  supports(ctx) {
994
1000
  if (String(ctx.requestedRuntime ?? "").trim().toLowerCase() !== "copilot") return {
995
1001
  supported: false,
@@ -1025,6 +1031,7 @@ function createCopilotAgentHarness(options) {
1025
1031
  };
1026
1032
  },
1027
1033
  runAttempt: (params) => runHarnessAttempt(params, "attempt"),
1034
+ runIsolatedCompletionV2,
1028
1035
  finalizeSettledTurn: async ({ attempt }) => {
1029
1036
  return projectSettledTurnFinalizationAttemptResult(await runHarnessAttempt(attempt, "settled-tool-finalization"));
1030
1037
  },
@@ -1060,7 +1067,7 @@ function createCopilotAgentHarness(options) {
1060
1067
  };
1061
1068
  const tracked = trackedSessions.get(openclawSessionId);
1062
1069
  const currentCompactKey = computeSessionCompactKey(params);
1063
- const { resolvePoolAcquire } = await import("./attempt-D6tQnv01.js");
1070
+ const { resolvePoolAcquire } = await import("./attempt-BNDq00ZS.js");
1064
1071
  let resolvedPoolAcquire;
1065
1072
  let currentAuth;
1066
1073
  try {
@@ -1200,4 +1207,4 @@ function createCopilotAgentHarness(options) {
1200
1207
  };
1201
1208
  }
1202
1209
  //#endregion
1203
- export { resolveCopilotAuth as a, createCopilotByokAuth as i, resolveCopilotProvider as n, createCopilotByokProxy as r, createCopilotAgentHarness as t };
1210
+ export { resolveCopilotAuth as a, createCopilotByokAuth as i, resolveCopilotProvider as n, tokenFingerprint as o, createCopilotByokProxy as r, createCopilotAgentHarness as t };
package/dist/harness.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createCopilotAgentHarness } from "./harness-D0K-5kNw.js";
1
+ import { t as createCopilotAgentHarness } from "./harness-EyKssDe5.js";
2
2
  export { createCopilotAgentHarness };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createCopilotAgentHarness } from "./harness-D0K-5kNw.js";
1
+ import { t as createCopilotAgentHarness } from "./harness-EyKssDe5.js";
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
@@ -0,0 +1,207 @@
1
+ import { n as resolveCopilotProvider, o as tokenFingerprint, r as createCopilotByokProxy } from "./harness-EyKssDe5.js";
2
+ import { r as createCopilotIsolatedSessionRestrictions, t as buildCopilotAssistantUsage } from "./usage-bridge-Cpa-ZYwL.js";
3
+ import { resolve } from "node:path";
4
+ //#region extensions/copilot/src/isolated-completion.ts
5
+ function startBestEffortCleanup(cleanup) {
6
+ try {
7
+ cleanup().catch(() => void 0);
8
+ } catch {}
9
+ }
10
+ function resolveReasoningEffort(thinkLevel) {
11
+ return thinkLevel === "low" || thinkLevel === "medium" || thinkLevel === "high" || thinkLevel === "xhigh" ? thinkLevel : void 0;
12
+ }
13
+ function createAbortError(signal) {
14
+ if (signal.reason instanceof Error) return signal.reason;
15
+ const error = new Error("aborted", signal.reason ? { cause: signal.reason } : void 0);
16
+ error.name = "AbortError";
17
+ return error;
18
+ }
19
+ function createTimeoutError(timeoutMs) {
20
+ const error = /* @__PURE__ */ new Error(`[copilot] isolated completion timed out after ${timeoutMs}ms`);
21
+ error.name = "TimeoutError";
22
+ return error;
23
+ }
24
+ async function awaitWithinCompletionBoundary(params) {
25
+ const signal = params.boundary.abortSignal;
26
+ if (signal?.aborted) throw createAbortError(signal);
27
+ const remainingMs = params.boundary.deadlineMs - Date.now();
28
+ if (remainingMs <= 0) throw createTimeoutError(params.boundary.timeoutMs);
29
+ let boundaryWon = false;
30
+ let boundaryError;
31
+ let timer;
32
+ let onAbort;
33
+ const boundary = new Promise((_resolve, reject) => {
34
+ const rejectBoundary = (error) => {
35
+ if (boundaryWon) return;
36
+ boundaryWon = true;
37
+ boundaryError = error;
38
+ params.onBoundary?.();
39
+ reject(error);
40
+ };
41
+ timer = setTimeout(() => rejectBoundary(createTimeoutError(params.boundary.timeoutMs)), remainingMs);
42
+ if (signal) {
43
+ onAbort = () => rejectBoundary(createAbortError(signal));
44
+ signal.addEventListener("abort", onAbort, { once: true });
45
+ if (signal.aborted) onAbort();
46
+ }
47
+ });
48
+ const operation = Promise.resolve().then(() => {
49
+ if (boundaryWon) throw boundaryError ?? createTimeoutError(params.boundary.timeoutMs);
50
+ return params.start(remainingMs);
51
+ }).then(async (value) => {
52
+ if (boundaryWon) await params.cleanupLate?.(value);
53
+ return value;
54
+ });
55
+ try {
56
+ return await Promise.race([operation, boundary]);
57
+ } finally {
58
+ if (timer) clearTimeout(timer);
59
+ if (signal && onAbort) signal.removeEventListener("abort", onAbort);
60
+ }
61
+ }
62
+ async function sendPrompt(params) {
63
+ return await awaitWithinCompletionBoundary({
64
+ boundary: params.boundary,
65
+ start: async (remainingMs) => await params.session.sendAndWait({
66
+ prompt: params.prompt,
67
+ ...params.requestHeaders ? { requestHeaders: params.requestHeaders } : {}
68
+ }, remainingMs),
69
+ onBoundary: () => {
70
+ params.session.abort().catch(() => void 0);
71
+ }
72
+ });
73
+ }
74
+ async function runCopilotIsolatedCompletion(params, getPool) {
75
+ const reasoningEffort = resolveReasoningEffort(params.thinkLevel);
76
+ if (params.thinkLevel !== void 0 && reasoningEffort === void 0) throw new Error(`[copilot] isolated completion does not support thinking level ${params.thinkLevel}`);
77
+ const boundary = {
78
+ abortSignal: params.abortSignal,
79
+ deadlineMs: Date.now() + params.timeoutMs,
80
+ timeoutMs: params.timeoutMs
81
+ };
82
+ if (params.authorization.owner !== "host") throw new Error("[copilot] isolated completion requires host-prepared authorization");
83
+ const authorization = params.authorization;
84
+ const { auth, model } = authorization;
85
+ const apiKey = auth.apiKey?.trim();
86
+ if (!apiKey) throw new Error("[copilot] isolated completion requires the prepared credential");
87
+ const resolvedProvider = resolveCopilotProvider({
88
+ model: {
89
+ api: model.api,
90
+ id: model.id,
91
+ provider: model.provider,
92
+ baseUrl: model.baseUrl,
93
+ headers: model.headers,
94
+ authHeader: model.authHeader,
95
+ contextTokens: model.contextTokens,
96
+ contextWindow: model.contextWindow,
97
+ maxTokens: params.streamParams?.maxTokens ?? model.maxTokens,
98
+ azureApiVersion: typeof model.params?.azureApiVersion === "string" ? model.params.azureApiVersion : void 0
99
+ },
100
+ resolvedApiKey: apiKey,
101
+ authProfileId: auth.profileId
102
+ });
103
+ const pool = await awaitWithinCompletionBoundary({
104
+ boundary,
105
+ start: getPool
106
+ });
107
+ const byokProxy = await awaitWithinCompletionBoundary({
108
+ boundary,
109
+ start: async () => await createCopilotByokProxy(resolvedProvider),
110
+ cleanupLate: async (proxy) => await proxy?.close()
111
+ });
112
+ const sessionProvider = byokProxy?.provider ?? resolvedProvider;
113
+ const githubAuth = sessionProvider.mode === "github-copilot";
114
+ const copilotHome = resolve(params.agentDir, "copilot");
115
+ const authProfileId = auth.profileId?.trim() || "prepared";
116
+ const authProfileVersion = authorization.sourceAuthFingerprint?.trim() || tokenFingerprint(apiKey);
117
+ let handle;
118
+ let session;
119
+ try {
120
+ const acquiredHandle = await awaitWithinCompletionBoundary({
121
+ boundary,
122
+ start: async () => await pool.acquire({
123
+ agentId: params.agentId,
124
+ authMode: githubAuth ? "gitHubToken" : "byok",
125
+ authProfileId,
126
+ authProfileVersion,
127
+ copilotHome,
128
+ clientMode: "empty"
129
+ }, {
130
+ copilotHome,
131
+ mode: "empty",
132
+ useLoggedInUser: false,
133
+ ...githubAuth ? { gitHubToken: apiKey } : {}
134
+ }),
135
+ cleanupLate: async (lateHandle) => await pool.release(lateHandle)
136
+ });
137
+ handle = acquiredHandle;
138
+ const sessionConfig = {
139
+ ...createCopilotIsolatedSessionRestrictions(),
140
+ model: model.id,
141
+ ...githubAuth ? { gitHubToken: apiKey } : {},
142
+ ...sessionProvider.provider ? { provider: sessionProvider.provider } : {},
143
+ ...reasoningEffort ? { reasoningEffort } : {},
144
+ systemMessage: {
145
+ mode: "replace",
146
+ content: params.systemPrompt
147
+ },
148
+ workingDirectory: params.workspaceDir
149
+ };
150
+ const createdSession = await awaitWithinCompletionBoundary({
151
+ boundary,
152
+ start: async () => await acquiredHandle.client.createSession(sessionConfig),
153
+ cleanupLate: async (lateSession) => {
154
+ startBestEffortCleanup(async () => await lateSession.abort());
155
+ startBestEffortCleanup(async () => await lateSession.disconnect());
156
+ }
157
+ });
158
+ session = createdSession;
159
+ const event = await sendPrompt({
160
+ boundary,
161
+ prompt: params.prompt,
162
+ requestHeaders: sessionProvider.provider?.headers,
163
+ session: createdSession
164
+ });
165
+ if (event?.type !== "assistant.message" || event.agentId !== void 0) throw new Error("[copilot] isolated completion did not return a root assistant message");
166
+ const content = [];
167
+ if (event.data.reasoningText) content.push({
168
+ type: "thinking",
169
+ thinking: event.data.reasoningText
170
+ });
171
+ if (event.data.content) content.push({
172
+ type: "text",
173
+ text: event.data.content
174
+ });
175
+ for (const toolRequest of event.data.toolRequests ?? []) {
176
+ const toolArguments = toolRequest.arguments;
177
+ content.push({
178
+ type: "toolCall",
179
+ id: toolRequest.toolCallId,
180
+ name: toolRequest.name,
181
+ arguments: toolArguments && typeof toolArguments === "object" && !Array.isArray(toolArguments) ? { ...toolArguments } : {}
182
+ });
183
+ }
184
+ return { assistant: {
185
+ role: "assistant",
186
+ content,
187
+ api: model.api,
188
+ provider: model.provider,
189
+ model: event.data.model ?? model.id,
190
+ stopReason: event.data.toolRequests?.length ? "toolUse" : "stop",
191
+ timestamp: Date.now(),
192
+ usage: buildCopilotAssistantUsage({ fallbackOutputTokens: event.data.outputTokens })
193
+ } };
194
+ } finally {
195
+ if (session) {
196
+ const sessionToClose = session;
197
+ startBestEffortCleanup(async () => await sessionToClose.disconnect());
198
+ }
199
+ if (byokProxy) startBestEffortCleanup(async () => await byokProxy.close());
200
+ if (handle) {
201
+ const handleToRelease = handle;
202
+ startBestEffortCleanup(async () => await pool.release(handleToRelease));
203
+ }
204
+ }
205
+ }
206
+ //#endregion
207
+ export { runCopilotIsolatedCompletion };
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import path, { normalize, resolve, sep } from "node:path";
3
+ import { toStringifiedError } from "openclaw/plugin-sdk/error-runtime";
3
4
  import { existsSync } from "node:fs";
4
5
  import { pathToFileURL } from "node:url";
5
6
  import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
@@ -106,7 +107,7 @@ function createCopilotClientPool(options = {}) {
106
107
  try {
107
108
  return await client.stop();
108
109
  } catch (error) {
109
- return [toError(error)];
110
+ return [toStringifiedError(error)];
110
111
  } finally {
111
112
  entry.state = { kind: "stopped" };
112
113
  maybeDeleteEntry(entry);
@@ -126,7 +127,7 @@ function createCopilotClientPool(options = {}) {
126
127
  await entry.state.promise;
127
128
  } catch (error) {
128
129
  maybeDeleteEntry(entry);
129
- return [toError(error)];
130
+ return [toStringifiedError(error)];
130
131
  }
131
132
  return stopEntry(entry);
132
133
  case "ready": return stopReadyOrIdleEntry(entry, entry.state.client);
@@ -168,7 +169,7 @@ function createCopilotClientPool(options = {}) {
168
169
  } catch (error) {
169
170
  entry.state = { kind: "stopped" };
170
171
  maybeDeleteEntry(entry);
171
- throw toError(error);
172
+ throw toStringifiedError(error);
172
173
  }
173
174
  })();
174
175
  entry.state = {
@@ -201,7 +202,7 @@ function createCopilotClientPool(options = {}) {
201
202
  client
202
203
  };
203
204
  } catch (error) {
204
- throw toError(error);
205
+ throw toStringifiedError(error);
205
206
  }
206
207
  }
207
208
  switch (existing.state.kind) {
@@ -218,7 +219,7 @@ function createCopilotClientPool(options = {}) {
218
219
  client
219
220
  };
220
221
  } catch (error) {
221
- throw toError(error);
222
+ throw toStringifiedError(error);
222
223
  }
223
224
  case "ready":
224
225
  existing.refCount += 1;
@@ -334,9 +335,5 @@ function normalizeCopilotHome(copilotHome) {
334
335
  if (process.platform === "win32") normalizedHome = normalizedHome.toLowerCase();
335
336
  return normalizedHome;
336
337
  }
337
- function toError(error) {
338
- if (error instanceof Error) return error;
339
- return new Error(String(error));
340
- }
341
338
  //#endregion
342
339
  export { createCopilotClientPool };
@@ -0,0 +1,82 @@
1
+ //#region extensions/copilot/src/session-restrictions.ts
2
+ const COPILOT_ISOLATED_EXCLUDED_TOOLS = [
3
+ "builtin:*",
4
+ "mcp:*",
5
+ "custom:*"
6
+ ];
7
+ /** Disable every ambient SDK capability for a prompt-only or settled final turn. */
8
+ function createCopilotIsolatedSessionRestrictions() {
9
+ return {
10
+ availableTools: [],
11
+ coauthorEnabled: false,
12
+ customAgents: [],
13
+ customAgentsLocalOnly: true,
14
+ embeddingCacheStorage: "in-memory",
15
+ enableConfigDiscovery: false,
16
+ enableFileHooks: false,
17
+ enableHostGitOperations: false,
18
+ enableOnDemandInstructionDiscovery: false,
19
+ enableSessionStore: false,
20
+ enableSkills: false,
21
+ excludedTools: [...COPILOT_ISOLATED_EXCLUDED_TOOLS],
22
+ includeSubAgentStreamingEvents: false,
23
+ infiniteSessions: { enabled: false },
24
+ instructionDirectories: [],
25
+ manageScheduleEnabled: false,
26
+ mcpOAuthTokenStorage: "in-memory",
27
+ mcpServers: {},
28
+ memory: { enabled: false },
29
+ pluginDirectories: [],
30
+ remoteSession: "off",
31
+ requestCanvasRenderer: false,
32
+ requestExtensions: false,
33
+ skillDirectories: [],
34
+ skipCustomInstructions: true,
35
+ skipEmbeddingRetrieval: true,
36
+ tools: []
37
+ };
38
+ }
39
+ //#endregion
40
+ //#region extensions/copilot/src/usage-bridge.ts
41
+ function isCopilotUsageSource(data) {
42
+ return typeof data === "object" && data !== null;
43
+ }
44
+ function buildZeroCost() {
45
+ return {
46
+ cacheRead: 0,
47
+ cacheWrite: 0,
48
+ input: 0,
49
+ output: 0,
50
+ total: 0
51
+ };
52
+ }
53
+ function coerceTokenCount(value) {
54
+ return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.trunc(value)) : void 0;
55
+ }
56
+ function normalizeCopilotUsage(data) {
57
+ if (!isCopilotUsageSource(data)) return;
58
+ const input = coerceTokenCount(data.inputTokens);
59
+ const output = coerceTokenCount(data.outputTokens);
60
+ const cacheRead = coerceTokenCount(data.cacheReadTokens);
61
+ const cacheWrite = coerceTokenCount(data.cacheWriteTokens);
62
+ return {
63
+ cacheRead,
64
+ cacheWrite,
65
+ input,
66
+ output,
67
+ total: (input ?? 0) + (output ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0)
68
+ };
69
+ }
70
+ function buildCopilotAssistantUsage(params) {
71
+ const usage = params.usage ?? normalizeCopilotUsage({ outputTokens: params.fallbackOutputTokens });
72
+ return {
73
+ cacheRead: usage?.cacheRead ?? 0,
74
+ cacheWrite: usage?.cacheWrite ?? 0,
75
+ cost: buildZeroCost(),
76
+ input: usage?.input ?? 0,
77
+ output: usage?.output ?? 0,
78
+ totalTokens: usage?.total ?? 0
79
+ };
80
+ }
81
+ //#endregion
82
+ export { normalizeCopilotUsage as n, createCopilotIsolatedSessionRestrictions as r, buildCopilotAssistantUsage as t };
@@ -1,5 +1,18 @@
1
1
  {
2
2
  "id": "copilot",
3
+ "doctorContract": {
4
+ "configRepair": true
5
+ },
6
+ "sessionRouteStateOwners": [
7
+ {
8
+ "id": "copilot",
9
+ "label": "GitHub Copilot agent runtime",
10
+ "providerIds": ["github-copilot"],
11
+ "runtimeIds": ["copilot"],
12
+ "cliSessionKeys": ["copilot"],
13
+ "authProfilePrefixes": ["github-copilot:"]
14
+ }
15
+ ],
3
16
  "name": "GitHub Copilot agent runtime",
4
17
  "description": "Registers the GitHub Copilot agent runtime.",
5
18
  "icon": "https://cdn.simpleicons.org/githubcopilot",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/copilot",
3
- "version": "2026.7.2-beta.7",
3
+ "version": "2026.8.1-beta.2",
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.7.2-beta.7"
27
+ "pluginApi": ">=2026.8.1-beta.2"
28
28
  },
29
29
  "build": {
30
- "openclawVersion": "2026.7.2-beta.7",
30
+ "openclawVersion": "2026.8.1-beta.2",
31
31
  "bundledDist": false
32
32
  },
33
33
  "release": {
@@ -45,7 +45,7 @@
45
45
  "README.md"
46
46
  ],
47
47
  "peerDependencies": {
48
- "openclaw": ">=2026.7.2-beta.7"
48
+ "openclaw": ">=2026.8.1-beta.2"
49
49
  },
50
50
  "peerDependenciesMeta": {
51
51
  "openclaw": {