refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -136,17 +136,28 @@ function isLegacyLabel(label: string): boolean {
return lower.includes("clawdbot") || lower.includes("moltbot");
}
async function readDirEntries(dir: string): Promise<string[]> {
try {
return await fs.readdir(dir);
} catch {
return [];
}
}
async function readUtf8File(filePath: string): Promise<string | null> {
try {
return await fs.readFile(filePath, "utf8");
} catch {
return null;
}
}
async function scanLaunchdDir(params: {
dir: string;
scope: "user" | "system";
}): Promise<ExtraGatewayService[]> {
const results: ExtraGatewayService[] = [];
let entries: string[] = [];
try {
entries = await fs.readdir(params.dir);
} catch {
return results;
}
const entries = await readDirEntries(params.dir);
for (const entry of entries) {
if (!entry.endsWith(".plist")) {
@@ -157,10 +168,8 @@ async function scanLaunchdDir(params: {
continue;
}
const fullPath = path.join(params.dir, entry);
let contents = "";
try {
contents = await fs.readFile(fullPath, "utf8");
} catch {
const contents = await readUtf8File(fullPath);
if (contents === null) {
continue;
}
const marker = detectMarker(contents);
@@ -204,12 +213,7 @@ async function scanSystemdDir(params: {
scope: "user" | "system";
}): Promise<ExtraGatewayService[]> {
const results: ExtraGatewayService[] = [];
let entries: string[] = [];
try {
entries = await fs.readdir(params.dir);
} catch {
return results;
}
const entries = await readDirEntries(params.dir);
for (const entry of entries) {
if (!entry.endsWith(".service")) {
@@ -220,10 +224,8 @@ async function scanSystemdDir(params: {
continue;
}
const fullPath = path.join(params.dir, entry);
let contents = "";
try {
contents = await fs.readFile(fullPath, "utf8");
} catch {
const contents = await readUtf8File(fullPath);
if (contents === null) {
continue;
}
const marker = detectMarker(contents);

View File

@@ -1,3 +1,5 @@
import { formatRuntimeStatusWithDetails } from "../infra/runtime-status.ts";
export type ServiceRuntimeLike = {
status?: string;
state?: string;
@@ -14,14 +16,7 @@ export function formatRuntimeStatus(runtime: ServiceRuntimeLike | undefined): st
if (!runtime) {
return null;
}
const status = runtime.status ?? "unknown";
const details: string[] = [];
if (runtime.pid) {
details.push(`pid ${runtime.pid}`);
}
if (runtime.state && runtime.state.toLowerCase() !== status) {
details.push(`state ${runtime.state}`);
}
if (runtime.subState) {
details.push(`sub ${runtime.subState}`);
}
@@ -40,5 +35,10 @@ export function formatRuntimeStatus(runtime: ServiceRuntimeLike | undefined): st
if (runtime.detail) {
details.push(runtime.detail);
}
return details.length > 0 ? `${status} (${details.join(", ")})` : status;
return formatRuntimeStatusWithDetails({
status: runtime.status,
pid: runtime.pid,
state: runtime.state,
details,
});
}