@remnic/core 9.3.532 → 9.3.534
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-cli.js +5 -5
- package/dist/access-http.d.ts +1 -1
- package/dist/access-mcp.d.ts +1 -1
- package/dist/access-service.d.ts +1 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/{chunk-CWWMTTQE.js → chunk-6GUG4YNM.js} +44 -1
- package/dist/{chunk-CWWMTTQE.js.map → chunk-6GUG4YNM.js.map} +1 -1
- package/dist/{chunk-QRMZX3PR.js → chunk-KLZDGMDI.js} +5 -5
- package/dist/{chunk-KCLX6LOV.js → chunk-SRAF4TIS.js} +4 -4
- package/dist/{chunk-BECQDWBA.js → chunk-TQNRI55H.js} +35 -2
- package/dist/chunk-TQNRI55H.js.map +1 -0
- package/dist/{chunk-QMYXNM4P.js → chunk-VU3SVYMA.js} +3 -3
- package/dist/{cli-CPe_2KB1.d.ts → cli-9pwA_PXm.d.ts} +1 -1
- package/dist/cli.d.ts +3 -3
- package/dist/cli.js +3 -3
- package/dist/{connectors-cli-DbTPNj2H.d.ts → connectors-cli-2iaQ5tX2.d.ts} +1 -1
- package/dist/connectors-cli.d.ts +2 -2
- package/dist/explicit-capture.d.ts +1 -1
- package/dist/{framework-CyHYDcri.d.ts → framework-CNDn2164.d.ts} +24 -7
- package/dist/index.d.ts +4 -4
- package/dist/index.js +18 -14
- package/dist/index.js.map +1 -1
- package/dist/live-connectors-runner.d.ts +1 -1
- package/dist/live-connectors-runner.js +3 -3
- package/dist/mcp-memory-inspector-app.d.ts +1 -1
- package/dist/orchestrator.d.ts +1 -1
- package/dist/orchestrator.js +5 -5
- package/dist/schemas.d.ts +22 -22
- package/dist/{state-store-4QZISH3J.js → state-store-Z3EN56O5.js} +2 -2
- package/dist/transfer/types.d.ts +12 -12
- package/package.json +1 -1
- package/src/connectors/live/framework.ts +71 -6
- package/src/connectors/live/github.ts +10 -0
- package/src/connectors/live/gmail.ts +10 -0
- package/src/connectors/live/google-drive.ts +12 -4
- package/src/connectors/live/index.ts +2 -0
- package/src/connectors/live/live-connectors.test.ts +141 -0
- package/src/connectors/live/notion.ts +8 -0
- package/src/index.ts +2 -0
- package/dist/chunk-BECQDWBA.js.map +0 -1
- /package/dist/{chunk-QRMZX3PR.js.map → chunk-KLZDGMDI.js.map} +0 -0
- /package/dist/{chunk-KCLX6LOV.js.map → chunk-SRAF4TIS.js.map} +0 -0
- /package/dist/{chunk-QMYXNM4P.js.map → chunk-VU3SVYMA.js.map} +0 -0
- /package/dist/{state-store-4QZISH3J.js.map → state-store-Z3EN56O5.js.map} +0 -0
package/dist/access-cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Orchestrator
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KLZDGMDI.js";
|
|
4
4
|
import "./chunk-Y2SXZ5KZ.js";
|
|
5
|
-
import "./chunk-S53PKKWK.js";
|
|
6
5
|
import "./chunk-BFBF3XEF.js";
|
|
6
|
+
import "./chunk-S53PKKWK.js";
|
|
7
7
|
import "./chunk-HHLLAQGZ.js";
|
|
8
8
|
import "./chunk-UWK5OXUJ.js";
|
|
9
9
|
import "./chunk-RLV3PQGH.js";
|
|
@@ -43,7 +43,7 @@ import "./chunk-ZZTOURJI.js";
|
|
|
43
43
|
import "./chunk-XKXKSQU7.js";
|
|
44
44
|
import "./chunk-3GPTTA4J.js";
|
|
45
45
|
import "./chunk-IISBCCWR.js";
|
|
46
|
-
import "./chunk-
|
|
46
|
+
import "./chunk-VU3SVYMA.js";
|
|
47
47
|
import "./chunk-H63EDPFJ.js";
|
|
48
48
|
import "./chunk-PD6O7AXF.js";
|
|
49
49
|
import "./chunk-YAZNBMNF.js";
|
|
@@ -104,8 +104,8 @@ import "./chunk-PCI747N2.js";
|
|
|
104
104
|
import {
|
|
105
105
|
resolvePluginEntry
|
|
106
106
|
} from "./chunk-CMTINOFS.js";
|
|
107
|
-
import "./chunk-
|
|
108
|
-
import "./chunk-
|
|
107
|
+
import "./chunk-TQNRI55H.js";
|
|
108
|
+
import "./chunk-6GUG4YNM.js";
|
|
109
109
|
import "./chunk-JXS5PDQ7.js";
|
|
110
110
|
import "./chunk-SKGV326D.js";
|
|
111
111
|
import "./chunk-BEUDU7Y4.js";
|
package/dist/access-http.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ import './local-llm.js';
|
|
|
32
32
|
import './fallback-llm.js';
|
|
33
33
|
import './resolve-provider-secret.js';
|
|
34
34
|
import './live-connectors-runner.js';
|
|
35
|
-
import './framework-
|
|
35
|
+
import './framework-CNDn2164.js';
|
|
36
36
|
import './relevance.js';
|
|
37
37
|
import './negative.js';
|
|
38
38
|
import './session-observer-state.js';
|
package/dist/access-mcp.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ import './local-llm.js';
|
|
|
30
30
|
import './fallback-llm.js';
|
|
31
31
|
import './resolve-provider-secret.js';
|
|
32
32
|
import './live-connectors-runner.js';
|
|
33
|
-
import './framework-
|
|
33
|
+
import './framework-CNDn2164.js';
|
|
34
34
|
import './relevance.js';
|
|
35
35
|
import './negative.js';
|
|
36
36
|
import './session-observer-state.js';
|
package/dist/access-service.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ import './session-integrity.js';
|
|
|
39
39
|
import './summarizer.js';
|
|
40
40
|
import './model-registry.js';
|
|
41
41
|
import './resolve-provider-secret.js';
|
|
42
|
-
import './framework-
|
|
42
|
+
import './framework-CNDn2164.js';
|
|
43
43
|
import './relevance.js';
|
|
44
44
|
import './negative.js';
|
|
45
45
|
import './session-observer-state.js';
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import './local-llm.js';
|
|
|
19
19
|
import './fallback-llm.js';
|
|
20
20
|
import './resolve-provider-secret.js';
|
|
21
21
|
import './live-connectors-runner.js';
|
|
22
|
-
import './framework-
|
|
22
|
+
import './framework-CNDn2164.js';
|
|
23
23
|
import './relevance.js';
|
|
24
24
|
import './negative.js';
|
|
25
25
|
import './recall-state.js';
|
|
@@ -9,6 +9,47 @@ import path from "path";
|
|
|
9
9
|
import { setTimeout as delay } from "timers/promises";
|
|
10
10
|
|
|
11
11
|
// src/connectors/live/framework.ts
|
|
12
|
+
var DEFAULT_SECRET_KEY_PARTS = [
|
|
13
|
+
"token",
|
|
14
|
+
"secret",
|
|
15
|
+
"password",
|
|
16
|
+
"credential",
|
|
17
|
+
"apikey",
|
|
18
|
+
"accesskey",
|
|
19
|
+
"privatekey",
|
|
20
|
+
"authorization",
|
|
21
|
+
"authheader",
|
|
22
|
+
"cookie"
|
|
23
|
+
];
|
|
24
|
+
function redactConnectorConfigSecrets(config) {
|
|
25
|
+
return redactConnectorConfigValue(config);
|
|
26
|
+
}
|
|
27
|
+
function redactConnectorConfigValue(value) {
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
return value.map((item) => redactConnectorConfigValue(item));
|
|
30
|
+
}
|
|
31
|
+
if (typeof value !== "object" || value === null) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
const out = {};
|
|
35
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
36
|
+
if (isConnectorSecretConfigKey(key)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
out[key] = redactConnectorConfigValue(nested);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function isConnectorSecretConfigKey(key) {
|
|
44
|
+
const normalized = key.replace(/[^a-z0-9]/giu, "").toLowerCase();
|
|
45
|
+
return DEFAULT_SECRET_KEY_PARTS.some((part) => normalized.includes(part));
|
|
46
|
+
}
|
|
47
|
+
function persistableConnectorConfig(connector, validated) {
|
|
48
|
+
if (typeof connector.persistConfig === "function") {
|
|
49
|
+
return connector.persistConfig(validated);
|
|
50
|
+
}
|
|
51
|
+
return redactConnectorConfigSecrets(validated);
|
|
52
|
+
}
|
|
12
53
|
var CONNECTOR_ID_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
13
54
|
function isValidConnectorId(id) {
|
|
14
55
|
return typeof id === "string" && CONNECTOR_ID_PATTERN.test(id);
|
|
@@ -549,6 +590,8 @@ var _refreshConnectorLockForTest = refreshConnectorLock;
|
|
|
549
590
|
var _releaseConnectorLockForTest = releaseConnectorLock;
|
|
550
591
|
|
|
551
592
|
export {
|
|
593
|
+
redactConnectorConfigSecrets,
|
|
594
|
+
persistableConnectorConfig,
|
|
552
595
|
CONNECTOR_ID_PATTERN,
|
|
553
596
|
isValidConnectorId,
|
|
554
597
|
ConnectorStateLockLostError,
|
|
@@ -563,4 +606,4 @@ export {
|
|
|
563
606
|
_refreshConnectorLockForTest,
|
|
564
607
|
_releaseConnectorLockForTest
|
|
565
608
|
};
|
|
566
|
-
//# sourceMappingURL=chunk-
|
|
609
|
+
//# sourceMappingURL=chunk-6GUG4YNM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/connectors/live/state-store.ts","../src/connectors/live/framework.ts"],"sourcesContent":["/**\n * @remnic/core — Live Connectors State Store (issue #683 PR 1/N)\n *\n * Persists per-connector cursor + sync metadata to\n * `<memoryDir>/state/connectors/<id>.json`\n *\n * Reasons this lives next to memory data, not in user config:\n * - cursors are *operational* state that should travel with the memory\n * directory when a user moves it across machines;\n * - it keeps memory + ingest provenance co-located so tooling that backs up\n * the memory directory captures cursor state too.\n *\n * Atomic-write contract (CLAUDE.md gotcha #54):\n * - We NEVER `rmSync(target)` before `renameSync(tmp, target)`.\n * - Writes go to a sibling tmp file and `rename()` swaps it in.\n * - On error, the tmp file is best-effort cleaned up; the previous good\n * state file is left untouched.\n *\n * Privacy: cursors are opaque connector-defined strings. We do not log them\n * and do not surface them through user-visible APIs. Document content NEVER\n * touches this module.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { setTimeout as delay } from \"node:timers/promises\";\n\nimport { expandTildePath } from \"../../utils/path.js\";\n\nimport { type ConnectorCursor, isValidConnectorId } from \"./framework.js\";\n\n/**\n * Status of the most recent sync attempt for a connector.\n *\n * `\"never\"` is distinct from `\"success\"` so callers can detect\n * \"registered but never run\" without inspecting timestamps. Per CLAUDE.md\n * gotcha #34, we deliberately distinguish empty/unknown from failure states.\n */\nexport type ConnectorSyncStatus = \"success\" | \"error\" | \"never\";\n\n/**\n * Persisted per-connector state.\n *\n * Stored as pretty-printed JSON for human inspection — the file is small\n * (one record per connector) and operators may need to debug stuck cursors\n * by hand.\n */\nexport interface ConnectorState {\n /** Connector id. Matches the filename stem. */\n readonly id: string;\n /** Last persisted cursor, or `null` if the connector has never synced. */\n readonly cursor: ConnectorCursor | null;\n /** ISO 8601 timestamp of the last completed sync attempt, or `null`. */\n readonly lastSyncAt: string | null;\n /** Status of the last completed sync attempt. */\n readonly lastSyncStatus: ConnectorSyncStatus;\n /** Optional error message from the last failed sync. Truncated to 1 KB. */\n readonly lastSyncError?: string;\n /** Cumulative count of documents successfully imported across all syncs. */\n readonly totalDocsImported: number;\n /** ISO 8601 timestamp of when this state record was last written. */\n readonly updatedAt: string;\n}\n\nconst STATE_DIR_NAME = \"state\";\nconst CONNECTORS_DIR_NAME = \"connectors\";\nconst CONNECTOR_LOCKS_DIR_NAME = \"connector-locks\";\nconst MAX_ERROR_LENGTH = 1024;\nconst CONNECTOR_LOCK_STALE_MS = 10 * 60 * 1000;\nconst CONNECTOR_LOCK_HEARTBEAT_MS = Math.max(1_000, Math.floor(CONNECTOR_LOCK_STALE_MS / 4));\nconst CONNECTOR_LOCK_TIMEOUT_MS = 60 * 1000;\nconst CONNECTOR_LOCK_RETRY_MS = 50;\nconst VALID_SYNC_STATUSES: ReadonlySet<ConnectorSyncStatus> = new Set([\"success\", \"error\", \"never\"]);\n\n/**\n * Internal error thrown when a state file's JSON is unparseable or its shape\n * doesn't match `ConnectorState`. Used by `listConnectorStates` to distinguish\n * \"skip this corrupt file\" cases from genuine I/O failures (`EACCES`, `EIO`)\n * that the caller must see.\n */\nclass ConnectorStateCorruptionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ConnectorStateCorruptionError\";\n }\n}\n\nexport class ConnectorStateLockLostError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ConnectorStateLockLostError\";\n }\n}\n\ninterface ConnectorLockLease {\n readonly path: string;\n readonly token: string;\n}\n\ninterface ConnectorLockMetadata {\n readonly pid: number;\n readonly token: string;\n readonly createdAt: string;\n readonly refreshedAt: string;\n}\n\ninterface ConnectorStateLockOptions {\n readonly heartbeatMs?: number;\n readonly unrefHeartbeat?: boolean;\n}\n\n/**\n * Resolve `<memoryDir>/state/connectors/`, expanding `~` per CLAUDE.md #17.\n */\nfunction resolveConnectorsDir(memoryDir: string): string {\n if (typeof memoryDir !== \"string\" || memoryDir.length === 0) {\n throw new TypeError(\"memoryDir must be a non-empty string\");\n }\n return path.join(expandTildePath(memoryDir), STATE_DIR_NAME, CONNECTORS_DIR_NAME);\n}\n\nfunction resolveConnectorLocksDir(memoryDir: string): string {\n if (typeof memoryDir !== \"string\" || memoryDir.length === 0) {\n throw new TypeError(\"memoryDir must be a non-empty string\");\n }\n return path.join(expandTildePath(memoryDir), STATE_DIR_NAME, CONNECTOR_LOCKS_DIR_NAME);\n}\n\n/**\n * Resolve the state file path for a single connector. Throws on invalid id\n * to prevent path traversal via crafted ids.\n */\nfunction resolveConnectorStatePath(memoryDir: string, id: string): string {\n if (!isValidConnectorId(id)) {\n throw new TypeError(\n `invalid connector id ${JSON.stringify(id)} — must match /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/`\n );\n }\n return path.join(resolveConnectorsDir(memoryDir), `${id}.json`);\n}\n\nfunction resolveConnectorLockPath(memoryDir: string, id: string): string {\n if (!isValidConnectorId(id)) {\n throw new TypeError(\n `invalid connector id ${JSON.stringify(id)} — must match /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/`\n );\n }\n return path.join(resolveConnectorLocksDir(memoryDir), `${id}.lock`);\n}\n\n/**\n * Type guard for parsed state records. Validates the on-disk shape so a\n * corrupted/edited file produces a clear error rather than crashing later.\n *\n * Per CLAUDE.md gotcha #18, JSON.parse('null') yields `null` which would\n * pass a naive truthy check. We explicitly require an object.\n */\nfunction isConnectorStateShape(value: unknown): value is ConnectorState {\n if (typeof value !== \"object\" || value === null) return false;\n const v = value as Record<string, unknown>;\n if (typeof v.id !== \"string\") return false;\n if (typeof v.lastSyncStatus !== \"string\") return false;\n if (![\"success\", \"error\", \"never\"].includes(v.lastSyncStatus)) return false;\n // totalDocsImported is a cumulative count — fractional values would corrupt\n // metrics on later increments. Mirror the boundary check in writeConnectorState.\n if (typeof v.totalDocsImported !== \"number\" || !Number.isInteger(v.totalDocsImported)) return false;\n if (v.totalDocsImported < 0) return false;\n if (typeof v.updatedAt !== \"string\") return false;\n if (v.lastSyncAt !== null && typeof v.lastSyncAt !== \"string\") return false;\n if (v.cursor !== null) {\n if (typeof v.cursor !== \"object\" || v.cursor === null) return false;\n const c = v.cursor as Record<string, unknown>;\n if (typeof c.kind !== \"string\" || typeof c.value !== \"string\" || typeof c.updatedAt !== \"string\") {\n return false;\n }\n }\n if (v.lastSyncError !== undefined && typeof v.lastSyncError !== \"string\") return false;\n return true;\n}\n\nfunction isConnectorLockMetadata(value: unknown): value is ConnectorLockMetadata {\n if (typeof value !== \"object\" || value === null) return false;\n const v = value as Record<string, unknown>;\n return (\n typeof v.pid === \"number\" &&\n Number.isInteger(v.pid) &&\n v.pid > 0 &&\n typeof v.token === \"string\" &&\n v.token.length > 0 &&\n typeof v.createdAt === \"string\" &&\n typeof v.refreshedAt === \"string\"\n );\n}\n\nfunction connectorLockMetadata(token: string, createdAt = new Date().toISOString()): ConnectorLockMetadata {\n return {\n pid: process.pid,\n token,\n createdAt,\n refreshedAt: new Date().toISOString(),\n };\n}\n\nasync function readConnectorLockMetadata(lockPath: string): Promise<ConnectorLockMetadata | null> {\n let raw: string;\n try {\n raw = await fs.readFile(lockPath, \"utf8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n try {\n const parsed = JSON.parse(raw) as unknown;\n return isConnectorLockMetadata(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction parseConnectorLockMetadata(raw: string): ConnectorLockMetadata | null {\n try {\n const parsed = JSON.parse(raw) as unknown;\n return isConnectorLockMetadata(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction isSameFileIdentity(left: import(\"node:fs\").Stats, right: import(\"node:fs\").Stats): boolean {\n return left.dev === right.dev && left.ino === right.ino;\n}\n\n/**\n * Reject any path component along `<memoryDir>/state/connectors/<id>.json`\n * that is a symlink. Without this guard, a symlink in any of those\n * components would let `fs.readFile` escape the memory root and consume an\n * arbitrary outside file as cursor state — silently poisoning sync state and\n * violating the project-wide rule against symlink traversal.\n *\n * `lstat` is used (not `stat`) so we observe the link itself rather than its\n * target. Missing components are tolerated — the caller's `readFile` /\n * `mkdir` will surface ENOENT in its normal way.\n *\n * (PR #724 review.)\n */\nasync function assertNoSymlinkOnPath(memoryDir: string, filePath: string): Promise<void> {\n const expandedRoot = expandTildePath(memoryDir);\n // Normalize so `..` segments can't bypass the prefix check below.\n const root = path.resolve(expandedRoot);\n const target = path.resolve(filePath);\n const rel = path.relative(root, target);\n // path.relative() yields a \"../...\" prefix when target escapes root.\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) {\n throw new Error(`connector state path ${target} escapes memory root ${root}`);\n }\n // Walk every component from root to target (inclusive) and lstat each.\n const segments = rel.length === 0 ? [] : rel.split(path.sep);\n let current = root;\n const componentsToCheck = [current];\n for (const seg of segments) {\n current = path.join(current, seg);\n componentsToCheck.push(current);\n }\n for (const component of componentsToCheck) {\n let stat: import(\"node:fs\").Stats;\n try {\n stat = await fs.lstat(component);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n // Not yet created — that's fine; caller's readFile/mkdir handles it.\n continue;\n }\n throw err;\n }\n if (stat.isSymbolicLink()) {\n throw new Error(`connector state path component ${component} is a symlink; refusing to follow`);\n }\n }\n}\n\nasync function tryAcquireConnectorLock(memoryDir: string, id: string): Promise<ConnectorLockLease | null> {\n const dir = resolveConnectorLocksDir(memoryDir);\n const lockPath = resolveConnectorLockPath(memoryDir, id);\n await assertNoSymlinkOnPath(memoryDir, lockPath);\n await fs.mkdir(dir, { recursive: true });\n let handle: Awaited<ReturnType<typeof fs.open>> | null = null;\n let acquiredLockFile = false;\n const token = randomUUID();\n try {\n handle = await fs.open(lockPath, \"wx\", 0o600);\n acquiredLockFile = true;\n await handle.writeFile(`${JSON.stringify(connectorLockMetadata(token))}\\n`, \"utf8\");\n await handle.close();\n handle = null;\n return { path: lockPath, token };\n } catch (err) {\n if (acquiredLockFile) {\n if (handle !== null) {\n try {\n await handle.close();\n } catch {\n // The original write/close failure is more actionable.\n }\n }\n try {\n await fs.unlink(lockPath);\n } catch (cleanupErr) {\n if ((cleanupErr as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new AggregateError(\n [err, cleanupErr],\n `failed to initialize connector state lock at ${lockPath}; cleanup also failed`\n );\n }\n }\n throw err;\n }\n if ((err as NodeJS.ErrnoException).code !== \"EEXIST\") {\n throw err;\n }\n let stat: import(\"node:fs\").Stats;\n try {\n stat = await fs.lstat(lockPath);\n } catch (statErr) {\n if ((statErr as NodeJS.ErrnoException).code === \"ENOENT\") {\n return null;\n }\n throw statErr;\n }\n if (stat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lockPath} is a symlink; refusing to follow`);\n }\n if (Date.now() - stat.mtimeMs > CONNECTOR_LOCK_STALE_MS) {\n await unlinkStaleConnectorLock(lockPath);\n return null;\n }\n return null;\n }\n}\n\nasync function shouldUnlinkStaleConnectorLock(lockPath: string, stat: import(\"node:fs\").Stats): Promise<boolean> {\n if (Date.now() - stat.mtimeMs <= CONNECTOR_LOCK_STALE_MS) return false;\n const metadata = await readConnectorLockMetadata(lockPath);\n if (metadata === null) return true;\n const refreshedAtMs = Date.parse(metadata.refreshedAt);\n if (!Number.isFinite(refreshedAtMs)) return true;\n return Date.now() - refreshedAtMs > CONNECTOR_LOCK_STALE_MS;\n}\n\nasync function unlinkStaleConnectorLock(lockPath: string): Promise<void> {\n const reclaimHandle = await openConnectorReclaimLock(lockPath);\n if (!reclaimHandle) return;\n try {\n await reclaimHandle.writeFile(`${process.pid}:${new Date().toISOString()}`, \"utf8\");\n await unlinkStaleConnectorLockWhileReclaimHeld(lockPath);\n } finally {\n await reclaimHandle.close().catch(() => undefined);\n await fs.unlink(connectorReclaimLockPath(lockPath)).catch(() => undefined);\n }\n}\n\nasync function unlinkStaleConnectorLockWhileReclaimHeld(lockPath: string): Promise<void> {\n let stat: import(\"node:fs\").Stats;\n try {\n stat = await fs.lstat(lockPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw err;\n }\n if (stat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lockPath} is a symlink; refusing to follow`);\n }\n if (!(await shouldUnlinkStaleConnectorLock(lockPath, stat))) return;\n try {\n await fs.unlink(lockPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n}\n\nfunction connectorReclaimLockPath(lockPath: string): string {\n return `${lockPath}.reclaim`;\n}\n\nasync function openConnectorReclaimLock(lockPath: string): Promise<Awaited<ReturnType<typeof fs.open>> | null> {\n const reclaimPath = connectorReclaimLockPath(lockPath);\n try {\n return await fs.open(reclaimPath, \"wx\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"EEXIST\") throw err;\n }\n\n let reclaimStat: import(\"node:fs\").Stats;\n try {\n reclaimStat = await fs.lstat(reclaimPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n if (reclaimStat.isSymbolicLink()) {\n throw new Error(`connector state path component ${reclaimPath} is a symlink; refusing to follow`);\n }\n if (Date.now() - reclaimStat.mtimeMs <= CONNECTOR_LOCK_STALE_MS) return null;\n await fs.unlink(reclaimPath);\n\n try {\n return await fs.open(reclaimPath, \"wx\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"EEXIST\") return null;\n throw err;\n }\n}\n\nasync function refreshConnectorLock(lease: ConnectorLockLease): Promise<boolean> {\n const reclaimHandle = await openConnectorReclaimLock(lease.path);\n if (!reclaimHandle) return false;\n try {\n await reclaimHandle.writeFile(`${process.pid}:${new Date().toISOString()}`, \"utf8\");\n return await refreshConnectorLockWhileReclaimHeld(lease);\n } finally {\n await reclaimHandle.close().catch(() => undefined);\n await fs.unlink(connectorReclaimLockPath(lease.path)).catch(() => undefined);\n }\n}\n\nasync function refreshConnectorLockWhileReclaimHeld(lease: ConnectorLockLease): Promise<boolean> {\n let handle: Awaited<ReturnType<typeof fs.open>>;\n try {\n handle = await fs.open(lease.path, \"r+\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n throw err;\n }\n try {\n const openedStat = await handle.stat();\n const metadata = parseConnectorLockMetadata(await handle.readFile(\"utf8\"));\n if (metadata?.token !== lease.token) return false;\n const body = `${JSON.stringify(connectorLockMetadata(lease.token, metadata.createdAt))}\\n`;\n await handle.truncate(0);\n await handle.write(body, 0, \"utf8\");\n let pathStat: import(\"node:fs\").Stats;\n try {\n pathStat = await fs.lstat(lease.path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n throw err;\n }\n if (pathStat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lease.path} is a symlink; refusing to follow`);\n }\n return isSameFileIdentity(openedStat, pathStat);\n } finally {\n await handle.close();\n }\n}\n\nasync function releaseConnectorLock(lease: ConnectorLockLease): Promise<void> {\n const reclaimHandle = await openConnectorReclaimLock(lease.path);\n if (!reclaimHandle) return;\n try {\n await reclaimHandle.writeFile(`${process.pid}:${new Date().toISOString()}`, \"utf8\");\n await releaseConnectorLockWhileReclaimHeld(lease);\n } finally {\n await reclaimHandle.close().catch(() => undefined);\n await fs.unlink(connectorReclaimLockPath(lease.path)).catch(() => undefined);\n }\n}\n\nasync function releaseConnectorLockWhileReclaimHeld(lease: ConnectorLockLease): Promise<void> {\n let handle: Awaited<ReturnType<typeof fs.open>>;\n try {\n handle = await fs.open(lease.path, \"r\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw err;\n }\n try {\n const openedStat = await handle.stat();\n const metadata = parseConnectorLockMetadata(await handle.readFile(\"utf8\"));\n if (metadata?.token !== lease.token) return;\n let pathStat: import(\"node:fs\").Stats;\n try {\n pathStat = await fs.lstat(lease.path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw err;\n }\n if (pathStat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lease.path} is a symlink; refusing to follow`);\n }\n if (!isSameFileIdentity(openedStat, pathStat)) return;\n try {\n await fs.unlink(lease.path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n } finally {\n await handle.close();\n }\n}\n\nasync function withConnectorStateLockInternal<T>(\n memoryDir: string,\n id: string,\n run: (abortSignal: AbortSignal) => Promise<T>,\n options: ConnectorStateLockOptions = {}\n): Promise<T> {\n const deadline = Date.now() + CONNECTOR_LOCK_TIMEOUT_MS;\n let lease: ConnectorLockLease | null = null;\n while (lease === null) {\n lease = await tryAcquireConnectorLock(memoryDir, id);\n if (lease !== null) break;\n if (Date.now() >= deadline) {\n throw new Error(`timed out waiting for connector \"${id}\" state lock`);\n }\n await delay(CONNECTOR_LOCK_RETRY_MS);\n }\n const abortController = new AbortController();\n let rejectLockLost!: (err: Error) => void;\n let lockLost = false;\n const lockLostPromise = new Promise<never>((_resolve, reject) => {\n rejectLockLost = reject;\n });\n const failLostLock = (message: string): void => {\n if (lockLost) return;\n lockLost = true;\n const err = new ConnectorStateLockLostError(message);\n abortController.abort(err);\n rejectLockLost(err);\n };\n const heartbeat = setInterval(() => {\n void refreshConnectorLock(lease)\n .then((refreshed) => {\n if (!refreshed) {\n failLostLock(`lost connector \"${id}\" state lock`);\n }\n })\n .catch((err) => {\n const message = err instanceof Error ? err.message : String(err);\n failLostLock(`lost connector \"${id}\" state lock: ${message}`);\n });\n }, options.heartbeatMs ?? CONNECTOR_LOCK_HEARTBEAT_MS);\n if (options.unrefHeartbeat !== false) {\n heartbeat.unref?.();\n }\n const runPromise = run(abortController.signal);\n try {\n return await Promise.race([runPromise, lockLostPromise]);\n } catch (err) {\n if (err instanceof ConnectorStateLockLostError) {\n await runPromise.catch(() => undefined);\n }\n throw err;\n } finally {\n clearInterval(heartbeat);\n await releaseConnectorLock(lease);\n }\n}\n\nexport async function withConnectorStateLock<T>(\n memoryDir: string,\n id: string,\n run: (abortSignal: AbortSignal) => Promise<T>\n): Promise<T> {\n return withConnectorStateLockInternal(memoryDir, id, run);\n}\n\nexport async function _withConnectorStateLockForTest<T>(\n memoryDir: string,\n id: string,\n run: (abortSignal: AbortSignal) => Promise<T>,\n options: ConnectorStateLockOptions\n): Promise<T> {\n return withConnectorStateLockInternal(memoryDir, id, run, options);\n}\n\n/**\n * Read the persisted state for a single connector.\n *\n * Returns `null` if the file does not exist (ENOENT). Throws on any other\n * I/O error or on shape mismatch — operators should see corruption loudly.\n *\n * Rejects symlinks anywhere on the path so a planted symlink can't redirect\n * reads outside the memory root. (PR #724 review.)\n */\nexport async function readConnectorState(memoryDir: string, id: string): Promise<ConnectorState | null> {\n const filePath = resolveConnectorStatePath(memoryDir, id);\n await assertNoSymlinkOnPath(memoryDir, filePath);\n let raw: string;\n try {\n raw = await fs.readFile(filePath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (err) {\n throw new ConnectorStateCorruptionError(\n `connector state at ${filePath} is not valid JSON: ${(err as Error).message}`\n );\n }\n if (!isConnectorStateShape(parsed)) {\n throw new ConnectorStateCorruptionError(`connector state at ${filePath} does not match ConnectorState shape`);\n }\n if (parsed.id !== id) {\n throw new ConnectorStateCorruptionError(\n `connector state at ${filePath} has mismatched id ${JSON.stringify(parsed.id)}; expected ${JSON.stringify(id)}`\n );\n }\n return parsed;\n}\n\n/**\n * Write state atomically: create-tmp + rename. Never destroys the previous\n * file before the new one is in place — see CLAUDE.md gotcha #54.\n *\n * We accept `Omit<ConnectorState, \"updatedAt\">` and stamp `updatedAt`\n * ourselves so callers can't accidentally persist a stale timestamp.\n */\nexport async function writeConnectorState(\n memoryDir: string,\n id: string,\n state: Omit<ConnectorState, \"updatedAt\">\n): Promise<ConnectorState> {\n if (!isValidConnectorId(id)) {\n throw new TypeError(\n `invalid connector id ${JSON.stringify(id)} — must match /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/`\n );\n }\n if (state.id !== id) {\n throw new Error(\n `writeConnectorState(): state.id ${JSON.stringify(state.id)} does not match id argument ${JSON.stringify(id)}`\n );\n }\n // Full boundary validation. Persisting an out-of-shape record would brick\n // the connector's cursor file: subsequent `readConnectorState` calls would\n // throw `ConnectorStateCorruptionError` until manual repair. JS callers\n // bypassing TS types must be rejected here, not later. (PR #724 review.)\n if (!VALID_SYNC_STATUSES.has(state.lastSyncStatus as ConnectorSyncStatus)) {\n throw new Error(\n `writeConnectorState(): lastSyncStatus must be one of ${[...VALID_SYNC_STATUSES].join(\", \")}, got ${JSON.stringify(state.lastSyncStatus)}`\n );\n }\n if (state.lastSyncAt !== null && typeof state.lastSyncAt !== \"string\") {\n throw new Error(`writeConnectorState(): lastSyncAt must be a string or null, got ${typeof state.lastSyncAt}`);\n }\n if (state.cursor !== null) {\n if (typeof state.cursor !== \"object\") {\n throw new Error(`writeConnectorState(): cursor must be an object or null`);\n }\n if (\n typeof state.cursor.kind !== \"string\" ||\n typeof state.cursor.value !== \"string\" ||\n typeof state.cursor.updatedAt !== \"string\"\n ) {\n throw new Error(`writeConnectorState(): cursor must have string kind, value, and updatedAt`);\n }\n }\n if (\n typeof state.totalDocsImported !== \"number\" ||\n !Number.isInteger(state.totalDocsImported) ||\n state.totalDocsImported < 0\n ) {\n throw new Error(`writeConnectorState(): totalDocsImported must be a non-negative integer`);\n }\n if (state.lastSyncError !== undefined && typeof state.lastSyncError !== \"string\") {\n throw new Error(`writeConnectorState(): lastSyncError must be a string when provided`);\n }\n const truncatedError =\n state.lastSyncError !== undefined && state.lastSyncError.length > MAX_ERROR_LENGTH\n ? state.lastSyncError.slice(0, MAX_ERROR_LENGTH)\n : state.lastSyncError;\n\n const finalState: ConnectorState = {\n id: state.id,\n cursor: state.cursor,\n lastSyncAt: state.lastSyncAt,\n lastSyncStatus: state.lastSyncStatus,\n ...(truncatedError !== undefined ? { lastSyncError: truncatedError } : {}),\n totalDocsImported: state.totalDocsImported,\n updatedAt: new Date().toISOString(),\n };\n\n const dir = resolveConnectorsDir(memoryDir);\n const targetPath = path.join(dir, `${id}.json`);\n // Reject planted symlinks before mkdir/write so a redirected target can't\n // overwrite an arbitrary file outside the memory root. (PR #724 review.)\n await assertNoSymlinkOnPath(memoryDir, targetPath);\n await fs.mkdir(dir, { recursive: true });\n const tmpPath = `${targetPath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n\n const body = `${JSON.stringify(finalState, null, 2)}\\n`;\n try {\n await fs.writeFile(tmpPath, body, { encoding: \"utf-8\", mode: 0o600 });\n await fs.rename(tmpPath, targetPath);\n } catch (err) {\n // Best-effort cleanup of the tmp file. Never touch `targetPath` — the\n // previous good state must remain readable on failure.\n try {\n await fs.unlink(tmpPath);\n } catch {\n // ignore\n }\n throw err;\n }\n return finalState;\n}\n\n/**\n * Enumerate every persisted connector state. Returns an empty array when\n * the directory does not exist yet (clean install, no syncs ever run).\n *\n * Files that do not match the `<id>.json` naming rule are skipped — this\n * keeps stray editor backups (`.json~`, `.swp`) from breaking enumeration.\n *\n * Corruption (unparseable JSON, shape mismatch, id mismatch) is also\n * skipped so one bad file doesn't take down the listing. Operators\n * inspecting `state/connectors/` can still see the offending file by hand.\n *\n * **Genuine I/O failures (`EACCES`, `EIO`, etc.) are NOT swallowed** —\n * silently returning an incomplete state set would make active connectors\n * appear missing and trigger duplicate ingestion on the next scheduler tick.\n * (PR #724 review.)\n */\nexport async function listConnectorStates(memoryDir: string): Promise<ConnectorState[]> {\n const dir = resolveConnectorsDir(memoryDir);\n // Refuse to enumerate through a symlinked state directory — a planted\n // symlink at <memoryDir>/state or <memoryDir>/state/connectors would\n // otherwise let reads escape the memory root. (PR #724 review.)\n await assertNoSymlinkOnPath(memoryDir, dir);\n let entries: string[];\n try {\n entries = await fs.readdir(dir);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n throw err;\n }\n const out: ConnectorState[] = [];\n for (const entry of entries) {\n if (!entry.endsWith(\".json\")) continue;\n const id = entry.slice(0, -\".json\".length);\n if (!isValidConnectorId(id)) continue;\n try {\n const state = await readConnectorState(memoryDir, id);\n if (state !== null) out.push(state);\n } catch (err) {\n if (err instanceof ConnectorStateCorruptionError) {\n // Skip corrupt files; preserve availability of the rest.\n continue;\n }\n // Anything else (EACCES, EIO, ENOTDIR, ...) is a real operational\n // failure. Fail loudly so the scheduler / CLI can surface it.\n throw err;\n }\n }\n out.sort((a, b) => a.id.localeCompare(b.id));\n return out;\n}\n\n/**\n * Test-only helper: resolve where a given connector's state lives. Exported\n * so tests can assert the on-disk layout without duplicating the path math.\n * Not part of the stable public API.\n *\n * @internal\n */\nexport function _connectorStatePathForTest(memoryDir: string, id: string): string {\n return resolveConnectorStatePath(memoryDir, id);\n}\n\nexport const _unlinkStaleConnectorLockForTest = unlinkStaleConnectorLock;\nexport const _tryAcquireConnectorLockForTest = tryAcquireConnectorLock;\nexport const _refreshConnectorLockForTest = refreshConnectorLock;\nexport const _releaseConnectorLockForTest = releaseConnectorLock;\n","/**\n * @remnic/core — Live Connectors Framework (issue #683 PR 1/N)\n *\n * Defines the contract that every \"live\" connector (Drive, Notion, Gmail,\n * GitHub, ...) must satisfy. A live connector is **continuous**: it runs on a\n * schedule, persists a cursor to disk, and ingests *new* documents since the\n * last sync. This is distinct from one-shot importers in\n * `packages/remnic-core/src/importers/` which transform an entire export file\n * in a single pass.\n *\n * This module is intentionally pure types + interfaces. No I/O. No schedule\n * wiring. Concrete connectors (PRs 2–5), the maintenance scheduler hookup\n * (separate PR), and the CLI surface (PR 6) are deferred.\n *\n * Naming caveat: `packages/remnic-core/src/connectors/` is already scoped to\n * the Codex marketplace integration. The live-connector framework lives under\n * the `live/` subdirectory to avoid collision. Do not import Codex symbols\n * from here, and do not import live-connector symbols from the Codex code.\n */\n\n/**\n * Free-form connector configuration. Validated by each connector's\n * `validateConfig` implementation. Stored alongside the cursor in the state\n * store. MUST be JSON-serializable: no functions, no class instances, no\n * circular references.\n *\n * Connectors MUST NOT persist secrets here — credentials belong in OS keychain\n * / OAuth token storage (PR 2 design).\n */\nexport type ConnectorConfig = Record<string, unknown>;\n\n/**\n * Opaque cursor describing \"where the last sync left off\". Each connector\n * defines what `kind` and `value` mean (e.g. Drive: `{kind: \"pageToken\",\n * value: \"...\"}`, Gmail: `{kind: \"historyId\", value: \"...\"}`). The orchestrator\n * treats it as opaque and only round-trips it through the state store.\n *\n * `updatedAt` is an ISO 8601 timestamp set by the framework when the cursor is\n * written. It is informational — connectors MUST NOT use it to decide\n * monotonicity. They own the `value` semantics.\n */\nexport interface ConnectorCursor {\n /** Connector-defined cursor kind (e.g. `\"pageToken\"`, `\"historyId\"`, `\"sinceTs\"`). */\n readonly kind: string;\n /** Connector-defined opaque cursor value. */\n readonly value: string;\n /** ISO 8601 timestamp of when this cursor was last written. */\n readonly updatedAt: string;\n}\n\n/**\n * Provenance for a connector-ingested document. Required so downstream recall\n * can attribute facts back to their origin and avoid re-ingesting on the next\n * incremental pass.\n */\nexport interface ConnectorDocumentSource {\n /** Stable connector id (matches `LiveConnector.id`). */\n readonly connector: string;\n /** Source-system identifier (Drive file id, Notion page id, Gmail msg id, ...). */\n readonly externalId: string;\n /** Optional source-system revision/version (etag, page version, history id). */\n readonly externalRevision?: string;\n /** Optional canonical URL pointing back at the source document. */\n readonly externalUrl?: string;\n /** ISO 8601 timestamp of when the connector fetched this document. */\n readonly fetchedAt: string;\n}\n\n/**\n * A single document yielded by an incremental sync. Connectors are responsible\n * for chunking large source documents themselves if needed; the orchestrator\n * ingests `content` as a unit.\n */\nexport interface ConnectorDocument {\n /** Connector-local stable id for this document. SHOULD match `source.externalId`. */\n readonly id: string;\n /** Optional human-readable title. */\n readonly title?: string;\n /** Body content. Plaintext or Markdown — connectors document their format. */\n readonly content: string;\n /** Provenance. Required. */\n readonly source: ConnectorDocumentSource;\n}\n\n/**\n * Arguments passed to `syncIncremental`. The framework owns cursor/config\n * lifecycle; connectors only read these and return the next cursor.\n */\nexport interface SyncIncrementalArgs {\n /** Last persisted cursor, or `null` on the first ever sync. */\n readonly cursor: ConnectorCursor | null;\n /** Validated connector config (already passed through `validateConfig`). */\n readonly config: ConnectorConfig;\n /** Optional abort signal. Connectors SHOULD honor it for cooperative cancellation. */\n readonly abortSignal?: AbortSignal;\n}\n\n/**\n * Result of a single incremental sync pass.\n *\n * `newDocs` MAY be empty (no new documents since the last cursor). `nextCursor`\n * MUST always be returned — even on no-op syncs the framework persists it so\n * `updatedAt` reflects the most recent attempt.\n */\nexport interface SyncIncrementalResult {\n readonly newDocs: ConnectorDocument[];\n readonly nextCursor: ConnectorCursor;\n}\n\n/**\n * The contract every live connector implements.\n *\n * Connectors MUST be:\n * - **Idempotent**: re-running with the same cursor MUST NOT duplicate\n * documents. The `source.externalId` + `source.externalRevision` pair is\n * used downstream for dedup.\n * - **Read-only on the source**: live connectors never mutate the upstream\n * system (no marking emails read, no editing Notion pages).\n * - **Cancellable**: long-running syncs SHOULD periodically check\n * `abortSignal.aborted` and bail cleanly.\n * - **Privacy-aware**: connectors MUST NOT log document content. Logging\n * metadata (counts, ids, timings) is fine.\n */\nexport interface LiveConnector {\n /**\n * Stable connector id. MUST match `CONNECTOR_ID_PATTERN` — lowercase\n * alphanumeric plus dash, 1–64 chars, must start AND end with alphanumeric\n * (no leading or trailing dash). The registry enforces this.\n */\n readonly id: string;\n /** Short human-readable name shown in CLI / status output. */\n readonly displayName: string;\n /** Optional longer description. */\n readonly description?: string;\n\n /**\n * Validate raw user-supplied config. MUST throw on malformed input — never\n * silently default. The returned object is what gets persisted and passed\n * back to `syncIncremental`. Connectors SHOULD strip unknown fields.\n */\n validateConfig(raw: unknown): ConnectorConfig;\n\n /**\n * Run one incremental sync pass. See `SyncIncrementalArgs` /\n * `SyncIncrementalResult` for the contract.\n */\n syncIncremental(args: SyncIncrementalArgs): Promise<SyncIncrementalResult>;\n}\n\n/**\n * Regex enforcing the connector-id naming rule. Exported so connectors and\n * tests can validate ids consistently with the registry.\n *\n * Rule: lowercase alphanumeric + dash, 1..64 chars, must start AND end with\n * alphanumeric (no leading or trailing dash). Single-char ids are allowed.\n */\nexport const CONNECTOR_ID_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;\n\n/**\n * Returns `true` if `id` is a syntactically valid connector id.\n */\nexport function isValidConnectorId(id: unknown): id is string {\n return typeof id === \"string\" && CONNECTOR_ID_PATTERN.test(id);\n}\n"],"mappings":";;;;;AAuBA,SAAS,kBAAkB;AAC3B,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AACjB,SAAS,cAAc,aAAa;;;ACkI7B,IAAM,uBAAuB;AAK7B,SAAS,mBAAmB,IAA2B;AAC5D,SAAO,OAAO,OAAO,YAAY,qBAAqB,KAAK,EAAE;AAC/D;;;ADlGA,IAAM,iBAAiB;AACvB,IAAM,sBAAsB;AAC5B,IAAM,2BAA2B;AACjC,IAAM,mBAAmB;AACzB,IAAM,0BAA0B,KAAK,KAAK;AAC1C,IAAM,8BAA8B,KAAK,IAAI,K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,UAAU,SAAS,MAAM,EAAE,UAAU,SAAS,MAAM,IAAM,CAAC;AACpE,UAAM,GAAG,OAAO,SAAS,UAAU;AAAA,EACrC,SAAS,KAAK;AAGZ,QAAI;AACF,YAAM,GAAG,OAAO,OAAO;AAAA,IACzB,QAAQ;AAAA,IAER;AACA,UAAM;AAAA,EACR;AACA,SAAO;AACT;AAkBA,eAAsB,oBAAoB,WAA8C;AACtF,QAAM,MAAM,qBAAqB,SAAS;AAI1C,QAAM,sBAAsB,WAAW,GAAG;AAC1C,MAAI;AACJ,MAAI;AACF,cAAU,MAAM,GAAG,QAAQ,GAAG;AAAA,EAChC,SAAS,KAAK;AACZ,QAAK,IAA8B,SAAS,SAAU,QAAO,CAAC;AAC9D,UAAM;AAAA,EACR;AACA,QAAM,MAAwB,CAAC;AAC/B,aAAW,SAAS,SAAS;AAC3B,QAAI,CAAC,MAAM,SAAS,OAAO,EAAG;AAC9B,UAAM,KAAK,MAAM,MAAM,GAAG,CAAC,QAAQ,MAAM;AACzC,QAAI,CAAC,mBAAmB,EAAE,EAAG;AAC7B,QAAI;AACF,YAAM,QAAQ,MAAM,mBAAmB,WAAW,EAAE;AACpD,UAAI,UAAU,KAAM,KAAI,KAAK,KAAK;AAAA,IACpC,SAAS,KAAK;AACZ,UAAI,eAAe,+BAA+B;AAEhD;AAAA,MACF;AAGA,YAAM;AAAA,IACR;AAAA,EACF;AACA,MAAI,KAAK,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC;AAC3C,SAAO;AACT;AASO,SAAS,2BAA2B,WAAmB,IAAoB;AAChF,SAAO,0BAA0B,WAAW,EAAE;AAChD;AAEO,IAAM,mCAAmC;AACzC,IAAM,kCAAkC;AACxC,IAAM,+BAA+B;AACrC,IAAM,+BAA+B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/connectors/live/state-store.ts","../src/connectors/live/framework.ts"],"sourcesContent":["/**\n * @remnic/core — Live Connectors State Store (issue #683 PR 1/N)\n *\n * Persists per-connector cursor + sync metadata to\n * `<memoryDir>/state/connectors/<id>.json`\n *\n * Reasons this lives next to memory data, not in user config:\n * - cursors are *operational* state that should travel with the memory\n * directory when a user moves it across machines;\n * - it keeps memory + ingest provenance co-located so tooling that backs up\n * the memory directory captures cursor state too.\n *\n * Atomic-write contract (CLAUDE.md gotcha #54):\n * - We NEVER `rmSync(target)` before `renameSync(tmp, target)`.\n * - Writes go to a sibling tmp file and `rename()` swaps it in.\n * - On error, the tmp file is best-effort cleaned up; the previous good\n * state file is left untouched.\n *\n * Privacy: cursors are opaque connector-defined strings. We do not log them\n * and do not surface them through user-visible APIs. Document content NEVER\n * touches this module.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { setTimeout as delay } from \"node:timers/promises\";\n\nimport { expandTildePath } from \"../../utils/path.js\";\n\nimport { type ConnectorCursor, isValidConnectorId } from \"./framework.js\";\n\n/**\n * Status of the most recent sync attempt for a connector.\n *\n * `\"never\"` is distinct from `\"success\"` so callers can detect\n * \"registered but never run\" without inspecting timestamps. Per CLAUDE.md\n * gotcha #34, we deliberately distinguish empty/unknown from failure states.\n */\nexport type ConnectorSyncStatus = \"success\" | \"error\" | \"never\";\n\n/**\n * Persisted per-connector state.\n *\n * Stored as pretty-printed JSON for human inspection — the file is small\n * (one record per connector) and operators may need to debug stuck cursors\n * by hand.\n */\nexport interface ConnectorState {\n /** Connector id. Matches the filename stem. */\n readonly id: string;\n /** Last persisted cursor, or `null` if the connector has never synced. */\n readonly cursor: ConnectorCursor | null;\n /** ISO 8601 timestamp of the last completed sync attempt, or `null`. */\n readonly lastSyncAt: string | null;\n /** Status of the last completed sync attempt. */\n readonly lastSyncStatus: ConnectorSyncStatus;\n /** Optional error message from the last failed sync. Truncated to 1 KB. */\n readonly lastSyncError?: string;\n /** Cumulative count of documents successfully imported across all syncs. */\n readonly totalDocsImported: number;\n /** ISO 8601 timestamp of when this state record was last written. */\n readonly updatedAt: string;\n}\n\nconst STATE_DIR_NAME = \"state\";\nconst CONNECTORS_DIR_NAME = \"connectors\";\nconst CONNECTOR_LOCKS_DIR_NAME = \"connector-locks\";\nconst MAX_ERROR_LENGTH = 1024;\nconst CONNECTOR_LOCK_STALE_MS = 10 * 60 * 1000;\nconst CONNECTOR_LOCK_HEARTBEAT_MS = Math.max(1_000, Math.floor(CONNECTOR_LOCK_STALE_MS / 4));\nconst CONNECTOR_LOCK_TIMEOUT_MS = 60 * 1000;\nconst CONNECTOR_LOCK_RETRY_MS = 50;\nconst VALID_SYNC_STATUSES: ReadonlySet<ConnectorSyncStatus> = new Set([\"success\", \"error\", \"never\"]);\n\n/**\n * Internal error thrown when a state file's JSON is unparseable or its shape\n * doesn't match `ConnectorState`. Used by `listConnectorStates` to distinguish\n * \"skip this corrupt file\" cases from genuine I/O failures (`EACCES`, `EIO`)\n * that the caller must see.\n */\nclass ConnectorStateCorruptionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ConnectorStateCorruptionError\";\n }\n}\n\nexport class ConnectorStateLockLostError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ConnectorStateLockLostError\";\n }\n}\n\ninterface ConnectorLockLease {\n readonly path: string;\n readonly token: string;\n}\n\ninterface ConnectorLockMetadata {\n readonly pid: number;\n readonly token: string;\n readonly createdAt: string;\n readonly refreshedAt: string;\n}\n\ninterface ConnectorStateLockOptions {\n readonly heartbeatMs?: number;\n readonly unrefHeartbeat?: boolean;\n}\n\n/**\n * Resolve `<memoryDir>/state/connectors/`, expanding `~` per CLAUDE.md #17.\n */\nfunction resolveConnectorsDir(memoryDir: string): string {\n if (typeof memoryDir !== \"string\" || memoryDir.length === 0) {\n throw new TypeError(\"memoryDir must be a non-empty string\");\n }\n return path.join(expandTildePath(memoryDir), STATE_DIR_NAME, CONNECTORS_DIR_NAME);\n}\n\nfunction resolveConnectorLocksDir(memoryDir: string): string {\n if (typeof memoryDir !== \"string\" || memoryDir.length === 0) {\n throw new TypeError(\"memoryDir must be a non-empty string\");\n }\n return path.join(expandTildePath(memoryDir), STATE_DIR_NAME, CONNECTOR_LOCKS_DIR_NAME);\n}\n\n/**\n * Resolve the state file path for a single connector. Throws on invalid id\n * to prevent path traversal via crafted ids.\n */\nfunction resolveConnectorStatePath(memoryDir: string, id: string): string {\n if (!isValidConnectorId(id)) {\n throw new TypeError(\n `invalid connector id ${JSON.stringify(id)} — must match /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/`\n );\n }\n return path.join(resolveConnectorsDir(memoryDir), `${id}.json`);\n}\n\nfunction resolveConnectorLockPath(memoryDir: string, id: string): string {\n if (!isValidConnectorId(id)) {\n throw new TypeError(\n `invalid connector id ${JSON.stringify(id)} — must match /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/`\n );\n }\n return path.join(resolveConnectorLocksDir(memoryDir), `${id}.lock`);\n}\n\n/**\n * Type guard for parsed state records. Validates the on-disk shape so a\n * corrupted/edited file produces a clear error rather than crashing later.\n *\n * Per CLAUDE.md gotcha #18, JSON.parse('null') yields `null` which would\n * pass a naive truthy check. We explicitly require an object.\n */\nfunction isConnectorStateShape(value: unknown): value is ConnectorState {\n if (typeof value !== \"object\" || value === null) return false;\n const v = value as Record<string, unknown>;\n if (typeof v.id !== \"string\") return false;\n if (typeof v.lastSyncStatus !== \"string\") return false;\n if (![\"success\", \"error\", \"never\"].includes(v.lastSyncStatus)) return false;\n // totalDocsImported is a cumulative count — fractional values would corrupt\n // metrics on later increments. Mirror the boundary check in writeConnectorState.\n if (typeof v.totalDocsImported !== \"number\" || !Number.isInteger(v.totalDocsImported)) return false;\n if (v.totalDocsImported < 0) return false;\n if (typeof v.updatedAt !== \"string\") return false;\n if (v.lastSyncAt !== null && typeof v.lastSyncAt !== \"string\") return false;\n if (v.cursor !== null) {\n if (typeof v.cursor !== \"object\" || v.cursor === null) return false;\n const c = v.cursor as Record<string, unknown>;\n if (typeof c.kind !== \"string\" || typeof c.value !== \"string\" || typeof c.updatedAt !== \"string\") {\n return false;\n }\n }\n if (v.lastSyncError !== undefined && typeof v.lastSyncError !== \"string\") return false;\n return true;\n}\n\nfunction isConnectorLockMetadata(value: unknown): value is ConnectorLockMetadata {\n if (typeof value !== \"object\" || value === null) return false;\n const v = value as Record<string, unknown>;\n return (\n typeof v.pid === \"number\" &&\n Number.isInteger(v.pid) &&\n v.pid > 0 &&\n typeof v.token === \"string\" &&\n v.token.length > 0 &&\n typeof v.createdAt === \"string\" &&\n typeof v.refreshedAt === \"string\"\n );\n}\n\nfunction connectorLockMetadata(token: string, createdAt = new Date().toISOString()): ConnectorLockMetadata {\n return {\n pid: process.pid,\n token,\n createdAt,\n refreshedAt: new Date().toISOString(),\n };\n}\n\nasync function readConnectorLockMetadata(lockPath: string): Promise<ConnectorLockMetadata | null> {\n let raw: string;\n try {\n raw = await fs.readFile(lockPath, \"utf8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n try {\n const parsed = JSON.parse(raw) as unknown;\n return isConnectorLockMetadata(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction parseConnectorLockMetadata(raw: string): ConnectorLockMetadata | null {\n try {\n const parsed = JSON.parse(raw) as unknown;\n return isConnectorLockMetadata(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction isSameFileIdentity(left: import(\"node:fs\").Stats, right: import(\"node:fs\").Stats): boolean {\n return left.dev === right.dev && left.ino === right.ino;\n}\n\n/**\n * Reject any path component along `<memoryDir>/state/connectors/<id>.json`\n * that is a symlink. Without this guard, a symlink in any of those\n * components would let `fs.readFile` escape the memory root and consume an\n * arbitrary outside file as cursor state — silently poisoning sync state and\n * violating the project-wide rule against symlink traversal.\n *\n * `lstat` is used (not `stat`) so we observe the link itself rather than its\n * target. Missing components are tolerated — the caller's `readFile` /\n * `mkdir` will surface ENOENT in its normal way.\n *\n * (PR #724 review.)\n */\nasync function assertNoSymlinkOnPath(memoryDir: string, filePath: string): Promise<void> {\n const expandedRoot = expandTildePath(memoryDir);\n // Normalize so `..` segments can't bypass the prefix check below.\n const root = path.resolve(expandedRoot);\n const target = path.resolve(filePath);\n const rel = path.relative(root, target);\n // path.relative() yields a \"../...\" prefix when target escapes root.\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) {\n throw new Error(`connector state path ${target} escapes memory root ${root}`);\n }\n // Walk every component from root to target (inclusive) and lstat each.\n const segments = rel.length === 0 ? [] : rel.split(path.sep);\n let current = root;\n const componentsToCheck = [current];\n for (const seg of segments) {\n current = path.join(current, seg);\n componentsToCheck.push(current);\n }\n for (const component of componentsToCheck) {\n let stat: import(\"node:fs\").Stats;\n try {\n stat = await fs.lstat(component);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n // Not yet created — that's fine; caller's readFile/mkdir handles it.\n continue;\n }\n throw err;\n }\n if (stat.isSymbolicLink()) {\n throw new Error(`connector state path component ${component} is a symlink; refusing to follow`);\n }\n }\n}\n\nasync function tryAcquireConnectorLock(memoryDir: string, id: string): Promise<ConnectorLockLease | null> {\n const dir = resolveConnectorLocksDir(memoryDir);\n const lockPath = resolveConnectorLockPath(memoryDir, id);\n await assertNoSymlinkOnPath(memoryDir, lockPath);\n await fs.mkdir(dir, { recursive: true });\n let handle: Awaited<ReturnType<typeof fs.open>> | null = null;\n let acquiredLockFile = false;\n const token = randomUUID();\n try {\n handle = await fs.open(lockPath, \"wx\", 0o600);\n acquiredLockFile = true;\n await handle.writeFile(`${JSON.stringify(connectorLockMetadata(token))}\\n`, \"utf8\");\n await handle.close();\n handle = null;\n return { path: lockPath, token };\n } catch (err) {\n if (acquiredLockFile) {\n if (handle !== null) {\n try {\n await handle.close();\n } catch {\n // The original write/close failure is more actionable.\n }\n }\n try {\n await fs.unlink(lockPath);\n } catch (cleanupErr) {\n if ((cleanupErr as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new AggregateError(\n [err, cleanupErr],\n `failed to initialize connector state lock at ${lockPath}; cleanup also failed`\n );\n }\n }\n throw err;\n }\n if ((err as NodeJS.ErrnoException).code !== \"EEXIST\") {\n throw err;\n }\n let stat: import(\"node:fs\").Stats;\n try {\n stat = await fs.lstat(lockPath);\n } catch (statErr) {\n if ((statErr as NodeJS.ErrnoException).code === \"ENOENT\") {\n return null;\n }\n throw statErr;\n }\n if (stat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lockPath} is a symlink; refusing to follow`);\n }\n if (Date.now() - stat.mtimeMs > CONNECTOR_LOCK_STALE_MS) {\n await unlinkStaleConnectorLock(lockPath);\n return null;\n }\n return null;\n }\n}\n\nasync function shouldUnlinkStaleConnectorLock(lockPath: string, stat: import(\"node:fs\").Stats): Promise<boolean> {\n if (Date.now() - stat.mtimeMs <= CONNECTOR_LOCK_STALE_MS) return false;\n const metadata = await readConnectorLockMetadata(lockPath);\n if (metadata === null) return true;\n const refreshedAtMs = Date.parse(metadata.refreshedAt);\n if (!Number.isFinite(refreshedAtMs)) return true;\n return Date.now() - refreshedAtMs > CONNECTOR_LOCK_STALE_MS;\n}\n\nasync function unlinkStaleConnectorLock(lockPath: string): Promise<void> {\n const reclaimHandle = await openConnectorReclaimLock(lockPath);\n if (!reclaimHandle) return;\n try {\n await reclaimHandle.writeFile(`${process.pid}:${new Date().toISOString()}`, \"utf8\");\n await unlinkStaleConnectorLockWhileReclaimHeld(lockPath);\n } finally {\n await reclaimHandle.close().catch(() => undefined);\n await fs.unlink(connectorReclaimLockPath(lockPath)).catch(() => undefined);\n }\n}\n\nasync function unlinkStaleConnectorLockWhileReclaimHeld(lockPath: string): Promise<void> {\n let stat: import(\"node:fs\").Stats;\n try {\n stat = await fs.lstat(lockPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw err;\n }\n if (stat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lockPath} is a symlink; refusing to follow`);\n }\n if (!(await shouldUnlinkStaleConnectorLock(lockPath, stat))) return;\n try {\n await fs.unlink(lockPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n}\n\nfunction connectorReclaimLockPath(lockPath: string): string {\n return `${lockPath}.reclaim`;\n}\n\nasync function openConnectorReclaimLock(lockPath: string): Promise<Awaited<ReturnType<typeof fs.open>> | null> {\n const reclaimPath = connectorReclaimLockPath(lockPath);\n try {\n return await fs.open(reclaimPath, \"wx\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"EEXIST\") throw err;\n }\n\n let reclaimStat: import(\"node:fs\").Stats;\n try {\n reclaimStat = await fs.lstat(reclaimPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n if (reclaimStat.isSymbolicLink()) {\n throw new Error(`connector state path component ${reclaimPath} is a symlink; refusing to follow`);\n }\n if (Date.now() - reclaimStat.mtimeMs <= CONNECTOR_LOCK_STALE_MS) return null;\n await fs.unlink(reclaimPath);\n\n try {\n return await fs.open(reclaimPath, \"wx\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"EEXIST\") return null;\n throw err;\n }\n}\n\nasync function refreshConnectorLock(lease: ConnectorLockLease): Promise<boolean> {\n const reclaimHandle = await openConnectorReclaimLock(lease.path);\n if (!reclaimHandle) return false;\n try {\n await reclaimHandle.writeFile(`${process.pid}:${new Date().toISOString()}`, \"utf8\");\n return await refreshConnectorLockWhileReclaimHeld(lease);\n } finally {\n await reclaimHandle.close().catch(() => undefined);\n await fs.unlink(connectorReclaimLockPath(lease.path)).catch(() => undefined);\n }\n}\n\nasync function refreshConnectorLockWhileReclaimHeld(lease: ConnectorLockLease): Promise<boolean> {\n let handle: Awaited<ReturnType<typeof fs.open>>;\n try {\n handle = await fs.open(lease.path, \"r+\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n throw err;\n }\n try {\n const openedStat = await handle.stat();\n const metadata = parseConnectorLockMetadata(await handle.readFile(\"utf8\"));\n if (metadata?.token !== lease.token) return false;\n const body = `${JSON.stringify(connectorLockMetadata(lease.token, metadata.createdAt))}\\n`;\n await handle.truncate(0);\n await handle.write(body, 0, \"utf8\");\n let pathStat: import(\"node:fs\").Stats;\n try {\n pathStat = await fs.lstat(lease.path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n throw err;\n }\n if (pathStat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lease.path} is a symlink; refusing to follow`);\n }\n return isSameFileIdentity(openedStat, pathStat);\n } finally {\n await handle.close();\n }\n}\n\nasync function releaseConnectorLock(lease: ConnectorLockLease): Promise<void> {\n const reclaimHandle = await openConnectorReclaimLock(lease.path);\n if (!reclaimHandle) return;\n try {\n await reclaimHandle.writeFile(`${process.pid}:${new Date().toISOString()}`, \"utf8\");\n await releaseConnectorLockWhileReclaimHeld(lease);\n } finally {\n await reclaimHandle.close().catch(() => undefined);\n await fs.unlink(connectorReclaimLockPath(lease.path)).catch(() => undefined);\n }\n}\n\nasync function releaseConnectorLockWhileReclaimHeld(lease: ConnectorLockLease): Promise<void> {\n let handle: Awaited<ReturnType<typeof fs.open>>;\n try {\n handle = await fs.open(lease.path, \"r\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw err;\n }\n try {\n const openedStat = await handle.stat();\n const metadata = parseConnectorLockMetadata(await handle.readFile(\"utf8\"));\n if (metadata?.token !== lease.token) return;\n let pathStat: import(\"node:fs\").Stats;\n try {\n pathStat = await fs.lstat(lease.path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw err;\n }\n if (pathStat.isSymbolicLink()) {\n throw new Error(`connector state path component ${lease.path} is a symlink; refusing to follow`);\n }\n if (!isSameFileIdentity(openedStat, pathStat)) return;\n try {\n await fs.unlink(lease.path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n } finally {\n await handle.close();\n }\n}\n\nasync function withConnectorStateLockInternal<T>(\n memoryDir: string,\n id: string,\n run: (abortSignal: AbortSignal) => Promise<T>,\n options: ConnectorStateLockOptions = {}\n): Promise<T> {\n const deadline = Date.now() + CONNECTOR_LOCK_TIMEOUT_MS;\n let lease: ConnectorLockLease | null = null;\n while (lease === null) {\n lease = await tryAcquireConnectorLock(memoryDir, id);\n if (lease !== null) break;\n if (Date.now() >= deadline) {\n throw new Error(`timed out waiting for connector \"${id}\" state lock`);\n }\n await delay(CONNECTOR_LOCK_RETRY_MS);\n }\n const abortController = new AbortController();\n let rejectLockLost!: (err: Error) => void;\n let lockLost = false;\n const lockLostPromise = new Promise<never>((_resolve, reject) => {\n rejectLockLost = reject;\n });\n const failLostLock = (message: string): void => {\n if (lockLost) return;\n lockLost = true;\n const err = new ConnectorStateLockLostError(message);\n abortController.abort(err);\n rejectLockLost(err);\n };\n const heartbeat = setInterval(() => {\n void refreshConnectorLock(lease)\n .then((refreshed) => {\n if (!refreshed) {\n failLostLock(`lost connector \"${id}\" state lock`);\n }\n })\n .catch((err) => {\n const message = err instanceof Error ? err.message : String(err);\n failLostLock(`lost connector \"${id}\" state lock: ${message}`);\n });\n }, options.heartbeatMs ?? CONNECTOR_LOCK_HEARTBEAT_MS);\n if (options.unrefHeartbeat !== false) {\n heartbeat.unref?.();\n }\n const runPromise = run(abortController.signal);\n try {\n return await Promise.race([runPromise, lockLostPromise]);\n } catch (err) {\n if (err instanceof ConnectorStateLockLostError) {\n await runPromise.catch(() => undefined);\n }\n throw err;\n } finally {\n clearInterval(heartbeat);\n await releaseConnectorLock(lease);\n }\n}\n\nexport async function withConnectorStateLock<T>(\n memoryDir: string,\n id: string,\n run: (abortSignal: AbortSignal) => Promise<T>\n): Promise<T> {\n return withConnectorStateLockInternal(memoryDir, id, run);\n}\n\nexport async function _withConnectorStateLockForTest<T>(\n memoryDir: string,\n id: string,\n run: (abortSignal: AbortSignal) => Promise<T>,\n options: ConnectorStateLockOptions\n): Promise<T> {\n return withConnectorStateLockInternal(memoryDir, id, run, options);\n}\n\n/**\n * Read the persisted state for a single connector.\n *\n * Returns `null` if the file does not exist (ENOENT). Throws on any other\n * I/O error or on shape mismatch — operators should see corruption loudly.\n *\n * Rejects symlinks anywhere on the path so a planted symlink can't redirect\n * reads outside the memory root. (PR #724 review.)\n */\nexport async function readConnectorState(memoryDir: string, id: string): Promise<ConnectorState | null> {\n const filePath = resolveConnectorStatePath(memoryDir, id);\n await assertNoSymlinkOnPath(memoryDir, filePath);\n let raw: string;\n try {\n raw = await fs.readFile(filePath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (err) {\n throw new ConnectorStateCorruptionError(\n `connector state at ${filePath} is not valid JSON: ${(err as Error).message}`\n );\n }\n if (!isConnectorStateShape(parsed)) {\n throw new ConnectorStateCorruptionError(`connector state at ${filePath} does not match ConnectorState shape`);\n }\n if (parsed.id !== id) {\n throw new ConnectorStateCorruptionError(\n `connector state at ${filePath} has mismatched id ${JSON.stringify(parsed.id)}; expected ${JSON.stringify(id)}`\n );\n }\n return parsed;\n}\n\n/**\n * Write state atomically: create-tmp + rename. Never destroys the previous\n * file before the new one is in place — see CLAUDE.md gotcha #54.\n *\n * We accept `Omit<ConnectorState, \"updatedAt\">` and stamp `updatedAt`\n * ourselves so callers can't accidentally persist a stale timestamp.\n */\nexport async function writeConnectorState(\n memoryDir: string,\n id: string,\n state: Omit<ConnectorState, \"updatedAt\">\n): Promise<ConnectorState> {\n if (!isValidConnectorId(id)) {\n throw new TypeError(\n `invalid connector id ${JSON.stringify(id)} — must match /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/`\n );\n }\n if (state.id !== id) {\n throw new Error(\n `writeConnectorState(): state.id ${JSON.stringify(state.id)} does not match id argument ${JSON.stringify(id)}`\n );\n }\n // Full boundary validation. Persisting an out-of-shape record would brick\n // the connector's cursor file: subsequent `readConnectorState` calls would\n // throw `ConnectorStateCorruptionError` until manual repair. JS callers\n // bypassing TS types must be rejected here, not later. (PR #724 review.)\n if (!VALID_SYNC_STATUSES.has(state.lastSyncStatus as ConnectorSyncStatus)) {\n throw new Error(\n `writeConnectorState(): lastSyncStatus must be one of ${[...VALID_SYNC_STATUSES].join(\", \")}, got ${JSON.stringify(state.lastSyncStatus)}`\n );\n }\n if (state.lastSyncAt !== null && typeof state.lastSyncAt !== \"string\") {\n throw new Error(`writeConnectorState(): lastSyncAt must be a string or null, got ${typeof state.lastSyncAt}`);\n }\n if (state.cursor !== null) {\n if (typeof state.cursor !== \"object\") {\n throw new Error(`writeConnectorState(): cursor must be an object or null`);\n }\n if (\n typeof state.cursor.kind !== \"string\" ||\n typeof state.cursor.value !== \"string\" ||\n typeof state.cursor.updatedAt !== \"string\"\n ) {\n throw new Error(`writeConnectorState(): cursor must have string kind, value, and updatedAt`);\n }\n }\n if (\n typeof state.totalDocsImported !== \"number\" ||\n !Number.isInteger(state.totalDocsImported) ||\n state.totalDocsImported < 0\n ) {\n throw new Error(`writeConnectorState(): totalDocsImported must be a non-negative integer`);\n }\n if (state.lastSyncError !== undefined && typeof state.lastSyncError !== \"string\") {\n throw new Error(`writeConnectorState(): lastSyncError must be a string when provided`);\n }\n const truncatedError =\n state.lastSyncError !== undefined && state.lastSyncError.length > MAX_ERROR_LENGTH\n ? state.lastSyncError.slice(0, MAX_ERROR_LENGTH)\n : state.lastSyncError;\n\n const finalState: ConnectorState = {\n id: state.id,\n cursor: state.cursor,\n lastSyncAt: state.lastSyncAt,\n lastSyncStatus: state.lastSyncStatus,\n ...(truncatedError !== undefined ? { lastSyncError: truncatedError } : {}),\n totalDocsImported: state.totalDocsImported,\n updatedAt: new Date().toISOString(),\n };\n\n const dir = resolveConnectorsDir(memoryDir);\n const targetPath = path.join(dir, `${id}.json`);\n // Reject planted symlinks before mkdir/write so a redirected target can't\n // overwrite an arbitrary file outside the memory root. (PR #724 review.)\n await assertNoSymlinkOnPath(memoryDir, targetPath);\n await fs.mkdir(dir, { recursive: true });\n const tmpPath = `${targetPath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n\n const body = `${JSON.stringify(finalState, null, 2)}\\n`;\n try {\n await fs.writeFile(tmpPath, body, { encoding: \"utf-8\", mode: 0o600 });\n await fs.rename(tmpPath, targetPath);\n } catch (err) {\n // Best-effort cleanup of the tmp file. Never touch `targetPath` — the\n // previous good state must remain readable on failure.\n try {\n await fs.unlink(tmpPath);\n } catch {\n // ignore\n }\n throw err;\n }\n return finalState;\n}\n\n/**\n * Enumerate every persisted connector state. Returns an empty array when\n * the directory does not exist yet (clean install, no syncs ever run).\n *\n * Files that do not match the `<id>.json` naming rule are skipped — this\n * keeps stray editor backups (`.json~`, `.swp`) from breaking enumeration.\n *\n * Corruption (unparseable JSON, shape mismatch, id mismatch) is also\n * skipped so one bad file doesn't take down the listing. Operators\n * inspecting `state/connectors/` can still see the offending file by hand.\n *\n * **Genuine I/O failures (`EACCES`, `EIO`, etc.) are NOT swallowed** —\n * silently returning an incomplete state set would make active connectors\n * appear missing and trigger duplicate ingestion on the next scheduler tick.\n * (PR #724 review.)\n */\nexport async function listConnectorStates(memoryDir: string): Promise<ConnectorState[]> {\n const dir = resolveConnectorsDir(memoryDir);\n // Refuse to enumerate through a symlinked state directory — a planted\n // symlink at <memoryDir>/state or <memoryDir>/state/connectors would\n // otherwise let reads escape the memory root. (PR #724 review.)\n await assertNoSymlinkOnPath(memoryDir, dir);\n let entries: string[];\n try {\n entries = await fs.readdir(dir);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n throw err;\n }\n const out: ConnectorState[] = [];\n for (const entry of entries) {\n if (!entry.endsWith(\".json\")) continue;\n const id = entry.slice(0, -\".json\".length);\n if (!isValidConnectorId(id)) continue;\n try {\n const state = await readConnectorState(memoryDir, id);\n if (state !== null) out.push(state);\n } catch (err) {\n if (err instanceof ConnectorStateCorruptionError) {\n // Skip corrupt files; preserve availability of the rest.\n continue;\n }\n // Anything else (EACCES, EIO, ENOTDIR, ...) is a real operational\n // failure. Fail loudly so the scheduler / CLI can surface it.\n throw err;\n }\n }\n out.sort((a, b) => a.id.localeCompare(b.id));\n return out;\n}\n\n/**\n * Test-only helper: resolve where a given connector's state lives. Exported\n * so tests can assert the on-disk layout without duplicating the path math.\n * Not part of the stable public API.\n *\n * @internal\n */\nexport function _connectorStatePathForTest(memoryDir: string, id: string): string {\n return resolveConnectorStatePath(memoryDir, id);\n}\n\nexport const _unlinkStaleConnectorLockForTest = unlinkStaleConnectorLock;\nexport const _tryAcquireConnectorLockForTest = tryAcquireConnectorLock;\nexport const _refreshConnectorLockForTest = refreshConnectorLock;\nexport const _releaseConnectorLockForTest = releaseConnectorLock;\n","/**\n * @remnic/core — Live Connectors Framework (issue #683 PR 1/N)\n *\n * Defines the contract that every \"live\" connector (Drive, Notion, Gmail,\n * GitHub, ...) must satisfy. A live connector is **continuous**: it runs on a\n * schedule, persists a cursor to disk, and ingests *new* documents since the\n * last sync. This is distinct from one-shot importers in\n * `packages/remnic-core/src/importers/` which transform an entire export file\n * in a single pass.\n *\n * This module is intentionally pure types + interfaces. No I/O. No schedule\n * wiring. Concrete connectors (PRs 2–5), the maintenance scheduler hookup\n * (separate PR), and the CLI surface (PR 6) are deferred.\n *\n * Naming caveat: `packages/remnic-core/src/connectors/` is already scoped to\n * the Codex marketplace integration. The live-connector framework lives under\n * the `live/` subdirectory to avoid collision. Do not import Codex symbols\n * from here, and do not import live-connector symbols from the Codex code.\n */\n\n/**\n * Free-form connector configuration. Validated by each connector's\n * `validateConfig` implementation and passed to `syncIncremental` for runtime\n * use. MUST be JSON-serializable: no functions, no class instances, no\n * circular references.\n *\n * Runtime configs may contain hydrated credentials. Do not persist a runtime\n * config directly. Any code that needs to store connector settings must call\n * `persistableConnectorConfig()` so credentials are stripped or replaced by\n * connector-owned references.\n */\nexport type ConnectorConfig = Record<string, unknown>;\n\nconst DEFAULT_SECRET_KEY_PARTS = [\n \"token\",\n \"secret\",\n \"password\",\n \"credential\",\n \"apikey\",\n \"accesskey\",\n \"privatekey\",\n \"authorization\",\n \"authheader\",\n \"cookie\",\n] as const;\n\n/**\n * Redact secret-looking keys from a JSON-serializable connector config.\n * Built-in connectors provide explicit projections, but this default keeps\n * third-party connectors from accidentally persisting obvious credentials.\n */\nexport function redactConnectorConfigSecrets(config: ConnectorConfig): ConnectorConfig {\n return redactConnectorConfigValue(config) as ConnectorConfig;\n}\n\nfunction redactConnectorConfigValue(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => redactConnectorConfigValue(item));\n }\n if (typeof value !== \"object\" || value === null) {\n return value;\n }\n const out: Record<string, unknown> = {};\n for (const [key, nested] of Object.entries(value as Record<string, unknown>)) {\n if (isConnectorSecretConfigKey(key)) {\n continue;\n }\n out[key] = redactConnectorConfigValue(nested);\n }\n return out;\n}\n\nfunction isConnectorSecretConfigKey(key: string): boolean {\n const normalized = key.replace(/[^a-z0-9]/giu, \"\").toLowerCase();\n return DEFAULT_SECRET_KEY_PARTS.some((part) => normalized.includes(part));\n}\n\n/**\n * Opaque cursor describing \"where the last sync left off\". Each connector\n * defines what `kind` and `value` mean (e.g. Drive: `{kind: \"pageToken\",\n * value: \"...\"}`, Gmail: `{kind: \"historyId\", value: \"...\"}`). The orchestrator\n * treats it as opaque and only round-trips it through the state store.\n *\n * `updatedAt` is an ISO 8601 timestamp set by the framework when the cursor is\n * written. It is informational — connectors MUST NOT use it to decide\n * monotonicity. They own the `value` semantics.\n */\nexport interface ConnectorCursor {\n /** Connector-defined cursor kind (e.g. `\"pageToken\"`, `\"historyId\"`, `\"sinceTs\"`). */\n readonly kind: string;\n /** Connector-defined opaque cursor value. */\n readonly value: string;\n /** ISO 8601 timestamp of when this cursor was last written. */\n readonly updatedAt: string;\n}\n\n/**\n * Provenance for a connector-ingested document. Required so downstream recall\n * can attribute facts back to their origin and avoid re-ingesting on the next\n * incremental pass.\n */\nexport interface ConnectorDocumentSource {\n /** Stable connector id (matches `LiveConnector.id`). */\n readonly connector: string;\n /** Source-system identifier (Drive file id, Notion page id, Gmail msg id, ...). */\n readonly externalId: string;\n /** Optional source-system revision/version (etag, page version, history id). */\n readonly externalRevision?: string;\n /** Optional canonical URL pointing back at the source document. */\n readonly externalUrl?: string;\n /** ISO 8601 timestamp of when the connector fetched this document. */\n readonly fetchedAt: string;\n}\n\n/**\n * A single document yielded by an incremental sync. Connectors are responsible\n * for chunking large source documents themselves if needed; the orchestrator\n * ingests `content` as a unit.\n */\nexport interface ConnectorDocument {\n /** Connector-local stable id for this document. SHOULD match `source.externalId`. */\n readonly id: string;\n /** Optional human-readable title. */\n readonly title?: string;\n /** Body content. Plaintext or Markdown — connectors document their format. */\n readonly content: string;\n /** Provenance. Required. */\n readonly source: ConnectorDocumentSource;\n}\n\n/**\n * Arguments passed to `syncIncremental`. The framework owns cursor/config\n * lifecycle; connectors only read these and return the next cursor.\n */\nexport interface SyncIncrementalArgs {\n /** Last persisted cursor, or `null` on the first ever sync. */\n readonly cursor: ConnectorCursor | null;\n /** Validated connector config (already passed through `validateConfig`). */\n readonly config: ConnectorConfig;\n /** Optional abort signal. Connectors SHOULD honor it for cooperative cancellation. */\n readonly abortSignal?: AbortSignal;\n}\n\n/**\n * Result of a single incremental sync pass.\n *\n * `newDocs` MAY be empty (no new documents since the last cursor). `nextCursor`\n * MUST always be returned — even on no-op syncs the framework persists it so\n * `updatedAt` reflects the most recent attempt.\n */\nexport interface SyncIncrementalResult {\n readonly newDocs: ConnectorDocument[];\n readonly nextCursor: ConnectorCursor;\n}\n\n/**\n * The contract every live connector implements.\n *\n * Connectors MUST be:\n * - **Idempotent**: re-running with the same cursor MUST NOT duplicate\n * documents. The `source.externalId` + `source.externalRevision` pair is\n * used downstream for dedup.\n * - **Read-only on the source**: live connectors never mutate the upstream\n * system (no marking emails read, no editing Notion pages).\n * - **Cancellable**: long-running syncs SHOULD periodically check\n * `abortSignal.aborted` and bail cleanly.\n * - **Privacy-aware**: connectors MUST NOT log document content. Logging\n * metadata (counts, ids, timings) is fine.\n */\nexport interface LiveConnector {\n /**\n * Stable connector id. MUST match `CONNECTOR_ID_PATTERN` — lowercase\n * alphanumeric plus dash, 1–64 chars, must start AND end with alphanumeric\n * (no leading or trailing dash). The registry enforces this.\n */\n readonly id: string;\n /** Short human-readable name shown in CLI / status output. */\n readonly displayName: string;\n /** Optional longer description. */\n readonly description?: string;\n\n /**\n * Validate raw user-supplied config. MUST throw on malformed input — never\n * silently default. The returned object is the runtime config passed back to\n * `syncIncremental`; it may contain hydrated credentials and MUST NOT be\n * persisted directly. Connectors SHOULD strip unknown fields.\n */\n validateConfig(raw: unknown): ConnectorConfig;\n\n /**\n * Return the subset of validated config that may be written to disk. Use this\n * for state/config persistence instead of `validateConfig()`. Connectors that\n * need credentials should omit the raw values here and store only non-secret\n * scope/schedule fields plus any connector-owned secret references.\n */\n persistConfig?(validated: ConnectorConfig): ConnectorConfig;\n\n /**\n * Run one incremental sync pass. See `SyncIncrementalArgs` /\n * `SyncIncrementalResult` for the contract.\n */\n syncIncremental(args: SyncIncrementalArgs): Promise<SyncIncrementalResult>;\n}\n\nexport function persistableConnectorConfig(\n connector: Pick<LiveConnector, \"persistConfig\">,\n validated: ConnectorConfig,\n): ConnectorConfig {\n if (typeof connector.persistConfig === \"function\") {\n return connector.persistConfig(validated);\n }\n return redactConnectorConfigSecrets(validated);\n}\n\n/**\n * Regex enforcing the connector-id naming rule. Exported so connectors and\n * tests can validate ids consistently with the registry.\n *\n * Rule: lowercase alphanumeric + dash, 1..64 chars, must start AND end with\n * alphanumeric (no leading or trailing dash). Single-char ids are allowed.\n */\nexport const CONNECTOR_ID_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;\n\n/**\n * Returns `true` if `id` is a syntactically valid connector id.\n */\nexport function isValidConnectorId(id: unknown): id is string {\n return typeof id === \"string\" && CONNECTOR_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ateFromEngram
|
|
3
|
-
} from "./chunk-S53PKKWK.js";
|
|
4
1
|
import {
|
|
5
2
|
ensureContradictionScanCron,
|
|
6
3
|
ensureDaySummaryCron,
|
|
@@ -10,6 +7,9 @@ import {
|
|
|
10
7
|
ensureProceduralMiningCron,
|
|
11
8
|
graphEdgeDecayCadenceToCronExpr
|
|
12
9
|
} from "./chunk-BFBF3XEF.js";
|
|
10
|
+
import {
|
|
11
|
+
migrateFromEngram
|
|
12
|
+
} from "./chunk-S53PKKWK.js";
|
|
13
13
|
import {
|
|
14
14
|
LcmEngine
|
|
15
15
|
} from "./chunk-RLV3PQGH.js";
|
|
@@ -124,7 +124,7 @@ import {
|
|
|
124
124
|
} from "./chunk-3GPTTA4J.js";
|
|
125
125
|
import {
|
|
126
126
|
runLiveConnectorsOnce
|
|
127
|
-
} from "./chunk-
|
|
127
|
+
} from "./chunk-VU3SVYMA.js";
|
|
128
128
|
import {
|
|
129
129
|
evaluateMemoryActionPolicy
|
|
130
130
|
} from "./chunk-H63EDPFJ.js";
|
|
@@ -12398,4 +12398,4 @@ export {
|
|
|
12398
12398
|
resolvePersistedMemoryRelativePath,
|
|
12399
12399
|
Orchestrator
|
|
12400
12400
|
};
|
|
12401
|
-
//# sourceMappingURL=chunk-
|
|
12401
|
+
//# sourceMappingURL=chunk-KLZDGMDI.js.map
|
|
@@ -158,10 +158,10 @@ import {
|
|
|
158
158
|
validateGmailConfig,
|
|
159
159
|
validateGoogleDriveConfig,
|
|
160
160
|
validateNotionConfig
|
|
161
|
-
} from "./chunk-
|
|
161
|
+
} from "./chunk-TQNRI55H.js";
|
|
162
162
|
import {
|
|
163
163
|
listConnectorStates
|
|
164
|
-
} from "./chunk-
|
|
164
|
+
} from "./chunk-6GUG4YNM.js";
|
|
165
165
|
import {
|
|
166
166
|
rescoreMemoryImportance
|
|
167
167
|
} from "./chunk-JXS5PDQ7.js";
|
|
@@ -3895,7 +3895,7 @@ function registerCli(api, orchestrator, registerOptions = {}) {
|
|
|
3895
3895
|
process.exitCode = 2;
|
|
3896
3896
|
return;
|
|
3897
3897
|
}
|
|
3898
|
-
const { readConnectorState, withConnectorStateLock, writeConnectorState } = await import("./state-store-
|
|
3898
|
+
const { readConnectorState, withConnectorStateLock, writeConnectorState } = await import("./state-store-Z3EN56O5.js");
|
|
3899
3899
|
const sharedIngestFn = async (docs) => {
|
|
3900
3900
|
const fetchedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3901
3901
|
const turns = docs.map((doc) => ({
|
|
@@ -6616,4 +6616,4 @@ export {
|
|
|
6616
6616
|
resolveMemoryDirForNamespace,
|
|
6617
6617
|
registerCli
|
|
6618
6618
|
};
|
|
6619
|
-
//# sourceMappingURL=chunk-
|
|
6619
|
+
//# sourceMappingURL=chunk-SRAF4TIS.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isValidConnectorId
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6GUG4YNM.js";
|
|
4
4
|
|
|
5
5
|
// src/connectors/live/registry.ts
|
|
6
6
|
var LiveConnectorRegistryError = class extends Error {
|
|
@@ -281,6 +281,14 @@ function createGoogleDriveConnector(options = {}) {
|
|
|
281
281
|
validateConfig(raw) {
|
|
282
282
|
return validateGoogleDriveConfig(raw);
|
|
283
283
|
},
|
|
284
|
+
persistConfig(validated) {
|
|
285
|
+
const config = validateGoogleDriveConfig(validated);
|
|
286
|
+
return Object.freeze({
|
|
287
|
+
clientId: config.clientId,
|
|
288
|
+
pollIntervalMs: config.pollIntervalMs,
|
|
289
|
+
folderIds: config.folderIds
|
|
290
|
+
});
|
|
291
|
+
},
|
|
284
292
|
async syncIncremental(args) {
|
|
285
293
|
const config = validateGoogleDriveConfig(args.config);
|
|
286
294
|
throwIfAborted(args.abortSignal);
|
|
@@ -739,6 +747,13 @@ function createNotionConnector(options = {}) {
|
|
|
739
747
|
validateConfig(raw) {
|
|
740
748
|
return validateNotionConfig(raw);
|
|
741
749
|
},
|
|
750
|
+
persistConfig(validated) {
|
|
751
|
+
const config = validateNotionConfig(validated);
|
|
752
|
+
return Object.freeze({
|
|
753
|
+
databaseIds: config.databaseIds,
|
|
754
|
+
pollIntervalMs: config.pollIntervalMs
|
|
755
|
+
});
|
|
756
|
+
},
|
|
742
757
|
async syncIncremental(args) {
|
|
743
758
|
const config = validateNotionConfig(args.config);
|
|
744
759
|
throwIfAborted2(args.abortSignal);
|
|
@@ -1269,6 +1284,15 @@ function createGmailConnector(options = {}) {
|
|
|
1269
1284
|
validateConfig(raw) {
|
|
1270
1285
|
return validateGmailConfig(raw);
|
|
1271
1286
|
},
|
|
1287
|
+
persistConfig(validated) {
|
|
1288
|
+
const config = validateGmailConfig(validated);
|
|
1289
|
+
return Object.freeze({
|
|
1290
|
+
clientId: config.clientId,
|
|
1291
|
+
userId: config.userId,
|
|
1292
|
+
query: config.query,
|
|
1293
|
+
pollIntervalMs: config.pollIntervalMs
|
|
1294
|
+
});
|
|
1295
|
+
},
|
|
1272
1296
|
async syncIncremental(args) {
|
|
1273
1297
|
const config = validateGmailConfig(args.config);
|
|
1274
1298
|
throwIfAborted3(args.abortSignal);
|
|
@@ -1692,6 +1716,15 @@ function createGitHubConnector(options = {}) {
|
|
|
1692
1716
|
validateConfig(raw) {
|
|
1693
1717
|
return validateGitHubConfig(raw);
|
|
1694
1718
|
},
|
|
1719
|
+
persistConfig(validated) {
|
|
1720
|
+
const config = validateGitHubConfig(validated);
|
|
1721
|
+
return Object.freeze({
|
|
1722
|
+
userLogin: config.userLogin,
|
|
1723
|
+
repos: config.repos,
|
|
1724
|
+
pollIntervalMs: config.pollIntervalMs,
|
|
1725
|
+
includeDiscussions: config.includeDiscussions
|
|
1726
|
+
});
|
|
1727
|
+
},
|
|
1695
1728
|
async syncIncremental(args) {
|
|
1696
1729
|
const config = validateGitHubConfig(args.config);
|
|
1697
1730
|
throwIfAborted4(args.abortSignal);
|
|
@@ -2077,4 +2110,4 @@ export {
|
|
|
2077
2110
|
validateGitHubConfig,
|
|
2078
2111
|
createGitHubConnector
|
|
2079
2112
|
};
|
|
2080
|
-
//# sourceMappingURL=chunk-
|
|
2113
|
+
//# sourceMappingURL=chunk-TQNRI55H.js.map
|