@pmndre/pine 0.0.0-stage → 0.22.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.
Files changed (151) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -2
  3. package/bin/pine.js +27 -0
  4. package/docs/SKILL.md +234 -0
  5. package/docs/references/agents.md +454 -0
  6. package/docs/references/coding.md +311 -0
  7. package/docs/references/computer.md +212 -0
  8. package/docs/references/configuration.md +310 -0
  9. package/docs/references/events.md +267 -0
  10. package/docs/references/mcp.md +420 -0
  11. package/docs/references/operations.md +394 -0
  12. package/docs/references/overview.md +195 -0
  13. package/docs/references/security.md +896 -0
  14. package/docs/references/setup.md +385 -0
  15. package/docs/references/sources.md +772 -0
  16. package/docs/references/stack.md +121 -0
  17. package/docs/references/tui.md +575 -0
  18. package/examples/home/.env.example +7 -0
  19. package/examples/home/USER.md +4 -0
  20. package/examples/home/agents/main/agent.json +4 -0
  21. package/examples/home/agents/main/workspace/AGENTS.md +14 -0
  22. package/examples/home/agents/main/workspace/MEMORY.md +4 -0
  23. package/examples/home/agents/main/workspace/SOUL.md +4 -0
  24. package/examples/home/models.json +62 -0
  25. package/examples/home/pine.json +34 -0
  26. package/examples/home/skills/README.txt +7 -0
  27. package/examples/launchd/com.pine.daemon.plist +32 -0
  28. package/examples/systemd/pine.service +22 -0
  29. package/mcp/browser.d.ts +99 -0
  30. package/mcp/browser.js +496 -0
  31. package/mcp/commands.d.ts +20 -0
  32. package/mcp/commands.js +88 -0
  33. package/mcp/computer.d.ts +139 -0
  34. package/mcp/computer.js +698 -0
  35. package/mcp/computer.swift +989 -0
  36. package/mcp/lib.d.ts +23 -0
  37. package/mcp/lib.js +52 -0
  38. package/mcp/web.d.ts +6 -0
  39. package/mcp/web.js +140 -0
  40. package/package.json +32 -4
  41. package/src/access.d.ts +112 -0
  42. package/src/access.js +438 -0
  43. package/src/actions.d.ts +75 -0
  44. package/src/actions.js +167 -0
  45. package/src/admin.d.ts +167 -0
  46. package/src/admin.js +625 -0
  47. package/src/agent-admin.d.ts +24 -0
  48. package/src/agent-admin.js +55 -0
  49. package/src/agents.d.ts +540 -0
  50. package/src/agents.js +2776 -0
  51. package/src/background.d.ts +29 -0
  52. package/src/background.js +100 -0
  53. package/src/cli.d.ts +2 -0
  54. package/src/cli.js +777 -0
  55. package/src/computer.d.ts +30 -0
  56. package/src/computer.js +32 -0
  57. package/src/config.d.ts +396 -0
  58. package/src/config.js +549 -0
  59. package/src/dev/claude-model.d.ts +37 -0
  60. package/src/dev/claude-model.js +204 -0
  61. package/src/env-file.d.ts +4 -0
  62. package/src/env-file.js +40 -0
  63. package/src/goals.d.ts +133 -0
  64. package/src/goals.js +316 -0
  65. package/src/http.d.ts +46 -0
  66. package/src/http.js +509 -0
  67. package/src/limiter.d.ts +32 -0
  68. package/src/limiter.js +84 -0
  69. package/src/login.d.ts +23 -0
  70. package/src/login.js +130 -0
  71. package/src/manual.d.ts +61 -0
  72. package/src/manual.js +443 -0
  73. package/src/mcp-config.d.ts +49 -0
  74. package/src/mcp-config.js +182 -0
  75. package/src/models.d.ts +90 -0
  76. package/src/models.js +274 -0
  77. package/src/net.d.ts +50 -0
  78. package/src/net.js +150 -0
  79. package/src/pine.d.ts +32 -0
  80. package/src/pine.js +134 -0
  81. package/src/programs.d.ts +123 -0
  82. package/src/programs.js +412 -0
  83. package/src/router.d.ts +56 -0
  84. package/src/router.js +164 -0
  85. package/src/sandbox-fs.d.ts +34 -0
  86. package/src/sandbox-fs.js +186 -0
  87. package/src/sandbox-linux.d.ts +96 -0
  88. package/src/sandbox-linux.js +297 -0
  89. package/src/sandbox-setup.d.ts +70 -0
  90. package/src/sandbox-setup.js +216 -0
  91. package/src/security.d.ts +238 -0
  92. package/src/security.js +660 -0
  93. package/src/skills.d.ts +67 -0
  94. package/src/skills.js +163 -0
  95. package/src/snapshots.d.ts +68 -0
  96. package/src/snapshots.js +306 -0
  97. package/src/source-types.d.ts +61 -0
  98. package/src/source-types.js +1 -0
  99. package/src/sources/command.d.ts +4 -0
  100. package/src/sources/command.js +77 -0
  101. package/src/sources/folder.d.ts +6 -0
  102. package/src/sources/folder.js +116 -0
  103. package/src/sources/ftp.d.ts +4 -0
  104. package/src/sources/ftp.js +307 -0
  105. package/src/sources/http.d.ts +4 -0
  106. package/src/sources/http.js +201 -0
  107. package/src/sources/mqtt.d.ts +18 -0
  108. package/src/sources/mqtt.js +97 -0
  109. package/src/sources/telegram.d.ts +22 -0
  110. package/src/sources/telegram.js +283 -0
  111. package/src/sources/webhook.d.ts +4 -0
  112. package/src/sources/webhook.js +52 -0
  113. package/src/sources.d.ts +344 -0
  114. package/src/sources.js +966 -0
  115. package/src/store.d.ts +99 -0
  116. package/src/store.js +277 -0
  117. package/src/timers.d.ts +83 -0
  118. package/src/timers.js +318 -0
  119. package/src/tools.d.ts +11 -0
  120. package/src/tools.js +1297 -0
  121. package/src/tui/app.d.ts +305 -0
  122. package/src/tui/app.js +3195 -0
  123. package/src/tui/client.d.ts +236 -0
  124. package/src/tui/client.js +131 -0
  125. package/src/tui/code-pane.d.ts +68 -0
  126. package/src/tui/code-pane.js +535 -0
  127. package/src/tui/highlight.d.ts +8 -0
  128. package/src/tui/highlight.js +86 -0
  129. package/src/tui/picture.d.ts +206 -0
  130. package/src/tui/picture.js +801 -0
  131. package/src/tui/run.d.ts +8 -0
  132. package/src/tui/run.js +97 -0
  133. package/src/tui/theme.d.ts +32 -0
  134. package/src/tui/theme.js +128 -0
  135. package/src/tui/undo.d.ts +5 -0
  136. package/src/tui/undo.js +50 -0
  137. package/src/tui/voice.d.ts +49 -0
  138. package/src/tui/voice.js +155 -0
  139. package/src/tui/voice.swift +223 -0
  140. package/src/types.d.ts +139 -0
  141. package/src/types.js +1 -0
  142. package/src/undo.d.ts +224 -0
  143. package/src/undo.js +465 -0
  144. package/src/update.d.ts +35 -0
  145. package/src/update.js +130 -0
  146. package/src/util.d.ts +65 -0
  147. package/src/util.js +171 -0
  148. package/src/watching.d.ts +20 -0
  149. package/src/watching.js +68 -0
  150. package/src/workspace-view.d.ts +72 -0
  151. package/src/workspace-view.js +221 -0
@@ -0,0 +1,236 @@
1
+ import type { PineEvent, Task, TaskResult, TranscriptEntry } from "../types.ts";
2
+ import type { TurnView, UndoResult } from "../undo.ts";
3
+ /** One conversation of an agent. `expires`: when it is removed by itself unless something more is said in it. */
4
+ export interface Conversation {
5
+ session: string;
6
+ tasks: number;
7
+ last: number;
8
+ pinned: boolean;
9
+ open: boolean;
10
+ expires?: number;
11
+ /** The folder opened for it, if any. */
12
+ folder?: string;
13
+ }
14
+ /** The goal of a conversation, as the daemon keeps it (src/goals.ts). `reason` is the judge's line: text to show, nothing more. */
15
+ export interface GoalInfo {
16
+ agent: string;
17
+ session: string;
18
+ objective: string;
19
+ status: "active" | "paused" | "met" | "blocked" | "limit";
20
+ round: number;
21
+ until: number;
22
+ note: string;
23
+ reason?: string;
24
+ }
25
+ export interface AgentInfo {
26
+ id: string;
27
+ main: boolean;
28
+ description: string;
29
+ workspace: string;
30
+ model: string;
31
+ mode: "manual" | "safe" | "auto" | "bypass" | "plan";
32
+ thinking: string;
33
+ delegates: string[];
34
+ }
35
+ /** Talks to a pine daemon over its control API. */
36
+ export declare class Client {
37
+ base: string;
38
+ private token;
39
+ constructor(base: string, token: string);
40
+ private call;
41
+ /** A picture from the daemon, or undefined when there is none (or it is not an image). */
42
+ private picture;
43
+ toolImage: (id: string) => Promise<{
44
+ mime: string;
45
+ bytes: Buffer;
46
+ } | undefined>;
47
+ taskImage: (task: number, n: number) => Promise<{
48
+ mime: string;
49
+ bytes: Buffer;
50
+ } | undefined>;
51
+ workspaceImage: (agent: string, file: string, session?: string) => Promise<{
52
+ mime: string;
53
+ bytes: Buffer;
54
+ } | undefined>;
55
+ fetchImage: (url: string) => Promise<{
56
+ mime: string;
57
+ bytes: Buffer;
58
+ } | undefined>;
59
+ sources: () => Promise<any[]>;
60
+ subscribeTo: (agent: string, source: string, details?: Record<string, unknown>) => Promise<any>;
61
+ unsubscribeFrom: (agent: string, source: string, session?: string) => Promise<{
62
+ unsubscribed: boolean;
63
+ sessions: string[];
64
+ }>;
65
+ subscribeAll: (source: string, details?: Record<string, unknown>) => Promise<any>;
66
+ unsubscribeAll: (source: string) => Promise<{
67
+ unsubscribed: boolean;
68
+ }>;
69
+ /** Tell the daemon a conversation was closed here; returns the sources it was subscribed to on its own. */
70
+ closeSession: (agent: string, session: string) => Promise<{
71
+ unsubscribed: string[];
72
+ }>;
73
+ get: <T>(url: string) => Promise<T>;
74
+ post: <T>(url: string, body?: unknown) => Promise<T>;
75
+ agents: () => Promise<AgentInfo[]>;
76
+ status: () => Promise<any>;
77
+ models: () => Promise<string[]>;
78
+ sessions: (agent: string) => Promise<Conversation[]>;
79
+ removeSession: (agent: string, session: string) => Promise<{
80
+ removed: boolean;
81
+ unsubscribed: string[];
82
+ sources: string[];
83
+ servers: string[];
84
+ }>;
85
+ renameSession: (agent: string, session: string, to: string) => Promise<{
86
+ session: string;
87
+ }>;
88
+ pinSession: (agent: string, session: string, pinned: boolean) => Promise<{
89
+ pinned: boolean;
90
+ }>;
91
+ folder: (agent: string, session: string) => Promise<{
92
+ folder?: string;
93
+ workspace: string;
94
+ }>;
95
+ programs: (agent: string, session: string) => Promise<{
96
+ id: number;
97
+ command: string;
98
+ processes: number;
99
+ ports: number[];
100
+ seconds: number;
101
+ background?: boolean;
102
+ output?: string;
103
+ }[]>;
104
+ goal: (agent: string, session: string) => Promise<{
105
+ goal?: GoalInfo;
106
+ }>;
107
+ /** Set a goal (`objective`), or pause, resume or clear the one there is (`action`). */
108
+ setGoal: (agent: string, session: string, what: {
109
+ objective: string;
110
+ } | {
111
+ action: "pause" | "resume" | "clear";
112
+ }) => Promise<{
113
+ goal?: GoalInfo;
114
+ cleared?: boolean;
115
+ }>;
116
+ stopProgram: (agent: string, session: string, id: number) => Promise<{
117
+ stopped: boolean;
118
+ }>;
119
+ folders: (agent: string) => Promise<{
120
+ session: string;
121
+ folder: string;
122
+ }[]>;
123
+ setFolder: (agent: string, session: string, folder: string | null) => Promise<{
124
+ folder?: string;
125
+ }>;
126
+ changes: (agent: string, session: string) => Promise<{
127
+ root: string;
128
+ repo: boolean;
129
+ branch?: string;
130
+ files: Array<{
131
+ path: string;
132
+ status: string;
133
+ added?: number;
134
+ removed?: number;
135
+ }>;
136
+ more: boolean;
137
+ }>;
138
+ diff: (agent: string, session: string, file: string) => Promise<{
139
+ diff: string;
140
+ truncated: boolean;
141
+ }>;
142
+ tree: (agent: string, session: string, dir: string) => Promise<{
143
+ entries: Array<{
144
+ name: string;
145
+ dir: boolean;
146
+ size: number;
147
+ }>;
148
+ more: boolean;
149
+ }>;
150
+ file: (agent: string, session: string, file: string) => Promise<{
151
+ text?: string;
152
+ size: number;
153
+ binary: boolean;
154
+ truncated: boolean;
155
+ }>;
156
+ /** Take back the owner's last message in a conversation, and bring back what was taken back last. */
157
+ undo: (agent: string, session: string) => Promise<UndoResult>;
158
+ redo: (agent: string, session: string) => Promise<UndoResult>;
159
+ /** What the last message changed in the conversation's folder, and one file's difference over it. */
160
+ turn: (agent: string, session: string) => Promise<TurnView>;
161
+ turnDiff: (agent: string, session: string, file: string) => Promise<{
162
+ diff: string;
163
+ truncated: boolean;
164
+ }>;
165
+ output: (task: number) => Promise<{
166
+ task: Task;
167
+ entries: TranscriptEntry[];
168
+ }>;
169
+ tabs: () => Promise<{
170
+ tabs: Array<{
171
+ agent: string;
172
+ session: string;
173
+ }>;
174
+ active: number;
175
+ code?: boolean;
176
+ notify?: boolean;
177
+ }>;
178
+ saveTabs: (tabs: Array<{
179
+ agent: string;
180
+ session: string;
181
+ }>, active: number, code?: boolean, notify?: boolean) => Promise<{
182
+ ok: boolean;
183
+ }>;
184
+ history: (agent: string, session: string, limit?: number) => Promise<Task[]>;
185
+ prompt: (agent: string, prompt: string, session: string, attachments?: Array<{
186
+ name: string;
187
+ data: string;
188
+ }>, whenBusy?: "steer" | "queue", mentions?: string[]) => Promise<{
189
+ task: number;
190
+ steered?: number;
191
+ }>;
192
+ /** Files of a conversation's folder whose path fits what was typed. */
193
+ find: (agent: string, session: string, q: string) => Promise<{
194
+ files: string[];
195
+ }>;
196
+ ask: (agent: string, prompt: string, session: string) => Promise<TaskResult>;
197
+ transcript: (task: number) => Promise<{
198
+ task: Task;
199
+ entries: TranscriptEntry[];
200
+ }>;
201
+ cancel: (task: number) => Promise<{
202
+ cancelled: boolean;
203
+ }>;
204
+ reset: (agent: string, session: string) => Promise<{
205
+ reset: boolean;
206
+ }>;
207
+ todos: (agent: string, session: string) => Promise<{
208
+ text: string;
209
+ status: "pending" | "in_progress" | "done";
210
+ }[]>;
211
+ compact: (agent: string, session: string) => Promise<{
212
+ task: number;
213
+ }>;
214
+ setThinking: (agent: string, level: string) => Promise<{
215
+ level: string;
216
+ }>;
217
+ setMode: (agent: string, mode: string, anyway?: string) => Promise<{
218
+ mode: string;
219
+ }>;
220
+ setModel: (agent: string, model: string) => Promise<{
221
+ model: string;
222
+ }>;
223
+ approvals: () => Promise<any[]>;
224
+ decide: (id: string, allow: boolean, always?: boolean, values?: Record<string, string>) => Promise<{
225
+ decided: boolean;
226
+ }>;
227
+ emit: (topic: string, payload: unknown) => Promise<{
228
+ id: number;
229
+ }>;
230
+ state: (pattern?: string) => Promise<{
231
+ key: string;
232
+ value: unknown;
233
+ }[]>;
234
+ /** Live events. Reconnects until the returned function is called. */
235
+ subscribe(onEvent: (e: PineEvent) => void, onState?: (connected: boolean) => void): () => void;
236
+ }
@@ -0,0 +1,131 @@
1
+ /** Talks to a pine daemon over its control API. */
2
+ export class Client {
3
+ base;
4
+ token;
5
+ constructor(base, token) {
6
+ this.base = base.replace(/\/$/, "");
7
+ this.token = token;
8
+ }
9
+ async call(method, url, body) {
10
+ const res = await fetch(this.base + url, {
11
+ method,
12
+ headers: { authorization: `Bearer ${this.token}`, ...(body !== undefined ? { "content-type": "application/json" } : {}) },
13
+ body: body !== undefined ? JSON.stringify(body) : undefined,
14
+ });
15
+ const json = await res.json().catch(() => ({}));
16
+ if (!res.ok)
17
+ throw new Error(json.error ?? `HTTP ${res.status}`);
18
+ return json;
19
+ }
20
+ /** A picture from the daemon, or undefined when there is none (or it is not an image). */
21
+ async picture(method, url, body) {
22
+ const res = await fetch(this.base + url, {
23
+ method,
24
+ headers: { authorization: `Bearer ${this.token}`, ...(body !== undefined ? { "content-type": "application/json" } : {}) },
25
+ body: body !== undefined ? JSON.stringify(body) : undefined,
26
+ });
27
+ if (res.status === 404)
28
+ return undefined;
29
+ if (!res.ok)
30
+ throw new Error((await res.json().catch(() => ({}))).error ?? `HTTP ${res.status}`);
31
+ return { mime: res.headers.get("content-type") ?? "", bytes: Buffer.from(await res.arrayBuffer()) };
32
+ }
33
+ toolImage = (id) => this.picture("GET", `/media/tool/${encodeURIComponent(id)}`);
34
+ taskImage = (task, n) => this.picture("GET", `/tasks/${task}/images/${n}`);
35
+ workspaceImage = (agent, file, session) => this.picture("GET", `/agents/${encodeURIComponent(agent)}/image?path=${encodeURIComponent(file)}${session ? `&session=${encodeURIComponent(session)}` : ""}`);
36
+ fetchImage = (url) => this.picture("POST", "/images/fetch", { url });
37
+ sources = () => this.get("/sources");
38
+ subscribeTo = (agent, source, details = {}) => this.post(`/agents/${agent}/subscribe`, { source, ...details });
39
+ unsubscribeFrom = (agent, source, session) => this.post(`/agents/${agent}/unsubscribe`, { source, session });
40
+ subscribeAll = (source, details = {}) => this.post("/subscribe", { source, ...details });
41
+ unsubscribeAll = (source) => this.post("/unsubscribe", { source });
42
+ /** Tell the daemon a conversation was closed here; returns the sources it was subscribed to on its own. */
43
+ closeSession = (agent, session) => this.post(`/agents/${agent}/close`, { session });
44
+ get = (url) => this.call("GET", url);
45
+ post = (url, body = {}) => this.call("POST", url, body);
46
+ agents = () => this.get("/agents");
47
+ status = () => this.get("/status");
48
+ models = () => this.get("/models");
49
+ sessions = (agent) => this.get(`/agents/${agent}/sessions`);
50
+ removeSession = (agent, session) => this.post(`/agents/${agent}/remove`, { session });
51
+ renameSession = (agent, session, to) => this.post(`/agents/${agent}/rename`, { session, to });
52
+ pinSession = (agent, session, pinned) => this.post(`/agents/${agent}/pin`, { session, pinned });
53
+ folder = (agent, session) => this.get(`/agents/${agent}/folder?session=${encodeURIComponent(session)}`);
54
+ programs = (agent, session) => this.get(`/agents/${agent}/programs?session=${encodeURIComponent(session)}`);
55
+ goal = (agent, session) => this.get(`/agents/${agent}/goal?session=${encodeURIComponent(session)}`);
56
+ /** Set a goal (`objective`), or pause, resume or clear the one there is (`action`). */
57
+ setGoal = (agent, session, what) => this.post(`/agents/${agent}/goal`, { session, ...what });
58
+ stopProgram = (agent, session, id) => this.post(`/agents/${agent}/programs/stop`, { session, id });
59
+ folders = (agent) => this.get(`/agents/${agent}/folders`);
60
+ setFolder = (agent, session, folder) => this.post(`/agents/${agent}/folder`, { session, folder });
61
+ changes = (agent, session) => this.get(`/agents/${agent}/view/changes?session=${encodeURIComponent(session)}`);
62
+ diff = (agent, session, file) => this.get(`/agents/${agent}/view/diff?session=${encodeURIComponent(session)}&path=${encodeURIComponent(file)}`);
63
+ tree = (agent, session, dir) => this.get(`/agents/${agent}/view/tree?session=${encodeURIComponent(session)}&path=${encodeURIComponent(dir)}`);
64
+ file = (agent, session, file) => this.get(`/agents/${agent}/view/file?session=${encodeURIComponent(session)}&path=${encodeURIComponent(file)}`);
65
+ /** Take back the owner's last message in a conversation, and bring back what was taken back last. */
66
+ undo = (agent, session) => this.post(`/agents/${agent}/undo`, { session });
67
+ redo = (agent, session) => this.post(`/agents/${agent}/redo`, { session });
68
+ /** What the last message changed in the conversation's folder, and one file's difference over it. */
69
+ turn = (agent, session) => this.get(`/agents/${agent}/view/turn?session=${encodeURIComponent(session)}`);
70
+ turnDiff = (agent, session, file) => this.get(`/agents/${agent}/view/turndiff?session=${encodeURIComponent(session)}&path=${encodeURIComponent(file)}`);
71
+ output = (task) => this.get(`/tasks/${task}/transcript?full=1`);
72
+ tabs = () => this.get("/ui/tabs");
73
+ saveTabs = (tabs, active, code = false, notify = true) => this.post("/ui/tabs", { tabs, active, code, notify });
74
+ history = (agent, session, limit = 30) => this.get(`/tasks?agent=${encodeURIComponent(agent)}&session=${encodeURIComponent(session)}&limit=${limit}`);
75
+ prompt = (agent, prompt, session, attachments, whenBusy = "queue", mentions) => this.post(`/agents/${agent}/prompt`, { prompt, session, wait: false, attachments, whenBusy, mentions });
76
+ /** Files of a conversation's folder whose path fits what was typed. */
77
+ find = (agent, session, q) => this.get(`/agents/${agent}/view/find?session=${encodeURIComponent(session)}&q=${encodeURIComponent(q)}`);
78
+ ask = (agent, prompt, session) => this.post(`/agents/${agent}/prompt`, { prompt, session });
79
+ transcript = (task) => this.get(`/tasks/${task}/transcript`);
80
+ cancel = (task) => this.post(`/tasks/${task}/cancel`);
81
+ reset = (agent, session) => this.post(`/agents/${agent}/reset`, { session });
82
+ todos = (agent, session) => this.get(`/agents/${agent}/todos?session=${encodeURIComponent(session)}`);
83
+ compact = (agent, session) => this.post(`/agents/${agent}/compact`, { session });
84
+ setThinking = (agent, level) => this.post(`/agents/${agent}/thinking`, { level });
85
+ setMode = (agent, mode, anyway) => this.post(`/agents/${agent}/mode`, { mode, session: anyway, anyway: anyway !== undefined });
86
+ setModel = (agent, model) => this.post(`/agents/${agent}/model`, { model });
87
+ approvals = () => this.get("/approvals");
88
+ decide = (id, allow, always = false, values) => this.post(`/approvals/${id}`, { allow, always, values });
89
+ emit = (topic, payload) => this.post("/events", { topic, payload });
90
+ state = (pattern = "#") => this.get(`/state?key=${encodeURIComponent(pattern)}`);
91
+ /** Live events. Reconnects until the returned function is called. */
92
+ subscribe(onEvent, onState = () => { }) {
93
+ const abort = new AbortController();
94
+ const loop = async () => {
95
+ while (!abort.signal.aborted) {
96
+ try {
97
+ const res = await fetch(`${this.base}/events/stream?topic=%23`, { headers: { authorization: `Bearer ${this.token}` }, signal: abort.signal });
98
+ if (!res.ok || !res.body)
99
+ throw new Error(`HTTP ${res.status}`);
100
+ onState(true);
101
+ let buf = "";
102
+ const decoder = new TextDecoder();
103
+ for await (const chunk of res.body) {
104
+ buf += decoder.decode(chunk, { stream: true });
105
+ for (let i = buf.indexOf("\n\n"); i >= 0; i = buf.indexOf("\n\n")) {
106
+ const block = buf.slice(0, i);
107
+ buf = buf.slice(i + 2);
108
+ if (!block.startsWith("data: "))
109
+ continue;
110
+ try {
111
+ onEvent(JSON.parse(block.slice(6)));
112
+ }
113
+ catch {
114
+ // A malformed frame is skipped; the stream goes on.
115
+ }
116
+ }
117
+ }
118
+ }
119
+ catch {
120
+ // fall through to the retry
121
+ }
122
+ if (abort.signal.aborted)
123
+ return;
124
+ onState(false);
125
+ await new Promise((r) => setTimeout(r, 1000));
126
+ }
127
+ };
128
+ void loop();
129
+ return () => abort.abort();
130
+ }
131
+ }
@@ -0,0 +1,68 @@
1
+ import { VStack } from "@earendil-works/pi-tui";
2
+ import type { Client } from "./client.ts";
3
+ export type PaneView = "changes" | "files" | "output" | "running";
4
+ export declare const PANE_VIEWS: PaneView[];
5
+ /** The conversation a pane shows. */
6
+ export interface PaneTarget {
7
+ agent: string;
8
+ session: string;
9
+ }
10
+ /** The lines of a diff as git prints it, in colours, without the lines that only name the file. */
11
+ export declare function diffLines(diff: string): string[];
12
+ export declare class CodePane {
13
+ /** What goes into the layout. */
14
+ readonly component: VStack;
15
+ private client;
16
+ private redraw;
17
+ private close;
18
+ private target;
19
+ private states;
20
+ private rows;
21
+ private scroll;
22
+ private hits;
23
+ private timer?;
24
+ private width;
25
+ /** Counts loads, so that an answer that arrives late does not overwrite a newer one. */
26
+ private turn;
27
+ private steps?;
28
+ constructor(opts: {
29
+ client: Client;
30
+ redraw: () => void;
31
+ close: () => void;
32
+ target: () => PaneTarget | undefined;
33
+ steps?: () => Array<{
34
+ text: string;
35
+ status: string;
36
+ }> | undefined;
37
+ });
38
+ private get state();
39
+ get view(): PaneView;
40
+ /** Show one of the views, from its top level. Without a view: whatever was shown last, read again. */
41
+ show(view?: PaneView): void;
42
+ /** The changes view, counted from before the owner's last message: what that message changed. */
43
+ showTurn(): void;
44
+ /** The conversation shown changed its folder: what was read from the old one is not shown any more. */
45
+ forget(target: PaneTarget): void;
46
+ /** Something happened that may have changed what is shown (a tool ran, a task ended): read it again in a moment. */
47
+ touch(): void;
48
+ stop(): void;
49
+ private load;
50
+ private fileRows;
51
+ private go;
52
+ private back;
53
+ private build;
54
+ /** What the owner's last message changed in the folder: the same list and diffs, between the states pine recorded before and after it. */
55
+ private turnRows;
56
+ private changesRows;
57
+ private filesRows;
58
+ /** A server or another program that the conversation's commands started and that is still there, each with a way to stop it. */
59
+ private runningRows;
60
+ private stopProgram;
61
+ private outputRows;
62
+ private renderHead;
63
+ /**
64
+ * The steps the agent listed for itself, kept at the top of the pane in every view: in the
65
+ * conversation they are soon far above, behind the tool calls of the work itself.
66
+ */
67
+ private stepsLines;
68
+ }