fix(tasktree): expose L1 source provenance

This commit is contained in:
root
2026-07-21 09:53:48 +02:00
parent ed3b88b886
commit 04d62900d7
@@ -1,8 +1,9 @@
import { mkdirSync, openSync, readFileSync, rmSync } from "node:fs";
import { mkdirSync, openSync, readFileSync, readlinkSync, realpathSync, rmSync } from "node:fs";
import { resolve } from "node:path";
const action = process.argv[2];
const root = process.cwd();
const repoRoot = resolve(root, "../..");
const stateDir = resolve(root, ".state/tasktree-native");
const pidPath = resolve(stateDir, "supervisor.pid");
const logPath = resolve(stateDir, "supervisor.log");
@@ -34,6 +35,33 @@ function isRunning(pid: number | null): boolean {
}
}
function canonicalPath(path: string): string {
try {
return realpathSync(path);
} catch {
return resolve(path);
}
}
function runningProcessCwd(pid: number | null): string | null {
if (!pid) return null;
try {
return canonicalPath(readlinkSync(`/proc/${pid}/cwd`));
} catch {
return null;
}
}
function gitCommit(workspace: string | null): string | null {
if (!workspace) return null;
const result = Bun.spawnSync(["git", "-C", workspace, "rev-parse", "HEAD"], {
stdout: "pipe",
stderr: "ignore"
});
if (result.exitCode !== 0) return null;
return result.stdout.toString().trim() || null;
}
async function waitForExit(pid: number): Promise<boolean> {
const deadline = Date.now() + 15000;
while (Date.now() < deadline) {
@@ -79,7 +107,26 @@ if (action === "start") {
}
} else if (action === "status") {
const running = isRunning(pid);
console.log(JSON.stringify({ ok: running, action, status: running ? "running" : "stopped", pid: running ? pid : null, logPath, servicesLogPath }));
const processCwd = runningProcessCwd(running ? pid : null);
const sourceWorkspace = processCwd ? canonicalPath(resolve(processCwd, "../..")) : null;
const expectedProcessCwd = canonicalPath(root);
const expectedSourceWorkspace = canonicalPath(repoRoot);
console.log(JSON.stringify({
ok: running,
action,
status: running ? "running" : "stopped",
pid: running ? pid : null,
logPath,
servicesLogPath,
provenance: {
expectedSourceWorkspace,
sourceWorkspace,
processCwd,
commit: gitCommit(sourceWorkspace),
workspaceMatches: sourceWorkspace === expectedSourceWorkspace,
processCwdMatches: processCwd === expectedProcessCwd
}
}));
process.exit(running ? 0 : 1);
} else if (action === "logs") {
for (const path of [logPath, servicesLogPath]) {