Skip to content

Commit 8f6d4f8

Browse files
claude-code-bestglm-5.2
andcommitted
chore(workflow-engine): 封包发布到 npm
- 移除 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 <zai-org@claude-code-best.win>
1 parent 336b9e3 commit 8f6d4f8

6 files changed

Lines changed: 199 additions & 9 deletions

File tree

packages/workflow-engine/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 claude-code-best
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/workflow-engine/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# @claude-code-best/workflow-engine
2+
3+
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.
4+
5+
## Why
6+
7+
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.
8+
9+
## Installation
10+
11+
```bash
12+
bun add @claude-code-best/workflow-engine
13+
# or
14+
npm install @claude-code-best/workflow-engine
15+
```
16+
17+
Runtime peer requirements: `ajv` and `zod` are pulled in automatically as dependencies.
18+
19+
## Minimal example
20+
21+
```ts
22+
import {
23+
createFileJournalStore,
24+
createHostHandle,
25+
runWorkflow,
26+
type WorkflowPorts,
27+
} from '@claude-code-best/workflow-engine'
28+
29+
const script = `
30+
export const meta = { name: 'hello', description: 'minimal demo' }
31+
phase('Greet')
32+
const reply = await agent({ prompt: 'Say hi in one short sentence.' })
33+
emit('result', { reply })
34+
`
35+
36+
const ports: WorkflowPorts = {
37+
// Provide your own agent runner + journal + progress emitter.
38+
// See examples/smoke.ts for a complete Anthropic SDK wiring.
39+
} as WorkflowPorts
40+
41+
const handle = createHostHandle()
42+
await runWorkflow({
43+
script,
44+
ports,
45+
workflowDir: '.wfe/runs/hello',
46+
hostHandle: handle,
47+
})
48+
```
49+
50+
For a fully wired end-to-end example with the Anthropic SDK, see [`examples/smoke.ts`](./examples/smoke.ts).
51+
52+
## Core primitives
53+
54+
- `agent(params)` — call the configured AgentRunner; supports structured-output via JSON Schema.
55+
- `phase(name)` — declare a logical phase (display + progress grouping).
56+
- `parallel([...])` — barrier-style fan-out with bounded concurrency.
57+
- `pipeline(stream, fn)` — streaming pipeline with per-item hooks.
58+
- `emit(type, payload)` — emit a progress event to the host.
59+
- `log.*` / hooks / budgets — see the TypeScript definitions for the full surface.
60+
61+
## Building from source
62+
63+
```bash
64+
bun install # from the repo root
65+
bun run build # outputs dist/index.js + dist/**/*.d.ts
66+
bun test # 178 tests
67+
```
68+
69+
## License
70+
71+
MIT © claude-code-best
Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,69 @@
11
{
22
"name": "@claude-code-best/workflow-engine",
33
"version": "0.1.0",
4-
"private": true,
4+
"description": "Deterministic JS script orchestration engine for multi-agent workflows. Zero core-layer runtime dependencies; talks to the world via port adapters.",
55
"type": "module",
6-
"main": "./src/index.ts",
7-
"types": "./src/index.ts",
6+
"license": "MIT",
7+
"author": "claude-code-best <claude-code-best@proton.me>",
8+
"homepage": "https://github.com/claude-code-best/claude-code/tree/main/packages/workflow-engine#readme",
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/claude-code-best/claude-code.git",
12+
"directory": "packages/workflow-engine"
13+
},
14+
"bugs": {
15+
"url": "https://github.com/claude-code-best/claude-code/issues"
16+
},
17+
"keywords": [
18+
"workflow",
19+
"orchestration",
20+
"multi-agent",
21+
"claude",
22+
"automation",
23+
"scripting",
24+
"deterministic"
25+
],
26+
"main": "./dist/index.js",
27+
"module": "./dist/index.js",
28+
"types": "./dist/index.d.ts",
829
"exports": {
9-
".": "./src/index.ts",
30+
".": {
31+
"types": "./dist/index.d.ts",
32+
"import": "./dist/index.js",
33+
"default": "./dist/index.js"
34+
},
1035
"./package.json": "./package.json"
1136
},
37+
"files": [
38+
"dist",
39+
"src",
40+
"!src/**/__tests__",
41+
"!src/**/*.test.ts",
42+
"scripts/build.ts",
43+
"tsconfig.json",
44+
"tsconfig.build.json",
45+
"README.md",
46+
"LICENSE"
47+
],
48+
"sideEffects": false,
49+
"engines": {
50+
"node": ">=20"
51+
},
52+
"publishConfig": {
53+
"access": "public"
54+
},
1255
"dependencies": {
1356
"ajv": "^8.18.0",
1457
"zod": "^4.3.6"
1558
},
1659
"devDependencies": {
17-
"@anthropic-ai/sdk": "^0.81.0"
60+
"@anthropic-ai/sdk": "^0.81.0",
61+
"bun-types": "latest"
62+
},
63+
"scripts": {
64+
"build": "bun run scripts/build.ts",
65+
"typecheck": "tsc --noEmit",
66+
"test": "bun test",
67+
"prepublishOnly": "bun run test && bun run build"
1868
}
1969
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { mkdir, rm } from 'node:fs/promises'
2+
3+
const ROOT = new URL('../', import.meta.url)
4+
const DIST = new URL('../dist/', import.meta.url)
5+
6+
await rm(DIST, { recursive: true, force: true })
7+
await mkdir(DIST, { recursive: true })
8+
9+
// Emit dist/**/*.js + dist/**/*.d.ts (+ maps) via tsc.
10+
const proc = Bun.spawn(['bunx', 'tsc', '-p', 'tsconfig.build.json'], {
11+
cwd: ROOT.pathname,
12+
stdout: 'inherit',
13+
stderr: 'inherit',
14+
})
15+
const exitCode = await proc.exited
16+
if (exitCode !== 0) {
17+
console.error('tsc emit failed')
18+
process.exit(exitCode)
19+
}
20+
21+
console.log('✓ build complete')

packages/workflow-engine/src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ export * from './engine/context.js'
1616
export * from './engine/hooks.js'
1717
export * from './engine/runWorkflow.js'
1818
export * from './progress/events.js'
19-
export {
19+
import {
2020
createWorkflowTool,
2121
type WorkflowToolDescriptor,
2222
} from './tool/WorkflowTool.js'
23-
export { workflowInputSchema, type WorkflowInput } from './tool/schema.js'
24-
export { persistInlineScript } from './tool/persistInline.js'
25-
export { WORKFLOW_TOOL_NAME } from './tool/constants.js'
23+
import { workflowInputSchema, type WorkflowInput } from './tool/schema.js'
24+
import { persistInlineScript } from './tool/persistInline.js'
25+
export {
26+
createWorkflowTool,
27+
type WorkflowToolDescriptor,
28+
workflowInputSchema,
29+
type WorkflowInput,
30+
persistInlineScript,
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"declaration": true,
6+
"declarationMap": false,
7+
"sourceMap": false,
8+
"outDir": "dist",
9+
"rootDir": "src",
10+
"module": "ESNext",
11+
"moduleResolution": "bundler",
12+
"target": "ESNext"
13+
},
14+
"include": ["src/**/*"],
15+
"exclude": [
16+
"node_modules",
17+
"src/**/__tests__/**",
18+
"examples/**",
19+
"scripts/**"
20+
]
21+
}

0 commit comments

Comments
 (0)