style(session): satisfy xdev rewind checks
This commit is contained in:
@@ -545,16 +545,11 @@ type SemanticToolResult = {
|
||||
*/
|
||||
function semanticToolResult(toolName: string | undefined, result: unknown): SemanticToolResult | undefined {
|
||||
if (toolName === "checkpoint" || toolName === "rewind") {
|
||||
const details =
|
||||
result && typeof result === "object" && "details" in result ? result.details : undefined;
|
||||
const details = result && typeof result === "object" && "details" in result ? result.details : undefined;
|
||||
return { toolName, details };
|
||||
}
|
||||
const dispatch = writeDeviceDispatch(toolName ?? "", result);
|
||||
if (
|
||||
!dispatch ||
|
||||
dispatch.mode !== "execute" ||
|
||||
(dispatch.tool !== "checkpoint" && dispatch.tool !== "rewind")
|
||||
) {
|
||||
if (dispatch?.mode !== "execute" || (dispatch.tool !== "checkpoint" && dispatch.tool !== "rewind")) {
|
||||
return undefined;
|
||||
}
|
||||
return { toolName: dispatch.tool, details: dispatch.inner };
|
||||
@@ -4410,13 +4405,7 @@ export class AgentSession {
|
||||
this.#invalidateFileCacheForPath(editedPath);
|
||||
}
|
||||
const phases = details?.phases;
|
||||
if (
|
||||
toolName === "todo" &&
|
||||
!isError &&
|
||||
details &&
|
||||
Array.isArray(phases) &&
|
||||
phases.every(isTodoPhase)
|
||||
) {
|
||||
if (toolName === "todo" && !isError && details && Array.isArray(phases) && phases.every(isTodoPhase)) {
|
||||
this.setTodoPhases(phases);
|
||||
if (this.#isTodoInitResult(details, toolCallId)) {
|
||||
this.#scheduleReplanTitleRefresh();
|
||||
@@ -4447,14 +4436,13 @@ export class AgentSession {
|
||||
checkpointMessageCount: this.agent.state.messages.length,
|
||||
checkpointEntryId,
|
||||
startedAt:
|
||||
(semanticDetails && stringProperty(semanticDetails, "startedAt")) ??
|
||||
new Date().toISOString(),
|
||||
(semanticDetails && stringProperty(semanticDetails, "startedAt")) ?? new Date().toISOString(),
|
||||
};
|
||||
this.#pendingRewindReport = undefined;
|
||||
this.#lastCompletedRewind = undefined;
|
||||
}
|
||||
if (semanticResult?.toolName === "rewind" && !isError && this.#checkpointState) {
|
||||
const detailReport = semanticDetails ? stringProperty(semanticDetails, "report")?.trim() ?? "" : "";
|
||||
const detailReport = semanticDetails ? (stringProperty(semanticDetails, "report")?.trim() ?? "") : "";
|
||||
const textReport = content?.find(part => part.type === "text")?.text?.trim() ?? "";
|
||||
const report = detailReport || textReport;
|
||||
if (report.length > 0) {
|
||||
|
||||
@@ -35,10 +35,7 @@ const xdevWriteTool: AgentTool<typeof xdevWriteSchema, unknown> = {
|
||||
const args = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
||||
const goal = "goal" in args && typeof args.goal === "string" ? args.goal : undefined;
|
||||
const report = "report" in args && typeof args.report === "string" ? args.report : undefined;
|
||||
const inner =
|
||||
tool === "checkpoint"
|
||||
? { goal, startedAt: "2026-01-01T00:00:00.000Z" }
|
||||
: { report, rewound: true };
|
||||
const inner = tool === "checkpoint" ? { goal, startedAt: "2026-01-01T00:00:00.000Z" } : { report, rewound: true };
|
||||
return {
|
||||
content: [{ type: "text" as const, text: `${tool} via xdev` }],
|
||||
details: {
|
||||
@@ -624,9 +621,10 @@ describe("AgentSession checkpoint rewind branch context", () => {
|
||||
startedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
expect(reloadedSession.getLastCompletedRewind()).toBeUndefined();
|
||||
await expect(rewindToolForSession(reloadedSession).execute("call_rewind_after_xdev_resume", {
|
||||
report: "post-resume findings",
|
||||
})).resolves.toMatchObject({ details: { report: "post-resume findings", rewound: true } });
|
||||
await expect(
|
||||
rewindToolForSession(reloadedSession).execute("call_rewind_after_xdev_resume", {
|
||||
report: "post-resume findings",
|
||||
}),
|
||||
).resolves.toMatchObject({ details: { report: "post-resume findings", rewound: true } });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user