@bli-cockpit/cli 0.2.49 → 0.2.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/raw-evidence-claude-reader.js +108 -0
- package/dist/adapters/raw-evidence-codex-reader.js +147 -0
- package/dist/adapters/raw-evidence-collection-state.js +199 -0
- package/dist/adapters/raw-evidence-facts.js +338 -0
- package/dist/adapters/raw-evidence-git-diff-reader.js +187 -0
- package/dist/adapters/raw-evidence-image-reader.js +107 -0
- package/dist/adapters/raw-evidence-sanitize.js +56 -0
- package/dist/adapters/raw-evidence-transcript-file.js +182 -0
- package/dist/adapters/raw-evidence.js +63 -1183
- package/dist/commands/backfill-batches.js +34 -0
- package/dist/commands/backfill-candidates.js +54 -0
- package/dist/commands/backfill-checkpoint.js +101 -0
- package/dist/commands/backfill-command-line.js +70 -0
- package/dist/commands/backfill-evidence-outcomes.js +104 -0
- package/dist/commands/backfill-issues.js +265 -0
- package/dist/commands/backfill-output.js +75 -0
- package/dist/commands/backfill-plan.js +71 -0
- package/dist/commands/backfill-reasons.js +107 -0
- package/dist/commands/backfill-report.js +298 -0
- package/dist/commands/backfill-result.js +150 -0
- package/dist/commands/backfill-scan.js +274 -0
- package/dist/commands/backfill-scope.js +114 -0
- package/dist/commands/backfill-session-report.js +145 -0
- package/dist/commands/backfill-types.js +1 -0
- package/dist/commands/backfill-upload.js +212 -0
- package/dist/commands/backfill.js +41 -1961
- package/dist/commands/doctor.js +57 -0
- package/dist/commands/jarvis-trace.js +184 -0
- package/dist/commands/jarvis.js +144 -4
- package/dist/commands/local-args-collector.js +26 -0
- package/dist/commands/local-args-tower.js +21 -0
- package/dist/commands/local-args.js +3 -1
- package/dist/commands/local-help.js +19 -2
- package/dist/commands/local.js +3 -0
- package/dist/commands/memory-install-claude.js +294 -0
- package/dist/commands/memory-install-codex.js +205 -0
- package/dist/commands/memory-install-contract.js +286 -0
- package/dist/commands/memory-install-files.js +63 -0
- package/dist/commands/memory-install-skills.js +121 -0
- package/dist/commands/memory-install-toml.js +265 -0
- package/dist/commands/memory-install.js +465 -0
- package/dist/commands/public-root.js +1 -1
- package/dist/commands/sync-followups.js +105 -0
- package/dist/commands/sync.js +7 -1
- package/dist/local-state-attributed-target.js +75 -0
- package/dist/local-state-config.js +147 -0
- package/dist/local-state-files.js +59 -0
- package/dist/local-state-identity.js +73 -0
- package/dist/local-state-pairing.js +263 -0
- package/dist/local-state-paths.js +61 -0
- package/dist/local-state-session.js +68 -0
- package/dist/local-state-status.js +163 -0
- package/dist/local-state-work-context.js +190 -0
- package/dist/local-state.js +34 -848
- package/dist/tower-client.js +3 -2
- package/dist/tower-stream.js +57 -3
- package/package.json +2 -1
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cockpit memory install` / `cockpit memory status` (BLI-3580).
|
|
3
|
+
*
|
|
4
|
+
* BLI Memory replaces hosted Supermemory: our own table, our own doors, and an
|
|
5
|
+
* MCP server (`@bli-cockpit/memory-mcp`, bin `bli-memory-mcp`) that both agent
|
|
6
|
+
* hosts talk to. Nothing about that reaches an intern's machine unless
|
|
7
|
+
* something puts it there — the vendor plugin never had a fleet install path,
|
|
8
|
+
* which is why every machine was configured by hand. This is that path, and it
|
|
9
|
+
* does not ask: `do-everything` runs it, and the sync tick re-runs it at most
|
|
10
|
+
* once a day so a machine converges without anyone typing anything.
|
|
11
|
+
*
|
|
12
|
+
* What it writes, and where, is in the two halves:
|
|
13
|
+
* memory-install-claude.ts ~/.claude.json (user-scope MCP) + ~/.claude/settings.json (hooks, allow-list)
|
|
14
|
+
* memory-install-codex.ts ~/.codex/config.toml (one table) + ~/.codex/skills/bli-memory/
|
|
15
|
+
*
|
|
16
|
+
* What this module owns is the decisions around them:
|
|
17
|
+
*
|
|
18
|
+
* - **Where the server is.** `bli-memory-mcp` ships as a DEPENDENCY of
|
|
19
|
+
* `@bli-cockpit/cli`, so the canonical lookup is the `node_modules/.bin` on
|
|
20
|
+
* the way up from THIS MODULE's own file — realpath-ed first, because a
|
|
21
|
+
* global `cockpit` is a symlink and walking up from the symlink finds
|
|
22
|
+
* nothing; PATH is the fallback. Nobody ever installs a second global
|
|
23
|
+
* package. See `resolveMemoryMcpBin`, which carries the receipt.
|
|
24
|
+
* - **No server, no write.** If the bin does not resolve, not one file is
|
|
25
|
+
* opened and the outcome is `skipped bin_missing` — see `no_bin_no_write`
|
|
26
|
+
* below for why a written-but-inert registration is the worse option.
|
|
27
|
+
* - **Which config shape.** `bli-memory-mcp --print-config --claude` wins when
|
|
28
|
+
* the bin answers it; the built-in template of the same shape is the
|
|
29
|
+
* fallback for an older server, and it is only ever used with a bin that
|
|
30
|
+
* actually resolved.
|
|
31
|
+
* - **Never throw at the caller.** The sync tick calls this. A failure is a
|
|
32
|
+
* named receipt, never an exception that could cost a machine its
|
|
33
|
+
* collection tick.
|
|
34
|
+
* - **Never claim an install it did not read back** (BLI-2541). Both halves
|
|
35
|
+
* re-read and re-parse; this module only aggregates what they proved.
|
|
36
|
+
*/
|
|
37
|
+
import fs from "node:fs";
|
|
38
|
+
import os from "node:os";
|
|
39
|
+
import path from "node:path";
|
|
40
|
+
import { fileURLToPath } from "node:url";
|
|
41
|
+
import { writeLine } from "./cli-io.js";
|
|
42
|
+
import { builtinMemoryInstallConfig, isUnsafeBinPath, MEMORY_MCP_BIN, parsePrintedMemoryInstallConfig, withResolvedBinPath, } from "./memory-install-contract.js";
|
|
43
|
+
import { defaultMemoryFileIo, } from "./memory-install-files.js";
|
|
44
|
+
import { installClaudeMemoryIntegration, inspectClaudeMemoryIntegration, } from "./memory-install-claude.js";
|
|
45
|
+
import { installCodexMemoryIntegration, inspectCodexMemoryIntegration, } from "./memory-install-codex.js";
|
|
46
|
+
import { DEFAULT_DASHBOARD_URL, getCollectorRuntimePaths, readLocalCollectorConfig, } from "../local-state.js";
|
|
47
|
+
import { envWithNodeRuntimeOnPath } from "../scheduled-self-update.js";
|
|
48
|
+
export async function runMemoryInstall(command, io, deps = {}) {
|
|
49
|
+
const outcome = command.action === "status"
|
|
50
|
+
? await inspectMemoryIntegration(command, io, deps)
|
|
51
|
+
: await installMemoryIntegration(command, io, deps);
|
|
52
|
+
if (command.json) {
|
|
53
|
+
writeLine(io.stdout, JSON.stringify(outcome, null, 2));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
for (const line of memoryOutcomeLines(outcome))
|
|
57
|
+
writeLine(io.stdout, line);
|
|
58
|
+
}
|
|
59
|
+
return outcome.status === "failed" ? 1 : 0;
|
|
60
|
+
}
|
|
61
|
+
export async function installMemoryIntegration(command, io, deps = {}) {
|
|
62
|
+
const homeDir = deps.homeDir ?? command.homeDir ?? os.homedir();
|
|
63
|
+
const platform = deps.platform ?? process.platform;
|
|
64
|
+
const fileIo = deps.io ?? defaultMemoryFileIo();
|
|
65
|
+
const resolved = await resolveMemoryConfig(command, io, platform, deps);
|
|
66
|
+
const targets = [resolved.binTarget];
|
|
67
|
+
// `no_bin_no_write`: with no resolved server there is nothing safe to
|
|
68
|
+
// register, so not one file is opened. The bin target carries the reason.
|
|
69
|
+
if (resolved.config) {
|
|
70
|
+
targets.push(...(await installClaudeMemoryIntegration({
|
|
71
|
+
homeDir,
|
|
72
|
+
config: resolved.config,
|
|
73
|
+
dryRun: command.dryRun,
|
|
74
|
+
io: fileIo,
|
|
75
|
+
})));
|
|
76
|
+
targets.push(...(await installCodexMemoryIntegration({
|
|
77
|
+
homeDir,
|
|
78
|
+
config: resolved.config,
|
|
79
|
+
dryRun: command.dryRun,
|
|
80
|
+
io: fileIo,
|
|
81
|
+
})));
|
|
82
|
+
}
|
|
83
|
+
const outcome = {
|
|
84
|
+
action: "install",
|
|
85
|
+
...aggregate(targets),
|
|
86
|
+
config_source: resolved.source,
|
|
87
|
+
bin_found: resolved.config !== null,
|
|
88
|
+
...(resolved.bin_source ? { bin_source: resolved.bin_source } : {}),
|
|
89
|
+
targets,
|
|
90
|
+
};
|
|
91
|
+
logMemoryOutcome(outcome, platform);
|
|
92
|
+
return outcome;
|
|
93
|
+
}
|
|
94
|
+
export async function inspectMemoryIntegration(command, io, deps = {}) {
|
|
95
|
+
const homeDir = deps.homeDir ?? command.homeDir ?? os.homedir();
|
|
96
|
+
const platform = deps.platform ?? process.platform;
|
|
97
|
+
const fileIo = deps.io ?? defaultMemoryFileIo();
|
|
98
|
+
const resolved = await resolveMemoryConfig(command, io, platform, deps);
|
|
99
|
+
const targets = [resolved.binTarget];
|
|
100
|
+
// Without a resolved server there is no shape to compare the stored config
|
|
101
|
+
// against, so `status` says the one true thing — the server is not here —
|
|
102
|
+
// rather than reporting four targets against a shape we invented.
|
|
103
|
+
if (resolved.config) {
|
|
104
|
+
targets.push(...(await inspectClaudeMemoryIntegration({
|
|
105
|
+
homeDir,
|
|
106
|
+
config: resolved.config,
|
|
107
|
+
io: fileIo,
|
|
108
|
+
})));
|
|
109
|
+
targets.push(...(await inspectCodexMemoryIntegration({
|
|
110
|
+
homeDir,
|
|
111
|
+
config: resolved.config,
|
|
112
|
+
io: fileIo,
|
|
113
|
+
})));
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
action: "status",
|
|
117
|
+
...aggregate(targets),
|
|
118
|
+
config_source: resolved.source,
|
|
119
|
+
bin_found: resolved.config !== null,
|
|
120
|
+
...(resolved.bin_source ? { bin_source: resolved.bin_source } : {}),
|
|
121
|
+
targets,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* **`no_bin_no_write`.** When `bli-memory-mcp` cannot be resolved, this command
|
|
126
|
+
* writes NOTHING — not the MCP entry, not the hooks, not the Codex table, not
|
|
127
|
+
* the skills.
|
|
128
|
+
*
|
|
129
|
+
* An earlier revision wrote the registration anyway, on the reasoning that a
|
|
130
|
+
* correct shape waiting for the package is better than nothing. It is not:
|
|
131
|
+
* Claude Code RUNS a registered hook. Three hooks pointing at a binary that
|
|
132
|
+
* does not exist would print a hook failure on every SessionStart, every
|
|
133
|
+
* prompt and every Stop, on every intern machine, until the package shipped —
|
|
134
|
+
* a self-inflicted outage in the one surface people look at all day.
|
|
135
|
+
*
|
|
136
|
+
* So an absent bin is `skipped bin_missing`: a receipt, not a write. The daily
|
|
137
|
+
* self-heal retries tomorrow, and the first tick after the package lands does
|
|
138
|
+
* the whole registration at once.
|
|
139
|
+
*/
|
|
140
|
+
async function resolveMemoryConfig(command, io, platform, deps) {
|
|
141
|
+
const dashboardUrl = await resolveDashboardUrl(command, deps);
|
|
142
|
+
const found = await resolveMemoryMcpBin({
|
|
143
|
+
env: envWithNodeRuntimeOnPath(io.env ?? process.env),
|
|
144
|
+
platform,
|
|
145
|
+
fileExists: deps.fileExists,
|
|
146
|
+
cliEntryPoint: deps.cliEntryPoint,
|
|
147
|
+
realpath: deps.realpath,
|
|
148
|
+
});
|
|
149
|
+
if (!found) {
|
|
150
|
+
return {
|
|
151
|
+
config: null,
|
|
152
|
+
source: "none",
|
|
153
|
+
binTarget: {
|
|
154
|
+
target: "bin",
|
|
155
|
+
status: "skipped",
|
|
156
|
+
reason: "bin_missing",
|
|
157
|
+
detail: `${MEMORY_MCP_BIN} is not installed beside this CLI or on PATH; nothing was written, and the next daily run will try again`,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (isUnsafeBinPath(found.path)) {
|
|
162
|
+
// A hook command is a shell string by the platform's design. A path that
|
|
163
|
+
// cannot be quoted safely is not escaped cleverly, and it is not swapped
|
|
164
|
+
// for a bare name that may resolve to something else either — the install
|
|
165
|
+
// refuses and says why.
|
|
166
|
+
return {
|
|
167
|
+
config: null,
|
|
168
|
+
source: "none",
|
|
169
|
+
binTarget: {
|
|
170
|
+
target: "bin",
|
|
171
|
+
status: "failed",
|
|
172
|
+
reason: "bin_path_unsafe",
|
|
173
|
+
detail: "the resolved bin path contains characters that cannot appear in a hook command; nothing was written",
|
|
174
|
+
},
|
|
175
|
+
bin_source: found.source,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const printed = await printedMemoryConfig(io, found.path);
|
|
179
|
+
if (printed) {
|
|
180
|
+
// The bin prints a BARE command name — it cannot know where it was
|
|
181
|
+
// installed, and it is nested inside the CLI's node_modules rather than on
|
|
182
|
+
// PATH. Path-qualifying it here is what makes the registration runnable at
|
|
183
|
+
// all; see `withResolvedBinPath`.
|
|
184
|
+
const qualified = withResolvedBinPath(printed, {
|
|
185
|
+
binPath: found.path,
|
|
186
|
+
platform,
|
|
187
|
+
dashboardUrl,
|
|
188
|
+
});
|
|
189
|
+
if (qualified) {
|
|
190
|
+
return {
|
|
191
|
+
config: qualified,
|
|
192
|
+
source: "bin",
|
|
193
|
+
binTarget: { target: "bin", status: "already", reason: "bin_printed_config" },
|
|
194
|
+
bin_source: found.source,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// A printed hook command this installer cannot re-point. The template is
|
|
198
|
+
// always path-qualified, so it is the safe answer — and the reason says
|
|
199
|
+
// which of the two fallbacks happened.
|
|
200
|
+
return {
|
|
201
|
+
config: builtinMemoryInstallConfig({ binPath: found.path, platform, dashboardUrl }),
|
|
202
|
+
source: "template",
|
|
203
|
+
binTarget: {
|
|
204
|
+
target: "bin",
|
|
205
|
+
status: "already",
|
|
206
|
+
reason: "bin_printed_config_unqualifiable",
|
|
207
|
+
detail: "the bin printed a hook command this installer could not re-point at the resolved path; the built-in shape was used",
|
|
208
|
+
},
|
|
209
|
+
bin_source: found.source,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
config: builtinMemoryInstallConfig({
|
|
214
|
+
binPath: found.path,
|
|
215
|
+
platform,
|
|
216
|
+
dashboardUrl,
|
|
217
|
+
}),
|
|
218
|
+
source: "template",
|
|
219
|
+
binTarget: {
|
|
220
|
+
target: "bin",
|
|
221
|
+
status: "already",
|
|
222
|
+
reason: "bin_present_template_used",
|
|
223
|
+
detail: "the bin did not print a usable --print-config; the built-in shape was used",
|
|
224
|
+
},
|
|
225
|
+
bin_source: found.source,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Asks the server for its own shape. Arguments go as an ARRAY — nothing is
|
|
230
|
+
* interpolated into a command line — and on Windows the captured runner routes
|
|
231
|
+
* a `.cmd` shim through ComSpec with its own escaping (process-runner.ts).
|
|
232
|
+
*/
|
|
233
|
+
async function printedMemoryConfig(io, binPath) {
|
|
234
|
+
const exec = io.exec;
|
|
235
|
+
if (!exec)
|
|
236
|
+
return null;
|
|
237
|
+
try {
|
|
238
|
+
const result = await exec(binPath, ["--print-config", "--claude"]);
|
|
239
|
+
if (result.code !== 0)
|
|
240
|
+
return null;
|
|
241
|
+
return parsePrintedMemoryInstallConfig(result.stdout);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
// Deliberately silent here: the caller reports
|
|
245
|
+
// `bin_present_template_used`, which is the same information with a name
|
|
246
|
+
// on it, and this path is reached on every machine that has an older bin.
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Two steps, in this order, and the first is the canonical one.
|
|
252
|
+
*
|
|
253
|
+
* **1. Beside the CLI that is running.** `bli-memory-mcp` ships as a DEPENDENCY
|
|
254
|
+
* of `@bli-cockpit/cli`, so installing the CLI installs the server, and npm
|
|
255
|
+
* links its bin into a `node_modules/.bin` on the path from this package up to
|
|
256
|
+
* the install root — `…/@bli-cockpit/cli/node_modules/.bin` when it is nested,
|
|
257
|
+
* `…/lib/node_modules/.bin` when npm hoists it. It is the ONLY lookup that
|
|
258
|
+
* cannot find somebody else's `bli-memory-mcp`. Nobody ever runs `npm i -g` for
|
|
259
|
+
* a second package.
|
|
260
|
+
*
|
|
261
|
+
* **2. PATH, as a fallback**, for a linked checkout or a hand-installed server.
|
|
262
|
+
* Done in this process rather than through `which`/`where`: it spawns nothing,
|
|
263
|
+
* behaves the same on both host families, and is testable without a fixture
|
|
264
|
+
* binary. The npm global bin sits beside the running node binary in the
|
|
265
|
+
* standard layouts, which is why the caller passes a PATH that already includes
|
|
266
|
+
* it (`envWithNodeRuntimeOnPath`) — the launchd tick's PATH is otherwise
|
|
267
|
+
* `/usr/bin:/bin:/usr/sbin:/sbin` and would find nothing.
|
|
268
|
+
*
|
|
269
|
+
* **What step 1 got wrong on the first real machine** (BLI-3580, CLI 0.2.50):
|
|
270
|
+
* it walked up from `process.argv[1]`, resolved with `path.resolve` and no
|
|
271
|
+
* symlink following. For a global install `argv[1]` is the SHIM — on Edward's
|
|
272
|
+
* Mac `/opt/homebrew/bin/cockpit`, a symlink into
|
|
273
|
+
* `/opt/homebrew/lib/node_modules/@bli-cockpit/cli/dist/cli.js`. The walk
|
|
274
|
+
* therefore started in `/opt/homebrew/bin`, went up through `/opt` to `/`, and
|
|
275
|
+
* never came within reach of the nested `.bin` that was sitting right there.
|
|
276
|
+
* Every machine reported `skipped bin_missing` with the server installed.
|
|
277
|
+
*
|
|
278
|
+
* Two changes, both in `besideAnchors` / `resolveBesideCli`:
|
|
279
|
+
*
|
|
280
|
+
* - The anchor is **this module's own file** first (`import.meta.url`), which
|
|
281
|
+
* is inside the installed package by construction and is never a shim. The
|
|
282
|
+
* entry point (injected, or `argv[1]`) stays as a second anchor for a build
|
|
283
|
+
* layout where this module has been bundled somewhere else.
|
|
284
|
+
* - Every anchor is **realpath-ed** before the walk, so a symlinked entry
|
|
285
|
+
* lands in the real tree. A path that will not resolve is used as given —
|
|
286
|
+
* the same bounded silence `container-tag.ts` uses, because a path that
|
|
287
|
+
* cannot be realpath-ed still identifies a directory well enough to look in.
|
|
288
|
+
*/
|
|
289
|
+
export async function resolveMemoryMcpBin(options) {
|
|
290
|
+
const exists = options.fileExists ?? defaultFileExists;
|
|
291
|
+
const beside = await resolveBesideCli(options, exists);
|
|
292
|
+
if (beside)
|
|
293
|
+
return { path: beside, source: "cli_dependency" };
|
|
294
|
+
const onPath = await resolveOnPath(options, exists);
|
|
295
|
+
return onPath ? { path: onPath, source: "path" } : null;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Where to start walking, in order of trustworthiness. This module's own
|
|
299
|
+
* location first: it is inside the installed package and cannot be a shim.
|
|
300
|
+
*/
|
|
301
|
+
function besideAnchors(options) {
|
|
302
|
+
const anchors = [];
|
|
303
|
+
const own = currentModulePath();
|
|
304
|
+
if (own)
|
|
305
|
+
anchors.push(own);
|
|
306
|
+
const entry = options.cliEntryPoint ?? process.argv[1];
|
|
307
|
+
if (entry)
|
|
308
|
+
anchors.push(entry);
|
|
309
|
+
return anchors;
|
|
310
|
+
}
|
|
311
|
+
function currentModulePath() {
|
|
312
|
+
try {
|
|
313
|
+
return fileURLToPath(import.meta.url);
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
// A bundler that dropped `import.meta` support. The entry-point anchor
|
|
317
|
+
// still covers it, so this is a narrowing rather than a failure.
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async function resolveBesideCli(options, exists) {
|
|
322
|
+
const platformPath = options.platform === "win32" ? path.win32 : path.posix;
|
|
323
|
+
const extensions = binExtensions(options.platform);
|
|
324
|
+
const realpath = options.realpath ?? defaultRealpath;
|
|
325
|
+
for (const anchor of besideAnchors(options)) {
|
|
326
|
+
let directory = platformPath.dirname(realpath(platformPath.resolve(anchor)));
|
|
327
|
+
// Bounded walk: deep enough for `…/node_modules/@scope/pkg/dist/cli.js`
|
|
328
|
+
// plus a hoisted root above it, and it stops at the filesystem root anyway.
|
|
329
|
+
for (let depth = 0; depth < 12; depth += 1) {
|
|
330
|
+
for (const extension of extensions) {
|
|
331
|
+
const candidate = platformPath.join(directory, "node_modules", ".bin", `${MEMORY_MCP_BIN}${extension}`);
|
|
332
|
+
if (await exists(candidate))
|
|
333
|
+
return candidate;
|
|
334
|
+
}
|
|
335
|
+
const parent = platformPath.dirname(directory);
|
|
336
|
+
if (parent === directory)
|
|
337
|
+
break;
|
|
338
|
+
directory = parent;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* `realpathSync.native` follows the symlink npm writes for a global bin. A
|
|
345
|
+
* path that does not resolve — a Windows path being reasoned about from a Mac
|
|
346
|
+
* in a test, a directory that has since moved — comes back unchanged rather
|
|
347
|
+
* than throwing, because the walk above can still look inside it.
|
|
348
|
+
*/
|
|
349
|
+
function defaultRealpath(value) {
|
|
350
|
+
try {
|
|
351
|
+
return fs.realpathSync.native(value);
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
return value;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async function resolveOnPath(options, exists) {
|
|
358
|
+
// The TARGET platform's path rules, not the running one's. On a real machine
|
|
359
|
+
// they are the same; asking for them explicitly is what lets the Windows
|
|
360
|
+
// lookup be tested from a Mac, which is the only Windows proof this repo
|
|
361
|
+
// gets before a release (AGENTS.md, supported fleet).
|
|
362
|
+
const platformPath = options.platform === "win32" ? path.win32 : path.posix;
|
|
363
|
+
const entries = (options.env["PATH"] ?? options.env["Path"] ?? "")
|
|
364
|
+
.split(platformPath.delimiter)
|
|
365
|
+
.map((entry) => entry.trim())
|
|
366
|
+
.filter(Boolean);
|
|
367
|
+
for (const entry of entries) {
|
|
368
|
+
for (const extension of binExtensions(options.platform)) {
|
|
369
|
+
const candidate = platformPath.join(entry, `${MEMORY_MCP_BIN}${extension}`);
|
|
370
|
+
if (await exists(candidate))
|
|
371
|
+
return candidate;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
/** npm writes `.cmd` (and `.ps1`) shims on Windows; POSIX gets the bare name. */
|
|
377
|
+
function binExtensions(platform) {
|
|
378
|
+
return platform === "win32" ? [".cmd", ".exe", ".bat", ""] : [""];
|
|
379
|
+
}
|
|
380
|
+
async function defaultFileExists(file) {
|
|
381
|
+
const { stat } = await import("node:fs/promises");
|
|
382
|
+
try {
|
|
383
|
+
return (await stat(file)).isFile();
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async function resolveDashboardUrl(command, deps) {
|
|
390
|
+
if (command.dashboardUrl)
|
|
391
|
+
return command.dashboardUrl;
|
|
392
|
+
const paths = getCollectorRuntimePaths(deps.homeDir ?? command.homeDir);
|
|
393
|
+
const config = await readLocalCollectorConfig(paths).catch(() => null);
|
|
394
|
+
return config?.dashboard_url ?? DEFAULT_DASHBOARD_URL;
|
|
395
|
+
}
|
|
396
|
+
function aggregate(targets) {
|
|
397
|
+
const failed = targets.filter((target) => target.status === "failed");
|
|
398
|
+
if (failed.length > 0) {
|
|
399
|
+
return {
|
|
400
|
+
status: "failed",
|
|
401
|
+
// The first named reason, not a count: an operator needs the reason, and
|
|
402
|
+
// the per-target list beside it carries the rest.
|
|
403
|
+
reason: failed[0]?.reason ?? "unknown_failure",
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
if (targets.some((target) => target.status === "would_install")) {
|
|
407
|
+
return { status: "would_install", reason: "dry_run" };
|
|
408
|
+
}
|
|
409
|
+
if (targets.some((target) => target.status === "installed")) {
|
|
410
|
+
return { status: "installed", reason: "wrote_entry" };
|
|
411
|
+
}
|
|
412
|
+
if (targets.some((target) => target.status === "mismatch" || target.status === "missing")) {
|
|
413
|
+
return { status: "missing", reason: "entry_absent" };
|
|
414
|
+
}
|
|
415
|
+
const skipped = targets.find((target) => target.status === "skipped");
|
|
416
|
+
if (skipped) {
|
|
417
|
+
// Not a failure and not a success: nothing was written, on purpose, and
|
|
418
|
+
// the next daily run will try again. `bin_missing` is the only one today.
|
|
419
|
+
return { status: "skipped", reason: skipped.reason };
|
|
420
|
+
}
|
|
421
|
+
return { status: "already", reason: "already_current" };
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Both branches log, and neither carries a path — a home directory names a
|
|
425
|
+
* person, and this line ends up in `sync.err.log` on every machine.
|
|
426
|
+
*/
|
|
427
|
+
function logMemoryOutcome(outcome, platform) {
|
|
428
|
+
const fields = {
|
|
429
|
+
status: outcome.status,
|
|
430
|
+
reason: outcome.reason,
|
|
431
|
+
config_source: outcome.config_source,
|
|
432
|
+
bin_found: outcome.bin_found,
|
|
433
|
+
platform,
|
|
434
|
+
installed_count: outcome.targets.filter((target) => target.status === "installed").length,
|
|
435
|
+
already_count: outcome.targets.filter((target) => target.status === "already").length,
|
|
436
|
+
failed: outcome.targets
|
|
437
|
+
.filter((target) => target.status === "failed")
|
|
438
|
+
.map((target) => `${target.target}:${target.reason}`),
|
|
439
|
+
};
|
|
440
|
+
// stderr on both branches: launchd captures it to sync.err.log, and stdout is
|
|
441
|
+
// reserved for `--json`.
|
|
442
|
+
console.error(outcome.status === "failed"
|
|
443
|
+
? "[memory-install] BLI Memory is not fully registered on this machine"
|
|
444
|
+
: "[memory-install] BLI Memory registration converged", JSON.stringify(fields));
|
|
445
|
+
}
|
|
446
|
+
export function memoryOutcomeLines(outcome) {
|
|
447
|
+
const headline = outcome.status === "installed"
|
|
448
|
+
? "BLI Memory registered on this machine."
|
|
449
|
+
: outcome.status === "already"
|
|
450
|
+
? "BLI Memory is already registered on this machine."
|
|
451
|
+
: outcome.status === "would_install"
|
|
452
|
+
? "BLI Memory would be registered (dry run; nothing was written)."
|
|
453
|
+
: outcome.status === "missing"
|
|
454
|
+
? "BLI Memory is not registered on this machine."
|
|
455
|
+
: outcome.status === "skipped"
|
|
456
|
+
? "BLI Memory was not registered and nothing was written: the bli-memory-mcp server is not on this machine yet."
|
|
457
|
+
: `BLI Memory is not fully registered: ${outcome.reason}.`;
|
|
458
|
+
const lines = [headline];
|
|
459
|
+
for (const target of outcome.targets) {
|
|
460
|
+
const where = target.path ? ` ${target.path}` : "";
|
|
461
|
+
const detail = target.detail ? ` — ${target.detail}` : "";
|
|
462
|
+
lines.push(` ${target.target}: ${target.status} (${target.reason})${where}${detail}`);
|
|
463
|
+
}
|
|
464
|
+
return lines;
|
|
465
|
+
}
|
|
@@ -15,7 +15,7 @@ export async function runCockpitCli(argv, io) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (command === "--version" || command === "-V" || command === "version") {
|
|
18
|
-
writeLine(io?.stdout ?? process.stdout, "0.2.
|
|
18
|
+
writeLine(io?.stdout ?? process.stdout, "0.2.51");
|
|
19
19
|
return 0;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the sync tick does AFTER collection's own outcome is decided and
|
|
3
|
+
* reported: keep this machine's CLI current on npm `latest` (BLI-2601), put a
|
|
4
|
+
* broken scheduler registration back (BLI-2721), and keep BLI Memory
|
|
5
|
+
* registered with both agent hosts (BLI-3580).
|
|
6
|
+
*
|
|
7
|
+
* Split out of commands/sync.ts (BLI-3578), moved verbatim. They belong
|
|
8
|
+
* together because they share one rule, and it is the reason both are called
|
|
9
|
+
* last: a follow-up may never block, delay or fail collection. Every error path
|
|
10
|
+
* here is swallowed on purpose and reported as its own named receipt — an
|
|
11
|
+
* `update` step, or an autostart repair step — never as a `sync` failure.
|
|
12
|
+
*/
|
|
13
|
+
import fs from "node:fs/promises";
|
|
14
|
+
import path from "node:path";
|
|
1
15
|
import { resolveAutostartRoots } from "./autostart-command.js";
|
|
16
|
+
import { installMemoryIntegration, } from "./memory-install.js";
|
|
2
17
|
import { redactedSyncErrorDetail, reportInstallEventsBestEffort, } from "./install-receipts.js";
|
|
3
18
|
import { runSelfUpdate, SelfUpdateError } from "./install-update.js";
|
|
4
19
|
import { getCollectorRuntimePaths, LOCAL_COLLECTOR_VERSION, } from "../local-state.js";
|
|
@@ -78,6 +93,96 @@ async function reportAutostartSelfHealOutcome(command, io, dashboardUrl, result)
|
|
|
78
93
|
io,
|
|
79
94
|
});
|
|
80
95
|
}
|
|
96
|
+
export const MEMORY_INSTALL_THROTTLE_MARKER = ".last-memory-install";
|
|
97
|
+
const MEMORY_INSTALL_MIN_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
98
|
+
/**
|
|
99
|
+
* BLI-3580: BLI Memory's registration converges on its own.
|
|
100
|
+
*
|
|
101
|
+
* Nobody is going to be asked to install a hook. `do-everything` registers it
|
|
102
|
+
* on the way through, and this puts it back if a host config is edited,
|
|
103
|
+
* replaced, or restored from a machine that never had it — at most once a day,
|
|
104
|
+
* because the steady state is "already current" and re-proving that every
|
|
105
|
+
* fifteen minutes is four file reads a tick for no new information.
|
|
106
|
+
*
|
|
107
|
+
* Same rule as the two follow-ups above: it runs only once collection's own
|
|
108
|
+
* outcome has been decided and reported, it never throws, and its outcome is
|
|
109
|
+
* its own named receipt rather than a sync failure.
|
|
110
|
+
*/
|
|
111
|
+
export async function runMemoryInstallAfterSync(command, io, dashboardUrl, options = {}) {
|
|
112
|
+
const paths = getCollectorRuntimePaths(command.homeDir);
|
|
113
|
+
const now = options.now ?? new Date();
|
|
114
|
+
const marker = path.join(paths.state_dir, MEMORY_INSTALL_THROTTLE_MARKER);
|
|
115
|
+
const lastAttempt = await fs.stat(marker).catch(() => null);
|
|
116
|
+
if (lastAttempt &&
|
|
117
|
+
now.getTime() - lastAttempt.mtimeMs < MEMORY_INSTALL_MIN_INTERVAL_MS) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// Written for the ATTEMPT, not the outcome — the same idiom the self-update
|
|
121
|
+
// and autostart repair use, so a machine that cannot write a host config does
|
|
122
|
+
// not retry it every fifteen minutes.
|
|
123
|
+
await fs.mkdir(paths.state_dir, { recursive: true }).catch(() => undefined);
|
|
124
|
+
await fs.writeFile(marker, now.toISOString()).catch(() => undefined);
|
|
125
|
+
let event;
|
|
126
|
+
try {
|
|
127
|
+
const outcome = await installMemoryIntegration({
|
|
128
|
+
kind: "memory",
|
|
129
|
+
action: "install",
|
|
130
|
+
homeDir: command.homeDir,
|
|
131
|
+
dashboardUrl,
|
|
132
|
+
dryRun: false,
|
|
133
|
+
json: command.json,
|
|
134
|
+
}, io);
|
|
135
|
+
event = memoryInstallEvent(outcome);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
event = {
|
|
139
|
+
step: "memory_install",
|
|
140
|
+
status: "fail",
|
|
141
|
+
error_code: "memory_install_threw",
|
|
142
|
+
error_detail: redactedSyncErrorDetail(error),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
await reportInstallEventsBestEffort({
|
|
146
|
+
homeDir: command.homeDir,
|
|
147
|
+
dashboardUrl,
|
|
148
|
+
command: "sync",
|
|
149
|
+
events: [event],
|
|
150
|
+
json: command.json,
|
|
151
|
+
io,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Target names and reason labels only. A target's `path` names a person's home
|
|
156
|
+
* directory and a `write_failed` detail can carry one, so neither travels: the
|
|
157
|
+
* receipt says `claude_hooks:read_back_mismatch`, which is the part an operator
|
|
158
|
+
* can act on.
|
|
159
|
+
*/
|
|
160
|
+
function memoryInstallEvent(outcome) {
|
|
161
|
+
const detail = [
|
|
162
|
+
`source=${outcome.config_source}`,
|
|
163
|
+
...outcome.targets.map((target) => `${target.target}:${target.status}/${target.reason}`),
|
|
164
|
+
].join("; ");
|
|
165
|
+
if (outcome.status === "failed") {
|
|
166
|
+
return {
|
|
167
|
+
step: "memory_install",
|
|
168
|
+
status: "fail",
|
|
169
|
+
error_code: outcome.reason,
|
|
170
|
+
error_detail: detail,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (outcome.status === "skipped") {
|
|
174
|
+
// Nothing was written, on purpose (`no_bin_no_write`). A fleet-wide
|
|
175
|
+
// `bin_missing` is the receipt that says the server package has not
|
|
176
|
+
// reached the machines yet — a fact, not a fault.
|
|
177
|
+
return {
|
|
178
|
+
step: "memory_install",
|
|
179
|
+
status: "skipped",
|
|
180
|
+
error_code: outcome.reason,
|
|
181
|
+
error_detail: detail,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return { step: "memory_install", status: "ok", error_detail: detail };
|
|
185
|
+
}
|
|
81
186
|
/**
|
|
82
187
|
* BLI-2601: the fleet keeps itself current on npm `latest` without anyone
|
|
83
188
|
* re-running `npm i -g @bli-cockpit/cli` by hand after day 0. This always
|
package/dist/commands/sync.js
CHANGED
|
@@ -5,7 +5,7 @@ import { discoverCommandWorktrees } from "./local-discovery.js";
|
|
|
5
5
|
import { sendCollectorHeartbeatBestEffort, } from "./heartbeat.js";
|
|
6
6
|
import { classifySyncFailureRecords, classifySyncHealthError, redactedSyncErrorDetail, reportInstallEventsBestEffort, } from "./install-receipts.js";
|
|
7
7
|
import { runAttributedWorktreeSync, } from "./session-sync.js";
|
|
8
|
-
import { runAutostartSelfHealAfterSync, runScheduledSelfUpdateAfterSync, } from "./sync-followups.js";
|
|
8
|
+
import { runAutostartSelfHealAfterSync, runMemoryInstallAfterSync, runScheduledSelfUpdateAfterSync, } from "./sync-followups.js";
|
|
9
9
|
import { describeError } from "../health-detail.js";
|
|
10
10
|
import { inspectBackfillLock } from "../backfill-lock.js";
|
|
11
11
|
import { rotateCollectorLogsBestEffort } from "../log-rotation.js";
|
|
@@ -49,6 +49,9 @@ export async function runSync(command, io) {
|
|
|
49
49
|
// already decided and reported, win or lose. See the function doc.
|
|
50
50
|
await runScheduledSelfUpdateAfterSync(command, io, dashboardUrl, minCliVersion ?? minCliVersionAtStart);
|
|
51
51
|
await runAutostartSelfHealAfterSync(command, io, dashboardUrl);
|
|
52
|
+
// BLI-3580: BLI Memory's registration converges the same way — after
|
|
53
|
+
// collection, at most once a day, its own receipt either way.
|
|
54
|
+
await runMemoryInstallAfterSync(command, io, dashboardUrl);
|
|
52
55
|
return result.exitCode;
|
|
53
56
|
}
|
|
54
57
|
catch (error) {
|
|
@@ -77,6 +80,9 @@ export async function runSync(command, io) {
|
|
|
77
80
|
});
|
|
78
81
|
await runScheduledSelfUpdateAfterSync(command, io, dashboardUrl, minCliVersion ?? minCliVersionAtStart);
|
|
79
82
|
await runAutostartSelfHealAfterSync(command, io, dashboardUrl);
|
|
83
|
+
// BLI-3580: BLI Memory's registration converges the same way — after
|
|
84
|
+
// collection, at most once a day, its own receipt either way.
|
|
85
|
+
await runMemoryInstallAfterSync(command, io, dashboardUrl);
|
|
80
86
|
throw error;
|
|
81
87
|
}
|
|
82
88
|
}
|