@edihasaj/recall 1.4.1 → 1.4.15
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 +17 -7
- package/dist/{chunk-WZWXYBP6.js → chunk-2E7UCWNS.js} +6 -3
- package/dist/{chunk-WZWXYBP6.js.map → chunk-2E7UCWNS.js.map} +1 -1
- package/dist/{chunk-JYWURG5T.js → chunk-5W3CDNJ6.js} +12 -2
- package/dist/chunk-5W3CDNJ6.js.map +1 -0
- package/dist/chunk-ADWOKDF6.js +23 -0
- package/dist/chunk-ADWOKDF6.js.map +1 -0
- package/dist/{chunk-CW3XJDH7.js → chunk-FDIV6YFT.js} +6 -2
- package/dist/{chunk-CW3XJDH7.js.map → chunk-FDIV6YFT.js.map} +1 -1
- package/dist/{chunk-EAFRT7RX.js → chunk-GMRT5DJZ.js} +7 -2
- package/dist/{chunk-EAFRT7RX.js.map → chunk-GMRT5DJZ.js.map} +1 -1
- package/dist/{chunk-PUMEMKGF.js → chunk-IMCI2CLJ.js} +7 -1
- package/dist/{chunk-PUMEMKGF.js.map → chunk-IMCI2CLJ.js.map} +1 -1
- package/dist/{chunk-ZBQGZCFL.js → chunk-KF3EGZWM.js} +99 -9
- package/dist/chunk-KF3EGZWM.js.map +1 -0
- package/dist/{chunk-NAYFAUSM.js → chunk-LCIVSUQO.js} +61 -21
- package/dist/chunk-LCIVSUQO.js.map +1 -0
- package/dist/{chunk-LWY4Z626.js → chunk-MESKBXZZ.js} +8 -4
- package/dist/{chunk-LWY4Z626.js.map → chunk-MESKBXZZ.js.map} +1 -1
- package/dist/{chunk-FHEH6QDU.js → chunk-PQOGHXET.js} +6 -1
- package/dist/{chunk-FHEH6QDU.js.map → chunk-PQOGHXET.js.map} +1 -1
- package/dist/{chunk-ZXCKMEJA.js → chunk-RRNELZJV.js} +11 -6
- package/dist/{chunk-ZXCKMEJA.js.map → chunk-RRNELZJV.js.map} +1 -1
- package/dist/{chunk-7CFX774S.js → chunk-SWPXUPMX.js} +306 -167
- package/dist/chunk-SWPXUPMX.js.map +1 -0
- package/dist/{chunk-T274LVWB.js → chunk-TZ4EU4SW.js} +15 -11
- package/dist/chunk-TZ4EU4SW.js.map +1 -0
- package/dist/chunk-UTOM43G2.js +594 -0
- package/dist/chunk-UTOM43G2.js.map +1 -0
- package/dist/{chunk-AFD43EOE.js → chunk-UZ4GFLH6.js} +8 -4
- package/dist/{chunk-AFD43EOE.js.map → chunk-UZ4GFLH6.js.map} +1 -1
- package/dist/{chunk-LUIYWYOT.js → chunk-VI6NOUXB.js} +51 -3
- package/dist/chunk-VI6NOUXB.js.map +1 -0
- package/dist/{chunk-TA4WSV6A.js → chunk-VZ456OCO.js} +204 -13
- package/dist/chunk-VZ456OCO.js.map +1 -0
- package/dist/{chunk-4UHRAQFG.js → chunk-ZECQ2LQB.js} +376 -58
- package/dist/chunk-ZECQ2LQB.js.map +1 -0
- package/dist/{cleanup-RTL2UETA.js → cleanup-KXCEVJ7V.js} +11 -10
- package/dist/cli.js +639 -784
- package/dist/cli.js.map +1 -1
- package/dist/codex-trust-H7VKP4G3.js +74 -0
- package/dist/codex-trust-H7VKP4G3.js.map +1 -0
- package/dist/daemon.js +174 -54
- package/dist/daemon.js.map +1 -1
- package/dist/dispatcher-GHC6RX54.js +22 -0
- package/dist/{embeddings-MILTROKW.js → embeddings-GYQBZWBD.js} +7 -5
- package/dist/ingest-6GDZNYCY.js +20 -0
- package/dist/{keychain-5KXUHKMF.js → keychain-TKPVUZCH.js} +3 -3
- package/dist/mcp.js +18 -14
- package/dist/mcp.js.map +1 -1
- package/dist/{memory-value-WXI2Q6TO.js → memory-value-A4UCC3DY.js} +11 -10
- package/dist/provenance-M5YFD6DO.js +50 -0
- package/dist/provenance-M5YFD6DO.js.map +1 -0
- package/dist/quality-TQ7CVPRO.js +25 -0
- package/dist/retrieval-7R5LKJAM.js +15 -0
- package/dist/{store-5C7ZKKZF.js → store-QKP6HQ45.js} +4 -4
- package/dist/sync-server.js +5 -2
- package/dist/sync-server.js.map +1 -1
- package/dist/{tasks-7SE6VHSQ.js → tasks-M5HSQSWK.js} +11 -10
- package/dist/{usage-VQ5LJCNH.js → usage-TQTOHPL7.js} +7 -4
- package/dist/{usage-VQ5LJCNH.js.map → usage-TQTOHPL7.js.map} +1 -1
- package/drizzle/0011_compact_telemetry_dedupe_keys.sql +25 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +15 -12
- package/dist/chunk-4UHRAQFG.js.map +0 -1
- package/dist/chunk-7CFX774S.js.map +0 -1
- package/dist/chunk-LUIYWYOT.js.map +0 -1
- package/dist/chunk-NAYFAUSM.js.map +0 -1
- package/dist/chunk-T274LVWB.js.map +0 -1
- package/dist/chunk-TA4WSV6A.js.map +0 -1
- package/dist/chunk-ZBQGZCFL.js.map +0 -1
- package/dist/dispatcher-PP5OKOLS.js +0 -21
- package/dist/ingest-HEXVIAL6.js +0 -19
- package/dist/quality-VKQUCL66.js +0 -24
- package/dist/retrieval-4MEIABHC.js +0 -14
- package/dist/tasks-7SE6VHSQ.js.map +0 -1
- /package/dist/{chunk-JYWURG5T.js.map → cleanup-KXCEVJ7V.js.map} +0 -0
- /package/dist/{cleanup-RTL2UETA.js.map → dispatcher-GHC6RX54.js.map} +0 -0
- /package/dist/{dispatcher-PP5OKOLS.js.map → embeddings-GYQBZWBD.js.map} +0 -0
- /package/dist/{embeddings-MILTROKW.js.map → ingest-6GDZNYCY.js.map} +0 -0
- /package/dist/{ingest-HEXVIAL6.js.map → keychain-TKPVUZCH.js.map} +0 -0
- /package/dist/{keychain-5KXUHKMF.js.map → memory-value-A4UCC3DY.js.map} +0 -0
- /package/dist/{memory-value-WXI2Q6TO.js.map → quality-TQ7CVPRO.js.map} +0 -0
- /package/dist/{quality-VKQUCL66.js.map → retrieval-7R5LKJAM.js.map} +0 -0
- /package/dist/{retrieval-4MEIABHC.js.map → store-QKP6HQ45.js.map} +0 -0
- /package/dist/{store-5C7ZKKZF.js.map → tasks-M5HSQSWK.js.map} +0 -0
package/README.md
CHANGED
|
@@ -237,6 +237,8 @@ recall health -r owner/repo
|
|
|
237
237
|
recall maintenance quality
|
|
238
238
|
recall eval value-retrieval --snapshot
|
|
239
239
|
recall maintenance quality --history
|
|
240
|
+
recall reliability
|
|
241
|
+
recall reliability --canary --real-embeddings
|
|
240
242
|
recall compile -r owner/repo
|
|
241
243
|
recall compile -r owner/repo --query "pytest -q" --include-candidates
|
|
242
244
|
```
|
|
@@ -261,26 +263,34 @@ RECALL_EMBEDDING_DIMS=384
|
|
|
261
263
|
RECALL_EMBEDDINGS_DISABLED=true
|
|
262
264
|
```
|
|
263
265
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
Windows x64 and ARM64 support local vector retrieval. Native ARM64 uses a
|
|
267
|
+
bundled ARM64 extension; other platforms keep the existing sqlite-vec loader.
|
|
268
|
+
This update preserves existing databases. If the native extension is missing
|
|
269
|
+
or cannot load, Recall keeps lexical retrieval available and reports the
|
|
270
|
+
reason in `/health`. See [storage strategy](docs/storage-strategy.md).
|
|
269
271
|
|
|
270
272
|
Daemon maintenance runs in-process on a timer.
|
|
271
273
|
|
|
272
274
|
Useful env vars:
|
|
273
275
|
|
|
274
276
|
```bash
|
|
275
|
-
RECALL_MAINTENANCE_INTERVAL_SECONDS=
|
|
276
|
-
RECALL_ACTIVITY_RETENTION_DAYS=
|
|
277
|
+
RECALL_MAINTENANCE_INTERVAL_SECONDS=3600
|
|
278
|
+
RECALL_ACTIVITY_RETENTION_DAYS=30
|
|
277
279
|
RECALL_FEEDBACK_RETENTION_DAYS=180
|
|
278
280
|
RECALL_SIGNAL_RETENTION_DAYS=180
|
|
279
281
|
RECALL_SQLITE_VACUUM_ENABLED=true
|
|
280
282
|
RECALL_SQLITE_VACUUM_MIN_FREE_PAGES=100
|
|
281
283
|
RECALL_SQLITE_VACUUM_MIN_FREE_RATIO=0.1
|
|
284
|
+
RECALL_CANDIDATE_UNCONFIRMED_DAYS=30
|
|
285
|
+
RECALL_RELIABILITY_PROBE_ENABLED=true
|
|
286
|
+
RECALL_RELIABILITY_PROBE_INTERVAL_SECONDS=86400
|
|
287
|
+
RECALL_RELIABILITY_PROBE_REAL_EMBEDDINGS=true
|
|
282
288
|
```
|
|
283
289
|
|
|
290
|
+
`recall reliability` separates compiler selection, hook emission, observed use,
|
|
291
|
+
and resolved outcomes. The daily probe checks the live database, newest backup,
|
|
292
|
+
and a disposable real-vector canary. See [Reliability and uncertainty](docs/reliability.md).
|
|
293
|
+
|
|
284
294
|
Inspect rolled-up session history:
|
|
285
295
|
|
|
286
296
|
```bash
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__esm,
|
|
3
|
-
__export
|
|
4
|
-
|
|
3
|
+
__export,
|
|
4
|
+
init_define_RECALL_BUILD_INFO
|
|
5
|
+
} from "./chunk-5W3CDNJ6.js";
|
|
5
6
|
|
|
6
7
|
// src/security/outbound-url.ts
|
|
7
8
|
import { isIP } from "net";
|
|
@@ -61,6 +62,7 @@ var BLOCKED_SYNC_HOSTS, BLOCKED_SYNC_SUFFIXES;
|
|
|
61
62
|
var init_outbound_url = __esm({
|
|
62
63
|
"src/security/outbound-url.ts"() {
|
|
63
64
|
"use strict";
|
|
65
|
+
init_define_RECALL_BUILD_INFO();
|
|
64
66
|
BLOCKED_SYNC_HOSTS = /* @__PURE__ */ new Set([
|
|
65
67
|
"localhost",
|
|
66
68
|
"metadata.google.internal"
|
|
@@ -280,6 +282,7 @@ function previewKey(_key) {
|
|
|
280
282
|
var KEYCHAIN_SERVICE, SIMPLE_ENV_FALLBACK;
|
|
281
283
|
var init_keychain = __esm({
|
|
282
284
|
"src/credentials/keychain.ts"() {
|
|
285
|
+
init_define_RECALL_BUILD_INFO();
|
|
283
286
|
init_outbound_url();
|
|
284
287
|
KEYCHAIN_SERVICE = "com.recall.llm";
|
|
285
288
|
SIMPLE_ENV_FALLBACK = {
|
|
@@ -303,4 +306,4 @@ export {
|
|
|
303
306
|
keychain_exports,
|
|
304
307
|
init_keychain
|
|
305
308
|
};
|
|
306
|
-
//# sourceMappingURL=chunk-
|
|
309
|
+
//# sourceMappingURL=chunk-2E7UCWNS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/security/outbound-url.ts","../src/credentials/keychain.ts"],"sourcesContent":["import { isIP } from \"node:net\";\n\nconst BLOCKED_SYNC_HOSTS = new Set([\n \"localhost\",\n \"metadata.google.internal\",\n]);\n\nconst BLOCKED_SYNC_SUFFIXES = [\n \".internal\",\n \".local\",\n \".localhost\",\n \".home.arpa\",\n];\n\ninterface NormalizeOptions {\n allowPath?: boolean;\n allowedHostSuffixes?: string[];\n blockPrivateNames?: boolean;\n}\n\nexport function normalizeHttpsBaseUrl(\n raw: string,\n label: string,\n options: NormalizeOptions = {},\n): string {\n let url: URL;\n try {\n url = new URL(raw.trim());\n } catch {\n throw new Error(`${label} must be a valid HTTPS URL`);\n }\n\n if (url.protocol !== \"https:\") {\n throw new Error(`${label} must use HTTPS`);\n }\n if (url.username || url.password) {\n throw new Error(`${label} must not contain credentials`);\n }\n if (url.search || url.hash) {\n throw new Error(`${label} must not contain a query or fragment`);\n }\n if (url.port && url.port !== \"443\") {\n throw new Error(`${label} must use the default HTTPS port`);\n }\n\n const hostname = url.hostname.toLowerCase().replace(/\\.$/, \"\");\n if (options.allowedHostSuffixes?.length) {\n const allowed = options.allowedHostSuffixes.some(\n (suffix) => hostname === suffix || hostname.endsWith(`.${suffix}`),\n );\n if (!allowed) {\n throw new Error(`${label} host is not supported`);\n }\n }\n\n if (options.blockPrivateNames) {\n const ipCandidate = hostname.replace(/^\\[|\\]$/g, \"\");\n if (\n isIP(ipCandidate) !== 0 ||\n BLOCKED_SYNC_HOSTS.has(hostname) ||\n BLOCKED_SYNC_SUFFIXES.some((suffix) => hostname.endsWith(suffix))\n ) {\n throw new Error(`${label} must use a public DNS hostname`);\n }\n }\n\n if (!options.allowPath && url.pathname !== \"/\") {\n throw new Error(`${label} must not contain a path`);\n }\n\n url.hostname = hostname;\n url.pathname = options.allowPath\n ? url.pathname.replace(/\\/+$/, \"\")\n : \"\";\n return url.toString().replace(/\\/$/, \"\");\n}\n\nexport function normalizeAzureOpenAiEndpoint(raw: string): string {\n return normalizeHttpsBaseUrl(raw, \"Azure endpoint\", {\n allowedHostSuffixes: [\"openai.azure.com\"],\n });\n}\n\nexport function normalizeSyncRemoteUrl(raw: string): string {\n return normalizeHttpsBaseUrl(raw, \"Sync URL\", {\n allowPath: true,\n blockPrivateNames: true,\n });\n}\n","import { execFileSync } from \"node:child_process\";\nimport { normalizeAzureOpenAiEndpoint } from \"../security/outbound-url.js\";\n\nexport type LlmProvider = \"openai\" | \"anthropic\" | \"azure-openai\";\n\nconst KEYCHAIN_SERVICE = \"com.recall.llm\";\n\nexport interface AzureOpenAiConfig {\n provider: \"azure-openai\";\n endpoint: string;\n deployment: string;\n api_version: string;\n key: string;\n}\n\nexport interface SimpleProviderConfig {\n provider: \"openai\" | \"anthropic\";\n key: string;\n}\n\nexport type ProviderConfig = SimpleProviderConfig | AzureOpenAiConfig;\n\nexport interface StoredCredential {\n provider: LlmProvider;\n source: \"keychain\" | \"env\";\n preview: string;\n detail?: string;\n}\n\nconst SIMPLE_ENV_FALLBACK: Record<\"openai\" | \"anthropic\", string> = {\n openai: \"OPENAI_API_KEY\",\n anthropic: \"ANTHROPIC_API_KEY\",\n};\n\nexport function getApiKey(provider: \"openai\" | \"anthropic\"): string | null {\n const cfg = getProviderConfig(provider);\n return cfg ? cfg.key : null;\n}\n\nexport function getProviderConfig(provider: LlmProvider): ProviderConfig | null {\n if (provider === \"azure-openai\") return readAzureConfig();\n const key = readSimpleKey(provider);\n return key ? { provider, key } : null;\n}\n\nexport function hasProviderConfigured(provider: LlmProvider): boolean {\n return getProviderConfig(provider) != null;\n}\n\nexport function setApiKey(provider: \"openai\" | \"anthropic\", key: string): void {\n if (process.platform !== \"darwin\") {\n throw new Error(\n \"Keychain storage is only supported on macOS. Set the \" +\n `${SIMPLE_ENV_FALLBACK[provider]} environment variable instead.`,\n );\n }\n if (!key || key.trim().length === 0) {\n throw new Error(\"Refusing to store an empty API key\");\n }\n writeKeychain(provider, key.trim());\n}\n\nexport function setAzureConfig(config: {\n endpoint: string;\n deployment: string;\n api_version: string;\n key: string;\n}): void {\n if (process.platform !== \"darwin\") {\n throw new Error(\n \"Keychain storage is only supported on macOS. Set the AZURE_OPENAI_* env vars instead.\",\n );\n }\n const normalized = {\n endpoint: normalizeAzureOpenAiEndpoint(config.endpoint),\n deployment: config.deployment.trim(),\n api_version: config.api_version.trim(),\n key: config.key.trim(),\n };\n if (!normalized.deployment) throw new Error(\"Azure deployment name is required\");\n if (!normalized.api_version) throw new Error(\"Azure api_version is required (e.g. 2024-10-21)\");\n if (!normalized.key) throw new Error(\"Azure api key is required\");\n writeKeychain(\"azure-openai\", JSON.stringify(normalized));\n}\n\nexport function deleteApiKey(provider: LlmProvider): boolean {\n if (process.platform !== \"darwin\") return false;\n try {\n execFileSync(\n \"security\",\n [\"delete-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", provider],\n { stdio: \"ignore\" },\n );\n return true;\n } catch {\n return false;\n }\n}\n\nexport function hasKeychainApiKey(provider: LlmProvider): boolean {\n if (process.platform !== \"darwin\") return false;\n try {\n execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", provider],\n { stdio: \"ignore\" },\n );\n return true;\n } catch {\n return false;\n }\n}\n\nexport function listCredentials(): StoredCredential[] {\n const results: StoredCredential[] = [];\n for (const provider of [\"openai\", \"anthropic\"] as const) {\n const fromChain = process.platform === \"darwin\" ? readSimpleKeychain(provider) : null;\n if (fromChain) {\n results.push({ provider, source: \"keychain\", preview: previewKey(fromChain) });\n continue;\n }\n const fromEnv = process.env[SIMPLE_ENV_FALLBACK[provider]];\n if (fromEnv && fromEnv.trim().length > 0) {\n results.push({ provider, source: \"env\", preview: previewKey(fromEnv) });\n }\n }\n const azure = readAzureConfig();\n if (azure) {\n results.push({\n provider: \"azure-openai\",\n source: azureSource(),\n preview: previewKey(azure.key),\n detail: `${azure.endpoint} · ${azure.deployment} · api-version=${azure.api_version}`,\n });\n }\n return results;\n}\n\nfunction readSimpleKey(provider: \"openai\" | \"anthropic\"): string | null {\n if (process.platform === \"darwin\") {\n const fromChain = readSimpleKeychain(provider);\n if (fromChain) return fromChain;\n }\n const fromEnv = process.env[SIMPLE_ENV_FALLBACK[provider]];\n return fromEnv && fromEnv.trim().length > 0 ? fromEnv.trim() : null;\n}\n\nfunction readSimpleKeychain(provider: \"openai\" | \"anthropic\"): string | null {\n try {\n const output = execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", provider, \"-w\"],\n { encoding: \"utf-8\", stdio: [\"ignore\", \"pipe\", \"ignore\"] },\n );\n const trimmed = output.trim();\n return trimmed.length > 0 ? trimmed : null;\n } catch {\n return null;\n }\n}\n\nfunction readAzureConfig(): AzureOpenAiConfig | null {\n if (process.platform === \"darwin\") {\n try {\n const raw = execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", \"azure-openai\", \"-w\"],\n { encoding: \"utf-8\", stdio: [\"ignore\", \"pipe\", \"ignore\"] },\n );\n const trimmed = raw.trim();\n if (trimmed.length > 0) {\n const parsed = JSON.parse(trimmed) as Omit<AzureOpenAiConfig, \"provider\">;\n if (parsed.endpoint && parsed.deployment && parsed.api_version && parsed.key) {\n return {\n provider: \"azure-openai\",\n ...parsed,\n endpoint: normalizeAzureOpenAiEndpoint(parsed.endpoint),\n };\n }\n }\n } catch {\n // fall through to env\n }\n }\n\n const endpoint = process.env.AZURE_OPENAI_ENDPOINT?.trim();\n const deployment = process.env.AZURE_OPENAI_DEPLOYMENT?.trim();\n const api_version = process.env.AZURE_OPENAI_API_VERSION?.trim();\n const key = process.env.AZURE_OPENAI_API_KEY?.trim();\n if (endpoint && deployment && api_version && key) {\n try {\n return {\n provider: \"azure-openai\",\n endpoint: normalizeAzureOpenAiEndpoint(endpoint),\n deployment,\n api_version,\n key,\n };\n } catch {\n return null;\n }\n }\n return null;\n}\n\nfunction azureSource(): \"keychain\" | \"env\" {\n if (process.platform !== \"darwin\") return \"env\";\n try {\n execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", \"azure-openai\", \"-w\"],\n { stdio: \"ignore\" },\n );\n return \"keychain\";\n } catch {\n return \"env\";\n }\n}\n\nfunction writeKeychain(provider: LlmProvider, value: string): void {\n // -U updates in place when an entry already exists.\n try {\n execFileSync(\n \"security\",\n [\n \"add-generic-password\",\n \"-U\",\n \"-s\", KEYCHAIN_SERVICE,\n \"-a\", provider,\n \"-w\", value,\n \"-T\", \"\",\n ],\n { stdio: \"ignore\" },\n );\n } catch {\n throw new Error(`Unable to store ${provider} credential in macOS Keychain`);\n }\n}\n\nfunction previewKey(_key: string): string {\n return \"[configured]\";\n}\n"],"mappings":";;;;;;AAAA,SAAS,YAAY;AAoBd,SAAS,sBACd,KACA,OACA,UAA4B,CAAC,GACrB;AACR,MAAI;AACJ,MAAI;AACF,UAAM,IAAI,IAAI,IAAI,KAAK,CAAC;AAAA,EAC1B,QAAQ;AACN,UAAM,IAAI,MAAM,GAAG,KAAK,4BAA4B;AAAA,EACtD;AAEA,MAAI,IAAI,aAAa,UAAU;AAC7B,UAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB;AAAA,EAC3C;AACA,MAAI,IAAI,YAAY,IAAI,UAAU;AAChC,UAAM,IAAI,MAAM,GAAG,KAAK,+BAA+B;AAAA,EACzD;AACA,MAAI,IAAI,UAAU,IAAI,MAAM;AAC1B,UAAM,IAAI,MAAM,GAAG,KAAK,uCAAuC;AAAA,EACjE;AACA,MAAI,IAAI,QAAQ,IAAI,SAAS,OAAO;AAClC,UAAM,IAAI,MAAM,GAAG,KAAK,k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0B,KAAK;AAC/D,QAAM,MAAM,QAAQ,IAAI,sBAAsB,KAAK;AACnD,MAAI,YAAY,cAAc,eAAe,KAAK;AAChD,QAAI;AACF,aAAO;AAAA,QACL,UAAU;AAAA,QACV,UAAU,6BAA6B,QAAQ;AAAA,QAC/C;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,cAAkC;AACzC,MAAI,QAAQ,aAAa,SAAU,QAAO;AAC1C,MAAI;AACF;AAAA,MACE;AAAA,MACA,CAAC,yBAAyB,MAAM,kBAAkB,MAAM,gBAAgB,IAAI;AAAA,MAC5E,EAAE,OAAO,SAAS;AAAA,IACpB;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,cAAc,UAAuB,OAAqB;AAEjE,MAAI;AACF;AAAA,MACE;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QAAM;AAAA,QACN;AAAA,QAAM;AAAA,QACN;AAAA,QAAM;AAAA,QACN;AAAA,QAAM;AAAA,MACR;AAAA,MACA,EAAE,OAAO,SAAS;AAAA,IACpB;AAAA,EACF,QAAQ;AACN,UAAM,IAAI,MAAM,mBAAmB,QAAQ,+BAA+B;AAAA,EAC5E;AACF;AAEA,SAAS,WAAW,MAAsB;AACxC,SAAO;AACT;AAjPA,IAKM,kBAwBA;AA7BN;AAAA;AACA;AAIA,IAAM,mBAAmB;AAwBzB,IAAM,sBAA8D;AAAA,MAClE,QAAQ;AAAA,MACR,WAAW;AAAA,IACb;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/security/outbound-url.ts","../src/credentials/keychain.ts"],"sourcesContent":["import { isIP } from \"node:net\";\n\nconst BLOCKED_SYNC_HOSTS = new Set([\n \"localhost\",\n \"metadata.google.internal\",\n]);\n\nconst BLOCKED_SYNC_SUFFIXES = [\n \".internal\",\n \".local\",\n \".localhost\",\n \".home.arpa\",\n];\n\ninterface NormalizeOptions {\n allowPath?: boolean;\n allowedHostSuffixes?: string[];\n blockPrivateNames?: boolean;\n}\n\nexport function normalizeHttpsBaseUrl(\n raw: string,\n label: string,\n options: NormalizeOptions = {},\n): string {\n let url: URL;\n try {\n url = new URL(raw.trim());\n } catch {\n throw new Error(`${label} must be a valid HTTPS URL`);\n }\n\n if (url.protocol !== \"https:\") {\n throw new Error(`${label} must use HTTPS`);\n }\n if (url.username || url.password) {\n throw new Error(`${label} must not contain credentials`);\n }\n if (url.search || url.hash) {\n throw new Error(`${label} must not contain a query or fragment`);\n }\n if (url.port && url.port !== \"443\") {\n throw new Error(`${label} must use the default HTTPS port`);\n }\n\n const hostname = url.hostname.toLowerCase().replace(/\\.$/, \"\");\n if (options.allowedHostSuffixes?.length) {\n const allowed = options.allowedHostSuffixes.some(\n (suffix) => hostname === suffix || hostname.endsWith(`.${suffix}`),\n );\n if (!allowed) {\n throw new Error(`${label} host is not supported`);\n }\n }\n\n if (options.blockPrivateNames) {\n const ipCandidate = hostname.replace(/^\\[|\\]$/g, \"\");\n if (\n isIP(ipCandidate) !== 0 ||\n BLOCKED_SYNC_HOSTS.has(hostname) ||\n BLOCKED_SYNC_SUFFIXES.some((suffix) => hostname.endsWith(suffix))\n ) {\n throw new Error(`${label} must use a public DNS hostname`);\n }\n }\n\n if (!options.allowPath && url.pathname !== \"/\") {\n throw new Error(`${label} must not contain a path`);\n }\n\n url.hostname = hostname;\n url.pathname = options.allowPath\n ? url.pathname.replace(/\\/+$/, \"\")\n : \"\";\n return url.toString().replace(/\\/$/, \"\");\n}\n\nexport function normalizeAzureOpenAiEndpoint(raw: string): string {\n return normalizeHttpsBaseUrl(raw, \"Azure endpoint\", {\n allowedHostSuffixes: [\"openai.azure.com\"],\n });\n}\n\nexport function normalizeSyncRemoteUrl(raw: string): string {\n return normalizeHttpsBaseUrl(raw, \"Sync URL\", {\n allowPath: true,\n blockPrivateNames: true,\n });\n}\n","import { execFileSync } from \"node:child_process\";\nimport { normalizeAzureOpenAiEndpoint } from \"../security/outbound-url.js\";\n\nexport type LlmProvider = \"openai\" | \"anthropic\" | \"azure-openai\";\n\nconst KEYCHAIN_SERVICE = \"com.recall.llm\";\n\nexport interface AzureOpenAiConfig {\n provider: \"azure-openai\";\n endpoint: string;\n deployment: string;\n api_version: string;\n key: string;\n}\n\nexport interface SimpleProviderConfig {\n provider: \"openai\" | \"anthropic\";\n key: string;\n}\n\nexport type ProviderConfig = SimpleProviderConfig | AzureOpenAiConfig;\n\nexport interface StoredCredential {\n provider: LlmProvider;\n source: \"keychain\" | \"env\";\n preview: string;\n detail?: string;\n}\n\nconst SIMPLE_ENV_FALLBACK: Record<\"openai\" | \"anthropic\", string> = {\n openai: \"OPENAI_API_KEY\",\n anthropic: \"ANTHROPIC_API_KEY\",\n};\n\nexport function getApiKey(provider: \"openai\" | \"anthropic\"): string | null {\n const cfg = getProviderConfig(provider);\n return cfg ? cfg.key : null;\n}\n\nexport function getProviderConfig(provider: LlmProvider): ProviderConfig | null {\n if (provider === \"azure-openai\") return readAzureConfig();\n const key = readSimpleKey(provider);\n return key ? { provider, key } : null;\n}\n\nexport function hasProviderConfigured(provider: LlmProvider): boolean {\n return getProviderConfig(provider) != null;\n}\n\nexport function setApiKey(provider: \"openai\" | \"anthropic\", key: string): void {\n if (process.platform !== \"darwin\") {\n throw new Error(\n \"Keychain storage is only supported on macOS. Set the \" +\n `${SIMPLE_ENV_FALLBACK[provider]} environment variable instead.`,\n );\n }\n if (!key || key.trim().length === 0) {\n throw new Error(\"Refusing to store an empty API key\");\n }\n writeKeychain(provider, key.trim());\n}\n\nexport function setAzureConfig(config: {\n endpoint: string;\n deployment: string;\n api_version: string;\n key: string;\n}): void {\n if (process.platform !== \"darwin\") {\n throw new Error(\n \"Keychain storage is only supported on macOS. Set the AZURE_OPENAI_* env vars instead.\",\n );\n }\n const normalized = {\n endpoint: normalizeAzureOpenAiEndpoint(config.endpoint),\n deployment: config.deployment.trim(),\n api_version: config.api_version.trim(),\n key: config.key.trim(),\n };\n if (!normalized.deployment) throw new Error(\"Azure deployment name is required\");\n if (!normalized.api_version) throw new Error(\"Azure api_version is required (e.g. 2024-10-21)\");\n if (!normalized.key) throw new Error(\"Azure api key is required\");\n writeKeychain(\"azure-openai\", JSON.stringify(normalized));\n}\n\nexport function deleteApiKey(provider: LlmProvider): boolean {\n if (process.platform !== \"darwin\") return false;\n try {\n execFileSync(\n \"security\",\n [\"delete-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", provider],\n { stdio: \"ignore\" },\n );\n return true;\n } catch {\n return false;\n }\n}\n\nexport function hasKeychainApiKey(provider: LlmProvider): boolean {\n if (process.platform !== \"darwin\") return false;\n try {\n execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", provider],\n { stdio: \"ignore\" },\n );\n return true;\n } catch {\n return false;\n }\n}\n\nexport function listCredentials(): StoredCredential[] {\n const results: StoredCredential[] = [];\n for (const provider of [\"openai\", \"anthropic\"] as const) {\n const fromChain = process.platform === \"darwin\" ? readSimpleKeychain(provider) : null;\n if (fromChain) {\n results.push({ provider, source: \"keychain\", preview: previewKey(fromChain) });\n continue;\n }\n const fromEnv = process.env[SIMPLE_ENV_FALLBACK[provider]];\n if (fromEnv && fromEnv.trim().length > 0) {\n results.push({ provider, source: \"env\", preview: previewKey(fromEnv) });\n }\n }\n const azure = readAzureConfig();\n if (azure) {\n results.push({\n provider: \"azure-openai\",\n source: azureSource(),\n preview: previewKey(azure.key),\n detail: `${azure.endpoint} · ${azure.deployment} · api-version=${azure.api_version}`,\n });\n }\n return results;\n}\n\nfunction readSimpleKey(provider: \"openai\" | \"anthropic\"): string | null {\n if (process.platform === \"darwin\") {\n const fromChain = readSimpleKeychain(provider);\n if (fromChain) return fromChain;\n }\n const fromEnv = process.env[SIMPLE_ENV_FALLBACK[provider]];\n return fromEnv && fromEnv.trim().length > 0 ? fromEnv.trim() : null;\n}\n\nfunction readSimpleKeychain(provider: \"openai\" | \"anthropic\"): string | null {\n try {\n const output = execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", provider, \"-w\"],\n { encoding: \"utf-8\", stdio: [\"ignore\", \"pipe\", \"ignore\"] },\n );\n const trimmed = output.trim();\n return trimmed.length > 0 ? trimmed : null;\n } catch {\n return null;\n }\n}\n\nfunction readAzureConfig(): AzureOpenAiConfig | null {\n if (process.platform === \"darwin\") {\n try {\n const raw = execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", \"azure-openai\", \"-w\"],\n { encoding: \"utf-8\", stdio: [\"ignore\", \"pipe\", \"ignore\"] },\n );\n const trimmed = raw.trim();\n if (trimmed.length > 0) {\n const parsed = JSON.parse(trimmed) as Omit<AzureOpenAiConfig, \"provider\">;\n if (parsed.endpoint && parsed.deployment && parsed.api_version && parsed.key) {\n return {\n provider: \"azure-openai\",\n ...parsed,\n endpoint: normalizeAzureOpenAiEndpoint(parsed.endpoint),\n };\n }\n }\n } catch {\n // fall through to env\n }\n }\n\n const endpoint = process.env.AZURE_OPENAI_ENDPOINT?.trim();\n const deployment = process.env.AZURE_OPENAI_DEPLOYMENT?.trim();\n const api_version = process.env.AZURE_OPENAI_API_VERSION?.trim();\n const key = process.env.AZURE_OPENAI_API_KEY?.trim();\n if (endpoint && deployment && api_version && key) {\n try {\n return {\n provider: \"azure-openai\",\n endpoint: normalizeAzureOpenAiEndpoint(endpoint),\n deployment,\n api_version,\n key,\n };\n } catch {\n return null;\n }\n }\n return null;\n}\n\nfunction azureSource(): \"keychain\" | \"env\" {\n if (process.platform !== \"darwin\") return \"env\";\n try {\n execFileSync(\n \"security\",\n [\"find-generic-password\", \"-s\", KEYCHAIN_SERVICE, \"-a\", \"azure-openai\", \"-w\"],\n { stdio: \"ignore\" },\n );\n return \"keychain\";\n } catch {\n return \"env\";\n }\n}\n\nfunction writeKeychain(provider: LlmProvider, value: string): void {\n // -U updates in place when an entry already exists.\n try {\n execFileSync(\n \"security\",\n [\n \"add-generic-password\",\n \"-U\",\n \"-s\", KEYCHAIN_SERVICE,\n \"-a\", provider,\n \"-w\", value,\n \"-T\", \"\",\n ],\n { stdio: \"ignore\" },\n );\n } catch {\n throw new Error(`Unable to store ${provider} credential in macOS Keychain`);\n }\n}\n\nfunction previewKey(_key: string): string {\n return \"[configured]\";\n}\n"],"mappings":";;;;;;;AAAA,SAAS,YAAY;AAoBd,SAAS,sBACd,KACA,OACA,UAA4B,CAAC,GACrB;AACR,MAAI;AACJ,MAAI;AACF,UAAM,IAAI,IAAI,IAAI,KAAK,CAAC;AAAA,EAC1B,QAAQ;AACN,UAAM,IAAI,MAAM,GAAG,KAAK,4BAA4B;AAAA,EACtD;AAEA,MAAI,IAAI,aAAa,UAAU;AAC7B,UAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB;AAAA,EAC3C;AACA,MAAI,IAAI,YAAY,IAAI,UAAU;AAChC,UAAM,IAAI,MAAM,GAAG,KAAK,+BAA+B;AAAA,EACzD;AACA,MAAI,IAAI,UAAU,IAAI,MAAM;AAC1B,UAAM,IAAI,MAAM,GAAG,KAAK,uCAAuC;AAAA,EACjE;AACA,MAAI,IAAI,QAAQ,IAAI,SAAS,OAAO;AAClC,UAAM,IAAI,MAAM,GAAG,KAAK,kCAAkC;AAAA,EAC5D;AAEA,QAAM,WAAW,IAAI,SAAS,YAAY,EAAE,QAAQ,OAAO,EAAE;AAC7D,MAAI,QAAQ,qBAAqB,QAAQ;AACvC,UAAM,UAAU,QAAQ,oBAAoB;AAAA,MAC1C,CAAC,WAAW,aAAa,UAAU,SAAS,SAAS,IAAI,MAAM,EAAE;AAAA,IACnE;AACA,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,GAAG,KAAK,wBAAwB;AAAA,IAClD;AAAA,EACF;AAEA,MAAI,QAAQ,mBAAmB;AAC7B,UAAM,cAAc,SAAS,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MACA,CAAC,yBAAyB,MAAM,kBAAkB,MAAM,gBAAgB,IAAI;AAAA,MAC5E,EAAE,OAAO,SAAS;AAAA,IACpB;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,cAAc,UAAuB,OAAqB;AAEjE,MAAI;AACF;AAAA,MACE;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QAAM;AAAA,QACN;AAAA,QAAM;AAAA,QACN;AAAA,QAAM;AAAA,QACN;AAAA,QAAM;AAAA,MACR;AAAA,MACA,EAAE,OAAO,SAAS;AAAA,IACpB;AAAA,EACF,QAAQ;AACN,UAAM,IAAI,MAAM,mBAAmB,QAAQ,+BAA+B;AAAA,EAC5E;AACF;AAEA,SAAS,WAAW,MAAsB;AACxC,SAAO;AACT;AAjPA,IAKM,kBAwBA;AA7BN;AAAA;AAAA;AACA;AAIA,IAAM,mBAAmB;AAwBzB,IAAM,sBAA8D;AAAA,MAClE,QAAQ;AAAA,MACR,WAAW;AAAA,IACb;AAAA;AAAA;","names":[]}
|
|
@@ -24,9 +24,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
};
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
|
|
27
|
+
// <define:__RECALL_BUILD_INFO__>
|
|
28
|
+
var define_RECALL_BUILD_INFO_default;
|
|
29
|
+
var init_define_RECALL_BUILD_INFO = __esm({
|
|
30
|
+
"<define:__RECALL_BUILD_INFO__>"() {
|
|
31
|
+
define_RECALL_BUILD_INFO_default = { sha: "494c997f5252ab6dd4806b497434e950b135a38c", built_at: "2026-09-24T20:41:24.667Z", dependencies: { "@huggingface/transformers": "4.2.0", "onnxruntime-node": "1.24.3", "better-sqlite3": "11.10.0", "sqlite-vec": "0.1.9", "@photostructure/sqlite-vec": "2.0.1" } };
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
27
35
|
export {
|
|
28
36
|
__esm,
|
|
29
37
|
__export,
|
|
30
|
-
__toCommonJS
|
|
38
|
+
__toCommonJS,
|
|
39
|
+
init_define_RECALL_BUILD_INFO,
|
|
40
|
+
define_RECALL_BUILD_INFO_default
|
|
31
41
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
42
|
+
//# sourceMappingURL=chunk-5W3CDNJ6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<define:__RECALL_BUILD_INFO__>"],"sourcesContent":["{\"sha\":\"494c997f5252ab6dd4806b497434e950b135a38c\",\"built_at\":\"2026-09-24T20:41:24.667Z\",\"dependencies\":{\"@huggingface/transformers\":\"4.2.0\",\"onnxruntime-node\":\"1.24.3\",\"better-sqlite3\":\"11.10.0\",\"sqlite-vec\":\"0.1.9\",\"@photostructure/sqlite-vec\":\"2.0.1\"}}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,yCAAC,KAAM,4CAA2C,UAAW,4BAA2B,cAAe,EAAC,6BAA4B,SAAQ,oBAAmB,UAAS,kBAAiB,WAAU,cAAa,SAAQ,8BAA6B,QAAO,EAAC;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_define_RECALL_BUILD_INFO
|
|
3
|
+
} from "./chunk-5W3CDNJ6.js";
|
|
4
|
+
|
|
5
|
+
// src/security/object.ts
|
|
6
|
+
init_define_RECALL_BUILD_INFO();
|
|
7
|
+
function defineOwn(target, key, value) {
|
|
8
|
+
Object.defineProperty(target, key, {
|
|
9
|
+
configurable: true,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
value,
|
|
12
|
+
writable: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function deleteOwn(target, key) {
|
|
16
|
+
Reflect.deleteProperty(target, key);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
defineOwn,
|
|
21
|
+
deleteOwn
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=chunk-ADWOKDF6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/security/object.ts"],"sourcesContent":["export function defineOwn<T>(\n target: Record<string, T>,\n key: string,\n value: T,\n): void {\n Object.defineProperty(target, key, {\n configurable: true,\n enumerable: true,\n value,\n writable: true,\n });\n}\n\nexport function deleteOwn(\n target: Record<string, unknown>,\n key: string,\n): void {\n Reflect.deleteProperty(target, key);\n}\n"],"mappings":";;;;;AAAA;AAAO,SAAS,UACd,QACA,KACA,OACM;AACN,SAAO,eAAe,QAAQ,KAAK;AAAA,IACjC,cAAc;AAAA,IACd,YAAY;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,EACZ,CAAC;AACH;AAEO,SAAS,UACd,QACA,KACM;AACN,UAAQ,eAAe,QAAQ,GAAG;AACpC;","names":[]}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sql
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VI6NOUXB.js";
|
|
4
|
+
import {
|
|
5
|
+
init_define_RECALL_BUILD_INFO
|
|
6
|
+
} from "./chunk-5W3CDNJ6.js";
|
|
4
7
|
|
|
5
8
|
// node_modules/drizzle-orm/sql/expressions/select.js
|
|
9
|
+
init_define_RECALL_BUILD_INFO();
|
|
6
10
|
function asc(column) {
|
|
7
11
|
return sql`${column} asc`;
|
|
8
12
|
}
|
|
@@ -14,4 +18,4 @@ export {
|
|
|
14
18
|
asc,
|
|
15
19
|
desc
|
|
16
20
|
};
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-FDIV6YFT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../node_modules/src/sql/expressions/select.ts"],"sourcesContent":["import type { AnyColumn } from '../../column.ts';\nimport type { SQL, SQLWrapper } from '../sql.ts';\nimport { sql } from '../sql.ts';\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in ascending\n * order. By the SQL standard, ascending order is the\n * default, so it is not usually necessary to specify\n * ascending sort order.\n *\n * ## Examples\n *\n * ```ts\n * // Return cars, starting with the oldest models\n * // and going in ascending order to the newest.\n * db.select().from(cars)\n * .orderBy(asc(cars.year));\n * ```\n *\n * @see desc to sort in descending order\n */\nexport function asc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} asc`;\n}\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in descending\n * order.\n *\n * ## Examples\n *\n * ```ts\n * // Select users, with the most recently created\n * // records coming first.\n * db.select().from(users)\n * .orderBy(desc(users.createdAt));\n * ```\n *\n * @see asc to sort in ascending order\n */\nexport function desc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} desc`;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../node_modules/src/sql/expressions/select.ts"],"sourcesContent":["import type { AnyColumn } from '../../column.ts';\nimport type { SQL, SQLWrapper } from '../sql.ts';\nimport { sql } from '../sql.ts';\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in ascending\n * order. By the SQL standard, ascending order is the\n * default, so it is not usually necessary to specify\n * ascending sort order.\n *\n * ## Examples\n *\n * ```ts\n * // Return cars, starting with the oldest models\n * // and going in ascending order to the newest.\n * db.select().from(cars)\n * .orderBy(asc(cars.year));\n * ```\n *\n * @see desc to sort in descending order\n */\nexport function asc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} asc`;\n}\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in descending\n * order.\n *\n * ## Examples\n *\n * ```ts\n * // Select users, with the most recently created\n * // records coming first.\n * db.select().from(users)\n * .orderBy(desc(users.createdAt));\n * ```\n *\n * @see asc to sort in ascending order\n */\nexport function desc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} desc`;\n}\n"],"mappings":";;;;;;;;AAEA;AAoBO,SAAS,IAAI,QAAqC;AACxD,SAAO,MAAM,MAAM;AACpB;AAkBO,SAAS,KAAK,QAAqC;AACzD,SAAO,MAAM,MAAM;AACpB;","names":[]}
|
|
@@ -8,12 +8,17 @@ import {
|
|
|
8
8
|
memoryEntities,
|
|
9
9
|
or,
|
|
10
10
|
sql
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-VI6NOUXB.js";
|
|
12
|
+
import {
|
|
13
|
+
init_define_RECALL_BUILD_INFO
|
|
14
|
+
} from "./chunk-5W3CDNJ6.js";
|
|
12
15
|
|
|
13
16
|
// src/graph/store.ts
|
|
17
|
+
init_define_RECALL_BUILD_INFO();
|
|
14
18
|
import { randomUUID } from "crypto";
|
|
15
19
|
|
|
16
20
|
// src/graph/normalize.ts
|
|
21
|
+
init_define_RECALL_BUILD_INFO();
|
|
17
22
|
function normalizeName(kind, raw) {
|
|
18
23
|
const trimmed = raw.trim();
|
|
19
24
|
switch (kind) {
|
|
@@ -285,4 +290,4 @@ export {
|
|
|
285
290
|
countRelations,
|
|
286
291
|
clearGraph
|
|
287
292
|
};
|
|
288
|
-
//# sourceMappingURL=chunk-
|
|
293
|
+
//# sourceMappingURL=chunk-GMRT5DJZ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graph/store.ts","../src/graph/normalize.ts"],"sourcesContent":["/**\n * Read/write layer for the knowledge graph tables. Pure DB operations —\n * no LLM calls, no business logic — so they're safe to call from any\n * code path (capture hook, dispatcher, scan, MCP tool).\n */\nimport { randomUUID } from \"node:crypto\";\nimport { and, eq, inArray, like, or, sql } from \"drizzle-orm\";\nimport type { RecallDb } from \"../db/client.js\";\nimport { entities, entityRelations, memoryEntities } from \"../db/schema.js\";\nimport { normalizeName, type EntityKind } from \"./normalize.js\";\n\nexport type RelationType =\n | \"uses\"\n | \"replaces\"\n | \"conflicts_with\"\n | \"tested_by\"\n | \"depends_on\"\n | \"references\"\n | \"part_of\";\n\nexport interface EntityRow {\n id: string;\n kind: EntityKind;\n name: string;\n normalized_name: string;\n repo: string | null;\n description: string | null;\n mention_count: number;\n first_seen_memory_id: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface EntityRelationRow {\n id: string;\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id: string | null;\n confidence: number;\n created_at: string;\n}\n\nexport interface UpsertEntityInput {\n kind: EntityKind;\n name: string;\n repo?: string | null;\n description?: string | null;\n first_seen_memory_id?: string | null;\n}\n\n/**\n * Insert or look up an entity by (kind, normalized_name, repo). Returns the\n * canonical row. Increments mention_count on every call so we can rank\n * entities by how often the codebase mentions them.\n */\nexport function upsertEntity(db: RecallDb, input: UpsertEntityInput): EntityRow {\n const normalized = normalizeName(input.kind, input.name);\n const repo = input.repo ?? null;\n const now = new Date().toISOString();\n\n const existing = findEntityByNormalized(db, input.kind, normalized, repo);\n if (existing) {\n db.update(entities)\n .set({\n mention_count: existing.mention_count + 1,\n updated_at: now,\n // Backfill description / first_seen if not previously set.\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n })\n .where(eq(entities.id, existing.id))\n .run();\n return {\n ...existing,\n mention_count: existing.mention_count + 1,\n updated_at: now,\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n };\n }\n\n const id = randomUUID();\n db.insert(entities)\n .values({\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n mention_count: 1,\n created_at: now,\n updated_at: now,\n })\n .run();\n return {\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n mention_count: 1,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n created_at: now,\n updated_at: now,\n };\n}\n\nexport function findEntityByNormalized(\n db: RecallDb,\n kind: EntityKind,\n normalized: string,\n repo: string | null,\n): EntityRow | null {\n const row = db\n .select()\n .from(entities)\n .where(\n and(\n eq(entities.kind, kind),\n eq(entities.normalized_name, normalized),\n repo === null\n ? sql`${entities.repo} IS NULL`\n : eq(entities.repo, repo),\n ),\n )\n .get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport function getEntity(db: RecallDb, id: string): EntityRow | null {\n const row = db.select().from(entities).where(eq(entities.id, id)).get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport interface ListEntitiesOptions {\n repo?: string;\n kind?: EntityKind;\n search?: string;\n limit?: number;\n offset?: number;\n}\n\nexport function listEntities(db: RecallDb, opts: ListEntitiesOptions = {}): EntityRow[] {\n const conditions = [] as Array<ReturnType<typeof eq> | ReturnType<typeof or>>;\n if (opts.repo) conditions.push(eq(entities.repo, opts.repo));\n if (opts.kind) conditions.push(eq(entities.kind, opts.kind));\n if (opts.search) {\n // Push the contains-match into SQL so LIMIT applies post-filter; the\n // previous in-memory filter only saw the top-N by mention_count and\n // missed long-tail matches entirely.\n const needle = `%${opts.search.toLowerCase()}%`;\n conditions.push(\n or(\n like(entities.normalized_name, needle),\n like(sql`lower(${entities.name})`, needle),\n )!,\n );\n }\n const where = conditions.length === 1 ? conditions[0] : conditions.length > 1 ? and(...conditions) : undefined;\n const builder = where\n ? db.select().from(entities).where(where)\n : db.select().from(entities);\n return builder\n .orderBy(sql`${entities.mention_count} DESC`)\n .limit(opts.limit ?? 200)\n .offset(opts.offset ?? 0)\n .all() as EntityRow[];\n}\n\nexport interface LinkMemoryEntityInput {\n memory_id: string;\n entity_id: string;\n source: \"heuristic\" | \"llm\" | \"manual\";\n weight?: number;\n}\n\n/** Idempotent: links a memory to an entity, no-op if the edge already exists. */\nexport function linkMemoryToEntity(db: RecallDb, input: LinkMemoryEntityInput): void {\n const existing = db\n .select({ id: memoryEntities.id })\n .from(memoryEntities)\n .where(\n and(\n eq(memoryEntities.memory_id, input.memory_id),\n eq(memoryEntities.entity_id, input.entity_id),\n ),\n )\n .get();\n if (existing) return;\n db.insert(memoryEntities)\n .values({\n id: randomUUID(),\n memory_id: input.memory_id,\n entity_id: input.entity_id,\n source: input.source,\n weight: input.weight ?? 1,\n created_at: new Date().toISOString(),\n })\n .run();\n}\n\nexport function listEntitiesForMemory(db: RecallDb, memoryId: string): EntityRow[] {\n return db\n .select({\n id: entities.id,\n kind: entities.kind,\n name: entities.name,\n normalized_name: entities.normalized_name,\n repo: entities.repo,\n description: entities.description,\n mention_count: entities.mention_count,\n first_seen_memory_id: entities.first_seen_memory_id,\n created_at: entities.created_at,\n updated_at: entities.updated_at,\n })\n .from(memoryEntities)\n .innerJoin(entities, eq(entities.id, memoryEntities.entity_id))\n .where(eq(memoryEntities.memory_id, memoryId))\n .all() as EntityRow[];\n}\n\nexport function listMemoryIdsForEntity(db: RecallDb, entityId: string): string[] {\n const rows = db\n .select({ memory_id: memoryEntities.memory_id })\n .from(memoryEntities)\n .where(eq(memoryEntities.entity_id, entityId))\n .all();\n return rows.map((r) => r.memory_id);\n}\n\nexport interface UpsertRelationInput {\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id?: string | null;\n confidence?: number;\n}\n\n/** Idempotent on (source, target, relation_type, source_memory_id). */\nexport function upsertRelation(db: RecallDb, input: UpsertRelationInput): EntityRelationRow {\n const sourceMem = input.source_memory_id ?? null;\n const existing = db\n .select()\n .from(entityRelations)\n .where(\n and(\n eq(entityRelations.source_entity_id, input.source_entity_id),\n eq(entityRelations.target_entity_id, input.target_entity_id),\n eq(entityRelations.relation_type, input.relation_type),\n sourceMem === null\n ? sql`${entityRelations.source_memory_id} IS NULL`\n : eq(entityRelations.source_memory_id, sourceMem),\n ),\n )\n .get() as EntityRelationRow | undefined;\n if (existing) {\n if (input.confidence !== undefined && input.confidence > existing.confidence) {\n db.update(entityRelations)\n .set({ confidence: input.confidence })\n .where(eq(entityRelations.id, existing.id))\n .run();\n return { ...existing, confidence: input.confidence };\n }\n return existing;\n }\n const id = randomUUID();\n const now = new Date().toISOString();\n db.insert(entityRelations)\n .values({\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n })\n .run();\n return {\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n };\n}\n\nexport function neighborsOf(\n db: RecallDb,\n entityId: string,\n options: { hops?: number; relationTypes?: RelationType[] } = {},\n): { entities: EntityRow[]; relations: EntityRelationRow[] } {\n const maxHops = Math.max(1, Math.min(5, options.hops ?? 1));\n const visited = new Set<string>([entityId]);\n let frontier = [entityId];\n const collectedRelations = new Map<string, EntityRelationRow>();\n\n for (let hop = 0; hop < maxHops; hop++) {\n if (frontier.length === 0) break;\n const next: string[] = [];\n const relationFilter = options.relationTypes;\n const outgoing = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.source_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.source_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n const incoming = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.target_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.target_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n\n for (const rel of [...outgoing, ...incoming]) {\n collectedRelations.set(rel.id, rel);\n for (const candidate of [rel.source_entity_id, rel.target_entity_id]) {\n if (!visited.has(candidate)) {\n visited.add(candidate);\n next.push(candidate);\n }\n }\n }\n frontier = next;\n }\n\n const entityRows = visited.size === 0\n ? []\n : (db\n .select()\n .from(entities)\n .where(inArray(entities.id, Array.from(visited)))\n .all() as EntityRow[]);\n\n return {\n entities: entityRows,\n relations: Array.from(collectedRelations.values()),\n };\n}\n\n/**\n * List every relation in the graph, optionally restricted to relations\n * whose source AND target entities both belong to the given repo. Used by\n * the WebUI to render the whole graph at once (no seed required).\n */\nexport function listAllRelations(\n db: RecallDb,\n opts: { repo?: string; limit?: number } = {},\n): EntityRelationRow[] {\n const limit = Math.min(Math.max(opts.limit ?? 2000, 1), 10_000);\n if (!opts.repo) {\n return db\n .select()\n .from(entityRelations)\n .limit(limit)\n .all() as EntityRelationRow[];\n }\n // Filter both endpoints to entities in the repo. Two-step: collect ids,\n // then pick relations whose endpoints are both inside that set.\n const repoEntityIds = db\n .select({ id: entities.id })\n .from(entities)\n .where(eq(entities.repo, opts.repo))\n .all()\n .map((r) => r.id);\n if (repoEntityIds.length === 0) return [];\n const idSet = new Set(repoEntityIds);\n const all = db\n .select()\n .from(entityRelations)\n .where(\n and(\n inArray(entityRelations.source_entity_id, repoEntityIds),\n inArray(entityRelations.target_entity_id, repoEntityIds),\n ),\n )\n .limit(limit)\n .all() as EntityRelationRow[];\n return all.filter(\n (r) => idSet.has(r.source_entity_id) && idSet.has(r.target_entity_id),\n );\n}\n\nexport function countEntities(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entities)\n .get();\n return Number(row?.c ?? 0);\n}\n\nexport function countRelations(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entityRelations)\n .get();\n return Number(row?.c ?? 0);\n}\n\n/**\n * Wipe all graph state (entities, relations, and memory→entity links). Used\n * by `graph backfill --rebuild` to regenerate the graph from scratch under\n * the current extraction rules, dropping entities that older/looser rules\n * produced (e.g. generic `pnpm build` command nodes).\n */\nexport function clearGraph(db: RecallDb): void {\n db.delete(memoryEntities).run();\n db.delete(entityRelations).run();\n db.delete(entities).run();\n}\n","/**\n * Canonical-form helpers for entity dedup. Two entities with the same\n * (kind, normalizedName, repo) collapse into one node.\n *\n * Normalization rules are conservative on purpose — we'd rather have a\n * duplicate than merge two semantically distinct things. Aggressive\n * merging belongs in a maintenance pass that can be reviewed.\n */\n\nexport type EntityKind =\n | \"file\"\n | \"function\"\n | \"library\"\n | \"tool\"\n | \"concept\"\n | \"repo_path\"\n | \"command\"\n | \"url\";\n\nexport function normalizeName(kind: EntityKind, raw: string): string {\n const trimmed = raw.trim();\n switch (kind) {\n case \"file\":\n case \"repo_path\":\n // Posix-style paths, no leading slash, no trailing slash.\n return trimmed\n .replace(/\\\\/g, \"/\")\n .replace(/^[./]+/, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n case \"function\":\n // foo() / Class.method / obj.method — keep the dotted form, drop parens/args.\n return trimmed\n .replace(/\\(.*\\)/, \"\")\n .replace(/\\s+/g, \"\")\n .toLowerCase();\n case \"library\":\n case \"tool\":\n case \"command\":\n // package names / CLI names: lowercase, strip @scope leading-only if present\n // but keep `@scope/name` distinct from `name`.\n return trimmed.toLowerCase();\n case \"url\":\n try {\n const u = new URL(trimmed);\n return `${u.hostname.toLowerCase()}${u.pathname.replace(/\\/+$/, \"\")}`;\n } catch {\n return trimmed.toLowerCase();\n }\n case \"concept\":\n default:\n return trimmed.toLowerCase().replace(/\\s+/g, \" \");\n }\n}\n\nexport function isPlausibleEntityName(kind: EntityKind, name: string): boolean {\n const n = name.trim();\n if (n.length === 0 || n.length > 200) return false;\n // Filter common false positives that look like identifiers but aren't.\n if (/^[0-9]+$/.test(n)) return false;\n if (kind === \"concept\" && n.split(/\\s+/).length > 8) return false;\n // Single-letter \"library\" tokens are almost always noise.\n if ((kind === \"library\" || kind === \"tool\") && n.length < 2) return false;\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,SAAS,kBAAkB;;;ACcpB,SAAS,cAAc,MAAkB,KAAqB;AACnE,QAAM,UAAU,IAAI,KAAK;AACzB,UAAQ,MAAM;AAAA,IACZ,KAAK;AAAA,IACL,KAAK;AAEH,aAAO,QACJ,QAAQ,OAAO,GAAG,EAClB,QAAQ,UAAU,EAAE,EACpB,QAAQ,QAA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C,MAAM,EAAE,EAAE;AAClB,MAAI,cAAc,WAAW,EAAG,QAAO,CAAC;AACxC,QAAM,QAAQ,IAAI,IAAI,aAAa;AACnC,QAAM,MAAM,GACT,OAAO,EACP,KAAK,eAAe,EACpB;AAAA,IACC;AAAA,MACE,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,MACvD,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,IACzD;AAAA,EACF,EACC,MAAM,KAAK,EACX,IAAI;AACP,SAAO,IAAI;AAAA,IACT,CAAC,MAAM,MAAM,IAAI,EAAE,gBAAgB,KAAK,MAAM,IAAI,EAAE,gBAAgB;AAAA,EACtE;AACF;AAEO,SAAS,cAAc,IAAsB;AAClD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,QAAQ,EACb,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAEO,SAAS,eAAe,IAAsB;AACnD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,eAAe,EACpB,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAQO,SAAS,WAAW,IAAoB;AAC7C,KAAG,OAAO,cAAc,EAAE,IAAI;AAC9B,KAAG,OAAO,eAAe,EAAE,IAAI;AAC/B,KAAG,OAAO,QAAQ,EAAE,IAAI;AAC1B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/graph/store.ts","../src/graph/normalize.ts"],"sourcesContent":["/**\n * Read/write layer for the knowledge graph tables. Pure DB operations —\n * no LLM calls, no business logic — so they're safe to call from any\n * code path (capture hook, dispatcher, scan, MCP tool).\n */\nimport { randomUUID } from \"node:crypto\";\nimport { and, eq, inArray, like, or, sql } from \"drizzle-orm\";\nimport type { RecallDb } from \"../db/client.js\";\nimport { entities, entityRelations, memoryEntities } from \"../db/schema.js\";\nimport { normalizeName, type EntityKind } from \"./normalize.js\";\n\nexport type RelationType =\n | \"uses\"\n | \"replaces\"\n | \"conflicts_with\"\n | \"tested_by\"\n | \"depends_on\"\n | \"references\"\n | \"part_of\";\n\nexport interface EntityRow {\n id: string;\n kind: EntityKind;\n name: string;\n normalized_name: string;\n repo: string | null;\n description: string | null;\n mention_count: number;\n first_seen_memory_id: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface EntityRelationRow {\n id: string;\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id: string | null;\n confidence: number;\n created_at: string;\n}\n\nexport interface UpsertEntityInput {\n kind: EntityKind;\n name: string;\n repo?: string | null;\n description?: string | null;\n first_seen_memory_id?: string | null;\n}\n\n/**\n * Insert or look up an entity by (kind, normalized_name, repo). Returns the\n * canonical row. Increments mention_count on every call so we can rank\n * entities by how often the codebase mentions them.\n */\nexport function upsertEntity(db: RecallDb, input: UpsertEntityInput): EntityRow {\n const normalized = normalizeName(input.kind, input.name);\n const repo = input.repo ?? null;\n const now = new Date().toISOString();\n\n const existing = findEntityByNormalized(db, input.kind, normalized, repo);\n if (existing) {\n db.update(entities)\n .set({\n mention_count: existing.mention_count + 1,\n updated_at: now,\n // Backfill description / first_seen if not previously set.\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n })\n .where(eq(entities.id, existing.id))\n .run();\n return {\n ...existing,\n mention_count: existing.mention_count + 1,\n updated_at: now,\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n };\n }\n\n const id = randomUUID();\n db.insert(entities)\n .values({\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n mention_count: 1,\n created_at: now,\n updated_at: now,\n })\n .run();\n return {\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n mention_count: 1,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n created_at: now,\n updated_at: now,\n };\n}\n\nexport function findEntityByNormalized(\n db: RecallDb,\n kind: EntityKind,\n normalized: string,\n repo: string | null,\n): EntityRow | null {\n const row = db\n .select()\n .from(entities)\n .where(\n and(\n eq(entities.kind, kind),\n eq(entities.normalized_name, normalized),\n repo === null\n ? sql`${entities.repo} IS NULL`\n : eq(entities.repo, repo),\n ),\n )\n .get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport function getEntity(db: RecallDb, id: string): EntityRow | null {\n const row = db.select().from(entities).where(eq(entities.id, id)).get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport interface ListEntitiesOptions {\n repo?: string;\n kind?: EntityKind;\n search?: string;\n limit?: number;\n offset?: number;\n}\n\nexport function listEntities(db: RecallDb, opts: ListEntitiesOptions = {}): EntityRow[] {\n const conditions = [] as Array<ReturnType<typeof eq> | ReturnType<typeof or>>;\n if (opts.repo) conditions.push(eq(entities.repo, opts.repo));\n if (opts.kind) conditions.push(eq(entities.kind, opts.kind));\n if (opts.search) {\n // Push the contains-match into SQL so LIMIT applies post-filter; the\n // previous in-memory filter only saw the top-N by mention_count and\n // missed long-tail matches entirely.\n const needle = `%${opts.search.toLowerCase()}%`;\n conditions.push(\n or(\n like(entities.normalized_name, needle),\n like(sql`lower(${entities.name})`, needle),\n )!,\n );\n }\n const where = conditions.length === 1 ? conditions[0] : conditions.length > 1 ? and(...conditions) : undefined;\n const builder = where\n ? db.select().from(entities).where(where)\n : db.select().from(entities);\n return builder\n .orderBy(sql`${entities.mention_count} DESC`)\n .limit(opts.limit ?? 200)\n .offset(opts.offset ?? 0)\n .all() as EntityRow[];\n}\n\nexport interface LinkMemoryEntityInput {\n memory_id: string;\n entity_id: string;\n source: \"heuristic\" | \"llm\" | \"manual\";\n weight?: number;\n}\n\n/** Idempotent: links a memory to an entity, no-op if the edge already exists. */\nexport function linkMemoryToEntity(db: RecallDb, input: LinkMemoryEntityInput): void {\n const existing = db\n .select({ id: memoryEntities.id })\n .from(memoryEntities)\n .where(\n and(\n eq(memoryEntities.memory_id, input.memory_id),\n eq(memoryEntities.entity_id, input.entity_id),\n ),\n )\n .get();\n if (existing) return;\n db.insert(memoryEntities)\n .values({\n id: randomUUID(),\n memory_id: input.memory_id,\n entity_id: input.entity_id,\n source: input.source,\n weight: input.weight ?? 1,\n created_at: new Date().toISOString(),\n })\n .run();\n}\n\nexport function listEntitiesForMemory(db: RecallDb, memoryId: string): EntityRow[] {\n return db\n .select({\n id: entities.id,\n kind: entities.kind,\n name: entities.name,\n normalized_name: entities.normalized_name,\n repo: entities.repo,\n description: entities.description,\n mention_count: entities.mention_count,\n first_seen_memory_id: entities.first_seen_memory_id,\n created_at: entities.created_at,\n updated_at: entities.updated_at,\n })\n .from(memoryEntities)\n .innerJoin(entities, eq(entities.id, memoryEntities.entity_id))\n .where(eq(memoryEntities.memory_id, memoryId))\n .all() as EntityRow[];\n}\n\nexport function listMemoryIdsForEntity(db: RecallDb, entityId: string): string[] {\n const rows = db\n .select({ memory_id: memoryEntities.memory_id })\n .from(memoryEntities)\n .where(eq(memoryEntities.entity_id, entityId))\n .all();\n return rows.map((r) => r.memory_id);\n}\n\nexport interface UpsertRelationInput {\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id?: string | null;\n confidence?: number;\n}\n\n/** Idempotent on (source, target, relation_type, source_memory_id). */\nexport function upsertRelation(db: RecallDb, input: UpsertRelationInput): EntityRelationRow {\n const sourceMem = input.source_memory_id ?? null;\n const existing = db\n .select()\n .from(entityRelations)\n .where(\n and(\n eq(entityRelations.source_entity_id, input.source_entity_id),\n eq(entityRelations.target_entity_id, input.target_entity_id),\n eq(entityRelations.relation_type, input.relation_type),\n sourceMem === null\n ? sql`${entityRelations.source_memory_id} IS NULL`\n : eq(entityRelations.source_memory_id, sourceMem),\n ),\n )\n .get() as EntityRelationRow | undefined;\n if (existing) {\n if (input.confidence !== undefined && input.confidence > existing.confidence) {\n db.update(entityRelations)\n .set({ confidence: input.confidence })\n .where(eq(entityRelations.id, existing.id))\n .run();\n return { ...existing, confidence: input.confidence };\n }\n return existing;\n }\n const id = randomUUID();\n const now = new Date().toISOString();\n db.insert(entityRelations)\n .values({\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n })\n .run();\n return {\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n };\n}\n\nexport function neighborsOf(\n db: RecallDb,\n entityId: string,\n options: { hops?: number; relationTypes?: RelationType[] } = {},\n): { entities: EntityRow[]; relations: EntityRelationRow[] } {\n const maxHops = Math.max(1, Math.min(5, options.hops ?? 1));\n const visited = new Set<string>([entityId]);\n let frontier = [entityId];\n const collectedRelations = new Map<string, EntityRelationRow>();\n\n for (let hop = 0; hop < maxHops; hop++) {\n if (frontier.length === 0) break;\n const next: string[] = [];\n const relationFilter = options.relationTypes;\n const outgoing = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.source_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.source_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n const incoming = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.target_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.target_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n\n for (const rel of [...outgoing, ...incoming]) {\n collectedRelations.set(rel.id, rel);\n for (const candidate of [rel.source_entity_id, rel.target_entity_id]) {\n if (!visited.has(candidate)) {\n visited.add(candidate);\n next.push(candidate);\n }\n }\n }\n frontier = next;\n }\n\n const entityRows = visited.size === 0\n ? []\n : (db\n .select()\n .from(entities)\n .where(inArray(entities.id, Array.from(visited)))\n .all() as EntityRow[]);\n\n return {\n entities: entityRows,\n relations: Array.from(collectedRelations.values()),\n };\n}\n\n/**\n * List every relation in the graph, optionally restricted to relations\n * whose source AND target entities both belong to the given repo. Used by\n * the WebUI to render the whole graph at once (no seed required).\n */\nexport function listAllRelations(\n db: RecallDb,\n opts: { repo?: string; limit?: number } = {},\n): EntityRelationRow[] {\n const limit = Math.min(Math.max(opts.limit ?? 2000, 1), 10_000);\n if (!opts.repo) {\n return db\n .select()\n .from(entityRelations)\n .limit(limit)\n .all() as EntityRelationRow[];\n }\n // Filter both endpoints to entities in the repo. Two-step: collect ids,\n // then pick relations whose endpoints are both inside that set.\n const repoEntityIds = db\n .select({ id: entities.id })\n .from(entities)\n .where(eq(entities.repo, opts.repo))\n .all()\n .map((r) => r.id);\n if (repoEntityIds.length === 0) return [];\n const idSet = new Set(repoEntityIds);\n const all = db\n .select()\n .from(entityRelations)\n .where(\n and(\n inArray(entityRelations.source_entity_id, repoEntityIds),\n inArray(entityRelations.target_entity_id, repoEntityIds),\n ),\n )\n .limit(limit)\n .all() as EntityRelationRow[];\n return all.filter(\n (r) => idSet.has(r.source_entity_id) && idSet.has(r.target_entity_id),\n );\n}\n\nexport function countEntities(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entities)\n .get();\n return Number(row?.c ?? 0);\n}\n\nexport function countRelations(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entityRelations)\n .get();\n return Number(row?.c ?? 0);\n}\n\n/**\n * Wipe all graph state (entities, relations, and memory→entity links). Used\n * by `graph backfill --rebuild` to regenerate the graph from scratch under\n * the current extraction rules, dropping entities that older/looser rules\n * produced (e.g. generic `pnpm build` command nodes).\n */\nexport function clearGraph(db: RecallDb): void {\n db.delete(memoryEntities).run();\n db.delete(entityRelations).run();\n db.delete(entities).run();\n}\n","/**\n * Canonical-form helpers for entity dedup. Two entities with the same\n * (kind, normalizedName, repo) collapse into one node.\n *\n * Normalization rules are conservative on purpose — we'd rather have a\n * duplicate than merge two semantically distinct things. Aggressive\n * merging belongs in a maintenance pass that can be reviewed.\n */\n\nexport type EntityKind =\n | \"file\"\n | \"function\"\n | \"library\"\n | \"tool\"\n | \"concept\"\n | \"repo_path\"\n | \"command\"\n | \"url\";\n\nexport function normalizeName(kind: EntityKind, raw: string): string {\n const trimmed = raw.trim();\n switch (kind) {\n case \"file\":\n case \"repo_path\":\n // Posix-style paths, no leading slash, no trailing slash.\n return trimmed\n .replace(/\\\\/g, \"/\")\n .replace(/^[./]+/, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n case \"function\":\n // foo() / Class.method / obj.method — keep the dotted form, drop parens/args.\n return trimmed\n .replace(/\\(.*\\)/, \"\")\n .replace(/\\s+/g, \"\")\n .toLowerCase();\n case \"library\":\n case \"tool\":\n case \"command\":\n // package names / CLI names: lowercase, strip @scope leading-only if present\n // but keep `@scope/name` distinct from `name`.\n return trimmed.toLowerCase();\n case \"url\":\n try {\n const u = new URL(trimmed);\n return `${u.hostname.toLowerCase()}${u.pathname.replace(/\\/+$/, \"\")}`;\n } catch {\n return trimmed.toLowerCase();\n }\n case \"concept\":\n default:\n return trimmed.toLowerCase().replace(/\\s+/g, \" \");\n }\n}\n\nexport function isPlausibleEntityName(kind: EntityKind, name: string): boolean {\n const n = name.trim();\n if (n.length === 0 || n.length > 200) return false;\n // Filter common false positives that look like identifiers but aren't.\n if (/^[0-9]+$/.test(n)) return false;\n if (kind === \"concept\" && n.split(/\\s+/).length > 8) return false;\n // Single-letter \"library\" tokens are almost always noise.\n if ((kind === \"library\" || kind === \"tool\") && n.length < 2) return false;\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAKA,SAAS,kBAAkB;;;ACL3B;AAmBO,SAAS,cAAc,MAAkB,KAAqB;AACnE,QAAM,UAAU,IAAI,KAAK;AACzB,UAAQ,MAAM;AAAA,IACZ,KAAK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C,EAC1B,KAAK,QAAQ,EACb,MAAM,GAAG,SAAS,MAAM,KAAK,IAAI,CAAC,EAClC,IAAI,EACJ,IAAI,CAAC,MAAM,EAAE,EAAE;AAClB,MAAI,cAAc,WAAW,EAAG,QAAO,CAAC;AACxC,QAAM,QAAQ,IAAI,IAAI,aAAa;AACnC,QAAM,MAAM,GACT,OAAO,EACP,KAAK,eAAe,EACpB;AAAA,IACC;AAAA,MACE,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,MACvD,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,IACzD;AAAA,EACF,EACC,MAAM,KAAK,EACX,IAAI;AACP,SAAO,IAAI;AAAA,IACT,CAAC,MAAM,MAAM,IAAI,EAAE,gBAAgB,KAAK,MAAM,IAAI,EAAE,gBAAgB;AAAA,EACtE;AACF;AAEO,SAAS,cAAc,IAAsB;AAClD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,QAAQ,EACb,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAEO,SAAS,eAAe,IAAsB;AACnD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,eAAe,EACpB,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAQO,SAAS,WAAW,IAAoB;AAC7C,KAAG,OAAO,cAAc,EAAE,IAAI;AAC9B,KAAG,OAAO,eAAe,EAAE,IAAI;AAC/B,KAAG,OAAO,QAAQ,EAAE,IAAI;AAC1B;","names":[]}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_define_RECALL_BUILD_INFO
|
|
3
|
+
} from "./chunk-5W3CDNJ6.js";
|
|
4
|
+
|
|
1
5
|
// src/observability/sentry.ts
|
|
6
|
+
init_define_RECALL_BUILD_INFO();
|
|
2
7
|
import * as Sentry from "@sentry/node";
|
|
3
8
|
var initialized = false;
|
|
4
9
|
function initSentry() {
|
|
@@ -21,9 +26,10 @@ function initSentry() {
|
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
// src/observability/instrument.ts
|
|
29
|
+
init_define_RECALL_BUILD_INFO();
|
|
24
30
|
initSentry();
|
|
25
31
|
|
|
26
32
|
export {
|
|
27
33
|
Sentry
|
|
28
34
|
};
|
|
29
|
-
//# sourceMappingURL=chunk-
|
|
35
|
+
//# sourceMappingURL=chunk-IMCI2CLJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/observability/sentry.ts","../src/observability/instrument.ts"],"sourcesContent":["/**\n * Optional, opt-in Sentry error reporting.\n *\n * Errors and crashes only — no performance tracing, no profiling, no session\n * replay, no default PII. The DSN comes exclusively from the `SENTRY_DSN`\n * environment variable; when it is empty or unset, {@link initSentry} is a hard\n * no-op and `Sentry.init` is never called, so the SDK sends nothing off-box.\n *\n * Recall is public OSS: community installs never phone home unless the operator\n * explicitly sets `SENTRY_DSN`. The DSN is intentionally NOT baked into source.\n *\n * The `@sentry/node` SDK installs its own `onUncaughtException` /\n * `onUnhandledRejection` handlers by default once initialized, so unhandled\n * crashes in a long-running process (daemon, sync server, MCP server) are\n * captured automatically.\n */\n\nimport * as Sentry from \"@sentry/node\";\n\nlet initialized = false;\n\n/**\n * Initialize Sentry iff `SENTRY_DSN` is set. Safe (and cheap) to call once at\n * each entrypoint's first side-effect. Returns whether Sentry was initialized.\n */\nexport function initSentry(): boolean {\n if (initialized) return true;\n\n const dsn = process.env.SENTRY_DSN?.trim();\n // Hard no-op without a DSN — the critical OSS guarantee. No init, no network.\n if (!dsn) return false;\n\n const environment =\n process.env.RECALL_ENV?.trim() ||\n process.env.NODE_ENV?.trim() ||\n \"production\";\n\n Sentry.init({\n dsn,\n environment,\n // Errors/crashes only — no performance traffic.\n tracesSampleRate: 0,\n // No profiling, no replay: keep only the error integrations.\n profilesSampleRate: 0,\n // Don't attach client IP, cookies, or any user identity.\n sendDefaultPii: false,\n });\n\n initialized = true;\n return true;\n}\n\nexport { Sentry };\n","/**\n * Side-effecting Sentry bootstrap.\n *\n * Import this FIRST — before any other module — at each long-running or\n * user-facing entrypoint so Sentry (if, and only if, `SENTRY_DSN` is set)\n * installs its error handlers before any other code runs:\n *\n * import \"./observability/instrument.js\";\n *\n * With `SENTRY_DSN` unset this is a hard no-op: no init, no network. See\n * {@link ./sentry.ts} for the full opt-in contract.\n */\n\nimport { initSentry } from \"./sentry.js\";\n\ninitSentry();\n"],"mappings":";AAiBA,YAAY,YAAY;AAExB,IAAI,cAAc;AAMX,SAAS,aAAsB;AACpC,MAAI,YAAa,QAAO;AAExB,QAAM,MAAM,QAAQ,IAAI,YAAY,KAAK;AAEzC,MAAI,CAAC,IAAK,QAAO;AAEjB,QAAM,cACJ,QAAQ,IAAI,YAAY,KAAK,KAC7B,QAAQ,IAAI,UAAU,KAAK,KAC3B;AAEF,EAAO,YAAK;AAAA,IACV;AAAA,IACA;AAAA;AAAA,IAEA,kBAAkB;AAAA;AAAA,IAElB,oBAAoB;AAAA;AAAA,IAEpB,gBAAgB;AAAA,EAClB,CAAC;AAED,gBAAc;AACd,SAAO;AACT;;;
|
|
1
|
+
{"version":3,"sources":["../src/observability/sentry.ts","../src/observability/instrument.ts"],"sourcesContent":["/**\n * Optional, opt-in Sentry error reporting.\n *\n * Errors and crashes only — no performance tracing, no profiling, no session\n * replay, no default PII. The DSN comes exclusively from the `SENTRY_DSN`\n * environment variable; when it is empty or unset, {@link initSentry} is a hard\n * no-op and `Sentry.init` is never called, so the SDK sends nothing off-box.\n *\n * Recall is public OSS: community installs never phone home unless the operator\n * explicitly sets `SENTRY_DSN`. The DSN is intentionally NOT baked into source.\n *\n * The `@sentry/node` SDK installs its own `onUncaughtException` /\n * `onUnhandledRejection` handlers by default once initialized, so unhandled\n * crashes in a long-running process (daemon, sync server, MCP server) are\n * captured automatically.\n */\n\nimport * as Sentry from \"@sentry/node\";\n\nlet initialized = false;\n\n/**\n * Initialize Sentry iff `SENTRY_DSN` is set. Safe (and cheap) to call once at\n * each entrypoint's first side-effect. Returns whether Sentry was initialized.\n */\nexport function initSentry(): boolean {\n if (initialized) return true;\n\n const dsn = process.env.SENTRY_DSN?.trim();\n // Hard no-op without a DSN — the critical OSS guarantee. No init, no network.\n if (!dsn) return false;\n\n const environment =\n process.env.RECALL_ENV?.trim() ||\n process.env.NODE_ENV?.trim() ||\n \"production\";\n\n Sentry.init({\n dsn,\n environment,\n // Errors/crashes only — no performance traffic.\n tracesSampleRate: 0,\n // No profiling, no replay: keep only the error integrations.\n profilesSampleRate: 0,\n // Don't attach client IP, cookies, or any user identity.\n sendDefaultPii: false,\n });\n\n initialized = true;\n return true;\n}\n\nexport { Sentry };\n","/**\n * Side-effecting Sentry bootstrap.\n *\n * Import this FIRST — before any other module — at each long-running or\n * user-facing entrypoint so Sentry (if, and only if, `SENTRY_DSN` is set)\n * installs its error handlers before any other code runs:\n *\n * import \"./observability/instrument.js\";\n *\n * With `SENTRY_DSN` unset this is a hard no-op: no init, no network. See\n * {@link ./sentry.ts} for the full opt-in contract.\n */\n\nimport { initSentry } from \"./sentry.js\";\n\ninitSentry();\n"],"mappings":";;;;;AAAA;AAiBA,YAAY,YAAY;AAExB,IAAI,cAAc;AAMX,SAAS,aAAsB;AACpC,MAAI,YAAa,QAAO;AAExB,QAAM,MAAM,QAAQ,IAAI,YAAY,KAAK;AAEzC,MAAI,CAAC,IAAK,QAAO;AAEjB,QAAM,cACJ,QAAQ,IAAI,YAAY,KAAK,KAC7B,QAAQ,IAAI,UAAU,KAAK,KAC3B;AAEF,EAAO,YAAK;AAAA,IACV;AAAA,IACA;AAAA;AAAA,IAEA,kBAAkB;AAAA;AAAA,IAElB,oBAAoB;AAAA;AAAA,IAEpB,gBAAgB;AAAA,EAClB,CAAC;AAED,gBAAc;AACd,SAAO;AACT;;;AClDA;AAeA,WAAW;","names":[]}
|