refactor(db): group database domain modules

This commit is contained in:
ZacharyZhang-NY committed 2026-04-22 19:24:25 -04:00
1 parent e43a89096d
commit 6da0a58769
160 files changed
+2124 -1999

No files matched your search

@@ -45,7 +45,7 @@ async function createHarness(): Promise<Harness> {
const db = new AppDatabase(profileDir);
db.init();
db.connectorsCrud.updateConnectorHealth({
db.core.connectors.updateConnectorHealth({
id: "openai-codex",
status: "ready",
authState: "authenticated",
@@ -53,12 +53,12 @@ async function createHarness(): Promise<Harness> {
lastError: null,
});
const companyId = db.company.saveCompany({
const companyId = db.core.company.saveCompany({
name: "Work Products Co",
description: "Tests archived visibility, bulk retirement, deliverable signal",
status: "active",
});
const workspaceId = db.workspacesMod.saveWorkspace({
const workspaceId = db.core.workspaces.saveWorkspace({
companyId,
name: "Primary",
localPath: workspacePath,
@@ -66,7 +66,7 @@ async function createHarness(): Promise<Harness> {
repoRef: "",
isPrimary: true,
});
const agentId = db.agents.saveAgent({
const agentId = db.core.agents.saveAgent({
companyId,
name: "Artifact Engineer",
role: "Engineer",
@@ -79,7 +79,7 @@ async function createHarness(): Promise<Harness> {
capabilities: "Writes files",
budgetMonthlyUsd: 100,
});
const taskId = db.tasks.saveTask({
const taskId = db.core.tasks.saveTask({
companyId,
title: "Produce artifact",
description: "",
@@ -88,7 +88,7 @@ async function createHarness(): Promise<Harness> {
priority: "medium",
status: "in_progress",
});
const run = db.runs.createRun({
const run = db.core.runs.createRun({
companyId,
taskId,
agentId,
@@ -107,7 +107,7 @@ async function createHarness(): Promise<Harness> {
}
function registerArtifact(harness: Harness, relativePath: string): string {
return harness.db.documentsMod.createWorkProduct({
return harness.db.core.documents.createWorkProduct({
companyId: harness.companyId,
taskId: harness.taskId,
workspaceId: harness.workspaceId,
@@ -126,12 +126,12 @@ describe("work_products archived visibility", () => {
try {
const activeId = registerArtifact(harness, "docs/active.md");
const archivedId = registerArtifact(harness, "docs/retired.md");
harness.db.documentsMod.updateWorkProduct(archivedId, harness.companyId, {
harness.db.core.documents.updateWorkProduct(archivedId, harness.companyId, {
status: "archived",
lastTouchedByRunId: harness.runId,
});
const snapshot = harness.db.snap.listSnapshot();
const snapshot = harness.db.projection.snapshot.listSnapshot();
const visibleIds = snapshot.workProducts.map((wp) => wp.id);
expect(visibleIds).toContain(activeId);
expect(visibleIds).not.toContain(archivedId);
@@ -145,12 +145,12 @@ describe("work_products archived visibility", () => {
try {
const activeId = registerArtifact(harness, "src/feature.ts");
const archivedId = registerArtifact(harness, "src/removed.ts");
harness.db.documentsMod.updateWorkProduct(archivedId, harness.companyId, {
harness.db.core.documents.updateWorkProduct(archivedId, harness.companyId, {
status: "archived",
lastTouchedByRunId: harness.runId,
});
const rows = harness.db.documentsMod.listWorkProductsForTask(harness.taskId, harness.companyId);
const rows = harness.db.core.documents.listWorkProductsForTask(harness.taskId, harness.companyId);
const ids = rows.map((r) => r.id);
expect(ids).toContain(activeId);
expect(ids).not.toContain(archivedId);
@@ -164,16 +164,16 @@ describe("work_products archived visibility", () => {
try {
const id = registerArtifact(harness, "notes/ghost.md");
expect(
harness.db.documentsMod.resolveWorkProductTarget(id, harness.companyId),
harness.db.core.documents.resolveWorkProductTarget(id, harness.companyId),
).not.toBeNull();
harness.db.documentsMod.updateWorkProduct(id, harness.companyId, {
harness.db.core.documents.updateWorkProduct(id, harness.companyId, {
status: "archived",
lastTouchedByRunId: harness.runId,
});
expect(
harness.db.documentsMod.resolveWorkProductTarget(id, harness.companyId),
harness.db.core.documents.resolveWorkProductTarget(id, harness.companyId),
).toMatchObject({ kind: "error", reason: "archived" });
} finally {
harness.db.close();
@@ -193,7 +193,7 @@ describe("work_products bulk retirement", () => {
ids.push(registerArtifact(harness, rel));
}
const archived = harness.db.documentsMod.archiveWorkProductsByExternalPaths({
const archived = harness.db.core.documents.archiveWorkProductsByExternalPaths({
companyId: harness.companyId,
workspaceId: harness.workspaceId,
provider: "filesystem",
@@ -206,7 +206,7 @@ describe("work_products bulk retirement", () => {
for (const id of ids) {
expect(archivedIdSet.has(id)).toBe(true);
}
const visible = harness.db.snap.listSnapshot().workProducts;
const visible = harness.db.projection.snapshot.listSnapshot().workProducts;
expect(visible.length).toBe(0);
} finally {
harness.db.close();
@@ -217,7 +217,7 @@ describe("work_products bulk retirement", () => {
const harness = await createHarness();
try {
const id = registerArtifact(harness, "tmp/scratch.log");
harness.db.documentsMod.archiveWorkProductsByExternalPaths({
harness.db.core.documents.archiveWorkProductsByExternalPaths({
companyId: harness.companyId,
workspaceId: harness.workspaceId,
provider: "filesystem",
@@ -225,7 +225,7 @@ describe("work_products bulk retirement", () => {
lastTouchedByRunId: harness.runId,
});
const second = harness.db.documentsMod.archiveWorkProductsByExternalPaths({
const second = harness.db.core.documents.archiveWorkProductsByExternalPaths({
companyId: harness.companyId,
workspaceId: harness.workspaceId,
provider: "filesystem",
@@ -235,7 +235,7 @@ describe("work_products bulk retirement", () => {
expect(second).toHaveLength(0);
expect(
harness.db.documentsMod.resolveWorkProductTarget(id, harness.companyId),
harness.db.core.documents.resolveWorkProductTarget(id, harness.companyId),
).toMatchObject({ kind: "error", reason: "archived" });
} finally {
harness.db.close();
@@ -252,7 +252,7 @@ describe("work_products bulk retirement", () => {
const workProductId = registerArtifact(harness, relPath);
expect(
harness.db.documentsMod.resolveWorkProductTarget(workProductId, harness.companyId),
harness.db.core.documents.resolveWorkProductTarget(workProductId, harness.companyId),
).not.toBeNull();
const baseline = {
@@ -277,7 +277,7 @@ describe("work_products bulk retirement", () => {
expect(retired.map((o) => (o as { relativePath: string }).relativePath)).toContain(relPath);
expect(
harness.db.documentsMod.resolveWorkProductTarget(workProductId, harness.companyId),
harness.db.core.documents.resolveWorkProductTarget(workProductId, harness.companyId),
).toMatchObject({ kind: "error", reason: "archived" });
} finally {
harness.db.close();
@@ -290,19 +290,19 @@ describe("work_products deliverable signal", () => {
const harness = await createHarness();
try {
const id = registerArtifact(harness, "deliverables/final.md");
const beforeArchive = harness.db.knowledgeMod.collectRunDeliverableSignals(
const beforeArchive = harness.db.core.knowledge.collectRunDeliverableSignals(
harness.runId,
harness.companyId,
harness.taskId,
);
expect(beforeArchive.hasWorkProduct).toBe(true);
harness.db.documentsMod.updateWorkProduct(id, harness.companyId, {
harness.db.core.documents.updateWorkProduct(id, harness.companyId, {
status: "archived",
lastTouchedByRunId: harness.runId,
});
const afterArchive = harness.db.knowledgeMod.collectRunDeliverableSignals(
const afterArchive = harness.db.core.knowledge.collectRunDeliverableSignals(
harness.runId,
harness.companyId,
harness.taskId,