reasonally 0.6.0 → 0.8.0
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 +20 -0
- package/dist/agent/session.js +1 -0
- package/dist/api.js +12 -3
- package/dist/cli.js +6 -1
- package/dist/login.js +20 -4
- package/dist/sync/client.js +789 -0
- package/dist/sync/command.js +105 -0
- package/dist/sync/entries.js +139 -0
- package/dist/sync/live.js +107 -0
- package/dist/sync/protocol.js +14 -0
- package/dist/sync/redact.js +35 -0
- package/dist/sync/store.js +214 -0
- package/dist/sync/tail.js +66 -0
- package/dist/tui/app.js +63 -5
- package/dist/tui/args.js +20 -1
- package/dist/tui/start.js +39 -2
- package/package.json +1 -1
package/dist/tui/app.js
CHANGED
|
@@ -14,6 +14,7 @@ import { changeRecord, listSessions, loadSession, sessionHolder, SessionWriter,
|
|
|
14
14
|
import { PLAN_OUTCOME_LABELS, PLAN_TOOL } from "../agent/tools/plan.js";
|
|
15
15
|
import { changedLines, editInEditor } from "./external-editor.js";
|
|
16
16
|
import { appCommand, closeMatches, COMMANDS, helpText, SOURCE_LABELS } from "./commands.js";
|
|
17
|
+
import { LiveTracker } from "../sync/live.js";
|
|
17
18
|
import { ApprovalBox, Clamped, PlanApprovalBox, PlanBlock, gap, Header, INDENT, Lines, markdownTheme, Picker, Reasoning, selectListTheme, ToolLine, UserMessage, } from "./components.js";
|
|
18
19
|
import { compactionNote, describeError, formatTokens, modelChoice, openElsewhere, retryMessage, sortModels, modeStatus, statusLine, } from "./format.js";
|
|
19
20
|
import { style, theme } from "./theme.js";
|
|
@@ -72,6 +73,10 @@ export class App {
|
|
|
72
73
|
lastPlanOutcome = null;
|
|
73
74
|
/** The plan is open in the person's editor. */
|
|
74
75
|
editingPlan = false;
|
|
76
|
+
/** What's happening now, for the web (see `src/sync/live.ts`). */
|
|
77
|
+
live = new LiveTracker();
|
|
78
|
+
turnFailed = false;
|
|
79
|
+
approvalsAsked = 0;
|
|
75
80
|
constructor(options) {
|
|
76
81
|
this.options = options;
|
|
77
82
|
this.session = options.session;
|
|
@@ -339,16 +344,20 @@ export class App {
|
|
|
339
344
|
const controller = new AbortController();
|
|
340
345
|
this.busy = controller;
|
|
341
346
|
this.pendingNext = null;
|
|
347
|
+
this.turnFailed = false;
|
|
348
|
+
this.liveUpdate(this.live.turnStarted());
|
|
342
349
|
this.showLoader("Thinking…");
|
|
343
350
|
try {
|
|
344
351
|
for await (const event of start(controller.signal))
|
|
345
352
|
this.onEvent(event);
|
|
346
353
|
}
|
|
347
354
|
catch (error) {
|
|
355
|
+
this.turnFailed = true;
|
|
348
356
|
this.showError(error);
|
|
349
357
|
}
|
|
350
358
|
finally {
|
|
351
359
|
this.busy = null;
|
|
360
|
+
this.liveUpdate(this.live.turnEnded(this.turnFailed));
|
|
352
361
|
this.reasoning?.finish();
|
|
353
362
|
this.hideLoader();
|
|
354
363
|
this.updateStatus();
|
|
@@ -387,8 +396,11 @@ export class App {
|
|
|
387
396
|
}
|
|
388
397
|
if (this.queued.length)
|
|
389
398
|
this.showQueued();
|
|
399
|
+
else
|
|
400
|
+
this.liveUpdate(this.live.setQueued(0));
|
|
390
401
|
}
|
|
391
402
|
showQueued() {
|
|
403
|
+
this.liveUpdate(this.live.setQueued(this.queued.length));
|
|
392
404
|
const text = theme.muted(`Queued (${this.queued.length}). Sends when this step finishes, or now with esc.`);
|
|
393
405
|
if (!this.queuedNote) {
|
|
394
406
|
this.queuedNote = new Lines(text, 2);
|
|
@@ -405,6 +417,7 @@ export class App {
|
|
|
405
417
|
this.replyText = "";
|
|
406
418
|
this.reasoning = null;
|
|
407
419
|
this.setLoader("Thinking…");
|
|
420
|
+
this.liveUpdate(this.live.modelStarted());
|
|
408
421
|
break;
|
|
409
422
|
case "reasoning":
|
|
410
423
|
if (!this.reasoning) {
|
|
@@ -423,6 +436,7 @@ export class App {
|
|
|
423
436
|
this.replyText += event.text;
|
|
424
437
|
this.reply.setText(this.replyText);
|
|
425
438
|
this.setLoader("Writing…");
|
|
439
|
+
this.liveUpdate(this.live.textDelta(event.text));
|
|
426
440
|
break;
|
|
427
441
|
case "tool_call_streaming":
|
|
428
442
|
this.reasoning?.finish();
|
|
@@ -437,11 +451,13 @@ export class App {
|
|
|
437
451
|
this.add(this.planBlock, "text");
|
|
438
452
|
}
|
|
439
453
|
this.setLoader("Writing the plan…");
|
|
454
|
+
this.liveUpdate(this.live.planDraft(event.text));
|
|
440
455
|
break;
|
|
441
456
|
case "plan_draft_dropped":
|
|
442
457
|
if (this.planBlock)
|
|
443
458
|
this.transcript.removeChild(this.planBlock);
|
|
444
459
|
this.planBlock = null;
|
|
460
|
+
this.liveUpdate(this.live.planDropped());
|
|
445
461
|
break;
|
|
446
462
|
case "mode_changed":
|
|
447
463
|
// The agent switched it (the plan was approved); the status line shows it below.
|
|
@@ -457,6 +473,7 @@ export class App {
|
|
|
457
473
|
const line = new ToolLine(event.id, event.title);
|
|
458
474
|
this.toolLines.set(event.id, line);
|
|
459
475
|
this.add(line, "steps");
|
|
476
|
+
this.liveUpdate(this.live.stepStarted(event.id, event.title));
|
|
460
477
|
const helpers = [...this.toolLines.values()].filter((l) => l.status === "running" && l.title.startsWith("Helper: ")).length;
|
|
461
478
|
this.setLoader(event.name === "task"
|
|
462
479
|
? helpers > 1
|
|
@@ -483,6 +500,8 @@ export class App {
|
|
|
483
500
|
line.expanded = true;
|
|
484
501
|
}
|
|
485
502
|
this.writer?.append(stepRecord(event.id, event.title, result));
|
|
503
|
+
this.liveUpdate(this.live.stepDone(event.id));
|
|
504
|
+
this.syncSaved();
|
|
486
505
|
if (line.expandable)
|
|
487
506
|
this.lastExpandable = line;
|
|
488
507
|
this.setLoader("Thinking…");
|
|
@@ -501,6 +520,7 @@ export class App {
|
|
|
501
520
|
this.notice(theme.muted(compactionNote(event.beforeTokens, event.afterTokens, this.model?.contextLength ?? 1)));
|
|
502
521
|
break;
|
|
503
522
|
case "error":
|
|
523
|
+
this.turnFailed = true;
|
|
504
524
|
this.showError(event.error);
|
|
505
525
|
break;
|
|
506
526
|
case "done":
|
|
@@ -525,9 +545,12 @@ export class App {
|
|
|
525
545
|
/** Shows an approval box and waits for y / a / n (or Esc, or the turn being stopped). */
|
|
526
546
|
/** Approvals wait their turn: helpers working at once ask one at a time. */
|
|
527
547
|
approve(request, signal) {
|
|
528
|
-
const show = () =>
|
|
529
|
-
|
|
530
|
-
|
|
548
|
+
const show = () => {
|
|
549
|
+
if (signal.aborted)
|
|
550
|
+
return Promise.resolve({ kind: "no" });
|
|
551
|
+
this.liveUpdate(this.live.approvalAsked(`approval-${++this.approvalsAsked}`, request));
|
|
552
|
+
return this.showApproval(request, signal).finally(() => this.liveUpdate(this.live.approvalAnswered()));
|
|
553
|
+
};
|
|
531
554
|
const next = this.approvals.then(show, show);
|
|
532
555
|
this.approvals = next.catch(() => { });
|
|
533
556
|
return next;
|
|
@@ -785,6 +808,7 @@ export class App {
|
|
|
785
808
|
if (this.header)
|
|
786
809
|
this.header.model = model.id;
|
|
787
810
|
this.writer?.append({ type: "model", id: model.id });
|
|
811
|
+
this.syncSaved();
|
|
788
812
|
if (this.agent) {
|
|
789
813
|
this.agent.options.model = model;
|
|
790
814
|
this.agent.messages[0] = { role: "system", content: this.options.systemPrompt(model) };
|
|
@@ -891,6 +915,36 @@ export class App {
|
|
|
891
915
|
return;
|
|
892
916
|
this.writer ??= SessionWriter.create(this.options.sessionsDir, this.options.cwd, this.model.id, new Date(), "terminal");
|
|
893
917
|
this.writer.append(changeRecord(change));
|
|
918
|
+
this.syncSaved();
|
|
919
|
+
}
|
|
920
|
+
/** Tells sync the conversation changed: it uploads what's new once the write has landed. */
|
|
921
|
+
syncSaved() {
|
|
922
|
+
const writer = this.writer;
|
|
923
|
+
if (!writer || !this.options.sync)
|
|
924
|
+
return;
|
|
925
|
+
this.options.sync.poke(writer.path, {
|
|
926
|
+
flush: () => writer.flush(),
|
|
927
|
+
status: this.live.threadStatus,
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
/** Tells sync what's happening now (sent at once for "now", grouped for "soon"). */
|
|
931
|
+
liveUpdate(urgency) {
|
|
932
|
+
const sync = this.options.sync;
|
|
933
|
+
const writer = this.writer;
|
|
934
|
+
if (!sync || !writer)
|
|
935
|
+
return;
|
|
936
|
+
sync.setLive(writer.path, this.live.snapshot(), urgency === "now");
|
|
937
|
+
if (urgency === "now")
|
|
938
|
+
sync.setStatus(writer.path, this.live.threadStatus);
|
|
939
|
+
}
|
|
940
|
+
/** Once, the first time this computer's conversations start showing on the web. */
|
|
941
|
+
showSyncNotice() {
|
|
942
|
+
this.notice(theme.muted("Conversations now also show on the web (summaries only). Turn off: reasonally sync off"));
|
|
943
|
+
this.tui.requestRender();
|
|
944
|
+
}
|
|
945
|
+
/** The key in use now (it changes when the person logs in again). */
|
|
946
|
+
get currentSession() {
|
|
947
|
+
return this.session;
|
|
894
948
|
}
|
|
895
949
|
/** Continues a saved conversation: reprints it as it looked, then carries on in the same file. */
|
|
896
950
|
resumeSession(loaded) {
|
|
@@ -911,6 +965,7 @@ export class App {
|
|
|
911
965
|
this.writer = SessionWriter.resume(loaded.path);
|
|
912
966
|
// The callers checked that nothing else has it open.
|
|
913
967
|
void this.writer.claim("terminal");
|
|
968
|
+
this.syncSaved();
|
|
914
969
|
for (const entry of loaded.display) {
|
|
915
970
|
if (entry.kind === "user") {
|
|
916
971
|
this.addUser(entry.command ? commandLabel(entry.command) : entry.text);
|
|
@@ -1118,7 +1173,8 @@ export class App {
|
|
|
1118
1173
|
const costText = cost > 0n ? style.dim(`~${formatUsd(cost)} this session`) : null;
|
|
1119
1174
|
const writer = this.writer;
|
|
1120
1175
|
const mcp = this.options.mcp;
|
|
1121
|
-
|
|
1176
|
+
const sync = this.options.sync;
|
|
1177
|
+
if (!writer && !mcp && !sync) {
|
|
1122
1178
|
this.options.onExit(code, costText);
|
|
1123
1179
|
return;
|
|
1124
1180
|
}
|
|
@@ -1126,7 +1182,9 @@ export class App {
|
|
|
1126
1182
|
const stopping = mcp
|
|
1127
1183
|
? Promise.race([mcp.close(), new Promise((r) => setTimeout(r, 2000).unref())])
|
|
1128
1184
|
: Promise.resolve();
|
|
1129
|
-
|
|
1185
|
+
// Sync gets a moment to send what's left; the rest goes next time.
|
|
1186
|
+
const syncing = sync?.stop(1_000);
|
|
1187
|
+
void Promise.all([writer?.release(), stopping, syncing]).then(() => {
|
|
1130
1188
|
const saved = writer?.started && !writer.failed
|
|
1131
1189
|
? `${style.dim("Saved. Continue with:")} reasonally --continue`
|
|
1132
1190
|
: null;
|
package/dist/tui/args.js
CHANGED
|
@@ -6,6 +6,7 @@ export function parseAgentArgs(argv) {
|
|
|
6
6
|
plan: false,
|
|
7
7
|
continue: false,
|
|
8
8
|
resume: false,
|
|
9
|
+
resumeId: null,
|
|
9
10
|
noWeb: false,
|
|
10
11
|
};
|
|
11
12
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -30,7 +31,21 @@ export function parseAgentArgs(argv) {
|
|
|
30
31
|
args.continue = true;
|
|
31
32
|
}
|
|
32
33
|
else if (arg === "--resume" || arg === "-r") {
|
|
33
|
-
|
|
34
|
+
// An id may follow: `--resume <id>` opens that conversation, `--resume` alone picks one.
|
|
35
|
+
const value = argv[i + 1];
|
|
36
|
+
if (value && !value.startsWith("-")) {
|
|
37
|
+
args.resumeId = value;
|
|
38
|
+
i++;
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
args.resume = true;
|
|
42
|
+
}
|
|
43
|
+
else if (arg.startsWith("--resume=")) {
|
|
44
|
+
const value = arg.slice("--resume=".length);
|
|
45
|
+
if (value)
|
|
46
|
+
args.resumeId = value;
|
|
47
|
+
else
|
|
48
|
+
args.resume = true;
|
|
34
49
|
}
|
|
35
50
|
else if (arg === "--no-web") {
|
|
36
51
|
args.noWeb = true;
|
|
@@ -41,6 +56,10 @@ export function parseAgentArgs(argv) {
|
|
|
41
56
|
}
|
|
42
57
|
if (args.plan && args.yes)
|
|
43
58
|
return { ok: false, error: "Pick one of --plan and --yes." };
|
|
59
|
+
if (args.continue && (args.resume || args.resumeId))
|
|
60
|
+
return { ok: false, error: "Pick one of --continue and --resume." };
|
|
61
|
+
if (args.resumeId && !/^[\w.-]+$/.test(args.resumeId))
|
|
62
|
+
return { ok: false, error: `"${args.resumeId}" isn't a conversation id.` };
|
|
44
63
|
return { ok: true, args };
|
|
45
64
|
}
|
|
46
65
|
/** Bare `reasonally` opens the agent only in an interactive terminal; scripts still get help. */
|
package/dist/tui/start.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { realpath } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { ProcessTerminal } from "@earendil-works/pi-tui";
|
|
@@ -83,10 +84,43 @@ export async function startTui(args, log) {
|
|
|
83
84
|
else if (!args.model)
|
|
84
85
|
model = models.find((m) => m.id === resume.model) ?? model;
|
|
85
86
|
}
|
|
87
|
+
// `--resume <id>`: that conversation, as the desktop app's Continue in terminal copies it.
|
|
88
|
+
let pickInstead = false;
|
|
89
|
+
if (args.resumeId) {
|
|
90
|
+
const target = (await listSessions(sessions)).find((s) => s.id === args.resumeId);
|
|
91
|
+
const holder = target ? await sessionHolder(target.path) : null;
|
|
92
|
+
resume = target && !holder ? await loadSession(target.path) : null;
|
|
93
|
+
if (holder)
|
|
94
|
+
startNotice = `${openElsewhere(holder)} Close it there to continue it here.`;
|
|
95
|
+
else if (!target) {
|
|
96
|
+
startNotice = "That conversation isn't in this folder. Pick one to resume.";
|
|
97
|
+
pickInstead = true;
|
|
98
|
+
}
|
|
99
|
+
else if (!resume)
|
|
100
|
+
startNotice = "That conversation couldn't be read.";
|
|
101
|
+
else if (!args.model)
|
|
102
|
+
model = models.find((m) => m.id === resume.model) ?? model;
|
|
103
|
+
}
|
|
86
104
|
const shell = shellFor(process.env).name;
|
|
87
105
|
const promptFor = (m) => systemPrompt({ cwd, home, platform: process.platform, shell, date: new Date(), model: m.id, branch }, instructions);
|
|
106
|
+
// This computer's conversations on the web (`reasonally sync`). Only a login syncs: a key from
|
|
107
|
+
// REASONALLY_API_KEY is for scripts and servers.
|
|
108
|
+
const { SyncClient } = await import("../sync/client.js");
|
|
109
|
+
let app = null;
|
|
110
|
+
const sync = new SyncClient({
|
|
111
|
+
configDir: config,
|
|
112
|
+
credentials: () => {
|
|
113
|
+
const current = app?.currentSession ?? session;
|
|
114
|
+
return current && !current.fromEnv
|
|
115
|
+
? { appUrl: current.appUrl, apiKey: current.apiKey }
|
|
116
|
+
: null;
|
|
117
|
+
},
|
|
118
|
+
client: "cli",
|
|
119
|
+
surface: "terminal",
|
|
120
|
+
appVersion: createRequire(import.meta.url)("../../package.json").version,
|
|
121
|
+
onFirstSync: () => app?.showSyncNotice(),
|
|
122
|
+
});
|
|
88
123
|
return await new Promise((resolve) => {
|
|
89
|
-
let app = null;
|
|
90
124
|
const quit = (code) => app?.exit(code);
|
|
91
125
|
const onSignal = () => quit(130);
|
|
92
126
|
const onCrash = (error) => {
|
|
@@ -111,7 +145,7 @@ export async function startTui(args, log) {
|
|
|
111
145
|
mcpErrors,
|
|
112
146
|
mcpConfigPath: mcpPath,
|
|
113
147
|
resume,
|
|
114
|
-
pickSession: args.resume,
|
|
148
|
+
pickSession: args.resume || pickInstead,
|
|
115
149
|
startNotice,
|
|
116
150
|
mode: args.plan ? "plan" : args.yes ? "full" : "ask",
|
|
117
151
|
web: args.noWeb ? WEB_OFF : DEFAULT_WEB_POLICY,
|
|
@@ -125,6 +159,7 @@ export async function startTui(args, log) {
|
|
|
125
159
|
return next;
|
|
126
160
|
},
|
|
127
161
|
rememberModel: (id) => writeLastModel(MODEL_MEMORY_KEY, id),
|
|
162
|
+
sync,
|
|
128
163
|
onExit: (code, summary) => {
|
|
129
164
|
if (summary)
|
|
130
165
|
process.stdout.write(`${summary}\n`);
|
|
@@ -137,5 +172,7 @@ export async function startTui(args, log) {
|
|
|
137
172
|
});
|
|
138
173
|
app.start();
|
|
139
174
|
void mcp?.start();
|
|
175
|
+
// In the background: nothing waits for it, and it goes quiet when it can't sync.
|
|
176
|
+
void sync.start().then(() => sync.backfill([sessions]));
|
|
140
177
|
});
|
|
141
178
|
}
|