@orgloop/agentctl 1.1.0 → 1.2.1

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.
@@ -0,0 +1,89 @@
1
+ import type { AgentAdapter, AgentSession, LaunchOpts, LifecycleEvent, ListOpts, PeekOpts, StopOpts } from "../core/types.js";
2
+ export interface PidInfo {
3
+ pid: number;
4
+ cwd: string;
5
+ args: string;
6
+ /** Process start time from `ps -p <pid> -o lstart=`, used to detect PID recycling */
7
+ startTime?: string;
8
+ }
9
+ /** Metadata persisted by launch() so status checks survive wrapper exit */
10
+ export interface LaunchedSessionMeta {
11
+ sessionId: string;
12
+ pid: number;
13
+ /** Process start time from `ps -p <pid> -o lstart=` for PID recycling detection */
14
+ startTime?: string;
15
+ /** The PID of the wrapper (agentctl launch) — may differ from `pid` (pi-rust process) */
16
+ wrapperPid?: number;
17
+ cwd: string;
18
+ model?: string;
19
+ prompt?: string;
20
+ launchedAt: string;
21
+ }
22
+ export interface PiRustAdapterOpts {
23
+ sessionDir?: string;
24
+ sessionsMetaDir?: string;
25
+ getPids?: () => Promise<Map<number, PidInfo>>;
26
+ /** Override PID liveness check for testing (default: process.kill(pid, 0)) */
27
+ isProcessAlive?: (pid: number) => boolean;
28
+ }
29
+ /**
30
+ * Pi Rust adapter — reads session data directly from ~/.pi/agent/sessions/
31
+ * and cross-references with running PIDs. NEVER maintains its own registry.
32
+ *
33
+ * Pi Rust (pi-rust / pi_agent_rust) stores sessions as JSONL files organized
34
+ * by project directory. It also maintains a SQLite index for fast lookups,
35
+ * but we read JSONL directly for simplicity and testability.
36
+ */
37
+ export declare class PiRustAdapter implements AgentAdapter {
38
+ readonly id = "pi-rust";
39
+ private readonly sessionDir;
40
+ private readonly sessionsMetaDir;
41
+ private readonly getPids;
42
+ private readonly isProcessAlive;
43
+ constructor(opts?: PiRustAdapterOpts);
44
+ list(opts?: ListOpts): Promise<AgentSession[]>;
45
+ peek(sessionId: string, opts?: PeekOpts): Promise<string>;
46
+ status(sessionId: string): Promise<AgentSession>;
47
+ launch(opts: LaunchOpts): Promise<AgentSession>;
48
+ /**
49
+ * Poll the launch log file for up to `timeoutMs` to extract the real session ID.
50
+ * Pi Rust's JSONL output includes the session ID in the first line (type: "session").
51
+ */
52
+ private pollForSessionId;
53
+ stop(sessionId: string, opts?: StopOpts): Promise<void>;
54
+ resume(sessionId: string, message: string): Promise<void>;
55
+ events(): AsyncIterable<LifecycleEvent>;
56
+ /** List .jsonl session files in a project directory */
57
+ private getSessionFiles;
58
+ /** Read and parse the session header (first line) from a JSONL file */
59
+ private readSessionHeader;
60
+ /** Extract the session ID from a JSONL filename (e.g., "2026-02-22T16-29-54.096Z_feb70071.jsonl" → "feb70071") */
61
+ private extractShortId;
62
+ private buildSession;
63
+ private isSessionRunning;
64
+ private processStartedAfterSession;
65
+ private findMatchingPid;
66
+ private parseSessionTail;
67
+ /** Read the first user prompt from a JSONL session file */
68
+ private readFirstPrompt;
69
+ /** Find a session JSONL file by session ID (full or prefix match) */
70
+ private findSessionFile;
71
+ private findPidForSession;
72
+ writeSessionMeta(meta: Omit<LaunchedSessionMeta, "startTime">): Promise<void>;
73
+ readSessionMeta(sessionId: string): Promise<LaunchedSessionMeta | null>;
74
+ private deleteSessionMeta;
75
+ }
76
+ /**
77
+ * Decode a Pi Rust project directory name back to the original path.
78
+ * Pi Rust encodes paths: "/" → "-", wrapped in "--".
79
+ * E.g., "--private-tmp-test-pi-rust--" → "/private/tmp/test-pi-rust"
80
+ *
81
+ * Note: This is a lossy encoding — hyphens in the original path are
82
+ * indistinguishable from path separators. We do our best to reconstruct.
83
+ */
84
+ export declare function decodeProjDir(dirName: string): string;
85
+ /**
86
+ * Encode a path as a Pi Rust project directory name.
87
+ * E.g., "/private/tmp/test-pi-rust" → "--private-tmp-test-pi-rust--"
88
+ */
89
+ export declare function encodeProjDir(cwdPath: string): string;