@co0ontty/wand 0.3.0 → 0.4.0

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.
@@ -18,18 +18,40 @@ export declare class SessionInputError extends Error {
18
18
  constructor(message: string, code: "SESSION_NOT_FOUND" | "SESSION_NOT_RUNNING" | "SESSION_NO_PTY", sessionId: string, sessionStatus?: SessionSnapshot["status"] | undefined);
19
19
  }
20
20
  export type ProcessEventHandler = (event: ProcessEvent) => void;
21
+ /** A Claude Code session discovered by scanning ~/.claude/projects/ directories. */
22
+ export interface ClaudeHistorySession {
23
+ claudeSessionId: string;
24
+ projectDir: string;
25
+ cwd: string;
26
+ firstUserMessage: string;
27
+ timestamp: string;
28
+ mtimeMs: number;
29
+ hasConversation: boolean;
30
+ managedByWand: boolean;
31
+ }
21
32
  export declare class ProcessManager extends EventEmitter {
22
33
  private readonly config;
23
34
  private readonly storage;
24
35
  private readonly sessions;
25
36
  private readonly logger;
26
37
  private readonly lifecycleManager;
38
+ /** Per-session debounce timers for throttled persist calls */
39
+ private readonly persistDebounceTimers;
40
+ /** Last persisted message count per session — used to skip redundant file writes */
41
+ private readonly lastPersistedMessageCount;
27
42
  constructor(config: WandConfig, storage: WandStorage, configDir?: string);
28
43
  on(event: "process", listener: ProcessEventHandler): this;
29
44
  private emitEvent;
30
45
  private cleanupOldSessions;
31
- start(command: string, cwd: string | undefined, mode: ExecutionMode, initialInput?: string): SessionSnapshot;
46
+ start(command: string, cwd: string | undefined, mode: ExecutionMode, initialInput?: string, opts?: {
47
+ resumedFromSessionId?: string;
48
+ autoRecovered?: boolean;
49
+ }): SessionSnapshot;
32
50
  list(): SessionSnapshot[];
51
+ hasClaudeSessionFile(cwd: string, claudeSessionId: string): boolean;
52
+ private claudeHistoryCache;
53
+ private static readonly HISTORY_CACHE_TTL_MS;
54
+ listClaudeHistorySessions(): ClaudeHistorySession[];
33
55
  get(id: string): SessionSnapshot | null;
34
56
  sendInput(id: string, input: string, view?: "chat" | "terminal"): SessionSnapshot;
35
57
  /** Emit a task event for a session, debounced to avoid flooding */
@@ -37,7 +59,8 @@ export declare class ProcessManager extends EventEmitter {
37
59
  resize(id: string, cols: number, rows: number): SessionSnapshot;
38
60
  stop(id: string): SessionSnapshot;
39
61
  delete(id: string): void;
40
- runStartupCommands(): Promise<SessionSnapshot[]>;
62
+ private deleteClaudeCache;
63
+ runStartupCommands(): SessionSnapshot[];
41
64
  private snapshot;
42
65
  private isPermissionBlocked;
43
66
  private defaultAutonomyPolicy;
@@ -45,13 +68,38 @@ export declare class ProcessManager extends EventEmitter {
45
68
  approvePermission(id: string): SessionSnapshot;
46
69
  denyPermission(id: string): SessionSnapshot;
47
70
  /**
48
- * Resolve permission with specific resolution type.
71
+ * Canonical permission resolution method.
72
+ * All other permission methods delegate to this.
49
73
  * @param resolution - "approve_once", "approve_turn", or "deny"
74
+ * @param requestId - Optional escalation request ID for validation
50
75
  */
51
- resolvePermission(id: string, resolution: "approve_once" | "approve_turn" | "deny"): SessionSnapshot;
76
+ resolvePermission(id: string, resolution: "approve_once" | "approve_turn" | "deny", requestId?: string): SessionSnapshot;
52
77
  private persist;
78
+ /**
79
+ * Schedule a debounced persist call for the given record.
80
+ * Multiple calls within the debounce window are coalesced into a single write.
81
+ * Use this in hot paths (e.g. onData) to reduce I/O pressure.
82
+ */
83
+ private schedulePersist;
84
+ /**
85
+ * Immediately persist any pending debounced write and clear the timer.
86
+ * Use this at critical points (exit, stop, delete) to ensure no data loss.
87
+ */
88
+ private flushPersist;
89
+ private backfillExitedClaudeSessionIds;
90
+ /**
91
+ * Auto-recover the most recent exited session that has a Claude session ID.
92
+ * Only resumes one session per server start, using the most recent eligible
93
+ * session. Sets `resumedToSessionId` on the original session and
94
+ * `autoRecovered: true` on the new session.
95
+ */
96
+ private autoRecoverExitedSessions;
53
97
  private archiveExpiredSessions;
54
98
  private assertCommandAllowed;
99
+ /**
100
+ * @deprecated Only retained for non-Claude-CLI sessions without ptyBridge.
101
+ * For Claude CLI sessions, auto-approval is handled by ClaudePtyBridge.detectPermission().
102
+ */
55
103
  private autoConfirmWithRecord;
56
104
  /**
57
105
  * Handle events from ClaudePtyBridge