refactor(core): finish TypeScript workspace migration

This commit is contained in:
tommy0103
2026-07-12 00:37:32 +08:00
parent 83d5703f7b
commit 535d8edb4d
31 changed files with 326 additions and 199 deletions
+22 -4
View File
@@ -27,12 +27,12 @@ function walk(dir) {
test('build:skill produces a runnable, readable, .ts-free skill artifact', () => {
execFileSync('npm', ['run', 'build:skill'], { cwd: repoRoot, encoding: 'utf8', stdio: 'pipe' });
// Structure: compiled Core + copied .mjs + schema + docs + package.json.
// Structure: compiled Core + schema + docs + package.json.
for (const rel of [
'package.json', 'SKILL.md', 'references/api-reference.md',
'scripts/core.js', 'scripts/persist.js', 'scripts/providers/claude.js',
'scripts/providers/codex.js', 'scripts/runtime.mjs', 'scripts/indexer.mjs',
'scripts/db.mjs', 'scripts/parsing.mjs', 'scripts/query.mjs', 'scripts/schema.sql',
'scripts/providers/codex.js', 'scripts/runtime.js', 'scripts/indexer.js',
'scripts/db.js', 'scripts/parsing.js', 'scripts/query.js', 'scripts/schema.sql',
]) {
assert.ok(existsSync(join(skillDir, rel)), `artifact missing ${rel}`);
}
@@ -56,7 +56,7 @@ test('build:skill produces a runnable, readable, .ts-free skill artifact', () =>
writeFileSync(join(projDir, 'smoke.jsonl'),
JSON.stringify({ uuid: 'm1', type: 'user', timestamp: '2026-06-10T10:00:00Z', cwd: '/tmp/proj', message: { role: 'user', content: 'hello artifact' } }) + '\n');
const env = { ...process.env, HOME: home };
const runtime = join(skillDir, 'scripts', 'runtime.mjs');
const runtime = join(skillDir, 'scripts', 'runtime.js');
const build = spawnSync(process.execPath, [runtime, '--build'], { env, encoding: 'utf8' });
assert.equal(build.status, 0, build.stderr || build.stdout);
@@ -65,6 +65,24 @@ test('build:skill produces a runnable, readable, .ts-free skill artifact', () =>
assert.equal(search.status, 0, search.stderr || search.stdout);
const hits = JSON.parse(search.stdout);
assert.equal(hits[0]?.message?.text, 'hello artifact', 'compiled artifact indexed and found the message');
const memoryPath = join(home, 'artifact-memory.md');
const attunePath = join(home, 'attune.mjs');
writeFileSync(memoryPath, '# Artifact memory\n');
writeFileSync(attunePath, `return remember(${JSON.stringify({
path: memoryPath,
session_id: 'smoke',
summary: 'Artifact release smoke memory',
})});`);
const attune = spawnSync(process.execPath, [runtime, '--attune', attunePath], { env, encoding: 'utf8' });
assert.equal(attune.status, 0, attune.stderr || attune.stdout);
assert.match(JSON.parse(attune.stdout).id, /^mem-/);
const queryPath = join(home, 'query.mjs');
writeFileSync(queryPath, "return memories({ sessionId: 'smoke', query: 'Artifact release smoke' });");
const query = spawnSync(process.execPath, [runtime, '--query', queryPath], { env, encoding: 'utf8' });
assert.equal(query.status, 0, query.stderr || query.stdout);
assert.equal(JSON.parse(query.stdout)[0]?.summary, 'Artifact release smoke memory');
} finally {
rmSync(home, { recursive: true, force: true });
}
+1 -1
View File
@@ -17,7 +17,7 @@ const require = createRequire(import.meta.url);
const { DatabaseSync } = require('node:sqlite');
function runRuntime(args, home) {
return spawnSync(process.execPath, ['packages/core/src/runtime.mjs', ...args], {
return spawnSync(process.execPath, ['packages/core/src/runtime.ts', ...args], {
cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8',
});
}
+1 -1
View File
@@ -23,7 +23,7 @@ import { readFileSync, writeFileSync, mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { createQueryApi, createAttuneApi } from '../packages/core/src/query.mjs';
import { createQueryApi, createAttuneApi } from '../packages/core/src/query.ts';
const require = createRequire(import.meta.url);
const { DatabaseSync } = require('node:sqlite');
+4 -4
View File
@@ -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, ['packages/core/src/runtime.mjs', '--query', queryPath], {
const result = spawnSync(process.execPath, ['packages/core/src/runtime.ts', '--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, ['packages/core/src/runtime.mjs', '--attune', attunePath], {
const result = spawnSync(process.execPath, ['packages/core/src/runtime.ts', '--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, ['packages/core/src/runtime.mjs', '--query', queryPath], {
const result = spawnSync(process.execPath, ['packages/core/src/runtime.ts', '--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, ['packages/core/src/runtime.mjs', '--query', queryPath], {
const result = spawnSync(process.execPath, ['packages/core/src/runtime.ts', '--query', queryPath], {
cwd: repoRoot,
env: { ...process.env, HOME: home },
encoding: 'utf8',
+2 -2
View File
@@ -2,7 +2,7 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { extractContentType, extractMessageIsMeta } from '../packages/core/src/db.mjs';
import { extractContentType, extractMessageIsMeta } from '../packages/core/src/db.ts';
async function readExecutableSchema() {
return readFile(new URL('../packages/core/src/schema.sql', import.meta.url), 'utf8');
@@ -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('../packages/core/src/db.mjs', import.meta.url), 'utf8');
const source = await readFile(new URL('../packages/core/src/db.ts', import.meta.url), 'utf8');
assert.match(source, /schema\.sql/);
assert.doesNotMatch(source, /CREATE TABLE IF NOT EXISTS sessions/);
+1 -1
View File
@@ -19,7 +19,7 @@ const require = createRequire(import.meta.url);
const { DatabaseSync } = require('node:sqlite');
function runRuntime(args, home) {
return spawnSync(process.execPath, ['packages/core/src/runtime.mjs', ...args], {
return spawnSync(process.execPath, ['packages/core/src/runtime.ts', ...args], {
cwd: repoRoot, env: { ...process.env, HOME: home }, encoding: 'utf8',
});
}
+1 -1
View File
@@ -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 '../packages/core/src/indexer.mjs';
import { inferProjectPath, refreshSessionProjectPaths, shouldSkipBuild } from '../packages/core/src/indexer.ts';
const require = createRequire(import.meta.url);
const { DatabaseSync } = require('node:sqlite');
+1 -1
View File
@@ -5,7 +5,7 @@ import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { createQueryApi, createAttuneApi } from '../packages/core/src/query.mjs';
import { createQueryApi, createAttuneApi } from '../packages/core/src/query.ts';
const require = createRequire(import.meta.url);
const { DatabaseSync } = require('node:sqlite');
+1 -1
View File
@@ -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, ['packages/core/src/runtime.mjs', ...args], {
return spawnSync(process.execPath, ['packages/core/src/runtime.ts', ...args], {
cwd: repoRoot,
env: { ...process.env, HOME: home },
encoding: 'utf8',
+1 -1
View File
@@ -12,7 +12,7 @@ const require = createRequire(import.meta.url);
const { DatabaseSync } = require('node:sqlite');
function runRuntime(args, { home }) {
return spawnSync(process.execPath, ['packages/core/src/runtime.mjs', ...args], {
return spawnSync(process.execPath, ['packages/core/src/runtime.ts', ...args], {
cwd: repoRoot,
env: { ...process.env, HOME: home },
encoding: 'utf8',