nlm-memory 0.4.2 → 0.5.1
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 +72 -34
- package/dist/cli/nlm.js +223 -33
- package/dist/cli/nlm.js.map +1 -1
- package/dist/core/adapters/cursor.d.ts +45 -0
- package/dist/core/adapters/cursor.js +397 -0
- package/dist/core/adapters/cursor.js.map +1 -0
- package/dist/core/adapters/from-source.js +10 -0
- package/dist/core/adapters/from-source.js.map +1 -1
- package/dist/core/adapters/windsurf.d.ts +44 -0
- package/dist/core/adapters/windsurf.js +299 -0
- package/dist/core/adapters/windsurf.js.map +1 -0
- package/dist/core/hook/claude-settings.d.ts +12 -5
- package/dist/core/hook/claude-settings.js +21 -6
- package/dist/core/hook/claude-settings.js.map +1 -1
- package/dist/core/sources/source-registry.d.ts +1 -1
- package/dist/core/sources/source-registry.js +18 -0
- package/dist/core/sources/source-registry.js.map +1 -1
- package/dist/core/storage/sqlite-session-store.d.ts +2 -0
- package/dist/core/storage/sqlite-session-store.js +38 -2
- package/dist/core/storage/sqlite-session-store.js.map +1 -1
- package/dist/hook/hook-auth.d.ts +13 -0
- package/dist/hook/hook-auth.js +19 -0
- package/dist/hook/hook-auth.js.map +1 -0
- package/dist/hook/prompt-recall-hook.js +7 -1
- package/dist/hook/prompt-recall-hook.js.map +1 -1
- package/dist/hook/session-start-hook.js +4 -1
- package/dist/hook/session-start-hook.js.map +1 -1
- package/dist/hook/stop-hook.js +4 -1
- package/dist/hook/stop-hook.js.map +1 -1
- package/dist/http/app.d.ts +2 -0
- package/dist/http/app.js +76 -1
- package/dist/http/app.js.map +1 -1
- package/dist/install/claude-code.js +1 -1
- package/dist/install/claude-code.js.map +1 -1
- package/dist/install/cursor.d.ts +25 -0
- package/dist/install/cursor.js +43 -0
- package/dist/install/cursor.js.map +1 -0
- package/dist/install/nlm-dir-perms.d.ts +19 -0
- package/dist/install/nlm-dir-perms.js +43 -0
- package/dist/install/nlm-dir-perms.js.map +1 -0
- package/dist/install/ollama.d.ts +18 -1
- package/dist/install/ollama.js +62 -7
- package/dist/install/ollama.js.map +1 -1
- package/dist/install/setup.d.ts +4 -0
- package/dist/install/setup.js +141 -18
- package/dist/install/setup.js.map +1 -1
- package/dist/install/windsurf.d.ts +25 -0
- package/dist/install/windsurf.js +43 -0
- package/dist/install/windsurf.js.map +1 -0
- package/dist/mcp/server.js +20 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/shared/types.d.ts +4 -0
- package/dist/ui/assets/{index-BA6IpU8g.css → index-Beo8psd-.css} +1 -1
- package/dist/ui/assets/index-CSPTTeeM.js +69 -0
- package/dist/ui/index.html +2 -2
- package/package.json +26 -1
- package/plugin/scripts/prompt-recall-hook.mjs +55 -4
- package/plugin/scripts/stop-hook.mjs +57 -6
- package/.agents/plugins/marketplace.json +0 -20
- package/.github/workflows/ci.yml +0 -30
- package/dist/ui/assets/index-B_qIVV0k.js +0 -69
- package/docs/methodology/re-derivation-rate.md +0 -112
- package/docs/methodology/useful-hit-rate.md +0 -79
- package/docs/plans/2026-05-20-fts5-lexical-recall.md +0 -1088
- package/docs/plans/2026-05-20-recall-daemon-wedge-fix.md +0 -662
- package/docs/plans/2026-05-20-recall-hook-design.md +0 -131
- package/docs/plans/2026-05-20-recall-hook-implementation.md +0 -1222
- package/docs/plans/desktop-product.md +0 -69
- package/docs/plans/factstore-design.md +0 -236
- package/logs/CHANGELOG/CHANGELOG-2026.md +0 -1389
- package/logs/CHANGELOG/CHANGELOG.md +0 -337
- package/migrations/000_initial_schema.sql +0 -174
- package/migrations/001_entity_type_rename.sql +0 -17
- package/migrations/002_adapter_state_extend.sql +0 -12
- package/migrations/003_session_embeddings.sql +0 -11
- package/migrations/004_facts.sql +0 -46
- package/migrations/005_sources.sql +0 -31
- package/migrations/006_providers.sql +0 -33
- package/migrations/007_source_tokens.sql +0 -17
- package/migrations/008_fts_rebuild.sql +0 -9
- package/migrations/009_session_embedding_chunks.sql +0 -46
- package/migrations/010_sources_opencode.sql +0 -30
- package/migrations/011_sources_hermes_agent.sql +0 -30
- package/migrations/012_sources_aider.sql +0 -30
- package/migrations/013_adapter_state_failure_count.sql +0 -12
- package/plugin-hermes-agent/README.md +0 -49
- package/plugin-hermes-agent/__init__.py +0 -75
- package/plugin-hermes-agent/plugin.yaml +0 -15
- package/scripts/backfill-citations.mjs +0 -0
- package/scripts/build-codex-plugin.mjs +0 -61
- package/scripts/deepseek-probe.mjs +0 -67
- package/scripts/extract-triples.mjs +0 -207
- package/scripts/longmemeval/embedding-cache.ts +0 -77
- package/scripts/longmemeval/fetch-dataset.sh +0 -25
- package/scripts/longmemeval/run-harness.ts +0 -315
- package/scripts/longmemeval/scorer.ts +0 -99
- package/scripts/longmemeval/tsconfig.json +0 -9
- package/scripts/longmemeval/types.ts +0 -35
- package/scripts/nlm-daily-digest.py +0 -239
- package/scripts/nlm-daily-digest.sh +0 -28
- package/src/cli/classify-parity.ts +0 -257
- package/src/cli/launchctl-helpers.ts +0 -49
- package/src/cli/nlm.ts +0 -885
- package/src/core/actions/actions-log.ts +0 -118
- package/src/core/actions/overlay.ts +0 -117
- package/src/core/adapters/aider.ts +0 -205
- package/src/core/adapters/claude-code.ts +0 -293
- package/src/core/adapters/common.ts +0 -54
- package/src/core/adapters/from-source.ts +0 -57
- package/src/core/adapters/hermes-agent.ts +0 -240
- package/src/core/adapters/hermes.ts +0 -277
- package/src/core/adapters/jsonl-generic.ts +0 -208
- package/src/core/adapters/opencode.ts +0 -281
- package/src/core/adapters/pi.ts +0 -264
- package/src/core/classifier/prompt.ts +0 -200
- package/src/core/dataset/build-dataset.ts +0 -463
- package/src/core/embedding/chunk-body.ts +0 -76
- package/src/core/embedding/embed-backfill.ts +0 -210
- package/src/core/embedding/embed-normalize.ts +0 -135
- package/src/core/facts/backfill-facts.ts +0 -254
- package/src/core/facts/extract-facts.ts +0 -50
- package/src/core/hook/citation-detect.ts +0 -124
- package/src/core/hook/cite-memo.ts +0 -68
- package/src/core/hook/claude-settings.ts +0 -166
- package/src/core/hook/gate.ts +0 -25
- package/src/core/hook/hook-log.ts +0 -41
- package/src/core/hook/memo-sweep.ts +0 -164
- package/src/core/hook/memo.ts +0 -67
- package/src/core/hook/pointer-block.ts +0 -26
- package/src/core/hook/select.ts +0 -32
- package/src/core/hook/transcript.ts +0 -121
- package/src/core/ingest/ingest-session.ts +0 -111
- package/src/core/providers/provider-models.ts +0 -100
- package/src/core/providers/provider-registry.ts +0 -196
- package/src/core/recall/citation-log.ts +0 -108
- package/src/core/recall/filter.ts +0 -27
- package/src/core/recall/index.ts +0 -6
- package/src/core/recall/match-fields.ts +0 -40
- package/src/core/recall/query-log.ts +0 -149
- package/src/core/recall/query-shape.ts +0 -66
- package/src/core/recall/recall-service.ts +0 -320
- package/src/core/recall/recent-log.ts +0 -59
- package/src/core/recall/tokenize.ts +0 -18
- package/src/core/recall/useful-scan.ts +0 -336
- package/src/core/recall-facts/fact-query-log.ts +0 -150
- package/src/core/recall-facts/fact-recall-service.ts +0 -327
- package/src/core/scheduler/scan-once.ts +0 -142
- package/src/core/scheduler/scheduler.ts +0 -225
- package/src/core/sources/source-registry.ts +0 -260
- package/src/core/storage/db-restore.ts +0 -133
- package/src/core/storage/live-status.ts +0 -45
- package/src/core/storage/migrate.ts +0 -72
- package/src/core/storage/sqlite-fact-store.ts +0 -304
- package/src/core/storage/sqlite-session-store.ts +0 -765
- package/src/hook/prompt-recall-hook.ts +0 -174
- package/src/hook/session-end-hook.ts +0 -81
- package/src/hook/session-start-hook.ts +0 -165
- package/src/hook/stop-hook.ts +0 -236
- package/src/http/app.ts +0 -1137
- package/src/install/claude-code.ts +0 -128
- package/src/install/codex.ts +0 -367
- package/src/install/hermes-agent.ts +0 -76
- package/src/install/hermes.ts +0 -78
- package/src/install/ollama.ts +0 -211
- package/src/install/setup.ts +0 -368
- package/src/llm/classifier-box.ts +0 -64
- package/src/llm/deepseek-client.ts +0 -150
- package/src/llm/env-autoload.ts +0 -55
- package/src/llm/ollama-client.ts +0 -189
- package/src/mcp/server.ts +0 -534
- package/src/ports/fact-store.ts +0 -102
- package/src/ports/llm-client.ts +0 -52
- package/src/ports/logger.ts +0 -16
- package/src/ports/session-store.ts +0 -45
- package/src/ports/transcript-adapter.ts +0 -55
- package/src/shared/types.ts +0 -145
- package/src/ui/App.tsx +0 -58
- package/src/ui/components/PromoteOpenButton.tsx +0 -65
- package/src/ui/components/SessionDrawer.tsx +0 -136
- package/src/ui/components/SideNav.tsx +0 -162
- package/src/ui/components/Skeleton.tsx +0 -107
- package/src/ui/index.html +0 -13
- package/src/ui/lib/actions.ts +0 -30
- package/src/ui/lib/api.ts +0 -92
- package/src/ui/lib/dataset.ts +0 -141
- package/src/ui/lib/registries.ts +0 -155
- package/src/ui/lib/view-settings.ts +0 -41
- package/src/ui/main.tsx +0 -15
- package/src/ui/pages/Live.tsx +0 -229
- package/src/ui/pages/Pulse.tsx +0 -415
- package/src/ui/pages/Recall.tsx +0 -190
- package/src/ui/pages/River.tsx +0 -308
- package/src/ui/pages/Search.tsx +0 -93
- package/src/ui/pages/Stub.tsx +0 -9
- package/src/ui/pages/Thread.tsx +0 -262
- package/src/ui/pages/settings/Classifier.tsx +0 -227
- package/src/ui/pages/settings/Data.tsx +0 -190
- package/src/ui/pages/settings/Index.tsx +0 -65
- package/src/ui/pages/settings/Labels.tsx +0 -224
- package/src/ui/pages/settings/Providers.tsx +0 -305
- package/src/ui/pages/settings/SettingsSubnav.tsx +0 -28
- package/src/ui/pages/settings/Sources.tsx +0 -326
- package/src/ui/pages/settings/Views.tsx +0 -96
- package/src/ui/styles.css +0 -1766
- package/src/ui/tsconfig.json +0 -21
- package/src/ui/vite.config.ts +0 -19
- package/tests/fixtures/claude_code/short_session.jsonl +0 -2
- package/tests/fixtures/claude_code/standard_iso.jsonl +0 -4
- package/tests/fixtures/claude_code/tool_heavy.jsonl +0 -8
- package/tests/fixtures/claude_code/with_subagent.jsonl +0 -7
- package/tests/fixtures/facts.ts +0 -17
- package/tests/fixtures/golden-corpus.ts +0 -85
- package/tests/fixtures/hermes/paired_request_dump.json +0 -24
- package/tests/fixtures/hermes/paired_session.json +0 -23
- package/tests/fixtures/hermes/request_dump.json +0 -28
- package/tests/fixtures/hermes/session_iso.json +0 -38
- package/tests/fixtures/hermes/session_unix.json +0 -38
- package/tests/fixtures/hermes/system_only.json +0 -18
- package/tests/fixtures/pi/error-connection-abort.jsonl +0 -8
- package/tests/fixtures/pi/short-successful.jsonl +0 -5
- package/tests/fixtures/pi/with-custom-message.jsonl +0 -6
- package/tests/fixtures/sessions.ts +0 -22
- package/tests/integration/backfill-facts.test.ts +0 -362
- package/tests/integration/citation-explicit.test.ts +0 -111
- package/tests/integration/cite-event.test.ts +0 -169
- package/tests/integration/cite-memo.test.ts +0 -87
- package/tests/integration/db-restore.test.ts +0 -153
- package/tests/integration/embed-backfill.test.ts +0 -176
- package/tests/integration/fact-supersedence.test.ts +0 -313
- package/tests/integration/fts-index.test.ts +0 -60
- package/tests/integration/getbyids-sqlite.test.ts +0 -60
- package/tests/integration/hermes-agent-hooks.test.ts +0 -248
- package/tests/integration/hook-claude-settings.test.ts +0 -205
- package/tests/integration/hook-log.test.ts +0 -54
- package/tests/integration/hook-memo.test.ts +0 -68
- package/tests/integration/hook-pre-compact.test.ts +0 -105
- package/tests/integration/hook-subagent-start.test.ts +0 -102
- package/tests/integration/http.test.ts +0 -401
- package/tests/integration/keyword-search-fts.test.ts +0 -66
- package/tests/integration/mcp-recall-logging.test.ts +0 -88
- package/tests/integration/mcp.test.ts +0 -248
- package/tests/integration/memo-sweep.test.ts +0 -91
- package/tests/integration/prompt-recall-hook.test.ts +0 -88
- package/tests/integration/provider-registry.test.ts +0 -107
- package/tests/integration/recall-golden.test.ts +0 -59
- package/tests/integration/recall-sqlite.test.ts +0 -169
- package/tests/integration/scheduler.test.ts +0 -391
- package/tests/integration/session-end-hook.test.ts +0 -48
- package/tests/integration/session-start-hook.test.ts +0 -126
- package/tests/integration/source-registry.test.ts +0 -120
- package/tests/integration/sqlite-fact-store.test.ts +0 -346
- package/tests/integration/stop-hook.test.ts +0 -560
- package/tests/integration/wal-checkpoint.test.ts +0 -49
- package/tests/unit/cli/launchctl-helpers.test.ts +0 -60
- package/tests/unit/core/adapters/aider.test.ts +0 -230
- package/tests/unit/core/adapters/claude-code.test.ts +0 -118
- package/tests/unit/core/adapters/hermes-agent.test.ts +0 -329
- package/tests/unit/core/adapters/hermes.test.ts +0 -81
- package/tests/unit/core/adapters/jsonl-generic.test.ts +0 -142
- package/tests/unit/core/adapters/opencode.test.ts +0 -354
- package/tests/unit/core/adapters/pi.test.ts +0 -110
- package/tests/unit/core/classifier/prompt.test.ts +0 -126
- package/tests/unit/core/embedding/chunk-body.test.ts +0 -100
- package/tests/unit/core/facts/extract-facts.test.ts +0 -117
- package/tests/unit/core/filter.test.ts +0 -40
- package/tests/unit/core/hook/citation-detect-cite-session.test.ts +0 -96
- package/tests/unit/core/hook/citation-detect.test.ts +0 -124
- package/tests/unit/core/hook/gate.test.ts +0 -29
- package/tests/unit/core/hook/pointer-block.test.ts +0 -22
- package/tests/unit/core/hook/select.test.ts +0 -66
- package/tests/unit/core/match-fields.test.ts +0 -39
- package/tests/unit/core/mcp-cite-session.test.ts +0 -51
- package/tests/unit/core/providers/provider-models.test.ts +0 -101
- package/tests/unit/core/query-shape.test.ts +0 -92
- package/tests/unit/core/recall-facts/fact-recall-service.test.ts +0 -258
- package/tests/unit/core/recall-service.test.ts +0 -200
- package/tests/unit/core/storage/live-status.test.ts +0 -54
- package/tests/unit/core/tokenize.test.ts +0 -32
- package/tests/unit/core/useful-scan.test.ts +0 -537
- package/tests/unit/llm/embed.test.ts +0 -93
- package/tests/unit/llm/ollama-client.test.ts +0 -124
- package/tests/unit/scripts/longmemeval-scorer.test.ts +0 -114
- package/tsconfig.json +0 -31
- package/tsconfig.test.json +0 -11
- package/vitest.config.ts +0 -22
package/src/install/ollama.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ollama preflight helpers for `nlm setup`.
|
|
3
|
-
*
|
|
4
|
-
* Three cases handled:
|
|
5
|
-
* 1. Ollama not installed → install it
|
|
6
|
-
* 2. Ollama installed, server not responding → start the server
|
|
7
|
-
* 3. Embedding model missing → pull it
|
|
8
|
-
*
|
|
9
|
-
* Platform support:
|
|
10
|
-
* macOS — brew install / Ollama.app / brew services / open -a
|
|
11
|
-
* Linux — official install.sh / systemctl / detached spawn
|
|
12
|
-
* Windows — winget install / detached spawn
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { homedir, platform } from "node:os";
|
|
17
|
-
import { join } from "node:path";
|
|
18
|
-
import { spawnSync, spawn } from "node:child_process";
|
|
19
|
-
|
|
20
|
-
export const EMBEDDING_MODEL = "nomic-embed-text";
|
|
21
|
-
const OS = platform();
|
|
22
|
-
|
|
23
|
-
export interface OllamaResult {
|
|
24
|
-
readonly ok: boolean;
|
|
25
|
-
readonly output: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// ── Detection ─────────────────────────────────────────────────────────────
|
|
29
|
-
|
|
30
|
-
export function ollamaBinaryAvailable(): boolean {
|
|
31
|
-
const r = spawnSync("ollama", ["--version"], { encoding: "utf8" });
|
|
32
|
-
return r.status === 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Returns true if the Ollama server is accepting API requests. */
|
|
36
|
-
export function ollamaServerRunning(): boolean {
|
|
37
|
-
const r = spawnSync("ollama", ["list"], { encoding: "utf8" });
|
|
38
|
-
return r.status === 0;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Returns true if nomic-embed-text is present in `ollama list`. */
|
|
42
|
-
export function embeddingModelPresent(): boolean {
|
|
43
|
-
const r = spawnSync("ollama", ["list"], { encoding: "utf8" });
|
|
44
|
-
if (r.status !== 0) return false;
|
|
45
|
-
return r.stdout.includes(EMBEDDING_MODEL);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function brewAvailable(): boolean {
|
|
49
|
-
return spawnSync("brew", ["--version"], { encoding: "utf8" }).status === 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function ollamaAppInstalled(): boolean {
|
|
53
|
-
return existsSync("/Applications/Ollama.app");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function wingetAvailable(): boolean {
|
|
57
|
-
return spawnSync("winget", ["--version"], { encoding: "utf8", shell: true }).status === 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function systemctlAvailable(): boolean {
|
|
61
|
-
return spawnSync("systemctl", ["--version"], { encoding: "utf8" }).status === 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ── Install ───────────────────────────────────────────────────────────────
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Install Ollama using the best available method for the current platform.
|
|
68
|
-
* Returns { ok: false } if no automated path exists — caller shows manual instructions.
|
|
69
|
-
*/
|
|
70
|
-
export function installOllama(): OllamaResult {
|
|
71
|
-
if (OS === "darwin") {
|
|
72
|
-
if (brewAvailable()) {
|
|
73
|
-
const r = spawnSync("brew", ["install", "ollama"], { encoding: "utf8" });
|
|
74
|
-
return { ok: r.status === 0, output: (r.stdout + r.stderr).trim() };
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
ok: false,
|
|
78
|
-
output: "Homebrew not found. Download Ollama from https://ollama.com/download and re-run setup.",
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (OS === "linux") {
|
|
83
|
-
// Runs: curl -fsSL https://ollama.com/install.sh | sh
|
|
84
|
-
// The official Ollama installer — sets up the binary and a systemd service.
|
|
85
|
-
// Requires sudo internally and may modify /etc/systemd/. The caller is
|
|
86
|
-
// responsible for confirming this with the user before calling.
|
|
87
|
-
const r = spawnSync("sh", ["-c", "curl -fsSL --proto '=https' https://ollama.com/install.sh | sh"], {
|
|
88
|
-
encoding: "utf8",
|
|
89
|
-
timeout: 120_000,
|
|
90
|
-
});
|
|
91
|
-
return { ok: r.status === 0, output: (r.stdout + r.stderr).trim() };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (OS === "win32") {
|
|
95
|
-
if (wingetAvailable()) {
|
|
96
|
-
const r = spawnSync("winget", ["install", "Ollama.Ollama"], { encoding: "utf8", shell: true });
|
|
97
|
-
return { ok: r.status === 0, output: (r.stdout + r.stderr).trim() };
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
ok: false,
|
|
101
|
-
output: "Download Ollama from https://ollama.com/download and re-run setup.",
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return { ok: false, output: `Unsupported platform: ${OS}. Install from https://ollama.com/download.` };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ── Server start ──────────────────────────────────────────────────────────
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Start the Ollama server in the background.
|
|
112
|
-
*
|
|
113
|
-
* Platform preference:
|
|
114
|
-
* macOS + brew → brew services start ollama
|
|
115
|
-
* macOS + app → open -a Ollama
|
|
116
|
-
* Linux + systemd → systemctl start ollama (needs sudo; falls back to spawn)
|
|
117
|
-
* All others → detached spawn of `ollama serve`
|
|
118
|
-
*/
|
|
119
|
-
export function startOllamaServer(): OllamaResult {
|
|
120
|
-
if (OS === "darwin") {
|
|
121
|
-
if (brewAvailable()) {
|
|
122
|
-
const r = spawnSync("brew", ["services", "start", "ollama"], { encoding: "utf8" });
|
|
123
|
-
if (r.status === 0) return { ok: true, output: "Started via brew services" };
|
|
124
|
-
}
|
|
125
|
-
if (ollamaAppInstalled()) {
|
|
126
|
-
const r = spawnSync("open", ["-a", "Ollama"], { encoding: "utf8" });
|
|
127
|
-
if (r.status === 0) return { ok: true, output: "Started via Ollama.app" };
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (OS === "linux" && systemctlAvailable()) {
|
|
132
|
-
// systemctl requires root — try without sudo first (works in user sessions
|
|
133
|
-
// where the service is installed under the current user), fall through on failure.
|
|
134
|
-
const r = spawnSync("systemctl", ["start", "ollama"], { encoding: "utf8" });
|
|
135
|
-
if (r.status === 0) return { ok: true, output: "Started via systemctl" };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Universal fallback: detach `ollama serve`.
|
|
139
|
-
try {
|
|
140
|
-
mkdirSync(join(homedir(), ".nlm", "logs"), { recursive: true });
|
|
141
|
-
const child = spawn("ollama", ["serve"], {
|
|
142
|
-
detached: true,
|
|
143
|
-
stdio: "ignore",
|
|
144
|
-
});
|
|
145
|
-
child.unref();
|
|
146
|
-
return { ok: true, output: `ollama serve started (pid ${child.pid})` };
|
|
147
|
-
} catch (e) {
|
|
148
|
-
return { ok: false, output: e instanceof Error ? e.message : String(e) };
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Poll until the Ollama server is accepting requests or maxAttempts is reached.
|
|
154
|
-
* Returns true if the server came up, false on timeout.
|
|
155
|
-
*/
|
|
156
|
-
export async function waitForOllamaServer(
|
|
157
|
-
maxAttempts = 15,
|
|
158
|
-
intervalMs = 1000,
|
|
159
|
-
): Promise<boolean> {
|
|
160
|
-
for (let i = 0; i < maxAttempts; i++) {
|
|
161
|
-
if (ollamaServerRunning()) return true;
|
|
162
|
-
await new Promise((res) => setTimeout(res, intervalMs));
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ── Model pull ────────────────────────────────────────────────────────────
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Pull the embedding model. Blocks until complete (~1–3 min on first run, a
|
|
171
|
-
* few seconds on subsequent runs). The caller shows a spinner during this call.
|
|
172
|
-
*/
|
|
173
|
-
export function pullEmbeddingModel(): OllamaResult {
|
|
174
|
-
// Give the server a moment to accept connections if it was just started.
|
|
175
|
-
const r = spawnSync("ollama", ["pull", EMBEDDING_MODEL], { encoding: "utf8" });
|
|
176
|
-
return { ok: r.status === 0, output: (r.stdout + r.stderr).trim() };
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// ── API key / classifier config ───────────────────────────────────────────
|
|
180
|
-
|
|
181
|
-
export type ClassifierChoice = "deepseek" | "ollama-offline";
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Write classifier config to ~/.nlm/.env. Merges into the existing file —
|
|
185
|
-
* only the lines we manage are updated; anything the user added by hand stays.
|
|
186
|
-
*/
|
|
187
|
-
export function writeClassifierConfig(choice: ClassifierChoice, apiKey?: string): void {
|
|
188
|
-
const envPath = join(homedir(), ".nlm", ".env");
|
|
189
|
-
const nlmDir = join(homedir(), ".nlm");
|
|
190
|
-
mkdirSync(nlmDir, { recursive: true, mode: 0o700 });
|
|
191
|
-
chmodSync(nlmDir, 0o700);
|
|
192
|
-
|
|
193
|
-
const existing = existsSync(envPath) ? readFileSync(envPath, "utf8") : "";
|
|
194
|
-
const kept = existing
|
|
195
|
-
.split("\n")
|
|
196
|
-
.filter((l) => !l.startsWith("DEEPSEEK_API_KEY=") && !l.startsWith("NLM_CLASSIFIER="))
|
|
197
|
-
.join("\n")
|
|
198
|
-
.replace(/\n{3,}/g, "\n\n")
|
|
199
|
-
.trim();
|
|
200
|
-
|
|
201
|
-
const additions: string[] = [];
|
|
202
|
-
if (choice === "deepseek" && apiKey) {
|
|
203
|
-
// Strip newlines that clipboard paste can introduce.
|
|
204
|
-
const sanitized = apiKey.replace(/[\r\n]/g, "").trim();
|
|
205
|
-
additions.push(`DEEPSEEK_API_KEY=${sanitized}`);
|
|
206
|
-
}
|
|
207
|
-
if (choice === "ollama-offline") additions.push("NLM_CLASSIFIER=ollama");
|
|
208
|
-
|
|
209
|
-
writeFileSync(envPath, [kept, ...additions].filter(Boolean).join("\n") + "\n", { mode: 0o600 });
|
|
210
|
-
chmodSync(envPath, 0o600);
|
|
211
|
-
}
|
package/src/install/setup.ts
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `nlm setup` — interactive first-run wizard.
|
|
3
|
-
*
|
|
4
|
-
* Step order:
|
|
5
|
-
* 1. Select runtimes
|
|
6
|
-
* 2. Ollama preflight (install → start server → pull embedding model)
|
|
7
|
-
* 3. Classifier API key
|
|
8
|
-
* 4. DB migrations
|
|
9
|
-
* 5. Daemon (LaunchAgent on macOS / systemd hint on Linux / Task Scheduler hint on Windows)
|
|
10
|
-
* 6. Per-runtime MCP + hook wiring
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
14
|
-
import { execFileSync } from "node:child_process";
|
|
15
|
-
import { homedir, platform } from "node:os";
|
|
16
|
-
import { join } from "node:path";
|
|
17
|
-
import {
|
|
18
|
-
cancel, confirm, intro, isCancel, log, multiselect, outro, password, select, spinner,
|
|
19
|
-
} from "@clack/prompts";
|
|
20
|
-
import { connectClaudeCode } from "./claude-code.js";
|
|
21
|
-
import { connectHermes } from "./hermes.js";
|
|
22
|
-
import { codexBinaryAvailable, connectCodex, pluginScriptsDir } from "./codex.js";
|
|
23
|
-
import { defaultDbPath as openCodeDefaultDbPath } from "../core/adapters/opencode.js";
|
|
24
|
-
import type { ClaudeHookEvent } from "../core/hook/claude-settings.js";
|
|
25
|
-
import {
|
|
26
|
-
type ClassifierChoice,
|
|
27
|
-
EMBEDDING_MODEL,
|
|
28
|
-
embeddingModelPresent,
|
|
29
|
-
installOllama,
|
|
30
|
-
ollamaBinaryAvailable,
|
|
31
|
-
ollamaServerRunning,
|
|
32
|
-
pullEmbeddingModel,
|
|
33
|
-
startOllamaServer,
|
|
34
|
-
waitForOllamaServer,
|
|
35
|
-
writeClassifierConfig,
|
|
36
|
-
} from "./ollama.js";
|
|
37
|
-
import { installClaudeCodeHooks } from "./claude-code.js";
|
|
38
|
-
|
|
39
|
-
const OS = platform();
|
|
40
|
-
|
|
41
|
-
export interface SetupOptions {
|
|
42
|
-
readonly nlmBinPath: string;
|
|
43
|
-
readonly nodeExecPath: string;
|
|
44
|
-
readonly migrationsDir: string;
|
|
45
|
-
readonly repoRoot: string;
|
|
46
|
-
readonly dbPath: string;
|
|
47
|
-
readonly launchAgentLabel: string;
|
|
48
|
-
readonly launchAgentPlist: string;
|
|
49
|
-
readonly buildPlist: (nodeExec: string, binPath: string) => string;
|
|
50
|
-
readonly claudeSettingsPath: string;
|
|
51
|
-
readonly allHooks: ReadonlyArray<{
|
|
52
|
-
event: ClaudeHookEvent;
|
|
53
|
-
script: string;
|
|
54
|
-
label: string;
|
|
55
|
-
}>;
|
|
56
|
-
readonly addHook: (path: string, command: string, event?: ClaudeHookEvent) => void;
|
|
57
|
-
readonly removeHook: (path: string, event?: ClaudeHookEvent | "*") => void;
|
|
58
|
-
readonly buildHookCommand: (nodeExec: string, script: string, mode: "shadow" | "live") => string;
|
|
59
|
-
readonly smokeTestHookCommand: (command: string, logPath: string) => { ok: boolean; reason?: string; stderr?: string };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
type RuntimeId = "claude-code" | "codex" | "opencode" | "hermes" | "pi";
|
|
63
|
-
|
|
64
|
-
interface RuntimeOption {
|
|
65
|
-
readonly id: RuntimeId;
|
|
66
|
-
readonly label: string;
|
|
67
|
-
readonly hint: string;
|
|
68
|
-
readonly detected: boolean;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function detectRuntimes(): RuntimeOption[] {
|
|
72
|
-
const claudeProjectsPath = process.env["NLM_CLAUDE_PROJECTS_PATH"]
|
|
73
|
-
?? join(homedir(), ".claude", "projects");
|
|
74
|
-
const hermesPath = process.env["NLM_HERMES_SESSIONS_PATH"]
|
|
75
|
-
?? join(homedir(), ".hermes", "sessions");
|
|
76
|
-
const piPath = process.env["PI_SESSIONS_PATH"]
|
|
77
|
-
?? join(homedir(), ".pi", "agent", "sessions");
|
|
78
|
-
const openCodeDb = openCodeDefaultDbPath();
|
|
79
|
-
|
|
80
|
-
return [
|
|
81
|
-
{
|
|
82
|
-
id: "claude-code",
|
|
83
|
-
label: "Claude Code",
|
|
84
|
-
hint: existsSync(claudeProjectsPath) ? "detected" : "not found",
|
|
85
|
-
detected: existsSync(claudeProjectsPath),
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
id: "codex",
|
|
89
|
-
label: "Codex (OpenAI)",
|
|
90
|
-
hint: codexBinaryAvailable() ? "detected" : "not found — install: npm i -g @openai/codex",
|
|
91
|
-
detected: codexBinaryAvailable(),
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: "opencode",
|
|
95
|
-
label: "OpenCode (sst)",
|
|
96
|
-
hint: existsSync(openCodeDb) ? "detected" : "not found",
|
|
97
|
-
detected: existsSync(openCodeDb),
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
id: "hermes",
|
|
101
|
-
label: "Hermes",
|
|
102
|
-
hint: existsSync(hermesPath) ? "detected" : "not found",
|
|
103
|
-
detected: existsSync(hermesPath),
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
id: "pi",
|
|
107
|
-
label: "pi.dev",
|
|
108
|
-
hint: existsSync(piPath) ? "detected" : "not found",
|
|
109
|
-
detected: existsSync(piPath),
|
|
110
|
-
},
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function runSetup(opts: SetupOptions): Promise<void> {
|
|
115
|
-
intro("NLM Memory — first-run setup");
|
|
116
|
-
|
|
117
|
-
// ── Step 1: runtime selection ─────────────────────────────────────────
|
|
118
|
-
const runtimes = detectRuntimes();
|
|
119
|
-
const detectedIds = runtimes.filter((r) => r.detected).map((r) => r.id);
|
|
120
|
-
|
|
121
|
-
const selected = await multiselect<RuntimeId>({
|
|
122
|
-
message: "Which AI coding runtimes do you use?",
|
|
123
|
-
options: runtimes.map((r) => ({ value: r.id, label: r.label, hint: r.hint })),
|
|
124
|
-
initialValues: detectedIds,
|
|
125
|
-
required: false,
|
|
126
|
-
});
|
|
127
|
-
if (isCancel(selected)) { cancel("Setup cancelled."); process.exit(0); }
|
|
128
|
-
const chosen = selected as RuntimeId[];
|
|
129
|
-
|
|
130
|
-
// ── Step 2: Ollama preflight ──────────────────────────────────────────
|
|
131
|
-
if (!ollamaBinaryAvailable()) {
|
|
132
|
-
const installMsg = OS === "linux"
|
|
133
|
-
? "Ollama not found. Install now? (runs the official install.sh as current user — see https://ollama.com/install.sh)"
|
|
134
|
-
: "Ollama not found. Install it now? (required for memory indexing)";
|
|
135
|
-
const doInstall = await confirm({ message: installMsg });
|
|
136
|
-
if (isCancel(doInstall)) { cancel("Setup cancelled."); process.exit(0); }
|
|
137
|
-
|
|
138
|
-
if (doInstall) {
|
|
139
|
-
const is = spinner();
|
|
140
|
-
is.start("Installing Ollama");
|
|
141
|
-
const result = installOllama();
|
|
142
|
-
if (result.ok) {
|
|
143
|
-
is.stop("Ollama installed");
|
|
144
|
-
} else {
|
|
145
|
-
is.stop("Ollama install failed");
|
|
146
|
-
log.warn(result.output);
|
|
147
|
-
log.warn("Install Ollama manually from https://ollama.com/download, then re-run `nlm setup`.");
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
log.warn("Skipping Ollama install — memory indexing won't work until Ollama is running with nomic-embed-text.");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Ensure server is running before attempting pull.
|
|
155
|
-
if (ollamaBinaryAvailable() && !ollamaServerRunning()) {
|
|
156
|
-
const ss = spinner();
|
|
157
|
-
ss.start("Starting Ollama server");
|
|
158
|
-
const result = startOllamaServer();
|
|
159
|
-
if (result.ok) {
|
|
160
|
-
ss.start("Waiting for Ollama server to accept connections");
|
|
161
|
-
const ready = await waitForOllamaServer(15, 1000);
|
|
162
|
-
if (ready) {
|
|
163
|
-
ss.stop("Ollama server ready");
|
|
164
|
-
} else {
|
|
165
|
-
ss.stop("Ollama server started but not responding yet");
|
|
166
|
-
log.warn("If the model pull fails, wait a moment and run `ollama pull nomic-embed-text` manually.");
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
ss.stop("Could not start Ollama server automatically");
|
|
170
|
-
log.warn(`Start it manually with \`ollama serve\`, then re-run \`nlm setup\`. (${result.output})`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (ollamaBinaryAvailable() && !embeddingModelPresent()) {
|
|
175
|
-
const doPull = await confirm({ message: `Pull the ${EMBEDDING_MODEL} embedding model now? (~274 MB, required for semantic recall)` });
|
|
176
|
-
if (isCancel(doPull)) { cancel("Setup cancelled."); process.exit(0); }
|
|
177
|
-
|
|
178
|
-
if (doPull) {
|
|
179
|
-
const ps = spinner();
|
|
180
|
-
ps.start(`Pulling ${EMBEDDING_MODEL} (this may take a few minutes)`);
|
|
181
|
-
const result = pullEmbeddingModel();
|
|
182
|
-
if (result.ok) {
|
|
183
|
-
ps.stop(`${EMBEDDING_MODEL} ready`);
|
|
184
|
-
} else {
|
|
185
|
-
ps.stop("Model pull failed");
|
|
186
|
-
log.warn(`Run \`ollama pull ${EMBEDDING_MODEL}\` manually to retry.`);
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
log.warn(`Skipping model pull — run \`ollama pull ${EMBEDDING_MODEL}\` before using memory recall.`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (ollamaBinaryAvailable() && embeddingModelPresent()) {
|
|
194
|
-
log.success(`Ollama ready — ${EMBEDDING_MODEL} present`);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// ── Step 3: classifier API key ────────────────────────────────────────
|
|
198
|
-
const wantKey = await confirm({ message: "Add a classifier API key? (enables accurate session tagging; DeepSeek is ~$0.002/session)" });
|
|
199
|
-
if (isCancel(wantKey)) { cancel("Setup cancelled."); process.exit(0); }
|
|
200
|
-
|
|
201
|
-
if (wantKey) {
|
|
202
|
-
const classifierChoice = await select<ClassifierChoice>({
|
|
203
|
-
message: "Which classifier?",
|
|
204
|
-
options: [
|
|
205
|
-
{ value: "deepseek", label: "DeepSeek", hint: "recommended — fast, cheap, needs DEEPSEEK_API_KEY" },
|
|
206
|
-
{ value: "ollama-offline", label: "Ollama (offline)", hint: "free, no API key, slower and less accurate" },
|
|
207
|
-
],
|
|
208
|
-
});
|
|
209
|
-
if (isCancel(classifierChoice)) { cancel("Setup cancelled."); process.exit(0); }
|
|
210
|
-
|
|
211
|
-
if (classifierChoice === "deepseek") {
|
|
212
|
-
const key = await password({ message: "DeepSeek API key (get one at platform.deepseek.com):" });
|
|
213
|
-
if (isCancel(key)) { cancel("Setup cancelled."); process.exit(0); }
|
|
214
|
-
if (key && (key as string).trim()) {
|
|
215
|
-
writeClassifierConfig("deepseek", (key as string).trim());
|
|
216
|
-
log.success("DeepSeek API key saved to ~/.nlm/.env");
|
|
217
|
-
} else {
|
|
218
|
-
log.warn("No key entered — set DEEPSEEK_API_KEY in ~/.nlm/.env later.");
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
writeClassifierConfig("ollama-offline");
|
|
222
|
-
log.success("Classifier set to Ollama offline (saved to ~/.nlm/.env)");
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// ── Step 4: migrations ────────────────────────────────────────────────
|
|
227
|
-
const ms = spinner();
|
|
228
|
-
ms.start("Running database migrations");
|
|
229
|
-
try {
|
|
230
|
-
const { SqliteSessionStore } = await import("../core/storage/sqlite-session-store.js");
|
|
231
|
-
const store = new SqliteSessionStore({ dbPath: opts.dbPath, migrationsDir: opts.migrationsDir });
|
|
232
|
-
store.close();
|
|
233
|
-
ms.stop("Database ready");
|
|
234
|
-
} catch (e) {
|
|
235
|
-
ms.stop("Migration failed");
|
|
236
|
-
log.error(`${e instanceof Error ? e.message : String(e)}`);
|
|
237
|
-
process.exit(1);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// ── Step 5: daemon ────────────────────────────────────────────────────
|
|
241
|
-
if (OS === "darwin") {
|
|
242
|
-
const installDaemon = await confirm({ message: "Install macOS LaunchAgent (auto-start on login)?" });
|
|
243
|
-
if (isCancel(installDaemon)) { cancel("Setup cancelled."); process.exit(0); }
|
|
244
|
-
|
|
245
|
-
if (installDaemon) {
|
|
246
|
-
const ds = spinner();
|
|
247
|
-
ds.start("Installing LaunchAgent");
|
|
248
|
-
try {
|
|
249
|
-
const uid = process.getuid?.();
|
|
250
|
-
if (uid === undefined) throw new Error("Could not determine UID");
|
|
251
|
-
mkdirSync(join(homedir(), ".nlm", "logs"), { recursive: true });
|
|
252
|
-
writeFileSync(opts.launchAgentPlist, opts.buildPlist(opts.nodeExecPath, opts.nlmBinPath), "utf8");
|
|
253
|
-
try {
|
|
254
|
-
execFileSync("launchctl", ["bootout", `gui/${uid}`, opts.launchAgentLabel], { stdio: "ignore" });
|
|
255
|
-
} catch { /* not loaded yet — expected */ }
|
|
256
|
-
execFileSync("launchctl", ["bootstrap", `gui/${uid}`, opts.launchAgentPlist]);
|
|
257
|
-
ds.stop("LaunchAgent installed — daemon running");
|
|
258
|
-
} catch (e) {
|
|
259
|
-
ds.stop("LaunchAgent install failed");
|
|
260
|
-
log.error(`${e instanceof Error ? e.message : String(e)}`);
|
|
261
|
-
log.warn("Run `nlm install` manually later.");
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
} else if (OS === "linux") {
|
|
265
|
-
log.info("Linux daemon: add `nlm start` to your init system to auto-start on boot.");
|
|
266
|
-
log.info(" systemd example: sudo systemctl enable --now nlm (after creating a unit file)");
|
|
267
|
-
log.info(" Quick start now: nlm start &");
|
|
268
|
-
} else if (OS === "win32") {
|
|
269
|
-
log.info("Windows daemon: run `nlm start` at login via Task Scheduler.");
|
|
270
|
-
log.info(" Or start manually: nlm start");
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// ── Step 6: per-runtime configuration ────────────────────────────────
|
|
274
|
-
for (const id of chosen) {
|
|
275
|
-
switch (id) {
|
|
276
|
-
case "claude-code": {
|
|
277
|
-
// MCP config
|
|
278
|
-
const cs = spinner();
|
|
279
|
-
cs.start("Configuring Claude Code — MCP server");
|
|
280
|
-
try {
|
|
281
|
-
const report = connectClaudeCode({ nlmBinPath: opts.nlmBinPath, nodeExecPath: opts.nodeExecPath });
|
|
282
|
-
cs.stop(`MCP server ${report.alreadyPresent ? "updated" : "written"} → ${report.mcpConfigPath}`);
|
|
283
|
-
} catch (e) {
|
|
284
|
-
cs.stop("MCP config write failed");
|
|
285
|
-
log.error(`${e instanceof Error ? e.message : String(e)}`);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Hooks — Claude Code hooks are process hooks (settings.json), not
|
|
289
|
-
// OS-level scripts, so they work on all platforms where Claude Code runs.
|
|
290
|
-
const hs = spinner();
|
|
291
|
-
hs.start("Configuring Claude Code — session hooks");
|
|
292
|
-
const hookLogPath = process.env["NLM_HOOK_LOG"] ?? join(homedir(), ".nlm", "hook-log.jsonl");
|
|
293
|
-
const hookResult = installClaudeCodeHooks({
|
|
294
|
-
nodeExecPath: opts.nodeExecPath,
|
|
295
|
-
hooks: opts.allHooks,
|
|
296
|
-
settingsPath: opts.claudeSettingsPath,
|
|
297
|
-
hookLogPath,
|
|
298
|
-
addHook: opts.addHook,
|
|
299
|
-
removeHook: opts.removeHook,
|
|
300
|
-
buildHookCommand: opts.buildHookCommand,
|
|
301
|
-
smokeTestHookCommand: opts.smokeTestHookCommand,
|
|
302
|
-
});
|
|
303
|
-
if (hookResult.ok) {
|
|
304
|
-
hs.stop(`${hookResult.count} hooks installed → ${opts.claudeSettingsPath}`);
|
|
305
|
-
} else {
|
|
306
|
-
hs.stop(`Hook install failed (${hookResult.failedLabel ?? "unknown"})`);
|
|
307
|
-
if (hookResult.errorMessage) log.error(hookResult.errorMessage);
|
|
308
|
-
log.warn("Run `nlm hook install` manually after checking your Node path.");
|
|
309
|
-
}
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
case "codex": {
|
|
314
|
-
if (!codexBinaryAvailable()) {
|
|
315
|
-
log.warn("Codex binary not found — install with `npm i -g @openai/codex`, then run `nlm connect codex`.");
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
const cs = spinner();
|
|
319
|
-
cs.start("Connecting Codex");
|
|
320
|
-
try {
|
|
321
|
-
const report = connectCodex({ source: "pbmagnet4/nlm-memory-ts" }, pluginScriptsDir(opts.repoRoot));
|
|
322
|
-
if (report.marketplaceAdd?.status !== 0 || report.pluginAdd?.status !== 0) {
|
|
323
|
-
cs.stop("Codex connect had errors — run `nlm connect codex` manually to retry");
|
|
324
|
-
} else {
|
|
325
|
-
cs.stop("Codex marketplace + plugin registered");
|
|
326
|
-
}
|
|
327
|
-
} catch (e) {
|
|
328
|
-
cs.stop("Codex connect failed");
|
|
329
|
-
log.error(`${e instanceof Error ? e.message : String(e)}`);
|
|
330
|
-
}
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
case "opencode":
|
|
335
|
-
log.success("OpenCode: session scanning enabled (passive — no extra config needed)");
|
|
336
|
-
break;
|
|
337
|
-
|
|
338
|
-
case "hermes": {
|
|
339
|
-
const hs = spinner();
|
|
340
|
-
hs.start("Configuring Hermes");
|
|
341
|
-
try {
|
|
342
|
-
const report = connectHermes({ nlmBinPath: opts.nlmBinPath, nodeExecPath: opts.nodeExecPath });
|
|
343
|
-
hs.stop(`MCP server ${report.alreadyPresent ? "updated" : "written"} → ${report.configPath}`);
|
|
344
|
-
} catch (e) {
|
|
345
|
-
hs.stop("Hermes config write failed");
|
|
346
|
-
log.error(`${e instanceof Error ? e.message : String(e)}`);
|
|
347
|
-
log.warn("Run `nlm connect hermes` manually after checking ~/.hermes/config.yaml.");
|
|
348
|
-
}
|
|
349
|
-
break;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
case "pi":
|
|
353
|
-
log.success("pi.dev: session scanning enabled (passive — no extra config needed)");
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// ── Summary ───────────────────────────────────────────────────────────
|
|
359
|
-
const needsRestart: string[] = [];
|
|
360
|
-
if (chosen.includes("claude-code")) needsRestart.push("Claude Code");
|
|
361
|
-
if (chosen.includes("hermes")) needsRestart.push("Hermes");
|
|
362
|
-
|
|
363
|
-
outro(
|
|
364
|
-
needsRestart.length > 0
|
|
365
|
-
? `Done! Restart ${needsRestart.join(" and ")} for the MCP server to activate, then start a session — memory will follow.`
|
|
366
|
-
: "Done! Start a session in any configured runtime and NLM will begin indexing automatically.",
|
|
367
|
-
);
|
|
368
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ClassifierBox — a mutable LLMClient wrapper holding the active classifier
|
|
3
|
-
* client. The scheduler reads `inner` on each tick, so a runtime swap takes
|
|
4
|
-
* effect on the next session ingest without restarting the daemon.
|
|
5
|
-
*
|
|
6
|
-
* Only `classify()` is delegated. `embed()` throws — embeddings are wired
|
|
7
|
-
* separately through the dedicated Ollama embedder; the classifier slot is
|
|
8
|
-
* for transcript classification only.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
ClassifyResult,
|
|
13
|
-
EmbedResult,
|
|
14
|
-
EmbeddingKind,
|
|
15
|
-
LLMClient,
|
|
16
|
-
} from "@ports/llm-client.js";
|
|
17
|
-
import { DeepSeekClient } from "./deepseek-client.js";
|
|
18
|
-
import { OllamaClient } from "./ollama-client.js";
|
|
19
|
-
|
|
20
|
-
export type ClassifierProvider = "deepseek" | "ollama";
|
|
21
|
-
|
|
22
|
-
export interface ClassifierBoxOptions {
|
|
23
|
-
readonly provider: ClassifierProvider;
|
|
24
|
-
readonly model: string;
|
|
25
|
-
readonly ollamaUrl?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class ClassifierBox implements LLMClient {
|
|
29
|
-
private inner: LLMClient;
|
|
30
|
-
private providerName: ClassifierProvider;
|
|
31
|
-
private modelName: string;
|
|
32
|
-
private readonly ollamaUrl: string;
|
|
33
|
-
|
|
34
|
-
constructor(opts: ClassifierBoxOptions) {
|
|
35
|
-
this.providerName = opts.provider;
|
|
36
|
-
this.modelName = opts.model;
|
|
37
|
-
this.ollamaUrl = opts.ollamaUrl ?? "http://localhost:11434";
|
|
38
|
-
this.inner = this.construct(opts.provider, opts.model);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get provider(): ClassifierProvider { return this.providerName; }
|
|
42
|
-
get model(): string { return this.modelName; }
|
|
43
|
-
|
|
44
|
-
swap(provider: ClassifierProvider, model: string): void {
|
|
45
|
-
this.inner = this.construct(provider, model);
|
|
46
|
-
this.providerName = provider;
|
|
47
|
-
this.modelName = model;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
embed(_text: string, _kind: EmbeddingKind): Promise<EmbedResult> {
|
|
51
|
-
throw new Error("ClassifierBox.embed is not supported — wire OllamaClient as the embedder.");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
classify(transcript: string): Promise<ClassifyResult> {
|
|
55
|
-
return this.inner.classify(transcript);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private construct(provider: ClassifierProvider, model: string): LLMClient {
|
|
59
|
-
if (provider === "ollama") {
|
|
60
|
-
return new OllamaClient({ baseUrl: this.ollamaUrl, classifyModel: model });
|
|
61
|
-
}
|
|
62
|
-
return new DeepSeekClient({ classifyModel: model });
|
|
63
|
-
}
|
|
64
|
-
}
|