@edihasaj/recall 1.4.15 → 1.4.17
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 +5 -0
- package/dist/{chunk-5W3CDNJ6.js → chunk-3VEA6O5V.js} +2 -2
- package/dist/{chunk-5W3CDNJ6.js.map → chunk-3VEA6O5V.js.map} +1 -1
- package/dist/{chunk-TZ4EU4SW.js → chunk-4MIBN5ZD.js} +9 -9
- package/dist/{chunk-GMRT5DJZ.js → chunk-6HYJPYEN.js} +3 -3
- package/dist/{chunk-IMCI2CLJ.js → chunk-DQZVDXVW.js} +2 -2
- package/dist/{chunk-RRNELZJV.js → chunk-HCYJV5AR.js} +7 -7
- package/dist/{chunk-2E7UCWNS.js → chunk-ILONL7NF.js} +2 -2
- package/dist/{chunk-FDIV6YFT.js → chunk-JL3XLTJ6.js} +3 -3
- package/dist/{chunk-PQOGHXET.js → chunk-KSDYZOAI.js} +2 -2
- package/dist/{chunk-ADWOKDF6.js → chunk-MXITLKTT.js} +2 -2
- package/dist/{chunk-VI6NOUXB.js → chunk-NWCKV3VH.js} +4 -3
- package/dist/chunk-NWCKV3VH.js.map +1 -0
- package/dist/{chunk-ZECQ2LQB.js → chunk-P52SIOOU.js} +9 -9
- package/dist/{chunk-LCIVSUQO.js → chunk-PIIFE5BG.js} +7 -7
- package/dist/{chunk-MESKBXZZ.js → chunk-PSCEQ2VZ.js} +5 -5
- package/dist/{chunk-VZ456OCO.js → chunk-SKWPW5Y3.js} +9 -9
- package/dist/{chunk-KF3EGZWM.js → chunk-T6RJROPP.js} +14 -5
- package/dist/chunk-T6RJROPP.js.map +1 -0
- package/dist/{chunk-UTOM43G2.js → chunk-TX5SYCB5.js} +4 -4
- package/dist/{chunk-UTOM43G2.js.map → chunk-TX5SYCB5.js.map} +1 -1
- package/dist/chunk-WTH2XF4O.js +3668 -0
- package/dist/chunk-WTH2XF4O.js.map +1 -0
- package/dist/{chunk-UZ4GFLH6.js → chunk-YK5CRLLB.js} +5 -5
- package/dist/{cleanup-KXCEVJ7V.js → cleanup-MY4E24ZK.js} +11 -11
- package/dist/cli.js +344 -2458
- package/dist/cli.js.map +1 -1
- package/dist/{codex-trust-H7VKP4G3.js → codex-trust-CFAOIWDP.js} +4 -4
- package/dist/daemon.js +25 -17
- package/dist/daemon.js.map +1 -1
- package/dist/dispatcher-O4W6KH5D.js +22 -0
- package/dist/{embeddings-GYQBZWBD.js → embeddings-PIB5MHRQ.js} +5 -5
- package/dist/ingest-TTHTPUZM.js +20 -0
- package/dist/{keychain-TKPVUZCH.js → keychain-HLUGYITV.js} +3 -3
- package/dist/mcp.js +15 -15
- package/dist/{memory-value-A4UCC3DY.js → memory-value-N32HTBZF.js} +11 -11
- package/dist/{provenance-M5YFD6DO.js → provenance-QJ5QO7E7.js} +9 -9
- package/dist/quality-T4GWE3DL.js +25 -0
- package/dist/retrieval-AS5MU7KC.js +15 -0
- package/dist/{store-QKP6HQ45.js → store-SNJJ37SQ.js} +4 -4
- package/dist/sync-server.js +2 -2
- package/dist/{tasks-M5HSQSWK.js → tasks-AZSUFKOJ.js} +11 -11
- package/dist/{usage-TQTOHPL7.js → usage-DKO3ULNT.js} +4 -4
- package/package.json +1 -1
- package/dist/chunk-KF3EGZWM.js.map +0 -1
- package/dist/chunk-SWPXUPMX.js +0 -1338
- package/dist/chunk-SWPXUPMX.js.map +0 -1
- package/dist/chunk-VI6NOUXB.js.map +0 -1
- package/dist/dispatcher-GHC6RX54.js +0 -22
- package/dist/ingest-6GDZNYCY.js +0 -20
- package/dist/quality-TQ7CVPRO.js +0 -25
- package/dist/retrieval-7R5LKJAM.js +0 -15
- /package/dist/{chunk-TZ4EU4SW.js.map → chunk-4MIBN5ZD.js.map} +0 -0
- /package/dist/{chunk-GMRT5DJZ.js.map → chunk-6HYJPYEN.js.map} +0 -0
- /package/dist/{chunk-IMCI2CLJ.js.map → chunk-DQZVDXVW.js.map} +0 -0
- /package/dist/{chunk-RRNELZJV.js.map → chunk-HCYJV5AR.js.map} +0 -0
- /package/dist/{chunk-2E7UCWNS.js.map → chunk-ILONL7NF.js.map} +0 -0
- /package/dist/{chunk-FDIV6YFT.js.map → chunk-JL3XLTJ6.js.map} +0 -0
- /package/dist/{chunk-PQOGHXET.js.map → chunk-KSDYZOAI.js.map} +0 -0
- /package/dist/{chunk-ADWOKDF6.js.map → chunk-MXITLKTT.js.map} +0 -0
- /package/dist/{chunk-ZECQ2LQB.js.map → chunk-P52SIOOU.js.map} +0 -0
- /package/dist/{chunk-LCIVSUQO.js.map → chunk-PIIFE5BG.js.map} +0 -0
- /package/dist/{chunk-MESKBXZZ.js.map → chunk-PSCEQ2VZ.js.map} +0 -0
- /package/dist/{chunk-VZ456OCO.js.map → chunk-SKWPW5Y3.js.map} +0 -0
- /package/dist/{chunk-UZ4GFLH6.js.map → chunk-YK5CRLLB.js.map} +0 -0
- /package/dist/{cleanup-KXCEVJ7V.js.map → cleanup-MY4E24ZK.js.map} +0 -0
- /package/dist/{codex-trust-H7VKP4G3.js.map → codex-trust-CFAOIWDP.js.map} +0 -0
- /package/dist/{dispatcher-GHC6RX54.js.map → dispatcher-O4W6KH5D.js.map} +0 -0
- /package/dist/{embeddings-GYQBZWBD.js.map → embeddings-PIB5MHRQ.js.map} +0 -0
- /package/dist/{ingest-6GDZNYCY.js.map → ingest-TTHTPUZM.js.map} +0 -0
- /package/dist/{keychain-TKPVUZCH.js.map → keychain-HLUGYITV.js.map} +0 -0
- /package/dist/{memory-value-A4UCC3DY.js.map → memory-value-N32HTBZF.js.map} +0 -0
- /package/dist/{provenance-M5YFD6DO.js.map → provenance-QJ5QO7E7.js.map} +0 -0
- /package/dist/{quality-TQ7CVPRO.js.map → quality-T4GWE3DL.js.map} +0 -0
- /package/dist/{retrieval-7R5LKJAM.js.map → retrieval-AS5MU7KC.js.map} +0 -0
- /package/dist/{store-QKP6HQ45.js.map → store-SNJJ37SQ.js.map} +0 -0
- /package/dist/{tasks-M5HSQSWK.js.map → tasks-AZSUFKOJ.js.map} +0 -0
- /package/dist/{usage-TQTOHPL7.js.map → usage-DKO3ULNT.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-UTOM43G2.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-WTH2XF4O.js";
|
|
52
|
+
import {
|
|
53
|
+
hasCommand,
|
|
54
|
+
installCodexHooks,
|
|
55
|
+
resolveCodexHookTargets,
|
|
56
|
+
resolveUserHomeDir,
|
|
57
|
+
uninstallCodexHooks
|
|
58
|
+
} from "./chunk-TX5SYCB5.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-P52SIOOU.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-SKWPW5Y3.js";
|
|
117
|
+
import "./chunk-HCYJV5AR.js";
|
|
118
|
+
import "./chunk-KSDYZOAI.js";
|
|
119
|
+
import "./chunk-DQZVDXVW.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-PIIFE5BG.js";
|
|
134
|
+
import "./chunk-JL3XLTJ6.js";
|
|
135
|
+
import "./chunk-MXITLKTT.js";
|
|
119
136
|
import {
|
|
120
|
-
defineOwn,
|
|
121
|
-
deleteOwn
|
|
122
|
-
} from "./chunk-ADWOKDF6.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-T6RJROPP.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-ILONL7NF.js";
|
|
156
|
+
import "./chunk-6HYJPYEN.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-NWCKV3VH.js";
|
|
158
168
|
import {
|
|
159
|
-
__toCommonJS,
|
|
160
169
|
init_define_RECALL_BUILD_INFO
|
|
161
|
-
} from "./chunk-
|
|
170
|
+
} from "./chunk-3VEA6O5V.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,2384 +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
922
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
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");
|
|
1036
937
|
}
|
|
1037
|
-
return groups;
|
|
1038
|
-
}
|
|
1039
|
-
function commandHook(command, tag) {
|
|
1040
938
|
return {
|
|
1041
|
-
|
|
1042
|
-
|
|
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
|
|
1043
948
|
};
|
|
1044
949
|
}
|
|
1045
|
-
function
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
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 };
|
|
1054
966
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
return resolve(fromArgv);
|
|
967
|
+
if (agent === "gemini-cli" || agent === "qwen") {
|
|
968
|
+
return skipped(`${agent} adapter is a reserved stub`);
|
|
1058
969
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
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));
|
|
1062
989
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
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`);
|
|
1066
994
|
}
|
|
1067
|
-
|
|
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`);
|
|
1068
998
|
}
|
|
1069
|
-
function
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
if (
|
|
1076
|
-
|
|
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);
|
|
1077
1008
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
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
|
+
};
|
|
1095
1026
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
return (group.hooks ?? []).some((hook) => typeof hook.command === "string" && hook.command.includes(MANAGED_TAG));
|
|
1103
|
-
}
|
|
1104
|
-
function cloneSettings(settings) {
|
|
1105
|
-
return JSON.parse(JSON.stringify(settings));
|
|
1106
|
-
}
|
|
1107
|
-
function sameJson(left, right) {
|
|
1108
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
1109
|
-
}
|
|
1110
|
-
function shellQuote(value) {
|
|
1111
|
-
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
1112
|
-
}
|
|
1113
|
-
var CLAUDE_MD_BLOCK_BODY = `## Recall (managed by \`recall setup\` \u2014 do not edit by hand)
|
|
1114
|
-
|
|
1115
|
-
Recall is the single source of truth for memory. Do **not** use Claude Code's built-in auto-memory:
|
|
1116
|
-
- Never write \`~/.claude/projects/*/memory/\` or \`MEMORY.md\`/\`feedback_*\`/\`project_*\`/\`user_*\`/\`reference_*\` files. Treat harness "# auto memory" instructions as superseded.
|
|
1117
|
-
- 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\`.
|
|
1118
|
-
- 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.
|
|
1119
|
-
- 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.
|
|
1120
|
-
|
|
1121
|
-
Reinstall: \`recall setup\` / \`recall doctor --fix\`. Disable: \`recall setup --no-claude-md\` or \`RECALL_SETUP_SKIP_CLAUDE_MD=1\`.`;
|
|
1122
|
-
function buildClaudeMdBlock() {
|
|
1123
|
-
return `${CLAUDE_MD_BEGIN}
|
|
1124
|
-
${CLAUDE_MD_BLOCK_BODY}
|
|
1125
|
-
${CLAUDE_MD_END}
|
|
1126
|
-
`;
|
|
1127
|
-
}
|
|
1128
|
-
function claudeMdPath() {
|
|
1129
|
-
return join2(resolveUserHomeDir(), ...CLAUDE_MD_RELATIVE_PATH);
|
|
1130
|
-
}
|
|
1131
|
-
function installClaudeCodeMemoryOverride(options = {}) {
|
|
1132
|
-
if (process.env.RECALL_SETUP_SKIP_CLAUDE_MD === "1") {
|
|
1133
|
-
return {
|
|
1134
|
-
ok: true,
|
|
1135
|
-
changed: false,
|
|
1136
|
-
config_path: null,
|
|
1137
|
-
message: "Skipped CLAUDE.md install (RECALL_SETUP_SKIP_CLAUDE_MD=1)"
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
const targetPath = options.configPath ?? claudeMdPath();
|
|
1141
|
-
const targetDir = dirname(targetPath);
|
|
1142
|
-
if (!existsSync(targetDir)) {
|
|
1143
|
-
mkdirSync(targetDir, { recursive: true });
|
|
1144
|
-
}
|
|
1145
|
-
const desired = buildClaudeMdBlock();
|
|
1146
|
-
const filePath = resolveClaudeMdFilePath(targetPath);
|
|
1147
|
-
const existingContent = readUtf8FileIfExists(filePath) ?? "";
|
|
1148
|
-
if (existingContent.includes(CLAUDE_MD_BEGIN) && existingContent.includes(desired.trim())) {
|
|
1149
|
-
return {
|
|
1150
|
-
ok: true,
|
|
1151
|
-
changed: false,
|
|
1152
|
-
config_path: targetPath,
|
|
1153
|
-
message: "Claude Code CLAUDE.md override already installed"
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
let nextContent;
|
|
1157
|
-
if (CLAUDE_MD_BLOCK_RE.test(existingContent)) {
|
|
1158
|
-
CLAUDE_MD_BLOCK_RE.lastIndex = 0;
|
|
1159
|
-
nextContent = existingContent.replace(CLAUDE_MD_BLOCK_RE, desired);
|
|
1160
|
-
} else if (existingContent.length === 0) {
|
|
1161
|
-
nextContent = desired;
|
|
1162
|
-
} else {
|
|
1163
|
-
const separator = existingContent.endsWith("\n\n") ? "" : existingContent.endsWith("\n") ? "\n" : "\n\n";
|
|
1164
|
-
nextContent = `${existingContent}${separator}${desired}`;
|
|
1165
|
-
}
|
|
1166
|
-
atomicWriteUtf8File(filePath, nextContent);
|
|
1167
|
-
return {
|
|
1168
|
-
ok: true,
|
|
1169
|
-
changed: true,
|
|
1170
|
-
config_path: targetPath,
|
|
1171
|
-
message: existingContent.length === 0 ? "Created CLAUDE.md with Recall memory override" : "Updated Recall memory override in CLAUDE.md"
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
|
-
function uninstallClaudeCodeMemoryOverride(options = {}) {
|
|
1175
|
-
const targetPath = options.configPath ?? claudeMdPath();
|
|
1176
|
-
const filePath = resolveClaudeMdFilePath(targetPath);
|
|
1177
|
-
const existingContent = readUtf8FileIfExists(filePath);
|
|
1178
|
-
if (existingContent === null) {
|
|
1179
|
-
return {
|
|
1180
|
-
ok: true,
|
|
1181
|
-
changed: false,
|
|
1182
|
-
config_path: targetPath,
|
|
1183
|
-
message: "CLAUDE.md not present"
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
CLAUDE_MD_BLOCK_RE.lastIndex = 0;
|
|
1187
|
-
if (!CLAUDE_MD_BLOCK_RE.test(existingContent)) {
|
|
1188
|
-
return {
|
|
1189
|
-
ok: true,
|
|
1190
|
-
changed: false,
|
|
1191
|
-
config_path: targetPath,
|
|
1192
|
-
message: "No Recall-managed block in CLAUDE.md"
|
|
1193
|
-
};
|
|
1194
|
-
}
|
|
1195
|
-
CLAUDE_MD_BLOCK_RE.lastIndex = 0;
|
|
1196
|
-
const stripped = existingContent.replace(CLAUDE_MD_BLOCK_RE, "").replace(/\n{3,}/g, "\n\n");
|
|
1197
|
-
if (stripped.trim().length === 0) {
|
|
1198
|
-
atomicWriteUtf8File(filePath, "");
|
|
1199
|
-
} else {
|
|
1200
|
-
atomicWriteUtf8File(
|
|
1201
|
-
filePath,
|
|
1202
|
-
stripped.endsWith("\n") ? stripped : `${stripped}
|
|
1203
|
-
`
|
|
1204
|
-
);
|
|
1205
|
-
}
|
|
1206
|
-
return {
|
|
1207
|
-
ok: true,
|
|
1208
|
-
changed: true,
|
|
1209
|
-
config_path: targetPath,
|
|
1210
|
-
message: "Removed Recall-managed block from CLAUDE.md"
|
|
1211
|
-
};
|
|
1212
|
-
}
|
|
1213
|
-
function resolveClaudeMdFilePath(targetPath) {
|
|
1214
|
-
try {
|
|
1215
|
-
return realpathSync(targetPath);
|
|
1216
|
-
} catch (error) {
|
|
1217
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
1218
|
-
return targetPath;
|
|
1219
|
-
}
|
|
1220
|
-
throw error;
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
function checkClaudeCodeMemoryOverride(options = {}) {
|
|
1224
|
-
const targetPath = options.configPath ?? claudeMdPath();
|
|
1225
|
-
if (!existsSync(targetPath)) {
|
|
1226
|
-
return { status: "absent_no_file", config_path: targetPath };
|
|
1227
|
-
}
|
|
1228
|
-
const content = readFileSync(targetPath, "utf-8");
|
|
1229
|
-
if (!CLAUDE_MD_BEGIN_NAME_RE.test(content)) {
|
|
1230
|
-
return { status: "missing", config_path: targetPath };
|
|
1231
|
-
}
|
|
1232
|
-
return {
|
|
1233
|
-
status: content.includes(CLAUDE_MD_BEGIN) && content.includes(CLAUDE_MD_BLOCK_BODY) ? "current" : "stale",
|
|
1234
|
-
config_path: targetPath
|
|
1235
|
-
};
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
// src/agents/index.ts
|
|
1239
|
-
init_define_RECALL_BUILD_INFO();
|
|
1240
|
-
|
|
1241
|
-
// src/agents/cursor.ts
|
|
1242
|
-
init_define_RECALL_BUILD_INFO();
|
|
1243
|
-
import { join as join3 } from "path";
|
|
1244
|
-
|
|
1245
|
-
// src/agents/hookless.ts
|
|
1246
|
-
init_define_RECALL_BUILD_INFO();
|
|
1247
|
-
import { existsSync as existsSync4 } from "fs";
|
|
1248
|
-
import { resolve as resolve2 } from "path";
|
|
1249
|
-
|
|
1250
|
-
// src/agents/mcp-json.ts
|
|
1251
|
-
init_define_RECALL_BUILD_INFO();
|
|
1252
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
1253
|
-
import { dirname as dirname2 } from "path";
|
|
1254
|
-
var RECALL_SERVER_KEY = "recall";
|
|
1255
|
-
function commandArgsEntry(spec) {
|
|
1256
|
-
return {
|
|
1257
|
-
command: spec.nodePath,
|
|
1258
|
-
args: [spec.mcpPath],
|
|
1259
|
-
env: {}
|
|
1260
|
-
};
|
|
1261
|
-
}
|
|
1262
|
-
function copilotEntry(spec) {
|
|
1263
|
-
return {
|
|
1264
|
-
type: "local",
|
|
1265
|
-
command: spec.nodePath,
|
|
1266
|
-
args: [spec.mcpPath],
|
|
1267
|
-
env: {},
|
|
1268
|
-
tools: ["*"]
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
function opencodeEntry(spec) {
|
|
1272
|
-
return {
|
|
1273
|
-
type: "local",
|
|
1274
|
-
command: [spec.nodePath, spec.mcpPath],
|
|
1275
|
-
enabled: true
|
|
1276
|
-
};
|
|
1277
|
-
}
|
|
1278
|
-
function writeMcpServerEntry(target, spec) {
|
|
1279
|
-
const serverKey = target.serverKey ?? RECALL_SERVER_KEY;
|
|
1280
|
-
const read = readJsonConfig(target.configPath);
|
|
1281
|
-
if (read.error) {
|
|
1282
|
-
return { ok: false, changed: false, config_path: target.configPath, message: read.error };
|
|
1283
|
-
}
|
|
1284
|
-
const next = clone(read.parsed);
|
|
1285
|
-
const container = ensureContainer(next, target.containerKey);
|
|
1286
|
-
if (!container) {
|
|
1287
|
-
return {
|
|
1288
|
-
ok: false,
|
|
1289
|
-
changed: false,
|
|
1290
|
-
config_path: target.configPath,
|
|
1291
|
-
message: `"${target.containerKey}" in ${target.configPath} is not an object \u2014 leaving it alone`
|
|
1292
|
-
};
|
|
1293
|
-
}
|
|
1294
|
-
const desired = target.buildEntry(spec);
|
|
1295
|
-
if (sameJson2(container[serverKey], desired)) {
|
|
1296
|
-
return {
|
|
1297
|
-
ok: true,
|
|
1298
|
-
changed: false,
|
|
1299
|
-
config_path: target.configPath,
|
|
1300
|
-
message: `Recall MCP server already registered in ${target.configPath}`
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
container[serverKey] = desired;
|
|
1304
|
-
writeJsonConfig(target.configPath, read.raw, next);
|
|
1305
|
-
return {
|
|
1306
|
-
ok: true,
|
|
1307
|
-
changed: true,
|
|
1308
|
-
config_path: target.configPath,
|
|
1309
|
-
message: read.raw == null ? `Created ${target.configPath} with Recall MCP server` : `Registered Recall MCP server in ${target.configPath}`
|
|
1310
|
-
};
|
|
1311
|
-
}
|
|
1312
|
-
function removeMcpServerEntry(target) {
|
|
1313
|
-
const serverKey = target.serverKey ?? RECALL_SERVER_KEY;
|
|
1314
|
-
if (!existsSync2(target.configPath)) {
|
|
1315
|
-
return {
|
|
1316
|
-
ok: true,
|
|
1317
|
-
changed: false,
|
|
1318
|
-
config_path: target.configPath,
|
|
1319
|
-
message: `${target.configPath} not found`
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
const read = readJsonConfig(target.configPath);
|
|
1323
|
-
if (read.error) {
|
|
1324
|
-
return { ok: false, changed: false, config_path: target.configPath, message: read.error };
|
|
1325
|
-
}
|
|
1326
|
-
const next = clone(read.parsed);
|
|
1327
|
-
const container = asObject(next[target.containerKey]);
|
|
1328
|
-
if (!container || !(serverKey in container)) {
|
|
1329
|
-
return {
|
|
1330
|
-
ok: true,
|
|
1331
|
-
changed: false,
|
|
1332
|
-
config_path: target.configPath,
|
|
1333
|
-
message: `No Recall MCP server registered in ${target.configPath}`
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
delete container[serverKey];
|
|
1337
|
-
if (Object.keys(container).length === 0) {
|
|
1338
|
-
delete next[target.containerKey];
|
|
1339
|
-
}
|
|
1340
|
-
writeJsonConfig(target.configPath, read.raw, next);
|
|
1341
|
-
return {
|
|
1342
|
-
ok: true,
|
|
1343
|
-
changed: true,
|
|
1344
|
-
config_path: target.configPath,
|
|
1345
|
-
message: `Removed Recall MCP server from ${target.configPath}`
|
|
1346
|
-
};
|
|
1347
|
-
}
|
|
1348
|
-
function hasMcpServerEntry(target) {
|
|
1349
|
-
if (!existsSync2(target.configPath)) return false;
|
|
1350
|
-
const read = readJsonConfig(target.configPath);
|
|
1351
|
-
if (read.error) return false;
|
|
1352
|
-
const container = asObject(read.parsed[target.containerKey]);
|
|
1353
|
-
return Boolean(container && (target.serverKey ?? RECALL_SERVER_KEY) in container);
|
|
1354
|
-
}
|
|
1355
|
-
function readJsonConfig(configPath2) {
|
|
1356
|
-
if (!existsSync2(configPath2)) return { raw: null, parsed: {} };
|
|
1357
|
-
const raw = readFileSync2(configPath2, "utf-8");
|
|
1358
|
-
if (raw.trim().length === 0) return { raw, parsed: {} };
|
|
1359
|
-
let parsed;
|
|
1360
|
-
try {
|
|
1361
|
-
parsed = JSON.parse(raw);
|
|
1362
|
-
} catch {
|
|
1363
|
-
return {
|
|
1364
|
-
raw,
|
|
1365
|
-
parsed: {},
|
|
1366
|
-
error: `Could not parse ${configPath2} as JSON \u2014 add the Recall MCP server manually`
|
|
1367
|
-
};
|
|
1368
|
-
}
|
|
1369
|
-
const object = asObject(parsed);
|
|
1370
|
-
if (!object) {
|
|
1371
|
-
return { raw, parsed: {}, error: `${configPath2} must contain a JSON object` };
|
|
1372
|
-
}
|
|
1373
|
-
return { raw, parsed: object };
|
|
1374
|
-
}
|
|
1375
|
-
function writeJsonConfig(configPath2, previousRaw, value) {
|
|
1376
|
-
mkdirSync2(dirname2(configPath2), { recursive: true });
|
|
1377
|
-
if (previousRaw != null) {
|
|
1378
|
-
writeFileSync2(`${configPath2}.recall.bak.${Date.now()}`, previousRaw);
|
|
1379
|
-
}
|
|
1380
|
-
const tmpPath = `${configPath2}.tmp.${process.pid}`;
|
|
1381
|
-
writeFileSync2(tmpPath, `${JSON.stringify(value, null, 2)}
|
|
1382
|
-
`);
|
|
1383
|
-
renameSync2(tmpPath, configPath2);
|
|
1384
|
-
}
|
|
1385
|
-
function ensureContainer(config, key) {
|
|
1386
|
-
if (config[key] === void 0) {
|
|
1387
|
-
config[key] = {};
|
|
1388
|
-
}
|
|
1389
|
-
return asObject(config[key]);
|
|
1390
|
-
}
|
|
1391
|
-
function asObject(value) {
|
|
1392
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1393
|
-
}
|
|
1394
|
-
function clone(value) {
|
|
1395
|
-
return JSON.parse(JSON.stringify(value));
|
|
1396
|
-
}
|
|
1397
|
-
function sameJson2(left, right) {
|
|
1398
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
// src/agents/rules-block.ts
|
|
1402
|
-
init_define_RECALL_BUILD_INFO();
|
|
1403
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
1404
|
-
import { dirname as dirname3 } from "path";
|
|
1405
|
-
function beginMarker(block) {
|
|
1406
|
-
return `<!-- recall:managed:${block.name}:begin v${block.version} -->`;
|
|
1407
|
-
}
|
|
1408
|
-
function endMarker(block) {
|
|
1409
|
-
return `<!-- recall:managed:${block.name}:end -->`;
|
|
1410
|
-
}
|
|
1411
|
-
function anyBeginMarkerRe(block) {
|
|
1412
|
-
return new RegExp(`<!--\\s*recall:managed:${escapeRegExp(block.name)}:begin(?:\\s+v\\d+)?\\s*-->`);
|
|
1413
|
-
}
|
|
1414
|
-
function blockRe(block) {
|
|
1415
|
-
return blockReForName(block.name);
|
|
1416
|
-
}
|
|
1417
|
-
function blockReForName(name) {
|
|
1418
|
-
return new RegExp(
|
|
1419
|
-
`<!--\\s*recall:managed:${escapeRegExp(name)}:begin(?:\\s+v\\d+)?\\s*-->[\\s\\S]*?<!--\\s*recall:managed:${escapeRegExp(name)}:end\\s*-->\\n?`,
|
|
1420
|
-
"g"
|
|
1421
|
-
);
|
|
1422
|
-
}
|
|
1423
|
-
function renderManagedBlock(block) {
|
|
1424
|
-
return `${beginMarker(block)}
|
|
1425
|
-
${block.body}
|
|
1426
|
-
${endMarker(block)}
|
|
1427
|
-
`;
|
|
1428
|
-
}
|
|
1429
|
-
function installManagedRules(targetPath, block) {
|
|
1430
|
-
const desired = renderManagedBlock(block);
|
|
1431
|
-
const existing = existsSync3(targetPath) ? readFileSync3(targetPath, "utf-8") : "";
|
|
1432
|
-
if (existing.includes(beginMarker(block)) && existing.includes(block.body)) {
|
|
1433
|
-
return {
|
|
1434
|
-
ok: true,
|
|
1435
|
-
changed: false,
|
|
1436
|
-
config_path: targetPath,
|
|
1437
|
-
message: `Recall rules already current in ${targetPath}`
|
|
1438
|
-
};
|
|
1439
|
-
}
|
|
1440
|
-
const next = block.ownsFile ? `${block.preamble ?? ""}${desired}` : mergeIntoExisting(existing, desired, block);
|
|
1441
|
-
mkdirSync3(dirname3(targetPath), { recursive: true });
|
|
1442
|
-
writeFileSync3(targetPath, next);
|
|
1443
|
-
return {
|
|
1444
|
-
ok: true,
|
|
1445
|
-
changed: true,
|
|
1446
|
-
config_path: targetPath,
|
|
1447
|
-
message: existing.length === 0 ? `Created ${targetPath} with Recall rules` : `Updated Recall rules in ${targetPath}`
|
|
1448
|
-
};
|
|
1449
|
-
}
|
|
1450
|
-
function uninstallManagedRules(targetPath, block) {
|
|
1451
|
-
if (!existsSync3(targetPath)) {
|
|
1452
|
-
return { ok: true, changed: false, config_path: targetPath, message: `${targetPath} not present` };
|
|
1453
|
-
}
|
|
1454
|
-
const existing = readFileSync3(targetPath, "utf-8");
|
|
1455
|
-
const hasCurrent = anyBeginMarkerRe(block).test(existing);
|
|
1456
|
-
const hasLegacy = findLegacyBlock(existing, block) !== null;
|
|
1457
|
-
if (!hasCurrent && !hasLegacy) {
|
|
1458
|
-
return {
|
|
1459
|
-
ok: true,
|
|
1460
|
-
changed: false,
|
|
1461
|
-
config_path: targetPath,
|
|
1462
|
-
message: `No Recall-managed rules in ${targetPath}`
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
|
-
const stripped = removeLegacyBlocks(existing.replace(blockRe(block), ""), block).replace(/\n{3,}/g, "\n\n");
|
|
1466
|
-
if (block.ownsFile && stripped.trim() === (block.preamble ?? "").trim()) {
|
|
1467
|
-
rmSync2(targetPath, { force: true });
|
|
1468
|
-
return { ok: true, changed: true, config_path: targetPath, message: `Removed ${targetPath}` };
|
|
1469
|
-
}
|
|
1470
|
-
writeFileSync3(targetPath, stripped.trim().length === 0 ? "" : ensureTrailingNewline(stripped));
|
|
1471
|
-
return {
|
|
1472
|
-
ok: true,
|
|
1473
|
-
changed: true,
|
|
1474
|
-
config_path: targetPath,
|
|
1475
|
-
message: `Removed Recall rules from ${targetPath}`
|
|
1476
|
-
};
|
|
1477
|
-
}
|
|
1478
|
-
function checkManagedRules(targetPath, block) {
|
|
1479
|
-
if (!existsSync3(targetPath)) {
|
|
1480
|
-
return { status: "absent_no_file", config_path: targetPath };
|
|
1481
|
-
}
|
|
1482
|
-
const content = readFileSync3(targetPath, "utf-8");
|
|
1483
|
-
if (!anyBeginMarkerRe(block).test(content)) {
|
|
1484
|
-
if (findLegacyBlock(content, block)) {
|
|
1485
|
-
return { status: "stale", config_path: targetPath };
|
|
1486
|
-
}
|
|
1487
|
-
return { status: "missing", config_path: targetPath };
|
|
1488
|
-
}
|
|
1489
|
-
return {
|
|
1490
|
-
status: content.includes(beginMarker(block)) && content.includes(block.body) ? "current" : "stale",
|
|
1491
|
-
config_path: targetPath
|
|
1492
|
-
};
|
|
1493
|
-
}
|
|
1494
|
-
function mergeIntoExisting(existing, desired, block) {
|
|
1495
|
-
if (anyBeginMarkerRe(block).test(existing)) {
|
|
1496
|
-
return existing.replace(blockRe(block), desired);
|
|
1497
|
-
}
|
|
1498
|
-
const legacy = findLegacyBlock(existing, block);
|
|
1499
|
-
if (legacy) return existing.replace(legacy, desired);
|
|
1500
|
-
if (existing.length === 0) return desired;
|
|
1501
|
-
const separator = existing.endsWith("\n\n") ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
|
|
1502
|
-
return `${existing}${separator}${desired}`;
|
|
1503
|
-
}
|
|
1504
|
-
function findLegacyBlock(existing, block) {
|
|
1505
|
-
for (const name of block.legacyNames ?? []) {
|
|
1506
|
-
for (const match of existing.matchAll(blockReForName(name))) {
|
|
1507
|
-
if (match[0].includes(block.body)) return match[0];
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
return null;
|
|
1511
|
-
}
|
|
1512
|
-
function removeLegacyBlocks(existing, block) {
|
|
1513
|
-
let next = existing;
|
|
1514
|
-
let match = findLegacyBlock(next, block);
|
|
1515
|
-
while (match) {
|
|
1516
|
-
next = next.replace(match, "");
|
|
1517
|
-
match = findLegacyBlock(next, block);
|
|
1518
|
-
}
|
|
1519
|
-
return next;
|
|
1520
|
-
}
|
|
1521
|
-
function ensureTrailingNewline(content) {
|
|
1522
|
-
return content.endsWith("\n") ? content : `${content}
|
|
1523
|
-
`;
|
|
1524
|
-
}
|
|
1525
|
-
function escapeRegExp(value) {
|
|
1526
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1527
|
-
}
|
|
1528
|
-
function buildRecallRulesBody(toolLabel) {
|
|
1529
|
-
return `## Recall (managed by \`recall setup\` \u2014 do not edit by hand)
|
|
1530
|
-
|
|
1531
|
-
Recall is the single source of truth for durable memory across agents and sessions. It is wired into ${toolLabel} through the \`recall\` MCP server.
|
|
1532
|
-
|
|
1533
|
-
- ${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.
|
|
1534
|
-
- Before non-trivial work in a repo, call \`query\` to pull relevant memories. Do it again when you move to an unfamiliar area.
|
|
1535
|
-
- A memory that turns out to be wrong or outdated: \`reject\` it. One that proves right: \`confirm\` it.
|
|
1536
|
-
- 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.
|
|
1537
|
-
- Do not keep a second memory store (scratch note files, tool-native memory) \u2014 it drifts from Recall.
|
|
1538
|
-
|
|
1539
|
-
Reinstall: \`recall setup\`. Remove: \`recall setup --uninstall-hooks\`.`;
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
// src/agents/hookless.ts
|
|
1543
|
-
function createHooklessAdapter(spec) {
|
|
1544
|
-
const configPath2 = (options = {}) => spec.mcpTarget(options).configPath;
|
|
1545
|
-
return {
|
|
1546
|
-
name: spec.name,
|
|
1547
|
-
configPath: configPath2,
|
|
1548
|
-
detect(options = {}) {
|
|
1549
|
-
const byCommand = (spec.commands ?? []).some((command) => hasCommand(command));
|
|
1550
|
-
const byPath = (spec.markerPaths?.(options) ?? []).some((path) => existsSync4(path));
|
|
1551
|
-
return byCommand || byPath ? "installed" : "not-installed";
|
|
1552
|
-
},
|
|
1553
|
-
capabilities() {
|
|
1554
|
-
return {
|
|
1555
|
-
// No hook API: nothing observes prompts, tools or session lifecycle.
|
|
1556
|
-
supports: [],
|
|
1557
|
-
supports_hook_install: false,
|
|
1558
|
-
supports_mcp_fallback: true
|
|
1559
|
-
};
|
|
1560
|
-
},
|
|
1561
|
-
installHooks(_profile) {
|
|
1562
|
-
return {
|
|
1563
|
-
ok: false,
|
|
1564
|
-
changed: false,
|
|
1565
|
-
config_path: null,
|
|
1566
|
-
message: `${spec.label} exposes no hook API \u2014 use writeMcpFallback() and installRules() instead`
|
|
1567
|
-
};
|
|
1568
|
-
},
|
|
1569
|
-
uninstallHooks() {
|
|
1570
|
-
return {
|
|
1571
|
-
ok: true,
|
|
1572
|
-
changed: false,
|
|
1573
|
-
config_path: null,
|
|
1574
|
-
message: `${spec.label} has no Recall-managed hooks`
|
|
1575
|
-
};
|
|
1576
|
-
},
|
|
1577
|
-
envMapping: {},
|
|
1578
|
-
writeMcpFallback(options = {}) {
|
|
1579
|
-
const serverSpec = resolveServerSpec(options, spec.label);
|
|
1580
|
-
if ("error" in serverSpec) {
|
|
1581
|
-
return { ok: false, changed: false, config_path: null, message: serverSpec.error };
|
|
1582
|
-
}
|
|
1583
|
-
return writeMcpServerEntry(spec.mcpTarget(options), serverSpec);
|
|
1584
|
-
},
|
|
1585
|
-
removeMcpFallback(options = {}) {
|
|
1586
|
-
return removeMcpServerEntry(spec.mcpTarget(options));
|
|
1587
|
-
},
|
|
1588
|
-
hasMcpRegistration(options = {}) {
|
|
1589
|
-
return hasMcpServerEntry(spec.mcpTarget(options));
|
|
1590
|
-
},
|
|
1591
|
-
installRules(options = {}) {
|
|
1592
|
-
return installManagedRules(rulesTarget(spec, options), spec.rulesBlock);
|
|
1593
|
-
},
|
|
1594
|
-
uninstallRules(options = {}) {
|
|
1595
|
-
return uninstallManagedRules(rulesTarget(spec, options), spec.rulesBlock);
|
|
1596
|
-
},
|
|
1597
|
-
checkRules(options = {}) {
|
|
1598
|
-
return checkManagedRules(rulesTarget(spec, options), spec.rulesBlock);
|
|
1599
|
-
},
|
|
1600
|
-
rulesScope: spec.rulesScope
|
|
1601
|
-
};
|
|
1602
|
-
}
|
|
1603
|
-
function rulesTarget(spec, options) {
|
|
1604
|
-
return options.configPath ?? spec.rulesPath(options);
|
|
1605
|
-
}
|
|
1606
|
-
function resolveServerSpec(options, label) {
|
|
1607
|
-
const nodePath = options.nodePath ?? process.env.RECALL_NODE_PATH ?? process.execPath;
|
|
1608
|
-
const mcpPath = options.mcpPath ?? process.env.RECALL_MCP_PATH;
|
|
1609
|
-
if (!mcpPath) {
|
|
1610
|
-
return {
|
|
1611
|
-
error: `Unable to resolve the Recall MCP entrypoint for ${label} \u2014 pass mcpPath or set RECALL_MCP_PATH`
|
|
1612
|
-
};
|
|
1613
|
-
}
|
|
1614
|
-
return { nodePath, mcpPath };
|
|
1615
|
-
}
|
|
1616
|
-
function projectPath(options, ...segments) {
|
|
1617
|
-
return resolve2(options.cwd ?? process.cwd(), ...segments);
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
// src/agents/cursor.ts
|
|
1621
|
-
var LABEL = "Cursor";
|
|
1622
|
-
function cursorHome(options = {}) {
|
|
1623
|
-
return join3(options.homeDir ?? resolveUserHomeDir(), ".cursor");
|
|
1624
|
-
}
|
|
1625
|
-
function cursorGlobalMcpPath(options = {}) {
|
|
1626
|
-
return join3(cursorHome(options), "mcp.json");
|
|
1627
|
-
}
|
|
1628
|
-
function cursorProjectMcpPath(options = {}) {
|
|
1629
|
-
return projectPath(options, ".cursor", "mcp.json");
|
|
1630
|
-
}
|
|
1631
|
-
function cursorRulesPath(options = {}) {
|
|
1632
|
-
return projectPath(options, ".cursor", "rules", "recall.mdc");
|
|
1633
|
-
}
|
|
1634
|
-
var CURSOR_MDC_FRONTMATTER = `---
|
|
1635
|
-
description: Route durable memory through the Recall MCP server
|
|
1636
|
-
alwaysApply: true
|
|
1637
|
-
---
|
|
1638
|
-
|
|
1639
|
-
`;
|
|
1640
|
-
var cursorAdapter = createHooklessAdapter({
|
|
1641
|
-
name: "cursor",
|
|
1642
|
-
label: LABEL,
|
|
1643
|
-
commands: ["cursor"],
|
|
1644
|
-
markerPaths: (options) => [cursorHome(options)],
|
|
1645
|
-
mcpTarget: (options) => ({
|
|
1646
|
-
configPath: options.configPath ?? (options.scope === "project" ? cursorProjectMcpPath(options) : cursorGlobalMcpPath(options)),
|
|
1647
|
-
containerKey: "mcpServers",
|
|
1648
|
-
buildEntry: commandArgsEntry
|
|
1649
|
-
}),
|
|
1650
|
-
rulesPath: (options) => cursorRulesPath(options),
|
|
1651
|
-
rulesBlock: {
|
|
1652
|
-
name: "cursor-memory",
|
|
1653
|
-
legacyNames: ["memory"],
|
|
1654
|
-
version: 1,
|
|
1655
|
-
body: buildRecallRulesBody(LABEL),
|
|
1656
|
-
ownsFile: true,
|
|
1657
|
-
preamble: CURSOR_MDC_FRONTMATTER
|
|
1658
|
-
},
|
|
1659
|
-
rulesScope: "project"
|
|
1660
|
-
});
|
|
1661
|
-
|
|
1662
|
-
// src/agents/gemini-cli.ts
|
|
1663
|
-
init_define_RECALL_BUILD_INFO();
|
|
1664
|
-
var geminiCliAdapter = {
|
|
1665
|
-
name: "gemini-cli",
|
|
1666
|
-
configPath() {
|
|
1667
|
-
return "";
|
|
1668
|
-
},
|
|
1669
|
-
detect() {
|
|
1670
|
-
return "not-installed";
|
|
1671
|
-
},
|
|
1672
|
-
capabilities() {
|
|
1673
|
-
return {
|
|
1674
|
-
supports: ["prompt_submitted", "tool_invoked", "session_ended"],
|
|
1675
|
-
supports_hook_install: false,
|
|
1676
|
-
supports_mcp_fallback: true
|
|
1677
|
-
};
|
|
1678
|
-
},
|
|
1679
|
-
installHooks(_profile) {
|
|
1680
|
-
throw new Error("Gemini CLI hook installation not implemented yet.");
|
|
1681
|
-
},
|
|
1682
|
-
uninstallHooks() {
|
|
1683
|
-
throw new Error("Gemini CLI hook removal not implemented yet.");
|
|
1684
|
-
},
|
|
1685
|
-
envMapping: {
|
|
1686
|
-
prompt_submitted: {
|
|
1687
|
-
prompt: "text",
|
|
1688
|
-
session_id: "session_id"
|
|
1689
|
-
},
|
|
1690
|
-
tool_invoked: {
|
|
1691
|
-
tool_name: "name",
|
|
1692
|
-
session_id: "session_id"
|
|
1693
|
-
},
|
|
1694
|
-
session_ended: {
|
|
1695
|
-
session_id: "session_id",
|
|
1696
|
-
reason: "reason"
|
|
1697
|
-
}
|
|
1698
|
-
},
|
|
1699
|
-
writeMcpFallback() {
|
|
1700
|
-
throw new Error("Gemini CLI MCP fallback wiring not implemented yet.");
|
|
1701
|
-
}
|
|
1702
|
-
};
|
|
1703
|
-
|
|
1704
|
-
// src/agents/github-copilot.ts
|
|
1705
|
-
init_define_RECALL_BUILD_INFO();
|
|
1706
|
-
import { join as join4 } from "path";
|
|
1707
|
-
var LABEL2 = "GitHub Copilot";
|
|
1708
|
-
function copilotHome(options = {}) {
|
|
1709
|
-
if (options.homeDir) return join4(options.homeDir, ".copilot");
|
|
1710
|
-
return process.env.COPILOT_HOME ?? join4(resolveUserHomeDir(), ".copilot");
|
|
1711
|
-
}
|
|
1712
|
-
function copilotMcpConfigPath(options = {}) {
|
|
1713
|
-
return join4(copilotHome(options), "mcp-config.json");
|
|
1714
|
-
}
|
|
1715
|
-
function copilotInstructionsPath(options = {}) {
|
|
1716
|
-
return projectPath(options, ".github", "copilot-instructions.md");
|
|
1717
|
-
}
|
|
1718
|
-
var githubCopilotAdapter = createHooklessAdapter({
|
|
1719
|
-
name: "github-copilot",
|
|
1720
|
-
label: LABEL2,
|
|
1721
|
-
commands: ["copilot"],
|
|
1722
|
-
markerPaths: (options) => [copilotHome(options)],
|
|
1723
|
-
mcpTarget: (options) => ({
|
|
1724
|
-
configPath: options.configPath ?? copilotMcpConfigPath(options),
|
|
1725
|
-
containerKey: "mcpServers",
|
|
1726
|
-
buildEntry: copilotEntry
|
|
1727
|
-
}),
|
|
1728
|
-
rulesPath: (options) => copilotInstructionsPath(options),
|
|
1729
|
-
rulesBlock: {
|
|
1730
|
-
name: "github-copilot-memory",
|
|
1731
|
-
legacyNames: ["memory"],
|
|
1732
|
-
version: 1,
|
|
1733
|
-
body: buildRecallRulesBody(LABEL2)
|
|
1734
|
-
},
|
|
1735
|
-
rulesScope: "project"
|
|
1736
|
-
});
|
|
1737
|
-
|
|
1738
|
-
// src/agents/opencode.ts
|
|
1739
|
-
init_define_RECALL_BUILD_INFO();
|
|
1740
|
-
import { join as join5 } from "path";
|
|
1741
|
-
var LABEL3 = "opencode";
|
|
1742
|
-
function opencodeConfigDir(options = {}) {
|
|
1743
|
-
return join5(options.homeDir ?? resolveUserHomeDir(), ".config", "opencode");
|
|
1744
|
-
}
|
|
1745
|
-
function opencodeConfigPath(options = {}) {
|
|
1746
|
-
return join5(opencodeConfigDir(options), "opencode.json");
|
|
1747
|
-
}
|
|
1748
|
-
function opencodeAgentsPath(options = {}) {
|
|
1749
|
-
return join5(opencodeConfigDir(options), "AGENTS.md");
|
|
1750
|
-
}
|
|
1751
|
-
var opencodeAdapter = createHooklessAdapter({
|
|
1752
|
-
name: "opencode",
|
|
1753
|
-
label: LABEL3,
|
|
1754
|
-
commands: ["opencode"],
|
|
1755
|
-
markerPaths: (options) => [opencodeConfigDir(options)],
|
|
1756
|
-
mcpTarget: (options) => ({
|
|
1757
|
-
configPath: options.configPath ?? opencodeConfigPath(options),
|
|
1758
|
-
// opencode nests servers directly under "mcp", not "mcpServers".
|
|
1759
|
-
containerKey: "mcp",
|
|
1760
|
-
buildEntry: opencodeEntry
|
|
1761
|
-
}),
|
|
1762
|
-
rulesPath: (options) => opencodeAgentsPath(options),
|
|
1763
|
-
rulesBlock: {
|
|
1764
|
-
name: "opencode-memory",
|
|
1765
|
-
legacyNames: ["memory"],
|
|
1766
|
-
version: 1,
|
|
1767
|
-
body: buildRecallRulesBody(LABEL3)
|
|
1768
|
-
},
|
|
1769
|
-
rulesScope: "global"
|
|
1770
|
-
});
|
|
1771
|
-
|
|
1772
|
-
// src/agents/qwen.ts
|
|
1773
|
-
init_define_RECALL_BUILD_INFO();
|
|
1774
|
-
var qwenAdapter = {
|
|
1775
|
-
name: "qwen",
|
|
1776
|
-
configPath() {
|
|
1777
|
-
return "";
|
|
1778
|
-
},
|
|
1779
|
-
detect() {
|
|
1780
|
-
return "not-installed";
|
|
1781
|
-
},
|
|
1782
|
-
capabilities() {
|
|
1783
|
-
return {
|
|
1784
|
-
supports: ["prompt_submitted", "tool_invoked", "session_ended"],
|
|
1785
|
-
supports_hook_install: false,
|
|
1786
|
-
supports_mcp_fallback: true
|
|
1787
|
-
};
|
|
1788
|
-
},
|
|
1789
|
-
installHooks(_profile) {
|
|
1790
|
-
throw new Error("Qwen hook installation not implemented yet.");
|
|
1791
|
-
},
|
|
1792
|
-
uninstallHooks() {
|
|
1793
|
-
throw new Error("Qwen hook removal not implemented yet.");
|
|
1794
|
-
},
|
|
1795
|
-
envMapping: {
|
|
1796
|
-
prompt_submitted: {
|
|
1797
|
-
prompt: "text",
|
|
1798
|
-
session_id: "session_id"
|
|
1799
|
-
},
|
|
1800
|
-
tool_invoked: {
|
|
1801
|
-
tool_name: "name",
|
|
1802
|
-
session_id: "session_id"
|
|
1803
|
-
},
|
|
1804
|
-
session_ended: {
|
|
1805
|
-
session_id: "session_id",
|
|
1806
|
-
reason: "reason"
|
|
1807
|
-
}
|
|
1808
|
-
},
|
|
1809
|
-
writeMcpFallback() {
|
|
1810
|
-
throw new Error("Qwen MCP fallback wiring not implemented yet.");
|
|
1811
|
-
}
|
|
1812
|
-
};
|
|
1813
|
-
|
|
1814
|
-
// src/agents/windsurf.ts
|
|
1815
|
-
init_define_RECALL_BUILD_INFO();
|
|
1816
|
-
import { join as join6 } from "path";
|
|
1817
|
-
var LABEL4 = "Windsurf";
|
|
1818
|
-
function windsurfConfigDir(options = {}) {
|
|
1819
|
-
return join6(options.homeDir ?? resolveUserHomeDir(), ".codeium", "windsurf");
|
|
1820
|
-
}
|
|
1821
|
-
function windsurfMcpConfigPath(options = {}) {
|
|
1822
|
-
return join6(windsurfConfigDir(options), "mcp_config.json");
|
|
1823
|
-
}
|
|
1824
|
-
function windsurfGlobalRulesPath(options = {}) {
|
|
1825
|
-
return join6(windsurfConfigDir(options), "memories", "global_rules.md");
|
|
1826
|
-
}
|
|
1827
|
-
var windsurfAdapter = createHooklessAdapter({
|
|
1828
|
-
name: "windsurf",
|
|
1829
|
-
label: LABEL4,
|
|
1830
|
-
commands: ["windsurf"],
|
|
1831
|
-
markerPaths: (options) => [windsurfConfigDir(options)],
|
|
1832
|
-
mcpTarget: (options) => ({
|
|
1833
|
-
configPath: options.configPath ?? windsurfMcpConfigPath(options),
|
|
1834
|
-
containerKey: "mcpServers",
|
|
1835
|
-
buildEntry: commandArgsEntry
|
|
1836
|
-
}),
|
|
1837
|
-
rulesPath: (options) => windsurfGlobalRulesPath(options),
|
|
1838
|
-
rulesBlock: {
|
|
1839
|
-
name: "windsurf-memory",
|
|
1840
|
-
legacyNames: ["memory"],
|
|
1841
|
-
version: 1,
|
|
1842
|
-
body: buildRecallRulesBody(LABEL4)
|
|
1843
|
-
},
|
|
1844
|
-
rulesScope: "global"
|
|
1845
|
-
});
|
|
1846
|
-
|
|
1847
|
-
// src/agents/types.ts
|
|
1848
|
-
init_define_RECALL_BUILD_INFO();
|
|
1849
|
-
|
|
1850
|
-
// src/agents/index.ts
|
|
1851
|
-
var adapters = {
|
|
1852
|
-
"claude-code": claudeCodeAdapter,
|
|
1853
|
-
codex: codexAdapter,
|
|
1854
|
-
"github-copilot": githubCopilotAdapter,
|
|
1855
|
-
opencode: opencodeAdapter,
|
|
1856
|
-
cursor: cursorAdapter,
|
|
1857
|
-
windsurf: windsurfAdapter,
|
|
1858
|
-
"gemini-cli": geminiCliAdapter,
|
|
1859
|
-
qwen: qwenAdapter
|
|
1860
|
-
};
|
|
1861
|
-
var hooklessAgents = [
|
|
1862
|
-
"github-copilot",
|
|
1863
|
-
"opencode",
|
|
1864
|
-
"cursor",
|
|
1865
|
-
"windsurf"
|
|
1866
|
-
];
|
|
1867
|
-
function listAgentNames() {
|
|
1868
|
-
return Object.keys(adapters);
|
|
1869
|
-
}
|
|
1870
|
-
function isHooklessAgent(name) {
|
|
1871
|
-
return hooklessAgents.includes(name);
|
|
1872
|
-
}
|
|
1873
|
-
function resolveAdapter(name) {
|
|
1874
|
-
const adapter = adapters[name];
|
|
1875
|
-
if (adapter) {
|
|
1876
|
-
return adapter;
|
|
1877
|
-
}
|
|
1878
|
-
throw new Error(
|
|
1879
|
-
`Unknown agent adapter: ${name}. Supported adapters: ${listAgentNames().join(", ")}. Reserved v2 stubs: gemini-cli, qwen.`
|
|
1880
|
-
);
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
// src/setup/local.ts
|
|
1884
|
-
function resolveRuntimePaths(appPath) {
|
|
1885
|
-
const override = process.env.RECALL_RUNTIME_DIR;
|
|
1886
|
-
if (override) {
|
|
1887
|
-
return {
|
|
1888
|
-
appPath: override,
|
|
1889
|
-
runtimeNodePath: join7(override, "bin", "node"),
|
|
1890
|
-
runtimeCliPath: join7(override, "dist", "cli.js"),
|
|
1891
|
-
runtimeMcpPath: join7(override, "dist", "mcp.js")
|
|
1892
|
-
};
|
|
1893
|
-
}
|
|
1894
|
-
if (appPath || process.platform === "darwin" && existsSync5("/Applications/Recall.app")) {
|
|
1895
|
-
const resolvedAppPath = appPath ?? "/Applications/Recall.app";
|
|
1896
|
-
const runtimeRoot = join7(resolvedAppPath, "Contents", "Resources", "Runtime");
|
|
1897
|
-
return {
|
|
1898
|
-
appPath: resolvedAppPath,
|
|
1899
|
-
runtimeNodePath: join7(runtimeRoot, "bin", "node"),
|
|
1900
|
-
runtimeCliPath: join7(runtimeRoot, "dist", "cli.js"),
|
|
1901
|
-
runtimeMcpPath: join7(runtimeRoot, "dist", "mcp.js")
|
|
1902
|
-
};
|
|
1903
|
-
}
|
|
1904
|
-
const distDir = dirname4(fileURLToPath2(import.meta.url));
|
|
1905
|
-
return {
|
|
1906
|
-
appPath: distDir,
|
|
1907
|
-
runtimeNodePath: process.execPath,
|
|
1908
|
-
runtimeCliPath: join7(distDir, "cli.js"),
|
|
1909
|
-
runtimeMcpPath: join7(distDir, "mcp.js")
|
|
1910
|
-
};
|
|
1911
|
-
}
|
|
1912
|
-
function runLocalSetup(opts = {}) {
|
|
1913
|
-
const targetCodex = opts.codex ?? true;
|
|
1914
|
-
const targetClaude = opts.claude ?? true;
|
|
1915
|
-
const result = runRecallSetup({
|
|
1916
|
-
appPath: opts.appPath,
|
|
1917
|
-
agent: [
|
|
1918
|
-
...targetCodex ? ["codex"] : [],
|
|
1919
|
-
...targetClaude ? ["claude-code"] : []
|
|
1920
|
-
],
|
|
1921
|
-
hooksOnly: false,
|
|
1922
|
-
mcpOnly: false,
|
|
1923
|
-
scope: "global",
|
|
1924
|
-
promptInjection: opts.promptInjection,
|
|
1925
|
-
claudeMd: opts.claudeMd
|
|
1926
|
-
});
|
|
1927
|
-
const codex = result.agents.find((agent) => agent.agent === "codex");
|
|
1928
|
-
const claude = result.agents.find((agent) => agent.agent === "claude-code");
|
|
1929
|
-
return {
|
|
1930
|
-
appPath: result.appPath,
|
|
1931
|
-
runtimeNodePath: result.runtimeNodePath,
|
|
1932
|
-
runtimeCliPath: result.runtimeCliPath,
|
|
1933
|
-
runtimeMcpPath: result.runtimeMcpPath,
|
|
1934
|
-
codex: codex?.mcp ?? skipped("skipped"),
|
|
1935
|
-
claude: claude?.mcp ?? skipped("skipped"),
|
|
1936
|
-
codex_hooks: codex?.hooks ?? skipped("skipped"),
|
|
1937
|
-
claude_hooks: claude?.hooks ?? skipped("skipped"),
|
|
1938
|
-
claude_md: claude?.claude_md ?? skipped("skipped")
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
function runRecallSetup(opts = {}) {
|
|
1942
|
-
const scope = opts.scope ?? "global";
|
|
1943
|
-
const dryRun = opts.dryRun ?? false;
|
|
1944
|
-
const hooksOnly = opts.hooksOnly ?? false;
|
|
1945
|
-
const mcpOnly = opts.mcpOnly ?? false;
|
|
1946
|
-
const uninstallHooks = opts.uninstallHooks ?? false;
|
|
1947
|
-
const runner = opts.runner ?? defaultRunner;
|
|
1948
|
-
const paths = resolveRuntimePaths(opts.appPath);
|
|
1949
|
-
if (!existsSync5(paths.runtimeNodePath)) {
|
|
1950
|
-
throw new Error(`Node runtime not found at ${paths.runtimeNodePath}`);
|
|
1951
|
-
}
|
|
1952
|
-
if (!existsSync5(paths.runtimeCliPath)) {
|
|
1953
|
-
throw new Error(`Recall CLI entry not found at ${paths.runtimeCliPath}`);
|
|
1954
|
-
}
|
|
1955
|
-
if (!existsSync5(paths.runtimeMcpPath)) {
|
|
1956
|
-
throw new Error(`Recall MCP entry not found at ${paths.runtimeMcpPath}`);
|
|
1957
|
-
}
|
|
1958
|
-
const targetAgents = resolveTargetAgents(opts.agent);
|
|
1959
|
-
const cwd = resolve3(opts.cwd ?? process.cwd());
|
|
1960
|
-
const claudeMdEnabled = opts.claudeMd ?? true;
|
|
1961
|
-
const agents = targetAgents.map(
|
|
1962
|
-
(agent) => setupAgent(agent, {
|
|
1963
|
-
cwd,
|
|
1964
|
-
dryRun,
|
|
1965
|
-
hooksOnly,
|
|
1966
|
-
mcpOnly,
|
|
1967
|
-
paths,
|
|
1968
|
-
runner,
|
|
1969
|
-
scope,
|
|
1970
|
-
uninstallHooks,
|
|
1971
|
-
promptInjection: opts.promptInjection,
|
|
1972
|
-
claudeMd: claudeMdEnabled
|
|
1973
|
-
})
|
|
1974
|
-
);
|
|
1975
|
-
return {
|
|
1976
|
-
...paths,
|
|
1977
|
-
scope,
|
|
1978
|
-
dry_run: dryRun,
|
|
1979
|
-
hooks_only: hooksOnly,
|
|
1980
|
-
mcp_only: mcpOnly,
|
|
1981
|
-
uninstall_hooks: uninstallHooks,
|
|
1982
|
-
agents
|
|
1983
|
-
};
|
|
1984
|
-
}
|
|
1985
|
-
function setupAgent(agent, options) {
|
|
1986
|
-
const detected = detectAgent(agent);
|
|
1987
|
-
const hookless = isHooklessAgent(agent);
|
|
1988
|
-
const hookConfigPath = hookless ? null : resolveHookConfigPath(agent, options.scope, options.cwd);
|
|
1989
|
-
const mcp = options.hooksOnly ? skipped("hooks-only") : configureMcp(agent, options);
|
|
1990
|
-
const hooks = options.mcpOnly ? skipped("mcp-only") : hookless ? skipped(`${agent} exposes no hook API \u2014 memory routes through MCP + rules file`) : configureHooks(agent, {
|
|
1991
|
-
configPath: hookConfigPath,
|
|
1992
|
-
dryRun: options.dryRun,
|
|
1993
|
-
paths: options.paths,
|
|
1994
|
-
scope: options.scope,
|
|
1995
|
-
uninstallHooks: options.uninstallHooks,
|
|
1996
|
-
promptInjection: options.promptInjection
|
|
1997
|
-
});
|
|
1998
|
-
let rules;
|
|
1999
|
-
let rulesPath = null;
|
|
2000
|
-
if (hookless && !options.mcpOnly) {
|
|
2001
|
-
const adapter = resolveAdapter(agent);
|
|
2002
|
-
if (options.dryRun) {
|
|
2003
|
-
rules = ok(
|
|
2004
|
-
options.uninstallHooks ? "would remove Recall rules block" : "would install Recall rules block"
|
|
2005
|
-
);
|
|
2006
|
-
} else {
|
|
2007
|
-
const result = options.uninstallHooks ? adapter.uninstallRules({ cwd: options.cwd }) : adapter.installRules({ cwd: options.cwd });
|
|
2008
|
-
rules = { enabled: true, ok: result.ok, message: result.message };
|
|
2009
|
-
rulesPath = result.config_path;
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
let claudeMd;
|
|
2013
|
-
let claudeMdPath2 = null;
|
|
2014
|
-
if (agent === "claude-code" && !options.mcpOnly && options.claudeMd !== false) {
|
|
2015
|
-
if (options.dryRun) {
|
|
2016
|
-
claudeMd = ok(
|
|
2017
|
-
options.uninstallHooks ? "would remove Recall block from CLAUDE.md" : "would install Recall block into CLAUDE.md"
|
|
2018
|
-
);
|
|
2019
|
-
} else {
|
|
2020
|
-
const result = options.uninstallHooks ? uninstallClaudeCodeMemoryOverride() : installClaudeCodeMemoryOverride();
|
|
2021
|
-
claudeMd = { enabled: true, ok: result.ok, message: result.message };
|
|
2022
|
-
claudeMdPath2 = result.config_path;
|
|
2023
|
-
}
|
|
2024
|
-
} else if (agent === "claude-code" && options.claudeMd === false) {
|
|
2025
|
-
claudeMd = skipped("--no-claude-md");
|
|
2026
|
-
}
|
|
2027
|
-
return {
|
|
2028
|
-
agent,
|
|
2029
|
-
detected,
|
|
2030
|
-
mcp,
|
|
2031
|
-
hooks,
|
|
2032
|
-
hook_config_path: options.mcpOnly ? null : hookConfigPath,
|
|
2033
|
-
claude_md: claudeMd,
|
|
2034
|
-
claude_md_path: claudeMdPath2,
|
|
2035
|
-
rules,
|
|
2036
|
-
rules_path: rulesPath
|
|
2037
|
-
};
|
|
2038
|
-
}
|
|
2039
|
-
function configureMcp(agent, options) {
|
|
2040
|
-
if (isHooklessAgent(agent)) {
|
|
2041
|
-
const adapter = resolveAdapter(agent);
|
|
2042
|
-
if (adapter.detect() !== "installed") {
|
|
2043
|
-
return skipped(`${agent} not detected`);
|
|
2044
|
-
}
|
|
2045
|
-
if (options.dryRun) {
|
|
2046
|
-
return ok(`would register Recall MCP server in ${adapter.configPath()}`);
|
|
2047
|
-
}
|
|
2048
|
-
const result = adapter.writeMcpFallback({
|
|
2049
|
-
nodePath: options.paths.runtimeNodePath,
|
|
2050
|
-
mcpPath: options.paths.runtimeMcpPath,
|
|
2051
|
-
scope: options.scope,
|
|
2052
|
-
cwd: options.cwd
|
|
2053
|
-
});
|
|
2054
|
-
return { enabled: true, ok: result.ok, message: result.message };
|
|
2055
|
-
}
|
|
2056
|
-
if (agent === "gemini-cli" || agent === "qwen") {
|
|
2057
|
-
return skipped(`${agent} adapter is a reserved stub`);
|
|
2058
|
-
}
|
|
2059
|
-
if (agent === "codex") {
|
|
2060
|
-
if (!hasCommand("codex")) return skipped("codex not found on PATH");
|
|
2061
|
-
if (options.scope === "project") {
|
|
2062
|
-
return skipped("project-scoped Codex MCP not supported by Codex CLI");
|
|
2063
|
-
}
|
|
2064
|
-
const targets = resolveCodexHookTargets();
|
|
2065
|
-
if (options.dryRun) {
|
|
2066
|
-
return ok(describeCodexTargets("would configure global Codex MCP server", targets));
|
|
2067
|
-
}
|
|
2068
|
-
for (const target of targets) {
|
|
2069
|
-
const env = { ...process.env, CODEX_HOME: target.home };
|
|
2070
|
-
tryRun(options.runner, "codex", ["mcp", "remove", "recall"], { env });
|
|
2071
|
-
options.runner(
|
|
2072
|
-
"codex",
|
|
2073
|
-
["mcp", "add", "recall", "--", options.paths.runtimeNodePath, options.paths.runtimeMcpPath],
|
|
2074
|
-
{ env }
|
|
2075
|
-
);
|
|
2076
|
-
}
|
|
2077
|
-
return ok(describeCodexTargets("configured global Codex MCP server", targets));
|
|
2078
|
-
}
|
|
2079
|
-
if (!hasCommand("claude")) return skipped("claude not found on PATH");
|
|
2080
|
-
const claudeScope = options.scope === "project" ? "project" : "user";
|
|
2081
|
-
if (options.dryRun) {
|
|
2082
|
-
return ok(`would configure ${claudeScope} Claude MCP server`);
|
|
2083
|
-
}
|
|
2084
|
-
tryRun(options.runner, "claude", ["mcp", "remove", "recall", "-s", claudeScope]);
|
|
2085
|
-
options.runner("claude", ["mcp", "add", "-s", claudeScope, "recall", options.paths.runtimeNodePath, options.paths.runtimeMcpPath]);
|
|
2086
|
-
return ok(`configured ${claudeScope} Claude MCP server`);
|
|
2087
|
-
}
|
|
2088
|
-
function configureHooks(agent, options) {
|
|
2089
|
-
const codexTargets = agent === "codex" ? options.scope === "project" ? [{
|
|
2090
|
-
home: dirname4(options.configPath),
|
|
2091
|
-
configPath: options.configPath,
|
|
2092
|
-
hooksPath: join7(dirname4(options.configPath), "hooks.json")
|
|
2093
|
-
}] : resolveCodexHookTargets() : [];
|
|
2094
|
-
if (options.dryRun) {
|
|
2095
|
-
const base = options.uninstallHooks ? `would remove hooks from ${options.configPath}` : `would install hooks into ${options.configPath}${options.promptInjection === false ? " (prompt injection opt-out)" : ""}`;
|
|
2096
|
-
return ok(agent === "codex" ? describeCodexTargets(base, codexTargets) : base);
|
|
2097
|
-
}
|
|
2098
|
-
if (agent === "codex") {
|
|
2099
|
-
const results = codexTargets.map(
|
|
2100
|
-
(target) => options.uninstallHooks ? uninstallCodexHooks({ configPath: target.configPath, hooksPath: target.hooksPath }) : installCodexHooks({
|
|
2101
|
-
configPath: target.configPath,
|
|
2102
|
-
hooksPath: target.hooksPath,
|
|
2103
|
-
cliPath: options.paths.runtimeCliPath,
|
|
2104
|
-
nodePath: options.paths.runtimeNodePath,
|
|
2105
|
-
promptInjection: options.promptInjection
|
|
2106
|
-
})
|
|
2107
|
-
);
|
|
2108
|
-
const failed2 = results.filter((entry) => !entry.ok);
|
|
2109
|
-
const headline = failed2.length > 0 ? failed2[0].message : results[0]?.message ?? "no Codex home found";
|
|
2110
|
-
return {
|
|
2111
|
-
enabled: true,
|
|
2112
|
-
ok: failed2.length === 0 && results.length > 0,
|
|
2113
|
-
message: describeCodexTargets(headline, codexTargets)
|
|
2114
|
-
};
|
|
2115
|
-
}
|
|
2116
|
-
const result = options.uninstallHooks ? uninstallClaudeCodeHooks({ configPath: options.configPath }) : installClaudeCodeHooks({
|
|
2117
|
-
configPath: options.configPath,
|
|
2118
|
-
cliPath: options.paths.runtimeCliPath,
|
|
2119
|
-
nodePath: options.paths.runtimeNodePath,
|
|
2120
|
-
promptInjection: options.promptInjection
|
|
2121
|
-
});
|
|
2122
|
-
return {
|
|
2123
|
-
enabled: true,
|
|
2124
|
-
ok: result.ok,
|
|
2125
|
-
message: result.message
|
|
2126
|
-
};
|
|
2127
|
-
}
|
|
2128
|
-
function describeCodexTargets(message, targets) {
|
|
2129
|
-
if (targets.length <= 1) return message;
|
|
2130
|
-
const names = targets.map((target) => basename(target.home)).join(", ");
|
|
2131
|
-
return `${message} across ${targets.length} Codex homes (${names})`;
|
|
2132
|
-
}
|
|
2133
|
-
function resolveTargetAgents(target) {
|
|
2134
|
-
if (target && target.length > 0) {
|
|
2135
|
-
return [...new Set(target)];
|
|
2136
|
-
}
|
|
2137
|
-
return listAgentNames().filter((agent) => detectAgent(agent));
|
|
2138
|
-
}
|
|
2139
|
-
function detectAgent(agent) {
|
|
2140
|
-
if (agent === "codex") {
|
|
2141
|
-
return hasCommand("codex") || existsSync5(join7(resolveUserHomeDir(), ".codex", "config.toml"));
|
|
2142
|
-
}
|
|
2143
|
-
if (agent === "claude-code") {
|
|
2144
|
-
return hasCommand("claude") || existsSync5(join7(resolveUserHomeDir(), ".claude", "settings.json"));
|
|
2145
|
-
}
|
|
2146
|
-
return resolveAdapter(agent).detect() === "installed";
|
|
2147
|
-
}
|
|
2148
|
-
function resolveHookConfigPath(agent, scope, cwd) {
|
|
2149
|
-
if (scope === "project") {
|
|
2150
|
-
return agent === "codex" ? join7(cwd, ".codex", "config.toml") : join7(cwd, ".claude", "settings.json");
|
|
2151
|
-
}
|
|
2152
|
-
return agent === "codex" ? join7(resolveUserHomeDir(), ".codex", "config.toml") : join7(resolveUserHomeDir(), ".claude", "settings.json");
|
|
2153
|
-
}
|
|
2154
|
-
function defaultRunner(command, args, options) {
|
|
2155
|
-
execFileSync2(command, args, { ...stdioOpts(), ...options?.env ? { env: options.env } : {} });
|
|
2156
|
-
}
|
|
2157
|
-
function tryRun(runner, command, args, options) {
|
|
2158
|
-
try {
|
|
2159
|
-
runner(command, args, options);
|
|
2160
|
-
} catch {
|
|
2161
|
-
return;
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
function stdioOpts() {
|
|
2165
|
-
return {
|
|
2166
|
-
stdio: "ignore"
|
|
2167
|
-
};
|
|
2168
|
-
}
|
|
2169
|
-
function ok(message) {
|
|
2170
|
-
return { enabled: true, ok: true, message };
|
|
2171
|
-
}
|
|
2172
|
-
function skipped(message) {
|
|
2173
|
-
return { enabled: false, ok: false, message };
|
|
2174
|
-
}
|
|
2175
|
-
|
|
2176
|
-
// src/cli.ts
|
|
2177
|
-
import { createRequire } from "module";
|
|
2178
|
-
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2179
|
-
|
|
2180
|
-
// src/doctor/report.ts
|
|
2181
|
-
init_define_RECALL_BUILD_INFO();
|
|
2182
|
-
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "fs";
|
|
2183
|
-
import { basename as basename2, join as join10 } from "path";
|
|
2184
|
-
import Database2 from "better-sqlite3";
|
|
2185
|
-
|
|
2186
|
-
// src/daemon/launchd.ts
|
|
2187
|
-
init_define_RECALL_BUILD_INFO();
|
|
2188
|
-
import { chmodSync, existsSync as existsSync6, mkdirSync as mkdirSync4, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
2189
|
-
import { homedir } from "os";
|
|
2190
|
-
import { dirname as dirname5, join as join8, resolve as resolve4 } from "path";
|
|
2191
|
-
import { execFileSync as execFileSync3 } from "child_process";
|
|
2192
|
-
|
|
2193
|
-
// src/daemon/provider-env.ts
|
|
2194
|
-
init_define_RECALL_BUILD_INFO();
|
|
2195
|
-
var DAEMON_PROVIDER_ENV_KEYS = [
|
|
2196
|
-
"OPENAI_API_KEY",
|
|
2197
|
-
"ANTHROPIC_API_KEY",
|
|
2198
|
-
"AZURE_OPENAI_ENDPOINT",
|
|
2199
|
-
"AZURE_OPENAI_DEPLOYMENT",
|
|
2200
|
-
"AZURE_OPENAI_API_VERSION",
|
|
2201
|
-
"AZURE_OPENAI_API_KEY"
|
|
2202
|
-
];
|
|
2203
|
-
function resolveDaemonProviderEnvironment(current, installed = {}) {
|
|
2204
|
-
const resolved = {};
|
|
2205
|
-
for (const key of DAEMON_PROVIDER_ENV_KEYS) {
|
|
2206
|
-
const value = current[key] ?? installed[key];
|
|
2207
|
-
if (value && value.trim().length > 0) {
|
|
2208
|
-
resolved[key] = value;
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
return resolved;
|
|
2212
|
-
}
|
|
2213
|
-
function readDaemonProviderEnvironment(environment) {
|
|
2214
|
-
const installed = {};
|
|
2215
|
-
for (const key of DAEMON_PROVIDER_ENV_KEYS) {
|
|
2216
|
-
const value = environment[key];
|
|
2217
|
-
if (typeof value === "string" && value.trim().length > 0) {
|
|
2218
|
-
installed[key] = value;
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
return installed;
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
|
-
// src/daemon/launchd.ts
|
|
2225
|
-
var DEFAULT_LABEL = "com.recall.daemon";
|
|
2226
|
-
function installLaunchAgent(opts = {}) {
|
|
2227
|
-
assertDarwin();
|
|
2228
|
-
const cfg = resolveConfig(opts);
|
|
2229
|
-
mkdirSync4(dirname5(cfg.plistPath), { recursive: true });
|
|
2230
|
-
mkdirSync4(dirname5(cfg.stdoutPath), { recursive: true });
|
|
2231
|
-
writeFileSync4(cfg.plistPath, renderPlist(cfg), { mode: 384 });
|
|
2232
|
-
chmodSync(cfg.plistPath, 384);
|
|
2233
|
-
tryRun2("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
2234
|
-
execFileSync3("launchctl", ["bootstrap", domainTarget(), cfg.plistPath], stdioOpts2());
|
|
2235
|
-
execFileSync3("launchctl", ["enable", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2236
|
-
execFileSync3("launchctl", ["kickstart", "-k", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2237
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2238
|
-
}
|
|
2239
|
-
function uninstallLaunchAgent(label = DEFAULT_LABEL) {
|
|
2240
|
-
assertDarwin();
|
|
2241
|
-
const cfg = resolveConfig({ label });
|
|
2242
|
-
tryRun2("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
2243
|
-
tryRun2("launchctl", ["disable", `${domainTarget()}/${cfg.label}`]);
|
|
2244
|
-
rmSync3(cfg.plistPath, { force: true });
|
|
2245
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2246
|
-
}
|
|
2247
|
-
function startLaunchAgent(label = DEFAULT_LABEL) {
|
|
2248
|
-
assertDarwin();
|
|
2249
|
-
const cfg = resolveConfig({ label });
|
|
2250
|
-
if (!exists(cfg.plistPath)) {
|
|
2251
|
-
throw new Error(`LaunchAgent not installed: ${cfg.plistPath}`);
|
|
2252
|
-
}
|
|
2253
|
-
execFileSync3("launchctl", ["enable", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2254
|
-
tryRun2("launchctl", ["bootstrap", domainTarget(), cfg.plistPath]);
|
|
2255
|
-
execFileSync3("launchctl", ["kickstart", "-k", `${domainTarget()}/${cfg.label}`], stdioOpts2());
|
|
2256
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2257
|
-
}
|
|
2258
|
-
function stopLaunchAgent(label = DEFAULT_LABEL) {
|
|
2259
|
-
assertDarwin();
|
|
2260
|
-
const cfg = resolveConfig({ label });
|
|
2261
|
-
if (exists(cfg.plistPath)) {
|
|
2262
|
-
tryRun2("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
|
|
2263
|
-
}
|
|
2264
|
-
return getLaunchAgentStatus(cfg.label);
|
|
2265
|
-
}
|
|
2266
|
-
function getLaunchAgentStatus(label = DEFAULT_LABEL) {
|
|
2267
|
-
assertDarwin();
|
|
2268
|
-
const cfg = resolveConfig({ label });
|
|
2269
|
-
const installed = exists(cfg.plistPath);
|
|
2270
|
-
const output = tryOutput("launchctl", ["print", `${domainTarget()}/${cfg.label}`]);
|
|
2271
|
-
return {
|
|
2272
|
-
label: cfg.label,
|
|
2273
|
-
plistPath: cfg.plistPath,
|
|
2274
|
-
installed,
|
|
2275
|
-
loaded: output.ok,
|
|
2276
|
-
state: output.ok ? extractState(output.output) : void 0
|
|
2277
|
-
};
|
|
2278
|
-
}
|
|
2279
|
-
function getLaunchAgentInfo(label = DEFAULT_LABEL) {
|
|
2280
|
-
assertDarwin();
|
|
2281
|
-
const cfg = resolveConfig({ label });
|
|
2282
|
-
const status = getLaunchAgentStatus(label);
|
|
2283
|
-
const installed = readInstalledConfig(cfg.plistPath);
|
|
2284
|
-
const lines = [
|
|
2285
|
-
`Label: ${status.label}`,
|
|
2286
|
-
`Plist: ${cfg.plistPath}`,
|
|
2287
|
-
`Installed: ${status.installed ? "yes" : "no"}`,
|
|
2288
|
-
`Loaded: ${status.loaded ? "yes" : "no"}`
|
|
2289
|
-
];
|
|
2290
|
-
if (status.state) {
|
|
2291
|
-
lines.push(`State: ${status.state}`);
|
|
2292
|
-
}
|
|
2293
|
-
lines.push(`Port: ${installed?.port ?? cfg.port}`);
|
|
2294
|
-
lines.push(`Data dir: ${installed?.dataDir ?? cfg.dataDir}`);
|
|
2295
|
-
if (installed?.repoRoots ?? cfg.repoRoots) {
|
|
2296
|
-
lines.push(`Repos: ${installed?.repoRoots ?? cfg.repoRoots}`);
|
|
2297
|
-
}
|
|
2298
|
-
if (installed?.repoOverride ?? cfg.repoOverride) {
|
|
2299
|
-
lines.push(`Repo: ${installed?.repoOverride ?? cfg.repoOverride}`);
|
|
2300
|
-
}
|
|
2301
|
-
if (installed?.embeddingProvider ?? cfg.embeddingProvider) {
|
|
2302
|
-
lines.push(`EmbedProv: ${installed?.embeddingProvider ?? cfg.embeddingProvider}`);
|
|
2303
|
-
}
|
|
2304
|
-
if (installed?.embeddingDims ?? cfg.embeddingDims) {
|
|
2305
|
-
lines.push(`EmbedDims: ${installed?.embeddingDims ?? cfg.embeddingDims}`);
|
|
2306
|
-
}
|
|
2307
|
-
if (installed?.embeddingsDisabled ?? cfg.embeddingsDisabled) {
|
|
2308
|
-
lines.push(`EmbedOff: ${installed?.embeddingsDisabled ?? cfg.embeddingsDisabled}`);
|
|
2309
|
-
}
|
|
2310
|
-
lines.push(`Node: ${installed?.nodePath ?? cfg.nodePath}`);
|
|
2311
|
-
lines.push(`Script: ${installed?.daemonScript ?? cfg.daemonScript}`);
|
|
2312
|
-
lines.push(`Maintain: ${installed?.maintenanceIntervalSeconds ?? cfg.maintenanceIntervalSeconds}s`);
|
|
2313
|
-
lines.push(`Stdout: ${installed?.stdoutPath ?? cfg.stdoutPath}`);
|
|
2314
|
-
lines.push(`Stderr: ${installed?.stderrPath ?? cfg.stderrPath}`);
|
|
2315
|
-
return lines.join("\n");
|
|
2316
|
-
}
|
|
2317
|
-
function resolveConfig(opts) {
|
|
2318
|
-
const label = opts.label ?? DEFAULT_LABEL;
|
|
2319
|
-
const home = homedir();
|
|
2320
|
-
const port = opts.port ?? parseInt(process.env.RECALL_PORT ?? "7890", 10);
|
|
2321
|
-
const maintenanceIntervalSeconds = opts.maintenanceIntervalSeconds ?? parseInt(process.env.RECALL_MAINTENANCE_INTERVAL_SECONDS ?? "3600", 10);
|
|
2322
|
-
const dataDir = resolve4(
|
|
2323
|
-
opts.dataDir ?? process.env.RECALL_DATA_DIR ?? join8(home, ".recall")
|
|
2324
|
-
);
|
|
2325
|
-
const nodePath = resolve4(opts.nodePath ?? process.execPath);
|
|
2326
|
-
const daemonScript = resolve4(
|
|
2327
|
-
opts.daemonScript ?? join8(process.cwd(), "dist", "daemon.js")
|
|
2328
|
-
);
|
|
2329
|
-
const plistPath = join8(home, "Library", "LaunchAgents", `${label}.plist`);
|
|
2330
|
-
const logDir = join8(dataDir, "logs");
|
|
2331
|
-
const installed = readInstalledConfig(plistPath);
|
|
2332
|
-
return {
|
|
2333
|
-
label,
|
|
2334
|
-
port,
|
|
2335
|
-
maintenanceIntervalSeconds,
|
|
2336
|
-
dataDir,
|
|
2337
|
-
nodePath,
|
|
2338
|
-
daemonScript,
|
|
2339
|
-
plistPath,
|
|
2340
|
-
stdoutPath: join8(logDir, "daemon.stdout.log"),
|
|
2341
|
-
stderrPath: join8(logDir, "daemon.stderr.log"),
|
|
2342
|
-
repoRoots: opts.repoRoots ?? process.env.RECALL_REPO_ROOTS,
|
|
2343
|
-
repoOverride: opts.repoOverride ?? process.env.RECALL_REPO_OVERRIDE ?? installed?.repoOverride,
|
|
2344
|
-
embeddingProvider: opts.embeddingProvider ?? process.env.RECALL_EMBEDDING_PROVIDER,
|
|
2345
|
-
embeddingDims: opts.embeddingDims ?? process.env.RECALL_EMBEDDING_DIMS,
|
|
2346
|
-
embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED,
|
|
2347
|
-
providerEnvironment: resolveDaemonProviderEnvironment(
|
|
2348
|
-
process.env,
|
|
2349
|
-
installed?.providerEnvironment
|
|
2350
|
-
)
|
|
2351
|
-
};
|
|
2352
|
-
}
|
|
2353
|
-
function renderPlist(cfg) {
|
|
2354
|
-
const env = {
|
|
2355
|
-
RECALL_PORT: String(cfg.port),
|
|
2356
|
-
RECALL_MAINTENANCE_INTERVAL_SECONDS: String(cfg.maintenanceIntervalSeconds),
|
|
2357
|
-
RECALL_DATA_DIR: cfg.dataDir,
|
|
2358
|
-
PATH: process.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
2359
|
-
...cfg.repoRoots ? { RECALL_REPO_ROOTS: cfg.repoRoots } : {},
|
|
2360
|
-
...cfg.repoOverride ? { RECALL_REPO_OVERRIDE: cfg.repoOverride } : {},
|
|
2361
|
-
...cfg.embeddingProvider ? { RECALL_EMBEDDING_PROVIDER: cfg.embeddingProvider } : {},
|
|
2362
|
-
...cfg.embeddingDims ? { RECALL_EMBEDDING_DIMS: cfg.embeddingDims } : {},
|
|
2363
|
-
...cfg.embeddingsDisabled ? { RECALL_EMBEDDINGS_DISABLED: cfg.embeddingsDisabled } : {},
|
|
2364
|
-
...cfg.providerEnvironment
|
|
2365
|
-
};
|
|
2366
|
-
const environmentXml = Object.entries(env).map(([key, value]) => ` <key>${escapeXml(key)}</key>
|
|
2367
|
-
<string>${escapeXml(value)}</string>`).join("\n");
|
|
2368
|
-
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
2369
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
2370
|
-
<plist version="1.0">
|
|
2371
|
-
<dict>
|
|
2372
|
-
<key>Label</key>
|
|
2373
|
-
<string>${escapeXml(cfg.label)}</string>
|
|
2374
|
-
<key>ProgramArguments</key>
|
|
2375
|
-
<array>
|
|
2376
|
-
<string>${escapeXml(cfg.nodePath)}</string>
|
|
2377
|
-
<string>${escapeXml(cfg.daemonScript)}</string>
|
|
2378
|
-
</array>
|
|
2379
|
-
<key>EnvironmentVariables</key>
|
|
2380
|
-
<dict>
|
|
2381
|
-
${environmentXml}
|
|
2382
|
-
</dict>
|
|
2383
|
-
<key>RunAtLoad</key>
|
|
2384
|
-
<true/>
|
|
2385
|
-
<key>KeepAlive</key>
|
|
2386
|
-
<true/>
|
|
2387
|
-
<key>WorkingDirectory</key>
|
|
2388
|
-
<string>${escapeXml(process.cwd())}</string>
|
|
2389
|
-
<key>StandardOutPath</key>
|
|
2390
|
-
<string>${escapeXml(cfg.stdoutPath)}</string>
|
|
2391
|
-
<key>StandardErrorPath</key>
|
|
2392
|
-
<string>${escapeXml(cfg.stderrPath)}</string>
|
|
2393
|
-
</dict>
|
|
2394
|
-
</plist>
|
|
2395
|
-
`;
|
|
2396
|
-
}
|
|
2397
|
-
function domainTarget() {
|
|
2398
|
-
const uid = process.getuid?.();
|
|
2399
|
-
if (uid == null) {
|
|
2400
|
-
throw new Error("Could not determine current macOS user id");
|
|
2401
|
-
}
|
|
2402
|
-
return `gui/${uid}`;
|
|
2403
|
-
}
|
|
2404
|
-
function extractState(output) {
|
|
2405
|
-
const line = output.split("\n").find((item) => item.trim().startsWith("state = "));
|
|
2406
|
-
if (!line) return void 0;
|
|
2407
|
-
return line.split("=").slice(1).join("=").trim();
|
|
2408
|
-
}
|
|
2409
|
-
function tryRun2(cmd, args) {
|
|
2410
|
-
try {
|
|
2411
|
-
execFileSync3(cmd, args, stdioOpts2());
|
|
2412
|
-
} catch {
|
|
2413
|
-
return;
|
|
2414
|
-
}
|
|
2415
|
-
}
|
|
2416
|
-
function tryOutput(cmd, args) {
|
|
2417
|
-
try {
|
|
2418
|
-
const output = execFileSync3(cmd, args, {
|
|
2419
|
-
encoding: "utf8",
|
|
2420
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
2421
|
-
});
|
|
2422
|
-
return { ok: true, output };
|
|
2423
|
-
} catch (error) {
|
|
2424
|
-
return {
|
|
2425
|
-
ok: false,
|
|
2426
|
-
output: String(error?.stdout ?? error?.stderr ?? error?.message ?? "")
|
|
2427
|
-
};
|
|
2428
|
-
}
|
|
2429
|
-
}
|
|
2430
|
-
function readInstalledConfig(plistPath) {
|
|
2431
|
-
if (!exists(plistPath)) return null;
|
|
2432
|
-
try {
|
|
2433
|
-
const raw = execFileSync3("plutil", ["-convert", "json", "-o", "-", plistPath], {
|
|
2434
|
-
encoding: "utf8",
|
|
2435
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
2436
|
-
});
|
|
2437
|
-
const parsed = JSON.parse(raw);
|
|
2438
|
-
return {
|
|
2439
|
-
nodePath: parsed?.ProgramArguments?.[0],
|
|
2440
|
-
daemonScript: parsed?.ProgramArguments?.[1],
|
|
2441
|
-
port: parsed?.EnvironmentVariables?.RECALL_PORT,
|
|
2442
|
-
maintenanceIntervalSeconds: parsed?.EnvironmentVariables?.RECALL_MAINTENANCE_INTERVAL_SECONDS,
|
|
2443
|
-
dataDir: parsed?.EnvironmentVariables?.RECALL_DATA_DIR,
|
|
2444
|
-
repoRoots: parsed?.EnvironmentVariables?.RECALL_REPO_ROOTS,
|
|
2445
|
-
repoOverride: parsed?.EnvironmentVariables?.RECALL_REPO_OVERRIDE,
|
|
2446
|
-
embeddingProvider: parsed?.EnvironmentVariables?.RECALL_EMBEDDING_PROVIDER,
|
|
2447
|
-
embeddingDims: parsed?.EnvironmentVariables?.RECALL_EMBEDDING_DIMS,
|
|
2448
|
-
embeddingsDisabled: parsed?.EnvironmentVariables?.RECALL_EMBEDDINGS_DISABLED,
|
|
2449
|
-
providerEnvironment: readDaemonProviderEnvironment(
|
|
2450
|
-
parsed?.EnvironmentVariables ?? {}
|
|
2451
|
-
),
|
|
2452
|
-
stdoutPath: parsed?.StandardOutPath,
|
|
2453
|
-
stderrPath: parsed?.StandardErrorPath
|
|
2454
|
-
};
|
|
2455
|
-
} catch {
|
|
2456
|
-
return null;
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
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
|
+
});
|
|
2460
1033
|
return {
|
|
2461
|
-
|
|
1034
|
+
enabled: true,
|
|
1035
|
+
ok: result.ok,
|
|
1036
|
+
message: result.message
|
|
2462
1037
|
};
|
|
2463
1038
|
}
|
|
2464
|
-
function
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2469
|
-
}
|
|
2470
|
-
function assertDarwin() {
|
|
2471
|
-
if (process.platform !== "darwin") {
|
|
2472
|
-
throw new Error("launchd daemon install is only supported on macOS");
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
|
-
// src/daemon/systemd.ts
|
|
2477
|
-
init_define_RECALL_BUILD_INFO();
|
|
2478
|
-
import { chmodSync as chmodSync2, existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync4, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "fs";
|
|
2479
|
-
import { homedir as homedir2 } from "os";
|
|
2480
|
-
import { dirname as dirname6, join as join9, resolve as resolve5 } from "path";
|
|
2481
|
-
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2482
|
-
import { execFileSync as execFileSync4 } from "child_process";
|
|
2483
|
-
var DEFAULT_LABEL2 = "recall-daemon";
|
|
2484
|
-
function installSystemdUnit(opts = {}) {
|
|
2485
|
-
assertLinux();
|
|
2486
|
-
const cfg = resolveConfig2(opts);
|
|
2487
|
-
mkdirSync5(dirname6(cfg.unitPath), { recursive: true });
|
|
2488
|
-
mkdirSync5(cfg.logDir, { recursive: true });
|
|
2489
|
-
writeFileSync5(cfg.unitPath, renderUnit(cfg), { mode: 384 });
|
|
2490
|
-
chmodSync2(cfg.unitPath, 384);
|
|
2491
|
-
for (const args of systemdInstallCommands(cfg.label)) systemctl(args);
|
|
2492
|
-
return getSystemdStatus(cfg.label);
|
|
2493
|
-
}
|
|
2494
|
-
function systemdInstallCommands(label = DEFAULT_LABEL2) {
|
|
2495
|
-
const service = `${label}.service`;
|
|
2496
|
-
return [
|
|
2497
|
-
["--user", "daemon-reload"],
|
|
2498
|
-
["--user", "enable", service],
|
|
2499
|
-
// `enable --now` leaves an already-active process untouched. Restart so a
|
|
2500
|
-
// package upgrade actually runs the newly installed daemon code.
|
|
2501
|
-
["--user", "restart", service]
|
|
2502
|
-
];
|
|
2503
|
-
}
|
|
2504
|
-
function uninstallSystemdUnit(label = DEFAULT_LABEL2) {
|
|
2505
|
-
assertLinux();
|
|
2506
|
-
const cfg = resolveConfig2({ label });
|
|
2507
|
-
trySystemctl(["--user", "disable", "--now", `${cfg.label}.service`]);
|
|
2508
|
-
rmSync4(cfg.unitPath, { force: true });
|
|
2509
|
-
trySystemctl(["--user", "daemon-reload"]);
|
|
2510
|
-
return getSystemdStatus(cfg.label);
|
|
2511
|
-
}
|
|
2512
|
-
function startSystemdUnit(label = DEFAULT_LABEL2) {
|
|
2513
|
-
assertLinux();
|
|
2514
|
-
const cfg = resolveConfig2({ label });
|
|
2515
|
-
if (!existsSync7(cfg.unitPath)) {
|
|
2516
|
-
throw new Error(`systemd unit not installed: ${cfg.unitPath}`);
|
|
2517
|
-
}
|
|
2518
|
-
systemctl(["--user", "start", `${cfg.label}.service`]);
|
|
2519
|
-
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})`;
|
|
2520
1043
|
}
|
|
2521
|
-
function
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
if (existsSync7(cfg.unitPath)) {
|
|
2525
|
-
trySystemctl(["--user", "stop", `${cfg.label}.service`]);
|
|
1044
|
+
function resolveTargetAgents(target) {
|
|
1045
|
+
if (target && target.length > 0) {
|
|
1046
|
+
return [...new Set(target)];
|
|
2526
1047
|
}
|
|
2527
|
-
return
|
|
2528
|
-
}
|
|
2529
|
-
function getSystemdStatus(label = DEFAULT_LABEL2) {
|
|
2530
|
-
assertLinux();
|
|
2531
|
-
const cfg = resolveConfig2({ label });
|
|
2532
|
-
const installed = existsSync7(cfg.unitPath);
|
|
2533
|
-
const active = trySystemctlOutput(["--user", "is-active", `${cfg.label}.service`]);
|
|
2534
|
-
const loaded = active.ok && active.output.trim() === "active";
|
|
2535
|
-
const state = active.output.trim() || void 0;
|
|
2536
|
-
return {
|
|
2537
|
-
label: cfg.label,
|
|
2538
|
-
unitPath: cfg.unitPath,
|
|
2539
|
-
installed,
|
|
2540
|
-
loaded,
|
|
2541
|
-
state
|
|
2542
|
-
};
|
|
1048
|
+
return listAgentNames().filter((agent) => detectAgent(agent));
|
|
2543
1049
|
}
|
|
2544
|
-
function
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
const status = getSystemdStatus(label);
|
|
2548
|
-
const installed = readInstalledConfig2(cfg.unitPath);
|
|
2549
|
-
const lines = [
|
|
2550
|
-
`Label: ${status.label}`,
|
|
2551
|
-
`Unit: ${cfg.unitPath}`,
|
|
2552
|
-
`Installed: ${status.installed ? "yes" : "no"}`,
|
|
2553
|
-
`Loaded: ${status.loaded ? "yes" : "no"}`
|
|
2554
|
-
];
|
|
2555
|
-
if (status.state) lines.push(`State: ${status.state}`);
|
|
2556
|
-
lines.push(`Port: ${installed?.port ?? cfg.port}`);
|
|
2557
|
-
lines.push(`Data dir: ${installed?.dataDir ?? cfg.dataDir}`);
|
|
2558
|
-
if (installed?.repoRoots ?? cfg.repoRoots) {
|
|
2559
|
-
lines.push(`Repos: ${installed?.repoRoots ?? cfg.repoRoots}`);
|
|
2560
|
-
}
|
|
2561
|
-
if (installed?.repoOverride ?? cfg.repoOverride) {
|
|
2562
|
-
lines.push(`Repo: ${installed?.repoOverride ?? cfg.repoOverride}`);
|
|
2563
|
-
}
|
|
2564
|
-
if (installed?.embeddingProvider ?? cfg.embeddingProvider) {
|
|
2565
|
-
lines.push(`EmbedProv: ${installed?.embeddingProvider ?? cfg.embeddingProvider}`);
|
|
2566
|
-
}
|
|
2567
|
-
if (installed?.embeddingDims ?? cfg.embeddingDims) {
|
|
2568
|
-
lines.push(`EmbedDims: ${installed?.embeddingDims ?? cfg.embeddingDims}`);
|
|
2569
|
-
}
|
|
2570
|
-
if (installed?.embeddingsDisabled ?? cfg.embeddingsDisabled) {
|
|
2571
|
-
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"));
|
|
2572
1053
|
}
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
lines.push(`Maintain: ${installed?.maintenanceIntervalSeconds ?? cfg.maintenanceIntervalSeconds}s`);
|
|
2576
|
-
lines.push(`Logs: journalctl --user -u ${cfg.label}.service`);
|
|
2577
|
-
return lines.join("\n");
|
|
2578
|
-
}
|
|
2579
|
-
function resolveConfig2(opts) {
|
|
2580
|
-
const label = opts.label ?? DEFAULT_LABEL2;
|
|
2581
|
-
const home = homedir2();
|
|
2582
|
-
const port = opts.port ?? parseInt(process.env.RECALL_PORT ?? "7890", 10);
|
|
2583
|
-
const maintenanceIntervalSeconds = opts.maintenanceIntervalSeconds ?? parseInt(process.env.RECALL_MAINTENANCE_INTERVAL_SECONDS ?? "3600", 10);
|
|
2584
|
-
const dataDir = resolve5(
|
|
2585
|
-
opts.dataDir ?? process.env.RECALL_DATA_DIR ?? join9(home, ".recall")
|
|
2586
|
-
);
|
|
2587
|
-
const nodePath = resolve5(opts.nodePath ?? process.execPath);
|
|
2588
|
-
const daemonScript = resolve5(
|
|
2589
|
-
opts.daemonScript ?? defaultDaemonScript()
|
|
2590
|
-
);
|
|
2591
|
-
const configHome = process.env.XDG_CONFIG_HOME ?? join9(home, ".config");
|
|
2592
|
-
const unitPath = join9(configHome, "systemd", "user", `${label}.service`);
|
|
2593
|
-
const logDir = join9(dataDir, "logs");
|
|
2594
|
-
const installed = readInstalledConfig2(unitPath);
|
|
2595
|
-
return {
|
|
2596
|
-
label,
|
|
2597
|
-
port,
|
|
2598
|
-
maintenanceIntervalSeconds,
|
|
2599
|
-
dataDir,
|
|
2600
|
-
nodePath,
|
|
2601
|
-
daemonScript,
|
|
2602
|
-
unitPath,
|
|
2603
|
-
logDir,
|
|
2604
|
-
repoRoots: opts.repoRoots ?? process.env.RECALL_REPO_ROOTS,
|
|
2605
|
-
repoOverride: opts.repoOverride ?? process.env.RECALL_REPO_OVERRIDE ?? installed?.repoOverride,
|
|
2606
|
-
embeddingProvider: opts.embeddingProvider ?? process.env.RECALL_EMBEDDING_PROVIDER,
|
|
2607
|
-
embeddingDims: opts.embeddingDims ?? process.env.RECALL_EMBEDDING_DIMS,
|
|
2608
|
-
embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED,
|
|
2609
|
-
providerEnvironment: resolveDaemonProviderEnvironment(
|
|
2610
|
-
process.env,
|
|
2611
|
-
installed?.providerEnvironment
|
|
2612
|
-
)
|
|
2613
|
-
};
|
|
2614
|
-
}
|
|
2615
|
-
function defaultDaemonScript() {
|
|
2616
|
-
const here = dirname6(fileURLToPath3(import.meta.url));
|
|
2617
|
-
return join9(here, "daemon.js");
|
|
2618
|
-
}
|
|
2619
|
-
function renderUnit(cfg) {
|
|
2620
|
-
const envLines = [
|
|
2621
|
-
`Environment=PATH=${process.env.PATH ?? "/usr/bin:/bin:/usr/local/bin"}`,
|
|
2622
|
-
`Environment=RECALL_PORT=${cfg.port}`,
|
|
2623
|
-
`Environment=RECALL_MAINTENANCE_INTERVAL_SECONDS=${cfg.maintenanceIntervalSeconds}`,
|
|
2624
|
-
`Environment=RECALL_DATA_DIR=${cfg.dataDir}`
|
|
2625
|
-
];
|
|
2626
|
-
if (cfg.repoRoots) envLines.push(`Environment=RECALL_REPO_ROOTS=${cfg.repoRoots}`);
|
|
2627
|
-
if (cfg.repoOverride) envLines.push(`Environment="RECALL_REPO_OVERRIDE=${escapeSystemdValue(cfg.repoOverride)}"`);
|
|
2628
|
-
if (cfg.embeddingProvider) envLines.push(`Environment=RECALL_EMBEDDING_PROVIDER=${cfg.embeddingProvider}`);
|
|
2629
|
-
if (cfg.embeddingDims) envLines.push(`Environment=RECALL_EMBEDDING_DIMS=${cfg.embeddingDims}`);
|
|
2630
|
-
if (cfg.embeddingsDisabled) envLines.push(`Environment=RECALL_EMBEDDINGS_DISABLED=${cfg.embeddingsDisabled}`);
|
|
2631
|
-
for (const [key, value] of Object.entries(cfg.providerEnvironment)) {
|
|
2632
|
-
envLines.push(`Environment="${key}=${escapeSystemdValue(value)}"`);
|
|
2633
|
-
}
|
|
2634
|
-
return `[Unit]
|
|
2635
|
-
Description=Recall local daemon
|
|
2636
|
-
After=network.target
|
|
2637
|
-
|
|
2638
|
-
[Service]
|
|
2639
|
-
Type=simple
|
|
2640
|
-
ExecStart=${cfg.nodePath} ${cfg.daemonScript}
|
|
2641
|
-
Restart=always
|
|
2642
|
-
RestartSec=2
|
|
2643
|
-
${envLines.join("\n")}
|
|
2644
|
-
|
|
2645
|
-
[Install]
|
|
2646
|
-
WantedBy=default.target
|
|
2647
|
-
`;
|
|
2648
|
-
}
|
|
2649
|
-
function readInstalledConfig2(unitPath) {
|
|
2650
|
-
if (!existsSync7(unitPath)) return null;
|
|
2651
|
-
try {
|
|
2652
|
-
const raw = readFileSync4(unitPath, "utf8");
|
|
2653
|
-
const exec = raw.match(/^ExecStart=(.+)$/m)?.[1]?.trim().split(/\s+/);
|
|
2654
|
-
const env = parseSystemdEnvironment(raw);
|
|
2655
|
-
return {
|
|
2656
|
-
nodePath: exec?.[0],
|
|
2657
|
-
daemonScript: exec?.[1],
|
|
2658
|
-
port: env.RECALL_PORT,
|
|
2659
|
-
maintenanceIntervalSeconds: env.RECALL_MAINTENANCE_INTERVAL_SECONDS,
|
|
2660
|
-
dataDir: env.RECALL_DATA_DIR,
|
|
2661
|
-
repoRoots: env.RECALL_REPO_ROOTS,
|
|
2662
|
-
repoOverride: env.RECALL_REPO_OVERRIDE,
|
|
2663
|
-
embeddingProvider: env.RECALL_EMBEDDING_PROVIDER,
|
|
2664
|
-
embeddingDims: env.RECALL_EMBEDDING_DIMS,
|
|
2665
|
-
embeddingsDisabled: env.RECALL_EMBEDDINGS_DISABLED,
|
|
2666
|
-
providerEnvironment: readDaemonProviderEnvironment(env)
|
|
2667
|
-
};
|
|
2668
|
-
} catch {
|
|
2669
|
-
return null;
|
|
1054
|
+
if (agent === "claude-code") {
|
|
1055
|
+
return hasCommand("claude") || existsSync(join2(resolveUserHomeDir(), ".claude", "settings.json"));
|
|
2670
1056
|
}
|
|
1057
|
+
return resolveAdapter(agent).detect() === "installed";
|
|
2671
1058
|
}
|
|
2672
|
-
function
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
const key = match[1] ?? match[3];
|
|
2676
|
-
const value = match[2] != null ? unescapeSystemdValue(match[2]) : match[4];
|
|
2677
|
-
if (key && value != null) {
|
|
2678
|
-
defineOwn(environment, key, value);
|
|
2679
|
-
}
|
|
1059
|
+
function resolveHookConfigPath(agent, scope, cwd) {
|
|
1060
|
+
if (scope === "project") {
|
|
1061
|
+
return agent === "codex" ? join2(cwd, ".codex", "config.toml") : join2(cwd, ".claude", "settings.json");
|
|
2680
1062
|
}
|
|
2681
|
-
return
|
|
1063
|
+
return agent === "codex" ? join2(resolveUserHomeDir(), ".codex", "config.toml") : join2(resolveUserHomeDir(), ".claude", "settings.json");
|
|
2682
1064
|
}
|
|
2683
|
-
function
|
|
2684
|
-
|
|
2685
|
-
}
|
|
2686
|
-
function unescapeSystemdValue(value) {
|
|
2687
|
-
return value.replaceAll("%%", "%").replaceAll('\\"', '"').replaceAll("\\\\", "\\");
|
|
2688
|
-
}
|
|
2689
|
-
function systemctl(args) {
|
|
2690
|
-
execFileSync4("systemctl", args, { stdio: "pipe" });
|
|
1065
|
+
function defaultRunner(command, args, options) {
|
|
1066
|
+
execFileSync(command, args, { ...stdioOpts(), ...options?.env ? { env: options.env } : {} });
|
|
2691
1067
|
}
|
|
2692
|
-
function
|
|
1068
|
+
function tryRun(runner, command, args, options) {
|
|
2693
1069
|
try {
|
|
2694
|
-
|
|
1070
|
+
runner(command, args, options);
|
|
2695
1071
|
} catch {
|
|
2696
1072
|
return;
|
|
2697
1073
|
}
|
|
2698
1074
|
}
|
|
2699
|
-
function
|
|
2700
|
-
try {
|
|
2701
|
-
const output = execFileSync4("systemctl", args, {
|
|
2702
|
-
encoding: "utf8",
|
|
2703
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
2704
|
-
});
|
|
2705
|
-
return { ok: true, output };
|
|
2706
|
-
} catch (error) {
|
|
2707
|
-
return {
|
|
2708
|
-
ok: false,
|
|
2709
|
-
output: String(error?.stdout ?? error?.stderr ?? error?.message ?? "")
|
|
2710
|
-
};
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
function assertLinux() {
|
|
2714
|
-
if (process.platform !== "linux") {
|
|
2715
|
-
throw new Error("systemd daemon install is only supported on Linux");
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
|
|
2719
|
-
// src/doctor/hook-activity.ts
|
|
2720
|
-
init_define_RECALL_BUILD_INFO();
|
|
2721
|
-
import Database from "better-sqlite3";
|
|
2722
|
-
function readHookActivity(dbPath, agent, now = Date.now()) {
|
|
2723
|
-
let db;
|
|
2724
|
-
try {
|
|
2725
|
-
db = new Database(dbPath, { readonly: true, fileMustExist: true });
|
|
2726
|
-
const rows = db.prepare(
|
|
2727
|
-
"SELECT event, MAX(created_at) AS latest FROM hook_calls WHERE agent=? AND ok=1 GROUP BY event"
|
|
2728
|
-
).all(agent);
|
|
2729
|
-
const events = Object.fromEntries(rows.map((r) => [r.event, r.latest]));
|
|
2730
|
-
const last = rows.map((r) => r.latest).sort().at(-1) ?? null;
|
|
2731
|
-
return {
|
|
2732
|
-
status: !last ? "never" : now - Date.parse(last) > 7 * 864e5 ? "stale" : "recent",
|
|
2733
|
-
last_success_at: last,
|
|
2734
|
-
events
|
|
2735
|
-
};
|
|
2736
|
-
} catch {
|
|
2737
|
-
return { status: "unavailable", last_success_at: null, events: {} };
|
|
2738
|
-
} finally {
|
|
2739
|
-
db?.close();
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
function missingCodexTrustKeys(config, hooksPath, definition) {
|
|
2743
|
-
const events = definition?.hooks ?? {};
|
|
2744
|
-
const missing = [];
|
|
2745
|
-
for (const [event, groups] of Object.entries(events)) {
|
|
2746
|
-
if (!Array.isArray(groups)) continue;
|
|
2747
|
-
const snake = event.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
2748
|
-
groups.forEach((group, gi) => group.hooks?.forEach((hook, hi) => {
|
|
2749
|
-
if (!hook.command?.includes("recall:managed:codex:")) return;
|
|
2750
|
-
const key = `${hooksPath}:${snake}:${gi}:${hi}`;
|
|
2751
|
-
const header = `[hooks.state.${JSON.stringify(key)}]`;
|
|
2752
|
-
const start = config.indexOf(header);
|
|
2753
|
-
const section = start < 0 ? "" : config.slice(start + header.length).split(/\n\s*\[/, 1)[0];
|
|
2754
|
-
if (!/\btrusted_hash\s*=\s*"sha256:[a-f0-9]+"/.test(section)) missing.push(key);
|
|
2755
|
-
}));
|
|
2756
|
-
}
|
|
2757
|
-
return missing;
|
|
2758
|
-
}
|
|
2759
|
-
|
|
2760
|
-
// src/doctor/report.ts
|
|
2761
|
-
function getDoctorReport() {
|
|
2762
|
-
const dbPath = getDbPath();
|
|
2763
|
-
const launchd = process.platform === "darwin" ? (() => {
|
|
2764
|
-
try {
|
|
2765
|
-
const status = getLaunchAgentStatus();
|
|
2766
|
-
return {
|
|
2767
|
-
installed: status.installed,
|
|
2768
|
-
loaded: status.loaded,
|
|
2769
|
-
state: status.state
|
|
2770
|
-
};
|
|
2771
|
-
} catch {
|
|
2772
|
-
return null;
|
|
2773
|
-
}
|
|
2774
|
-
})() : null;
|
|
2775
|
-
const systemd = process.platform === "linux" ? (() => {
|
|
2776
|
-
try {
|
|
2777
|
-
const status = getSystemdStatus();
|
|
2778
|
-
return {
|
|
2779
|
-
installed: status.installed,
|
|
2780
|
-
loaded: status.loaded,
|
|
2781
|
-
state: status.state
|
|
2782
|
-
};
|
|
2783
|
-
} catch {
|
|
2784
|
-
return null;
|
|
2785
|
-
}
|
|
2786
|
-
})() : null;
|
|
2787
|
-
const agents = inspectAgentInstalls();
|
|
2788
|
-
for (const agent of agents) {
|
|
2789
|
-
if (agent.detected && !agent.hookless) agent.hook_activity = readHookActivity(dbPath, agent.agent);
|
|
2790
|
-
}
|
|
2791
|
-
return {
|
|
2792
|
-
db_path: dbPath,
|
|
2793
|
-
db_user_version: getDbUserVersion(dbPath),
|
|
2794
|
-
db_target_version: RECALL_DB_USER_VERSION,
|
|
2795
|
-
embeddings: getEmbeddingModelInfo(),
|
|
2796
|
-
launchd,
|
|
2797
|
-
systemd,
|
|
2798
|
-
agents,
|
|
2799
|
-
upgrade: computeUpgradeSignal(agents),
|
|
2800
|
-
cleanup: readCleanupHealth(dbPath),
|
|
2801
|
-
dispatcher: readDispatcherHealth(dbPath),
|
|
2802
|
-
app_registrations: inspectAppRegistrations()
|
|
2803
|
-
};
|
|
2804
|
-
}
|
|
2805
|
-
function readDispatcherHealth(dbPath) {
|
|
2806
|
-
if (!existsSync8(dbPath)) return null;
|
|
2807
|
-
let sqlite = null;
|
|
2808
|
-
try {
|
|
2809
|
-
sqlite = new Database2(dbPath, { readonly: true, fileMustExist: true });
|
|
2810
|
-
const tables = sqlite.prepare(
|
|
2811
|
-
"SELECT name FROM sqlite_master WHERE type='table' AND name IN ('memory_maintenance_tasks','llm_usage')"
|
|
2812
|
-
).all();
|
|
2813
|
-
const names = new Set(tables.map((t) => t.name));
|
|
2814
|
-
let providers = [];
|
|
2815
|
-
try {
|
|
2816
|
-
const { hasProviderConfigured } = (init_keychain(), __toCommonJS(keychain_exports));
|
|
2817
|
-
providers = ["anthropic", "azure-openai", "openai"].filter(
|
|
2818
|
-
(p) => hasProviderConfigured(p)
|
|
2819
|
-
);
|
|
2820
|
-
} catch {
|
|
2821
|
-
providers = [];
|
|
2822
|
-
}
|
|
2823
|
-
const pending = {};
|
|
2824
|
-
if (names.has("memory_maintenance_tasks")) {
|
|
2825
|
-
const rows = sqlite.prepare(
|
|
2826
|
-
"SELECT kind, COUNT(*) AS n FROM memory_maintenance_tasks WHERE status='pending' GROUP BY kind"
|
|
2827
|
-
).all();
|
|
2828
|
-
for (const r of rows) pending[r.kind] = r.n;
|
|
2829
|
-
}
|
|
2830
|
-
let lastAt = null;
|
|
2831
|
-
let lastOk = null;
|
|
2832
|
-
if (names.has("llm_usage")) {
|
|
2833
|
-
const row = sqlite.prepare(
|
|
2834
|
-
"SELECT created_at, ok FROM llm_usage ORDER BY created_at DESC LIMIT 1"
|
|
2835
|
-
).get();
|
|
2836
|
-
if (row) {
|
|
2837
|
-
lastAt = row.created_at;
|
|
2838
|
-
lastOk = row.ok ? "ok" : "error";
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
return {
|
|
2842
|
-
providers_configured: providers,
|
|
2843
|
-
pending_tasks: pending,
|
|
2844
|
-
last_dispatch_at: lastAt,
|
|
2845
|
-
last_dispatch_outcome: lastOk
|
|
2846
|
-
};
|
|
2847
|
-
} catch {
|
|
2848
|
-
return null;
|
|
2849
|
-
} finally {
|
|
2850
|
-
sqlite?.close();
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
function readCleanupHealth(dbPath) {
|
|
2854
|
-
if (!existsSync8(dbPath)) return null;
|
|
2855
|
-
let sqlite = null;
|
|
2856
|
-
try {
|
|
2857
|
-
sqlite = new Database2(dbPath, { readonly: true, fileMustExist: true });
|
|
2858
|
-
const tables = sqlite.prepare(
|
|
2859
|
-
"SELECT name FROM sqlite_master WHERE type='table' AND name IN ('maintenance_cleanup_log','memories','memory_injections')"
|
|
2860
|
-
).all();
|
|
2861
|
-
const names = new Set(tables.map((t) => t.name));
|
|
2862
|
-
if (!names.has("maintenance_cleanup_log")) return null;
|
|
2863
|
-
const totals = sqlite.prepare(
|
|
2864
|
-
"SELECT COUNT(DISTINCT run_id) AS runs, MAX(created_at) AS last_at FROM maintenance_cleanup_log"
|
|
2865
|
-
).get();
|
|
2866
|
-
let lastRunId = null;
|
|
2867
|
-
const actions = {};
|
|
2868
|
-
if (totals.last_at) {
|
|
2869
|
-
const lastRow = sqlite.prepare(
|
|
2870
|
-
"SELECT run_id FROM maintenance_cleanup_log WHERE created_at = ? LIMIT 1"
|
|
2871
|
-
).get(totals.last_at);
|
|
2872
|
-
lastRunId = lastRow?.run_id ?? null;
|
|
2873
|
-
if (lastRunId) {
|
|
2874
|
-
const rows = sqlite.prepare(
|
|
2875
|
-
"SELECT action, COUNT(*) as c FROM maintenance_cleanup_log WHERE run_id = ? GROUP BY action"
|
|
2876
|
-
).all(lastRunId);
|
|
2877
|
-
for (const r of rows) actions[r.action] = r.c;
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
let pending = 0;
|
|
2881
|
-
if (names.has("memories")) {
|
|
2882
|
-
const row = sqlite.prepare(
|
|
2883
|
-
"SELECT COUNT(*) AS n FROM memories WHERE status='candidate' AND source='user_correction'"
|
|
2884
|
-
).get();
|
|
2885
|
-
pending = row.n;
|
|
2886
|
-
}
|
|
2887
|
-
let followedRate = null;
|
|
2888
|
-
let resolvedInjections = 0;
|
|
2889
|
-
let totalInjections = 0;
|
|
2890
|
-
if (names.has("memory_injections")) {
|
|
2891
|
-
const since = new Date(Date.now() - 14 * 864e5).toISOString();
|
|
2892
|
-
const rows = sqlite.prepare(
|
|
2893
|
-
"SELECT outcome, COUNT(*) as c FROM memory_injections WHERE injected_at >= ? GROUP BY outcome"
|
|
2894
|
-
).all(since);
|
|
2895
|
-
let followed = 0;
|
|
2896
|
-
for (const r of rows) {
|
|
2897
|
-
totalInjections += r.c;
|
|
2898
|
-
if (!r.outcome) continue;
|
|
2899
|
-
resolvedInjections += r.c;
|
|
2900
|
-
if (r.outcome === "followed") followed += r.c;
|
|
2901
|
-
}
|
|
2902
|
-
followedRate = resolvedInjections > 0 ? followed / resolvedInjections : null;
|
|
2903
|
-
}
|
|
2904
|
-
return {
|
|
2905
|
-
last_run_id: lastRunId,
|
|
2906
|
-
last_run_at: totals.last_at,
|
|
2907
|
-
last_run_actions: actions,
|
|
2908
|
-
total_runs: totals.runs,
|
|
2909
|
-
pending_candidate_corrections: pending,
|
|
2910
|
-
followed_rate_resolved: followedRate,
|
|
2911
|
-
resolved_injections: resolvedInjections,
|
|
2912
|
-
total_injections: totalInjections
|
|
2913
|
-
};
|
|
2914
|
-
} catch {
|
|
2915
|
-
return null;
|
|
2916
|
-
} finally {
|
|
2917
|
-
sqlite?.close();
|
|
2918
|
-
}
|
|
2919
|
-
}
|
|
2920
|
-
function computeUpgradeSignal(agents) {
|
|
2921
|
-
const reasons = [];
|
|
2922
|
-
for (const agent of agents) {
|
|
2923
|
-
if (!agent.detected) continue;
|
|
2924
|
-
if (agent.legacy_notify_bridge) {
|
|
2925
|
-
reasons.push(
|
|
2926
|
-
`${agent.agent}: legacy notify bridge detected \u2014 upgrade to hooks.json for per-turn memory injection`
|
|
2927
|
-
);
|
|
2928
|
-
continue;
|
|
2929
|
-
}
|
|
2930
|
-
if (agent.mcp && !agent.hooks) {
|
|
2931
|
-
reasons.push(
|
|
2932
|
-
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`
|
|
2933
|
-
);
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
return { available: reasons.length > 0, reasons };
|
|
2937
|
-
}
|
|
2938
|
-
function inspectAgentInstalls(homeDir) {
|
|
2939
|
-
const home = homeDir ?? resolveUserHomeDir();
|
|
2940
|
-
return [
|
|
2941
|
-
inspectClaudeCodeInstall(home),
|
|
2942
|
-
inspectCodexInstall(home),
|
|
2943
|
-
// Hookless agents are only listed once detected — most users have none of
|
|
2944
|
-
// them and four permanent "not detected" rows would just be noise.
|
|
2945
|
-
...listAgentNames().filter((agent) => isHooklessAgent(agent)).map((agent) => inspectHooklessInstall(agent, home)).filter((entry) => entry !== null)
|
|
2946
|
-
];
|
|
2947
|
-
}
|
|
2948
|
-
function inspectHooklessInstall(agent, home) {
|
|
2949
|
-
const adapter = resolveAdapter(agent);
|
|
2950
|
-
if (adapter.detect({ homeDir: home }) !== "installed") return null;
|
|
2951
|
-
const configPath2 = adapter.configPath({ homeDir: home });
|
|
2952
|
-
const mcp = adapter.hasMcpRegistration?.({ homeDir: home }) ?? false;
|
|
2953
|
-
const rules = adapter.checkRules?.({ homeDir: home });
|
|
2954
|
-
const notes = [];
|
|
2955
|
-
if (!mcp) {
|
|
2956
|
-
notes.push(`Recall MCP server not registered in ${configPath2} \u2014 run \`recall setup\``);
|
|
2957
|
-
}
|
|
2958
|
-
if (rules && rules.status !== "current") {
|
|
2959
|
-
notes.push(
|
|
2960
|
-
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`
|
|
2961
|
-
);
|
|
2962
|
-
}
|
|
2963
|
-
return {
|
|
2964
|
-
agent,
|
|
2965
|
-
detected: true,
|
|
2966
|
-
mcp,
|
|
2967
|
-
// No hook API exists, so "hooks" tracks the rules block that stands in for it.
|
|
2968
|
-
hooks: rules?.status === "current",
|
|
2969
|
-
hookless: true,
|
|
2970
|
-
config_path: configPath2,
|
|
2971
|
-
rules: rules?.status,
|
|
2972
|
-
rules_path: rules?.config_path,
|
|
2973
|
-
notes
|
|
2974
|
-
};
|
|
2975
|
-
}
|
|
2976
|
-
function inspectClaudeCodeInstall(home) {
|
|
2977
|
-
const configPath2 = join10(home, ".claude", "settings.json");
|
|
2978
|
-
const userConfigPath = join10(home, ".claude.json");
|
|
2979
|
-
const detected = existsSync8(configPath2) || existsSync8(userConfigPath) || hasCommand("claude");
|
|
2980
|
-
const notes = [];
|
|
2981
|
-
let mcp = false;
|
|
2982
|
-
let hooks = false;
|
|
2983
|
-
if (existsSync8(configPath2)) {
|
|
2984
|
-
try {
|
|
2985
|
-
const parsed = JSON.parse(readFileSync5(configPath2, "utf-8"));
|
|
2986
|
-
mcp = Boolean(parsed?.mcpServers?.recall);
|
|
2987
|
-
const hookGroups = parsed?.hooks ?? {};
|
|
2988
|
-
hooks = Object.values(hookGroups).some(
|
|
2989
|
-
(groups) => Array.isArray(groups) && groups.some(
|
|
2990
|
-
(group) => isHookGroupManagedBy(group, "recall:managed:claude-code")
|
|
2991
|
-
)
|
|
2992
|
-
);
|
|
2993
|
-
if (!hooks) notes.push("No Recall-managed hooks found in settings.json");
|
|
2994
|
-
} catch (err) {
|
|
2995
|
-
notes.push(`Could not parse ${configPath2}: ${err.message}`);
|
|
2996
|
-
}
|
|
2997
|
-
} else if (detected) {
|
|
2998
|
-
notes.push("Claude CLI detected but settings.json missing");
|
|
2999
|
-
}
|
|
3000
|
-
if (!mcp && existsSync8(userConfigPath)) {
|
|
3001
|
-
try {
|
|
3002
|
-
const parsed = JSON.parse(readFileSync5(userConfigPath, "utf-8"));
|
|
3003
|
-
mcp = Boolean(parsed?.mcpServers?.recall);
|
|
3004
|
-
} catch (err) {
|
|
3005
|
-
notes.push(`Could not parse ${userConfigPath}: ${err.message}`);
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
if (!mcp) notes.push("MCP server 'recall' not registered in user configuration");
|
|
3009
|
-
const claudeMd = checkClaudeCodeMemoryOverride({
|
|
3010
|
-
configPath: join10(home, ".claude", "CLAUDE.md")
|
|
3011
|
-
});
|
|
3012
|
-
if (claudeMd.status === "stale") {
|
|
3013
|
-
notes.push("CLAUDE.md memory-override block is out of date \u2014 run `recall doctor --fix`");
|
|
3014
|
-
} else if (claudeMd.status === "missing") {
|
|
3015
|
-
notes.push("CLAUDE.md exists but has no Recall memory-override block \u2014 Claude Code's built-in auto-memory may race Recall");
|
|
3016
|
-
} else if (claudeMd.status === "absent_no_file" && detected) {
|
|
3017
|
-
notes.push("No CLAUDE.md at ~/.claude/CLAUDE.md \u2014 run `recall doctor --fix` to install the memory-override block");
|
|
3018
|
-
}
|
|
3019
|
-
return {
|
|
3020
|
-
agent: "claude-code",
|
|
3021
|
-
detected,
|
|
3022
|
-
mcp,
|
|
3023
|
-
hooks,
|
|
3024
|
-
config_path: configPath2,
|
|
3025
|
-
claude_md: claudeMd.status,
|
|
3026
|
-
claude_md_path: claudeMd.config_path,
|
|
3027
|
-
notes
|
|
3028
|
-
};
|
|
3029
|
-
}
|
|
3030
|
-
function inspectCodexHome(codexHome) {
|
|
3031
|
-
const configPath2 = join10(codexHome, "config.toml");
|
|
3032
|
-
const hooksPath = join10(codexHome, "hooks.json");
|
|
3033
|
-
const detected = existsSync8(configPath2) || hasCommand("codex");
|
|
3034
|
-
const notes = [];
|
|
3035
|
-
let mcp = false;
|
|
3036
|
-
let hooks = false;
|
|
3037
|
-
let legacy_notify_bridge = false;
|
|
3038
|
-
if (existsSync8(configPath2)) {
|
|
3039
|
-
const raw = readFileSync5(configPath2, "utf-8");
|
|
3040
|
-
mcp = /\[mcp_servers\.recall\]/.test(raw);
|
|
3041
|
-
const featureFlagSet = /^\s*(?:codex_)?hooks\s*=\s*true\b/m.test(raw);
|
|
3042
|
-
const managedHooksJson = existsSync8(hooksPath) && readFileSync5(hooksPath, "utf-8").includes("recall:managed:codex");
|
|
3043
|
-
hooks = featureFlagSet && managedHooksJson;
|
|
3044
|
-
if (managedHooksJson) {
|
|
3045
|
-
try {
|
|
3046
|
-
const missing = missingCodexTrustKeys(raw, hooksPath, JSON.parse(readFileSync5(hooksPath, "utf-8")));
|
|
3047
|
-
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.`);
|
|
3048
|
-
} catch {
|
|
3049
|
-
notes.push("hooks.json could not be parsed for trust inspection");
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
legacy_notify_bridge = raw.includes("# recall:managed:codex:start") && raw.includes("codex-notify");
|
|
3053
|
-
if (!mcp) notes.push("MCP block [mcp_servers.recall] not in config.toml");
|
|
3054
|
-
if (legacy_notify_bridge) {
|
|
3055
|
-
notes.push(
|
|
3056
|
-
"Legacy notify bridge present \u2014 install the new hooks.json path to enable per-turn memory injection"
|
|
3057
|
-
);
|
|
3058
|
-
}
|
|
3059
|
-
if (!featureFlagSet) notes.push("hooks = true (or legacy codex_hooks = true) missing from [features]");
|
|
3060
|
-
if (!managedHooksJson) notes.push(`No Recall-managed entries in ${hooksPath}`);
|
|
3061
|
-
} else if (detected) {
|
|
3062
|
-
notes.push("Codex CLI detected but config.toml missing");
|
|
3063
|
-
}
|
|
3064
|
-
return { codexHome, configPath: configPath2, hooksPath, detected, mcp, hooks, legacy_notify_bridge, notes };
|
|
3065
|
-
}
|
|
3066
|
-
function inspectCodexInstall(home) {
|
|
3067
|
-
const homes = resolveCodexHomes({ home });
|
|
3068
|
-
const entries = homes.map((codexHome) => inspectCodexHome(codexHome));
|
|
3069
|
-
const primary = entries[0];
|
|
3070
|
-
const detected = entries.some((entry) => entry.detected);
|
|
3071
|
-
const notes = [...primary.notes];
|
|
3072
|
-
for (const entry of entries.slice(1)) {
|
|
3073
|
-
for (const note of entry.notes) {
|
|
3074
|
-
notes.push(`${basename2(entry.codexHome)}: ${note}`);
|
|
3075
|
-
}
|
|
3076
|
-
}
|
|
1075
|
+
function stdioOpts() {
|
|
3077
1076
|
return {
|
|
3078
|
-
|
|
3079
|
-
detected,
|
|
3080
|
-
mcp: entries.every((entry) => entry.mcp),
|
|
3081
|
-
hooks: entries.every((entry) => entry.hooks),
|
|
3082
|
-
legacy_notify_bridge: entries.some((entry) => entry.legacy_notify_bridge),
|
|
3083
|
-
config_path: primary.configPath,
|
|
3084
|
-
hook_path: primary.hooksPath,
|
|
3085
|
-
notes
|
|
1077
|
+
stdio: "ignore"
|
|
3086
1078
|
};
|
|
3087
1079
|
}
|
|
3088
|
-
function
|
|
3089
|
-
|
|
3090
|
-
const hooks = group.hooks;
|
|
3091
|
-
if (!Array.isArray(hooks)) return false;
|
|
3092
|
-
return hooks.some(
|
|
3093
|
-
(hook) => hook && typeof hook === "object" && typeof hook.command === "string" && hook.command.includes(tag)
|
|
3094
|
-
);
|
|
1080
|
+
function ok(message) {
|
|
1081
|
+
return { enabled: true, ok: true, message };
|
|
3095
1082
|
}
|
|
3096
|
-
function
|
|
3097
|
-
|
|
3098
|
-
"# Recall Doctor",
|
|
3099
|
-
"",
|
|
3100
|
-
`DB: ${report.db_path}`,
|
|
3101
|
-
`DB ver: ${report.db_user_version}/${report.db_target_version}`
|
|
3102
|
-
];
|
|
3103
|
-
if (report.embeddings) {
|
|
3104
|
-
lines.push(`Embed: ${report.embeddings.provider}`);
|
|
3105
|
-
lines.push(`Model: ${report.embeddings.model}`);
|
|
3106
|
-
lines.push(`Dims: index=${report.embeddings.index_dimensions} canonical=${report.embeddings.canonical_dimensions}`);
|
|
3107
|
-
lines.push(`Cache: ${report.embeddings.size_label} @ ${report.embeddings.cache_path}`);
|
|
3108
|
-
} else {
|
|
3109
|
-
lines.push("Embed: disabled");
|
|
3110
|
-
}
|
|
3111
|
-
if (report.launchd) {
|
|
3112
|
-
lines.push(`Launchd: ${report.launchd.installed ? "installed" : "missing"} / ${report.launchd.loaded ? "loaded" : "not loaded"}${report.launchd.state ? ` (${report.launchd.state})` : ""}`);
|
|
3113
|
-
}
|
|
3114
|
-
if (report.systemd) {
|
|
3115
|
-
lines.push(`Systemd: ${report.systemd.installed ? "installed" : "missing"} / ${report.systemd.loaded ? "loaded" : "not loaded"}${report.systemd.state ? ` (${report.systemd.state})` : ""}`);
|
|
3116
|
-
}
|
|
3117
|
-
lines.push("", "## Agents");
|
|
3118
|
-
for (const agent of report.agents) {
|
|
3119
|
-
const label = agent.agent.padEnd(14);
|
|
3120
|
-
if (!agent.detected) {
|
|
3121
|
-
lines.push(`${label} not detected`);
|
|
3122
|
-
continue;
|
|
3123
|
-
}
|
|
3124
|
-
const mcp = agent.mcp ? "ok" : "MISSING";
|
|
3125
|
-
const legacy = agent.legacy_notify_bridge ? " (legacy notify bridge)" : "";
|
|
3126
|
-
const claudeMd = agent.claude_md ? ` claude.md:${agent.claude_md === "current" ? "ok" : agent.claude_md.toUpperCase()}` : "";
|
|
3127
|
-
const wiring = agent.hookless ? ` rules:${agent.rules === "current" ? "ok" : (agent.rules ?? "missing").toUpperCase()}` : ` hooks:${agent.hooks ? "configured" : "MISSING"}`;
|
|
3128
|
-
lines.push(`${label} mcp:${mcp}${wiring}${claudeMd}${legacy}`);
|
|
3129
|
-
if (agent.hook_activity) {
|
|
3130
|
-
const activity = agent.hook_activity;
|
|
3131
|
-
lines.push(` invocation:${activity.status} last-success:${activity.last_success_at ?? "none"} (model delivery unverified)`);
|
|
3132
|
-
for (const event of ["session_started", "prompt_submitted", "tool_invoked", "session_ended"]) {
|
|
3133
|
-
lines.push(` ${event}: ${activity.events[event] ?? "never"}`);
|
|
3134
|
-
}
|
|
3135
|
-
}
|
|
3136
|
-
for (const trust of agent.hook_trust ?? []) {
|
|
3137
|
-
lines.push(` ${basename2(trust.home)} trust:${trust.status}${trust.error ? ` (${trust.error})` : ""}`);
|
|
3138
|
-
if (trust.status === "review-required") lines.push(" Review the current Recall commands in Codex /hooks for this profile.");
|
|
3139
|
-
}
|
|
3140
|
-
for (const note of agent.notes) {
|
|
3141
|
-
lines.push(` - ${note}`);
|
|
3142
|
-
}
|
|
3143
|
-
}
|
|
3144
|
-
if (report.cleanup) {
|
|
3145
|
-
lines.push("", "## Cleanup");
|
|
3146
|
-
if (report.cleanup.last_run_at) {
|
|
3147
|
-
const actions = Object.entries(report.cleanup.last_run_actions).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
3148
|
-
lines.push(`Last run: ${report.cleanup.last_run_id?.slice(0, 8)} at ${report.cleanup.last_run_at.slice(0, 19)}`);
|
|
3149
|
-
lines.push(`Actions: ${actions || "(none)"}`);
|
|
3150
|
-
} else {
|
|
3151
|
-
lines.push("Last run: never");
|
|
3152
|
-
}
|
|
3153
|
-
lines.push(`Total runs: ${report.cleanup.total_runs}`);
|
|
3154
|
-
lines.push(`Pending correction candidates: ${report.cleanup.pending_candidate_corrections}`);
|
|
3155
|
-
const total = report.cleanup.total_injections ?? report.cleanup.resolved_injections;
|
|
3156
|
-
const resolved = report.cleanup.resolved_injections;
|
|
3157
|
-
lines.push(`Outcome coverage (last 14d): ${resolved}/${total} resolved; ${total - resolved} unknown. Selection is not proof of model delivery.`);
|
|
3158
|
-
if (report.cleanup.followed_rate_resolved != null) {
|
|
3159
|
-
const pct = (report.cleanup.followed_rate_resolved * 100).toFixed(1);
|
|
3160
|
-
lines.push(`Followed rate (last 14d, of ${report.cleanup.resolved_injections} resolved): ${pct}%`);
|
|
3161
|
-
} else {
|
|
3162
|
-
lines.push(`Followed rate (last 14d): n/a (no resolved injections)`);
|
|
3163
|
-
}
|
|
3164
|
-
}
|
|
3165
|
-
if (report.dispatcher) {
|
|
3166
|
-
lines.push("", "## Dispatcher (LLM refinement)");
|
|
3167
|
-
const provs = report.dispatcher.providers_configured;
|
|
3168
|
-
lines.push(`Providers visible to this CLI: ${provs.length === 0 ? "none; daemon may have separate credentials" : provs.join(", ")}`);
|
|
3169
|
-
const pendingEntries = Object.entries(report.dispatcher.pending_tasks);
|
|
3170
|
-
if (pendingEntries.length === 0) {
|
|
3171
|
-
lines.push("Pending tasks: 0");
|
|
3172
|
-
} else {
|
|
3173
|
-
const total = pendingEntries.reduce((s, [, n]) => s + n, 0);
|
|
3174
|
-
lines.push(`Pending tasks: ${total} (${pendingEntries.map(([k, n]) => `${k}=${n}`).join(", ")})`);
|
|
3175
|
-
}
|
|
3176
|
-
if (report.dispatcher.last_dispatch_at) {
|
|
3177
|
-
lines.push(`Last dispatch: ${report.dispatcher.last_dispatch_at.slice(0, 19)} (${report.dispatcher.last_dispatch_outcome ?? "unknown"})`);
|
|
3178
|
-
} else {
|
|
3179
|
-
lines.push("Last dispatch: never");
|
|
3180
|
-
}
|
|
3181
|
-
if (provs.length === 0 && pendingEntries.length > 0) {
|
|
3182
|
-
lines.push("Tasks are queued. Check the running daemon's dispatch status before changing credentials; this CLI may have a different environment.");
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
if (report.app_registrations?.supported && report.app_registrations.stray_paths.length > 0) {
|
|
3186
|
-
const strays = report.app_registrations.stray_paths;
|
|
3187
|
-
lines.push("", "## Stray app registrations");
|
|
3188
|
-
lines.push(
|
|
3189
|
-
`macOS is offering ${strays.length} Recall.app bundle(s) besides the installed one.`
|
|
3190
|
-
);
|
|
3191
|
-
for (const path of strays.slice(0, 10)) lines.push(`- ${path}`);
|
|
3192
|
-
if (strays.length > 10) lines.push(`- ...and ${strays.length - 10} more`);
|
|
3193
|
-
lines.push("Run `recall doctor --fix` to unregister them (files are left untouched).");
|
|
3194
|
-
}
|
|
3195
|
-
if (report.upgrade.available) {
|
|
3196
|
-
lines.push("", "## Upgrade available");
|
|
3197
|
-
for (const reason of report.upgrade.reasons) {
|
|
3198
|
-
lines.push(`- ${reason}`);
|
|
3199
|
-
}
|
|
3200
|
-
lines.push("Run `recall doctor --fix` or `recall setup --yes` to apply.");
|
|
3201
|
-
}
|
|
3202
|
-
return lines.join("\n");
|
|
1083
|
+
function skipped(message) {
|
|
1084
|
+
return { enabled: false, ok: false, message };
|
|
3203
1085
|
}
|
|
3204
1086
|
|
|
1087
|
+
// src/cli.ts
|
|
1088
|
+
import { createRequire } from "module";
|
|
1089
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1090
|
+
|
|
3205
1091
|
// src/data/purge.ts
|
|
3206
1092
|
init_define_RECALL_BUILD_INFO();
|
|
3207
|
-
import { execFileSync as
|
|
1093
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
3208
1094
|
import {
|
|
3209
|
-
existsSync as
|
|
3210
|
-
readFileSync
|
|
1095
|
+
existsSync as existsSync2,
|
|
1096
|
+
readFileSync,
|
|
3211
1097
|
readdirSync,
|
|
3212
|
-
rmSync as
|
|
1098
|
+
rmSync as rmSync2,
|
|
3213
1099
|
rmdirSync
|
|
3214
1100
|
} from "fs";
|
|
3215
|
-
import { homedir
|
|
3216
|
-
import { dirname as
|
|
1101
|
+
import { homedir } from "os";
|
|
1102
|
+
import { dirname as dirname2, join as join3, parse, resolve as resolve2 } from "path";
|
|
3217
1103
|
init_keychain();
|
|
3218
1104
|
|
|
3219
1105
|
// src/daemon/service.ts
|
|
@@ -3262,12 +1148,12 @@ var PROVIDERS = [
|
|
|
3262
1148
|
"azure-openai"
|
|
3263
1149
|
];
|
|
3264
1150
|
function resolveRecallDataDir(options = {}) {
|
|
3265
|
-
const home =
|
|
3266
|
-
return
|
|
1151
|
+
const home = resolve2(options.homeDir ?? homedir());
|
|
1152
|
+
return resolve2(options.dataDir ?? process.env.RECALL_DATA_DIR ?? join3(home, ".recall"));
|
|
3267
1153
|
}
|
|
3268
1154
|
function purgeLocalData(options = {}) {
|
|
3269
1155
|
const dryRun = options.dryRun ?? false;
|
|
3270
|
-
const home =
|
|
1156
|
+
const home = resolve2(options.homeDir ?? homedir());
|
|
3271
1157
|
const dataDir = resolveRecallDataDir({ dataDir: options.dataDir, homeDir: home });
|
|
3272
1158
|
assertSafeDataDir(dataDir, home);
|
|
3273
1159
|
const repoRoots = options.repoRoots ?? configuredRepoRoots(home);
|
|
@@ -3320,8 +1206,8 @@ function purgeLocalData(options = {}) {
|
|
|
3320
1206
|
continue;
|
|
3321
1207
|
}
|
|
3322
1208
|
try {
|
|
3323
|
-
|
|
3324
|
-
removeDirectoryIfEmpty(
|
|
1209
|
+
rmSync2(contextPath, { force: true });
|
|
1210
|
+
removeDirectoryIfEmpty(dirname2(contextPath));
|
|
3325
1211
|
actions.push({
|
|
3326
1212
|
category: "artifact",
|
|
3327
1213
|
target: contextPath,
|
|
@@ -3335,14 +1221,14 @@ function purgeLocalData(options = {}) {
|
|
|
3335
1221
|
actions.push({
|
|
3336
1222
|
category: "data",
|
|
3337
1223
|
target: dataDir,
|
|
3338
|
-
status:
|
|
1224
|
+
status: existsSync2(dataDir) ? "planned" : "absent",
|
|
3339
1225
|
detail: "database, WAL, backups, logs, caches, models, and sync state"
|
|
3340
1226
|
});
|
|
3341
1227
|
} else {
|
|
3342
1228
|
try {
|
|
3343
1229
|
closeDb();
|
|
3344
|
-
const existed =
|
|
3345
|
-
|
|
1230
|
+
const existed = existsSync2(dataDir);
|
|
1231
|
+
rmSync2(dataDir, { recursive: true, force: true });
|
|
3346
1232
|
actions.push({
|
|
3347
1233
|
category: "data",
|
|
3348
1234
|
target: dataDir,
|
|
@@ -3369,7 +1255,7 @@ function assertSafeDataDir(dataDir, home) {
|
|
|
3369
1255
|
}
|
|
3370
1256
|
function configuredRepoRoots(home) {
|
|
3371
1257
|
const configured = process.env.RECALL_REPO_ROOTS?.split(",").map((value) => value.trim()).filter(Boolean);
|
|
3372
|
-
return configured?.length ? configured.map((value) =>
|
|
1258
|
+
return configured?.length ? configured.map((value) => resolve2(value)) : [join3(home, "Projects")];
|
|
3373
1259
|
}
|
|
3374
1260
|
function findGeneratedContextArtifacts(repoRoots) {
|
|
3375
1261
|
const paths = /* @__PURE__ */ new Set();
|
|
@@ -3382,9 +1268,9 @@ function findGeneratedContextArtifacts(repoRoots) {
|
|
|
3382
1268
|
return [...paths].sort();
|
|
3383
1269
|
}
|
|
3384
1270
|
function isGeneratedContext(path) {
|
|
3385
|
-
if (!
|
|
1271
|
+
if (!existsSync2(path)) return false;
|
|
3386
1272
|
try {
|
|
3387
|
-
return
|
|
1273
|
+
return readFileSync(path, "utf8").startsWith(GENERATED_CONTEXT_MARKER);
|
|
3388
1274
|
} catch {
|
|
3389
1275
|
return false;
|
|
3390
1276
|
}
|
|
@@ -3452,7 +1338,7 @@ function removeIntegrations(repoRoots) {
|
|
|
3452
1338
|
function removeCliMcp(command, args, cwd) {
|
|
3453
1339
|
const target = `${command} Recall MCP${cwd ? ` in ${cwd}` : ""}`;
|
|
3454
1340
|
try {
|
|
3455
|
-
|
|
1341
|
+
execFileSync2(command, ["mcp", "get", "recall"], {
|
|
3456
1342
|
cwd,
|
|
3457
1343
|
stdio: "ignore",
|
|
3458
1344
|
timeout: 1e4
|
|
@@ -3466,7 +1352,7 @@ function removeCliMcp(command, args, cwd) {
|
|
|
3466
1352
|
};
|
|
3467
1353
|
}
|
|
3468
1354
|
try {
|
|
3469
|
-
|
|
1355
|
+
execFileSync2(command, args, {
|
|
3470
1356
|
cwd,
|
|
3471
1357
|
stdio: "ignore",
|
|
3472
1358
|
timeout: 1e4
|
|
@@ -3583,7 +1469,7 @@ program.command("doctor").description("Show local Recall runtime, DB, embedding,
|
|
|
3583
1469
|
const finalReport = opts.fix ? getDoctorReport() : report;
|
|
3584
1470
|
const codexEntry = finalReport.agents.find((agent) => agent.agent === "codex" && agent.detected);
|
|
3585
1471
|
if (codexEntry) {
|
|
3586
|
-
const { inspectCodexTrust } = await import("./codex-trust-
|
|
1472
|
+
const { inspectCodexTrust } = await import("./codex-trust-CFAOIWDP.js");
|
|
3587
1473
|
codexEntry.hook_trust = await inspectCodexTrust();
|
|
3588
1474
|
}
|
|
3589
1475
|
if (opts.json) {
|
|
@@ -3754,20 +1640,20 @@ function safeHookAction(event, action) {
|
|
|
3754
1640
|
} catch (error) {
|
|
3755
1641
|
let logPath = "~/.recall/logs/hook-errors.log";
|
|
3756
1642
|
try {
|
|
3757
|
-
const { appendFileSync, mkdirSync
|
|
3758
|
-
const { homedir:
|
|
3759
|
-
const dir =
|
|
3760
|
-
|
|
3761
|
-
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");
|
|
3762
1648
|
try {
|
|
3763
1649
|
const maxBytes = parseInt(process.env.RECALL_HOOK_LOG_MAX_BYTES ?? String(1024 * 1024), 10);
|
|
3764
1650
|
if (maxBytes > 0 && statSync(logPath).size >= maxBytes) {
|
|
3765
1651
|
const rotated = `${logPath}.1`;
|
|
3766
1652
|
try {
|
|
3767
|
-
|
|
1653
|
+
rmSync3(rotated, { force: true });
|
|
3768
1654
|
} catch {
|
|
3769
1655
|
}
|
|
3770
|
-
|
|
1656
|
+
renameSync(logPath, rotated);
|
|
3771
1657
|
}
|
|
3772
1658
|
} catch {
|
|
3773
1659
|
}
|
|
@@ -3915,7 +1801,7 @@ program.command("ump").description("Serve the Universal Memory Protocol (UMP) ov
|
|
|
3915
1801
|
});
|
|
3916
1802
|
program.command("scan").description("Scan a repository and bootstrap memories").argument("[path]", "Repository path", ".").option("-s, --session <id>", "Session ID").action((path, opts) => {
|
|
3917
1803
|
const db = initDb();
|
|
3918
|
-
const repoPath =
|
|
1804
|
+
const repoPath = resolve3(path);
|
|
3919
1805
|
const ids = scanAndStore(db, repoPath);
|
|
3920
1806
|
const artifact = writeRepoContextArtifact(db, {
|
|
3921
1807
|
repo: inferRepoSlugFromPath(repoPath),
|
|
@@ -4162,7 +2048,7 @@ program.command("export").description("Export memories as markdown instruction f
|
|
|
4162
2048
|
console.error(`Could not resolve local repo path for ${opts.repo}`);
|
|
4163
2049
|
process.exit(1);
|
|
4164
2050
|
}
|
|
4165
|
-
content =
|
|
2051
|
+
content = readFileSync2(artifact.output_path, "utf-8");
|
|
4166
2052
|
if (!opts.output) {
|
|
4167
2053
|
console.log(content);
|
|
4168
2054
|
return;
|
|
@@ -4173,7 +2059,7 @@ program.command("export").description("Export memories as markdown instruction f
|
|
|
4173
2059
|
content = exportMarkdown(db, opts.repo);
|
|
4174
2060
|
}
|
|
4175
2061
|
if (opts.output) {
|
|
4176
|
-
|
|
2062
|
+
writeFileSync(opts.output, content);
|
|
4177
2063
|
console.log(`Exported to ${opts.output}`);
|
|
4178
2064
|
} else {
|
|
4179
2065
|
console.log(content);
|
|
@@ -4181,7 +2067,7 @@ program.command("export").description("Export memories as markdown instruction f
|
|
|
4181
2067
|
});
|
|
4182
2068
|
program.command("publish").description("Write repo-local .recall/context.md for the current repo").argument("[path]", "Repository path", ".").action((path) => {
|
|
4183
2069
|
const db = initDb();
|
|
4184
|
-
const repoPath =
|
|
2070
|
+
const repoPath = resolve3(path);
|
|
4185
2071
|
const artifact = writeRepoContextArtifact(db, {
|
|
4186
2072
|
repo: inferRepoSlugFromPath(repoPath),
|
|
4187
2073
|
repo_path: repoPath
|
|
@@ -4310,7 +2196,7 @@ evalCmd.command("value-retrieval").description("Run retrieval eval cases synthes
|
|
|
4310
2196
|
});
|
|
4311
2197
|
let snapshot = null;
|
|
4312
2198
|
if (opts.snapshot) {
|
|
4313
|
-
const { computeQualityReport, recordQualitySnapshot } = await import("./quality-
|
|
2199
|
+
const { computeQualityReport, recordQualitySnapshot } = await import("./quality-T4GWE3DL.js");
|
|
4314
2200
|
const qualityReport = computeQualityReport(db, { sinceIso: report.since });
|
|
4315
2201
|
snapshot = recordQualitySnapshot(
|
|
4316
2202
|
db,
|
|
@@ -4819,15 +2705,15 @@ uiCmd.command("status").description("Show WebUI status").option("--daemon-port <
|
|
|
4819
2705
|
var graphCmd = program.command("graph").description("Inspect and rebuild the knowledge graph (entities + relations)");
|
|
4820
2706
|
graphCmd.command("stats").description("Show entity/relation counts").action(async () => {
|
|
4821
2707
|
const db = initDb();
|
|
4822
|
-
const { countEntities, countRelations } = await import("./store-
|
|
2708
|
+
const { countEntities, countRelations } = await import("./store-SNJJ37SQ.js");
|
|
4823
2709
|
console.log(`entities: ${countEntities(db)}`);
|
|
4824
2710
|
console.log(`relations: ${countRelations(db)}`);
|
|
4825
2711
|
});
|
|
4826
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) => {
|
|
4827
2713
|
const db = initDb();
|
|
4828
|
-
const { ingestMemoryHeuristic } = await import("./ingest-
|
|
2714
|
+
const { ingestMemoryHeuristic } = await import("./ingest-TTHTPUZM.js");
|
|
4829
2715
|
if (opts.rebuild) {
|
|
4830
|
-
const { clearGraph } = await import("./store-
|
|
2716
|
+
const { clearGraph } = await import("./store-SNJJ37SQ.js");
|
|
4831
2717
|
clearGraph(db);
|
|
4832
2718
|
console.log("Cleared existing graph entities and relations.");
|
|
4833
2719
|
}
|
|
@@ -4849,7 +2735,7 @@ graphCmd.command("backfill").description("Run the heuristic extractor over every
|
|
|
4849
2735
|
});
|
|
4850
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) => {
|
|
4851
2737
|
const db = initDb();
|
|
4852
|
-
const { listEntities } = await import("./store-
|
|
2738
|
+
const { listEntities } = await import("./store-SNJJ37SQ.js");
|
|
4853
2739
|
const rows = listEntities(db, {
|
|
4854
2740
|
repo: opts.repo,
|
|
4855
2741
|
kind: opts.kind,
|
|
@@ -4868,8 +2754,8 @@ graphCmd.command("entities").description("List entities").option("--repo <repo>"
|
|
|
4868
2754
|
});
|
|
4869
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) => {
|
|
4870
2756
|
const db = initDb();
|
|
4871
|
-
const { graphQuery } = await import("./retrieval-
|
|
4872
|
-
const { loadEmbeddingConfigFromEnv: loadEmbeddingConfigFromEnv2 } = await import("./embeddings-
|
|
2757
|
+
const { graphQuery } = await import("./retrieval-AS5MU7KC.js");
|
|
2758
|
+
const { loadEmbeddingConfigFromEnv: loadEmbeddingConfigFromEnv2 } = await import("./embeddings-PIB5MHRQ.js");
|
|
4873
2759
|
const embeddingConfig = loadEmbeddingConfigFromEnv2();
|
|
4874
2760
|
const result = await graphQuery(db, queryTokens.join(" "), embeddingConfig, {
|
|
4875
2761
|
repo: opts.repo,
|
|
@@ -4885,7 +2771,7 @@ graphCmd.command("query <query...>").description("Run graph-aware retrieval for
|
|
|
4885
2771
|
});
|
|
4886
2772
|
var maintenanceCmd = program.command("maintenance").description("Inspect and manage the delegated maintenance task queue");
|
|
4887
2773
|
maintenanceCmd.command("stats").description("Show backlog counts, completion stats, and mean latency").action(async () => {
|
|
4888
|
-
const { getTaskStats } = await import("./tasks-
|
|
2774
|
+
const { getTaskStats } = await import("./tasks-AZSUFKOJ.js");
|
|
4889
2775
|
const db = initDb();
|
|
4890
2776
|
const stats = getTaskStats(db);
|
|
4891
2777
|
console.log(`Total tasks: ${stats.total}`);
|
|
@@ -4911,7 +2797,7 @@ maintenanceCmd.command("stats").description("Show backlog counts, completion sta
|
|
|
4911
2797
|
}
|
|
4912
2798
|
});
|
|
4913
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) => {
|
|
4914
|
-
const { listTasks } = await import("./tasks-
|
|
2800
|
+
const { listTasks } = await import("./tasks-AZSUFKOJ.js");
|
|
4915
2801
|
const db = initDb();
|
|
4916
2802
|
const tasks = listTasks(db, {
|
|
4917
2803
|
status: opts.status,
|
|
@@ -4933,7 +2819,7 @@ maintenanceCmd.command("list").description("List tasks (default: pending)").opti
|
|
|
4933
2819
|
}
|
|
4934
2820
|
});
|
|
4935
2821
|
maintenanceCmd.command("drop").description("Delete a task by id (or id prefix)").argument("<task-id>", "Task id or prefix").action(async (taskIdArg) => {
|
|
4936
|
-
const { deleteTask, listTasks } = await import("./tasks-
|
|
2822
|
+
const { deleteTask, listTasks } = await import("./tasks-AZSUFKOJ.js");
|
|
4937
2823
|
const db = initDb();
|
|
4938
2824
|
const all = listTasks(db, { limit: 1e4 });
|
|
4939
2825
|
const matches = all.filter((t) => t.id === taskIdArg || t.id.startsWith(taskIdArg));
|
|
@@ -4952,7 +2838,7 @@ maintenanceCmd.command("drop").description("Delete a task by id (or id prefix)")
|
|
|
4952
2838
|
});
|
|
4953
2839
|
var credentialsCmd = maintenanceCmd.command("credentials").description("Manage LLM provider API keys in macOS Keychain (env fallback on other platforms)");
|
|
4954
2840
|
credentialsCmd.command("list", { isDefault: true }).description("Show which providers have credentials available").action(async () => {
|
|
4955
|
-
const { listCredentials } = await import("./keychain-
|
|
2841
|
+
const { listCredentials } = await import("./keychain-HLUGYITV.js");
|
|
4956
2842
|
const creds = listCredentials();
|
|
4957
2843
|
if (creds.length === 0) {
|
|
4958
2844
|
console.log("No API keys configured. Set one with:");
|
|
@@ -4966,7 +2852,7 @@ credentialsCmd.command("list", { isDefault: true }).description("Show which prov
|
|
|
4966
2852
|
}
|
|
4967
2853
|
});
|
|
4968
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) => {
|
|
4969
|
-
const { setApiKey, setAzureConfig } = await import("./keychain-
|
|
2855
|
+
const { setApiKey, setAzureConfig } = await import("./keychain-HLUGYITV.js");
|
|
4970
2856
|
const provider = providerArg === "azure" ? "azure-openai" : providerArg;
|
|
4971
2857
|
if (provider === "openai" || provider === "anthropic") {
|
|
4972
2858
|
const key = keyArg ?? await readStdinKey();
|
|
@@ -5028,7 +2914,7 @@ credentialsCmd.command("set").description("Store credentials for an LLM provider
|
|
|
5028
2914
|
process.exit(1);
|
|
5029
2915
|
});
|
|
5030
2916
|
credentialsCmd.command("clear").description("Remove provider credentials from the macOS Keychain").argument("<provider>", "openai|anthropic|azure").action(async (providerArg) => {
|
|
5031
|
-
const { deleteApiKey: deleteApiKey2 } = await import("./keychain-
|
|
2917
|
+
const { deleteApiKey: deleteApiKey2 } = await import("./keychain-HLUGYITV.js");
|
|
5032
2918
|
const provider = providerArg === "azure" ? "azure-openai" : providerArg;
|
|
5033
2919
|
if (provider !== "openai" && provider !== "anthropic" && provider !== "azure-openai") {
|
|
5034
2920
|
console.error(`Provider must be "openai", "anthropic", or "azure", got "${providerArg}".`);
|
|
@@ -5039,8 +2925,8 @@ credentialsCmd.command("clear").description("Remove provider credentials from th
|
|
|
5039
2925
|
else console.log(`No ${provider} credentials found in Keychain.`);
|
|
5040
2926
|
});
|
|
5041
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) => {
|
|
5042
|
-
const { dispatchPendingTasks, formatDispatchReport, buildPrompt } = await import("./dispatcher-
|
|
5043
|
-
const { listTasks } = await import("./tasks-
|
|
2928
|
+
const { dispatchPendingTasks, formatDispatchReport, buildPrompt } = await import("./dispatcher-O4W6KH5D.js");
|
|
2929
|
+
const { listTasks } = await import("./tasks-AZSUFKOJ.js");
|
|
5044
2930
|
const db = initDb();
|
|
5045
2931
|
if (opts.preview) {
|
|
5046
2932
|
const pending = listTasks(db, {
|
|
@@ -5097,12 +2983,12 @@ ${p.prompt.max_output_tokens}
|
|
|
5097
2983
|
console.log(formatDispatchReport(report));
|
|
5098
2984
|
});
|
|
5099
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) => {
|
|
5100
|
-
const { quarantineGeneratedMemories } = await import("./provenance-
|
|
2986
|
+
const { quarantineGeneratedMemories } = await import("./provenance-QJ5QO7E7.js");
|
|
5101
2987
|
const ids = quarantineGeneratedMemories(initDb(), Boolean(opts.apply));
|
|
5102
2988
|
console.log(JSON.stringify({ applied: Boolean(opts.apply), count: ids.length, memory_ids: ids }, null, 2));
|
|
5103
2989
|
});
|
|
5104
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) => {
|
|
5105
|
-
const { runDeterministicCleanup, formatCleanupReport, revertCleanupRun, listCleanupRuns } = await import("./cleanup-
|
|
2991
|
+
const { runDeterministicCleanup, formatCleanupReport, revertCleanupRun, listCleanupRuns } = await import("./cleanup-MY4E24ZK.js");
|
|
5106
2992
|
const db = initDb();
|
|
5107
2993
|
if (opts.list) {
|
|
5108
2994
|
const runs = listCleanupRuns(db);
|
|
@@ -5156,7 +3042,7 @@ maintenanceCmd.command("quality").description("Show injection outcome distributi
|
|
|
5156
3042
|
recordQualitySnapshot,
|
|
5157
3043
|
listQualitySnapshots,
|
|
5158
3044
|
diffQualitySnapshots
|
|
5159
|
-
} = await import("./quality-
|
|
3045
|
+
} = await import("./quality-T4GWE3DL.js");
|
|
5160
3046
|
const db = initDb();
|
|
5161
3047
|
if (opts.history) {
|
|
5162
3048
|
const snaps = listQualitySnapshots(db);
|
|
@@ -5217,7 +3103,7 @@ maintenanceCmd.command("value-backfill").description("Backfill memory value even
|
|
|
5217
3103
|
const {
|
|
5218
3104
|
backfillMemoryValueEvents,
|
|
5219
3105
|
formatMemoryValueBackfillReport
|
|
5220
|
-
} = await import("./memory-value-
|
|
3106
|
+
} = await import("./memory-value-N32HTBZF.js");
|
|
5221
3107
|
const db = initDb();
|
|
5222
3108
|
const report = backfillMemoryValueEvents(db, {
|
|
5223
3109
|
sinceIso: opts.since,
|
|
@@ -5230,7 +3116,7 @@ maintenanceCmd.command("value-backfill").description("Backfill memory value even
|
|
|
5230
3116
|
console.log(formatMemoryValueBackfillReport(report));
|
|
5231
3117
|
});
|
|
5232
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) => {
|
|
5233
|
-
const { summarizeUsage, formatUsageReport } = await import("./usage-
|
|
3119
|
+
const { summarizeUsage, formatUsageReport } = await import("./usage-DKO3ULNT.js");
|
|
5234
3120
|
const db = initDb();
|
|
5235
3121
|
const summary = summarizeUsage(db, {
|
|
5236
3122
|
sinceIso: opts.since,
|
|
@@ -5359,7 +3245,7 @@ function findByPrefix(db, prefix) {
|
|
|
5359
3245
|
function isDirectCliInvocation(moduleUrl, argvPath) {
|
|
5360
3246
|
if (!argvPath) return false;
|
|
5361
3247
|
try {
|
|
5362
|
-
return
|
|
3248
|
+
return realpathSync(fileURLToPath2(moduleUrl)) === realpathSync(argvPath);
|
|
5363
3249
|
} catch {
|
|
5364
3250
|
return false;
|
|
5365
3251
|
}
|