dsh-github-copilot 0.4.0-alpha.99 → 0.4.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.
- package/AGENTS.md +104 -16
- package/CHANGELOG.md +223 -0
- package/CONTRIBUTING.md +9 -0
- package/README.md +108 -18
- package/README.zh.md +99 -18
- package/deployment-baseline.json +227 -8
- package/docs/account-management-experience.md +143 -0
- package/docs/auto-high-cost.md +154 -0
- package/docs/auto-iteration-review.json +22 -0
- package/docs/auto-review-sampling.md +60 -0
- package/docs/auto-task-routing.md +8 -6
- package/docs/automatic-model-routing.md +33 -5
- package/docs/copilot-accounts.md +409 -0
- package/docs/copilot-compaction.md +23 -2
- package/docs/copilot-usage.md +24 -4
- package/docs/evidence-driven-iteration.md +86 -0
- package/docs/images/copilot-accounts-credits.png +0 -0
- package/docs/images/copilot-accounts.png +0 -0
- package/docs/images/copilot-current-provenance.json +39 -0
- package/docs/images/copilot-model-preferences.png +0 -0
- package/docs/images/copilot-search-routing.png +0 -0
- package/docs/images/copilot-session-continuation.png +0 -0
- package/docs/manual-compaction-recovery.md +50 -7
- package/docs/mockups/copilot-account-dropdown.html +71 -0
- package/docs/mockups/copilot-account-management.html +393 -0
- package/docs/model-compatibility-acceptance.md +34 -16
- package/docs/npm-distribution.md +9 -1
- package/docs/official-first-020-rc2.md +1 -0
- package/docs/plugin-diagnostics.md +452 -0
- package/docs/session-continuation.md +141 -0
- package/docs/session-search-routing.md +1 -1
- package/docs/single-route-migration.md +5 -4
- package/lib/client.js +4415 -846
- package/lib/client.js.map +1 -1
- package/lib/diagnostics-analysis-io.js +78 -0
- package/lib/diagnostics-analysis.js +425 -0
- package/lib/diagnostics-types-FVf6zjob.js +182 -0
- package/lib/index.js +10455 -6037
- package/lib/manual-compaction-recovery.js +163 -38
- package/lib/remote.js +593 -34
- package/lib/routed-web.js +1 -1
- package/lib/{search-routing-jzNYveyK.js → search-routing-CV2hs8as.js} +139 -139
- package/lib/types/account-dropdown.d.ts +22 -0
- package/lib/types/account-model-auth.d.ts +1 -1
- package/lib/types/authorization-code-clipboard.d.ts +4 -0
- package/lib/types/authorization-controller.d.ts +2 -0
- package/lib/types/auto-allocation-card.d.ts +9 -0
- package/lib/types/auto-allocation-evidence.d.ts +38 -0
- package/lib/types/auto-allocation.d.ts +24 -0
- package/lib/types/auto-model-host.d.ts +2 -0
- package/lib/types/auto-model-routing.d.ts +6 -2
- package/lib/types/auto-review-sampling.d.ts +6 -0
- package/lib/types/auto-task-classifier.d.ts +1 -1
- package/lib/types/background-compaction.d.ts +2 -2
- package/lib/types/client.d.ts +19 -3
- package/lib/types/compaction-continuation-ui.d.ts +29 -0
- package/lib/types/compaction-continuation.d.ts +48 -0
- package/lib/types/compaction-input-estimate.d.ts +24 -0
- package/lib/types/compaction-replay.d.ts +18 -0
- package/lib/types/composer-notice-style.d.ts +7 -0
- package/lib/types/config.d.ts +42 -2
- package/lib/types/context-evidence-ui.d.ts +18 -1
- package/lib/types/context-evidence.d.ts +152 -4
- package/lib/types/copilot-account-presentation.d.ts +7 -0
- package/lib/types/copilot-accounts-card.d.ts +43 -0
- package/lib/types/copilot-accounts-host.d.ts +93 -0
- package/lib/types/copilot-accounts-remote.d.ts +85 -0
- package/lib/types/copilot-accounts-types.d.ts +43 -0
- package/lib/types/copilot-auth.d.ts +9 -2
- package/lib/types/copilot-usage-card.d.ts +23 -0
- package/lib/types/copilot-usage-host.d.ts +9 -1
- package/lib/types/copilot-usage-remote.d.ts +2 -1
- package/lib/types/copilot-usage-types.d.ts +1 -0
- package/lib/types/diagnostics-analysis-io.d.ts +23 -0
- package/lib/types/diagnostics-analysis.d.ts +295 -0
- package/lib/types/diagnostics-card.d.ts +11 -0
- package/lib/types/diagnostics-client.d.ts +13 -0
- package/lib/types/diagnostics-collector.d.ts +36 -0
- package/lib/types/diagnostics-host.d.ts +72 -0
- package/lib/types/diagnostics-remote.d.ts +109 -0
- package/lib/types/diagnostics-types.d.ts +431 -0
- package/lib/types/manual-compaction-recovery.d.ts +18 -3
- package/lib/types/model-preferences-card.d.ts +1 -1
- package/lib/types/native-settings-style.d.ts +10 -0
- package/lib/types/parent-model-follow-card.d.ts +2 -11
- package/lib/types/preview-provider.d.ts +5 -0
- package/lib/types/preview-route.d.ts +7 -5
- package/lib/types/remote.d.ts +9 -6
- package/lib/types/replay-recovery-host.d.ts +2 -2
- package/lib/types/replay-recovery-ui.d.ts +3 -1
- package/lib/types/request-body-evidence.d.ts +3 -1
- package/lib/types/responses-replay-compat.d.ts +2 -1
- package/lib/types/responses-request-compression.d.ts +33 -0
- package/lib/types/session-accounts-controller.d.ts +20 -0
- package/lib/types/session-accounts-host.d.ts +33 -0
- package/lib/types/session-accounts-remote.d.ts +114 -0
- package/lib/types/session-accounts.d.ts +38 -0
- package/lib/types/session-continuation-host.d.ts +45 -0
- package/lib/types/session-continuation-remote.d.ts +22 -0
- package/lib/types/session-continuation-types.d.ts +62 -0
- package/lib/types/session-continuation-ui.d.ts +49 -0
- package/lib/types/session-continuation.d.ts +14 -0
- package/lib/types/turn-request-models.d.ts +55 -0
- package/lib/types/turn-selection-card.d.ts +15 -1
- package/lib/types/turn-selection-host.d.ts +23 -0
- package/lib/types/turn-selection-remote.d.ts +4 -0
- package/lib/types/turn-selection.d.ts +19 -4
- package/package.json +29 -12
- package/scripts/analyze-diagnostics.mjs +91 -0
- package/scripts/iteration-review.mjs +53 -0
|
@@ -1,12 +1,38 @@
|
|
|
1
|
+
import { d as diagnosticsReason, u as diagnosticsOutcome } from "./diagnostics-types-FVf6zjob.js";
|
|
1
2
|
import "./copilot-identity-DRZY_d2X.js";
|
|
2
3
|
import { i as resolveRequestBudgetPolicy, r as calculateRequestBudget } from "./request-budget-DLY_aRq0.js";
|
|
3
|
-
import
|
|
4
|
+
import z from "@deepseek-ai/schemastery";
|
|
5
|
+
import { LlmError, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
4
6
|
import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
|
|
5
7
|
import { CommandDefinitionId } from "@deepseek-ai/dsh-commands/brand";
|
|
6
8
|
//#region lib/types/background-compaction.js
|
|
7
9
|
const WAIT_MS = 2147483647;
|
|
8
|
-
const USAGE = "Usage: /copilot-compact [status|cancel]";
|
|
10
|
+
const USAGE = "Usage: /copilot-compact [status|cancel|visible-history]. visible-history authorizes one lossy summary without old encrypted reasoning or its embedded summaries; stored source history is unchanged.";
|
|
9
11
|
const FAILED = "COPILOT_BACKGROUND_COMPACTION_FAILED: inspect the native compaction/end record; no success is implied.";
|
|
12
|
+
function failureDetail(cause) {
|
|
13
|
+
const allowed = /* @__PURE__ */ new Set([
|
|
14
|
+
"COPILOT_RESPONSES_REPLAY_SCOPE_MISMATCH",
|
|
15
|
+
"COPILOT_RESPONSES_REPLAY_UNSUPPORTED",
|
|
16
|
+
"COPILOT_RESPONSES_REPLAY_INVALID_PAYLOAD",
|
|
17
|
+
"CONTEXT_WINDOW_EXCEEDED",
|
|
18
|
+
"COPILOT_MANUAL_RECOVERY_ACCOUNT_PROOF_UNAVAILABLE",
|
|
19
|
+
"COPILOT_MANUAL_RECOVERY_FIXED_PREFIX",
|
|
20
|
+
"COPILOT_MANUAL_RECOVERY_INDIVISIBLE",
|
|
21
|
+
"COPILOT_MANUAL_RECOVERY_CALL_LIMIT",
|
|
22
|
+
"COPILOT_MANUAL_RECOVERY_EMPTY_SUMMARY",
|
|
23
|
+
"COPILOT_MANUAL_RECOVERY_UNBALANCED",
|
|
24
|
+
"COPILOT_COMPACTION_REPLAY_UNAVAILABLE",
|
|
25
|
+
"COPILOT_COMPACTION_REPLAY_REVOKED"
|
|
26
|
+
]);
|
|
27
|
+
const visited = /* @__PURE__ */ new Set();
|
|
28
|
+
for (let depth = 0; depth < 8 && cause instanceof Error && !visited.has(cause); depth++) {
|
|
29
|
+
visited.add(cause);
|
|
30
|
+
const code = /^[A-Z][A-Z_]+(?=:|$)/.exec(cause.message)?.[0];
|
|
31
|
+
if (code && allowed.has(code)) return `${code}: compaction failed; stored source history is unchanged.${code === "COPILOT_RESPONSES_REPLAY_SCOPE_MISMATCH" ? " Review loss of hidden context before explicitly using /copilot-compact visible-history. No automatic retry." : ""} Inspect the native compaction/end record.`;
|
|
32
|
+
cause = cause.cause;
|
|
33
|
+
}
|
|
34
|
+
return FAILED;
|
|
35
|
+
}
|
|
10
36
|
/** Own only admission and job lifetime; the selected engine owns all history transactions. */
|
|
11
37
|
var BackgroundCompaction = class {
|
|
12
38
|
jobs;
|
|
@@ -30,12 +56,12 @@ var BackgroundCompaction = class {
|
|
|
30
56
|
text: "Compaction admission cancelled."
|
|
31
57
|
};
|
|
32
58
|
const action = rawInput.trim();
|
|
33
|
-
if (action !== "" && action !== "status" && action !== "cancel") return {
|
|
59
|
+
if (action !== "" && action !== "status" && action !== "cancel" && action !== "visible-history") return {
|
|
34
60
|
kind: "error",
|
|
35
61
|
text: USAGE
|
|
36
62
|
};
|
|
37
63
|
const id = this.latest.get(agent);
|
|
38
|
-
if (action
|
|
64
|
+
if (action === "status" || action === "cancel") {
|
|
39
65
|
if (id === void 0) return {
|
|
40
66
|
kind: "error",
|
|
41
67
|
text: "No background compaction job for this Session."
|
|
@@ -74,20 +100,21 @@ var BackgroundCompaction = class {
|
|
|
74
100
|
done = Promise.resolve().then(async () => {
|
|
75
101
|
try {
|
|
76
102
|
cancel.signal.throwIfAborted();
|
|
77
|
-
const result = await this.compact(agent, cancel.signal);
|
|
103
|
+
const result = await this.compact(agent, cancel.signal, action === "visible-history");
|
|
78
104
|
return {
|
|
79
105
|
status: "completed",
|
|
80
106
|
detail: result === null ? "No compactable history." : `Compacted ${result.shadowedSeqs.length} history items (~${result.shadowedTokenCount} tokens).`
|
|
81
107
|
};
|
|
82
|
-
} catch {
|
|
108
|
+
} catch (cause) {
|
|
83
109
|
if (cancel.signal.aborted) return {
|
|
84
110
|
status: "killed",
|
|
85
111
|
detail: "Compaction cancelled; inspect native history for its transaction outcome."
|
|
86
112
|
};
|
|
87
|
-
|
|
113
|
+
const detail = failureDetail(cause);
|
|
114
|
+
this.warn(detail);
|
|
88
115
|
return {
|
|
89
116
|
status: "failed",
|
|
90
|
-
detail
|
|
117
|
+
detail
|
|
91
118
|
};
|
|
92
119
|
} finally {
|
|
93
120
|
this.active.delete(agent);
|
|
@@ -146,12 +173,67 @@ function installBackgroundCompaction(ctx, compact) {
|
|
|
146
173
|
definitionId: CommandDefinitionId("dsh-github-copilot/background-compaction"),
|
|
147
174
|
name: "copilot-compact",
|
|
148
175
|
description: "Start background manual compaction, inspect status, or cancel",
|
|
149
|
-
input: { hint: "status | cancel (omit
|
|
176
|
+
input: { hint: "status | cancel | visible-history (explicit lossy recovery; omit for normal compaction)" },
|
|
150
177
|
handler: (invocation) => controller.execute(invocation.agent, invocation.rawInput, invocation.signal)
|
|
151
178
|
});
|
|
152
179
|
}, "Copilot background compaction");
|
|
153
180
|
}
|
|
154
181
|
//#endregion
|
|
182
|
+
//#region lib/types/compaction-input-estimate.js
|
|
183
|
+
function compactionSafeBoundaries(messages) {
|
|
184
|
+
const pending = /* @__PURE__ */ new Set();
|
|
185
|
+
const boundaries = [0];
|
|
186
|
+
for (let index = 0; index < messages.length; index++) {
|
|
187
|
+
const message = messages[index];
|
|
188
|
+
if (message.role === "assistant") for (const block of message.content) {
|
|
189
|
+
if (block.type !== "tool-call") continue;
|
|
190
|
+
if (!block.id || pending.has(block.id)) throw new Error("COPILOT_MANUAL_RECOVERY_UNBALANCED");
|
|
191
|
+
pending.add(block.id);
|
|
192
|
+
}
|
|
193
|
+
if (message.role === "tool" && (!message.toolCallId || !pending.delete(message.toolCallId))) throw new Error("COPILOT_MANUAL_RECOVERY_UNBALANCED");
|
|
194
|
+
if (pending.size === 0) boundaries.push(index + 1);
|
|
195
|
+
}
|
|
196
|
+
if (pending.size !== 0) throw new Error("COPILOT_MANUAL_RECOVERY_UNBALANCED");
|
|
197
|
+
return boundaries;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Conservative content-byte planning, not provider-exact token accounting.
|
|
201
|
+
* Native admission still checks converted replay, images and the full request.
|
|
202
|
+
*/
|
|
203
|
+
function estimateCompactionInputBytes(input) {
|
|
204
|
+
return Buffer.byteLength(JSON.stringify({
|
|
205
|
+
tools: input.tools,
|
|
206
|
+
messages: input.messages.map((message) => ({
|
|
207
|
+
role: message.role,
|
|
208
|
+
content: message.content,
|
|
209
|
+
...message.role === "tool" ? {
|
|
210
|
+
toolCallId: message.toolCallId,
|
|
211
|
+
isError: message.isError
|
|
212
|
+
} : {}
|
|
213
|
+
}))
|
|
214
|
+
}), "utf8");
|
|
215
|
+
}
|
|
216
|
+
function reduceCompactionInputLimit(input, inputLimit) {
|
|
217
|
+
const originalSize = estimateCompactionInputBytes(input);
|
|
218
|
+
const fixedSize = estimateCompactionInputBytes({
|
|
219
|
+
tools: input.tools,
|
|
220
|
+
messages: input.messages[0]?.role === "system" ? input.messages.slice(0, 1) : []
|
|
221
|
+
});
|
|
222
|
+
const prefix = input.messages[0]?.role === "system" ? input.messages.slice(0, 1) : [];
|
|
223
|
+
const messages = input.messages.slice(prefix.length);
|
|
224
|
+
let start = 0;
|
|
225
|
+
let minimum = fixedSize;
|
|
226
|
+
for (const end of compactionSafeBoundaries(messages).slice(1)) {
|
|
227
|
+
minimum = Math.max(minimum, estimateCompactionInputBytes({
|
|
228
|
+
tools: input.tools,
|
|
229
|
+
messages: [...prefix, ...messages.slice(start, end)]
|
|
230
|
+
}));
|
|
231
|
+
start = end;
|
|
232
|
+
}
|
|
233
|
+
if (minimum >= originalSize) throw new Error("COPILOT_MANUAL_RECOVERY_INDIVISIBLE");
|
|
234
|
+
return Math.min(inputLimit, Math.max(minimum, fixedSize + Math.floor((originalSize - fixedSize) / 2)));
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
155
237
|
//#region lib/types/manual-compaction-recovery.js
|
|
156
238
|
function recoverError(code) {
|
|
157
239
|
return /* @__PURE__ */ new Error(`COPILOT_MANUAL_RECOVERY_${code}`);
|
|
@@ -169,7 +251,7 @@ function sumUsage(usages) {
|
|
|
169
251
|
};
|
|
170
252
|
}
|
|
171
253
|
/**
|
|
172
|
-
* Bounded
|
|
254
|
+
* Bounded map/fold. The native engine still owns the only
|
|
173
255
|
* durable transaction, source-stability check, shrink check and cancellation.
|
|
174
256
|
*/
|
|
175
257
|
async function summarizeOversizedManualInput(options) {
|
|
@@ -179,22 +261,7 @@ async function summarizeOversizedManualInput(options) {
|
|
|
179
261
|
const prefix = input.messages[0]?.role === "system" ? input.messages.slice(0, 1) : [];
|
|
180
262
|
const messages = input.messages.slice(prefix.length);
|
|
181
263
|
if (messages.length === 0) throw recoverError("NO_HISTORY");
|
|
182
|
-
const
|
|
183
|
-
const safeBoundaries = /* @__PURE__ */ new Set([0]);
|
|
184
|
-
for (let index = 0; index < messages.length; index++) {
|
|
185
|
-
const message = messages[index];
|
|
186
|
-
if (message.role === "assistant") {
|
|
187
|
-
for (const block of message.content) if (block.type === "tool-call") {
|
|
188
|
-
if (!block.id || pending.has(block.id)) throw recoverError("UNBALANCED");
|
|
189
|
-
pending.add(block.id);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (message.role === "tool") {
|
|
193
|
-
if (!message.toolCallId || !pending.delete(message.toolCallId)) throw recoverError("UNBALANCED");
|
|
194
|
-
}
|
|
195
|
-
if (pending.size === 0) safeBoundaries.add(index + 1);
|
|
196
|
-
}
|
|
197
|
-
if (pending.size !== 0) throw recoverError("UNBALANCED");
|
|
264
|
+
const safeBoundaries = new Set(compactionSafeBoundaries(messages));
|
|
198
265
|
let previous;
|
|
199
266
|
let offset = 0;
|
|
200
267
|
let calls = 0;
|
|
@@ -244,11 +311,22 @@ async function summarizeOversizedManualInput(options) {
|
|
|
244
311
|
* mount both: Cordis compaction is a singleton, not an overridable service.
|
|
245
312
|
*/
|
|
246
313
|
var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine {
|
|
314
|
+
static Config = z.intersect([BasicCompactionEngine.Config, z.object({ automaticRecovery: z.boolean().default(true) })]);
|
|
247
315
|
manual = /* @__PURE__ */ new WeakMap();
|
|
316
|
+
visibleHistory = /* @__PURE__ */ new WeakSet();
|
|
317
|
+
automaticRecovery;
|
|
248
318
|
constructor(ctx, config = {}) {
|
|
249
|
-
|
|
319
|
+
const { automaticRecovery = true, ...nativeConfig } = config;
|
|
320
|
+
if (typeof automaticRecovery !== "boolean") throw recoverError("INVALID_POLICY");
|
|
321
|
+
super(ctx, nativeConfig);
|
|
322
|
+
this.automaticRecovery = automaticRecovery;
|
|
250
323
|
ctx.inject(["commands", "jobs"], (scope) => {
|
|
251
|
-
installBackgroundCompaction(scope, (agent, signal) =>
|
|
324
|
+
installBackgroundCompaction(scope, (agent, signal, visibleHistory) => {
|
|
325
|
+
if (!visibleHistory) return this.compactNow(agent, signal);
|
|
326
|
+
if (this.manual.has(agent)) throw recoverError("BUSY");
|
|
327
|
+
this.visibleHistory.add(agent);
|
|
328
|
+
return this.compactNow(agent, signal).finally(() => this.visibleHistory.delete(agent));
|
|
329
|
+
});
|
|
252
330
|
});
|
|
253
331
|
}
|
|
254
332
|
async compactNow(agent, signal, sourceCommandId) {
|
|
@@ -263,7 +341,8 @@ var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine
|
|
|
263
341
|
}
|
|
264
342
|
async summarize(input, agent, signal) {
|
|
265
343
|
const routed = agent.session.requestHeader()?.config;
|
|
266
|
-
const
|
|
344
|
+
const target = routed?.provider && routed.model ? routed : agent.options;
|
|
345
|
+
const policy = this.config.modelPolicies.find((item) => item.provider === target.provider && item.model === target.model);
|
|
267
346
|
const configuredProvider = policy?.summarizationProvider ?? this.config.summarizationProvider;
|
|
268
347
|
const configuredModel = policy?.summarizationModel ?? this.config.summarizationModel;
|
|
269
348
|
const selected = configuredProvider.length > 0 ? {
|
|
@@ -275,23 +354,64 @@ var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine
|
|
|
275
354
|
};
|
|
276
355
|
const summaryProvider = selected.provider;
|
|
277
356
|
const summaryModel = selected.model;
|
|
278
|
-
if (!this.manual.has(agent) || summaryProvider !== "github-copilot-preview" || !summaryModel)
|
|
279
|
-
|
|
280
|
-
|
|
357
|
+
if (!this.manual.has(agent) && !this.automaticRecovery || summaryProvider !== "github-copilot-preview" || !summaryModel) {
|
|
358
|
+
if (this.visibleHistory.has(agent)) throw new Error("COPILOT_COMPACTION_REPLAY_UNAVAILABLE");
|
|
359
|
+
return super.summarize(input, agent, signal);
|
|
360
|
+
}
|
|
281
361
|
const maxTokens = policy?.maxTokens ?? this.config.maxTokens;
|
|
362
|
+
const operationSignal = signal ?? new AbortController().signal;
|
|
363
|
+
const summarize = () => this.summarizeManaged(input, agent, summaryModel, maxTokens, operationSignal);
|
|
364
|
+
if (!this.visibleHistory.has(agent)) return summarize();
|
|
365
|
+
const recovery = this.ctx.get("githubCopilotCompactionReplay");
|
|
366
|
+
if (!recovery) throw new Error("COPILOT_COMPACTION_REPLAY_UNAVAILABLE");
|
|
367
|
+
return recovery.run(agent.session.id, summaryModel, operationSignal, summarize);
|
|
368
|
+
}
|
|
369
|
+
async summarizeManaged(input, agent, summaryModel, maxTokens, operationSignal) {
|
|
370
|
+
const lease = this.ctx.get("githubCopilotPreview")?.recoveryLimits(summaryModel, agent);
|
|
371
|
+
if (lease === void 0) throw recoverError("ACCOUNT_PROOF_UNAVAILABLE");
|
|
372
|
+
if (this.visibleHistory.has(agent) && lease.api !== "openai-responses") throw new Error("COPILOT_COMPACTION_REPLAY_UNAVAILABLE");
|
|
373
|
+
const agents = this.ctx.get("agents");
|
|
374
|
+
if (this.ctx.get("githubCopilotSessionAccounts") !== void 0 && agents === void 0) throw recoverError("INITIATOR_UNAVAILABLE");
|
|
375
|
+
const summarize = async (candidate) => {
|
|
376
|
+
const observed = this.ctx.get("githubCopilotDiagnostics")?.collector.begin("compaction-summary");
|
|
377
|
+
observed?.stage("summary-attempt");
|
|
378
|
+
try {
|
|
379
|
+
const result = await (agents === void 0 ? super.summarize(candidate, agent, operationSignal) : agents.withInitiator(agent, () => super.summarize(candidate, agent, operationSignal)));
|
|
380
|
+
observed?.finish("success");
|
|
381
|
+
return result;
|
|
382
|
+
} catch (error) {
|
|
383
|
+
const reason = diagnosticsReason(error);
|
|
384
|
+
if (operationSignal.aborted) this.ctx.get("githubCopilotDiagnostics")?.markCompactionCancelled(agent.session);
|
|
385
|
+
observed?.finish(operationSignal.aborted ? "cancelled" : diagnosticsOutcome(reason), reason);
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
282
389
|
const budget = calculateRequestBudget(lease.limits, maxTokens, resolveRequestBudgetPolicy(lease.policy));
|
|
283
390
|
if (!budget.ok) throw recoverError(budget.code);
|
|
284
391
|
const toolHistoryBytes = Buffer.byteLength(JSON.stringify(agent.session.toolHistory()), "utf8");
|
|
285
|
-
|
|
392
|
+
let inputLimit = budget.budget.hardInputLimit - 4096 - toolHistoryBytes;
|
|
286
393
|
if (inputLimit <= 0) throw recoverError("FIXED_PREFIX");
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
394
|
+
const estimate = estimateCompactionInputBytes;
|
|
395
|
+
operationSignal.throwIfAborted();
|
|
396
|
+
lease.assertCurrent();
|
|
397
|
+
const originalSize = estimate(input);
|
|
398
|
+
let failedAttempt = false;
|
|
399
|
+
if (originalSize <= inputLimit) try {
|
|
400
|
+
return await summarize(input);
|
|
401
|
+
} catch (error) {
|
|
402
|
+
operationSignal.throwIfAborted();
|
|
403
|
+
if (!(error instanceof LlmError) || error.code !== "CONTEXT_WINDOW_EXCEEDED") throw error;
|
|
404
|
+
lease.assertCurrent();
|
|
405
|
+
inputLimit = reduceCompactionInputLimit(input, inputLimit);
|
|
406
|
+
failedAttempt = true;
|
|
407
|
+
}
|
|
408
|
+
this.ctx.logger.info("[github-copilot] Segmented compaction recovery started; up to %d additional model calls.", failedAttempt ? 15 : 16);
|
|
409
|
+
const result = await summarizeOversizedManualInput({
|
|
291
410
|
input,
|
|
292
411
|
inputLimit,
|
|
293
412
|
signal: operationSignal,
|
|
294
413
|
estimate,
|
|
414
|
+
maxCalls: failedAttempt ? 15 : 16,
|
|
295
415
|
assertCurrent: lease.assertCurrent,
|
|
296
416
|
makeCheckpoint: (summary) => createUserMessage({
|
|
297
417
|
source: { kind: "user" },
|
|
@@ -307,8 +427,13 @@ var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine
|
|
|
307
427
|
}
|
|
308
428
|
]
|
|
309
429
|
}),
|
|
310
|
-
summarize
|
|
430
|
+
summarize
|
|
311
431
|
});
|
|
432
|
+
if (failedAttempt) {
|
|
433
|
+
const { usage: _usage, ...unaccounted } = result;
|
|
434
|
+
return unaccounted;
|
|
435
|
+
}
|
|
436
|
+
return result;
|
|
312
437
|
}
|
|
313
438
|
};
|
|
314
439
|
//#endregion
|