9bbdfc41bd
Phase 7: Engine + extract + workflow-as-agent merged into execute package. All CLI imports migrated from @uncaged/workflow to specific packages. 105 CLI tests pass, 0 failures. Changes: - New @uncaged/workflow-execute package (engine/, extract/, workflow-as-agent) - CLI src/ and __tests__/ rewritten to import from split packages - bundle-validator updated to allow @uncaged/workflow-cas imports - ensure-uncaged-workflow-symlink creates symlinks for all new packages Ref: #143, closes #150
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import type { Result } from "@uncaged/workflow-protocol";
|
|
|
|
import {
|
|
readWorkerCtl,
|
|
resolveRunningHashForThread,
|
|
sendWorkerTcpCommand,
|
|
} from "../../worker-spawn.js";
|
|
|
|
type ThreadControlAction = "kill" | "pause" | "resume";
|
|
|
|
async function cmdThreadControl(
|
|
storageRoot: string,
|
|
threadId: string,
|
|
action: ThreadControlAction,
|
|
): Promise<Result<void, string>> {
|
|
const hashResult = await resolveRunningHashForThread(storageRoot, threadId);
|
|
if (!hashResult.ok) {
|
|
return hashResult;
|
|
}
|
|
|
|
const ctlResult = await readWorkerCtl(storageRoot, hashResult.value);
|
|
if (!ctlResult.ok) {
|
|
return ctlResult;
|
|
}
|
|
|
|
return await sendWorkerTcpCommand(
|
|
ctlResult.value.port,
|
|
{ type: action, threadId },
|
|
{ awaitResponseLine: true },
|
|
);
|
|
}
|
|
|
|
export async function cmdKill(
|
|
storageRoot: string,
|
|
threadId: string,
|
|
): Promise<Result<void, string>> {
|
|
return cmdThreadControl(storageRoot, threadId, "kill");
|
|
}
|
|
|
|
export async function cmdPause(
|
|
storageRoot: string,
|
|
threadId: string,
|
|
): Promise<Result<void, string>> {
|
|
return cmdThreadControl(storageRoot, threadId, "pause");
|
|
}
|
|
|
|
export async function cmdResume(
|
|
storageRoot: string,
|
|
threadId: string,
|
|
): Promise<Result<void, string>> {
|
|
return cmdThreadControl(storageRoot, threadId, "resume");
|
|
}
|