chat-recall 0.7.26 → 0.7.30
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/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 +1835 -1219
- package/dist/cli.js.map +1 -1
- package/dist/install-hooks.d.ts.map +1 -1
- package/dist/install-hooks.js +32 -1
- 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 +1433 -456
- 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
|
@@ -2034,7 +2034,7 @@ var require_thread_stream = __commonJS({
|
|
|
2034
2034
|
var { version: version2 } = require_package();
|
|
2035
2035
|
var { EventEmitter } = __require("events");
|
|
2036
2036
|
var { Worker: Worker2 } = __require("worker_threads");
|
|
2037
|
-
var { join:
|
|
2037
|
+
var { join: join69 } = __require("path");
|
|
2038
2038
|
var { pathToFileURL } = __require("url");
|
|
2039
2039
|
var { wait } = require_wait();
|
|
2040
2040
|
var {
|
|
@@ -2077,7 +2077,7 @@ var require_thread_stream = __commonJS({
|
|
|
2077
2077
|
function createWorker(stream, opts) {
|
|
2078
2078
|
const { filename, workerData } = opts;
|
|
2079
2079
|
const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
|
|
2080
|
-
const toExecute = bundlerOverrides["thread-stream-worker"] ||
|
|
2080
|
+
const toExecute = bundlerOverrides["thread-stream-worker"] || join69(__dirname, "lib", "worker.js");
|
|
2081
2081
|
const worker = new Worker2(toExecute, {
|
|
2082
2082
|
...opts.workerOpts,
|
|
2083
2083
|
trackUnmanagedFds: false,
|
|
@@ -2480,7 +2480,7 @@ var require_transport = __commonJS({
|
|
|
2480
2480
|
"use strict";
|
|
2481
2481
|
var { createRequire: createRequire3 } = __require("module");
|
|
2482
2482
|
var getCallers = require_caller();
|
|
2483
|
-
var { join:
|
|
2483
|
+
var { join: join69, isAbsolute: isAbsolute5, sep: sep5 } = __require("node:path");
|
|
2484
2484
|
var sleep2 = require_atomic_sleep();
|
|
2485
2485
|
var onExit = require_on_exit_leak_free();
|
|
2486
2486
|
var ThreadStream = require_thread_stream();
|
|
@@ -2543,7 +2543,7 @@ var require_transport = __commonJS({
|
|
|
2543
2543
|
throw new Error("only one of target or targets can be specified");
|
|
2544
2544
|
}
|
|
2545
2545
|
if (targets) {
|
|
2546
|
-
target = bundlerOverrides["pino-worker"] ||
|
|
2546
|
+
target = bundlerOverrides["pino-worker"] || join69(__dirname, "worker.js");
|
|
2547
2547
|
options.targets = targets.filter((dest) => dest.target).map((dest) => {
|
|
2548
2548
|
return {
|
|
2549
2549
|
...dest,
|
|
@@ -2561,7 +2561,7 @@ var require_transport = __commonJS({
|
|
|
2561
2561
|
});
|
|
2562
2562
|
});
|
|
2563
2563
|
} else if (pipeline) {
|
|
2564
|
-
target = bundlerOverrides["pino-worker"] ||
|
|
2564
|
+
target = bundlerOverrides["pino-worker"] || join69(__dirname, "worker.js");
|
|
2565
2565
|
options.pipelines = [pipeline.map((dest) => {
|
|
2566
2566
|
return {
|
|
2567
2567
|
...dest,
|
|
@@ -2583,12 +2583,12 @@ var require_transport = __commonJS({
|
|
|
2583
2583
|
return origin;
|
|
2584
2584
|
}
|
|
2585
2585
|
if (origin === "pino/file") {
|
|
2586
|
-
return
|
|
2586
|
+
return join69(__dirname, "..", "file.js");
|
|
2587
2587
|
}
|
|
2588
2588
|
let fixTarget2;
|
|
2589
2589
|
for (const filePath of callers) {
|
|
2590
2590
|
try {
|
|
2591
|
-
const context3 = filePath === "node:repl" ? process.cwd() +
|
|
2591
|
+
const context3 = filePath === "node:repl" ? process.cwd() + sep5 : filePath;
|
|
2592
2592
|
fixTarget2 = createRequire3(context3).resolve(origin);
|
|
2593
2593
|
break;
|
|
2594
2594
|
} catch (err) {
|
|
@@ -3572,7 +3572,7 @@ var require_safe_stable_stringify = __commonJS({
|
|
|
3572
3572
|
return circularValue;
|
|
3573
3573
|
}
|
|
3574
3574
|
let res = "";
|
|
3575
|
-
let
|
|
3575
|
+
let join69 = ",";
|
|
3576
3576
|
const originalIndentation = indentation;
|
|
3577
3577
|
if (Array.isArray(value)) {
|
|
3578
3578
|
if (value.length === 0) {
|
|
@@ -3586,7 +3586,7 @@ var require_safe_stable_stringify = __commonJS({
|
|
|
3586
3586
|
indentation += spacer;
|
|
3587
3587
|
res += `
|
|
3588
3588
|
${indentation}`;
|
|
3589
|
-
|
|
3589
|
+
join69 = `,
|
|
3590
3590
|
${indentation}`;
|
|
3591
3591
|
}
|
|
3592
3592
|
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
@@ -3594,13 +3594,13 @@ ${indentation}`;
|
|
|
3594
3594
|
for (; i < maximumValuesToStringify - 1; i++) {
|
|
3595
3595
|
const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
3596
3596
|
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
3597
|
-
res +=
|
|
3597
|
+
res += join69;
|
|
3598
3598
|
}
|
|
3599
3599
|
const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
3600
3600
|
res += tmp !== void 0 ? tmp : "null";
|
|
3601
3601
|
if (value.length - 1 > maximumBreadth) {
|
|
3602
3602
|
const removedKeys = value.length - maximumBreadth - 1;
|
|
3603
|
-
res += `${
|
|
3603
|
+
res += `${join69}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
3604
3604
|
}
|
|
3605
3605
|
if (spacer !== "") {
|
|
3606
3606
|
res += `
|
|
@@ -3621,7 +3621,7 @@ ${originalIndentation}`;
|
|
|
3621
3621
|
let separator = "";
|
|
3622
3622
|
if (spacer !== "") {
|
|
3623
3623
|
indentation += spacer;
|
|
3624
|
-
|
|
3624
|
+
join69 = `,
|
|
3625
3625
|
${indentation}`;
|
|
3626
3626
|
whitespace = " ";
|
|
3627
3627
|
}
|
|
@@ -3635,13 +3635,13 @@ ${indentation}`;
|
|
|
3635
3635
|
const tmp = stringifyFnReplacer(key3, value, stack, replacer, spacer, indentation);
|
|
3636
3636
|
if (tmp !== void 0) {
|
|
3637
3637
|
res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
|
|
3638
|
-
separator =
|
|
3638
|
+
separator = join69;
|
|
3639
3639
|
}
|
|
3640
3640
|
}
|
|
3641
3641
|
if (keyLength > maximumBreadth) {
|
|
3642
3642
|
const removedKeys = keyLength - maximumBreadth;
|
|
3643
3643
|
res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
|
|
3644
|
-
separator =
|
|
3644
|
+
separator = join69;
|
|
3645
3645
|
}
|
|
3646
3646
|
if (spacer !== "" && separator.length > 1) {
|
|
3647
3647
|
res = `
|
|
@@ -3682,7 +3682,7 @@ ${originalIndentation}`;
|
|
|
3682
3682
|
}
|
|
3683
3683
|
const originalIndentation = indentation;
|
|
3684
3684
|
let res = "";
|
|
3685
|
-
let
|
|
3685
|
+
let join69 = ",";
|
|
3686
3686
|
if (Array.isArray(value)) {
|
|
3687
3687
|
if (value.length === 0) {
|
|
3688
3688
|
return "[]";
|
|
@@ -3695,7 +3695,7 @@ ${originalIndentation}`;
|
|
|
3695
3695
|
indentation += spacer;
|
|
3696
3696
|
res += `
|
|
3697
3697
|
${indentation}`;
|
|
3698
|
-
|
|
3698
|
+
join69 = `,
|
|
3699
3699
|
${indentation}`;
|
|
3700
3700
|
}
|
|
3701
3701
|
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
@@ -3703,13 +3703,13 @@ ${indentation}`;
|
|
|
3703
3703
|
for (; i < maximumValuesToStringify - 1; i++) {
|
|
3704
3704
|
const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
3705
3705
|
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
3706
|
-
res +=
|
|
3706
|
+
res += join69;
|
|
3707
3707
|
}
|
|
3708
3708
|
const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
3709
3709
|
res += tmp !== void 0 ? tmp : "null";
|
|
3710
3710
|
if (value.length - 1 > maximumBreadth) {
|
|
3711
3711
|
const removedKeys = value.length - maximumBreadth - 1;
|
|
3712
|
-
res += `${
|
|
3712
|
+
res += `${join69}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
3713
3713
|
}
|
|
3714
3714
|
if (spacer !== "") {
|
|
3715
3715
|
res += `
|
|
@@ -3722,7 +3722,7 @@ ${originalIndentation}`;
|
|
|
3722
3722
|
let whitespace = "";
|
|
3723
3723
|
if (spacer !== "") {
|
|
3724
3724
|
indentation += spacer;
|
|
3725
|
-
|
|
3725
|
+
join69 = `,
|
|
3726
3726
|
${indentation}`;
|
|
3727
3727
|
whitespace = " ";
|
|
3728
3728
|
}
|
|
@@ -3731,7 +3731,7 @@ ${indentation}`;
|
|
|
3731
3731
|
const tmp = stringifyArrayReplacer(key3, value[key3], stack, replacer, spacer, indentation);
|
|
3732
3732
|
if (tmp !== void 0) {
|
|
3733
3733
|
res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
|
|
3734
|
-
separator =
|
|
3734
|
+
separator = join69;
|
|
3735
3735
|
}
|
|
3736
3736
|
}
|
|
3737
3737
|
if (spacer !== "" && separator.length > 1) {
|
|
@@ -3789,20 +3789,20 @@ ${originalIndentation}`;
|
|
|
3789
3789
|
indentation += spacer;
|
|
3790
3790
|
let res2 = `
|
|
3791
3791
|
${indentation}`;
|
|
3792
|
-
const
|
|
3792
|
+
const join70 = `,
|
|
3793
3793
|
${indentation}`;
|
|
3794
3794
|
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
3795
3795
|
let i = 0;
|
|
3796
3796
|
for (; i < maximumValuesToStringify - 1; i++) {
|
|
3797
3797
|
const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
3798
3798
|
res2 += tmp2 !== void 0 ? tmp2 : "null";
|
|
3799
|
-
res2 +=
|
|
3799
|
+
res2 += join70;
|
|
3800
3800
|
}
|
|
3801
3801
|
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
3802
3802
|
res2 += tmp !== void 0 ? tmp : "null";
|
|
3803
3803
|
if (value.length - 1 > maximumBreadth) {
|
|
3804
3804
|
const removedKeys = value.length - maximumBreadth - 1;
|
|
3805
|
-
res2 += `${
|
|
3805
|
+
res2 += `${join70}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
3806
3806
|
}
|
|
3807
3807
|
res2 += `
|
|
3808
3808
|
${originalIndentation}`;
|
|
@@ -3818,16 +3818,16 @@ ${originalIndentation}`;
|
|
|
3818
3818
|
return '"[Object]"';
|
|
3819
3819
|
}
|
|
3820
3820
|
indentation += spacer;
|
|
3821
|
-
const
|
|
3821
|
+
const join69 = `,
|
|
3822
3822
|
${indentation}`;
|
|
3823
3823
|
let res = "";
|
|
3824
3824
|
let separator = "";
|
|
3825
3825
|
let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
3826
3826
|
if (isTypedArrayWithEntries(value)) {
|
|
3827
|
-
res += stringifyTypedArray(value,
|
|
3827
|
+
res += stringifyTypedArray(value, join69, maximumBreadth);
|
|
3828
3828
|
keys = keys.slice(value.length);
|
|
3829
3829
|
maximumPropertiesToStringify -= value.length;
|
|
3830
|
-
separator =
|
|
3830
|
+
separator = join69;
|
|
3831
3831
|
}
|
|
3832
3832
|
if (deterministic) {
|
|
3833
3833
|
keys = sort(keys, comparator);
|
|
@@ -3838,13 +3838,13 @@ ${indentation}`;
|
|
|
3838
3838
|
const tmp = stringifyIndent(key3, value[key3], stack, spacer, indentation);
|
|
3839
3839
|
if (tmp !== void 0) {
|
|
3840
3840
|
res += `${separator}${strEscape(key3)}: ${tmp}`;
|
|
3841
|
-
separator =
|
|
3841
|
+
separator = join69;
|
|
3842
3842
|
}
|
|
3843
3843
|
}
|
|
3844
3844
|
if (keyLength > maximumBreadth) {
|
|
3845
3845
|
const removedKeys = keyLength - maximumBreadth;
|
|
3846
3846
|
res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
|
|
3847
|
-
separator =
|
|
3847
|
+
separator = join69;
|
|
3848
3848
|
}
|
|
3849
3849
|
if (separator !== "") {
|
|
3850
3850
|
res = `
|
|
@@ -9672,11 +9672,11 @@ async function archiveRawSession(store, sessionId) {
|
|
|
9672
9672
|
return await store.putRawSession(sessionId, exp.tool, Math.floor(exp.mtime), gz, size);
|
|
9673
9673
|
}
|
|
9674
9674
|
function detectForkPredecessor(sessionPath) {
|
|
9675
|
-
const { readFileSync:
|
|
9676
|
-
const { dirname: dirname30, join:
|
|
9675
|
+
const { readFileSync: readFileSync55, readdirSync: readdirSync36 } = requireFs();
|
|
9676
|
+
const { dirname: dirname30, join: join69, basename: basename30 } = requirePath();
|
|
9677
9677
|
let text;
|
|
9678
9678
|
try {
|
|
9679
|
-
text =
|
|
9679
|
+
text = readFileSync55(sessionPath, "utf-8");
|
|
9680
9680
|
} catch {
|
|
9681
9681
|
return null;
|
|
9682
9682
|
}
|
|
@@ -9710,7 +9710,7 @@ function detectForkPredecessor(sessionPath) {
|
|
|
9710
9710
|
if (!f.endsWith(".jsonl") || f === self || f === "sessions-index.json")
|
|
9711
9711
|
continue;
|
|
9712
9712
|
try {
|
|
9713
|
-
if (
|
|
9713
|
+
if (readFileSync55(join69(dir, f), "utf-8").includes(`"uuid":"${headParent}"`)) {
|
|
9714
9714
|
return basename30(f, ".jsonl");
|
|
9715
9715
|
}
|
|
9716
9716
|
} catch {
|
|
@@ -15913,10 +15913,10 @@ var init_types = __esm({
|
|
|
15913
15913
|
|
|
15914
15914
|
// ../engine/dist/transcript/opencode.js
|
|
15915
15915
|
async function parseOpenCodeSubagents(parentSessionId) {
|
|
15916
|
-
const { existsSync:
|
|
15916
|
+
const { existsSync: existsSync62 } = await import("fs");
|
|
15917
15917
|
const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
|
|
15918
15918
|
const dbPath = opencodeBackend2.dbPath();
|
|
15919
|
-
if (!
|
|
15919
|
+
if (!existsSync62(dbPath))
|
|
15920
15920
|
return [];
|
|
15921
15921
|
const realParent = parentSessionId.replace("opencode_", "");
|
|
15922
15922
|
const db = openOpencodeDbOrThrow(dbPath);
|
|
@@ -15957,10 +15957,10 @@ async function parseOpenCodeSubagents(parentSessionId) {
|
|
|
15957
15957
|
}
|
|
15958
15958
|
}
|
|
15959
15959
|
async function parseOpenCodeTranscript(sessionId) {
|
|
15960
|
-
const { existsSync:
|
|
15960
|
+
const { existsSync: existsSync62 } = await import("fs");
|
|
15961
15961
|
const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
|
|
15962
15962
|
const dbPath = opencodeBackend2.dbPath();
|
|
15963
|
-
if (!
|
|
15963
|
+
if (!existsSync62(dbPath))
|
|
15964
15964
|
return [];
|
|
15965
15965
|
const realId = sessionId.replace("opencode_", "");
|
|
15966
15966
|
const db = openOpencodeDbOrThrow(dbPath);
|
|
@@ -23197,10 +23197,10 @@ var require_resolve_block_map = __commonJS({
|
|
|
23197
23197
|
let offset = bm.offset;
|
|
23198
23198
|
let commentEnd = null;
|
|
23199
23199
|
for (const collItem of bm.items) {
|
|
23200
|
-
const { start, key: key2, sep:
|
|
23200
|
+
const { start, key: key2, sep: sep5, value } = collItem;
|
|
23201
23201
|
const keyProps = resolveProps.resolveProps(start, {
|
|
23202
23202
|
indicator: "explicit-key-ind",
|
|
23203
|
-
next: key2 ??
|
|
23203
|
+
next: key2 ?? sep5?.[0],
|
|
23204
23204
|
offset,
|
|
23205
23205
|
onError,
|
|
23206
23206
|
parentIndent: bm.indent,
|
|
@@ -23214,7 +23214,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
23214
23214
|
else if ("indent" in key2 && key2.indent !== bm.indent)
|
|
23215
23215
|
onError(offset, "BAD_INDENT", startColMsg);
|
|
23216
23216
|
}
|
|
23217
|
-
if (!keyProps.anchor && !keyProps.tag && !
|
|
23217
|
+
if (!keyProps.anchor && !keyProps.tag && !sep5) {
|
|
23218
23218
|
commentEnd = keyProps.end;
|
|
23219
23219
|
if (keyProps.comment) {
|
|
23220
23220
|
if (map.comment)
|
|
@@ -23238,7 +23238,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
23238
23238
|
ctx.atKey = false;
|
|
23239
23239
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
23240
23240
|
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
|
|
23241
|
-
const valueProps = resolveProps.resolveProps(
|
|
23241
|
+
const valueProps = resolveProps.resolveProps(sep5 ?? [], {
|
|
23242
23242
|
indicator: "map-value-ind",
|
|
23243
23243
|
next: value,
|
|
23244
23244
|
offset: keyNode.range[2],
|
|
@@ -23254,7 +23254,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
23254
23254
|
if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
|
|
23255
23255
|
onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
|
|
23256
23256
|
}
|
|
23257
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset,
|
|
23257
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep5, null, valueProps, onError);
|
|
23258
23258
|
if (ctx.schema.compat)
|
|
23259
23259
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
|
|
23260
23260
|
offset = valueNode.range[2];
|
|
@@ -23345,7 +23345,7 @@ var require_resolve_end = __commonJS({
|
|
|
23345
23345
|
let comment = "";
|
|
23346
23346
|
if (end) {
|
|
23347
23347
|
let hasSpace = false;
|
|
23348
|
-
let
|
|
23348
|
+
let sep5 = "";
|
|
23349
23349
|
for (const token of end) {
|
|
23350
23350
|
const { source, type } = token;
|
|
23351
23351
|
switch (type) {
|
|
@@ -23359,13 +23359,13 @@ var require_resolve_end = __commonJS({
|
|
|
23359
23359
|
if (!comment)
|
|
23360
23360
|
comment = cb;
|
|
23361
23361
|
else
|
|
23362
|
-
comment +=
|
|
23363
|
-
|
|
23362
|
+
comment += sep5 + cb;
|
|
23363
|
+
sep5 = "";
|
|
23364
23364
|
break;
|
|
23365
23365
|
}
|
|
23366
23366
|
case "newline":
|
|
23367
23367
|
if (comment)
|
|
23368
|
-
|
|
23368
|
+
sep5 += source;
|
|
23369
23369
|
hasSpace = true;
|
|
23370
23370
|
break;
|
|
23371
23371
|
default:
|
|
@@ -23408,18 +23408,18 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
23408
23408
|
let offset = fc.offset + fc.start.source.length;
|
|
23409
23409
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
23410
23410
|
const collItem = fc.items[i];
|
|
23411
|
-
const { start, key: key2, sep:
|
|
23411
|
+
const { start, key: key2, sep: sep5, value } = collItem;
|
|
23412
23412
|
const props = resolveProps.resolveProps(start, {
|
|
23413
23413
|
flow: fcName,
|
|
23414
23414
|
indicator: "explicit-key-ind",
|
|
23415
|
-
next: key2 ??
|
|
23415
|
+
next: key2 ?? sep5?.[0],
|
|
23416
23416
|
offset,
|
|
23417
23417
|
onError,
|
|
23418
23418
|
parentIndent: fc.indent,
|
|
23419
23419
|
startOnNewline: false
|
|
23420
23420
|
});
|
|
23421
23421
|
if (!props.found) {
|
|
23422
|
-
if (!props.anchor && !props.tag && !
|
|
23422
|
+
if (!props.anchor && !props.tag && !sep5 && !value) {
|
|
23423
23423
|
if (i === 0 && props.comma)
|
|
23424
23424
|
onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
|
|
23425
23425
|
else if (i < fc.items.length - 1)
|
|
@@ -23473,8 +23473,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
23473
23473
|
}
|
|
23474
23474
|
}
|
|
23475
23475
|
}
|
|
23476
|
-
if (!isMap2 && !
|
|
23477
|
-
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end,
|
|
23476
|
+
if (!isMap2 && !sep5 && !props.found) {
|
|
23477
|
+
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep5, null, props, onError);
|
|
23478
23478
|
coll.items.push(valueNode);
|
|
23479
23479
|
offset = valueNode.range[2];
|
|
23480
23480
|
if (isBlock(value))
|
|
@@ -23486,7 +23486,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
23486
23486
|
if (isBlock(key2))
|
|
23487
23487
|
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
23488
23488
|
ctx.atKey = false;
|
|
23489
|
-
const valueProps = resolveProps.resolveProps(
|
|
23489
|
+
const valueProps = resolveProps.resolveProps(sep5 ?? [], {
|
|
23490
23490
|
flow: fcName,
|
|
23491
23491
|
indicator: "map-value-ind",
|
|
23492
23492
|
next: value,
|
|
@@ -23497,8 +23497,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
23497
23497
|
});
|
|
23498
23498
|
if (valueProps.found) {
|
|
23499
23499
|
if (!isMap2 && !props.found && ctx.options.strict) {
|
|
23500
|
-
if (
|
|
23501
|
-
for (const st of
|
|
23500
|
+
if (sep5)
|
|
23501
|
+
for (const st of sep5) {
|
|
23502
23502
|
if (st === valueProps.found)
|
|
23503
23503
|
break;
|
|
23504
23504
|
if (st.type === "newline") {
|
|
@@ -23515,7 +23515,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
23515
23515
|
else
|
|
23516
23516
|
onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
|
|
23517
23517
|
}
|
|
23518
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end,
|
|
23518
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep5, null, valueProps, onError) : null;
|
|
23519
23519
|
if (valueNode) {
|
|
23520
23520
|
if (isBlock(value))
|
|
23521
23521
|
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
@@ -23695,7 +23695,7 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
23695
23695
|
chompStart = i + 1;
|
|
23696
23696
|
}
|
|
23697
23697
|
let value = "";
|
|
23698
|
-
let
|
|
23698
|
+
let sep5 = "";
|
|
23699
23699
|
let prevMoreIndented = false;
|
|
23700
23700
|
for (let i = 0; i < contentStart; ++i)
|
|
23701
23701
|
value += lines[i][0].slice(trimIndent) + "\n";
|
|
@@ -23712,24 +23712,24 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
23712
23712
|
indent2 = "";
|
|
23713
23713
|
}
|
|
23714
23714
|
if (type === Scalar.Scalar.BLOCK_LITERAL) {
|
|
23715
|
-
value +=
|
|
23716
|
-
|
|
23715
|
+
value += sep5 + indent2.slice(trimIndent) + content;
|
|
23716
|
+
sep5 = "\n";
|
|
23717
23717
|
} else if (indent2.length > trimIndent || content[0] === " ") {
|
|
23718
|
-
if (
|
|
23719
|
-
|
|
23720
|
-
else if (!prevMoreIndented &&
|
|
23721
|
-
|
|
23722
|
-
value +=
|
|
23723
|
-
|
|
23718
|
+
if (sep5 === " ")
|
|
23719
|
+
sep5 = "\n";
|
|
23720
|
+
else if (!prevMoreIndented && sep5 === "\n")
|
|
23721
|
+
sep5 = "\n\n";
|
|
23722
|
+
value += sep5 + indent2.slice(trimIndent) + content;
|
|
23723
|
+
sep5 = "\n";
|
|
23724
23724
|
prevMoreIndented = true;
|
|
23725
23725
|
} else if (content === "") {
|
|
23726
|
-
if (
|
|
23726
|
+
if (sep5 === "\n")
|
|
23727
23727
|
value += "\n";
|
|
23728
23728
|
else
|
|
23729
|
-
|
|
23729
|
+
sep5 = "\n";
|
|
23730
23730
|
} else {
|
|
23731
|
-
value +=
|
|
23732
|
-
|
|
23731
|
+
value += sep5 + content;
|
|
23732
|
+
sep5 = " ";
|
|
23733
23733
|
prevMoreIndented = false;
|
|
23734
23734
|
}
|
|
23735
23735
|
}
|
|
@@ -23912,25 +23912,25 @@ var require_resolve_flow_scalar = __commonJS({
|
|
|
23912
23912
|
trimBoth = /^[ \t]+|[ \t]+$/g;
|
|
23913
23913
|
}
|
|
23914
23914
|
let res = match[1].replace(trimEnd, "");
|
|
23915
|
-
let
|
|
23915
|
+
let sep5 = " ";
|
|
23916
23916
|
let pos = line.lastIndex;
|
|
23917
23917
|
while (match = line.exec(source)) {
|
|
23918
23918
|
const lm = match[1].replace(trimBoth, "");
|
|
23919
23919
|
if (lm === "") {
|
|
23920
|
-
if (
|
|
23921
|
-
res +=
|
|
23920
|
+
if (sep5 === "\n")
|
|
23921
|
+
res += sep5;
|
|
23922
23922
|
else
|
|
23923
|
-
|
|
23923
|
+
sep5 = "\n";
|
|
23924
23924
|
} else {
|
|
23925
|
-
res +=
|
|
23926
|
-
|
|
23925
|
+
res += sep5 + lm;
|
|
23926
|
+
sep5 = " ";
|
|
23927
23927
|
}
|
|
23928
23928
|
pos = line.lastIndex;
|
|
23929
23929
|
}
|
|
23930
23930
|
const last = /[ \t]*(.*)/sy;
|
|
23931
23931
|
last.lastIndex = pos;
|
|
23932
23932
|
match = last.exec(source);
|
|
23933
|
-
return res +
|
|
23933
|
+
return res + sep5 + (match?.[1] ?? "");
|
|
23934
23934
|
}
|
|
23935
23935
|
function doubleQuotedValue(source, onError) {
|
|
23936
23936
|
let res = "";
|
|
@@ -24740,14 +24740,14 @@ var require_cst_stringify = __commonJS({
|
|
|
24740
24740
|
}
|
|
24741
24741
|
}
|
|
24742
24742
|
}
|
|
24743
|
-
function stringifyItem({ start, key: key2, sep:
|
|
24743
|
+
function stringifyItem({ start, key: key2, sep: sep5, value }) {
|
|
24744
24744
|
let res = "";
|
|
24745
24745
|
for (const st of start)
|
|
24746
24746
|
res += st.source;
|
|
24747
24747
|
if (key2)
|
|
24748
24748
|
res += stringifyToken(key2);
|
|
24749
|
-
if (
|
|
24750
|
-
for (const st of
|
|
24749
|
+
if (sep5)
|
|
24750
|
+
for (const st of sep5)
|
|
24751
24751
|
res += st.source;
|
|
24752
24752
|
if (value)
|
|
24753
24753
|
res += stringifyToken(value);
|
|
@@ -25638,7 +25638,7 @@ var require_parser = __commonJS({
|
|
|
25638
25638
|
}
|
|
25639
25639
|
}
|
|
25640
25640
|
}
|
|
25641
|
-
var
|
|
25641
|
+
var Parser2 = class {
|
|
25642
25642
|
/**
|
|
25643
25643
|
* @param onNewLine - If defined, called separately with the start position of
|
|
25644
25644
|
* each new line (in `parse()`, including the start of input).
|
|
@@ -25914,18 +25914,18 @@ var require_parser = __commonJS({
|
|
|
25914
25914
|
if (this.type === "map-value-ind") {
|
|
25915
25915
|
const prev = getPrevProps(this.peek(2));
|
|
25916
25916
|
const start = getFirstKeyStartProps(prev);
|
|
25917
|
-
let
|
|
25917
|
+
let sep5;
|
|
25918
25918
|
if (scalar.end) {
|
|
25919
|
-
|
|
25920
|
-
|
|
25919
|
+
sep5 = scalar.end;
|
|
25920
|
+
sep5.push(this.sourceToken);
|
|
25921
25921
|
delete scalar.end;
|
|
25922
25922
|
} else
|
|
25923
|
-
|
|
25923
|
+
sep5 = [this.sourceToken];
|
|
25924
25924
|
const map = {
|
|
25925
25925
|
type: "block-map",
|
|
25926
25926
|
offset: scalar.offset,
|
|
25927
25927
|
indent: scalar.indent,
|
|
25928
|
-
items: [{ start, key: scalar, sep:
|
|
25928
|
+
items: [{ start, key: scalar, sep: sep5 }]
|
|
25929
25929
|
};
|
|
25930
25930
|
this.onKeyLine = true;
|
|
25931
25931
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -26078,15 +26078,15 @@ var require_parser = __commonJS({
|
|
|
26078
26078
|
} else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
26079
26079
|
const start2 = getFirstKeyStartProps(it.start);
|
|
26080
26080
|
const key2 = it.key;
|
|
26081
|
-
const
|
|
26082
|
-
|
|
26081
|
+
const sep5 = it.sep;
|
|
26082
|
+
sep5.push(this.sourceToken);
|
|
26083
26083
|
delete it.key;
|
|
26084
26084
|
delete it.sep;
|
|
26085
26085
|
this.stack.push({
|
|
26086
26086
|
type: "block-map",
|
|
26087
26087
|
offset: this.offset,
|
|
26088
26088
|
indent: this.indent,
|
|
26089
|
-
items: [{ start: start2, key: key2, sep:
|
|
26089
|
+
items: [{ start: start2, key: key2, sep: sep5 }]
|
|
26090
26090
|
});
|
|
26091
26091
|
} else if (start.length > 0) {
|
|
26092
26092
|
it.sep = it.sep.concat(start, this.sourceToken);
|
|
@@ -26280,13 +26280,13 @@ var require_parser = __commonJS({
|
|
|
26280
26280
|
const prev = getPrevProps(parent);
|
|
26281
26281
|
const start = getFirstKeyStartProps(prev);
|
|
26282
26282
|
fixFlowSeqItems(fc);
|
|
26283
|
-
const
|
|
26284
|
-
|
|
26283
|
+
const sep5 = fc.end.splice(1, fc.end.length);
|
|
26284
|
+
sep5.push(this.sourceToken);
|
|
26285
26285
|
const map = {
|
|
26286
26286
|
type: "block-map",
|
|
26287
26287
|
offset: fc.offset,
|
|
26288
26288
|
indent: fc.indent,
|
|
26289
|
-
items: [{ start, key: fc, sep:
|
|
26289
|
+
items: [{ start, key: fc, sep: sep5 }]
|
|
26290
26290
|
};
|
|
26291
26291
|
this.onKeyLine = true;
|
|
26292
26292
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -26411,7 +26411,7 @@ var require_parser = __commonJS({
|
|
|
26411
26411
|
}
|
|
26412
26412
|
}
|
|
26413
26413
|
};
|
|
26414
|
-
exports.Parser =
|
|
26414
|
+
exports.Parser = Parser2;
|
|
26415
26415
|
}
|
|
26416
26416
|
});
|
|
26417
26417
|
|
|
@@ -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.30";
|
|
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.30" : "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.30";
|
|
31279
31279
|
} catch {
|
|
31280
31280
|
}
|
|
31281
31281
|
}
|
|
@@ -31484,6 +31484,1220 @@ var init_which = __esm({
|
|
|
31484
31484
|
}
|
|
31485
31485
|
});
|
|
31486
31486
|
|
|
31487
|
+
// ../engine/dist/core/guard-registration.js
|
|
31488
|
+
var guard_registration_exports = {};
|
|
31489
|
+
__export(guard_registration_exports, {
|
|
31490
|
+
GUARD_ID: () => GUARD_ID,
|
|
31491
|
+
guardCommand: () => guardCommand,
|
|
31492
|
+
guardTargets: () => guardTargets,
|
|
31493
|
+
guardWrapperName: () => guardWrapperName,
|
|
31494
|
+
guardWrapperSource: () => guardWrapperSource,
|
|
31495
|
+
legacyAgyHooksFile: () => legacyAgyHooksFile,
|
|
31496
|
+
opencodeConfigDir: () => opencodeConfigDir,
|
|
31497
|
+
opencodePluginDir: () => opencodePluginDir,
|
|
31498
|
+
opencodePluginSource: () => opencodePluginSource,
|
|
31499
|
+
registerGuard: () => registerGuard,
|
|
31500
|
+
unregisterGuard: () => unregisterGuard
|
|
31501
|
+
});
|
|
31502
|
+
import { homedir as homedir17 } from "os";
|
|
31503
|
+
import { join as join50 } from "path";
|
|
31504
|
+
function legacyAgyHooksFile() {
|
|
31505
|
+
return join50(agyBackend.homeDir(), "hooks.json");
|
|
31506
|
+
}
|
|
31507
|
+
function opencodeConfigDir() {
|
|
31508
|
+
const xdg = process.env.XDG_CONFIG_HOME;
|
|
31509
|
+
const base4 = xdg && xdg.trim() ? xdg : join50(homedir17(), ".config");
|
|
31510
|
+
return join50(base4, "opencode");
|
|
31511
|
+
}
|
|
31512
|
+
function opencodePluginDir() {
|
|
31513
|
+
return join50(opencodeConfigDir(), "plugins");
|
|
31514
|
+
}
|
|
31515
|
+
function guardTargets() {
|
|
31516
|
+
return [
|
|
31517
|
+
{
|
|
31518
|
+
tool: "codex",
|
|
31519
|
+
label: "Codex",
|
|
31520
|
+
configPath: join50(codexBackend.homeDir(), "hooks.json"),
|
|
31521
|
+
homeDir: codexBackend.homeDir(),
|
|
31522
|
+
// Codex will not run a hook until a person has reviewed it, and the
|
|
31523
|
+
// approval is bound to the hook's hash. There is no way to grant it from
|
|
31524
|
+
// outside: /etc/codex/requirements.toml is the root-owned admin policy,
|
|
31525
|
+
// and the only other route is the per-invocation
|
|
31526
|
+
// --dangerously-bypass-hook-trust flag. An installer that could grant its
|
|
31527
|
+
// own approval is the thing the gate exists to stop.
|
|
31528
|
+
note: "Codex asks you to approve a hook before it runs one. Run /hooks in Codex once to approve this."
|
|
31529
|
+
},
|
|
31530
|
+
{
|
|
31531
|
+
tool: "agy",
|
|
31532
|
+
label: "Antigravity",
|
|
31533
|
+
configPath: agyBackend.sharedHooksFile(),
|
|
31534
|
+
homeDir: agyBackend.homeDir()
|
|
31535
|
+
},
|
|
31536
|
+
{
|
|
31537
|
+
tool: "cursor",
|
|
31538
|
+
label: "Cursor",
|
|
31539
|
+
configPath: join50(cursorBackend.homeDir(), "hooks.json"),
|
|
31540
|
+
homeDir: cursorBackend.homeDir(),
|
|
31541
|
+
note: "Cursor checks a shell command before it runs and a file edit after it is written."
|
|
31542
|
+
},
|
|
31543
|
+
{
|
|
31544
|
+
tool: "opencode",
|
|
31545
|
+
label: "OpenCode",
|
|
31546
|
+
configPath: join50(opencodePluginDir(), "chat-recall-guard.js"),
|
|
31547
|
+
homeDir: opencodeConfigDir(),
|
|
31548
|
+
note: "OpenCode plugin hooks do not fire for subagent tool calls, so a delegating agent bypasses this."
|
|
31549
|
+
}
|
|
31550
|
+
];
|
|
31551
|
+
}
|
|
31552
|
+
function guardWrapperName(tool) {
|
|
31553
|
+
return `chat_recall_guard_${tool}.sh`;
|
|
31554
|
+
}
|
|
31555
|
+
function guardWrapperSource(tool, hookPath) {
|
|
31556
|
+
return `#!/bin/sh
|
|
31557
|
+
# Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
31558
|
+
CHAT_RECALL_GUARD_HARNESS=${tool}
|
|
31559
|
+
export CHAT_RECALL_GUARD_HARNESS
|
|
31560
|
+
exec ${JSON.stringify(hookPath)} "$@"
|
|
31561
|
+
`;
|
|
31562
|
+
}
|
|
31563
|
+
function guardCommand(wrapperPath) {
|
|
31564
|
+
return wrapperPath.includes(" ") ? `"${wrapperPath}"` : wrapperPath;
|
|
31565
|
+
}
|
|
31566
|
+
function mergeCodex(config2, command) {
|
|
31567
|
+
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
31568
|
+
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
31569
|
+
const kept = asArray2(hooks.PreToolUse).filter((e) => !asArray2(e?.hooks).some((h) => isOurs(h?.command)));
|
|
31570
|
+
kept.push({
|
|
31571
|
+
matcher: CODEX_MATCHER,
|
|
31572
|
+
hooks: [{ type: "command", command, statusMessage: "chat-recall: checking decisions", timeout: TIMEOUT_SECS }]
|
|
31573
|
+
});
|
|
31574
|
+
hooks.PreToolUse = kept;
|
|
31575
|
+
c.hooks = hooks;
|
|
31576
|
+
return c;
|
|
31577
|
+
}
|
|
31578
|
+
function stripCodex(config2) {
|
|
31579
|
+
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
31580
|
+
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
31581
|
+
const before = asArray2(hooks.PreToolUse);
|
|
31582
|
+
const kept = before.filter((e) => !asArray2(e?.hooks).some((h) => isOurs(h?.command)));
|
|
31583
|
+
if (kept.length)
|
|
31584
|
+
hooks.PreToolUse = kept;
|
|
31585
|
+
else
|
|
31586
|
+
delete hooks.PreToolUse;
|
|
31587
|
+
c.hooks = hooks;
|
|
31588
|
+
return { config: c, removed: before.length - kept.length };
|
|
31589
|
+
}
|
|
31590
|
+
function mergeAgy(config2, command) {
|
|
31591
|
+
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
31592
|
+
c[GUARD_ID] = {
|
|
31593
|
+
enabled: true,
|
|
31594
|
+
PreToolUse: [{
|
|
31595
|
+
matcher: AGY_MATCHER,
|
|
31596
|
+
hooks: [{ type: "command", command, timeout: TIMEOUT_SECS }]
|
|
31597
|
+
}]
|
|
31598
|
+
};
|
|
31599
|
+
return c;
|
|
31600
|
+
}
|
|
31601
|
+
function stripAgy(config2) {
|
|
31602
|
+
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
31603
|
+
const had = Object.prototype.hasOwnProperty.call(c, GUARD_ID) ? 1 : 0;
|
|
31604
|
+
delete c[GUARD_ID];
|
|
31605
|
+
return { config: c, removed: had };
|
|
31606
|
+
}
|
|
31607
|
+
function mergeCursor(config2, command) {
|
|
31608
|
+
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
31609
|
+
c.version = typeof c.version === "number" ? c.version : 1;
|
|
31610
|
+
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
31611
|
+
for (const event of ["beforeShellExecution", "afterFileEdit"]) {
|
|
31612
|
+
const kept = asArray2(hooks[event]).filter((e) => !isOurs(e?.command));
|
|
31613
|
+
kept.push({ command });
|
|
31614
|
+
hooks[event] = kept;
|
|
31615
|
+
}
|
|
31616
|
+
c.hooks = hooks;
|
|
31617
|
+
return c;
|
|
31618
|
+
}
|
|
31619
|
+
function stripCursor(config2) {
|
|
31620
|
+
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
31621
|
+
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
31622
|
+
let removed = 0;
|
|
31623
|
+
for (const event of ["beforeShellExecution", "afterFileEdit"]) {
|
|
31624
|
+
const before = asArray2(hooks[event]);
|
|
31625
|
+
const kept = before.filter((e) => !isOurs(e?.command));
|
|
31626
|
+
removed += before.length - kept.length;
|
|
31627
|
+
if (kept.length)
|
|
31628
|
+
hooks[event] = kept;
|
|
31629
|
+
else
|
|
31630
|
+
delete hooks[event];
|
|
31631
|
+
}
|
|
31632
|
+
c.hooks = hooks;
|
|
31633
|
+
return { config: c, removed };
|
|
31634
|
+
}
|
|
31635
|
+
function registerGuard(tool, config2, command) {
|
|
31636
|
+
switch (tool) {
|
|
31637
|
+
case "codex":
|
|
31638
|
+
return mergeCodex(config2, command);
|
|
31639
|
+
case "agy":
|
|
31640
|
+
return mergeAgy(config2, command);
|
|
31641
|
+
case "cursor":
|
|
31642
|
+
return mergeCursor(config2, command);
|
|
31643
|
+
}
|
|
31644
|
+
}
|
|
31645
|
+
function unregisterGuard(tool, config2) {
|
|
31646
|
+
switch (tool) {
|
|
31647
|
+
case "codex":
|
|
31648
|
+
return stripCodex(config2);
|
|
31649
|
+
case "agy":
|
|
31650
|
+
return stripAgy(config2);
|
|
31651
|
+
case "cursor":
|
|
31652
|
+
return stripCursor(config2);
|
|
31653
|
+
}
|
|
31654
|
+
}
|
|
31655
|
+
function opencodePluginSource(hookPath) {
|
|
31656
|
+
return `// Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
31657
|
+
//
|
|
31658
|
+
// Sends each tool call to the same guard the other harnesses run, and prints
|
|
31659
|
+
// what it says. Blocking is opt-in: set CHAT_RECALL_GUARD_ENFORCE=1 and a
|
|
31660
|
+
// finding throws, which is how an OpenCode plugin stops a call.
|
|
31661
|
+
import { spawn } from "child_process";
|
|
31662
|
+
|
|
31663
|
+
const HOOK = ${JSON.stringify(hookPath)};
|
|
31664
|
+
|
|
31665
|
+
function ask(payload) {
|
|
31666
|
+
return new Promise((resolve) => {
|
|
31667
|
+
let out = "";
|
|
31668
|
+
const child = spawn(HOOK, {
|
|
31669
|
+
env: { ...process.env, CHAT_RECALL_GUARD_HARNESS: "opencode" },
|
|
31670
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
31671
|
+
});
|
|
31672
|
+
const done = setTimeout(() => { child.kill(); resolve(null); }, ${TIMEOUT_SECS * 1e3});
|
|
31673
|
+
child.stdout.on("data", (c) => { out += c; });
|
|
31674
|
+
child.on("error", () => { clearTimeout(done); resolve(null); });
|
|
31675
|
+
child.on("close", () => {
|
|
31676
|
+
clearTimeout(done);
|
|
31677
|
+
try { resolve(out.trim() ? JSON.parse(out) : null); } catch { resolve(null); }
|
|
31678
|
+
});
|
|
31679
|
+
child.stdin.end(JSON.stringify(payload));
|
|
31680
|
+
});
|
|
31681
|
+
}
|
|
31682
|
+
|
|
31683
|
+
async function check(tool, args) {
|
|
31684
|
+
const verdict = await ask({ tool, args });
|
|
31685
|
+
if (!verdict || !verdict.message) return;
|
|
31686
|
+
if (verdict.block) throw new Error(verdict.message);
|
|
31687
|
+
console.error(verdict.message);
|
|
31688
|
+
}
|
|
31689
|
+
|
|
31690
|
+
async function setup(ctx) {
|
|
31691
|
+
await ctx.tool.hook("execute.before", (event) => check(event?.tool, event?.input));
|
|
31692
|
+
}
|
|
31693
|
+
|
|
31694
|
+
async function server() {
|
|
31695
|
+
return {
|
|
31696
|
+
"tool.execute.before": (input, output) => check(input?.tool, output?.args),
|
|
31697
|
+
};
|
|
31698
|
+
}
|
|
31699
|
+
|
|
31700
|
+
export default { id: "${GUARD_ID}", server, setup };
|
|
31701
|
+
`;
|
|
31702
|
+
}
|
|
31703
|
+
var GUARD_ID, AGY_MATCHER, CODEX_MATCHER, TIMEOUT_SECS, isOurs, asArray2;
|
|
31704
|
+
var init_guard_registration = __esm({
|
|
31705
|
+
"../engine/dist/core/guard-registration.js"() {
|
|
31706
|
+
"use strict";
|
|
31707
|
+
init_backends();
|
|
31708
|
+
GUARD_ID = "chat-recall-guard";
|
|
31709
|
+
AGY_MATCHER = "run_command|write_to_file|replace_file_content|multi_replace_file_content";
|
|
31710
|
+
CODEX_MATCHER = "Bash|apply_patch|Edit|Write";
|
|
31711
|
+
TIMEOUT_SECS = 8;
|
|
31712
|
+
isOurs = (cmd) => typeof cmd === "string" && cmd.includes("chat_recall_guard");
|
|
31713
|
+
asArray2 = (v) => Array.isArray(v) ? v : [];
|
|
31714
|
+
}
|
|
31715
|
+
});
|
|
31716
|
+
|
|
31717
|
+
// ../engine/dist/core/session-messages.js
|
|
31718
|
+
function selfIntroduction(sessionId) {
|
|
31719
|
+
return [
|
|
31720
|
+
MESSAGES_MARKER,
|
|
31721
|
+
`chat-recall session id: ${sessionId}`,
|
|
31722
|
+
"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."
|
|
31723
|
+
].join("\n");
|
|
31724
|
+
}
|
|
31725
|
+
var MESSAGES_MARKER, INTERRUPT_MARKER;
|
|
31726
|
+
var init_session_messages = __esm({
|
|
31727
|
+
"../engine/dist/core/session-messages.js"() {
|
|
31728
|
+
"use strict";
|
|
31729
|
+
MESSAGES_MARKER = "<!-- chat-recall-messages -->";
|
|
31730
|
+
INTERRUPT_MARKER = "<!-- chat-recall:interrupt -->";
|
|
31731
|
+
}
|
|
31732
|
+
});
|
|
31733
|
+
|
|
31734
|
+
// ../engine/dist/core/message-registration.js
|
|
31735
|
+
var message_registration_exports = {};
|
|
31736
|
+
__export(message_registration_exports, {
|
|
31737
|
+
MESSAGES_ID: () => MESSAGES_ID,
|
|
31738
|
+
OPENCODE_TUI_PACKAGE: () => OPENCODE_TUI_PACKAGE,
|
|
31739
|
+
isOurPluginSource: () => isOurPluginSource,
|
|
31740
|
+
isOurTuiSource: () => isOurTuiSource,
|
|
31741
|
+
messageCommand: () => messageCommand,
|
|
31742
|
+
messageTargets: () => messageTargets,
|
|
31743
|
+
messageWrapperName: () => messageWrapperName,
|
|
31744
|
+
messageWrapperSource: () => messageWrapperSource,
|
|
31745
|
+
opencodeMessagesSource: () => opencodeMessagesSource,
|
|
31746
|
+
opencodeTuiFiles: () => opencodeTuiFiles,
|
|
31747
|
+
opencodeTuiSource: () => opencodeTuiSource,
|
|
31748
|
+
piAgentDir: () => piAgentDir,
|
|
31749
|
+
piMessagesSource: () => piMessagesSource,
|
|
31750
|
+
registerMessages: () => registerMessages,
|
|
31751
|
+
unregisterMessages: () => unregisterMessages
|
|
31752
|
+
});
|
|
31753
|
+
import { homedir as homedir18 } from "os";
|
|
31754
|
+
import { join as join51 } from "path";
|
|
31755
|
+
function piAgentDir() {
|
|
31756
|
+
const dir = process.env.PI_CODING_AGENT_DIR;
|
|
31757
|
+
return dir && dir.trim() ? dir : join51(homedir18(), ".pi", "agent");
|
|
31758
|
+
}
|
|
31759
|
+
function messageTargets() {
|
|
31760
|
+
return [
|
|
31761
|
+
{
|
|
31762
|
+
tool: "codex",
|
|
31763
|
+
label: "Codex",
|
|
31764
|
+
configPath: join51(codexBackend.homeDir(), "hooks.json"),
|
|
31765
|
+
homeDir: codexBackend.homeDir(),
|
|
31766
|
+
// Codex binds its approval to the hook's hash, and only a person can give it.
|
|
31767
|
+
note: "Codex asks you to approve a hook before it runs one. Run /hooks in Codex once to approve the message hook."
|
|
31768
|
+
},
|
|
31769
|
+
{
|
|
31770
|
+
tool: "agy",
|
|
31771
|
+
label: "Antigravity",
|
|
31772
|
+
configPath: agyBackend.sharedHooksFile(),
|
|
31773
|
+
homeDir: agyBackend.homeDir()
|
|
31774
|
+
},
|
|
31775
|
+
{
|
|
31776
|
+
tool: "cursor",
|
|
31777
|
+
label: "Cursor",
|
|
31778
|
+
configPath: join51(cursorBackend.homeDir(), "hooks.json"),
|
|
31779
|
+
homeDir: cursorBackend.homeDir(),
|
|
31780
|
+
note: "Cursor delivers a message at the start of a session and when the agent stops, as a follow-up prompt."
|
|
31781
|
+
},
|
|
31782
|
+
{
|
|
31783
|
+
tool: "opencode",
|
|
31784
|
+
label: "OpenCode",
|
|
31785
|
+
configPath: join51(opencodePluginDir(), `${MESSAGES_ID}.js`),
|
|
31786
|
+
homeDir: opencodeConfigDir()
|
|
31787
|
+
},
|
|
31788
|
+
{
|
|
31789
|
+
tool: "pi",
|
|
31790
|
+
label: "pi",
|
|
31791
|
+
configPath: join51(piAgentDir(), "extensions", `${MESSAGES_ID}.js`),
|
|
31792
|
+
homeDir: piAgentDir()
|
|
31793
|
+
}
|
|
31794
|
+
];
|
|
31795
|
+
}
|
|
31796
|
+
function messageWrapperName(tool) {
|
|
31797
|
+
return `chat_recall_messages_${tool}.sh`;
|
|
31798
|
+
}
|
|
31799
|
+
function messageWrapperSource(tool, nodePath, hookEntry) {
|
|
31800
|
+
return `#!/bin/sh
|
|
31801
|
+
# Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
31802
|
+
exec ${JSON.stringify(nodePath)} ${JSON.stringify(hookEntry)} --tool ${tool} "$@"
|
|
31803
|
+
`;
|
|
31804
|
+
}
|
|
31805
|
+
function messageCommand(wrapperPath, args = "") {
|
|
31806
|
+
const p = wrapperPath.includes(" ") ? `"${wrapperPath}"` : wrapperPath;
|
|
31807
|
+
return args ? `${p} ${args}` : p;
|
|
31808
|
+
}
|
|
31809
|
+
function mergeCodex2(config2, command) {
|
|
31810
|
+
const c = obj(config2);
|
|
31811
|
+
const hooks = obj(c.hooks);
|
|
31812
|
+
for (const event of CODEX_EVENTS) {
|
|
31813
|
+
const kept = asArray3(hooks[event]).filter((e) => !asArray3(e?.hooks).some((h) => isOurs2(h?.command)));
|
|
31814
|
+
kept.push({ hooks: [{ type: "command", command, timeout: TIMEOUT_SECS2 }] });
|
|
31815
|
+
hooks[event] = kept;
|
|
31816
|
+
}
|
|
31817
|
+
c.hooks = hooks;
|
|
31818
|
+
return c;
|
|
31819
|
+
}
|
|
31820
|
+
function stripCodex2(config2) {
|
|
31821
|
+
const c = obj(config2);
|
|
31822
|
+
const hooks = obj(c.hooks);
|
|
31823
|
+
let removed = 0;
|
|
31824
|
+
for (const event of CODEX_EVENTS) {
|
|
31825
|
+
const before = asArray3(hooks[event]);
|
|
31826
|
+
const kept = before.filter((e) => !asArray3(e?.hooks).some((h) => isOurs2(h?.command)));
|
|
31827
|
+
removed += before.length - kept.length;
|
|
31828
|
+
if (kept.length)
|
|
31829
|
+
hooks[event] = kept;
|
|
31830
|
+
else
|
|
31831
|
+
delete hooks[event];
|
|
31832
|
+
}
|
|
31833
|
+
if (Object.keys(hooks).length)
|
|
31834
|
+
c.hooks = hooks;
|
|
31835
|
+
else
|
|
31836
|
+
delete c.hooks;
|
|
31837
|
+
return { config: c, removed };
|
|
31838
|
+
}
|
|
31839
|
+
function mergeAgy2(config2, command) {
|
|
31840
|
+
const c = obj(config2);
|
|
31841
|
+
const run = (event) => [{ type: "command", command: `${command} --event ${event}`, timeout: TIMEOUT_SECS2 }];
|
|
31842
|
+
c[MESSAGES_ID] = {
|
|
31843
|
+
enabled: true,
|
|
31844
|
+
SessionStart: run("SessionStart"),
|
|
31845
|
+
PreInvocation: run("PreInvocation"),
|
|
31846
|
+
Stop: run("Stop")
|
|
31847
|
+
};
|
|
31848
|
+
return c;
|
|
31849
|
+
}
|
|
31850
|
+
function stripAgy2(config2) {
|
|
31851
|
+
const c = obj(config2);
|
|
31852
|
+
const had = Object.prototype.hasOwnProperty.call(c, MESSAGES_ID) ? 1 : 0;
|
|
31853
|
+
delete c[MESSAGES_ID];
|
|
31854
|
+
return { config: c, removed: had };
|
|
31855
|
+
}
|
|
31856
|
+
function mergeCursor2(config2, command) {
|
|
31857
|
+
const c = obj(config2);
|
|
31858
|
+
c.version = typeof c.version === "number" ? c.version : 1;
|
|
31859
|
+
const hooks = obj(c.hooks);
|
|
31860
|
+
for (const event of CURSOR_EVENTS) {
|
|
31861
|
+
const kept = asArray3(hooks[event]).filter((e) => !isOurs2(e?.command));
|
|
31862
|
+
kept.push({ command, timeout: TIMEOUT_SECS2 });
|
|
31863
|
+
hooks[event] = kept;
|
|
31864
|
+
}
|
|
31865
|
+
c.hooks = hooks;
|
|
31866
|
+
return c;
|
|
31867
|
+
}
|
|
31868
|
+
function stripCursor2(config2) {
|
|
31869
|
+
const c = obj(config2);
|
|
31870
|
+
const hooks = obj(c.hooks);
|
|
31871
|
+
let removed = 0;
|
|
31872
|
+
for (const event of CURSOR_EVENTS) {
|
|
31873
|
+
const before = asArray3(hooks[event]);
|
|
31874
|
+
const kept = before.filter((e) => !isOurs2(e?.command));
|
|
31875
|
+
removed += before.length - kept.length;
|
|
31876
|
+
if (kept.length)
|
|
31877
|
+
hooks[event] = kept;
|
|
31878
|
+
else
|
|
31879
|
+
delete hooks[event];
|
|
31880
|
+
}
|
|
31881
|
+
c.hooks = hooks;
|
|
31882
|
+
return { config: c, removed };
|
|
31883
|
+
}
|
|
31884
|
+
function registerMessages(tool, config2, command) {
|
|
31885
|
+
switch (tool) {
|
|
31886
|
+
case "codex":
|
|
31887
|
+
return mergeCodex2(config2, command);
|
|
31888
|
+
case "agy":
|
|
31889
|
+
return mergeAgy2(config2, command);
|
|
31890
|
+
case "cursor":
|
|
31891
|
+
return mergeCursor2(config2, command);
|
|
31892
|
+
}
|
|
31893
|
+
}
|
|
31894
|
+
function unregisterMessages(tool, config2) {
|
|
31895
|
+
switch (tool) {
|
|
31896
|
+
case "codex":
|
|
31897
|
+
return stripCodex2(config2);
|
|
31898
|
+
case "agy":
|
|
31899
|
+
return stripAgy2(config2);
|
|
31900
|
+
case "cursor":
|
|
31901
|
+
return stripCursor2(config2);
|
|
31902
|
+
}
|
|
31903
|
+
}
|
|
31904
|
+
function isOurPluginSource(source) {
|
|
31905
|
+
return source.includes(`${MESSAGES_ID}: written by`);
|
|
31906
|
+
}
|
|
31907
|
+
function isOurTuiSource(source) {
|
|
31908
|
+
return source.startsWith("// Written by `chat-recall install-hooks`");
|
|
31909
|
+
}
|
|
31910
|
+
function runnerSource(wrapperPath) {
|
|
31911
|
+
return `import { spawn } from "child_process";
|
|
31912
|
+
|
|
31913
|
+
const HOOK = ${JSON.stringify(wrapperPath)};
|
|
31914
|
+
|
|
31915
|
+
/**
|
|
31916
|
+
* The process this plugin runs in. The headless service a TUI starts reports
|
|
31917
|
+
* events for the same sessions, so the kind is what tells a coordinator which
|
|
31918
|
+
* row has a window. The first argument is the subcommand ("serve", "run", or
|
|
31919
|
+
* none for the TUI itself).
|
|
31920
|
+
*/
|
|
31921
|
+
const KIND = (() => {
|
|
31922
|
+
const args = process.argv.slice(1).filter((a) => !a.startsWith("-"));
|
|
31923
|
+
if (args.includes("serve")) return "serve";
|
|
31924
|
+
if (args[0] === "run") return "run";
|
|
31925
|
+
return undefined;
|
|
31926
|
+
})();
|
|
31927
|
+
|
|
31928
|
+
function payload(sessionId, event, cwd) {
|
|
31929
|
+
const p = { session_id: sessionId, hook_event_name: event, cwd, pid: process.pid };
|
|
31930
|
+
if (KIND) p.kind = KIND;
|
|
31931
|
+
return p;
|
|
31932
|
+
}
|
|
31933
|
+
|
|
31934
|
+
function runHook(sessionId, event, cwd) {
|
|
31935
|
+
return new Promise((resolve) => {
|
|
31936
|
+
let out = "";
|
|
31937
|
+
let child;
|
|
31938
|
+
try {
|
|
31939
|
+
child = spawn(HOOK, [], { stdio: ["pipe", "pipe", "ignore"] });
|
|
31940
|
+
} catch {
|
|
31941
|
+
resolve("");
|
|
31942
|
+
return;
|
|
31943
|
+
}
|
|
31944
|
+
const done = setTimeout(() => { child.kill(); resolve(""); }, ${TIMEOUT_SECS2 * 1e3});
|
|
31945
|
+
child.stdout.on("data", (c) => { out += c; });
|
|
31946
|
+
child.on("error", () => { clearTimeout(done); resolve(""); });
|
|
31947
|
+
child.on("close", () => { clearTimeout(done); resolve(out.trim()); });
|
|
31948
|
+
child.stdin.end(JSON.stringify(payload(sessionId, event, cwd)));
|
|
31949
|
+
});
|
|
31950
|
+
}
|
|
31951
|
+
|
|
31952
|
+
/**
|
|
31953
|
+
* Wait for a message to an idle session. The hook long-polls the server and
|
|
31954
|
+
* prints the messages when one arrives; onText gets them. One watcher per
|
|
31955
|
+
* session, owned by this process for as long as the session lives: a turn
|
|
31956
|
+
* starting does not stop it, and a watcher that exits is started again.
|
|
31957
|
+
* --supervised makes the hook say why it stopped (75 ended, 76 another
|
|
31958
|
+
* watcher, 77 not a session to watch) instead of exiting silently.
|
|
31959
|
+
*/
|
|
31960
|
+
const waiters = new Map();
|
|
31961
|
+
|
|
31962
|
+
function startWaiter(sessionId, cwd, onText) {
|
|
31963
|
+
const running = waiters.get(sessionId);
|
|
31964
|
+
if (running && !running.stopped) return;
|
|
31965
|
+
const rec = { child: null, stopped: false, timer: null, tries: 0 };
|
|
31966
|
+
waiters.set(sessionId, rec);
|
|
31967
|
+
const again = (ms) => {
|
|
31968
|
+
if (rec.stopped) return;
|
|
31969
|
+
clearTimeout(rec.timer);
|
|
31970
|
+
rec.timer = setTimeout(launch, ms);
|
|
31971
|
+
};
|
|
31972
|
+
const launch = () => {
|
|
31973
|
+
if (rec.stopped) return;
|
|
31974
|
+
let out = "";
|
|
31975
|
+
let child;
|
|
31976
|
+
try {
|
|
31977
|
+
child = spawn(HOOK, ["--wait", "--supervised"], { stdio: ["pipe", "pipe", "ignore"] });
|
|
31978
|
+
} catch {
|
|
31979
|
+
again(5000);
|
|
31980
|
+
return;
|
|
31981
|
+
}
|
|
31982
|
+
rec.child = child;
|
|
31983
|
+
child.stdout.on("data", (c) => { out += c; });
|
|
31984
|
+
// The close event follows an error, and carries the exit code.
|
|
31985
|
+
child.on("error", () => {});
|
|
31986
|
+
child.on("close", (code) => {
|
|
31987
|
+
rec.child = null;
|
|
31988
|
+
if (rec.stopped) return;
|
|
31989
|
+
const text = out.trim();
|
|
31990
|
+
if (text) {
|
|
31991
|
+
rec.tries = 0;
|
|
31992
|
+
Promise.resolve().then(() => onText(text)).catch(() => {}).then(() => again(0));
|
|
31993
|
+
return;
|
|
31994
|
+
}
|
|
31995
|
+
// 75: the session ended. 76: another process already waits for it.
|
|
31996
|
+
// 77: not a session the watcher serves. Asking again will not change
|
|
31997
|
+
// any of them, so the next event starts a watcher instead.
|
|
31998
|
+
if (code === 75 || code === 76 || code === 77) { waiters.delete(sessionId); return; }
|
|
31999
|
+
rec.tries += 1;
|
|
32000
|
+
again(Math.min(30000, 250 * 2 ** Math.min(rec.tries, 7)));
|
|
32001
|
+
});
|
|
32002
|
+
child.stdin.end(JSON.stringify({ session_id: sessionId, hook_event_name: "Stop", cwd }));
|
|
32003
|
+
};
|
|
32004
|
+
launch();
|
|
32005
|
+
}
|
|
32006
|
+
|
|
32007
|
+
function stopWaiter(sessionId) {
|
|
32008
|
+
const rec = waiters.get(sessionId);
|
|
32009
|
+
if (!rec) return;
|
|
32010
|
+
rec.stopped = true;
|
|
32011
|
+
clearTimeout(rec.timer);
|
|
32012
|
+
waiters.delete(sessionId);
|
|
32013
|
+
try { rec.child?.kill(); } catch { /* gone */ }
|
|
32014
|
+
}
|
|
32015
|
+
|
|
32016
|
+
/**
|
|
32017
|
+
* Start watchers for the sessions that were already open when this plugin
|
|
32018
|
+
* loaded. A reload replaces the plugin, so the new instance has no map from
|
|
32019
|
+
* before, and an idle session emits no further event: without this sweep it
|
|
32020
|
+
* would wait forever for a turn it never starts. Only recent sessions, most
|
|
32021
|
+
* recently used first, because the list can hold every session in the folder.
|
|
32022
|
+
*/
|
|
32023
|
+
async function watchExisting(ctx, cwd, onTextFor) {
|
|
32024
|
+
try {
|
|
32025
|
+
const r = await ctx.session.list?.({});
|
|
32026
|
+
const list = Array.isArray(r) ? r : (r?.data ?? r?.sessions ?? []);
|
|
32027
|
+
const recent = list
|
|
32028
|
+
.filter((s) => s && s.id && !s.parentID)
|
|
32029
|
+
.sort((a, b) => (b.time?.updated ?? 0) - (a.time?.updated ?? 0))
|
|
32030
|
+
.slice(0, 8);
|
|
32031
|
+
for (const s of recent) startWaiter("opencode_" + s.id, cwd, onTextFor(s.id));
|
|
32032
|
+
} catch { /* an older runtime has no list: events still start watchers */ }
|
|
32033
|
+
}
|
|
32034
|
+
`;
|
|
32035
|
+
}
|
|
32036
|
+
function opencodeMessagesSource(wrapperPath) {
|
|
32037
|
+
return `// ${MESSAGES_ID}: written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
32038
|
+
//
|
|
32039
|
+
// Reports each opencode session to chat-recall and adds the messages that
|
|
32040
|
+
// other sessions sent it to the next prompt.
|
|
32041
|
+
${runnerSource(wrapperPath)}
|
|
32042
|
+
const RUN_END = new Set(["session.execution.succeeded", "session.execution.failed", "session.execution.interrupted", "session.idle"]);
|
|
32043
|
+
const INTERRUPT = ${JSON.stringify(INTERRUPT_MARKER)};
|
|
32044
|
+
const INTRO = ${JSON.stringify(selfIntroduction("\0SESSION\0"))};
|
|
32045
|
+
const intro = (id) => INTRO.replace("\0SESSION\0", "opencode_" + id);
|
|
32046
|
+
|
|
32047
|
+
async function setup(ctx) {
|
|
32048
|
+
const dir = ctx?.location?.directory;
|
|
32049
|
+
// A session of a shared \`opencode serve\` belongs to the folder it was made
|
|
32050
|
+
// in, and that is not this plugin instance's folder: the service sends one
|
|
32051
|
+
// plugin instance the events of every project it serves. Asking the session
|
|
32052
|
+
// is the only source that stays right. The instance's folder is the fallback
|
|
32053
|
+
// for a session that cannot be read (just deleted, or an old server).
|
|
32054
|
+
const dirOf = async (id) => {
|
|
32055
|
+
try {
|
|
32056
|
+
const s = await ctx.session.get({ sessionID: id });
|
|
32057
|
+
const d = s?.location?.directory ?? s?.directory;
|
|
32058
|
+
if (typeof d === "string" && d) return d;
|
|
32059
|
+
} catch { /* unknown session: the instance folder is the best guess */ }
|
|
32060
|
+
return dir;
|
|
32061
|
+
};
|
|
32062
|
+
const children = new Set();
|
|
32063
|
+
const isChild = async (id) => {
|
|
32064
|
+
if (children.has(id)) return true;
|
|
32065
|
+
try {
|
|
32066
|
+
const s = await ctx.session.get({ sessionID: id });
|
|
32067
|
+
if (s?.parentID) { children.add(id); return true; }
|
|
32068
|
+
} catch { /* unknown: treat as a main session */ }
|
|
32069
|
+
return false;
|
|
32070
|
+
};
|
|
32071
|
+
// A message becomes a prompt, so an idle session acts on it with nobody
|
|
32072
|
+
// typing. An urgent message stops the turn in progress first.
|
|
32073
|
+
const deliver = (id) => async (text) => {
|
|
32074
|
+
let body = text;
|
|
32075
|
+
if (body.startsWith(INTERRUPT)) {
|
|
32076
|
+
body = body.slice(INTERRUPT.length).replace(/^\\n+/, "");
|
|
32077
|
+
try {
|
|
32078
|
+
if (typeof ctx.session.interrupt === "function") await ctx.session.interrupt({ sessionID: id });
|
|
32079
|
+
else if (typeof ctx.session.abort === "function") await ctx.session.abort({ sessionID: id });
|
|
32080
|
+
} catch { /* the turn was already over */ }
|
|
32081
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
32082
|
+
}
|
|
32083
|
+
await ctx.session.prompt({ sessionID: id, text: body });
|
|
32084
|
+
};
|
|
32085
|
+
await ctx.session.hook("prompt", async (event) => {
|
|
32086
|
+
const id = event?.sessionID;
|
|
32087
|
+
if (!id || !event.prompt || (await isChild(id))) return;
|
|
32088
|
+
// The watcher is not stopped for a turn. A message sent while this turn
|
|
32089
|
+
// runs is already in flight to the runtime as the next prompt, and the
|
|
32090
|
+
// hook below catches anything the watcher did not take.
|
|
32091
|
+
startWaiter("opencode_" + id, await dirOf(id), deliver(id));
|
|
32092
|
+
// The first prompt registers the session; the hook adds only waiting messages.
|
|
32093
|
+
const text = await runHook("opencode_" + id, "UserPromptSubmit", await dirOf(id));
|
|
32094
|
+
if (text) event.prompt.text = [event.prompt.text, text].filter(Boolean).join("\\n\\n");
|
|
32095
|
+
});
|
|
32096
|
+
// The session id goes into the system context of each model call: the agent
|
|
32097
|
+
// always knows it, the user does not see it, and no prompt repeats it.
|
|
32098
|
+
await ctx.session.hook("context", async (event) => {
|
|
32099
|
+
const id = event?.sessionID;
|
|
32100
|
+
if (!id || !Array.isArray(event.system) || (await isChild(id))) return;
|
|
32101
|
+
event.system.push({ type: "text", text: intro(id) });
|
|
32102
|
+
});
|
|
32103
|
+
const controller = new AbortController();
|
|
32104
|
+
(async () => {
|
|
32105
|
+
try {
|
|
32106
|
+
for await (const ev of ctx.event.subscribe({ signal: controller.signal })) {
|
|
32107
|
+
const id = ev?.data?.sessionID ?? ev?.properties?.sessionID;
|
|
32108
|
+
// A session that was open before this plugin loaded (a reload, an
|
|
32109
|
+
// update) is not in started, and still gets its waiter.
|
|
32110
|
+
if (!id || (await isChild(id))) continue;
|
|
32111
|
+
if (RUN_END.has(ev.type)) {
|
|
32112
|
+
const at = await dirOf(id);
|
|
32113
|
+
await runHook("opencode_" + id, "Stop", at);
|
|
32114
|
+
// An idle session acts on a message from another session by itself:
|
|
32115
|
+
// the text becomes its next prompt.
|
|
32116
|
+
startWaiter("opencode_" + id, at, deliver(id));
|
|
32117
|
+
} else if (ev.type === "session.created") {
|
|
32118
|
+
startWaiter("opencode_" + id, await dirOf(id), deliver(id));
|
|
32119
|
+
} else if (ev.type === "session.deleted") {
|
|
32120
|
+
stopWaiter("opencode_" + id);
|
|
32121
|
+
await runHook("opencode_" + id, "SessionEnd", await dirOf(id));
|
|
32122
|
+
}
|
|
32123
|
+
}
|
|
32124
|
+
} catch { /* the subscription ends with the plugin */ }
|
|
32125
|
+
})();
|
|
32126
|
+
await watchExisting(ctx, dir, deliver);
|
|
32127
|
+
return () => {
|
|
32128
|
+
controller.abort();
|
|
32129
|
+
for (const id of [...waiters.keys()]) stopWaiter(id);
|
|
32130
|
+
};
|
|
32131
|
+
}
|
|
32132
|
+
|
|
32133
|
+
const pending = new Map();
|
|
32134
|
+
const children = new Set();
|
|
32135
|
+
let seq = 0;
|
|
32136
|
+
|
|
32137
|
+
function partId() {
|
|
32138
|
+
seq += 1;
|
|
32139
|
+
return "prt_" + Date.now().toString(16) + seq.toString(16).padStart(4, "0") + "chatrecall";
|
|
32140
|
+
}
|
|
32141
|
+
|
|
32142
|
+
async function server({ directory }) {
|
|
32143
|
+
return {
|
|
32144
|
+
event: async ({ event }) => {
|
|
32145
|
+
const info = event?.properties?.info;
|
|
32146
|
+
if (event?.type === "session.created" && info?.id) {
|
|
32147
|
+
if (info.parentID) { children.add(info.id); return; }
|
|
32148
|
+
const text = await runHook("opencode_" + info.id, "SessionStart", directory);
|
|
32149
|
+
if (text) pending.set(info.id, text);
|
|
32150
|
+
} else if (event?.type === "session.idle" && event.properties?.sessionID && !children.has(event.properties.sessionID)) {
|
|
32151
|
+
await runHook("opencode_" + event.properties.sessionID, "Stop", directory);
|
|
32152
|
+
} else if (event?.type === "session.deleted" && info?.id) {
|
|
32153
|
+
children.delete(info.id);
|
|
32154
|
+
pending.delete(info.id);
|
|
32155
|
+
await runHook("opencode_" + info.id, "SessionEnd", directory);
|
|
32156
|
+
}
|
|
32157
|
+
},
|
|
32158
|
+
"experimental.chat.system.transform": async (input, output) => {
|
|
32159
|
+
const id = input?.sessionID;
|
|
32160
|
+
if (!id || children.has(id) || !Array.isArray(output?.system)) return;
|
|
32161
|
+
output.system.push(intro(id));
|
|
32162
|
+
},
|
|
32163
|
+
"chat.message": async (input, output) => {
|
|
32164
|
+
const id = input?.sessionID;
|
|
32165
|
+
if (!id || children.has(id) || !output?.message) return;
|
|
32166
|
+
const before = pending.get(id) ?? "";
|
|
32167
|
+
pending.delete(id);
|
|
32168
|
+
const now = await runHook("opencode_" + id, "UserPromptSubmit", directory);
|
|
32169
|
+
const text = [before, now].filter(Boolean).join("\\n\\n");
|
|
32170
|
+
if (!text) return;
|
|
32171
|
+
output.parts.push({ id: partId(), sessionID: id, messageID: output.message.id, type: "text", text, synthetic: true });
|
|
32172
|
+
},
|
|
32173
|
+
};
|
|
32174
|
+
}
|
|
32175
|
+
|
|
32176
|
+
export default { id: "${MESSAGES_ID}", server, setup };
|
|
32177
|
+
`;
|
|
32178
|
+
}
|
|
32179
|
+
function opencodeTuiSource(wrapperPath) {
|
|
32180
|
+
return `// Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
32181
|
+
//
|
|
32182
|
+
// Registers this opencode TUI with chat-recall before it has a session, so a
|
|
32183
|
+
// message sent to the folder reaches it: the message becomes the TUI's first
|
|
32184
|
+
// session and first prompt. Also reports the session the TUI shows as "tui".
|
|
32185
|
+
import { spawn } from "node:child_process";
|
|
32186
|
+
import { randomBytes } from "node:crypto";
|
|
32187
|
+
import { Plugin } from "@opencode/plugin/tui";
|
|
32188
|
+
|
|
32189
|
+
const HOOK = ${JSON.stringify(wrapperPath)};
|
|
32190
|
+
const PID = process.pid;
|
|
32191
|
+
const POLL_MS = 4000;
|
|
32192
|
+
const RUN_MS = 8000;
|
|
32193
|
+
|
|
32194
|
+
// One state per process, not per module instance. opencode loads this entry
|
|
32195
|
+
// more than once in one TUI process, and a reload keeps the old instance
|
|
32196
|
+
// alive; two instances would each open a presence loop, and the folder would
|
|
32197
|
+
// answer as two windows.
|
|
32198
|
+
const STATE = Symbol.for("chat-recall.tui-plugin");
|
|
32199
|
+
const state = globalThis[STATE] ??= { api: undefined, presence: undefined, timer: undefined, reported: undefined, disposed: false, id: undefined };
|
|
32200
|
+
state.id ??= "tui_" + randomBytes(8).toString("hex");
|
|
32201
|
+
|
|
32202
|
+
/** Run the hook once and return what it printed. */
|
|
32203
|
+
function run(payload, args) {
|
|
32204
|
+
return new Promise((resolve) => {
|
|
32205
|
+
let out = "";
|
|
32206
|
+
let child;
|
|
32207
|
+
try {
|
|
32208
|
+
child = spawn(HOOK, args, { stdio: ["pipe", "pipe", "ignore"] });
|
|
32209
|
+
} catch {
|
|
32210
|
+
resolve("");
|
|
32211
|
+
return;
|
|
32212
|
+
}
|
|
32213
|
+
const done = setTimeout(() => { child.kill(); resolve(""); }, RUN_MS);
|
|
32214
|
+
child.stdout.on("data", (c) => { out += c; });
|
|
32215
|
+
child.on("error", () => { clearTimeout(done); resolve(""); });
|
|
32216
|
+
child.on("close", () => { clearTimeout(done); resolve(out.trim()); });
|
|
32217
|
+
child.stdin.end(JSON.stringify(payload));
|
|
32218
|
+
});
|
|
32219
|
+
}
|
|
32220
|
+
|
|
32221
|
+
function route(api) {
|
|
32222
|
+
try {
|
|
32223
|
+
const r = api.ui.router.current();
|
|
32224
|
+
return r && typeof r === "object" ? r : undefined;
|
|
32225
|
+
} catch {
|
|
32226
|
+
return undefined;
|
|
32227
|
+
}
|
|
32228
|
+
}
|
|
32229
|
+
|
|
32230
|
+
function sessionOf(api) {
|
|
32231
|
+
const r = route(api);
|
|
32232
|
+
return r && r.type === "session" && typeof r.sessionID === "string" ? r.sessionID : undefined;
|
|
32233
|
+
}
|
|
32234
|
+
|
|
32235
|
+
async function report(api, sessionID) {
|
|
32236
|
+
if (!sessionID || sessionID === state.reported) return;
|
|
32237
|
+
state.reported = sessionID;
|
|
32238
|
+
await run({ session_id: "opencode_" + sessionID, cwd: api.location.directory, kind: "tui", pid: PID }, ["--report"]);
|
|
32239
|
+
}
|
|
32240
|
+
|
|
32241
|
+
function stopPresence() {
|
|
32242
|
+
const child = state.presence;
|
|
32243
|
+
state.presence = undefined;
|
|
32244
|
+
if (child) {
|
|
32245
|
+
try { child.kill(); } catch { /* already gone */ }
|
|
32246
|
+
}
|
|
32247
|
+
}
|
|
32248
|
+
|
|
32249
|
+
/**
|
|
32250
|
+
* Register the folder while the TUI shows no session. A message for the folder
|
|
32251
|
+
* arrives on stdout as {"text", "ids"}; the lease expires if this plugin dies
|
|
32252
|
+
* before the prompt lands, and the message is delivered again.
|
|
32253
|
+
*/
|
|
32254
|
+
function startPresence(api) {
|
|
32255
|
+
if (state.disposed || state.presence) return;
|
|
32256
|
+
const dir = api.location.directory;
|
|
32257
|
+
let child;
|
|
32258
|
+
try {
|
|
32259
|
+
child = spawn(HOOK, ["--presence"], { stdio: ["pipe", "pipe", "ignore"] });
|
|
32260
|
+
} catch {
|
|
32261
|
+
return;
|
|
32262
|
+
}
|
|
32263
|
+
state.presence = child;
|
|
32264
|
+
let buffer = "";
|
|
32265
|
+
child.stdout.on("data", (chunk) => {
|
|
32266
|
+
buffer += chunk;
|
|
32267
|
+
let i;
|
|
32268
|
+
while ((i = buffer.indexOf("\\n")) >= 0) {
|
|
32269
|
+
const line = buffer.slice(0, i).trim();
|
|
32270
|
+
buffer = buffer.slice(i + 1);
|
|
32271
|
+
if (!line || state.presence !== child) continue;
|
|
32272
|
+
let msg;
|
|
32273
|
+
try { msg = JSON.parse(line); } catch { continue; }
|
|
32274
|
+
stopPresence();
|
|
32275
|
+
openFirst(api, dir, msg).catch(() => {});
|
|
32276
|
+
break;
|
|
32277
|
+
}
|
|
32278
|
+
});
|
|
32279
|
+
child.on("error", () => { if (state.presence === child) state.presence = undefined; });
|
|
32280
|
+
child.on("close", () => { if (state.presence === child) state.presence = undefined; });
|
|
32281
|
+
child.stdin.end(JSON.stringify({ session_id: state.id, cwd: dir, pid: PID }));
|
|
32282
|
+
}
|
|
32283
|
+
|
|
32284
|
+
/** The message becomes the TUI's first session and first prompt. */
|
|
32285
|
+
async function openFirst(api, dir, msg) {
|
|
32286
|
+
const text = typeof msg.text === "string" ? msg.text : "";
|
|
32287
|
+
const ids = Array.isArray(msg.ids) ? msg.ids.filter((i) => typeof i === "string") : [];
|
|
32288
|
+
if (!text) return;
|
|
32289
|
+
let id;
|
|
32290
|
+
try {
|
|
32291
|
+
const created = await api.client.session.create({ title: "chat-recall message", location: { directory: dir } });
|
|
32292
|
+
id = created?.data?.data?.id ?? created?.data?.id ?? created?.id;
|
|
32293
|
+
} catch {
|
|
32294
|
+
return;
|
|
32295
|
+
}
|
|
32296
|
+
if (typeof id !== "string" || !id) return;
|
|
32297
|
+
try { api.ui.router.navigate({ type: "session", sessionID: id }); } catch { /* the route follows the new session */ }
|
|
32298
|
+
await report(api, id);
|
|
32299
|
+
try {
|
|
32300
|
+
await api.client.session.prompt({ sessionID: id, text });
|
|
32301
|
+
} catch {
|
|
32302
|
+
// The session exists but the prompt did not land. Leave the messages
|
|
32303
|
+
// unacknowledged: their lease returns them.
|
|
32304
|
+
return;
|
|
32305
|
+
}
|
|
32306
|
+
if (ids.length) await run({ session_id: state.id, ids }, ["--ack"]);
|
|
32307
|
+
}
|
|
32308
|
+
|
|
32309
|
+
/** Follow the route: report the session it shows, register the folder otherwise. */
|
|
32310
|
+
function tick() {
|
|
32311
|
+
const api = state.api;
|
|
32312
|
+
if (state.disposed || !api) return;
|
|
32313
|
+
const id = sessionOf(api);
|
|
32314
|
+
if (id) {
|
|
32315
|
+
report(api, id).catch(() => {});
|
|
32316
|
+
stopPresence();
|
|
32317
|
+
} else {
|
|
32318
|
+
startPresence(api);
|
|
32319
|
+
}
|
|
32320
|
+
}
|
|
32321
|
+
|
|
32322
|
+
function shutdown() {
|
|
32323
|
+
state.disposed = true;
|
|
32324
|
+
if (state.timer) { clearInterval(state.timer); state.timer = undefined; }
|
|
32325
|
+
stopPresence();
|
|
32326
|
+
}
|
|
32327
|
+
|
|
32328
|
+
export default Plugin.define({
|
|
32329
|
+
id: "chat-recall-tui",
|
|
32330
|
+
async setup(api) {
|
|
32331
|
+
// Only the TUI has a renderer and a route. A headless process that loads
|
|
32332
|
+
// this entry has neither, and must not answer for anyone's folder.
|
|
32333
|
+
if (!api?.renderer || !api?.location?.directory || !api?.ui?.router) return;
|
|
32334
|
+
// A reload after dispose starts a new life on the same process-wide state.
|
|
32335
|
+
if (state.disposed) { state.disposed = false; state.timer = undefined; state.reported = undefined; }
|
|
32336
|
+
state.api = api;
|
|
32337
|
+
tick();
|
|
32338
|
+
if (!state.timer) {
|
|
32339
|
+
state.timer = setInterval(tick, POLL_MS);
|
|
32340
|
+
if (typeof state.timer.unref === "function") state.timer.unref();
|
|
32341
|
+
}
|
|
32342
|
+
try { api.attention?.dispose?.(shutdown); } catch { /* no dispose registry */ }
|
|
32343
|
+
},
|
|
32344
|
+
});
|
|
32345
|
+
`;
|
|
32346
|
+
}
|
|
32347
|
+
function opencodeTuiFiles(wrapperPath) {
|
|
32348
|
+
return [
|
|
32349
|
+
{
|
|
32350
|
+
name: "package.json",
|
|
32351
|
+
source: JSON.stringify({
|
|
32352
|
+
name: OPENCODE_TUI_PACKAGE,
|
|
32353
|
+
private: true,
|
|
32354
|
+
type: "module",
|
|
32355
|
+
exports: { ".": "./index.js", "./tui": "./tui.js" }
|
|
32356
|
+
}, null, 2) + "\n"
|
|
32357
|
+
},
|
|
32358
|
+
{
|
|
32359
|
+
// The package's server entry. The message plugin next to it is the
|
|
32360
|
+
// server plugin; this one only has to exist for the package to load.
|
|
32361
|
+
name: "index.js",
|
|
32362
|
+
source: `// Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
32363
|
+
export default { id: "${OPENCODE_TUI_PACKAGE}", setup() {} };
|
|
32364
|
+
`
|
|
32365
|
+
},
|
|
32366
|
+
{ name: "tui.js", source: opencodeTuiSource(wrapperPath) }
|
|
32367
|
+
];
|
|
32368
|
+
}
|
|
32369
|
+
function piMessagesSource(wrapperPath) {
|
|
32370
|
+
return `// ${MESSAGES_ID}: written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
32371
|
+
//
|
|
32372
|
+
// Reports each pi session to chat-recall and adds the messages that other
|
|
32373
|
+
// sessions sent it to the next prompt.
|
|
32374
|
+
${runnerSource(wrapperPath)}
|
|
32375
|
+
const INTERRUPT = ${JSON.stringify(INTERRUPT_MARKER)};
|
|
32376
|
+
export default function (pi) {
|
|
32377
|
+
let pending = "";
|
|
32378
|
+
const idOf = (ctx) => "pi_" + ctx.sessionManager.getSessionId();
|
|
32379
|
+
const cwdOf = (ctx) => ctx.sessionManager.getCwd();
|
|
32380
|
+
|
|
32381
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
32382
|
+
pending = await runHook(idOf(ctx), "SessionStart", cwdOf(ctx));
|
|
32383
|
+
});
|
|
32384
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
32385
|
+
if (event.messageType !== "user") return;
|
|
32386
|
+
const now = await runHook(idOf(ctx), "UserPromptSubmit", cwdOf(ctx));
|
|
32387
|
+
const text = [pending, now].filter(Boolean).join("\\n\\n");
|
|
32388
|
+
pending = "";
|
|
32389
|
+
if (!text) return;
|
|
32390
|
+
return { message: { customType: "${MESSAGES_ID}", content: text, display: true } };
|
|
32391
|
+
});
|
|
32392
|
+
pi.on("agent_end", async (_event, ctx) => {
|
|
32393
|
+
await runHook(idOf(ctx), "Stop", cwdOf(ctx));
|
|
32394
|
+
// An idle session acts on a message from another session by itself.
|
|
32395
|
+
startWaiter(idOf(ctx), cwdOf(ctx), (text) => {
|
|
32396
|
+
const body = text.startsWith(INTERRUPT) ? text.slice(INTERRUPT.length).replace(/^\\n+/, "") : text;
|
|
32397
|
+
pi.sendUserMessage(body);
|
|
32398
|
+
});
|
|
32399
|
+
});
|
|
32400
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
32401
|
+
stopWaiter(idOf(ctx));
|
|
32402
|
+
await runHook(idOf(ctx), "SessionEnd", cwdOf(ctx));
|
|
32403
|
+
});
|
|
32404
|
+
}
|
|
32405
|
+
`;
|
|
32406
|
+
}
|
|
32407
|
+
var MESSAGES_ID, TIMEOUT_SECS2, isOurs2, asArray3, obj, CODEX_EVENTS, CURSOR_EVENTS, OPENCODE_TUI_PACKAGE;
|
|
32408
|
+
var init_message_registration = __esm({
|
|
32409
|
+
"../engine/dist/core/message-registration.js"() {
|
|
32410
|
+
"use strict";
|
|
32411
|
+
init_backends();
|
|
32412
|
+
init_guard_registration();
|
|
32413
|
+
init_session_messages();
|
|
32414
|
+
MESSAGES_ID = "chat-recall-messages";
|
|
32415
|
+
TIMEOUT_SECS2 = 10;
|
|
32416
|
+
isOurs2 = (cmd) => typeof cmd === "string" && cmd.includes("chat_recall_messages_");
|
|
32417
|
+
asArray3 = (v) => Array.isArray(v) ? v : [];
|
|
32418
|
+
obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? { ...v } : {};
|
|
32419
|
+
CODEX_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop", "SessionEnd"];
|
|
32420
|
+
CURSOR_EVENTS = ["sessionStart", "beforeSubmitPrompt", "stop", "sessionEnd"];
|
|
32421
|
+
OPENCODE_TUI_PACKAGE = "chat-recall-tui";
|
|
32422
|
+
}
|
|
32423
|
+
});
|
|
32424
|
+
|
|
32425
|
+
// ../engine/dist/core/opencode-tui-config.js
|
|
32426
|
+
import { existsSync as existsSync46, readFileSync as readFileSync41, renameSync as renameSync5, writeFileSync as writeFileSync12 } from "node:fs";
|
|
32427
|
+
import { join as join52, relative, sep as sep4 } from "node:path";
|
|
32428
|
+
function tuiConfigPath(configDir = opencodeConfigDir()) {
|
|
32429
|
+
const jsonc = join52(configDir, "tui.jsonc");
|
|
32430
|
+
if (existsSync46(jsonc))
|
|
32431
|
+
return jsonc;
|
|
32432
|
+
return join52(configDir, "tui.json");
|
|
32433
|
+
}
|
|
32434
|
+
function tuiPluginEntry(configDir = opencodeConfigDir()) {
|
|
32435
|
+
const file = join52(opencodePluginDir(), OPENCODE_TUI_PACKAGE, "tui.js");
|
|
32436
|
+
return `./${relative(configDir, file).split(sep4).join("/")}`;
|
|
32437
|
+
}
|
|
32438
|
+
function tokenize(src) {
|
|
32439
|
+
const out = [];
|
|
32440
|
+
let i = 0;
|
|
32441
|
+
while (i < src.length) {
|
|
32442
|
+
const c = src[i];
|
|
32443
|
+
if (c === " " || c === " " || c === "\n" || c === "\r" || c === "\uFEFF") {
|
|
32444
|
+
i += 1;
|
|
32445
|
+
continue;
|
|
32446
|
+
}
|
|
32447
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
32448
|
+
const e = src.indexOf("\n", i);
|
|
32449
|
+
i = e < 0 ? src.length : e + 1;
|
|
32450
|
+
continue;
|
|
32451
|
+
}
|
|
32452
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
32453
|
+
const e = src.indexOf("*/", i + 2);
|
|
32454
|
+
if (e < 0)
|
|
32455
|
+
throw new SyntaxError(`unterminated comment at ${i}`);
|
|
32456
|
+
i = e + 2;
|
|
32457
|
+
continue;
|
|
32458
|
+
}
|
|
32459
|
+
if (c === "{" || c === "}" || c === "[" || c === "]" || c === ":" || c === ",") {
|
|
32460
|
+
out.push({ t: "p", v: c, start: i, end: i + 1 });
|
|
32461
|
+
i += 1;
|
|
32462
|
+
continue;
|
|
32463
|
+
}
|
|
32464
|
+
if (c === '"') {
|
|
32465
|
+
let j3 = i + 1;
|
|
32466
|
+
while (j3 < src.length && src[j3] !== '"') {
|
|
32467
|
+
if (src[j3] === "\\")
|
|
32468
|
+
j3 += 1;
|
|
32469
|
+
j3 += 1;
|
|
32470
|
+
}
|
|
32471
|
+
if (j3 >= src.length)
|
|
32472
|
+
throw new SyntaxError(`unterminated string at ${i}`);
|
|
32473
|
+
out.push({ t: "s", v: JSON.parse(src.slice(i, j3 + 1)), start: i, end: j3 + 1 });
|
|
32474
|
+
i = j3 + 1;
|
|
32475
|
+
continue;
|
|
32476
|
+
}
|
|
32477
|
+
let j2 = i;
|
|
32478
|
+
while (j2 < src.length && !/[\s,:{}[\]"/]/.test(src[j2]))
|
|
32479
|
+
j2 += 1;
|
|
32480
|
+
if (j2 === i)
|
|
32481
|
+
throw new SyntaxError(`unexpected character at ${i}`);
|
|
32482
|
+
out.push({ t: "a", v: src.slice(i, j2), start: i, end: j2 });
|
|
32483
|
+
i = j2;
|
|
32484
|
+
}
|
|
32485
|
+
return out;
|
|
32486
|
+
}
|
|
32487
|
+
function parseRoot(src) {
|
|
32488
|
+
const toks = tokenize(src);
|
|
32489
|
+
if (toks.length === 0)
|
|
32490
|
+
return null;
|
|
32491
|
+
const p = new Parser(toks);
|
|
32492
|
+
const root = p.value();
|
|
32493
|
+
if (root.k !== "obj")
|
|
32494
|
+
throw new SyntaxError("the top level is not an object");
|
|
32495
|
+
const rest = toks.findIndex((t) => t.start >= root.end);
|
|
32496
|
+
if (rest !== -1)
|
|
32497
|
+
throw new SyntaxError(`unexpected "${toks[rest].v}" after the top-level object`);
|
|
32498
|
+
return root;
|
|
32499
|
+
}
|
|
32500
|
+
function pluginArray(root) {
|
|
32501
|
+
if (!root || root.k !== "obj")
|
|
32502
|
+
return {};
|
|
32503
|
+
const prop = root.props.find((p) => p.key === "plugin");
|
|
32504
|
+
if (!prop)
|
|
32505
|
+
return {};
|
|
32506
|
+
if (prop.value.k !== "arr")
|
|
32507
|
+
return { error: '"plugin" is not a list' };
|
|
32508
|
+
return { arr: prop.value };
|
|
32509
|
+
}
|
|
32510
|
+
function splice(src, from, to, insert) {
|
|
32511
|
+
return src.slice(0, from) + insert + src.slice(to);
|
|
32512
|
+
}
|
|
32513
|
+
function hasTuiPluginEntry(src, entry) {
|
|
32514
|
+
try {
|
|
32515
|
+
const { arr } = pluginArray(parseRoot(src));
|
|
32516
|
+
return !!arr && arr.items.some((it) => it.k === "str" && it.v === entry);
|
|
32517
|
+
} catch {
|
|
32518
|
+
return false;
|
|
32519
|
+
}
|
|
32520
|
+
}
|
|
32521
|
+
function addTuiPluginEntry(src, entry) {
|
|
32522
|
+
let root;
|
|
32523
|
+
try {
|
|
32524
|
+
root = parseRoot(src);
|
|
32525
|
+
} catch (e) {
|
|
32526
|
+
return { ok: false, reason: `not valid JSONC: ${e.message}` };
|
|
32527
|
+
}
|
|
32528
|
+
const literal = JSON.stringify(entry);
|
|
32529
|
+
if (!root) {
|
|
32530
|
+
return { ok: true, changed: true, text: `{
|
|
32531
|
+
"plugin": [${literal}]
|
|
32532
|
+
}
|
|
32533
|
+
` };
|
|
32534
|
+
}
|
|
32535
|
+
const { arr, error } = pluginArray(root);
|
|
32536
|
+
if (error)
|
|
32537
|
+
return { ok: false, reason: error };
|
|
32538
|
+
if (arr) {
|
|
32539
|
+
if (arr.items.some((it) => it.k === "str" && it.v === entry))
|
|
32540
|
+
return { ok: true, changed: false, text: src };
|
|
32541
|
+
const last = arr.items[arr.items.length - 1];
|
|
32542
|
+
const text = last ? splice(src, last.end, last.end, `, ${literal}`) : splice(src, arr.closeStart, arr.closeStart, literal);
|
|
32543
|
+
return { ok: true, changed: true, text };
|
|
32544
|
+
}
|
|
32545
|
+
const props = root.props;
|
|
32546
|
+
if (props.length === 0) {
|
|
32547
|
+
return { ok: true, changed: true, text: splice(src, root.start + 1, root.start + 1, `
|
|
32548
|
+
"plugin": [${literal}]
|
|
32549
|
+
`) };
|
|
32550
|
+
}
|
|
32551
|
+
const lastValue = props[props.length - 1].value;
|
|
32552
|
+
return { ok: true, changed: true, text: splice(src, lastValue.end, lastValue.end, `,
|
|
32553
|
+
"plugin": [${literal}]`) };
|
|
32554
|
+
}
|
|
32555
|
+
function removeTuiPluginEntry(src, entry) {
|
|
32556
|
+
let text = src;
|
|
32557
|
+
let changed = false;
|
|
32558
|
+
for (; ; ) {
|
|
32559
|
+
let root;
|
|
32560
|
+
try {
|
|
32561
|
+
root = parseRoot(text);
|
|
32562
|
+
} catch (e) {
|
|
32563
|
+
return { ok: false, reason: `not valid JSONC: ${e.message}` };
|
|
32564
|
+
}
|
|
32565
|
+
const { arr, error } = pluginArray(root);
|
|
32566
|
+
if (error)
|
|
32567
|
+
return { ok: false, reason: error };
|
|
32568
|
+
if (!arr)
|
|
32569
|
+
break;
|
|
32570
|
+
const i = arr.items.findIndex((it) => it.k === "str" && it.v === entry);
|
|
32571
|
+
if (i === -1)
|
|
32572
|
+
break;
|
|
32573
|
+
const item = arr.items[i];
|
|
32574
|
+
const comma = arr.commas[i];
|
|
32575
|
+
if (comma !== null) {
|
|
32576
|
+
text = splice(text, item.start, comma + 1, "");
|
|
32577
|
+
} else if (i > 0 && arr.commas[i - 1] !== null) {
|
|
32578
|
+
text = splice(text, arr.commas[i - 1], item.end, "");
|
|
32579
|
+
} else {
|
|
32580
|
+
text = splice(text, item.start, item.end, "");
|
|
32581
|
+
}
|
|
32582
|
+
changed = true;
|
|
32583
|
+
}
|
|
32584
|
+
return { ok: true, changed, text };
|
|
32585
|
+
}
|
|
32586
|
+
function writeTextAtomic(path, text) {
|
|
32587
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
32588
|
+
writeFileSync12(tmp, text);
|
|
32589
|
+
renameSync5(tmp, path);
|
|
32590
|
+
}
|
|
32591
|
+
function registerTuiPlugin(path = tuiConfigPath(), entry = tuiPluginEntry()) {
|
|
32592
|
+
const current = existsSync46(path) ? readFileSync41(path, "utf-8") : "";
|
|
32593
|
+
const edit = addTuiPluginEntry(current, entry);
|
|
32594
|
+
if (!edit.ok)
|
|
32595
|
+
return { status: "unparseable", path, reason: edit.reason };
|
|
32596
|
+
if (!edit.changed)
|
|
32597
|
+
return { status: "present", path };
|
|
32598
|
+
writeTextAtomic(path, edit.text);
|
|
32599
|
+
return { status: "added", path };
|
|
32600
|
+
}
|
|
32601
|
+
function unregisterTuiPlugin(path = tuiConfigPath(), entry = tuiPluginEntry()) {
|
|
32602
|
+
if (!existsSync46(path))
|
|
32603
|
+
return { removed: false, path };
|
|
32604
|
+
const edit = removeTuiPluginEntry(readFileSync41(path, "utf-8"), entry);
|
|
32605
|
+
if (!edit.ok || !edit.changed)
|
|
32606
|
+
return { removed: false, path };
|
|
32607
|
+
writeTextAtomic(path, edit.text);
|
|
32608
|
+
return { removed: true, path };
|
|
32609
|
+
}
|
|
32610
|
+
var ATOM, Parser;
|
|
32611
|
+
var init_opencode_tui_config = __esm({
|
|
32612
|
+
"../engine/dist/core/opencode-tui-config.js"() {
|
|
32613
|
+
"use strict";
|
|
32614
|
+
init_guard_registration();
|
|
32615
|
+
init_message_registration();
|
|
32616
|
+
ATOM = /^(true|false|null|-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?)$/;
|
|
32617
|
+
Parser = class {
|
|
32618
|
+
toks;
|
|
32619
|
+
i = 0;
|
|
32620
|
+
constructor(toks) {
|
|
32621
|
+
this.toks = toks;
|
|
32622
|
+
}
|
|
32623
|
+
at() {
|
|
32624
|
+
return this.toks[this.i];
|
|
32625
|
+
}
|
|
32626
|
+
isP(t, v) {
|
|
32627
|
+
return !!t && t.t === "p" && t.v === v;
|
|
32628
|
+
}
|
|
32629
|
+
value() {
|
|
32630
|
+
const t = this.at();
|
|
32631
|
+
if (!t)
|
|
32632
|
+
throw new SyntaxError("unexpected end of file");
|
|
32633
|
+
if (t.t === "s") {
|
|
32634
|
+
this.i += 1;
|
|
32635
|
+
return { k: "str", start: t.start, end: t.end, v: t.v };
|
|
32636
|
+
}
|
|
32637
|
+
if (t.t === "a") {
|
|
32638
|
+
if (!ATOM.test(t.v))
|
|
32639
|
+
throw new SyntaxError(`unknown word "${t.v}" at ${t.start}`);
|
|
32640
|
+
this.i += 1;
|
|
32641
|
+
return { k: "atom", start: t.start, end: t.end, v: t.v };
|
|
32642
|
+
}
|
|
32643
|
+
if (this.isP(t, "{"))
|
|
32644
|
+
return this.object(t);
|
|
32645
|
+
if (this.isP(t, "["))
|
|
32646
|
+
return this.array(t);
|
|
32647
|
+
throw new SyntaxError(`unexpected "${t.v}" at ${t.start}`);
|
|
32648
|
+
}
|
|
32649
|
+
object(open3) {
|
|
32650
|
+
this.i += 1;
|
|
32651
|
+
const props = [];
|
|
32652
|
+
for (; ; ) {
|
|
32653
|
+
const k = this.at();
|
|
32654
|
+
if (this.isP(k, "}")) {
|
|
32655
|
+
this.i += 1;
|
|
32656
|
+
return { k: "obj", start: open3.start, end: k.end, closeStart: k.start, props };
|
|
32657
|
+
}
|
|
32658
|
+
if (!k || k.t !== "s")
|
|
32659
|
+
throw new SyntaxError(`expected a key at ${k ? k.start : "end"}`);
|
|
32660
|
+
this.i += 1;
|
|
32661
|
+
if (!this.isP(this.at(), ":"))
|
|
32662
|
+
throw new SyntaxError(`expected ":" after key at ${k.start}`);
|
|
32663
|
+
this.i += 1;
|
|
32664
|
+
props.push({ key: k.v, value: this.value() });
|
|
32665
|
+
const n = this.at();
|
|
32666
|
+
if (this.isP(n, ",")) {
|
|
32667
|
+
this.i += 1;
|
|
32668
|
+
continue;
|
|
32669
|
+
}
|
|
32670
|
+
if (this.isP(n, "}"))
|
|
32671
|
+
continue;
|
|
32672
|
+
throw new SyntaxError(`expected "," or "}" at ${n ? n.start : "end"}`);
|
|
32673
|
+
}
|
|
32674
|
+
}
|
|
32675
|
+
array(open3) {
|
|
32676
|
+
this.i += 1;
|
|
32677
|
+
const items = [];
|
|
32678
|
+
const commas = [];
|
|
32679
|
+
for (; ; ) {
|
|
32680
|
+
const n = this.at();
|
|
32681
|
+
if (this.isP(n, "]")) {
|
|
32682
|
+
this.i += 1;
|
|
32683
|
+
return { k: "arr", start: open3.start, end: n.end, closeStart: n.start, items, commas };
|
|
32684
|
+
}
|
|
32685
|
+
items.push(this.value());
|
|
32686
|
+
const c = this.at();
|
|
32687
|
+
if (this.isP(c, ",")) {
|
|
32688
|
+
commas.push(c.start);
|
|
32689
|
+
this.i += 1;
|
|
32690
|
+
continue;
|
|
32691
|
+
}
|
|
32692
|
+
commas.push(null);
|
|
32693
|
+
if (!this.isP(this.at(), "]"))
|
|
32694
|
+
throw new SyntaxError(`expected "," or "]" at ${c ? c.start : "end"}`);
|
|
32695
|
+
}
|
|
32696
|
+
}
|
|
32697
|
+
};
|
|
32698
|
+
}
|
|
32699
|
+
});
|
|
32700
|
+
|
|
31487
32701
|
// src/init-report.ts
|
|
31488
32702
|
var init_report_exports = {};
|
|
31489
32703
|
__export(init_report_exports, {
|
|
@@ -31530,12 +32744,12 @@ __export(mcp_clients_exports, {
|
|
|
31530
32744
|
inspectMcpClients: () => inspectMcpClients,
|
|
31531
32745
|
registerMcpEverywhere: () => registerMcpEverywhere
|
|
31532
32746
|
});
|
|
31533
|
-
import { existsSync as
|
|
31534
|
-
import { homedir as
|
|
31535
|
-
import { dirname as dirname21, join as
|
|
31536
|
-
function
|
|
32747
|
+
import { existsSync as existsSync47, mkdirSync as mkdirSync12, readFileSync as readFileSync42, writeFileSync as writeFileSync13 } from "fs";
|
|
32748
|
+
import { homedir as homedir19 } from "os";
|
|
32749
|
+
import { dirname as dirname21, join as join53 } from "path";
|
|
32750
|
+
function piAgentDir2(home) {
|
|
31537
32751
|
const override = process.env.CHAT_RECALL_PI_HOME?.trim() || loadSourceSettings().piHome || process.env.PI_CODING_AGENT_DIR?.trim();
|
|
31538
|
-
return override ? expandTildePath(override) :
|
|
32752
|
+
return override ? expandTildePath(override) : join53(home, ".pi", "agent");
|
|
31539
32753
|
}
|
|
31540
32754
|
function envHome(varName, fallback) {
|
|
31541
32755
|
const v = process.env[varName];
|
|
@@ -31543,17 +32757,17 @@ function envHome(varName, fallback) {
|
|
|
31543
32757
|
}
|
|
31544
32758
|
function writeFileMkdir(path, body2) {
|
|
31545
32759
|
mkdirSync12(dirname21(path), { recursive: true });
|
|
31546
|
-
|
|
32760
|
+
writeFileSync13(path, body2);
|
|
31547
32761
|
}
|
|
31548
32762
|
function readJsonObject(path) {
|
|
31549
|
-
const raw =
|
|
32763
|
+
const raw = readFileSync42(path, "utf-8");
|
|
31550
32764
|
if (raw.trim() === "")
|
|
31551
32765
|
return {};
|
|
31552
32766
|
return JSON.parse(raw);
|
|
31553
32767
|
}
|
|
31554
32768
|
function registerMcpServersJson(target, path, spec) {
|
|
31555
32769
|
let cfg = {};
|
|
31556
|
-
if (
|
|
32770
|
+
if (existsSync47(path)) {
|
|
31557
32771
|
try {
|
|
31558
32772
|
cfg = readJsonObject(path);
|
|
31559
32773
|
} catch (err) {
|
|
@@ -31582,7 +32796,7 @@ function registerOpencodeJson(path, spec) {
|
|
|
31582
32796
|
const id = "opencode";
|
|
31583
32797
|
const label = "OpenCode";
|
|
31584
32798
|
let cfg = {};
|
|
31585
|
-
if (
|
|
32799
|
+
if (existsSync47(path)) {
|
|
31586
32800
|
try {
|
|
31587
32801
|
cfg = readJsonObject(path);
|
|
31588
32802
|
} catch (err) {
|
|
@@ -31621,7 +32835,7 @@ function registerCodexToml(path, spec) {
|
|
|
31621
32835
|
const id = "codex";
|
|
31622
32836
|
const label = "Codex";
|
|
31623
32837
|
const block = codexBlock(spec);
|
|
31624
|
-
const prev =
|
|
32838
|
+
const prev = existsSync47(path) ? readFileSync42(path, "utf-8") : "";
|
|
31625
32839
|
const lines = prev.length ? prev.split("\n") : [];
|
|
31626
32840
|
const start = lines.findIndex((l) => l.trim() === CODEX_HEADER);
|
|
31627
32841
|
if (start === -1) {
|
|
@@ -31653,18 +32867,18 @@ function getMcpClient(id) {
|
|
|
31653
32867
|
return t;
|
|
31654
32868
|
}
|
|
31655
32869
|
function registerMcpEverywhere(spec, opts = {}) {
|
|
31656
|
-
const home = opts.home ??
|
|
32870
|
+
const home = opts.home ?? homedir19();
|
|
31657
32871
|
const forced = new Set(opts.extraIds ?? []);
|
|
31658
32872
|
return MCP_CLIENTS.filter((c) => c.isPresent(home) || forced.has(c.id)).map((c) => c.register(spec, home));
|
|
31659
32873
|
}
|
|
31660
32874
|
function inspectMcpClients(opts = {}) {
|
|
31661
|
-
const home = opts.home ??
|
|
32875
|
+
const home = opts.home ?? homedir19();
|
|
31662
32876
|
return MCP_CLIENTS.map((c) => {
|
|
31663
32877
|
const path = c.configPath(home);
|
|
31664
32878
|
let registered = false;
|
|
31665
|
-
if (
|
|
32879
|
+
if (existsSync47(path)) {
|
|
31666
32880
|
try {
|
|
31667
|
-
const raw =
|
|
32881
|
+
const raw = readFileSync42(path, "utf-8");
|
|
31668
32882
|
registered = c.id === "codex" ? raw.includes(CODEX_HEADER) : !!(JSON.parse(raw).mcpServers?.[MCP_SERVER_NAME] ?? JSON.parse(raw).mcp?.[MCP_SERVER_NAME]);
|
|
31669
32883
|
} catch {
|
|
31670
32884
|
registered = false;
|
|
@@ -31686,7 +32900,7 @@ var init_mcp_clients = __esm({
|
|
|
31686
32900
|
id: "claude",
|
|
31687
32901
|
label: "Claude Code",
|
|
31688
32902
|
bin: "claude",
|
|
31689
|
-
configPath: (home) =>
|
|
32903
|
+
configPath: (home) => join53(home, ".mcp.json"),
|
|
31690
32904
|
// Claude Code is the reference client and `init`'s historical target, so we
|
|
31691
32905
|
// always write it — a fresh machine has no ~/.claude yet on first install.
|
|
31692
32906
|
isPresent: () => true,
|
|
@@ -31698,10 +32912,10 @@ var init_mcp_clients = __esm({
|
|
|
31698
32912
|
id: "codex",
|
|
31699
32913
|
label: "Codex",
|
|
31700
32914
|
bin: "codex",
|
|
31701
|
-
configPath: (home) =>
|
|
32915
|
+
configPath: (home) => join53(envHome("CHAT_RECALL_CODEX_HOME", join53(home, ".codex")), "config.toml"),
|
|
31702
32916
|
isPresent(home) {
|
|
31703
32917
|
const p = this.configPath(home);
|
|
31704
|
-
return
|
|
32918
|
+
return existsSync47(p) || existsSync47(dirname21(p));
|
|
31705
32919
|
},
|
|
31706
32920
|
register(spec, home) {
|
|
31707
32921
|
return registerCodexToml(this.configPath(home), spec);
|
|
@@ -31711,10 +32925,10 @@ var init_mcp_clients = __esm({
|
|
|
31711
32925
|
id: "opencode",
|
|
31712
32926
|
label: "OpenCode",
|
|
31713
32927
|
bin: "opencode",
|
|
31714
|
-
configPath: (home) =>
|
|
32928
|
+
configPath: (home) => join53(envHome("XDG_CONFIG_HOME", join53(home, ".config")), "opencode", "opencode.json"),
|
|
31715
32929
|
isPresent(home) {
|
|
31716
32930
|
const p = this.configPath(home);
|
|
31717
|
-
return
|
|
32931
|
+
return existsSync47(p) || existsSync47(dirname21(p));
|
|
31718
32932
|
},
|
|
31719
32933
|
register(spec, home) {
|
|
31720
32934
|
return registerOpencodeJson(this.configPath(home), spec);
|
|
@@ -31726,9 +32940,9 @@ var init_mcp_clients = __esm({
|
|
|
31726
32940
|
id: "agy",
|
|
31727
32941
|
label: "Antigravity",
|
|
31728
32942
|
bin: "agy",
|
|
31729
|
-
configPath: (home) =>
|
|
32943
|
+
configPath: (home) => join53(home, ".gemini", "config", "mcp_config.json"),
|
|
31730
32944
|
isPresent(home) {
|
|
31731
|
-
return
|
|
32945
|
+
return existsSync47(join53(home, ".gemini", "antigravity-cli")) || existsSync47(this.configPath(home));
|
|
31732
32946
|
},
|
|
31733
32947
|
register(spec, home) {
|
|
31734
32948
|
return registerMcpServersJson(this, this.configPath(home), spec);
|
|
@@ -31738,10 +32952,10 @@ var init_mcp_clients = __esm({
|
|
|
31738
32952
|
id: "cursor",
|
|
31739
32953
|
label: "Cursor",
|
|
31740
32954
|
bin: "cursor",
|
|
31741
|
-
configPath: (home) =>
|
|
32955
|
+
configPath: (home) => join53(home, ".cursor", "mcp.json"),
|
|
31742
32956
|
isPresent(home) {
|
|
31743
32957
|
const p = this.configPath(home);
|
|
31744
|
-
return
|
|
32958
|
+
return existsSync47(p) || existsSync47(dirname21(p));
|
|
31745
32959
|
},
|
|
31746
32960
|
register(spec, home) {
|
|
31747
32961
|
return registerMcpServersJson(this, this.configPath(home), spec);
|
|
@@ -31753,10 +32967,10 @@ var init_mcp_clients = __esm({
|
|
|
31753
32967
|
id: "pi",
|
|
31754
32968
|
label: "Pi",
|
|
31755
32969
|
bin: "pi",
|
|
31756
|
-
configPath: (home) =>
|
|
32970
|
+
configPath: (home) => join53(piAgentDir2(home), "mcp.json"),
|
|
31757
32971
|
isPresent(home) {
|
|
31758
32972
|
const p = this.configPath(home);
|
|
31759
|
-
return
|
|
32973
|
+
return existsSync47(p) || existsSync47(piAgentDir2(home));
|
|
31760
32974
|
},
|
|
31761
32975
|
register(spec, home) {
|
|
31762
32976
|
return registerMcpServersJson(this, this.configPath(home), spec);
|
|
@@ -31780,9 +32994,9 @@ __export(companions_exports, {
|
|
|
31780
32994
|
uninstallCodeindex: () => uninstallCodeindex,
|
|
31781
32995
|
unregisterCodeindexMcp: () => unregisterCodeindexMcp
|
|
31782
32996
|
});
|
|
31783
|
-
import { existsSync as
|
|
31784
|
-
import { homedir as
|
|
31785
|
-
import { join as
|
|
32997
|
+
import { existsSync as existsSync48, mkdirSync as mkdirSync13, statSync as statSync43, chmodSync as chmodSync4, unlinkSync as unlinkSync3, renameSync as renameSync6, createWriteStream as createWriteStream2, readFileSync as readFileSync43, writeFileSync as writeFileSync14 } from "node:fs";
|
|
32998
|
+
import { homedir as homedir20 } from "node:os";
|
|
32999
|
+
import { join as join54 } from "node:path";
|
|
31786
33000
|
import { execSync as execSync3 } from "node:child_process";
|
|
31787
33001
|
import { createHash as createHash11 } from "node:crypto";
|
|
31788
33002
|
function expectedCodeindexSha256(artifact) {
|
|
@@ -31892,7 +33106,7 @@ async function installCodeindex(opts = {}) {
|
|
|
31892
33106
|
if (!expected) {
|
|
31893
33107
|
throw new Error(`No pinned checksum for ${status.artifactName} \u2014 refusing to install an unverified binary. Add its sha256 to CODEINDEX_SHA256 in companions.ts.`);
|
|
31894
33108
|
}
|
|
31895
|
-
const actual = createHash11("sha256").update(
|
|
33109
|
+
const actual = createHash11("sha256").update(readFileSync43(tmpPath)).digest("hex");
|
|
31896
33110
|
if (actual !== expected) {
|
|
31897
33111
|
throw new Error(`Checksum mismatch for ${status.artifactName}.
|
|
31898
33112
|
expected ${expected}
|
|
@@ -31900,10 +33114,10 @@ async function installCodeindex(opts = {}) {
|
|
|
31900
33114
|
Refusing to install. The release may have been re-uploaded, or something is serving different bytes.`);
|
|
31901
33115
|
}
|
|
31902
33116
|
chmodSync4(tmpPath, 493);
|
|
31903
|
-
|
|
33117
|
+
renameSync6(tmpPath, CODEINDEX_BIN_PATH);
|
|
31904
33118
|
} catch (err) {
|
|
31905
33119
|
try {
|
|
31906
|
-
if (
|
|
33120
|
+
if (existsSync48(tmpPath))
|
|
31907
33121
|
unlinkSync3(tmpPath);
|
|
31908
33122
|
} catch {
|
|
31909
33123
|
}
|
|
@@ -31912,7 +33126,7 @@ Refusing to install. The release may have been re-uploaded, or something is serv
|
|
|
31912
33126
|
return checkCodeindexStatus();
|
|
31913
33127
|
}
|
|
31914
33128
|
function uninstallCodeindex() {
|
|
31915
|
-
if (
|
|
33129
|
+
if (existsSync48(CODEINDEX_BIN_PATH)) {
|
|
31916
33130
|
unlinkSync3(CODEINDEX_BIN_PATH);
|
|
31917
33131
|
return { removed: true, path: CODEINDEX_BIN_PATH };
|
|
31918
33132
|
}
|
|
@@ -31920,9 +33134,9 @@ function uninstallCodeindex() {
|
|
|
31920
33134
|
}
|
|
31921
33135
|
function registerCodeindexMcp(mcpJsonPath, binaryPath) {
|
|
31922
33136
|
let cfg = {};
|
|
31923
|
-
if (
|
|
33137
|
+
if (existsSync48(mcpJsonPath)) {
|
|
31924
33138
|
try {
|
|
31925
|
-
cfg = JSON.parse(
|
|
33139
|
+
cfg = JSON.parse(readFileSync43(mcpJsonPath, "utf-8"));
|
|
31926
33140
|
} catch {
|
|
31927
33141
|
cfg = {};
|
|
31928
33142
|
}
|
|
@@ -31931,22 +33145,22 @@ function registerCodeindexMcp(mcpJsonPath, binaryPath) {
|
|
|
31931
33145
|
if (cfg.mcpServers["codeindex"])
|
|
31932
33146
|
return { added: false };
|
|
31933
33147
|
cfg.mcpServers["codeindex"] = { command: binaryPath, args: ["--mcp"] };
|
|
31934
|
-
|
|
33148
|
+
writeFileSync14(mcpJsonPath, JSON.stringify(cfg, null, 2));
|
|
31935
33149
|
return { added: true };
|
|
31936
33150
|
}
|
|
31937
33151
|
function unregisterCodeindexMcp(mcpJsonPath) {
|
|
31938
|
-
if (!
|
|
33152
|
+
if (!existsSync48(mcpJsonPath))
|
|
31939
33153
|
return { removed: false };
|
|
31940
33154
|
let cfg;
|
|
31941
33155
|
try {
|
|
31942
|
-
cfg = JSON.parse(
|
|
33156
|
+
cfg = JSON.parse(readFileSync43(mcpJsonPath, "utf-8"));
|
|
31943
33157
|
} catch {
|
|
31944
33158
|
return { removed: false };
|
|
31945
33159
|
}
|
|
31946
33160
|
if (!cfg.mcpServers?.["codeindex"])
|
|
31947
33161
|
return { removed: false };
|
|
31948
33162
|
delete cfg.mcpServers["codeindex"];
|
|
31949
|
-
|
|
33163
|
+
writeFileSync14(mcpJsonPath, JSON.stringify(cfg, null, 2));
|
|
31950
33164
|
return { removed: true };
|
|
31951
33165
|
}
|
|
31952
33166
|
var CODEINDEX_REPO, CODEINDEX_VERSION, CODEINDEX_SHA256, CODEINDEX_INSTALL_DIR, CODEINDEX_BIN_NAME, CODEINDEX_BIN_PATH;
|
|
@@ -31964,9 +33178,9 @@ var init_companions = __esm({
|
|
|
31964
33178
|
"x86_64-windows": "a96fc8c8949bb399a44cc0615b12e458460a529c69f01e8829cc39a20f45ab29",
|
|
31965
33179
|
"aarch64-windows": "42620d56272cd9ba9d785569d8d754d6b4a3e80f36f28db3e0c483fd600ed117"
|
|
31966
33180
|
};
|
|
31967
|
-
CODEINDEX_INSTALL_DIR =
|
|
33181
|
+
CODEINDEX_INSTALL_DIR = join54(homedir20(), ".local", "bin");
|
|
31968
33182
|
CODEINDEX_BIN_NAME = process.platform === "win32" ? "codeindex.exe" : "codeindex";
|
|
31969
|
-
CODEINDEX_BIN_PATH =
|
|
33183
|
+
CODEINDEX_BIN_PATH = join54(CODEINDEX_INSTALL_DIR, CODEINDEX_BIN_NAME);
|
|
31970
33184
|
}
|
|
31971
33185
|
});
|
|
31972
33186
|
|
|
@@ -31981,15 +33195,15 @@ __export(install_skills_exports, {
|
|
|
31981
33195
|
skillsSourceDir: () => skillsSourceDir,
|
|
31982
33196
|
uninstallSkills: () => uninstallSkills
|
|
31983
33197
|
});
|
|
31984
|
-
import { readdirSync as readdirSync33, existsSync as
|
|
33198
|
+
import { readdirSync as readdirSync33, existsSync as existsSync49, mkdirSync as mkdirSync14, rmSync as rmSync8, cpSync, writeFileSync as writeFileSync15, readFileSync as readFileSync44, statSync as statSync44, realpathSync as realpathSync5 } from "fs";
|
|
31985
33199
|
import { createHash as createHash12 } from "crypto";
|
|
31986
|
-
import { join as
|
|
33200
|
+
import { join as join55, basename as basename23 } from "path";
|
|
31987
33201
|
function skillsSourceDir() {
|
|
31988
|
-
return
|
|
33202
|
+
return join55(import.meta.dirname, "..", "skills");
|
|
31989
33203
|
}
|
|
31990
33204
|
function version() {
|
|
31991
33205
|
try {
|
|
31992
|
-
return JSON.parse(
|
|
33206
|
+
return JSON.parse(readFileSync44(new URL("../package.json", import.meta.url), "utf-8")).version || "0.0.0";
|
|
31993
33207
|
} catch {
|
|
31994
33208
|
return "0.0.0";
|
|
31995
33209
|
}
|
|
@@ -31998,9 +33212,9 @@ function skillsFingerprint() {
|
|
|
31998
33212
|
const src = skillsSourceDir();
|
|
31999
33213
|
const h = createHash12("sha256");
|
|
32000
33214
|
for (const name of bundledSkillNames()) {
|
|
32001
|
-
for (const rel of filesUnder(
|
|
33215
|
+
for (const rel of filesUnder(join55(src, name)).sort()) {
|
|
32002
33216
|
h.update(name + "/" + rel);
|
|
32003
|
-
h.update(
|
|
33217
|
+
h.update(readFileSync44(join55(src, name, rel)));
|
|
32004
33218
|
}
|
|
32005
33219
|
}
|
|
32006
33220
|
return h.digest("hex").slice(0, 12);
|
|
@@ -32010,7 +33224,7 @@ function filesUnder(dir, prefix = "") {
|
|
|
32010
33224
|
for (const e of readdirSync33(dir, { withFileTypes: true })) {
|
|
32011
33225
|
if (e.name === MARKER) continue;
|
|
32012
33226
|
const rel = prefix ? `${prefix}/${e.name}` : e.name;
|
|
32013
|
-
if (e.isDirectory()) out.push(...filesUnder(
|
|
33227
|
+
if (e.isDirectory()) out.push(...filesUnder(join55(dir, e.name), rel));
|
|
32014
33228
|
else out.push(rel);
|
|
32015
33229
|
}
|
|
32016
33230
|
return out;
|
|
@@ -32020,8 +33234,8 @@ function skillStamp() {
|
|
|
32020
33234
|
}
|
|
32021
33235
|
function bundledSkillNames() {
|
|
32022
33236
|
const src = skillsSourceDir();
|
|
32023
|
-
if (!
|
|
32024
|
-
return readdirSync33(src, { withFileTypes: true }).filter((e) => e.isDirectory() &&
|
|
33237
|
+
if (!existsSync49(src)) return [];
|
|
33238
|
+
return readdirSync33(src, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync49(join55(src, e.name, "SKILL.md"))).map((e) => e.name).sort();
|
|
32025
33239
|
}
|
|
32026
33240
|
function realPathOrSelf(p) {
|
|
32027
33241
|
try {
|
|
@@ -32034,7 +33248,7 @@ function claudeSkillTargets() {
|
|
|
32034
33248
|
const targets = [];
|
|
32035
33249
|
const seen = /* @__PURE__ */ new Set();
|
|
32036
33250
|
for (const home of claudeHomeDirs()) {
|
|
32037
|
-
const dir =
|
|
33251
|
+
const dir = join55(home, "skills");
|
|
32038
33252
|
const key2 = realPathOrSelf(dir);
|
|
32039
33253
|
if (seen.has(key2)) continue;
|
|
32040
33254
|
seen.add(key2);
|
|
@@ -32045,7 +33259,7 @@ function claudeSkillTargets() {
|
|
|
32045
33259
|
dir,
|
|
32046
33260
|
// Judge each profile on ITS OWN transcripts, not the primary's: a home
|
|
32047
33261
|
// with no projects/ is a directory someone made, not a Claude install.
|
|
32048
|
-
available:
|
|
33262
|
+
available: existsSync49(join55(home, "projects"))
|
|
32049
33263
|
});
|
|
32050
33264
|
}
|
|
32051
33265
|
if (targets.length === 0) {
|
|
@@ -32060,17 +33274,17 @@ function skillTargets() {
|
|
|
32060
33274
|
// both produces "skill conflict" duplicate warnings. Every tool we support
|
|
32061
33275
|
// has its own dir, so per-tool coverage is complete.
|
|
32062
33276
|
...claudeSkillTargets(),
|
|
32063
|
-
{ id: "agy", label: "Antigravity", dir:
|
|
33277
|
+
{ id: "agy", label: "Antigravity", dir: join55(agyBackend.homeDir(), "skills"), available: agyBackend.isAvailable() },
|
|
32064
33278
|
{ id: "codex", label: "Codex", dir: codexBackend.skillsDir(), available: codexBackend.isAvailable() },
|
|
32065
33279
|
{ id: "opencode", label: "OpenCode", dir: opencodeBackend.skillsDir(), available: opencodeBackend.isAvailable() },
|
|
32066
33280
|
// Cursor DOES have its own dir (~/.cursor/skills). `skills-cursor` next to
|
|
32067
33281
|
// it is Cursor's bundled set — read-only, never an install target.
|
|
32068
|
-
{ id: "cursor", label: "Cursor", dir:
|
|
33282
|
+
{ id: "cursor", label: "Cursor", dir: join55(cursorHomeDir(), "skills"), available: cursorBackend.isAvailable() },
|
|
32069
33283
|
{ id: "pi", label: "Pi", dir: piBackend.skillsDir(), available: piBackend.isAvailable() }
|
|
32070
33284
|
];
|
|
32071
33285
|
}
|
|
32072
33286
|
function isManaged(dir) {
|
|
32073
|
-
return
|
|
33287
|
+
return existsSync49(join55(dir, MARKER));
|
|
32074
33288
|
}
|
|
32075
33289
|
function installSkills(opts = {}) {
|
|
32076
33290
|
const onlyAvailable = opts.onlyAvailable ?? true;
|
|
@@ -32087,15 +33301,15 @@ function installSkills(opts = {}) {
|
|
|
32087
33301
|
continue;
|
|
32088
33302
|
}
|
|
32089
33303
|
for (const name of names) {
|
|
32090
|
-
const dest =
|
|
32091
|
-
if (
|
|
33304
|
+
const dest = join55(t.dir, name);
|
|
33305
|
+
if (existsSync49(dest) && !isManaged(dest)) {
|
|
32092
33306
|
skippedUserOwned.push(name);
|
|
32093
33307
|
continue;
|
|
32094
33308
|
}
|
|
32095
33309
|
mkdirSync14(t.dir, { recursive: true });
|
|
32096
33310
|
rmSync8(dest, { recursive: true, force: true });
|
|
32097
|
-
cpSync(
|
|
32098
|
-
|
|
33311
|
+
cpSync(join55(src, name), dest, { recursive: true });
|
|
33312
|
+
writeFileSync15(join55(dest, MARKER), `${stamp}
|
|
32099
33313
|
`);
|
|
32100
33314
|
installed.push(name);
|
|
32101
33315
|
}
|
|
@@ -32108,13 +33322,13 @@ function uninstallSkills() {
|
|
|
32108
33322
|
const perTarget = [];
|
|
32109
33323
|
for (const t of skillTargets()) {
|
|
32110
33324
|
const removed = [];
|
|
32111
|
-
if (!
|
|
33325
|
+
if (!existsSync49(t.dir)) {
|
|
32112
33326
|
perTarget.push({ id: t.id, label: t.label, removed });
|
|
32113
33327
|
continue;
|
|
32114
33328
|
}
|
|
32115
33329
|
for (const entry of readdirSync33(t.dir, { withFileTypes: true })) {
|
|
32116
33330
|
if (!entry.isDirectory()) continue;
|
|
32117
|
-
const dir =
|
|
33331
|
+
const dir = join55(t.dir, entry.name);
|
|
32118
33332
|
if (isManaged(dir) && (names.has(entry.name) || entry.name.startsWith("chat-recall"))) {
|
|
32119
33333
|
rmSync8(dir, { recursive: true, force: true });
|
|
32120
33334
|
removed.push(entry.name);
|
|
@@ -32131,10 +33345,10 @@ function skillsNeedRefresh() {
|
|
|
32131
33345
|
for (const t of skillTargets()) {
|
|
32132
33346
|
if (!t.available) continue;
|
|
32133
33347
|
for (const name of names) {
|
|
32134
|
-
const marker =
|
|
32135
|
-
if (!
|
|
33348
|
+
const marker = join55(t.dir, name, MARKER);
|
|
33349
|
+
if (!existsSync49(marker)) return true;
|
|
32136
33350
|
try {
|
|
32137
|
-
if (
|
|
33351
|
+
if (readFileSync44(marker, "utf-8").trim() !== cur) return true;
|
|
32138
33352
|
} catch {
|
|
32139
33353
|
return true;
|
|
32140
33354
|
}
|
|
@@ -32149,11 +33363,11 @@ function skillStatus() {
|
|
|
32149
33363
|
let installed = 0;
|
|
32150
33364
|
let ver = null;
|
|
32151
33365
|
for (const name of names) {
|
|
32152
|
-
const marker =
|
|
32153
|
-
if (
|
|
33366
|
+
const marker = join55(t.dir, name, MARKER);
|
|
33367
|
+
if (existsSync49(marker)) {
|
|
32154
33368
|
installed++;
|
|
32155
33369
|
try {
|
|
32156
|
-
ver =
|
|
33370
|
+
ver = readFileSync44(marker, "utf-8").trim();
|
|
32157
33371
|
} catch {
|
|
32158
33372
|
}
|
|
32159
33373
|
}
|
|
@@ -32178,9 +33392,9 @@ var init_install_skills = __esm({
|
|
|
32178
33392
|
});
|
|
32179
33393
|
|
|
32180
33394
|
// ../engine/dist/core/artifact-codec.js
|
|
32181
|
-
import { readFileSync as
|
|
32182
|
-
import { basename as basename24, join as
|
|
32183
|
-
import { homedir as
|
|
33395
|
+
import { readFileSync as readFileSync45 } from "fs";
|
|
33396
|
+
import { basename as basename24, join as join56 } from "path";
|
|
33397
|
+
import { homedir as homedir21 } from "os";
|
|
32184
33398
|
function parseCommandText(content, format, fallbackName) {
|
|
32185
33399
|
if (format === "toml") {
|
|
32186
33400
|
const t = parseScalarToml(content);
|
|
@@ -32202,30 +33416,30 @@ function parseAgentText(content, format, fallbackName) {
|
|
|
32202
33416
|
return { name: fm.name || fallbackName, description: fm.description || "", tools: fm.tools, body: body2.trim() };
|
|
32203
33417
|
}
|
|
32204
33418
|
function readCommand(filePath, format) {
|
|
32205
|
-
return parseCommandText(
|
|
33419
|
+
return parseCommandText(readFileSync45(filePath, "utf-8"), format, base2(filePath));
|
|
32206
33420
|
}
|
|
32207
33421
|
function readAgent(filePath, format) {
|
|
32208
|
-
return parseAgentText(
|
|
33422
|
+
return parseAgentText(readFileSync45(filePath, "utf-8"), format, base2(filePath));
|
|
32209
33423
|
}
|
|
32210
33424
|
function readInstructions(filePath, name) {
|
|
32211
|
-
const content =
|
|
33425
|
+
const content = readFileSync45(filePath, "utf-8");
|
|
32212
33426
|
return { name, description: "", body: content };
|
|
32213
33427
|
}
|
|
32214
33428
|
function commandPath(tool, name) {
|
|
32215
33429
|
switch (tool) {
|
|
32216
33430
|
case "claude":
|
|
32217
|
-
return
|
|
33431
|
+
return join56(claudeBackend.commandsDir(), `${name}.md`);
|
|
32218
33432
|
case "agy":
|
|
32219
|
-
return
|
|
33433
|
+
return join56(join56(agyBackend.homeDir(), "commands"), `${name}.toml`);
|
|
32220
33434
|
case "opencode":
|
|
32221
|
-
return
|
|
33435
|
+
return join56(opencodeBackend.commandsDir(), `${name}.md`);
|
|
32222
33436
|
case "codex":
|
|
32223
|
-
return
|
|
33437
|
+
return join56(codexBackend.promptsDir(), `${name}.md`);
|
|
32224
33438
|
case "cursor":
|
|
32225
|
-
return
|
|
33439
|
+
return join56(cursorHomeDir(), "commands", `${name}.md`);
|
|
32226
33440
|
// Pi's prompt templates are flat *.md files in the agent dir.
|
|
32227
33441
|
case "pi":
|
|
32228
|
-
return
|
|
33442
|
+
return join56(piBackend.promptsDir(), `${name}.md`);
|
|
32229
33443
|
// Hermes has no command files. copyArtifactToTool refuses this target first.
|
|
32230
33444
|
case "hermes":
|
|
32231
33445
|
throw new Error("Hermes has no command files");
|
|
@@ -32234,15 +33448,15 @@ function commandPath(tool, name) {
|
|
|
32234
33448
|
function agentPath(tool, name) {
|
|
32235
33449
|
switch (tool) {
|
|
32236
33450
|
case "claude":
|
|
32237
|
-
return
|
|
33451
|
+
return join56(claudeBackend.agentsDir(), `${name}.md`);
|
|
32238
33452
|
case "agy":
|
|
32239
|
-
return
|
|
33453
|
+
return join56(join56(agyBackend.homeDir(), "agents"), `${name}.md`);
|
|
32240
33454
|
case "opencode":
|
|
32241
|
-
return
|
|
33455
|
+
return join56(opencodeBackend.agentsDir(), `${name}.md`);
|
|
32242
33456
|
case "codex":
|
|
32243
|
-
return
|
|
33457
|
+
return join56(codexBackend.agentsDir(), `${name}.toml`);
|
|
32244
33458
|
case "cursor":
|
|
32245
|
-
return
|
|
33459
|
+
return join56(cursorHomeDir(), "agents", `${name}.md`);
|
|
32246
33460
|
// Pi has no named agent personas. copyArtifactToTool refuses this target first.
|
|
32247
33461
|
case "pi":
|
|
32248
33462
|
throw new Error("Pi has no agent files");
|
|
@@ -32279,23 +33493,23 @@ function instructionsFilename(tool) {
|
|
|
32279
33493
|
function instructionsPath(tool, projectPath) {
|
|
32280
33494
|
const file = instructionsFilename(tool);
|
|
32281
33495
|
if (projectPath)
|
|
32282
|
-
return
|
|
33496
|
+
return join56(projectPath, file);
|
|
32283
33497
|
switch (tool) {
|
|
32284
33498
|
case "claude":
|
|
32285
|
-
return
|
|
33499
|
+
return join56(claudeBackend.homeDir(), file);
|
|
32286
33500
|
case "agy":
|
|
32287
|
-
return
|
|
33501
|
+
return join56(agyBackend.homeDir(), file);
|
|
32288
33502
|
case "codex":
|
|
32289
|
-
return
|
|
33503
|
+
return join56(codexBackend.homeDir(), file);
|
|
32290
33504
|
case "opencode":
|
|
32291
|
-
return
|
|
33505
|
+
return join56(homedir21(), ".config", "opencode", file);
|
|
32292
33506
|
// Cursor has no single user-scope instructions FILE — user-level guidance
|
|
32293
33507
|
// is User Rules plus ~/.cursor/rules/*.mdc. AGENTS.md at the home root is
|
|
32294
33508
|
// the closest equivalent and is what a mirror can actually write.
|
|
32295
33509
|
case "cursor":
|
|
32296
|
-
return
|
|
33510
|
+
return join56(cursorHomeDir(), file);
|
|
32297
33511
|
case "pi":
|
|
32298
|
-
return
|
|
33512
|
+
return join56(piBackend.homeDir(), file);
|
|
32299
33513
|
case "hermes":
|
|
32300
33514
|
throw new Error("Hermes has no instruction file mapping");
|
|
32301
33515
|
}
|
|
@@ -32364,9 +33578,9 @@ __export(toolkit_sync_exports, {
|
|
|
32364
33578
|
supportedTargetsFor: () => supportedTargetsFor,
|
|
32365
33579
|
writeMcpEntry: () => writeMcpEntry
|
|
32366
33580
|
});
|
|
32367
|
-
import { existsSync as
|
|
32368
|
-
import { dirname as dirname22, join as
|
|
32369
|
-
import { homedir as
|
|
33581
|
+
import { existsSync as existsSync50, mkdirSync as mkdirSync15, readFileSync as readFileSync46, readdirSync as readdirSync34, writeFileSync as writeFileSync16, cpSync as cpSync2, rmSync as rmSync9 } from "fs";
|
|
33582
|
+
import { dirname as dirname22, join as join57, basename as basename25 } from "path";
|
|
33583
|
+
import { homedir as homedir22 } from "os";
|
|
32370
33584
|
function supportedTargetsFor(type) {
|
|
32371
33585
|
return SUPPORTED_TARGETS[type];
|
|
32372
33586
|
}
|
|
@@ -32407,16 +33621,16 @@ function skillsDirFor(tool) {
|
|
|
32407
33621
|
case "claude":
|
|
32408
33622
|
return claudeBackend.skillsDir();
|
|
32409
33623
|
case "agy":
|
|
32410
|
-
return
|
|
33624
|
+
return join57(agyBackend.homeDir(), "skills");
|
|
32411
33625
|
case "opencode":
|
|
32412
33626
|
return opencodeBackend.skillsDir();
|
|
32413
33627
|
case "codex":
|
|
32414
33628
|
return codexBackend.skillsDir();
|
|
32415
33629
|
// user skills, NOT .system
|
|
32416
33630
|
case "cursor":
|
|
32417
|
-
return
|
|
33631
|
+
return join57(cursorHomeDir(), "skills");
|
|
32418
33632
|
case "hermes":
|
|
32419
|
-
return
|
|
33633
|
+
return join57(hermesBackend.homeDir(), "skills");
|
|
32420
33634
|
case "pi":
|
|
32421
33635
|
return piBackend.skillsDir();
|
|
32422
33636
|
}
|
|
@@ -32424,23 +33638,23 @@ function skillsDirFor(tool) {
|
|
|
32424
33638
|
function skillDirsNamed(tool, name) {
|
|
32425
33639
|
const root = skillsDirFor(tool);
|
|
32426
33640
|
const found = [];
|
|
32427
|
-
if (
|
|
32428
|
-
found.push(
|
|
32429
|
-
if (tool !== "hermes" || !
|
|
33641
|
+
if (existsSync50(join57(root, name)))
|
|
33642
|
+
found.push(join57(root, name));
|
|
33643
|
+
if (tool !== "hermes" || !existsSync50(root))
|
|
32430
33644
|
return found;
|
|
32431
33645
|
for (const category of readdirSync34(root)) {
|
|
32432
|
-
const candidate =
|
|
32433
|
-
if (
|
|
33646
|
+
const candidate = join57(root, category, name);
|
|
33647
|
+
if (existsSync50(join57(candidate, "SKILL.md")))
|
|
32434
33648
|
found.push(candidate);
|
|
32435
33649
|
}
|
|
32436
33650
|
return found;
|
|
32437
33651
|
}
|
|
32438
33652
|
function copySkill(row, toTool) {
|
|
32439
33653
|
const skillDir = row.extra.skillDir || dirname22(row.filePath);
|
|
32440
|
-
if (!
|
|
33654
|
+
if (!existsSync50(skillDir))
|
|
32441
33655
|
return { ok: false, status: 404, error: `Source dir missing: ${skillDir}` };
|
|
32442
33656
|
const name = row.extra.skillName || basename25(skillDir);
|
|
32443
|
-
const targetDir =
|
|
33657
|
+
const targetDir = join57(skillsDirFor(toTool), name);
|
|
32444
33658
|
const existing = skillDirsNamed(toTool, name);
|
|
32445
33659
|
if (existing.length)
|
|
32446
33660
|
return { ok: false, status: 409, error: `Already exists: ${existing[0]}` };
|
|
@@ -32453,26 +33667,26 @@ function copySkill(row, toTool) {
|
|
|
32453
33667
|
}
|
|
32454
33668
|
}
|
|
32455
33669
|
function mcpJsonCandidates(tool) {
|
|
32456
|
-
const home =
|
|
33670
|
+
const home = homedir22();
|
|
32457
33671
|
switch (tool) {
|
|
32458
33672
|
case "claude":
|
|
32459
33673
|
return [
|
|
32460
|
-
{ path:
|
|
32461
|
-
{ path:
|
|
33674
|
+
{ path: join57(home, ".mcp.json"), key: "mcpServers" },
|
|
33675
|
+
{ path: join57(home, ".claude.json"), key: "mcpServers" }
|
|
32462
33676
|
];
|
|
32463
33677
|
case "gemini":
|
|
32464
|
-
return [{ path:
|
|
33678
|
+
return [{ path: join57(home, ".gemini", "settings.json"), key: "mcpServers" }];
|
|
32465
33679
|
case "agy":
|
|
32466
|
-
return [{ path:
|
|
33680
|
+
return [{ path: join57(home, ".gemini", "config", "mcp_config.json"), key: "mcpServers" }];
|
|
32467
33681
|
case "cursor":
|
|
32468
|
-
return [{ path:
|
|
33682
|
+
return [{ path: join57(cursorHomeDir(), "mcp.json"), key: "mcpServers" }];
|
|
32469
33683
|
case "pi":
|
|
32470
33684
|
return [{ path: piMcpConfigPath(), key: "mcpServers" }];
|
|
32471
33685
|
case "opencode":
|
|
32472
33686
|
return [
|
|
32473
|
-
{ path:
|
|
32474
|
-
{ path:
|
|
32475
|
-
{ path:
|
|
33687
|
+
{ path: join57(home, ".config", "opencode", "opencode.json"), key: "mcp" },
|
|
33688
|
+
{ path: join57(home, ".config", "opencode", "config.json"), key: "mcp" },
|
|
33689
|
+
{ path: join57(home, ".opencode", "config.json"), key: "mcp" }
|
|
32476
33690
|
];
|
|
32477
33691
|
default:
|
|
32478
33692
|
return [];
|
|
@@ -32480,14 +33694,14 @@ function mcpJsonCandidates(tool) {
|
|
|
32480
33694
|
}
|
|
32481
33695
|
function readMcpEntry(tool, name) {
|
|
32482
33696
|
if (tool === "codex")
|
|
32483
|
-
return readCodexMcpEntry(
|
|
33697
|
+
return readCodexMcpEntry(join57(homedir22(), ".codex", "config.toml"), name);
|
|
32484
33698
|
if (tool === "hermes")
|
|
32485
33699
|
return readHermesMcpServers()?.[name] ?? null;
|
|
32486
33700
|
for (const t of mcpJsonCandidates(tool)) {
|
|
32487
|
-
if (!
|
|
33701
|
+
if (!existsSync50(t.path))
|
|
32488
33702
|
continue;
|
|
32489
33703
|
try {
|
|
32490
|
-
const cfg = JSON.parse(
|
|
33704
|
+
const cfg = JSON.parse(readFileSync46(t.path, "utf-8"));
|
|
32491
33705
|
const block = cfg[t.key] || {};
|
|
32492
33706
|
if (block[name])
|
|
32493
33707
|
return block[name];
|
|
@@ -32497,11 +33711,11 @@ function readMcpEntry(tool, name) {
|
|
|
32497
33711
|
return null;
|
|
32498
33712
|
}
|
|
32499
33713
|
function readCodexMcpEntry(path, target) {
|
|
32500
|
-
if (!
|
|
33714
|
+
if (!existsSync50(path))
|
|
32501
33715
|
return null;
|
|
32502
33716
|
let content;
|
|
32503
33717
|
try {
|
|
32504
|
-
content =
|
|
33718
|
+
content = readFileSync46(path, "utf-8");
|
|
32505
33719
|
} catch {
|
|
32506
33720
|
return null;
|
|
32507
33721
|
}
|
|
@@ -32551,8 +33765,8 @@ function readCodexMcpEntry(path, target) {
|
|
|
32551
33765
|
}
|
|
32552
33766
|
function writeCodexMcpEntry(path, name, entry) {
|
|
32553
33767
|
let content = "";
|
|
32554
|
-
if (
|
|
32555
|
-
content =
|
|
33768
|
+
if (existsSync50(path))
|
|
33769
|
+
content = readFileSync46(path, "utf-8");
|
|
32556
33770
|
const header = `[mcp_servers.${name}]`;
|
|
32557
33771
|
if (content.includes(header))
|
|
32558
33772
|
return false;
|
|
@@ -32582,15 +33796,15 @@ function writeCodexMcpEntry(path, name, entry) {
|
|
|
32582
33796
|
lines.push(`${k} = ${escape(String(v))}`);
|
|
32583
33797
|
}
|
|
32584
33798
|
mkdirSync15(dirname22(path), { recursive: true });
|
|
32585
|
-
|
|
33799
|
+
writeFileSync16(path, content + lines.join("\n") + "\n");
|
|
32586
33800
|
return true;
|
|
32587
33801
|
}
|
|
32588
33802
|
function writeMcpEntry(toTool, name, entry) {
|
|
32589
33803
|
if (toTool === "hermes")
|
|
32590
33804
|
return writeHermesMcp(name, entry);
|
|
32591
|
-
const home =
|
|
33805
|
+
const home = homedir22();
|
|
32592
33806
|
if (toTool === "codex") {
|
|
32593
|
-
const path2 =
|
|
33807
|
+
const path2 = join57(home, ".codex", "config.toml");
|
|
32594
33808
|
if (!writeCodexMcpEntry(path2, name, entry))
|
|
32595
33809
|
return { ok: false, status: 409, error: `MCP "${name}" already exists in ${path2}.` };
|
|
32596
33810
|
return { ok: true, targetPath: path2 };
|
|
@@ -32598,25 +33812,25 @@ function writeMcpEntry(toTool, name, entry) {
|
|
|
32598
33812
|
let path;
|
|
32599
33813
|
let key2;
|
|
32600
33814
|
if (toTool === "claude") {
|
|
32601
|
-
path =
|
|
33815
|
+
path = join57(home, ".mcp.json");
|
|
32602
33816
|
key2 = "mcpServers";
|
|
32603
33817
|
} else if (toTool === "agy") {
|
|
32604
|
-
path =
|
|
33818
|
+
path = join57(home, ".gemini", "config", "mcp_config.json");
|
|
32605
33819
|
key2 = "mcpServers";
|
|
32606
33820
|
} else if (toTool === "cursor") {
|
|
32607
|
-
path =
|
|
33821
|
+
path = join57(cursorHomeDir(), "mcp.json");
|
|
32608
33822
|
key2 = "mcpServers";
|
|
32609
33823
|
} else if (toTool === "pi") {
|
|
32610
33824
|
path = piMcpConfigPath();
|
|
32611
33825
|
key2 = "mcpServers";
|
|
32612
33826
|
} else {
|
|
32613
|
-
path =
|
|
33827
|
+
path = join57(home, ".config", "opencode", "opencode.json");
|
|
32614
33828
|
key2 = "mcp";
|
|
32615
33829
|
}
|
|
32616
33830
|
let cfg = {};
|
|
32617
|
-
if (
|
|
33831
|
+
if (existsSync50(path)) {
|
|
32618
33832
|
try {
|
|
32619
|
-
cfg = JSON.parse(
|
|
33833
|
+
cfg = JSON.parse(readFileSync46(path, "utf-8"));
|
|
32620
33834
|
} catch {
|
|
32621
33835
|
return { ok: false, status: 500, error: `Target config is malformed: ${path}` };
|
|
32622
33836
|
}
|
|
@@ -32648,7 +33862,7 @@ function writeMcpEntry(toTool, name, entry) {
|
|
|
32648
33862
|
}
|
|
32649
33863
|
cfg[key2][name] = normalized;
|
|
32650
33864
|
try {
|
|
32651
|
-
|
|
33865
|
+
writeFileSync16(path, JSON.stringify(cfg, null, 2));
|
|
32652
33866
|
return { ok: true, targetPath: path };
|
|
32653
33867
|
} catch (e) {
|
|
32654
33868
|
return { ok: false, status: 500, error: e instanceof Error ? e.message : "write failed" };
|
|
@@ -32678,11 +33892,11 @@ function copyCommandOrAgent(type, row, toTool) {
|
|
|
32678
33892
|
return { ok: false, status: 404, error: `Source unreadable: ${e instanceof Error ? e.message : "failed"}` };
|
|
32679
33893
|
}
|
|
32680
33894
|
const out = emit(type, art, toTool);
|
|
32681
|
-
if (
|
|
33895
|
+
if (existsSync50(out.path))
|
|
32682
33896
|
return { ok: false, status: 409, error: `Already exists: ${out.path}` };
|
|
32683
33897
|
try {
|
|
32684
33898
|
mkdirSync15(dirname22(out.path), { recursive: true });
|
|
32685
|
-
|
|
33899
|
+
writeFileSync16(out.path, out.content);
|
|
32686
33900
|
return { ok: true, targetPath: out.path };
|
|
32687
33901
|
} catch (e) {
|
|
32688
33902
|
return { ok: false, status: 500, error: e instanceof Error ? e.message : "write failed" };
|
|
@@ -32698,11 +33912,11 @@ function copyInstructions(row, toTool) {
|
|
|
32698
33912
|
return { ok: false, status: 404, error: `Source unreadable: ${e instanceof Error ? e.message : "failed"}` };
|
|
32699
33913
|
}
|
|
32700
33914
|
const out = emit("instructions", art, toTool, row.projectPath || void 0);
|
|
32701
|
-
if (
|
|
33915
|
+
if (existsSync50(out.path))
|
|
32702
33916
|
return { ok: false, status: 409, error: `Already exists: ${out.path}` };
|
|
32703
33917
|
try {
|
|
32704
33918
|
mkdirSync15(dirname22(out.path), { recursive: true });
|
|
32705
|
-
|
|
33919
|
+
writeFileSync16(out.path, out.content);
|
|
32706
33920
|
return { ok: true, targetPath: out.path };
|
|
32707
33921
|
} catch (e) {
|
|
32708
33922
|
return { ok: false, status: 500, error: e instanceof Error ? e.message : "write failed" };
|
|
@@ -32712,14 +33926,14 @@ function writeHermesMcp(name, entry) {
|
|
|
32712
33926
|
if (!entry?.command && !entry?.url)
|
|
32713
33927
|
return { ok: false, status: 400, error: `MCP "${name}" has no command or url to write.` };
|
|
32714
33928
|
const path = hermesConfigPath();
|
|
32715
|
-
if (!
|
|
33929
|
+
if (!existsSync50(path))
|
|
32716
33930
|
return { ok: false, status: 404, error: `${path} not found` };
|
|
32717
33931
|
try {
|
|
32718
|
-
const after = addHermesMcpServer(
|
|
33932
|
+
const after = addHermesMcpServer(readFileSync46(path, "utf-8"), name, hermesServerEntry(entry));
|
|
32719
33933
|
if (after === null)
|
|
32720
33934
|
return { ok: false, status: 409, error: `MCP "${name}" already exists in ${path}` };
|
|
32721
33935
|
const backupPaths = [backupToTrash(path, `mcp-hermes-${name}-config.yaml`)];
|
|
32722
|
-
|
|
33936
|
+
writeFileSync16(path, after);
|
|
32723
33937
|
return { ok: true, targetPath: path, backupPaths };
|
|
32724
33938
|
} catch (e) {
|
|
32725
33939
|
return removeFailed(e, "write failed");
|
|
@@ -32754,7 +33968,7 @@ async function removeArtifactFromTool(type, name, tool) {
|
|
|
32754
33968
|
return removeCommandOrAgent(type, name, tool);
|
|
32755
33969
|
}
|
|
32756
33970
|
function backupToTrash(src, label) {
|
|
32757
|
-
const dest =
|
|
33971
|
+
const dest = join57(getDataDir(), "trash", `${Date.now()}-${label.replace(/[^A-Za-z0-9._-]/g, "_")}`);
|
|
32758
33972
|
mkdirSync15(dirname22(dest), { recursive: true });
|
|
32759
33973
|
cpSync2(src, dest, { recursive: true });
|
|
32760
33974
|
return dest;
|
|
@@ -32765,7 +33979,7 @@ function removeFailed(e, fallback) {
|
|
|
32765
33979
|
function removeSkill(name, tool) {
|
|
32766
33980
|
const found = skillDirsNamed(tool, name);
|
|
32767
33981
|
if (found.length === 0)
|
|
32768
|
-
return { ok: false, status: 404, error: `Not found: ${
|
|
33982
|
+
return { ok: false, status: 404, error: `Not found: ${join57(skillsDirFor(tool), name)}` };
|
|
32769
33983
|
if (found.length > 1)
|
|
32770
33984
|
return { ok: false, status: 409, error: `${found.length} skills named "${name}" for ${tool}; none removed` };
|
|
32771
33985
|
const dir = found[0];
|
|
@@ -32786,7 +34000,7 @@ async function removeCommandOrAgent(type, name, tool) {
|
|
|
32786
34000
|
const [row] = rows;
|
|
32787
34001
|
if (row.readonly)
|
|
32788
34002
|
return { ok: false, status: 400, error: "Artifact is read-only (system/bundled)." };
|
|
32789
|
-
if (!row.filePath || !
|
|
34003
|
+
if (!row.filePath || !existsSync50(row.filePath))
|
|
32790
34004
|
return { ok: false, status: 404, error: "Source has no file on disk" };
|
|
32791
34005
|
try {
|
|
32792
34006
|
const backupPaths = [backupToTrash(row.filePath, `${type}-${tool}-${name}`)];
|
|
@@ -32799,30 +34013,30 @@ async function removeCommandOrAgent(type, name, tool) {
|
|
|
32799
34013
|
function removeMcp(name, tool) {
|
|
32800
34014
|
if (tool === "hermes") {
|
|
32801
34015
|
const path = hermesConfigPath();
|
|
32802
|
-
if (!
|
|
34016
|
+
if (!existsSync50(path))
|
|
32803
34017
|
return { ok: false, status: 404, error: `${path} not found` };
|
|
32804
34018
|
try {
|
|
32805
|
-
const after = deleteHermesMcpServer(
|
|
34019
|
+
const after = deleteHermesMcpServer(readFileSync46(path, "utf-8"), name);
|
|
32806
34020
|
if (after === null)
|
|
32807
34021
|
return { ok: false, status: 404, error: `MCP "${name}" not found in ${path}` };
|
|
32808
34022
|
const backupPaths2 = [backupToTrash(path, `mcp-hermes-${name}-config.yaml`)];
|
|
32809
|
-
|
|
34023
|
+
writeFileSync16(path, after);
|
|
32810
34024
|
return { ok: true, targetPath: path, backupPaths: backupPaths2 };
|
|
32811
34025
|
} catch (e) {
|
|
32812
34026
|
return removeFailed(e, "write failed");
|
|
32813
34027
|
}
|
|
32814
34028
|
}
|
|
32815
34029
|
if (tool === "codex") {
|
|
32816
|
-
const path =
|
|
32817
|
-
if (!
|
|
34030
|
+
const path = join57(homedir22(), ".codex", "config.toml");
|
|
34031
|
+
if (!existsSync50(path))
|
|
32818
34032
|
return { ok: false, status: 404, error: "config.toml not found" };
|
|
32819
|
-
const before =
|
|
34033
|
+
const before = readFileSync46(path, "utf-8");
|
|
32820
34034
|
const after = stripCodexMcpBlock(before, name);
|
|
32821
34035
|
if (before === after)
|
|
32822
34036
|
return { ok: false, status: 404, error: `MCP "${name}" not found in ${path}` };
|
|
32823
34037
|
try {
|
|
32824
34038
|
const backupPaths2 = [backupToTrash(path, `mcp-codex-${name}`)];
|
|
32825
|
-
|
|
34039
|
+
writeFileSync16(path, after);
|
|
32826
34040
|
return { ok: true, targetPath: path, backupPaths: backupPaths2 };
|
|
32827
34041
|
} catch (e) {
|
|
32828
34042
|
return removeFailed(e, "write failed");
|
|
@@ -32831,15 +34045,15 @@ function removeMcp(name, tool) {
|
|
|
32831
34045
|
let removedFrom;
|
|
32832
34046
|
const backupPaths = [];
|
|
32833
34047
|
for (const c of mcpJsonCandidates(tool)) {
|
|
32834
|
-
if (!
|
|
34048
|
+
if (!existsSync50(c.path))
|
|
32835
34049
|
continue;
|
|
32836
34050
|
try {
|
|
32837
|
-
const cfg = JSON.parse(
|
|
34051
|
+
const cfg = JSON.parse(readFileSync46(c.path, "utf-8"));
|
|
32838
34052
|
if (!cfg[c.key]?.[name])
|
|
32839
34053
|
continue;
|
|
32840
34054
|
backupPaths.push(backupToTrash(c.path, `mcp-${tool}-${name}-${basename25(c.path)}`));
|
|
32841
34055
|
delete cfg[c.key][name];
|
|
32842
|
-
|
|
34056
|
+
writeFileSync16(c.path, JSON.stringify(cfg, null, 2));
|
|
32843
34057
|
if (!removedFrom)
|
|
32844
34058
|
removedFrom = c.path;
|
|
32845
34059
|
} catch (e) {
|
|
@@ -32996,8 +34210,8 @@ __export(toolkit_pull_exports, {
|
|
|
32996
34210
|
platformRefusal: () => platformRefusal,
|
|
32997
34211
|
portableCommand: () => portableCommand
|
|
32998
34212
|
});
|
|
32999
|
-
import { existsSync as
|
|
33000
|
-
import { dirname as dirname23, join as
|
|
34213
|
+
import { existsSync as existsSync51, mkdirSync as mkdirSync16, statSync as statSync45, writeFileSync as writeFileSync17 } from "node:fs";
|
|
34214
|
+
import { dirname as dirname23, join as join58, basename as basename26, isAbsolute as isAbsolute4 } from "node:path";
|
|
33001
34215
|
function isExecutableFile(p) {
|
|
33002
34216
|
try {
|
|
33003
34217
|
return statSync45(p).isFile();
|
|
@@ -33167,9 +34381,9 @@ function executePull(rows, opts = {}) {
|
|
|
33167
34381
|
const outcomes = [];
|
|
33168
34382
|
for (const { name, body: body2, truncated, redacted, tools } of skills) {
|
|
33169
34383
|
for (const tool of tools) {
|
|
33170
|
-
const dir =
|
|
33171
|
-
const file =
|
|
33172
|
-
if (
|
|
34384
|
+
const dir = join58(skillsDirFor(tool), name);
|
|
34385
|
+
const file = join58(dir, "SKILL.md");
|
|
34386
|
+
if (existsSync51(file)) {
|
|
33173
34387
|
outcomes.push({ type: "skill", name, tool, status: "present" });
|
|
33174
34388
|
continue;
|
|
33175
34389
|
}
|
|
@@ -33183,7 +34397,7 @@ function executePull(rows, opts = {}) {
|
|
|
33183
34397
|
}
|
|
33184
34398
|
try {
|
|
33185
34399
|
mkdirSync16(dir, { recursive: true });
|
|
33186
|
-
|
|
34400
|
+
writeFileSync17(file, body2);
|
|
33187
34401
|
outcomes.push({ type: "skill", name, tool, status: "written", path: file, redactedContent: redacted });
|
|
33188
34402
|
} catch (e) {
|
|
33189
34403
|
outcomes.push({ type: "skill", name, tool, status: "failed", reason: e instanceof Error ? e.message : "write failed" });
|
|
@@ -33214,7 +34428,7 @@ function executePull(rows, opts = {}) {
|
|
|
33214
34428
|
outcomes.push({ type, name, tool, status: "failed", reason: e instanceof Error ? e.message : "emit failed" });
|
|
33215
34429
|
continue;
|
|
33216
34430
|
}
|
|
33217
|
-
if (
|
|
34431
|
+
if (existsSync51(out.path)) {
|
|
33218
34432
|
outcomes.push({ type, name, tool, status: "present" });
|
|
33219
34433
|
continue;
|
|
33220
34434
|
}
|
|
@@ -33224,7 +34438,7 @@ function executePull(rows, opts = {}) {
|
|
|
33224
34438
|
}
|
|
33225
34439
|
try {
|
|
33226
34440
|
mkdirSync16(dirname23(out.path), { recursive: true });
|
|
33227
|
-
|
|
34441
|
+
writeFileSync17(out.path, out.content);
|
|
33228
34442
|
outcomes.push({ type, name, tool, status: "written", path: out.path, redactedContent: redacted });
|
|
33229
34443
|
} catch (e) {
|
|
33230
34444
|
outcomes.push({ type, name, tool, status: "failed", reason: e instanceof Error ? e.message : "write failed" });
|
|
@@ -33255,832 +34469,199 @@ function executePull(rows, opts = {}) {
|
|
|
33255
34469
|
status: "skipped",
|
|
33256
34470
|
reason: "its command contains a secret, which is never uploaded \u2014 register this one by hand"
|
|
33257
34471
|
});
|
|
33258
|
-
continue;
|
|
33259
|
-
}
|
|
33260
|
-
const entry = { ...built.entry };
|
|
33261
|
-
let rewrittenCommand;
|
|
33262
|
-
if (!entry.url) {
|
|
33263
|
-
const raw = Array.isArray(entry.command) ? entry.command[0] : entry.command;
|
|
33264
|
-
const port = portableCommand(raw);
|
|
33265
|
-
if ("missing" in port) {
|
|
33266
|
-
outcomes.push({ type: "mcp", name, tool, status: "skipped", reason: `not installed here: ${port.missing}` });
|
|
33267
|
-
continue;
|
|
33268
|
-
}
|
|
33269
|
-
if (port.rewritten) {
|
|
33270
|
-
rewrittenCommand = port.command;
|
|
33271
|
-
if (Array.isArray(entry.command))
|
|
33272
|
-
entry.command = [port.command, ...entry.command.slice(1)];
|
|
33273
|
-
else
|
|
33274
|
-
entry.command = port.command;
|
|
33275
|
-
}
|
|
33276
|
-
}
|
|
33277
|
-
if (opts.dryRun) {
|
|
33278
|
-
outcomes.push({ type: "mcp", name, tool, status: "written", reason: "dry run", needsEnv: built.needsEnv, rewrittenCommand });
|
|
33279
|
-
continue;
|
|
33280
|
-
}
|
|
33281
|
-
const r = writeMcpEntry(tool, name, entry);
|
|
33282
|
-
if (r.ok)
|
|
33283
|
-
outcomes.push({ type: "mcp", name, tool, status: "written", path: r.targetPath, needsEnv: built.needsEnv, rewrittenCommand });
|
|
33284
|
-
else if (r.status === 409)
|
|
33285
|
-
outcomes.push({ type: "mcp", name, tool, status: "present" });
|
|
33286
|
-
else
|
|
33287
|
-
outcomes.push({ type: "mcp", name, tool, status: "failed", reason: r.error });
|
|
33288
|
-
}
|
|
33289
|
-
}
|
|
33290
|
-
return { outcomes, unsupported };
|
|
33291
|
-
}
|
|
33292
|
-
var NOT_REBUILDABLE;
|
|
33293
|
-
var init_toolkit_pull = __esm({
|
|
33294
|
-
"../engine/dist/core/toolkit-pull.js"() {
|
|
33295
|
-
"use strict";
|
|
33296
|
-
init_which();
|
|
33297
|
-
init_toolkit_sync();
|
|
33298
|
-
init_artifact_codec();
|
|
33299
|
-
NOT_REBUILDABLE = {
|
|
33300
|
-
// Instructions are the one type that SHOULD not travel by device: a CLAUDE.md
|
|
33301
|
-
// belongs to a repository, so installing one per machine would put a
|
|
33302
|
-
// project's rules somewhere they do not apply.
|
|
33303
|
-
instructions: "project-scoped \u2014 it belongs to a repo, not to a machine"
|
|
33304
|
-
};
|
|
33305
|
-
}
|
|
33306
|
-
});
|
|
33307
|
-
|
|
33308
|
-
// src/init-progress.ts
|
|
33309
|
-
var init_progress_exports = {};
|
|
33310
|
-
__export(init_progress_exports, {
|
|
33311
|
-
handOffLine: () => handOffLine,
|
|
33312
|
-
progressLine: () => progressLine2,
|
|
33313
|
-
renderBar: () => renderBar,
|
|
33314
|
-
renderCount: () => renderCount,
|
|
33315
|
-
spawnDetachedSync: () => spawnDetachedSync,
|
|
33316
|
-
watchFirstSync: () => watchFirstSync
|
|
33317
|
-
});
|
|
33318
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
33319
|
-
function renderBar(done, total, width = 12) {
|
|
33320
|
-
if (total <= 0) return "\u2591".repeat(width);
|
|
33321
|
-
const ratio = Math.max(0, Math.min(1, done / total));
|
|
33322
|
-
const filled = Math.round(ratio * width);
|
|
33323
|
-
return "\u2588".repeat(filled) + "\u2591".repeat(width - filled);
|
|
33324
|
-
}
|
|
33325
|
-
function renderCount(done, total) {
|
|
33326
|
-
const n = (x) => x.toLocaleString("en-US");
|
|
33327
|
-
return `${n(done)}/${n(total)}`;
|
|
33328
|
-
}
|
|
33329
|
-
function progressLine2(snap) {
|
|
33330
|
-
if (!snap || snap.total <= 0) return "starting\u2026";
|
|
33331
|
-
if (snap.complete) return `${renderCount(snap.done, snap.total)} indexed`;
|
|
33332
|
-
return `${renderBar(snap.done, snap.total)} ${renderCount(snap.done, snap.total)}`;
|
|
33333
|
-
}
|
|
33334
|
-
function handOffLine(snap) {
|
|
33335
|
-
const where = snap && snap.total > 0 ? `${renderCount(snap.done, snap.total)} so far` : "started";
|
|
33336
|
-
return `${where} \u2014 continuing in the background`;
|
|
33337
|
-
}
|
|
33338
|
-
async function watchFirstSync(deps) {
|
|
33339
|
-
const handOffAfterMs = deps.handOffAfterMs ?? 2e4;
|
|
33340
|
-
const pollMs = deps.pollMs ?? 400;
|
|
33341
|
-
const started = deps.now();
|
|
33342
|
-
deps.startWorker();
|
|
33343
|
-
let snap = null;
|
|
33344
|
-
for (; ; ) {
|
|
33345
|
-
snap = deps.readProgress();
|
|
33346
|
-
if (snap?.complete) return { finished: true, snapshot: snap };
|
|
33347
|
-
if (deps.now() - started >= handOffAfterMs) return { finished: false, snapshot: snap };
|
|
33348
|
-
deps.draw(progressLine2(snap));
|
|
33349
|
-
await deps.sleep(pollMs);
|
|
33350
|
-
}
|
|
33351
|
-
}
|
|
33352
|
-
function spawnDetachedSync(extraArgs = []) {
|
|
33353
|
-
const entry = process.argv[1];
|
|
33354
|
-
if (!entry) return;
|
|
33355
|
-
const child = spawn2(process.execPath, [entry, "sync", ...extraArgs], {
|
|
33356
|
-
detached: true,
|
|
33357
|
-
stdio: "ignore",
|
|
33358
|
-
windowsHide: true
|
|
33359
|
-
});
|
|
33360
|
-
child.unref();
|
|
33361
|
-
}
|
|
33362
|
-
var init_init_progress = __esm({
|
|
33363
|
-
"src/init-progress.ts"() {
|
|
33364
|
-
"use strict";
|
|
33365
|
-
}
|
|
33366
|
-
});
|
|
33367
|
-
|
|
33368
|
-
// src/board-hooks.ts
|
|
33369
|
-
var board_hooks_exports = {};
|
|
33370
|
-
__export(board_hooks_exports, {
|
|
33371
|
-
BOARD_HOOKS: () => BOARD_HOOKS,
|
|
33372
|
-
MESSAGE_HOOK_EVENTS: () => MESSAGE_HOOK_EVENTS,
|
|
33373
|
-
MESSAGE_WAITER_EVENTS: () => MESSAGE_WAITER_EVENTS,
|
|
33374
|
-
MESSAGE_WAITER_TIMEOUT_SECONDS: () => MESSAGE_WAITER_TIMEOUT_SECONDS,
|
|
33375
|
-
boardHookCommand: () => boardHookCommand,
|
|
33376
|
-
boardHookEntries: () => boardHookEntries,
|
|
33377
|
-
isBoardHookEntry: () => isBoardHookEntry,
|
|
33378
|
-
isCurrentMessageWaiterEntry: () => isCurrentMessageWaiterEntry,
|
|
33379
|
-
isMessageHookEntry: () => isMessageHookEntry,
|
|
33380
|
-
isMessageWaiterEntry: () => isMessageWaiterEntry,
|
|
33381
|
-
messageHookCommand: () => messageHookCommand,
|
|
33382
|
-
messageHookEntries: () => messageHookEntries,
|
|
33383
|
-
resolveCliEntry: () => resolveCliEntry,
|
|
33384
|
-
resolveMessageHookEntry: () => resolveMessageHookEntry
|
|
33385
|
-
});
|
|
33386
|
-
import { existsSync as existsSync51 } from "node:fs";
|
|
33387
|
-
import { join as join56 } from "node:path";
|
|
33388
|
-
function entryCommand(entry) {
|
|
33389
|
-
const cmd = entry?.hooks?.[0]?.command;
|
|
33390
|
-
return typeof cmd === "string" ? cmd : null;
|
|
33391
|
-
}
|
|
33392
|
-
function boardHookCommand(execPath, cliEntry, mode) {
|
|
33393
|
-
return `"${execPath}" "${cliEntry}" task-hook --${mode}`;
|
|
33394
|
-
}
|
|
33395
|
-
function isBoardHookEntry(entry) {
|
|
33396
|
-
const cmd = entryCommand(entry);
|
|
33397
|
-
if (cmd === null) return false;
|
|
33398
|
-
if (cmd.includes("chat_recall_task_hook.sh")) return true;
|
|
33399
|
-
return cmd.includes("task-hook") && (cmd.includes("--claim") || cmd.includes("--close"));
|
|
33400
|
-
}
|
|
33401
|
-
function boardHookEntries(execPath, cliEntry) {
|
|
33402
|
-
return BOARD_HOOKS.map(({ event, mode }) => [
|
|
33403
|
-
event,
|
|
33404
|
-
{ matcher: "", hooks: [{ type: "command", command: boardHookCommand(execPath, cliEntry, mode) }] }
|
|
33405
|
-
]);
|
|
33406
|
-
}
|
|
33407
|
-
function messageHookCommand(execPath, hookEntry, waiter = false) {
|
|
33408
|
-
return `"${execPath}" "${hookEntry}"${waiter ? " --wait" : ""}`;
|
|
33409
|
-
}
|
|
33410
|
-
function isMessageHookEntry(entry) {
|
|
33411
|
-
const cmd = entryCommand(entry);
|
|
33412
|
-
return cmd !== null && /message-hook\.(js|ts)"?( --wait)?$/.test(cmd.trim());
|
|
33413
|
-
}
|
|
33414
|
-
function isMessageWaiterEntry(entry) {
|
|
33415
|
-
return isMessageHookEntry(entry) && /--wait$/.test(entryCommand(entry).trim());
|
|
33416
|
-
}
|
|
33417
|
-
function isCurrentMessageWaiterEntry(entry) {
|
|
33418
|
-
if (!isMessageWaiterEntry(entry)) return false;
|
|
33419
|
-
return entry.hooks?.[0]?.timeout === MESSAGE_WAITER_TIMEOUT_SECONDS;
|
|
33420
|
-
}
|
|
33421
|
-
function messageHookEntries(execPath, hookEntry) {
|
|
33422
|
-
const turn = messageHookCommand(execPath, hookEntry);
|
|
33423
|
-
const waiter = messageHookCommand(execPath, hookEntry, true);
|
|
33424
|
-
return [
|
|
33425
|
-
...MESSAGE_HOOK_EVENTS.map((event) => [event, { matcher: "", hooks: [{ type: "command", command: turn }] }]),
|
|
33426
|
-
...MESSAGE_WAITER_EVENTS.map((event) => [event, {
|
|
33427
|
-
matcher: "",
|
|
33428
|
-
hooks: [{ type: "command", command: waiter, asyncRewake: true, timeout: MESSAGE_WAITER_TIMEOUT_SECONDS }]
|
|
33429
|
-
}])
|
|
33430
|
-
];
|
|
33431
|
-
}
|
|
33432
|
-
function resolveCliEntry(distDir) {
|
|
33433
|
-
const bundled = join56(distDir, "cli.js");
|
|
33434
|
-
return existsSync51(bundled) ? bundled : join56(distDir, "cli.ts");
|
|
33435
|
-
}
|
|
33436
|
-
function resolveMessageHookEntry(distDir) {
|
|
33437
|
-
const bundled = join56(distDir, "message-hook.js");
|
|
33438
|
-
return existsSync51(bundled) ? bundled : join56(distDir, "message-hook.ts");
|
|
33439
|
-
}
|
|
33440
|
-
var BOARD_HOOKS, MESSAGE_HOOK_EVENTS, MESSAGE_WAITER_EVENTS, MESSAGE_WAITER_TIMEOUT_SECONDS;
|
|
33441
|
-
var init_board_hooks = __esm({
|
|
33442
|
-
"src/board-hooks.ts"() {
|
|
33443
|
-
"use strict";
|
|
33444
|
-
BOARD_HOOKS = [
|
|
33445
|
-
{ event: "UserPromptSubmit", mode: "claim" },
|
|
33446
|
-
{ event: "SessionEnd", mode: "close" }
|
|
33447
|
-
];
|
|
33448
|
-
MESSAGE_HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop", "SessionEnd"];
|
|
33449
|
-
MESSAGE_WAITER_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop"];
|
|
33450
|
-
MESSAGE_WAITER_TIMEOUT_SECONDS = 86400;
|
|
33451
|
-
}
|
|
33452
|
-
});
|
|
33453
|
-
|
|
33454
|
-
// ../engine/dist/core/guard-registration.js
|
|
33455
|
-
var guard_registration_exports = {};
|
|
33456
|
-
__export(guard_registration_exports, {
|
|
33457
|
-
GUARD_ID: () => GUARD_ID,
|
|
33458
|
-
guardCommand: () => guardCommand,
|
|
33459
|
-
guardTargets: () => guardTargets,
|
|
33460
|
-
guardWrapperName: () => guardWrapperName,
|
|
33461
|
-
guardWrapperSource: () => guardWrapperSource,
|
|
33462
|
-
legacyAgyHooksFile: () => legacyAgyHooksFile,
|
|
33463
|
-
opencodeConfigDir: () => opencodeConfigDir,
|
|
33464
|
-
opencodePluginDir: () => opencodePluginDir,
|
|
33465
|
-
opencodePluginSource: () => opencodePluginSource,
|
|
33466
|
-
registerGuard: () => registerGuard,
|
|
33467
|
-
unregisterGuard: () => unregisterGuard
|
|
33468
|
-
});
|
|
33469
|
-
import { homedir as homedir21 } from "os";
|
|
33470
|
-
import { join as join57 } from "path";
|
|
33471
|
-
function legacyAgyHooksFile() {
|
|
33472
|
-
return join57(agyBackend.homeDir(), "hooks.json");
|
|
33473
|
-
}
|
|
33474
|
-
function opencodeConfigDir() {
|
|
33475
|
-
const xdg = process.env.XDG_CONFIG_HOME;
|
|
33476
|
-
const base4 = xdg && xdg.trim() ? xdg : join57(homedir21(), ".config");
|
|
33477
|
-
return join57(base4, "opencode");
|
|
33478
|
-
}
|
|
33479
|
-
function opencodePluginDir() {
|
|
33480
|
-
return join57(opencodeConfigDir(), "plugins");
|
|
33481
|
-
}
|
|
33482
|
-
function guardTargets() {
|
|
33483
|
-
return [
|
|
33484
|
-
{
|
|
33485
|
-
tool: "codex",
|
|
33486
|
-
label: "Codex",
|
|
33487
|
-
configPath: join57(codexBackend.homeDir(), "hooks.json"),
|
|
33488
|
-
homeDir: codexBackend.homeDir(),
|
|
33489
|
-
// Codex will not run a hook until a person has reviewed it, and the
|
|
33490
|
-
// approval is bound to the hook's hash. There is no way to grant it from
|
|
33491
|
-
// outside: /etc/codex/requirements.toml is the root-owned admin policy,
|
|
33492
|
-
// and the only other route is the per-invocation
|
|
33493
|
-
// --dangerously-bypass-hook-trust flag. An installer that could grant its
|
|
33494
|
-
// own approval is the thing the gate exists to stop.
|
|
33495
|
-
note: "Codex asks you to approve a hook before it runs one. Run /hooks in Codex once to approve this."
|
|
33496
|
-
},
|
|
33497
|
-
{
|
|
33498
|
-
tool: "agy",
|
|
33499
|
-
label: "Antigravity",
|
|
33500
|
-
configPath: agyBackend.sharedHooksFile(),
|
|
33501
|
-
homeDir: agyBackend.homeDir()
|
|
33502
|
-
},
|
|
33503
|
-
{
|
|
33504
|
-
tool: "cursor",
|
|
33505
|
-
label: "Cursor",
|
|
33506
|
-
configPath: join57(cursorBackend.homeDir(), "hooks.json"),
|
|
33507
|
-
homeDir: cursorBackend.homeDir(),
|
|
33508
|
-
note: "Cursor checks a shell command before it runs and a file edit after it is written."
|
|
33509
|
-
},
|
|
33510
|
-
{
|
|
33511
|
-
tool: "opencode",
|
|
33512
|
-
label: "OpenCode",
|
|
33513
|
-
configPath: join57(opencodePluginDir(), "chat-recall-guard.js"),
|
|
33514
|
-
homeDir: opencodeConfigDir(),
|
|
33515
|
-
note: "OpenCode plugin hooks do not fire for subagent tool calls, so a delegating agent bypasses this."
|
|
33516
|
-
}
|
|
33517
|
-
];
|
|
33518
|
-
}
|
|
33519
|
-
function guardWrapperName(tool) {
|
|
33520
|
-
return `chat_recall_guard_${tool}.sh`;
|
|
33521
|
-
}
|
|
33522
|
-
function guardWrapperSource(tool, hookPath) {
|
|
33523
|
-
return `#!/bin/sh
|
|
33524
|
-
# Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
33525
|
-
CHAT_RECALL_GUARD_HARNESS=${tool}
|
|
33526
|
-
export CHAT_RECALL_GUARD_HARNESS
|
|
33527
|
-
exec ${JSON.stringify(hookPath)} "$@"
|
|
33528
|
-
`;
|
|
33529
|
-
}
|
|
33530
|
-
function guardCommand(wrapperPath) {
|
|
33531
|
-
return wrapperPath.includes(" ") ? `"${wrapperPath}"` : wrapperPath;
|
|
33532
|
-
}
|
|
33533
|
-
function mergeCodex(config2, command) {
|
|
33534
|
-
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
33535
|
-
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
33536
|
-
const kept = asArray2(hooks.PreToolUse).filter((e) => !asArray2(e?.hooks).some((h) => isOurs(h?.command)));
|
|
33537
|
-
kept.push({
|
|
33538
|
-
matcher: CODEX_MATCHER,
|
|
33539
|
-
hooks: [{ type: "command", command, statusMessage: "chat-recall: checking decisions", timeout: TIMEOUT_SECS }]
|
|
33540
|
-
});
|
|
33541
|
-
hooks.PreToolUse = kept;
|
|
33542
|
-
c.hooks = hooks;
|
|
33543
|
-
return c;
|
|
33544
|
-
}
|
|
33545
|
-
function stripCodex(config2) {
|
|
33546
|
-
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
33547
|
-
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
33548
|
-
const before = asArray2(hooks.PreToolUse);
|
|
33549
|
-
const kept = before.filter((e) => !asArray2(e?.hooks).some((h) => isOurs(h?.command)));
|
|
33550
|
-
if (kept.length)
|
|
33551
|
-
hooks.PreToolUse = kept;
|
|
33552
|
-
else
|
|
33553
|
-
delete hooks.PreToolUse;
|
|
33554
|
-
c.hooks = hooks;
|
|
33555
|
-
return { config: c, removed: before.length - kept.length };
|
|
33556
|
-
}
|
|
33557
|
-
function mergeAgy(config2, command) {
|
|
33558
|
-
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
33559
|
-
c[GUARD_ID] = {
|
|
33560
|
-
enabled: true,
|
|
33561
|
-
PreToolUse: [{
|
|
33562
|
-
matcher: AGY_MATCHER,
|
|
33563
|
-
hooks: [{ type: "command", command, timeout: TIMEOUT_SECS }]
|
|
33564
|
-
}]
|
|
33565
|
-
};
|
|
33566
|
-
return c;
|
|
33567
|
-
}
|
|
33568
|
-
function stripAgy(config2) {
|
|
33569
|
-
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
33570
|
-
const had = Object.prototype.hasOwnProperty.call(c, GUARD_ID) ? 1 : 0;
|
|
33571
|
-
delete c[GUARD_ID];
|
|
33572
|
-
return { config: c, removed: had };
|
|
33573
|
-
}
|
|
33574
|
-
function mergeCursor(config2, command) {
|
|
33575
|
-
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
33576
|
-
c.version = typeof c.version === "number" ? c.version : 1;
|
|
33577
|
-
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
33578
|
-
for (const event of ["beforeShellExecution", "afterFileEdit"]) {
|
|
33579
|
-
const kept = asArray2(hooks[event]).filter((e) => !isOurs(e?.command));
|
|
33580
|
-
kept.push({ command });
|
|
33581
|
-
hooks[event] = kept;
|
|
33582
|
-
}
|
|
33583
|
-
c.hooks = hooks;
|
|
33584
|
-
return c;
|
|
33585
|
-
}
|
|
33586
|
-
function stripCursor(config2) {
|
|
33587
|
-
const c = config2 && typeof config2 === "object" ? { ...config2 } : {};
|
|
33588
|
-
const hooks = c.hooks && typeof c.hooks === "object" ? { ...c.hooks } : {};
|
|
33589
|
-
let removed = 0;
|
|
33590
|
-
for (const event of ["beforeShellExecution", "afterFileEdit"]) {
|
|
33591
|
-
const before = asArray2(hooks[event]);
|
|
33592
|
-
const kept = before.filter((e) => !isOurs(e?.command));
|
|
33593
|
-
removed += before.length - kept.length;
|
|
33594
|
-
if (kept.length)
|
|
33595
|
-
hooks[event] = kept;
|
|
33596
|
-
else
|
|
33597
|
-
delete hooks[event];
|
|
33598
|
-
}
|
|
33599
|
-
c.hooks = hooks;
|
|
33600
|
-
return { config: c, removed };
|
|
33601
|
-
}
|
|
33602
|
-
function registerGuard(tool, config2, command) {
|
|
33603
|
-
switch (tool) {
|
|
33604
|
-
case "codex":
|
|
33605
|
-
return mergeCodex(config2, command);
|
|
33606
|
-
case "agy":
|
|
33607
|
-
return mergeAgy(config2, command);
|
|
33608
|
-
case "cursor":
|
|
33609
|
-
return mergeCursor(config2, command);
|
|
33610
|
-
}
|
|
33611
|
-
}
|
|
33612
|
-
function unregisterGuard(tool, config2) {
|
|
33613
|
-
switch (tool) {
|
|
33614
|
-
case "codex":
|
|
33615
|
-
return stripCodex(config2);
|
|
33616
|
-
case "agy":
|
|
33617
|
-
return stripAgy(config2);
|
|
33618
|
-
case "cursor":
|
|
33619
|
-
return stripCursor(config2);
|
|
33620
|
-
}
|
|
33621
|
-
}
|
|
33622
|
-
function opencodePluginSource(hookPath) {
|
|
33623
|
-
return `// Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
33624
|
-
//
|
|
33625
|
-
// Sends each tool call to the same guard the other harnesses run, and prints
|
|
33626
|
-
// what it says. Blocking is opt-in: set CHAT_RECALL_GUARD_ENFORCE=1 and a
|
|
33627
|
-
// finding throws, which is how an OpenCode plugin stops a call.
|
|
33628
|
-
import { spawn } from "child_process";
|
|
33629
|
-
|
|
33630
|
-
const HOOK = ${JSON.stringify(hookPath)};
|
|
33631
|
-
|
|
33632
|
-
function ask(payload) {
|
|
33633
|
-
return new Promise((resolve) => {
|
|
33634
|
-
let out = "";
|
|
33635
|
-
const child = spawn(HOOK, {
|
|
33636
|
-
env: { ...process.env, CHAT_RECALL_GUARD_HARNESS: "opencode" },
|
|
33637
|
-
stdio: ["pipe", "pipe", "ignore"],
|
|
33638
|
-
});
|
|
33639
|
-
const done = setTimeout(() => { child.kill(); resolve(null); }, ${TIMEOUT_SECS * 1e3});
|
|
33640
|
-
child.stdout.on("data", (c) => { out += c; });
|
|
33641
|
-
child.on("error", () => { clearTimeout(done); resolve(null); });
|
|
33642
|
-
child.on("close", () => {
|
|
33643
|
-
clearTimeout(done);
|
|
33644
|
-
try { resolve(out.trim() ? JSON.parse(out) : null); } catch { resolve(null); }
|
|
33645
|
-
});
|
|
33646
|
-
child.stdin.end(JSON.stringify(payload));
|
|
33647
|
-
});
|
|
33648
|
-
}
|
|
33649
|
-
|
|
33650
|
-
async function check(tool, args) {
|
|
33651
|
-
const verdict = await ask({ tool, args });
|
|
33652
|
-
if (!verdict || !verdict.message) return;
|
|
33653
|
-
if (verdict.block) throw new Error(verdict.message);
|
|
33654
|
-
console.error(verdict.message);
|
|
33655
|
-
}
|
|
33656
|
-
|
|
33657
|
-
async function setup(ctx) {
|
|
33658
|
-
await ctx.tool.hook("execute.before", (event) => check(event?.tool, event?.input));
|
|
33659
|
-
}
|
|
33660
|
-
|
|
33661
|
-
async function server() {
|
|
33662
|
-
return {
|
|
33663
|
-
"tool.execute.before": (input, output) => check(input?.tool, output?.args),
|
|
33664
|
-
};
|
|
33665
|
-
}
|
|
33666
|
-
|
|
33667
|
-
export default { id: "${GUARD_ID}", server, setup };
|
|
33668
|
-
`;
|
|
33669
|
-
}
|
|
33670
|
-
var GUARD_ID, AGY_MATCHER, CODEX_MATCHER, TIMEOUT_SECS, isOurs, asArray2;
|
|
33671
|
-
var init_guard_registration = __esm({
|
|
33672
|
-
"../engine/dist/core/guard-registration.js"() {
|
|
33673
|
-
"use strict";
|
|
33674
|
-
init_backends();
|
|
33675
|
-
GUARD_ID = "chat-recall-guard";
|
|
33676
|
-
AGY_MATCHER = "run_command|write_to_file|replace_file_content|multi_replace_file_content";
|
|
33677
|
-
CODEX_MATCHER = "Bash|apply_patch|Edit|Write";
|
|
33678
|
-
TIMEOUT_SECS = 8;
|
|
33679
|
-
isOurs = (cmd) => typeof cmd === "string" && cmd.includes("chat_recall_guard");
|
|
33680
|
-
asArray2 = (v) => Array.isArray(v) ? v : [];
|
|
34472
|
+
continue;
|
|
34473
|
+
}
|
|
34474
|
+
const entry = { ...built.entry };
|
|
34475
|
+
let rewrittenCommand;
|
|
34476
|
+
if (!entry.url) {
|
|
34477
|
+
const raw = Array.isArray(entry.command) ? entry.command[0] : entry.command;
|
|
34478
|
+
const port = portableCommand(raw);
|
|
34479
|
+
if ("missing" in port) {
|
|
34480
|
+
outcomes.push({ type: "mcp", name, tool, status: "skipped", reason: `not installed here: ${port.missing}` });
|
|
34481
|
+
continue;
|
|
34482
|
+
}
|
|
34483
|
+
if (port.rewritten) {
|
|
34484
|
+
rewrittenCommand = port.command;
|
|
34485
|
+
if (Array.isArray(entry.command))
|
|
34486
|
+
entry.command = [port.command, ...entry.command.slice(1)];
|
|
34487
|
+
else
|
|
34488
|
+
entry.command = port.command;
|
|
34489
|
+
}
|
|
34490
|
+
}
|
|
34491
|
+
if (opts.dryRun) {
|
|
34492
|
+
outcomes.push({ type: "mcp", name, tool, status: "written", reason: "dry run", needsEnv: built.needsEnv, rewrittenCommand });
|
|
34493
|
+
continue;
|
|
34494
|
+
}
|
|
34495
|
+
const r = writeMcpEntry(tool, name, entry);
|
|
34496
|
+
if (r.ok)
|
|
34497
|
+
outcomes.push({ type: "mcp", name, tool, status: "written", path: r.targetPath, needsEnv: built.needsEnv, rewrittenCommand });
|
|
34498
|
+
else if (r.status === 409)
|
|
34499
|
+
outcomes.push({ type: "mcp", name, tool, status: "present" });
|
|
34500
|
+
else
|
|
34501
|
+
outcomes.push({ type: "mcp", name, tool, status: "failed", reason: r.error });
|
|
34502
|
+
}
|
|
33681
34503
|
}
|
|
33682
|
-
}
|
|
33683
|
-
|
|
33684
|
-
// ../engine/dist/core/session-messages.js
|
|
33685
|
-
function selfIntroduction(sessionId) {
|
|
33686
|
-
return [
|
|
33687
|
-
MESSAGES_MARKER,
|
|
33688
|
-
`chat-recall session id: ${sessionId}`,
|
|
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
|
-
].join("\n");
|
|
34504
|
+
return { outcomes, unsupported };
|
|
33691
34505
|
}
|
|
33692
|
-
var
|
|
33693
|
-
var
|
|
33694
|
-
"../engine/dist/core/
|
|
34506
|
+
var NOT_REBUILDABLE;
|
|
34507
|
+
var init_toolkit_pull = __esm({
|
|
34508
|
+
"../engine/dist/core/toolkit-pull.js"() {
|
|
33695
34509
|
"use strict";
|
|
33696
|
-
|
|
34510
|
+
init_which();
|
|
34511
|
+
init_toolkit_sync();
|
|
34512
|
+
init_artifact_codec();
|
|
34513
|
+
NOT_REBUILDABLE = {
|
|
34514
|
+
// Instructions are the one type that SHOULD not travel by device: a CLAUDE.md
|
|
34515
|
+
// belongs to a repository, so installing one per machine would put a
|
|
34516
|
+
// project's rules somewhere they do not apply.
|
|
34517
|
+
instructions: "project-scoped \u2014 it belongs to a repo, not to a machine"
|
|
34518
|
+
};
|
|
33697
34519
|
}
|
|
33698
34520
|
});
|
|
33699
34521
|
|
|
33700
|
-
//
|
|
33701
|
-
var
|
|
33702
|
-
__export(
|
|
33703
|
-
|
|
33704
|
-
|
|
33705
|
-
|
|
33706
|
-
|
|
33707
|
-
|
|
33708
|
-
|
|
33709
|
-
opencodeMessagesSource: () => opencodeMessagesSource,
|
|
33710
|
-
piAgentDir: () => piAgentDir2,
|
|
33711
|
-
piMessagesSource: () => piMessagesSource,
|
|
33712
|
-
registerMessages: () => registerMessages,
|
|
33713
|
-
unregisterMessages: () => unregisterMessages
|
|
34522
|
+
// src/init-progress.ts
|
|
34523
|
+
var init_progress_exports = {};
|
|
34524
|
+
__export(init_progress_exports, {
|
|
34525
|
+
handOffLine: () => handOffLine,
|
|
34526
|
+
progressLine: () => progressLine2,
|
|
34527
|
+
renderBar: () => renderBar,
|
|
34528
|
+
renderCount: () => renderCount,
|
|
34529
|
+
spawnDetachedSync: () => spawnDetachedSync,
|
|
34530
|
+
watchFirstSync: () => watchFirstSync
|
|
33714
34531
|
});
|
|
33715
|
-
import {
|
|
33716
|
-
|
|
33717
|
-
|
|
33718
|
-
const
|
|
33719
|
-
|
|
33720
|
-
|
|
33721
|
-
function messageTargets() {
|
|
33722
|
-
return [
|
|
33723
|
-
{
|
|
33724
|
-
tool: "codex",
|
|
33725
|
-
label: "Codex",
|
|
33726
|
-
configPath: join58(codexBackend.homeDir(), "hooks.json"),
|
|
33727
|
-
homeDir: codexBackend.homeDir(),
|
|
33728
|
-
// Codex binds its approval to the hook's hash, and only a person can give it.
|
|
33729
|
-
note: "Codex asks you to approve a hook before it runs one. Run /hooks in Codex once to approve the message hook."
|
|
33730
|
-
},
|
|
33731
|
-
{
|
|
33732
|
-
tool: "agy",
|
|
33733
|
-
label: "Antigravity",
|
|
33734
|
-
configPath: agyBackend.sharedHooksFile(),
|
|
33735
|
-
homeDir: agyBackend.homeDir()
|
|
33736
|
-
},
|
|
33737
|
-
{
|
|
33738
|
-
tool: "cursor",
|
|
33739
|
-
label: "Cursor",
|
|
33740
|
-
configPath: join58(cursorBackend.homeDir(), "hooks.json"),
|
|
33741
|
-
homeDir: cursorBackend.homeDir(),
|
|
33742
|
-
note: "Cursor delivers a message at the start of a session and when the agent stops, as a follow-up prompt."
|
|
33743
|
-
},
|
|
33744
|
-
{
|
|
33745
|
-
tool: "opencode",
|
|
33746
|
-
label: "OpenCode",
|
|
33747
|
-
configPath: join58(opencodePluginDir(), `${MESSAGES_ID}.js`),
|
|
33748
|
-
homeDir: opencodeConfigDir()
|
|
33749
|
-
},
|
|
33750
|
-
{
|
|
33751
|
-
tool: "pi",
|
|
33752
|
-
label: "pi",
|
|
33753
|
-
configPath: join58(piAgentDir2(), "extensions", `${MESSAGES_ID}.js`),
|
|
33754
|
-
homeDir: piAgentDir2()
|
|
33755
|
-
}
|
|
33756
|
-
];
|
|
33757
|
-
}
|
|
33758
|
-
function messageWrapperName(tool) {
|
|
33759
|
-
return `chat_recall_messages_${tool}.sh`;
|
|
33760
|
-
}
|
|
33761
|
-
function messageWrapperSource(tool, nodePath, hookEntry) {
|
|
33762
|
-
return `#!/bin/sh
|
|
33763
|
-
# Written by \`chat-recall install-hooks\`. Re-running replaces it.
|
|
33764
|
-
exec ${JSON.stringify(nodePath)} ${JSON.stringify(hookEntry)} --tool ${tool} "$@"
|
|
33765
|
-
`;
|
|
33766
|
-
}
|
|
33767
|
-
function messageCommand(wrapperPath, args = "") {
|
|
33768
|
-
const p = wrapperPath.includes(" ") ? `"${wrapperPath}"` : wrapperPath;
|
|
33769
|
-
return args ? `${p} ${args}` : p;
|
|
33770
|
-
}
|
|
33771
|
-
function mergeCodex2(config2, command) {
|
|
33772
|
-
const c = obj(config2);
|
|
33773
|
-
const hooks = obj(c.hooks);
|
|
33774
|
-
for (const event of CODEX_EVENTS) {
|
|
33775
|
-
const kept = asArray3(hooks[event]).filter((e) => !asArray3(e?.hooks).some((h) => isOurs2(h?.command)));
|
|
33776
|
-
kept.push({ hooks: [{ type: "command", command, timeout: TIMEOUT_SECS2 }] });
|
|
33777
|
-
hooks[event] = kept;
|
|
33778
|
-
}
|
|
33779
|
-
c.hooks = hooks;
|
|
33780
|
-
return c;
|
|
33781
|
-
}
|
|
33782
|
-
function stripCodex2(config2) {
|
|
33783
|
-
const c = obj(config2);
|
|
33784
|
-
const hooks = obj(c.hooks);
|
|
33785
|
-
let removed = 0;
|
|
33786
|
-
for (const event of CODEX_EVENTS) {
|
|
33787
|
-
const before = asArray3(hooks[event]);
|
|
33788
|
-
const kept = before.filter((e) => !asArray3(e?.hooks).some((h) => isOurs2(h?.command)));
|
|
33789
|
-
removed += before.length - kept.length;
|
|
33790
|
-
if (kept.length)
|
|
33791
|
-
hooks[event] = kept;
|
|
33792
|
-
else
|
|
33793
|
-
delete hooks[event];
|
|
33794
|
-
}
|
|
33795
|
-
if (Object.keys(hooks).length)
|
|
33796
|
-
c.hooks = hooks;
|
|
33797
|
-
else
|
|
33798
|
-
delete c.hooks;
|
|
33799
|
-
return { config: c, removed };
|
|
34532
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
34533
|
+
function renderBar(done, total, width = 12) {
|
|
34534
|
+
if (total <= 0) return "\u2591".repeat(width);
|
|
34535
|
+
const ratio = Math.max(0, Math.min(1, done / total));
|
|
34536
|
+
const filled = Math.round(ratio * width);
|
|
34537
|
+
return "\u2588".repeat(filled) + "\u2591".repeat(width - filled);
|
|
33800
34538
|
}
|
|
33801
|
-
function
|
|
33802
|
-
const
|
|
33803
|
-
|
|
33804
|
-
c[MESSAGES_ID] = {
|
|
33805
|
-
enabled: true,
|
|
33806
|
-
SessionStart: run("SessionStart"),
|
|
33807
|
-
PreInvocation: run("PreInvocation"),
|
|
33808
|
-
Stop: run("Stop")
|
|
33809
|
-
};
|
|
33810
|
-
return c;
|
|
34539
|
+
function renderCount(done, total) {
|
|
34540
|
+
const n = (x) => x.toLocaleString("en-US");
|
|
34541
|
+
return `${n(done)}/${n(total)}`;
|
|
33811
34542
|
}
|
|
33812
|
-
function
|
|
33813
|
-
|
|
33814
|
-
|
|
33815
|
-
|
|
33816
|
-
return { config: c, removed: had };
|
|
34543
|
+
function progressLine2(snap) {
|
|
34544
|
+
if (!snap || snap.total <= 0) return "starting\u2026";
|
|
34545
|
+
if (snap.complete) return `${renderCount(snap.done, snap.total)} indexed`;
|
|
34546
|
+
return `${renderBar(snap.done, snap.total)} ${renderCount(snap.done, snap.total)}`;
|
|
33817
34547
|
}
|
|
33818
|
-
function
|
|
33819
|
-
const
|
|
33820
|
-
|
|
33821
|
-
const hooks = obj(c.hooks);
|
|
33822
|
-
for (const event of CURSOR_EVENTS) {
|
|
33823
|
-
const kept = asArray3(hooks[event]).filter((e) => !isOurs2(e?.command));
|
|
33824
|
-
kept.push({ command, timeout: TIMEOUT_SECS2 });
|
|
33825
|
-
hooks[event] = kept;
|
|
33826
|
-
}
|
|
33827
|
-
c.hooks = hooks;
|
|
33828
|
-
return c;
|
|
34548
|
+
function handOffLine(snap) {
|
|
34549
|
+
const where = snap && snap.total > 0 ? `${renderCount(snap.done, snap.total)} so far` : "started";
|
|
34550
|
+
return `${where} \u2014 continuing in the background`;
|
|
33829
34551
|
}
|
|
33830
|
-
function
|
|
33831
|
-
const
|
|
33832
|
-
const
|
|
33833
|
-
|
|
33834
|
-
|
|
33835
|
-
|
|
33836
|
-
|
|
33837
|
-
|
|
33838
|
-
if (
|
|
33839
|
-
|
|
33840
|
-
|
|
33841
|
-
|
|
34552
|
+
async function watchFirstSync(deps) {
|
|
34553
|
+
const handOffAfterMs = deps.handOffAfterMs ?? 2e4;
|
|
34554
|
+
const pollMs = deps.pollMs ?? 400;
|
|
34555
|
+
const started = deps.now();
|
|
34556
|
+
deps.startWorker();
|
|
34557
|
+
let snap = null;
|
|
34558
|
+
for (; ; ) {
|
|
34559
|
+
snap = deps.readProgress();
|
|
34560
|
+
if (snap?.complete) return { finished: true, snapshot: snap };
|
|
34561
|
+
if (deps.now() - started >= handOffAfterMs) return { finished: false, snapshot: snap };
|
|
34562
|
+
deps.draw(progressLine2(snap));
|
|
34563
|
+
await deps.sleep(pollMs);
|
|
33842
34564
|
}
|
|
33843
|
-
c.hooks = hooks;
|
|
33844
|
-
return { config: c, removed };
|
|
33845
34565
|
}
|
|
33846
|
-
function
|
|
33847
|
-
|
|
33848
|
-
|
|
33849
|
-
|
|
33850
|
-
|
|
33851
|
-
|
|
33852
|
-
|
|
33853
|
-
|
|
33854
|
-
|
|
34566
|
+
function spawnDetachedSync(extraArgs = []) {
|
|
34567
|
+
const entry = process.argv[1];
|
|
34568
|
+
if (!entry) return;
|
|
34569
|
+
const child = spawn2(process.execPath, [entry, "sync", ...extraArgs], {
|
|
34570
|
+
detached: true,
|
|
34571
|
+
stdio: "ignore",
|
|
34572
|
+
windowsHide: true
|
|
34573
|
+
});
|
|
34574
|
+
child.unref();
|
|
33855
34575
|
}
|
|
33856
|
-
|
|
33857
|
-
|
|
33858
|
-
|
|
33859
|
-
return stripCodex2(config2);
|
|
33860
|
-
case "agy":
|
|
33861
|
-
return stripAgy2(config2);
|
|
33862
|
-
case "cursor":
|
|
33863
|
-
return stripCursor2(config2);
|
|
34576
|
+
var init_init_progress = __esm({
|
|
34577
|
+
"src/init-progress.ts"() {
|
|
34578
|
+
"use strict";
|
|
33864
34579
|
}
|
|
33865
|
-
}
|
|
33866
|
-
function isOurPluginSource(source) {
|
|
33867
|
-
return source.includes(`${MESSAGES_ID}: written by`);
|
|
33868
|
-
}
|
|
33869
|
-
function runnerSource(wrapperPath) {
|
|
33870
|
-
return `import { spawn } from "child_process";
|
|
33871
|
-
|
|
33872
|
-
const HOOK = ${JSON.stringify(wrapperPath)};
|
|
34580
|
+
});
|
|
33873
34581
|
|
|
33874
|
-
|
|
33875
|
-
|
|
33876
|
-
|
|
33877
|
-
|
|
33878
|
-
|
|
33879
|
-
|
|
33880
|
-
|
|
33881
|
-
|
|
33882
|
-
|
|
33883
|
-
|
|
33884
|
-
|
|
33885
|
-
|
|
33886
|
-
|
|
33887
|
-
|
|
33888
|
-
|
|
33889
|
-
|
|
34582
|
+
// src/board-hooks.ts
|
|
34583
|
+
var board_hooks_exports = {};
|
|
34584
|
+
__export(board_hooks_exports, {
|
|
34585
|
+
BOARD_HOOKS: () => BOARD_HOOKS,
|
|
34586
|
+
MESSAGE_HOOK_EVENTS: () => MESSAGE_HOOK_EVENTS,
|
|
34587
|
+
MESSAGE_WAITER_EVENTS: () => MESSAGE_WAITER_EVENTS,
|
|
34588
|
+
MESSAGE_WAITER_TIMEOUT_SECONDS: () => MESSAGE_WAITER_TIMEOUT_SECONDS,
|
|
34589
|
+
boardHookCommand: () => boardHookCommand,
|
|
34590
|
+
boardHookEntries: () => boardHookEntries,
|
|
34591
|
+
isBoardHookEntry: () => isBoardHookEntry,
|
|
34592
|
+
isCurrentMessageWaiterEntry: () => isCurrentMessageWaiterEntry,
|
|
34593
|
+
isMessageHookEntry: () => isMessageHookEntry,
|
|
34594
|
+
isMessageWaiterEntry: () => isMessageWaiterEntry,
|
|
34595
|
+
messageHookCommand: () => messageHookCommand,
|
|
34596
|
+
messageHookEntries: () => messageHookEntries,
|
|
34597
|
+
resolveCliEntry: () => resolveCliEntry,
|
|
34598
|
+
resolveMessageHookEntry: () => resolveMessageHookEntry
|
|
34599
|
+
});
|
|
34600
|
+
import { existsSync as existsSync52 } from "node:fs";
|
|
34601
|
+
import { join as join59 } from "node:path";
|
|
34602
|
+
function entryCommand(entry) {
|
|
34603
|
+
const cmd = entry?.hooks?.[0]?.command;
|
|
34604
|
+
return typeof cmd === "string" ? cmd : null;
|
|
33890
34605
|
}
|
|
33891
|
-
|
|
33892
|
-
|
|
33893
|
-
* 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.
|
|
33896
|
-
*/
|
|
33897
|
-
const waiters = new Map();
|
|
33898
|
-
|
|
33899
|
-
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 }));
|
|
34606
|
+
function boardHookCommand(execPath, cliEntry, mode) {
|
|
34607
|
+
return `"${execPath}" "${cliEntry}" task-hook --${mode}`;
|
|
33917
34608
|
}
|
|
33918
|
-
|
|
33919
|
-
|
|
33920
|
-
|
|
33921
|
-
if (
|
|
33922
|
-
|
|
33923
|
-
try { child.kill(); } catch { /* gone */ }
|
|
34609
|
+
function isBoardHookEntry(entry) {
|
|
34610
|
+
const cmd = entryCommand(entry);
|
|
34611
|
+
if (cmd === null) return false;
|
|
34612
|
+
if (cmd.includes("chat_recall_task_hook.sh")) return true;
|
|
34613
|
+
return cmd.includes("task-hook") && (cmd.includes("--claim") || cmd.includes("--close"));
|
|
33924
34614
|
}
|
|
33925
|
-
|
|
34615
|
+
function boardHookEntries(execPath, cliEntry) {
|
|
34616
|
+
return BOARD_HOOKS.map(({ event, mode }) => [
|
|
34617
|
+
event,
|
|
34618
|
+
{ matcher: "", hooks: [{ type: "command", command: boardHookCommand(execPath, cliEntry, mode) }] }
|
|
34619
|
+
]);
|
|
33926
34620
|
}
|
|
33927
|
-
function
|
|
33928
|
-
return
|
|
33929
|
-
//
|
|
33930
|
-
// Reports each opencode session to chat-recall and adds the messages that
|
|
33931
|
-
// other sessions sent it to the next prompt.
|
|
33932
|
-
${runnerSource(wrapperPath)}
|
|
33933
|
-
const RUN_END = new Set(["session.execution.succeeded", "session.execution.failed", "session.execution.interrupted", "session.idle"]);
|
|
33934
|
-
const INTRO = ${JSON.stringify(selfIntroduction("\0SESSION\0"))};
|
|
33935
|
-
const intro = (id) => INTRO.replace("\0SESSION\0", "opencode_" + id);
|
|
33936
|
-
|
|
33937
|
-
async function setup(ctx) {
|
|
33938
|
-
const dir = ctx?.location?.directory;
|
|
33939
|
-
const children = new Set();
|
|
33940
|
-
const isChild = async (id) => {
|
|
33941
|
-
if (children.has(id)) return true;
|
|
33942
|
-
try {
|
|
33943
|
-
const s = await ctx.session.get({ sessionID: id });
|
|
33944
|
-
if (s?.parentID) { children.add(id); return true; }
|
|
33945
|
-
} catch { /* unknown: treat as a main session */ }
|
|
33946
|
-
return false;
|
|
33947
|
-
};
|
|
33948
|
-
await ctx.session.hook("prompt", async (event) => {
|
|
33949
|
-
const id = event?.sessionID;
|
|
33950
|
-
if (!id || !event.prompt || (await isChild(id))) return;
|
|
33951
|
-
stopWaiter("opencode_" + id);
|
|
33952
|
-
// The first prompt registers the session; the hook adds only waiting messages.
|
|
33953
|
-
const text = await runHook("opencode_" + id, "UserPromptSubmit", dir);
|
|
33954
|
-
if (text) event.prompt.text = [event.prompt.text, text].filter(Boolean).join("\\n\\n");
|
|
33955
|
-
});
|
|
33956
|
-
// The session id goes into the system context of each model call: the agent
|
|
33957
|
-
// always knows it, the user does not see it, and no prompt repeats it.
|
|
33958
|
-
await ctx.session.hook("context", async (event) => {
|
|
33959
|
-
const id = event?.sessionID;
|
|
33960
|
-
if (!id || !Array.isArray(event.system) || (await isChild(id))) return;
|
|
33961
|
-
event.system.push({ type: "text", text: intro(id) });
|
|
33962
|
-
});
|
|
33963
|
-
const controller = new AbortController();
|
|
33964
|
-
(async () => {
|
|
33965
|
-
try {
|
|
33966
|
-
for await (const ev of ctx.event.subscribe({ signal: controller.signal })) {
|
|
33967
|
-
const id = ev?.data?.sessionID ?? ev?.properties?.sessionID;
|
|
33968
|
-
// A session that was open before this plugin loaded (a reload, an
|
|
33969
|
-
// update) is not in started, and still gets its waiter.
|
|
33970
|
-
if (!id || (await isChild(id))) continue;
|
|
33971
|
-
if (RUN_END.has(ev.type)) {
|
|
33972
|
-
await runHook("opencode_" + id, "Stop", dir);
|
|
33973
|
-
// An idle session acts on a message from another session by itself:
|
|
33974
|
-
// the text becomes its next prompt.
|
|
33975
|
-
startWaiter("opencode_" + id, dir, (text) => ctx.session.prompt({ sessionID: id, text }));
|
|
33976
|
-
} else if (ev.type === "session.deleted") {
|
|
33977
|
-
stopWaiter("opencode_" + id);
|
|
33978
|
-
await runHook("opencode_" + id, "SessionEnd", dir);
|
|
33979
|
-
}
|
|
33980
|
-
}
|
|
33981
|
-
} catch { /* the subscription ends with the plugin */ }
|
|
33982
|
-
})();
|
|
33983
|
-
return () => {
|
|
33984
|
-
controller.abort();
|
|
33985
|
-
for (const id of [...waiters.keys()]) stopWaiter(id);
|
|
33986
|
-
};
|
|
34621
|
+
function messageHookCommand(execPath, hookEntry, waiter = false) {
|
|
34622
|
+
return `"${execPath}" "${hookEntry}"${waiter ? " --wait" : ""}`;
|
|
33987
34623
|
}
|
|
33988
|
-
|
|
33989
|
-
const
|
|
33990
|
-
|
|
33991
|
-
let seq = 0;
|
|
33992
|
-
|
|
33993
|
-
function partId() {
|
|
33994
|
-
seq += 1;
|
|
33995
|
-
return "prt_" + Date.now().toString(16) + seq.toString(16).padStart(4, "0") + "chatrecall";
|
|
34624
|
+
function isMessageHookEntry(entry) {
|
|
34625
|
+
const cmd = entryCommand(entry);
|
|
34626
|
+
return cmd !== null && /message-hook\.(js|ts)"?( --wait)?$/.test(cmd.trim());
|
|
33996
34627
|
}
|
|
33997
|
-
|
|
33998
|
-
|
|
33999
|
-
return {
|
|
34000
|
-
event: async ({ event }) => {
|
|
34001
|
-
const info = event?.properties?.info;
|
|
34002
|
-
if (event?.type === "session.created" && info?.id) {
|
|
34003
|
-
if (info.parentID) { children.add(info.id); return; }
|
|
34004
|
-
const text = await runHook("opencode_" + info.id, "SessionStart", directory);
|
|
34005
|
-
if (text) pending.set(info.id, text);
|
|
34006
|
-
} else if (event?.type === "session.idle" && event.properties?.sessionID && !children.has(event.properties.sessionID)) {
|
|
34007
|
-
await runHook("opencode_" + event.properties.sessionID, "Stop", directory);
|
|
34008
|
-
} else if (event?.type === "session.deleted" && info?.id) {
|
|
34009
|
-
children.delete(info.id);
|
|
34010
|
-
pending.delete(info.id);
|
|
34011
|
-
await runHook("opencode_" + info.id, "SessionEnd", directory);
|
|
34012
|
-
}
|
|
34013
|
-
},
|
|
34014
|
-
"experimental.chat.system.transform": async (input, output) => {
|
|
34015
|
-
const id = input?.sessionID;
|
|
34016
|
-
if (!id || children.has(id) || !Array.isArray(output?.system)) return;
|
|
34017
|
-
output.system.push(intro(id));
|
|
34018
|
-
},
|
|
34019
|
-
"chat.message": async (input, output) => {
|
|
34020
|
-
const id = input?.sessionID;
|
|
34021
|
-
if (!id || children.has(id) || !output?.message) return;
|
|
34022
|
-
const before = pending.get(id) ?? "";
|
|
34023
|
-
pending.delete(id);
|
|
34024
|
-
const now = await runHook("opencode_" + id, "UserPromptSubmit", directory);
|
|
34025
|
-
const text = [before, now].filter(Boolean).join("\\n\\n");
|
|
34026
|
-
if (!text) return;
|
|
34027
|
-
output.parts.push({ id: partId(), sessionID: id, messageID: output.message.id, type: "text", text, synthetic: true });
|
|
34028
|
-
},
|
|
34029
|
-
};
|
|
34628
|
+
function isMessageWaiterEntry(entry) {
|
|
34629
|
+
return isMessageHookEntry(entry) && /--wait$/.test(entryCommand(entry).trim());
|
|
34030
34630
|
}
|
|
34031
|
-
|
|
34032
|
-
|
|
34033
|
-
|
|
34631
|
+
function isCurrentMessageWaiterEntry(entry) {
|
|
34632
|
+
if (!isMessageWaiterEntry(entry)) return false;
|
|
34633
|
+
return entry.hooks?.[0]?.timeout === MESSAGE_WAITER_TIMEOUT_SECONDS;
|
|
34034
34634
|
}
|
|
34035
|
-
function
|
|
34036
|
-
|
|
34037
|
-
|
|
34038
|
-
|
|
34039
|
-
|
|
34040
|
-
|
|
34041
|
-
|
|
34042
|
-
|
|
34043
|
-
|
|
34044
|
-
|
|
34045
|
-
|
|
34046
|
-
pi.on("session_start", async (_event, ctx) => {
|
|
34047
|
-
pending = await runHook(idOf(ctx), "SessionStart", cwdOf(ctx));
|
|
34048
|
-
});
|
|
34049
|
-
pi.on("before_agent_start", async (event, ctx) => {
|
|
34050
|
-
stopWaiter(idOf(ctx));
|
|
34051
|
-
if (event.messageType !== "user") return;
|
|
34052
|
-
const now = await runHook(idOf(ctx), "UserPromptSubmit", cwdOf(ctx));
|
|
34053
|
-
const text = [pending, now].filter(Boolean).join("\\n\\n");
|
|
34054
|
-
pending = "";
|
|
34055
|
-
if (!text) return;
|
|
34056
|
-
return { message: { customType: "${MESSAGES_ID}", content: text, display: true } };
|
|
34057
|
-
});
|
|
34058
|
-
pi.on("agent_end", async (_event, ctx) => {
|
|
34059
|
-
await runHook(idOf(ctx), "Stop", cwdOf(ctx));
|
|
34060
|
-
// An idle session acts on a message from another session by itself.
|
|
34061
|
-
startWaiter(idOf(ctx), cwdOf(ctx), (text) => pi.sendUserMessage(text));
|
|
34062
|
-
});
|
|
34063
|
-
pi.on("session_shutdown", async (_event, ctx) => {
|
|
34064
|
-
stopWaiter(idOf(ctx));
|
|
34065
|
-
await runHook(idOf(ctx), "SessionEnd", cwdOf(ctx));
|
|
34066
|
-
});
|
|
34635
|
+
function messageHookEntries(execPath, hookEntry) {
|
|
34636
|
+
const turn = messageHookCommand(execPath, hookEntry);
|
|
34637
|
+
const waiter = messageHookCommand(execPath, hookEntry, true);
|
|
34638
|
+
return [
|
|
34639
|
+
...MESSAGE_HOOK_EVENTS.map((event) => [event, { matcher: "", hooks: [{ type: "command", command: turn }] }]),
|
|
34640
|
+
...MESSAGE_WAITER_EVENTS.map((event) => [event, {
|
|
34641
|
+
matcher: "",
|
|
34642
|
+
hooks: [{ type: "command", command: waiter, asyncRewake: true, timeout: MESSAGE_WAITER_TIMEOUT_SECONDS }]
|
|
34643
|
+
}])
|
|
34644
|
+
];
|
|
34067
34645
|
}
|
|
34068
|
-
|
|
34646
|
+
function resolveCliEntry(distDir) {
|
|
34647
|
+
const bundled = join59(distDir, "cli.js");
|
|
34648
|
+
return existsSync52(bundled) ? bundled : join59(distDir, "cli.ts");
|
|
34069
34649
|
}
|
|
34070
|
-
|
|
34071
|
-
|
|
34072
|
-
"
|
|
34650
|
+
function resolveMessageHookEntry(distDir) {
|
|
34651
|
+
const bundled = join59(distDir, "message-hook.js");
|
|
34652
|
+
return existsSync52(bundled) ? bundled : join59(distDir, "message-hook.ts");
|
|
34653
|
+
}
|
|
34654
|
+
var BOARD_HOOKS, MESSAGE_HOOK_EVENTS, MESSAGE_WAITER_EVENTS, MESSAGE_WAITER_TIMEOUT_SECONDS;
|
|
34655
|
+
var init_board_hooks = __esm({
|
|
34656
|
+
"src/board-hooks.ts"() {
|
|
34073
34657
|
"use strict";
|
|
34074
|
-
|
|
34075
|
-
|
|
34076
|
-
|
|
34077
|
-
|
|
34078
|
-
|
|
34079
|
-
|
|
34080
|
-
|
|
34081
|
-
obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? { ...v } : {};
|
|
34082
|
-
CODEX_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop", "SessionEnd"];
|
|
34083
|
-
CURSOR_EVENTS = ["sessionStart", "beforeSubmitPrompt", "stop", "sessionEnd"];
|
|
34658
|
+
BOARD_HOOKS = [
|
|
34659
|
+
{ event: "UserPromptSubmit", mode: "claim" },
|
|
34660
|
+
{ event: "SessionEnd", mode: "close" }
|
|
34661
|
+
];
|
|
34662
|
+
MESSAGE_HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop", "SessionEnd"];
|
|
34663
|
+
MESSAGE_WAITER_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop"];
|
|
34664
|
+
MESSAGE_WAITER_TIMEOUT_SECONDS = 86400;
|
|
34084
34665
|
}
|
|
34085
34666
|
});
|
|
34086
34667
|
|
|
@@ -34098,8 +34679,8 @@ __export(install_hooks_exports, {
|
|
|
34098
34679
|
removeOurEntries: () => removeOurEntries,
|
|
34099
34680
|
uninstallHooks: () => uninstallHooks
|
|
34100
34681
|
});
|
|
34101
|
-
import { chmodSync as chmodSync5, copyFileSync as copyFileSync3, existsSync as
|
|
34102
|
-
import { dirname as dirname24, join as
|
|
34682
|
+
import { chmodSync as chmodSync5, copyFileSync as copyFileSync3, existsSync as existsSync53, mkdirSync as mkdirSync17, readFileSync as readFileSync47, realpathSync as realpathSync6, renameSync as renameSync7, rmSync as rmSync10, unlinkSync as unlinkSync4, writeFileSync as writeFileSync18 } from "node:fs";
|
|
34683
|
+
import { dirname as dirname24, join as join60 } from "node:path";
|
|
34103
34684
|
function isOurEntry(entry) {
|
|
34104
34685
|
const cmd = entry?.hooks?.[0]?.command;
|
|
34105
34686
|
if (typeof cmd !== "string") return false;
|
|
@@ -34109,8 +34690,8 @@ function claudeSettingsFiles() {
|
|
|
34109
34690
|
const out = [];
|
|
34110
34691
|
const seen = /* @__PURE__ */ new Set();
|
|
34111
34692
|
for (const home of claudeHomeDirs()) {
|
|
34112
|
-
if (!
|
|
34113
|
-
const file =
|
|
34693
|
+
if (!existsSync53(join60(home, "projects"))) continue;
|
|
34694
|
+
const file = join60(home, "settings.json");
|
|
34114
34695
|
let key2;
|
|
34115
34696
|
try {
|
|
34116
34697
|
key2 = realpathSync6(file);
|
|
@@ -34126,10 +34707,10 @@ function claudeSettingsFiles() {
|
|
|
34126
34707
|
}
|
|
34127
34708
|
function findScript(distDir, name) {
|
|
34128
34709
|
return [
|
|
34129
|
-
|
|
34130
|
-
|
|
34131
|
-
|
|
34132
|
-
].find((p) =>
|
|
34710
|
+
join60(distDir, "..", "hooks", name),
|
|
34711
|
+
join60(distDir, "..", "..", "hooks", name),
|
|
34712
|
+
join60(distDir, "..", "..", "..", "hooks", name)
|
|
34713
|
+
].find((p) => existsSync53(p));
|
|
34133
34714
|
}
|
|
34134
34715
|
function hookEntries(sel, paths) {
|
|
34135
34716
|
const cmd = (command, extra = {}) => [{ type: "command", command, ...extra }];
|
|
@@ -34173,9 +34754,9 @@ function removeOurEntries(config2) {
|
|
|
34173
34754
|
return removed;
|
|
34174
34755
|
}
|
|
34175
34756
|
function readJson4(file) {
|
|
34176
|
-
if (!
|
|
34757
|
+
if (!existsSync53(file)) return {};
|
|
34177
34758
|
try {
|
|
34178
|
-
const v = JSON.parse(
|
|
34759
|
+
const v = JSON.parse(readFileSync47(file, "utf-8"));
|
|
34179
34760
|
return v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
34180
34761
|
} catch {
|
|
34181
34762
|
return null;
|
|
@@ -34189,15 +34770,15 @@ function writeJsonAtomic(file, value) {
|
|
|
34189
34770
|
}
|
|
34190
34771
|
mkdirSync17(dirname24(target), { recursive: true });
|
|
34191
34772
|
const tmp = `${target}.chat-recall-${process.pid}.tmp`;
|
|
34192
|
-
|
|
34193
|
-
|
|
34773
|
+
writeFileSync18(tmp, JSON.stringify(value, null, 2) + "\n");
|
|
34774
|
+
renameSync7(tmp, target);
|
|
34194
34775
|
}
|
|
34195
34776
|
function statePath() {
|
|
34196
|
-
return
|
|
34777
|
+
return join60(getHooksDir(), "install.json");
|
|
34197
34778
|
}
|
|
34198
34779
|
function readState() {
|
|
34199
34780
|
try {
|
|
34200
|
-
return JSON.parse(
|
|
34781
|
+
return JSON.parse(readFileSync47(statePath(), "utf-8"));
|
|
34201
34782
|
} catch {
|
|
34202
34783
|
return null;
|
|
34203
34784
|
}
|
|
@@ -34211,7 +34792,7 @@ async function installHooks(distDir, sel = ALL_HOOKS) {
|
|
|
34211
34792
|
if (!sel[key2]) continue;
|
|
34212
34793
|
const source = findScript(distDir, SCRIPTS[key2]);
|
|
34213
34794
|
if (!source) continue;
|
|
34214
|
-
const target =
|
|
34795
|
+
const target = join60(scriptsDir, SCRIPTS[key2]);
|
|
34215
34796
|
copyFileSync3(source, target);
|
|
34216
34797
|
chmodSync5(target, 493);
|
|
34217
34798
|
scripts[key2] = target;
|
|
@@ -34242,17 +34823,18 @@ async function installHooks(distDir, sel = ALL_HOOKS) {
|
|
|
34242
34823
|
mergeOurEntries(config2, entries);
|
|
34243
34824
|
writeJsonAtomic(settingsFile, config2);
|
|
34244
34825
|
report.written.push(settingsFile);
|
|
34245
|
-
report.migrated += migrateHooksJson(
|
|
34826
|
+
report.migrated += migrateHooksJson(join60(dirname24(settingsFile), "hooks.json"));
|
|
34246
34827
|
}
|
|
34247
34828
|
if (sel.guard && scripts.guard) report.guardTargets = await addGuardToOtherTools(scriptsDir, scripts.guard);
|
|
34248
34829
|
if (sel.messages && !shellSkipped) {
|
|
34249
34830
|
report.messageTargets = await addMessagesToOtherTools(scriptsDir, process.execPath, resolveMessageHookEntry(distDir));
|
|
34250
34831
|
}
|
|
34832
|
+
if (!sel.messages) unregisterTuiPlugin();
|
|
34251
34833
|
writeJsonAtomic(statePath(), { version: cliVersion(), selection: sel });
|
|
34252
34834
|
return report;
|
|
34253
34835
|
}
|
|
34254
34836
|
function migrateHooksJson(file) {
|
|
34255
|
-
if (!
|
|
34837
|
+
if (!existsSync53(file)) return 0;
|
|
34256
34838
|
const config2 = readJson4(file);
|
|
34257
34839
|
if (!config2) return 0;
|
|
34258
34840
|
const removed = removeOurEntries(config2);
|
|
@@ -34264,8 +34846,8 @@ function migrateHooksJson(file) {
|
|
|
34264
34846
|
async function uninstallHooks() {
|
|
34265
34847
|
const report = { removed: 0, files: [], guardRemoved: [], messagesRemoved: [] };
|
|
34266
34848
|
for (const settingsFile of claudeSettingsFiles()) {
|
|
34267
|
-
for (const file of [settingsFile,
|
|
34268
|
-
if (!
|
|
34849
|
+
for (const file of [settingsFile, join60(dirname24(settingsFile), "hooks.json")]) {
|
|
34850
|
+
if (!existsSync53(file)) continue;
|
|
34269
34851
|
const config2 = readJson4(file);
|
|
34270
34852
|
if (!config2) continue;
|
|
34271
34853
|
const removed = removeOurEntries(config2);
|
|
@@ -34302,13 +34884,13 @@ async function addGuardToOtherTools(scriptsDir, guardScript) {
|
|
|
34302
34884
|
const out = [];
|
|
34303
34885
|
removeLegacyAgyGuard(reg);
|
|
34304
34886
|
for (const target of reg.guardTargets()) {
|
|
34305
|
-
if (!
|
|
34306
|
-
const wrapper =
|
|
34307
|
-
|
|
34887
|
+
if (!existsSync53(target.homeDir)) continue;
|
|
34888
|
+
const wrapper = join60(scriptsDir, reg.guardWrapperName(target.tool));
|
|
34889
|
+
writeFileSync18(wrapper, reg.guardWrapperSource(target.tool, guardScript));
|
|
34308
34890
|
chmodSync5(wrapper, 493);
|
|
34309
34891
|
mkdirSync17(dirname24(target.configPath), { recursive: true });
|
|
34310
34892
|
if (target.tool === "opencode") {
|
|
34311
|
-
|
|
34893
|
+
writeFileSync18(target.configPath, reg.opencodePluginSource(wrapper));
|
|
34312
34894
|
} else {
|
|
34313
34895
|
const merged = reg.registerGuard(target.tool, readJson4(target.configPath) ?? {}, reg.guardCommand(wrapper));
|
|
34314
34896
|
writeJsonAtomic(target.configPath, merged);
|
|
@@ -34322,9 +34904,9 @@ async function removeGuardFromOtherTools() {
|
|
|
34322
34904
|
const out = [];
|
|
34323
34905
|
removeLegacyAgyGuard(reg);
|
|
34324
34906
|
for (const target of reg.guardTargets()) {
|
|
34325
|
-
if (!
|
|
34907
|
+
if (!existsSync53(target.configPath)) continue;
|
|
34326
34908
|
if (target.tool === "opencode") {
|
|
34327
|
-
if (!
|
|
34909
|
+
if (!readFileSync47(target.configPath, "utf-8").includes("chat-recall install-hooks")) continue;
|
|
34328
34910
|
unlinkSync4(target.configPath);
|
|
34329
34911
|
} else {
|
|
34330
34912
|
const r = reg.unregisterGuard(target.tool, readJson4(target.configPath) ?? {});
|
|
@@ -34337,7 +34919,7 @@ async function removeGuardFromOtherTools() {
|
|
|
34337
34919
|
}
|
|
34338
34920
|
function removeLegacyAgyGuard(reg) {
|
|
34339
34921
|
const file = reg.legacyAgyHooksFile();
|
|
34340
|
-
if (!
|
|
34922
|
+
if (!existsSync53(file)) return;
|
|
34341
34923
|
const r = reg.unregisterGuard("agy", readJson4(file) ?? {});
|
|
34342
34924
|
if (r.removed) writeJsonAtomic(file, r.config);
|
|
34343
34925
|
}
|
|
@@ -34345,15 +34927,26 @@ async function addMessagesToOtherTools(scriptsDir, nodePath, hookEntry) {
|
|
|
34345
34927
|
const reg = await Promise.resolve().then(() => (init_message_registration(), message_registration_exports));
|
|
34346
34928
|
const out = [];
|
|
34347
34929
|
for (const target of reg.messageTargets()) {
|
|
34348
|
-
if (!
|
|
34349
|
-
const wrapper =
|
|
34350
|
-
|
|
34930
|
+
if (!existsSync53(target.homeDir)) continue;
|
|
34931
|
+
const wrapper = join60(scriptsDir, reg.messageWrapperName(target.tool));
|
|
34932
|
+
writeFileSync18(wrapper, reg.messageWrapperSource(target.tool, nodePath, hookEntry));
|
|
34351
34933
|
chmodSync5(wrapper, 493);
|
|
34352
34934
|
mkdirSync17(dirname24(target.configPath), { recursive: true });
|
|
34353
34935
|
if (target.tool === "opencode") {
|
|
34354
|
-
|
|
34936
|
+
writeFileSync18(target.configPath, reg.opencodeMessagesSource(wrapper));
|
|
34937
|
+
const dir = join60(dirname24(target.configPath), reg.OPENCODE_TUI_PACKAGE);
|
|
34938
|
+
mkdirSync17(dir, { recursive: true });
|
|
34939
|
+
for (const file of reg.opencodeTuiFiles(wrapper)) writeFileSync18(join60(dir, file.name), file.source);
|
|
34940
|
+
const tui = registerTuiPlugin();
|
|
34941
|
+
if (tui.status === "unparseable") {
|
|
34942
|
+
out.push({
|
|
34943
|
+
label: "OpenCode TUI",
|
|
34944
|
+
configPath: tui.path,
|
|
34945
|
+
note: `Not added: ${tui.reason}. Add "${tuiPluginEntry()}" to its plugin list by hand.`
|
|
34946
|
+
});
|
|
34947
|
+
}
|
|
34355
34948
|
} else if (target.tool === "pi") {
|
|
34356
|
-
|
|
34949
|
+
writeFileSync18(target.configPath, reg.piMessagesSource(wrapper));
|
|
34357
34950
|
} else {
|
|
34358
34951
|
const config2 = readJson4(target.configPath);
|
|
34359
34952
|
if (!config2) continue;
|
|
@@ -34366,11 +34959,18 @@ async function addMessagesToOtherTools(scriptsDir, nodePath, hookEntry) {
|
|
|
34366
34959
|
async function removeMessagesFromOtherTools() {
|
|
34367
34960
|
const reg = await Promise.resolve().then(() => (init_message_registration(), message_registration_exports));
|
|
34368
34961
|
const out = [];
|
|
34962
|
+
const tui = unregisterTuiPlugin();
|
|
34963
|
+
if (tui.removed) out.push({ label: "OpenCode TUI", configPath: tui.path });
|
|
34369
34964
|
for (const target of reg.messageTargets()) {
|
|
34370
|
-
if (!
|
|
34965
|
+
if (!existsSync53(target.configPath)) continue;
|
|
34371
34966
|
if (target.tool === "opencode" || target.tool === "pi") {
|
|
34372
|
-
if (!reg.isOurPluginSource(
|
|
34967
|
+
if (!reg.isOurPluginSource(readFileSync47(target.configPath, "utf-8"))) continue;
|
|
34373
34968
|
unlinkSync4(target.configPath);
|
|
34969
|
+
if (target.tool === "opencode") {
|
|
34970
|
+
const dir = join60(dirname24(target.configPath), reg.OPENCODE_TUI_PACKAGE);
|
|
34971
|
+
const tui2 = join60(dir, "tui.js");
|
|
34972
|
+
if (existsSync53(tui2) && reg.isOurTuiSource(readFileSync47(tui2, "utf-8"))) rmSync10(dir, { recursive: true, force: true });
|
|
34973
|
+
}
|
|
34374
34974
|
} else {
|
|
34375
34975
|
const config2 = readJson4(target.configPath);
|
|
34376
34976
|
if (!config2) continue;
|
|
@@ -34391,6 +34991,7 @@ var init_install_hooks = __esm({
|
|
|
34391
34991
|
init_tool_paths();
|
|
34392
34992
|
init_board_hooks();
|
|
34393
34993
|
init_http();
|
|
34994
|
+
init_opencode_tui_config();
|
|
34394
34995
|
ALL_HOOKS = {
|
|
34395
34996
|
save: true,
|
|
34396
34997
|
resume: true,
|
|
@@ -34854,11 +35455,11 @@ var verify_repair_exports = {};
|
|
|
34854
35455
|
__export(verify_repair_exports, {
|
|
34855
35456
|
forceFullResync: () => forceFullResync
|
|
34856
35457
|
});
|
|
34857
|
-
import { copyFileSync as copyFileSync4, existsSync as
|
|
35458
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync54 } from "fs";
|
|
34858
35459
|
function forceFullResync(server, sessionIds) {
|
|
34859
35460
|
if (sessionIds.length === 0) return 0;
|
|
34860
35461
|
const path = ledgerFilePath();
|
|
34861
|
-
if (
|
|
35462
|
+
if (existsSync54(path)) {
|
|
34862
35463
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace(/-/g, "");
|
|
34863
35464
|
try {
|
|
34864
35465
|
copyFileSync4(path, `${path}.bak-${stamp}`);
|
|
@@ -35048,8 +35649,8 @@ __export(collector_exports, {
|
|
|
35048
35649
|
});
|
|
35049
35650
|
import { spawn as spawn3 } from "node:child_process";
|
|
35050
35651
|
import { execSync as execSync4 } from "node:child_process";
|
|
35051
|
-
import { readFileSync as
|
|
35052
|
-
import { join as
|
|
35652
|
+
import { readFileSync as readFileSync48 } from "node:fs";
|
|
35653
|
+
import { join as join61, basename as basename28 } from "node:path";
|
|
35053
35654
|
async function resolveCodeindexBin(autoInstall = true) {
|
|
35054
35655
|
let st = checkCodeindexStatus();
|
|
35055
35656
|
if (!st.installed && autoInstall)
|
|
@@ -35231,7 +35832,7 @@ async function collectCode(opts) {
|
|
|
35231
35832
|
}
|
|
35232
35833
|
const complexity = (r) => {
|
|
35233
35834
|
try {
|
|
35234
|
-
const txt =
|
|
35835
|
+
const txt = readFileSync48(join61(ws, r), "utf8");
|
|
35235
35836
|
if (txt.length > 2e6)
|
|
35236
35837
|
return 1;
|
|
35237
35838
|
const m = txt.match(CF_RE);
|
|
@@ -36015,8 +36616,8 @@ __export(project_tasks_exports, {
|
|
|
36015
36616
|
pushProjectTaskStatuses: () => pushProjectTaskStatuses,
|
|
36016
36617
|
renderTeamTasksMd: () => renderTeamTasksMd
|
|
36017
36618
|
});
|
|
36018
|
-
import { existsSync as
|
|
36019
|
-
import { join as
|
|
36619
|
+
import { existsSync as existsSync55, readFileSync as readFileSync49, writeFileSync as writeFileSync19, mkdirSync as mkdirSync18, statSync as statSync46 } from "node:fs";
|
|
36620
|
+
import { join as join62, dirname as dirname25 } from "node:path";
|
|
36020
36621
|
import { homedir as homedir23 } from "node:os";
|
|
36021
36622
|
function isTeamTaskStatus(v) {
|
|
36022
36623
|
return !!v && TEAM_STATUSES.has(v);
|
|
@@ -36067,11 +36668,11 @@ function parseTaskFile(content) {
|
|
|
36067
36668
|
return out;
|
|
36068
36669
|
}
|
|
36069
36670
|
function ledgerPath2() {
|
|
36070
|
-
return
|
|
36671
|
+
return join62(homedir23(), ".chat-recall", "project-tasks-ledger.json");
|
|
36071
36672
|
}
|
|
36072
36673
|
function readLedger() {
|
|
36073
36674
|
try {
|
|
36074
|
-
return JSON.parse(
|
|
36675
|
+
return JSON.parse(readFileSync49(ledgerPath2(), "utf8"));
|
|
36075
36676
|
} catch {
|
|
36076
36677
|
return {};
|
|
36077
36678
|
}
|
|
@@ -36082,7 +36683,7 @@ function writeLedger(l) {
|
|
|
36082
36683
|
} catch {
|
|
36083
36684
|
}
|
|
36084
36685
|
try {
|
|
36085
|
-
|
|
36686
|
+
writeFileSync19(ledgerPath2(), JSON.stringify(l));
|
|
36086
36687
|
} catch {
|
|
36087
36688
|
}
|
|
36088
36689
|
}
|
|
@@ -36100,8 +36701,8 @@ async function pushProjectTaskStatuses(base4, authHeaders, opts = {}) {
|
|
|
36100
36701
|
continue;
|
|
36101
36702
|
}
|
|
36102
36703
|
for (const project of projects) {
|
|
36103
|
-
const file =
|
|
36104
|
-
if (!
|
|
36704
|
+
const file = join62(project, fk.filename);
|
|
36705
|
+
if (!existsSync55(file)) continue;
|
|
36105
36706
|
let mtime;
|
|
36106
36707
|
try {
|
|
36107
36708
|
mtime = statSync46(file).mtimeMs;
|
|
@@ -36111,7 +36712,7 @@ async function pushProjectTaskStatuses(base4, authHeaders, opts = {}) {
|
|
|
36111
36712
|
if (ledger[file] === mtime) continue;
|
|
36112
36713
|
let changed;
|
|
36113
36714
|
try {
|
|
36114
|
-
changed = parseTaskFile(
|
|
36715
|
+
changed = parseTaskFile(readFileSync49(file, "utf8")).filter((t) => t.kind === fk.kind);
|
|
36115
36716
|
} catch {
|
|
36116
36717
|
continue;
|
|
36117
36718
|
}
|
|
@@ -36184,8 +36785,8 @@ __export(intent_drain_exports, {
|
|
|
36184
36785
|
instructionTargets: () => instructionTargets,
|
|
36185
36786
|
runIntent: () => runIntent
|
|
36186
36787
|
});
|
|
36187
|
-
import { existsSync as
|
|
36188
|
-
import { join as
|
|
36788
|
+
import { existsSync as existsSync56, readFileSync as readFileSync50, writeFileSync as writeFileSync20, appendFileSync, mkdirSync as mkdirSync19 } from "node:fs";
|
|
36789
|
+
import { join as join63 } from "node:path";
|
|
36189
36790
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
36190
36791
|
import { dirname as dirname26 } from "node:path";
|
|
36191
36792
|
function instructionTargets(rootPath, isGlobal) {
|
|
@@ -36199,17 +36800,17 @@ function instructionTargets(rootPath, isGlobal) {
|
|
|
36199
36800
|
const tools = installed.length ? installed : [INSTRUCTION_TOOLS[0]];
|
|
36200
36801
|
if (isGlobal) return [...new Set(tools.map((t) => instructionsPath(t.id)))];
|
|
36201
36802
|
if (!rootPath) return [];
|
|
36202
|
-
const present = INSTRUCTION_FILENAMES.map((f) =>
|
|
36803
|
+
const present = INSTRUCTION_FILENAMES.map((f) => join63(rootPath, f)).filter((p) => existsSync56(p));
|
|
36203
36804
|
if (present.length) return present;
|
|
36204
|
-
return [...new Set(tools.map((t) =>
|
|
36805
|
+
return [...new Set(tools.map((t) => join63(rootPath, instructionsFilename(t.id))))];
|
|
36205
36806
|
}
|
|
36206
36807
|
function applyCodeRecommendation(intent) {
|
|
36207
36808
|
try {
|
|
36208
36809
|
const meta = JSON.parse(intent.name || "{}");
|
|
36209
36810
|
if (intent.artifact_type === "write_tasks_file") {
|
|
36210
36811
|
if (!meta.rootPath || !meta.content) return { status: "error", result: JSON.stringify({ error: "missing rootPath or content" }) };
|
|
36211
|
-
const file =
|
|
36212
|
-
|
|
36812
|
+
const file = join63(meta.rootPath, meta.filename || "CODE_TASKS.md");
|
|
36813
|
+
writeFileSync20(file, meta.content);
|
|
36213
36814
|
return { status: "done", result: JSON.stringify({ wrote: file }) };
|
|
36214
36815
|
}
|
|
36215
36816
|
if (intent.artifact_type === "append_claude_md") {
|
|
@@ -36227,7 +36828,7 @@ function applyCodeRecommendation(intent) {
|
|
|
36227
36828
|
mkdirSync19(dir, { recursive: true });
|
|
36228
36829
|
} catch {
|
|
36229
36830
|
}
|
|
36230
|
-
const existing =
|
|
36831
|
+
const existing = existsSync56(file) ? readFileSync50(file, "utf8") : "";
|
|
36231
36832
|
if (existing.includes(text)) {
|
|
36232
36833
|
skipped.push(file);
|
|
36233
36834
|
continue;
|
|
@@ -36237,7 +36838,7 @@ function applyCodeRecommendation(intent) {
|
|
|
36237
36838
|
${text}
|
|
36238
36839
|
`;
|
|
36239
36840
|
if (existing) appendFileSync(file, block);
|
|
36240
|
-
else
|
|
36841
|
+
else writeFileSync20(file, `# ${meta.rootPath?.split("/").pop() || "Global"} instructions
|
|
36241
36842
|
${block}`);
|
|
36242
36843
|
appended.push(file);
|
|
36243
36844
|
}
|
|
@@ -36413,10 +37014,10 @@ var init_intent_drain = __esm({
|
|
|
36413
37014
|
ownVersion2 = "0.0.0";
|
|
36414
37015
|
try {
|
|
36415
37016
|
const dir = dirname26(fileURLToPath4(import.meta.url));
|
|
36416
|
-
ownVersion2 = JSON.parse(
|
|
37017
|
+
ownVersion2 = JSON.parse(readFileSync50(join63(dir, "../package.json"), "utf-8")).version || ownVersion2;
|
|
36417
37018
|
} catch {
|
|
36418
37019
|
try {
|
|
36419
|
-
if (true) ownVersion2 = "0.7.
|
|
37020
|
+
if (true) ownVersion2 = "0.7.30";
|
|
36420
37021
|
} catch {
|
|
36421
37022
|
}
|
|
36422
37023
|
}
|
|
@@ -36617,48 +37218,48 @@ var team_merge_exports = {};
|
|
|
36617
37218
|
__export(team_merge_exports, {
|
|
36618
37219
|
mergePullResult: () => mergePullResult
|
|
36619
37220
|
});
|
|
36620
|
-
import { existsSync as
|
|
36621
|
-
import { dirname as dirname27, join as
|
|
37221
|
+
import { existsSync as existsSync57, mkdirSync as mkdirSync20, readFileSync as readFileSync51, rmSync as rmSync11, writeFileSync as writeFileSync21, statSync as statSync47 } from "fs";
|
|
37222
|
+
import { dirname as dirname27, join as join64 } from "path";
|
|
36622
37223
|
import { createHash as createHash15 } from "crypto";
|
|
36623
37224
|
function installPathFor(art, tool) {
|
|
36624
37225
|
switch (art.type) {
|
|
36625
37226
|
case "skill":
|
|
36626
37227
|
switch (tool) {
|
|
36627
37228
|
case "claude":
|
|
36628
|
-
return
|
|
37229
|
+
return join64(claudeBackend.skillsDir(), art.name, "SKILL.md");
|
|
36629
37230
|
// Antigravity's OWN skills dir. It used to resolve to the shared
|
|
36630
37231
|
// ~/.gemini/skills while toolkit-sync installed to
|
|
36631
37232
|
// ~/.gemini/antigravity-cli/skills, so a team skill landed in one place
|
|
36632
37233
|
// and a synced skill in the other.
|
|
36633
37234
|
case "agy":
|
|
36634
|
-
return
|
|
37235
|
+
return join64(agyBackend.homeDir(), "skills", art.name, "SKILL.md");
|
|
36635
37236
|
case "opencode":
|
|
36636
|
-
return
|
|
37237
|
+
return join64(opencodeBackend.skillsDir(), art.name, "SKILL.md");
|
|
36637
37238
|
// User skills go to ~/.codex/skills (NOT .system, which is OpenAI's bundle).
|
|
36638
37239
|
case "codex":
|
|
36639
|
-
return
|
|
37240
|
+
return join64(codexBackend.skillsDir(), art.name, "SKILL.md");
|
|
36640
37241
|
case "cursor":
|
|
36641
|
-
return
|
|
37242
|
+
return join64(cursorHomeDir(), "skills", art.name, "SKILL.md");
|
|
36642
37243
|
}
|
|
36643
37244
|
break;
|
|
36644
37245
|
case "agent":
|
|
36645
37246
|
if (tool === "claude")
|
|
36646
|
-
return
|
|
37247
|
+
return join64(claudeBackend.agentsDir(), `${art.name}.md`);
|
|
36647
37248
|
return null;
|
|
36648
37249
|
case "command":
|
|
36649
37250
|
if (tool === "claude")
|
|
36650
|
-
return
|
|
37251
|
+
return join64(claudeBackend.commandsDir(), `${art.name}.md`);
|
|
36651
37252
|
return null;
|
|
36652
37253
|
case "hook":
|
|
36653
37254
|
if (tool === "claude")
|
|
36654
|
-
return
|
|
37255
|
+
return join64(claudeBackend.homeDir(), "chat-recall-hooks", `${art.name}.json`);
|
|
36655
37256
|
return null;
|
|
36656
37257
|
case "plan":
|
|
36657
37258
|
switch (tool) {
|
|
36658
37259
|
case "claude":
|
|
36659
|
-
return
|
|
37260
|
+
return join64(claudeBackend.plansDir(), `${art.name}.md`);
|
|
36660
37261
|
case "opencode":
|
|
36661
|
-
return
|
|
37262
|
+
return join64(opencodeBackend.plansDir(), `${art.name}.md`);
|
|
36662
37263
|
case "agy":
|
|
36663
37264
|
return null;
|
|
36664
37265
|
// Antigravity plans live per-session
|
|
@@ -36669,11 +37270,11 @@ function installPathFor(art, tool) {
|
|
|
36669
37270
|
}
|
|
36670
37271
|
break;
|
|
36671
37272
|
case "instructions":
|
|
36672
|
-
return
|
|
37273
|
+
return join64(getDataDir(), "team-instructions", tool, `${art.name}.md`);
|
|
36673
37274
|
case "mcp":
|
|
36674
|
-
return
|
|
37275
|
+
return join64(getDataDir(), "team-mcps", `${art.name}.json`);
|
|
36675
37276
|
case "plugin":
|
|
36676
|
-
return
|
|
37277
|
+
return join64(getDataDir(), "team-plugins", tool, art.name, "manifest.json");
|
|
36677
37278
|
}
|
|
36678
37279
|
return null;
|
|
36679
37280
|
}
|
|
@@ -36713,7 +37314,7 @@ async function mergePullResult(opts) {
|
|
|
36713
37314
|
continue;
|
|
36714
37315
|
}
|
|
36715
37316
|
mkdirSync20(dirname27(path), { recursive: true });
|
|
36716
|
-
|
|
37317
|
+
writeFileSync21(path, body2);
|
|
36717
37318
|
pending.push({ artifactId: a.id, tool, artifactType: a.type, artifactName: a.name, sha256: sha, installedAt: Date.now() });
|
|
36718
37319
|
report.written.push({ artifactId: a.id, path });
|
|
36719
37320
|
} catch (err) {
|
|
@@ -36734,8 +37335,8 @@ async function mergePullResult(opts) {
|
|
|
36734
37335
|
if (!path)
|
|
36735
37336
|
continue;
|
|
36736
37337
|
try {
|
|
36737
|
-
if (
|
|
36738
|
-
|
|
37338
|
+
if (existsSync57(path))
|
|
37339
|
+
rmSync11(path, { force: true });
|
|
36739
37340
|
await teamInstallsForget(id, row.tool);
|
|
36740
37341
|
report.removed.push({ artifactId: id, path });
|
|
36741
37342
|
} catch (err) {
|
|
@@ -36752,12 +37353,12 @@ async function mergePullResult(opts) {
|
|
|
36752
37353
|
}
|
|
36753
37354
|
function readFileIfExists(path) {
|
|
36754
37355
|
try {
|
|
36755
|
-
if (!
|
|
37356
|
+
if (!existsSync57(path))
|
|
36756
37357
|
return null;
|
|
36757
37358
|
const s = statSync47(path);
|
|
36758
37359
|
if (!s.isFile())
|
|
36759
37360
|
return null;
|
|
36760
|
-
return
|
|
37361
|
+
return readFileSync51(path);
|
|
36761
37362
|
} catch {
|
|
36762
37363
|
return null;
|
|
36763
37364
|
}
|
|
@@ -36838,8 +37439,8 @@ var init_vault_crypto = __esm({
|
|
|
36838
37439
|
});
|
|
36839
37440
|
|
|
36840
37441
|
// ../engine/dist/core/vault-source.js
|
|
36841
|
-
import { existsSync as
|
|
36842
|
-
import { extname, join as
|
|
37442
|
+
import { existsSync as existsSync58, readdirSync as readdirSync35, statSync as statSync48 } from "fs";
|
|
37443
|
+
import { extname, join as join65 } from "path";
|
|
36843
37444
|
function* walkVaultSources() {
|
|
36844
37445
|
const t = loadSettings().team.vault;
|
|
36845
37446
|
const include2 = new Set(t.syncTools);
|
|
@@ -36864,7 +37465,7 @@ function safeStat(path) {
|
|
|
36864
37465
|
}
|
|
36865
37466
|
function* walkClaude() {
|
|
36866
37467
|
const root = claudeBackend.projectsDir();
|
|
36867
|
-
if (!
|
|
37468
|
+
if (!existsSync58(root))
|
|
36868
37469
|
return;
|
|
36869
37470
|
let projectDirs = [];
|
|
36870
37471
|
try {
|
|
@@ -36876,7 +37477,7 @@ function* walkClaude() {
|
|
|
36876
37477
|
if (proj.startsWith("."))
|
|
36877
37478
|
continue;
|
|
36878
37479
|
const projectPath = resolveProjectDirName(proj);
|
|
36879
|
-
const projDir =
|
|
37480
|
+
const projDir = join65(root, proj);
|
|
36880
37481
|
let entries = [];
|
|
36881
37482
|
try {
|
|
36882
37483
|
entries = readdirSync35(projDir);
|
|
@@ -36886,7 +37487,7 @@ function* walkClaude() {
|
|
|
36886
37487
|
for (const f of entries) {
|
|
36887
37488
|
if (extname(f) !== ".jsonl")
|
|
36888
37489
|
continue;
|
|
36889
|
-
const path =
|
|
37490
|
+
const path = join65(projDir, f);
|
|
36890
37491
|
const s = safeStat(path);
|
|
36891
37492
|
if (!s)
|
|
36892
37493
|
continue;
|
|
@@ -36916,8 +37517,8 @@ function* walkCursor() {
|
|
|
36916
37517
|
}
|
|
36917
37518
|
}
|
|
36918
37519
|
function* walkCodex() {
|
|
36919
|
-
const sessionsRoot =
|
|
36920
|
-
if (!
|
|
37520
|
+
const sessionsRoot = join65(codexBackend.homeDir(), "sessions");
|
|
37521
|
+
if (!existsSync58(sessionsRoot))
|
|
36921
37522
|
return;
|
|
36922
37523
|
const stack = [sessionsRoot];
|
|
36923
37524
|
while (stack.length) {
|
|
@@ -36929,7 +37530,7 @@ function* walkCodex() {
|
|
|
36929
37530
|
continue;
|
|
36930
37531
|
}
|
|
36931
37532
|
for (const e of entries) {
|
|
36932
|
-
const path =
|
|
37533
|
+
const path = join65(dir, e.name);
|
|
36933
37534
|
if (e.isDirectory()) {
|
|
36934
37535
|
stack.push(path);
|
|
36935
37536
|
continue;
|
|
@@ -36945,8 +37546,8 @@ function* walkCodex() {
|
|
|
36945
37546
|
}
|
|
36946
37547
|
}
|
|
36947
37548
|
function* walkAgy() {
|
|
36948
|
-
const brainDir =
|
|
36949
|
-
if (!
|
|
37549
|
+
const brainDir = join65(agyBackend.homeDir(), "brain");
|
|
37550
|
+
if (!existsSync58(brainDir))
|
|
36950
37551
|
return;
|
|
36951
37552
|
let sessionDirs = [];
|
|
36952
37553
|
try {
|
|
@@ -36955,18 +37556,18 @@ function* walkAgy() {
|
|
|
36955
37556
|
return;
|
|
36956
37557
|
}
|
|
36957
37558
|
for (const rawId of sessionDirs) {
|
|
36958
|
-
const sessionPath =
|
|
37559
|
+
const sessionPath = join65(brainDir, rawId);
|
|
36959
37560
|
try {
|
|
36960
37561
|
if (!statSync48(sessionPath).isDirectory())
|
|
36961
37562
|
continue;
|
|
36962
37563
|
} catch {
|
|
36963
37564
|
continue;
|
|
36964
37565
|
}
|
|
36965
|
-
let filePath =
|
|
36966
|
-
if (!
|
|
36967
|
-
filePath =
|
|
37566
|
+
let filePath = join65(sessionPath, ".system_generated", "logs", "transcript.jsonl");
|
|
37567
|
+
if (!existsSync58(filePath)) {
|
|
37568
|
+
filePath = join65(sessionPath, ".system_generated", "logs", "transcript_full.jsonl");
|
|
36968
37569
|
}
|
|
36969
|
-
if (!
|
|
37570
|
+
if (!existsSync58(filePath))
|
|
36970
37571
|
continue;
|
|
36971
37572
|
const s = safeStat(filePath);
|
|
36972
37573
|
if (!s)
|
|
@@ -37002,8 +37603,8 @@ __export(vault_client_exports, {
|
|
|
37002
37603
|
vaultStatus: () => vaultStatus,
|
|
37003
37604
|
vaultSync: () => vaultSync
|
|
37004
37605
|
});
|
|
37005
|
-
import { mkdirSync as mkdirSync21, readFileSync as
|
|
37006
|
-
import { dirname as dirname28, join as
|
|
37606
|
+
import { mkdirSync as mkdirSync21, readFileSync as readFileSync52, writeFileSync as writeFileSync22, existsSync as existsSync59 } from "fs";
|
|
37607
|
+
import { dirname as dirname28, join as join66 } from "path";
|
|
37007
37608
|
function context2() {
|
|
37008
37609
|
const s = loadSettings().team;
|
|
37009
37610
|
if (!s.enabled)
|
|
@@ -37142,7 +37743,7 @@ async function vaultSync(passphrase) {
|
|
|
37142
37743
|
continue;
|
|
37143
37744
|
}
|
|
37144
37745
|
try {
|
|
37145
|
-
const plaintext =
|
|
37746
|
+
const plaintext = readFileSync52(src.path);
|
|
37146
37747
|
const sourceSha = sha256Hex(plaintext);
|
|
37147
37748
|
const priorSha = uploaded.get(uploadKey(src.sessionId, src.tool));
|
|
37148
37749
|
if (priorSha === sourceSha) {
|
|
@@ -37194,7 +37795,7 @@ async function vaultSync(passphrase) {
|
|
|
37194
37795
|
}
|
|
37195
37796
|
function importedPathFor(tool, sessionId) {
|
|
37196
37797
|
const base4 = sessionId.replace(/^gemini_/, "").replace(/^codex_/, "").replace(/^agy_/, "").replace(/^cursor_/, "").replace(/^opencode_/, "");
|
|
37197
|
-
return
|
|
37798
|
+
return join66(IMPORTED_ROOT(), tool, `${base4}.jsonl`);
|
|
37198
37799
|
}
|
|
37199
37800
|
async function vaultRestore(passphrase, opts = {}) {
|
|
37200
37801
|
const ctx = context2();
|
|
@@ -37215,7 +37816,7 @@ async function vaultRestore(passphrase, opts = {}) {
|
|
|
37215
37816
|
}
|
|
37216
37817
|
try {
|
|
37217
37818
|
const path = importedPathFor(blob.tool, blob.sessionId);
|
|
37218
|
-
if (
|
|
37819
|
+
if (existsSync59(path)) {
|
|
37219
37820
|
const localStat = await import("fs").then((m) => m.statSync(path));
|
|
37220
37821
|
if (Math.abs(localStat.mtimeMs - blob.mtimeSourceMs) < 1) {
|
|
37221
37822
|
report.skipped.push({ sessionId: blob.sessionId, tool: blob.tool, reason: "unchanged" });
|
|
@@ -37232,7 +37833,7 @@ async function vaultRestore(passphrase, opts = {}) {
|
|
|
37232
37833
|
}
|
|
37233
37834
|
const plaintext = decryptBlob(key2, cipher);
|
|
37234
37835
|
mkdirSync21(dirname28(path), { recursive: true });
|
|
37235
|
-
|
|
37836
|
+
writeFileSync22(path, Buffer.from(plaintext));
|
|
37236
37837
|
const { utimesSync } = await import("fs");
|
|
37237
37838
|
const t = blob.mtimeSourceMs / 1e3;
|
|
37238
37839
|
utimesSync(path, t, t);
|
|
@@ -37283,7 +37884,7 @@ var init_vault_client = __esm({
|
|
|
37283
37884
|
uploadKey = (sessionId, tool) => `${sessionId}\0${tool}`;
|
|
37284
37885
|
VaultPassphraseMismatchError = class extends Error {
|
|
37285
37886
|
};
|
|
37286
|
-
IMPORTED_ROOT = () =>
|
|
37887
|
+
IMPORTED_ROOT = () => join66(getDataDir(), "imported");
|
|
37287
37888
|
}
|
|
37288
37889
|
});
|
|
37289
37890
|
|
|
@@ -37764,13 +38365,13 @@ function parseCommitLog(raw) {
|
|
|
37764
38365
|
return [];
|
|
37765
38366
|
const out = [];
|
|
37766
38367
|
for (const record3 of raw.split("")) {
|
|
37767
|
-
const
|
|
37768
|
-
if (
|
|
38368
|
+
const sep5 = record3.indexOf("");
|
|
38369
|
+
if (sep5 < 0)
|
|
37769
38370
|
continue;
|
|
37770
|
-
const sha = record3.slice(0,
|
|
38371
|
+
const sha = record3.slice(0, sep5).trim();
|
|
37771
38372
|
if (!/^[0-9a-f]{7,40}$/i.test(sha))
|
|
37772
38373
|
continue;
|
|
37773
|
-
out.push({ sha, message: record3.slice(
|
|
38374
|
+
out.push({ sha, message: record3.slice(sep5 + 1) });
|
|
37774
38375
|
}
|
|
37775
38376
|
return out;
|
|
37776
38377
|
}
|
|
@@ -37845,15 +38446,15 @@ __export(service_installer_exports, {
|
|
|
37845
38446
|
uninstallService: () => uninstallService
|
|
37846
38447
|
});
|
|
37847
38448
|
import { execSync as execSync5 } from "child_process";
|
|
37848
|
-
import { existsSync as
|
|
38449
|
+
import { existsSync as existsSync60, mkdirSync as mkdirSync22, readFileSync as readFileSync53, rmSync as rmSync12, writeFileSync as writeFileSync23 } from "fs";
|
|
37849
38450
|
import { homedir as homedir24 } from "os";
|
|
37850
|
-
import { join as
|
|
38451
|
+
import { join as join67 } from "path";
|
|
37851
38452
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
37852
38453
|
function resolveDaemonPaths() {
|
|
37853
38454
|
const watchJs = fileURLToPath5(new URL("./watch.js", import.meta.url));
|
|
37854
38455
|
const node = process.execPath;
|
|
37855
|
-
const dataDir =
|
|
37856
|
-
const logFile =
|
|
38456
|
+
const dataDir = join67(homedir24(), ".chat-recall");
|
|
38457
|
+
const logFile = join67(dataDir, "watch.log");
|
|
37857
38458
|
return { watchJs, node, logFile, dataDir };
|
|
37858
38459
|
}
|
|
37859
38460
|
function tryCmd(cmd) {
|
|
@@ -37880,13 +38481,13 @@ function refreshServiceDefinition() {
|
|
|
37880
38481
|
if (process.platform !== "linux") return false;
|
|
37881
38482
|
try {
|
|
37882
38483
|
const { watchJs, node, logFile } = resolveDaemonPaths();
|
|
37883
|
-
const unitPath =
|
|
37884
|
-
if (!
|
|
37885
|
-
const current =
|
|
38484
|
+
const unitPath = join67(homedir24(), ".config", "systemd", "user", "chat-recall-watch.service");
|
|
38485
|
+
if (!existsSync60(unitPath)) return false;
|
|
38486
|
+
const current = readFileSync53(unitPath, "utf8");
|
|
37886
38487
|
if (!current.includes(watchJs)) return false;
|
|
37887
38488
|
const wanted = renderSystemdUnit(watchJs, node, logFile);
|
|
37888
|
-
if (
|
|
37889
|
-
|
|
38489
|
+
if (readFileSync53(unitPath, "utf8") === wanted) return false;
|
|
38490
|
+
writeFileSync23(unitPath, wanted);
|
|
37890
38491
|
execSync5("systemctl --user daemon-reload", { stdio: "ignore" });
|
|
37891
38492
|
return true;
|
|
37892
38493
|
} catch {
|
|
@@ -37911,11 +38512,11 @@ function installService() {
|
|
|
37911
38512
|
);
|
|
37912
38513
|
}
|
|
37913
38514
|
function installSystemd(watchJs, node, logFile) {
|
|
37914
|
-
const unitDir =
|
|
37915
|
-
const unitPath =
|
|
38515
|
+
const unitDir = join67(homedir24(), ".config", "systemd", "user");
|
|
38516
|
+
const unitPath = join67(unitDir, "chat-recall-watch.service");
|
|
37916
38517
|
const unit = renderSystemdUnit(watchJs, node, logFile);
|
|
37917
38518
|
mkdirSync22(unitDir, { recursive: true });
|
|
37918
|
-
|
|
38519
|
+
writeFileSync23(unitPath, unit);
|
|
37919
38520
|
try {
|
|
37920
38521
|
execSync5("systemctl --user daemon-reload && systemctl --user enable chat-recall-watch.service && systemctl --user restart chat-recall-watch.service", { stdio: "inherit" });
|
|
37921
38522
|
try {
|
|
@@ -37998,11 +38599,11 @@ function renderSystemdUnit(watchJs, node, logFile) {
|
|
|
37998
38599
|
}
|
|
37999
38600
|
function installLaunchd(watchJs, node, logFile) {
|
|
38000
38601
|
const label = "com.chat-recall.watch";
|
|
38001
|
-
const plistDir =
|
|
38002
|
-
const plistPath =
|
|
38602
|
+
const plistDir = join67(homedir24(), "Library", "LaunchAgents");
|
|
38603
|
+
const plistPath = join67(plistDir, `${label}.plist`);
|
|
38003
38604
|
const plist = renderLaunchdPlist(watchJs, node, logFile, label);
|
|
38004
38605
|
mkdirSync22(plistDir, { recursive: true });
|
|
38005
|
-
|
|
38606
|
+
writeFileSync23(plistPath, plist);
|
|
38006
38607
|
try {
|
|
38007
38608
|
try {
|
|
38008
38609
|
execSync5(`launchctl unload "${plistPath}"`, { stdio: "ignore" });
|
|
@@ -38055,9 +38656,9 @@ function uninstallService() {
|
|
|
38055
38656
|
removed = true;
|
|
38056
38657
|
} catch {
|
|
38057
38658
|
}
|
|
38058
|
-
const unitPath =
|
|
38059
|
-
if (
|
|
38060
|
-
|
|
38659
|
+
const unitPath = join67(homedir24(), ".config", "systemd", "user", "chat-recall-watch.service");
|
|
38660
|
+
if (existsSync60(unitPath)) {
|
|
38661
|
+
rmSync12(unitPath, { force: true });
|
|
38061
38662
|
removed = true;
|
|
38062
38663
|
}
|
|
38063
38664
|
try {
|
|
@@ -38067,14 +38668,14 @@ function uninstallService() {
|
|
|
38067
38668
|
return removed;
|
|
38068
38669
|
}
|
|
38069
38670
|
if (process.platform === "darwin") {
|
|
38070
|
-
const plistPath =
|
|
38671
|
+
const plistPath = join67(homedir24(), "Library", "LaunchAgents", "com.chat-recall.watch.plist");
|
|
38071
38672
|
try {
|
|
38072
38673
|
execSync5(`launchctl unload "${plistPath}" 2>/dev/null`, { stdio: "ignore" });
|
|
38073
38674
|
} catch {
|
|
38074
38675
|
}
|
|
38075
38676
|
let removed = false;
|
|
38076
|
-
if (
|
|
38077
|
-
|
|
38677
|
+
if (existsSync60(plistPath)) {
|
|
38678
|
+
rmSync12(plistPath, { force: true });
|
|
38078
38679
|
removed = true;
|
|
38079
38680
|
}
|
|
38080
38681
|
return removed;
|
|
@@ -38603,9 +39204,9 @@ init_project_resolver();
|
|
|
38603
39204
|
import { config } from "dotenv";
|
|
38604
39205
|
import { Command } from "commander";
|
|
38605
39206
|
import chalk2 from "chalk";
|
|
38606
|
-
import { existsSync as
|
|
39207
|
+
import { existsSync as existsSync61, readFileSync as readFileSync54, writeFileSync as writeFileSync24 } from "fs";
|
|
38607
39208
|
import { homedir as homedir25 } from "os";
|
|
38608
|
-
import { join as
|
|
39209
|
+
import { join as join68, resolve as resolve2, dirname as dirname29, basename as basename29 } from "path";
|
|
38609
39210
|
|
|
38610
39211
|
// ../engine/dist/core/score-tier.js
|
|
38611
39212
|
var STRONG_RATIO = 0.85;
|
|
@@ -38752,6 +39353,8 @@ function askForStar(resultCount, dim) {
|
|
|
38752
39353
|
}
|
|
38753
39354
|
|
|
38754
39355
|
// src/cli.ts
|
|
39356
|
+
init_opencode_tui_config();
|
|
39357
|
+
init_guard_registration();
|
|
38755
39358
|
function matchLabel(tier) {
|
|
38756
39359
|
switch (tier) {
|
|
38757
39360
|
case "strong":
|
|
@@ -38846,13 +39449,13 @@ async function serverDelete(path, body2) {
|
|
|
38846
39449
|
}
|
|
38847
39450
|
var pkgEngines = (() => {
|
|
38848
39451
|
try {
|
|
38849
|
-
return JSON.parse(
|
|
39452
|
+
return JSON.parse(readFileSync54(new URL("../package.json", import.meta.url), "utf-8")).engines?.node ?? "";
|
|
38850
39453
|
} catch {
|
|
38851
39454
|
return "";
|
|
38852
39455
|
}
|
|
38853
39456
|
})();
|
|
38854
39457
|
var pkgVersion = JSON.parse(
|
|
38855
|
-
|
|
39458
|
+
readFileSync54(new URL("../package.json", import.meta.url), "utf-8")
|
|
38856
39459
|
).version;
|
|
38857
39460
|
var DEFAULT_SERVER = (process.env.CHAT_RECALL_DEFAULT_SERVER || "https://chatrecall.dev").replace(/\/+$/, "");
|
|
38858
39461
|
var DEFAULT_ALLOW = [
|
|
@@ -39032,10 +39635,10 @@ program.command("init").description("Set up chat-recall: connect to your server,
|
|
|
39032
39635
|
} else if (target) {
|
|
39033
39636
|
}
|
|
39034
39637
|
if (!options.skipMcp) {
|
|
39035
|
-
const projectRoot =
|
|
39638
|
+
const projectRoot = join68(import.meta.dirname, "..");
|
|
39036
39639
|
let mcpBinOnPath = false;
|
|
39037
39640
|
mcpBinOnPath = isOnPath("chat-recall-mcp");
|
|
39038
|
-
const launch = mcpBinOnPath ? { command: "chat-recall-mcp" } : { command: "node", args: [
|
|
39641
|
+
const launch = mcpBinOnPath ? { command: "chat-recall-mcp" } : { command: "node", args: [join68(projectRoot, "dist", "mcp-relay.js")] };
|
|
39039
39642
|
const MCP_ENV = { NODE_OPTIONS: "--max-old-space-size=1024" };
|
|
39040
39643
|
const { registerMcpEverywhere: registerMcpEverywhere2 } = await Promise.resolve().then(() => (init_mcp_clients(), mcp_clients_exports));
|
|
39041
39644
|
const MCP_CLIENT_FOR_BIN = {
|
|
@@ -39076,7 +39679,7 @@ program.command("init").description("Set up chat-recall: connect to your server,
|
|
|
39076
39679
|
const detected = checkCodeindexStatus2();
|
|
39077
39680
|
if (detected.installed && !forceInstall) {
|
|
39078
39681
|
if (!options.skipMcp) {
|
|
39079
|
-
const mcpJsonPath =
|
|
39682
|
+
const mcpJsonPath = join68(homedir25(), ".mcp.json");
|
|
39080
39683
|
const reg = registerCodeindexMcp2(mcpJsonPath, detected.path);
|
|
39081
39684
|
}
|
|
39082
39685
|
} else if (forceInstall) {
|
|
@@ -39085,7 +39688,7 @@ program.command("init").description("Set up chat-recall: connect to your server,
|
|
|
39085
39688
|
if (result.installed) {
|
|
39086
39689
|
const sizeMb = result.size ? `${(result.size / 1024 / 1024).toFixed(1)} MB` : "?";
|
|
39087
39690
|
if (!options.skipMcp) {
|
|
39088
|
-
const mcpJsonPath =
|
|
39691
|
+
const mcpJsonPath = join68(homedir25(), ".mcp.json");
|
|
39089
39692
|
const reg = registerCodeindexMcp2(mcpJsonPath, CODEINDEX_BIN_PATH2);
|
|
39090
39693
|
}
|
|
39091
39694
|
} else if (!result.prebuiltAvailable) {
|
|
@@ -39541,8 +40144,8 @@ memory.command("wake-up").description("Generate wake-up context (high-importance
|
|
|
39541
40144
|
try {
|
|
39542
40145
|
const identityFile = getIdentityFilePath();
|
|
39543
40146
|
let identity = "AI coding assistant";
|
|
39544
|
-
if (
|
|
39545
|
-
identity =
|
|
40147
|
+
if (existsSync61(identityFile)) {
|
|
40148
|
+
identity = readFileSync54(identityFile, "utf-8").trim();
|
|
39546
40149
|
}
|
|
39547
40150
|
const lines = [
|
|
39548
40151
|
chalk2.bold("# Wake-Up Context"),
|
|
@@ -39642,7 +40245,7 @@ program.command("feedback").argument("<message...>", "what you want to say \u201
|
|
|
39642
40245
|
}
|
|
39643
40246
|
});
|
|
39644
40247
|
program.command("doctor").description("Quick health check across login, server, credentials, hooks, MCP server, and codeindex").option("--purge-local", "Remove the legacy local index (cache.db + vector/KG files) left by pre-thin-collector versions \u2014 storage is server-side now. Requires login; keeps credentials, sync ledger, identity, and the audit log.").action(async (opts) => {
|
|
39645
|
-
const { existsSync:
|
|
40248
|
+
const { existsSync: existsSync62, readFileSync: readFileSync55, statSync: statSync49 } = await import("fs");
|
|
39646
40249
|
const { execSync: execSync6 } = await import("child_process");
|
|
39647
40250
|
const rows = [];
|
|
39648
40251
|
const note = (ok, label, detail) => rows.push({ ok, label, detail });
|
|
@@ -39705,8 +40308,8 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39705
40308
|
}
|
|
39706
40309
|
}
|
|
39707
40310
|
}
|
|
39708
|
-
const credFile =
|
|
39709
|
-
if (!
|
|
40311
|
+
const credFile = join68(getDataDir(), "credentials.json");
|
|
40312
|
+
if (!existsSync62(credFile)) {
|
|
39710
40313
|
note(false, "Credentials file", `missing \u2014 run \`chat-recall login <server-url>\``);
|
|
39711
40314
|
} else {
|
|
39712
40315
|
try {
|
|
@@ -39725,14 +40328,14 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39725
40328
|
const label = `Claude hooks (${profile})`;
|
|
39726
40329
|
let hooks;
|
|
39727
40330
|
try {
|
|
39728
|
-
hooks =
|
|
40331
|
+
hooks = existsSync62(settingsFile) ? JSON.parse(readFileSync55(settingsFile, "utf-8")).hooks || {} : {};
|
|
39729
40332
|
} catch {
|
|
39730
40333
|
note(false, label, `${settingsFile} is not valid JSON, so no hook in it runs`);
|
|
39731
40334
|
continue;
|
|
39732
40335
|
}
|
|
39733
|
-
const legacy =
|
|
40336
|
+
const legacy = join68(dirname29(settingsFile), "hooks.json");
|
|
39734
40337
|
try {
|
|
39735
|
-
const stranded =
|
|
40338
|
+
const stranded = existsSync62(legacy) ? Object.values(JSON.parse(readFileSync55(legacy, "utf-8")).hooks || {}).flat().filter(isOurEntry2).length : 0;
|
|
39736
40339
|
if (stranded) note(false, `Old hook file (${profile})`, `${stranded} chat-recall entr${stranded === 1 ? "y" : "ies"} in ${legacy}, which Claude Code does not read \u2014 run \`chat-recall install-hooks\` to move them`);
|
|
39737
40340
|
} catch {
|
|
39738
40341
|
}
|
|
@@ -39756,9 +40359,9 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39756
40359
|
try {
|
|
39757
40360
|
const reg = await Promise.resolve().then(() => (init_guard_registration(), guard_registration_exports));
|
|
39758
40361
|
for (const target2 of reg.guardTargets()) {
|
|
39759
|
-
if (!
|
|
40362
|
+
if (!existsSync62(target2.homeDir)) continue;
|
|
39760
40363
|
const label = `Decision guard \u2014 ${target2.label}`;
|
|
39761
|
-
if (!
|
|
40364
|
+
if (!existsSync62(target2.configPath)) {
|
|
39762
40365
|
note(false, label, `not registered \u2014 run \`chat-recall install-hooks\``);
|
|
39763
40366
|
continue;
|
|
39764
40367
|
}
|
|
@@ -39768,7 +40371,7 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39768
40371
|
}
|
|
39769
40372
|
let registered = false;
|
|
39770
40373
|
try {
|
|
39771
|
-
const cfg = JSON.parse(
|
|
40374
|
+
const cfg = JSON.parse(readFileSync55(target2.configPath, "utf-8"));
|
|
39772
40375
|
registered = JSON.stringify(cfg).includes("chat_recall_guard");
|
|
39773
40376
|
} catch {
|
|
39774
40377
|
}
|
|
@@ -39781,12 +40384,12 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39781
40384
|
try {
|
|
39782
40385
|
const reg = await Promise.resolve().then(() => (init_message_registration(), message_registration_exports));
|
|
39783
40386
|
for (const target2 of reg.messageTargets()) {
|
|
39784
|
-
if (!
|
|
40387
|
+
if (!existsSync62(target2.homeDir)) continue;
|
|
39785
40388
|
const label = `Messages \u2014 ${target2.label}`;
|
|
39786
|
-
let registered =
|
|
40389
|
+
let registered = existsSync62(target2.configPath);
|
|
39787
40390
|
if (registered) {
|
|
39788
40391
|
try {
|
|
39789
|
-
const text =
|
|
40392
|
+
const text = readFileSync55(target2.configPath, "utf-8");
|
|
39790
40393
|
registered = text.includes("chat_recall_messages_") || reg.isOurPluginSource(text);
|
|
39791
40394
|
} catch {
|
|
39792
40395
|
registered = false;
|
|
@@ -39798,12 +40401,25 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39798
40401
|
} catch (err) {
|
|
39799
40402
|
note(false, "Messages", `check failed: ${err}`);
|
|
39800
40403
|
}
|
|
40404
|
+
try {
|
|
40405
|
+
if (existsSync62(opencodeConfigDir())) {
|
|
40406
|
+
const path = tuiConfigPath();
|
|
40407
|
+
const present = existsSync62(path) && hasTuiPluginEntry(readFileSync55(path, "utf-8"), tuiPluginEntry());
|
|
40408
|
+
note(
|
|
40409
|
+
present,
|
|
40410
|
+
"Messages \u2014 OpenCode TUI",
|
|
40411
|
+
present ? path : `${path} has no "${tuiPluginEntry()}" entry \u2014 run \`chat-recall install-hooks\``
|
|
40412
|
+
);
|
|
40413
|
+
}
|
|
40414
|
+
} catch (err) {
|
|
40415
|
+
note(false, "Messages \u2014 OpenCode TUI", `check failed: ${err}`);
|
|
40416
|
+
}
|
|
39801
40417
|
try {
|
|
39802
40418
|
const { skillTargets: skillTargets2, bundledSkillNames: bundledSkillNames2 } = await Promise.resolve().then(() => (init_install_skills(), install_skills_exports));
|
|
39803
40419
|
const want = bundledSkillNames2().length;
|
|
39804
40420
|
for (const t of skillTargets2()) {
|
|
39805
40421
|
if (!t.available) continue;
|
|
39806
|
-
const have = want === 0 ? 0 : bundledSkillNames2().filter((n) =>
|
|
40422
|
+
const have = want === 0 ? 0 : bundledSkillNames2().filter((n) => existsSync62(join68(t.dir, n, ".chat-recall-managed"))).length;
|
|
39807
40423
|
note(
|
|
39808
40424
|
have === want,
|
|
39809
40425
|
`Skills \u2014 ${t.label}`,
|
|
@@ -39878,25 +40494,25 @@ program.command("doctor").description("Quick health check across login, server,
|
|
|
39878
40494
|
note(watchRunning, "Watch daemon", watchRunning ? "running" : "not running (run `chat-recall watch --install-service` to keep collection running)");
|
|
39879
40495
|
const dataDir = getDataDir();
|
|
39880
40496
|
const legacyPaths = [
|
|
39881
|
-
|
|
39882
|
-
|
|
39883
|
-
|
|
39884
|
-
|
|
39885
|
-
|
|
39886
|
-
|
|
40497
|
+
join68(dataDir, "cache.db"),
|
|
40498
|
+
join68(dataDir, "cache.db-wal"),
|
|
40499
|
+
join68(dataDir, "cache.db-shm"),
|
|
40500
|
+
join68(dataDir, "index", "lancedb"),
|
|
40501
|
+
join68(dataDir, "index", "knowledge_graph.db"),
|
|
40502
|
+
join68(dataDir, "index", "metadata.db")
|
|
39887
40503
|
];
|
|
39888
|
-
const legacyPresent = legacyPaths.filter((p) =>
|
|
40504
|
+
const legacyPresent = legacyPaths.filter((p) => existsSync62(p));
|
|
39889
40505
|
if (opts.purgeLocal) {
|
|
39890
40506
|
if (!target) {
|
|
39891
40507
|
note(false, "Purge legacy index", "refused \u2014 log in and `chat-recall sync` first, so your history is on the server before removing local copies");
|
|
39892
40508
|
} else if (legacyPresent.length === 0) {
|
|
39893
40509
|
note(true, "Purge legacy index", "nothing to remove");
|
|
39894
40510
|
} else {
|
|
39895
|
-
const { rmSync:
|
|
40511
|
+
const { rmSync: rmSync13 } = await import("fs");
|
|
39896
40512
|
let removed = 0;
|
|
39897
40513
|
for (const p of legacyPresent) {
|
|
39898
40514
|
try {
|
|
39899
|
-
|
|
40515
|
+
rmSync13(p, { recursive: true, force: true });
|
|
39900
40516
|
removed++;
|
|
39901
40517
|
} catch {
|
|
39902
40518
|
}
|
|
@@ -39956,7 +40572,7 @@ companions.command("install").description("Install codeindex (downloads from mun
|
|
|
39956
40572
|
if (result.installed) {
|
|
39957
40573
|
const sizeMb = result.size ? `${(result.size / 1024 / 1024).toFixed(1)} MB` : "?";
|
|
39958
40574
|
console.log(chalk2.green(`\u2713 codeindex installed (${sizeMb}) \u2192 ${result.path}`));
|
|
39959
|
-
const mcpJsonPath =
|
|
40575
|
+
const mcpJsonPath = join68(homedir25(), ".mcp.json");
|
|
39960
40576
|
const reg = registerCodeindexMcp2(mcpJsonPath, CODEINDEX_BIN_PATH2);
|
|
39961
40577
|
if (reg.added) console.log(chalk2.dim(` Registered as MCP server in ${mcpJsonPath}`));
|
|
39962
40578
|
else console.log(chalk2.dim(` Already registered as MCP server`));
|
|
@@ -39978,7 +40594,7 @@ companions.command("uninstall").description("Remove the codeindex binary chat-re
|
|
|
39978
40594
|
const r = uninstallCodeindex2();
|
|
39979
40595
|
if (r.removed) console.log(chalk2.green(`\u2713 Removed ${r.path}`));
|
|
39980
40596
|
else console.log(chalk2.dim(` Nothing to remove at ${r.path}`));
|
|
39981
|
-
const mcpJsonPath =
|
|
40597
|
+
const mcpJsonPath = join68(homedir25(), ".mcp.json");
|
|
39982
40598
|
const u = unregisterCodeindexMcp2(mcpJsonPath);
|
|
39983
40599
|
if (u.removed) console.log(chalk2.dim(` Unregistered MCP server from ${mcpJsonPath}`));
|
|
39984
40600
|
});
|
|
@@ -40530,10 +41146,10 @@ tasks.command("pull [dir]").description("Write TEAM_TASKS.md for your tasks in t
|
|
|
40530
41146
|
try {
|
|
40531
41147
|
const { resolveProjectId: resolveProjectId2 } = await Promise.resolve().then(() => (init_project_resolver(), project_resolver_exports));
|
|
40532
41148
|
const { renderTeamTasksMd: renderTeamTasksMd2, parseTeamTasksFile: parseTeamTasksFile2 } = await Promise.resolve().then(() => (init_project_tasks(), project_tasks_exports));
|
|
40533
|
-
const { writeFileSync:
|
|
40534
|
-
const { join:
|
|
40535
|
-
const file =
|
|
40536
|
-
if (!opts.force &&
|
|
41149
|
+
const { writeFileSync: writeFileSync25, readFileSync: readFileSync55, existsSync: existsSync62 } = await import("node:fs");
|
|
41150
|
+
const { join: join69 } = await import("node:path");
|
|
41151
|
+
const file = join69(cwd, "TEAM_TASKS.md");
|
|
41152
|
+
if (!opts.force && existsSync62(file) && parseTeamTasksFile2(readFileSync55(file, "utf8")).length > 0) {
|
|
40537
41153
|
console.error(chalk2.red("TEAM_TASKS.md has unpushed edits."), "Run", chalk2.bold("chat-recall tasks push"), "first, or", chalk2.bold("tasks pull --force"), "to discard.");
|
|
40538
41154
|
process.exit(1);
|
|
40539
41155
|
}
|
|
@@ -40541,7 +41157,7 @@ tasks.command("pull [dir]").description("Write TEAM_TASKS.md for your tasks in t
|
|
|
40541
41157
|
const pid = resolved && resolved.source !== "ignored" ? resolved.id : "";
|
|
40542
41158
|
const { tasks: tasks2 } = await serverGet("/api/tasks?assignee=@me");
|
|
40543
41159
|
const mine = tasks2.filter((t) => !pid || !t.projectId || t.projectId === pid);
|
|
40544
|
-
|
|
41160
|
+
writeFileSync25(file, renderTeamTasksMd2(mine));
|
|
40545
41161
|
console.log(chalk2.green("\u2713 wrote"), "TEAM_TASKS.md", chalk2.gray(`(${mine.length} task(s))`), "\u2014 edit, then", chalk2.bold("chat-recall tasks push"));
|
|
40546
41162
|
} catch (e) {
|
|
40547
41163
|
console.error(chalk2.red(e instanceof Error ? e.message : String(e)));
|
|
@@ -40552,14 +41168,14 @@ tasks.command("push [dir]").description("Push TEAM_TASKS.md status edits back to
|
|
|
40552
41168
|
const cwd = dir || process.cwd();
|
|
40553
41169
|
try {
|
|
40554
41170
|
const { parseTeamTasksFile: parseTeamTasksFile2 } = await Promise.resolve().then(() => (init_project_tasks(), project_tasks_exports));
|
|
40555
|
-
const { readFileSync:
|
|
40556
|
-
const { join:
|
|
40557
|
-
const file =
|
|
40558
|
-
if (!
|
|
41171
|
+
const { readFileSync: readFileSync55, existsSync: existsSync62 } = await import("node:fs");
|
|
41172
|
+
const { join: join69 } = await import("node:path");
|
|
41173
|
+
const file = join69(cwd, "TEAM_TASKS.md");
|
|
41174
|
+
if (!existsSync62(file)) {
|
|
40559
41175
|
console.error(chalk2.red("no TEAM_TASKS.md here \u2014"), "run", chalk2.bold("chat-recall tasks pull"), "first");
|
|
40560
41176
|
process.exit(1);
|
|
40561
41177
|
}
|
|
40562
|
-
const edits = parseTeamTasksFile2(
|
|
41178
|
+
const edits = parseTeamTasksFile2(readFileSync55(file, "utf8"));
|
|
40563
41179
|
let n = 0;
|
|
40564
41180
|
for (const e of edits) {
|
|
40565
41181
|
await serverPatch(`/api/tasks/${encodeURIComponent(e.id)}`, { status: e.intent });
|
|
@@ -40665,8 +41281,8 @@ team.command("publish <type> <name> <file>").description("Publish a local file a
|
|
|
40665
41281
|
console.error(chalk2.red(`Invalid tool: ${opts.tool}. Must be one of: ${validTools.join(", ")}`));
|
|
40666
41282
|
process.exit(1);
|
|
40667
41283
|
}
|
|
40668
|
-
const { readFileSync:
|
|
40669
|
-
const body2 =
|
|
41284
|
+
const { readFileSync: readFileSync55 } = await import("fs");
|
|
41285
|
+
const body2 = readFileSync55(file);
|
|
40670
41286
|
const { teamPublish: teamPublish2 } = await Promise.resolve().then(() => (init_team_client(), team_client_exports));
|
|
40671
41287
|
const a = await teamPublish2({
|
|
40672
41288
|
type,
|
|
@@ -41093,7 +41709,7 @@ program.command("dossier <project>").description("Generate a project dossier (ov
|
|
|
41093
41709
|
);
|
|
41094
41710
|
const md = dossier.markdown;
|
|
41095
41711
|
if (options.out) {
|
|
41096
|
-
|
|
41712
|
+
writeFileSync24(options.out, md);
|
|
41097
41713
|
console.log(chalk2.green(`Wrote dossier to ${options.out} (${md.length} chars)`));
|
|
41098
41714
|
} else {
|
|
41099
41715
|
console.log(md);
|