@nathanstephenson/flow 0.1.9 → 0.1.10-beta.10
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/README.md +60 -21
- package/build/backend-worker-chunks/chunk-3KDHJA5P.mjs +162 -0
- package/build/backend-worker-chunks/{chunk-UQDH2COY.mjs → chunk-K774KOGL.mjs} +2 -7
- package/build/backend-worker-chunks/chunk-LAEUXDNH.mjs +130 -0
- package/build/backend-worker-chunks/{chunk-MLOUI3ZM.mjs → chunk-NZZME2I3.mjs} +6 -1
- package/build/backend-worker-chunks/claude-JG2FXYBQ.mjs +35859 -0
- package/build/backend-worker-chunks/{pi-M4OA2FGL.mjs → pi-KJSP23AO.mjs} +2138 -93
- package/build/backend-worker.mjs +77 -123
- package/build/workflow-runtime.cjs +12 -12
- package/dist/backend/claude/background-calls.js +7 -3
- package/dist/backend/claude/import.js +415 -0
- package/dist/backend/claude/index.js +201 -21
- package/dist/backend/claude/session-tools.js +14 -0
- package/dist/backend/claude/subagents.js +41 -9
- package/dist/backend/claude/todo-list.js +114 -0
- package/dist/backend/claude/workflow-parent.js +1 -1
- package/dist/backend/diff-excerpt-instructions.js +8 -0
- package/dist/backend/fake/index.js +54 -6
- package/dist/backend/mcp.js +4 -1
- package/dist/backend/pi/agent-permissions.js +1 -1
- package/dist/backend/pi/cache-warming.js +8 -0
- package/dist/backend/pi/canonical-json.js +120 -0
- package/dist/backend/pi/compaction-model.js +3 -2
- package/dist/backend/pi/host-auth.js +258 -0
- package/dist/backend/pi/import.js +269 -0
- package/dist/backend/pi/index.js +125 -21
- package/dist/backend/pi/model-auth.js +159 -0
- package/dist/backend/pi/model-catalog.js +120 -0
- package/dist/backend/pi/model-config.js +5 -0
- package/dist/backend/pi/model-selection.js +32 -0
- package/dist/backend/pi/plan-limits.js +41 -0
- package/dist/backend/pi/session-tools.js +21 -0
- package/dist/backend/pi/state.js +19 -1
- package/dist/backend/pi/subagents.js +7 -3
- package/dist/backend/pi/todo-list.js +23 -0
- package/dist/backend/pi/work.js +9 -1
- package/dist/backend/pi/workflow-parent.js +1 -1
- package/dist/backend/pi/workflow-subagent.js +4 -3
- package/dist/backend/plan-limits.js +17 -0
- package/dist/backend/session-tools.js +27 -0
- package/dist/backend/worker/claude-state.js +48 -0
- package/dist/backend/worker/entry.js +49 -8
- package/dist/backend/worker/index.js +155 -17
- package/dist/backend/worker/launcher.js +11 -4
- package/dist/backend/worker/protocol.js +2 -1
- package/dist/backend/worker/rpc.js +13 -0
- package/dist/backend/worker/sandbox-mcp.js +18 -7
- package/dist/backend/workflow-tools.js +9 -6
- package/dist/build-id +1 -1
- package/dist/cli/application.js +48 -42
- package/dist/cli/bootstrap.js +2 -2
- package/dist/cli/host-control.js +1 -1
- package/dist/cli/install-guard.js +2 -2
- package/dist/cli/main.js +4 -4
- package/dist/cli/systemd-update.js +3 -3
- package/dist/cli/update.js +6 -6
- package/dist/cli/web-update.js +6 -6
- package/dist/client/connection.js +46 -0
- package/dist/client/context-usage.js +3 -4
- package/dist/client/diff.js +40 -0
- package/dist/client/enquiry.js +0 -6
- package/dist/client/markdown.js +3 -2
- package/dist/client/model-choices.js +1 -1
- package/dist/client/permission.js +1 -2
- package/dist/client/project-name.js +3 -1
- package/dist/client/reduce.js +77 -3
- package/dist/client/relative-time.js +1 -1
- package/dist/client/scope-kind.js +6 -3
- package/dist/client/search.js +1 -1
- package/dist/client/status.js +1 -1
- package/dist/client/subagent-tree.js +49 -0
- package/dist/client/tool-chains.js +1 -1
- package/dist/client/tool-summary.js +28 -18
- package/dist/daemon/changes.js +128 -0
- package/dist/daemon/commit.js +84 -0
- package/dist/daemon/config-store.js +8 -3
- package/dist/daemon/config.js +105 -4
- package/dist/daemon/diff-excerpts.js +52 -0
- package/dist/daemon/git-state.js +197 -0
- package/dist/daemon/git.js +53 -10
- package/dist/daemon/github-image.js +18 -0
- package/dist/daemon/github.js +54 -0
- package/dist/daemon/host-control-routes.js +1 -1
- package/dist/daemon/host.js +1010 -116
- package/dist/daemon/http.js +4 -1
- package/dist/daemon/log.js +3 -0
- package/dist/daemon/mcp-auth.js +1 -1
- package/dist/daemon/models.js +2 -2
- package/dist/daemon/pi-model-cache.js +44 -0
- package/dist/daemon/pull-request.js +223 -138
- package/dist/daemon/push.js +43 -0
- package/dist/daemon/repository.js +123 -0
- package/dist/daemon/runtime.js +103 -22
- package/dist/daemon/secret-store.js +1 -1
- package/dist/daemon/server.js +111 -14
- package/dist/daemon/session-tool-views.js +22 -0
- package/dist/daemon/skills.js +24 -0
- package/dist/daemon/spend-ledger.js +118 -0
- package/dist/daemon/stack-metadata.js +12 -5
- package/dist/daemon/stack.js +162 -657
- package/dist/daemon/store.js +2 -0
- package/dist/daemon/summariser.js +30 -12
- package/dist/daemon/tour.js +56 -0
- package/dist/daemon/whisper.js +144 -0
- package/dist/daemon/workflow-authoring-scope-checks.js +1 -1
- package/dist/daemon/workflow-authoring-scope.js +1 -1
- package/dist/daemon/workflow-builder-files.js +2 -2
- package/dist/daemon/workflow-builder-guidance.js +1 -1
- package/dist/daemon/workflow-builder-routes.js +2 -2
- package/dist/daemon/workflow-builder.js +44 -17
- package/dist/daemon/workflow-environment.js +193 -0
- package/dist/daemon/workflow-execution-launch.js +77 -0
- package/dist/daemon/workflow-execution-resources.js +76 -0
- package/dist/daemon/workflow-execution-routes.js +17 -8
- package/dist/daemon/workflow-execution-values.js +128 -0
- package/dist/daemon/workflow-executions.js +434 -305
- package/dist/daemon/workflow-mcp-authoring-routes.js +2 -2
- package/dist/daemon/workflow-mcp-authoring.js +4 -4
- package/dist/daemon/workflow-mcp.js +1 -1
- package/dist/daemon/workflow-routes.js +60 -2
- package/dist/daemon/workflow-schedule-driver.js +251 -0
- package/dist/daemon/workflow-schedule-routes.js +137 -0
- package/dist/daemon/workflow-schedules.js +342 -0
- package/dist/isolation/filesystem.js +6 -2
- package/dist/isolation/sandbox.js +61 -18
- package/dist/isolation/shared-sandbox.js +3 -3
- package/dist/isolation/toolchain-assets.js +1 -1
- package/dist/protocol/events.js +3 -0
- package/dist/protocol/plan-limits.js +1 -0
- package/dist/protocol/settings.js +1 -0
- package/dist/protocol/spend.js +2 -0
- package/dist/protocol/stack.js +12 -39
- package/dist/protocol/workflow-schedules.js +1 -0
- package/dist/workflows/calls.js +53 -0
- package/dist/workflows/errors.js +2 -0
- package/dist/workflows/executors.js +6 -5
- package/dist/workflows/graph.js +83 -9
- package/dist/workflows/invocations.js +23 -0
- package/dist/workflows/mcp.js +1 -1
- package/dist/workflows/owner.js +45 -0
- package/dist/workflows/records.js +150 -10
- package/dist/workflows/recovery.js +87 -2
- package/dist/workflows/runtime-settings.js +16 -16
- package/dist/workflows/runtime.js +2 -2
- package/dist/workflows/schedule-errors.js +2 -0
- package/dist/workflows/schedule-store.js +385 -0
- package/dist/workflows/scheduler.js +389 -98
- package/dist/workflows/schedules.js +130 -0
- package/dist/workflows/schema.js +3 -1
- package/dist/workflows/store.js +126 -13
- package/package.json +10 -6
- package/web/dist/assets/index-C76t-z4w.css +2 -0
- package/web/dist/assets/{index-DRfeO6GJ.js → index-WPfbYVQ4.js} +39 -23
- package/web/dist/assets/{switch-DIogWclb.js → select-C5Ly2OpB.js} +1 -1
- package/web/dist/assets/{settings-mcp-Clp_jMWW.js → settings-mcp-BF-yqpeQ.js} +1 -1
- package/web/dist/assets/{settings-secrets-BIO_hXZ1.js → settings-secrets-WLarr2QP.js} +1 -1
- package/web/dist/assets/settings-workflows-DdcdRWFD.js +23 -0
- package/web/dist/assets/workflow-api-GjAmHc22.js +6 -0
- package/web/dist/assets/workflows-BhY3Uibo.js +149 -0
- package/web/dist/assets/workflows-pane-DElCcEpN.js +1 -0
- package/web/dist/index.html +6 -5
- package/build/backend-worker-chunks/chunk-J2DBNTL7.mjs +0 -94
- package/build/backend-worker-chunks/claude-GTW5KHY5.mjs +0 -30778
- package/dist/daemon/publish.js +0 -289
- package/dist/tui/app.js +0 -612
- package/dist/tui/keys.js +0 -90
- package/dist/tui/render.js +0 -411
- package/web/dist/assets/index-DgQFpKbn.css +0 -2
- package/web/dist/assets/settings-workflows-H-6eCff3.js +0 -23
- package/web/dist/assets/workflow-api-BfExddae.js +0 -6
- package/web/dist/assets/workflow-editors-CsbVx4WJ.js +0 -139
- package/web/dist/assets/workflows-Bv0sj7d0.js +0 -7
- package/web/dist/assets/workflows-pane-DHm44w7P.js +0 -1
- /package/dist/protocol/{publish.js → imports.js} +0 -0
package/dist/cli/application.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import { getHostStatus, launchBackground, requestHostStop, requireRestartable, waitUntil } from
|
|
4
|
-
import { readHost, oidcFingerprint } from
|
|
5
|
-
import { startRuntime } from
|
|
3
|
+
import { getHostStatus, launchBackground, requestHostStop, requireRestartable, waitUntil } from './host-control.js';
|
|
4
|
+
import { readHost, oidcFingerprint } from '../daemon/ownership.js';
|
|
5
|
+
import { startRuntime } from '../daemon/runtime.js';
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
|
-
import {
|
|
8
|
-
import { embeddedWorkflowRuntime } from "../workflows/runtime-asset.js";
|
|
7
|
+
import { embeddedWorkflowRuntime } from '../workflows/runtime-asset.js';
|
|
9
8
|
import { fileURLToPath } from 'node:url';
|
|
10
9
|
import { getAsset, isSea } from 'node:sea';
|
|
11
10
|
import { EMBEDDED } from "../web/embedded.js";
|
|
@@ -15,20 +14,19 @@ import { connect } from "../client/connection.js";
|
|
|
15
14
|
import { answerLines } from "../client/enquiry.js";
|
|
16
15
|
import { authorisationLabel } from "../client/permission.js";
|
|
17
16
|
import { initialState, reduce } from "../client/reduce.js";
|
|
18
|
-
import {
|
|
19
|
-
import { updateUnsupportedReason } from "./install-guard.js";
|
|
17
|
+
import { updateUnsupportedReason } from './install-guard.js';
|
|
20
18
|
let webUpdateSupport;
|
|
21
19
|
const USAGE = `usage:
|
|
22
20
|
flow --version print the installed version
|
|
23
21
|
flow update [--force] update a private global npm installation
|
|
24
|
-
flow tui [--scope DIR] [--backend claude|pi|fake] interactive terminal client
|
|
25
22
|
flow serve [--port N] [--address HOST] run the Session Host in the foreground
|
|
26
23
|
flow serve start|status|stop|restart [--force] control a background Session Host
|
|
27
24
|
flow list list Agent Sessions
|
|
25
|
+
flow import [--backend B] [--scope DIR] list a backend's own conversations to import
|
|
26
|
+
flow import ID [--backend B] [--scope DIR] [--view] import one; --view makes it read-only
|
|
28
27
|
flow [--session ID] [--scope DIR] [--backend B] [--model M] [--effort L] "<prompt>"
|
|
29
28
|
one prompt, then exit
|
|
30
29
|
|
|
31
|
-
tui without --scope uses the Project Root from config.json, else this directory.
|
|
32
30
|
A one-shot prompt always uses this directory unless --scope names another.`;
|
|
33
31
|
function installedVersion() {
|
|
34
32
|
return JSON.parse(isSea() ? getAsset('package.json', 'utf8') : readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
|
|
@@ -69,6 +67,7 @@ async function main() {
|
|
|
69
67
|
help: { type: "boolean", default: false },
|
|
70
68
|
version: { type: "boolean", default: false },
|
|
71
69
|
force: { type: 'boolean', default: false },
|
|
70
|
+
view: { type: 'boolean', default: false },
|
|
72
71
|
'background-host': { type: 'boolean', default: false },
|
|
73
72
|
},
|
|
74
73
|
});
|
|
@@ -108,20 +107,6 @@ async function main() {
|
|
|
108
107
|
await stop();
|
|
109
108
|
return 0;
|
|
110
109
|
}
|
|
111
|
-
if (command === "tui") {
|
|
112
|
-
const { connection, stop } = await clientConnection();
|
|
113
|
-
try {
|
|
114
|
-
await runTui({
|
|
115
|
-
connection,
|
|
116
|
-
scope: values.scope ?? configuredScope() ?? process.cwd(),
|
|
117
|
-
...(values.backend === undefined ? {} : { backend: values.backend }),
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
await stop();
|
|
122
|
-
}
|
|
123
|
-
return 0;
|
|
124
|
-
}
|
|
125
110
|
if (command === "list") {
|
|
126
111
|
const { connection, stop } = await clientConnection();
|
|
127
112
|
try {
|
|
@@ -134,6 +119,11 @@ async function main() {
|
|
|
134
119
|
}
|
|
135
120
|
return 0;
|
|
136
121
|
}
|
|
122
|
+
if (command === "import") {
|
|
123
|
+
if (positionals.length > 2)
|
|
124
|
+
throw new Error(`Unexpected import arguments: ${positionals.slice(2).join(' ')}`);
|
|
125
|
+
return await importConversation(positionals[1], values);
|
|
126
|
+
}
|
|
137
127
|
const prompt = positionals.join(" ").trim();
|
|
138
128
|
if (!prompt) {
|
|
139
129
|
console.log(USAGE);
|
|
@@ -141,21 +131,6 @@ async function main() {
|
|
|
141
131
|
}
|
|
142
132
|
return await oneShot(prompt, values);
|
|
143
133
|
}
|
|
144
|
-
/**
|
|
145
|
-
* The Project Root, for a client that named no Scope.
|
|
146
|
-
*
|
|
147
|
-
* Read straight off disk rather than asked of the daemon, because the TUI may be talking to one it
|
|
148
|
-
* did not start, and `/api/config`'s `scope` falls back to *that process's* working directory —
|
|
149
|
-
* which is not this reader's. Only the configured root is a safe answer to borrow; the fallback to
|
|
150
|
-
* `process.cwd()` has to happen here, where the cwd is the right one.
|
|
151
|
-
*
|
|
152
|
-
* A one-time read rather than a read-through, and that does not contradict ADR 0009: an Agent
|
|
153
|
-
* Session's Scope is fixed for its whole life, so this value is consumed the moment it is asked for
|
|
154
|
-
* and there is no later one for it to go stale against.
|
|
155
|
-
*/
|
|
156
|
-
function configuredScope() {
|
|
157
|
-
return new ConfigStore().projectRoot();
|
|
158
|
-
}
|
|
159
134
|
/** Build a Session Host with every Backend Adapter registered and prior sessions loaded. */
|
|
160
135
|
const LOOPBACK = "127.0.0.1";
|
|
161
136
|
async function startHost(port, address, mode = 'embedded') {
|
|
@@ -200,6 +175,37 @@ async function clientConnection() {
|
|
|
200
175
|
const { daemon, stop } = await startHost();
|
|
201
176
|
return { connection: connect(daemon), stop };
|
|
202
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* List the conversations a backend's own tool recorded in a Scope, or import one of them (ADR 0047).
|
|
180
|
+
*
|
|
181
|
+
* The Scope defaults to this directory, as a one-shot prompt's does, and not to the Project Root:
|
|
182
|
+
* Claude Code and pi key their conversations by the directory they were started in, so the directory
|
|
183
|
+
* somebody is standing in is the one whose conversations they mean.
|
|
184
|
+
*/
|
|
185
|
+
async function importConversation(id, values) {
|
|
186
|
+
const backend = values.backend === undefined ? {} : { backend: values.backend };
|
|
187
|
+
const scope = resolve(values.scope ?? process.cwd());
|
|
188
|
+
const { connection, stop } = await clientConnection();
|
|
189
|
+
try {
|
|
190
|
+
if (id === undefined) {
|
|
191
|
+
const conversations = await connection.command({ type: "list_imports", ...backend, scope });
|
|
192
|
+
if (conversations.length === 0)
|
|
193
|
+
console.log(`no conversations to import in ${scope}`);
|
|
194
|
+
for (const conversation of conversations) {
|
|
195
|
+
const imported = conversation.importedAs ? ` (imported as ${conversation.importedAs})` : "";
|
|
196
|
+
console.log(`${conversation.id} ${conversation.updatedAt.slice(0, 10)} ${String(conversation.prompts).padStart(3)} prompts ${conversation.title}${imported}`);
|
|
197
|
+
}
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
const mode = values.view ? "view" : "continue";
|
|
201
|
+
const sessionId = await connection.command({ type: "import", ...backend, scope, conversationId: id, mode });
|
|
202
|
+
console.log(mode === "view" ? `session ${sessionId} (read-only)` : `session ${sessionId}\n continue with: --session ${sessionId}`);
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
await stop();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
203
209
|
async function oneShot(prompt, values) {
|
|
204
210
|
const effort = effortLevel(values.effort);
|
|
205
211
|
const { daemon, stop } = await startHost();
|
|
@@ -236,11 +242,11 @@ async function oneShot(prompt, values) {
|
|
|
236
242
|
* worst of the three things that could happen, because it looks like a slow model rather
|
|
237
243
|
* than like a question. Aborting ends the turn, which prints the `aborted` row below and
|
|
238
244
|
* gets the transcript written; the Agent Session is left Dormant like any other, so `--session`
|
|
239
|
-
* can pick it up in the
|
|
245
|
+
* can pick it up in the web client, where it *can* be answered.
|
|
240
246
|
*/
|
|
241
247
|
if (entry.event.type === "enquiry" && entry.event.state === "asked") {
|
|
242
248
|
console.log(" ? the model asked a question, and this runner has no way to answer it");
|
|
243
|
-
console.log(` ? resume with: --session ${sessionId} (or open it in the
|
|
249
|
+
console.log(` ? resume with: --session ${sessionId} (or open it in the web UI)`);
|
|
244
250
|
void connection.command({ type: "abort", sessionId });
|
|
245
251
|
}
|
|
246
252
|
/*
|
|
@@ -267,7 +273,7 @@ async function oneShot(prompt, values) {
|
|
|
267
273
|
const { tool, callId } = state.authorising;
|
|
268
274
|
refused = callId;
|
|
269
275
|
console.log(` ! ${tool} needs authorising, and this runner has no way to ask; refusing it`);
|
|
270
|
-
console.log(` ! authorise it with: --session ${sessionId} (or open it in the
|
|
276
|
+
console.log(` ! authorise it with: --session ${sessionId} (or open it in the web UI)`);
|
|
271
277
|
// Rejection swallowed rather than dropped: `--session` resumes a live Agent Session, and a
|
|
272
278
|
// call decided in another client between the reducer seeing it and this landing comes back
|
|
273
279
|
// as a refusal. There is nothing to do about that — the prompt is settled either way — and
|
|
@@ -325,7 +331,7 @@ function format(entry) {
|
|
|
325
331
|
case "enquiry": {
|
|
326
332
|
// This runner takes no input, so an Enquiry it sees is one it aborts (see `oneShot`) — what
|
|
327
333
|
// reaches here is therefore `aborted`, and what it prints is what was asked and went
|
|
328
|
-
// unanswered. The
|
|
334
|
+
// unanswered. The web client is where one can actually be answered.
|
|
329
335
|
const asked = answerLines(entry.questions, entry.answers).join("; ");
|
|
330
336
|
return ` ? [${entry.status}] ${asked}`;
|
|
331
337
|
}
|
package/dist/cli/bootstrap.js
CHANGED
|
@@ -342,7 +342,7 @@ function installation(slot) {
|
|
|
342
342
|
if (!active.some((other) => other.id === lease.id && other.pid === process.pid && other.root === lease.root)) throw new Error("Update process has no installation lease");
|
|
343
343
|
const selected = host && active.find((other) => other.pid === host.pid && other.root === lease.root);
|
|
344
344
|
if (systemdArgs && selected && JSON.stringify(selected.args) !== JSON.stringify(systemdArgs)) throw new Error("Configured systemd hostArgs do not match the running Session Host; correct systemd-update.json before updating");
|
|
345
|
-
if (active.some((other) => other.id !== lease.id && !(host && other.pid === host.pid && other.root === lease.root && (systemdArgs ? JSON.stringify(other.args) === JSON.stringify(systemdArgs) : other.args.includes("--background-host"))))) throw new Error("Stop all other Flow hosts and CLI
|
|
345
|
+
if (active.some((other) => other.id !== lease.id && !(host && other.pid === host.pid && other.root === lease.root && (systemdArgs ? JSON.stringify(other.args) === JSON.stringify(systemdArgs) : other.args.includes("--background-host"))))) throw new Error("Stop all other Flow hosts and CLI clients using this installation first");
|
|
346
346
|
if (host && !active.some((other) => other.pid === host.pid && other.root === lease.root)) throw new Error("Stop all pre-guard Flow processes before updating");
|
|
347
347
|
save(barrier);
|
|
348
348
|
});
|
|
@@ -889,7 +889,7 @@ async function bootstrap() {
|
|
|
889
889
|
if (!managed) throw new Error("Missing systemd update configuration");
|
|
890
890
|
await assertSystemdOwner(managed, managed.updater, process.pid);
|
|
891
891
|
}
|
|
892
|
-
const lease = await install.register("
|
|
892
|
+
const lease = await install.register("b0e0ff3f-abb1-4d6f-9468-feee46715304", root, args, process.env.FLOW_UPDATE_CAPABILITY ?? systemdCapability(root));
|
|
893
893
|
delete process.env.FLOW_UPDATE_CAPABILITY;
|
|
894
894
|
process.on("exit", lease.release);
|
|
895
895
|
if (args[0] === "update") {
|
package/dist/cli/host-control.js
CHANGED
|
@@ -2,7 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { closeSync, constants, fchmodSync, mkdirSync, openSync, realpathSync, statSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
-
import { oidcFingerprint, readHost } from
|
|
5
|
+
import { oidcFingerprint, readHost } from '../daemon/ownership.js';
|
|
6
6
|
export class HostRefusal extends Error {
|
|
7
7
|
}
|
|
8
8
|
export function processAlive(pid) {
|
|
@@ -2,7 +2,7 @@ import { mkdirSync, realpathSync, lstatSync, readFileSync, writeFileSync, readdi
|
|
|
2
2
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
3
|
import { createHash, randomUUID } from 'node:crypto';
|
|
4
4
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
-
import { processAlive } from
|
|
5
|
+
import { processAlive } from './host-control.js';
|
|
6
6
|
export const packageName = '@nathanstephenson/flow';
|
|
7
7
|
function record(path) {
|
|
8
8
|
try {
|
|
@@ -272,7 +272,7 @@ export function installation(slot) {
|
|
|
272
272
|
if (systemdArgs && selected && JSON.stringify(selected.args) !== JSON.stringify(systemdArgs))
|
|
273
273
|
throw new Error('Configured systemd hostArgs do not match the running Session Host; correct systemd-update.json before updating');
|
|
274
274
|
if (active.some(other => other.id !== lease.id && !(host && other.pid === host.pid && other.root === lease.root && (systemdArgs ? JSON.stringify(other.args) === JSON.stringify(systemdArgs) : other.args.includes('--background-host')))))
|
|
275
|
-
throw new Error('Stop all other Flow hosts and CLI
|
|
275
|
+
throw new Error('Stop all other Flow hosts and CLI clients using this installation first');
|
|
276
276
|
if (host && !active.some(other => other.pid === host.pid && other.root === lease.root))
|
|
277
277
|
throw new Error('Stop all pre-guard Flow processes before updating');
|
|
278
278
|
save(barrier);
|
package/dist/cli/main.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { isSea } from 'node:sea';
|
|
3
3
|
if (process.argv[2] === '--flow-workflow-authoring-scope-reader' && process.env.FLOW_WORKFLOW_AUTHORING_SCOPE_READER === '1') {
|
|
4
|
-
void import(
|
|
4
|
+
void import('../daemon/workflow-authoring-scope-reader.js').then(({ runWorkflowAuthoringScopeReader }) => runWorkflowAuthoringScopeReader()).catch(() => {
|
|
5
5
|
process.exitCode = 1;
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
8
|
else if (process.argv[2] === '--flow-workflow-builder-reader' && process.env.FLOW_WORKFLOW_BUILDER_READER === '1') {
|
|
9
|
-
void import(
|
|
9
|
+
void import('../daemon/workflow-builder-reader.js').then(({ runWorkflowBuilderReader }) => runWorkflowBuilderReader()).catch(() => {
|
|
10
10
|
process.exitCode = 1;
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
else if (process.argv[2] === '--flow-isolation-launch' ||
|
|
14
14
|
(process.argv[2] === '--flow-backend-worker' && process.env.FLOW_BACKEND_WORKER === '1')) {
|
|
15
|
-
void import(
|
|
15
|
+
void import('../backend/worker/entry.js').catch(error => {
|
|
16
16
|
console.error(error instanceof Error ? error.message : error);
|
|
17
17
|
process.exitCode = 1;
|
|
18
18
|
});
|
|
@@ -22,7 +22,7 @@ else if (!isSea() && import.meta.url.endsWith('.js')) {
|
|
|
22
22
|
process.exitCode = 1;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
void import(
|
|
25
|
+
void import('./application.js').then(({ runCli }) => runCli()).catch(error => {
|
|
26
26
|
console.error(error instanceof Error ? error.message : error);
|
|
27
27
|
process.exitCode = 1;
|
|
28
28
|
});
|
|
@@ -2,9 +2,9 @@ import { execFile } from 'node:child_process';
|
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import { readFileSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { getHostStatus, waitUntil } from
|
|
6
|
-
import { readHost } from
|
|
7
|
-
import { isReleaseVersion } from
|
|
5
|
+
import { getHostStatus, waitUntil } from './host-control.js';
|
|
6
|
+
import { readHost } from '../daemon/ownership.js';
|
|
7
|
+
import { isReleaseVersion } from '../daemon/release-checker.js';
|
|
8
8
|
const exec = promisify(execFile);
|
|
9
9
|
export function parseSystemdUpdate(value) {
|
|
10
10
|
const c = value;
|
package/dist/cli/update.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { accessSync, constants, readFileSync, realpathSync } from 'node:fs';
|
|
3
3
|
import { delimiter, join, resolve } from 'node:path';
|
|
4
|
-
import { packageName, privatePath } from
|
|
5
|
-
import { readHost } from
|
|
6
|
-
import { backgroundHostArgs, getHostStatus, HostRefusal, launchBackground, processAlive, requestHostStop, requireRestartable, waitUntil } from
|
|
7
|
-
import { InstallationProcessUncertain, replacePackage } from
|
|
8
|
-
import { assertSystemdOwner, restoreSystemd, resumeSystemdAdmission, systemctl, SystemdCommandFailed } from
|
|
9
|
-
import { newerReleaseVersion } from
|
|
4
|
+
import { packageName, privatePath } from './install-guard.js';
|
|
5
|
+
import { readHost } from '../daemon/ownership.js';
|
|
6
|
+
import { backgroundHostArgs, getHostStatus, HostRefusal, launchBackground, processAlive, requestHostStop, requireRestartable, waitUntil } from './host-control.js';
|
|
7
|
+
import { InstallationProcessUncertain, replacePackage } from './install-process.js';
|
|
8
|
+
import { assertSystemdOwner, restoreSystemd, resumeSystemdAdmission, systemctl, SystemdCommandFailed } from './systemd-update.js';
|
|
9
|
+
import { newerReleaseVersion } from '../daemon/release-checker.js';
|
|
10
10
|
export function npmExecutable() {
|
|
11
11
|
for (const directory of (process.env.PATH ?? '').split(delimiter)) {
|
|
12
12
|
const path = resolve(directory, 'npm');
|
package/dist/cli/web-update.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { systemdUpdate, launchSystemdUpdate, SystemdLaunchUncertain } from
|
|
1
|
+
import { systemdUpdate, launchSystemdUpdate, SystemdLaunchUncertain } from './systemd-update.js';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { closeSync, constants, fchmodSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmdirSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
|
-
import { newerReleaseVersion, ReleaseChecker } from
|
|
7
|
-
import { UpdateRefusal } from
|
|
8
|
-
export { UpdateRefusal } from
|
|
9
|
-
import { processAlive } from
|
|
10
|
-
import { inspectUpdateInstallation } from
|
|
6
|
+
import { newerReleaseVersion, ReleaseChecker } from '../daemon/release-checker.js';
|
|
7
|
+
import { UpdateRefusal } from '../daemon/update-api.js';
|
|
8
|
+
export { UpdateRefusal } from '../daemon/update-api.js';
|
|
9
|
+
import { processAlive } from './host-control.js';
|
|
10
|
+
import { inspectUpdateInstallation } from './update.js';
|
|
11
11
|
const STATUS_FILE = 'web-update.json';
|
|
12
12
|
const STATUS_LOCK = 'web-update-lock';
|
|
13
13
|
const STATUS_LOCK_ATTEMPTS = 100;
|
|
@@ -121,6 +121,52 @@ export function connect(options) {
|
|
|
121
121
|
})();
|
|
122
122
|
return () => { stopped = true; stream?.abort(); wake?.(); };
|
|
123
123
|
},
|
|
124
|
+
subscribeAttention(onRaise) {
|
|
125
|
+
let stopped = false;
|
|
126
|
+
let stream;
|
|
127
|
+
let wake;
|
|
128
|
+
let attempt = 0;
|
|
129
|
+
void (async () => {
|
|
130
|
+
while (!stopped) {
|
|
131
|
+
const controller = new AbortController();
|
|
132
|
+
stream = controller;
|
|
133
|
+
const arm = () => setTimeout(() => controller.abort(), SILENCE_MS);
|
|
134
|
+
let watchdog = arm();
|
|
135
|
+
const receivedChunk = () => { clearTimeout(watchdog); watchdog = arm(); };
|
|
136
|
+
const openedAt = Date.now();
|
|
137
|
+
try {
|
|
138
|
+
const response = await fetch(`${options.url}/api/attention/events`, {
|
|
139
|
+
headers, ...credentials, signal: controller.signal,
|
|
140
|
+
});
|
|
141
|
+
if (FATAL_STATUS.has(response.status))
|
|
142
|
+
return;
|
|
143
|
+
if (response.ok && response.body) {
|
|
144
|
+
for await (const raised of readEventStream(response.body, receivedChunk)) {
|
|
145
|
+
if (stopped)
|
|
146
|
+
return;
|
|
147
|
+
onRaise(raised);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
if (stopped)
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
clearTimeout(watchdog);
|
|
157
|
+
}
|
|
158
|
+
if (stopped)
|
|
159
|
+
return;
|
|
160
|
+
attempt = Date.now() - openedAt >= BACKOFF_MIN_MS ? 1 : attempt + 1;
|
|
161
|
+
await new Promise(resolve => {
|
|
162
|
+
const timer = setTimeout(resolve, backoffMs(attempt));
|
|
163
|
+
wake = () => { clearTimeout(timer); resolve(); };
|
|
164
|
+
});
|
|
165
|
+
wake = undefined;
|
|
166
|
+
}
|
|
167
|
+
})();
|
|
168
|
+
return () => { stopped = true; stream?.abort(); wake?.(); };
|
|
169
|
+
},
|
|
124
170
|
subscribe({ sessionId, since, onEntry, onError, onLink, silenceMs }) {
|
|
125
171
|
const events = `${options.url}/api/sessions/${encodeURIComponent(sessionId)}/events`;
|
|
126
172
|
const silence = silenceMs ?? SILENCE_MS;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* How much of the Conversation Context is spent, as one short chrome label.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* as a sentence fragment, and because it is the one with tests.
|
|
4
|
+
* `context 12%` rather than `12% context`, because it reads as a label rather than as a sentence
|
|
5
|
+
* fragment.
|
|
7
6
|
*/
|
|
8
7
|
export function contextUsageLabel(usage) {
|
|
9
8
|
if (!usage)
|
|
@@ -43,7 +42,7 @@ export function contextUsageDetail(usage) {
|
|
|
43
42
|
* cent, and rounding that to `$0.00` would report free work. Anything at or above a cent reads in
|
|
44
43
|
* the two places money is normally written.
|
|
45
44
|
*/
|
|
46
|
-
function money(usd) {
|
|
45
|
+
export function money(usd) {
|
|
47
46
|
if (usd >= 0.01)
|
|
48
47
|
return `$${usd.toFixed(2)}`;
|
|
49
48
|
if (usd === 0)
|
package/dist/client/diff.js
CHANGED
|
@@ -66,6 +66,46 @@ export function textDiff(text, lang) {
|
|
|
66
66
|
return { text: line, kind };
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
export function numberedDiff(text) {
|
|
70
|
+
const hunks = [];
|
|
71
|
+
let hunk;
|
|
72
|
+
let old = 0;
|
|
73
|
+
let next = 0;
|
|
74
|
+
for (const line of text.split("\n")) {
|
|
75
|
+
const header = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/.exec(line);
|
|
76
|
+
if (header) {
|
|
77
|
+
hunk = { oldStart: Number(header[1]), oldCount: Number(header[2] ?? 1), newStart: Number(header[3]), newCount: Number(header[4] ?? 1), lines: [{ kind: "context", text: line }] };
|
|
78
|
+
hunks.push(hunk);
|
|
79
|
+
old = hunk.oldStart;
|
|
80
|
+
next = hunk.newStart;
|
|
81
|
+
}
|
|
82
|
+
else if (!hunk)
|
|
83
|
+
continue;
|
|
84
|
+
else if (line.startsWith("-"))
|
|
85
|
+
hunk.lines.push({ kind: "removed", text: line, old: old++ });
|
|
86
|
+
else if (line.startsWith("+"))
|
|
87
|
+
hunk.lines.push({ kind: "added", text: line, new: next++ });
|
|
88
|
+
else if (line.startsWith(" "))
|
|
89
|
+
hunk.lines.push({ kind: "context", text: line, old: old++, new: next++ });
|
|
90
|
+
else if (line.startsWith("\\"))
|
|
91
|
+
hunk.lines.push({ kind: "context", text: line });
|
|
92
|
+
}
|
|
93
|
+
return { deleted: /^\+\+\+ \/dev\/null$/m.test(text), hunks };
|
|
94
|
+
}
|
|
95
|
+
export function excerptHunks(hunks, deleted, range) {
|
|
96
|
+
if (!range)
|
|
97
|
+
return hunks;
|
|
98
|
+
return hunks.filter(hunk => {
|
|
99
|
+
const start = deleted ? hunk.oldStart : hunk.newStart;
|
|
100
|
+
const end = start + Math.max(deleted ? hunk.oldCount : hunk.newCount, 1) - 1;
|
|
101
|
+
return start <= range.to && end >= range.from;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export function hunksUnchanged(excerpt, current) {
|
|
105
|
+
const text = (hunk) => hunk.lines.map(line => line.text).join("\n");
|
|
106
|
+
const now = new Set(current.map(text));
|
|
107
|
+
return excerpt.every(hunk => now.has(text(hunk)));
|
|
108
|
+
}
|
|
69
109
|
function lines(text) {
|
|
70
110
|
if (!text)
|
|
71
111
|
return [];
|
package/dist/client/enquiry.js
CHANGED
|
@@ -25,12 +25,6 @@ export function cursorAfter(current, delta, rows) {
|
|
|
25
25
|
return 0;
|
|
26
26
|
return (((current + delta) % rows) + rows) % rows;
|
|
27
27
|
}
|
|
28
|
-
/** Where the cursor lands after moving by `delta`, clamped — the TUI's idiom, as every list there clamps. */
|
|
29
|
-
export function cursorClamped(current, delta, rows) {
|
|
30
|
-
if (rows <= 0)
|
|
31
|
-
return 0;
|
|
32
|
-
return Math.min(rows - 1, Math.max(0, current + delta));
|
|
33
|
-
}
|
|
34
28
|
/**
|
|
35
29
|
* Where the cursor goes when the box gains or loses its first character.
|
|
36
30
|
*
|
package/dist/client/markdown.js
CHANGED
|
@@ -156,12 +156,13 @@ function toImage(href, alt, raw, options) {
|
|
|
156
156
|
if (!src || !/^https?:\/\//i.test(src))
|
|
157
157
|
return { kind: "text", text: raw };
|
|
158
158
|
const url = new URL(src);
|
|
159
|
-
const blob = /^\/([^/]+)\/([^/]+)\/blob\/(.+)$/.exec(url.pathname);
|
|
159
|
+
const blob = /^\/([^/]+)\/([^/]+)\/(?:blob|raw)\/(.+)$/.exec(url.pathname);
|
|
160
160
|
if (url.hostname === "github.com" && blob) {
|
|
161
161
|
url.hostname = "raw.githubusercontent.com";
|
|
162
162
|
url.pathname = `/${blob[1]}/${blob[2]}/${blob[3]}`;
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
const github = url.hostname === "raw.githubusercontent.com" || (url.hostname === "github.com" && url.pathname.startsWith("/user-attachments/assets/"));
|
|
165
|
+
return { kind: "image", src: options.imageProxy && github ? `${options.imageProxy}${encodeURIComponent(url.href)}` : url.href, alt };
|
|
165
166
|
}
|
|
166
167
|
function htmlImages(text, options) {
|
|
167
168
|
const tags = text.match(/<img\b(?:[^"'<>]|"[^"]*"|'[^']*')*\/?>/gi);
|
|
@@ -8,7 +8,7 @@ export function modelChoices(capabilities) {
|
|
|
8
8
|
* `Capabilities` is how a model list arrives inside an Agent Session, and `GET /api/models` is how
|
|
9
9
|
* it arrives before there is one (ADR 0020) — the New Agent Session view reads the second. Only
|
|
10
10
|
* `.models` was ever used here, so taking the list is the whole of the generalisation, and
|
|
11
|
-
* `modelChoices` keeps its signature
|
|
11
|
+
* `modelChoices` keeps its signature.
|
|
12
12
|
*/
|
|
13
13
|
export function modelChoicesOf(models) {
|
|
14
14
|
if (!models)
|
|
@@ -27,8 +27,7 @@ export const PERMISSION_CHOICES = [
|
|
|
27
27
|
description: "Run it, and never ask again in any Agent Session. Revocable in Settings.",
|
|
28
28
|
},
|
|
29
29
|
];
|
|
30
|
-
//
|
|
31
|
-
// view beside the source choices rather than allocating and scanning the same list in that hot path.
|
|
30
|
+
// The fixed narrowed view, kept beside the source choices rather than sliced on every render.
|
|
32
31
|
const ONE_SHOT_PERMISSION_CHOICES = PERMISSION_CHOICES.slice(0, 2);
|
|
33
32
|
/** The same shared controls, narrowed for requests whose scope can never become standing. */
|
|
34
33
|
export function permissionChoices(allowAlways) {
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* question is asked one segment higher up. A flag rather than the repository's name over the wire,
|
|
13
13
|
* because the name is already here in the Scope.
|
|
14
14
|
*/
|
|
15
|
-
export function projectName(scope, worktree) {
|
|
15
|
+
export function projectName(scope, worktree, readOnly) {
|
|
16
|
+
if (readOnly)
|
|
17
|
+
return "<chat>";
|
|
16
18
|
const path = worktree ? scope.slice(0, Math.max(0, scope.lastIndexOf("/"))) : scope;
|
|
17
19
|
const cut = path.lastIndexOf("/");
|
|
18
20
|
return (cut < 0 ? path : path.slice(cut + 1)) || scope;
|
package/dist/client/reduce.js
CHANGED
|
@@ -45,7 +45,7 @@ export function reduceAll(entries, from = initialState()) {
|
|
|
45
45
|
function stampTurnEnd(entries, at) {
|
|
46
46
|
for (let index = entries.length - 1; index >= 0; index--) {
|
|
47
47
|
const entry = entries[index];
|
|
48
|
-
if (entry.kind === "user")
|
|
48
|
+
if (entry.kind === "user" && entry.producer === undefined)
|
|
49
49
|
return entries;
|
|
50
50
|
if (entry.kind === "assistant" && entry.producer === undefined) {
|
|
51
51
|
if (entry.endedAt === at)
|
|
@@ -111,14 +111,21 @@ function applyEvent(state, event, at) {
|
|
|
111
111
|
return {
|
|
112
112
|
...state,
|
|
113
113
|
spoken: true,
|
|
114
|
+
// A finished list has said what it had to; it goes when the human moves on.
|
|
115
|
+
...(state.todoList?.every((item) => item.status === "completed") ? { todoList: undefined } : {}),
|
|
114
116
|
entries: upsert(state.entries, {
|
|
115
117
|
kind: "user",
|
|
116
118
|
id: event.id,
|
|
117
|
-
|
|
119
|
+
...(event.fromSessionId === undefined
|
|
120
|
+
? { text: event.text }
|
|
121
|
+
: { text: event.text.slice(event.text.indexOf("\n") + 1), fromSessionId: event.fromSessionId }),
|
|
122
|
+
...(event.note === undefined ? {} : { note: event.note }),
|
|
118
123
|
...(event.attachments === undefined ? {} : { attachments: event.attachments }),
|
|
119
124
|
at,
|
|
120
125
|
}),
|
|
121
126
|
};
|
|
127
|
+
case "subagent_instruction":
|
|
128
|
+
return { ...state, entries: upsert(state.entries, { kind: "user", id: event.id, text: event.text, producer: event.producer, at }) };
|
|
122
129
|
case "turn_started":
|
|
123
130
|
return { ...state, turnInFlight: true };
|
|
124
131
|
case "message":
|
|
@@ -132,6 +139,11 @@ function applyEvent(state, event, at) {
|
|
|
132
139
|
...producerOf(event),
|
|
133
140
|
}),
|
|
134
141
|
};
|
|
142
|
+
case "diff_excerpts":
|
|
143
|
+
return {
|
|
144
|
+
...state,
|
|
145
|
+
entries: state.entries.map((entry) => entry.kind === "assistant" && entry.id === event.messageId ? { ...entry, excerpts: event.excerpts } : entry),
|
|
146
|
+
};
|
|
135
147
|
case "thinking":
|
|
136
148
|
return {
|
|
137
149
|
...state,
|
|
@@ -184,6 +196,9 @@ function applyEvent(state, event, at) {
|
|
|
184
196
|
id: event.subagentId,
|
|
185
197
|
name: event.name,
|
|
186
198
|
...(event.description === undefined ? {} : { description: event.description }),
|
|
199
|
+
...(event.model === undefined ? {} : { model: event.model }),
|
|
200
|
+
...(event.effort === undefined ? {} : { effort: event.effort }),
|
|
201
|
+
...(event.producer === undefined ? {} : { producer: event.producer }),
|
|
187
202
|
status: event.state,
|
|
188
203
|
// Only ever set alongside "waiting", so a Subagent that resumes drops it rather than
|
|
189
204
|
// carrying a stale object it is no longer waiting on.
|
|
@@ -284,6 +299,20 @@ function applyEvent(state, event, at) {
|
|
|
284
299
|
})),
|
|
285
300
|
};
|
|
286
301
|
}
|
|
302
|
+
case "plan": {
|
|
303
|
+
const todoList = event.entries.length === 0 ? undefined
|
|
304
|
+
: state.todoList !== undefined && sameTodos(state.todoList, event.entries) ? state.todoList : event.entries;
|
|
305
|
+
const callId = event.callId;
|
|
306
|
+
const tool = callId === undefined ? undefined
|
|
307
|
+
: state.entries.find((entry) => entry.kind === "tool" && entry.id === callId);
|
|
308
|
+
const stale = tool?.kind === "tool" && !(tool.todos !== undefined && sameTodos(tool.todos, event.entries));
|
|
309
|
+
const entries = stale && callId !== undefined
|
|
310
|
+
? patchTool(state.entries, callId, (row) => ({ ...row, todos: todoList ?? [] }))
|
|
311
|
+
: state.entries;
|
|
312
|
+
if (todoList === state.todoList && entries === state.entries)
|
|
313
|
+
return state;
|
|
314
|
+
return { ...state, todoList, entries };
|
|
315
|
+
}
|
|
287
316
|
case "turn_ended":
|
|
288
317
|
return {
|
|
289
318
|
...state,
|
|
@@ -335,7 +364,8 @@ function applyEvent(state, event, at) {
|
|
|
335
364
|
case "notice":
|
|
336
365
|
return {
|
|
337
366
|
...state,
|
|
338
|
-
entries: [...state.entries, { kind: "notice", id: `notice-${state.entries.length}`, level: event.level, text: event.text
|
|
367
|
+
entries: [...state.entries, { kind: "notice", id: `notice-${state.entries.length}`, level: event.level, text: event.text,
|
|
368
|
+
...(event.sessionId === undefined ? {} : { sessionId: event.sessionId }) }],
|
|
339
369
|
};
|
|
340
370
|
case "compacting":
|
|
341
371
|
// Absent rather than `false`, so Chrome's identity comparison sees the same value it saw
|
|
@@ -384,6 +414,28 @@ function applyEvent(state, event, at) {
|
|
|
384
414
|
{ kind: "marker", id: `settled-${state.entries.length}`, marker: "settled", text: "Settled" },
|
|
385
415
|
],
|
|
386
416
|
};
|
|
417
|
+
case "rewound": {
|
|
418
|
+
const from = state.entries.findIndex((entry) => entry.kind === "user" && entry.id === event.userMessageId);
|
|
419
|
+
const text = event.restore === "files" ? "Files rewound" : event.restore === "both" ? "Rewound conversation and files" : "Rewound conversation";
|
|
420
|
+
const conversation = from >= 0 && event.restore !== "files";
|
|
421
|
+
const entries = conversation
|
|
422
|
+
? state.entries.map((entry, index) => index < from || entry.rewound ? entry : { ...entry, rewound: true })
|
|
423
|
+
: state.entries;
|
|
424
|
+
return {
|
|
425
|
+
...state,
|
|
426
|
+
// The list as the Conversation Context now remembers it: what the last call it still holds left.
|
|
427
|
+
...(conversation ? { todoList: todoListBefore(entries, state.todoList) } : {}),
|
|
428
|
+
entries: [...entries, { kind: "marker", id: `rewound-${state.entries.length}`, marker: "rewound", text }],
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
case "forked":
|
|
432
|
+
return {
|
|
433
|
+
...state,
|
|
434
|
+
entries: [
|
|
435
|
+
...state.entries,
|
|
436
|
+
{ kind: "marker", id: `forked-${state.entries.length}`, marker: "forked", text: "Forked", fromSessionId: event.fromSessionId },
|
|
437
|
+
],
|
|
438
|
+
};
|
|
387
439
|
case "revived":
|
|
388
440
|
return {
|
|
389
441
|
...state,
|
|
@@ -471,6 +523,28 @@ function nextAwaiting(entries, except) {
|
|
|
471
523
|
...(next.producer === undefined ? {} : { producer: next.producer }),
|
|
472
524
|
} : undefined;
|
|
473
525
|
}
|
|
526
|
+
function sameTodos(left, right) {
|
|
527
|
+
return left === right || (left.length === right.length && left.every((item, index) => {
|
|
528
|
+
const other = right[index];
|
|
529
|
+
return item.content === other.content && item.status === other.status && item.priority === other.priority;
|
|
530
|
+
}));
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* The Todo List as the last call a Rewind left in the Conversation Context reported it.
|
|
534
|
+
*
|
|
535
|
+
* `current` is returned when that is still the list, so an unchanged chrome is not republished.
|
|
536
|
+
*/
|
|
537
|
+
function todoListBefore(entries, current) {
|
|
538
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
539
|
+
const entry = entries[index];
|
|
540
|
+
if (entry.kind !== "tool" || entry.rewound || entry.todos === undefined)
|
|
541
|
+
continue;
|
|
542
|
+
if (entry.todos.length === 0)
|
|
543
|
+
return undefined;
|
|
544
|
+
return current !== undefined && sameTodos(current, entry.todos) ? current : entry.todos;
|
|
545
|
+
}
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
474
548
|
/** Spread onto an Entry, so an unattributed event does not carry an explicit `producer: undefined`. */
|
|
475
549
|
function producerOf(event) {
|
|
476
550
|
return event.producer === undefined ? {} : { producer: event.producer };
|