From 587518ac0948e408169bf202dc08f63cafcc4422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Fri, 8 May 2026 06:37:56 +0000 Subject: [PATCH] refactor(workflow): cleanup engine re-exports, final verification (Phase 4) - Remove all re-exports from @uncaged/workflow -> @uncaged/workflow-runtime - Fix cli-workflow imports to use @uncaged/workflow-runtime for types - Update bundle-validator to allow @uncaged/workflow-runtime imports - Update init templates to reference @uncaged/workflow-runtime - 378 tests passing, build + check clean Refs #121, relates #125 --- package.json | 1 + .../__tests__/init-template.test.ts | 1 + packages/cli-workflow/package.json | 1 + .../src/commands/init/templates.ts | 7 +++--- .../cli-workflow/src/commands/thread/live.ts | 2 +- packages/cli-workflow/tsconfig.json | 2 +- .../__tests__/bundle-validator.test.ts | 10 ++++++++ .../workflow/src/bundle/bundle-validator.ts | 2 +- packages/workflow/src/index.ts | 24 ------------------- 9 files changed, 20 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 9ecc7a7..8871b81 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "packages/*" ], "scripts": { + "build": "bunx tsc --build", "check": "bunx tsc --build && biome check .", "typecheck": "bunx tsc --build", "format": "biome format --write .", diff --git a/packages/cli-workflow/__tests__/init-template.test.ts b/packages/cli-workflow/__tests__/init-template.test.ts index d1a9277..c1423e9 100644 --- a/packages/cli-workflow/__tests__/init-template.test.ts +++ b/packages/cli-workflow/__tests__/init-template.test.ts @@ -51,6 +51,7 @@ describe("init template", () => { }; expect(pkg.type).toBe("module"); expect(pkg.dependencies["@uncaged/workflow"]).toBeDefined(); + expect(pkg.dependencies["@uncaged/workflow-runtime"]).toBeDefined(); expect(pkg.dependencies.zod).toBeDefined(); expect(pkg.name).toContain("review-pr"); diff --git a/packages/cli-workflow/package.json b/packages/cli-workflow/package.json index c156c29..c0bb241 100644 --- a/packages/cli-workflow/package.json +++ b/packages/cli-workflow/package.json @@ -6,6 +6,7 @@ "uncaged-workflow": "src/cli.ts" }, "dependencies": { + "@uncaged/workflow-runtime": "workspace:*", "@uncaged/workflow": "workspace:*", "hono": "^4.12.18", "yaml": "^2.8.4" diff --git a/packages/cli-workflow/src/commands/init/templates.ts b/packages/cli-workflow/src/commands/init/templates.ts index 89d2809..5ccebc1 100644 --- a/packages/cli-workflow/src/commands/init/templates.ts +++ b/packages/cli-workflow/src/commands/init/templates.ts @@ -7,6 +7,7 @@ export function templatePackageJson(templateName: string): string { type: "module", dependencies: { "@uncaged/workflow": "^0.1.0", + "@uncaged/workflow-runtime": "^0.1.0", zod: "^4.0.0", }, }, @@ -31,7 +32,7 @@ export function templateTsconfigJson(): string { } export function templateRolesTs(): string { - return `import type { RoleDefinition } from "@uncaged/workflow"; + return `import type { RoleDefinition } from "@uncaged/workflow-runtime"; import * as z from "zod/v4"; export const HELLO_TEMPLATE_DESCRIPTION = @@ -58,7 +59,7 @@ export const greeterRole: RoleDefinition = { } export function templateModeratorTs(): string { - return `import { END, type Moderator, type ModeratorContext } from "@uncaged/workflow"; + return `import { END, type Moderator, type ModeratorContext } from "@uncaged/workflow-runtime"; import type { HelloTemplateMeta } from "./roles.js"; @@ -74,7 +75,7 @@ export const helloTemplateModerator: Moderator = ( } export function templateIndexTs(): string { - return `import type { WorkflowDefinition } from "@uncaged/workflow"; + return `import type { WorkflowDefinition } from "@uncaged/workflow-runtime"; import { helloTemplateModerator } from "./moderator.js"; import { diff --git a/packages/cli-workflow/src/commands/thread/live.ts b/packages/cli-workflow/src/commands/thread/live.ts index d1cf879..bb9b684 100644 --- a/packages/cli-workflow/src/commands/thread/live.ts +++ b/packages/cli-workflow/src/commands/thread/live.ts @@ -9,8 +9,8 @@ import { getGlobalCasDir, tryParseRoleStepRecord, tryParseWorkflowResultRecord, - type WorkflowCompletion, } from "@uncaged/workflow"; +import type { WorkflowCompletion } from "@uncaged/workflow-runtime"; import { dimGreyLine, highlightLiveRole } from "../../cli-color.js"; import { printCliError, printCliLine } from "../../cli-output.js"; diff --git a/packages/cli-workflow/tsconfig.json b/packages/cli-workflow/tsconfig.json index 436a5c3..764b246 100644 --- a/packages/cli-workflow/tsconfig.json +++ b/packages/cli-workflow/tsconfig.json @@ -17,6 +17,6 @@ "rootDir": "src", "types": ["bun-types"] }, - "references": [{ "path": "../workflow" }], + "references": [{ "path": "../workflow-runtime" }, { "path": "../workflow" }], "include": ["src/**/*.ts"] } diff --git a/packages/workflow/__tests__/bundle-validator.test.ts b/packages/workflow/__tests__/bundle-validator.test.ts index d7a77a4..ad7af01 100644 --- a/packages/workflow/__tests__/bundle-validator.test.ts +++ b/packages/workflow/__tests__/bundle-validator.test.ts @@ -39,6 +39,16 @@ export const run = async function* (_input, options) { expect(r.ok).toBe(true); }); + test("allows static import of @uncaged/workflow-runtime", () => { + const source = `${minimalDescriptor}import { createWorkflow } from "@uncaged/workflow-runtime"; +import { putContentMerkleNode } from "@uncaged/workflow"; + +export const run = createWorkflow({ description: "x", roles: {}, moderator: () => "END" }, {}); +`; + const r = validateWorkflowBundle({ filePath: "/tmp/w.esm.js", source }); + expect(r.ok).toBe(true); + }); + test("rejects wrong filename suffix", () => { const r = validateWorkflowBundle({ filePath: "/tmp/w.js", diff --git a/packages/workflow/src/bundle/bundle-validator.ts b/packages/workflow/src/bundle/bundle-validator.ts index 0e8e38a..b140145 100644 --- a/packages/workflow/src/bundle/bundle-validator.ts +++ b/packages/workflow/src/bundle/bundle-validator.ts @@ -38,7 +38,7 @@ function isAllowedImportSpecifier(spec: string): boolean { if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) { return false; } - if (spec === "@uncaged/workflow") { + if (spec === "@uncaged/workflow" || spec === "@uncaged/workflow-runtime") { return true; } return isBuiltin(spec); diff --git a/packages/workflow/src/index.ts b/packages/workflow/src/index.ts index 5c2ea34..685791e 100644 --- a/packages/workflow/src/index.ts +++ b/packages/workflow/src/index.ts @@ -1,27 +1,3 @@ -export { - type AgentBinding, - type AgentContext, - type AgentFn, - END, - type ExtractContext, - type ExtractMode, - type LlmProvider, - type Moderator, - type ModeratorContext, - type RoleDefinition, - type RoleMeta, - type RoleOutput, - type RoleStep, - START, - type StartStep, - type ThreadContext, - type ThreadInput, - type WorkflowCompletion, - type WorkflowDefinition, - type WorkflowFn, - type WorkflowFnOptions, - type WorkflowResult, -} from "@uncaged/workflow-runtime"; export { buildDescriptor, type ExtractedBundleExports,