@keyou007/agent-bot 0.1.16-alpha.3 → 0.1.16-alpha.4

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.
@@ -9,33 +9,6 @@ export class SessionMetadataHydrator {
9
9
  ) {}
10
10
 
11
11
  async hydrate(session: SessionRecord): Promise<SessionRecord> {
12
- if (
13
- session.runtimeKind === "codex"
14
- && session.remoteSessionId
15
- && session.lastTurnId
16
- && session.status === "running"
17
- && session.lastTurnStatus === "running"
18
- ) {
19
- const runtime = this.runtimes.forAgent(session.agentName);
20
- const loaded = runtime.getSession(session.localSessionId) ?? await runtime.resumeSession({
21
- localSessionId: session.localSessionId,
22
- remoteSessionId: session.remoteSessionId,
23
- activeTurnId: session.lastTurnId,
24
- lastTurnId: session.lastTurnId,
25
- lastTurnStatus: session.lastTurnStatus,
26
- agentName: session.agentName,
27
- cwd: session.cwd,
28
- title: session.title,
29
- model: session.model,
30
- reasoningEffort: session.reasoningEffort,
31
- permissionMode: session.permissionMode ?? "auto",
32
- });
33
- const synchronized = await runtime.synchronizeSession(loaded.localSessionId);
34
- if (synchronized.title) {
35
- this.store.updateRuntimeSession(session.localSessionId, { title: synchronized.title });
36
- }
37
- return this.store.getSession(session.localSessionId) ?? session;
38
- }
39
12
  if (session.title || !session.runtimeKind || !session.remoteSessionId) return session;
40
13
  if (session.runtimeKind === "codex" && !session.lastTurnId) return session;
41
14
  const metadata = await this.runtimes.forAgent(session.agentName).readSessionMetadata(session.remoteSessionId);
@@ -111,6 +111,7 @@ export type TurnAttemptStatus =
111
111
  | "accepted"
112
112
  | "running"
113
113
  | "recovering"
114
+ | "cancelling"
114
115
  | "completed"
115
116
  | "failed"
116
117
  | "cancelled"
@@ -633,6 +634,15 @@ export class StateStore {
633
634
  return rows.map(mapTurnAttempt);
634
635
  }
635
636
 
637
+ listCancellationRequestedTurnAttempts(): TurnAttemptRecord[] {
638
+ const rows = this.db.prepare(`
639
+ SELECT * FROM turn_attempts
640
+ WHERE status = 'cancelling'
641
+ ORDER BY created_at ASC, rowid ASC
642
+ `).all() as TurnAttemptRow[];
643
+ return rows.map(mapTurnAttempt);
644
+ }
645
+
636
646
  updateTurnAttempt(
637
647
  attemptId: string,
638
648
  patch: Partial<{
@@ -697,6 +707,19 @@ export class StateStore {
697
707
  return row ? mapTurnAttempt(row) : undefined;
698
708
  }
699
709
 
710
+ requestTurnAttemptCancellation(turnId: string): TurnAttemptRecord | undefined {
711
+ const existing = this.findIncompleteTurnAttemptByTurnId(turnId);
712
+ if (!existing) return undefined;
713
+ this.updateTurnAttempt(existing.attemptId, { status: "cancelling" });
714
+ return existing;
715
+ }
716
+
717
+ restoreTurnAttemptAfterCancellationFailure(attempt: TurnAttemptRecord): void {
718
+ const current = this.getTurnAttempt(attempt.attemptId);
719
+ if (current?.status !== "cancelling") return;
720
+ this.updateTurnAttempt(attempt.attemptId, { status: attempt.status });
721
+ }
722
+
700
723
  touchTurnAttempt(turnId: string, activityAt = new Date()): void {
701
724
  const timestamp = activityAt.toISOString();
702
725
  const throttleCutoff = new Date(activityAt.getTime() - 15_000).toISOString();
@@ -737,6 +760,17 @@ export class StateStore {
737
760
  return this.getTurnAttempt(attemptId);
738
761
  }
739
762
 
763
+ prepareUnstartedTurnAttemptRetry(attemptId: string): TurnAttemptRecord | undefined {
764
+ const existing = this.getTurnAttempt(attemptId);
765
+ if (!existing || existing.turnId || !isIncompleteTurnAttemptStatus(existing.status)) return undefined;
766
+ this.updateTurnAttempt(attemptId, {
767
+ pendingTurnId: null,
768
+ retryCount: existing.retryCount + 1,
769
+ status: "recovering",
770
+ });
771
+ return this.getTurnAttempt(attemptId);
772
+ }
773
+
740
774
  rebindPendingTurnMessages(localSessionId: string, sourceTurnId: string, targetTurnId: string): void {
741
775
  const now = new Date().toISOString();
742
776
  const rebind = this.db.transaction(() => {