@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,204 @@
1
+ // Development model server: an OpenAI-compatible /v1/chat/completions endpoint whose answers come
2
+ // from `claude -p`. It lets pine (and pi) run against a capable model before a local one is set
3
+ // up. Each request starts one `claude` process, so it is slow and uses your Claude plan; do not
4
+ // point a production daemon at it.
5
+ import { spawn } from "node:child_process";
6
+ import fs from "node:fs";
7
+ import http from "node:http";
8
+ import os from "node:os";
9
+ import path from "node:path";
10
+ const RULES = `You are standing in for a language model behind an OpenAI-style chat completions API. An agent harness sends you its system prompt, the tools it offers and the conversation so far. Your only job is to write the next assistant message.
11
+
12
+ You have no tools of your own in this role. The tools listed in <tools> belong to the harness: you ask for them in your reply, the harness runs them and sends the conversation back with the results in <tool_result> blocks.
13
+
14
+ Reply with exactly one JSON object and nothing else (no prose before or after, no code fence):
15
+
16
+ {"text": "<what the assistant says, may be empty>", "tool_calls": [{"name": "<tool name>", "arguments": { ... }}]}
17
+
18
+ - "arguments" must match the tool's parameter schema.
19
+ - Every tool in <tools> is available. Use them the way the harness system prompt expects: act, do not ask for permission to use a tool the role is meant to use.
20
+ - Several calls in one reply are fine. Never state the outcome of a call before you have seen its <tool_result>.
21
+ - When the task is done or needs no tool, put the answer in "text" and use "tool_calls": [].
22
+ - Pictures of the conversation are attached to this message, in order. Where one belongs, the conversation says [picture 1], [picture 2] and so on.
23
+
24
+ Play the role the harness system prompt defines.`;
25
+ /** The model's reply is one JSON object; tolerate a code fence or stray text around it. */
26
+ export function parseReply(raw) {
27
+ const start = raw.indexOf("{");
28
+ const end = raw.lastIndexOf("}");
29
+ if (start >= 0 && end > start) {
30
+ try {
31
+ const o = JSON.parse(raw.slice(start, end + 1));
32
+ if (o && typeof o === "object" && ("text" in o || "tool_calls" in o)) {
33
+ return { text: String(o.text ?? ""), tool_calls: Array.isArray(o.tool_calls) ? o.tool_calls.filter((c) => c && typeof c.name === "string") : [] };
34
+ }
35
+ }
36
+ catch {
37
+ // fall through: treat the whole reply as text
38
+ }
39
+ }
40
+ return { text: raw.trim(), tool_calls: [] };
41
+ }
42
+ /**
43
+ * The prompt for a request. Pictures cannot be part of a text: each leaves a mark where it
44
+ * stood and is added to `pictures`, which go along with the prompt in the same order.
45
+ */
46
+ export function buildPrompt(body, pictures = []) {
47
+ const textOf = (content) => typeof content === "string"
48
+ ? content
49
+ : Array.isArray(content)
50
+ ? content
51
+ .map((p) => {
52
+ if (p.type === "text")
53
+ return p.text;
54
+ const m = p.type === "image_url" ? /^data:([^;,]+);base64,(.+)$/s.exec(String(p.image_url?.url ?? "")) : null;
55
+ if (!m)
56
+ return `[${p.type} omitted]`;
57
+ pictures.push({ media_type: m[1], data: m[2] });
58
+ return `[picture ${pictures.length}]`;
59
+ })
60
+ .join("")
61
+ : "";
62
+ const messages = body.messages ?? [];
63
+ const system = messages.filter((m) => m.role === "system" || m.role === "developer").map((m) => textOf(m.content)).join("\n\n");
64
+ const tools = (body.tools ?? []).map((t) => ({ name: t.function?.name ?? t.name, description: t.function?.description ?? t.description, parameters: t.function?.parameters ?? t.parameters }));
65
+ const turns = messages
66
+ .filter((m) => m.role !== "system" && m.role !== "developer")
67
+ .map((m) => {
68
+ if (m.role === "tool")
69
+ return `<tool_result id="${m.tool_call_id ?? ""}">\n${textOf(m.content)}\n</tool_result>`;
70
+ if (m.role === "assistant") {
71
+ const calls = (m.tool_calls ?? []).map((c) => `<tool_call id="${c.id}" name="${c.function?.name}">${c.function?.arguments ?? "{}"}</tool_call>`).join("\n");
72
+ return `<assistant>\n${[textOf(m.content), calls].filter(Boolean).join("\n")}\n</assistant>`;
73
+ }
74
+ return `<user>\n${textOf(m.content)}\n</user>`;
75
+ });
76
+ return `<harness_system_prompt>\n${system}\n</harness_system_prompt>\n\n<tools>\n${JSON.stringify(tools, null, 1)}\n</tools>\n\n<conversation>\n${turns.join("\n")}\n</conversation>\n\nWrite the next assistant message now, as the single JSON object described in your instructions.`;
77
+ }
78
+ export async function startClaudeModel(opts = {}) {
79
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "pine-claude-model-"));
80
+ const max = opts.concurrency ?? 3;
81
+ const log = opts.log ?? (() => { });
82
+ let active = 0;
83
+ const queue = [];
84
+ const stats = { requests: 0, failures: 0 };
85
+ const take = () => (active < max ? (active++, Promise.resolve()) : new Promise((r) => queue.push(r)));
86
+ const give = () => {
87
+ const next = queue.shift();
88
+ if (next)
89
+ next();
90
+ else
91
+ active--;
92
+ };
93
+ const ask = (prompt, model, signal, pictures = []) => new Promise((resolve, reject) => {
94
+ // A prompt with pictures goes in as a message of parts, and the answer comes back as a stream of lines whose last one is the result.
95
+ const format = pictures.length ? ["--input-format", "stream-json", "--output-format", "stream-json", "--verbose"] : ["--output-format", "json"];
96
+ const child = spawn(opts.claudePath ?? "claude", ["-p", "--model", model, ...format, "--tools", "", "--strict-mcp-config", "--no-session-persistence", "--setting-sources", "", "--disable-slash-commands", "--system-prompt", RULES], { cwd, stdio: ["pipe", "pipe", "pipe"] });
97
+ let out = "";
98
+ let err = "";
99
+ child.stdout.on("data", (d) => (out += d));
100
+ child.stderr.on("data", (d) => (err += d));
101
+ const onAbort = () => child.kill("SIGKILL");
102
+ signal.addEventListener("abort", onAbort, { once: true });
103
+ child.on("error", reject);
104
+ child.on("close", (code) => {
105
+ signal.removeEventListener("abort", onAbort);
106
+ if (signal.aborted)
107
+ return reject(new Error("aborted"));
108
+ try {
109
+ const json = pictures.length ? out.trim().split("\n").map((l) => { try {
110
+ return JSON.parse(l);
111
+ }
112
+ catch {
113
+ return undefined;
114
+ } }).findLast((m) => m?.type === "result") : JSON.parse(out);
115
+ if (!json)
116
+ throw new Error("no result in the output");
117
+ if (json.is_error)
118
+ throw new Error(String(json.result ?? "claude reported an error"));
119
+ resolve(parseReply(String(json.result ?? "")));
120
+ }
121
+ catch (e) {
122
+ reject(new Error(`claude -p failed (exit ${code}): ${e.message} ${err.slice(0, 300)}`));
123
+ }
124
+ });
125
+ child.stdin.on("error", () => { });
126
+ child.stdin.end(pictures.length ? `${JSON.stringify({ type: "user", message: { role: "user", content: [{ type: "text", text: prompt }, ...pictures.map((p) => ({ type: "image", source: { type: "base64", ...p } }))] } })}\n` : prompt);
127
+ });
128
+ const server = http.createServer(async (req, res) => {
129
+ if (req.method === "GET") {
130
+ res.writeHead(200, { "content-type": "application/json" });
131
+ return res.end(JSON.stringify({ object: "list", data: ["haiku", "sonnet", "opus"].map((id) => ({ id: `claude-${id}`, object: "model" })) }));
132
+ }
133
+ let raw = "";
134
+ for await (const c of req)
135
+ raw += c;
136
+ let body;
137
+ try {
138
+ body = JSON.parse(raw);
139
+ }
140
+ catch {
141
+ res.writeHead(400, { "content-type": "application/json" });
142
+ return res.end(JSON.stringify({ error: { message: "invalid JSON" } }));
143
+ }
144
+ const abort = new AbortController();
145
+ res.on("close", () => !res.writableEnded && abort.abort());
146
+ const model = /^(claude-)?(haiku|sonnet|opus|fable)$/.test(String(body.model)) ? String(body.model).replace(/^claude-/, "") : (opts.model ?? "haiku");
147
+ const pictures = [];
148
+ const prompt = buildPrompt(body, pictures);
149
+ stats.requests++;
150
+ const t0 = Date.now();
151
+ await take();
152
+ let answer;
153
+ try {
154
+ answer = await ask(prompt, model, abort.signal, pictures);
155
+ }
156
+ catch (e) {
157
+ stats.failures++;
158
+ give();
159
+ if (abort.signal.aborted)
160
+ return;
161
+ log(`request failed: ${e.message}`);
162
+ res.writeHead(500, { "content-type": "application/json" });
163
+ return res.end(JSON.stringify({ error: { message: e.message, type: "server_error" } }));
164
+ }
165
+ give();
166
+ const calls = answer.tool_calls
167
+ .map((c, i) => ({ index: i, id: `call_${stats.requests}_${i}`, type: "function", function: { name: c.name, arguments: typeof c.arguments === "string" ? c.arguments : JSON.stringify(c.arguments ?? {}) } }));
168
+ log(`${model} ${Date.now() - t0} ms: ${calls.length ? calls.map((c) => c.function.name).join(", ") : `text (${answer.text.length} chars)`}`);
169
+ const usage = { prompt_tokens: Math.ceil(prompt.length / 4), completion_tokens: Math.ceil((answer.text.length + JSON.stringify(calls).length) / 4), total_tokens: 0 };
170
+ usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
171
+ const id = `chatcmpl-claude-${stats.requests}`;
172
+ const base = { id, created: Math.floor(Date.now() / 1000), model: body.model };
173
+ const finish = calls.length ? "tool_calls" : "stop";
174
+ if (!body.stream) {
175
+ res.writeHead(200, { "content-type": "application/json" });
176
+ return res.end(JSON.stringify({ ...base, object: "chat.completion", choices: [{ index: 0, message: { role: "assistant", content: answer.text, ...(calls.length ? { tool_calls: calls.map(({ index: _i, ...c }) => c) } : {}) }, finish_reason: finish }], usage }));
177
+ }
178
+ const chunk = (delta, finish_reason = null, extra = {}) => res.write(`data: ${JSON.stringify({ ...base, object: "chat.completion.chunk", choices: [{ index: 0, delta, finish_reason }], ...extra })}\n\n`);
179
+ res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", connection: "keep-alive" });
180
+ chunk({ role: "assistant", content: "" });
181
+ for (let i = 0; i < answer.text.length; i += 80)
182
+ chunk({ content: answer.text.slice(i, i + 80) });
183
+ for (const c of calls)
184
+ chunk({ tool_calls: [c] });
185
+ chunk({}, finish, { usage });
186
+ res.write("data: [DONE]\n\n");
187
+ res.end();
188
+ });
189
+ await new Promise((resolve, reject) => {
190
+ server.once("error", (e) => reject(e.code === "EADDRINUSE" ? new Error(`port ${opts.port} is already in use; pick another with --port and set the same port in models.json`) : e));
191
+ server.listen(opts.port ?? 0, opts.host ?? "127.0.0.1", resolve);
192
+ });
193
+ const port = server.address().port;
194
+ return {
195
+ port,
196
+ baseUrl: `http://127.0.0.1:${port}/v1`,
197
+ stats,
198
+ close: () => new Promise((r) => {
199
+ server.closeAllConnections?.();
200
+ server.close(() => r());
201
+ fs.rmSync(cwd, { recursive: true, force: true });
202
+ }),
203
+ };
204
+ }
@@ -0,0 +1,4 @@
1
+ /** Set entries in .env, replacing ones of the same name. The file stays readable by its owner only. */
2
+ export declare function setEnv(home: string, entries: Record<string, string>): void;
3
+ /** Take entries out of .env again. */
4
+ export declare function unsetEnv(home: string, names: string[]): void;
@@ -0,0 +1,40 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { parseEnv } from "node:util";
4
+ // pine's .env file holds the secrets the configuration refers to as ${NAME}. A secret that reaches
5
+ // pine through a tool call (a broker's password, say) is put here, not into pine.json or an
6
+ // agent.json, so that the configuration files never hold one.
7
+ const fileOf = (home) => path.join(home, ".env");
8
+ /** How a value is written so that it reads back exactly as it is. */
9
+ function quoted(value) {
10
+ if (/[\r\n]/.test(value))
11
+ throw new Error("a secret cannot contain a line break");
12
+ for (const form of [value, `'${value}'`, `"${value}"`, `\`${value}\``])
13
+ if (parseEnv(`X=${form}`).X === value)
14
+ return form;
15
+ throw new Error("this value cannot be stored in the .env file (it mixes every kind of quote)");
16
+ }
17
+ /** Set entries in .env, replacing ones of the same name. The file stays readable by its owner only. */
18
+ export function setEnv(home, entries) {
19
+ const names = Object.keys(entries);
20
+ if (!names.length)
21
+ return;
22
+ for (const name of names)
23
+ if (!/^[A-Z][A-Z0-9_]*$/.test(name))
24
+ throw new Error(`"${name}" is not a usable name for an .env entry`);
25
+ const lines = Object.entries(entries).map(([name, value]) => `${name}=${quoted(value)}`);
26
+ const kept = fs.existsSync(fileOf(home)) ? fs.readFileSync(fileOf(home), "utf8").split("\n").filter((line) => !names.some((name) => line.startsWith(`${name}=`))) : [];
27
+ while (kept.length && !kept.at(-1).trim())
28
+ kept.pop();
29
+ fs.writeFileSync(fileOf(home), `${[...kept, ...lines].join("\n")}\n`, { mode: 0o600 });
30
+ fs.chmodSync(fileOf(home), 0o600);
31
+ }
32
+ /** Take entries out of .env again. */
33
+ export function unsetEnv(home, names) {
34
+ if (!names.length || !fs.existsSync(fileOf(home)))
35
+ return;
36
+ const lines = fs.readFileSync(fileOf(home), "utf8").split("\n");
37
+ const kept = lines.filter((line) => !names.some((name) => line.startsWith(`${name}=`)));
38
+ if (kept.length !== lines.length)
39
+ fs.writeFileSync(fileOf(home), kept.join("\n"), { mode: 0o600 });
40
+ }
package/src/goals.d.ts ADDED
@@ -0,0 +1,133 @@
1
+ import type { AgentManager } from "./agents.ts";
2
+ import type { Task } from "./types.ts";
3
+ import { type Logger } from "./util.ts";
4
+ /**
5
+ * Goal mode: the owner gives a conversation an objective, and the agent is called again each time
6
+ * it ends a turn until a judge says the objective is met.
7
+ *
8
+ * Who may do what:
9
+ * - Only the owner sets, pauses, resumes or clears a goal, through the control API. There is no
10
+ * tool for any of it: an agent cannot give itself a goal or more rounds.
11
+ * - A goal belongs to the owner's side of a conversation. A run started from outside works in
12
+ * another session ("~u"); it has no goal, its end is never judged, and it is never continued.
13
+ * - What calls the agent again is the owner's objective and pine's fixed text, nothing else. The
14
+ * judge reads the agent's answer, which may repeat what a web page said; so the judge's reason
15
+ * is shown to the owner and never put in front of the agent.
16
+ * - The judge decides only whether to go on. Which actions may run is the gate's business
17
+ * (src/agents.ts), in a round of a goal as in any other task.
18
+ */
19
+ export type GoalStatus = "active" | "paused" | "met" | "blocked" | "limit";
20
+ export type GoalVerdict = "met" | "continue" | "blocked";
21
+ export interface Goal {
22
+ agent: string;
23
+ /** The conversation, by its session key. */
24
+ session: string;
25
+ /** What the owner wants reached, in their words. */
26
+ objective: string;
27
+ status: GoalStatus;
28
+ /** The round it is in, or ended in. The first is the owner's own message with the objective. */
29
+ round: number;
30
+ /** The round after which it stops by itself. */
31
+ until: number;
32
+ /** Rounds in a row that ended "not met" without a single tool call. */
33
+ idle: number;
34
+ set: number;
35
+ /** The task of the round that is waiting, running or being judged. */
36
+ task?: number;
37
+ /** What happened last, in pine's words. */
38
+ note: string;
39
+ /** The judge's one line. For the owner to read; it never goes into a prompt. */
40
+ reason?: string;
41
+ }
42
+ /** The first message of a goal: the objective as the owner typed it, and pine's fixed line. */
43
+ export declare const startPrompt: (objective: string) => string;
44
+ /**
45
+ * What calls the agent again. It holds the owner's objective and fixed text of pine's, and nothing
46
+ * else: no word of the agent's answer and none of the judge's.
47
+ */
48
+ export declare const continuePrompt: (objective: string) => string;
49
+ /** What the judge is asked: the goal and the answer, each marked as what it is. */
50
+ export declare function judgePrompt(objective: string, answer: string, toolCalls: number): {
51
+ system: string;
52
+ user: string;
53
+ };
54
+ /**
55
+ * The judge's line, read strictly: the last line that starts with one of the three words. Anything
56
+ * else is no verdict, and no verdict is never "go on".
57
+ */
58
+ export declare function parseJudgement(text: string): {
59
+ verdict: GoalVerdict;
60
+ reason?: string;
61
+ } | undefined;
62
+ type Manager = Pick<AgentManager, "cfg" | "kv" | "tasks" | "bus" | "limiter" | "models" | "submit" | "cancel" | "resolveModel" | "modelFor">;
63
+ export declare class Goals {
64
+ private m;
65
+ private log;
66
+ private key;
67
+ /** True while this class submits a first message itself: that one is the goal, not the owner interrupting it. */
68
+ private starting;
69
+ /** Judge calls under way, by conversation, so that a pause ends the call too. */
70
+ private judging;
71
+ constructor(manager: Manager, log: Logger, sessionKey: (session: string) => string);
72
+ private id;
73
+ private conversation;
74
+ /** The goal of a conversation, if it has one. */
75
+ get(agent: string, session: string): Goal | undefined;
76
+ private save;
77
+ /** For whoever shows the conversation: what the goal is now and what just happened. */
78
+ private tell;
79
+ private rounds;
80
+ /** Set the goal of a conversation and start on it. Reached from the control API only. */
81
+ set(agent: string, session: string, wanted: string): Goal;
82
+ /** No further rounds until the owner says so. A round that is running ends by itself. */
83
+ pause(agent: string, session: string): Goal;
84
+ /** Go on with a goal that stopped: paused, blocked, at its limit, or called met too early. */
85
+ resume(agent: string, session: string): Goal;
86
+ /** Take the goal off a conversation. Reached from the control API. */
87
+ clear(agent: string, session: string): boolean;
88
+ /** The conversation is reset or removed: its goal goes with it. */
89
+ drop(agent: string, session: string): void;
90
+ /** The conversation has another name now. */
91
+ rename(agent: string, from: string, to: string): void;
92
+ private end;
93
+ /** A round that has not started does not start. Returns whether there was one. */
94
+ private unqueue;
95
+ private halt;
96
+ /**
97
+ * The task that calls the agent again.
98
+ *
99
+ * Trust "owner": like a schedule, it acts at the owner's wish, and its text is the owner's own
100
+ * objective inside a fixed frame of pine's. Nothing the agent wrote, read or was told by a tool
101
+ * is in it, so nothing from outside gains the owner's voice by being repeated here.
102
+ *
103
+ * Kind "notify": it is pine speaking in the same conversation, like the "[pine: ...]" notices
104
+ * after add_mcp_server. It is not "prompt": the owner did not type it now, so it does not
105
+ * count as the owner interrupting their own goal.
106
+ */
107
+ private next;
108
+ /**
109
+ * A task of the owner's is about to start in a conversation. If it is a message of their own,
110
+ * they have something else to say, or a correction: the goal waits until they say to go on.
111
+ * Their own message is one they typed (kind "prompt", through the control API), or one they
112
+ * sent through a source they talk to the agent with, such as Telegram: an event that wants its
113
+ * answer sent back. Otherwise "stop" sent from a phone would be answered and then overruled by
114
+ * the next round. A schedule, a device's report and pine's own notices are not the owner
115
+ * speaking, and change nothing. Called by `AgentManager.submit`.
116
+ */
117
+ incoming(agent: string, session: string, kind: string, wantsAnswer: boolean): void;
118
+ /**
119
+ * A task ended. If it was the round of an active goal, the judge is asked; when the owner
120
+ * stopped it, or it failed, the goal waits. Called by `AgentManager.finish` for every task.
121
+ */
122
+ ended(task: Task, stopping?: boolean): void;
123
+ /**
124
+ * After a start of the daemon. A goal that was being worked on waits for the owner's word: its
125
+ * round was interrupted, or the judge was, or the round had not started yet (then it does not
126
+ * start now). Work that goes on by itself should not begin because a machine came back up.
127
+ */
128
+ restore(): void;
129
+ private judge;
130
+ /** One model call without tools. Undefined: no verdict (the model did not answer in time, or not in the form asked for). */
131
+ private ask;
132
+ }
133
+ export {};