chore(integration): snapshot local main worktree

This commit is contained in:
inman
2026-08-31 10:23:21 +08:00
parent 48a9189939
commit 33fb31fb28
116 changed files with 8108 additions and 3026 deletions

View File

@@ -454,7 +454,7 @@ function publicWorkerState(state: PiWorkerPoolState): ConversationSnapshot['work
code: state.failureCode === 'PI_RPC_PROTOCOL_ERROR'
? 'CODING_RUNTIME_PROTOCOL_ERROR'
: 'CODING_RUNTIME_START_FAILED',
message: 'The local Agent worker stopped unexpectedly',
message: '本地 Agent 服务已中断。',
recoverable: true,
},
};
@@ -462,6 +462,17 @@ function publicWorkerState(state: PiWorkerPoolState): ConversationSnapshot['work
return { status: 'ready', generation: state.generation };
}
function samePublicWorkerState(
left: ConversationSnapshot['worker'],
right: ConversationSnapshot['worker'],
): boolean {
return left.status === right.status
&& left.generation === right.generation
&& left.error?.code === right.error?.code
&& left.error?.message === right.error?.message
&& left.error?.recoverable === right.error?.recoverable;
}
function runtimeFailure(error: unknown): CodingRuntimePublicError {
if (error instanceof CodingRuntimeContractError) return clone(error.publicError);
if (error instanceof PiSessionProjectionError) {
@@ -471,7 +482,7 @@ function runtimeFailure(error: unknown): CodingRuntimePublicError {
if (error.code === 'PI_RPC_PROTOCOL_ERROR') {
return {
code: 'CODING_RUNTIME_PROTOCOL_ERROR',
message: 'The local Agent protocol failed',
message: '本地 Agent 通信异常,当前对话已停止。',
recoverable: true,
};
}
@@ -492,7 +503,7 @@ function runtimeFailure(error: unknown): CodingRuntimePublicError {
}
return {
code: 'CODING_RUNTIME_START_FAILED',
message: 'The local Agent is unavailable',
message: '本地 Agent 服务暂不可用。',
recoverable: true,
};
}
@@ -586,7 +597,10 @@ export class PiConversationRuntime implements CodingConversationRuntime {
});
}
this.interactions = new PiInteractionStore(this.pool, (interaction) => {
this.emit(interaction.conversationId, { op: 'interaction.upsert', interaction }, interaction.runId);
this.emit(interaction.conversationId, {
op: 'interaction.remove',
interactionId: interaction.id,
}, interaction.runId);
});
this.extensionUi = new PiExtensionUiProjector({
getDraftRevision: options.getDraftRevision ?? (() => 0),
@@ -624,7 +638,10 @@ export class PiConversationRuntime implements CodingConversationRuntime {
));
this.resetProjector(input.conversationId);
} else {
this.emit(input.conversationId, { op: 'worker.state', state: publicWorkerState(worker) });
const nextWorker = publicWorkerState(worker);
if (!samePublicWorkerState(this.snapshot(input.conversationId).worker, nextWorker)) {
this.emit(input.conversationId, { op: 'worker.state', state: nextWorker });
}
}
if (isNewState) {
try {
@@ -1411,6 +1428,8 @@ export class PiConversationRuntime implements CodingConversationRuntime {
run: {
status: 'idle',
runId: event.runId,
...(current.mode ? { mode: current.mode } : {}),
...(current.startedAt !== undefined ? { startedAt: current.startedAt } : {}),
settledAt: this.now(),
terminalReason: 'completed',
},
@@ -1571,6 +1590,8 @@ export class PiConversationRuntime implements CodingConversationRuntime {
run: {
status: 'error',
runId,
...(current.mode ? { mode: current.mode } : {}),
...(current.startedAt !== undefined ? { startedAt: current.startedAt } : {}),
settledAt: this.now(),
terminalReason: 'failed',
error: publicError,