@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.
- package/LICENSE +21 -0
- package/README.md +226 -2
- package/bin/pine.js +27 -0
- package/docs/SKILL.md +234 -0
- package/docs/references/agents.md +454 -0
- package/docs/references/coding.md +311 -0
- package/docs/references/computer.md +212 -0
- package/docs/references/configuration.md +310 -0
- package/docs/references/events.md +267 -0
- package/docs/references/mcp.md +420 -0
- package/docs/references/operations.md +394 -0
- package/docs/references/overview.md +195 -0
- package/docs/references/security.md +896 -0
- package/docs/references/setup.md +385 -0
- package/docs/references/sources.md +772 -0
- package/docs/references/stack.md +121 -0
- package/docs/references/tui.md +575 -0
- package/examples/home/.env.example +7 -0
- package/examples/home/USER.md +4 -0
- package/examples/home/agents/main/agent.json +4 -0
- package/examples/home/agents/main/workspace/AGENTS.md +14 -0
- package/examples/home/agents/main/workspace/MEMORY.md +4 -0
- package/examples/home/agents/main/workspace/SOUL.md +4 -0
- package/examples/home/models.json +62 -0
- package/examples/home/pine.json +34 -0
- package/examples/home/skills/README.txt +7 -0
- package/examples/launchd/com.pine.daemon.plist +32 -0
- package/examples/systemd/pine.service +22 -0
- package/mcp/browser.d.ts +99 -0
- package/mcp/browser.js +496 -0
- package/mcp/commands.d.ts +20 -0
- package/mcp/commands.js +88 -0
- package/mcp/computer.d.ts +139 -0
- package/mcp/computer.js +698 -0
- package/mcp/computer.swift +989 -0
- package/mcp/lib.d.ts +23 -0
- package/mcp/lib.js +52 -0
- package/mcp/web.d.ts +6 -0
- package/mcp/web.js +140 -0
- package/package.json +32 -4
- package/src/access.d.ts +112 -0
- package/src/access.js +438 -0
- package/src/actions.d.ts +75 -0
- package/src/actions.js +167 -0
- package/src/admin.d.ts +167 -0
- package/src/admin.js +625 -0
- package/src/agent-admin.d.ts +24 -0
- package/src/agent-admin.js +55 -0
- package/src/agents.d.ts +540 -0
- package/src/agents.js +2776 -0
- package/src/background.d.ts +29 -0
- package/src/background.js +100 -0
- package/src/cli.d.ts +2 -0
- package/src/cli.js +777 -0
- package/src/computer.d.ts +30 -0
- package/src/computer.js +32 -0
- package/src/config.d.ts +396 -0
- package/src/config.js +549 -0
- package/src/dev/claude-model.d.ts +37 -0
- package/src/dev/claude-model.js +204 -0
- package/src/env-file.d.ts +4 -0
- package/src/env-file.js +40 -0
- package/src/goals.d.ts +133 -0
- package/src/goals.js +316 -0
- package/src/http.d.ts +46 -0
- package/src/http.js +509 -0
- package/src/limiter.d.ts +32 -0
- package/src/limiter.js +84 -0
- package/src/login.d.ts +23 -0
- package/src/login.js +130 -0
- package/src/manual.d.ts +61 -0
- package/src/manual.js +443 -0
- package/src/mcp-config.d.ts +49 -0
- package/src/mcp-config.js +182 -0
- package/src/models.d.ts +90 -0
- package/src/models.js +274 -0
- package/src/net.d.ts +50 -0
- package/src/net.js +150 -0
- package/src/pine.d.ts +32 -0
- package/src/pine.js +134 -0
- package/src/programs.d.ts +123 -0
- package/src/programs.js +412 -0
- package/src/router.d.ts +56 -0
- package/src/router.js +164 -0
- package/src/sandbox-fs.d.ts +34 -0
- package/src/sandbox-fs.js +186 -0
- package/src/sandbox-linux.d.ts +96 -0
- package/src/sandbox-linux.js +297 -0
- package/src/sandbox-setup.d.ts +70 -0
- package/src/sandbox-setup.js +216 -0
- package/src/security.d.ts +238 -0
- package/src/security.js +660 -0
- package/src/skills.d.ts +67 -0
- package/src/skills.js +163 -0
- package/src/snapshots.d.ts +68 -0
- package/src/snapshots.js +306 -0
- package/src/source-types.d.ts +61 -0
- package/src/source-types.js +1 -0
- package/src/sources/command.d.ts +4 -0
- package/src/sources/command.js +77 -0
- package/src/sources/folder.d.ts +6 -0
- package/src/sources/folder.js +116 -0
- package/src/sources/ftp.d.ts +4 -0
- package/src/sources/ftp.js +307 -0
- package/src/sources/http.d.ts +4 -0
- package/src/sources/http.js +201 -0
- package/src/sources/mqtt.d.ts +18 -0
- package/src/sources/mqtt.js +97 -0
- package/src/sources/telegram.d.ts +22 -0
- package/src/sources/telegram.js +283 -0
- package/src/sources/webhook.d.ts +4 -0
- package/src/sources/webhook.js +52 -0
- package/src/sources.d.ts +344 -0
- package/src/sources.js +966 -0
- package/src/store.d.ts +99 -0
- package/src/store.js +277 -0
- package/src/timers.d.ts +83 -0
- package/src/timers.js +318 -0
- package/src/tools.d.ts +11 -0
- package/src/tools.js +1297 -0
- package/src/tui/app.d.ts +305 -0
- package/src/tui/app.js +3195 -0
- package/src/tui/client.d.ts +236 -0
- package/src/tui/client.js +131 -0
- package/src/tui/code-pane.d.ts +68 -0
- package/src/tui/code-pane.js +535 -0
- package/src/tui/highlight.d.ts +8 -0
- package/src/tui/highlight.js +86 -0
- package/src/tui/picture.d.ts +206 -0
- package/src/tui/picture.js +801 -0
- package/src/tui/run.d.ts +8 -0
- package/src/tui/run.js +97 -0
- package/src/tui/theme.d.ts +32 -0
- package/src/tui/theme.js +128 -0
- package/src/tui/undo.d.ts +5 -0
- package/src/tui/undo.js +50 -0
- package/src/tui/voice.d.ts +49 -0
- package/src/tui/voice.js +155 -0
- package/src/tui/voice.swift +223 -0
- package/src/types.d.ts +139 -0
- package/src/types.js +1 -0
- package/src/undo.d.ts +224 -0
- package/src/undo.js +465 -0
- package/src/update.d.ts +35 -0
- package/src/update.js +130 -0
- package/src/util.d.ts +65 -0
- package/src/util.js +171 -0
- package/src/watching.d.ts +20 -0
- package/src/watching.js +68 -0
- package/src/workspace-view.d.ts +72 -0
- package/src/workspace-view.js +221 -0
package/src/undo.js
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { errText } from "./util.js";
|
|
5
|
+
const KEEP_TURNS = 40;
|
|
6
|
+
const KEEP_UNDONE = 20;
|
|
7
|
+
/**
|
|
8
|
+
* A message the owner typed into a conversation: the only thing undo takes back. Not one that
|
|
9
|
+
* was steered into a running task: that is part of the task's turn and has no run of its own.
|
|
10
|
+
*/
|
|
11
|
+
export const ownerMessage = (t) => t.kind === "prompt" && t.meta.trust === "owner" && t.parent === undefined && !t.session.startsWith("_t") && !t.session.endsWith("~u") && !t.meta.label?.startsWith("steered into");
|
|
12
|
+
/** The message without what pine added to it at the time. */
|
|
13
|
+
export const typed = (prompt) => prompt.replace(/\n\n\[files attached by your owner, saved in your workspace: [^\]]*\]$/, "");
|
|
14
|
+
const tally = (root, files, left) => ({
|
|
15
|
+
root,
|
|
16
|
+
// Seen from the folder as it was: a file the message made is removed, one it deleted comes back.
|
|
17
|
+
changed: files.filter((f) => f.status === "M").length,
|
|
18
|
+
removed: files.filter((f) => f.status === "D").length,
|
|
19
|
+
back: files.filter((f) => f.status === "A").length,
|
|
20
|
+
files: files.slice(0, 20).map((f) => f.path),
|
|
21
|
+
left,
|
|
22
|
+
});
|
|
23
|
+
export class Turns {
|
|
24
|
+
kv;
|
|
25
|
+
tasks;
|
|
26
|
+
snapshots;
|
|
27
|
+
log;
|
|
28
|
+
/** Tasks whose turn has its "before" (or is getting it): asked with every tool call, so answered from here. */
|
|
29
|
+
seen = new Map();
|
|
30
|
+
/**
|
|
31
|
+
* What a conversation was allowed before each message and when it was taken back, as far as
|
|
32
|
+
* the daemon holds that in memory only (see `AgentManager.rightsOf`). Gone with a restart, as
|
|
33
|
+
* those rights are.
|
|
34
|
+
*/
|
|
35
|
+
rights = new Map();
|
|
36
|
+
constructor(deps) {
|
|
37
|
+
this.kv = deps.kv;
|
|
38
|
+
this.tasks = deps.tasks;
|
|
39
|
+
this.snapshots = deps.snapshots;
|
|
40
|
+
this.log = deps.log;
|
|
41
|
+
}
|
|
42
|
+
of(agent, session) {
|
|
43
|
+
return this.kv.get(`turns:${agent}:${session}`) ?? [];
|
|
44
|
+
}
|
|
45
|
+
undone(agent, session) {
|
|
46
|
+
return this.kv.get(`undone:${agent}:${session}`) ?? [];
|
|
47
|
+
}
|
|
48
|
+
save(agent, session, turn) {
|
|
49
|
+
const list = this.of(agent, session);
|
|
50
|
+
const i = list.findIndex((t) => t.task === turn.task);
|
|
51
|
+
if (i >= 0)
|
|
52
|
+
list[i] = turn;
|
|
53
|
+
else
|
|
54
|
+
list.push(turn);
|
|
55
|
+
this.kv.set(`turns:${agent}:${session}`, list.slice(-KEEP_TURNS));
|
|
56
|
+
}
|
|
57
|
+
/** The turn a task's work belongs to: that of the owner's message at the top of it, else the last one of its conversation. */
|
|
58
|
+
turnOf(task) {
|
|
59
|
+
// Sub-agents and tasks handed on are part of the work of the task at the top of them.
|
|
60
|
+
const top = task.meta.root === undefined || task.meta.root === task.id ? task : this.tasks.get(task.meta.root);
|
|
61
|
+
if (!top || top.meta.trust !== "owner" || top.parent !== undefined || top.session.startsWith("_t") || top.session.endsWith("~u"))
|
|
62
|
+
return undefined;
|
|
63
|
+
// The owner's message itself, or something that followed it in the conversation: an answer
|
|
64
|
+
// that came back later, an event, a schedule. Each is a step of its own in that turn.
|
|
65
|
+
const turn = ownerMessage(top) ? this.of(top.agent, top.session).find((t) => t.task === top.id) : this.of(top.agent, top.session).at(-1);
|
|
66
|
+
return turn && { agent: top.agent, session: top.session, turn, step: top.id };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A task is about to be worked on in a conversation. Whatever was taken back there is now final:
|
|
70
|
+
* the conversation goes on from where it stood, and a redo would put the old continuation over
|
|
71
|
+
* the new one. A message of the owner's begins a turn.
|
|
72
|
+
*/
|
|
73
|
+
starting(task, at) {
|
|
74
|
+
if (task.session.startsWith("_t"))
|
|
75
|
+
return;
|
|
76
|
+
if (this.undone(task.agent, task.session).length)
|
|
77
|
+
this.kv.set(`undone:${task.agent}:${task.session}`, null);
|
|
78
|
+
if (!ownerMessage(task))
|
|
79
|
+
return;
|
|
80
|
+
this.save(task.agent, task.session, { task: task.id, file: at.file && path.basename(at.file), leaf: at.leaf, root: at.root, steps: [], marks: at.marks });
|
|
81
|
+
this.remember(task.id, "before", at.rights);
|
|
82
|
+
}
|
|
83
|
+
remember(task, when, rights) {
|
|
84
|
+
this.rights.set(`${task}:${when}`, rights);
|
|
85
|
+
if (this.rights.size > 400)
|
|
86
|
+
for (const key of [...this.rights.keys()].slice(0, 200))
|
|
87
|
+
this.rights.delete(key);
|
|
88
|
+
}
|
|
89
|
+
recall(task, when) {
|
|
90
|
+
return this.rights.get(`${task}:${when}`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Before a tool call: the first one of a turn records the folder as it is. Until a tool runs
|
|
94
|
+
* nothing can have changed there, so a message that is only answered costs nothing.
|
|
95
|
+
*/
|
|
96
|
+
touching(task) {
|
|
97
|
+
let p = this.seen.get(task.id);
|
|
98
|
+
if (!p) {
|
|
99
|
+
// Never a reason for a tool call to fail.
|
|
100
|
+
p = this.record(task, "before").catch((e) => this.log.warn(`undo: task #${task.id}`, errText(e)));
|
|
101
|
+
this.seen.set(task.id, p);
|
|
102
|
+
if (this.seen.size > 500)
|
|
103
|
+
for (const id of [...this.seen.keys()].slice(0, 250))
|
|
104
|
+
this.seen.delete(id);
|
|
105
|
+
}
|
|
106
|
+
return p;
|
|
107
|
+
}
|
|
108
|
+
/** A task ended. If it ran tools, the folder as it is now is what its turn left behind. */
|
|
109
|
+
async ended(task, tools) {
|
|
110
|
+
this.seen.delete(task.id);
|
|
111
|
+
if (tools > 0)
|
|
112
|
+
await this.record(task, "after").catch((e) => this.log.warn(`undo: task #${task.id}`, errText(e)));
|
|
113
|
+
}
|
|
114
|
+
async record(task, which) {
|
|
115
|
+
const at = this.turnOf(task);
|
|
116
|
+
if (!at || at.turn.problem)
|
|
117
|
+
return;
|
|
118
|
+
const id = at.step;
|
|
119
|
+
const known = at.turn.steps.some((s) => s.task === id);
|
|
120
|
+
if (which === "before" ? known : !known)
|
|
121
|
+
return;
|
|
122
|
+
let snap;
|
|
123
|
+
let problem;
|
|
124
|
+
try {
|
|
125
|
+
snap = await this.snapshots.take(at.turn.root);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
problem = errText(e);
|
|
129
|
+
this.log.warn(`the folder ${at.turn.root} was not recorded ${which} task #${task.id}: undo will not restore files there`, problem);
|
|
130
|
+
}
|
|
131
|
+
// Read again: the turn may have been taken back, or written by another task, while git ran.
|
|
132
|
+
const turn = this.of(at.agent, at.session).find((t) => t.task === at.turn.task);
|
|
133
|
+
if (!turn)
|
|
134
|
+
return;
|
|
135
|
+
const step = turn.steps.find((s) => s.task === id);
|
|
136
|
+
if (snap && which === "before" && !step)
|
|
137
|
+
turn.steps.push({ task: id, before: snap });
|
|
138
|
+
else if (snap && step)
|
|
139
|
+
step.after = snap;
|
|
140
|
+
// Without a "before" there is nothing to go back to. A missed "after" only means the present is taken for it.
|
|
141
|
+
else if (!snap && which === "before")
|
|
142
|
+
turn.problem = problem;
|
|
143
|
+
this.save(at.agent, at.session, turn);
|
|
144
|
+
}
|
|
145
|
+
/** Take a turn out of the list (its message is being taken back). */
|
|
146
|
+
drop(agent, session, task) {
|
|
147
|
+
this.kv.set(`turns:${agent}:${session}`, this.of(agent, session).filter((t) => t.task !== task));
|
|
148
|
+
}
|
|
149
|
+
putBack(agent, session, turn) {
|
|
150
|
+
this.save(agent, session, turn);
|
|
151
|
+
this.kv.set(`turns:${agent}:${session}`, this.of(agent, session).sort((a, b) => a.task - b.task));
|
|
152
|
+
}
|
|
153
|
+
park(agent, session, rec) {
|
|
154
|
+
const list = [...this.undone(agent, session), rec].slice(-KEEP_UNDONE);
|
|
155
|
+
this.kv.set(`undone:${agent}:${session}`, list);
|
|
156
|
+
return list.length;
|
|
157
|
+
}
|
|
158
|
+
/** The message taken back last, taken off the list. */
|
|
159
|
+
unpark(agent, session) {
|
|
160
|
+
const list = this.undone(agent, session);
|
|
161
|
+
const rec = list.pop();
|
|
162
|
+
this.kv.set(`undone:${agent}:${session}`, list.length ? list : null);
|
|
163
|
+
return { rec, left: list.length };
|
|
164
|
+
}
|
|
165
|
+
/** A conversation was reset or removed: nothing of it can be taken back or brought back any more. */
|
|
166
|
+
forget(agent, session) {
|
|
167
|
+
this.kv.set(`turns:${agent}:${session}`, null);
|
|
168
|
+
this.kv.set(`undone:${agent}:${session}`, null);
|
|
169
|
+
}
|
|
170
|
+
rename(agent, from, to) {
|
|
171
|
+
const turns = this.kv.get(`turns:${agent}:${from}`);
|
|
172
|
+
const undone = this.kv.get(`undone:${agent}:${from}`);
|
|
173
|
+
this.forget(agent, from);
|
|
174
|
+
if (turns)
|
|
175
|
+
this.kv.set(`turns:${agent}:${to}`, turns);
|
|
176
|
+
// The tasks that wait for a redo go back into the list under the name the conversation has then.
|
|
177
|
+
for (const u of undone ?? [])
|
|
178
|
+
for (const row of u.rows)
|
|
179
|
+
if (row.agent === agent && row.session === from)
|
|
180
|
+
row.session = to;
|
|
181
|
+
if (undone)
|
|
182
|
+
this.kv.set(`undone:${agent}:${to}`, undone);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The files of a turn back to what they were before it. Only files the turn's work changed are
|
|
186
|
+
* set, and only where they are not like that already: what the owner changed elsewhere in the
|
|
187
|
+
* folder since stays. `started`: whether the message was worked on at all.
|
|
188
|
+
*/
|
|
189
|
+
async back(turn, started) {
|
|
190
|
+
if (!turn)
|
|
191
|
+
return started ? { note: "the folder was not recorded for this message, so no file was restored" } : {};
|
|
192
|
+
if (turn.problem)
|
|
193
|
+
return { note: `the folder was not recorded for this message (${turn.problem}), so no file was restored` };
|
|
194
|
+
// No tool ran: there is nothing the message could have changed.
|
|
195
|
+
if (!turn.steps.length)
|
|
196
|
+
return { restored: tally(turn.root, [], []) };
|
|
197
|
+
if (!fs.existsSync(turn.root))
|
|
198
|
+
return { note: `${turn.root} is not there any more, so no file was restored` };
|
|
199
|
+
let cur;
|
|
200
|
+
const files = new Map();
|
|
201
|
+
const paths = new Set();
|
|
202
|
+
const left = new Set();
|
|
203
|
+
try {
|
|
204
|
+
// The last step first, each back to its own beginning: a file two steps changed ends at the earlier one's.
|
|
205
|
+
for (const step of [...turn.steps].reverse()) {
|
|
206
|
+
// A step that was stopped just now has no "after": the present is it.
|
|
207
|
+
const after = step.after ?? (await this.snapshots.take(turn.root));
|
|
208
|
+
const done = await this.snapshots.restore(turn.root, step.before, { within: [step.before, after] });
|
|
209
|
+
cur ??= done.cur;
|
|
210
|
+
for (const f of done.files)
|
|
211
|
+
files.set(f.path, f);
|
|
212
|
+
for (const p of done.paths)
|
|
213
|
+
paths.add(p);
|
|
214
|
+
for (const p of done.left)
|
|
215
|
+
left.add(p);
|
|
216
|
+
}
|
|
217
|
+
return { restored: tally(turn.root, [...files.values()], [...left]), cur, paths: [...paths] };
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
this.log.warn(`undo: the files in ${turn.root} were not restored`, errText(e));
|
|
221
|
+
// What a step already set back can still be brought back by a redo.
|
|
222
|
+
return { note: `${files.size ? "not all files were restored" : "the files were not restored"}: ${errText(e)}`, cur, paths: [...paths] };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** The same files as the message had left them: a redo. */
|
|
226
|
+
async again(rec) {
|
|
227
|
+
const root = rec.turn?.root;
|
|
228
|
+
if (!root || !rec.cur)
|
|
229
|
+
return {};
|
|
230
|
+
if (!rec.paths?.length)
|
|
231
|
+
return { restored: tally(root, [], []) };
|
|
232
|
+
if (!fs.existsSync(root))
|
|
233
|
+
return { note: `${root} is not there any more, so no file was restored` };
|
|
234
|
+
try {
|
|
235
|
+
const done = await this.snapshots.restore(root, rec.cur, { only: rec.paths, avoid: (rec.turn?.steps ?? []).flatMap((s) => [s.before, ...(s.after ? [s.after] : [])]) });
|
|
236
|
+
return { restored: tally(root, done.files, done.left) };
|
|
237
|
+
}
|
|
238
|
+
catch (e) {
|
|
239
|
+
this.log.warn(`redo: the files in ${root} were not restored`, errText(e));
|
|
240
|
+
return { note: `the files were not restored: ${errText(e)}` };
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** The two states between which the last message of a conversation lies, if the folder was recorded. */
|
|
244
|
+
async span(agent, session, running) {
|
|
245
|
+
const turn = this.of(agent, session).at(-1);
|
|
246
|
+
const task = turn && this.tasks.get(turn.task);
|
|
247
|
+
if (!turn || !task)
|
|
248
|
+
return { head: { files: [], more: false, note: "No message of yours has been worked on in this conversation since pine keeps track of that. What the next one changes is listed here." } };
|
|
249
|
+
const head = { task: turn.task, prompt: typed(task.prompt).slice(0, 200), root: turn.root, files: [], more: false };
|
|
250
|
+
if (turn.problem)
|
|
251
|
+
return { head: { ...head, note: `The folder was not recorded for this message: ${turn.problem}.` } };
|
|
252
|
+
if (!turn.steps.length)
|
|
253
|
+
return { head };
|
|
254
|
+
const last = turn.steps.at(-1);
|
|
255
|
+
// While it is being worked on, what it has changed so far.
|
|
256
|
+
const to = running(last.task) || !last.after ? await this.snapshots.take(turn.root) : last.after;
|
|
257
|
+
return { head, turn, from: turn.steps[0].before, to };
|
|
258
|
+
}
|
|
259
|
+
/** What the last message of a conversation changed in its folder. `running`: whether a task is still being worked on. */
|
|
260
|
+
async view(agent, session, running) {
|
|
261
|
+
try {
|
|
262
|
+
const at = await this.span(agent, session, running);
|
|
263
|
+
if (!at.turn || !at.from || !at.to)
|
|
264
|
+
return at.head;
|
|
265
|
+
const files = await this.snapshots.changed(at.turn.root, at.from, at.to);
|
|
266
|
+
return { ...at.head, files: files.slice(0, 300), more: files.length > 300 };
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
return { files: [], more: false, note: errText(e) };
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/** The difference of one file over the last message. */
|
|
273
|
+
async viewDiff(agent, session, running, file) {
|
|
274
|
+
const at = await this.span(agent, session, running).catch(() => undefined);
|
|
275
|
+
return at?.turn && at.from && at.to ? this.snapshots.diff(at.turn.root, at.from, at.to, file) : undefined;
|
|
276
|
+
}
|
|
277
|
+
/** Every state that is still referred to, by folder: the rest can be dropped. */
|
|
278
|
+
kept() {
|
|
279
|
+
const out = new Map();
|
|
280
|
+
const add = (root, ...snaps) => {
|
|
281
|
+
if (!root)
|
|
282
|
+
return;
|
|
283
|
+
if (!out.has(root))
|
|
284
|
+
out.set(root, new Set());
|
|
285
|
+
for (const s of snaps)
|
|
286
|
+
if (s)
|
|
287
|
+
out.get(root).add(s.tree);
|
|
288
|
+
};
|
|
289
|
+
for (const key of this.kv.keys("turns:"))
|
|
290
|
+
for (const t of this.kv.get(key) ?? [])
|
|
291
|
+
add(t.root, ...t.steps.flatMap((s) => [s.before, s.after]));
|
|
292
|
+
for (const key of this.kv.keys("undone:"))
|
|
293
|
+
for (const u of this.kv.get(key) ?? [])
|
|
294
|
+
add(u.turn?.root, u.cur, ...(u.turn?.steps ?? []).flatMap((s) => [s.before, s.after]));
|
|
295
|
+
return out;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const NOTHING_TO_REDO = "there is nothing to bring back: /redo takes back the last /undo, until a new message is sent";
|
|
299
|
+
/**
|
|
300
|
+
* Take back the owner's last message in a conversation, with everything that followed it there.
|
|
301
|
+
* In this order: what runs is stopped; the session file is put back to before the message; the
|
|
302
|
+
* files go back; its tasks leave the task list, from which history is shown, and wait in private
|
|
303
|
+
* storage for a redo; the conversation's outside-content mark and what the owner allowed in it
|
|
304
|
+
* are again what they were before the message, because what gave rise to them is gone, as after
|
|
305
|
+
* a reset.
|
|
306
|
+
*/
|
|
307
|
+
export async function undoMessage(h, agentId, key) {
|
|
308
|
+
const mine = () => h.tasks.list({ agent: agentId, session: key, limit: 1000 });
|
|
309
|
+
const msg = mine().find(ownerMessage);
|
|
310
|
+
if (!msg)
|
|
311
|
+
throw new Error("there is no message of yours in this conversation to take back");
|
|
312
|
+
// One that still waits its turn has done nothing and is nowhere but in the list: it is withdrawn,
|
|
313
|
+
// without waiting for what runs before it, and there is nothing a redo could bring back.
|
|
314
|
+
if (msg.status === "pending") {
|
|
315
|
+
h.cancel(msg.id);
|
|
316
|
+
for (const t of h.tasks.take([msg.id]))
|
|
317
|
+
h.forgetTask(t.id);
|
|
318
|
+
h.log.info(`conversation ${agentId}:${key}: the owner withdrew message #${msg.id} before it was worked on`);
|
|
319
|
+
return { task: msg.id, prompt: typed(msg.prompt), stopped: 0, waiting: true, redo: h.turns.undone(agentId, key).length, more: mine().some(ownerMessage) };
|
|
320
|
+
}
|
|
321
|
+
// Its own run, what came after it in the conversation, and the work those started anywhere.
|
|
322
|
+
const later = new Set(mine().filter((t) => t.id >= msg.id).map((t) => t.id));
|
|
323
|
+
const active = [...h.tasks.byStatus("running"), ...h.tasks.byStatus("pending")].filter((t) => later.has(t.id) || later.has(t.meta.root ?? t.id));
|
|
324
|
+
for (const t of active)
|
|
325
|
+
h.cancel(t.id);
|
|
326
|
+
return h.quiet(agentId, key, async () => {
|
|
327
|
+
await Promise.all(active.map((t) => h.wait(t.id).catch(() => undefined)));
|
|
328
|
+
// Exactly what was there when the owner asked: a message sent since then waits behind this and is not part of it.
|
|
329
|
+
const rows = mine().filter((t) => later.has(t.id));
|
|
330
|
+
const now = rows.find((t) => t.id === msg.id);
|
|
331
|
+
if (!now)
|
|
332
|
+
throw new Error("that message was taken back already");
|
|
333
|
+
const perm = `${agentId}:${key}`;
|
|
334
|
+
const turn = h.turns.of(agentId, key).find((t) => t.task === msg.id);
|
|
335
|
+
const started = now.started !== undefined;
|
|
336
|
+
// The conversation first: if its file cannot be put back, nothing has been changed yet and the owner is told.
|
|
337
|
+
// Without a record of where it stood (a message from before pine kept one), it is looked for by its text.
|
|
338
|
+
const dir = path.join(h.cfg.agents[agentId].dir, "sessions", key);
|
|
339
|
+
const stood = started ? rewind(turn?.file ? path.join(dir, turn.file) : sessionFile(dir), turn ? turn.leaf : undefined, now.prompt, msg.id) : undefined;
|
|
340
|
+
const files = await h.turns.back(turn, started);
|
|
341
|
+
const taken = h.tasks.take(rows.map((t) => t.id));
|
|
342
|
+
for (const t of taken)
|
|
343
|
+
h.forgetTask(t.id);
|
|
344
|
+
const marks = { taint: h.kv.get(`taint:${perm}`) ?? undefined, keep: h.kv.get(`keep:${perm}`) === true };
|
|
345
|
+
h.turns.remember(msg.id, "after", h.rights(perm));
|
|
346
|
+
if (turn) {
|
|
347
|
+
h.turns.drop(agentId, key, msg.id);
|
|
348
|
+
h.kv.set(`taint:${perm}`, turn.marks.taint ?? null);
|
|
349
|
+
h.kv.set(`keep:${perm}`, turn.marks.keep ? true : null);
|
|
350
|
+
h.setRights(perm, h.turns.recall(msg.id, "before"));
|
|
351
|
+
}
|
|
352
|
+
const redo = h.turns.park(agentId, key, { task: msg.id, rows: taken, turn, file: stood && path.basename(stood.file), leaf: stood?.leaf, cur: files.cur, paths: files.paths, marks });
|
|
353
|
+
const stopped = active.filter((t) => t.status === "running").length;
|
|
354
|
+
h.log.info(`conversation ${perm}: the owner took back message #${msg.id}${stopped ? `, ${stopped} running task${stopped === 1 ? "" : "s"} stopped` : ""}${files.restored ? `, ${files.restored.changed + files.restored.removed + files.restored.back} files restored in ${files.restored.root}` : ""}${files.note ? ` (${files.note})` : ""}`);
|
|
355
|
+
h.bus.publish(`agent/${agentId}/undone`, { agent: agentId, session: key, message: msg.id, tasks: taken.length, files: files.restored ? files.restored.changed + files.restored.removed + files.restored.back : undefined }, { source: "pine" });
|
|
356
|
+
return { task: msg.id, prompt: typed(now.prompt), stopped, restored: files.restored, note: files.note, redo, more: mine().some(ownerMessage) };
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/** Bring back the message that was taken back last: its files, its place in the conversation, its tasks, and what was allowed. */
|
|
360
|
+
export async function redoMessage(h, agentId, key) {
|
|
361
|
+
const mine = () => h.tasks.list({ agent: agentId, session: key, limit: 1000 });
|
|
362
|
+
if (!h.turns.undone(agentId, key).length)
|
|
363
|
+
throw new Error(NOTHING_TO_REDO);
|
|
364
|
+
// A message that waits to be worked on makes the undo final the moment it starts; it already counts.
|
|
365
|
+
if (mine().some((t) => t.status === "pending" || t.status === "running"))
|
|
366
|
+
throw new Error("something new is being worked on in this conversation, so what was taken back stays taken back");
|
|
367
|
+
return h.quiet(agentId, key, async () => {
|
|
368
|
+
const { rec, left } = h.turns.unpark(agentId, key);
|
|
369
|
+
if (!rec)
|
|
370
|
+
throw new Error(NOTHING_TO_REDO);
|
|
371
|
+
const perm = `${agentId}:${key}`;
|
|
372
|
+
forward(rec.file && path.join(h.cfg.agents[agentId].dir, "sessions", key, rec.file), rec.leaf, rec.task);
|
|
373
|
+
const files = await h.turns.again(rec);
|
|
374
|
+
h.tasks.putBack(rec.rows);
|
|
375
|
+
if (rec.turn) {
|
|
376
|
+
h.turns.putBack(agentId, key, rec.turn);
|
|
377
|
+
h.kv.set(`taint:${perm}`, rec.marks.taint ?? null);
|
|
378
|
+
h.kv.set(`keep:${perm}`, rec.marks.keep ? true : null);
|
|
379
|
+
h.setRights(perm, h.turns.recall(rec.task, "after"));
|
|
380
|
+
}
|
|
381
|
+
const msg = rec.rows.find((t) => t.id === rec.task);
|
|
382
|
+
h.log.info(`conversation ${perm}: the owner brought back message #${rec.task}${files.restored ? `, ${files.restored.changed + files.restored.removed + files.restored.back} files restored in ${files.restored.root}` : ""}${files.note ? ` (${files.note})` : ""}`);
|
|
383
|
+
h.bus.publish(`agent/${agentId}/redone`, { agent: agentId, session: key, message: rec.task, tasks: rec.rows.length, files: files.restored ? files.restored.changed + files.restored.removed + files.restored.back : undefined }, { source: "pine" });
|
|
384
|
+
return { task: rec.task, prompt: typed(msg?.prompt ?? ""), stopped: 0, restored: files.restored, note: files.note, redo: left, more: mine().some(ownerMessage) };
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
// ---- pi's session file ---------------------------------------------------------------------------
|
|
388
|
+
// A session is a tree of entries in one file, and the conversation is the path from its newest
|
|
389
|
+
// entry to the root. pi can go back to an earlier entry (`branch`), but only in memory: a session
|
|
390
|
+
// opened from the file stands at the last entry written. So going back is made to last by
|
|
391
|
+
// writing an entry there: one of pine's own, which is no message and is not sent to the model.
|
|
392
|
+
// The entries that were left stay in the file as a branch nobody stands on, which is what lets a
|
|
393
|
+
// redo return to them. The session must not be open while this is done.
|
|
394
|
+
/**
|
|
395
|
+
* The lines of a session file that are the conversation as it stands: the entries on the way
|
|
396
|
+
* from the newest one to the first. In a file in which nothing was taken back that is all of them.
|
|
397
|
+
*/
|
|
398
|
+
export function onBranch(lines) {
|
|
399
|
+
const entries = lines.map((line) => {
|
|
400
|
+
try {
|
|
401
|
+
const e = JSON.parse(line);
|
|
402
|
+
return e && typeof e.id === "string" && e.type !== "session" ? e : undefined;
|
|
403
|
+
}
|
|
404
|
+
catch {
|
|
405
|
+
return undefined;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
const byId = new Map(entries.filter(Boolean).map((e) => [e.id, e]));
|
|
409
|
+
const kept = new Set();
|
|
410
|
+
for (let at = entries.findLast(Boolean); at && !kept.has(at.id); at = at.parentId ? byId.get(at.parentId) : undefined)
|
|
411
|
+
kept.add(at.id);
|
|
412
|
+
return lines.filter((_, i) => !entries[i] || kept.has(entries[i].id));
|
|
413
|
+
}
|
|
414
|
+
/** The newest session file of a conversation, as pi would continue it. */
|
|
415
|
+
export function sessionFile(dir) {
|
|
416
|
+
try {
|
|
417
|
+
const newest = fs.readdirSync(dir).filter((f) => f.endsWith(".jsonl")).sort().at(-1);
|
|
418
|
+
return newest && path.join(dir, newest);
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
return undefined;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Put a conversation back to before a message. `leaf` is where it stood then, when that is known;
|
|
426
|
+
* otherwise the message is looked for by its text. Returns where it stood until now, or undefined
|
|
427
|
+
* when the file holds nothing of that message (it was never worked on).
|
|
428
|
+
*/
|
|
429
|
+
export function rewind(file, leaf, prompt, task) {
|
|
430
|
+
if (!file || !fs.existsSync(file))
|
|
431
|
+
return undefined;
|
|
432
|
+
const sm = SessionManager.open(file);
|
|
433
|
+
const from = sm.getLeafId();
|
|
434
|
+
let to = leaf;
|
|
435
|
+
if (to === undefined) {
|
|
436
|
+
const needle = prompt.slice(0, 200);
|
|
437
|
+
const said = sm.getBranch().filter((e) => e.type === "message" && e.message?.role === "user" && textOf(e.message.content).includes(needle)).at(-1);
|
|
438
|
+
if (!said)
|
|
439
|
+
return undefined;
|
|
440
|
+
to = said.parentId ?? null;
|
|
441
|
+
}
|
|
442
|
+
if (to !== null && !sm.getEntry(to))
|
|
443
|
+
return undefined;
|
|
444
|
+
// Already there: the message was queued behind this point and never reached the file.
|
|
445
|
+
if (to === from)
|
|
446
|
+
return undefined;
|
|
447
|
+
if (to === null)
|
|
448
|
+
sm.resetLeaf();
|
|
449
|
+
else
|
|
450
|
+
sm.branch(to);
|
|
451
|
+
sm.appendCustomEntry("pine-undo", { task });
|
|
452
|
+
return { file, leaf: from };
|
|
453
|
+
}
|
|
454
|
+
/** Put a conversation back to where it stood before `rewind`. */
|
|
455
|
+
export function forward(file, leaf, task) {
|
|
456
|
+
if (!file || !leaf || !fs.existsSync(file))
|
|
457
|
+
return false;
|
|
458
|
+
const sm = SessionManager.open(file);
|
|
459
|
+
if (!sm.getEntry(leaf))
|
|
460
|
+
return false;
|
|
461
|
+
sm.branch(leaf);
|
|
462
|
+
sm.appendCustomEntry("pine-redo", { task });
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
const textOf = (content) => (typeof content === "string" ? content : Array.isArray(content) ? content.filter((x) => x?.type === "text").map((x) => x.text).join("\n") : "");
|
package/src/update.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How this copy of pine got here.
|
|
3
|
+
* checkout: a git clone, which runs the sources directly. It is updated with git.
|
|
4
|
+
* global: installed with "npm install -g". It is updated with npm.
|
|
5
|
+
* local: a dependency inside some project's node_modules. That project decides its version.
|
|
6
|
+
*/
|
|
7
|
+
export type InstallKind = "checkout" | "global" | "local";
|
|
8
|
+
export declare function installKind(root: string, globalRoot?: string): InstallKind;
|
|
9
|
+
/** Whether version a is higher than version b ("1.10.0" is higher than "1.9.3"). */
|
|
10
|
+
export declare function newer(a: string, b: string): boolean;
|
|
11
|
+
export declare function installed(root?: string): {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
kind: InstallKind;
|
|
15
|
+
root: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* What to say after an update, and whether it worked: the version on disk has to be the one
|
|
19
|
+
* that was asked for. npm can say that a version exists and still install an older one for a
|
|
20
|
+
* few minutes after it was published (its two answers come from different places), and
|
|
21
|
+
* "pine is now <the old version>" must not read like success.
|
|
22
|
+
*/
|
|
23
|
+
export declare function outcome(name: string, wanted: string | undefined, now: string): {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
text: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Update pine, or with `check` only say whether there is something newer. Returns the exit code.
|
|
29
|
+
* `browser` fetches the browser build of the version that is on disk afterwards.
|
|
30
|
+
*/
|
|
31
|
+
export declare function update(opts: {
|
|
32
|
+
check: boolean;
|
|
33
|
+
out: (line: string) => void;
|
|
34
|
+
browser: boolean;
|
|
35
|
+
}): Promise<number>;
|
package/src/update.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { PINE_ROOT } from "./config.js";
|
|
5
|
+
const real = (p) => {
|
|
6
|
+
try {
|
|
7
|
+
return fs.realpathSync(p);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return path.resolve(p);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export function installKind(root, globalRoot) {
|
|
14
|
+
if (fs.existsSync(path.join(root, ".git")) && fs.existsSync(path.join(root, "src", "cli.ts")))
|
|
15
|
+
return "checkout";
|
|
16
|
+
if (globalRoot && (real(root) + path.sep).startsWith(real(globalRoot) + path.sep))
|
|
17
|
+
return "global";
|
|
18
|
+
return "local";
|
|
19
|
+
}
|
|
20
|
+
/** Whether version a is higher than version b ("1.10.0" is higher than "1.9.3"). */
|
|
21
|
+
export function newer(a, b) {
|
|
22
|
+
const parse = (v) => v.split("-")[0].split(".").map((n) => Number(n) || 0);
|
|
23
|
+
const [x, y] = [parse(a), parse(b)];
|
|
24
|
+
for (let i = 0; i < 3; i++)
|
|
25
|
+
if ((x[i] ?? 0) !== (y[i] ?? 0))
|
|
26
|
+
return (x[i] ?? 0) > (y[i] ?? 0);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
export function installed(root = PINE_ROOT) {
|
|
30
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
31
|
+
const globalRoot = capture("npm", ["root", "-g"]);
|
|
32
|
+
return { name: pkg.name, version: pkg.version, kind: installKind(root, globalRoot), root };
|
|
33
|
+
}
|
|
34
|
+
function capture(cmd, args, cwd) {
|
|
35
|
+
const r = spawnSync(cmd, args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
36
|
+
return r.status === 0 ? r.stdout.trim() : undefined;
|
|
37
|
+
}
|
|
38
|
+
const show = (cmd, args, cwd) => spawnSync(cmd, args, { cwd, stdio: "inherit" }).status ?? 1;
|
|
39
|
+
const RESTART = "A pine that is running keeps the old version until it is restarted: quit the terminal UI and open it again, or restart the daemon.";
|
|
40
|
+
/**
|
|
41
|
+
* What to say after an update, and whether it worked: the version on disk has to be the one
|
|
42
|
+
* that was asked for. npm can say that a version exists and still install an older one for a
|
|
43
|
+
* few minutes after it was published (its two answers come from different places), and
|
|
44
|
+
* "pine is now <the old version>" must not read like success.
|
|
45
|
+
*/
|
|
46
|
+
export function outcome(name, wanted, now) {
|
|
47
|
+
if (wanted && newer(wanted, now)) {
|
|
48
|
+
return { ok: false, text: `\nNot updated: pine is still ${now}. npm knows ${wanted} but did not install it; that happens for a few minutes after a version is published. Run "pine update" again in a moment, or install it by its number:\n\n npm install -g ${name}@${wanted}` };
|
|
49
|
+
}
|
|
50
|
+
return { ok: true, text: `\npine is now ${now}. ${RESTART}` };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Update pine, or with `check` only say whether there is something newer. Returns the exit code.
|
|
54
|
+
* `browser` fetches the browser build of the version that is on disk afterwards.
|
|
55
|
+
*/
|
|
56
|
+
export async function update(opts) {
|
|
57
|
+
const { out } = opts;
|
|
58
|
+
const me = installed();
|
|
59
|
+
let wanted;
|
|
60
|
+
if (me.kind === "checkout") {
|
|
61
|
+
const branch = capture("git", ["rev-parse", "--abbrev-ref", "HEAD"], me.root) ?? "?";
|
|
62
|
+
if (!capture("git", ["rev-parse", "--abbrev-ref", "@{u}"], me.root)) {
|
|
63
|
+
out(`This is a checkout in ${me.root}, and its branch ${branch} does not follow one on a server, so there is nothing to update from. Set that up with git, or pull by hand.`);
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
if (spawnSync("git", ["fetch", "--quiet"], { cwd: me.root, stdio: "inherit" }).status !== 0) {
|
|
67
|
+
out("Could not reach the repository this checkout follows.");
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
const behind = Number(capture("git", ["rev-list", "--count", "HEAD..@{u}"], me.root) ?? 0);
|
|
71
|
+
if (!behind) {
|
|
72
|
+
out(`pine ${me.version} (checkout in ${me.root}, branch ${branch}) is up to date.`);
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
if (opts.check) {
|
|
76
|
+
out(`${behind} new commit${behind === 1 ? "" : "s"} for this checkout (${me.root}, branch ${branch}). Run "pine update" to get ${behind === 1 ? "it" : "them"}.`);
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
out(`Getting ${behind} new commit${behind === 1 ? "" : "s"} ...`);
|
|
80
|
+
// Only ever a fast-forward: your own commits and changes are never rewritten or thrown away.
|
|
81
|
+
if (show("git", ["pull", "--ff-only"], me.root) !== 0) {
|
|
82
|
+
out("git could not simply move this checkout forward (you have commits or changes of your own in the way). Nothing was changed; sort it out with git and run pine update again.");
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
out("Installing what the new version depends on ...");
|
|
86
|
+
if (show("npm", ["install", "--no-audit", "--no-fund"], me.root) !== 0)
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const latest = capture("npm", ["view", me.name, "version"]);
|
|
91
|
+
if (!latest) {
|
|
92
|
+
out(`Could not ask npm for the latest version of ${me.name}. You may be offline.`);
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
if (!newer(latest, me.version)) {
|
|
96
|
+
out(`pine ${me.version} is the latest version.`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
if (me.kind === "local") {
|
|
100
|
+
out(`pine ${latest} is available (this is ${me.version}). This copy is a dependency of the project it is installed in (${me.root}); update it there:\n\n npm install ${me.name}@latest`);
|
|
101
|
+
return opts.check ? 0 : 1;
|
|
102
|
+
}
|
|
103
|
+
if (opts.check) {
|
|
104
|
+
out(`pine ${latest} is available (this is ${me.version}). Run "pine update" to install it.`);
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
out(`Updating pine ${me.version} to ${latest} ...`);
|
|
108
|
+
wanted = latest;
|
|
109
|
+
// By its number, not as "latest": npm then installs this version or says that it cannot.
|
|
110
|
+
if (show("npm", ["install", "-g", `${me.name}@${latest}`, "--no-audit", "--no-fund"]) !== 0) {
|
|
111
|
+
out(`npm could not install ${latest}. Right after a version is published that can take a few minutes: run "pine update" again in a moment. To see why, run it yourself:\n\n npm install -g ${me.name}@${latest}`);
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// The version on disk decides whether it worked, not what npm said it would do.
|
|
116
|
+
const done = outcome(me.name, wanted, installed(me.root).version);
|
|
117
|
+
if (!done.ok) {
|
|
118
|
+
out(done.text);
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
// The browser build has to match the new version, so the new version's own installer fetches it.
|
|
122
|
+
if (opts.browser) {
|
|
123
|
+
out("Making sure the browser the web tools drive matches ...");
|
|
124
|
+
const status = show(process.execPath, [path.join(me.root, "bin", "pine.js"), "browser-install"]);
|
|
125
|
+
if (status !== 0)
|
|
126
|
+
out(`The browser could not be fetched (exit ${status}). Run "pine browser-install" when you are online.`);
|
|
127
|
+
}
|
|
128
|
+
out(done.text);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|