feat: add @uncaged/workflow-agent-builtin package #420
Reference in New Issue
Block a user
Delete Branch "feat/builtin-agent"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Built-in role agent (
uwf-builtin) that uses workflow config models directly with its own tool-calling run loop. No external agent dependency (no hermes/openclaw/claude-code).Why
Enable self-contained workflow execution without requiring external agent CLIs.
Changes
packages/workflow-agent-builtin/(1848 lines)src/llm/: OpenAI-compatible chat completion client with tool_calls supportsrc/tools/: P0 toolkit — read_file, write_file, run_command (path sandboxed)src/loop.ts: Agent run loop (multi-turn LLM ↔ tool execution)src/prompt.ts: Prompt assembly (aligned with uwf-hermes)src/detail.ts: CAS detail recording per turnsrc/agent.ts: createBuiltinAgent() via createAgent factorysrc/cli.ts: CLI entry point (uwf-builtin)workflow-agent-kit: export resolveStorageRootdocs/builtin-agent-research.mdConfig
Shell tool requires
UWF_BUILTIN_ALLOW_SHELL=1.Tests
5 new tests (LLM parsing, path security, prompt building). All existing tests pass.
76a5b14957todeac2336b6Review: @uncaged/workflow-agent-builtin
整体架构清晰,与现有 hermes/claude-code agent 包对齐良好,类型安全做得不错。但有几个安全和正确性问题需要修复。
🔴 Must Fix
1. Path sandbox 可被 symlink 绕过 (
src/tools/path.ts)resolvePathInWorkspace只做relative()检查,没有realpath解析。LLM 可先run_command创建符号链接workspace/link -> /etc,再read_file("link/shadow")读取任意文件。建议 resolve 后加fs.realpathSync,对真实路径再做一次检查。2.
run_commandstdout/stderr 无限缓冲 → OOMon('data')回调无限拼接字符串,恶意命令可输出 GB 级数据。应在回调中就做截断检查。3.
run_commandtimeout 后仅 SIGTERM,无 SIGKILL fallback进程可忽略 SIGTERM 继续运行。建议 SIGTERM 后 5s 再 SIGKILL。
4.
run_commandshell=true + 仅 cwd 沙箱 = 虚假安全感command 本身可以
cd /anywhere && ...。cwd 检查在 shell=true 下形同虚设。建议注释/文档明确说明UWF_BUILTIN_ALLOW_SHELL=1是完全无沙箱的 shell 访问。🟡 Suggestions
5. 测试覆盖不足 — 无 loop.ts 测试(核心多轮逻辑)、无 run_command 测试、path.test.ts 缺边界用例(symlink、绝对路径、空字符串)。建议至少加 loop 的 mock LLM 测试。
6. LLM 客户端无重试 — 429/5xx 直接抛异常,建议加指数退避。
7.
maxTurns耗尽时优雅降级 — 最后一轮仍有 tool_calls 时没发 "请总结" 请求,可能返回空输出。8. schema 每次 detail 写入都重新注册 — 应缓存。
9.
docs/builtin-agent-research.md(779行) — 调研文档建议移到 wiki,不合入代码库。10.
package.jsonbin 指向./src/cli.ts— 发布时应指向dist/cli.js,否则非 bun 环境无法运行。11. session Map 无清理 —
createBuiltinAgent暴露为 API,长期运行可能泄漏。修复 symlink 绕过和 OOM 风险后可合入,其余可作 follow-up。
更正:撤回安全相关意见
经主人指出,role agent 本身应有设备完整权限,安全边界由外部沙箱机制保证。因此撤回以下意见:
Path sandbox symlink 绕过shell=true cwd 沙箱仍然建议修复的稳定性问题:
run_commandstdout/stderr 无限缓冲 → OOM(这是稳定性问题,不是安全问题)其余测试覆盖、LLM 重试、schema 缓存等建议不变,可 follow-up。
如果 OOM 和 SIGKILL 也打算后续再处理,可以直接合入。
补充建议:去掉 in-workspace 路径限制
Role agent 应有设备完整权限(安全边界由外部沙箱保证),
resolvePathInWorkspace的路径限制是多余的,还会阻碍 agent 读写 workspace 外文件的正当需求。建议:
read_file/write_file直接用path.resolve(cwd, inputPath)即可,不做越界检查run_command的 cwd 参数同理UWF_BUILTIN_ALLOW_SHELL门控也可以去掉,shell 默认可用简化后代码更干净,也符合实际使用场景。
LGTM ✅ 路径限制和 shell 门控已移除,简洁干净。稳定性改进留 follow-up。