chat-recall 0.7.26 → 0.7.29

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/cli.js CHANGED
@@ -28164,7 +28164,7 @@ var init_http = __esm({
28164
28164
  CLI_VERSION = JSON.parse(readFileSync34(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
28165
28165
  } catch {
28166
28166
  try {
28167
- if (true) CLI_VERSION = "0.7.26";
28167
+ if (true) CLI_VERSION = "0.7.29";
28168
28168
  } catch {
28169
28169
  }
28170
28170
  }
@@ -28662,7 +28662,7 @@ var init_telemetry = __esm({
28662
28662
  init_sync_client();
28663
28663
  cliVersion2 = () => {
28664
28664
  try {
28665
- return true ? "0.7.26" : "dev";
28665
+ return true ? "0.7.29" : "dev";
28666
28666
  } catch {
28667
28667
  return "dev";
28668
28668
  }
@@ -31275,7 +31275,7 @@ var init_sync_client = __esm({
31275
31275
  ownVersion = JSON.parse(readFileSync39(join46(dir, "../package.json"), "utf-8")).version || ownVersion;
31276
31276
  } catch {
31277
31277
  try {
31278
- if (true) ownVersion = "0.7.26";
31278
+ if (true) ownVersion = "0.7.29";
31279
31279
  } catch {
31280
31280
  }
31281
31281
  }
@@ -33689,11 +33689,12 @@ function selfIntroduction(sessionId) {
33689
33689
  "Other sessions of this account can send messages here. Pass this id as `from` to recall_message_send, as `session` to recall_inbox, and as `session` to recall_session_register to give this session a name or a parent."
33690
33690
  ].join("\n");
33691
33691
  }
33692
- var MESSAGES_MARKER;
33692
+ var MESSAGES_MARKER, INTERRUPT_MARKER;
33693
33693
  var init_session_messages = __esm({
33694
33694
  "../engine/dist/core/session-messages.js"() {
33695
33695
  "use strict";
33696
33696
  MESSAGES_MARKER = "<!-- chat-recall-messages -->";
33697
+ INTERRUPT_MARKER = "<!-- chat-recall:interrupt -->";
33697
33698
  }
33698
33699
  });
33699
33700
 
@@ -33701,12 +33702,16 @@ var init_session_messages = __esm({
33701
33702
  var message_registration_exports = {};
33702
33703
  __export(message_registration_exports, {
33703
33704
  MESSAGES_ID: () => MESSAGES_ID,
33705
+ OPENCODE_TUI_PACKAGE: () => OPENCODE_TUI_PACKAGE,
33704
33706
  isOurPluginSource: () => isOurPluginSource,
33707
+ isOurTuiSource: () => isOurTuiSource,
33705
33708
  messageCommand: () => messageCommand,
33706
33709
  messageTargets: () => messageTargets,
33707
33710
  messageWrapperName: () => messageWrapperName,
33708
33711
  messageWrapperSource: () => messageWrapperSource,
33709
33712
  opencodeMessagesSource: () => opencodeMessagesSource,
33713
+ opencodeTuiFiles: () => opencodeTuiFiles,
33714
+ opencodeTuiSource: () => opencodeTuiSource,
33710
33715
  piAgentDir: () => piAgentDir2,
33711
33716
  piMessagesSource: () => piMessagesSource,
33712
33717
  registerMessages: () => registerMessages,
@@ -33866,11 +33871,33 @@ function unregisterMessages(tool, config2) {
33866
33871
  function isOurPluginSource(source) {
33867
33872
  return source.includes(`${MESSAGES_ID}: written by`);
33868
33873
  }
33874
+ function isOurTuiSource(source) {
33875
+ return source.startsWith("// Written by `chat-recall install-hooks`");
33876
+ }
33869
33877
  function runnerSource(wrapperPath) {
33870
33878
  return `import { spawn } from "child_process";
33871
33879
 
33872
33880
  const HOOK = ${JSON.stringify(wrapperPath)};
33873
33881
 
33882
+ /**
33883
+ * The process this plugin runs in. The headless service a TUI starts reports
33884
+ * events for the same sessions, so the kind is what tells a coordinator which
33885
+ * row has a window. The first argument is the subcommand ("serve", "run", or
33886
+ * none for the TUI itself).
33887
+ */
33888
+ const KIND = (() => {
33889
+ const args = process.argv.slice(1).filter((a) => !a.startsWith("-"));
33890
+ if (args.includes("serve")) return "serve";
33891
+ if (args[0] === "run") return "run";
33892
+ return undefined;
33893
+ })();
33894
+
33895
+ function payload(sessionId, event, cwd) {
33896
+ const p = { session_id: sessionId, hook_event_name: event, cwd, pid: process.pid };
33897
+ if (KIND) p.kind = KIND;
33898
+ return p;
33899
+ }
33900
+
33874
33901
  function runHook(sessionId, event, cwd) {
33875
33902
  return new Promise((resolve) => {
33876
33903
  let out = "";
@@ -33885,42 +33912,91 @@ function runHook(sessionId, event, cwd) {
33885
33912
  child.stdout.on("data", (c) => { out += c; });
33886
33913
  child.on("error", () => { clearTimeout(done); resolve(""); });
33887
33914
  child.on("close", () => { clearTimeout(done); resolve(out.trim()); });
33888
- child.stdin.end(JSON.stringify({ session_id: sessionId, hook_event_name: event, cwd }));
33915
+ child.stdin.end(JSON.stringify(payload(sessionId, event, cwd)));
33889
33916
  });
33890
33917
  }
33891
33918
 
33892
33919
  /**
33893
33920
  * Wait for a message to an idle session. The hook long-polls the server and
33894
- * prints the messages when one arrives; onText gets them. One waiter per
33895
- * session; stopWaiter ends it when the session gets a prompt.
33921
+ * prints the messages when one arrives; onText gets them. One watcher per
33922
+ * session, owned by this process for as long as the session lives: a turn
33923
+ * starting does not stop it, and a watcher that exits is started again.
33924
+ * --supervised makes the hook say why it stopped (75 ended, 76 another
33925
+ * watcher, 77 not a session to watch) instead of exiting silently.
33896
33926
  */
33897
33927
  const waiters = new Map();
33898
33928
 
33899
33929
  function startWaiter(sessionId, cwd, onText) {
33900
- if (waiters.has(sessionId)) return;
33901
- let out = "";
33902
- let child;
33903
- try {
33904
- child = spawn(HOOK, ["--wait"], { stdio: ["pipe", "pipe", "ignore"] });
33905
- } catch {
33906
- return;
33907
- }
33908
- waiters.set(sessionId, child);
33909
- child.stdout.on("data", (c) => { out += c; });
33910
- child.on("error", () => { waiters.delete(sessionId); });
33911
- child.on("close", () => {
33912
- if (waiters.get(sessionId) === child) waiters.delete(sessionId);
33913
- const text = out.trim();
33914
- if (text) Promise.resolve().then(() => onText(text)).catch(() => {});
33915
- });
33916
- child.stdin.end(JSON.stringify({ session_id: sessionId, hook_event_name: "Stop", cwd }));
33930
+ const running = waiters.get(sessionId);
33931
+ if (running && !running.stopped) return;
33932
+ const rec = { child: null, stopped: false, timer: null, tries: 0 };
33933
+ waiters.set(sessionId, rec);
33934
+ const again = (ms) => {
33935
+ if (rec.stopped) return;
33936
+ clearTimeout(rec.timer);
33937
+ rec.timer = setTimeout(launch, ms);
33938
+ };
33939
+ const launch = () => {
33940
+ if (rec.stopped) return;
33941
+ let out = "";
33942
+ let child;
33943
+ try {
33944
+ child = spawn(HOOK, ["--wait", "--supervised"], { stdio: ["pipe", "pipe", "ignore"] });
33945
+ } catch {
33946
+ again(5000);
33947
+ return;
33948
+ }
33949
+ rec.child = child;
33950
+ child.stdout.on("data", (c) => { out += c; });
33951
+ // The close event follows an error, and carries the exit code.
33952
+ child.on("error", () => {});
33953
+ child.on("close", (code) => {
33954
+ rec.child = null;
33955
+ if (rec.stopped) return;
33956
+ const text = out.trim();
33957
+ if (text) {
33958
+ rec.tries = 0;
33959
+ Promise.resolve().then(() => onText(text)).catch(() => {}).then(() => again(0));
33960
+ return;
33961
+ }
33962
+ // 75: the session ended. 76: another process already waits for it.
33963
+ // 77: not a session the watcher serves. Asking again will not change
33964
+ // any of them, so the next event starts a watcher instead.
33965
+ if (code === 75 || code === 76 || code === 77) { waiters.delete(sessionId); return; }
33966
+ rec.tries += 1;
33967
+ again(Math.min(30000, 250 * 2 ** Math.min(rec.tries, 7)));
33968
+ });
33969
+ child.stdin.end(JSON.stringify({ session_id: sessionId, hook_event_name: "Stop", cwd }));
33970
+ };
33971
+ launch();
33917
33972
  }
33918
33973
 
33919
33974
  function stopWaiter(sessionId) {
33920
- const child = waiters.get(sessionId);
33921
- if (!child) return;
33975
+ const rec = waiters.get(sessionId);
33976
+ if (!rec) return;
33977
+ rec.stopped = true;
33978
+ clearTimeout(rec.timer);
33922
33979
  waiters.delete(sessionId);
33923
- try { child.kill(); } catch { /* gone */ }
33980
+ try { rec.child?.kill(); } catch { /* gone */ }
33981
+ }
33982
+
33983
+ /**
33984
+ * Start watchers for the sessions that were already open when this plugin
33985
+ * loaded. A reload replaces the plugin, so the new instance has no map from
33986
+ * before, and an idle session emits no further event: without this sweep it
33987
+ * would wait forever for a turn it never starts. Only recent sessions, most
33988
+ * recently used first, because the list can hold every session in the folder.
33989
+ */
33990
+ async function watchExisting(ctx, cwd, onTextFor) {
33991
+ try {
33992
+ const r = await ctx.session.list?.({});
33993
+ const list = Array.isArray(r) ? r : (r?.data ?? r?.sessions ?? []);
33994
+ const recent = list
33995
+ .filter((s) => s && s.id && !s.parentID)
33996
+ .sort((a, b) => (b.time?.updated ?? 0) - (a.time?.updated ?? 0))
33997
+ .slice(0, 8);
33998
+ for (const s of recent) startWaiter("opencode_" + s.id, cwd, onTextFor(s.id));
33999
+ } catch { /* an older runtime has no list: events still start watchers */ }
33924
34000
  }
33925
34001
  `;
33926
34002
  }
@@ -33931,11 +34007,25 @@ function opencodeMessagesSource(wrapperPath) {
33931
34007
  // other sessions sent it to the next prompt.
33932
34008
  ${runnerSource(wrapperPath)}
33933
34009
  const RUN_END = new Set(["session.execution.succeeded", "session.execution.failed", "session.execution.interrupted", "session.idle"]);
34010
+ const INTERRUPT = ${JSON.stringify(INTERRUPT_MARKER)};
33934
34011
  const INTRO = ${JSON.stringify(selfIntroduction("\0SESSION\0"))};
33935
34012
  const intro = (id) => INTRO.replace("\0SESSION\0", "opencode_" + id);
33936
34013
 
33937
34014
  async function setup(ctx) {
33938
34015
  const dir = ctx?.location?.directory;
34016
+ // A session of a shared \`opencode serve\` belongs to the folder it was made
34017
+ // in, and that is not this plugin instance's folder: the service sends one
34018
+ // plugin instance the events of every project it serves. Asking the session
34019
+ // is the only source that stays right. The instance's folder is the fallback
34020
+ // for a session that cannot be read (just deleted, or an old server).
34021
+ const dirOf = async (id) => {
34022
+ try {
34023
+ const s = await ctx.session.get({ sessionID: id });
34024
+ const d = s?.location?.directory ?? s?.directory;
34025
+ if (typeof d === "string" && d) return d;
34026
+ } catch { /* unknown session: the instance folder is the best guess */ }
34027
+ return dir;
34028
+ };
33939
34029
  const children = new Set();
33940
34030
  const isChild = async (id) => {
33941
34031
  if (children.has(id)) return true;
@@ -33945,12 +34035,29 @@ async function setup(ctx) {
33945
34035
  } catch { /* unknown: treat as a main session */ }
33946
34036
  return false;
33947
34037
  };
34038
+ // A message becomes a prompt, so an idle session acts on it with nobody
34039
+ // typing. An urgent message stops the turn in progress first.
34040
+ const deliver = (id) => async (text) => {
34041
+ let body = text;
34042
+ if (body.startsWith(INTERRUPT)) {
34043
+ body = body.slice(INTERRUPT.length).replace(/^\\n+/, "");
34044
+ try {
34045
+ if (typeof ctx.session.interrupt === "function") await ctx.session.interrupt({ sessionID: id });
34046
+ else if (typeof ctx.session.abort === "function") await ctx.session.abort({ sessionID: id });
34047
+ } catch { /* the turn was already over */ }
34048
+ await new Promise((r) => setTimeout(r, 250));
34049
+ }
34050
+ await ctx.session.prompt({ sessionID: id, text: body });
34051
+ };
33948
34052
  await ctx.session.hook("prompt", async (event) => {
33949
34053
  const id = event?.sessionID;
33950
34054
  if (!id || !event.prompt || (await isChild(id))) return;
33951
- stopWaiter("opencode_" + id);
34055
+ // The watcher is not stopped for a turn. A message sent while this turn
34056
+ // runs is already in flight to the runtime as the next prompt, and the
34057
+ // hook below catches anything the watcher did not take.
34058
+ startWaiter("opencode_" + id, await dirOf(id), deliver(id));
33952
34059
  // The first prompt registers the session; the hook adds only waiting messages.
33953
- const text = await runHook("opencode_" + id, "UserPromptSubmit", dir);
34060
+ const text = await runHook("opencode_" + id, "UserPromptSubmit", await dirOf(id));
33954
34061
  if (text) event.prompt.text = [event.prompt.text, text].filter(Boolean).join("\\n\\n");
33955
34062
  });
33956
34063
  // The session id goes into the system context of each model call: the agent
@@ -33969,17 +34076,21 @@ async function setup(ctx) {
33969
34076
  // update) is not in started, and still gets its waiter.
33970
34077
  if (!id || (await isChild(id))) continue;
33971
34078
  if (RUN_END.has(ev.type)) {
33972
- await runHook("opencode_" + id, "Stop", dir);
34079
+ const at = await dirOf(id);
34080
+ await runHook("opencode_" + id, "Stop", at);
33973
34081
  // An idle session acts on a message from another session by itself:
33974
34082
  // the text becomes its next prompt.
33975
- startWaiter("opencode_" + id, dir, (text) => ctx.session.prompt({ sessionID: id, text }));
34083
+ startWaiter("opencode_" + id, at, deliver(id));
34084
+ } else if (ev.type === "session.created") {
34085
+ startWaiter("opencode_" + id, await dirOf(id), deliver(id));
33976
34086
  } else if (ev.type === "session.deleted") {
33977
34087
  stopWaiter("opencode_" + id);
33978
- await runHook("opencode_" + id, "SessionEnd", dir);
34088
+ await runHook("opencode_" + id, "SessionEnd", await dirOf(id));
33979
34089
  }
33980
34090
  }
33981
34091
  } catch { /* the subscription ends with the plugin */ }
33982
34092
  })();
34093
+ await watchExisting(ctx, dir, deliver);
33983
34094
  return () => {
33984
34095
  controller.abort();
33985
34096
  for (const id of [...waiters.keys()]) stopWaiter(id);
@@ -34032,12 +34143,203 @@ async function server({ directory }) {
34032
34143
  export default { id: "${MESSAGES_ID}", server, setup };
34033
34144
  `;
34034
34145
  }
34146
+ function opencodeTuiSource(wrapperPath) {
34147
+ return `// Written by \`chat-recall install-hooks\`. Re-running replaces it.
34148
+ //
34149
+ // Registers this opencode TUI with chat-recall before it has a session, so a
34150
+ // message sent to the folder reaches it: the message becomes the TUI's first
34151
+ // session and first prompt. Also reports the session the TUI shows as "tui".
34152
+ import { spawn } from "node:child_process";
34153
+ import { randomBytes } from "node:crypto";
34154
+ import { Plugin } from "@opencode/plugin/tui";
34155
+
34156
+ const HOOK = ${JSON.stringify(wrapperPath)};
34157
+ const PID = process.pid;
34158
+ const POLL_MS = 4000;
34159
+ const RUN_MS = 8000;
34160
+
34161
+ // One state per process, not per module instance. opencode loads this entry
34162
+ // more than once in one TUI process, and a reload keeps the old instance
34163
+ // alive; two instances would each open a presence loop, and the folder would
34164
+ // answer as two windows.
34165
+ const STATE = Symbol.for("chat-recall.tui-plugin");
34166
+ const state = globalThis[STATE] ??= { api: undefined, presence: undefined, timer: undefined, reported: undefined, disposed: false, id: undefined };
34167
+ state.id ??= "tui_" + randomBytes(8).toString("hex");
34168
+
34169
+ /** Run the hook once and return what it printed. */
34170
+ function run(payload, args) {
34171
+ return new Promise((resolve) => {
34172
+ let out = "";
34173
+ let child;
34174
+ try {
34175
+ child = spawn(HOOK, args, { stdio: ["pipe", "pipe", "ignore"] });
34176
+ } catch {
34177
+ resolve("");
34178
+ return;
34179
+ }
34180
+ const done = setTimeout(() => { child.kill(); resolve(""); }, RUN_MS);
34181
+ child.stdout.on("data", (c) => { out += c; });
34182
+ child.on("error", () => { clearTimeout(done); resolve(""); });
34183
+ child.on("close", () => { clearTimeout(done); resolve(out.trim()); });
34184
+ child.stdin.end(JSON.stringify(payload));
34185
+ });
34186
+ }
34187
+
34188
+ function route(api) {
34189
+ try {
34190
+ const r = api.ui.router.current();
34191
+ return r && typeof r === "object" ? r : undefined;
34192
+ } catch {
34193
+ return undefined;
34194
+ }
34195
+ }
34196
+
34197
+ function sessionOf(api) {
34198
+ const r = route(api);
34199
+ return r && r.type === "session" && typeof r.sessionID === "string" ? r.sessionID : undefined;
34200
+ }
34201
+
34202
+ async function report(api, sessionID) {
34203
+ if (!sessionID || sessionID === state.reported) return;
34204
+ state.reported = sessionID;
34205
+ await run({ session_id: "opencode_" + sessionID, cwd: api.location.directory, kind: "tui", pid: PID }, ["--report"]);
34206
+ }
34207
+
34208
+ function stopPresence() {
34209
+ const child = state.presence;
34210
+ state.presence = undefined;
34211
+ if (child) {
34212
+ try { child.kill(); } catch { /* already gone */ }
34213
+ }
34214
+ }
34215
+
34216
+ /**
34217
+ * Register the folder while the TUI shows no session. A message for the folder
34218
+ * arrives on stdout as {"text", "ids"}; the lease expires if this plugin dies
34219
+ * before the prompt lands, and the message is delivered again.
34220
+ */
34221
+ function startPresence(api) {
34222
+ if (state.disposed || state.presence) return;
34223
+ const dir = api.location.directory;
34224
+ let child;
34225
+ try {
34226
+ child = spawn(HOOK, ["--presence"], { stdio: ["pipe", "pipe", "ignore"] });
34227
+ } catch {
34228
+ return;
34229
+ }
34230
+ state.presence = child;
34231
+ let buffer = "";
34232
+ child.stdout.on("data", (chunk) => {
34233
+ buffer += chunk;
34234
+ let i;
34235
+ while ((i = buffer.indexOf("\\n")) >= 0) {
34236
+ const line = buffer.slice(0, i).trim();
34237
+ buffer = buffer.slice(i + 1);
34238
+ if (!line || state.presence !== child) continue;
34239
+ let msg;
34240
+ try { msg = JSON.parse(line); } catch { continue; }
34241
+ stopPresence();
34242
+ openFirst(api, dir, msg).catch(() => {});
34243
+ break;
34244
+ }
34245
+ });
34246
+ child.on("error", () => { if (state.presence === child) state.presence = undefined; });
34247
+ child.on("close", () => { if (state.presence === child) state.presence = undefined; });
34248
+ child.stdin.end(JSON.stringify({ session_id: state.id, cwd: dir, pid: PID }));
34249
+ }
34250
+
34251
+ /** The message becomes the TUI's first session and first prompt. */
34252
+ async function openFirst(api, dir, msg) {
34253
+ const text = typeof msg.text === "string" ? msg.text : "";
34254
+ const ids = Array.isArray(msg.ids) ? msg.ids.filter((i) => typeof i === "string") : [];
34255
+ if (!text) return;
34256
+ let id;
34257
+ try {
34258
+ const created = await api.client.session.create({ title: "chat-recall message", location: { directory: dir } });
34259
+ id = created?.data?.data?.id ?? created?.data?.id ?? created?.id;
34260
+ } catch {
34261
+ return;
34262
+ }
34263
+ if (typeof id !== "string" || !id) return;
34264
+ try { api.ui.router.navigate({ type: "session", sessionID: id }); } catch { /* the route follows the new session */ }
34265
+ await report(api, id);
34266
+ try {
34267
+ await api.client.session.prompt({ sessionID: id, text });
34268
+ } catch {
34269
+ // The session exists but the prompt did not land. Leave the messages
34270
+ // unacknowledged: their lease returns them.
34271
+ return;
34272
+ }
34273
+ if (ids.length) await run({ session_id: state.id, ids }, ["--ack"]);
34274
+ }
34275
+
34276
+ /** Follow the route: report the session it shows, register the folder otherwise. */
34277
+ function tick() {
34278
+ const api = state.api;
34279
+ if (state.disposed || !api) return;
34280
+ const id = sessionOf(api);
34281
+ if (id) {
34282
+ report(api, id).catch(() => {});
34283
+ stopPresence();
34284
+ } else {
34285
+ startPresence(api);
34286
+ }
34287
+ }
34288
+
34289
+ function shutdown() {
34290
+ state.disposed = true;
34291
+ if (state.timer) { clearInterval(state.timer); state.timer = undefined; }
34292
+ stopPresence();
34293
+ }
34294
+
34295
+ export default Plugin.define({
34296
+ id: "chat-recall-tui",
34297
+ async setup(api) {
34298
+ // Only the TUI has a renderer and a route. A headless process that loads
34299
+ // this entry has neither, and must not answer for anyone's folder.
34300
+ if (!api?.renderer || !api?.location?.directory || !api?.ui?.router) return;
34301
+ // A reload after dispose starts a new life on the same process-wide state.
34302
+ if (state.disposed) { state.disposed = false; state.timer = undefined; state.reported = undefined; }
34303
+ state.api = api;
34304
+ tick();
34305
+ if (!state.timer) {
34306
+ state.timer = setInterval(tick, POLL_MS);
34307
+ if (typeof state.timer.unref === "function") state.timer.unref();
34308
+ }
34309
+ try { api.attention?.dispose?.(shutdown); } catch { /* no dispose registry */ }
34310
+ },
34311
+ });
34312
+ `;
34313
+ }
34314
+ function opencodeTuiFiles(wrapperPath) {
34315
+ return [
34316
+ {
34317
+ name: "package.json",
34318
+ source: JSON.stringify({
34319
+ name: OPENCODE_TUI_PACKAGE,
34320
+ private: true,
34321
+ type: "module",
34322
+ exports: { ".": "./index.js", "./tui": "./tui.js" }
34323
+ }, null, 2) + "\n"
34324
+ },
34325
+ {
34326
+ // The package's server entry. The message plugin next to it is the
34327
+ // server plugin; this one only has to exist for the package to load.
34328
+ name: "index.js",
34329
+ source: `// Written by \`chat-recall install-hooks\`. Re-running replaces it.
34330
+ export default { id: "${OPENCODE_TUI_PACKAGE}", setup() {} };
34331
+ `
34332
+ },
34333
+ { name: "tui.js", source: opencodeTuiSource(wrapperPath) }
34334
+ ];
34335
+ }
34035
34336
  function piMessagesSource(wrapperPath) {
34036
34337
  return `// ${MESSAGES_ID}: written by \`chat-recall install-hooks\`. Re-running replaces it.
34037
34338
  //
34038
34339
  // Reports each pi session to chat-recall and adds the messages that other
34039
34340
  // sessions sent it to the next prompt.
34040
34341
  ${runnerSource(wrapperPath)}
34342
+ const INTERRUPT = ${JSON.stringify(INTERRUPT_MARKER)};
34041
34343
  export default function (pi) {
34042
34344
  let pending = "";
34043
34345
  const idOf = (ctx) => "pi_" + ctx.sessionManager.getSessionId();
@@ -34047,7 +34349,6 @@ export default function (pi) {
34047
34349
  pending = await runHook(idOf(ctx), "SessionStart", cwdOf(ctx));
34048
34350
  });
34049
34351
  pi.on("before_agent_start", async (event, ctx) => {
34050
- stopWaiter(idOf(ctx));
34051
34352
  if (event.messageType !== "user") return;
34052
34353
  const now = await runHook(idOf(ctx), "UserPromptSubmit", cwdOf(ctx));
34053
34354
  const text = [pending, now].filter(Boolean).join("\\n\\n");
@@ -34058,7 +34359,10 @@ export default function (pi) {
34058
34359
  pi.on("agent_end", async (_event, ctx) => {
34059
34360
  await runHook(idOf(ctx), "Stop", cwdOf(ctx));
34060
34361
  // An idle session acts on a message from another session by itself.
34061
- startWaiter(idOf(ctx), cwdOf(ctx), (text) => pi.sendUserMessage(text));
34362
+ startWaiter(idOf(ctx), cwdOf(ctx), (text) => {
34363
+ const body = text.startsWith(INTERRUPT) ? text.slice(INTERRUPT.length).replace(/^\\n+/, "") : text;
34364
+ pi.sendUserMessage(body);
34365
+ });
34062
34366
  });
34063
34367
  pi.on("session_shutdown", async (_event, ctx) => {
34064
34368
  stopWaiter(idOf(ctx));
@@ -34067,7 +34371,7 @@ export default function (pi) {
34067
34371
  }
34068
34372
  `;
34069
34373
  }
34070
- var MESSAGES_ID, TIMEOUT_SECS2, isOurs2, asArray3, obj, CODEX_EVENTS, CURSOR_EVENTS;
34374
+ var MESSAGES_ID, TIMEOUT_SECS2, isOurs2, asArray3, obj, CODEX_EVENTS, CURSOR_EVENTS, OPENCODE_TUI_PACKAGE;
34071
34375
  var init_message_registration = __esm({
34072
34376
  "../engine/dist/core/message-registration.js"() {
34073
34377
  "use strict";
@@ -34081,6 +34385,7 @@ var init_message_registration = __esm({
34081
34385
  obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? { ...v } : {};
34082
34386
  CODEX_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop", "SessionEnd"];
34083
34387
  CURSOR_EVENTS = ["sessionStart", "beforeSubmitPrompt", "stop", "sessionEnd"];
34388
+ OPENCODE_TUI_PACKAGE = "chat-recall-tui";
34084
34389
  }
34085
34390
  });
34086
34391
 
@@ -34098,7 +34403,7 @@ __export(install_hooks_exports, {
34098
34403
  removeOurEntries: () => removeOurEntries,
34099
34404
  uninstallHooks: () => uninstallHooks
34100
34405
  });
34101
- import { chmodSync as chmodSync5, copyFileSync as copyFileSync3, existsSync as existsSync52, mkdirSync as mkdirSync17, readFileSync as readFileSync46, realpathSync as realpathSync6, renameSync as renameSync6, unlinkSync as unlinkSync4, writeFileSync as writeFileSync17 } from "node:fs";
34406
+ import { chmodSync as chmodSync5, copyFileSync as copyFileSync3, existsSync as existsSync52, mkdirSync as mkdirSync17, readFileSync as readFileSync46, realpathSync as realpathSync6, renameSync as renameSync6, rmSync as rmSync10, unlinkSync as unlinkSync4, writeFileSync as writeFileSync17 } from "node:fs";
34102
34407
  import { dirname as dirname24, join as join59 } from "node:path";
34103
34408
  function isOurEntry(entry) {
34104
34409
  const cmd = entry?.hooks?.[0]?.command;
@@ -34352,6 +34657,9 @@ async function addMessagesToOtherTools(scriptsDir, nodePath, hookEntry) {
34352
34657
  mkdirSync17(dirname24(target.configPath), { recursive: true });
34353
34658
  if (target.tool === "opencode") {
34354
34659
  writeFileSync17(target.configPath, reg.opencodeMessagesSource(wrapper));
34660
+ const dir = join59(dirname24(target.configPath), reg.OPENCODE_TUI_PACKAGE);
34661
+ mkdirSync17(dir, { recursive: true });
34662
+ for (const file of reg.opencodeTuiFiles(wrapper)) writeFileSync17(join59(dir, file.name), file.source);
34355
34663
  } else if (target.tool === "pi") {
34356
34664
  writeFileSync17(target.configPath, reg.piMessagesSource(wrapper));
34357
34665
  } else {
@@ -34371,6 +34679,11 @@ async function removeMessagesFromOtherTools() {
34371
34679
  if (target.tool === "opencode" || target.tool === "pi") {
34372
34680
  if (!reg.isOurPluginSource(readFileSync46(target.configPath, "utf-8"))) continue;
34373
34681
  unlinkSync4(target.configPath);
34682
+ if (target.tool === "opencode") {
34683
+ const dir = join59(dirname24(target.configPath), reg.OPENCODE_TUI_PACKAGE);
34684
+ const tui = join59(dir, "tui.js");
34685
+ if (existsSync52(tui) && reg.isOurTuiSource(readFileSync46(tui, "utf-8"))) rmSync10(dir, { recursive: true, force: true });
34686
+ }
34374
34687
  } else {
34375
34688
  const config2 = readJson4(target.configPath);
34376
34689
  if (!config2) continue;
@@ -36416,7 +36729,7 @@ var init_intent_drain = __esm({
36416
36729
  ownVersion2 = JSON.parse(readFileSync49(join62(dir, "../package.json"), "utf-8")).version || ownVersion2;
36417
36730
  } catch {
36418
36731
  try {
36419
- if (true) ownVersion2 = "0.7.26";
36732
+ if (true) ownVersion2 = "0.7.29";
36420
36733
  } catch {
36421
36734
  }
36422
36735
  }
@@ -36617,7 +36930,7 @@ var team_merge_exports = {};
36617
36930
  __export(team_merge_exports, {
36618
36931
  mergePullResult: () => mergePullResult
36619
36932
  });
36620
- import { existsSync as existsSync56, mkdirSync as mkdirSync20, readFileSync as readFileSync50, rmSync as rmSync10, writeFileSync as writeFileSync20, statSync as statSync47 } from "fs";
36933
+ import { existsSync as existsSync56, mkdirSync as mkdirSync20, readFileSync as readFileSync50, rmSync as rmSync11, writeFileSync as writeFileSync20, statSync as statSync47 } from "fs";
36621
36934
  import { dirname as dirname27, join as join63 } from "path";
36622
36935
  import { createHash as createHash15 } from "crypto";
36623
36936
  function installPathFor(art, tool) {
@@ -36735,7 +37048,7 @@ async function mergePullResult(opts) {
36735
37048
  continue;
36736
37049
  try {
36737
37050
  if (existsSync56(path))
36738
- rmSync10(path, { force: true });
37051
+ rmSync11(path, { force: true });
36739
37052
  await teamInstallsForget(id, row.tool);
36740
37053
  report.removed.push({ artifactId: id, path });
36741
37054
  } catch (err) {
@@ -37845,7 +38158,7 @@ __export(service_installer_exports, {
37845
38158
  uninstallService: () => uninstallService
37846
38159
  });
37847
38160
  import { execSync as execSync5 } from "child_process";
37848
- import { existsSync as existsSync59, mkdirSync as mkdirSync22, readFileSync as readFileSync52, rmSync as rmSync11, writeFileSync as writeFileSync22 } from "fs";
38161
+ import { existsSync as existsSync59, mkdirSync as mkdirSync22, readFileSync as readFileSync52, rmSync as rmSync12, writeFileSync as writeFileSync22 } from "fs";
37849
38162
  import { homedir as homedir24 } from "os";
37850
38163
  import { join as join66 } from "path";
37851
38164
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -38057,7 +38370,7 @@ function uninstallService() {
38057
38370
  }
38058
38371
  const unitPath = join66(homedir24(), ".config", "systemd", "user", "chat-recall-watch.service");
38059
38372
  if (existsSync59(unitPath)) {
38060
- rmSync11(unitPath, { force: true });
38373
+ rmSync12(unitPath, { force: true });
38061
38374
  removed = true;
38062
38375
  }
38063
38376
  try {
@@ -38074,7 +38387,7 @@ function uninstallService() {
38074
38387
  }
38075
38388
  let removed = false;
38076
38389
  if (existsSync59(plistPath)) {
38077
- rmSync11(plistPath, { force: true });
38390
+ rmSync12(plistPath, { force: true });
38078
38391
  removed = true;
38079
38392
  }
38080
38393
  return removed;
@@ -39892,11 +40205,11 @@ program.command("doctor").description("Quick health check across login, server,
39892
40205
  } else if (legacyPresent.length === 0) {
39893
40206
  note(true, "Purge legacy index", "nothing to remove");
39894
40207
  } else {
39895
- const { rmSync: rmSync12 } = await import("fs");
40208
+ const { rmSync: rmSync13 } = await import("fs");
39896
40209
  let removed = 0;
39897
40210
  for (const p of legacyPresent) {
39898
40211
  try {
39899
- rmSync12(p, { recursive: true, force: true });
40212
+ rmSync13(p, { recursive: true, force: true });
39900
40213
  removed++;
39901
40214
  } catch {
39902
40215
  }
@@ -17,7 +17,7 @@
17
17
  * `install-hooks --uninstall` records the choice, and the MCP server then
18
18
  * leaves the hooks out.
19
19
  */
20
- import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
20
+ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';
21
21
  import { dirname, join } from 'node:path';
22
22
  import { getHooksDir } from '@chat-recall/engine/core/paths.js';
23
23
  import { claudeBackend } from '@chat-recall/engine/core/backends/claude.js';
@@ -383,6 +383,12 @@ async function addMessagesToOtherTools(scriptsDir, nodePath, hookEntry) {
383
383
  mkdirSync(dirname(target.configPath), { recursive: true });
384
384
  if (target.tool === 'opencode') {
385
385
  writeFileSync(target.configPath, reg.opencodeMessagesSource(wrapper));
386
+ // The TUI plugin is a package next to the file: opencode loads its
387
+ // server entry and its "./tui" entry from the package.json exports.
388
+ const dir = join(dirname(target.configPath), reg.OPENCODE_TUI_PACKAGE);
389
+ mkdirSync(dir, { recursive: true });
390
+ for (const file of reg.opencodeTuiFiles(wrapper))
391
+ writeFileSync(join(dir, file.name), file.source);
386
392
  }
387
393
  else if (target.tool === 'pi') {
388
394
  writeFileSync(target.configPath, reg.piMessagesSource(wrapper));
@@ -407,6 +413,14 @@ async function removeMessagesFromOtherTools() {
407
413
  if (!reg.isOurPluginSource(readFileSync(target.configPath, 'utf-8')))
408
414
  continue;
409
415
  unlinkSync(target.configPath);
416
+ if (target.tool === 'opencode') {
417
+ // Only a package we wrote goes: the marker is on the first line of the
418
+ // TUI entry, and a folder without it is someone else's plugin.
419
+ const dir = join(dirname(target.configPath), reg.OPENCODE_TUI_PACKAGE);
420
+ const tui = join(dir, 'tui.js');
421
+ if (existsSync(tui) && reg.isOurTuiSource(readFileSync(tui, 'utf-8')))
422
+ rmSync(dir, { recursive: true, force: true });
423
+ }
410
424
  }
411
425
  else {
412
426
  const config = readJson(target.configPath);