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/dist/ui/index.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>nlm memory</title>
|
|
7
|
-
<script type="module" crossorigin src="/ui/assets/index-
|
|
8
|
-
<link rel="stylesheet" crossorigin href="/ui/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/ui/assets/index-CSPTTeeM.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/ui/assets/index-Beo8psd-.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nlm-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Local-first non-linear memory operating system for AI operators.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=20.0.0"
|
|
9
9
|
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/pbmagnet4/nlm-memory-ts.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/pbmagnet4/nlm-memory-ts#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/pbmagnet4/nlm-memory-ts/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"ai",
|
|
20
|
+
"memory",
|
|
21
|
+
"mcp",
|
|
22
|
+
"claude-code",
|
|
23
|
+
"codex",
|
|
24
|
+
"hermes",
|
|
25
|
+
"local-first",
|
|
26
|
+
"recall",
|
|
27
|
+
"session-memory"
|
|
28
|
+
],
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"plugin",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
10
35
|
"bin": {
|
|
11
36
|
"nlm": "dist/cli/nlm.js"
|
|
12
37
|
},
|
|
@@ -87,6 +87,56 @@ function selectHits(params) {
|
|
|
87
87
|
return eligible.slice(0, limit);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// src/llm/env-autoload.ts
|
|
91
|
+
import { readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
|
|
92
|
+
import { homedir as homedir3 } from "node:os";
|
|
93
|
+
import { resolve } from "node:path";
|
|
94
|
+
var DEFAULT_SEARCH_PATHS = [
|
|
95
|
+
"~/.nlm/.env",
|
|
96
|
+
"./.env",
|
|
97
|
+
"../.env",
|
|
98
|
+
"../../.env"
|
|
99
|
+
];
|
|
100
|
+
function expandHome(p) {
|
|
101
|
+
if (p.startsWith("~/")) return resolve(homedir3(), p.slice(2));
|
|
102
|
+
return p;
|
|
103
|
+
}
|
|
104
|
+
function autoloadEnv(extraPaths = []) {
|
|
105
|
+
const loaded = [];
|
|
106
|
+
const paths = [...DEFAULT_SEARCH_PATHS, ...extraPaths];
|
|
107
|
+
for (const raw of paths) {
|
|
108
|
+
const path = expandHome(raw);
|
|
109
|
+
if (!existsSync2(path)) continue;
|
|
110
|
+
try {
|
|
111
|
+
const content = readFileSync2(path, "utf8");
|
|
112
|
+
for (const line of content.split("\n")) {
|
|
113
|
+
const trimmed = line.trim();
|
|
114
|
+
if (!trimmed || trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
115
|
+
const eq = trimmed.indexOf("=");
|
|
116
|
+
const key = trimmed.slice(0, eq).trim();
|
|
117
|
+
let value = trimmed.slice(eq + 1).trim();
|
|
118
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
119
|
+
value = value.slice(1, -1);
|
|
120
|
+
}
|
|
121
|
+
if (key && process.env[key] === void 0) {
|
|
122
|
+
process.env[key] = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
loaded.push(path);
|
|
126
|
+
} catch {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return loaded;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/hook/hook-auth.ts
|
|
134
|
+
function hookAuthHeaders(extra = {}) {
|
|
135
|
+
const token = process.env["NLM_MCP_TOKEN"];
|
|
136
|
+
if (!token) return { ...extra };
|
|
137
|
+
return { ...extra, authorization: `Bearer ${token}` };
|
|
138
|
+
}
|
|
139
|
+
|
|
90
140
|
// src/hook/prompt-recall-hook.ts
|
|
91
141
|
var SCORE_THRESHOLD = 0;
|
|
92
142
|
var PER_FIRE_CAP = 3;
|
|
@@ -143,12 +193,12 @@ async function runHook(input, deps) {
|
|
|
143
193
|
return "";
|
|
144
194
|
}
|
|
145
195
|
function readStdin() {
|
|
146
|
-
return new Promise((
|
|
196
|
+
return new Promise((resolve2) => {
|
|
147
197
|
let data = "";
|
|
148
198
|
process.stdin.setEncoding("utf8");
|
|
149
199
|
process.stdin.on("data", (chunk) => data += chunk);
|
|
150
|
-
process.stdin.on("end", () =>
|
|
151
|
-
process.stdin.on("error", () =>
|
|
200
|
+
process.stdin.on("end", () => resolve2(data));
|
|
201
|
+
process.stdin.on("error", () => resolve2(data));
|
|
152
202
|
});
|
|
153
203
|
}
|
|
154
204
|
async function recallOverHttp(prompt) {
|
|
@@ -158,7 +208,7 @@ async function recallOverHttp(prompt) {
|
|
|
158
208
|
const timer = setTimeout(() => controller.abort(), RECALL_TIMEOUT_MS);
|
|
159
209
|
try {
|
|
160
210
|
const res = await fetch(url, {
|
|
161
|
-
headers: { "x-recall-source": "hook" },
|
|
211
|
+
headers: hookAuthHeaders({ "x-recall-source": "hook" }),
|
|
162
212
|
signal: controller.signal
|
|
163
213
|
});
|
|
164
214
|
if (!res.ok) return [];
|
|
@@ -180,6 +230,7 @@ async function recallOverHttp(prompt) {
|
|
|
180
230
|
}
|
|
181
231
|
async function main() {
|
|
182
232
|
try {
|
|
233
|
+
autoloadEnv();
|
|
183
234
|
const raw = await readStdin();
|
|
184
235
|
const payload = JSON.parse(raw);
|
|
185
236
|
const prompt = typeof payload.prompt === "string" ? payload.prompt : "";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/hook/stop-hook.ts
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { appendFileSync, mkdirSync as mkdirSync3 } from "node:fs";
|
|
6
|
-
import { homedir as
|
|
6
|
+
import { homedir as homedir4 } from "node:os";
|
|
7
7
|
import { dirname, join as join3 } from "node:path";
|
|
8
8
|
|
|
9
9
|
// src/core/hook/citation-detect.ts
|
|
@@ -162,6 +162,56 @@ function readAllAssistantTurns(transcriptPath) {
|
|
|
162
162
|
return turns;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
// src/llm/env-autoload.ts
|
|
166
|
+
import { readFileSync as readFileSync4, existsSync as existsSync4 } from "node:fs";
|
|
167
|
+
import { homedir as homedir3 } from "node:os";
|
|
168
|
+
import { resolve } from "node:path";
|
|
169
|
+
var DEFAULT_SEARCH_PATHS = [
|
|
170
|
+
"~/.nlm/.env",
|
|
171
|
+
"./.env",
|
|
172
|
+
"../.env",
|
|
173
|
+
"../../.env"
|
|
174
|
+
];
|
|
175
|
+
function expandHome(p) {
|
|
176
|
+
if (p.startsWith("~/")) return resolve(homedir3(), p.slice(2));
|
|
177
|
+
return p;
|
|
178
|
+
}
|
|
179
|
+
function autoloadEnv(extraPaths = []) {
|
|
180
|
+
const loaded = [];
|
|
181
|
+
const paths = [...DEFAULT_SEARCH_PATHS, ...extraPaths];
|
|
182
|
+
for (const raw of paths) {
|
|
183
|
+
const path = expandHome(raw);
|
|
184
|
+
if (!existsSync4(path)) continue;
|
|
185
|
+
try {
|
|
186
|
+
const content = readFileSync4(path, "utf8");
|
|
187
|
+
for (const line of content.split("\n")) {
|
|
188
|
+
const trimmed = line.trim();
|
|
189
|
+
if (!trimmed || trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
190
|
+
const eq = trimmed.indexOf("=");
|
|
191
|
+
const key = trimmed.slice(0, eq).trim();
|
|
192
|
+
let value = trimmed.slice(eq + 1).trim();
|
|
193
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
194
|
+
value = value.slice(1, -1);
|
|
195
|
+
}
|
|
196
|
+
if (key && process.env[key] === void 0) {
|
|
197
|
+
process.env[key] = value;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
loaded.push(path);
|
|
201
|
+
} catch {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return loaded;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/hook/hook-auth.ts
|
|
209
|
+
function hookAuthHeaders(extra = {}) {
|
|
210
|
+
const token = process.env["NLM_MCP_TOKEN"];
|
|
211
|
+
if (!token) return { ...extra };
|
|
212
|
+
return { ...extra, authorization: `Bearer ${token}` };
|
|
213
|
+
}
|
|
214
|
+
|
|
165
215
|
// src/hook/stop-hook.ts
|
|
166
216
|
var RESPONSE_PREVIEW_CHARS = 200;
|
|
167
217
|
var POST_TIMEOUT_MS = 1500;
|
|
@@ -229,7 +279,7 @@ async function runStopHook(input, deps) {
|
|
|
229
279
|
};
|
|
230
280
|
}
|
|
231
281
|
function logPath() {
|
|
232
|
-
return process.env["NLM_HOOK_LOG"] ?? join3(
|
|
282
|
+
return process.env["NLM_HOOK_LOG"] ?? join3(homedir4(), ".nlm", "hook-log.jsonl");
|
|
233
283
|
}
|
|
234
284
|
function logStopResult(result) {
|
|
235
285
|
try {
|
|
@@ -254,12 +304,12 @@ function logStopResult(result) {
|
|
|
254
304
|
}
|
|
255
305
|
}
|
|
256
306
|
function readStdin() {
|
|
257
|
-
return new Promise((
|
|
307
|
+
return new Promise((resolve2) => {
|
|
258
308
|
let data = "";
|
|
259
309
|
process.stdin.setEncoding("utf8");
|
|
260
310
|
process.stdin.on("data", (chunk) => data += chunk);
|
|
261
|
-
process.stdin.on("end", () =>
|
|
262
|
-
process.stdin.on("error", () =>
|
|
311
|
+
process.stdin.on("end", () => resolve2(data));
|
|
312
|
+
process.stdin.on("error", () => resolve2(data));
|
|
263
313
|
});
|
|
264
314
|
}
|
|
265
315
|
async function postCitationOverHttp(conversationId, citedId, kind, responsePreview) {
|
|
@@ -270,7 +320,7 @@ async function postCitationOverHttp(conversationId, citedId, kind, responsePrevi
|
|
|
270
320
|
try {
|
|
271
321
|
await fetch(url, {
|
|
272
322
|
method: "POST",
|
|
273
|
-
headers: { "content-type": "application/json" },
|
|
323
|
+
headers: hookAuthHeaders({ "content-type": "application/json" }),
|
|
274
324
|
body: JSON.stringify({
|
|
275
325
|
conversation_id: conversationId,
|
|
276
326
|
cited_id: citedId,
|
|
@@ -285,6 +335,7 @@ async function postCitationOverHttp(conversationId, citedId, kind, responsePrevi
|
|
|
285
335
|
}
|
|
286
336
|
async function main() {
|
|
287
337
|
try {
|
|
338
|
+
autoloadEnv();
|
|
288
339
|
const raw = await readStdin();
|
|
289
340
|
const payload = JSON.parse(raw);
|
|
290
341
|
const conversationId = typeof payload.session_id === "string" ? payload.session_id : "unknown";
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "nlm-memory-ts",
|
|
3
|
-
"interface": {
|
|
4
|
-
"displayName": "nlm-memory"
|
|
5
|
-
},
|
|
6
|
-
"plugins": [
|
|
7
|
-
{
|
|
8
|
-
"name": "nlm-memory",
|
|
9
|
-
"source": {
|
|
10
|
-
"source": "local",
|
|
11
|
-
"path": "./plugin"
|
|
12
|
-
},
|
|
13
|
-
"policy": {
|
|
14
|
-
"installation": "AVAILABLE",
|
|
15
|
-
"authentication": "ON_USE"
|
|
16
|
-
},
|
|
17
|
-
"category": "Coding"
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [main]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [main]
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
test:
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
steps:
|
|
13
|
-
- uses: actions/checkout@v4
|
|
14
|
-
|
|
15
|
-
- uses: actions/setup-node@v4
|
|
16
|
-
with:
|
|
17
|
-
node-version: "20"
|
|
18
|
-
cache: npm
|
|
19
|
-
|
|
20
|
-
- name: Install dependencies
|
|
21
|
-
run: npm ci
|
|
22
|
-
|
|
23
|
-
- name: Typecheck
|
|
24
|
-
run: npm run typecheck
|
|
25
|
-
|
|
26
|
-
- name: Test
|
|
27
|
-
run: npm test
|
|
28
|
-
|
|
29
|
-
- name: Build (server)
|
|
30
|
-
run: npm run build
|