From bd5e5a435b26959086c3d66367315b71b7288df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Mon, 18 May 2026 16:38:55 +0000 Subject: [PATCH] simplify: thread fork only takes step-hash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove thread-id argument — CAS node is self-contained, no need to specify which thread it belongs to. Just verify the hash is a valid StartNode or StepNode. Refs #342 --- packages/cli-uwf/src/cli.ts | 7 +++--- packages/cli-uwf/src/commands/thread.ts | 31 ++++--------------------- packages/uwf-protocol/src/types.ts | 1 - 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/packages/cli-uwf/src/cli.ts b/packages/cli-uwf/src/cli.ts index 7272ff9..a8b8b22 100755 --- a/packages/cli-uwf/src/cli.ts +++ b/packages/cli-uwf/src/cli.ts @@ -161,12 +161,11 @@ thread thread .command("fork") .description("Fork a thread from a specific step") - .argument("", "Thread ULID") - .argument("", "CAS hash of the step to fork from") - .action((threadId: string, stepHash: string) => { + .argument("", "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); }); }); diff --git a/packages/cli-uwf/src/commands/thread.ts b/packages/cli-uwf/src/commands/thread.ts index a7b8eae..f718996 100644 --- a/packages/cli-uwf/src/commands/thread.ts +++ b/packages/cli-uwf/src/commands/thread.ts @@ -521,35 +521,15 @@ export async function cmdThreadSteps( export async function cmdThreadFork( storageRoot: string, - threadId: ThreadId, stepHash: CasRef, ): Promise { - 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, }, }; diff --git a/packages/uwf-protocol/src/types.ts b/packages/uwf-protocol/src/types.ts index deccd79..34f4822 100644 --- a/packages/uwf-protocol/src/types.ts +++ b/packages/uwf-protocol/src/types.ts @@ -109,7 +109,6 @@ export type ThreadStepsOutput = { export type ThreadForkOutput = { thread: ThreadId; forkedFrom: { - thread: ThreadId; step: CasRef; }; };