fix: use optionalEnv with defaults for agent CLI paths in bundle entry

requireEnv causes silent worker crash when env vars are missing —
thread shows 0 steps with no error. Use optionalEnv + sensible defaults.

Also added pitfall guidance in skill author docs.

小橘 🍊
This commit is contained in:
2026-05-15 09:25:39 +00:00
parent 0f3661b566
commit 40530d757e
3 changed files with 30 additions and 4 deletions
+7 -1
View File
@@ -1,7 +1,13 @@
{
"$schema": "https://biomejs.dev/schemas/2.4.15/schema.json",
"files": {
"includes": ["**", "!**/dist", "!**/node_modules", "!packages/workflow/workflow"]
"includes": [
"**",
"!**/dist",
"!**/node_modules",
"!packages/workflow/workflow",
"!xiaoju/scripts/bundle.ts"
]
},
"assist": { "actions": { "source": { "organizeImports": "on" } } },
"formatter": {
+20
View File
@@ -301,6 +301,26 @@ function createLazyAdapter(): AdapterFn {
}
\`\`\`
### Agent CLI paths: use optionalEnv with defaults
When binding agent adapters (cursor-agent, hermes, etc.), **always use \`optionalEnv\` with a sensible default** — never \`requireEnv\`. The worker process may start without the expected env vars, causing a silent crash.
Discover the correct CLI path yourself (e.g. \`which cursor-agent\`, \`which hermes\`) and use it as the fallback:
\`\`\`typescript
// ❌ WRONG — worker crash if env var missing, thread silently fails with 0 steps
const adapter = createCursorAgent({
command: requireEnv("WORKFLOW_CURSOR_COMMAND", "set it"),
...
});
// ✅ CORRECT — env override with discovered default
const adapter = createCursorAgent({
command: optionalEnv("WORKFLOW_CURSOR_COMMAND") ?? "cursor-agent",
...
});
\`\`\`
### Bundle import restrictions
The bundle validator only allows these import specifiers:
@@ -7,11 +7,11 @@
import { createCursorAgent } from "@uncaged/workflow-agent-cursor";
import { createHermesAgent } from "@uncaged/workflow-agent-hermes";
import { createWorkflow } from "@uncaged/workflow-runtime";
import { optionalEnv, requireEnv } from "@uncaged/workflow-util";
import { optionalEnv } from "@uncaged/workflow-util";
import { buildDevelopDescriptor, developWorkflowDefinition } from "./src/index.js";
const cursorAdapter = createCursorAgent({
command: requireEnv("WORKFLOW_CURSOR_COMMAND", "set WORKFLOW_CURSOR_COMMAND (e.g. cursor-agent)"),
command: optionalEnv("WORKFLOW_CURSOR_COMMAND") ?? "cursor-agent",
model: optionalEnv("WORKFLOW_CURSOR_MODEL"),
timeout: optionalEnv("WORKFLOW_CURSOR_TIMEOUT")
? Number(optionalEnv("WORKFLOW_CURSOR_TIMEOUT"))
@@ -20,7 +20,7 @@ const cursorAdapter = createCursorAgent({
});
const hermesAdapter = createHermesAgent({
command: requireEnv("WORKFLOW_HERMES_COMMAND", "set WORKFLOW_HERMES_COMMAND (absolute path to hermes CLI)"),
command: optionalEnv("WORKFLOW_HERMES_COMMAND") ?? "hermes",
model: optionalEnv("WORKFLOW_HERMES_MODEL"),
timeout: optionalEnv("WORKFLOW_HERMES_TIMEOUT")
? Number(optionalEnv("WORKFLOW_HERMES_TIMEOUT"))