reasonally 0.6.0 → 0.7.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/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 = () => signal.aborted
529
- ? Promise.resolve({ kind: "no" })
530
- : this.showApproval(request, signal);
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
- if (!writer && !mcp) {
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
- void Promise.all([writer?.release(), stopping]).then(() => {
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/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";
@@ -85,8 +86,24 @@ export async function startTui(args, log) {
85
86
  }
86
87
  const shell = shellFor(process.env).name;
87
88
  const promptFor = (m) => systemPrompt({ cwd, home, platform: process.platform, shell, date: new Date(), model: m.id, branch }, instructions);
89
+ // This computer's conversations on the web (`reasonally sync`). Only a login syncs: a key from
90
+ // REASONALLY_API_KEY is for scripts and servers.
91
+ const { SyncClient } = await import("../sync/client.js");
92
+ let app = null;
93
+ const sync = new SyncClient({
94
+ configDir: config,
95
+ credentials: () => {
96
+ const current = app?.currentSession ?? session;
97
+ return current && !current.fromEnv
98
+ ? { appUrl: current.appUrl, apiKey: current.apiKey }
99
+ : null;
100
+ },
101
+ client: "cli",
102
+ surface: "terminal",
103
+ appVersion: createRequire(import.meta.url)("../../package.json").version,
104
+ onFirstSync: () => app?.showSyncNotice(),
105
+ });
88
106
  return await new Promise((resolve) => {
89
- let app = null;
90
107
  const quit = (code) => app?.exit(code);
91
108
  const onSignal = () => quit(130);
92
109
  const onCrash = (error) => {
@@ -125,6 +142,7 @@ export async function startTui(args, log) {
125
142
  return next;
126
143
  },
127
144
  rememberModel: (id) => writeLastModel(MODEL_MEMORY_KEY, id),
145
+ sync,
128
146
  onExit: (code, summary) => {
129
147
  if (summary)
130
148
  process.stdout.write(`${summary}\n`);
@@ -137,5 +155,7 @@ export async function startTui(args, log) {
137
155
  });
138
156
  app.start();
139
157
  void mcp?.start();
158
+ // In the background: nothing waits for it, and it goes quiet when it can't sync.
159
+ void sync.start().then(() => sync.backfill([sessions]));
140
160
  });
141
161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reasonally",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Reasonally's coding agent in your terminal, plus the coding agents you already use, on Reasonally models.",
5
5
  "type": "module",
6
6
  "bin": {