singularity-forge/src/web/inspect-service.ts
Mikael Hugo b24f426f2b batch: snapshot of in-flight v2 work
This commit captures uncommitted modifications that accumulated in the
working tree across multiple in-progress workstreams. It is a snapshot
to clear the deck before sf v3 work begins; individual workstreams
should land separately on top of this.

Notable additions:
- trace-collector.ts, traces.ts, src/tests/trace-export.test.ts —
  trace export plumbing
- biome.json — Biome linter configuration
- .gitignore — exclude native/npm/**/*.node compiled binaries

The bulk of the diff is across src/resources/extensions/sf/ (301 files)
and src/resources/extensions/sf/tests/ (277 files), reflecting the
ongoing sf extension work. Specific feature commits should follow this
snapshot rather than being archaeology'd out of it.

The 76MB native/npm/linux-x64-gnu/forge_engine.node compiled binary
was left out of the commit — it's now gitignored and built locally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-29 12:42:31 +02:00

62 lines
1.7 KiB
TypeScript

import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import type { InspectData } from "../../web/lib/remaining-command-types.ts";
import { resolveBridgeRuntimeConfig } from "./bridge-service.ts";
/**
* Collects project inspection data by reading sf-db.json directly.
* No child process needed — sf-db.json is plain JSON with no .js imports.
*/
export async function collectInspectData(
projectCwdOverride?: string,
): Promise<InspectData> {
const config = resolveBridgeRuntimeConfig(undefined, projectCwdOverride);
const { projectCwd } = config;
const sfDir = join(projectCwd, ".sf");
const dbPath = join(sfDir, "sf-db.json");
let schemaVersion: number | null = null;
let decisions: Array<{
id: string;
decision: string;
choice: string;
[k: string]: unknown;
}> = [];
let requirements: Array<{
id: string;
status: string;
description: string;
[k: string]: unknown;
}> = [];
let artifacts: unknown[] = [];
if (existsSync(dbPath)) {
try {
const db = JSON.parse(readFileSync(dbPath, "utf-8"));
schemaVersion = db.schema_version ?? null;
decisions = db.decisions || [];
requirements = db.requirements || [];
artifacts = db.artifacts || [];
} catch {
// Corrupt or unreadable — return empty state
}
}
return {
schemaVersion,
counts: {
decisions: decisions.length,
requirements: requirements.length,
artifacts: artifacts.length,
},
recentDecisions: decisions
.slice(-5)
.reverse()
.map((d) => ({ id: d.id, decision: d.decision, choice: d.choice })),
recentRequirements: requirements
.slice(-5)
.reverse()
.map((r) => ({ id: r.id, status: r.status, description: r.description })),
};
}