Merge pull request 'simplify: thread fork only takes step-hash' (#346) from fix/342-fork-simplify into main

This commit is contained in:
2026-05-18 16:43:33 +00:00
3 changed files with 8 additions and 31 deletions
+3 -4
View File
@@ -161,12 +161,11 @@ thread
thread
.command("fork")
.description("Fork a thread from a specific step")
.argument("<thread-id>", "Thread ULID")
.argument("<step-hash>", "CAS hash of the step to fork from")
.action((threadId: string, stepHash: string) => {
.argument("<step-hash>", "CAS hash of the StartNode or StepNode to fork from")
.action((stepHash: string) => {
const storageRoot = resolveStorageRoot();
runAction(async () => {
const result = await cmdThreadFork(storageRoot, threadId, stepHash);
const result = await cmdThreadFork(storageRoot, stepHash);
writeOutput(result);
});
});
+5 -26
View File
@@ -521,35 +521,15 @@ export async function cmdThreadSteps(
export async function cmdThreadFork(
storageRoot: string,
threadId: ThreadId,
stepHash: CasRef,
): Promise<ThreadForkOutput> {
const headHash = await resolveHeadHash(storageRoot, threadId);
const uwf = await createUwfStore(storageRoot);
// Verify stepHash belongs to this thread by walking the chain
let found = false;
let cur: CasRef | null = headHash;
while (cur !== null) {
if (cur === stepHash) {
found = true;
break;
}
const node = uwf.store.get(cur);
if (node === null) break;
if (node.type === uwf.schemas.startNode) {
// startHash check
if (cur === stepHash) {
found = true;
}
break;
}
const payload = node.payload as StepNodePayload;
cur = payload.prev;
const node = uwf.store.get(stepHash);
if (node === null) {
fail(`CAS node not found: ${stepHash}`);
}
if (!found) {
fail(`step ${stepHash} not found in thread ${threadId}`);
if (node.type !== uwf.schemas.startNode && node.type !== uwf.schemas.stepNode) {
fail(`node ${stepHash} is not a StartNode or StepNode`);
}
const newThreadId = generateUlid(Date.now()) as ThreadId;
@@ -560,7 +540,6 @@ export async function cmdThreadFork(
return {
thread: newThreadId,
forkedFrom: {
thread: threadId,
step: stepHash,
},
};
-1
View File
@@ -109,7 +109,6 @@ export type ThreadStepsOutput = {
export type ThreadForkOutput = {
thread: ThreadId;
forkedFrom: {
thread: ThreadId;
step: CasRef;
};
};