feat: Phase 1 — CAS thread storage types + helpers

- Add StartNode, StateNode, ContentMerkleNode types to workflow-protocol
- Add collectRefs() to workflow-cas — extracts CAS hashes from StateNode payload
- Add findReachableHashes() to workflow-cas — recursive mark traversal via refs[]
- Tests: 7 pass (collect-refs + reachable)

Refs #155, closes #156

小橘 <xiaoju@shazhou.work>
This commit is contained in:
2026-05-09 07:30:47 +00:00
parent 8f78a00063
commit 6f000512d2
9 changed files with 280 additions and 34 deletions
@@ -0,0 +1,36 @@
// ── CAS thread chain nodes (RFC: CAS-based thread storage) ──────────
export type StartNodePayload = {
name: string;
hash: string;
maxRounds: number;
depth: number;
};
export type StartNode = {
type: "start";
payload: StartNodePayload;
refs: string[];
};
export type StateNodePayload = {
role: string;
meta: Record<string, unknown>;
start: string;
content: string;
ancestors: string[];
compact: string | null;
timestamp: number;
};
export type StateNode = {
type: "state";
payload: StateNodePayload;
refs: string[];
};
export type ContentMerkleNode = {
type: "content";
payload: string;
refs: string[];
};
+36 -30
View File
@@ -1,40 +1,46 @@
// ── Types ──────────────────────────────────────────────────────────
export type {
Result,
CasStore,
WorkflowRoleSchema,
WorkflowRoleDescriptor,
WorkflowDescriptor,
RoleMeta,
RoleOutput,
StartStep,
RoleStep,
ThreadContext,
ModeratorContext,
AgentContext,
ExtractContext,
WorkflowCompletion,
WorkflowResult,
LlmProvider,
ProviderConfig,
ResolvedModel,
WorkflowConfig,
ExtractFn,
AgentFn,
AgentBinding,
WorkflowRuntime,
WorkflowFn,
RoleDefinition,
Moderator,
WorkflowDefinition,
AdvanceOutcome,
ContentMerkleNode,
StartNode,
StateNode,
} from "./cas-types.js";
export type {
AdvanceOutcome,
AgentBinding,
AgentContext,
AgentFn,
CasStore,
ExtractContext,
ExtractFn,
LlmProvider,
Moderator,
ModeratorContext,
ProviderConfig,
ResolvedModel,
Result,
RoleDefinition,
RoleMeta,
RoleOutput,
RoleStep,
StartStep,
ThreadContext,
WorkflowCompletion,
WorkflowConfig,
WorkflowDefinition,
WorkflowDescriptor,
WorkflowFn,
WorkflowResult,
WorkflowRoleDescriptor,
WorkflowRoleSchema,
WorkflowRuntime,
} from "./types.js";
// ── Constants ──────────────────────────────────────────────────────
export { START, END } from "./types.js";
export { END, START } from "./types.js";
// ── Constructor functions ──────────────────────────────────────────
export { ok, err } from "./result.js";
export { err, ok } from "./result.js";