@nothumanwork/nn 0.1.0
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/LICENSE +21 -0
- package/README.md +77 -0
- package/bin/nn.js +106 -0
- package/package.json +74 -0
- package/src/config/env.ts +31 -0
- package/src/config/paths.ts +50 -0
- package/src/config/runtime.ts +37 -0
- package/src/config/sync.ts +48 -0
- package/src/db/client.ts +333 -0
- package/src/db/libsql-native.ts +66 -0
- package/src/db/lock.ts +72 -0
- package/src/db/migrate.ts +246 -0
- package/src/db/replica-migrate.ts +162 -0
- package/src/db/schema.sql +99 -0
- package/src/export/claude.ts +92 -0
- package/src/export/codex.ts +86 -0
- package/src/export/cursor.ts +68 -0
- package/src/export/generic.ts +19 -0
- package/src/export/registry.ts +118 -0
- package/src/export/types.ts +44 -0
- package/src/hooks/ingest.ts +107 -0
- package/src/hooks/resolvers/antigravity.ts +44 -0
- package/src/hooks/resolvers/claude.ts +27 -0
- package/src/hooks/resolvers/codex.ts +65 -0
- package/src/hooks/resolvers/common.ts +21 -0
- package/src/hooks/resolvers/cursor.ts +31 -0
- package/src/hooks/resolvers/grok.ts +59 -0
- package/src/hooks/resolvers/index.ts +35 -0
- package/src/hooks/resolvers/pi.ts +72 -0
- package/src/hooks/types.ts +20 -0
- package/src/index.ts +247 -0
- package/src/ingest/jsonl.ts +38 -0
- package/src/ingest/pipeline.ts +101 -0
- package/src/install/index.ts +227 -0
- package/src/install/types.ts +85 -0
- package/src/ir/event-id.ts +26 -0
- package/src/ir/types.ts +84 -0
- package/src/providers/antigravity/index.ts +175 -0
- package/src/providers/claude/index.ts +228 -0
- package/src/providers/codex/index.ts +264 -0
- package/src/providers/copilot/index.ts +24 -0
- package/src/providers/cursor/index.ts +340 -0
- package/src/providers/grok/index.ts +146 -0
- package/src/providers/pi/index.ts +197 -0
- package/src/providers/registry.ts +31 -0
- package/src/providers/types.ts +53 -0
- package/src/sync/coordinator.ts +186 -0
- package/src/sync/turso.ts +64 -0
- package/src/types/assets.d.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Human Works
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# nn
|
|
2
|
+
|
|
3
|
+
Neural Net — multi-provider transcript fabric for AI coding agents.
|
|
4
|
+
|
|
5
|
+
Ingest, search, export, and sync conversation transcripts across Cursor, Claude Code, Codex, Pi, Grok, Antigravity, and more.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @nothumanwork/nn --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install globally:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @nothumanwork/nn
|
|
17
|
+
nn --help
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Install hooks for all supported providers (project-local)
|
|
24
|
+
nn install hooks
|
|
25
|
+
|
|
26
|
+
# Install hooks globally
|
|
27
|
+
nn install hooks --global
|
|
28
|
+
|
|
29
|
+
# Ingest transcripts from a provider
|
|
30
|
+
nn ingest --provider cursor --all
|
|
31
|
+
|
|
32
|
+
# Search normalized events
|
|
33
|
+
nn search "turso sync"
|
|
34
|
+
|
|
35
|
+
# List sessions
|
|
36
|
+
nn sessions list
|
|
37
|
+
|
|
38
|
+
# Export a session (stdout by default)
|
|
39
|
+
nn export --session <id>
|
|
40
|
+
|
|
41
|
+
# Check local DB and sync health
|
|
42
|
+
nn doctor
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Commands
|
|
46
|
+
|
|
47
|
+
| Command | Description |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `nn install hooks [--global] [--provider <id>]` | Install agent hooks |
|
|
50
|
+
| `nn hook --provider <id> --event <kind>` | Hook entrypoint (used by agents) |
|
|
51
|
+
| `nn ingest --provider <id> [--session <id>] [--all]` | Ingest provider transcripts |
|
|
52
|
+
| `nn export --session <id> [--to <target>] [--output <file>]` | Export a session |
|
|
53
|
+
| `nn search <query> [--limit <n>]` | Search transcript events |
|
|
54
|
+
| `nn sessions list [--provider <id>]` | List ingested sessions |
|
|
55
|
+
| `nn sync status\|push\|pull` | Turso embedded-replica sync |
|
|
56
|
+
| `nn doctor` | Validate DB, hooks, and sync setup |
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
Local state lives in `.nn/state/` (override with `NN_STATE_DIR` or `NN_DB_PATH`).
|
|
61
|
+
|
|
62
|
+
Turso sync is optional — set `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN` to enable cloud sync.
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
This package ships prebuilt Bun-compiled binaries per platform. To build from source:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bun install
|
|
70
|
+
bun run build # host platform only
|
|
71
|
+
bun run build:all # all publish targets
|
|
72
|
+
bun test
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|
package/bin/nn.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const packageRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
11
|
+
const sourceEntry = join(packageRoot, "src/index.ts");
|
|
12
|
+
|
|
13
|
+
function isGlibcLinux() {
|
|
14
|
+
if (process.platform !== "linux") {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return Boolean(process.report?.getReport().header.glibcVersionRuntime);
|
|
19
|
+
} catch {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function activeTargetName() {
|
|
25
|
+
const { platform, arch } = process;
|
|
26
|
+
if (platform === "darwin") {
|
|
27
|
+
return `${platform}-${arch}`;
|
|
28
|
+
}
|
|
29
|
+
if (platform === "linux" && arch === "arm64") {
|
|
30
|
+
return isGlibcLinux() ? "linux-arm64-gnu" : "linux-arm64-musl";
|
|
31
|
+
}
|
|
32
|
+
if (platform === "linux" && arch === "x64") {
|
|
33
|
+
return isGlibcLinux() ? "linux-x64-gnu" : "linux-x64-musl";
|
|
34
|
+
}
|
|
35
|
+
if (platform === "win32" && arch === "x64") {
|
|
36
|
+
return "win32-x64";
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function resolvePlatformBinary() {
|
|
42
|
+
const targetName = activeTargetName();
|
|
43
|
+
if (!targetName) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const pkg = `@nothumanwork/nn-${targetName}`;
|
|
48
|
+
const isWindows = targetName === "win32-x64";
|
|
49
|
+
try {
|
|
50
|
+
const pkgRoot = dirname(require.resolve(`${pkg}/package.json`));
|
|
51
|
+
const binaryPath = join(pkgRoot, "bin", isWindows ? "nn.exe" : "nn");
|
|
52
|
+
return existsSync(binaryPath) ? binaryPath : undefined;
|
|
53
|
+
} catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function findBun() {
|
|
59
|
+
const bunFromPath = spawnSync("bun", ["--version"], {
|
|
60
|
+
encoding: "utf8",
|
|
61
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
62
|
+
});
|
|
63
|
+
if (bunFromPath.status === 0) {
|
|
64
|
+
return "bun";
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function run(cmd, args) {
|
|
70
|
+
const result = spawnSync(cmd, args, {
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
env: process.env,
|
|
73
|
+
});
|
|
74
|
+
if (result.error) {
|
|
75
|
+
console.error(`nn: failed to run ${cmd}: ${result.error.message}`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
process.exit(result.status ?? 1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const args = process.argv.slice(2);
|
|
82
|
+
const binaryPath = resolvePlatformBinary();
|
|
83
|
+
|
|
84
|
+
if (binaryPath) {
|
|
85
|
+
run(binaryPath, args);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!existsSync(sourceEntry)) {
|
|
89
|
+
console.error(
|
|
90
|
+
`nn: no prebuilt binary for ${process.platform}-${process.arch} and source entry is unavailable.`,
|
|
91
|
+
);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const bun = findBun();
|
|
96
|
+
if (!bun) {
|
|
97
|
+
console.error(
|
|
98
|
+
`nn: no prebuilt binary for ${process.platform}-${process.arch}. Install Bun (https://bun.sh) or use a supported platform.`,
|
|
99
|
+
);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.warn(
|
|
104
|
+
`nn: using Bun fallback for ${process.platform}-${process.arch} (platform package not installed)`,
|
|
105
|
+
);
|
|
106
|
+
run(bun, ["run", sourceEntry, ...args]);
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nothumanwork/nn",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Neural Net — multi-provider transcript fabric for AI coding agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "The Human Works",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/thehumanworks/nn.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/thehumanworks/nn#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/thehumanworks/nn/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cursor",
|
|
18
|
+
"claude",
|
|
19
|
+
"codex",
|
|
20
|
+
"transcripts",
|
|
21
|
+
"ai-agents",
|
|
22
|
+
"hooks",
|
|
23
|
+
"sqlite",
|
|
24
|
+
"turso"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"nn": "./bin/nn.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"bin",
|
|
34
|
+
"src",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"nn": "doppler run --config prd --project vault -- bun run src/index.ts",
|
|
43
|
+
"build": "bun run scripts/build.ts",
|
|
44
|
+
"build:all": "bun run scripts/build-all.ts",
|
|
45
|
+
"prepare:platform-packages": "bun run scripts/prepare-platform-packages.ts",
|
|
46
|
+
"install:bin": "bun run scripts/build.ts --install",
|
|
47
|
+
"prepublishOnly": "bun run build:all && bun run prepare:platform-packages",
|
|
48
|
+
"publish:all": "bun run scripts/publish-npm.ts",
|
|
49
|
+
"test": "bun test",
|
|
50
|
+
"typecheck": "bunx tsc --noEmit"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@libsql/client": "^0.17.3"
|
|
54
|
+
},
|
|
55
|
+
"optionalDependencies": {
|
|
56
|
+
"@nothumanwork/nn-darwin-arm64": "0.1.0",
|
|
57
|
+
"@nothumanwork/nn-darwin-x64": "0.1.0",
|
|
58
|
+
"@nothumanwork/nn-linux-arm64-gnu": "0.1.0",
|
|
59
|
+
"@nothumanwork/nn-linux-arm64-musl": "0.1.0",
|
|
60
|
+
"@nothumanwork/nn-linux-x64-gnu": "0.1.0",
|
|
61
|
+
"@nothumanwork/nn-linux-x64-musl": "0.1.0",
|
|
62
|
+
"@nothumanwork/nn-win32-x64": "0.1.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@libsql/darwin-arm64": "0.5.29",
|
|
66
|
+
"@libsql/darwin-x64": "0.5.29",
|
|
67
|
+
"@libsql/linux-arm64-gnu": "0.5.29",
|
|
68
|
+
"@libsql/linux-arm64-musl": "0.5.29",
|
|
69
|
+
"@libsql/linux-x64-gnu": "0.5.29",
|
|
70
|
+
"@libsql/linux-x64-musl": "0.5.29",
|
|
71
|
+
"@libsql/win32-x64-msvc": "0.5.29",
|
|
72
|
+
"@types/bun": "latest"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function readRaw(name: string): string | undefined {
|
|
2
|
+
const value = process.env[name]?.trim();
|
|
3
|
+
return value || undefined;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function envString(name: string): string | undefined {
|
|
7
|
+
return readRaw(name);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function envInt(name: string, defaultValue: number): number {
|
|
11
|
+
const raw = readRaw(name);
|
|
12
|
+
if (!raw) {
|
|
13
|
+
return defaultValue;
|
|
14
|
+
}
|
|
15
|
+
const value = Number(raw);
|
|
16
|
+
return Number.isFinite(value) && value >= 0 ? value : defaultValue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function envBool(name: string, defaultValue: boolean): boolean {
|
|
20
|
+
const raw = readRaw(name)?.toLowerCase();
|
|
21
|
+
if (!raw) {
|
|
22
|
+
return defaultValue;
|
|
23
|
+
}
|
|
24
|
+
if (["1", "true", "yes", "on"].includes(raw)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (["0", "false", "no", "off"].includes(raw)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return defaultValue;
|
|
31
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { envString } from "./env.ts";
|
|
5
|
+
|
|
6
|
+
export const DB_BASENAME = "nn.db";
|
|
7
|
+
export const LOCK_BASENAME = "nn-ingest.lock";
|
|
8
|
+
|
|
9
|
+
export function projectDir(): string {
|
|
10
|
+
return envString("NN_PROJECT_DIR") || envString("CURSOR_PROJECT_DIR") || process.cwd();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Provider-agnostic project-local state (DB, sync coordinator, locks). */
|
|
14
|
+
export function stateDir(): string {
|
|
15
|
+
const override = envString("NN_STATE_DIR");
|
|
16
|
+
if (override) {
|
|
17
|
+
return resolve(override);
|
|
18
|
+
}
|
|
19
|
+
return resolve(projectDir(), ".nn/state");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function dbPath(): string {
|
|
23
|
+
const override = envString("NN_DB_PATH");
|
|
24
|
+
if (override) {
|
|
25
|
+
return resolve(override);
|
|
26
|
+
}
|
|
27
|
+
return resolve(stateDir(), DB_BASENAME);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function lockPath(): string {
|
|
31
|
+
return resolve(stateDir(), LOCK_BASENAME);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function homeDir(): string {
|
|
35
|
+
return homedir();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function encodeProjectSlug(projectPath: string): string {
|
|
39
|
+
const normalized = projectPath.replace(/\\/g, "/");
|
|
40
|
+
if (normalized === "/") {
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
return normalized.replace(/^\//, "").replace(/\//g, "-").replace(/\./g, "-");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function ensureProjectDir(cwd?: string): void {
|
|
47
|
+
if (cwd && !envString("NN_PROJECT_DIR") && !envString("CURSOR_PROJECT_DIR")) {
|
|
48
|
+
process.env.NN_PROJECT_DIR = cwd;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
export function isCompiledExecutable(): boolean {
|
|
5
|
+
return import.meta.path.includes("/$bunfs/");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function packageRoot(): string {
|
|
9
|
+
if (isCompiledExecutable()) {
|
|
10
|
+
return dirname(process.execPath);
|
|
11
|
+
}
|
|
12
|
+
return resolve(import.meta.dir, "../..");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function cliEntrypoint(): string {
|
|
16
|
+
if (isCompiledExecutable()) {
|
|
17
|
+
return process.execPath;
|
|
18
|
+
}
|
|
19
|
+
return resolve(packageRoot(), "src/index.ts");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function nnCommand(sourceRoot = packageRoot()): string {
|
|
23
|
+
if (isCompiledExecutable()) {
|
|
24
|
+
return process.execPath;
|
|
25
|
+
}
|
|
26
|
+
if (existsSync(resolve(sourceRoot, "src/index.ts"))) {
|
|
27
|
+
return `bun run ${resolve(sourceRoot, "src/index.ts")}`;
|
|
28
|
+
}
|
|
29
|
+
return `bun run ${cliEntrypoint()}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function coordinatorSpawn(): { cmd: string[] } {
|
|
33
|
+
if (isCompiledExecutable()) {
|
|
34
|
+
return { cmd: [process.execPath, "__coordinator"] };
|
|
35
|
+
}
|
|
36
|
+
return { cmd: [process.execPath, cliEntrypoint(), "__coordinator"] };
|
|
37
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
|
|
3
|
+
import { envBool, envInt } from "./env.ts";
|
|
4
|
+
import { stateDir } from "./paths.ts";
|
|
5
|
+
|
|
6
|
+
export interface SyncConfig {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
debounceMs: number;
|
|
9
|
+
flushTimeoutMs: number;
|
|
10
|
+
syncIntervalMs: number;
|
|
11
|
+
pullOnSession: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isValidTursoUrl(url: string): boolean {
|
|
15
|
+
if (url.includes("{{") || url.includes("}}")) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const parsed = new URL(url);
|
|
20
|
+
return parsed.protocol === "libsql:" || parsed.protocol === "https:";
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function tursoConfigured(): boolean {
|
|
27
|
+
const url = process.env.TURSO_DATABASE_URL?.trim();
|
|
28
|
+
const token = process.env.TURSO_AUTH_TOKEN?.trim();
|
|
29
|
+
if (!url || !token) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return isValidTursoUrl(url);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function syncConfig(): SyncConfig {
|
|
36
|
+
const configured = tursoConfigured();
|
|
37
|
+
return {
|
|
38
|
+
enabled: configured && envBool("NN_SYNC_ENABLED", true),
|
|
39
|
+
debounceMs: envInt("NN_SYNC_DEBOUNCE_MS", 3000),
|
|
40
|
+
flushTimeoutMs: envInt("NN_SYNC_FLUSH_TIMEOUT_MS", 5000),
|
|
41
|
+
syncIntervalMs: envInt("NN_SYNC_INTERVAL_MS", 0),
|
|
42
|
+
pullOnSession: envBool("NN_SYNC_PULL_ON_SESSION", configured),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function coordinatorStatePath(): string {
|
|
47
|
+
return join(stateDir(), "sync-coordinator.json");
|
|
48
|
+
}
|