From 83d5703f7b61e7e694edd7b22f8fb45b7fe3aeba Mon Sep 17 00:00:00 2001 From: tommy0103 Date: Sun, 12 Jul 2026 00:28:17 +0800 Subject: [PATCH] refactor(core): move shared runtime into workspace package --- app/package.json | 2 +- app/src/main/index.ts | 2 +- app/src/main/indexer.ts | 14 ++++----- package-lock.json | 11 +++++++ package.json | 7 +++-- packages/core/package.json | 29 +++++++++++++++++++ {scripts => packages/core/src}/core.ts | 2 +- {scripts => packages/core/src}/db.mjs | 1 + {scripts => packages/core/src}/indexer.mjs | 1 + {scripts => packages/core/src}/parsing.mjs | 2 +- {scripts => packages/core/src}/persist.ts | 2 +- .../core/src}/providers/claude.ts | 2 +- .../core/src}/providers/codex.ts | 2 +- .../core/src}/providers/types.ts | 2 +- {scripts => packages/core/src}/query.mjs | 1 + {scripts => packages/core/src}/runtime.mjs | 2 +- {scripts => packages/core/src}/schema.sql | 1 + {scripts => packages/core/src}/tx.ts | 2 +- .../core/src}/write-coordinator.ts | 2 +- .../core/src}/writer-lease.ts | 2 +- packages/core/tsconfig.build.json | 11 +++++++ packages/core/tsconfig.json | 7 +++++ tests/app-main-settings.test.mjs | 2 +- tests/app-writer-lease.test.mjs | 2 +- tests/claude-parse.test.mjs | 2 +- tests/codex-index.test.mjs | 2 +- tests/codex-parse.test.mjs | 2 +- tests/contract-helper-shapes.test.mjs | 4 +-- tests/daemon-arbitration.test.mjs | 10 +++---- tests/db-schema.test.mjs | 6 ++-- tests/incremental-index.test.mjs | 2 +- tests/indexer-upsert-drift.test.mjs | 6 ++-- tests/indexer.test.mjs | 2 +- tests/persist.test.mjs | 6 ++-- tests/query.test.mjs | 4 +-- tests/runtime-cli-envelope.test.mjs | 2 +- tests/runtime.test.mjs | 2 +- tests/write-transaction.test.mjs | 4 +-- tests/writer-lease.test.mjs | 2 +- tsconfig.build.json | 10 +------ tsconfig.json | 2 +- tsconfig.skill.json | 4 +-- 42 files changed, 120 insertions(+), 63 deletions(-) create mode 100644 packages/core/package.json rename {scripts => packages/core/src}/core.ts (97%) rename {scripts => packages/core/src}/db.mjs (97%) rename {scripts => packages/core/src}/indexer.mjs (99%) rename {scripts => packages/core/src}/parsing.mjs (99%) rename {scripts => packages/core/src}/persist.ts (99%) rename {scripts => packages/core/src}/providers/claude.ts (98%) rename {scripts => packages/core/src}/providers/codex.ts (99%) rename {scripts => packages/core/src}/providers/types.ts (99%) rename {scripts => packages/core/src}/query.mjs (99%) rename {scripts => packages/core/src}/runtime.mjs (95%) rename {scripts => packages/core/src}/schema.sql (99%) rename {scripts => packages/core/src}/tx.ts (98%) rename {scripts => packages/core/src}/write-coordinator.ts (96%) rename {scripts => packages/core/src}/writer-lease.ts (97%) create mode 100644 packages/core/tsconfig.build.json create mode 100644 packages/core/tsconfig.json diff --git a/app/package.json b/app/package.json index 433caa8..e1f89c9 100644 --- a/app/package.json +++ b/app/package.json @@ -51,7 +51,7 @@ ], "extraResources": [ { - "from": "../scripts/schema.sql", + "from": "../packages/core/src/schema.sql", "to": "scripts/schema.sql" } ] diff --git a/app/src/main/index.ts b/app/src/main/index.ts index 8f35ad4..e44ce86 100644 --- a/app/src/main/index.ts +++ b/app/src/main/index.ts @@ -9,7 +9,7 @@ import { writeHeartbeat } from './indexer.ts'; import { createIndexerService } from './indexer-service.ts'; import { createWorkerBuildIndex } from './indexer-worker-client.ts'; import { buildRecapExportQuery } from './recap-capture-query.ts'; -import { acquireWriterLease, writerLockPathFor } from '../../../scripts/writer-lease.ts'; +import { acquireWriterLease, writerLockPathFor } from '../../../packages/core/src/writer-lease.ts'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); diff --git a/app/src/main/indexer.ts b/app/src/main/indexer.ts index c6211bb..0493af9 100644 --- a/app/src/main/indexer.ts +++ b/app/src/main/indexer.ts @@ -3,12 +3,12 @@ import os from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import Database from 'better-sqlite3'; -import { parse as claudeParse } from '../../../scripts/providers/claude.ts'; -import { parse as codexParse } from '../../../scripts/providers/codex.ts'; -import { persist } from '../../../scripts/persist.ts'; -import { runWriteTransaction, configureConnection, betterSqliteTransactionAdapter } from '../../../scripts/tx.ts'; -import { acquireWriterLease, writerLockPathFor } from '../../../scripts/writer-lease.ts'; -import { runRetryableWriteTransaction, isBeginBusyFailure, hasUnusableTransaction } from '../../../scripts/write-coordinator.ts'; +import { parse as claudeParse } from '../../../packages/core/src/providers/claude.ts'; +import { parse as codexParse } from '../../../packages/core/src/providers/codex.ts'; +import { persist } from '../../../packages/core/src/persist.ts'; +import { runWriteTransaction, configureConnection, betterSqliteTransactionAdapter } from '../../../packages/core/src/tx.ts'; +import { acquireWriterLease, writerLockPathFor } from '../../../packages/core/src/writer-lease.ts'; +import { runRetryableWriteTransaction, isBeginBusyFailure, hasUnusableTransaction } from '../../../packages/core/src/write-coordinator.ts'; import { inferProjectPath, isDir, @@ -17,7 +17,7 @@ import { codexRawId, codexParentThreadId, readCodexGuardianThreadInfo, -} from '../../../scripts/parsing.mjs'; +} from '../../../packages/core/src/parsing.mjs'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); diff --git a/package-lock.json b/package-lock.json index d49896c..e9cb13b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "obelisk", "version": "0.1.0", "license": "AGPL-3.0", + "workspaces": [ + "packages/*" + ], "devDependencies": { "@eslint/js": "^10.0.1", "@types/node": "^26.1.1", @@ -211,6 +214,10 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@obelisk/core": { + "resolved": "packages/core", + "link": true + }, "node_modules/@types/esrecurse": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", @@ -1275,6 +1282,10 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "packages/core": { + "name": "@obelisk/core", + "version": "0.1.0" } } } diff --git a/package.json b/package.json index 048e176..3651406 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,15 @@ "type": "module", "description": "Explicit memory infrastructure for coding agents — a queryable SQLite evidence layer over local Claude Code and Codex history, plus human-approved durable memory.", "license": "AGPL-3.0", + "workspaces": [ + "packages/*" + ], "scripts": { "test": "node --experimental-test-module-mocks --test tests/*.test.mjs", "typecheck": "tsc --noEmit && tsc --noEmit -p app/tsconfig.json", "lint": "eslint .", - "build:core": "rm -rf dist && tsc -p tsconfig.build.json", - "build:skill": "rm -rf dist/obelisk-skill && tsc -p tsconfig.skill.json && cp scripts/schema.sql dist/obelisk-skill/scripts/ && cp SKILL.md dist/obelisk-skill/ && cp -R references dist/obelisk-skill/references && cp packaging/skill-package.json dist/obelisk-skill/package.json", + "build:core": "npm run build --workspace @obelisk/core", + "build:skill": "rm -rf dist/obelisk-skill && tsc -p tsconfig.skill.json && cp packages/core/src/schema.sql dist/obelisk-skill/scripts/ && cp SKILL.md dist/obelisk-skill/ && cp -R references dist/obelisk-skill/references && cp packaging/skill-package.json dist/obelisk-skill/package.json", "publish:skill": "npm run build:skill && packaging/publish-skill.sh" }, "devDependencies": { diff --git a/packages/core/package.json b/packages/core/package.json new file mode 100644 index 0000000..9c09405 --- /dev/null +++ b/packages/core/package.json @@ -0,0 +1,29 @@ +{ + "name": "@obelisk/core", + "version": "0.1.0", + "private": true, + "type": "module", + "description": "Shared indexing and query core for Obelisk transports.", + "exports": { + ".": "./dist/core.js", + "./db": "./dist/db.js", + "./indexer": "./dist/indexer.js", + "./parsing": "./dist/parsing.js", + "./persist": "./dist/persist.js", + "./providers/claude": "./dist/providers/claude.js", + "./providers/codex": "./dist/providers/codex.js", + "./providers/types": "./dist/providers/types.js", + "./query": "./dist/query.js", + "./tx": "./dist/tx.js", + "./write-coordinator": "./dist/write-coordinator.js", + "./writer-lease": "./dist/writer-lease.js" + }, + "files": [ + "dist", + "src/schema.sql" + ], + "scripts": { + "build": "rm -rf dist && tsc -p tsconfig.build.json", + "typecheck": "tsc --noEmit -p tsconfig.json" + } +} diff --git a/scripts/core.ts b/packages/core/src/core.ts similarity index 97% rename from scripts/core.ts rename to packages/core/src/core.ts index ee85cd2..1ea1aef 100644 --- a/scripts/core.ts +++ b/packages/core/src/core.ts @@ -1,4 +1,4 @@ -// Obelisk Core (see docs/adr/0003-core-typescript-esm-precompiled.md). +// Obelisk Core package (see docs/adr/0003-core-typescript-esm-precompiled.md). // // The single shared implementation behind every transport. runtime.mjs (skill), // and later the CLI and MCP server, are thin shells over these four functions; diff --git a/scripts/db.mjs b/packages/core/src/db.mjs similarity index 97% rename from scripts/db.mjs rename to packages/core/src/db.mjs index 4b66404..a698a10 100644 --- a/scripts/db.mjs +++ b/packages/core/src/db.mjs @@ -1,3 +1,4 @@ +// node:sqlite lifecycle and migrations for the Core package. import { createRequire } from 'node:module'; import { CLAUDE_DIR, CODEX_DIR, TEXT_LIMIT, trunc, truncJson, extractText, extractContentType, extractMessageIsMeta, filePath, isDir, readLines } from './parsing.mjs'; import { configureConnection } from './tx.ts'; diff --git a/scripts/indexer.mjs b/packages/core/src/indexer.mjs similarity index 99% rename from scripts/indexer.mjs rename to packages/core/src/indexer.mjs index d78f9b7..5c42f50 100644 --- a/scripts/indexer.mjs +++ b/packages/core/src/indexer.mjs @@ -1,3 +1,4 @@ +// Passive-pull indexing orchestration for the Core package. import { DB_PATH, openDb, openReadDb, openWriterLeaseDb, rebuildMemoryFts } from './db.mjs'; import { CLAUDE_DIR, CODEX_DIR, PROJECTS_DIR, fs, path, isDir, readLines, diff --git a/scripts/parsing.mjs b/packages/core/src/parsing.mjs similarity index 99% rename from scripts/parsing.mjs rename to packages/core/src/parsing.mjs index b31640b..9217026 100644 --- a/scripts/parsing.mjs +++ b/packages/core/src/parsing.mjs @@ -1,4 +1,4 @@ -// Pure parse/discover helpers — node:sqlite-free by construction, so the compiled +// Core's pure parse/discover helpers — node:sqlite-free by construction, so the compiled // providers can be consumed by the app (better-sqlite3 / a Node without // node:sqlite). Moved verbatim from db.mjs and indexer.mjs (Phase 5d-1); they use // only node:fs/path/os. Kept as .mjs (plain ESM) for a low-risk verbatim move. diff --git a/scripts/persist.ts b/packages/core/src/persist.ts similarity index 99% rename from scripts/persist.ts rename to packages/core/src/persist.ts index 0815f4e..a40001a 100644 --- a/scripts/persist.ts +++ b/packages/core/src/persist.ts @@ -1,4 +1,4 @@ -// Shared persist layer (see docs/adr/0001). +// Shared Core persist layer (see docs/adr/0001). // // Provider-agnostic and binding-agnostic: it consumes the IndexRecord stream // from any adapter's parse() and writes rows into the injected database handle diff --git a/scripts/providers/claude.ts b/packages/core/src/providers/claude.ts similarity index 98% rename from scripts/providers/claude.ts rename to packages/core/src/providers/claude.ts index 268ec20..d7002e5 100644 --- a/scripts/providers/claude.ts +++ b/packages/core/src/providers/claude.ts @@ -1,4 +1,4 @@ -// Claude Code provider adapter (see docs/adr/0001). +// Claude Code provider adapter in Core (see docs/adr/0001). // // Pure: discovers Claude transcript files and parses one into a record stream. // It never touches the Obelisk database. The per-line logic mirrors the original diff --git a/scripts/providers/codex.ts b/packages/core/src/providers/codex.ts similarity index 99% rename from scripts/providers/codex.ts rename to packages/core/src/providers/codex.ts index ff594d9..b14c75a 100644 --- a/scripts/providers/codex.ts +++ b/packages/core/src/providers/codex.ts @@ -1,4 +1,4 @@ -// Codex provider adapter (see docs/adr/0001). +// Codex provider adapter in Core (see docs/adr/0001). // // Pure: discovers Codex rollout files and parses one into a record stream. It // never touches the Obelisk database. Unlike claude, codex is a FULL-REPARSE diff --git a/scripts/providers/types.ts b/packages/core/src/providers/types.ts similarity index 99% rename from scripts/providers/types.ts rename to packages/core/src/providers/types.ts index ba6d0df..829bc78 100644 --- a/scripts/providers/types.ts +++ b/packages/core/src/providers/types.ts @@ -1,4 +1,4 @@ -// Phase 5 target contract (see docs/adr/0001). +// Core provider contract (see docs/adr/0001). // // The indexing layer splits along two orthogonal axes: // - Provider axis: pure per-source adapters (claude, codex, later opencode, diff --git a/scripts/query.mjs b/packages/core/src/query.mjs similarity index 99% rename from scripts/query.mjs rename to packages/core/src/query.mjs index a320684..7127984 100644 --- a/scripts/query.mjs +++ b/packages/core/src/query.mjs @@ -1,3 +1,4 @@ +// Query and attune sandbox helpers for the Core package. import { readLines, fs, path } from './db.mjs'; function normalizeOpts(optsOrScalar, scalarKey = 'sessionId') { diff --git a/scripts/runtime.mjs b/packages/core/src/runtime.mjs similarity index 95% rename from scripts/runtime.mjs rename to packages/core/src/runtime.mjs index 5794372..7494fc8 100644 --- a/scripts/runtime.mjs +++ b/packages/core/src/runtime.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -// Skill transport: a thin CLI shell over Obelisk Core (scripts/core.ts). +// Skill transport: a thin CLI shell over the Obelisk Core package. // It only parses args, reads script files, prints JSON, and owns the uniform // { error, stack } + exit-1 error envelope. All logic lives in Core. diff --git a/scripts/schema.sql b/packages/core/src/schema.sql similarity index 99% rename from scripts/schema.sql rename to packages/core/src/schema.sql index 199280c..c7ef67f 100644 --- a/scripts/schema.sql +++ b/packages/core/src/schema.sql @@ -1,3 +1,4 @@ +-- Shared Obelisk Core schema. CREATE TABLE IF NOT EXISTS sessions ( id TEXT PRIMARY KEY, title TEXT, project TEXT, project_path TEXT, started_at TEXT, ended_at TEXT, git_branch TEXT, version TEXT, diff --git a/scripts/tx.ts b/packages/core/src/tx.ts similarity index 98% rename from scripts/tx.ts rename to packages/core/src/tx.ts index f3d4127..03f5e89 100644 --- a/scripts/tx.ts +++ b/packages/core/src/tx.ts @@ -1,4 +1,4 @@ -// Binding-agnostic SQLite write plumbing shared by the skill and app indexers +// Binding-agnostic SQLite write plumbing shared from the Core package // (docs/adr/0006). The injected db must expose `exec(sql)`; this works for both // node:sqlite (skill/CLI) and better-sqlite3 (app), same injection model as // `persist`. diff --git a/scripts/write-coordinator.ts b/packages/core/src/write-coordinator.ts similarity index 96% rename from scripts/write-coordinator.ts rename to packages/core/src/write-coordinator.ts index ed703bc..d13b2f2 100644 --- a/scripts/write-coordinator.ts +++ b/packages/core/src/write-coordinator.ts @@ -1,4 +1,4 @@ -// Bounded retry policy above the transaction primitive. Callers opt in only for +// Core's bounded retry policy above the transaction primitive. Callers opt in only for // idempotent work; BEGIN contention and an uncertain/live transaction are never // retried here. diff --git a/scripts/writer-lease.ts b/packages/core/src/writer-lease.ts similarity index 97% rename from scripts/writer-lease.ts rename to packages/core/src/writer-lease.ts index 97ae2c7..18957d4 100644 --- a/scripts/writer-lease.ts +++ b/packages/core/src/writer-lease.ts @@ -1,4 +1,4 @@ -// Cross-process single-writer lease for a complete Obelisk index build. The +// Cross-process single-writer lease shared by every Obelisk mutation. The // lock lives in a dedicated SQLite database so node:sqlite and better-sqlite3 // share identical locking semantics on every supported platform. diff --git a/packages/core/tsconfig.build.json b/packages/core/tsconfig.build.json new file mode 100644 index 0000000..3dc3216 --- /dev/null +++ b/packages/core/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "dist", + "rootDir": "src", + "declaration": true, + "rewriteRelativeImportExtensions": true + }, + "include": ["src/**/*.ts", "src/**/*.mjs"] +} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json new file mode 100644 index 0000000..49508cd --- /dev/null +++ b/packages/core/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": true + }, + "include": ["src/**/*"] +} diff --git a/tests/app-main-settings.test.mjs b/tests/app-main-settings.test.mjs index f6a5abe..8fe4370 100644 --- a/tests/app-main-settings.test.mjs +++ b/tests/app-main-settings.test.mjs @@ -7,7 +7,7 @@ import { mkdirSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { acquireWriterLease } from '../scripts/writer-lease.ts'; +import { acquireWriterLease } from '../packages/core/src/writer-lease.ts'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); diff --git a/tests/app-writer-lease.test.mjs b/tests/app-writer-lease.test.mjs index f535560..85f0ee1 100644 --- a/tests/app-writer-lease.test.mjs +++ b/tests/app-writer-lease.test.mjs @@ -6,7 +6,7 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { buildIndex } from '../app/src/main/indexer.ts'; -import { acquireWriterLease, writerLockPathFor } from '../scripts/writer-lease.ts'; +import { acquireWriterLease, writerLockPathFor } from '../packages/core/src/writer-lease.ts'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); diff --git a/tests/claude-parse.test.mjs b/tests/claude-parse.test.mjs index ffae8dc..cda01b3 100644 --- a/tests/claude-parse.test.mjs +++ b/tests/claude-parse.test.mjs @@ -8,7 +8,7 @@ import { mkdtempSync, writeFileSync, statSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { parse } from '../scripts/providers/claude.ts'; +import { parse } from '../packages/core/src/providers/claude.ts'; function writeFixture() { const dir = mkdtempSync(join(tmpdir(), 'obelisk-claude-parse-')); diff --git a/tests/codex-index.test.mjs b/tests/codex-index.test.mjs index 97a39fd..4072ba3 100644 --- a/tests/codex-index.test.mjs +++ b/tests/codex-index.test.mjs @@ -17,7 +17,7 @@ const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); function runRuntime(args, home) { - return spawnSync(process.execPath, ['scripts/runtime.mjs', ...args], { + return spawnSync(process.execPath, ['packages/core/src/runtime.mjs', ...args], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', }); } diff --git a/tests/codex-parse.test.mjs b/tests/codex-parse.test.mjs index 2a2ce91..e7208eb 100644 --- a/tests/codex-parse.test.mjs +++ b/tests/codex-parse.test.mjs @@ -9,7 +9,7 @@ import { mkdtempSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { parse } from '../scripts/providers/codex.ts'; +import { parse } from '../packages/core/src/providers/codex.ts'; function writeFixture(lines) { const dir = mkdtempSync(join(tmpdir(), 'obelisk-codex-parse-')); diff --git a/tests/contract-helper-shapes.test.mjs b/tests/contract-helper-shapes.test.mjs index 7b09cdf..a9cb7d0 100644 --- a/tests/contract-helper-shapes.test.mjs +++ b/tests/contract-helper-shapes.test.mjs @@ -23,11 +23,11 @@ import { readFileSync, writeFileSync, mkdtempSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { createQueryApi, createAttuneApi } from '../scripts/query.mjs'; +import { createQueryApi, createAttuneApi } from '../packages/core/src/query.mjs'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); -const SCHEMA = readFileSync(new URL('../scripts/schema.sql', import.meta.url), 'utf8'); +const SCHEMA = readFileSync(new URL('../packages/core/src/schema.sql', import.meta.url), 'utf8'); const API_REFERENCE = readFileSync(new URL('../references/api-reference.md', import.meta.url), 'utf8'); // Every key asserted below is recorded here so the doc-sync guard can confirm diff --git a/tests/daemon-arbitration.test.mjs b/tests/daemon-arbitration.test.mjs index c2f04cc..60dbe9e 100644 --- a/tests/daemon-arbitration.test.mjs +++ b/tests/daemon-arbitration.test.mjs @@ -6,7 +6,7 @@ import { tmpdir } from 'node:os'; import { join, resolve } from 'node:path'; import { spawnSync } from 'node:child_process'; -import { acquireWriterLease, writerLockPathFor } from '../scripts/writer-lease.ts'; +import { acquireWriterLease, writerLockPathFor } from '../packages/core/src/writer-lease.ts'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); @@ -27,7 +27,7 @@ test('a passive query does not mutate the index while a fresh daemon owns writes const queryPath = join(home, 'query.mjs'); writeFileSync(queryPath, "return 'read-only';"); - const result = spawnSync(process.execPath, ['scripts/runtime.mjs', '--query', queryPath], { + const result = spawnSync(process.execPath, ['packages/core/src/runtime.mjs', '--query', queryPath], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', @@ -55,7 +55,7 @@ test('attune refuses to mutate the index while a fresh daemon owns writes', () = const attunePath = join(home, 'attune.mjs'); writeFileSync(attunePath, 'return true;'); - const result = spawnSync(process.execPath, ['scripts/runtime.mjs', '--attune', attunePath], { + const result = spawnSync(process.execPath, ['packages/core/src/runtime.mjs', '--attune', attunePath], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', @@ -86,7 +86,7 @@ test('a passive query stays read-only when another process holds the writer leas try { const queryPath = join(home, 'query.mjs'); writeFileSync(queryPath, "return 'writer-busy';"); - const result = spawnSync(process.execPath, ['scripts/runtime.mjs', '--query', queryPath], { + const result = spawnSync(process.execPath, ['packages/core/src/runtime.mjs', '--query', queryPath], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', @@ -120,7 +120,7 @@ test('a passive query fails closed when daemon ownership cannot be read', () => try { const queryPath = join(home, 'query.mjs'); writeFileSync(queryPath, "return 'ownership-unknown';"); - const result = spawnSync(process.execPath, ['scripts/runtime.mjs', '--query', queryPath], { + const result = spawnSync(process.execPath, ['packages/core/src/runtime.mjs', '--query', queryPath], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', diff --git a/tests/db-schema.test.mjs b/tests/db-schema.test.mjs index e331001..2c0d8d0 100644 --- a/tests/db-schema.test.mjs +++ b/tests/db-schema.test.mjs @@ -2,10 +2,10 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; -import { extractContentType, extractMessageIsMeta } from '../scripts/db.mjs'; +import { extractContentType, extractMessageIsMeta } from '../packages/core/src/db.mjs'; async function readExecutableSchema() { - return readFile(new URL('../scripts/schema.sql', import.meta.url), 'utf8'); + return readFile(new URL('../packages/core/src/schema.sql', import.meta.url), 'utf8'); } async function readSchemaReference() { @@ -21,7 +21,7 @@ async function readSkill() { } test('db module loads the executable schema from scripts/schema.sql', async () => { - const source = await readFile(new URL('../scripts/db.mjs', import.meta.url), 'utf8'); + const source = await readFile(new URL('../packages/core/src/db.mjs', import.meta.url), 'utf8'); assert.match(source, /schema\.sql/); assert.doesNotMatch(source, /CREATE TABLE IF NOT EXISTS sessions/); diff --git a/tests/incremental-index.test.mjs b/tests/incremental-index.test.mjs index 0bcb63c..073fd15 100644 --- a/tests/incremental-index.test.mjs +++ b/tests/incremental-index.test.mjs @@ -19,7 +19,7 @@ const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); function runRuntime(args, home) { - return spawnSync(process.execPath, ['scripts/runtime.mjs', ...args], { + return spawnSync(process.execPath, ['packages/core/src/runtime.mjs', ...args], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', }); } diff --git a/tests/indexer-upsert-drift.test.mjs b/tests/indexer-upsert-drift.test.mjs index dc31b58..e721308 100644 --- a/tests/indexer-upsert-drift.test.mjs +++ b/tests/indexer-upsert-drift.test.mjs @@ -11,12 +11,12 @@ import { mkdtempSync, writeFileSync, readFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { parse } from '../scripts/providers/claude.ts'; -import { persist } from '../scripts/persist.ts'; +import { parse } from '../packages/core/src/providers/claude.ts'; +import { persist } from '../packages/core/src/persist.ts'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); -const SCHEMA = readFileSync(new URL('../scripts/schema.sql', import.meta.url), 'utf8'); +const SCHEMA = readFileSync(new URL('../packages/core/src/schema.sql', import.meta.url), 'utf8'); function fixtureUnit() { const dir = mkdtempSync(join(tmpdir(), 'obelisk-drift-')); diff --git a/tests/indexer.test.mjs b/tests/indexer.test.mjs index e94f2d6..69abd84 100644 --- a/tests/indexer.test.mjs +++ b/tests/indexer.test.mjs @@ -2,7 +2,7 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; -import { inferProjectPath, refreshSessionProjectPaths, shouldSkipBuild } from '../scripts/indexer.mjs'; +import { inferProjectPath, refreshSessionProjectPaths, shouldSkipBuild } from '../packages/core/src/indexer.mjs'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); diff --git a/tests/persist.test.mjs b/tests/persist.test.mjs index 07dfd58..70e7a6d 100644 --- a/tests/persist.test.mjs +++ b/tests/persist.test.mjs @@ -9,12 +9,12 @@ import { mkdtempSync, writeFileSync, readFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { parse } from '../scripts/providers/claude.ts'; -import { persist } from '../scripts/persist.ts'; +import { parse } from '../packages/core/src/providers/claude.ts'; +import { persist } from '../packages/core/src/persist.ts'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); -const SCHEMA = readFileSync(new URL('../scripts/schema.sql', import.meta.url), 'utf8'); +const SCHEMA = readFileSync(new URL('../packages/core/src/schema.sql', import.meta.url), 'utf8'); function fixtureUnit() { const dir = mkdtempSync(join(tmpdir(), 'obelisk-persist-')); diff --git a/tests/query.test.mjs b/tests/query.test.mjs index b38b5ad..0019f57 100644 --- a/tests/query.test.mjs +++ b/tests/query.test.mjs @@ -5,11 +5,11 @@ import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { createQueryApi, createAttuneApi } from '../scripts/query.mjs'; +import { createQueryApi, createAttuneApi } from '../packages/core/src/query.mjs'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); -const SCHEMA = readFileSync(new URL('../scripts/schema.sql', import.meta.url), 'utf8'); +const SCHEMA = readFileSync(new URL('../packages/core/src/schema.sql', import.meta.url), 'utf8'); function memoryDb({ projectPath = '/tmp/quiet-zero-test' } = {}) { const db = new DatabaseSync(':memory:'); diff --git a/tests/runtime-cli-envelope.test.mjs b/tests/runtime-cli-envelope.test.mjs index 74e69ba..f728bdd 100644 --- a/tests/runtime-cli-envelope.test.mjs +++ b/tests/runtime-cli-envelope.test.mjs @@ -23,7 +23,7 @@ import { spawnSync } from 'node:child_process'; const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..'); function runRuntime(args, { home }) { - return spawnSync(process.execPath, ['scripts/runtime.mjs', ...args], { + return spawnSync(process.execPath, ['packages/core/src/runtime.mjs', ...args], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', diff --git a/tests/runtime.test.mjs b/tests/runtime.test.mjs index a6c3083..ceb2c02 100644 --- a/tests/runtime.test.mjs +++ b/tests/runtime.test.mjs @@ -12,7 +12,7 @@ const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); function runRuntime(args, { home }) { - return spawnSync(process.execPath, ['scripts/runtime.mjs', ...args], { + return spawnSync(process.execPath, ['packages/core/src/runtime.mjs', ...args], { cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8', diff --git a/tests/write-transaction.test.mjs b/tests/write-transaction.test.mjs index b455618..c0ecccd 100644 --- a/tests/write-transaction.test.mjs +++ b/tests/write-transaction.test.mjs @@ -5,8 +5,8 @@ import { mkdtempSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { nodeSqliteTransactionAdapter, runWriteTransaction } from '../scripts/tx.ts'; -import { hasUnusableTransaction, isBeginBusyFailure, isRetryableWriteFailure } from '../scripts/write-coordinator.ts'; +import { nodeSqliteTransactionAdapter, runWriteTransaction } from '../packages/core/src/tx.ts'; +import { hasUnusableTransaction, isBeginBusyFailure, isRetryableWriteFailure } from '../packages/core/src/write-coordinator.ts'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); diff --git a/tests/writer-lease.test.mjs b/tests/writer-lease.test.mjs index 997e260..cfab516 100644 --- a/tests/writer-lease.test.mjs +++ b/tests/writer-lease.test.mjs @@ -5,7 +5,7 @@ import { mkdtempSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { acquireWriterLease } from '../scripts/writer-lease.ts'; +import { acquireWriterLease } from '../packages/core/src/writer-lease.ts'; const require = createRequire(import.meta.url); const { DatabaseSync } = require('node:sqlite'); diff --git a/tsconfig.build.json b/tsconfig.build.json index c117cff..2122e83 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,11 +1,3 @@ { - "extends": "./tsconfig.json", - "compilerOptions": { - "noEmit": false, - "outDir": "dist", - "rootDir": "scripts", - "declaration": true, - "rewriteRelativeImportExtensions": true - }, - "include": ["scripts/providers/**/*.ts", "scripts/persist.ts"] + "extends": "./packages/core/tsconfig.build.json" } diff --git a/tsconfig.json b/tsconfig.json index 0d2929f..45a4347 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,7 @@ "resolveJsonModule": true, "forceConsistentCasingInFileNames": true }, - "include": ["scripts/**/*", "tests/**/*"], + "include": ["packages/core/src/**/*", "tests/**/*"], "exclude": [ "node_modules", "app", diff --git a/tsconfig.skill.json b/tsconfig.skill.json index 2cb3883..c87d549 100644 --- a/tsconfig.skill.json +++ b/tsconfig.skill.json @@ -3,9 +3,9 @@ "compilerOptions": { "noEmit": false, "outDir": "dist/obelisk-skill/scripts", - "rootDir": "scripts", + "rootDir": "packages/core/src", "declaration": false, "rewriteRelativeImportExtensions": true }, - "include": ["scripts/**/*.ts", "scripts/**/*.mjs"] + "include": ["packages/core/src/**/*.ts", "packages/core/src/**/*.mjs"] }