From 8f6d4f88dde6435cffd3ad9bb7e1bb1ae8143477 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Mon, 22 Jun 2026 20:09:24 +0800 Subject: [PATCH] =?UTF-8?q?chore(workflow-engine):=20=E5=B0=81=E5=8C=85?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=88=B0=20npm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 private,补全 exports/types/files/publishConfig/license/repository 等 - 添加 LICENSE (MIT) 与 README - 添加 scripts/build.ts + tsconfig.build.json,用 tsc emit 输出 dist/**/*.js + .d.ts (Bun bundle + external zod 会丢失 createWorkflowTool/workflowInputSchema/persistInlineScript 符号,改用 tsc emit) - 修 src/index.ts 的 WORKFLOW_TOOL_NAME 重复 export;tool/* 的 named re-export 改为 import + 再 export Co-Authored-By: glm-5.2 --- packages/workflow-engine/LICENSE | 21 ++++++ packages/workflow-engine/README.md | 71 ++++++++++++++++++++ packages/workflow-engine/package.json | 60 +++++++++++++++-- packages/workflow-engine/scripts/build.ts | 21 ++++++ packages/workflow-engine/src/index.ts | 14 ++-- packages/workflow-engine/tsconfig.build.json | 21 ++++++ 6 files changed, 199 insertions(+), 9 deletions(-) create mode 100644 packages/workflow-engine/LICENSE create mode 100644 packages/workflow-engine/README.md create mode 100644 packages/workflow-engine/scripts/build.ts create mode 100644 packages/workflow-engine/tsconfig.build.json diff --git a/packages/workflow-engine/LICENSE b/packages/workflow-engine/LICENSE new file mode 100644 index 000000000..4a0c3e1e4 --- /dev/null +++ b/packages/workflow-engine/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 claude-code-best + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/workflow-engine/README.md b/packages/workflow-engine/README.md new file mode 100644 index 000000000..a49527434 --- /dev/null +++ b/packages/workflow-engine/README.md @@ -0,0 +1,71 @@ +# @claude-code-best/workflow-engine + +Deterministic JS script orchestration engine for multi-agent workflows. The core layer has zero runtime dependencies and talks to the outside world exclusively through **port adapters** — you bring your own agent backend, journal store, and progress sink. + +## Why + +When you orchestrate multiple LLM agents, you want the orchestration itself to be **deterministic, replayable, and testable**. This engine runs a plain JS script (compiled by Bun's transpiler) with primitives like `agent()`, `phase()`, `parallel()` and `pipeline()`. The non-deterministic parts (the LLM, the file system, the clock) are isolated behind ports, so the same script produces the same journal on every replay. + +## Installation + +```bash +bun add @claude-code-best/workflow-engine +# or +npm install @claude-code-best/workflow-engine +``` + +Runtime peer requirements: `ajv` and `zod` are pulled in automatically as dependencies. + +## Minimal example + +```ts +import { + createFileJournalStore, + createHostHandle, + runWorkflow, + type WorkflowPorts, +} from '@claude-code-best/workflow-engine' + +const script = ` +export const meta = { name: 'hello', description: 'minimal demo' } +phase('Greet') +const reply = await agent({ prompt: 'Say hi in one short sentence.' }) +emit('result', { reply }) +` + +const ports: WorkflowPorts = { + // Provide your own agent runner + journal + progress emitter. + // See examples/smoke.ts for a complete Anthropic SDK wiring. +} as WorkflowPorts + +const handle = createHostHandle() +await runWorkflow({ + script, + ports, + workflowDir: '.wfe/runs/hello', + hostHandle: handle, +}) +``` + +For a fully wired end-to-end example with the Anthropic SDK, see [`examples/smoke.ts`](./examples/smoke.ts). + +## Core primitives + +- `agent(params)` — call the configured AgentRunner; supports structured-output via JSON Schema. +- `phase(name)` — declare a logical phase (display + progress grouping). +- `parallel([...])` — barrier-style fan-out with bounded concurrency. +- `pipeline(stream, fn)` — streaming pipeline with per-item hooks. +- `emit(type, payload)` — emit a progress event to the host. +- `log.*` / hooks / budgets — see the TypeScript definitions for the full surface. + +## Building from source + +```bash +bun install # from the repo root +bun run build # outputs dist/index.js + dist/**/*.d.ts +bun test # 178 tests +``` + +## License + +MIT © claude-code-best diff --git a/packages/workflow-engine/package.json b/packages/workflow-engine/package.json index a13f05448..989d6da3a 100644 --- a/packages/workflow-engine/package.json +++ b/packages/workflow-engine/package.json @@ -1,19 +1,69 @@ { "name": "@claude-code-best/workflow-engine", "version": "0.1.0", - "private": true, + "description": "Deterministic JS script orchestration engine for multi-agent workflows. Zero core-layer runtime dependencies; talks to the world via port adapters.", "type": "module", - "main": "./src/index.ts", - "types": "./src/index.ts", + "license": "MIT", + "author": "claude-code-best ", + "homepage": "https://github.com/claude-code-best/claude-code/tree/main/packages/workflow-engine#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/claude-code-best/claude-code.git", + "directory": "packages/workflow-engine" + }, + "bugs": { + "url": "https://github.com/claude-code-best/claude-code/issues" + }, + "keywords": [ + "workflow", + "orchestration", + "multi-agent", + "claude", + "automation", + "scripting", + "deterministic" + ], + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { - ".": "./src/index.ts", + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "default": "./dist/index.js" + }, "./package.json": "./package.json" }, + "files": [ + "dist", + "src", + "!src/**/__tests__", + "!src/**/*.test.ts", + "scripts/build.ts", + "tsconfig.json", + "tsconfig.build.json", + "README.md", + "LICENSE" + ], + "sideEffects": false, + "engines": { + "node": ">=20" + }, + "publishConfig": { + "access": "public" + }, "dependencies": { "ajv": "^8.18.0", "zod": "^4.3.6" }, "devDependencies": { - "@anthropic-ai/sdk": "^0.81.0" + "@anthropic-ai/sdk": "^0.81.0", + "bun-types": "latest" + }, + "scripts": { + "build": "bun run scripts/build.ts", + "typecheck": "tsc --noEmit", + "test": "bun test", + "prepublishOnly": "bun run test && bun run build" } } diff --git a/packages/workflow-engine/scripts/build.ts b/packages/workflow-engine/scripts/build.ts new file mode 100644 index 000000000..766fd0248 --- /dev/null +++ b/packages/workflow-engine/scripts/build.ts @@ -0,0 +1,21 @@ +import { mkdir, rm } from 'node:fs/promises' + +const ROOT = new URL('../', import.meta.url) +const DIST = new URL('../dist/', import.meta.url) + +await rm(DIST, { recursive: true, force: true }) +await mkdir(DIST, { recursive: true }) + +// Emit dist/**/*.js + dist/**/*.d.ts (+ maps) via tsc. +const proc = Bun.spawn(['bunx', 'tsc', '-p', 'tsconfig.build.json'], { + cwd: ROOT.pathname, + stdout: 'inherit', + stderr: 'inherit', +}) +const exitCode = await proc.exited +if (exitCode !== 0) { + console.error('tsc emit failed') + process.exit(exitCode) +} + +console.log('✓ build complete') diff --git a/packages/workflow-engine/src/index.ts b/packages/workflow-engine/src/index.ts index 5d790123d..cb04ade31 100644 --- a/packages/workflow-engine/src/index.ts +++ b/packages/workflow-engine/src/index.ts @@ -16,10 +16,16 @@ export * from './engine/context.js' export * from './engine/hooks.js' export * from './engine/runWorkflow.js' export * from './progress/events.js' -export { +import { createWorkflowTool, type WorkflowToolDescriptor, } from './tool/WorkflowTool.js' -export { workflowInputSchema, type WorkflowInput } from './tool/schema.js' -export { persistInlineScript } from './tool/persistInline.js' -export { WORKFLOW_TOOL_NAME } from './tool/constants.js' +import { workflowInputSchema, type WorkflowInput } from './tool/schema.js' +import { persistInlineScript } from './tool/persistInline.js' +export { + createWorkflowTool, + type WorkflowToolDescriptor, + workflowInputSchema, + type WorkflowInput, + persistInlineScript, +} diff --git a/packages/workflow-engine/tsconfig.build.json b/packages/workflow-engine/tsconfig.build.json new file mode 100644 index 000000000..240b6fc45 --- /dev/null +++ b/packages/workflow-engine/tsconfig.build.json @@ -0,0 +1,21 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "declarationMap": false, + "sourceMap": false, + "outDir": "dist", + "rootDir": "src", + "module": "ESNext", + "moduleResolution": "bundler", + "target": "ESNext" + }, + "include": ["src/**/*"], + "exclude": [ + "node_modules", + "src/**/__tests__/**", + "examples/**", + "scripts/**" + ] +}