chat-recall 0.7.25 → 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/board-hooks.d.ts +21 -0
- package/dist/board-hooks.d.ts.map +1 -1
- package/dist/board-hooks.js +28 -1
- package/dist/board-hooks.js.map +1 -1
- package/dist/channel-detect.d.ts +28 -0
- package/dist/channel-detect.d.ts.map +1 -0
- package/dist/channel-detect.js +128 -0
- package/dist/channel-detect.js.map +1 -0
- package/dist/channel-state.d.ts +35 -0
- package/dist/channel-state.d.ts.map +1 -0
- package/dist/channel-state.js +192 -0
- package/dist/channel-state.js.map +1 -0
- package/dist/channel.d.ts +71 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +157 -0
- package/dist/channel.js.map +1 -0
- package/dist/cli.js +370 -47
- package/dist/install-hooks.js +17 -3
- package/dist/install-hooks.js.map +1 -1
- package/dist/mcp-relay.js +73 -1
- package/dist/mcp-relay.js.map +1 -1
- package/dist/mcp.js +1095 -390
- package/dist/mcp.js.map +1 -1
- package/dist/message-hook-core.d.ts +14 -1
- package/dist/message-hook-core.d.ts.map +1 -1
- package/dist/message-hook-core.js +14 -1
- package/dist/message-hook-core.js.map +1 -1
- package/dist/message-hook.js +275 -35
- package/dist/message-hook.js.map +1 -1
- package/dist/watch.js +5 -5
- package/package.json +1 -1
- package/skills/chat-recall-sessions/SKILL.md +25 -2
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.
|
|
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.
|
|
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.
|
|
31278
|
+
if (true) ownVersion = "0.7.29";
|
|
31279
31279
|
} catch {
|
|
31280
31280
|
}
|
|
31281
31281
|
}
|
|
@@ -33371,9 +33371,11 @@ __export(board_hooks_exports, {
|
|
|
33371
33371
|
BOARD_HOOKS: () => BOARD_HOOKS,
|
|
33372
33372
|
MESSAGE_HOOK_EVENTS: () => MESSAGE_HOOK_EVENTS,
|
|
33373
33373
|
MESSAGE_WAITER_EVENTS: () => MESSAGE_WAITER_EVENTS,
|
|
33374
|
+
MESSAGE_WAITER_TIMEOUT_SECONDS: () => MESSAGE_WAITER_TIMEOUT_SECONDS,
|
|
33374
33375
|
boardHookCommand: () => boardHookCommand,
|
|
33375
33376
|
boardHookEntries: () => boardHookEntries,
|
|
33376
33377
|
isBoardHookEntry: () => isBoardHookEntry,
|
|
33378
|
+
isCurrentMessageWaiterEntry: () => isCurrentMessageWaiterEntry,
|
|
33377
33379
|
isMessageHookEntry: () => isMessageHookEntry,
|
|
33378
33380
|
isMessageWaiterEntry: () => isMessageWaiterEntry,
|
|
33379
33381
|
messageHookCommand: () => messageHookCommand,
|
|
@@ -33412,12 +33414,19 @@ function isMessageHookEntry(entry) {
|
|
|
33412
33414
|
function isMessageWaiterEntry(entry) {
|
|
33413
33415
|
return isMessageHookEntry(entry) && /--wait$/.test(entryCommand(entry).trim());
|
|
33414
33416
|
}
|
|
33417
|
+
function isCurrentMessageWaiterEntry(entry) {
|
|
33418
|
+
if (!isMessageWaiterEntry(entry)) return false;
|
|
33419
|
+
return entry.hooks?.[0]?.timeout === MESSAGE_WAITER_TIMEOUT_SECONDS;
|
|
33420
|
+
}
|
|
33415
33421
|
function messageHookEntries(execPath, hookEntry) {
|
|
33416
33422
|
const turn = messageHookCommand(execPath, hookEntry);
|
|
33417
33423
|
const waiter = messageHookCommand(execPath, hookEntry, true);
|
|
33418
33424
|
return [
|
|
33419
33425
|
...MESSAGE_HOOK_EVENTS.map((event) => [event, { matcher: "", hooks: [{ type: "command", command: turn }] }]),
|
|
33420
|
-
...MESSAGE_WAITER_EVENTS.map((event) => [event, {
|
|
33426
|
+
...MESSAGE_WAITER_EVENTS.map((event) => [event, {
|
|
33427
|
+
matcher: "",
|
|
33428
|
+
hooks: [{ type: "command", command: waiter, asyncRewake: true, timeout: MESSAGE_WAITER_TIMEOUT_SECONDS }]
|
|
33429
|
+
}])
|
|
33421
33430
|
];
|
|
33422
33431
|
}
|
|
33423
33432
|
function resolveCliEntry(distDir) {
|
|
@@ -33428,7 +33437,7 @@ function resolveMessageHookEntry(distDir) {
|
|
|
33428
33437
|
const bundled = join56(distDir, "message-hook.js");
|
|
33429
33438
|
return existsSync51(bundled) ? bundled : join56(distDir, "message-hook.ts");
|
|
33430
33439
|
}
|
|
33431
|
-
var BOARD_HOOKS, MESSAGE_HOOK_EVENTS, MESSAGE_WAITER_EVENTS;
|
|
33440
|
+
var BOARD_HOOKS, MESSAGE_HOOK_EVENTS, MESSAGE_WAITER_EVENTS, MESSAGE_WAITER_TIMEOUT_SECONDS;
|
|
33432
33441
|
var init_board_hooks = __esm({
|
|
33433
33442
|
"src/board-hooks.ts"() {
|
|
33434
33443
|
"use strict";
|
|
@@ -33438,6 +33447,7 @@ var init_board_hooks = __esm({
|
|
|
33438
33447
|
];
|
|
33439
33448
|
MESSAGE_HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop", "SessionEnd"];
|
|
33440
33449
|
MESSAGE_WAITER_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop"];
|
|
33450
|
+
MESSAGE_WAITER_TIMEOUT_SECONDS = 86400;
|
|
33441
33451
|
}
|
|
33442
33452
|
});
|
|
33443
33453
|
|
|
@@ -33679,11 +33689,12 @@ function selfIntroduction(sessionId) {
|
|
|
33679
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."
|
|
33680
33690
|
].join("\n");
|
|
33681
33691
|
}
|
|
33682
|
-
var MESSAGES_MARKER;
|
|
33692
|
+
var MESSAGES_MARKER, INTERRUPT_MARKER;
|
|
33683
33693
|
var init_session_messages = __esm({
|
|
33684
33694
|
"../engine/dist/core/session-messages.js"() {
|
|
33685
33695
|
"use strict";
|
|
33686
33696
|
MESSAGES_MARKER = "<!-- chat-recall-messages -->";
|
|
33697
|
+
INTERRUPT_MARKER = "<!-- chat-recall:interrupt -->";
|
|
33687
33698
|
}
|
|
33688
33699
|
});
|
|
33689
33700
|
|
|
@@ -33691,12 +33702,16 @@ var init_session_messages = __esm({
|
|
|
33691
33702
|
var message_registration_exports = {};
|
|
33692
33703
|
__export(message_registration_exports, {
|
|
33693
33704
|
MESSAGES_ID: () => MESSAGES_ID,
|
|
33705
|
+
OPENCODE_TUI_PACKAGE: () => OPENCODE_TUI_PACKAGE,
|
|
33694
33706
|
isOurPluginSource: () => isOurPluginSource,
|
|
33707
|
+
isOurTuiSource: () => isOurTuiSource,
|
|
33695
33708
|
messageCommand: () => messageCommand,
|
|
33696
33709
|
messageTargets: () => messageTargets,
|
|
33697
33710
|
messageWrapperName: () => messageWrapperName,
|
|
33698
33711
|
messageWrapperSource: () => messageWrapperSource,
|
|
33699
33712
|
opencodeMessagesSource: () => opencodeMessagesSource,
|
|
33713
|
+
opencodeTuiFiles: () => opencodeTuiFiles,
|
|
33714
|
+
opencodeTuiSource: () => opencodeTuiSource,
|
|
33700
33715
|
piAgentDir: () => piAgentDir2,
|
|
33701
33716
|
piMessagesSource: () => piMessagesSource,
|
|
33702
33717
|
registerMessages: () => registerMessages,
|
|
@@ -33856,11 +33871,33 @@ function unregisterMessages(tool, config2) {
|
|
|
33856
33871
|
function isOurPluginSource(source) {
|
|
33857
33872
|
return source.includes(`${MESSAGES_ID}: written by`);
|
|
33858
33873
|
}
|
|
33874
|
+
function isOurTuiSource(source) {
|
|
33875
|
+
return source.startsWith("// Written by `chat-recall install-hooks`");
|
|
33876
|
+
}
|
|
33859
33877
|
function runnerSource(wrapperPath) {
|
|
33860
33878
|
return `import { spawn } from "child_process";
|
|
33861
33879
|
|
|
33862
33880
|
const HOOK = ${JSON.stringify(wrapperPath)};
|
|
33863
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
|
+
|
|
33864
33901
|
function runHook(sessionId, event, cwd) {
|
|
33865
33902
|
return new Promise((resolve) => {
|
|
33866
33903
|
let out = "";
|
|
@@ -33875,42 +33912,91 @@ function runHook(sessionId, event, cwd) {
|
|
|
33875
33912
|
child.stdout.on("data", (c) => { out += c; });
|
|
33876
33913
|
child.on("error", () => { clearTimeout(done); resolve(""); });
|
|
33877
33914
|
child.on("close", () => { clearTimeout(done); resolve(out.trim()); });
|
|
33878
|
-
child.stdin.end(JSON.stringify(
|
|
33915
|
+
child.stdin.end(JSON.stringify(payload(sessionId, event, cwd)));
|
|
33879
33916
|
});
|
|
33880
33917
|
}
|
|
33881
33918
|
|
|
33882
33919
|
/**
|
|
33883
33920
|
* Wait for a message to an idle session. The hook long-polls the server and
|
|
33884
|
-
* prints the messages when one arrives; onText gets them. One
|
|
33885
|
-
* session
|
|
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.
|
|
33886
33926
|
*/
|
|
33887
33927
|
const waiters = new Map();
|
|
33888
33928
|
|
|
33889
33929
|
function startWaiter(sessionId, cwd, onText) {
|
|
33890
|
-
|
|
33891
|
-
|
|
33892
|
-
|
|
33893
|
-
|
|
33894
|
-
|
|
33895
|
-
|
|
33896
|
-
|
|
33897
|
-
|
|
33898
|
-
|
|
33899
|
-
|
|
33900
|
-
|
|
33901
|
-
|
|
33902
|
-
|
|
33903
|
-
|
|
33904
|
-
|
|
33905
|
-
|
|
33906
|
-
|
|
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();
|
|
33907
33972
|
}
|
|
33908
33973
|
|
|
33909
33974
|
function stopWaiter(sessionId) {
|
|
33910
|
-
const
|
|
33911
|
-
if (!
|
|
33975
|
+
const rec = waiters.get(sessionId);
|
|
33976
|
+
if (!rec) return;
|
|
33977
|
+
rec.stopped = true;
|
|
33978
|
+
clearTimeout(rec.timer);
|
|
33912
33979
|
waiters.delete(sessionId);
|
|
33913
|
-
try { child
|
|
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 */ }
|
|
33914
34000
|
}
|
|
33915
34001
|
`;
|
|
33916
34002
|
}
|
|
@@ -33921,11 +34007,25 @@ function opencodeMessagesSource(wrapperPath) {
|
|
|
33921
34007
|
// other sessions sent it to the next prompt.
|
|
33922
34008
|
${runnerSource(wrapperPath)}
|
|
33923
34009
|
const RUN_END = new Set(["session.execution.succeeded", "session.execution.failed", "session.execution.interrupted", "session.idle"]);
|
|
34010
|
+
const INTERRUPT = ${JSON.stringify(INTERRUPT_MARKER)};
|
|
33924
34011
|
const INTRO = ${JSON.stringify(selfIntroduction("\0SESSION\0"))};
|
|
33925
34012
|
const intro = (id) => INTRO.replace("\0SESSION\0", "opencode_" + id);
|
|
33926
34013
|
|
|
33927
34014
|
async function setup(ctx) {
|
|
33928
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
|
+
};
|
|
33929
34029
|
const children = new Set();
|
|
33930
34030
|
const isChild = async (id) => {
|
|
33931
34031
|
if (children.has(id)) return true;
|
|
@@ -33935,12 +34035,29 @@ async function setup(ctx) {
|
|
|
33935
34035
|
} catch { /* unknown: treat as a main session */ }
|
|
33936
34036
|
return false;
|
|
33937
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
|
+
};
|
|
33938
34052
|
await ctx.session.hook("prompt", async (event) => {
|
|
33939
34053
|
const id = event?.sessionID;
|
|
33940
34054
|
if (!id || !event.prompt || (await isChild(id))) return;
|
|
33941
|
-
|
|
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));
|
|
33942
34059
|
// The first prompt registers the session; the hook adds only waiting messages.
|
|
33943
|
-
const text = await runHook("opencode_" + id, "UserPromptSubmit",
|
|
34060
|
+
const text = await runHook("opencode_" + id, "UserPromptSubmit", await dirOf(id));
|
|
33944
34061
|
if (text) event.prompt.text = [event.prompt.text, text].filter(Boolean).join("\\n\\n");
|
|
33945
34062
|
});
|
|
33946
34063
|
// The session id goes into the system context of each model call: the agent
|
|
@@ -33959,17 +34076,21 @@ async function setup(ctx) {
|
|
|
33959
34076
|
// update) is not in started, and still gets its waiter.
|
|
33960
34077
|
if (!id || (await isChild(id))) continue;
|
|
33961
34078
|
if (RUN_END.has(ev.type)) {
|
|
33962
|
-
await
|
|
34079
|
+
const at = await dirOf(id);
|
|
34080
|
+
await runHook("opencode_" + id, "Stop", at);
|
|
33963
34081
|
// An idle session acts on a message from another session by itself:
|
|
33964
34082
|
// the text becomes its next prompt.
|
|
33965
|
-
startWaiter("opencode_" + id,
|
|
34083
|
+
startWaiter("opencode_" + id, at, deliver(id));
|
|
34084
|
+
} else if (ev.type === "session.created") {
|
|
34085
|
+
startWaiter("opencode_" + id, await dirOf(id), deliver(id));
|
|
33966
34086
|
} else if (ev.type === "session.deleted") {
|
|
33967
34087
|
stopWaiter("opencode_" + id);
|
|
33968
|
-
await runHook("opencode_" + id, "SessionEnd",
|
|
34088
|
+
await runHook("opencode_" + id, "SessionEnd", await dirOf(id));
|
|
33969
34089
|
}
|
|
33970
34090
|
}
|
|
33971
34091
|
} catch { /* the subscription ends with the plugin */ }
|
|
33972
34092
|
})();
|
|
34093
|
+
await watchExisting(ctx, dir, deliver);
|
|
33973
34094
|
return () => {
|
|
33974
34095
|
controller.abort();
|
|
33975
34096
|
for (const id of [...waiters.keys()]) stopWaiter(id);
|
|
@@ -34022,12 +34143,203 @@ async function server({ directory }) {
|
|
|
34022
34143
|
export default { id: "${MESSAGES_ID}", server, setup };
|
|
34023
34144
|
`;
|
|
34024
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
|
+
}
|
|
34025
34336
|
function piMessagesSource(wrapperPath) {
|
|
34026
34337
|
return `// ${MESSAGES_ID}: written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
34027
34338
|
//
|
|
34028
34339
|
// Reports each pi session to chat-recall and adds the messages that other
|
|
34029
34340
|
// sessions sent it to the next prompt.
|
|
34030
34341
|
${runnerSource(wrapperPath)}
|
|
34342
|
+
const INTERRUPT = ${JSON.stringify(INTERRUPT_MARKER)};
|
|
34031
34343
|
export default function (pi) {
|
|
34032
34344
|
let pending = "";
|
|
34033
34345
|
const idOf = (ctx) => "pi_" + ctx.sessionManager.getSessionId();
|
|
@@ -34037,7 +34349,6 @@ export default function (pi) {
|
|
|
34037
34349
|
pending = await runHook(idOf(ctx), "SessionStart", cwdOf(ctx));
|
|
34038
34350
|
});
|
|
34039
34351
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
34040
|
-
stopWaiter(idOf(ctx));
|
|
34041
34352
|
if (event.messageType !== "user") return;
|
|
34042
34353
|
const now = await runHook(idOf(ctx), "UserPromptSubmit", cwdOf(ctx));
|
|
34043
34354
|
const text = [pending, now].filter(Boolean).join("\\n\\n");
|
|
@@ -34048,7 +34359,10 @@ export default function (pi) {
|
|
|
34048
34359
|
pi.on("agent_end", async (_event, ctx) => {
|
|
34049
34360
|
await runHook(idOf(ctx), "Stop", cwdOf(ctx));
|
|
34050
34361
|
// An idle session acts on a message from another session by itself.
|
|
34051
|
-
startWaiter(idOf(ctx), cwdOf(ctx), (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
|
+
});
|
|
34052
34366
|
});
|
|
34053
34367
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
34054
34368
|
stopWaiter(idOf(ctx));
|
|
@@ -34057,7 +34371,7 @@ export default function (pi) {
|
|
|
34057
34371
|
}
|
|
34058
34372
|
`;
|
|
34059
34373
|
}
|
|
34060
|
-
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;
|
|
34061
34375
|
var init_message_registration = __esm({
|
|
34062
34376
|
"../engine/dist/core/message-registration.js"() {
|
|
34063
34377
|
"use strict";
|
|
@@ -34071,6 +34385,7 @@ var init_message_registration = __esm({
|
|
|
34071
34385
|
obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? { ...v } : {};
|
|
34072
34386
|
CODEX_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop", "SessionEnd"];
|
|
34073
34387
|
CURSOR_EVENTS = ["sessionStart", "beforeSubmitPrompt", "stop", "sessionEnd"];
|
|
34388
|
+
OPENCODE_TUI_PACKAGE = "chat-recall-tui";
|
|
34074
34389
|
}
|
|
34075
34390
|
});
|
|
34076
34391
|
|
|
@@ -34088,7 +34403,7 @@ __export(install_hooks_exports, {
|
|
|
34088
34403
|
removeOurEntries: () => removeOurEntries,
|
|
34089
34404
|
uninstallHooks: () => uninstallHooks
|
|
34090
34405
|
});
|
|
34091
|
-
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";
|
|
34092
34407
|
import { dirname as dirname24, join as join59 } from "node:path";
|
|
34093
34408
|
function isOurEntry(entry) {
|
|
34094
34409
|
const cmd = entry?.hooks?.[0]?.command;
|
|
@@ -34274,7 +34589,7 @@ function profileMissingHooks(settingsFile, sel) {
|
|
|
34274
34589
|
const config2 = readJson4(settingsFile);
|
|
34275
34590
|
if (!config2) return false;
|
|
34276
34591
|
const has = (event, test) => (Array.isArray(config2.hooks?.[event]) ? config2.hooks[event] : []).some(test);
|
|
34277
|
-
if (sel.messages && !(has("Stop",
|
|
34592
|
+
if (sel.messages && !(has("Stop", isCurrentMessageWaiterEntry) && has("SessionStart", isMessageHookEntry))) return true;
|
|
34278
34593
|
if (sel.taskBoard && !has("UserPromptSubmit", isBoardHookEntry)) return true;
|
|
34279
34594
|
if (process.platform !== "win32" && sel.save && !has("Stop", (e) => isOurEntry(e) && !isMessageHookEntry(e))) return true;
|
|
34280
34595
|
return false;
|
|
@@ -34342,6 +34657,9 @@ async function addMessagesToOtherTools(scriptsDir, nodePath, hookEntry) {
|
|
|
34342
34657
|
mkdirSync17(dirname24(target.configPath), { recursive: true });
|
|
34343
34658
|
if (target.tool === "opencode") {
|
|
34344
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);
|
|
34345
34663
|
} else if (target.tool === "pi") {
|
|
34346
34664
|
writeFileSync17(target.configPath, reg.piMessagesSource(wrapper));
|
|
34347
34665
|
} else {
|
|
@@ -34361,6 +34679,11 @@ async function removeMessagesFromOtherTools() {
|
|
|
34361
34679
|
if (target.tool === "opencode" || target.tool === "pi") {
|
|
34362
34680
|
if (!reg.isOurPluginSource(readFileSync46(target.configPath, "utf-8"))) continue;
|
|
34363
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
|
+
}
|
|
34364
34687
|
} else {
|
|
34365
34688
|
const config2 = readJson4(target.configPath);
|
|
34366
34689
|
if (!config2) continue;
|
|
@@ -36406,7 +36729,7 @@ var init_intent_drain = __esm({
|
|
|
36406
36729
|
ownVersion2 = JSON.parse(readFileSync49(join62(dir, "../package.json"), "utf-8")).version || ownVersion2;
|
|
36407
36730
|
} catch {
|
|
36408
36731
|
try {
|
|
36409
|
-
if (true) ownVersion2 = "0.7.
|
|
36732
|
+
if (true) ownVersion2 = "0.7.29";
|
|
36410
36733
|
} catch {
|
|
36411
36734
|
}
|
|
36412
36735
|
}
|
|
@@ -36607,7 +36930,7 @@ var team_merge_exports = {};
|
|
|
36607
36930
|
__export(team_merge_exports, {
|
|
36608
36931
|
mergePullResult: () => mergePullResult
|
|
36609
36932
|
});
|
|
36610
|
-
import { existsSync as existsSync56, mkdirSync as mkdirSync20, readFileSync as readFileSync50, rmSync as
|
|
36933
|
+
import { existsSync as existsSync56, mkdirSync as mkdirSync20, readFileSync as readFileSync50, rmSync as rmSync11, writeFileSync as writeFileSync20, statSync as statSync47 } from "fs";
|
|
36611
36934
|
import { dirname as dirname27, join as join63 } from "path";
|
|
36612
36935
|
import { createHash as createHash15 } from "crypto";
|
|
36613
36936
|
function installPathFor(art, tool) {
|
|
@@ -36725,7 +37048,7 @@ async function mergePullResult(opts) {
|
|
|
36725
37048
|
continue;
|
|
36726
37049
|
try {
|
|
36727
37050
|
if (existsSync56(path))
|
|
36728
|
-
|
|
37051
|
+
rmSync11(path, { force: true });
|
|
36729
37052
|
await teamInstallsForget(id, row.tool);
|
|
36730
37053
|
report.removed.push({ artifactId: id, path });
|
|
36731
37054
|
} catch (err) {
|
|
@@ -37835,7 +38158,7 @@ __export(service_installer_exports, {
|
|
|
37835
38158
|
uninstallService: () => uninstallService
|
|
37836
38159
|
});
|
|
37837
38160
|
import { execSync as execSync5 } from "child_process";
|
|
37838
|
-
import { existsSync as existsSync59, mkdirSync as mkdirSync22, readFileSync as readFileSync52, rmSync as
|
|
38161
|
+
import { existsSync as existsSync59, mkdirSync as mkdirSync22, readFileSync as readFileSync52, rmSync as rmSync12, writeFileSync as writeFileSync22 } from "fs";
|
|
37839
38162
|
import { homedir as homedir24 } from "os";
|
|
37840
38163
|
import { join as join66 } from "path";
|
|
37841
38164
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -38047,7 +38370,7 @@ function uninstallService() {
|
|
|
38047
38370
|
}
|
|
38048
38371
|
const unitPath = join66(homedir24(), ".config", "systemd", "user", "chat-recall-watch.service");
|
|
38049
38372
|
if (existsSync59(unitPath)) {
|
|
38050
|
-
|
|
38373
|
+
rmSync12(unitPath, { force: true });
|
|
38051
38374
|
removed = true;
|
|
38052
38375
|
}
|
|
38053
38376
|
try {
|
|
@@ -38064,7 +38387,7 @@ function uninstallService() {
|
|
|
38064
38387
|
}
|
|
38065
38388
|
let removed = false;
|
|
38066
38389
|
if (existsSync59(plistPath)) {
|
|
38067
|
-
|
|
38390
|
+
rmSync12(plistPath, { force: true });
|
|
38068
38391
|
removed = true;
|
|
38069
38392
|
}
|
|
38070
38393
|
return removed;
|
|
@@ -39882,11 +40205,11 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39882
40205
|
} else if (legacyPresent.length === 0) {
|
|
39883
40206
|
note(true, "Purge legacy index", "nothing to remove");
|
|
39884
40207
|
} else {
|
|
39885
|
-
const { rmSync:
|
|
40208
|
+
const { rmSync: rmSync13 } = await import("fs");
|
|
39886
40209
|
let removed = 0;
|
|
39887
40210
|
for (const p of legacyPresent) {
|
|
39888
40211
|
try {
|
|
39889
|
-
|
|
40212
|
+
rmSync13(p, { recursive: true, force: true });
|
|
39890
40213
|
removed++;
|
|
39891
40214
|
} catch {
|
|
39892
40215
|
}
|