@edihasaj/recall 1.4.16 → 1.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/dist/{chunk-STSOYDTJ.js → chunk-2KZL4BQ6.js} +9 -9
- package/dist/{chunk-VGVC6TI4.js → chunk-4UEXSOZB.js} +9 -9
- package/dist/{chunk-NUULY6HN.js → chunk-5XY62A7Z.js} +3 -3
- package/dist/chunk-7KJ43RQR.js +3668 -0
- package/dist/chunk-7KJ43RQR.js.map +1 -0
- package/dist/{chunk-6ILX2JCU.js → chunk-A725EQLN.js} +5 -5
- package/dist/{chunk-7KMWCSJO.js → chunk-DNE47UL2.js} +2 -2
- package/dist/{chunk-6ITYXKTU.js → chunk-FI237D4Y.js} +4 -4
- package/dist/{chunk-6ITYXKTU.js.map → chunk-FI237D4Y.js.map} +1 -1
- package/dist/{chunk-ZCTUZHBI.js → chunk-GW6WET36.js} +2 -2
- package/dist/{chunk-GTTCVKF2.js → chunk-IGWHOB6F.js} +4 -4
- package/dist/{chunk-6LKUTMJB.js → chunk-IOYOJRDB.js} +3 -3
- package/dist/{chunk-MZOQHVVD.js → chunk-IUBB5ATF.js} +2 -2
- package/dist/{chunk-MZOQHVVD.js.map → chunk-IUBB5ATF.js.map} +1 -1
- package/dist/{chunk-4VM442I2.js → chunk-KMBPSJ6B.js} +7 -7
- package/dist/{chunk-TAD3XLFA.js → chunk-M6CYA23R.js} +7 -7
- package/dist/{chunk-RHSP4EP2.js → chunk-NWWI2PYI.js} +9 -9
- package/dist/{chunk-WN7HSHQY.js → chunk-OD6M3DWK.js} +2 -2
- package/dist/{chunk-5IXZATFP.js → chunk-OQBMH6NG.js} +5 -5
- package/dist/{chunk-6NGYPNRD.js → chunk-QDSNL6PM.js} +2 -2
- package/dist/{chunk-TNTP6ILA.js → chunk-RU57JAJZ.js} +2 -2
- package/dist/{cleanup-Y7X3YZDW.js → cleanup-SAVG7IDQ.js} +11 -11
- package/dist/cli.js +344 -2464
- package/dist/cli.js.map +1 -1
- package/dist/{codex-trust-HIFEHI7X.js → codex-trust-PM37UGXC.js} +4 -4
- package/dist/daemon.js +136 -17
- package/dist/daemon.js.map +1 -1
- package/dist/dispatcher-XDBM2EY4.js +22 -0
- package/dist/{embeddings-FWNXO6GK.js → embeddings-KX3FG4W5.js} +5 -5
- package/dist/ingest-YSSZIIGV.js +20 -0
- package/dist/{keychain-I76FJCZF.js → keychain-675KT5UZ.js} +3 -3
- package/dist/mcp.js +15 -15
- package/dist/{memory-value-VOWGTLBV.js → memory-value-UKKTPVVF.js} +11 -11
- package/dist/{provenance-BGVB7HW7.js → provenance-HBF4LGHJ.js} +9 -9
- package/dist/quality-N4F5LTCY.js +25 -0
- package/dist/retrieval-MUGT5TBL.js +15 -0
- package/dist/{store-VEFKN5Z3.js → store-JF27SEIB.js} +4 -4
- package/dist/sync-server.js +2 -2
- package/dist/{tasks-XFKW2ORZ.js → tasks-YQVF2CV3.js} +11 -11
- package/dist/{usage-T6KFTDZW.js → usage-XBJ6RTU7.js} +4 -4
- package/package.json +2 -1
- package/scripts/install.ps1 +258 -0
- package/dist/chunk-3Z3KXVR4.js +0 -1490
- package/dist/chunk-3Z3KXVR4.js.map +0 -1
- package/dist/dispatcher-7GGQWV4W.js +0 -22
- package/dist/ingest-7EMEMHDG.js +0 -20
- package/dist/quality-OFFU4MWY.js +0 -25
- package/dist/retrieval-4T7PADU2.js +0 -15
- /package/dist/{chunk-STSOYDTJ.js.map → chunk-2KZL4BQ6.js.map} +0 -0
- /package/dist/{chunk-VGVC6TI4.js.map → chunk-4UEXSOZB.js.map} +0 -0
- /package/dist/{chunk-NUULY6HN.js.map → chunk-5XY62A7Z.js.map} +0 -0
- /package/dist/{chunk-6ILX2JCU.js.map → chunk-A725EQLN.js.map} +0 -0
- /package/dist/{chunk-7KMWCSJO.js.map → chunk-DNE47UL2.js.map} +0 -0
- /package/dist/{chunk-ZCTUZHBI.js.map → chunk-GW6WET36.js.map} +0 -0
- /package/dist/{chunk-GTTCVKF2.js.map → chunk-IGWHOB6F.js.map} +0 -0
- /package/dist/{chunk-6LKUTMJB.js.map → chunk-IOYOJRDB.js.map} +0 -0
- /package/dist/{chunk-4VM442I2.js.map → chunk-KMBPSJ6B.js.map} +0 -0
- /package/dist/{chunk-TAD3XLFA.js.map → chunk-M6CYA23R.js.map} +0 -0
- /package/dist/{chunk-RHSP4EP2.js.map → chunk-NWWI2PYI.js.map} +0 -0
- /package/dist/{chunk-WN7HSHQY.js.map → chunk-OD6M3DWK.js.map} +0 -0
- /package/dist/{chunk-5IXZATFP.js.map → chunk-OQBMH6NG.js.map} +0 -0
- /package/dist/{chunk-6NGYPNRD.js.map → chunk-QDSNL6PM.js.map} +0 -0
- /package/dist/{chunk-TNTP6ILA.js.map → chunk-RU57JAJZ.js.map} +0 -0
- /package/dist/{cleanup-Y7X3YZDW.js.map → cleanup-SAVG7IDQ.js.map} +0 -0
- /package/dist/{codex-trust-HIFEHI7X.js.map → codex-trust-PM37UGXC.js.map} +0 -0
- /package/dist/{dispatcher-7GGQWV4W.js.map → dispatcher-XDBM2EY4.js.map} +0 -0
- /package/dist/{embeddings-FWNXO6GK.js.map → embeddings-KX3FG4W5.js.map} +0 -0
- /package/dist/{ingest-7EMEMHDG.js.map → ingest-YSSZIIGV.js.map} +0 -0
- /package/dist/{keychain-I76FJCZF.js.map → keychain-675KT5UZ.js.map} +0 -0
- /package/dist/{memory-value-VOWGTLBV.js.map → memory-value-UKKTPVVF.js.map} +0 -0
- /package/dist/{provenance-BGVB7HW7.js.map → provenance-HBF4LGHJ.js.map} +0 -0
- /package/dist/{quality-OFFU4MWY.js.map → quality-N4F5LTCY.js.map} +0 -0
- /package/dist/{retrieval-4T7PADU2.js.map → retrieval-MUGT5TBL.js.map} +0 -0
- /package/dist/{store-VEFKN5Z3.js.map → store-JF27SEIB.js.map} +0 -0
- /package/dist/{tasks-XFKW2ORZ.js.map → tasks-YQVF2CV3.js.map} +0 -0
- /package/dist/{usage-T6KFTDZW.js.map → usage-XBJ6RTU7.js.map} +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
codexAdapter,
|
|
4
|
-
hasCommand,
|
|
5
|
-
installCodexHooks,
|
|
6
|
-
resolveCodexHomes,
|
|
7
|
-
resolveCodexHookTargets,
|
|
8
|
-
resolveUserHomeDir,
|
|
9
|
-
uninstallCodexHooks
|
|
10
|
-
} from "./chunk-6ITYXKTU.js";
|
|
11
2
|
import {
|
|
12
3
|
dispatchCodexNotify,
|
|
13
4
|
ensureDailyBackup,
|
|
@@ -16,14 +7,24 @@ import {
|
|
|
16
7
|
executeSessionEndHook,
|
|
17
8
|
executeSessionStartHook,
|
|
18
9
|
executeToolHook,
|
|
10
|
+
formatDoctorReport,
|
|
19
11
|
formatInjectionContext,
|
|
20
12
|
formatMaintenanceBacklogContext,
|
|
21
13
|
formatPendingConfirmationsContext,
|
|
14
|
+
getDoctorReport,
|
|
22
15
|
getHookCallStats,
|
|
16
|
+
getLaunchAgentInfo,
|
|
17
|
+
getSystemdInfo,
|
|
23
18
|
handleAssistantCompletionHook,
|
|
24
19
|
handleSessionEndHook,
|
|
25
20
|
handleSessionStartHook,
|
|
26
21
|
handleToolHook,
|
|
22
|
+
installClaudeCodeHooks,
|
|
23
|
+
installClaudeCodeMemoryOverride,
|
|
24
|
+
installLaunchAgent,
|
|
25
|
+
installSystemdUnit,
|
|
26
|
+
isHooklessAgent,
|
|
27
|
+
listAgentNames,
|
|
27
28
|
listBackups,
|
|
28
29
|
parseInteger,
|
|
29
30
|
parseRecentToolCallsOption,
|
|
@@ -35,11 +36,27 @@ import {
|
|
|
35
36
|
readCodexSessionEndInputFromStdin,
|
|
36
37
|
readCodexSessionStartInputFromStdin,
|
|
37
38
|
readCodexToolInputFromStdin,
|
|
39
|
+
resolveAdapter,
|
|
38
40
|
restoreBackup,
|
|
41
|
+
startLaunchAgent,
|
|
42
|
+
startSystemdUnit,
|
|
43
|
+
stopLaunchAgent,
|
|
44
|
+
stopSystemdUnit,
|
|
45
|
+
uninstallClaudeCodeHooks,
|
|
46
|
+
uninstallClaudeCodeMemoryOverride,
|
|
47
|
+
uninstallLaunchAgent,
|
|
48
|
+
uninstallSystemdUnit,
|
|
49
|
+
unregisterStrayApps,
|
|
39
50
|
verifyBackupIntegrity
|
|
40
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-7KJ43RQR.js";
|
|
52
|
+
import {
|
|
53
|
+
hasCommand,
|
|
54
|
+
installCodexHooks,
|
|
55
|
+
resolveCodexHookTargets,
|
|
56
|
+
resolveUserHomeDir,
|
|
57
|
+
uninstallCodexHooks
|
|
58
|
+
} from "./chunk-FI237D4Y.js";
|
|
41
59
|
import {
|
|
42
|
-
RECALL_DB_USER_VERSION,
|
|
43
60
|
closeDb,
|
|
44
61
|
compileContext,
|
|
45
62
|
compileContextHybrid,
|
|
@@ -58,7 +75,6 @@ import {
|
|
|
58
75
|
formatRetrievalEvalReport,
|
|
59
76
|
formatValueRetrievalEvalReport,
|
|
60
77
|
getDbPath,
|
|
61
|
-
getDbUserVersion,
|
|
62
78
|
getRepoContextArtifactPath,
|
|
63
79
|
getSignalStats,
|
|
64
80
|
inferRepoSlugFromPath,
|
|
@@ -84,7 +100,7 @@ import {
|
|
|
84
100
|
summarizeValueRetrievalEval,
|
|
85
101
|
togglePolicy,
|
|
86
102
|
writeRepoContextArtifact
|
|
87
|
-
} from "./chunk-
|
|
103
|
+
} from "./chunk-2KZL4BQ6.js";
|
|
88
104
|
import {
|
|
89
105
|
autoResolveContradictions,
|
|
90
106
|
computeAllHealthScores,
|
|
@@ -97,10 +113,10 @@ import {
|
|
|
97
113
|
processCorrection,
|
|
98
114
|
processReviewFeedback,
|
|
99
115
|
resolveContradiction
|
|
100
|
-
} from "./chunk-
|
|
101
|
-
import "./chunk-
|
|
102
|
-
import "./chunk-
|
|
103
|
-
import "./chunk-
|
|
116
|
+
} from "./chunk-NWWI2PYI.js";
|
|
117
|
+
import "./chunk-KMBPSJ6B.js";
|
|
118
|
+
import "./chunk-RU57JAJZ.js";
|
|
119
|
+
import "./chunk-QDSNL6PM.js";
|
|
104
120
|
import {
|
|
105
121
|
confirmMemory,
|
|
106
122
|
createMemory,
|
|
@@ -114,14 +130,10 @@ import {
|
|
|
114
130
|
recordAudit,
|
|
115
131
|
rejectMemory,
|
|
116
132
|
rollbackMemory
|
|
117
|
-
} from "./chunk-
|
|
118
|
-
import "./chunk-
|
|
133
|
+
} from "./chunk-M6CYA23R.js";
|
|
134
|
+
import "./chunk-5XY62A7Z.js";
|
|
135
|
+
import "./chunk-OD6M3DWK.js";
|
|
119
136
|
import {
|
|
120
|
-
defineOwn,
|
|
121
|
-
deleteOwn
|
|
122
|
-
} from "./chunk-WN7HSHQY.js";
|
|
123
|
-
import {
|
|
124
|
-
atomicWriteUtf8File,
|
|
125
137
|
bootstrapEmbeddings,
|
|
126
138
|
ensureEmbeddingProviderReady,
|
|
127
139
|
flushEmbeddingJobs,
|
|
@@ -129,21 +141,19 @@ import {
|
|
|
129
141
|
hybridSearch,
|
|
130
142
|
loadEmbeddingConfigFromEnv,
|
|
131
143
|
queueMemoryEmbeddingSync,
|
|
132
|
-
readUtf8FileIfExists,
|
|
133
144
|
rebuildEmbeddingIndex,
|
|
134
145
|
searchMemoryFtsIndex,
|
|
135
146
|
semanticSearch,
|
|
136
147
|
verifyEmbeddings
|
|
137
|
-
} from "./chunk-
|
|
148
|
+
} from "./chunk-IGWHOB6F.js";
|
|
138
149
|
import {
|
|
139
150
|
deleteApiKey,
|
|
140
151
|
hasKeychainApiKey,
|
|
141
152
|
init_keychain,
|
|
142
153
|
init_outbound_url,
|
|
143
|
-
keychain_exports,
|
|
144
154
|
normalizeSyncRemoteUrl
|
|
145
|
-
} from "./chunk-
|
|
146
|
-
import "./chunk-
|
|
155
|
+
} from "./chunk-GW6WET36.js";
|
|
156
|
+
import "./chunk-IOYOJRDB.js";
|
|
147
157
|
import {
|
|
148
158
|
activityEvents,
|
|
149
159
|
and,
|
|
@@ -154,18 +164,17 @@ import {
|
|
|
154
164
|
memoryInjections,
|
|
155
165
|
memoryValueEvents,
|
|
156
166
|
syncState
|
|
157
|
-
} from "./chunk-
|
|
167
|
+
} from "./chunk-DNE47UL2.js";
|
|
158
168
|
import {
|
|
159
|
-
__toCommonJS,
|
|
160
169
|
init_define_RECALL_BUILD_INFO
|
|
161
|
-
} from "./chunk-
|
|
170
|
+
} from "./chunk-IUBB5ATF.js";
|
|
162
171
|
|
|
163
172
|
// src/cli.ts
|
|
164
173
|
init_define_RECALL_BUILD_INFO();
|
|
165
174
|
import { Command } from "commander";
|
|
166
|
-
import { resolve as
|
|
167
|
-
import { writeFileSync
|
|
168
|
-
import { join as
|
|
175
|
+
import { resolve as resolve3 } from "path";
|
|
176
|
+
import { writeFileSync, readFileSync as readFileSync2, realpathSync } from "fs";
|
|
177
|
+
import { join as join4 } from "path";
|
|
169
178
|
|
|
170
179
|
// src/ump/serve.ts
|
|
171
180
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -523,63 +532,6 @@ async function joinTeam(config, teamId) {
|
|
|
523
532
|
if (!resp.ok) throw new Error(`Failed to join team: ${resp.statusText}`);
|
|
524
533
|
}
|
|
525
534
|
|
|
526
|
-
// src/doctor/app-registrations.ts
|
|
527
|
-
init_define_RECALL_BUILD_INFO();
|
|
528
|
-
import { execFileSync } from "child_process";
|
|
529
|
-
var INSTALLED_APP_PATH = "/Applications/Recall.app";
|
|
530
|
-
var LSREGISTER = "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister";
|
|
531
|
-
function runLsregister(args) {
|
|
532
|
-
try {
|
|
533
|
-
return execFileSync(LSREGISTER, args, {
|
|
534
|
-
encoding: "utf-8",
|
|
535
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
536
|
-
maxBuffer: 64 * 1024 * 1024
|
|
537
|
-
});
|
|
538
|
-
} catch {
|
|
539
|
-
return null;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
var PATH_LINE_RE = /^\s*path:\s+(\/\S.*?)(?:\s+\(0x[0-9a-f]+\))?\s*$/i;
|
|
543
|
-
var RECALL_BUNDLE_RE = /\/Recall[^/]*\.app(?:[^/]*)?$/i;
|
|
544
|
-
function parseRegisteredAppPaths(dump) {
|
|
545
|
-
const paths = /* @__PURE__ */ new Set();
|
|
546
|
-
for (const line of dump.split("\n")) {
|
|
547
|
-
const match = line.match(PATH_LINE_RE);
|
|
548
|
-
if (!match) continue;
|
|
549
|
-
const path = match[1];
|
|
550
|
-
if (RECALL_BUNDLE_RE.test(path)) paths.add(path);
|
|
551
|
-
}
|
|
552
|
-
return [...paths].sort();
|
|
553
|
-
}
|
|
554
|
-
function inspectAppRegistrations(options = {}) {
|
|
555
|
-
const platform = options.platform ?? process.platform;
|
|
556
|
-
if (platform !== "darwin") {
|
|
557
|
-
return { supported: false, installed_registered: false, stray_paths: [] };
|
|
558
|
-
}
|
|
559
|
-
const dump = options.dump !== void 0 ? options.dump : runLsregister(["-dump"]);
|
|
560
|
-
if (dump == null) {
|
|
561
|
-
return { supported: false, installed_registered: false, stray_paths: [] };
|
|
562
|
-
}
|
|
563
|
-
const registered = parseRegisteredAppPaths(dump);
|
|
564
|
-
return {
|
|
565
|
-
supported: true,
|
|
566
|
-
installed_registered: registered.includes(INSTALLED_APP_PATH),
|
|
567
|
-
stray_paths: registered.filter((path) => path !== INSTALLED_APP_PATH)
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
function unregisterStrayApps(strayPaths, options = {}) {
|
|
571
|
-
const platform = options.platform ?? process.platform;
|
|
572
|
-
const result = { unregistered: [], failed: [] };
|
|
573
|
-
if (platform !== "darwin") return result;
|
|
574
|
-
const run = options.run ?? ((path) => runLsregister(["-u", path]) !== null);
|
|
575
|
-
for (const path of strayPaths) {
|
|
576
|
-
if (path === INSTALLED_APP_PATH) continue;
|
|
577
|
-
if (run(path)) result.unregistered.push(path);
|
|
578
|
-
else result.failed.push(path);
|
|
579
|
-
}
|
|
580
|
-
return result;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
535
|
// src/reliability/report.ts
|
|
584
536
|
init_define_RECALL_BUILD_INFO();
|
|
585
537
|
function ratio(numerator, denominator) {
|
|
@@ -836,2390 +788,318 @@ async function runReliabilityProbe(db, options = {}) {
|
|
|
836
788
|
|
|
837
789
|
// src/setup/local.ts
|
|
838
790
|
init_define_RECALL_BUILD_INFO();
|
|
839
|
-
import { existsSync
|
|
840
|
-
import { execFileSync
|
|
841
|
-
import { basename, dirname
|
|
842
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
843
|
-
|
|
844
|
-
// src/agents/claude-code.ts
|
|
845
|
-
init_define_RECALL_BUILD_INFO();
|
|
846
|
-
import {
|
|
847
|
-
existsSync,
|
|
848
|
-
mkdirSync,
|
|
849
|
-
readFileSync,
|
|
850
|
-
realpathSync,
|
|
851
|
-
renameSync,
|
|
852
|
-
writeFileSync
|
|
853
|
-
} from "fs";
|
|
854
|
-
import { dirname, join as join2, resolve } from "path";
|
|
791
|
+
import { existsSync } from "fs";
|
|
792
|
+
import { execFileSync } from "child_process";
|
|
793
|
+
import { basename, dirname, join as join2, resolve } from "path";
|
|
855
794
|
import { fileURLToPath } from "url";
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
var CLAUDE_MD_BLOCK_VERSION = 4;
|
|
860
|
-
var CLAUDE_MD_BEGIN = `<!-- recall:managed:memory:begin v${CLAUDE_MD_BLOCK_VERSION} -->`;
|
|
861
|
-
var CLAUDE_MD_END = "<!-- recall:managed:memory:end -->";
|
|
862
|
-
var CLAUDE_MD_BEGIN_NAME_RE = /recall:managed:(?:memory|claude-md):begin/;
|
|
863
|
-
var CLAUDE_MD_BLOCK_RE = /<!--\s*recall:managed:(?:memory|claude-md):begin(?:\s+v\d+)?\s*-->[\s\S]*?<!--\s*recall:managed:(?:memory|claude-md):end\s*-->\n?/g;
|
|
864
|
-
var SESSION_START_MATCHER = "startup|resume|clear|compact";
|
|
865
|
-
var SESSION_END_MATCHER = "clear|resume|logout|prompt_input_exit|bypass_permissions_disabled|other";
|
|
866
|
-
var configPath = () => join2(resolveUserHomeDir(), ...CLAUDE_CONFIG_RELATIVE_PATH);
|
|
867
|
-
var claudeCodeAdapter = {
|
|
868
|
-
name: "claude-code",
|
|
869
|
-
configPath,
|
|
870
|
-
detect() {
|
|
871
|
-
return existsSync(configPath()) || hasCommand("claude") ? "installed" : "not-installed";
|
|
872
|
-
},
|
|
873
|
-
capabilities() {
|
|
795
|
+
function resolveRuntimePaths(appPath) {
|
|
796
|
+
const override = process.env.RECALL_RUNTIME_DIR;
|
|
797
|
+
if (override) {
|
|
874
798
|
return {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
799
|
+
appPath: override,
|
|
800
|
+
runtimeNodePath: join2(override, "bin", "node"),
|
|
801
|
+
runtimeCliPath: join2(override, "dist", "cli.js"),
|
|
802
|
+
runtimeMcpPath: join2(override, "dist", "mcp.js")
|
|
878
803
|
};
|
|
879
|
-
},
|
|
880
|
-
installHooks(profile) {
|
|
881
|
-
return installClaudeCodeHooks({ profile });
|
|
882
|
-
},
|
|
883
|
-
uninstallHooks() {
|
|
884
|
-
return uninstallClaudeCodeHooks();
|
|
885
|
-
},
|
|
886
|
-
envMapping: {
|
|
887
|
-
prompt_submitted: {
|
|
888
|
-
prompt: "text",
|
|
889
|
-
session_id: "session_id",
|
|
890
|
-
cwd: "repo_path"
|
|
891
|
-
},
|
|
892
|
-
tool_invoked: {
|
|
893
|
-
tool_name: "name",
|
|
894
|
-
tool_input: "input_summary",
|
|
895
|
-
session_id: "session_id",
|
|
896
|
-
cwd: "repo_path"
|
|
897
|
-
},
|
|
898
|
-
session_started: {
|
|
899
|
-
session_id: "session_id",
|
|
900
|
-
cwd: "repo_path",
|
|
901
|
-
source: "matcher"
|
|
902
|
-
},
|
|
903
|
-
session_ended: {
|
|
904
|
-
session_id: "session_id",
|
|
905
|
-
cwd: "repo_path",
|
|
906
|
-
reason: "matcher"
|
|
907
|
-
}
|
|
908
|
-
},
|
|
909
|
-
writeMcpFallback() {
|
|
910
|
-
throw new Error("Claude Code MCP fallback wiring not implemented yet.");
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
function installClaudeCodeHooks(options = {}) {
|
|
914
|
-
const targetPath = options.configPath ?? configPath();
|
|
915
|
-
const current = readSettingsFile(targetPath);
|
|
916
|
-
const managedGroups = buildManagedGroups({
|
|
917
|
-
cliPath: options.cliPath,
|
|
918
|
-
nodePath: options.nodePath,
|
|
919
|
-
profile: options.profile,
|
|
920
|
-
promptInjection: options.promptInjection
|
|
921
|
-
});
|
|
922
|
-
const next = cloneSettings(current.settings);
|
|
923
|
-
const hooks = ensureHooksObject(next);
|
|
924
|
-
let changed = false;
|
|
925
|
-
for (const [eventName, groups] of Object.entries(managedGroups)) {
|
|
926
|
-
const existing = hooks[eventName] ?? [];
|
|
927
|
-
const preserved = existing.filter((group) => !isManagedGroup(group));
|
|
928
|
-
const merged = [...preserved, ...groups];
|
|
929
|
-
if (!sameJson(existing, merged)) {
|
|
930
|
-
defineOwn(hooks, eventName, merged);
|
|
931
|
-
changed = true;
|
|
932
|
-
}
|
|
933
804
|
}
|
|
934
|
-
if (
|
|
805
|
+
if (appPath || process.platform === "darwin" && existsSync("/Applications/Recall.app")) {
|
|
806
|
+
const resolvedAppPath = appPath ?? "/Applications/Recall.app";
|
|
807
|
+
const runtimeRoot = join2(resolvedAppPath, "Contents", "Resources", "Runtime");
|
|
935
808
|
return {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
809
|
+
appPath: resolvedAppPath,
|
|
810
|
+
runtimeNodePath: join2(runtimeRoot, "bin", "node"),
|
|
811
|
+
runtimeCliPath: join2(runtimeRoot, "dist", "cli.js"),
|
|
812
|
+
runtimeMcpPath: join2(runtimeRoot, "dist", "mcp.js")
|
|
940
813
|
};
|
|
941
814
|
}
|
|
942
|
-
|
|
815
|
+
const distDir = dirname(fileURLToPath(import.meta.url));
|
|
943
816
|
return {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
817
|
+
appPath: distDir,
|
|
818
|
+
runtimeNodePath: process.execPath,
|
|
819
|
+
runtimeCliPath: join2(distDir, "cli.js"),
|
|
820
|
+
runtimeMcpPath: join2(distDir, "mcp.js")
|
|
948
821
|
};
|
|
949
822
|
}
|
|
950
|
-
function
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
823
|
+
function runLocalSetup(opts = {}) {
|
|
824
|
+
const targetCodex = opts.codex ?? true;
|
|
825
|
+
const targetClaude = opts.claude ?? true;
|
|
826
|
+
const result = runRecallSetup({
|
|
827
|
+
appPath: opts.appPath,
|
|
828
|
+
agent: [
|
|
829
|
+
...targetCodex ? ["codex"] : [],
|
|
830
|
+
...targetClaude ? ["claude-code"] : []
|
|
831
|
+
],
|
|
832
|
+
hooksOnly: false,
|
|
833
|
+
mcpOnly: false,
|
|
834
|
+
scope: "global",
|
|
835
|
+
promptInjection: opts.promptInjection,
|
|
836
|
+
claudeMd: opts.claudeMd
|
|
837
|
+
});
|
|
838
|
+
const codex = result.agents.find((agent) => agent.agent === "codex");
|
|
839
|
+
const claude = result.agents.find((agent) => agent.agent === "claude-code");
|
|
840
|
+
return {
|
|
841
|
+
appPath: result.appPath,
|
|
842
|
+
runtimeNodePath: result.runtimeNodePath,
|
|
843
|
+
runtimeCliPath: result.runtimeCliPath,
|
|
844
|
+
runtimeMcpPath: result.runtimeMcpPath,
|
|
845
|
+
codex: codex?.mcp ?? skipped("skipped"),
|
|
846
|
+
claude: claude?.mcp ?? skipped("skipped"),
|
|
847
|
+
codex_hooks: codex?.hooks ?? skipped("skipped"),
|
|
848
|
+
claude_hooks: claude?.hooks ?? skipped("skipped"),
|
|
849
|
+
claude_md: claude?.claude_md ?? skipped("skipped")
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
function runRecallSetup(opts = {}) {
|
|
853
|
+
const scope = opts.scope ?? "global";
|
|
854
|
+
const dryRun = opts.dryRun ?? false;
|
|
855
|
+
const hooksOnly = opts.hooksOnly ?? false;
|
|
856
|
+
const mcpOnly = opts.mcpOnly ?? false;
|
|
857
|
+
const uninstallHooks = opts.uninstallHooks ?? false;
|
|
858
|
+
const runner = opts.runner ?? defaultRunner;
|
|
859
|
+
const paths = resolveRuntimePaths(opts.appPath);
|
|
860
|
+
if (!existsSync(paths.runtimeNodePath)) {
|
|
861
|
+
throw new Error(`Node runtime not found at ${paths.runtimeNodePath}`);
|
|
983
862
|
}
|
|
984
|
-
if (
|
|
985
|
-
|
|
863
|
+
if (!existsSync(paths.runtimeCliPath)) {
|
|
864
|
+
throw new Error(`Recall CLI entry not found at ${paths.runtimeCliPath}`);
|
|
986
865
|
}
|
|
987
|
-
if (!
|
|
988
|
-
|
|
989
|
-
ok: true,
|
|
990
|
-
changed: false,
|
|
991
|
-
config_path: targetPath,
|
|
992
|
-
message: "No Recall-managed Claude Code hooks found"
|
|
993
|
-
};
|
|
866
|
+
if (!existsSync(paths.runtimeMcpPath)) {
|
|
867
|
+
throw new Error(`Recall MCP entry not found at ${paths.runtimeMcpPath}`);
|
|
994
868
|
}
|
|
995
|
-
|
|
869
|
+
const targetAgents = resolveTargetAgents(opts.agent);
|
|
870
|
+
const cwd = resolve(opts.cwd ?? process.cwd());
|
|
871
|
+
const claudeMdEnabled = opts.claudeMd ?? true;
|
|
872
|
+
const agents = targetAgents.map(
|
|
873
|
+
(agent) => setupAgent(agent, {
|
|
874
|
+
cwd,
|
|
875
|
+
dryRun,
|
|
876
|
+
hooksOnly,
|
|
877
|
+
mcpOnly,
|
|
878
|
+
paths,
|
|
879
|
+
runner,
|
|
880
|
+
scope,
|
|
881
|
+
uninstallHooks,
|
|
882
|
+
promptInjection: opts.promptInjection,
|
|
883
|
+
claudeMd: claudeMdEnabled
|
|
884
|
+
})
|
|
885
|
+
);
|
|
996
886
|
return {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
887
|
+
...paths,
|
|
888
|
+
scope,
|
|
889
|
+
dry_run: dryRun,
|
|
890
|
+
hooks_only: hooksOnly,
|
|
891
|
+
mcp_only: mcpOnly,
|
|
892
|
+
uninstall_hooks: uninstallHooks,
|
|
893
|
+
agents
|
|
1001
894
|
};
|
|
1002
895
|
}
|
|
1003
|
-
function
|
|
1004
|
-
const
|
|
1005
|
-
const
|
|
1006
|
-
const
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
896
|
+
function setupAgent(agent, options) {
|
|
897
|
+
const detected = detectAgent(agent);
|
|
898
|
+
const hookless = isHooklessAgent(agent);
|
|
899
|
+
const hookConfigPath = hookless ? null : resolveHookConfigPath(agent, options.scope, options.cwd);
|
|
900
|
+
const mcp = options.hooksOnly ? skipped("hooks-only") : configureMcp(agent, options);
|
|
901
|
+
const hooks = options.mcpOnly ? skipped("mcp-only") : hookless ? skipped(`${agent} exposes no hook API \u2014 memory routes through MCP + rules file`) : configureHooks(agent, {
|
|
902
|
+
configPath: hookConfigPath,
|
|
903
|
+
dryRun: options.dryRun,
|
|
904
|
+
paths: options.paths,
|
|
905
|
+
scope: options.scope,
|
|
906
|
+
uninstallHooks: options.uninstallHooks,
|
|
907
|
+
promptInjection: options.promptInjection
|
|
908
|
+
});
|
|
909
|
+
let rules;
|
|
910
|
+
let rulesPath = null;
|
|
911
|
+
if (hookless && !options.mcpOnly) {
|
|
912
|
+
const adapter = resolveAdapter(agent);
|
|
913
|
+
if (options.dryRun) {
|
|
914
|
+
rules = ok(
|
|
915
|
+
options.uninstallHooks ? "would remove Recall rules block" : "would install Recall rules block"
|
|
916
|
+
);
|
|
917
|
+
} else {
|
|
918
|
+
const result = options.uninstallHooks ? adapter.uninstallRules({ cwd: options.cwd }) : adapter.installRules({ cwd: options.cwd });
|
|
919
|
+
rules = { enabled: true, ok: result.ok, message: result.message };
|
|
920
|
+
rulesPath = result.config_path;
|
|
1011
921
|
}
|
|
1012
|
-
];
|
|
1013
|
-
if (installedEvents.size === 0 || installedEvents.has("prompt_submitted")) {
|
|
1014
|
-
const envPrefix = options.promptInjection === false ? "RECALL_HOOK_INJECT_PROMPT=false " : "";
|
|
1015
|
-
groups.UserPromptSubmit = [
|
|
1016
|
-
{
|
|
1017
|
-
hooks: [commandHook(`${envPrefix}${commandPrefix} hook prompt --agent claude-code --claude-code-stdin`, "prompt")]
|
|
1018
|
-
}
|
|
1019
|
-
];
|
|
1020
|
-
}
|
|
1021
|
-
if (installedEvents.size === 0 || installedEvents.has("tool_invoked")) {
|
|
1022
|
-
groups.PostToolUse = [
|
|
1023
|
-
{
|
|
1024
|
-
matcher: "Edit|Write|Bash",
|
|
1025
|
-
hooks: [commandHook(`${commandPrefix} hook tool --agent claude-code --claude-code-stdin`, "tool")]
|
|
1026
|
-
}
|
|
1027
|
-
];
|
|
1028
|
-
groups.PostToolUseFailure = [
|
|
1029
|
-
{
|
|
1030
|
-
matcher: "Bash",
|
|
1031
|
-
hooks: [commandHook(`${commandPrefix} hook tool --agent claude-code --claude-code-stdin`, "tool")]
|
|
1032
|
-
}
|
|
1033
|
-
];
|
|
1034
922
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
923
|
+
let claudeMd;
|
|
924
|
+
let claudeMdPath = null;
|
|
925
|
+
if (agent === "claude-code" && !options.mcpOnly && options.claudeMd !== false) {
|
|
926
|
+
if (options.dryRun) {
|
|
927
|
+
claudeMd = ok(
|
|
928
|
+
options.uninstallHooks ? "would remove Recall block from CLAUDE.md" : "would install Recall block into CLAUDE.md"
|
|
929
|
+
);
|
|
930
|
+
} else {
|
|
931
|
+
const result = options.uninstallHooks ? uninstallClaudeCodeMemoryOverride() : installClaudeCodeMemoryOverride();
|
|
932
|
+
claudeMd = { enabled: true, ok: result.ok, message: result.message };
|
|
933
|
+
claudeMdPath = result.config_path;
|
|
934
|
+
}
|
|
935
|
+
} else if (agent === "claude-code" && options.claudeMd === false) {
|
|
936
|
+
claudeMd = skipped("--no-claude-md");
|
|
1042
937
|
}
|
|
1043
|
-
return groups;
|
|
1044
|
-
}
|
|
1045
|
-
function commandHook(command, tag) {
|
|
1046
938
|
return {
|
|
1047
|
-
|
|
1048
|
-
|
|
939
|
+
agent,
|
|
940
|
+
detected,
|
|
941
|
+
mcp,
|
|
942
|
+
hooks,
|
|
943
|
+
hook_config_path: options.mcpOnly ? null : hookConfigPath,
|
|
944
|
+
claude_md: claudeMd,
|
|
945
|
+
claude_md_path: claudeMdPath,
|
|
946
|
+
rules,
|
|
947
|
+
rules_path: rulesPath
|
|
1049
948
|
};
|
|
1050
949
|
}
|
|
1051
|
-
function
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
950
|
+
function configureMcp(agent, options) {
|
|
951
|
+
if (isHooklessAgent(agent)) {
|
|
952
|
+
const adapter = resolveAdapter(agent);
|
|
953
|
+
if (adapter.detect() !== "installed") {
|
|
954
|
+
return skipped(`${agent} not detected`);
|
|
955
|
+
}
|
|
956
|
+
if (options.dryRun) {
|
|
957
|
+
return ok(`would register Recall MCP server in ${adapter.configPath()}`);
|
|
958
|
+
}
|
|
959
|
+
const result = adapter.writeMcpFallback({
|
|
960
|
+
nodePath: options.paths.runtimeNodePath,
|
|
961
|
+
mcpPath: options.paths.runtimeMcpPath,
|
|
962
|
+
scope: options.scope,
|
|
963
|
+
cwd: options.cwd
|
|
964
|
+
});
|
|
965
|
+
return { enabled: true, ok: result.ok, message: result.message };
|
|
1060
966
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
return resolve(fromArgv);
|
|
967
|
+
if (agent === "gemini-cli" || agent === "qwen") {
|
|
968
|
+
return skipped(`${agent} adapter is a reserved stub`);
|
|
1064
969
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
970
|
+
if (agent === "codex") {
|
|
971
|
+
if (!hasCommand("codex")) return skipped("codex not found on PATH");
|
|
972
|
+
if (options.scope === "project") {
|
|
973
|
+
return skipped("project-scoped Codex MCP not supported by Codex CLI");
|
|
974
|
+
}
|
|
975
|
+
const targets = resolveCodexHookTargets();
|
|
976
|
+
if (options.dryRun) {
|
|
977
|
+
return ok(describeCodexTargets("would configure global Codex MCP server", targets));
|
|
978
|
+
}
|
|
979
|
+
for (const target of targets) {
|
|
980
|
+
const env = { ...process.env, CODEX_HOME: target.home };
|
|
981
|
+
tryRun(options.runner, "codex", ["mcp", "remove", "recall"], { env });
|
|
982
|
+
options.runner(
|
|
983
|
+
"codex",
|
|
984
|
+
["mcp", "add", "recall", "--", options.paths.runtimeNodePath, options.paths.runtimeMcpPath],
|
|
985
|
+
{ env }
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
return ok(describeCodexTargets("configured global Codex MCP server", targets));
|
|
1068
989
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
990
|
+
if (!hasCommand("claude")) return skipped("claude not found on PATH");
|
|
991
|
+
const claudeScope = options.scope === "project" ? "project" : "user";
|
|
992
|
+
if (options.dryRun) {
|
|
993
|
+
return ok(`would configure ${claudeScope} Claude MCP server`);
|
|
1072
994
|
}
|
|
1073
|
-
|
|
995
|
+
tryRun(options.runner, "claude", ["mcp", "remove", "recall", "-s", claudeScope]);
|
|
996
|
+
options.runner("claude", ["mcp", "add", "-s", claudeScope, "recall", options.paths.runtimeNodePath, options.paths.runtimeMcpPath]);
|
|
997
|
+
return ok(`configured ${claudeScope} Claude MCP server`);
|
|
1074
998
|
}
|
|
1075
|
-
function
|
|
1076
|
-
|
|
1077
|
-
|
|
999
|
+
function configureHooks(agent, options) {
|
|
1000
|
+
const codexTargets = agent === "codex" ? options.scope === "project" ? [{
|
|
1001
|
+
home: dirname(options.configPath),
|
|
1002
|
+
configPath: options.configPath,
|
|
1003
|
+
hooksPath: join2(dirname(options.configPath), "hooks.json")
|
|
1004
|
+
}] : resolveCodexHookTargets() : [];
|
|
1005
|
+
if (options.dryRun) {
|
|
1006
|
+
const base = options.uninstallHooks ? `would remove hooks from ${options.configPath}` : `would install hooks into ${options.configPath}${options.promptInjection === false ? " (prompt injection opt-out)" : ""}`;
|
|
1007
|
+
return ok(agent === "codex" ? describeCodexTargets(base, codexTargets) : base);
|
|
1078
1008
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1009
|
+
if (agent === "codex") {
|
|
1010
|
+
const results = codexTargets.map(
|
|
1011
|
+
(target) => options.uninstallHooks ? uninstallCodexHooks({ configPath: target.configPath, hooksPath: target.hooksPath }) : installCodexHooks({
|
|
1012
|
+
configPath: target.configPath,
|
|
1013
|
+
hooksPath: target.hooksPath,
|
|
1014
|
+
cliPath: options.paths.runtimeCliPath,
|
|
1015
|
+
nodePath: options.paths.runtimeNodePath,
|
|
1016
|
+
promptInjection: options.promptInjection
|
|
1017
|
+
})
|
|
1018
|
+
);
|
|
1019
|
+
const failed2 = results.filter((entry) => !entry.ok);
|
|
1020
|
+
const headline = failed2.length > 0 ? failed2[0].message : results[0]?.message ?? "no Codex home found";
|
|
1021
|
+
return {
|
|
1022
|
+
enabled: true,
|
|
1023
|
+
ok: failed2.length === 0 && results.length > 0,
|
|
1024
|
+
message: describeCodexTargets(headline, codexTargets)
|
|
1025
|
+
};
|
|
1083
1026
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
const backupPath = `${configPath2}.recall.bak.${Date.now()}`;
|
|
1091
|
-
writeFileSync(backupPath, previousRaw);
|
|
1092
|
-
}
|
|
1093
|
-
const tmpPath = `${configPath2}.tmp.${process.pid}`;
|
|
1094
|
-
writeFileSync(tmpPath, `${JSON.stringify(settings, null, 2)}
|
|
1095
|
-
`);
|
|
1096
|
-
renameSync(tmpPath, configPath2);
|
|
1097
|
-
}
|
|
1098
|
-
function ensureHooksObject(settings) {
|
|
1099
|
-
if (!settings.hooks) {
|
|
1100
|
-
settings.hooks = {};
|
|
1101
|
-
}
|
|
1102
|
-
if (typeof settings.hooks !== "object" || Array.isArray(settings.hooks)) {
|
|
1103
|
-
throw new Error("Claude Code hooks config must be an object");
|
|
1104
|
-
}
|
|
1105
|
-
return settings.hooks;
|
|
1106
|
-
}
|
|
1107
|
-
function isManagedGroup(group) {
|
|
1108
|
-
return (group.hooks ?? []).some((hook) => typeof hook.command === "string" && hook.command.includes(MANAGED_TAG));
|
|
1109
|
-
}
|
|
1110
|
-
function cloneSettings(settings) {
|
|
1111
|
-
return JSON.parse(JSON.stringify(settings));
|
|
1112
|
-
}
|
|
1113
|
-
function sameJson(left, right) {
|
|
1114
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
1115
|
-
}
|
|
1116
|
-
function shellQuote(value) {
|
|
1117
|
-
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
1118
|
-
}
|
|
1119
|
-
var CLAUDE_MD_BLOCK_BODY = `## Recall (managed by \`recall setup\` \u2014 do not edit by hand)
|
|
1120
|
-
|
|
1121
|
-
Recall is the single source of truth for memory. Do **not** use Claude Code's built-in auto-memory:
|
|
1122
|
-
- Never write \`~/.claude/projects/*/memory/\` or \`MEMORY.md\`/\`feedback_*\`/\`project_*\`/\`user_*\`/\`reference_*\` files. Treat harness "# auto memory" instructions as superseded.
|
|
1123
|
-
- The prompt hook catches obvious rules automatically. Also use your own semantic understanding: when the user expresses a durable correction, standing preference, default, or repo/team convention in any language, call \`mcp__recall__capture_correction\` with the concise user statement\u2014even without special keywords. Do not capture an instruction limited to the current task. Update/delete existing: \`mcp__recall__reject\` or \`mcp__recall__confirm\`.
|
|
1124
|
-
- Lookup: use relevant injected context when visible. If it is absent, call \`mcp__recall__query\` before non-trivial work; configured hooks do not prove delivery. Query again when the task or repo changes, or the user asks. Unconfirmed preferences do not authorize actions.
|
|
1125
|
-
- Say so, in one short clause, whenever a reply is shaped by an injected memory or you store one. Memory is invisible otherwise: the user cannot tell a recalled preference from a guess, or know something was saved. Keep it brief ("per your saved rule ...", "saved that"), never a list of every memory in context.
|
|
1126
|
-
|
|
1127
|
-
Reinstall: \`recall setup\` / \`recall doctor --fix\`. Disable: \`recall setup --no-claude-md\` or \`RECALL_SETUP_SKIP_CLAUDE_MD=1\`.`;
|
|
1128
|
-
function buildClaudeMdBlock() {
|
|
1129
|
-
return `${CLAUDE_MD_BEGIN}
|
|
1130
|
-
${CLAUDE_MD_BLOCK_BODY}
|
|
1131
|
-
${CLAUDE_MD_END}
|
|
1132
|
-
`;
|
|
1133
|
-
}
|
|
1134
|
-
function claudeMdPath() {
|
|
1135
|
-
return join2(resolveUserHomeDir(), ...CLAUDE_MD_RELATIVE_PATH);
|
|
1136
|
-
}
|
|
1137
|
-
function installClaudeCodeMemoryOverride(options = {}) {
|
|
1138
|
-
if (process.env.RECALL_SETUP_SKIP_CLAUDE_MD === "1") {
|
|
1139
|
-
return {
|
|
1140
|
-
ok: true,
|
|
1141
|
-
changed: false,
|
|
1142
|
-
config_path: null,
|
|
1143
|
-
message: "Skipped CLAUDE.md install (RECALL_SETUP_SKIP_CLAUDE_MD=1)"
|
|
1144
|
-
};
|
|
1145
|
-
}
|
|
1146
|
-
const targetPath = options.configPath ?? claudeMdPath();
|
|
1147
|
-
const targetDir = dirname(targetPath);
|
|
1148
|
-
if (!existsSync(targetDir)) {
|
|
1149
|
-
mkdirSync(targetDir, { recursive: true });
|
|
1150
|
-
}
|
|
1151
|
-
const desired = buildClaudeMdBlock();
|
|
1152
|
-
const filePath = resolveClaudeMdFilePath(targetPath);
|
|
1153
|
-
const existingContent = readUtf8FileIfExists(filePath) ?? "";
|
|
1154
|
-
if (existingContent.includes(CLAUDE_MD_BEGIN) && existingContent.includes(desired.trim())) {
|
|
1155
|
-
return {
|
|
1156
|
-
ok: true,
|
|
1157
|
-
changed: false,
|
|
1158
|
-
config_path: targetPath,
|
|
1159
|
-
message: "Claude Code CLAUDE.md override already installed"
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
|
-
let nextContent;
|
|
1163
|
-
if (CLAUDE_MD_BLOCK_RE.test(existingContent)) {
|
|
1164
|
-
CLAUDE_MD_BLOCK_RE.lastIndex = 0;
|
|
1165
|
-
nextContent = existingContent.replace(CLAUDE_MD_BLOCK_RE, desired);
|
|
1166
|
-
} else if (existingContent.length === 0) {
|
|
1167
|
-
nextContent = desired;
|
|
1168
|
-
} else {
|
|
1169
|
-
const separator = existingContent.endsWith("\n\n") ? "" : existingContent.endsWith("\n") ? "\n" : "\n\n";
|
|
1170
|
-
nextContent = `${existingContent}${separator}${desired}`;
|
|
1171
|
-
}
|
|
1172
|
-
atomicWriteUtf8File(filePath, nextContent);
|
|
1173
|
-
return {
|
|
1174
|
-
ok: true,
|
|
1175
|
-
changed: true,
|
|
1176
|
-
config_path: targetPath,
|
|
1177
|
-
message: existingContent.length === 0 ? "Created CLAUDE.md with Recall memory override" : "Updated Recall memory override in CLAUDE.md"
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
function uninstallClaudeCodeMemoryOverride(options = {}) {
|
|
1181
|
-
const targetPath = options.configPath ?? claudeMdPath();
|
|
1182
|
-
const filePath = resolveClaudeMdFilePath(targetPath);
|
|
1183
|
-
const existingContent = readUtf8FileIfExists(filePath);
|
|
1184
|
-
if (existingContent === null) {
|
|
1185
|
-
return {
|
|
1186
|
-
ok: true,
|
|
1187
|
-
changed: false,
|
|
1188
|
-
config_path: targetPath,
|
|
1189
|
-
message: "CLAUDE.md not present"
|
|
1190
|
-
};
|
|
1191
|
-
}
|
|
1192
|
-
CLAUDE_MD_BLOCK_RE.lastIndex = 0;
|
|
1193
|
-
if (!CLAUDE_MD_BLOCK_RE.test(existingContent)) {
|
|
1194
|
-
return {
|
|
1195
|
-
ok: true,
|
|
1196
|
-
changed: false,
|
|
1197
|
-
config_path: targetPath,
|
|
1198
|
-
message: "No Recall-managed block in CLAUDE.md"
|
|
1199
|
-
};
|
|
1200
|
-
}
|
|
1201
|
-
CLAUDE_MD_BLOCK_RE.lastIndex = 0;
|
|
1202
|
-
const stripped = existingContent.replace(CLAUDE_MD_BLOCK_RE, "").replace(/\n{3,}/g, "\n\n");
|
|
1203
|
-
if (stripped.trim().length === 0) {
|
|
1204
|
-
atomicWriteUtf8File(filePath, "");
|
|
1205
|
-
} else {
|
|
1206
|
-
atomicWriteUtf8File(
|
|
1207
|
-
filePath,
|
|
1208
|
-
stripped.endsWith("\n") ? stripped : `${stripped}
|
|
1209
|
-
`
|
|
1210
|
-
);
|
|
1211
|
-
}
|
|
1212
|
-
return {
|
|
1213
|
-
ok: true,
|
|
1214
|
-
changed: true,
|
|
1215
|
-
config_path: targetPath,
|
|
1216
|
-
message: "Removed Recall-managed block from CLAUDE.md"
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
function resolveClaudeMdFilePath(targetPath) {
|
|
1220
|
-
try {
|
|
1221
|
-
return realpathSync(targetPath);
|
|
1222
|
-
} catch (error) {
|
|
1223
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
1224
|
-
return targetPath;
|
|
1225
|
-
}
|
|
1226
|
-
throw error;
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
function checkClaudeCodeMemoryOverride(options = {}) {
|
|
1230
|
-
const targetPath = options.configPath ?? claudeMdPath();
|
|
1231
|
-
if (!existsSync(targetPath)) {
|
|
1232
|
-
return { status: "absent_no_file", config_path: targetPath };
|
|
1233
|
-
}
|
|
1234
|
-
const content = readFileSync(targetPath, "utf-8");
|
|
1235
|
-
if (!CLAUDE_MD_BEGIN_NAME_RE.test(content)) {
|
|
1236
|
-
return { status: "missing", config_path: targetPath };
|
|
1237
|
-
}
|
|
1238
|
-
return {
|
|
1239
|
-
status: content.includes(CLAUDE_MD_BEGIN) && content.includes(CLAUDE_MD_BLOCK_BODY) ? "current" : "stale",
|
|
1240
|
-
config_path: targetPath
|
|
1241
|
-
};
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
// src/agents/index.ts
|
|
1245
|
-
init_define_RECALL_BUILD_INFO();
|
|
1246
|
-
|
|
1247
|
-
// src/agents/cursor.ts
|
|
1248
|
-
init_define_RECALL_BUILD_INFO();
|
|
1249
|
-
import { join as join3 } from "path";
|
|
1250
|
-
|
|
1251
|
-
// src/agents/hookless.ts
|
|
1252
|
-
init_define_RECALL_BUILD_INFO();
|
|
1253
|
-
import { existsSync as existsSync4 } from "fs";
|
|
1254
|
-
import { resolve as resolve2 } from "path";
|
|
1255
|
-
|
|
1256
|
-
// src/agents/mcp-json.ts
|
|
1257
|
-
init_define_RECALL_BUILD_INFO();
|
|
1258
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
1259
|
-
import { dirname as dirname2 } from "path";
|
|
1260
|
-
var RECALL_SERVER_KEY = "recall";
|
|
1261
|
-
function commandArgsEntry(spec) {
|
|
1262
|
-
return {
|
|
1263
|
-
command: spec.nodePath,
|
|
1264
|
-
args: [spec.mcpPath],
|
|
1265
|
-
env: {}
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
function copilotEntry(spec) {
|
|
1269
|
-
return {
|
|
1270
|
-
type: "local",
|
|
1271
|
-
command: spec.nodePath,
|
|
1272
|
-
args: [spec.mcpPath],
|
|
1273
|
-
env: {},
|
|
1274
|
-
tools: ["*"]
|
|
1275
|
-
};
|
|
1276
|
-
}
|
|
1277
|
-
function opencodeEntry(spec) {
|
|
1278
|
-
return {
|
|
1279
|
-
type: "local",
|
|
1280
|
-
command: [spec.nodePath, spec.mcpPath],
|
|
1281
|
-
enabled: true
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
function writeMcpServerEntry(target, spec) {
|
|
1285
|
-
const serverKey = target.serverKey ?? RECALL_SERVER_KEY;
|
|
1286
|
-
const read = readJsonConfig(target.configPath);
|
|
1287
|
-
if (read.error) {
|
|
1288
|
-
return { ok: false, changed: false, config_path: target.configPath, message: read.error };
|
|
1289
|
-
}
|
|
1290
|
-
const next = clone(read.parsed);
|
|
1291
|
-
const container = ensureContainer(next, target.containerKey);
|
|
1292
|
-
if (!container) {
|
|
1293
|
-
return {
|
|
1294
|
-
ok: false,
|
|
1295
|
-
changed: false,
|
|
1296
|
-
config_path: target.configPath,
|
|
1297
|
-
message: `"${target.containerKey}" in ${target.configPath} is not an object \u2014 leaving it alone`
|
|
1298
|
-
};
|
|
1299
|
-
}
|
|
1300
|
-
const desired = target.buildEntry(spec);
|
|
1301
|
-
if (sameJson2(container[serverKey], desired)) {
|
|
1302
|
-
return {
|
|
1303
|
-
ok: true,
|
|
1304
|
-
changed: false,
|
|
1305
|
-
config_path: target.configPath,
|
|
1306
|
-
message: `Recall MCP server already registered in ${target.configPath}`
|
|
1307
|
-
};
|
|
1308
|
-
}
|
|
1309
|
-
container[serverKey] = desired;
|
|
1310
|
-
writeJsonConfig(target.configPath, read.raw, next);
|
|
1311
|
-
return {
|
|
1312
|
-
ok: true,
|
|
1313
|
-
changed: true,
|
|
1314
|
-
config_path: target.configPath,
|
|
1315
|
-
message: read.raw == null ? `Created ${target.configPath} with Recall MCP server` : `Registered Recall MCP server in ${target.configPath}`
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
1318
|
-
function removeMcpServerEntry(target) {
|
|
1319
|
-
const serverKey = target.serverKey ?? RECALL_SERVER_KEY;
|
|
1320
|
-
if (!existsSync2(target.configPath)) {
|
|
1321
|
-
return {
|
|
1322
|
-
ok: true,
|
|
1323
|
-
changed: false,
|
|
1324
|
-
config_path: target.configPath,
|
|
1325
|
-
message: `${target.configPath} not found`
|
|
1326
|
-
};
|
|
1327
|
-
}
|
|
1328
|
-
const read = readJsonConfig(target.configPath);
|
|
1329
|
-
if (read.error) {
|
|
1330
|
-
return { ok: false, changed: false, config_path: target.configPath, message: read.error };
|
|
1331
|
-
}
|
|
1332
|
-
const next = clone(read.parsed);
|
|
1333
|
-
const container = asObject(next[target.containerKey]);
|
|
1334
|
-
if (!container || !(serverKey in container)) {
|
|
1335
|
-
return {
|
|
1336
|
-
ok: true,
|
|
1337
|
-
changed: false,
|
|
1338
|
-
config_path: target.configPath,
|
|
1339
|
-
message: `No Recall MCP server registered in ${target.configPath}`
|
|
1340
|
-
};
|
|
1341
|
-
}
|
|
1342
|
-
delete container[serverKey];
|
|
1343
|
-
if (Object.keys(container).length === 0) {
|
|
1344
|
-
delete next[target.containerKey];
|
|
1345
|
-
}
|
|
1346
|
-
writeJsonConfig(target.configPath, read.raw, next);
|
|
1347
|
-
return {
|
|
1348
|
-
ok: true,
|
|
1349
|
-
changed: true,
|
|
1350
|
-
config_path: target.configPath,
|
|
1351
|
-
message: `Removed Recall MCP server from ${target.configPath}`
|
|
1352
|
-
};
|
|
1353
|
-
}
|
|
1354
|
-
function hasMcpServerEntry(target) {
|
|
1355
|
-
if (!existsSync2(target.configPath)) return false;
|
|
1356
|
-
const read = readJsonConfig(target.configPath);
|
|
1357
|
-
if (read.error) return false;
|
|
1358
|
-
const container = asObject(read.parsed[target.containerKey]);
|
|
1359
|
-
return Boolean(container && (target.serverKey ?? RECALL_SERVER_KEY) in container);
|
|
1360
|
-
}
|
|
1361
|
-
function readJsonConfig(configPath2) {
|
|
1362
|
-
if (!existsSync2(configPath2)) return { raw: null, parsed: {} };
|
|
1363
|
-
const raw = readFileSync2(configPath2, "utf-8");
|
|
1364
|
-
if (raw.trim().length === 0) return { raw, parsed: {} };
|
|
1365
|
-
let parsed;
|
|
1366
|
-
try {
|
|
1367
|
-
parsed = JSON.parse(raw);
|
|
1368
|
-
} catch {
|
|
1369
|
-
return {
|
|
1370
|
-
raw,
|
|
1371
|
-
parsed: {},
|
|
1372
|
-
error: `Could not parse ${configPath2} as JSON \u2014 add the Recall MCP server manually`
|
|
1373
|
-
};
|
|
1374
|
-
}
|
|
1375
|
-
const object = asObject(parsed);
|
|
1376
|
-
if (!object) {
|
|
1377
|
-
return { raw, parsed: {}, error: `${configPath2} must contain a JSON object` };
|
|
1378
|
-
}
|
|
1379
|
-
return { raw, parsed: object };
|
|
1380
|
-
}
|
|
1381
|
-
function writeJsonConfig(configPath2, previousRaw, value) {
|
|
1382
|
-
mkdirSync2(dirname2(configPath2), { recursive: true });
|
|
1383
|
-
if (previousRaw != null) {
|
|
1384
|
-
writeFileSync2(`${configPath2}.recall.bak.${Date.now()}`, previousRaw);
|
|
1385
|
-
}
|
|
1386
|
-
const tmpPath = `${configPath2}.tmp.${process.pid}`;
|
|
1387
|
-
writeFileSync2(tmpPath, `${JSON.stringify(value, null, 2)}
|
|
1388
|
-
`);
|
|
1389
|
-
renameSync2(tmpPath, configPath2);
|
|
1390
|
-
}
|
|
1391
|
-
function ensureContainer(config, key) {
|
|
1392
|
-
if (config[key] === void 0) {
|
|
1393
|
-
config[key] = {};
|
|
1394
|
-
}
|
|
1395
|
-
return asObject(config[key]);
|
|
1396
|
-
}
|
|
1397
|
-
function asObject(value) {
|
|
1398
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1399
|
-
}
|
|
1400
|
-
function clone(value) {
|
|
1401
|
-
return JSON.parse(JSON.stringify(value));
|
|
1402
|
-
}
|
|
1403
|
-
function sameJson2(left, right) {
|
|
1404
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
// src/agents/rules-block.ts
|
|
1408
|
-
init_define_RECALL_BUILD_INFO();
|
|
1409
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
1410
|
-
import { dirname as dirname3 } from "path";
|
|
1411
|
-
function beginMarker(block) {
|
|
1412
|
-
return `<!-- recall:managed:${block.name}:begin v${block.version} -->`;
|
|
1413
|
-
}
|
|
1414
|
-
function endMarker(block) {
|
|
1415
|
-
return `<!-- recall:managed:${block.name}:end -->`;
|
|
1416
|
-
}
|
|
1417
|
-
function anyBeginMarkerRe(block) {
|
|
1418
|
-
return new RegExp(`<!--\\s*recall:managed:${escapeRegExp(block.name)}:begin(?:\\s+v\\d+)?\\s*-->`);
|
|
1419
|
-
}
|
|
1420
|
-
function blockRe(block) {
|
|
1421
|
-
return blockReForName(block.name);
|
|
1422
|
-
}
|
|
1423
|
-
function blockReForName(name) {
|
|
1424
|
-
return new RegExp(
|
|
1425
|
-
`<!--\\s*recall:managed:${escapeRegExp(name)}:begin(?:\\s+v\\d+)?\\s*-->[\\s\\S]*?<!--\\s*recall:managed:${escapeRegExp(name)}:end\\s*-->\\n?`,
|
|
1426
|
-
"g"
|
|
1427
|
-
);
|
|
1428
|
-
}
|
|
1429
|
-
function renderManagedBlock(block) {
|
|
1430
|
-
return `${beginMarker(block)}
|
|
1431
|
-
${block.body}
|
|
1432
|
-
${endMarker(block)}
|
|
1433
|
-
`;
|
|
1434
|
-
}
|
|
1435
|
-
function installManagedRules(targetPath, block) {
|
|
1436
|
-
const desired = renderManagedBlock(block);
|
|
1437
|
-
const existing = existsSync3(targetPath) ? readFileSync3(targetPath, "utf-8") : "";
|
|
1438
|
-
if (existing.includes(beginMarker(block)) && existing.includes(block.body)) {
|
|
1439
|
-
return {
|
|
1440
|
-
ok: true,
|
|
1441
|
-
changed: false,
|
|
1442
|
-
config_path: targetPath,
|
|
1443
|
-
message: `Recall rules already current in ${targetPath}`
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
const next = block.ownsFile ? `${block.preamble ?? ""}${desired}` : mergeIntoExisting(existing, desired, block);
|
|
1447
|
-
mkdirSync3(dirname3(targetPath), { recursive: true });
|
|
1448
|
-
writeFileSync3(targetPath, next);
|
|
1449
|
-
return {
|
|
1450
|
-
ok: true,
|
|
1451
|
-
changed: true,
|
|
1452
|
-
config_path: targetPath,
|
|
1453
|
-
message: existing.length === 0 ? `Created ${targetPath} with Recall rules` : `Updated Recall rules in ${targetPath}`
|
|
1454
|
-
};
|
|
1455
|
-
}
|
|
1456
|
-
function uninstallManagedRules(targetPath, block) {
|
|
1457
|
-
if (!existsSync3(targetPath)) {
|
|
1458
|
-
return { ok: true, changed: false, config_path: targetPath, message: `${targetPath} not present` };
|
|
1459
|
-
}
|
|
1460
|
-
const existing = readFileSync3(targetPath, "utf-8");
|
|
1461
|
-
const hasCurrent = anyBeginMarkerRe(block).test(existing);
|
|
1462
|
-
const hasLegacy = findLegacyBlock(existing, block) !== null;
|
|
1463
|
-
if (!hasCurrent && !hasLegacy) {
|
|
1464
|
-
return {
|
|
1465
|
-
ok: true,
|
|
1466
|
-
changed: false,
|
|
1467
|
-
config_path: targetPath,
|
|
1468
|
-
message: `No Recall-managed rules in ${targetPath}`
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
const stripped = removeLegacyBlocks(existing.replace(blockRe(block), ""), block).replace(/\n{3,}/g, "\n\n");
|
|
1472
|
-
if (block.ownsFile && stripped.trim() === (block.preamble ?? "").trim()) {
|
|
1473
|
-
rmSync2(targetPath, { force: true });
|
|
1474
|
-
return { ok: true, changed: true, config_path: targetPath, message: `Removed ${targetPath}` };
|
|
1475
|
-
}
|
|
1476
|
-
writeFileSync3(targetPath, stripped.trim().length === 0 ? "" : ensureTrailingNewline(stripped));
|
|
1477
|
-
return {
|
|
1478
|
-
ok: true,
|
|
1479
|
-
changed: true,
|
|
1480
|
-
config_path: targetPath,
|
|
1481
|
-
message: `Removed Recall rules from ${targetPath}`
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
function checkManagedRules(targetPath, block) {
|
|
1485
|
-
if (!existsSync3(targetPath)) {
|
|
1486
|
-
return { status: "absent_no_file", config_path: targetPath };
|
|
1487
|
-
}
|
|
1488
|
-
const content = readFileSync3(targetPath, "utf-8");
|
|
1489
|
-
if (!anyBeginMarkerRe(block).test(content)) {
|
|
1490
|
-
if (findLegacyBlock(content, block)) {
|
|
1491
|
-
return { status: "stale", config_path: targetPath };
|
|
1492
|
-
}
|
|
1493
|
-
return { status: "missing", config_path: targetPath };
|
|
1494
|
-
}
|
|
1495
|
-
return {
|
|
1496
|
-
status: content.includes(beginMarker(block)) && content.includes(block.body) ? "current" : "stale",
|
|
1497
|
-
config_path: targetPath
|
|
1498
|
-
};
|
|
1499
|
-
}
|
|
1500
|
-
function mergeIntoExisting(existing, desired, block) {
|
|
1501
|
-
if (anyBeginMarkerRe(block).test(existing)) {
|
|
1502
|
-
return existing.replace(blockRe(block), desired);
|
|
1503
|
-
}
|
|
1504
|
-
const legacy = findLegacyBlock(existing, block);
|
|
1505
|
-
if (legacy) return existing.replace(legacy, desired);
|
|
1506
|
-
if (existing.length === 0) return desired;
|
|
1507
|
-
const separator = existing.endsWith("\n\n") ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
|
|
1508
|
-
return `${existing}${separator}${desired}`;
|
|
1509
|
-
}
|
|
1510
|
-
function findLegacyBlock(existing, block) {
|
|
1511
|
-
for (const name of block.legacyNames ?? []) {
|
|
1512
|
-
for (const match of existing.matchAll(blockReForName(name))) {
|
|
1513
|
-
if (match[0].includes(block.body)) return match[0];
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
return null;
|
|
1517
|
-
}
|
|
1518
|
-
function removeLegacyBlocks(existing, block) {
|
|
1519
|
-
let next = existing;
|
|
1520
|
-
let match = findLegacyBlock(next, block);
|
|
1521
|
-
while (match) {
|
|
1522
|
-
next = next.replace(match, "");
|
|
1523
|
-
match = findLegacyBlock(next, block);
|
|
1524
|
-
}
|
|
1525
|
-
return next;
|
|
1526
|
-
}
|
|
1527
|
-
function ensureTrailingNewline(content) {
|
|
1528
|
-
return content.endsWith("\n") ? content : `${content}
|
|
1529
|
-
`;
|
|
1530
|
-
}
|
|
1531
|
-
function escapeRegExp(value) {
|
|
1532
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1533
|
-
}
|
|
1534
|
-
function buildRecallRulesBody(toolLabel) {
|
|
1535
|
-
return `## Recall (managed by \`recall setup\` \u2014 do not edit by hand)
|
|
1536
|
-
|
|
1537
|
-
Recall is the single source of truth for durable memory across agents and sessions. It is wired into ${toolLabel} through the \`recall\` MCP server.
|
|
1538
|
-
|
|
1539
|
-
- ${toolLabel} has no lifecycle hooks, so capture is **manual**: use your semantic understanding in any language. When the user expresses a durable correction, standing preference, default, or repo/team convention, call \`capture_correction\` with the concise user statement\u2014even without special keywords. Do not capture an instruction limited to the current task.
|
|
1540
|
-
- Before non-trivial work in a repo, call \`query\` to pull relevant memories. Do it again when you move to an unfamiliar area.
|
|
1541
|
-
- A memory that turns out to be wrong or outdated: \`reject\` it. One that proves right: \`confirm\` it.
|
|
1542
|
-
- Say so, in one short clause, whenever a reply is shaped by a memory you recalled or you store one. Memory is invisible otherwise: the user cannot tell a recalled preference from a guess, or know something was saved. Keep it brief, never a list of everything retrieved.
|
|
1543
|
-
- Do not keep a second memory store (scratch note files, tool-native memory) \u2014 it drifts from Recall.
|
|
1544
|
-
|
|
1545
|
-
Reinstall: \`recall setup\`. Remove: \`recall setup --uninstall-hooks\`.`;
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
// src/agents/hookless.ts
|
|
1549
|
-
function createHooklessAdapter(spec) {
|
|
1550
|
-
const configPath2 = (options = {}) => spec.mcpTarget(options).configPath;
|
|
1551
|
-
return {
|
|
1552
|
-
name: spec.name,
|
|
1553
|
-
configPath: configPath2,
|
|
1554
|
-
detect(options = {}) {
|
|
1555
|
-
const byCommand = (spec.commands ?? []).some((command) => hasCommand(command));
|
|
1556
|
-
const byPath = (spec.markerPaths?.(options) ?? []).some((path) => existsSync4(path));
|
|
1557
|
-
return byCommand || byPath ? "installed" : "not-installed";
|
|
1558
|
-
},
|
|
1559
|
-
capabilities() {
|
|
1560
|
-
return {
|
|
1561
|
-
// No hook API: nothing observes prompts, tools or session lifecycle.
|
|
1562
|
-
supports: [],
|
|
1563
|
-
supports_hook_install: false,
|
|
1564
|
-
supports_mcp_fallback: true
|
|
1565
|
-
};
|
|
1566
|
-
},
|
|
1567
|
-
installHooks(_profile) {
|
|
1568
|
-
return {
|
|
1569
|
-
ok: false,
|
|
1570
|
-
changed: false,
|
|
1571
|
-
config_path: null,
|
|
1572
|
-
message: `${spec.label} exposes no hook API \u2014 use writeMcpFallback() and installRules() instead`
|
|
1573
|
-
};
|
|
1574
|
-
},
|
|
1575
|
-
uninstallHooks() {
|
|
1576
|
-
return {
|
|
1577
|
-
ok: true,
|
|
1578
|
-
changed: false,
|
|
1579
|
-
config_path: null,
|
|
1580
|
-
message: `${spec.label} has no Recall-managed hooks`
|
|
1581
|
-
};
|
|
1582
|
-
},
|
|
1583
|
-
envMapping: {},
|
|
1584
|
-
writeMcpFallback(options = {}) {
|
|
1585
|
-
const serverSpec = resolveServerSpec(options, spec.label);
|
|
1586
|
-
if ("error" in serverSpec) {
|
|
1587
|
-
return { ok: false, changed: false, config_path: null, message: serverSpec.error };
|
|
1588
|
-
}
|
|
1589
|
-
return writeMcpServerEntry(spec.mcpTarget(options), serverSpec);
|
|
1590
|
-
},
|
|
1591
|
-
removeMcpFallback(options = {}) {
|
|
1592
|
-
return removeMcpServerEntry(spec.mcpTarget(options));
|
|
1593
|
-
},
|
|
1594
|
-
hasMcpRegistration(options = {}) {
|
|
1595
|
-
return hasMcpServerEntry(spec.mcpTarget(options));
|
|
1596
|
-
},
|
|
1597
|
-
installRules(options = {}) {
|
|
1598
|
-
return installManagedRules(rulesTarget(spec, options), spec.rulesBlock);
|
|
1599
|
-
},
|
|
1600
|
-
uninstallRules(options = {}) {
|
|
1601
|
-
return uninstallManagedRules(rulesTarget(spec, options), spec.rulesBlock);
|
|
1602
|
-
},
|
|
1603
|
-
checkRules(options = {}) {
|
|
1604
|
-
return checkManagedRules(rulesTarget(spec, options), spec.rulesBlock);
|
|
1605
|
-
},
|
|
1606
|
-
rulesScope: spec.rulesScope
|
|
1607
|
-
};
|
|
1608
|
-
}
|
|
1609
|
-
function rulesTarget(spec, options) {
|
|
1610
|
-
return options.configPath ?? spec.rulesPath(options);
|
|
1611
|
-
}
|
|
1612
|
-
function resolveServerSpec(options, label) {
|
|
1613
|
-
const nodePath = options.nodePath ?? process.env.RECALL_NODE_PATH ?? process.execPath;
|
|
1614
|
-
const mcpPath = options.mcpPath ?? process.env.RECALL_MCP_PATH;
|
|
1615
|
-
if (!mcpPath) {
|
|
1616
|
-
return {
|
|
1617
|
-
error: `Unable to resolve the Recall MCP entrypoint for ${label} \u2014 pass mcpPath or set RECALL_MCP_PATH`
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1620
|
-
return { nodePath, mcpPath };
|
|
1621
|
-
}
|
|
1622
|
-
function projectPath(options, ...segments) {
|
|
1623
|
-
return resolve2(options.cwd ?? process.cwd(), ...segments);
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
// src/agents/cursor.ts
|
|
1627
|
-
var LABEL = "Cursor";
|
|
1628
|
-
function cursorHome(options = {}) {
|
|
1629
|
-
return join3(options.homeDir ?? resolveUserHomeDir(), ".cursor");
|
|
1630
|
-
}
|
|
1631
|
-
function cursorGlobalMcpPath(options = {}) {
|
|
1632
|
-
return join3(cursorHome(options), "mcp.json");
|
|
1633
|
-
}
|
|
1634
|
-
function cursorProjectMcpPath(options = {}) {
|
|
1635
|
-
return projectPath(options, ".cursor", "mcp.json");
|
|
1636
|
-
}
|
|
1637
|
-
function cursorRulesPath(options = {}) {
|
|
1638
|
-
return projectPath(options, ".cursor", "rules", "recall.mdc");
|
|
1639
|
-
}
|
|
1640
|
-
var CURSOR_MDC_FRONTMATTER = `---
|
|
1641
|
-
description: Route durable memory through the Recall MCP server
|
|
1642
|
-
alwaysApply: true
|
|
1643
|
-
---
|
|
1644
|
-
|
|
1645
|
-
`;
|
|
1646
|
-
var cursorAdapter = createHooklessAdapter({
|
|
1647
|
-
name: "cursor",
|
|
1648
|
-
label: LABEL,
|
|
1649
|
-
commands: ["cursor"],
|
|
1650
|
-
markerPaths: (options) => [cursorHome(options)],
|
|
1651
|
-
mcpTarget: (options) => ({
|
|
1652
|
-
configPath: options.configPath ?? (options.scope === "project" ? cursorProjectMcpPath(options) : cursorGlobalMcpPath(options)),
|
|
1653
|
-
containerKey: "mcpServers",
|
|
1654
|
-
buildEntry: commandArgsEntry
|
|
1655
|
-
}),
|
|
1656
|
-
rulesPath: (options) => cursorRulesPath(options),
|
|
1657
|
-
rulesBlock: {
|
|
1658
|
-
name: "cursor-memory",
|
|
1659
|
-
legacyNames: ["memory"],
|
|
1660
|
-
version: 1,
|
|
1661
|
-
body: buildRecallRulesBody(LABEL),
|
|
1662
|
-
ownsFile: true,
|
|
1663
|
-
preamble: CURSOR_MDC_FRONTMATTER
|
|
1664
|
-
},
|
|
1665
|
-
rulesScope: "project"
|
|
1666
|
-
});
|
|
1667
|
-
|
|
1668
|
-
// src/agents/gemini-cli.ts
|
|
1669
|
-
init_define_RECALL_BUILD_INFO();
|
|
1670
|
-
var geminiCliAdapter = {
|
|
1671
|
-
name: "gemini-cli",
|
|
1672
|
-
configPath() {
|
|
1673
|
-
return "";
|
|
1674
|
-
},
|
|
1675
|
-
detect() {
|
|
1676
|
-
return "not-installed";
|
|
1677
|
-
},
|
|
1678
|
-
capabilities() {
|
|
1679
|
-
return {
|
|
1680
|
-
supports: ["prompt_submitted", "tool_invoked", "session_ended"],
|
|
1681
|
-
supports_hook_install: false,
|
|
1682
|
-
supports_mcp_fallback: true
|
|
1683
|
-
};
|
|
1684
|
-
},
|
|
1685
|
-
installHooks(_profile) {
|
|
1686
|
-
throw new Error("Gemini CLI hook installation not implemented yet.");
|
|
1687
|
-
},
|
|
1688
|
-
uninstallHooks() {
|
|
1689
|
-
throw new Error("Gemini CLI hook removal not implemented yet.");
|
|
1690
|
-
},
|
|
1691
|
-
envMapping: {
|
|
1692
|
-
prompt_submitted: {
|
|
1693
|
-
prompt: "text",
|
|
1694
|
-
session_id: "session_id"
|
|
1695
|
-
},
|
|
1696
|
-
tool_invoked: {
|
|
1697
|
-
tool_name: "name",
|
|
1698
|
-
session_id: "session_id"
|
|
1699
|
-
},
|
|
1700
|
-
session_ended: {
|
|
1701
|
-
session_id: "session_id",
|
|
1702
|
-
reason: "reason"
|
|
1703
|
-
}
|
|
1704
|
-
},
|
|
1705
|
-
writeMcpFallback() {
|
|
1706
|
-
throw new Error("Gemini CLI MCP fallback wiring not implemented yet.");
|
|
1707
|
-
}
|
|
1708
|
-
};
|
|
1709
|
-
|
|
1710
|
-
// src/agents/github-copilot.ts
|
|
1711
|
-
init_define_RECALL_BUILD_INFO();
|
|
1712
|
-
import { join as join4 } from "path";
|
|
1713
|
-
var LABEL2 = "GitHub Copilot";
|
|
1714
|
-
function copilotHome(options = {}) {
|
|
1715
|
-
if (options.homeDir) return join4(options.homeDir, ".copilot");
|
|
1716
|
-
return process.env.COPILOT_HOME ?? join4(resolveUserHomeDir(), ".copilot");
|
|
1717
|
-
}
|
|
1718
|
-
function copilotMcpConfigPath(options = {}) {
|
|
1719
|
-
return join4(copilotHome(options), "mcp-config.json");
|
|
1720
|
-
}
|
|
1721
|
-
function copilotInstructionsPath(options = {}) {
|
|
1722
|
-
return projectPath(options, ".github", "copilot-instructions.md");
|
|
1723
|
-
}
|
|
1724
|
-
var githubCopilotAdapter = createHooklessAdapter({
|
|
1725
|
-
name: "github-copilot",
|
|
1726
|
-
label: LABEL2,
|
|
1727
|
-
commands: ["copilot"],
|
|
1728
|
-
markerPaths: (options) => [copilotHome(options)],
|
|
1729
|
-
mcpTarget: (options) => ({
|
|
1730
|
-
configPath: options.configPath ?? copilotMcpConfigPath(options),
|
|
1731
|
-
containerKey: "mcpServers",
|
|
1732
|
-
buildEntry: copilotEntry
|
|
1733
|
-
}),
|
|
1734
|
-
rulesPath: (options) => copilotInstructionsPath(options),
|
|
1735
|
-
rulesBlock: {
|
|
1736
|
-
name: "github-copilot-memory",
|
|
1737
|
-
legacyNames: ["memory"],
|
|
1738
|
-
version: 1,
|
|
1739
|
-
body: buildRecallRulesBody(LABEL2)
|
|
1740
|
-
},
|
|
1741
|
-
rulesScope: "project"
|
|
1742
|
-
});
|
|
1743
|
-
|
|
1744
|
-
// src/agents/opencode.ts
|
|
1745
|
-
init_define_RECALL_BUILD_INFO();
|
|
1746
|
-
import { join as join5 } from "path";
|
|
1747
|
-
var LABEL3 = "opencode";
|
|
1748
|
-
function opencodeConfigDir(options = {}) {
|
|
1749
|
-
return join5(options.homeDir ?? resolveUserHomeDir(), ".config", "opencode");
|
|
1750
|
-
}
|
|
1751
|
-
function opencodeConfigPath(options = {}) {
|
|
1752
|
-
return join5(opencodeConfigDir(options), "opencode.json");
|
|
1753
|
-
}
|
|
1754
|
-
function opencodeAgentsPath(options = {}) {
|
|
1755
|
-
return join5(opencodeConfigDir(options), "AGENTS.md");
|
|
1756
|
-
}
|
|
1757
|
-
var opencodeAdapter = createHooklessAdapter({
|
|
1758
|
-
name: "opencode",
|
|
1759
|
-
label: LABEL3,
|
|
1760
|
-
commands: ["opencode"],
|
|
1761
|
-
markerPaths: (options) => [opencodeConfigDir(options)],
|
|
1762
|
-
mcpTarget: (options) => ({
|
|
1763
|
-
configPath: options.configPath ?? opencodeConfigPath(options),
|
|
1764
|
-
// opencode nests servers directly under "mcp", not "mcpServers".
|
|
1765
|
-
containerKey: "mcp",
|
|
1766
|
-
buildEntry: opencodeEntry
|
|
1767
|
-
}),
|
|
1768
|
-
rulesPath: (options) => opencodeAgentsPath(options),
|
|
1769
|
-
rulesBlock: {
|
|
1770
|
-
name: "opencode-memory",
|
|
1771
|
-
legacyNames: ["memory"],
|
|
1772
|
-
version: 1,
|
|
1773
|
-
body: buildRecallRulesBody(LABEL3)
|
|
1774
|
-
},
|
|
1775
|
-
rulesScope: "global"
|
|
1776
|
-
});
|
|
1777
|
-
|
|
1778
|
-
// src/agents/qwen.ts
|
|
1779
|
-
init_define_RECALL_BUILD_INFO();
|
|
1780
|
-
var qwenAdapter = {
|
|
1781
|
-
name: "qwen",
|
|
1782
|
-
configPath() {
|
|
1783
|
-
return "";
|
|
1784
|
-
},
|
|
1785
|
-
detect() {
|
|
1786
|
-
return "not-installed";
|
|
1787
|
-
},
|
|
1788
|
-
capabilities() {
|
|
1789
|
-
return {
|
|
1790
|
-
supports: ["prompt_submitted", "tool_invoked", "session_ended"],
|
|
1791
|
-
supports_hook_install: false,
|
|
1792
|
-
supports_mcp_fallback: true
|
|
1793
|
-
};
|
|
1794
|
-
},
|
|
1795
|
-
installHooks(_profile) {
|
|
1796
|
-
throw new Error("Qwen hook installation not implemented yet.");
|
|
1797
|
-
},
|
|
1798
|
-
uninstallHooks() {
|
|
1799
|
-
throw new Error("Qwen hook removal not implemented yet.");
|
|
1800
|
-
},
|
|
1801
|
-
envMapping: {
|
|
1802
|
-
prompt_submitted: {
|
|
1803
|
-
prompt: "text",
|
|
1804
|
-
session_id: "session_id"
|
|
1805
|
-
},
|
|
1806
|
-
tool_invoked: {
|
|
1807
|
-
tool_name: "name",
|
|
1808
|
-
session_id: "session_id"
|
|
1809
|
-
},
|
|
1810
|
-
session_ended: {
|
|
1811
|
-
session_id: "session_id",
|
|
1812
|
-
reason: "reason"
|
|
1813
|
-
}
|
|
1814
|
-
},
|
|
1815
|
-
writeMcpFallback() {
|
|
1816
|
-
throw new Error("Qwen MCP fallback wiring not implemented yet.");
|
|
1817
|
-
}
|
|
1818
|
-
};
|
|
1819
|
-
|
|
1820
|
-
// src/agents/windsurf.ts
|
|
1821
|
-
init_define_RECALL_BUILD_INFO();
|
|
1822
|
-
import { join as join6 } from "path";
|
|
1823
|
-
var LABEL4 = "Windsurf";
|
|
1824
|
-
function windsurfConfigDir(options = {}) {
|
|
1825
|
-
return join6(options.homeDir ?? resolveUserHomeDir(), ".codeium", "windsurf");
|
|
1826
|
-
}
|
|
1827
|
-
function windsurfMcpConfigPath(options = {}) {
|
|
1828
|
-
return join6(windsurfConfigDir(options), "mcp_config.json");
|
|
1829
|
-
}
|
|
1830
|
-
function windsurfGlobalRulesPath(options = {}) {
|
|
1831
|
-
return join6(windsurfConfigDir(options), "memories", "global_rules.md");
|
|
1832
|
-
}
|
|
1833
|
-
var windsurfAdapter = createHooklessAdapter({
|
|
1834
|
-
name: "windsurf",
|
|
1835
|
-
label: LABEL4,
|
|
1836
|
-
commands: ["windsurf"],
|
|
1837
|
-
markerPaths: (options) => [windsurfConfigDir(options)],
|
|
1838
|
-
mcpTarget: (options) => ({
|
|
1839
|
-
configPath: options.configPath ?? windsurfMcpConfigPath(options),
|
|
1840
|
-
containerKey: "mcpServers",
|
|
1841
|
-
buildEntry: commandArgsEntry
|
|
1842
|
-
}),
|
|
1843
|
-
rulesPath: (options) => windsurfGlobalRulesPath(options),
|
|
1844
|
-
rulesBlock: {
|
|
1845
|
-
name: "windsurf-memory",
|
|
1846
|
-
legacyNames: ["memory"],
|
|
1847
|
-
version: 1,
|
|
1848
|
-
body: buildRecallRulesBody(LABEL4)
|
|
1849
|
-
},
|
|
1850
|
-
rulesScope: "global"
|
|
1851
|
-
});
|
|
1852
|
-
|
|
1853
|
-
// src/agents/types.ts
|
|
1854
|
-
init_define_RECALL_BUILD_INFO();
|
|
1855
|
-
|
|
1856
|
-
// src/agents/index.ts
|
|
1857
|
-
var adapters = {
|
|
1858
|
-
"claude-code": claudeCodeAdapter,
|
|
1859
|
-
codex: codexAdapter,
|
|
1860
|
-
"github-copilot": githubCopilotAdapter,
|
|
1861
|
-
opencode: opencodeAdapter,
|
|
1862
|
-
cursor: cursorAdapter,
|
|
1863
|
-
windsurf: windsurfAdapter,
|
|
1864
|
-
"gemini-cli": geminiCliAdapter,
|
|
1865
|
-
qwen: qwenAdapter
|
|
1866
|
-
};
|
|
1867
|
-
var hooklessAgents = [
|
|
1868
|
-
"github-copilot",
|
|
1869
|
-
"opencode",
|
|
1870
|
-
"cursor",
|
|
1871
|
-
"windsurf"
|
|
1872
|
-
];
|
|
1873
|
-
function listAgentNames() {
|
|
1874
|
-
return Object.keys(adapters);
|
|
1875
|
-
}
|
|
1876
|
-
function isHooklessAgent(name) {
|
|
1877
|
-
return hooklessAgents.includes(name);
|
|
1878
|
-
}
|
|
1879
|
-
function resolveAdapter(name) {
|
|
1880
|
-
const adapter = adapters[name];
|
|
1881
|
-
if (adapter) {
|
|
1882
|
-
return adapter;
|
|
1883
|
-
}
|
|
1884
|
-
throw new Error(
|
|
1885
|
-
`Unknown agent adapter: ${name}. Supported adapters: ${listAgentNames().join(", ")}. Reserved v2 stubs: gemini-cli, qwen.`
|
|
1886
|
-
);
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
// src/setup/local.ts
|
|
1890
|
-
function resolveRuntimePaths(appPath) {
|
|
1891
|
-
const override = process.env.RECALL_RUNTIME_DIR;
|
|
1892
|
-
if (override) {
|
|
1893
|
-
return {
|
|
1894
|
-
appPath: override,
|
|
1895
|
-
runtimeNodePath: join7(override, "bin", "node"),
|
|
1896
|
-
runtimeCliPath: join7(override, "dist", "cli.js"),
|
|
1897
|
-
runtimeMcpPath: join7(override, "dist", "mcp.js")
|
|
1898
|
-
};
|
|
1899
|
-
}
|
|
1900
|
-
if (appPath || process.platform === "darwin" && existsSync5("/Applications/Recall.app")) {
|
|
1901
|
-
const resolvedAppPath = appPath ?? "/Applications/Recall.app";
|
|
1902
|
-
const runtimeRoot = join7(resolvedAppPath, "Contents", "Resources", "Runtime");
|
|
1903
|
-
return {
|
|
1904
|
-
appPath: resolvedAppPath,
|
|
1905
|
-
runtimeNodePath: join7(runtimeRoot, "bin", "node"),
|
|
1906
|
-
runtimeCliPath: join7(runtimeRoot, "dist", "cli.js"),
|
|
1907
|
-
runtimeMcpPath: join7(runtimeRoot, "dist", "mcp.js")
|
|
1908
|
-
};
|
|
1909
|
-
}
|
|
1910
|
-
const distDir = dirname4(fileURLToPath2(import.meta.url));
|
|
1911
|
-
return {
|
|
1912
|
-
appPath: distDir,
|
|
1913
|
-
runtimeNodePath: process.execPath,
|
|
1914
|
-
runtimeCliPath: join7(distDir, "cli.js"),
|
|
1915
|
-
runtimeMcpPath: join7(distDir, "mcp.js")
|
|
1916
|
-
};
|
|
1917
|
-
}
|
|
1918
|
-
function runLocalSetup(opts = {}) {
|
|
1919
|
-
const targetCodex = opts.codex ?? true;
|
|
1920
|
-
const targetClaude = opts.claude ?? true;
|
|
1921
|
-
const result = runRecallSetup({
|
|
1922
|
-
appPath: opts.appPath,
|
|
1923
|
-
agent: [
|
|
1924
|
-
...targetCodex ? ["codex"] : [],
|
|
1925
|
-
...targetClaude ? ["claude-code"] : []
|
|
1926
|
-
],
|
|
1927
|
-
hooksOnly: false,
|
|
1928
|
-
mcpOnly: false,
|
|
1929
|
-
scope: "global",
|
|
1930
|
-
promptInjection: opts.promptInjection,
|
|
1931
|
-
claudeMd: opts.claudeMd
|
|
1932
|
-
});
|
|
1933
|
-
const codex = result.agents.find((agent) => agent.agent === "codex");
|
|
1934
|
-
const claude = result.agents.find((agent) => agent.agent === "claude-code");
|
|
1935
|
-
return {
|
|
1936
|
-
appPath: result.appPath,
|
|
1937
|
-
runtimeNodePath: result.runtimeNodePath,
|
|
1938
|
-
runtimeCliPath: result.runtimeCliPath,
|
|
1939
|
-
runtimeMcpPath: result.runtimeMcpPath,
|
|
1940
|
-
codex: codex?.mcp ?? skipped("skipped"),
|
|
1941
|
-
claude: claude?.mcp ?? skipped("skipped"),
|
|
1942
|
-
codex_hooks: codex?.hooks ?? skipped("skipped"),
|
|
1943
|
-
claude_hooks: claude?.hooks ?? skipped("skipped"),
|
|
1944
|
-
claude_md: claude?.claude_md ?? skipped("skipped")
|
|
1945
|
-
};
|
|
1946
|
-
}
|
|
1947
|
-
function runRecallSetup(opts = {}) {
|
|
1948
|
-
const scope = opts.scope ?? "global";
|
|
1949
|
-
const dryRun = opts.dryRun ?? false;
|
|
1950
|
-
const hooksOnly = opts.hooksOnly ?? false;
|
|
1951
|
-
const mcpOnly = opts.mcpOnly ?? false;
|
|
1952
|
-
const uninstallHooks = opts.uninstallHooks ?? false;
|
|
1953
|
-
const runner = opts.runner ?? defaultRunner;
|
|
1954
|
-
const paths = resolveRuntimePaths(opts.appPath);
|
|
1955
|
-
if (!existsSync5(paths.runtimeNodePath)) {
|
|
1956
|
-
throw new Error(`Node runtime not found at ${paths.runtimeNodePath}`);
|
|
1957
|
-
}
|
|
1958
|
-
if (!existsSync5(paths.runtimeCliPath)) {
|
|
1959
|
-
throw new Error(`Recall CLI entry not found at ${paths.runtimeCliPath}`);
|
|
1960
|
-
}
|
|
1961
|
-
if (!existsSync5(paths.runtimeMcpPath)) {
|
|
1962
|
-
throw new Error(`Recall MCP entry not found at ${paths.runtimeMcpPath}`);
|
|
1963
|
-
}
|
|
1964
|
-
const targetAgents = resolveTargetAgents(opts.agent);
|
|
1965
|
-
const cwd = resolve3(opts.cwd ?? process.cwd());
|
|
1966
|
-
const claudeMdEnabled = opts.claudeMd ?? true;
|
|
1967
|
-
const agents = targetAgents.map(
|
|
1968
|
-
(agent) => setupAgent(agent, {
|
|
1969
|
-
cwd,
|
|
1970
|
-
dryRun,
|
|
1971
|
-
hooksOnly,
|
|
1972
|
-
mcpOnly,
|
|
1973
|
-
paths,
|
|
1974
|
-
runner,
|
|
1975
|
-
scope,
|
|
1976
|
-
uninstallHooks,
|
|
1977
|
-
promptInjection: opts.promptInjection,
|
|
1978
|
-
claudeMd: claudeMdEnabled
|
|
1979
|
-
})
|
|
1980
|
-
);
|
|
1981
|
-
return {
|
|
1982
|
-
...paths,
|
|
1983
|
-
scope,
|
|
1984
|
-
dry_run: dryRun,
|
|
1985
|
-
hooks_only: hooksOnly,
|
|
1986
|
-
mcp_only: mcpOnly,
|
|
1987
|
-
uninstall_hooks: uninstallHooks,
|
|
1988
|
-
agents
|
|
1989
|
-
};
|
|
1990
|
-
}
|
|
1991
|
-
function setupAgent(agent, options) {
|
|
1992
|
-
const detected = detectAgent(agent);
|
|
1993
|
-
const hookless = isHooklessAgent(agent);
|
|
1994
|
-
const hookConfigPath = hookless ? null : resolveHookConfigPath(agent, options.scope, options.cwd);
|
|
1995
|
-
const mcp = options.hooksOnly ? skipped("hooks-only") : configureMcp(agent, options);
|
|
1996
|
-
const hooks = options.mcpOnly ? skipped("mcp-only") : hookless ? skipped(`${agent} exposes no hook API \u2014 memory routes through MCP + rules file`) : configureHooks(agent, {
|
|
1997
|
-
configPath: hookConfigPath,
|
|
1998
|
-
dryRun: options.dryRun,
|
|
1999
|
-
paths: options.paths,
|
|
2000
|
-
scope: options.scope,
|
|
2001
|
-
uninstallHooks: options.uninstallHooks,
|
|
2002
|
-
promptInjection: options.promptInjection
|
|
2003
|
-
});
|
|
2004
|
-
let rules;
|
|
2005
|
-
let rulesPath = null;
|
|
2006
|
-
if (hookless && !options.mcpOnly) {
|
|
2007
|
-
const adapter = resolveAdapter(agent);
|
|
2008
|
-
if (options.dryRun) {
|
|
2009
|
-
rules = ok(
|
|
2010
|
-
options.uninstallHooks ? "would remove Recall rules block" : "would install Recall rules block"
|
|
2011
|
-
);
|
|
2012
|
-
} else {
|
|
2013
|
-
const result = options.uninstallHooks ? adapter.uninstallRules({ cwd: options.cwd }) : adapter.installRules({ cwd: options.cwd });
|
|
2014
|
-
rules = { enabled: true, ok: result.ok, message: result.message };
|
|
2015
|
-
rulesPath = result.config_path;
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
let claudeMd;
|
|
2019
|
-
let claudeMdPath2 = null;
|
|
2020
|
-
if (agent === "claude-code" && !options.mcpOnly && options.claudeMd !== false) {
|
|
2021
|
-
if (options.dryRun) {
|
|
2022
|
-
claudeMd = ok(
|
|
2023
|
-
options.uninstallHooks ? "would remove Recall block from CLAUDE.md" : "would install Recall block into CLAUDE.md"
|
|
2024
|
-
);
|
|
2025
|
-
} else {
|
|
2026
|
-
const result = options.uninstallHooks ? uninstallClaudeCodeMemoryOverride() : installClaudeCodeMemoryOverride();
|
|
2027
|
-
claudeMd = { enabled: true, ok: result.ok, message: result.message };
|
|
2028
|
-
claudeMdPath2 = result.config_path;
|
|
2029
|
-
}
|
|
2030
|
-
} else if (agent === "claude-code" && options.claudeMd === false) {
|
|
2031
|
-
claudeMd = skipped("--no-claude-md");
|
|
2032
|
-
}
|
|
2033
|
-
return {
|
|
2034
|
-
agent,
|
|
2035
|
-
detected,
|
|
2036
|
-
mcp,
|
|
2037
|
-
hooks,
|
|
2038
|
-
hook_config_path: options.mcpOnly ? null : hookConfigPath,
|
|
2039
|
-
claude_md: claudeMd,
|
|
2040
|
-
claude_md_path: claudeMdPath2,
|
|
2041
|
-
rules,
|
|
2042
|
-
rules_path: rulesPath
|
|
2043
|
-
};
|
|
2044
|
-
}
|
|
2045
|
-
function configureMcp(agent, options) {
|
|
2046
|
-
if (isHooklessAgent(agent)) {
|
|
2047
|
-
const adapter = resolveAdapter(agent);
|
|
2048
|
-
if (adapter.detect() !== "installed") {
|
|
2049
|
-
return skipped(`${agent} not detected`);
|
|
2050
|
-
}
|
|
2051
|
-
if (options.dryRun) {
|
|
2052
|
-
return ok(`would register Recall MCP server in ${adapter.configPath()}`);
|
|
2053
|
-
}
|
|
2054
|
-
const result = adapter.writeMcpFallback({
|
|
2055
|
-
nodePath: options.paths.runtimeNodePath,
|
|
2056
|
-
mcpPath: options.paths.runtimeMcpPath,
|
|
2057
|
-
scope: options.scope,
|
|
2058
|
-
cwd: options.cwd
|
|
2059
|
-
});
|
|
2060
|
-
return { enabled: true, ok: result.ok, message: result.message };
|
|
2061
|
-
}
|
|
2062
|
-
if (agent === "gemini-cli" || agent === "qwen") {
|
|
2063
|
-
return skipped(`${agent} adapter is a reserved stub`);
|
|
2064
|
-
}
|
|
2065
|
-
if (agent === "codex") {
|
|
2066
|
-
if (!hasCommand("codex")) return skipped("codex not found on PATH");
|
|
2067
|
-
if (options.scope === "project") {
|
|
2068
|
-
return skipped("project-scoped Codex MCP not supported by Codex CLI");
|
|
2069
|
-
}
|
|
2070
|
-
const targets = resolveCodexHookTargets();
|
|
2071
|
-
if (options.dryRun) {
|
|
2072
|
-
return ok(describeCodexTargets("would configure global Codex MCP server", targets));
|
|
2073
|
-
}
|
|
2074
|
-
for (const target of targets) {
|
|
2075
|
-
const env = { ...process.env, CODEX_HOME: target.home };
|
|
2076
|
-
tryRun(options.runner, "codex", ["mcp", "remove", "recall"], { env });
|
|
2077
|
-
options.runner(
|
|
2078
|
-
"codex",
|
|
2079
|
-
["mcp", "add", "recall", "--", options.paths.runtimeNodePath, options.paths.runtimeMcpPath],
|
|
2080
|
-
{ env }
|
|
2081
|
-
);
|
|
2082
|
-
}
|
|
2083
|
-
return ok(describeCodexTargets("configured global Codex MCP server", targets));
|
|
2084
|
-
}
|
|
2085
|
-
if (!hasCommand("claude")) return skipped("claude not found on PATH");
|
|
2086
|
-
const claudeScope = options.scope === "project" ? "project" : "user";
|
|
2087
|
-
if (options.dryRun) {
|
|
2088
|
-
return ok(`would configure ${claudeScope} Claude MCP server`);
|
|
2089
|
-
}
|
|
2090
|
-
tryRun(options.runner, "claude", ["mcp", "remove", "recall", "-s", claudeScope]);
|
|
2091
|
-
options.runner("claude", ["mcp", "add", "-s", claudeScope, "recall", options.paths.runtimeNodePath, options.paths.runtimeMcpPath]);
|
|
2092
|
-
return ok(`configured ${claudeScope} Claude MCP server`);
|
|
2093
|
-
}
|
|
2094
|
-
function configureHooks(agent, options) {
|
|
2095
|
-
const codexTargets = agent === "codex" ? options.scope === "project" ? [{
|
|
2096
|
-
home: dirname4(options.configPath),
|
|
2097
|
-
configPath: options.configPath,
|
|
2098
|
-
hooksPath: join7(dirname4(options.configPath), "hooks.json")
|
|
2099
|
-
}] : resolveCodexHookTargets() : [];
|
|
2100
|
-
if (options.dryRun) {
|
|
2101
|
-
const base = options.uninstallHooks ? `would remove hooks from ${options.configPath}` : `would install hooks into ${options.configPath}${options.promptInjection === false ? " (prompt injection opt-out)" : ""}`;
|
|
2102
|
-
return ok(agent === "codex" ? describeCodexTargets(base, codexTargets) : base);
|
|
2103
|
-
}
|
|
2104
|
-
if (agent === "codex") {
|
|
2105
|
-
const results = codexTargets.map(
|
|
2106
|
-
(target) => options.uninstallHooks ? uninstallCodexHooks({ configPath: target.configPath, hooksPath: target.hooksPath }) : installCodexHooks({
|
|
2107
|
-
configPath: target.configPath,
|
|
2108
|
-
hooksPath: target.hooksPath,
|
|
2109
|
-
cliPath: options.paths.runtimeCliPath,
|
|
2110
|
-
nodePath: options.paths.runtimeNodePath,
|
|
2111
|
-
promptInjection: options.promptInjection
|
|
2112
|
-
})
|
|
2113
|
-
);
|
|
2114
|
-
const failed2 = results.filter((entry) => !entry.ok);
|
|
2115
|
-
const headline = failed2.length > 0 ? failed2[0].message : results[0]?.message ?? "no Codex home found";
|
|
2116
|
-
return {
|
|
2117
|
-
enabled: true,
|
|
2118
|
-
ok: failed2.length === 0 && results.length > 0,
|
|
2119
|
-
message: describeCodexTargets(headline, codexTargets)
|
|
2120
|
-
};
|
|
2121
|
-
}
|
|
2122
|
-
const result = options.uninstallHooks ? uninstallClaudeCodeHooks({ configPath: options.configPath }) : installClaudeCodeHooks({
|
|
2123
|
-
configPath: options.configPath,
|
|
2124
|
-
cliPath: options.paths.runtimeCliPath,
|
|
2125
|
-
nodePath: options.paths.runtimeNodePath,
|
|
2126
|
-
promptInjection: options.promptInjection
|
|
2127
|
-
});
|
|
2128
|
-
return {
|
|
2129
|
-
enabled: true,
|
|
2130
|
-
ok: result.ok,
|
|
2131
|
-
message: result.message
|
|
2132
|
-
};
|
|
2133
|
-
}
|
|
2134
|
-
function describeCodexTargets(message, targets) {
|
|
2135
|
-
if (targets.length <= 1) return message;
|
|
2136
|
-
const names = targets.map((target) => basename(target.home)).join(", ");
|
|
2137
|
-
return `${message} across ${targets.length} Codex homes (${names})`;
|
|
2138
|
-
}
|
|
2139
|
-
function resolveTargetAgents(target) {
|
|
2140
|
-
if (target && target.length > 0) {
|
|
2141
|
-
return [...new Set(target)];
|
|
2142
|
-
}
|
|
2143
|
-
return listAgentNames().filter((agent) => detectAgent(agent));
|
|
2144
|
-
}
|
|
2145
|
-
function detectAgent(agent) {
|
|
2146
|
-
if (agent === "codex") {
|
|
2147
|
-
return hasCommand("codex") || existsSync5(join7(resolveUserHomeDir(), ".codex", "config.toml"));
|
|
2148
|
-
}
|
|
2149
|
-
if (agent === "claude-code") {
|
|
2150
|
-
return hasCommand("claude") || existsSync5(join7(resolveUserHomeDir(), ".claude", "settings.json"));
|
|
2151
|
-
}
|
|
2152
|
-
return resolveAdapter(agent).detect() === "installed";
|
|
2153
|
-
}
|
|
2154
|
-
function resolveHookConfigPath(agent, scope, cwd) {
|
|
2155
|
-
if (scope === "project") {
|
|
2156
|
-
return agent === "codex" ? join7(cwd, ".codex", "config.toml") : join7(cwd, ".claude", "settings.json");
|
|
2157
|
-
}
|
|
2158
|
-
return agent === "codex" ? join7(resolveUserHomeDir(), ".codex", "config.toml") : join7(resolveUserHomeDir(), ".claude", "settings.json");
|
|
2159
|
-
}
|
|
2160
|
-
function defaultRunner(command, args, options) {
|
|
2161
|
-
execFileSync2(command, args, { ...stdioOpts(), ...options?.env ? { env: options.env } : {} });
|
|
2162
|
-
}
|
|
2163
|
-
function tryRun(runner, command, args, options) {
|
|
2164
|
-
try {
|
|
2165
|
-
runner(command, args, options);
|
|
2166
|
-
} catch {
|
|
2167
|
-
return;
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
function stdioOpts() {
|
|
2171
|
-
return {
|
|
2172
|
-
stdio: "ignore"
|
|
2173
|
-
};
|
|
2174
|
-
}
|
|
2175
|
-
function ok(message) {
|
|
2176
|
-
return { enabled: true, ok: true, message };
|
|
2177
|
-
}
|
|
2178
|
-
function skipped(message) {
|
|
2179
|
-
return { enabled: false, ok: false, message };
|
|
2180
|
-
}
|
|
2181
|
-
|
|
2182
|
-
// src/cli.ts
|
|
2183
|
-
import { createRequire } from "module";
|
|
2184
|
-
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2185
|
-
|
|
2186
|
-
// src/doctor/report.ts
|
|
2187
|
-
init_define_RECALL_BUILD_INFO();
|
|
2188
|
-
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "fs";
|
|
2189
|
-
import { basename as basename2, join as join10 } from "path";
|
|
2190
|
-
import Database2 from "better-sqlite3";
|
|
2191
|
-
|
|
2192
|
-
// src/daemon/launchd.ts
|
|
2193
|
-
init_define_RECALL_BUILD_INFO();
|
|
2194
|
-
import { chmodSync, existsSync as existsSync6, mkdirSync as mkdirSync4, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
2195
|
-
import { homedir } from "os";
|
|
2196
|
-
import { dirname as dirname5, join as join8, resolve as resolve4 } from "path";
|
|
2197
|
-
import { execFileSync as execFileSync3 } from "child_process";
|
|
2198
|
-
|
|
2199
|
-
// src/daemon/provider-env.ts
|
|
2200
|
-
init_define_RECALL_BUILD_INFO();
|
|
2201
|
-
var DAEMON_PROVIDER_ENV_KEYS = [
|
|
2202
|
-
"OPENAI_API_KEY",
|
|
2203
|
-
"ANTHROPIC_API_KEY",
|
|
2204
|
-
"AZURE_OPENAI_ENDPOINT",
|
|
2205
|
-
"AZURE_OPENAI_DEPLOYMENT",
|
|
2206
|
-
"AZURE_OPENAI_API_VERSION",
|
|
2207
|
-
"AZURE_OPENAI_API_KEY"
|
|
2208
|
-
];
|
|
2209
|
-
function resolveDaemonProviderEnvironment(current, installed = {}) {
|
|
2210
|
-
const resolved = {};
|
|
2211
|
-
for (const key of DAEMON_PROVIDER_ENV_KEYS) {
|
|
2212
|
-
const value = current[key] ?? installed[key];
|
|
2213
|
-
if (value && value.trim().length > 0) {
|
|
2214
|
-
resolved[key] = value;
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
return resolved;
|
|
2218
|
-
}
|
|
2219
|
-
function readDaemonProviderEnvironment(environment) {
|
|
2220
|
-
const installed = {};
|
|
2221
|
-
for (const key of DAEMON_PROVIDER_ENV_KEYS) {
|
|
2222
|
-
const value = environment[key];
|
|
2223
|
-
if (typeof value === "string" && value.trim().length > 0) {
|
|
2224
|
-
installed[key] = value;
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
return installed;
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
// src/daemon/launchd.ts
|
|
2231
|
-
var DEFAULT_LABEL = "com.recall.daemon";
|
|
2232
|
-
function installLaunchAgent(opts = {}) {
|
|
2233
|
-
assertDarwin();
|
|
2234
|
-
const cfg = resolveConfig(opts);
|
|
2235
|
-
mkdirSync4(dirname5(cfg.plistPath), { recursive: true });
|
|
2236
|
-
mkdirSync4(dirname5(cfg.stdoutPath), { recursive: true });
|
|
2237
|
-
writeFileSync4(cfg.plistPath, renderPlist(cfg), { mode: 384 });
|
|
2238
|
-
chmodSync(cfg.plistPath, 384);
|
|
2239
|
-
tryRun2("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
2240
|
-
execFileSync3("launchctl", ["bootstrap", domainTarget(), cfg.plistPath], stdioOpts2());
|
|
2241
|
-
execFileSync3("launchctl", ["enable", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2242
|
-
execFileSync3("launchctl", ["kickstart", "-k", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2243
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2244
|
-
}
|
|
2245
|
-
function uninstallLaunchAgent(label = DEFAULT_LABEL) {
|
|
2246
|
-
assertDarwin();
|
|
2247
|
-
const cfg = resolveConfig({ label });
|
|
2248
|
-
tryRun2("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
2249
|
-
tryRun2("launchctl", ["disable", `${domainTarget()}/${cfg.label}`]);
|
|
2250
|
-
rmSync3(cfg.plistPath, { force: true });
|
|
2251
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2252
|
-
}
|
|
2253
|
-
function startLaunchAgent(label = DEFAULT_LABEL) {
|
|
2254
|
-
assertDarwin();
|
|
2255
|
-
const cfg = resolveConfig({ label });
|
|
2256
|
-
if (!exists(cfg.plistPath)) {
|
|
2257
|
-
throw new Error(`LaunchAgent not installed: ${cfg.plistPath}`);
|
|
2258
|
-
}
|
|
2259
|
-
execFileSync3("launchctl", ["enable", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2260
|
-
tryRun2("launchctl", ["bootstrap", domainTarget(), cfg.plistPath]);
|
|
2261
|
-
execFileSync3("launchctl", ["kickstart", "-k", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2262
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2263
|
-
}
|
|
2264
|
-
function stopLaunchAgent(label = DEFAULT_LABEL) {
|
|
2265
|
-
assertDarwin();
|
|
2266
|
-
const cfg = resolveConfig({ label });
|
|
2267
|
-
if (exists(cfg.plistPath)) {
|
|
2268
|
-
tryRun2("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
2269
|
-
}
|
|
2270
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2271
|
-
}
|
|
2272
|
-
function getLaunchAgentStatus(label = DEFAULT_LABEL) {
|
|
2273
|
-
assertDarwin();
|
|
2274
|
-
const cfg = resolveConfig({ label });
|
|
2275
|
-
const installed = exists(cfg.plistPath);
|
|
2276
|
-
const output = tryOutput("launchctl", ["print", `${domainTarget()}/${cfg.label}`]);
|
|
2277
|
-
return {
|
|
2278
|
-
label: cfg.label,
|
|
2279
|
-
plistPath: cfg.plistPath,
|
|
2280
|
-
installed,
|
|
2281
|
-
loaded: output.ok,
|
|
2282
|
-
state: output.ok ? extractState(output.output) : void 0
|
|
2283
|
-
};
|
|
2284
|
-
}
|
|
2285
|
-
function getLaunchAgentInfo(label = DEFAULT_LABEL) {
|
|
2286
|
-
assertDarwin();
|
|
2287
|
-
const cfg = resolveConfig({ label });
|
|
2288
|
-
const status = getLaunchAgentStatus(label);
|
|
2289
|
-
const installed = readInstalledConfig(cfg.plistPath);
|
|
2290
|
-
const lines = [
|
|
2291
|
-
`Label: ${status.label}`,
|
|
2292
|
-
`Plist: ${cfg.plistPath}`,
|
|
2293
|
-
`Installed: ${status.installed ? "yes" : "no"}`,
|
|
2294
|
-
`Loaded: ${status.loaded ? "yes" : "no"}`
|
|
2295
|
-
];
|
|
2296
|
-
if (status.state) {
|
|
2297
|
-
lines.push(`State: ${status.state}`);
|
|
2298
|
-
}
|
|
2299
|
-
lines.push(`Port: ${installed?.port ?? cfg.port}`);
|
|
2300
|
-
lines.push(`Data dir: ${installed?.dataDir ?? cfg.dataDir}`);
|
|
2301
|
-
if (installed?.repoRoots ?? cfg.repoRoots) {
|
|
2302
|
-
lines.push(`Repos: ${installed?.repoRoots ?? cfg.repoRoots}`);
|
|
2303
|
-
}
|
|
2304
|
-
if (installed?.repoOverride ?? cfg.repoOverride) {
|
|
2305
|
-
lines.push(`Repo: ${installed?.repoOverride ?? cfg.repoOverride}`);
|
|
2306
|
-
}
|
|
2307
|
-
if (installed?.embeddingProvider ?? cfg.embeddingProvider) {
|
|
2308
|
-
lines.push(`EmbedProv: ${installed?.embeddingProvider ?? cfg.embeddingProvider}`);
|
|
2309
|
-
}
|
|
2310
|
-
if (installed?.embeddingDims ?? cfg.embeddingDims) {
|
|
2311
|
-
lines.push(`EmbedDims: ${installed?.embeddingDims ?? cfg.embeddingDims}`);
|
|
2312
|
-
}
|
|
2313
|
-
if (installed?.embeddingsDisabled ?? cfg.embeddingsDisabled) {
|
|
2314
|
-
lines.push(`EmbedOff: ${installed?.embeddingsDisabled ?? cfg.embeddingsDisabled}`);
|
|
2315
|
-
}
|
|
2316
|
-
lines.push(`Node: ${installed?.nodePath ?? cfg.nodePath}`);
|
|
2317
|
-
lines.push(`Script: ${installed?.daemonScript ?? cfg.daemonScript}`);
|
|
2318
|
-
lines.push(`Maintain: ${installed?.maintenanceIntervalSeconds ?? cfg.maintenanceIntervalSeconds}s`);
|
|
2319
|
-
lines.push(`Stdout: ${installed?.stdoutPath ?? cfg.stdoutPath}`);
|
|
2320
|
-
lines.push(`Stderr: ${installed?.stderrPath ?? cfg.stderrPath}`);
|
|
2321
|
-
return lines.join("\n");
|
|
2322
|
-
}
|
|
2323
|
-
function resolveConfig(opts) {
|
|
2324
|
-
const label = opts.label ?? DEFAULT_LABEL;
|
|
2325
|
-
const home = homedir();
|
|
2326
|
-
const port = opts.port ?? parseInt(process.env.RECALL_PORT ?? "7890", 10);
|
|
2327
|
-
const maintenanceIntervalSeconds = opts.maintenanceIntervalSeconds ?? parseInt(process.env.RECALL_MAINTENANCE_INTERVAL_SECONDS ?? "3600", 10);
|
|
2328
|
-
const dataDir = resolve4(
|
|
2329
|
-
opts.dataDir ?? process.env.RECALL_DATA_DIR ?? join8(home, ".recall")
|
|
2330
|
-
);
|
|
2331
|
-
const nodePath = resolve4(opts.nodePath ?? process.execPath);
|
|
2332
|
-
const daemonScript = resolve4(
|
|
2333
|
-
opts.daemonScript ?? join8(process.cwd(), "dist", "daemon.js")
|
|
2334
|
-
);
|
|
2335
|
-
const plistPath = join8(home, "Library", "LaunchAgents", `${label}.plist`);
|
|
2336
|
-
const logDir = join8(dataDir, "logs");
|
|
2337
|
-
const installed = readInstalledConfig(plistPath);
|
|
2338
|
-
return {
|
|
2339
|
-
label,
|
|
2340
|
-
port,
|
|
2341
|
-
maintenanceIntervalSeconds,
|
|
2342
|
-
dataDir,
|
|
2343
|
-
nodePath,
|
|
2344
|
-
daemonScript,
|
|
2345
|
-
plistPath,
|
|
2346
|
-
stdoutPath: join8(logDir, "daemon.stdout.log"),
|
|
2347
|
-
stderrPath: join8(logDir, "daemon.stderr.log"),
|
|
2348
|
-
repoRoots: opts.repoRoots ?? process.env.RECALL_REPO_ROOTS,
|
|
2349
|
-
repoOverride: opts.repoOverride ?? process.env.RECALL_REPO_OVERRIDE ?? installed?.repoOverride,
|
|
2350
|
-
embeddingProvider: opts.embeddingProvider ?? process.env.RECALL_EMBEDDING_PROVIDER,
|
|
2351
|
-
embeddingDims: opts.embeddingDims ?? process.env.RECALL_EMBEDDING_DIMS,
|
|
2352
|
-
embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED,
|
|
2353
|
-
providerEnvironment: resolveDaemonProviderEnvironment(
|
|
2354
|
-
process.env,
|
|
2355
|
-
installed?.providerEnvironment
|
|
2356
|
-
)
|
|
2357
|
-
};
|
|
2358
|
-
}
|
|
2359
|
-
function renderPlist(cfg) {
|
|
2360
|
-
const env = {
|
|
2361
|
-
RECALL_PORT: String(cfg.port),
|
|
2362
|
-
RECALL_MAINTENANCE_INTERVAL_SECONDS: String(cfg.maintenanceIntervalSeconds),
|
|
2363
|
-
RECALL_DATA_DIR: cfg.dataDir,
|
|
2364
|
-
PATH: process.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
2365
|
-
...cfg.repoRoots ? { RECALL_REPO_ROOTS: cfg.repoRoots } : {},
|
|
2366
|
-
...cfg.repoOverride ? { RECALL_REPO_OVERRIDE: cfg.repoOverride } : {},
|
|
2367
|
-
...cfg.embeddingProvider ? { RECALL_EMBEDDING_PROVIDER: cfg.embeddingProvider } : {},
|
|
2368
|
-
...cfg.embeddingDims ? { RECALL_EMBEDDING_DIMS: cfg.embeddingDims } : {},
|
|
2369
|
-
...cfg.embeddingsDisabled ? { RECALL_EMBEDDINGS_DISABLED: cfg.embeddingsDisabled } : {},
|
|
2370
|
-
...cfg.providerEnvironment
|
|
2371
|
-
};
|
|
2372
|
-
const environmentXml = Object.entries(env).map(([key, value]) => ` <key>${escapeXml(key)}</key>
|
|
2373
|
-
<string>${escapeXml(value)}</string>`).join("\n");
|
|
2374
|
-
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
2375
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
2376
|
-
<plist version="1.0">
|
|
2377
|
-
<dict>
|
|
2378
|
-
<key>Label</key>
|
|
2379
|
-
<string>${escapeXml(cfg.label)}</string>
|
|
2380
|
-
<key>ProgramArguments</key>
|
|
2381
|
-
<array>
|
|
2382
|
-
<string>${escapeXml(cfg.nodePath)}</string>
|
|
2383
|
-
<string>${escapeXml(cfg.daemonScript)}</string>
|
|
2384
|
-
</array>
|
|
2385
|
-
<key>EnvironmentVariables</key>
|
|
2386
|
-
<dict>
|
|
2387
|
-
${environmentXml}
|
|
2388
|
-
</dict>
|
|
2389
|
-
<key>RunAtLoad</key>
|
|
2390
|
-
<true/>
|
|
2391
|
-
<key>KeepAlive</key>
|
|
2392
|
-
<true/>
|
|
2393
|
-
<key>WorkingDirectory</key>
|
|
2394
|
-
<string>${escapeXml(process.cwd())}</string>
|
|
2395
|
-
<key>StandardOutPath</key>
|
|
2396
|
-
<string>${escapeXml(cfg.stdoutPath)}</string>
|
|
2397
|
-
<key>StandardErrorPath</key>
|
|
2398
|
-
<string>${escapeXml(cfg.stderrPath)}</string>
|
|
2399
|
-
</dict>
|
|
2400
|
-
</plist>
|
|
2401
|
-
`;
|
|
2402
|
-
}
|
|
2403
|
-
function domainTarget() {
|
|
2404
|
-
const uid = process.getuid?.();
|
|
2405
|
-
if (uid == null) {
|
|
2406
|
-
throw new Error("Could not determine current macOS user id");
|
|
2407
|
-
}
|
|
2408
|
-
return `gui/${uid}`;
|
|
2409
|
-
}
|
|
2410
|
-
function extractState(output) {
|
|
2411
|
-
const line = output.split("\n").find((item) => item.trim().startsWith("state = "));
|
|
2412
|
-
if (!line) return void 0;
|
|
2413
|
-
return line.split("=").slice(1).join("=").trim();
|
|
2414
|
-
}
|
|
2415
|
-
function tryRun2(cmd, args) {
|
|
2416
|
-
try {
|
|
2417
|
-
execFileSync3(cmd, args, stdioOpts2());
|
|
2418
|
-
} catch {
|
|
2419
|
-
return;
|
|
2420
|
-
}
|
|
2421
|
-
}
|
|
2422
|
-
function tryOutput(cmd, args) {
|
|
2423
|
-
try {
|
|
2424
|
-
const output = execFileSync3(cmd, args, {
|
|
2425
|
-
encoding: "utf8",
|
|
2426
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
2427
|
-
});
|
|
2428
|
-
return { ok: true, output };
|
|
2429
|
-
} catch (error) {
|
|
2430
|
-
return {
|
|
2431
|
-
ok: false,
|
|
2432
|
-
output: String(error?.stdout ?? error?.stderr ?? error?.message ?? "")
|
|
2433
|
-
};
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
function readInstalledConfig(plistPath) {
|
|
2437
|
-
if (!exists(plistPath)) return null;
|
|
2438
|
-
try {
|
|
2439
|
-
const raw = execFileSync3("plutil", ["-convert", "json", "-o", "-", plistPath], {
|
|
2440
|
-
encoding: "utf8",
|
|
2441
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
2442
|
-
});
|
|
2443
|
-
const parsed = JSON.parse(raw);
|
|
2444
|
-
return {
|
|
2445
|
-
nodePath: parsed?.ProgramArguments?.[0],
|
|
2446
|
-
daemonScript: parsed?.ProgramArguments?.[1],
|
|
2447
|
-
port: parsed?.EnvironmentVariables?.RECALL_PORT,
|
|
2448
|
-
maintenanceIntervalSeconds: parsed?.EnvironmentVariables?.RECALL_MAINTENANCE_INTERVAL_SECONDS,
|
|
2449
|
-
dataDir: parsed?.EnvironmentVariables?.RECALL_DATA_DIR,
|
|
2450
|
-
repoRoots: parsed?.EnvironmentVariables?.RECALL_REPO_ROOTS,
|
|
2451
|
-
repoOverride: parsed?.EnvironmentVariables?.RECALL_REPO_OVERRIDE,
|
|
2452
|
-
embeddingProvider: parsed?.EnvironmentVariables?.RECALL_EMBEDDING_PROVIDER,
|
|
2453
|
-
embeddingDims: parsed?.EnvironmentVariables?.RECALL_EMBEDDING_DIMS,
|
|
2454
|
-
embeddingsDisabled: parsed?.EnvironmentVariables?.RECALL_EMBEDDINGS_DISABLED,
|
|
2455
|
-
providerEnvironment: readDaemonProviderEnvironment(
|
|
2456
|
-
parsed?.EnvironmentVariables ?? {}
|
|
2457
|
-
),
|
|
2458
|
-
stdoutPath: parsed?.StandardOutPath,
|
|
2459
|
-
stderrPath: parsed?.StandardErrorPath
|
|
2460
|
-
};
|
|
2461
|
-
} catch {
|
|
2462
|
-
return null;
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
function stdioOpts2() {
|
|
1027
|
+
const result = options.uninstallHooks ? uninstallClaudeCodeHooks({ configPath: options.configPath }) : installClaudeCodeHooks({
|
|
1028
|
+
configPath: options.configPath,
|
|
1029
|
+
cliPath: options.paths.runtimeCliPath,
|
|
1030
|
+
nodePath: options.paths.runtimeNodePath,
|
|
1031
|
+
promptInjection: options.promptInjection
|
|
1032
|
+
});
|
|
2466
1033
|
return {
|
|
2467
|
-
|
|
1034
|
+
enabled: true,
|
|
1035
|
+
ok: result.ok,
|
|
1036
|
+
message: result.message
|
|
2468
1037
|
};
|
|
2469
1038
|
}
|
|
2470
|
-
function
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2475
|
-
}
|
|
2476
|
-
function assertDarwin() {
|
|
2477
|
-
if (process.platform !== "darwin") {
|
|
2478
|
-
throw new Error("launchd daemon install is only supported on macOS");
|
|
2479
|
-
}
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
// src/daemon/systemd.ts
|
|
2483
|
-
init_define_RECALL_BUILD_INFO();
|
|
2484
|
-
import { chmodSync as chmodSync2, existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync4, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "fs";
|
|
2485
|
-
import { homedir as homedir2 } from "os";
|
|
2486
|
-
import { dirname as dirname6, join as join9, resolve as resolve5 } from "path";
|
|
2487
|
-
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2488
|
-
import { execFileSync as execFileSync4 } from "child_process";
|
|
2489
|
-
var DEFAULT_LABEL2 = "recall-daemon";
|
|
2490
|
-
function installSystemdUnit(opts = {}) {
|
|
2491
|
-
assertLinux();
|
|
2492
|
-
const cfg = resolveConfig2(opts);
|
|
2493
|
-
mkdirSync5(dirname6(cfg.unitPath), { recursive: true });
|
|
2494
|
-
mkdirSync5(cfg.logDir, { recursive: true });
|
|
2495
|
-
writeFileSync5(cfg.unitPath, renderUnit(cfg), { mode: 384 });
|
|
2496
|
-
chmodSync2(cfg.unitPath, 384);
|
|
2497
|
-
for (const args of systemdInstallCommands(cfg.label)) systemctl(args);
|
|
2498
|
-
return getSystemdStatus(cfg.label);
|
|
2499
|
-
}
|
|
2500
|
-
function systemdInstallCommands(label = DEFAULT_LABEL2) {
|
|
2501
|
-
const service = `${label}.service`;
|
|
2502
|
-
return [
|
|
2503
|
-
["--user", "daemon-reload"],
|
|
2504
|
-
["--user", "enable", service],
|
|
2505
|
-
// `enable --now` leaves an already-active process untouched. Restart so a
|
|
2506
|
-
// package upgrade actually runs the newly installed daemon code.
|
|
2507
|
-
["--user", "restart", service]
|
|
2508
|
-
];
|
|
2509
|
-
}
|
|
2510
|
-
function uninstallSystemdUnit(label = DEFAULT_LABEL2) {
|
|
2511
|
-
assertLinux();
|
|
2512
|
-
const cfg = resolveConfig2({ label });
|
|
2513
|
-
trySystemctl(["--user", "disable", "--now", `${cfg.label}.service`]);
|
|
2514
|
-
rmSync4(cfg.unitPath, { force: true });
|
|
2515
|
-
trySystemctl(["--user", "daemon-reload"]);
|
|
2516
|
-
return getSystemdStatus(cfg.label);
|
|
2517
|
-
}
|
|
2518
|
-
function startSystemdUnit(label = DEFAULT_LABEL2) {
|
|
2519
|
-
assertLinux();
|
|
2520
|
-
const cfg = resolveConfig2({ label });
|
|
2521
|
-
if (!existsSync7(cfg.unitPath)) {
|
|
2522
|
-
throw new Error(`systemd unit not installed: ${cfg.unitPath}`);
|
|
2523
|
-
}
|
|
2524
|
-
systemctl(["--user", "start", `${cfg.label}.service`]);
|
|
2525
|
-
return getSystemdStatus(cfg.label);
|
|
1039
|
+
function describeCodexTargets(message, targets) {
|
|
1040
|
+
if (targets.length <= 1) return message;
|
|
1041
|
+
const names = targets.map((target) => basename(target.home)).join(", ");
|
|
1042
|
+
return `${message} across ${targets.length} Codex homes (${names})`;
|
|
2526
1043
|
}
|
|
2527
|
-
function
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
if (existsSync7(cfg.unitPath)) {
|
|
2531
|
-
trySystemctl(["--user", "stop", `${cfg.label}.service`]);
|
|
1044
|
+
function resolveTargetAgents(target) {
|
|
1045
|
+
if (target && target.length > 0) {
|
|
1046
|
+
return [...new Set(target)];
|
|
2532
1047
|
}
|
|
2533
|
-
return
|
|
2534
|
-
}
|
|
2535
|
-
function getSystemdStatus(label = DEFAULT_LABEL2) {
|
|
2536
|
-
assertLinux();
|
|
2537
|
-
const cfg = resolveConfig2({ label });
|
|
2538
|
-
const installed = existsSync7(cfg.unitPath);
|
|
2539
|
-
const active = trySystemctlOutput(["--user", "is-active", `${cfg.label}.service`]);
|
|
2540
|
-
const loaded = active.ok && active.output.trim() === "active";
|
|
2541
|
-
const state = active.output.trim() || void 0;
|
|
2542
|
-
return {
|
|
2543
|
-
label: cfg.label,
|
|
2544
|
-
unitPath: cfg.unitPath,
|
|
2545
|
-
installed,
|
|
2546
|
-
loaded,
|
|
2547
|
-
state
|
|
2548
|
-
};
|
|
1048
|
+
return listAgentNames().filter((agent) => detectAgent(agent));
|
|
2549
1049
|
}
|
|
2550
|
-
function
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
const status = getSystemdStatus(label);
|
|
2554
|
-
const installed = readInstalledConfig2(cfg.unitPath);
|
|
2555
|
-
const lines = [
|
|
2556
|
-
`Label: ${status.label}`,
|
|
2557
|
-
`Unit: ${cfg.unitPath}`,
|
|
2558
|
-
`Installed: ${status.installed ? "yes" : "no"}`,
|
|
2559
|
-
`Loaded: ${status.loaded ? "yes" : "no"}`
|
|
2560
|
-
];
|
|
2561
|
-
if (status.state) lines.push(`State: ${status.state}`);
|
|
2562
|
-
lines.push(`Port: ${installed?.port ?? cfg.port}`);
|
|
2563
|
-
lines.push(`Data dir: ${installed?.dataDir ?? cfg.dataDir}`);
|
|
2564
|
-
if (installed?.repoRoots ?? cfg.repoRoots) {
|
|
2565
|
-
lines.push(`Repos: ${installed?.repoRoots ?? cfg.repoRoots}`);
|
|
2566
|
-
}
|
|
2567
|
-
if (installed?.repoOverride ?? cfg.repoOverride) {
|
|
2568
|
-
lines.push(`Repo: ${installed?.repoOverride ?? cfg.repoOverride}`);
|
|
2569
|
-
}
|
|
2570
|
-
if (installed?.embeddingProvider ?? cfg.embeddingProvider) {
|
|
2571
|
-
lines.push(`EmbedProv: ${installed?.embeddingProvider ?? cfg.embeddingProvider}`);
|
|
2572
|
-
}
|
|
2573
|
-
if (installed?.embeddingDims ?? cfg.embeddingDims) {
|
|
2574
|
-
lines.push(`EmbedDims: ${installed?.embeddingDims ?? cfg.embeddingDims}`);
|
|
2575
|
-
}
|
|
2576
|
-
if (installed?.embeddingsDisabled ?? cfg.embeddingsDisabled) {
|
|
2577
|
-
lines.push(`EmbedOff: ${installed?.embeddingsDisabled ?? cfg.embeddingsDisabled}`);
|
|
1050
|
+
function detectAgent(agent) {
|
|
1051
|
+
if (agent === "codex") {
|
|
1052
|
+
return hasCommand("codex") || existsSync(join2(resolveUserHomeDir(), ".codex", "config.toml"));
|
|
2578
1053
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
lines.push(`Maintain: ${installed?.maintenanceIntervalSeconds ?? cfg.maintenanceIntervalSeconds}s`);
|
|
2582
|
-
lines.push(`Logs: journalctl --user -u ${cfg.label}.service`);
|
|
2583
|
-
return lines.join("\n");
|
|
2584
|
-
}
|
|
2585
|
-
function resolveConfig2(opts) {
|
|
2586
|
-
const label = opts.label ?? DEFAULT_LABEL2;
|
|
2587
|
-
const home = homedir2();
|
|
2588
|
-
const port = opts.port ?? parseInt(process.env.RECALL_PORT ?? "7890", 10);
|
|
2589
|
-
const maintenanceIntervalSeconds = opts.maintenanceIntervalSeconds ?? parseInt(process.env.RECALL_MAINTENANCE_INTERVAL_SECONDS ?? "3600", 10);
|
|
2590
|
-
const dataDir = resolve5(
|
|
2591
|
-
opts.dataDir ?? process.env.RECALL_DATA_DIR ?? join9(home, ".recall")
|
|
2592
|
-
);
|
|
2593
|
-
const nodePath = resolve5(opts.nodePath ?? process.execPath);
|
|
2594
|
-
const daemonScript = resolve5(
|
|
2595
|
-
opts.daemonScript ?? defaultDaemonScript()
|
|
2596
|
-
);
|
|
2597
|
-
const configHome = process.env.XDG_CONFIG_HOME ?? join9(home, ".config");
|
|
2598
|
-
const unitPath = join9(configHome, "systemd", "user", `${label}.service`);
|
|
2599
|
-
const logDir = join9(dataDir, "logs");
|
|
2600
|
-
const installed = readInstalledConfig2(unitPath);
|
|
2601
|
-
return {
|
|
2602
|
-
label,
|
|
2603
|
-
port,
|
|
2604
|
-
maintenanceIntervalSeconds,
|
|
2605
|
-
dataDir,
|
|
2606
|
-
nodePath,
|
|
2607
|
-
daemonScript,
|
|
2608
|
-
unitPath,
|
|
2609
|
-
logDir,
|
|
2610
|
-
repoRoots: opts.repoRoots ?? process.env.RECALL_REPO_ROOTS,
|
|
2611
|
-
repoOverride: opts.repoOverride ?? process.env.RECALL_REPO_OVERRIDE ?? installed?.repoOverride,
|
|
2612
|
-
embeddingProvider: opts.embeddingProvider ?? process.env.RECALL_EMBEDDING_PROVIDER,
|
|
2613
|
-
embeddingDims: opts.embeddingDims ?? process.env.RECALL_EMBEDDING_DIMS,
|
|
2614
|
-
embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED,
|
|
2615
|
-
providerEnvironment: resolveDaemonProviderEnvironment(
|
|
2616
|
-
process.env,
|
|
2617
|
-
installed?.providerEnvironment
|
|
2618
|
-
)
|
|
2619
|
-
};
|
|
2620
|
-
}
|
|
2621
|
-
function defaultDaemonScript() {
|
|
2622
|
-
const here = dirname6(fileURLToPath3(import.meta.url));
|
|
2623
|
-
return join9(here, "daemon.js");
|
|
2624
|
-
}
|
|
2625
|
-
function renderUnit(cfg) {
|
|
2626
|
-
const envLines = [
|
|
2627
|
-
`Environment=PATH=${process.env.PATH ?? "/usr/bin:/bin:/usr/local/bin"}`,
|
|
2628
|
-
`Environment=RECALL_PORT=${cfg.port}`,
|
|
2629
|
-
`Environment=RECALL_MAINTENANCE_INTERVAL_SECONDS=${cfg.maintenanceIntervalSeconds}`,
|
|
2630
|
-
`Environment=RECALL_DATA_DIR=${cfg.dataDir}`
|
|
2631
|
-
];
|
|
2632
|
-
if (cfg.repoRoots) envLines.push(`Environment=RECALL_REPO_ROOTS=${cfg.repoRoots}`);
|
|
2633
|
-
if (cfg.repoOverride) envLines.push(`Environment="RECALL_REPO_OVERRIDE=${escapeSystemdValue(cfg.repoOverride)}"`);
|
|
2634
|
-
if (cfg.embeddingProvider) envLines.push(`Environment=RECALL_EMBEDDING_PROVIDER=${cfg.embeddingProvider}`);
|
|
2635
|
-
if (cfg.embeddingDims) envLines.push(`Environment=RECALL_EMBEDDING_DIMS=${cfg.embeddingDims}`);
|
|
2636
|
-
if (cfg.embeddingsDisabled) envLines.push(`Environment=RECALL_EMBEDDINGS_DISABLED=${cfg.embeddingsDisabled}`);
|
|
2637
|
-
for (const [key, value] of Object.entries(cfg.providerEnvironment)) {
|
|
2638
|
-
envLines.push(`Environment="${key}=${escapeSystemdValue(value)}"`);
|
|
2639
|
-
}
|
|
2640
|
-
return `[Unit]
|
|
2641
|
-
Description=Recall local daemon
|
|
2642
|
-
After=network.target
|
|
2643
|
-
|
|
2644
|
-
[Service]
|
|
2645
|
-
Type=simple
|
|
2646
|
-
ExecStart=${cfg.nodePath} ${cfg.daemonScript}
|
|
2647
|
-
Restart=always
|
|
2648
|
-
RestartSec=2
|
|
2649
|
-
${envLines.join("\n")}
|
|
2650
|
-
|
|
2651
|
-
[Install]
|
|
2652
|
-
WantedBy=default.target
|
|
2653
|
-
`;
|
|
2654
|
-
}
|
|
2655
|
-
function readInstalledConfig2(unitPath) {
|
|
2656
|
-
if (!existsSync7(unitPath)) return null;
|
|
2657
|
-
try {
|
|
2658
|
-
const raw = readFileSync4(unitPath, "utf8");
|
|
2659
|
-
const exec = raw.match(/^ExecStart=(.+)$/m)?.[1]?.trim().split(/\s+/);
|
|
2660
|
-
const env = parseSystemdEnvironment(raw);
|
|
2661
|
-
return {
|
|
2662
|
-
nodePath: exec?.[0],
|
|
2663
|
-
daemonScript: exec?.[1],
|
|
2664
|
-
port: env.RECALL_PORT,
|
|
2665
|
-
maintenanceIntervalSeconds: env.RECALL_MAINTENANCE_INTERVAL_SECONDS,
|
|
2666
|
-
dataDir: env.RECALL_DATA_DIR,
|
|
2667
|
-
repoRoots: env.RECALL_REPO_ROOTS,
|
|
2668
|
-
repoOverride: env.RECALL_REPO_OVERRIDE,
|
|
2669
|
-
embeddingProvider: env.RECALL_EMBEDDING_PROVIDER,
|
|
2670
|
-
embeddingDims: env.RECALL_EMBEDDING_DIMS,
|
|
2671
|
-
embeddingsDisabled: env.RECALL_EMBEDDINGS_DISABLED,
|
|
2672
|
-
providerEnvironment: readDaemonProviderEnvironment(env)
|
|
2673
|
-
};
|
|
2674
|
-
} catch {
|
|
2675
|
-
return null;
|
|
1054
|
+
if (agent === "claude-code") {
|
|
1055
|
+
return hasCommand("claude") || existsSync(join2(resolveUserHomeDir(), ".claude", "settings.json"));
|
|
2676
1056
|
}
|
|
1057
|
+
return resolveAdapter(agent).detect() === "installed";
|
|
2677
1058
|
}
|
|
2678
|
-
function
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
const key = match[1] ?? match[3];
|
|
2682
|
-
const value = match[2] != null ? unescapeSystemdValue(match[2]) : match[4];
|
|
2683
|
-
if (key && value != null) {
|
|
2684
|
-
defineOwn(environment, key, value);
|
|
2685
|
-
}
|
|
1059
|
+
function resolveHookConfigPath(agent, scope, cwd) {
|
|
1060
|
+
if (scope === "project") {
|
|
1061
|
+
return agent === "codex" ? join2(cwd, ".codex", "config.toml") : join2(cwd, ".claude", "settings.json");
|
|
2686
1062
|
}
|
|
2687
|
-
return
|
|
1063
|
+
return agent === "codex" ? join2(resolveUserHomeDir(), ".codex", "config.toml") : join2(resolveUserHomeDir(), ".claude", "settings.json");
|
|
2688
1064
|
}
|
|
2689
|
-
function
|
|
2690
|
-
|
|
2691
|
-
}
|
|
2692
|
-
function unescapeSystemdValue(value) {
|
|
2693
|
-
return value.replaceAll("%%", "%").replaceAll('\\"', '"').replaceAll("\\\\", "\\");
|
|
2694
|
-
}
|
|
2695
|
-
function systemctl(args) {
|
|
2696
|
-
execFileSync4("systemctl", args, { stdio: "pipe" });
|
|
1065
|
+
function defaultRunner(command, args, options) {
|
|
1066
|
+
execFileSync(command, args, { ...stdioOpts(), ...options?.env ? { env: options.env } : {} });
|
|
2697
1067
|
}
|
|
2698
|
-
function
|
|
1068
|
+
function tryRun(runner, command, args, options) {
|
|
2699
1069
|
try {
|
|
2700
|
-
|
|
1070
|
+
runner(command, args, options);
|
|
2701
1071
|
} catch {
|
|
2702
1072
|
return;
|
|
2703
1073
|
}
|
|
2704
1074
|
}
|
|
2705
|
-
function
|
|
2706
|
-
try {
|
|
2707
|
-
const output = execFileSync4("systemctl", args, {
|
|
2708
|
-
encoding: "utf8",
|
|
2709
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
2710
|
-
});
|
|
2711
|
-
return { ok: true, output };
|
|
2712
|
-
} catch (error) {
|
|
2713
|
-
return {
|
|
2714
|
-
ok: false,
|
|
2715
|
-
output: String(error?.stdout ?? error?.stderr ?? error?.message ?? "")
|
|
2716
|
-
};
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
function assertLinux() {
|
|
2720
|
-
if (process.platform !== "linux") {
|
|
2721
|
-
throw new Error("systemd daemon install is only supported on Linux");
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
|
|
2725
|
-
// src/doctor/hook-activity.ts
|
|
2726
|
-
init_define_RECALL_BUILD_INFO();
|
|
2727
|
-
import Database from "better-sqlite3";
|
|
2728
|
-
function readHookActivity(dbPath, agent, now = Date.now()) {
|
|
2729
|
-
let db;
|
|
2730
|
-
try {
|
|
2731
|
-
db = new Database(dbPath, { readonly: true, fileMustExist: true });
|
|
2732
|
-
const rows = db.prepare(
|
|
2733
|
-
"SELECT event, MAX(created_at) AS latest FROM hook_calls WHERE agent=? AND ok=1 GROUP BY event"
|
|
2734
|
-
).all(agent);
|
|
2735
|
-
const events = Object.fromEntries(rows.map((r) => [r.event, r.latest]));
|
|
2736
|
-
const last = rows.map((r) => r.latest).sort().at(-1) ?? null;
|
|
2737
|
-
return {
|
|
2738
|
-
status: !last ? "never" : now - Date.parse(last) > 7 * 864e5 ? "stale" : "recent",
|
|
2739
|
-
last_success_at: last,
|
|
2740
|
-
events
|
|
2741
|
-
};
|
|
2742
|
-
} catch {
|
|
2743
|
-
return { status: "unavailable", last_success_at: null, events: {} };
|
|
2744
|
-
} finally {
|
|
2745
|
-
db?.close();
|
|
2746
|
-
}
|
|
2747
|
-
}
|
|
2748
|
-
function missingCodexTrustKeys(config, hooksPath, definition) {
|
|
2749
|
-
const events = definition?.hooks ?? {};
|
|
2750
|
-
const missing = [];
|
|
2751
|
-
for (const [event, groups] of Object.entries(events)) {
|
|
2752
|
-
if (!Array.isArray(groups)) continue;
|
|
2753
|
-
const snake = event.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
2754
|
-
groups.forEach((group, gi) => group.hooks?.forEach((hook, hi) => {
|
|
2755
|
-
if (!hook.command?.includes("recall:managed:codex:")) return;
|
|
2756
|
-
const key = `${hooksPath}:${snake}:${gi}:${hi}`;
|
|
2757
|
-
const header = `[hooks.state.${JSON.stringify(key)}]`;
|
|
2758
|
-
const start = config.indexOf(header);
|
|
2759
|
-
const section = start < 0 ? "" : config.slice(start + header.length).split(/\n\s*\[/, 1)[0];
|
|
2760
|
-
if (!/\btrusted_hash\s*=\s*"sha256:[a-f0-9]+"/.test(section)) missing.push(key);
|
|
2761
|
-
}));
|
|
2762
|
-
}
|
|
2763
|
-
return missing;
|
|
2764
|
-
}
|
|
2765
|
-
|
|
2766
|
-
// src/doctor/report.ts
|
|
2767
|
-
function getDoctorReport() {
|
|
2768
|
-
const dbPath = getDbPath();
|
|
2769
|
-
const launchd = process.platform === "darwin" ? (() => {
|
|
2770
|
-
try {
|
|
2771
|
-
const status = getLaunchAgentStatus();
|
|
2772
|
-
return {
|
|
2773
|
-
installed: status.installed,
|
|
2774
|
-
loaded: status.loaded,
|
|
2775
|
-
state: status.state
|
|
2776
|
-
};
|
|
2777
|
-
} catch {
|
|
2778
|
-
return null;
|
|
2779
|
-
}
|
|
2780
|
-
})() : null;
|
|
2781
|
-
const systemd = process.platform === "linux" ? (() => {
|
|
2782
|
-
try {
|
|
2783
|
-
const status = getSystemdStatus();
|
|
2784
|
-
return {
|
|
2785
|
-
installed: status.installed,
|
|
2786
|
-
loaded: status.loaded,
|
|
2787
|
-
state: status.state
|
|
2788
|
-
};
|
|
2789
|
-
} catch {
|
|
2790
|
-
return null;
|
|
2791
|
-
}
|
|
2792
|
-
})() : null;
|
|
2793
|
-
const agents = inspectAgentInstalls();
|
|
2794
|
-
for (const agent of agents) {
|
|
2795
|
-
if (agent.detected && !agent.hookless) agent.hook_activity = readHookActivity(dbPath, agent.agent);
|
|
2796
|
-
}
|
|
2797
|
-
return {
|
|
2798
|
-
db_path: dbPath,
|
|
2799
|
-
db_user_version: getDbUserVersion(dbPath),
|
|
2800
|
-
db_target_version: RECALL_DB_USER_VERSION,
|
|
2801
|
-
embeddings: getEmbeddingModelInfo(),
|
|
2802
|
-
launchd,
|
|
2803
|
-
systemd,
|
|
2804
|
-
agents,
|
|
2805
|
-
upgrade: computeUpgradeSignal(agents),
|
|
2806
|
-
cleanup: readCleanupHealth(dbPath),
|
|
2807
|
-
dispatcher: readDispatcherHealth(dbPath),
|
|
2808
|
-
app_registrations: inspectAppRegistrations()
|
|
2809
|
-
};
|
|
2810
|
-
}
|
|
2811
|
-
function readDispatcherHealth(dbPath) {
|
|
2812
|
-
if (!existsSync8(dbPath)) return null;
|
|
2813
|
-
let sqlite = null;
|
|
2814
|
-
try {
|
|
2815
|
-
sqlite = new Database2(dbPath, { readonly: true, fileMustExist: true });
|
|
2816
|
-
const tables = sqlite.prepare(
|
|
2817
|
-
"SELECT name FROM sqlite_master WHERE type='table' AND name IN ('memory_maintenance_tasks','llm_usage')"
|
|
2818
|
-
).all();
|
|
2819
|
-
const names = new Set(tables.map((t) => t.name));
|
|
2820
|
-
let providers = [];
|
|
2821
|
-
try {
|
|
2822
|
-
const { hasProviderConfigured } = (init_keychain(), __toCommonJS(keychain_exports));
|
|
2823
|
-
providers = ["anthropic", "azure-openai", "openai"].filter(
|
|
2824
|
-
(p) => hasProviderConfigured(p)
|
|
2825
|
-
);
|
|
2826
|
-
} catch {
|
|
2827
|
-
providers = [];
|
|
2828
|
-
}
|
|
2829
|
-
const pending = {};
|
|
2830
|
-
if (names.has("memory_maintenance_tasks")) {
|
|
2831
|
-
const rows = sqlite.prepare(
|
|
2832
|
-
"SELECT kind, COUNT(*) AS n FROM memory_maintenance_tasks WHERE status='pending' GROUP BY kind"
|
|
2833
|
-
).all();
|
|
2834
|
-
for (const r of rows) pending[r.kind] = r.n;
|
|
2835
|
-
}
|
|
2836
|
-
let lastAt = null;
|
|
2837
|
-
let lastOk = null;
|
|
2838
|
-
if (names.has("llm_usage")) {
|
|
2839
|
-
const row = sqlite.prepare(
|
|
2840
|
-
"SELECT created_at, ok FROM llm_usage ORDER BY created_at DESC LIMIT 1"
|
|
2841
|
-
).get();
|
|
2842
|
-
if (row) {
|
|
2843
|
-
lastAt = row.created_at;
|
|
2844
|
-
lastOk = row.ok ? "ok" : "error";
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
return {
|
|
2848
|
-
providers_configured: providers,
|
|
2849
|
-
pending_tasks: pending,
|
|
2850
|
-
last_dispatch_at: lastAt,
|
|
2851
|
-
last_dispatch_outcome: lastOk
|
|
2852
|
-
};
|
|
2853
|
-
} catch {
|
|
2854
|
-
return null;
|
|
2855
|
-
} finally {
|
|
2856
|
-
sqlite?.close();
|
|
2857
|
-
}
|
|
2858
|
-
}
|
|
2859
|
-
function readCleanupHealth(dbPath) {
|
|
2860
|
-
if (!existsSync8(dbPath)) return null;
|
|
2861
|
-
let sqlite = null;
|
|
2862
|
-
try {
|
|
2863
|
-
sqlite = new Database2(dbPath, { readonly: true, fileMustExist: true });
|
|
2864
|
-
const tables = sqlite.prepare(
|
|
2865
|
-
"SELECT name FROM sqlite_master WHERE type='table' AND name IN ('maintenance_cleanup_log','memories','memory_injections')"
|
|
2866
|
-
).all();
|
|
2867
|
-
const names = new Set(tables.map((t) => t.name));
|
|
2868
|
-
if (!names.has("maintenance_cleanup_log")) return null;
|
|
2869
|
-
const totals = sqlite.prepare(
|
|
2870
|
-
"SELECT COUNT(DISTINCT run_id) AS runs, MAX(created_at) AS last_at FROM maintenance_cleanup_log"
|
|
2871
|
-
).get();
|
|
2872
|
-
let lastRunId = null;
|
|
2873
|
-
const actions = {};
|
|
2874
|
-
if (totals.last_at) {
|
|
2875
|
-
const lastRow = sqlite.prepare(
|
|
2876
|
-
"SELECT run_id FROM maintenance_cleanup_log WHERE created_at = ? LIMIT 1"
|
|
2877
|
-
).get(totals.last_at);
|
|
2878
|
-
lastRunId = lastRow?.run_id ?? null;
|
|
2879
|
-
if (lastRunId) {
|
|
2880
|
-
const rows = sqlite.prepare(
|
|
2881
|
-
"SELECT action, COUNT(*) as c FROM maintenance_cleanup_log WHERE run_id = ? GROUP BY action"
|
|
2882
|
-
).all(lastRunId);
|
|
2883
|
-
for (const r of rows) actions[r.action] = r.c;
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
2886
|
-
let pending = 0;
|
|
2887
|
-
if (names.has("memories")) {
|
|
2888
|
-
const row = sqlite.prepare(
|
|
2889
|
-
"SELECT COUNT(*) AS n FROM memories WHERE status='candidate' AND source='user_correction'"
|
|
2890
|
-
).get();
|
|
2891
|
-
pending = row.n;
|
|
2892
|
-
}
|
|
2893
|
-
let followedRate = null;
|
|
2894
|
-
let resolvedInjections = 0;
|
|
2895
|
-
let totalInjections = 0;
|
|
2896
|
-
if (names.has("memory_injections")) {
|
|
2897
|
-
const since = new Date(Date.now() - 14 * 864e5).toISOString();
|
|
2898
|
-
const rows = sqlite.prepare(
|
|
2899
|
-
"SELECT outcome, COUNT(*) as c FROM memory_injections WHERE injected_at >= ? GROUP BY outcome"
|
|
2900
|
-
).all(since);
|
|
2901
|
-
let followed = 0;
|
|
2902
|
-
for (const r of rows) {
|
|
2903
|
-
totalInjections += r.c;
|
|
2904
|
-
if (!r.outcome) continue;
|
|
2905
|
-
resolvedInjections += r.c;
|
|
2906
|
-
if (r.outcome === "followed") followed += r.c;
|
|
2907
|
-
}
|
|
2908
|
-
followedRate = resolvedInjections > 0 ? followed / resolvedInjections : null;
|
|
2909
|
-
}
|
|
2910
|
-
return {
|
|
2911
|
-
last_run_id: lastRunId,
|
|
2912
|
-
last_run_at: totals.last_at,
|
|
2913
|
-
last_run_actions: actions,
|
|
2914
|
-
total_runs: totals.runs,
|
|
2915
|
-
pending_candidate_corrections: pending,
|
|
2916
|
-
followed_rate_resolved: followedRate,
|
|
2917
|
-
resolved_injections: resolvedInjections,
|
|
2918
|
-
total_injections: totalInjections
|
|
2919
|
-
};
|
|
2920
|
-
} catch {
|
|
2921
|
-
return null;
|
|
2922
|
-
} finally {
|
|
2923
|
-
sqlite?.close();
|
|
2924
|
-
}
|
|
2925
|
-
}
|
|
2926
|
-
function computeUpgradeSignal(agents) {
|
|
2927
|
-
const reasons = [];
|
|
2928
|
-
for (const agent of agents) {
|
|
2929
|
-
if (!agent.detected) continue;
|
|
2930
|
-
if (agent.legacy_notify_bridge) {
|
|
2931
|
-
reasons.push(
|
|
2932
|
-
`${agent.agent}: legacy notify bridge detected \u2014 upgrade to hooks.json for per-turn memory injection`
|
|
2933
|
-
);
|
|
2934
|
-
continue;
|
|
2935
|
-
}
|
|
2936
|
-
if (agent.mcp && !agent.hooks) {
|
|
2937
|
-
reasons.push(
|
|
2938
|
-
agent.hookless ? `${agent.agent}: MCP configured but the Recall rules block is missing or stale \u2014 run \`recall setup\`` : `${agent.agent}: MCP configured but lifecycle hooks missing \u2014 memory injection depends on the model calling query`
|
|
2939
|
-
);
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
2942
|
-
return { available: reasons.length > 0, reasons };
|
|
2943
|
-
}
|
|
2944
|
-
function inspectAgentInstalls(homeDir) {
|
|
2945
|
-
const home = homeDir ?? resolveUserHomeDir();
|
|
2946
|
-
return [
|
|
2947
|
-
inspectClaudeCodeInstall(home),
|
|
2948
|
-
inspectCodexInstall(home),
|
|
2949
|
-
// Hookless agents are only listed once detected — most users have none of
|
|
2950
|
-
// them and four permanent "not detected" rows would just be noise.
|
|
2951
|
-
...listAgentNames().filter((agent) => isHooklessAgent(agent)).map((agent) => inspectHooklessInstall(agent, home)).filter((entry) => entry !== null)
|
|
2952
|
-
];
|
|
2953
|
-
}
|
|
2954
|
-
function inspectHooklessInstall(agent, home) {
|
|
2955
|
-
const adapter = resolveAdapter(agent);
|
|
2956
|
-
if (adapter.detect({ homeDir: home }) !== "installed") return null;
|
|
2957
|
-
const configPath2 = adapter.configPath({ homeDir: home });
|
|
2958
|
-
const mcp = adapter.hasMcpRegistration?.({ homeDir: home }) ?? false;
|
|
2959
|
-
const rules = adapter.checkRules?.({ homeDir: home });
|
|
2960
|
-
const notes = [];
|
|
2961
|
-
if (!mcp) {
|
|
2962
|
-
notes.push(`Recall MCP server not registered in ${configPath2} \u2014 run \`recall setup\``);
|
|
2963
|
-
}
|
|
2964
|
-
if (rules && rules.status !== "current") {
|
|
2965
|
-
notes.push(
|
|
2966
|
-
rules.status === "stale" ? `Recall rules block in ${rules.config_path} is out of date \u2014 run \`recall setup\`` : `No Recall rules block in ${rules.config_path} \u2014 ${agent} will not capture memories on its own`
|
|
2967
|
-
);
|
|
2968
|
-
}
|
|
2969
|
-
return {
|
|
2970
|
-
agent,
|
|
2971
|
-
detected: true,
|
|
2972
|
-
mcp,
|
|
2973
|
-
// No hook API exists, so "hooks" tracks the rules block that stands in for it.
|
|
2974
|
-
hooks: rules?.status === "current",
|
|
2975
|
-
hookless: true,
|
|
2976
|
-
config_path: configPath2,
|
|
2977
|
-
rules: rules?.status,
|
|
2978
|
-
rules_path: rules?.config_path,
|
|
2979
|
-
notes
|
|
2980
|
-
};
|
|
2981
|
-
}
|
|
2982
|
-
function inspectClaudeCodeInstall(home) {
|
|
2983
|
-
const configPath2 = join10(home, ".claude", "settings.json");
|
|
2984
|
-
const userConfigPath = join10(home, ".claude.json");
|
|
2985
|
-
const detected = existsSync8(configPath2) || existsSync8(userConfigPath) || hasCommand("claude");
|
|
2986
|
-
const notes = [];
|
|
2987
|
-
let mcp = false;
|
|
2988
|
-
let hooks = false;
|
|
2989
|
-
if (existsSync8(configPath2)) {
|
|
2990
|
-
try {
|
|
2991
|
-
const parsed = JSON.parse(readFileSync5(configPath2, "utf-8"));
|
|
2992
|
-
mcp = Boolean(parsed?.mcpServers?.recall);
|
|
2993
|
-
const hookGroups = parsed?.hooks ?? {};
|
|
2994
|
-
hooks = Object.values(hookGroups).some(
|
|
2995
|
-
(groups) => Array.isArray(groups) && groups.some(
|
|
2996
|
-
(group) => isHookGroupManagedBy(group, "recall:managed:claude-code")
|
|
2997
|
-
)
|
|
2998
|
-
);
|
|
2999
|
-
if (!hooks) notes.push("No Recall-managed hooks found in settings.json");
|
|
3000
|
-
} catch (err) {
|
|
3001
|
-
notes.push(`Could not parse ${configPath2}: ${err.message}`);
|
|
3002
|
-
}
|
|
3003
|
-
} else if (detected) {
|
|
3004
|
-
notes.push("Claude CLI detected but settings.json missing");
|
|
3005
|
-
}
|
|
3006
|
-
if (!mcp && existsSync8(userConfigPath)) {
|
|
3007
|
-
try {
|
|
3008
|
-
const parsed = JSON.parse(readFileSync5(userConfigPath, "utf-8"));
|
|
3009
|
-
mcp = Boolean(parsed?.mcpServers?.recall);
|
|
3010
|
-
} catch (err) {
|
|
3011
|
-
notes.push(`Could not parse ${userConfigPath}: ${err.message}`);
|
|
3012
|
-
}
|
|
3013
|
-
}
|
|
3014
|
-
if (!mcp) notes.push("MCP server 'recall' not registered in user configuration");
|
|
3015
|
-
const claudeMd = checkClaudeCodeMemoryOverride({
|
|
3016
|
-
configPath: join10(home, ".claude", "CLAUDE.md")
|
|
3017
|
-
});
|
|
3018
|
-
if (claudeMd.status === "stale") {
|
|
3019
|
-
notes.push("CLAUDE.md memory-override block is out of date \u2014 run `recall doctor --fix`");
|
|
3020
|
-
} else if (claudeMd.status === "missing") {
|
|
3021
|
-
notes.push("CLAUDE.md exists but has no Recall memory-override block \u2014 Claude Code's built-in auto-memory may race Recall");
|
|
3022
|
-
} else if (claudeMd.status === "absent_no_file" && detected) {
|
|
3023
|
-
notes.push("No CLAUDE.md at ~/.claude/CLAUDE.md \u2014 run `recall doctor --fix` to install the memory-override block");
|
|
3024
|
-
}
|
|
3025
|
-
return {
|
|
3026
|
-
agent: "claude-code",
|
|
3027
|
-
detected,
|
|
3028
|
-
mcp,
|
|
3029
|
-
hooks,
|
|
3030
|
-
config_path: configPath2,
|
|
3031
|
-
claude_md: claudeMd.status,
|
|
3032
|
-
claude_md_path: claudeMd.config_path,
|
|
3033
|
-
notes
|
|
3034
|
-
};
|
|
3035
|
-
}
|
|
3036
|
-
function inspectCodexHome(codexHome) {
|
|
3037
|
-
const configPath2 = join10(codexHome, "config.toml");
|
|
3038
|
-
const hooksPath = join10(codexHome, "hooks.json");
|
|
3039
|
-
const detected = existsSync8(configPath2) || hasCommand("codex");
|
|
3040
|
-
const notes = [];
|
|
3041
|
-
let mcp = false;
|
|
3042
|
-
let hooks = false;
|
|
3043
|
-
let legacy_notify_bridge = false;
|
|
3044
|
-
if (existsSync8(configPath2)) {
|
|
3045
|
-
const raw = readFileSync5(configPath2, "utf-8");
|
|
3046
|
-
mcp = /\[mcp_servers\.recall\]/.test(raw);
|
|
3047
|
-
const featureFlagSet = /^\s*(?:codex_)?hooks\s*=\s*true\b/m.test(raw);
|
|
3048
|
-
const managedHooksJson = existsSync8(hooksPath) && readFileSync5(hooksPath, "utf-8").includes("recall:managed:codex");
|
|
3049
|
-
hooks = featureFlagSet && managedHooksJson;
|
|
3050
|
-
if (managedHooksJson) {
|
|
3051
|
-
try {
|
|
3052
|
-
const missing = missingCodexTrustKeys(raw, hooksPath, JSON.parse(readFileSync5(hooksPath, "utf-8")));
|
|
3053
|
-
if (missing.length) notes.push(`${missing.length} Recall hooks lack trust for this profile path. Review them with Codex /hooks; setup does not grant trust.`);
|
|
3054
|
-
} catch {
|
|
3055
|
-
notes.push("hooks.json could not be parsed for trust inspection");
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
legacy_notify_bridge = raw.includes("# recall:managed:codex:start") && raw.includes("codex-notify");
|
|
3059
|
-
if (!mcp) notes.push("MCP block [mcp_servers.recall] not in config.toml");
|
|
3060
|
-
if (legacy_notify_bridge) {
|
|
3061
|
-
notes.push(
|
|
3062
|
-
"Legacy notify bridge present \u2014 install the new hooks.json path to enable per-turn memory injection"
|
|
3063
|
-
);
|
|
3064
|
-
}
|
|
3065
|
-
if (!featureFlagSet) notes.push("hooks = true (or legacy codex_hooks = true) missing from [features]");
|
|
3066
|
-
if (!managedHooksJson) notes.push(`No Recall-managed entries in ${hooksPath}`);
|
|
3067
|
-
} else if (detected) {
|
|
3068
|
-
notes.push("Codex CLI detected but config.toml missing");
|
|
3069
|
-
}
|
|
3070
|
-
return { codexHome, configPath: configPath2, hooksPath, detected, mcp, hooks, legacy_notify_bridge, notes };
|
|
3071
|
-
}
|
|
3072
|
-
function inspectCodexInstall(home) {
|
|
3073
|
-
const homes = resolveCodexHomes({ home });
|
|
3074
|
-
const entries = homes.map((codexHome) => inspectCodexHome(codexHome));
|
|
3075
|
-
const primary = entries[0];
|
|
3076
|
-
const detected = entries.some((entry) => entry.detected);
|
|
3077
|
-
const notes = [...primary.notes];
|
|
3078
|
-
for (const entry of entries.slice(1)) {
|
|
3079
|
-
for (const note of entry.notes) {
|
|
3080
|
-
notes.push(`${basename2(entry.codexHome)}: ${note}`);
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
1075
|
+
function stdioOpts() {
|
|
3083
1076
|
return {
|
|
3084
|
-
|
|
3085
|
-
detected,
|
|
3086
|
-
mcp: entries.every((entry) => entry.mcp),
|
|
3087
|
-
hooks: entries.every((entry) => entry.hooks),
|
|
3088
|
-
legacy_notify_bridge: entries.some((entry) => entry.legacy_notify_bridge),
|
|
3089
|
-
config_path: primary.configPath,
|
|
3090
|
-
hook_path: primary.hooksPath,
|
|
3091
|
-
notes
|
|
1077
|
+
stdio: "ignore"
|
|
3092
1078
|
};
|
|
3093
1079
|
}
|
|
3094
|
-
function
|
|
3095
|
-
|
|
3096
|
-
const hooks = group.hooks;
|
|
3097
|
-
if (!Array.isArray(hooks)) return false;
|
|
3098
|
-
return hooks.some(
|
|
3099
|
-
(hook) => hook && typeof hook === "object" && typeof hook.command === "string" && hook.command.includes(tag)
|
|
3100
|
-
);
|
|
1080
|
+
function ok(message) {
|
|
1081
|
+
return { enabled: true, ok: true, message };
|
|
3101
1082
|
}
|
|
3102
|
-
function
|
|
3103
|
-
|
|
3104
|
-
"# Recall Doctor",
|
|
3105
|
-
"",
|
|
3106
|
-
`DB: ${report.db_path}`,
|
|
3107
|
-
`DB ver: ${report.db_user_version}/${report.db_target_version}`
|
|
3108
|
-
];
|
|
3109
|
-
if (report.embeddings) {
|
|
3110
|
-
lines.push(`Embed: ${report.embeddings.provider}`);
|
|
3111
|
-
lines.push(`Model: ${report.embeddings.model}`);
|
|
3112
|
-
lines.push(`Dims: index=${report.embeddings.index_dimensions} canonical=${report.embeddings.canonical_dimensions}`);
|
|
3113
|
-
lines.push(`Cache: ${report.embeddings.size_label} @ ${report.embeddings.cache_path}`);
|
|
3114
|
-
} else {
|
|
3115
|
-
lines.push("Embed: disabled");
|
|
3116
|
-
}
|
|
3117
|
-
if (report.launchd) {
|
|
3118
|
-
lines.push(`Launchd: ${report.launchd.installed ? "installed" : "missing"} / ${report.launchd.loaded ? "loaded" : "not loaded"}${report.launchd.state ? ` (${report.launchd.state})` : ""}`);
|
|
3119
|
-
}
|
|
3120
|
-
if (report.systemd) {
|
|
3121
|
-
lines.push(`Systemd: ${report.systemd.installed ? "installed" : "missing"} / ${report.systemd.loaded ? "loaded" : "not loaded"}${report.systemd.state ? ` (${report.systemd.state})` : ""}`);
|
|
3122
|
-
}
|
|
3123
|
-
lines.push("", "## Agents");
|
|
3124
|
-
for (const agent of report.agents) {
|
|
3125
|
-
const label = agent.agent.padEnd(14);
|
|
3126
|
-
if (!agent.detected) {
|
|
3127
|
-
lines.push(`${label} not detected`);
|
|
3128
|
-
continue;
|
|
3129
|
-
}
|
|
3130
|
-
const mcp = agent.mcp ? "ok" : "MISSING";
|
|
3131
|
-
const legacy = agent.legacy_notify_bridge ? " (legacy notify bridge)" : "";
|
|
3132
|
-
const claudeMd = agent.claude_md ? ` claude.md:${agent.claude_md === "current" ? "ok" : agent.claude_md.toUpperCase()}` : "";
|
|
3133
|
-
const wiring = agent.hookless ? ` rules:${agent.rules === "current" ? "ok" : (agent.rules ?? "missing").toUpperCase()}` : ` hooks:${agent.hooks ? "configured" : "MISSING"}`;
|
|
3134
|
-
lines.push(`${label} mcp:${mcp}${wiring}${claudeMd}${legacy}`);
|
|
3135
|
-
if (agent.hook_activity) {
|
|
3136
|
-
const activity = agent.hook_activity;
|
|
3137
|
-
lines.push(` invocation:${activity.status} last-success:${activity.last_success_at ?? "none"} (model delivery unverified)`);
|
|
3138
|
-
for (const event of ["session_started", "prompt_submitted", "tool_invoked", "session_ended"]) {
|
|
3139
|
-
lines.push(` ${event}: ${activity.events[event] ?? "never"}`);
|
|
3140
|
-
}
|
|
3141
|
-
}
|
|
3142
|
-
for (const trust of agent.hook_trust ?? []) {
|
|
3143
|
-
lines.push(` ${basename2(trust.home)} trust:${trust.status}${trust.error ? ` (${trust.error})` : ""}`);
|
|
3144
|
-
if (trust.status === "review-required") lines.push(" Review the current Recall commands in Codex /hooks for this profile.");
|
|
3145
|
-
}
|
|
3146
|
-
for (const note of agent.notes) {
|
|
3147
|
-
lines.push(` - ${note}`);
|
|
3148
|
-
}
|
|
3149
|
-
}
|
|
3150
|
-
if (report.cleanup) {
|
|
3151
|
-
lines.push("", "## Cleanup");
|
|
3152
|
-
if (report.cleanup.last_run_at) {
|
|
3153
|
-
const actions = Object.entries(report.cleanup.last_run_actions).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
3154
|
-
lines.push(`Last run: ${report.cleanup.last_run_id?.slice(0, 8)} at ${report.cleanup.last_run_at.slice(0, 19)}`);
|
|
3155
|
-
lines.push(`Actions: ${actions || "(none)"}`);
|
|
3156
|
-
} else {
|
|
3157
|
-
lines.push("Last run: never");
|
|
3158
|
-
}
|
|
3159
|
-
lines.push(`Total runs: ${report.cleanup.total_runs}`);
|
|
3160
|
-
lines.push(`Pending correction candidates: ${report.cleanup.pending_candidate_corrections}`);
|
|
3161
|
-
const total = report.cleanup.total_injections ?? report.cleanup.resolved_injections;
|
|
3162
|
-
const resolved = report.cleanup.resolved_injections;
|
|
3163
|
-
lines.push(`Outcome coverage (last 14d): ${resolved}/${total} resolved; ${total - resolved} unknown. Selection is not proof of model delivery.`);
|
|
3164
|
-
if (report.cleanup.followed_rate_resolved != null) {
|
|
3165
|
-
const pct = (report.cleanup.followed_rate_resolved * 100).toFixed(1);
|
|
3166
|
-
lines.push(`Followed rate (last 14d, of ${report.cleanup.resolved_injections} resolved): ${pct}%`);
|
|
3167
|
-
} else {
|
|
3168
|
-
lines.push(`Followed rate (last 14d): n/a (no resolved injections)`);
|
|
3169
|
-
}
|
|
3170
|
-
}
|
|
3171
|
-
if (report.dispatcher) {
|
|
3172
|
-
lines.push("", "## Dispatcher (LLM refinement)");
|
|
3173
|
-
const provs = report.dispatcher.providers_configured;
|
|
3174
|
-
lines.push(`Providers visible to this CLI: ${provs.length === 0 ? "none; daemon may have separate credentials" : provs.join(", ")}`);
|
|
3175
|
-
const pendingEntries = Object.entries(report.dispatcher.pending_tasks);
|
|
3176
|
-
if (pendingEntries.length === 0) {
|
|
3177
|
-
lines.push("Pending tasks: 0");
|
|
3178
|
-
} else {
|
|
3179
|
-
const total = pendingEntries.reduce((s, [, n]) => s + n, 0);
|
|
3180
|
-
lines.push(`Pending tasks: ${total} (${pendingEntries.map(([k, n]) => `${k}=${n}`).join(", ")})`);
|
|
3181
|
-
}
|
|
3182
|
-
if (report.dispatcher.last_dispatch_at) {
|
|
3183
|
-
lines.push(`Last dispatch: ${report.dispatcher.last_dispatch_at.slice(0, 19)} (${report.dispatcher.last_dispatch_outcome ?? "unknown"})`);
|
|
3184
|
-
} else {
|
|
3185
|
-
lines.push("Last dispatch: never");
|
|
3186
|
-
}
|
|
3187
|
-
if (provs.length === 0 && pendingEntries.length > 0) {
|
|
3188
|
-
lines.push("Tasks are queued. Check the running daemon's dispatch status before changing credentials; this CLI may have a different environment.");
|
|
3189
|
-
}
|
|
3190
|
-
}
|
|
3191
|
-
if (report.app_registrations?.supported && report.app_registrations.stray_paths.length > 0) {
|
|
3192
|
-
const strays = report.app_registrations.stray_paths;
|
|
3193
|
-
lines.push("", "## Stray app registrations");
|
|
3194
|
-
lines.push(
|
|
3195
|
-
`macOS is offering ${strays.length} Recall.app bundle(s) besides the installed one.`
|
|
3196
|
-
);
|
|
3197
|
-
for (const path of strays.slice(0, 10)) lines.push(`- ${path}`);
|
|
3198
|
-
if (strays.length > 10) lines.push(`- ...and ${strays.length - 10} more`);
|
|
3199
|
-
lines.push("Run `recall doctor --fix` to unregister them (files are left untouched).");
|
|
3200
|
-
}
|
|
3201
|
-
if (report.upgrade.available) {
|
|
3202
|
-
lines.push("", "## Upgrade available");
|
|
3203
|
-
for (const reason of report.upgrade.reasons) {
|
|
3204
|
-
lines.push(`- ${reason}`);
|
|
3205
|
-
}
|
|
3206
|
-
lines.push("Run `recall doctor --fix` or `recall setup --yes` to apply.");
|
|
3207
|
-
}
|
|
3208
|
-
return lines.join("\n");
|
|
1083
|
+
function skipped(message) {
|
|
1084
|
+
return { enabled: false, ok: false, message };
|
|
3209
1085
|
}
|
|
3210
1086
|
|
|
1087
|
+
// src/cli.ts
|
|
1088
|
+
import { createRequire } from "module";
|
|
1089
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1090
|
+
|
|
3211
1091
|
// src/data/purge.ts
|
|
3212
1092
|
init_define_RECALL_BUILD_INFO();
|
|
3213
|
-
import { execFileSync as
|
|
1093
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
3214
1094
|
import {
|
|
3215
|
-
existsSync as
|
|
3216
|
-
readFileSync
|
|
1095
|
+
existsSync as existsSync2,
|
|
1096
|
+
readFileSync,
|
|
3217
1097
|
readdirSync,
|
|
3218
|
-
rmSync as
|
|
1098
|
+
rmSync as rmSync2,
|
|
3219
1099
|
rmdirSync
|
|
3220
1100
|
} from "fs";
|
|
3221
|
-
import { homedir
|
|
3222
|
-
import { dirname as
|
|
1101
|
+
import { homedir } from "os";
|
|
1102
|
+
import { dirname as dirname2, join as join3, parse, resolve as resolve2 } from "path";
|
|
3223
1103
|
init_keychain();
|
|
3224
1104
|
|
|
3225
1105
|
// src/daemon/service.ts
|
|
@@ -3268,12 +1148,12 @@ var PROVIDERS = [
|
|
|
3268
1148
|
"azure-openai"
|
|
3269
1149
|
];
|
|
3270
1150
|
function resolveRecallDataDir(options = {}) {
|
|
3271
|
-
const home =
|
|
3272
|
-
return
|
|
1151
|
+
const home = resolve2(options.homeDir ?? homedir());
|
|
1152
|
+
return resolve2(options.dataDir ?? process.env.RECALL_DATA_DIR ?? join3(home, ".recall"));
|
|
3273
1153
|
}
|
|
3274
1154
|
function purgeLocalData(options = {}) {
|
|
3275
1155
|
const dryRun = options.dryRun ?? false;
|
|
3276
|
-
const home =
|
|
1156
|
+
const home = resolve2(options.homeDir ?? homedir());
|
|
3277
1157
|
const dataDir = resolveRecallDataDir({ dataDir: options.dataDir, homeDir: home });
|
|
3278
1158
|
assertSafeDataDir(dataDir, home);
|
|
3279
1159
|
const repoRoots = options.repoRoots ?? configuredRepoRoots(home);
|
|
@@ -3326,8 +1206,8 @@ function purgeLocalData(options = {}) {
|
|
|
3326
1206
|
continue;
|
|
3327
1207
|
}
|
|
3328
1208
|
try {
|
|
3329
|
-
|
|
3330
|
-
removeDirectoryIfEmpty(
|
|
1209
|
+
rmSync2(contextPath, { force: true });
|
|
1210
|
+
removeDirectoryIfEmpty(dirname2(contextPath));
|
|
3331
1211
|
actions.push({
|
|
3332
1212
|
category: "artifact",
|
|
3333
1213
|
target: contextPath,
|
|
@@ -3341,14 +1221,14 @@ function purgeLocalData(options = {}) {
|
|
|
3341
1221
|
actions.push({
|
|
3342
1222
|
category: "data",
|
|
3343
1223
|
target: dataDir,
|
|
3344
|
-
status:
|
|
1224
|
+
status: existsSync2(dataDir) ? "planned" : "absent",
|
|
3345
1225
|
detail: "database, WAL, backups, logs, caches, models, and sync state"
|
|
3346
1226
|
});
|
|
3347
1227
|
} else {
|
|
3348
1228
|
try {
|
|
3349
1229
|
closeDb();
|
|
3350
|
-
const existed =
|
|
3351
|
-
|
|
1230
|
+
const existed = existsSync2(dataDir);
|
|
1231
|
+
rmSync2(dataDir, { recursive: true, force: true });
|
|
3352
1232
|
actions.push({
|
|
3353
1233
|
category: "data",
|
|
3354
1234
|
target: dataDir,
|
|
@@ -3375,7 +1255,7 @@ function assertSafeDataDir(dataDir, home) {
|
|
|
3375
1255
|
}
|
|
3376
1256
|
function configuredRepoRoots(home) {
|
|
3377
1257
|
const configured = process.env.RECALL_REPO_ROOTS?.split(",").map((value) => value.trim()).filter(Boolean);
|
|
3378
|
-
return configured?.length ? configured.map((value) =>
|
|
1258
|
+
return configured?.length ? configured.map((value) => resolve2(value)) : [join3(home, "Projects")];
|
|
3379
1259
|
}
|
|
3380
1260
|
function findGeneratedContextArtifacts(repoRoots) {
|
|
3381
1261
|
const paths = /* @__PURE__ */ new Set();
|
|
@@ -3388,9 +1268,9 @@ function findGeneratedContextArtifacts(repoRoots) {
|
|
|
3388
1268
|
return [...paths].sort();
|
|
3389
1269
|
}
|
|
3390
1270
|
function isGeneratedContext(path) {
|
|
3391
|
-
if (!
|
|
1271
|
+
if (!existsSync2(path)) return false;
|
|
3392
1272
|
try {
|
|
3393
|
-
return
|
|
1273
|
+
return readFileSync(path, "utf8").startsWith(GENERATED_CONTEXT_MARKER);
|
|
3394
1274
|
} catch {
|
|
3395
1275
|
return false;
|
|
3396
1276
|
}
|
|
@@ -3458,7 +1338,7 @@ function removeIntegrations(repoRoots) {
|
|
|
3458
1338
|
function removeCliMcp(command, args, cwd) {
|
|
3459
1339
|
const target = `${command} Recall MCP${cwd ? ` in ${cwd}` : ""}`;
|
|
3460
1340
|
try {
|
|
3461
|
-
|
|
1341
|
+
execFileSync2(command, ["mcp", "get", "recall"], {
|
|
3462
1342
|
cwd,
|
|
3463
1343
|
stdio: "ignore",
|
|
3464
1344
|
timeout: 1e4
|
|
@@ -3472,7 +1352,7 @@ function removeCliMcp(command, args, cwd) {
|
|
|
3472
1352
|
};
|
|
3473
1353
|
}
|
|
3474
1354
|
try {
|
|
3475
|
-
|
|
1355
|
+
execFileSync2(command, args, {
|
|
3476
1356
|
cwd,
|
|
3477
1357
|
stdio: "ignore",
|
|
3478
1358
|
timeout: 1e4
|
|
@@ -3589,7 +1469,7 @@ program.command("doctor").description("Show local Recall runtime, DB, embedding,
|
|
|
3589
1469
|
const finalReport = opts.fix ? getDoctorReport() : report;
|
|
3590
1470
|
const codexEntry = finalReport.agents.find((agent) => agent.agent === "codex" && agent.detected);
|
|
3591
1471
|
if (codexEntry) {
|
|
3592
|
-
const { inspectCodexTrust } = await import("./codex-trust-
|
|
1472
|
+
const { inspectCodexTrust } = await import("./codex-trust-PM37UGXC.js");
|
|
3593
1473
|
codexEntry.hook_trust = await inspectCodexTrust();
|
|
3594
1474
|
}
|
|
3595
1475
|
if (opts.json) {
|
|
@@ -3760,20 +1640,20 @@ function safeHookAction(event, action) {
|
|
|
3760
1640
|
} catch (error) {
|
|
3761
1641
|
let logPath = "~/.recall/logs/hook-errors.log";
|
|
3762
1642
|
try {
|
|
3763
|
-
const { appendFileSync, mkdirSync
|
|
3764
|
-
const { homedir:
|
|
3765
|
-
const dir =
|
|
3766
|
-
|
|
3767
|
-
logPath =
|
|
1643
|
+
const { appendFileSync, mkdirSync, statSync, renameSync, rmSync: rmSync3 } = await import("fs");
|
|
1644
|
+
const { homedir: homedir2 } = await import("os");
|
|
1645
|
+
const dir = join4(homedir2(), ".recall", "logs");
|
|
1646
|
+
mkdirSync(dir, { recursive: true });
|
|
1647
|
+
logPath = join4(dir, "hook-errors.log");
|
|
3768
1648
|
try {
|
|
3769
1649
|
const maxBytes = parseInt(process.env.RECALL_HOOK_LOG_MAX_BYTES ?? String(1024 * 1024), 10);
|
|
3770
1650
|
if (maxBytes > 0 && statSync(logPath).size >= maxBytes) {
|
|
3771
1651
|
const rotated = `${logPath}.1`;
|
|
3772
1652
|
try {
|
|
3773
|
-
|
|
1653
|
+
rmSync3(rotated, { force: true });
|
|
3774
1654
|
} catch {
|
|
3775
1655
|
}
|
|
3776
|
-
|
|
1656
|
+
renameSync(logPath, rotated);
|
|
3777
1657
|
}
|
|
3778
1658
|
} catch {
|
|
3779
1659
|
}
|
|
@@ -3921,7 +1801,7 @@ program.command("ump").description("Serve the Universal Memory Protocol (UMP) ov
|
|
|
3921
1801
|
});
|
|
3922
1802
|
program.command("scan").description("Scan a repository and bootstrap memories").argument("[path]", "Repository path", ".").option("-s, --session <id>", "Session ID").action((path, opts) => {
|
|
3923
1803
|
const db = initDb();
|
|
3924
|
-
const repoPath =
|
|
1804
|
+
const repoPath = resolve3(path);
|
|
3925
1805
|
const ids = scanAndStore(db, repoPath);
|
|
3926
1806
|
const artifact = writeRepoContextArtifact(db, {
|
|
3927
1807
|
repo: inferRepoSlugFromPath(repoPath),
|
|
@@ -4168,7 +2048,7 @@ program.command("export").description("Export memories as markdown instruction f
|
|
|
4168
2048
|
console.error(`Could not resolve local repo path for ${opts.repo}`);
|
|
4169
2049
|
process.exit(1);
|
|
4170
2050
|
}
|
|
4171
|
-
content =
|
|
2051
|
+
content = readFileSync2(artifact.output_path, "utf-8");
|
|
4172
2052
|
if (!opts.output) {
|
|
4173
2053
|
console.log(content);
|
|
4174
2054
|
return;
|
|
@@ -4179,7 +2059,7 @@ program.command("export").description("Export memories as markdown instruction f
|
|
|
4179
2059
|
content = exportMarkdown(db, opts.repo);
|
|
4180
2060
|
}
|
|
4181
2061
|
if (opts.output) {
|
|
4182
|
-
|
|
2062
|
+
writeFileSync(opts.output, content);
|
|
4183
2063
|
console.log(`Exported to ${opts.output}`);
|
|
4184
2064
|
} else {
|
|
4185
2065
|
console.log(content);
|
|
@@ -4187,7 +2067,7 @@ program.command("export").description("Export memories as markdown instruction f
|
|
|
4187
2067
|
});
|
|
4188
2068
|
program.command("publish").description("Write repo-local .recall/context.md for the current repo").argument("[path]", "Repository path", ".").action((path) => {
|
|
4189
2069
|
const db = initDb();
|
|
4190
|
-
const repoPath =
|
|
2070
|
+
const repoPath = resolve3(path);
|
|
4191
2071
|
const artifact = writeRepoContextArtifact(db, {
|
|
4192
2072
|
repo: inferRepoSlugFromPath(repoPath),
|
|
4193
2073
|
repo_path: repoPath
|
|
@@ -4316,7 +2196,7 @@ evalCmd.command("value-retrieval").description("Run retrieval eval cases synthes
|
|
|
4316
2196
|
});
|
|
4317
2197
|
let snapshot = null;
|
|
4318
2198
|
if (opts.snapshot) {
|
|
4319
|
-
const { computeQualityReport, recordQualitySnapshot } = await import("./quality-
|
|
2199
|
+
const { computeQualityReport, recordQualitySnapshot } = await import("./quality-N4F5LTCY.js");
|
|
4320
2200
|
const qualityReport = computeQualityReport(db, { sinceIso: report.since });
|
|
4321
2201
|
snapshot = recordQualitySnapshot(
|
|
4322
2202
|
db,
|
|
@@ -4825,15 +2705,15 @@ uiCmd.command("status").description("Show WebUI status").option("--daemon-port <
|
|
|
4825
2705
|
var graphCmd = program.command("graph").description("Inspect and rebuild the knowledge graph (entities + relations)");
|
|
4826
2706
|
graphCmd.command("stats").description("Show entity/relation counts").action(async () => {
|
|
4827
2707
|
const db = initDb();
|
|
4828
|
-
const { countEntities, countRelations } = await import("./store-
|
|
2708
|
+
const { countEntities, countRelations } = await import("./store-JF27SEIB.js");
|
|
4829
2709
|
console.log(`entities: ${countEntities(db)}`);
|
|
4830
2710
|
console.log(`relations: ${countRelations(db)}`);
|
|
4831
2711
|
});
|
|
4832
2712
|
graphCmd.command("backfill").description("Run the heuristic extractor over every active memory (idempotent)").option("--repo <repo>", "Limit to a single repo").option("--limit <n>", "Cap rows processed", "10000").option("--rebuild", "Clear all existing entities/relations first, then re-extract").action(async (opts) => {
|
|
4833
2713
|
const db = initDb();
|
|
4834
|
-
const { ingestMemoryHeuristic } = await import("./ingest-
|
|
2714
|
+
const { ingestMemoryHeuristic } = await import("./ingest-YSSZIIGV.js");
|
|
4835
2715
|
if (opts.rebuild) {
|
|
4836
|
-
const { clearGraph } = await import("./store-
|
|
2716
|
+
const { clearGraph } = await import("./store-JF27SEIB.js");
|
|
4837
2717
|
clearGraph(db);
|
|
4838
2718
|
console.log("Cleared existing graph entities and relations.");
|
|
4839
2719
|
}
|
|
@@ -4855,7 +2735,7 @@ graphCmd.command("backfill").description("Run the heuristic extractor over every
|
|
|
4855
2735
|
});
|
|
4856
2736
|
graphCmd.command("entities").description("List entities").option("--repo <repo>", "Filter by repo").option("--kind <kind>", "Filter by entity kind").option("--search <q>", "Substring filter on name").option("--limit <n>", "Max rows", "50").action(async (opts) => {
|
|
4857
2737
|
const db = initDb();
|
|
4858
|
-
const { listEntities } = await import("./store-
|
|
2738
|
+
const { listEntities } = await import("./store-JF27SEIB.js");
|
|
4859
2739
|
const rows = listEntities(db, {
|
|
4860
2740
|
repo: opts.repo,
|
|
4861
2741
|
kind: opts.kind,
|
|
@@ -4874,8 +2754,8 @@ graphCmd.command("entities").description("List entities").option("--repo <repo>"
|
|
|
4874
2754
|
});
|
|
4875
2755
|
graphCmd.command("query <query...>").description("Run graph-aware retrieval for a query").option("--repo <repo>", "Restrict to repo").option("--hops <n>", "Graph hops", "2").option("--limit <n>", "Max hits", "10").action(async (queryTokens, opts) => {
|
|
4876
2756
|
const db = initDb();
|
|
4877
|
-
const { graphQuery } = await import("./retrieval-
|
|
4878
|
-
const { loadEmbeddingConfigFromEnv: loadEmbeddingConfigFromEnv2 } = await import("./embeddings-
|
|
2757
|
+
const { graphQuery } = await import("./retrieval-MUGT5TBL.js");
|
|
2758
|
+
const { loadEmbeddingConfigFromEnv: loadEmbeddingConfigFromEnv2 } = await import("./embeddings-KX3FG4W5.js");
|
|
4879
2759
|
const embeddingConfig = loadEmbeddingConfigFromEnv2();
|
|
4880
2760
|
const result = await graphQuery(db, queryTokens.join(" "), embeddingConfig, {
|
|
4881
2761
|
repo: opts.repo,
|
|
@@ -4891,7 +2771,7 @@ graphCmd.command("query <query...>").description("Run graph-aware retrieval for
|
|
|
4891
2771
|
});
|
|
4892
2772
|
var maintenanceCmd = program.command("maintenance").description("Inspect and manage the delegated maintenance task queue");
|
|
4893
2773
|
maintenanceCmd.command("stats").description("Show backlog counts, completion stats, and mean latency").action(async () => {
|
|
4894
|
-
const { getTaskStats } = await import("./tasks-
|
|
2774
|
+
const { getTaskStats } = await import("./tasks-YQVF2CV3.js");
|
|
4895
2775
|
const db = initDb();
|
|
4896
2776
|
const stats = getTaskStats(db);
|
|
4897
2777
|
console.log(`Total tasks: ${stats.total}`);
|
|
@@ -4917,7 +2797,7 @@ maintenanceCmd.command("stats").description("Show backlog counts, completion sta
|
|
|
4917
2797
|
}
|
|
4918
2798
|
});
|
|
4919
2799
|
maintenanceCmd.command("list").description("List tasks (default: pending)").option("-s, --status <status>", "pending|claimed|completed|abandoned", "pending").option("-k, --kind <kind>", "Filter by kind").option("-r, --repo <repo>", "Filter by repo").option("-n, --limit <n>", "Max entries", "20").action(async (opts) => {
|
|
4920
|
-
const { listTasks } = await import("./tasks-
|
|
2800
|
+
const { listTasks } = await import("./tasks-YQVF2CV3.js");
|
|
4921
2801
|
const db = initDb();
|
|
4922
2802
|
const tasks = listTasks(db, {
|
|
4923
2803
|
status: opts.status,
|
|
@@ -4939,7 +2819,7 @@ maintenanceCmd.command("list").description("List tasks (default: pending)").opti
|
|
|
4939
2819
|
}
|
|
4940
2820
|
});
|
|
4941
2821
|
maintenanceCmd.command("drop").description("Delete a task by id (or id prefix)").argument("<task-id>", "Task id or prefix").action(async (taskIdArg) => {
|
|
4942
|
-
const { deleteTask, listTasks } = await import("./tasks-
|
|
2822
|
+
const { deleteTask, listTasks } = await import("./tasks-YQVF2CV3.js");
|
|
4943
2823
|
const db = initDb();
|
|
4944
2824
|
const all = listTasks(db, { limit: 1e4 });
|
|
4945
2825
|
const matches = all.filter((t) => t.id === taskIdArg || t.id.startsWith(taskIdArg));
|
|
@@ -4958,7 +2838,7 @@ maintenanceCmd.command("drop").description("Delete a task by id (or id prefix)")
|
|
|
4958
2838
|
});
|
|
4959
2839
|
var credentialsCmd = maintenanceCmd.command("credentials").description("Manage LLM provider API keys in macOS Keychain (env fallback on other platforms)");
|
|
4960
2840
|
credentialsCmd.command("list", { isDefault: true }).description("Show which providers have credentials available").action(async () => {
|
|
4961
|
-
const { listCredentials } = await import("./keychain-
|
|
2841
|
+
const { listCredentials } = await import("./keychain-675KT5UZ.js");
|
|
4962
2842
|
const creds = listCredentials();
|
|
4963
2843
|
if (creds.length === 0) {
|
|
4964
2844
|
console.log("No API keys configured. Set one with:");
|
|
@@ -4972,7 +2852,7 @@ credentialsCmd.command("list", { isDefault: true }).description("Show which prov
|
|
|
4972
2852
|
}
|
|
4973
2853
|
});
|
|
4974
2854
|
credentialsCmd.command("set").description("Store credentials for an LLM provider in the macOS Keychain").argument("<provider>", "openai|anthropic|azure").argument("[key]", "API key (prompts via stdin if omitted; required for openai/anthropic and for azure unless --stdin-json is used)").option("--endpoint <url>", "Azure OpenAI resource endpoint (e.g. https://myresource.openai.azure.com)").option("--deployment <name>", "Azure OpenAI deployment name").option("--api-version <version>", "Azure OpenAI api-version (e.g. 2024-10-21)").option("--stdin-json", "Read the azure config (endpoint/deployment/api_version/key) as a JSON object from stdin").action(async (providerArg, keyArg, opts) => {
|
|
4975
|
-
const { setApiKey, setAzureConfig } = await import("./keychain-
|
|
2855
|
+
const { setApiKey, setAzureConfig } = await import("./keychain-675KT5UZ.js");
|
|
4976
2856
|
const provider = providerArg === "azure" ? "azure-openai" : providerArg;
|
|
4977
2857
|
if (provider === "openai" || provider === "anthropic") {
|
|
4978
2858
|
const key = keyArg ?? await readStdinKey();
|
|
@@ -5034,7 +2914,7 @@ credentialsCmd.command("set").description("Store credentials for an LLM provider
|
|
|
5034
2914
|
process.exit(1);
|
|
5035
2915
|
});
|
|
5036
2916
|
credentialsCmd.command("clear").description("Remove provider credentials from the macOS Keychain").argument("<provider>", "openai|anthropic|azure").action(async (providerArg) => {
|
|
5037
|
-
const { deleteApiKey: deleteApiKey2 } = await import("./keychain-
|
|
2917
|
+
const { deleteApiKey: deleteApiKey2 } = await import("./keychain-675KT5UZ.js");
|
|
5038
2918
|
const provider = providerArg === "azure" ? "azure-openai" : providerArg;
|
|
5039
2919
|
if (provider !== "openai" && provider !== "anthropic" && provider !== "azure-openai") {
|
|
5040
2920
|
console.error(`Provider must be "openai", "anthropic", or "azure", got "${providerArg}".`);
|
|
@@ -5045,8 +2925,8 @@ credentialsCmd.command("clear").description("Remove provider credentials from th
|
|
|
5045
2925
|
else console.log(`No ${provider} credentials found in Keychain.`);
|
|
5046
2926
|
});
|
|
5047
2927
|
maintenanceCmd.command("dispatch").description("Run the daemon-owned dispatcher once against pending maintenance tasks (requires a configured LLM provider)").option("--provider <provider>", "openai|anthropic|azure-openai (defaults to whichever is configured)").option("--model <model>", "Model override").option("--kind <kind>", "Restrict to a single task kind (repeatable)", (value, acc = []) => [...acc, value], []).option("--repo <repo>", "Restrict to a single repo").option("--max <n>", "Max tasks to run this round", "5").option("--dry-run", "Show which tasks would be dispatched; do not call the LLM").option("--preview", "Show the actual prompts that would be sent (no provider needed; no LLM call)").option("--json", "Emit the raw JSON report").action(async (opts) => {
|
|
5048
|
-
const { dispatchPendingTasks, formatDispatchReport, buildPrompt } = await import("./dispatcher-
|
|
5049
|
-
const { listTasks } = await import("./tasks-
|
|
2928
|
+
const { dispatchPendingTasks, formatDispatchReport, buildPrompt } = await import("./dispatcher-XDBM2EY4.js");
|
|
2929
|
+
const { listTasks } = await import("./tasks-YQVF2CV3.js");
|
|
5050
2930
|
const db = initDb();
|
|
5051
2931
|
if (opts.preview) {
|
|
5052
2932
|
const pending = listTasks(db, {
|
|
@@ -5103,12 +2983,12 @@ ${p.prompt.max_output_tokens}
|
|
|
5103
2983
|
console.log(formatDispatchReport(report));
|
|
5104
2984
|
});
|
|
5105
2985
|
maintenanceCmd.command("quarantine-generated").description("Preview memories supported only by generated messages; preserve them outside injection").option("--apply", "Quarantine matching memories with reversible audit snapshots").action(async (opts) => {
|
|
5106
|
-
const { quarantineGeneratedMemories } = await import("./provenance-
|
|
2986
|
+
const { quarantineGeneratedMemories } = await import("./provenance-HBF4LGHJ.js");
|
|
5107
2987
|
const ids = quarantineGeneratedMemories(initDb(), Boolean(opts.apply));
|
|
5108
2988
|
console.log(JSON.stringify({ applied: Boolean(opts.apply), count: ids.length, memory_ids: ids }, null, 2));
|
|
5109
2989
|
});
|
|
5110
2990
|
maintenanceCmd.command("cleanup").description("Run deterministic, LLM-free cleanup for duplicate, low-quality, stale, and mis-scoped memories").option("--apply", "Persist changes (default is dry-run)").option("--only <action>", "Restrict to one action: dedupe_exact_merge|reject_fragment_candidate|promote_repeat_correction|suppress_unproductive_command|globalize_cross_repo|reject_test_fixture_repo|reject_invalid_scope|reject_generic_scanned_tooling").option("--revert <run-id>", "Revert a previous cleanup run (id or 8-char prefix)").option("--list", "List recent cleanup runs").option("--json", "Emit the raw JSON report").action(async (opts) => {
|
|
5111
|
-
const { runDeterministicCleanup, formatCleanupReport, revertCleanupRun, listCleanupRuns } = await import("./cleanup-
|
|
2991
|
+
const { runDeterministicCleanup, formatCleanupReport, revertCleanupRun, listCleanupRuns } = await import("./cleanup-SAVG7IDQ.js");
|
|
5112
2992
|
const db = initDb();
|
|
5113
2993
|
if (opts.list) {
|
|
5114
2994
|
const runs = listCleanupRuns(db);
|
|
@@ -5162,7 +3042,7 @@ maintenanceCmd.command("quality").description("Show injection outcome distributi
|
|
|
5162
3042
|
recordQualitySnapshot,
|
|
5163
3043
|
listQualitySnapshots,
|
|
5164
3044
|
diffQualitySnapshots
|
|
5165
|
-
} = await import("./quality-
|
|
3045
|
+
} = await import("./quality-N4F5LTCY.js");
|
|
5166
3046
|
const db = initDb();
|
|
5167
3047
|
if (opts.history) {
|
|
5168
3048
|
const snaps = listQualitySnapshots(db);
|
|
@@ -5223,7 +3103,7 @@ maintenanceCmd.command("value-backfill").description("Backfill memory value even
|
|
|
5223
3103
|
const {
|
|
5224
3104
|
backfillMemoryValueEvents,
|
|
5225
3105
|
formatMemoryValueBackfillReport
|
|
5226
|
-
} = await import("./memory-value-
|
|
3106
|
+
} = await import("./memory-value-UKKTPVVF.js");
|
|
5227
3107
|
const db = initDb();
|
|
5228
3108
|
const report = backfillMemoryValueEvents(db, {
|
|
5229
3109
|
sinceIso: opts.since,
|
|
@@ -5236,7 +3116,7 @@ maintenanceCmd.command("value-backfill").description("Backfill memory value even
|
|
|
5236
3116
|
console.log(formatMemoryValueBackfillReport(report));
|
|
5237
3117
|
});
|
|
5238
3118
|
maintenanceCmd.command("usage").description("Summarize LLM API usage (tokens, cost) across recent maintenance runs").option("--since <iso>", "Window start (default: last 30 days)").option("--limit <n>", "Recent-call rows to show", "10").option("--json", "Emit raw JSON summary").action(async (opts) => {
|
|
5239
|
-
const { summarizeUsage, formatUsageReport } = await import("./usage-
|
|
3119
|
+
const { summarizeUsage, formatUsageReport } = await import("./usage-XBJ6RTU7.js");
|
|
5240
3120
|
const db = initDb();
|
|
5241
3121
|
const summary = summarizeUsage(db, {
|
|
5242
3122
|
sinceIso: opts.since,
|
|
@@ -5365,7 +3245,7 @@ function findByPrefix(db, prefix) {
|
|
|
5365
3245
|
function isDirectCliInvocation(moduleUrl, argvPath) {
|
|
5366
3246
|
if (!argvPath) return false;
|
|
5367
3247
|
try {
|
|
5368
|
-
return
|
|
3248
|
+
return realpathSync(fileURLToPath2(moduleUrl)) === realpathSync(argvPath);
|
|
5369
3249
|
} catch {
|
|
5370
3250
|
return false;
|
|
5371
3251
|
}
|