pi-antigravity-bridge 0.1.10 → 0.1.11
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/CHANGELOG.md +15 -0
- package/package.json +1 -1
- package/src/acp/binary-resolver.ts +3 -1
- package/src/acp/process-manager.ts +45 -13
- package/src/index.ts +15 -3
- package/src/session/checkpoint-sync.ts +4 -2
- package/src/session/reconcile.ts +63 -9
- package/src/session/turn-coordinator.ts +393 -303
- package/src/tools/agy-mirror-tools.ts +63 -5
- package/src/tools/agy-renderers.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.11] - 2026-11-22
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- 完善与 `pi-traffic-optimization` 等观测扩展的协同:上报宿主 MCP 工具结果回传、投影同步状态、多步预注入历史负载与辅助请求状态。
|
|
8
|
+
- 延长模板会话库落盘等待窗口,并统一解析 `agy_read` 等镜像工具中的 `file://` 路径与行范围参数。
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- 修复单图归档工具结果在超长重放截断时可能丢失 `ctx://image/` 句柄,以及多步预注入保留的历史图片缺少来源标签的问题。
|
|
13
|
+
- 修复大量图片搭配短文本触发单步上限时无故裁切短文本的问题。
|
|
14
|
+
- 修复会话恢复阶段用户中断后继续执行后续恢复步骤,以及初始化中途失败残留本地 MCP 会话绑定的问题。
|
|
15
|
+
- 修复前序请求超时未收敛时重叠发送请求、辅助请求未将模型拒绝或取消判为错误或中止,以及切换模型后迟到用量通知改写新模型上下文窗口的问题。
|
|
16
|
+
- 修复 `agy-tools` 与 `hybrid` 模式跳过受损历史库自愈校验、POSIX 退出清理可能跳过强杀信号、后台模型刷新未随会话关闭取消,以及 Windows 命令行参数尾部反斜杠转义错误的问题。
|
|
17
|
+
|
|
3
18
|
## [0.1.10] - 2026-11-22
|
|
4
19
|
|
|
5
20
|
### Fixed
|
package/package.json
CHANGED
|
@@ -155,7 +155,9 @@ export function quoteWindowsCmdArg(arg: string): string {
|
|
|
155
155
|
if (arg.length === 0) return '""';
|
|
156
156
|
const escapedPercents = arg.replace(/%/g, "%%");
|
|
157
157
|
if (!/[\s"&|<>^()!;,=%]/.test(escapedPercents)) return escapedPercents;
|
|
158
|
-
|
|
158
|
+
const escapedQuotes = escapedPercents.replace(/(\\*)"/g, '$1$1""');
|
|
159
|
+
const escapedTrailingBackslashes = escapedQuotes.replace(/(\\+)$/, "$1$1");
|
|
160
|
+
return `"${escapedTrailingBackslashes}"`;
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
/**
|
|
@@ -21,9 +21,22 @@ import {
|
|
|
21
21
|
NdjsonLineParser,
|
|
22
22
|
} from "./protocol.ts";
|
|
23
23
|
|
|
24
|
+
function readPackageVersion(): string {
|
|
25
|
+
try {
|
|
26
|
+
const raw = fs.readFileSync(new URL("../../package.json", import.meta.url), "utf8");
|
|
27
|
+
const parsed = JSON.parse(raw) as { version?: unknown };
|
|
28
|
+
if (typeof parsed.version === "string" && parsed.version.trim().length > 0) {
|
|
29
|
+
return parsed.version.trim();
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
// 忽略读取异常,回退默认版本号
|
|
33
|
+
}
|
|
34
|
+
return "0.1.10";
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
export const BRIDGE_AGENT_NAME = "pi-bridge";
|
|
25
38
|
export const CLIENT_INFO_NAME = "pi-antigravity-bridge";
|
|
26
|
-
export const CLIENT_INFO_VERSION =
|
|
39
|
+
export const CLIENT_INFO_VERSION = readPackageVersion();
|
|
27
40
|
|
|
28
41
|
export class AcpRpcError extends Error {
|
|
29
42
|
readonly code: number;
|
|
@@ -640,20 +653,20 @@ export class AcpClientConnection {
|
|
|
640
653
|
}
|
|
641
654
|
|
|
642
655
|
if (this.isAlive) {
|
|
643
|
-
await new Promise<
|
|
656
|
+
const exitedGracefully = await new Promise<boolean>((resolve) => {
|
|
644
657
|
let settled = false;
|
|
645
658
|
let killTimer: ReturnType<typeof setTimeout> | undefined;
|
|
646
|
-
const finish = () => {
|
|
659
|
+
const finish = (graceful: boolean) => {
|
|
647
660
|
if (settled) return;
|
|
648
661
|
settled = true;
|
|
649
662
|
if (killTimer) {
|
|
650
663
|
clearTimeout(killTimer);
|
|
651
664
|
killTimer = undefined;
|
|
652
665
|
}
|
|
653
|
-
resolve();
|
|
666
|
+
resolve(graceful);
|
|
654
667
|
};
|
|
655
668
|
|
|
656
|
-
this.proc.once("close", finish);
|
|
669
|
+
this.proc.once("close", () => finish(true));
|
|
657
670
|
try {
|
|
658
671
|
this.proc.stdin.end();
|
|
659
672
|
} catch {
|
|
@@ -662,12 +675,15 @@ export class AcpClientConnection {
|
|
|
662
675
|
|
|
663
676
|
killTimer = setTimeout(() => {
|
|
664
677
|
if (!settled) {
|
|
665
|
-
|
|
666
|
-
finish();
|
|
678
|
+
finish(false);
|
|
667
679
|
}
|
|
668
680
|
}, 1_500);
|
|
669
681
|
killTimer.unref();
|
|
670
682
|
});
|
|
683
|
+
|
|
684
|
+
if (!exitedGracefully && this.proc.exitCode === null) {
|
|
685
|
+
await this.forceKillProcessTree();
|
|
686
|
+
}
|
|
671
687
|
}
|
|
672
688
|
|
|
673
689
|
this.closed = true;
|
|
@@ -683,7 +699,7 @@ export class AcpClientConnection {
|
|
|
683
699
|
void this.managedAgentDir;
|
|
684
700
|
}
|
|
685
701
|
|
|
686
|
-
private forceKillProcessTree(): void {
|
|
702
|
+
private async forceKillProcessTree(): Promise<void> {
|
|
687
703
|
const pid = this.proc.pid;
|
|
688
704
|
if (!pid) return;
|
|
689
705
|
|
|
@@ -717,11 +733,27 @@ export class AcpClientConnection {
|
|
|
717
733
|
};
|
|
718
734
|
|
|
719
735
|
sendPosixGroupOrPid("SIGTERM");
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
736
|
+
if (this.proc.exitCode !== null) {
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
await new Promise<void>((resolve) => {
|
|
741
|
+
let done = false;
|
|
742
|
+
const finish = () => {
|
|
743
|
+
if (done) return;
|
|
744
|
+
done = true;
|
|
745
|
+
clearTimeout(timer);
|
|
746
|
+
this.proc.off("close", finish);
|
|
747
|
+
resolve();
|
|
748
|
+
};
|
|
749
|
+
const timer = setTimeout(() => {
|
|
750
|
+
if (this.proc.exitCode === null) {
|
|
751
|
+
sendPosixGroupOrPid("SIGKILL");
|
|
752
|
+
}
|
|
753
|
+
finish();
|
|
754
|
+
}, 500);
|
|
755
|
+
this.proc.once("close", finish);
|
|
756
|
+
});
|
|
725
757
|
}
|
|
726
758
|
|
|
727
759
|
private writeJson(payload: unknown): void {
|
package/src/index.ts
CHANGED
|
@@ -219,13 +219,21 @@ export default function antigravityBridgeExtension(pi: ExtensionAPI): void {
|
|
|
219
219
|
pi.registerToolRenderer(createAgyToolRendererResolver());
|
|
220
220
|
|
|
221
221
|
// 3. 注册 `/agy` 命令族
|
|
222
|
-
|
|
222
|
+
let backgroundRefreshController: AbortController | undefined;
|
|
223
|
+
const refreshAndReRegisterModels = async (
|
|
224
|
+
ctx: ExtensionContext,
|
|
225
|
+
overrideSignal?: AbortSignal,
|
|
226
|
+
): Promise<number> => {
|
|
227
|
+
const signal = overrideSignal ?? ctx.signal;
|
|
223
228
|
const snapshot = await probeLiveAntigravityCatalog(
|
|
224
229
|
processManager,
|
|
225
230
|
coordinator.config,
|
|
226
231
|
ctx.cwd,
|
|
227
|
-
{ signal
|
|
232
|
+
{ signal, force: true },
|
|
228
233
|
);
|
|
234
|
+
if (signal?.aborted) {
|
|
235
|
+
return currentModels.length;
|
|
236
|
+
}
|
|
229
237
|
if (snapshot.tier) {
|
|
230
238
|
coordinator.setLatestTier(snapshot.tier);
|
|
231
239
|
}
|
|
@@ -274,7 +282,9 @@ export default function antigravityBridgeExtension(pi: ExtensionAPI): void {
|
|
|
274
282
|
typeof diskCache.updatedAt !== "number" ||
|
|
275
283
|
Date.now() - diskCache.updatedAt > MODEL_CACHE_STALE_MS;
|
|
276
284
|
if (isCacheStale) {
|
|
277
|
-
|
|
285
|
+
backgroundRefreshController?.abort();
|
|
286
|
+
backgroundRefreshController = new AbortController();
|
|
287
|
+
void refreshAndReRegisterModels(ctx, backgroundRefreshController.signal).catch(() => {});
|
|
278
288
|
}
|
|
279
289
|
});
|
|
280
290
|
|
|
@@ -330,6 +340,8 @@ export default function antigravityBridgeExtension(pi: ExtensionAPI): void {
|
|
|
330
340
|
});
|
|
331
341
|
|
|
332
342
|
pi.on("session_shutdown", async () => {
|
|
343
|
+
backgroundRefreshController?.abort();
|
|
344
|
+
backgroundRefreshController = undefined;
|
|
333
345
|
await coordinator.dispose();
|
|
334
346
|
});
|
|
335
347
|
}
|
|
@@ -39,6 +39,8 @@ export interface AgySessionAnchor {
|
|
|
39
39
|
projectionDigest?: string;
|
|
40
40
|
/** 可选:该 AGY 会话实际承载的 `pi-traffic-optimization` 归档占位符总数 */
|
|
41
41
|
projectedCount?: number;
|
|
42
|
+
/** 可选:该锚点落盘时后端已使用的上下文 token 水位(供恢复时评估是否因归档投影重建) */
|
|
43
|
+
usedTokens?: number;
|
|
42
44
|
/** 可选的本地 SQLite 会话数据库检查点水位 */
|
|
43
45
|
dbCheckpoint?: SqliteDbCheckpoint;
|
|
44
46
|
}
|
|
@@ -891,8 +893,8 @@ export async function cloneTemplateSqliteConversationWithPreload(
|
|
|
891
893
|
const convDir = resolveAgyConversationsDir(config);
|
|
892
894
|
const templateDbPath = path.join(convDir, `${templateSessionId}.db`);
|
|
893
895
|
|
|
894
|
-
// 等待刚刚关闭的模板会话完成 SQLite/WAL 落盘(最长
|
|
895
|
-
const deadline = Date.now() +
|
|
896
|
+
// 等待刚刚关闭的模板会话完成 SQLite/WAL 落盘(最长 1200ms,快速轮询并响应取消信号)
|
|
897
|
+
const deadline = Date.now() + 1_200;
|
|
896
898
|
let templateReady = false;
|
|
897
899
|
while (!options?.signal?.aborted) {
|
|
898
900
|
if (fs.existsSync(templateDbPath)) {
|
package/src/session/reconcile.ts
CHANGED
|
@@ -624,13 +624,22 @@ function serializeReplayHistoryEntry(
|
|
|
624
624
|
.map((c) => c.text)
|
|
625
625
|
.join("\n");
|
|
626
626
|
// 对 pi-traffic-optimization 已生成的紧凑 ctx:// 归档占位符保留原文不裁切,确保 handle 与 context_recall 指引完整
|
|
627
|
-
|
|
627
|
+
let cappedTexts = isTrafficOptToolPlaceholder(rawTexts)
|
|
628
628
|
? rawTexts
|
|
629
629
|
: truncateUtf8Middle(
|
|
630
630
|
rawTexts,
|
|
631
631
|
limits.maxToolBytes,
|
|
632
632
|
"\n...[tool output truncated in replay]...\n",
|
|
633
633
|
);
|
|
634
|
+
// 若仅单图归档的工具结果因正文过长被截断,补回被裁掉的 ctx://image/ 归档句柄行,避免模型丢失图片引用
|
|
635
|
+
if (cappedTexts !== rawTexts) {
|
|
636
|
+
const missingImagePlaceholders = rawTexts
|
|
637
|
+
.split("\n")
|
|
638
|
+
.filter((line) => isTrafficOptImagePlaceholder(line) && !cappedTexts.includes(line));
|
|
639
|
+
if (missingImagePlaceholders.length > 0) {
|
|
640
|
+
cappedTexts = `${cappedTexts}\n${missingImagePlaceholders.join("\n")}`;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
634
643
|
entryBlocks.push({
|
|
635
644
|
type: "text",
|
|
636
645
|
text: `<tool_result id="${msg.toolCallId}" tool="${msg.toolName}" status="${status}">\n${cappedTexts}\n</tool_result>`,
|
|
@@ -741,15 +750,28 @@ export function buildPromptBlocksPreloadPlan(
|
|
|
741
750
|
512,
|
|
742
751
|
Math.floor((maxStepTokens - wrapperOverheadTokens) * 0.9),
|
|
743
752
|
);
|
|
753
|
+
const minProtectedTextBytes = Math.min(chunkBytesLimit, 16_384);
|
|
754
|
+
const minProtectedTextTokens = Math.min(chunkTokensLimit, 4_096);
|
|
744
755
|
const finalTextBytesLimit = Math.max(
|
|
745
|
-
|
|
756
|
+
minProtectedTextBytes,
|
|
746
757
|
Math.min(chunkBytesLimit, maxStepBytes - nonTextMeasured.bytes - wrapperOverheadBytes),
|
|
747
758
|
);
|
|
748
759
|
const finalTextTokensLimit = Math.max(
|
|
749
|
-
|
|
760
|
+
minProtectedTextTokens,
|
|
750
761
|
Math.min(chunkTokensLimit, maxStepTokens - nonTextMeasured.tokens - wrapperOverheadTokens),
|
|
751
762
|
);
|
|
752
763
|
|
|
764
|
+
// 若超限纯粹源自图片数量过多而文本本身位于保护预算内,原样保留块结构,避免无意义裁切短文本
|
|
765
|
+
const combinedTextBytes = Buffer.byteLength(combinedText, "utf8");
|
|
766
|
+
const combinedTextTokens = estimateStepTokens(combinedText);
|
|
767
|
+
if (combinedTextBytes <= finalTextBytesLimit && combinedTextTokens <= finalTextTokensLimit) {
|
|
768
|
+
return {
|
|
769
|
+
preloadedTurns: [],
|
|
770
|
+
finalPromptBlocks: [...promptBlocks],
|
|
771
|
+
singleStepFallbackBlocks: [...promptBlocks],
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
|
|
753
775
|
// 单步安全降级块:保留头部 35% 与末尾 65%(优先保住末尾问题与输出格式要求)
|
|
754
776
|
const fallbackText = truncateTextMiddleToSafeBudget(
|
|
755
777
|
combinedText,
|
|
@@ -981,13 +1003,19 @@ export function buildFreshReplayPlan(options: FreshReplayPlanOptions): FreshRepl
|
|
|
981
1003
|
Math.min(MAX_PRELOAD_TOTAL_HISTORY_BYTES, totalHistoryTokenBudget * 4);
|
|
982
1004
|
|
|
983
1005
|
const preloadEntriesReversed: { text: string; bytes: number; tokens: number }[] = [];
|
|
984
|
-
const preservedRecentHistoryImages:
|
|
1006
|
+
const preservedRecentHistoryImages: Array<{
|
|
1007
|
+
block: Extract<AcpPromptBlock, { type: "image" }>;
|
|
1008
|
+
source:
|
|
1009
|
+
| { kind: "toolResult"; toolCallId: string; toolName: string; status: "ok" | "error" }
|
|
1010
|
+
| { kind: "user" };
|
|
1011
|
+
}> = [];
|
|
985
1012
|
let totalUsedHistoryBytes = 0;
|
|
986
1013
|
let totalUsedHistoryTokens = 0;
|
|
987
1014
|
let omittedMessageCount = 0;
|
|
988
1015
|
|
|
989
1016
|
for (let i = historySlice.length - 1; i >= 0; i--) {
|
|
990
|
-
const
|
|
1017
|
+
const historyMsg = historySlice[i];
|
|
1018
|
+
const serialized = serializeReplayHistoryEntry(historyMsg, {
|
|
991
1019
|
maxMessageBytes: MAX_PRELOAD_SINGLE_MESSAGE_TEXT_BYTES,
|
|
992
1020
|
maxToolBytes: MAX_PRELOAD_SINGLE_TOOL_TEXT_BYTES,
|
|
993
1021
|
});
|
|
@@ -999,7 +1027,18 @@ export function buildFreshReplayPlan(options: FreshReplayPlanOptions): FreshRepl
|
|
|
999
1027
|
textSegments.push(block.text);
|
|
1000
1028
|
} else if (block.type === "image") {
|
|
1001
1029
|
if (preservedRecentHistoryImages.length < MAX_FRESH_REPLAY_HISTORY_IMAGES) {
|
|
1002
|
-
preservedRecentHistoryImages.push(
|
|
1030
|
+
preservedRecentHistoryImages.push({
|
|
1031
|
+
block,
|
|
1032
|
+
source:
|
|
1033
|
+
historyMsg.role === "toolResult"
|
|
1034
|
+
? {
|
|
1035
|
+
kind: "toolResult",
|
|
1036
|
+
toolCallId: historyMsg.toolCallId,
|
|
1037
|
+
toolName: historyMsg.toolName,
|
|
1038
|
+
status: historyMsg.isError ? "error" : "ok",
|
|
1039
|
+
}
|
|
1040
|
+
: { kind: "user" },
|
|
1041
|
+
});
|
|
1003
1042
|
textSegments.push(`[attached recent ${block.mimeType} image from history]`);
|
|
1004
1043
|
} else {
|
|
1005
1044
|
textSegments.push(`[earlier ${block.mimeType} image omitted in replay]`);
|
|
@@ -1141,14 +1180,29 @@ export function buildFreshReplayPlan(options: FreshReplayPlanOptions): FreshRepl
|
|
|
1141
1180
|
if (workspaceContextBlock && !workspacePlaced) {
|
|
1142
1181
|
finalCandidateBlocks.push({ type: "text", text: workspaceContextBlock });
|
|
1143
1182
|
}
|
|
1144
|
-
//
|
|
1183
|
+
// 仅在剩余预算充足时附带少量近期历史图片(保留来源标签),绝不挤爆末尾用户提问
|
|
1145
1184
|
if (preservedRecentHistoryImages.length > 0) {
|
|
1185
|
+
const wrappedHistoryImageBlocks: AcpPromptBlock[] = [];
|
|
1186
|
+
for (const item of [...preservedRecentHistoryImages].reverse()) {
|
|
1187
|
+
if (item.source.kind === "toolResult") {
|
|
1188
|
+
wrappedHistoryImageBlocks.push({
|
|
1189
|
+
type: "text",
|
|
1190
|
+
text: `<tool_result id="${item.source.toolCallId}" tool="${item.source.toolName}" status="${item.source.status}">\n[recent image preserved from history]\n</tool_result>`,
|
|
1191
|
+
});
|
|
1192
|
+
} else {
|
|
1193
|
+
wrappedHistoryImageBlocks.push({
|
|
1194
|
+
type: "text",
|
|
1195
|
+
text: "[recent user image preserved from history]",
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
wrappedHistoryImageBlocks.push(item.block);
|
|
1199
|
+
}
|
|
1146
1200
|
const tailWithImgs = measurePromptBlocksSize([
|
|
1147
|
-
...
|
|
1201
|
+
...wrappedHistoryImageBlocks,
|
|
1148
1202
|
...rawTailBlocks,
|
|
1149
1203
|
]);
|
|
1150
1204
|
if (tailWithImgs.bytes <= maxStepBytes && tailWithImgs.tokens <= maxStepTokens) {
|
|
1151
|
-
finalCandidateBlocks.push(...
|
|
1205
|
+
finalCandidateBlocks.push(...wrappedHistoryImageBlocks);
|
|
1152
1206
|
}
|
|
1153
1207
|
}
|
|
1154
1208
|
finalCandidateBlocks.push(...rawTailBlocks);
|