Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e8dd398f28 | |||
| 61d95cc47f |
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"mode": "exit",
|
|
||||||
"tag": "alpha",
|
|
||||||
"initialVersions": {
|
|
||||||
"@uncaged/cli-workflow": "0.4.5",
|
|
||||||
"@uncaged/workflow-agent-cursor": "0.4.5",
|
|
||||||
"@uncaged/workflow-agent-hermes": "0.4.5",
|
|
||||||
"@uncaged/workflow-agent-llm": "0.4.5",
|
|
||||||
"@uncaged/workflow-agent-react": "0.4.5",
|
|
||||||
"@uncaged/workflow-cas": "0.4.5",
|
|
||||||
"@uncaged/workflow-dashboard": "0.1.0",
|
|
||||||
"@uncaged/workflow-execute": "0.4.5",
|
|
||||||
"@uncaged/workflow-gateway": "0.4.5",
|
|
||||||
"@uncaged/workflow-protocol": "0.4.5",
|
|
||||||
"@uncaged/workflow-reactor": "0.4.5",
|
|
||||||
"@uncaged/workflow-register": "0.4.5",
|
|
||||||
"@uncaged/workflow-runtime": "0.4.5",
|
|
||||||
"@uncaged/workflow-template-develop": "0.4.5",
|
|
||||||
"@uncaged/workflow-template-solve-issue": "0.4.5",
|
|
||||||
"@uncaged/workflow-util": "0.4.5",
|
|
||||||
"@uncaged/workflow-util-agent": "0.4.5"
|
|
||||||
},
|
|
||||||
"changesets": [
|
|
||||||
"env-api-unify",
|
|
||||||
"fix-internal-deps",
|
|
||||||
"fix-publish-src",
|
|
||||||
"fix-workspace-deps",
|
|
||||||
"rfc-252-agent-fn"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -7,19 +7,18 @@ on:
|
|||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: oven-sh/setup-bun@v2
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
|
||||||
- run: bun install
|
- name: Install dependencies
|
||||||
|
run: bun install
|
||||||
|
|
||||||
- name: Build
|
- name: Check
|
||||||
run: bun run build
|
|
||||||
|
|
||||||
- name: Lint
|
|
||||||
run: bun run check
|
run: bun run check
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
|
|||||||
@@ -8,32 +8,20 @@ roles:
|
|||||||
- docker
|
- docker
|
||||||
- shell
|
- shell
|
||||||
procedure: |
|
procedure: |
|
||||||
1. Start a Docker container with isolated storage.
|
1. Start a Docker container with isolated storage:
|
||||||
IMPORTANT: Mount the source code READ-ONLY to prevent the container
|
|
||||||
from overwriting host files (e.g. bun install would replace macOS bun with Linux bun).
|
|
||||||
Use a container-local HOME so bun/npm installs stay inside the container.
|
|
||||||
Add host.docker.internal mapping for LLM API access from inside the container.
|
|
||||||
```
|
```
|
||||||
docker run -d --name uwf-e2e-$$ \
|
docker run -d --name uwf-e2e-$$ \
|
||||||
-v "$(pwd):/workspace:ro" \
|
-v $HOME:$HOME \
|
||||||
-e HOME=/root \
|
-e HOME=$HOME \
|
||||||
-e UNCAGED_WORKFLOW_STORAGE_ROOT=/tmp/uwf-e2e-storage \
|
-e UNCAGED_WORKFLOW_STORAGE_ROOT=/tmp/uwf-e2e-storage \
|
||||||
--add-host=host.docker.internal:host-gateway \
|
-w ~/repos/workflow \
|
||||||
-w /workspace \
|
|
||||||
node:22-bookworm \
|
node:22-bookworm \
|
||||||
sleep infinity
|
sleep infinity
|
||||||
```
|
```
|
||||||
NOTE: Run this from the workflow monorepo root directory.
|
2. Inside the container, install bun, install deps, then `bun link` all packages
|
||||||
On macOS Docker Desktop, host.docker.internal is already available;
|
so that `uwf`, `uwf-hermes`, `uwf-builtin` are on PATH (from source):
|
||||||
--add-host ensures it also works on Linux Docker.
|
|
||||||
|
|
||||||
2. Inside the container, copy source to a writable location, install bun, install deps,
|
|
||||||
then `bun link` all packages so that `uwf`, `uwf-hermes`, `uwf-builtin` are on PATH:
|
|
||||||
```
|
```
|
||||||
docker exec uwf-e2e-$$ bash -c '
|
docker exec uwf-e2e-$$ bash -c '
|
||||||
# Copy source to writable location (mount is read-only)
|
|
||||||
cp -r /workspace /root/workflow
|
|
||||||
|
|
||||||
# Install bun
|
# Install bun
|
||||||
curl -fsSL https://bun.sh/install | bash
|
curl -fsSL https://bun.sh/install | bash
|
||||||
export PATH="$HOME/.bun/bin:$PATH"
|
export PATH="$HOME/.bun/bin:$PATH"
|
||||||
@@ -42,7 +30,7 @@ roles:
|
|||||||
mkdir -p $UNCAGED_WORKFLOW_STORAGE_ROOT
|
mkdir -p $UNCAGED_WORKFLOW_STORAGE_ROOT
|
||||||
|
|
||||||
# Install workspace deps
|
# Install workspace deps
|
||||||
cd /root/workflow && bun install
|
cd ~/repos/workflow && bun install --frozen-lockfile
|
||||||
|
|
||||||
# bun link each package that has a bin entry
|
# bun link each package that has a bin entry
|
||||||
cd packages/cli-workflow && bun link && cd ../..
|
cd packages/cli-workflow && bun link && cd ../..
|
||||||
@@ -56,15 +44,11 @@ roles:
|
|||||||
docker exec uwf-e2e-$$ bash -c 'export PATH="$HOME/.bun/bin:$PATH" && uwf-hermes --help'
|
docker exec uwf-e2e-$$ bash -c 'export PATH="$HOME/.bun/bin:$PATH" && uwf-hermes --help'
|
||||||
docker exec uwf-e2e-$$ bash -c 'export PATH="$HOME/.bun/bin:$PATH" && uwf-builtin --help'
|
docker exec uwf-e2e-$$ bash -c 'export PATH="$HOME/.bun/bin:$PATH" && uwf-builtin --help'
|
||||||
```
|
```
|
||||||
4. Copy host uwf config into the container's isolated storage.
|
4. Copy host config if it exists:
|
||||||
The host config contains provider credentials and model settings needed for LLM calls.
|
|
||||||
Also rewrite any localhost URLs to host.docker.internal so the container can reach host services.
|
|
||||||
```
|
```
|
||||||
docker cp ~/.uncaged/workflow/config.yaml uwf-e2e-$$:/tmp/uwf-e2e-storage/config.yaml 2>/dev/null || true
|
|
||||||
docker exec uwf-e2e-$$ bash -c '
|
docker exec uwf-e2e-$$ bash -c '
|
||||||
if [ -f $UNCAGED_WORKFLOW_STORAGE_ROOT/config.yaml ]; then
|
if [ -f $HOME/.uncaged/workflow/config.yaml ]; then
|
||||||
sed -i "s|localhost|host.docker.internal|g; s|127\.0\.0\.1|host.docker.internal|g" \
|
cp $HOME/.uncaged/workflow/config.yaml $UNCAGED_WORKFLOW_STORAGE_ROOT/config.yaml
|
||||||
$UNCAGED_WORKFLOW_STORAGE_ROOT/config.yaml
|
|
||||||
fi
|
fi
|
||||||
'
|
'
|
||||||
```
|
```
|
||||||
@@ -103,7 +87,7 @@ roles:
|
|||||||
3. `uwf config get models.test.name` — verify it returns "test-model"
|
3. `uwf config get models.test.name` — verify it returns "test-model"
|
||||||
|
|
||||||
Workflow registration tests:
|
Workflow registration tests:
|
||||||
4. `uwf workflow add /root/workflow/examples/debate.yaml` — register a workflow (use debate.yaml as it has no $SUSPEND dependency)
|
4. `uwf workflow add ~/repos/workflow/examples/solve-issue.yaml` — register workflow
|
||||||
5. Verify the output contains a hash
|
5. Verify the output contains a hash
|
||||||
6. `uwf workflow list` — verify non-empty array
|
6. `uwf workflow list` — verify non-empty array
|
||||||
7. Capture the workflow name from the list
|
7. Capture the workflow name from the list
|
||||||
@@ -213,7 +197,7 @@ roles:
|
|||||||
Cancel:
|
Cancel:
|
||||||
1. Start a second thread: `uwf thread start <workflowName> -p 'E2E cancel test'`
|
1. Start a second thread: `uwf thread start <workflowName> -p 'E2E cancel test'`
|
||||||
2. Cancel it: `uwf thread cancel <secondThreadId>`
|
2. Cancel it: `uwf thread cancel <secondThreadId>`
|
||||||
3. Verify it appears in cancelled list: `uwf thread list --status cancelled`
|
3. Verify it appears in completed list: `uwf thread list --status completed`
|
||||||
|
|
||||||
Fork:
|
Fork:
|
||||||
4. Fork from the first thread's last step: `uwf step fork <lastStepHash>`
|
4. Fork from the first thread's last step: `uwf step fork <lastStepHash>`
|
||||||
|
|||||||
+21
-69
@@ -23,12 +23,6 @@ roles:
|
|||||||
1. Store it via `uwf cas put-text "<markdown content>"` and capture the returned hash
|
1. Store it via `uwf cas put-text "<markdown content>"` and capture the returned hash
|
||||||
2. Put the hash in frontmatter.plan (required when $status=ready)
|
2. Put the hash in frontmatter.plan (required when $status=ready)
|
||||||
3. Set repoPath to the absolute path of the repository root
|
3. Set repoPath to the absolute path of the repository root
|
||||||
|
|
||||||
IMPORTANT: Extract the repo remote (owner/repo) from git:
|
|
||||||
```bash
|
|
||||||
git remote get-url origin | sed 's|.*[:/]\([^/]*/[^.]*\).*|\1|'
|
|
||||||
```
|
|
||||||
Store the result as repoRemote in your frontmatter output so downstream roles can use it for tea/API calls.
|
|
||||||
output: "Output a brief summary of the test spec. Set $status to ready (with plan hash and repoPath) or insufficient_info."
|
output: "Output a brief summary of the test spec. Set $status to ready (with plan hash and repoPath) or insufficient_info."
|
||||||
frontmatter:
|
frontmatter:
|
||||||
oneOf:
|
oneOf:
|
||||||
@@ -36,12 +30,10 @@ roles:
|
|||||||
$status: { const: "ready" }
|
$status: { const: "ready" }
|
||||||
plan: { type: string }
|
plan: { type: string }
|
||||||
repoPath: { type: string }
|
repoPath: { type: string }
|
||||||
repoRemote: { type: string }
|
required: [$status, plan, repoPath]
|
||||||
required: [$status, plan, repoPath, repoRemote]
|
|
||||||
- properties:
|
- properties:
|
||||||
$status: { const: "insufficient_info" }
|
$status: { const: "insufficient_info" }
|
||||||
reason: { type: string }
|
required: [$status]
|
||||||
required: [$status, reason]
|
|
||||||
developer:
|
developer:
|
||||||
description: "TDD implementation per test spec"
|
description: "TDD implementation per test spec"
|
||||||
goal: "You are a developer agent. You implement code changes following TDD — write tests first, then implementation."
|
goal: "You are a developer agent. You implement code changes following TDD — write tests first, then implementation."
|
||||||
@@ -69,17 +61,6 @@ roles:
|
|||||||
9. Implement the code to make tests pass
|
9. Implement the code to make tests pass
|
||||||
10. Ensure `bun run build` passes with no errors
|
10. Ensure `bun run build` passes with no errors
|
||||||
11. Run `bun test` to verify all tests pass
|
11. Run `bun test` to verify all tests pass
|
||||||
- If tests fail on first run:
|
|
||||||
* Read the test output carefully for missing imports or setup issues
|
|
||||||
* Check if you're running tests from the correct working directory (package root vs workspace root)
|
|
||||||
* Fix the immediate issue and rerun ONCE
|
|
||||||
* If tests still fail after 2 attempts: check the test spec for ambiguities
|
|
||||||
* If stuck after 3 test cycles: set $status=failed with detailed error report rather than continuing blind retries
|
|
||||||
12. MANDATORY VERIFICATION before reporting done:
|
|
||||||
- Run `git branch --show-current` and confirm branch name matches expected
|
|
||||||
- Run `git status` and verify changed files exist
|
|
||||||
- Run `ls -la <key-implementation-files>` to verify they exist on disk
|
|
||||||
- If ANY verification fails: retry the implementation, do NOT report done
|
|
||||||
|
|
||||||
If you cannot complete the implementation (e.g. the issue is too complex, blocked by external factors,
|
If you cannot complete the implementation (e.g. the issue is too complex, blocked by external factors,
|
||||||
or repeated attempts fail), set $status=failed with a reason.
|
or repeated attempts fail), set $status=failed with a reason.
|
||||||
@@ -90,7 +71,6 @@ roles:
|
|||||||
$status: { const: "done" }
|
$status: { const: "done" }
|
||||||
branch: { type: string }
|
branch: { type: string }
|
||||||
worktree: { type: string }
|
worktree: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
required: [$status, branch, worktree]
|
required: [$status, branch, worktree]
|
||||||
- properties:
|
- properties:
|
||||||
$status: { const: "failed" }
|
$status: { const: "failed" }
|
||||||
@@ -105,12 +85,7 @@ roles:
|
|||||||
procedure: |
|
procedure: |
|
||||||
The worktree path is provided in your task prompt. cd into it first.
|
The worktree path is provided in your task prompt. cd into it first.
|
||||||
|
|
||||||
CRITICAL: You MUST execute every verification command below. Do NOT report results without running the actual commands. Do NOT rely on prior context or assumptions.
|
Before reviewing, verify the git branch:
|
||||||
|
|
||||||
Before reviewing, verify the worktree and branch exist:
|
|
||||||
0. Run `cd <worktree-path> && pwd` to confirm the path is accessible
|
|
||||||
- If the cd fails: the worktree truly doesn't exist, reject with that reason
|
|
||||||
- If the cd succeeds: proceed with step 1 below
|
|
||||||
1. Run `git branch --show-current` — confirm the branch name references the issue number being worked on
|
1. Run `git branch --show-current` — confirm the branch name references the issue number being worked on
|
||||||
2. If the branch doesn't correspond to the issue, flag it in your output and reject
|
2. If the branch doesn't correspond to the issue, flag it in your output and reject
|
||||||
|
|
||||||
@@ -134,13 +109,11 @@ roles:
|
|||||||
$status: { const: "approved" }
|
$status: { const: "approved" }
|
||||||
branch: { type: string }
|
branch: { type: string }
|
||||||
worktree: { type: string }
|
worktree: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
required: [$status, branch, worktree]
|
required: [$status, branch, worktree]
|
||||||
- properties:
|
- properties:
|
||||||
$status: { const: "rejected" }
|
$status: { const: "rejected" }
|
||||||
comments: { type: string }
|
comments: { type: string }
|
||||||
worktree: { type: string }
|
worktree: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
required: [$status, comments, worktree]
|
required: [$status, comments, worktree]
|
||||||
tester:
|
tester:
|
||||||
description: "Functional correctness verification"
|
description: "Functional correctness verification"
|
||||||
@@ -164,48 +137,33 @@ roles:
|
|||||||
$status: { const: "passed" }
|
$status: { const: "passed" }
|
||||||
branch: { type: string }
|
branch: { type: string }
|
||||||
worktree: { type: string }
|
worktree: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
required: [$status, branch, worktree]
|
required: [$status, branch, worktree]
|
||||||
- properties:
|
- properties:
|
||||||
$status: { const: "fix_code" }
|
$status: { const: "fix_code" }
|
||||||
report: { type: string }
|
report: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
worktree: { type: string }
|
|
||||||
branch: { type: string }
|
|
||||||
required: [$status, report]
|
required: [$status, report]
|
||||||
- properties:
|
- properties:
|
||||||
$status: { const: "fix_spec" }
|
$status: { const: "fix_spec" }
|
||||||
report: { type: string }
|
report: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
worktree: { type: string }
|
|
||||||
branch: { type: string }
|
|
||||||
required: [$status, report]
|
required: [$status, report]
|
||||||
committer:
|
committer:
|
||||||
description: "Commits and creates PR"
|
description: "Commits and creates PR"
|
||||||
goal: "You are a committer agent. You create a clean commit and push a PR linking the original issue."
|
goal: "You are a committer agent. You create a clean commit and push a PR linking the original issue."
|
||||||
capabilities: []
|
capabilities: []
|
||||||
procedure: |
|
procedure: |
|
||||||
The worktree path, branch name, and repo remote (owner/repo) are provided in your task prompt.
|
The worktree path, branch name, and repo info are provided in your task prompt.
|
||||||
cd into the worktree first.
|
cd into the worktree first.
|
||||||
|
|
||||||
Note: You inherit the developer's worktree and branch. Do NOT create a new branch.
|
Note: You inherit the developer's worktree and branch. Do NOT create a new branch.
|
||||||
1. Check `git status` — if working tree is clean and branch is ahead of origin, skip to step 3 (push).
|
1. Stage all changes: `git add -A`
|
||||||
2. If there are unstaged/uncommitted changes: `git add -A` then `git commit -m "type: description\n\nFixes #N"`
|
2. Commit with a descriptive message referencing the issue: `git commit -m "type: description\n\nFixes #N"`
|
||||||
3. Push the branch: `git push -u origin <branch-name>`
|
3. Push the branch: `git push -u origin <branch-name>`
|
||||||
4. **Verify push succeeded** — run `git ls-remote origin <branch-name>` and confirm it prints a commit hash.
|
- If push hook fails: capture the error log in your output, mark hook_failed
|
||||||
- If no output or push failed: capture the error, mark hook_failed
|
4. On push success: create a PR via `tea pr create --repo <owner/repo> --title "..." --description "..."`
|
||||||
5. Create a PR using the Gitea API (do NOT use `tea pr create` — it fails in worktrees):
|
- Extract owner/repo from: `git remote get-url origin | sed 's/.*[:/]\([^/]*\/[^.]*\).*/\1/'`
|
||||||
```bash
|
- PR description must include: What / Why / Changes / Ref sections, with `Fixes #N` in Ref
|
||||||
GITEA_TOKEN=$(cfg get GITEA_TOKEN)
|
- On tea failure: capture stderr/stdout, include PR details for manual creation, mark hook_failed
|
||||||
curl -s -X POST -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
|
5. After PR creation, clean up the worktree:
|
||||||
"https://git.shazhou.work/api/v1/repos/<owner>/<repo>/pulls" \
|
|
||||||
-d '{"title":"...","body":"...","head":"<branch>","base":"main"}'
|
|
||||||
```
|
|
||||||
- The repo remote (owner/repo format, e.g. "uncaged/workflow") is given in your task prompt — use it directly.
|
|
||||||
- PR body must include: What / Why / Changes / Ref sections, with `Fixes #N` in Ref
|
|
||||||
6. **Verify PR was created** — parse the curl response JSON: it must contain a `"number"` field. Print the PR URL.
|
|
||||||
- If curl returns an error or no number field: capture the response, mark hook_failed
|
|
||||||
7. After PR creation, clean up the worktree:
|
|
||||||
- cd to the repo root (parent of .worktrees)
|
- cd to the repo root (parent of .worktrees)
|
||||||
- `git worktree remove <worktree-path>`
|
- `git worktree remove <worktree-path>`
|
||||||
output: "Include PR URL on success or error log on failure. Set $status to committed (with prUrl) or hook_failed (with error)."
|
output: "Include PR URL on success or error log on failure. Set $status to committed (with prUrl) or hook_failed (with error)."
|
||||||
@@ -214,33 +172,27 @@ roles:
|
|||||||
- properties:
|
- properties:
|
||||||
$status: { const: "committed" }
|
$status: { const: "committed" }
|
||||||
prUrl: { type: string }
|
prUrl: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
worktree: { type: string }
|
|
||||||
branch: { type: string }
|
|
||||||
required: [$status, prUrl]
|
required: [$status, prUrl]
|
||||||
- properties:
|
- properties:
|
||||||
$status: { const: "hook_failed" }
|
$status: { const: "hook_failed" }
|
||||||
error: { type: string }
|
error: { type: string }
|
||||||
repoRemote: { type: string }
|
|
||||||
worktree: { type: string }
|
|
||||||
branch: { type: string }
|
|
||||||
required: [$status, error]
|
required: [$status, error]
|
||||||
graph:
|
graph:
|
||||||
$START:
|
$START:
|
||||||
_: { role: "planner", prompt: "Analyze the issue and produce an implementation plan." }
|
_: { role: "planner", prompt: "Analyze the issue and produce an implementation plan." }
|
||||||
planner:
|
planner:
|
||||||
insufficient_info: { role: "$SUSPEND", prompt: "信息不足,需要补充:{{{reason}}}" }
|
insufficient_info: { role: "$END", prompt: "Insufficient information to proceed; end the workflow." }
|
||||||
ready: { role: "developer", prompt: "Implement the TDD test spec (CAS hash: {{{plan}}}) in repo {{{repoPath}}}. Repo remote: {{{repoRemote}}}." }
|
ready: { role: "developer", prompt: "Implement the TDD test spec (CAS hash: {{{plan}}}) in repo {{{repoPath}}}." }
|
||||||
developer:
|
developer:
|
||||||
done: { role: "reviewer", prompt: "Review branch {{{branch}}} at {{{worktree}}} for code standards compliance. Repo remote: {{{repoRemote}}}." }
|
done: { role: "reviewer", prompt: "Review branch {{{branch}}} at {{{worktree}}} for code standards compliance." }
|
||||||
failed: { role: "$END", prompt: "Developer failed: {{{reason}}}. Ending workflow." }
|
failed: { role: "$END", prompt: "Developer failed: {{{reason}}}. Ending workflow." }
|
||||||
reviewer:
|
reviewer:
|
||||||
rejected: { role: "developer", prompt: "Reviewer rejected: {{{comments}}}. Fix the issues in repo {{{worktree}}}. Repo remote: {{{repoRemote}}}." }
|
rejected: { role: "developer", prompt: "Reviewer rejected: {{{comments}}}. Fix the issues in repo {{{worktree}}}." }
|
||||||
approved: { role: "tester", prompt: "Review passed. Run tests on branch {{{branch}}} at {{{worktree}}}. Repo remote: {{{repoRemote}}}." }
|
approved: { role: "tester", prompt: "Review passed. Run tests on branch {{{branch}}} at {{{worktree}}}." }
|
||||||
tester:
|
tester:
|
||||||
fix_code: { role: "developer", prompt: "Tests found code issues: {{{report}}}. Fix and re-submit. Worktree: {{{worktree}}}. Repo remote: {{{repoRemote}}}." }
|
fix_code: { role: "developer", prompt: "Tests found code issues: {{{report}}}. Fix and re-submit." }
|
||||||
fix_spec: { role: "planner", prompt: "Tests found spec issues: {{{report}}}. Revise the test spec. Repo remote: {{{repoRemote}}}." }
|
fix_spec: { role: "planner", prompt: "Tests found spec issues: {{{report}}}. Revise the test spec." }
|
||||||
passed: { role: "committer", prompt: "All tests passed. Commit and push branch {{{branch}}} from {{{worktree}}}. Repo remote (owner/repo): {{{repoRemote}}}." }
|
passed: { role: "committer", prompt: "All tests passed. Commit and push branch {{{branch}}} from {{{worktree}}}." }
|
||||||
committer:
|
committer:
|
||||||
hook_failed: { role: "developer", prompt: "Push hook failed: {{{error}}}. Fix and re-submit. Worktree: {{{worktree}}}. Repo remote: {{{repoRemote}}}." }
|
hook_failed: { role: "developer", prompt: "Push hook failed: {{{error}}}. Fix and re-submit." }
|
||||||
committed: { role: "$END", prompt: "PR created: {{{prUrl}}}. Workflow complete." }
|
committed: { role: "$END", prompt: "PR created: {{{prUrl}}}. Workflow complete." }
|
||||||
|
|||||||
-183
@@ -1,183 +0,0 @@
|
|||||||
# UWF Bootstrap Guide
|
|
||||||
|
|
||||||
This guide helps any AI agent set up `uwf` (Uncaged Workflow) from scratch — or self-check and upgrade an existing installation.
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
- **bun** — `uwf` is built with bun. Install: `curl -fsSL https://bun.sh/install | bash`
|
|
||||||
- **Network access** — to install npm packages
|
|
||||||
|
|
||||||
> **Already have uwf?** Jump to [Self-Check & Upgrade](#self-check--upgrade).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Fresh Install
|
|
||||||
|
|
||||||
### 1. Install uwf CLI
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bun install -g @uncaged/cli-workflow
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ **Check:** `uwf --version` prints a version number (e.g. `0.5.1`).
|
|
||||||
|
|
||||||
### 2. Install Agent Adapter
|
|
||||||
|
|
||||||
Install the adapter that matches your agent runtime. Pick **one**:
|
|
||||||
|
|
||||||
| Agent | Package | Binary |
|
|
||||||
|-------|---------|--------|
|
|
||||||
| Hermes | `@uncaged/workflow-agent-hermes` | `uwf-hermes` |
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Example: Hermes agent
|
|
||||||
bun install -g @uncaged/workflow-agent-hermes
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ **Check:** `uwf-hermes --version` prints a version number.
|
|
||||||
|
|
||||||
### 3. Setup
|
|
||||||
|
|
||||||
Run the interactive wizard:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uwf setup
|
|
||||||
```
|
|
||||||
|
|
||||||
Or configure non-interactively:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uwf setup \
|
|
||||||
--provider <name> \
|
|
||||||
--base-url <url> \
|
|
||||||
--api-key <key> \
|
|
||||||
--model <model-name> \
|
|
||||||
--agent hermes
|
|
||||||
```
|
|
||||||
|
|
||||||
This creates `~/.uncaged/workflow/config.yaml` with your provider, model, and default agent.
|
|
||||||
|
|
||||||
#### Config Structure
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
providers:
|
|
||||||
my-provider:
|
|
||||||
baseUrl: https://api.example.com/v1
|
|
||||||
apiKey: sk-xxx
|
|
||||||
models:
|
|
||||||
default:
|
|
||||||
provider: my-provider
|
|
||||||
name: my-model
|
|
||||||
agents:
|
|
||||||
hermes:
|
|
||||||
command: uwf-hermes
|
|
||||||
args: []
|
|
||||||
defaultAgent: hermes
|
|
||||||
defaultModel: default
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ **Check:** `cat ~/.uncaged/workflow/config.yaml` shows valid provider, model, and agent config.
|
|
||||||
|
|
||||||
### 4. Verify Installation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uwf workflow list # should return empty array or existing workflows
|
|
||||||
uwf skill user # prints usage guide
|
|
||||||
uwf skill author # prints workflow authoring guide
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ **Check:** All three commands run without errors.
|
|
||||||
|
|
||||||
### 5. Add the uwf Skill
|
|
||||||
|
|
||||||
```bash
|
|
||||||
mkdir -p ~/.hermes/skills/devops/uwf
|
|
||||||
uwf skill bootstrap > ~/.hermes/skills/devops/uwf/SKILL.md
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ **Check:** `cat ~/.hermes/skills/devops/uwf/SKILL.md` shows the skill content with triggers `uwf`, `workflow`, `工作流`.
|
|
||||||
|
|
||||||
### 6. Smoke Test
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Register an example workflow
|
|
||||||
uwf workflow add examples/analyze-topic.yaml
|
|
||||||
|
|
||||||
# Start a thread
|
|
||||||
uwf thread start analyze-topic -p "Analyze the concept of technical debt"
|
|
||||||
|
|
||||||
# Execute it (one moderator → agent → extract cycle)
|
|
||||||
uwf thread exec <thread-id>
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ **Check:** Thread reaches `completed` status. Verify with `uwf thread list`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Self-Check & Upgrade
|
|
||||||
|
|
||||||
Already have uwf installed? Run through this checklist to verify and upgrade.
|
|
||||||
|
|
||||||
### Version Check
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uwf --version
|
|
||||||
uwf-hermes --version # or your agent adapter
|
|
||||||
```
|
|
||||||
|
|
||||||
Compare with latest published versions:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bun pm ls -g | grep -E "cli-workflow|workflow-agent"
|
|
||||||
npm info @uncaged/cli-workflow version
|
|
||||||
npm info @uncaged/workflow-agent-hermes version
|
|
||||||
```
|
|
||||||
|
|
||||||
If local version < published version, upgrade:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bun install -g @uncaged/cli-workflow@latest
|
|
||||||
bun install -g @uncaged/workflow-agent-hermes@latest
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ **Check:** `uwf --version` matches `npm info @uncaged/cli-workflow version`.
|
|
||||||
|
|
||||||
### Config Check
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cat ~/.uncaged/workflow/config.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
Verify:
|
|
||||||
- [ ] `providers` has at least one entry with valid `baseUrl` and `apiKey`
|
|
||||||
- [ ] `models.default` references an existing provider
|
|
||||||
- [ ] `agents` has your adapter configured
|
|
||||||
- [ ] `defaultAgent` and `defaultModel` are set
|
|
||||||
|
|
||||||
### Skill Check
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cat ~/.hermes/skills/devops/uwf/SKILL.md
|
|
||||||
```
|
|
||||||
|
|
||||||
Verify the skill is up to date:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uwf skill bootstrap | diff - ~/.hermes/skills/devops/uwf/SKILL.md
|
|
||||||
```
|
|
||||||
|
|
||||||
If `diff` produces any output, the local skill is outdated. Update:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uwf skill bootstrap > ~/.hermes/skills/devops/uwf/SKILL.md
|
|
||||||
```
|
|
||||||
|
|
||||||
### Functional Check
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uwf workflow list # should not error
|
|
||||||
uwf skill user # should print usage guide
|
|
||||||
uwf skill author # should print authoring guide
|
|
||||||
```
|
|
||||||
|
|
||||||
✅ All green? You're good to go.
|
|
||||||
@@ -13,7 +13,7 @@ This monorepo implements a stateless workflow engine driven by a single-step CLI
|
|||||||
| **Role** | A named actor within a workflow. Each role has a system prompt and a JSON Schema `outputSchema`. |
|
| **Role** | A named actor within a workflow. Each role has a system prompt and a JSON Schema `outputSchema`. |
|
||||||
| **Moderator** | Status-based graph evaluator — determines the next role (or `$END`) with zero LLM cost. |
|
| **Moderator** | Status-based graph evaluator — determines the next role (or `$END`) with zero LLM cost. |
|
||||||
| **Agent** | An external CLI command (`uwf-hermes`, etc.) spawned by `uwf thread step`. Produces frontmatter markdown output. |
|
| **Agent** | An external CLI command (`uwf-hermes`, etc.) spawned by `uwf thread step`. Produces frontmatter markdown output. |
|
||||||
| **CAS** | Content-Addressed Storage via `@ocas/core` — all workflow definitions, thread nodes, and outputs are immutable CAS nodes. |
|
| **CAS** | Content-Addressed Storage via `@uncaged/json-cas` — all workflow definitions, thread nodes, and outputs are immutable CAS nodes. |
|
||||||
| **Registry** | `~/.uncaged/workflow/registry.yaml` — maps workflow names to current CAS hashes. |
|
| **Registry** | `~/.uncaged/workflow/registry.yaml` — maps workflow names to current CAS hashes. |
|
||||||
|
|
||||||
### Monorepo Structure
|
### Monorepo Structure
|
||||||
@@ -35,7 +35,7 @@ workflow/
|
|||||||
|
|
||||||
- Dependency layers: `workflow-protocol` → `workflow-util` → `workflow-util-agent` → `workflow-agent-hermes` / `cli-workflow`
|
- Dependency layers: `workflow-protocol` → `workflow-util` → `workflow-util-agent` → `workflow-agent-hermes` / `cli-workflow`
|
||||||
- Packages use `workspace:^` protocol (resolves to `^x.y.z` on publish)
|
- Packages use `workspace:^` protocol (resolves to `^x.y.z` on publish)
|
||||||
- External CAS: `@ocas/core` (store API, hashing, schema validation) + `@ocas/fs` (filesystem backend)
|
- External CAS: `@uncaged/json-cas` (store API, hashing, schema validation) + `@uncaged/json-cas-fs` (filesystem backend)
|
||||||
|
|
||||||
## Language & Paradigm
|
## Language & Paradigm
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ node scripts/publish-all.mjs --dry-run # preview without publishing
|
|||||||
examples/solve-issue.yaml — write a workflow YAML definition
|
examples/solve-issue.yaml — write a workflow YAML definition
|
||||||
│ uwf workflow put
|
│ uwf workflow put
|
||||||
▼
|
▼
|
||||||
~/.uncaged/json-cas/ — Workflow stored as CAS node (unified CAS store)
|
~/.uncaged/workflow/cas/ — Workflow stored as CAS node
|
||||||
~/.uncaged/workflow/registry.yaml — name → hash mapping updated
|
~/.uncaged/workflow/registry.yaml — name → hash mapping updated
|
||||||
│ uwf thread start <name> -p "..."
|
│ uwf thread start <name> -p "..."
|
||||||
▼
|
▼
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ App (uses protocol; not in the runtime engine stack)
|
|||||||
workflow-dashboard Web UI for visual workflow editing
|
workflow-dashboard Web UI for visual workflow editing
|
||||||
```
|
```
|
||||||
|
|
||||||
External CAS: [`@ocas/core`](https://www.npmjs.com/package/@ocas/core) (store API, hashing, schema validation) + `@ocas/fs` (filesystem backend).
|
External CAS: [`@uncaged/json-cas`](https://www.npmjs.com/package/@uncaged/json-cas) (store API, hashing, schema validation) + `@uncaged/json-cas-fs` (filesystem backend).
|
||||||
|
|
||||||
See [docs/architecture.md](docs/architecture.md) for the full design — three-phase engine loop, CAS node types, storage layout, agent CLI protocol, and design decisions.
|
See [docs/architecture.md](docs/architecture.md) for the full design — three-phase engine loop, CAS node types, storage layout, agent CLI protocol, and design decisions.
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://biomejs.dev/schemas/2.4.14/schema.json",
|
"$schema": "https://biomejs.dev/schemas/2.4.15/schema.json",
|
||||||
"files": {
|
"files": {
|
||||||
"includes": [
|
"includes": [
|
||||||
"**",
|
"**",
|
||||||
@@ -39,8 +39,7 @@
|
|||||||
"linter": {
|
"linter": {
|
||||||
"rules": {
|
"rules": {
|
||||||
"suspicious": {
|
"suspicious": {
|
||||||
"noExplicitAny": "off",
|
"noExplicitAny": "off"
|
||||||
"noConsole": "off"
|
|
||||||
},
|
},
|
||||||
"style": {
|
"style": {
|
||||||
"noNonNullAssertion": "off"
|
"noNonNullAssertion": "off"
|
||||||
|
|||||||
+15
-15
@@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
A stateless workflow engine driven by a single-step CLI. Workflows are YAML definitions stored as CAS nodes; threads are immutable chains of CAS-linked step nodes. No daemon — each `uwf thread step` invocation runs one moderator→agent→extract cycle and exits.
|
A stateless workflow engine driven by a single-step CLI. Workflows are YAML definitions stored as CAS nodes; threads are immutable chains of CAS-linked step nodes. No daemon — each `uwf thread step` invocation runs one moderator→agent→extract cycle and exits.
|
||||||
|
|
||||||
The implementation lives in **5** active packages under `packages/`, plus two external CAS packages (`@ocas/core`, `@ocas/fs`). Legacy packages reside in `legacy-packages/` and are not part of the active stack.
|
The implementation lives in **5** active packages under `packages/`, plus two external CAS packages (`@uncaged/json-cas`, `@uncaged/json-cas-fs`). Legacy packages reside in `legacy-packages/` and are not part of the active stack.
|
||||||
|
|
||||||
## Package map
|
## Package map
|
||||||
|
|
||||||
| Layer | Package | One-line role |
|
| Layer | Package | One-line role |
|
||||||
|-------|---------|---------------|
|
|-------|---------|---------------|
|
||||||
| Contract | `@uncaged/workflow-protocol` → `workflow-protocol` | Shared TypeScript types (`WorkflowPayload`, `StepNodePayload`, `ModeratorContext`, `WorkflowConfig`, etc.). No runtime deps beyond `@ocas/fs`. |
|
| Contract | `@uncaged/workflow-protocol` → `workflow-protocol` | Shared TypeScript types (`WorkflowPayload`, `StepNodePayload`, `ModeratorContext`, `WorkflowConfig`, etc.). No runtime deps beyond `@uncaged/json-cas-fs`. |
|
||||||
| Shared infra | `@uncaged/workflow-util` → `workflow-util` | Crockford Base32, ULID generation, `createLogger`, frontmatter parsing/validation. |
|
| Shared infra | `@uncaged/workflow-util` → `workflow-util` | Crockford Base32, ULID generation, `createLogger`, frontmatter parsing/validation. |
|
||||||
| Agent framework | `@uncaged/workflow-util-agent` → `workflow-util-agent` | `createAgent` entrypoint factory, context builder, frontmatter fast-path extractor, LLM extract fallback, output format instruction builder. |
|
| Agent framework | `@uncaged/workflow-util-agent` → `workflow-util-agent` | `createAgent` entrypoint factory, context builder, frontmatter fast-path extractor, LLM extract fallback, output format instruction builder. |
|
||||||
| Agent: Hermes | `@uncaged/workflow-agent-hermes` → `workflow-agent-hermes` | `uwf-hermes` CLI binary — spawns `hermes chat`, pipes prompt, captures session detail. |
|
| Agent: Hermes | `@uncaged/workflow-agent-hermes` → `workflow-agent-hermes` | `uwf-hermes` CLI binary — spawns `hermes chat`, pipes prompt, captures session detail. |
|
||||||
@@ -24,8 +24,8 @@ The implementation lives in **5** active packages under `packages/`, plus two ex
|
|||||||
|
|
||||||
| Package | Role |
|
| Package | Role |
|
||||||
|---------|------|
|
|---------|------|
|
||||||
| `@ocas/core` | Content-addressed store API, XXH64 hashing, JSON Schema registration and validation. |
|
| `@uncaged/json-cas` | Content-addressed store API, XXH64 hashing, JSON Schema registration and validation. |
|
||||||
| `@ocas/fs` | Filesystem backend for `ocas`. |
|
| `@uncaged/json-cas-fs` | Filesystem backend for `json-cas`. |
|
||||||
| `mustache` | Template renderer for edge prompts (used by `cli-workflow` moderator). |
|
| `mustache` | Template renderer for edge prompts (used by `cli-workflow` moderator). |
|
||||||
| `commander` | CLI argument parsing (used by `cli-workflow`). |
|
| `commander` | CLI argument parsing (used by `cli-workflow`). |
|
||||||
| `dotenv` | Loads `.env` files for API keys. |
|
| `dotenv` | Loads `.env` files for API keys. |
|
||||||
@@ -36,8 +36,8 @@ The implementation lives in **5** active packages under `packages/`, plus two ex
|
|||||||
```mermaid
|
```mermaid
|
||||||
flowchart BT
|
flowchart BT
|
||||||
subgraph External
|
subgraph External
|
||||||
jcas["@ocas/core"]
|
jcas["@uncaged/json-cas"]
|
||||||
jcasfs["@ocas/fs"]
|
jcasfs["@uncaged/json-cas-fs"]
|
||||||
end
|
end
|
||||||
subgraph L0["Layer 0 — contract"]
|
subgraph L0["Layer 0 — contract"]
|
||||||
protocol["@uncaged/workflow-protocol"]
|
protocol["@uncaged/workflow-protocol"]
|
||||||
@@ -146,7 +146,7 @@ Key properties:
|
|||||||
- **`roles`** — inline role definitions; each `meta` is a JSON Schema (stored as its own CAS node on registration)
|
- **`roles`** — inline role definitions; each `meta` is a JSON Schema (stored as its own CAS node on registration)
|
||||||
- **`graph`** — `Record<Role | "$START", Record<Status, Target>>` — status-based routing; each role maps statuses to targets
|
- **`graph`** — `Record<Role | "$START", Record<Status, Target>>` — status-based routing; each role maps statuses to targets
|
||||||
- **No agent binding** — agent selection is a deployment concern, configured in `config.yaml`
|
- **No agent binding** — agent selection is a deployment concern, configured in `config.yaml`
|
||||||
- **No Zod** — all schemas are JSON Schema, validated through `@ocas/core`
|
- **No Zod** — all schemas are JSON Schema, validated through `@uncaged/json-cas`
|
||||||
|
|
||||||
## Three-phase engine loop
|
## Three-phase engine loop
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ Structured output extraction uses a two-layer strategy (`workflow-util-agent`):
|
|||||||
2. Validate required fields (`validateFrontmatter`)
|
2. Validate required fields (`validateFrontmatter`)
|
||||||
3. Build a candidate object from frontmatter fields (`status`, `next`, `confidence`, `artifacts`, `scope`)
|
3. Build a candidate object from frontmatter fields (`status`, `next`, `confidence`, `artifacts`, `scope`)
|
||||||
4. `store.put()` the candidate against the role's `meta` schema
|
4. `store.put()` the candidate against the role's `meta` schema
|
||||||
5. Validate with `ocas` schema validation
|
5. Validate with `json-cas` schema validation
|
||||||
6. If valid → return `outputHash` (zero LLM cost)
|
6. If valid → return `outputHash` (zero LLM cost)
|
||||||
|
|
||||||
### Layer 2: LLM extract fallback (`extract.ts`)
|
### Layer 2: LLM extract fallback (`extract.ts`)
|
||||||
@@ -302,7 +302,7 @@ payload:
|
|||||||
capabilities: [planning, issue-analysis]
|
capabilities: [planning, issue-analysis]
|
||||||
procedure: "Analyze the issue and create a plan."
|
procedure: "Analyze the issue and create a plan."
|
||||||
output: "Output the plan summary."
|
output: "Output the plan summary."
|
||||||
meta: "5GWKR8TN1V3JA" # ocas_ref → JSON Schema node
|
meta: "5GWKR8TN1V3JA" # cas_ref → JSON Schema node
|
||||||
conditions:
|
conditions:
|
||||||
notApproved:
|
notApproved:
|
||||||
description: "Reviewer rejected"
|
description: "Reviewer rejected"
|
||||||
@@ -318,7 +318,7 @@ payload:
|
|||||||
```yaml
|
```yaml
|
||||||
type: <start-node-schema-hash>
|
type: <start-node-schema-hash>
|
||||||
payload:
|
payload:
|
||||||
workflow: "4KNM2PXR3B1QW" # ocas_ref → Workflow
|
workflow: "4KNM2PXR3B1QW" # cas_ref → Workflow
|
||||||
prompt: "Fix the login bug..."
|
prompt: "Fix the login bug..."
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -327,11 +327,11 @@ payload:
|
|||||||
```yaml
|
```yaml
|
||||||
type: <step-node-schema-hash>
|
type: <step-node-schema-hash>
|
||||||
payload:
|
payload:
|
||||||
start: "4TNVW8KR2B3MA" # ocas_ref → StartNode
|
start: "4TNVW8KR2B3MA" # cas_ref → StartNode
|
||||||
prev: "2MXBG6PN4A8JR" # ocas_ref → previous StepNode (null for first step)
|
prev: "2MXBG6PN4A8JR" # cas_ref → previous StepNode (null for first step)
|
||||||
role: "developer"
|
role: "developer"
|
||||||
output: "9KRVW3TN5F1QA" # ocas_ref → structured output (validated against meta schema)
|
output: "9KRVW3TN5F1QA" # cas_ref → structured output (validated against meta schema)
|
||||||
detail: "7BQST3VW9F2MA" # ocas_ref → execution detail (raw turns, session data)
|
detail: "7BQST3VW9F2MA" # cas_ref → execution detail (raw turns, session data)
|
||||||
agent: "uwf-hermes" # agent command used (plain string)
|
agent: "uwf-hermes" # agent command used (plain string)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -484,7 +484,7 @@ Binary: `uwf`
|
|||||||
| **Frontmatter markdown output** | Agents produce structured meta (YAML frontmatter) alongside free-form content (markdown body). Enables zero-cost extraction when frontmatter is well-formed. |
|
| **Frontmatter markdown output** | Agents produce structured meta (YAML frontmatter) alongside free-form content (markdown body). Enables zero-cost extraction when frontmatter is well-formed. |
|
||||||
| **Two-layer extract** | Fast path avoids LLM calls when agents follow the format; LLM fallback handles messy output gracefully. |
|
| **Two-layer extract** | Fast path avoids LLM calls when agents follow the format; LLM fallback handles messy output gracefully. |
|
||||||
| **Prompt injection for format** | Output format instruction prepended to system prompt ensures agents produce parseable output without per-agent configuration. |
|
| **Prompt injection for format** | Output format instruction prepended to system prompt ensures agents produce parseable output without per-agent configuration. |
|
||||||
| **JSON Schema (not Zod)** | Schemas are CAS-native data — storable, hashable, validatable through `ocas`. No code generation, no runtime library dependency. |
|
| **JSON Schema (not Zod)** | Schemas are CAS-native data — storable, hashable, validatable through `json-cas`. No code generation, no runtime library dependency. |
|
||||||
| **Agent as external command** | Agents are independent CLI binaries (`uwf-hermes`, `uwf-cursor`). Swappable per workflow/role via config. No tight coupling to the engine. |
|
| **Agent as external command** | Agents are independent CLI binaries (`uwf-hermes`, `uwf-cursor`). Swappable per workflow/role via config. No tight coupling to the engine. |
|
||||||
| **No daemon** | Process starts, does one step, exits. Simpler failure model, no connection management. |
|
| **No daemon** | Process starts, does one step, exits. Simpler failure model, no connection management. |
|
||||||
| **Crockford Base32** | Filesystem-safe, case-insensitive, readable, compact. |
|
| **Crockford Base32** | Filesystem-safe, case-insensitive, readable, compact. |
|
||||||
|
|||||||
@@ -630,7 +630,7 @@ flowchart TB
|
|||||||
Spawn -->|"stdout: step hash"| Step
|
Spawn -->|"stdout: step hash"| Step
|
||||||
```
|
```
|
||||||
|
|
||||||
**新包**:`packages/workflow-agent-builtin`,bin `uwf-builtin`,仅依赖 `workflow-util-agent`、`workflow-protocol`、`workflow-util`(可选 `@ocas/core` 写 detail schema)。
|
**新包**:`packages/workflow-agent-builtin`,bin `uwf-builtin`,仅依赖 `workflow-util-agent`、`workflow-protocol`、`workflow-util`(可选 `@uncaged/json-cas` 写 detail schema)。
|
||||||
|
|
||||||
**分层**:
|
**分层**:
|
||||||
|
|
||||||
|
|||||||
+25
-25
@@ -22,7 +22,7 @@ uwf workflow show <workflow-id> # 查看 workflow 定义
|
|||||||
uwf workflow list # 列出已注册 workflows
|
uwf workflow list # 列出已注册 workflows
|
||||||
```
|
```
|
||||||
|
|
||||||
两组对称,各 3-4 个子命令。CAS 操作交给 `ocas` CLI,不在 `uwf` 中重复。
|
两组对称,各 3-4 个子命令。CAS 操作交给 `json-cas` CLI,不在 `uwf` 中重复。
|
||||||
|
|
||||||
### 1.2 `uwf thread start`
|
### 1.2 `uwf thread start`
|
||||||
|
|
||||||
@@ -136,14 +136,14 @@ uwf-hermes <thread-id> <role>
|
|||||||
|
|
||||||
沿用 json-cas 的三层:bootstrap meta-schema → JSON Schema nodes → data nodes。
|
沿用 json-cas 的三层:bootstrap meta-schema → JSON Schema nodes → data nodes。
|
||||||
|
|
||||||
下面所有 CAS 节点都遵循 `{ type: ocas_ref, payload: T, timestamp: number }` 的标准格式。
|
下面所有 CAS 节点都遵循 `{ type: cas_ref, payload: T, timestamp: number }` 的标准格式。
|
||||||
`ocas_ref` 类型的字符串字段在 ocas 中已内置支持,不需要额外的 `$ref` 包装。
|
`cas_ref` 类型的字符串字段在 json-cas 中已内置支持,不需要额外的 `$ref` 包装。
|
||||||
|
|
||||||
### 2.2 数据节点
|
### 2.2 数据节点
|
||||||
|
|
||||||
#### `Workflow`
|
#### `Workflow`
|
||||||
|
|
||||||
Roles 和 moderator 内联在 Workflow 中,只有 meta 独立为 CAS 节点(方便 ocas 校验)。
|
Roles 和 moderator 内联在 Workflow 中,只有 meta 独立为 CAS 节点(方便 json-cas 校验)。
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
type: <workflow-schema-hash>
|
type: <workflow-schema-hash>
|
||||||
@@ -157,21 +157,21 @@ payload:
|
|||||||
capabilities: [planning, issue-analysis]
|
capabilities: [planning, issue-analysis]
|
||||||
procedure: "Analyze the issue and create a plan."
|
procedure: "Analyze the issue and create a plan."
|
||||||
output: "Output the plan summary."
|
output: "Output the plan summary."
|
||||||
meta: "5GWKR8TN1V3JA" # ocas_ref → JSON Schema 节点(ocas 内置)
|
meta: "5GWKR8TN1V3JA" # cas_ref → JSON Schema 节点(json-cas 内置)
|
||||||
developer:
|
developer:
|
||||||
description: "Implements code changes"
|
description: "Implements code changes"
|
||||||
goal: "You are a developer agent..."
|
goal: "You are a developer agent..."
|
||||||
capabilities: [file-edit, shell]
|
capabilities: [file-edit, shell]
|
||||||
procedure: "Implement the plan."
|
procedure: "Implement the plan."
|
||||||
output: "List all files changed."
|
output: "List all files changed."
|
||||||
meta: "8CNWT4KR6D1HV" # ocas_ref → JSON Schema 节点
|
meta: "8CNWT4KR6D1HV" # cas_ref → JSON Schema 节点
|
||||||
reviewer:
|
reviewer:
|
||||||
description: "Reviews code changes"
|
description: "Reviews code changes"
|
||||||
goal: "You are a code reviewer..."
|
goal: "You are a code reviewer..."
|
||||||
capabilities: [code-review]
|
capabilities: [code-review]
|
||||||
procedure: "Review the implementation."
|
procedure: "Review the implementation."
|
||||||
output: "Approve or reject with comments."
|
output: "Approve or reject with comments."
|
||||||
meta: "1VPBG9SM5E7WK" # ocas_ref → JSON Schema 节点
|
meta: "1VPBG9SM5E7WK" # cas_ref → JSON Schema 节点
|
||||||
conditions:
|
conditions:
|
||||||
needsClarification:
|
needsClarification:
|
||||||
description: "Planner requests clarification from user"
|
description: "Planner requests clarification from user"
|
||||||
@@ -198,7 +198,7 @@ payload:
|
|||||||
condition: null
|
condition: null
|
||||||
```
|
```
|
||||||
|
|
||||||
- `roles` — 内联定义,每个 role 的 `meta` 是独立的 ocas_ref(指向 ocas 内置 JSON Schema 节点)
|
- `roles` — 内联定义,每个 role 的 `meta` 是独立的 cas_ref(指向 json-cas 内置 JSON Schema 节点)
|
||||||
- `graph` — `Record<Role | "$START", Record<Status, Target>>`,每个 Target = `{ role, prompt }`
|
- `graph` — `Record<Role | "$START", Record<Status, Target>>`,每个 Target = `{ role, prompt }`
|
||||||
- Status 来自上一个 role 输出的 `status` 字段,`$START` 用 `_` 作为初始 status
|
- Status 来自上一个 role 输出的 `status` 字段,`$START` 用 `_` 作为初始 status
|
||||||
- Prompt 模板使用 Mustache 渲染,变量来自 lastOutput
|
- Prompt 模板使用 Mustache 渲染,变量来自 lastOutput
|
||||||
@@ -220,7 +220,7 @@ evaluate(graph, lastRole, lastOutput) → { role, prompt }
|
|||||||
```yaml
|
```yaml
|
||||||
type: <start-node-schema-hash>
|
type: <start-node-schema-hash>
|
||||||
payload:
|
payload:
|
||||||
workflow: "4KNM2PXR3B1QW" # ocas_ref → Workflow
|
workflow: "4KNM2PXR3B1QW" # cas_ref → Workflow
|
||||||
prompt: "Fix the login bug..."
|
prompt: "Fix the login bug..."
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -232,18 +232,18 @@ payload:
|
|||||||
```yaml
|
```yaml
|
||||||
type: <step-node-schema-hash>
|
type: <step-node-schema-hash>
|
||||||
payload:
|
payload:
|
||||||
start: "4TNVW8KR2B3MA" # ocas_ref → StartNode(每个 step 都引用)
|
start: "4TNVW8KR2B3MA" # cas_ref → StartNode(每个 step 都引用)
|
||||||
prev: "2MXBG6PN4A8JR" # ocas_ref → 前一个 StepNode,第一步为 null
|
prev: "2MXBG6PN4A8JR" # cas_ref → 前一个 StepNode,第一步为 null
|
||||||
role: "developer"
|
role: "developer"
|
||||||
output: "9KRVW3TN5F1QA" # ocas_ref → 结构化输出节点(符合 role 的 meta schema)
|
output: "9KRVW3TN5F1QA" # cas_ref → 结构化输出节点(符合 role 的 meta schema)
|
||||||
detail: "7BQST3VW9F2MA" # ocas_ref → 执行详情(content node / 子 workflow terminal StepNode / ...)
|
detail: "7BQST3VW9F2MA" # cas_ref → 执行详情(content node / 子 workflow terminal StepNode / ...)
|
||||||
agent: "uwf-cursor" # 实际使用的 agent 命令(纯字符串)
|
agent: "uwf-cursor" # 实际使用的 agent 命令(纯字符串)
|
||||||
```
|
```
|
||||||
|
|
||||||
- `start` — 每个 StepNode 都直接引用 StartNode,方便随机访问
|
- `start` — 每个 StepNode 都直接引用 StartNode,方便随机访问
|
||||||
- `prev` — 前一个 StepNode 的 ocas_ref,第一步为 `null`(不指向 StartNode)
|
- `prev` — 前一个 StepNode 的 cas_ref,第一步为 `null`(不指向 StartNode)
|
||||||
- `output` — ocas_ref,指向符合 role meta schema 的 CAS 节点,可用 ocas 校验
|
- `output` — cas_ref,指向符合 role meta schema 的 CAS 节点,可用 json-cas 校验
|
||||||
- `detail` — ocas_ref,指向执行详情。可以是原始 agent 输出(content node),也可以是子 workflow thread 的 terminal StepNode(workflowAsAgent 场景)
|
- `detail` — cas_ref,指向执行详情。可以是原始 agent 输出(content node),也可以是子 workflow thread 的 terminal StepNode(workflowAsAgent 场景)
|
||||||
- `agent` — 纯字符串,不是 CAS 节点
|
- `agent` — 纯字符串,不是 CAS 节点
|
||||||
|
|
||||||
### 2.3 链式结构
|
### 2.3 链式结构
|
||||||
@@ -337,7 +337,7 @@ OPENROUTER_API_KEY=sk-or-...
|
|||||||
|
|
||||||
## 3. 包结构
|
## 3. 包结构
|
||||||
|
|
||||||
全新包,不复用现有 packages,避免命名冲突。CAS 直接依赖 `@ocas/core`。
|
全新包,不复用现有 packages,避免命名冲突。CAS 直接依赖 `@uncaged/json-cas`。
|
||||||
|
|
||||||
```
|
```
|
||||||
packages/
|
packages/
|
||||||
@@ -349,8 +349,8 @@ packages/
|
|||||||
```
|
```
|
||||||
|
|
||||||
**外部依赖:**
|
**外部依赖:**
|
||||||
- `@ocas/core` — CAS 存储、hash、schema 校验
|
- `@uncaged/json-cas` — CAS 存储、hash、schema 校验
|
||||||
- `@ocas/fs` — 文件系统 CAS 后端
|
- `@uncaged/json-cas-fs` — 文件系统 CAS 后端
|
||||||
|
|
||||||
**现有包全部保留不动**,新旧并存,逐步迁移。
|
**现有包全部保留不动**,新旧并存,逐步迁移。
|
||||||
|
|
||||||
@@ -372,8 +372,8 @@ type ThreadId = string;
|
|||||||
/** 一个 step 的核心数据,被 StepNode payload 和 moderator 上下文共享 */
|
/** 一个 step 的核心数据,被 StepNode payload 和 moderator 上下文共享 */
|
||||||
type StepRecord = {
|
type StepRecord = {
|
||||||
role: string;
|
role: string;
|
||||||
output: CasRef; // ocas_ref → 结构化输出节点(符合 role meta schema)
|
output: CasRef; // cas_ref → 结构化输出节点(符合 role meta schema)
|
||||||
detail: CasRef; // ocas_ref → 执行详情(content node / 子 workflow terminal StepNode)
|
detail: CasRef; // cas_ref → 执行详情(content node / 子 workflow terminal StepNode)
|
||||||
agent: string; // 实际使用的 agent 命令(纯字符串)
|
agent: string; // 实际使用的 agent 命令(纯字符串)
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@@ -387,7 +387,7 @@ type RoleDefinition = {
|
|||||||
capabilities: string[];
|
capabilities: string[];
|
||||||
procedure: string;
|
procedure: string;
|
||||||
output: string;
|
output: string;
|
||||||
meta: CasRef; // ocas_ref → ocas 内置 JSON Schema 节点
|
meta: CasRef; // cas_ref → json-cas 内置 JSON Schema 节点
|
||||||
};
|
};
|
||||||
|
|
||||||
type Target = {
|
type Target = {
|
||||||
@@ -407,13 +407,13 @@ type WorkflowPayload = {
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
type StartNodePayload = {
|
type StartNodePayload = {
|
||||||
workflow: CasRef; // ocas_ref → Workflow
|
workflow: CasRef; // cas_ref → Workflow
|
||||||
prompt: string;
|
prompt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type StepNodePayload = StepRecord & {
|
type StepNodePayload = StepRecord & {
|
||||||
start: CasRef; // ocas_ref → StartNode(每个 step 都引用)
|
start: CasRef; // cas_ref → StartNode(每个 step 都引用)
|
||||||
prev: CasRef | null; // ocas_ref → 前一个 StepNode,第一步为 null
|
prev: CasRef | null; // cas_ref → 前一个 StepNode,第一步为 null
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+11
-48
@@ -8,46 +8,22 @@ roles:
|
|||||||
- issue-analysis
|
- issue-analysis
|
||||||
- planning
|
- planning
|
||||||
procedure: |
|
procedure: |
|
||||||
CRITICAL: First, determine which mode you are in by scanning the task prompt.
|
On first run (no previous steps):
|
||||||
Choose EXACTLY ONE mode — do NOT default to Mode A if Mode B applies.
|
|
||||||
|
|
||||||
**How to choose:**
|
|
||||||
- If the prompt contains ANY of these keywords: "PR #", "PR#", "pulls/", "继续修复", "continue", "review feedback", "existing branch", "fix/", or mentions a branch name → **Mode B**
|
|
||||||
- If the prompt was forwarded from tester with fix_spec → **Mode C**
|
|
||||||
- Otherwise → **Mode A**
|
|
||||||
|
|
||||||
**Mode A — Fresh issue (first time, no existing PR):**
|
|
||||||
1. Read the issue and all comments from Gitea using `tea issues <number> -r <owner/repo>`
|
1. Read the issue and all comments from Gitea using `tea issues <number> -r <owner/repo>`
|
||||||
2. Look for project conventions files (CLAUDE.md, CONTRIBUTING.md, .cursor/rules/) in the repo
|
2. Look for project conventions files (CLAUDE.md, CONTRIBUTING.md, .cursor/rules/) in the repo
|
||||||
3. Assess whether the issue has enough information to produce a test spec
|
3. Assess whether the issue has enough information to produce a test spec
|
||||||
4. If insufficient info: comment on the issue via `echo "..." | tea comment <number> -r <owner/repo>` (skip if you already commented), then output $status=insufficient_info
|
4. If insufficient info: comment on the issue via `echo "..." | tea comment <number> -r <owner/repo>` (skip if you already commented), then output $status=insufficient_info
|
||||||
5. If sufficient: produce a detailed TDD test spec in markdown covering all scenarios
|
5. If sufficient: produce a detailed TDD test spec in markdown covering all scenarios
|
||||||
6. Store it via `uwf cas put-text "<markdown content>"` and capture the returned hash
|
|
||||||
7. Output **$status=ready** with plan hash and repoPath
|
|
||||||
|
|
||||||
**Mode B — Continue on existing PR (prompt mentions PR, branch, or review feedback):**
|
On subsequent runs (bounced back by tester with fix_spec):
|
||||||
YOU MUST output $status=continue (NOT ready) when in this mode.
|
|
||||||
1. Extract the PR number and branch name from the prompt
|
|
||||||
2. Read the PR and its review comments from Gitea: `tea pr <number> --comments -r <owner/repo>`
|
|
||||||
3. Read the existing issue for full context: `tea issues <number> -r <owner/repo>`
|
|
||||||
4. Look for project conventions files (CLAUDE.md, CONTRIBUTING.md, .cursor/rules/) in the repo
|
|
||||||
5. Produce a TDD test spec that ONLY covers the changes requested in the review — do NOT re-spec already-implemented features
|
|
||||||
6. Store it via `uwf cas put-text "<markdown content>"` and capture the returned hash
|
|
||||||
7. Find the existing worktree: `git worktree list` and locate the branch
|
|
||||||
8. Output **$status=continue** with plan hash, repoPath, branch name, and worktree path
|
|
||||||
|
|
||||||
**Mode C — Bounced back by tester (fix_spec):**
|
|
||||||
1. Read the tester's output from the previous step to understand what's wrong with the spec
|
1. Read the tester's output from the previous step to understand what's wrong with the spec
|
||||||
2. Revise the test spec accordingly
|
2. Revise the test spec accordingly
|
||||||
3. Store it via `uwf cas put-text "<markdown content>"` and capture the returned hash
|
|
||||||
4. Output **$status=ready** with plan hash and repoPath
|
|
||||||
|
|
||||||
IMPORTANT: Extract the repo remote (owner/repo) from git:
|
After producing the test spec:
|
||||||
```bash
|
1. Store it via `uwf cas put-text "<markdown content>"` and capture the returned hash
|
||||||
git remote get-url origin | sed 's|.*[:/]\([^/]*/[^.]*\).*|\1|'
|
2. Put the hash in frontmatter.plan (required when $status=ready)
|
||||||
```
|
3. Set repoPath to the absolute path of the repository root
|
||||||
Store the result as repoRemote in your frontmatter output so downstream roles can use it.
|
output: "Output a brief summary of the test spec. Set $status to ready (with plan hash and repoPath) or insufficient_info."
|
||||||
output: "Output a brief summary of the test spec. Set $status to ready (fresh), continue (existing PR), or insufficient_info."
|
|
||||||
frontmatter:
|
frontmatter:
|
||||||
oneOf:
|
oneOf:
|
||||||
- properties:
|
- properties:
|
||||||
@@ -55,17 +31,9 @@ roles:
|
|||||||
plan: { type: string }
|
plan: { type: string }
|
||||||
repoPath: { type: string }
|
repoPath: { type: string }
|
||||||
required: [$status, plan, repoPath]
|
required: [$status, plan, repoPath]
|
||||||
- properties:
|
|
||||||
$status: { const: "continue" }
|
|
||||||
plan: { type: string }
|
|
||||||
repoPath: { type: string }
|
|
||||||
branch: { type: string }
|
|
||||||
worktree: { type: string }
|
|
||||||
required: [$status, plan, repoPath, branch, worktree]
|
|
||||||
- properties:
|
- properties:
|
||||||
$status: { const: "insufficient_info" }
|
$status: { const: "insufficient_info" }
|
||||||
reason: { type: string }
|
required: [$status]
|
||||||
required: [$status, reason]
|
|
||||||
developer:
|
developer:
|
||||||
description: "TDD implementation per test spec"
|
description: "TDD implementation per test spec"
|
||||||
goal: "You are a developer agent. You implement code changes following TDD — write tests first, then implementation."
|
goal: "You are a developer agent. You implement code changes following TDD — write tests first, then implementation."
|
||||||
@@ -81,14 +49,10 @@ roles:
|
|||||||
3. First time (no existing branch):
|
3. First time (no existing branch):
|
||||||
- `git worktree add .worktrees/fix/<issue-number>-<short-slug> -b fix/<issue-number>-<short-slug> origin/main`
|
- `git worktree add .worktrees/fix/<issue-number>-<short-slug> -b fix/<issue-number>-<short-slug> origin/main`
|
||||||
- `cd .worktrees/fix/<issue-number>-<short-slug> && bun install`
|
- `cd .worktrees/fix/<issue-number>-<short-slug> && bun install`
|
||||||
4. If continuing on existing branch (prompt says "Continue work on existing branch" or provides a worktree path):
|
4. If bounced back from reviewer or tester (branch already exists):
|
||||||
- cd directly into the worktree path provided in the prompt
|
|
||||||
- `git fetch origin && git rebase origin/main`
|
|
||||||
- Do NOT create a new branch or worktree
|
|
||||||
5. If bounced back from reviewer or tester (branch already exists but no explicit worktree path):
|
|
||||||
- cd into the existing worktree under `.worktrees/fix/<issue-number>-<short-slug>`
|
- cd into the existing worktree under `.worktrees/fix/<issue-number>-<short-slug>`
|
||||||
- `git fetch origin && git rebase origin/main`
|
- `git fetch origin && git rebase origin/main`
|
||||||
6. ALL subsequent work must happen inside the worktree directory.
|
5. ALL subsequent work must happen inside the worktree directory.
|
||||||
|
|
||||||
Then implement TDD:
|
Then implement TDD:
|
||||||
6. Read the test spec from CAS: `uwf cas get <plan hash>` (find the hash from the planner's output in your task prompt)
|
6. Read the test spec from CAS: `uwf cas get <plan hash>` (find the hash from the planner's output in your task prompt)
|
||||||
@@ -217,9 +181,8 @@ graph:
|
|||||||
$START:
|
$START:
|
||||||
_: { role: "planner", prompt: "Analyze the issue and produce an implementation plan." }
|
_: { role: "planner", prompt: "Analyze the issue and produce an implementation plan." }
|
||||||
planner:
|
planner:
|
||||||
insufficient_info: { role: "$SUSPEND", prompt: "信息不足,需要补充:{{{reason}}}" }
|
insufficient_info: { role: "$END", prompt: "Insufficient information to proceed; end the workflow." }
|
||||||
ready: { role: "developer", prompt: "Implement the TDD test spec (CAS hash: {{{plan}}}) in repo {{{repoPath}}}." }
|
ready: { role: "developer", prompt: "Implement the TDD test spec (CAS hash: {{{plan}}}) in repo {{{repoPath}}}." }
|
||||||
continue: { role: "developer", prompt: "Continue work on existing branch {{{branch}}} at worktree {{{worktree}}}. Implement the revised TDD test spec (CAS hash: {{{plan}}}) in repo {{{repoPath}}}. Do NOT create a new branch or worktree — cd into the existing worktree and work there." }
|
|
||||||
developer:
|
developer:
|
||||||
done: { role: "reviewer", prompt: "Review branch {{{branch}}} at {{{worktree}}} for code standards compliance." }
|
done: { role: "reviewer", prompt: "Review branch {{{branch}}} at {{{worktree}}} for code standards compliance." }
|
||||||
failed: { role: "$END", prompt: "Developer failed: {{{reason}}}. Ending workflow." }
|
failed: { role: "$END", prompt: "Developer failed: {{{reason}}}. Ending workflow." }
|
||||||
|
|||||||
+1
-6
@@ -1,14 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-monorepo",
|
"name": "@uncaged/workflow-monorepo",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "bun@1.3.14",
|
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"uwf": "bun packages/cli-workflow/src/cli.ts",
|
"uwf": "bun packages/cli-workflow/src/cli.ts",
|
||||||
"preinstall": "npx only-allow bun",
|
|
||||||
"prepublishOnly": "echo 'Use bun run release instead' && exit 1",
|
|
||||||
"build": "bunx tsc --build",
|
"build": "bunx tsc --build",
|
||||||
"check": "bunx tsc --build && biome check . && bash scripts/lint-log-tags.sh",
|
"check": "bunx tsc --build && biome check . && bash scripts/lint-log-tags.sh",
|
||||||
"typecheck": "bunx tsc --build",
|
"typecheck": "bunx tsc --build",
|
||||||
@@ -26,9 +23,7 @@
|
|||||||
"@types/node": "^25.7.0",
|
"@types/node": "^25.7.0",
|
||||||
"@types/xxhashjs": "^0.2.4",
|
"@types/xxhashjs": "^0.2.4",
|
||||||
"@uncaged/workflow-agent-hermes": "workspace:*",
|
"@uncaged/workflow-agent-hermes": "workspace:*",
|
||||||
"bun-types": "^1.3.13",
|
"bun-types": "^1.3.13"
|
||||||
"typescript": "^5.8.3",
|
|
||||||
"yaml": "^2.9.0"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# @uncaged/cli-workflow
|
||||||
|
|
||||||
|
## 0.5.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Add 5 persona-based skills (actor, user, author, developer, adapter) and fix skill CLI description truncation
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-util@0.5.1
|
||||||
|
- @uncaged/workflow-protocol@0.5.1
|
||||||
|
- @uncaged/workflow-util-agent@0.5.1
|
||||||
@@ -20,7 +20,7 @@ workflow → thread → step → turn
|
|||||||
|
|
||||||
This package has no library `src/index.ts` — it is consumed as a CLI binary only.
|
This package has no library `src/index.ts` — it is consumed as a CLI binary only.
|
||||||
|
|
||||||
**Dependencies:** `@ocas/core`, `@ocas/fs`, `@uncaged/workflow-util-agent`, `@uncaged/workflow-protocol`, `@uncaged/workflow-util`, `commander`, `dotenv`, `mustache`, `yaml`
|
**Dependencies:** `@uncaged/json-cas`, `@uncaged/json-cas-fs`, `@uncaged/workflow-util-agent`, `@uncaged/workflow-protocol`, `@uncaged/workflow-util`, `commander`, `dotenv`, `mustache`, `yaml`
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -209,13 +209,4 @@ src/
|
|||||||
| `~/.uncaged/workflow/.env` | API keys (referenced by `apiKeyEnv` in config) |
|
| `~/.uncaged/workflow/.env` | API keys (referenced by `apiKeyEnv` in config) |
|
||||||
| `~/.uncaged/workflow/registry.yaml` | Workflow name → CAS hash |
|
| `~/.uncaged/workflow/registry.yaml` | Workflow name → CAS hash |
|
||||||
| `~/.uncaged/workflow/threads.yaml` | Active thread head pointers |
|
| `~/.uncaged/workflow/threads.yaml` | Active thread head pointers |
|
||||||
| `~/.uncaged/json-cas/` | Content-addressed node storage (unified CAS store, shared with `ocas` CLI) |
|
| `~/.uncaged/workflow/cas/` | Content-addressed node storage |
|
||||||
|
|
||||||
### Environment Variables
|
|
||||||
|
|
||||||
| Variable | Purpose | Default |
|
|
||||||
|----------|---------|---------|
|
|
||||||
| `UNCAGED_CAS_DIR` | Override the global CAS directory location | `~/.uncaged/json-cas` |
|
|
||||||
| `UNCAGED_WORKFLOW_STORAGE_ROOT` | Internal override for workflow metadata storage | `~/.uncaged/workflow` |
|
|
||||||
| `WORKFLOW_STORAGE_ROOT` | User override for workflow metadata storage | `~/.uncaged/workflow` |
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/cli-workflow",
|
"name": "@uncaged/cli-workflow",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"dist",
|
"dist",
|
||||||
@@ -11,8 +11,8 @@
|
|||||||
"uwf": "./dist/cli.js"
|
"uwf": "./dist/cli.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ocas/core": "^0.1.1",
|
"@uncaged/json-cas": "^0.5.3",
|
||||||
"@ocas/fs": "^0.1.1",
|
"@uncaged/json-cas-fs": "^0.5.3",
|
||||||
"@uncaged/workflow-protocol": "workspace:^",
|
"@uncaged/workflow-protocol": "workspace:^",
|
||||||
"@uncaged/workflow-util": "workspace:^",
|
"@uncaged/workflow-util": "workspace:^",
|
||||||
"@uncaged/workflow-util-agent": "workspace:^",
|
"@uncaged/workflow-util-agent": "workspace:^",
|
||||||
@@ -22,24 +22,24 @@
|
|||||||
"yaml": "^2.8.4"
|
"yaml": "^2.8.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublishOnly": "echo 'Use bun run release from repo root' && exit 1",
|
"test": "vitest run",
|
||||||
"test": "bun test src/",
|
"test:ci": "vitest run"
|
||||||
"test:ci": "bun test src/"
|
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/mustache": "^4.2.6"
|
"@types/mustache": "^4.2.6",
|
||||||
|
"vitest": "^4.1.6"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow.git",
|
"url": "https://github.com/shazhou-ww/uncaged-workflow.git",
|
||||||
"directory": "packages/cli-workflow"
|
"directory": "packages/cli-workflow"
|
||||||
},
|
},
|
||||||
"homepage": "https://git.shazhou.work/uncaged/workflow#readme",
|
"homepage": "https://github.com/shazhou-ww/uncaged-workflow#readme",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow/issues"
|
"url": "https://github.com/shazhou-ww/uncaged-workflow/issues"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,178 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { execFileSync } from "node:child_process";
|
|
||||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { putSchema } from "@ocas/core";
|
|
||||||
import { createFsStore } from "@ocas/fs";
|
|
||||||
import type { CasRef, StepNodePayload, ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
|
||||||
import { saveThreadsIndex } from "../store.js";
|
|
||||||
|
|
||||||
// ── schemas ──────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const OUTPUT_SCHEMA = {
|
|
||||||
type: "object" as const,
|
|
||||||
properties: {
|
|
||||||
$status: { type: "string" as const, enum: ["done", "failed"] },
|
|
||||||
result: { type: "string" as const },
|
|
||||||
},
|
|
||||||
required: ["$status"],
|
|
||||||
additionalProperties: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
// ── fixture ──────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
let tmpDir: string;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-roundtrip-test-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("C1: adapter JSON round-trip integration", () => {
|
|
||||||
test("mock agent outputs JSON, CLI parses it and updates thread head in CAS", async () => {
|
|
||||||
// 1. Set up CAS store with workflow, start node, and output schema
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
const store = createFsStore(casDir);
|
|
||||||
const schemas = await registerUwfSchemas(store);
|
|
||||||
|
|
||||||
const outputSchemaHash = await putSchema(store, OUTPUT_SCHEMA);
|
|
||||||
|
|
||||||
const workflowHash = await store.put(schemas.workflow, {
|
|
||||||
name: "test-roundtrip",
|
|
||||||
description: "roundtrip integration test",
|
|
||||||
roles: {
|
|
||||||
worker: {
|
|
||||||
description: "Worker role",
|
|
||||||
goal: "Do work",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "work",
|
|
||||||
output: "result",
|
|
||||||
frontmatter: outputSchemaHash,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
$START: { _: { role: "worker", prompt: "Do the work", location: null } },
|
|
||||||
worker: { done: { role: "$END", prompt: "completed", location: null } },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const startHash = await store.put(schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "Test round-trip task",
|
|
||||||
});
|
|
||||||
|
|
||||||
const threadId = "01ROUNDTRIPTEST0000000000" as ThreadId;
|
|
||||||
await saveThreadsIndex(tmpDir, { [threadId]: startHash });
|
|
||||||
|
|
||||||
// 2. Pre-create CAS nodes that the mock agent would produce
|
|
||||||
const outputHash = await store.put(outputSchemaHash, {
|
|
||||||
$status: "done",
|
|
||||||
result: "test-ok",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Use text schema for detail (simple placeholder)
|
|
||||||
const detailHash = await store.put(schemas.text, "mock detail");
|
|
||||||
|
|
||||||
const startedAtMs = 1716600000000;
|
|
||||||
const completedAtMs = 1716600001500;
|
|
||||||
|
|
||||||
const stepHash = await store.put(schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: null,
|
|
||||||
role: "worker",
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-mock",
|
|
||||||
edgePrompt: "Do the work",
|
|
||||||
startedAtMs,
|
|
||||||
completedAtMs,
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 3. Create a minimal mock agent shell script that just outputs JSON
|
|
||||||
// The step node is already in CAS — the agent just needs to print the JSON line
|
|
||||||
const mockAgentPath = join(tmpDir, "mock-agent.sh");
|
|
||||||
const adapterJson = JSON.stringify({
|
|
||||||
stepHash,
|
|
||||||
detailHash,
|
|
||||||
role: "worker",
|
|
||||||
frontmatter: { $status: "done", result: "test-ok" },
|
|
||||||
body: "",
|
|
||||||
startedAtMs,
|
|
||||||
completedAtMs,
|
|
||||||
});
|
|
||||||
await writeFile(mockAgentPath, `#!/bin/sh\necho '${adapterJson}'\n`, { mode: 0o755 });
|
|
||||||
|
|
||||||
// 4. Write config.yaml
|
|
||||||
const configPath = join(tmpDir, "config.yaml");
|
|
||||||
await writeFile(
|
|
||||||
configPath,
|
|
||||||
`defaultAgent: uwf-hermes\ndefaultModel: test-model\nagentOverrides: null\nagents: {}\nproviders: {}\nmodels: {}\n`,
|
|
||||||
);
|
|
||||||
|
|
||||||
// 5. Run CLI with agent override pointing to our mock
|
|
||||||
const cliPath = join(import.meta.dirname, "..", "cli.js");
|
|
||||||
let stdout: string;
|
|
||||||
let stderr: string;
|
|
||||||
let exitCode: number;
|
|
||||||
|
|
||||||
try {
|
|
||||||
stdout = execFileSync(
|
|
||||||
"bun",
|
|
||||||
["run", cliPath, "thread", "exec", threadId, "--agent", mockAgentPath],
|
|
||||||
{
|
|
||||||
encoding: "utf8",
|
|
||||||
stdio: ["ignore", "pipe", "pipe"],
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
WORKFLOW_STORAGE_ROOT: tmpDir,
|
|
||||||
UNCAGED_CAS_DIR: casDir,
|
|
||||||
},
|
|
||||||
cwd: tmpDir,
|
|
||||||
timeout: 30000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
stderr = "";
|
|
||||||
exitCode = 0;
|
|
||||||
} catch (e: unknown) {
|
|
||||||
const err = e as NodeJS.ErrnoException & {
|
|
||||||
stdout?: string;
|
|
||||||
stderr?: string;
|
|
||||||
status?: number;
|
|
||||||
};
|
|
||||||
stdout = err.stdout ?? "";
|
|
||||||
stderr = err.stderr ?? "";
|
|
||||||
exitCode = err.status ?? 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. Verify
|
|
||||||
if (exitCode !== 0) {
|
|
||||||
throw new Error(`CLI exited with code ${exitCode}\nstdout: ${stdout}\nstderr: ${stderr}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse CLI output
|
|
||||||
const cliOutput = JSON.parse(stdout.trim());
|
|
||||||
expect(cliOutput).toHaveProperty("thread", threadId);
|
|
||||||
expect(cliOutput).toHaveProperty("head", stepHash);
|
|
||||||
expect(cliOutput.head).toMatch(/^[0-9A-HJ-NP-TV-Z]{13}$/);
|
|
||||||
|
|
||||||
// Verify the CAS step node exists and has correct metadata
|
|
||||||
const storeAfter = createFsStore(casDir);
|
|
||||||
const stepNode = storeAfter.get(cliOutput.head as CasRef);
|
|
||||||
expect(stepNode).not.toBeNull();
|
|
||||||
|
|
||||||
const payload = stepNode!.payload as StepNodePayload;
|
|
||||||
expect(payload.role).toBe("worker");
|
|
||||||
expect(payload.agent).toBe("uwf-mock");
|
|
||||||
expect(payload.startedAtMs).toBe(1716600000000);
|
|
||||||
expect(payload.completedAtMs).toBe(1716600001500);
|
|
||||||
expect(payload.output).toBe(outputHash);
|
|
||||||
expect(payload.detail).toBe(detailHash);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,27 +1,19 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { execSync } from "node:child_process";
|
import { execSync } from "node:child_process";
|
||||||
import { mkdir, rm } from "node:fs/promises";
|
import { mkdir, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdCasPutText } from "../commands/cas.js";
|
import { cmdCasPutText } from "../commands/cas.js";
|
||||||
|
|
||||||
let storageRoot: string;
|
let storageRoot: string;
|
||||||
let casDir: string;
|
|
||||||
let uwfPath: string;
|
let uwfPath: string;
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
storageRoot = join(
|
storageRoot = join(
|
||||||
tmpdir(),
|
tmpdir(),
|
||||||
`uwf-cas-exit-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
`uwf-cas-exit-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
||||||
);
|
);
|
||||||
casDir = join(storageRoot, "cas");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
await mkdir(storageRoot, { recursive: true });
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
|
|
||||||
// Set UNCAGED_CAS_DIR for this test
|
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
// Find the uwf CLI path
|
// Find the uwf CLI path
|
||||||
uwfPath = join(__dirname, "../../src/cli.ts");
|
uwfPath = join(__dirname, "../../src/cli.ts");
|
||||||
@@ -29,13 +21,6 @@ beforeEach(async () => {
|
|||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await rm(storageRoot, { recursive: true, force: true });
|
await rm(storageRoot, { recursive: true, force: true });
|
||||||
|
|
||||||
// Restore original environment
|
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
type ExecResult = {
|
type ExecResult = {
|
||||||
@@ -47,11 +32,7 @@ type ExecResult = {
|
|||||||
function execUwf(args: string[]): ExecResult {
|
function execUwf(args: string[]): ExecResult {
|
||||||
try {
|
try {
|
||||||
const stdout = execSync(`bun ${uwfPath} ${args.join(" ")}`, {
|
const stdout = execSync(`bun ${uwfPath} ${args.join(" ")}`, {
|
||||||
env: {
|
env: { ...process.env, WORKFLOW_STORAGE_ROOT: storageRoot },
|
||||||
...process.env,
|
|
||||||
WORKFLOW_STORAGE_ROOT: storageRoot,
|
|
||||||
UNCAGED_CAS_DIR: casDir,
|
|
||||||
},
|
|
||||||
encoding: "utf-8",
|
encoding: "utf-8",
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, rm } from "node:fs/promises";
|
import { mkdir, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdCasHas, cmdCasPutText } from "../commands/cas.js";
|
import { cmdCasHas, cmdCasPutText } from "../commands/cas.js";
|
||||||
|
|
||||||
let storageRoot: string;
|
let storageRoot: string;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
import {
|
import {
|
||||||
cmdConfigGet,
|
cmdConfigGet,
|
||||||
cmdConfigList,
|
cmdConfigList,
|
||||||
@@ -143,44 +143,6 @@ defaultModel: default
|
|||||||
const masked = maskApiKeys(config);
|
const masked = maskApiKeys(config);
|
||||||
expect(masked).toEqual(config);
|
expect(masked).toEqual(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("does not mask non-provider apiKey fields", () => {
|
|
||||||
const config = {
|
|
||||||
apiKey: "root-level-key",
|
|
||||||
providers: {
|
|
||||||
dashscope: { apiKey: "sk-secret" },
|
|
||||||
},
|
|
||||||
models: {
|
|
||||||
default: { provider: "dashscope" },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const masked = maskApiKeys(config);
|
|
||||||
// Root-level apiKey should NOT be masked
|
|
||||||
expect(masked.apiKey).toBe("root-level-key");
|
|
||||||
// Provider apiKey SHOULD be masked
|
|
||||||
const providers = masked.providers as Record<string, Record<string, unknown>>;
|
|
||||||
expect(providers.dashscope.apiKey).toBe("***MASKED***");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles empty provider object", () => {
|
|
||||||
const config = {
|
|
||||||
providers: { dashscope: {} },
|
|
||||||
};
|
|
||||||
const masked = maskApiKeys(config);
|
|
||||||
expect(masked).toEqual({ providers: { dashscope: {} } });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles provider with null apiKey", () => {
|
|
||||||
const config = {
|
|
||||||
providers: {
|
|
||||||
dashscope: { apiKey: null, baseUrl: "https://example.com" },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const masked = maskApiKeys(config);
|
|
||||||
const providers = masked.providers as Record<string, Record<string, unknown>>;
|
|
||||||
expect(providers.dashscope.apiKey).toBe("***MASKED***");
|
|
||||||
expect(providers.dashscope.baseUrl).toBe("https://example.com");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -656,85 +618,5 @@ defaultModel: default
|
|||||||
rmSync(tempDir, { recursive: true, force: true });
|
rmSync(tempDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("agentOverrides — accepts valid 3-segment path", async () => {
|
|
||||||
const tempDir = mkdtempSync(join(tmpdir(), "test-config-"));
|
|
||||||
try {
|
|
||||||
createTestConfig(tempDir, sampleConfig);
|
|
||||||
await cmdConfigSet(tempDir, "agentOverrides.solve-issue.planner", "claude-code");
|
|
||||||
const value = await cmdConfigGet(tempDir, "agentOverrides.solve-issue.planner");
|
|
||||||
expect(value).toBe("claude-code");
|
|
||||||
} finally {
|
|
||||||
rmSync(tempDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("agentOverrides — rejects incomplete path (2 segments)", async () => {
|
|
||||||
const tempDir = mkdtempSync(join(tmpdir(), "test-config-"));
|
|
||||||
try {
|
|
||||||
createTestConfig(tempDir, sampleConfig);
|
|
||||||
await expect(cmdConfigSet(tempDir, "agentOverrides.solve-issue", "hermes")).rejects.toThrow(
|
|
||||||
/incomplete path|must specify a field/i,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
rmSync(tempDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("modelOverrides — accepts valid 2-segment path", async () => {
|
|
||||||
const tempDir = mkdtempSync(join(tmpdir(), "test-config-"));
|
|
||||||
try {
|
|
||||||
createTestConfig(tempDir, sampleConfig);
|
|
||||||
await cmdConfigSet(tempDir, "modelOverrides.extract", "gpt4");
|
|
||||||
const value = await cmdConfigGet(tempDir, "modelOverrides.extract");
|
|
||||||
expect(value).toBe("gpt4");
|
|
||||||
} finally {
|
|
||||||
rmSync(tempDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("modelOverrides — rejects incomplete path (1 segment only)", async () => {
|
|
||||||
const tempDir = mkdtempSync(join(tmpdir(), "test-config-"));
|
|
||||||
try {
|
|
||||||
createTestConfig(tempDir, sampleConfig);
|
|
||||||
await expect(cmdConfigSet(tempDir, "modelOverrides", "gpt4")).rejects.toThrow(
|
|
||||||
/incomplete path|must specify a field/i,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
rmSync(tempDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("rejects unknown top-level key (regression)", async () => {
|
|
||||||
const tempDir = mkdtempSync(join(tmpdir(), "test-config-"));
|
|
||||||
try {
|
|
||||||
createTestConfig(tempDir, sampleConfig);
|
|
||||||
await expect(cmdConfigSet(tempDir, "randomKey", "value")).rejects.toThrow(
|
|
||||||
/Unknown config key/,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
rmSync(tempDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("no legacy apiKeyEnv references", () => {
|
|
||||||
test("config.ts has no references to apiKeyEnv", () => {
|
|
||||||
const configSource = readFileSync(
|
|
||||||
join(__dirname, "..", "..", "src", "commands", "config.ts"),
|
|
||||||
"utf8",
|
|
||||||
);
|
|
||||||
expect(configSource).not.toContain("apiKeyEnv");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("config.test.ts has no references to apiKeyEnv (except this test)", () => {
|
|
||||||
const testSource = readFileSync(__filename, "utf8");
|
|
||||||
// Remove this test block's own mentions before checking
|
|
||||||
const withoutThisTest = testSource.replace(
|
|
||||||
/describe\("no legacy apiKeyEnv references"[\s\S]*$/,
|
|
||||||
"",
|
|
||||||
);
|
|
||||||
expect(withoutThisTest).not.toContain("apiKeyEnv");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,457 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { putSchema } from "@ocas/core";
|
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { createMarker, deleteMarker } from "../background/index.js";
|
|
||||||
import { cmdThreadList, cmdThreadShow, cmdThreadStart } from "../commands/thread.js";
|
|
||||||
import {
|
|
||||||
appendThreadHistory,
|
|
||||||
createUwfStore,
|
|
||||||
loadThreadsIndex,
|
|
||||||
saveThreadsIndex,
|
|
||||||
} from "../store.js";
|
|
||||||
|
|
||||||
const OUTPUT_SCHEMA = {
|
|
||||||
type: "object" as const,
|
|
||||||
properties: {
|
|
||||||
$status: { type: "string" as const },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const SIMPLE_WORKFLOW_YAML = `
|
|
||||||
name: test-current-role
|
|
||||||
description: Test workflow for currentRole
|
|
||||||
roles:
|
|
||||||
roleA:
|
|
||||||
description: First role
|
|
||||||
goal: Do A
|
|
||||||
capabilities: ["coding"]
|
|
||||||
procedure: Do A
|
|
||||||
output: |
|
|
||||||
$status: "ready"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string, enum: ["ready", "not-ready"] }
|
|
||||||
roleB:
|
|
||||||
description: Second role
|
|
||||||
goal: Do B
|
|
||||||
capabilities: ["coding"]
|
|
||||||
procedure: Do B
|
|
||||||
output: |
|
|
||||||
$status: "done"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: roleA
|
|
||||||
prompt: "Do A"
|
|
||||||
location: null
|
|
||||||
roleA:
|
|
||||||
ready:
|
|
||||||
role: roleB
|
|
||||||
prompt: "Do B"
|
|
||||||
location: null
|
|
||||||
not-ready:
|
|
||||||
role: roleA
|
|
||||||
prompt: "Try again"
|
|
||||||
location: null
|
|
||||||
roleB:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CONDITIONAL_WORKFLOW_YAML = `
|
|
||||||
name: test-conditional-role
|
|
||||||
description: Conditional routing workflow
|
|
||||||
roles:
|
|
||||||
roleA:
|
|
||||||
description: First role
|
|
||||||
goal: Do A
|
|
||||||
capabilities: ["coding"]
|
|
||||||
procedure: Do A
|
|
||||||
output: |
|
|
||||||
$status: "pass"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string, enum: ["pass", "fail"] }
|
|
||||||
roleB:
|
|
||||||
description: Pass role
|
|
||||||
goal: Do B
|
|
||||||
capabilities: ["coding"]
|
|
||||||
procedure: Do B
|
|
||||||
output: |
|
|
||||||
$status: "done"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
roleC:
|
|
||||||
description: Fail role
|
|
||||||
goal: Do C
|
|
||||||
capabilities: ["coding"]
|
|
||||||
procedure: Do C
|
|
||||||
output: |
|
|
||||||
$status: "done"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: roleA
|
|
||||||
prompt: "Do A"
|
|
||||||
location: null
|
|
||||||
roleA:
|
|
||||||
pass:
|
|
||||||
role: roleB
|
|
||||||
prompt: "Do B (pass)"
|
|
||||||
location: null
|
|
||||||
fail:
|
|
||||||
role: roleC
|
|
||||||
prompt: "Do C (fail)"
|
|
||||||
location: null
|
|
||||||
roleB:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
roleC:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
const SINGLE_ROLE_WORKFLOW_YAML = `
|
|
||||||
name: test-single-role
|
|
||||||
description: Single role that goes to END
|
|
||||||
roles:
|
|
||||||
worker:
|
|
||||||
description: Worker
|
|
||||||
goal: Work
|
|
||||||
capabilities: ["coding"]
|
|
||||||
procedure: Work
|
|
||||||
output: |
|
|
||||||
$status: "done"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: worker
|
|
||||||
prompt: "Work"
|
|
||||||
location: null
|
|
||||||
worker:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
/** Helper: insert a completed step node after the current head. */
|
|
||||||
async function insertStepNode(
|
|
||||||
storageRoot: string,
|
|
||||||
threadId: ThreadId,
|
|
||||||
role: string,
|
|
||||||
outputPayload: Record<string, unknown>,
|
|
||||||
): Promise<void> {
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const headEntry = index[threadId];
|
|
||||||
if (headEntry === undefined) throw new Error(`thread ${threadId} not in index`);
|
|
||||||
const head = headEntry.head;
|
|
||||||
|
|
||||||
const outputSchemaHash = await putSchema(uwf.store, OUTPUT_SCHEMA);
|
|
||||||
const outputHash = await uwf.store.put(outputSchemaHash, outputPayload);
|
|
||||||
|
|
||||||
// Use text schema for detail (simple placeholder)
|
|
||||||
const detailHash = await uwf.store.put(uwf.schemas.text, "detail-placeholder");
|
|
||||||
|
|
||||||
// Resolve start hash from head
|
|
||||||
const headNode = uwf.store.get(head);
|
|
||||||
if (headNode === null) throw new Error(`head ${head} not found`);
|
|
||||||
const isStart = headNode.type === uwf.schemas.startNode;
|
|
||||||
const startHash = isStart ? head : (headNode.payload as { start: CasRef }).start;
|
|
||||||
|
|
||||||
const stepHash = (await uwf.store.put(uwf.schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: isStart ? null : head,
|
|
||||||
role,
|
|
||||||
prompt: `Do ${role}`,
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
})) as CasRef;
|
|
||||||
|
|
||||||
index[threadId] = { head: stepHash, suspendedRole: null, suspendMessage: null };
|
|
||||||
await saveThreadsIndex(storageRoot, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("currentRole field", () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
let storageRoot: string;
|
|
||||||
let casDir: string;
|
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
async function setup() {
|
|
||||||
tmpDir = join(
|
|
||||||
tmpdir(),
|
|
||||||
`uwf-test-current-role-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
||||||
);
|
|
||||||
storageRoot = join(tmpDir, "storage");
|
|
||||||
casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
|
|
||||||
// Set UNCAGED_CAS_DIR for this test
|
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function teardown() {
|
|
||||||
if (tmpDir) {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
// Restore original environment
|
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// T1: idle at start — currentRole = first role from graph
|
|
||||||
test("thread show — idle at start returns first role as currentRole", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-current-role.yaml");
|
|
||||||
await writeFile(wf, SIMPLE_WORKFLOW_YAML, "utf8");
|
|
||||||
const { thread } = await cmdThreadStart(storageRoot, wf, "test", tmpDir);
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, thread as ThreadId);
|
|
||||||
expect(result.status).toBe("idle");
|
|
||||||
expect(result.currentRole).toBe("roleA");
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T2: idle after one step — currentRole = next role
|
|
||||||
test("thread show — idle after step returns next role as currentRole", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-current-role.yaml");
|
|
||||||
await writeFile(wf, SIMPLE_WORKFLOW_YAML, "utf8");
|
|
||||||
const { thread } = await cmdThreadStart(storageRoot, wf, "test", tmpDir);
|
|
||||||
|
|
||||||
await insertStepNode(storageRoot, thread as ThreadId, "roleA", { $status: "ready" });
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, thread as ThreadId);
|
|
||||||
expect(result.status).toBe("idle");
|
|
||||||
expect(result.currentRole).toBe("roleB");
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T3: completed → currentRole = null
|
|
||||||
test("thread show — completed thread returns null currentRole", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-current-role.yaml");
|
|
||||||
await writeFile(wf, SIMPLE_WORKFLOW_YAML, "utf8");
|
|
||||||
const { thread, workflow } = await cmdThreadStart(storageRoot, wf, "test", tmpDir);
|
|
||||||
const tid = thread as ThreadId;
|
|
||||||
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const head = index[tid]!.head;
|
|
||||||
delete index[tid];
|
|
||||||
await saveThreadsIndex(storageRoot, index);
|
|
||||||
await appendThreadHistory(storageRoot, {
|
|
||||||
thread: tid,
|
|
||||||
workflow,
|
|
||||||
head,
|
|
||||||
completedAt: Date.now(),
|
|
||||||
reason: "completed",
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, tid);
|
|
||||||
expect(result.status).toBe("completed");
|
|
||||||
expect(result.currentRole).toBe(null);
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T4: cancelled → currentRole = null
|
|
||||||
test("thread show — cancelled thread returns null currentRole", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-current-role.yaml");
|
|
||||||
await writeFile(wf, SIMPLE_WORKFLOW_YAML, "utf8");
|
|
||||||
const { thread, workflow } = await cmdThreadStart(storageRoot, wf, "test", tmpDir);
|
|
||||||
const tid = thread as ThreadId;
|
|
||||||
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const head = index[tid]!.head;
|
|
||||||
delete index[tid];
|
|
||||||
await saveThreadsIndex(storageRoot, index);
|
|
||||||
await appendThreadHistory(storageRoot, {
|
|
||||||
thread: tid,
|
|
||||||
workflow,
|
|
||||||
head,
|
|
||||||
completedAt: Date.now(),
|
|
||||||
reason: "cancelled",
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, tid);
|
|
||||||
expect(result.status).toBe("cancelled");
|
|
||||||
expect(result.currentRole).toBe(null);
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T5: running → currentRole = role being executed
|
|
||||||
test("thread show — running thread returns current role", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-current-role.yaml");
|
|
||||||
await writeFile(wf, SIMPLE_WORKFLOW_YAML, "utf8");
|
|
||||||
const { thread, workflow } = await cmdThreadStart(storageRoot, wf, "test", tmpDir);
|
|
||||||
const tid = thread as ThreadId;
|
|
||||||
|
|
||||||
await createMarker(storageRoot, {
|
|
||||||
thread: tid,
|
|
||||||
workflow,
|
|
||||||
pid: process.pid,
|
|
||||||
startedAt: Date.now(),
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await cmdThreadShow(storageRoot, tid);
|
|
||||||
expect(result.status).toBe("running");
|
|
||||||
expect(result.currentRole).toBe("roleA");
|
|
||||||
} finally {
|
|
||||||
await deleteMarker(storageRoot, tid);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T6: thread list — mixed statuses with correct currentRole
|
|
||||||
test("thread list — returns correct currentRole for each status", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-current-role.yaml");
|
|
||||||
await writeFile(wf, SIMPLE_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
// idle thread
|
|
||||||
const idle = await cmdThreadStart(storageRoot, wf, "idle", tmpDir);
|
|
||||||
const idleId = idle.thread as ThreadId;
|
|
||||||
|
|
||||||
// completed thread
|
|
||||||
const comp = await cmdThreadStart(storageRoot, wf, "completed", tmpDir);
|
|
||||||
const compId = comp.thread as ThreadId;
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const compHead = index[compId]!.head;
|
|
||||||
delete index[compId];
|
|
||||||
await saveThreadsIndex(storageRoot, index);
|
|
||||||
await appendThreadHistory(storageRoot, {
|
|
||||||
thread: compId,
|
|
||||||
workflow: comp.workflow,
|
|
||||||
head: compHead,
|
|
||||||
completedAt: Date.now(),
|
|
||||||
reason: "completed",
|
|
||||||
});
|
|
||||||
|
|
||||||
const list = await cmdThreadList(storageRoot, null, null, null, 0, 100);
|
|
||||||
|
|
||||||
const idleItem = list.find((i) => i.thread === idleId);
|
|
||||||
expect(idleItem).toBeDefined();
|
|
||||||
expect(idleItem!.currentRole).toBe("roleA");
|
|
||||||
|
|
||||||
const compItem = list.find((i) => i.thread === compId);
|
|
||||||
expect(compItem).toBeDefined();
|
|
||||||
expect(compItem!.currentRole).toBe(null);
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T7: thread list — idle at start has correct currentRole
|
|
||||||
test("thread list — idle thread at start has correct currentRole", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-current-role.yaml");
|
|
||||||
await writeFile(wf, SIMPLE_WORKFLOW_YAML, "utf8");
|
|
||||||
const { thread } = await cmdThreadStart(storageRoot, wf, "test", tmpDir);
|
|
||||||
|
|
||||||
const list = await cmdThreadList(storageRoot, null, null, null, 0, 100);
|
|
||||||
const item = list.find((i) => i.thread === (thread as ThreadId));
|
|
||||||
expect(item).toBeDefined();
|
|
||||||
expect(item!.currentRole).toBe("roleA");
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T8: conditional routing — $status=pass vs fail
|
|
||||||
test("thread show — conditional routing selects correct next role", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-conditional-role.yaml");
|
|
||||||
await writeFile(wf, CONDITIONAL_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
// pass path
|
|
||||||
const t1 = await cmdThreadStart(storageRoot, wf, "pass test", tmpDir);
|
|
||||||
await insertStepNode(storageRoot, t1.thread as ThreadId, "roleA", { $status: "pass" });
|
|
||||||
const r1 = await cmdThreadShow(storageRoot, t1.thread as ThreadId);
|
|
||||||
expect(r1.currentRole).toBe("roleB");
|
|
||||||
|
|
||||||
// fail path
|
|
||||||
const t2 = await cmdThreadStart(storageRoot, wf, "fail test", tmpDir);
|
|
||||||
await insertStepNode(storageRoot, t2.thread as ThreadId, "roleA", { $status: "fail" });
|
|
||||||
const r2 = await cmdThreadShow(storageRoot, t2.thread as ThreadId);
|
|
||||||
expect(r2.currentRole).toBe("roleC");
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// T9: next role is $END → currentRole = null
|
|
||||||
test("thread show — when next is $END, currentRole is null", async () => {
|
|
||||||
await setup();
|
|
||||||
try {
|
|
||||||
const wf = join(tmpDir, "test-single-role.yaml");
|
|
||||||
await writeFile(wf, SINGLE_ROLE_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
const { thread } = await cmdThreadStart(storageRoot, wf, "test", tmpDir);
|
|
||||||
// worker → _ maps to $END
|
|
||||||
await insertStepNode(storageRoot, thread as ThreadId, "worker", {});
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, thread as ThreadId);
|
|
||||||
expect(result.currentRole).toBe(null);
|
|
||||||
} finally {
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { parse } from "yaml";
|
|
||||||
import { createIncludeTag } from "../include.js";
|
|
||||||
|
|
||||||
let tmpDir: string;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "include-tag-test-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("!include tag", () => {
|
|
||||||
test("includes .md file as string", async () => {
|
|
||||||
await writeFile(join(tmpDir, "prompt.md"), "You are an analyst.");
|
|
||||||
const yaml = "system: !include prompt.md";
|
|
||||||
const result = parse(yaml, { customTags: [createIncludeTag(tmpDir)] });
|
|
||||||
expect(result.system).toBe("You are an analyst.");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("includes .json file as parsed object", async () => {
|
|
||||||
await writeFile(join(tmpDir, "schema.json"), '{"type":"object","properties":{}}');
|
|
||||||
const yaml = "outputSchema: !include schema.json";
|
|
||||||
const result = parse(yaml, { customTags: [createIncludeTag(tmpDir)] });
|
|
||||||
expect(result.outputSchema).toEqual({ type: "object", properties: {} });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("includes .yaml file as parsed object", async () => {
|
|
||||||
await writeFile(join(tmpDir, "config.yaml"), "key: value\nlist:\n - a\n - b");
|
|
||||||
const yaml = "config: !include config.yaml";
|
|
||||||
const result = parse(yaml, { customTags: [createIncludeTag(tmpDir)] });
|
|
||||||
expect(result.config).toEqual({ key: "value", list: ["a", "b"] });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("resolves relative subdirectory paths", async () => {
|
|
||||||
const subdir = join(tmpDir, "roles");
|
|
||||||
await mkdir(subdir, { recursive: true });
|
|
||||||
await writeFile(join(subdir, "analyst.md"), "Analyze data.");
|
|
||||||
const yaml = "system: !include roles/analyst.md";
|
|
||||||
const result = parse(yaml, { customTags: [createIncludeTag(tmpDir)] });
|
|
||||||
expect(result.system).toBe("Analyze data.");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("throws on missing file", () => {
|
|
||||||
const yaml = "system: !include nonexistent.md";
|
|
||||||
expect(() => parse(yaml, { customTags: [createIncludeTag(tmpDir)] })).toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("includes .txt file as string", async () => {
|
|
||||||
await writeFile(join(tmpDir, "note.txt"), "Hello world");
|
|
||||||
const yaml = "note: !include note.txt";
|
|
||||||
const result = parse(yaml, { customTags: [createIncludeTag(tmpDir)] });
|
|
||||||
expect(result.note).toBe("Hello world");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("blocks path traversal with ../", async () => {
|
|
||||||
const yaml = "secret: !include ../../etc/passwd";
|
|
||||||
expect(() => parse(yaml, { customTags: [createIncludeTag(tmpDir)] })).toThrow(
|
|
||||||
/path traversal blocked/,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("blocks absolute path traversal", async () => {
|
|
||||||
const yaml = "secret: !include /etc/passwd";
|
|
||||||
expect(() => parse(yaml, { customTags: [createIncludeTag(tmpDir)] })).toThrow(
|
|
||||||
/path traversal blocked/,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("supports nested !include in yaml files", async () => {
|
|
||||||
const subdir = join(tmpDir, "parts");
|
|
||||||
await mkdir(subdir, { recursive: true });
|
|
||||||
await writeFile(join(subdir, "inner.md"), "nested content");
|
|
||||||
await writeFile(join(tmpDir, "outer.yaml"), "value: !include parts/inner.md");
|
|
||||||
const yaml = "config: !include outer.yaml";
|
|
||||||
const result = parse(yaml, { customTags: [createIncludeTag(tmpDir)] });
|
|
||||||
expect(result.config).toEqual({ value: "nested content" });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
import { mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdLogClean, cmdLogList, cmdLogShow } from "../commands/log.js";
|
import { cmdLogClean, cmdLogList, cmdLogShow } from "../commands/log.js";
|
||||||
|
|
||||||
let storageRoot: string;
|
let storageRoot: string;
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import type { Target, WorkflowPayload } from "@uncaged/workflow-protocol";
|
import type { Target, WorkflowPayload } from "@uncaged/workflow-protocol";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
import { evaluate } from "../moderator/evaluate.js";
|
import { evaluate } from "../moderator/evaluate.js";
|
||||||
|
|
||||||
const solveIssueGraph: WorkflowPayload["graph"] = {
|
const solveIssueGraph: WorkflowPayload["graph"] = {
|
||||||
$START: {
|
$START: {
|
||||||
_: { role: "planner", prompt: "Start planning from the issue in the task.", location: null },
|
_: { role: "planner", prompt: "Start planning from the issue in the task." },
|
||||||
},
|
},
|
||||||
planner: {
|
planner: {
|
||||||
_: { role: "developer", prompt: "Implement the plan: {{plan}}", location: null },
|
_: { role: "developer", prompt: "Implement the plan: {{plan}}" },
|
||||||
},
|
},
|
||||||
developer: {
|
developer: {
|
||||||
_: { role: "reviewer", prompt: "Review the changes: {{summary}}", location: null },
|
_: { role: "reviewer", prompt: "Review the changes: {{summary}}" },
|
||||||
},
|
},
|
||||||
reviewer: {
|
reviewer: {
|
||||||
approved: { role: "$END", prompt: "Done.", location: null },
|
approved: { role: "$END", prompt: "Done." },
|
||||||
rejected: { role: "developer", prompt: "Fix: {{comments}}", location: null },
|
rejected: { role: "developer", prompt: "Fix: {{comments}}" },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,11 +24,7 @@ describe("evaluate", () => {
|
|||||||
const result = evaluate(solveIssueGraph, "$START", { $status: "_" });
|
const result = evaluate(solveIssueGraph, "$START", { $status: "_" });
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: {
|
value: { role: "planner", prompt: "Start planning from the issue in the task." },
|
||||||
role: "planner",
|
|
||||||
prompt: "Start planning from the issue in the task.",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,7 +35,7 @@ describe("evaluate", () => {
|
|||||||
});
|
});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: { role: "developer", prompt: "Fix: missing tests", location: null },
|
value: { role: "developer", prompt: "Fix: missing tests" },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,50 +43,7 @@ describe("evaluate", () => {
|
|||||||
const result = evaluate(solveIssueGraph, "reviewer", { $status: "approved" });
|
const result = evaluate(solveIssueGraph, "reviewer", { $status: "approved" });
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: { role: "$END", prompt: "Done.", location: null },
|
value: { role: "$END", prompt: "Done." },
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("status-based routing (needs input → $SUSPEND)", () => {
|
|
||||||
const graph: Record<string, Record<string, Target>> = {
|
|
||||||
...solveIssueGraph,
|
|
||||||
reviewer: {
|
|
||||||
...solveIssueGraph.reviewer,
|
|
||||||
needs_input: { role: "$SUSPEND", prompt: "Waiting for user input.", location: null },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const result = evaluate(graph, "reviewer", { $status: "needs_input" });
|
|
||||||
expect(result).toEqual({
|
|
||||||
ok: true,
|
|
||||||
value: {
|
|
||||||
action: "suspend",
|
|
||||||
suspendedRole: "reviewer",
|
|
||||||
prompt: "Waiting for user input.",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("$SUSPEND prompt template renders mustache variables", () => {
|
|
||||||
const graph: Record<string, Record<string, Target>> = {
|
|
||||||
reviewer: {
|
|
||||||
needs_input: {
|
|
||||||
role: "$SUSPEND",
|
|
||||||
prompt: "Please clarify: {{{question}}}",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const result = evaluate(graph, "reviewer", {
|
|
||||||
$status: "needs_input",
|
|
||||||
question: "Which API endpoint?",
|
|
||||||
});
|
|
||||||
expect(result).toEqual({
|
|
||||||
ok: true,
|
|
||||||
value: {
|
|
||||||
action: "suspend",
|
|
||||||
suspendedRole: "reviewer",
|
|
||||||
prompt: "Please clarify: Which API endpoint?",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -117,11 +70,7 @@ describe("evaluate", () => {
|
|||||||
});
|
});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: {
|
value: { role: "developer", prompt: "Implement the plan: Add auth middleware" },
|
||||||
role: "developer",
|
|
||||||
prompt: "Implement the plan: Add auth middleware",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,14 +81,14 @@ describe("evaluate", () => {
|
|||||||
});
|
});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: { role: "developer", prompt: 'Fix: use <T> & "Result<T, E>" types', location: null },
|
value: { role: "developer", prompt: 'Fix: use <T> & "Result<T, E>" types' },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("triple mustache also works for unescaped output", () => {
|
test("triple mustache also works for unescaped output", () => {
|
||||||
const graph: Record<string, Record<string, Target>> = {
|
const graph: Record<string, Record<string, Target>> = {
|
||||||
reviewer: {
|
reviewer: {
|
||||||
_: { role: "developer", prompt: "Fix: {{{comments}}}", location: null },
|
_: { role: "developer", prompt: "Fix: {{{comments}}}" },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const result = evaluate(graph, "reviewer", {
|
const result = evaluate(graph, "reviewer", {
|
||||||
@@ -148,7 +97,7 @@ describe("evaluate", () => {
|
|||||||
});
|
});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: { role: "developer", prompt: "Fix: <script>alert(1)</script>", location: null },
|
value: { role: "developer", prompt: "Fix: <script>alert(1)</script>" },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -158,11 +107,7 @@ describe("evaluate", () => {
|
|||||||
});
|
});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: {
|
value: { role: "developer", prompt: "Implement the plan: Add auth middleware" },
|
||||||
role: "developer",
|
|
||||||
prompt: "Implement the plan: Add auth middleware",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -172,7 +117,6 @@ describe("evaluate", () => {
|
|||||||
_: {
|
_: {
|
||||||
role: "developer",
|
role: "developer",
|
||||||
prompt: "Address: {{review.comments}}",
|
prompt: "Address: {{review.comments}}",
|
||||||
location: null,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -182,7 +126,7 @@ describe("evaluate", () => {
|
|||||||
});
|
});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: { role: "developer", prompt: "Address: refactor the handler", location: null },
|
value: { role: "developer", prompt: "Address: refactor the handler" },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
const originalExit = process.exit;
|
|
||||||
|
|
||||||
process.exit = ((code?: number) => {
|
|
||||||
throw new Error(`process.exit(${code ?? 1})`);
|
|
||||||
}) as typeof process.exit;
|
|
||||||
|
|
||||||
export { originalExit };
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { execFileSync } from "node:child_process";
|
|
||||||
import { dirname, join } from "node:path";
|
|
||||||
import { fileURLToPath } from "node:url";
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
||||||
|
|
||||||
import {
|
|
||||||
cmdPromptAdapter,
|
|
||||||
cmdPromptAuthor,
|
|
||||||
cmdPromptDeveloper,
|
|
||||||
cmdPromptList,
|
|
||||||
cmdPromptSetup,
|
|
||||||
cmdPromptUsage,
|
|
||||||
cmdPromptUser,
|
|
||||||
} from "../commands/prompt.js";
|
|
||||||
|
|
||||||
describe("prompt commands", () => {
|
|
||||||
test("prompt list returns all prompt names", () => {
|
|
||||||
const result = cmdPromptList();
|
|
||||||
expect(result).toBeInstanceOf(Array);
|
|
||||||
expect(result).toContain("user");
|
|
||||||
expect(result).toContain("author");
|
|
||||||
expect(result).toContain("developer");
|
|
||||||
expect(result).toContain("adapter");
|
|
||||||
for (const name of result) {
|
|
||||||
expect(name).toMatch(/^\S+$/);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prompt user returns non-empty markdown string", () => {
|
|
||||||
const result = cmdPromptUser();
|
|
||||||
expect(typeof result).toBe("string");
|
|
||||||
expect(result).toContain("uwf");
|
|
||||||
expect(result).toContain("thread");
|
|
||||||
expect(result).toContain("workflow");
|
|
||||||
expect(result).toContain("Quick Start");
|
|
||||||
expect(result.length).toBeGreaterThan(500);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prompt author returns non-empty markdown string", () => {
|
|
||||||
const result = cmdPromptAuthor();
|
|
||||||
expect(typeof result).toBe("string");
|
|
||||||
expect(result).toContain("frontmatter");
|
|
||||||
expect(result).toContain("graph");
|
|
||||||
expect(result).toContain("$START");
|
|
||||||
expect(result).toContain("$END");
|
|
||||||
expect(result).toContain("$status");
|
|
||||||
expect(result.length).toBeGreaterThan(500);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prompt developer returns non-empty markdown string", () => {
|
|
||||||
const result = cmdPromptDeveloper();
|
|
||||||
expect(typeof result).toBe("string");
|
|
||||||
expect(result).toContain("Monorepo");
|
|
||||||
expect(result).toContain("CAS");
|
|
||||||
expect(result).toContain("Biome");
|
|
||||||
expect(result.length).toBeGreaterThan(500);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prompt adapter returns non-empty markdown string", () => {
|
|
||||||
const result = cmdPromptAdapter();
|
|
||||||
expect(typeof result).toBe("string");
|
|
||||||
expect(result).toContain("createAgent");
|
|
||||||
expect(result).toContain("AgentContext");
|
|
||||||
expect(result).toContain("frontmatter");
|
|
||||||
expect(result.length).toBeGreaterThan(500);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prompt usage combines all references", () => {
|
|
||||||
const result = cmdPromptUsage();
|
|
||||||
expect(typeof result).toBe("string");
|
|
||||||
expect(result).toContain("User Reference");
|
|
||||||
expect(result).toContain("Author Reference");
|
|
||||||
expect(result).toContain("Developer Reference");
|
|
||||||
expect(result).toContain("Adapter Reference");
|
|
||||||
expect(result).toContain("---");
|
|
||||||
expect(result.length).toBeGreaterThan(2000);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prompt setup returns setup instructions", () => {
|
|
||||||
const result = cmdPromptSetup();
|
|
||||||
expect(typeof result).toBe("string");
|
|
||||||
expect(result).toContain("uwf Skill Setup");
|
|
||||||
expect(result).toContain("uwf prompt usage");
|
|
||||||
expect(result).toContain("uwf prompt setup");
|
|
||||||
expect(result).toContain("SKILL.md");
|
|
||||||
expect(result).toContain("version");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prompt help subcommand is suppressed", () => {
|
|
||||||
const output = execFileSync("bun", ["src/cli.ts", "prompt", "--help"], {
|
|
||||||
cwd: join(__dirname, "..", ".."),
|
|
||||||
encoding: "utf-8",
|
|
||||||
env: { ...process.env, PATH: `/opt/homebrew/bin:${process.env.PATH}` },
|
|
||||||
});
|
|
||||||
expect(output).not.toMatch(/help\s+\[command\]/i);
|
|
||||||
expect(output).toContain("usage");
|
|
||||||
expect(output).toContain("setup");
|
|
||||||
expect(output).toContain("user");
|
|
||||||
expect(output).toContain("author");
|
|
||||||
expect(output).toContain("developer");
|
|
||||||
expect(output).toContain("adapter");
|
|
||||||
expect(output).toContain("list");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdtemp, rm } from "node:fs/promises";
|
import { mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { resolveHeadHash } from "../commands/shared.js";
|
import { resolveHeadHash } from "../commands/shared.js";
|
||||||
import { appendThreadHistory, saveThreadsIndex } from "../store.js";
|
import { appendThreadHistory, saveThreadsIndex } from "../store.js";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import { mkdtemp, rm } from "node:fs/promises";
|
import { mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||||
import { parse } from "yaml";
|
import { parse } from "yaml";
|
||||||
import { _agentNameFromBinary, _printAgentMenu, cmdSetup } from "../commands/setup.js";
|
import { _agentNameFromBinary, _printAgentMenu, cmdSetup } from "../commands/setup.js";
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ describe("_agentNameFromBinary", () => {
|
|||||||
describe("_printAgentMenu", () => {
|
describe("_printAgentMenu", () => {
|
||||||
test("prints known agents with labels", () => {
|
test("prints known agents with labels", () => {
|
||||||
const logs: string[] = [];
|
const logs: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((...args: unknown[]) => {
|
vi.spyOn(console, "log").mockImplementation((...args: unknown[]) => {
|
||||||
logs.push(args.join(" "));
|
logs.push(args.join(" "));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -40,12 +40,12 @@ describe("_printAgentMenu", () => {
|
|||||||
expect(logs.some((l) => l.includes("Hermes"))).toBe(true);
|
expect(logs.some((l) => l.includes("Hermes"))).toBe(true);
|
||||||
expect(logs.some((l) => l.includes("Claude Code"))).toBe(true);
|
expect(logs.some((l) => l.includes("Claude Code"))).toBe(true);
|
||||||
|
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("prints unknown agents with binary name as label", () => {
|
test("prints unknown agents with binary name as label", () => {
|
||||||
const logs: string[] = [];
|
const logs: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((...args: unknown[]) => {
|
vi.spyOn(console, "log").mockImplementation((...args: unknown[]) => {
|
||||||
logs.push(args.join(" "));
|
logs.push(args.join(" "));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ describe("_printAgentMenu", () => {
|
|||||||
|
|
||||||
expect(logs.some((l) => l.includes("uwf-custom-agent"))).toBe(true);
|
expect(logs.some((l) => l.includes("uwf-custom-agent"))).toBe(true);
|
||||||
|
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ describe("cmdSetup agent configuration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
await rm(storageRoot, { recursive: true, force: true });
|
await rm(storageRoot, { recursive: true, force: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,7 +80,9 @@ describe("cmdSetup agent configuration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("defaults to hermes agent when no agent specified", async () => {
|
test("defaults to hermes agent when no agent specified", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({}), { status: 200 }),
|
||||||
|
);
|
||||||
|
|
||||||
const result = await cmdSetup(baseArgs());
|
const result = await cmdSetup(baseArgs());
|
||||||
|
|
||||||
@@ -91,7 +93,9 @@ describe("cmdSetup agent configuration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("writes specified agent as default", async () => {
|
test("writes specified agent as default", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({}), { status: 200 }),
|
||||||
|
);
|
||||||
|
|
||||||
const result = await cmdSetup({ ...baseArgs(), agent: "claude-code" });
|
const result = await cmdSetup({ ...baseArgs(), agent: "claude-code" });
|
||||||
|
|
||||||
@@ -102,7 +106,9 @@ describe("cmdSetup agent configuration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("preserves existing agents when adding new one", async () => {
|
test("preserves existing agents when adding new one", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({}), { status: 200 }),
|
||||||
|
);
|
||||||
|
|
||||||
// First setup with hermes
|
// First setup with hermes
|
||||||
await cmdSetup(baseArgs());
|
await cmdSetup(baseArgs());
|
||||||
@@ -116,7 +122,9 @@ describe("cmdSetup agent configuration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("updates defaultAgent on re-run with different agent", async () => {
|
test("updates defaultAgent on re-run with different agent", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({}), { status: 200 }),
|
||||||
|
);
|
||||||
|
|
||||||
await cmdSetup(baseArgs());
|
await cmdSetup(baseArgs());
|
||||||
const config1 = parse(readFileSync(join(storageRoot, "config.yaml"), "utf8"));
|
const config1 = parse(readFileSync(join(storageRoot, "config.yaml"), "utf8"));
|
||||||
@@ -128,7 +136,9 @@ describe("cmdSetup agent configuration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("normalizes agent name with uwf- prefix to bare name", async () => {
|
test("normalizes agent name with uwf- prefix to bare name", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({}), { status: 200 }),
|
||||||
|
);
|
||||||
|
|
||||||
const result = await cmdSetup({ ...baseArgs(), agent: "uwf-hermes" });
|
const result = await cmdSetup({ ...baseArgs(), agent: "uwf-hermes" });
|
||||||
|
|
||||||
@@ -141,7 +151,9 @@ describe("cmdSetup agent configuration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("normalizes uwf-claude-code to claude-code", async () => {
|
test("normalizes uwf-claude-code to claude-code", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({}), { status: 200 }),
|
||||||
|
);
|
||||||
|
|
||||||
const result = await cmdSetup({ ...baseArgs(), agent: "uwf-claude-code" });
|
const result = await cmdSetup({ ...baseArgs(), agent: "uwf-claude-code" });
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { afterEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
||||||
import { mkdirSync, writeFileSync } from "node:fs";
|
import { mkdirSync, writeFileSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||||
import {
|
import {
|
||||||
_discoverAgents,
|
_discoverAgents,
|
||||||
_isBackspace,
|
_isBackspace,
|
||||||
@@ -178,7 +178,7 @@ describe("_isBackspace", () => {
|
|||||||
|
|
||||||
describe("_printProviderMenu", () => {
|
describe("_printProviderMenu", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
const providers = [
|
const providers = [
|
||||||
@@ -188,7 +188,7 @@ describe("_printProviderMenu", () => {
|
|||||||
|
|
||||||
test("prints correct number of lines (one per provider + custom)", () => {
|
test("prints correct number of lines (one per provider + custom)", () => {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
lines.push(msg);
|
lines.push(msg);
|
||||||
});
|
});
|
||||||
_printProviderMenu(providers);
|
_printProviderMenu(providers);
|
||||||
@@ -198,7 +198,7 @@ describe("_printProviderMenu", () => {
|
|||||||
|
|
||||||
test("custom option number = providers.length + 1", () => {
|
test("custom option number = providers.length + 1", () => {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
lines.push(msg);
|
lines.push(msg);
|
||||||
});
|
});
|
||||||
_printProviderMenu(providers);
|
_printProviderMenu(providers);
|
||||||
@@ -208,7 +208,7 @@ describe("_printProviderMenu", () => {
|
|||||||
|
|
||||||
test("each provider line contains its label and baseUrl", () => {
|
test("each provider line contains its label and baseUrl", () => {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
lines.push(msg);
|
lines.push(msg);
|
||||||
});
|
});
|
||||||
_printProviderMenu(providers);
|
_printProviderMenu(providers);
|
||||||
@@ -294,12 +294,12 @@ describe("_resolveModelChoice", () => {
|
|||||||
|
|
||||||
describe("_printModelMenu", () => {
|
describe("_printModelMenu", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("prints all models — each model name appears in output", () => {
|
test("prints all models — each model name appears in output", () => {
|
||||||
const output: string[] = [];
|
const output: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
output.push(msg);
|
output.push(msg);
|
||||||
});
|
});
|
||||||
const models = ["model-a", "model-b", "model-c"];
|
const models = ["model-a", "model-b", "model-c"];
|
||||||
@@ -312,7 +312,7 @@ describe("_printModelMenu", () => {
|
|||||||
|
|
||||||
test("single column when termCols is very small", () => {
|
test("single column when termCols is very small", () => {
|
||||||
const output: string[] = [];
|
const output: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
output.push(msg);
|
output.push(msg);
|
||||||
});
|
});
|
||||||
_printModelMenu(["a", "b", "c"], 1);
|
_printModelMenu(["a", "b", "c"], 1);
|
||||||
@@ -322,7 +322,7 @@ describe("_printModelMenu", () => {
|
|||||||
|
|
||||||
test("wide terminal fits multiple columns", () => {
|
test("wide terminal fits multiple columns", () => {
|
||||||
const output: string[] = [];
|
const output: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
output.push(msg);
|
output.push(msg);
|
||||||
});
|
});
|
||||||
const models = Array.from({ length: 6 }, (_, i) => `m${i}`);
|
const models = Array.from({ length: 6 }, (_, i) => `m${i}`);
|
||||||
@@ -338,12 +338,12 @@ describe("_printModelMenu", () => {
|
|||||||
|
|
||||||
describe("_printValidationResult", () => {
|
describe("_printValidationResult", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("ok=true prints success message containing '✓'", () => {
|
test("ok=true prints success message containing '✓'", () => {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
lines.push(msg);
|
lines.push(msg);
|
||||||
});
|
});
|
||||||
_printValidationResult({ ok: true, error: null });
|
_printValidationResult({ ok: true, error: null });
|
||||||
@@ -352,7 +352,7 @@ describe("_printValidationResult", () => {
|
|||||||
|
|
||||||
test("ok=false prints warning message containing '⚠'", () => {
|
test("ok=false prints warning message containing '⚠'", () => {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
lines.push(msg);
|
lines.push(msg);
|
||||||
});
|
});
|
||||||
_printValidationResult({ ok: false, error: "HTTP 401" });
|
_printValidationResult({ ok: false, error: "HTTP 401" });
|
||||||
@@ -361,7 +361,7 @@ describe("_printValidationResult", () => {
|
|||||||
|
|
||||||
test("ok=false includes the error string in output", () => {
|
test("ok=false includes the error string in output", () => {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
spyOn(console, "log").mockImplementation((msg: string) => {
|
vi.spyOn(console, "log").mockImplementation((msg: string) => {
|
||||||
lines.push(msg);
|
lines.push(msg);
|
||||||
});
|
});
|
||||||
_printValidationResult({ ok: false, error: "HTTP 401" });
|
_printValidationResult({ ok: false, error: "HTTP 401" });
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
||||||
import { mkdtemp, rm } from "node:fs/promises";
|
import { mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||||
import { cmdSetup, validateModel } from "../commands/setup.js";
|
import { cmdSetup, validateModel } from "../commands/setup.js";
|
||||||
|
|
||||||
describe("validateModel", () => {
|
describe("validateModel", () => {
|
||||||
@@ -10,18 +10,18 @@ describe("validateModel", () => {
|
|||||||
const MODEL = "test-model";
|
const MODEL = "test-model";
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("success path — returns ok on 200", async () => {
|
test("success path — returns ok on 200", async () => {
|
||||||
const mockFetch = spyOn(globalThis, "fetch").mockResolvedValue(
|
const mockFetch = vi
|
||||||
new Response(JSON.stringify({}), { status: 200 }),
|
.spyOn(globalThis, "fetch")
|
||||||
);
|
.mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
||||||
|
|
||||||
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
||||||
|
|
||||||
expect(result).toEqual({ ok: true, value: undefined });
|
expect(result).toEqual({ ok: true, value: undefined });
|
||||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
expect(mockFetch).toHaveBeenCalledOnce();
|
||||||
|
|
||||||
const [url, opts] = mockFetch.mock.calls[0]!;
|
const [url, opts] = mockFetch.mock.calls[0]!;
|
||||||
expect(url).toBe(`${BASE_URL}/chat/completions`);
|
expect(url).toBe(`${BASE_URL}/chat/completions`);
|
||||||
@@ -37,7 +37,7 @@ describe("validateModel", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("HTTP 401 — returns error containing 401", async () => {
|
test("HTTP 401 — returns error containing 401", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }),
|
new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ describe("validateModel", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("HTTP 404 — returns error containing 404", async () => {
|
test("HTTP 404 — returns error containing 404", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
new Response("Not Found", { status: 404, statusText: "Not Found" }),
|
new Response("Not Found", { status: 404, statusText: "Not Found" }),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ describe("validateModel", () => {
|
|||||||
|
|
||||||
test("network timeout — returns error mentioning timeout", async () => {
|
test("network timeout — returns error mentioning timeout", async () => {
|
||||||
const err = new DOMException("signal timed out", "AbortError");
|
const err = new DOMException("signal timed out", "AbortError");
|
||||||
spyOn(globalThis, "fetch").mockRejectedValue(err);
|
vi.spyOn(globalThis, "fetch").mockRejectedValue(err);
|
||||||
|
|
||||||
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ describe("validateModel", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("network error (DNS/connection) — returns error mentioning connectivity", async () => {
|
test("network error (DNS/connection) — returns error mentioning connectivity", async () => {
|
||||||
spyOn(globalThis, "fetch").mockRejectedValue(new TypeError("fetch failed"));
|
vi.spyOn(globalThis, "fetch").mockRejectedValue(new TypeError("fetch failed"));
|
||||||
|
|
||||||
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
||||||
|
|
||||||
@@ -86,9 +86,9 @@ describe("validateModel", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("request body correctness", async () => {
|
test("request body correctness", async () => {
|
||||||
const mockFetch = spyOn(globalThis, "fetch").mockResolvedValue(
|
const mockFetch = vi
|
||||||
new Response(JSON.stringify({}), { status: 200 }),
|
.spyOn(globalThis, "fetch")
|
||||||
);
|
.mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
||||||
|
|
||||||
await validateModel(BASE_URL, API_KEY, "my-special-model");
|
await validateModel(BASE_URL, API_KEY, "my-special-model");
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ describe("cmdSetup with validation", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
mock.restore();
|
vi.restoreAllMocks();
|
||||||
await rm(storageRoot, { recursive: true, force: true });
|
await rm(storageRoot, { recursive: true, force: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,7 +122,9 @@ describe("cmdSetup with validation", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("includes validation result on success", async () => {
|
test("includes validation result on success", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
|
new Response(JSON.stringify({}), { status: 200 }),
|
||||||
|
);
|
||||||
|
|
||||||
const result = await cmdSetup(setupArgs());
|
const result = await cmdSetup(setupArgs());
|
||||||
|
|
||||||
@@ -132,7 +134,7 @@ describe("cmdSetup with validation", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("includes validation failure — config still saved", async () => {
|
test("includes validation failure — config still saved", async () => {
|
||||||
spyOn(globalThis, "fetch").mockResolvedValue(
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||||
new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }),
|
new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
import { execFileSync } from "node:child_process";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
import {
|
||||||
|
cmdSkillActor,
|
||||||
|
cmdSkillAdapter,
|
||||||
|
cmdSkillArchitecture,
|
||||||
|
cmdSkillAuthor,
|
||||||
|
cmdSkillCli,
|
||||||
|
cmdSkillDeveloper,
|
||||||
|
cmdSkillList,
|
||||||
|
cmdSkillModerator,
|
||||||
|
cmdSkillUser,
|
||||||
|
cmdSkillYaml,
|
||||||
|
} from "../commands/skill.js";
|
||||||
|
|
||||||
|
describe("skill commands", () => {
|
||||||
|
test("skill list returns all skill names", () => {
|
||||||
|
const result = cmdSkillList();
|
||||||
|
expect(result).toBeInstanceOf(Array);
|
||||||
|
expect(result).toContain("cli");
|
||||||
|
expect(result).toContain("architecture");
|
||||||
|
expect(result).toContain("yaml");
|
||||||
|
expect(result).toContain("moderator");
|
||||||
|
expect(result).toContain("actor");
|
||||||
|
expect(result).toContain("user");
|
||||||
|
expect(result).toContain("author");
|
||||||
|
expect(result).toContain("developer");
|
||||||
|
expect(result).toContain("adapter");
|
||||||
|
for (const name of result) {
|
||||||
|
expect(name).toMatch(/^\S+$/);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill architecture returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillArchitecture();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("CAS");
|
||||||
|
expect(result).toContain("Thread");
|
||||||
|
expect(result).toContain("Workflow");
|
||||||
|
expect(result).toContain("Step");
|
||||||
|
expect(result.length).toBeGreaterThan(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill yaml returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillYaml();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("roles");
|
||||||
|
expect(result).toContain("graph");
|
||||||
|
expect(result).toContain("frontmatter");
|
||||||
|
expect(result.length).toBeGreaterThan(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill moderator returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillModerator();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("routing");
|
||||||
|
expect(result).toContain("status");
|
||||||
|
expect(result.length).toBeGreaterThan(200);
|
||||||
|
// Check for edge or graph
|
||||||
|
expect(result).toMatch(/edge|graph/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill cli returns CLI reference markdown", () => {
|
||||||
|
const result = cmdSkillCli();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("uwf");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill actor returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillActor();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("frontmatter");
|
||||||
|
expect(result).toContain("CAS");
|
||||||
|
expect(result).toContain("status");
|
||||||
|
expect(result.length).toBeGreaterThan(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill user returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillUser();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("uwf");
|
||||||
|
expect(result).toContain("thread");
|
||||||
|
expect(result).toContain("workflow");
|
||||||
|
expect(result).toContain("Quick Start");
|
||||||
|
expect(result.length).toBeGreaterThan(500);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill author returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillAuthor();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("frontmatter");
|
||||||
|
expect(result).toContain("graph");
|
||||||
|
expect(result).toContain("$START");
|
||||||
|
expect(result).toContain("$END");
|
||||||
|
expect(result).toContain("$status");
|
||||||
|
expect(result.length).toBeGreaterThan(500);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill developer returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillDeveloper();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("Monorepo");
|
||||||
|
expect(result).toContain("CAS");
|
||||||
|
expect(result).toContain("Biome");
|
||||||
|
expect(result.length).toBeGreaterThan(500);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill adapter returns non-empty markdown string", () => {
|
||||||
|
const result = cmdSkillAdapter();
|
||||||
|
expect(typeof result).toBe("string");
|
||||||
|
expect(result).toContain("createAgent");
|
||||||
|
expect(result).toContain("AgentContext");
|
||||||
|
expect(result).toContain("frontmatter");
|
||||||
|
expect(result.length).toBeGreaterThan(500);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skill help subcommand is suppressed", () => {
|
||||||
|
const output = execFileSync("bun", ["src/cli.ts", "skill", "--help"], {
|
||||||
|
cwd: join(__dirname, "..", ".."),
|
||||||
|
encoding: "utf-8",
|
||||||
|
env: { ...process.env, PATH: `/opt/homebrew/bin:${process.env.PATH}` },
|
||||||
|
});
|
||||||
|
expect(output).not.toMatch(/help\s+\[command\]/i);
|
||||||
|
expect(output).toContain("cli");
|
||||||
|
expect(output).toContain("architecture");
|
||||||
|
expect(output).toContain("yaml");
|
||||||
|
expect(output).toContain("moderator");
|
||||||
|
expect(output).toContain("actor");
|
||||||
|
expect(output).toContain("user");
|
||||||
|
expect(output).toContain("author");
|
||||||
|
expect(output).toContain("developer");
|
||||||
|
expect(output).toContain("adapter");
|
||||||
|
expect(output).toContain("list");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { WorkflowPayload } from "@uncaged/workflow-protocol";
|
import type { WorkflowPayload } from "@uncaged/workflow-protocol";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
import { parse } from "yaml";
|
import { parse } from "yaml";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test: Issue #474 - tea pr create fails in git worktree directories
|
* Test: Issue #474 - tea pr create fails in git worktree directories
|
||||||
*
|
*
|
||||||
* This test verifies that the solve-issue workflow's committer role
|
* This test verifies that the solve-issue workflow's committer role
|
||||||
* uses direct Gitea API calls via curl instead of tea pr create,
|
* includes the --repo flag when running tea pr create, which fixes
|
||||||
* which fixes the "path segment [0] is empty" error in worktree directories.
|
* the "path segment [0] is empty" error in worktree directories.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
describe("solve-issue workflow: Gitea API PR creation", () => {
|
describe("solve-issue workflow: tea pr create worktree fix", () => {
|
||||||
// Navigate up from packages/cli-workflow/src/__tests__ to repo root
|
// Navigate up from packages/cli-workflow/src/__tests__ to repo root
|
||||||
const workflowPath = join(
|
const workflowPath = join(
|
||||||
import.meta.dirname,
|
import.meta.dirname,
|
||||||
@@ -24,7 +24,7 @@ describe("solve-issue workflow: Gitea API PR creation", () => {
|
|||||||
"solve-issue.yaml",
|
"solve-issue.yaml",
|
||||||
);
|
);
|
||||||
|
|
||||||
test("committer procedure should use curl API instead of tea pr create", async () => {
|
test("committer procedure should include --repo flag in tea pr create command", async () => {
|
||||||
const yamlContent = await readFile(workflowPath, "utf-8");
|
const yamlContent = await readFile(workflowPath, "utf-8");
|
||||||
const workflow = parse(yamlContent) as WorkflowPayload;
|
const workflow = parse(yamlContent) as WorkflowPayload;
|
||||||
|
|
||||||
@@ -32,38 +32,43 @@ describe("solve-issue workflow: Gitea API PR creation", () => {
|
|||||||
const committerProcedure = workflow.roles.committer?.procedure;
|
const committerProcedure = workflow.roles.committer?.procedure;
|
||||||
expect(committerProcedure).toBeDefined();
|
expect(committerProcedure).toBeDefined();
|
||||||
|
|
||||||
// Verify the procedure uses curl API, not tea pr create
|
// Verify the procedure includes tea pr create with --repo flag
|
||||||
expect(committerProcedure).toContain("curl");
|
expect(committerProcedure).toContain("tea pr create");
|
||||||
expect(committerProcedure).toContain("api/v1/repos");
|
expect(committerProcedure).toContain("--repo");
|
||||||
expect(committerProcedure).toContain("/pulls");
|
|
||||||
|
|
||||||
// Verify it explicitly warns against tea pr create
|
// Verify the --repo flag appears before or together with tea pr create
|
||||||
expect(committerProcedure).toMatch(/do NOT use.*tea pr create/i);
|
// This ensures the command is: tea pr create --repo <owner/repo> ...
|
||||||
|
const teaPrCreateMatch = committerProcedure?.match(/tea pr create[^\n]*/);
|
||||||
|
expect(teaPrCreateMatch).not.toBeNull();
|
||||||
|
|
||||||
|
if (teaPrCreateMatch) {
|
||||||
|
const teaCommandLine = teaPrCreateMatch[0];
|
||||||
|
expect(teaCommandLine).toContain("--repo");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("committer procedure should reference repoRemote from task prompt", async () => {
|
test("committer procedure should mention repo extraction from git remote", async () => {
|
||||||
const yamlContent = await readFile(workflowPath, "utf-8");
|
const yamlContent = await readFile(workflowPath, "utf-8");
|
||||||
const workflow = parse(yamlContent) as WorkflowPayload;
|
const workflow = parse(yamlContent) as WorkflowPayload;
|
||||||
|
|
||||||
const committerProcedure = workflow.roles.committer?.procedure;
|
const committerProcedure = workflow.roles.committer?.procedure;
|
||||||
expect(committerProcedure).toBeDefined();
|
expect(committerProcedure).toBeDefined();
|
||||||
|
|
||||||
// Verify the procedure mentions repoRemote is provided in task prompt
|
// Verify the procedure mentions extracting repo info from git remote
|
||||||
expect(committerProcedure).toMatch(/repo remote.*provided.*task prompt/i);
|
// This ensures fallback logic is documented
|
||||||
expect(committerProcedure).toMatch(/owner\/repo/i);
|
expect(committerProcedure).toMatch(/git remote/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("committer procedure should include error handling for curl failures", async () => {
|
test("committer procedure should include error handling for tea failures", async () => {
|
||||||
const yamlContent = await readFile(workflowPath, "utf-8");
|
const yamlContent = await readFile(workflowPath, "utf-8");
|
||||||
const workflow = parse(yamlContent) as WorkflowPayload;
|
const workflow = parse(yamlContent) as WorkflowPayload;
|
||||||
|
|
||||||
const committerProcedure = workflow.roles.committer?.procedure;
|
const committerProcedure = workflow.roles.committer?.procedure;
|
||||||
expect(committerProcedure).toBeDefined();
|
expect(committerProcedure).toBeDefined();
|
||||||
|
|
||||||
// Verify the procedure includes error handling guidance for curl
|
// Verify the procedure includes error handling guidance
|
||||||
// This ensures we capture failures and provide actionable output
|
// This ensures we capture failures and provide actionable output
|
||||||
expect(committerProcedure).toMatch(/error|fail/i);
|
expect(committerProcedure).toMatch(/error|fail/i);
|
||||||
expect(committerProcedure).toContain("hook_failed");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("workflow should be parseable as valid WorkflowPayload", async () => {
|
test("workflow should be parseable as valid WorkflowPayload", async () => {
|
||||||
@@ -93,51 +98,9 @@ describe("solve-issue workflow: Gitea API PR creation", () => {
|
|||||||
expect(frontmatter).toBeDefined();
|
expect(frontmatter).toBeDefined();
|
||||||
expect(frontmatter?.oneOf).toBeDefined();
|
expect(frontmatter?.oneOf).toBeDefined();
|
||||||
const committedVariant = frontmatter.oneOf.find(
|
const committedVariant = frontmatter.oneOf.find(
|
||||||
(v: any) => v.properties?.$status?.const === "committed",
|
(v: any) => v.properties?.["$status"]?.const === "committed",
|
||||||
);
|
);
|
||||||
expect(committedVariant).toBeDefined();
|
expect(committedVariant).toBeDefined();
|
||||||
expect(committedVariant.required).toContain("$status");
|
expect(committedVariant.required).toContain("$status");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("developer procedure should include mandatory verification step", async () => {
|
|
||||||
const yamlContent = await readFile(workflowPath, "utf-8");
|
|
||||||
const workflow = parse(yamlContent) as WorkflowPayload;
|
|
||||||
|
|
||||||
const developerProcedure = workflow.roles.developer?.procedure;
|
|
||||||
expect(developerProcedure).toBeDefined();
|
|
||||||
|
|
||||||
// Verify the procedure includes mandatory verification step
|
|
||||||
expect(developerProcedure).toContain("MANDATORY VERIFICATION");
|
|
||||||
expect(developerProcedure).toContain("git branch --show-current");
|
|
||||||
expect(developerProcedure).toContain("git status");
|
|
||||||
expect(developerProcedure).toMatch(/ls -la|verify.*exist/i);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("reviewer procedure should enforce worktree path verification", async () => {
|
|
||||||
const yamlContent = await readFile(workflowPath, "utf-8");
|
|
||||||
const workflow = parse(yamlContent) as WorkflowPayload;
|
|
||||||
|
|
||||||
const reviewerProcedure = workflow.roles.reviewer?.procedure;
|
|
||||||
expect(reviewerProcedure).toBeDefined();
|
|
||||||
|
|
||||||
// Verify the procedure includes critical enforcement
|
|
||||||
expect(reviewerProcedure).toContain("CRITICAL");
|
|
||||||
expect(reviewerProcedure).toMatch(/cd.*pwd/);
|
|
||||||
expect(reviewerProcedure).toContain(
|
|
||||||
"Do NOT report results without running the actual commands",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("developer procedure should include test debugging escalation", async () => {
|
|
||||||
const yamlContent = await readFile(workflowPath, "utf-8");
|
|
||||||
const workflow = parse(yamlContent) as WorkflowPayload;
|
|
||||||
|
|
||||||
const developerProcedure = workflow.roles.developer?.procedure;
|
|
||||||
expect(developerProcedure).toBeDefined();
|
|
||||||
|
|
||||||
// Verify the procedure includes test failure guidance
|
|
||||||
expect(developerProcedure).toMatch(/tests fail.*first run/i);
|
|
||||||
expect(developerProcedure).toMatch(/3 test cycles|after 3 attempts/i);
|
|
||||||
expect(developerProcedure).toContain("$status=failed");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* B-group tests: validate JSON parsing logic used by spawnAgent.
|
|
||||||
*
|
|
||||||
* We test the parsing logic inline since spawnAgent is a private function.
|
|
||||||
* These tests verify the contract: last line of stdout must be valid JSON
|
|
||||||
* with a valid stepHash CasRef.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const CASREF_PATTERN = /^[0-9A-HJ-NP-TV-Z]{13}$/;
|
|
||||||
|
|
||||||
function isCasRef(s: string): boolean {
|
|
||||||
return CASREF_PATTERN.test(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
type AdapterOutput = {
|
|
||||||
stepHash: string;
|
|
||||||
detailHash: string;
|
|
||||||
role: string;
|
|
||||||
frontmatter: Record<string, unknown>;
|
|
||||||
body: string;
|
|
||||||
startedAtMs: number;
|
|
||||||
completedAtMs: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
function parseAgentStdout(stdout: string): AdapterOutput {
|
|
||||||
const line = stdout.trim().split("\n").pop()?.trim() ?? "";
|
|
||||||
let parsed: unknown;
|
|
||||||
try {
|
|
||||||
parsed = JSON.parse(line);
|
|
||||||
} catch {
|
|
||||||
throw new Error(`agent stdout last line is not valid JSON: ${line || "(empty)"}`);
|
|
||||||
}
|
|
||||||
const obj = parsed as Record<string, unknown>;
|
|
||||||
if (
|
|
||||||
typeof obj !== "object" ||
|
|
||||||
obj === null ||
|
|
||||||
typeof obj.stepHash !== "string" ||
|
|
||||||
!isCasRef(obj.stepHash as string)
|
|
||||||
) {
|
|
||||||
throw new Error(`agent stdout JSON missing valid stepHash: ${line}`);
|
|
||||||
}
|
|
||||||
return obj as unknown as AdapterOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
const VALID_OUTPUT: AdapterOutput = {
|
|
||||||
stepHash: "0123456789ABC",
|
|
||||||
detailHash: "DEFGH12345678",
|
|
||||||
role: "planner",
|
|
||||||
frontmatter: { $status: "ready", plan: "somehash" },
|
|
||||||
body: "Plan body",
|
|
||||||
startedAtMs: 1000,
|
|
||||||
completedAtMs: 2000,
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("spawnAgent JSON parsing", () => {
|
|
||||||
test("B1. parses valid JSON from agent stdout", () => {
|
|
||||||
const stdout = `${JSON.stringify(VALID_OUTPUT)}\n`;
|
|
||||||
const result = parseAgentStdout(stdout);
|
|
||||||
expect(result.stepHash).toBe("0123456789ABC");
|
|
||||||
expect(result.detailHash).toBe("DEFGH12345678");
|
|
||||||
expect(result.role).toBe("planner");
|
|
||||||
expect(result.frontmatter).toEqual({ $status: "ready", plan: "somehash" });
|
|
||||||
expect(result.body).toBe("Plan body");
|
|
||||||
expect(result.startedAtMs).toBe(1000);
|
|
||||||
expect(result.completedAtMs).toBe(2000);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("B2. extracts stepHash for head pointer", () => {
|
|
||||||
const stdout = `${JSON.stringify(VALID_OUTPUT)}\n`;
|
|
||||||
const result = parseAgentStdout(stdout);
|
|
||||||
expect(result.stepHash).toBe("0123456789ABC");
|
|
||||||
expect(isCasRef(result.stepHash)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("B3. handles debug lines before JSON", () => {
|
|
||||||
const debugLines = "[debug] loading context...\n[debug] running agent...\n";
|
|
||||||
const stdout = `${debugLines + JSON.stringify(VALID_OUTPUT)}\n`;
|
|
||||||
const result = parseAgentStdout(stdout);
|
|
||||||
expect(result.stepHash).toBe("0123456789ABC");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("B4. rejects non-JSON last line", () => {
|
|
||||||
const stdout = "not-json-at-all\n";
|
|
||||||
expect(() => parseAgentStdout(stdout)).toThrow("not valid JSON");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("B5. rejects JSON missing stepHash", () => {
|
|
||||||
const incomplete = { detailHash: "DEFGH12345678", role: "planner" };
|
|
||||||
const stdout = `${JSON.stringify(incomplete)}\n`;
|
|
||||||
expect(() => parseAgentStdout(stdout)).toThrow("missing valid stepHash");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("B6. rejects JSON with invalid stepHash", () => {
|
|
||||||
const bad = { ...VALID_OUTPUT, stepHash: "not-a-hash" };
|
|
||||||
const stdout = `${JSON.stringify(bad)}\n`;
|
|
||||||
expect(() => parseAgentStdout(stdout)).toThrow("missing valid stepHash");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { bootstrap, putSchema } from "@ocas/core";
|
import { bootstrap, putSchema } from "@uncaged/json-cas";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
import type { CasRef } from "@uncaged/workflow-protocol";
|
import type { CasRef } from "@uncaged/workflow-protocol";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdStepRead } from "../commands/step.js";
|
import { cmdStepRead } from "../commands/step.js";
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
import { registerUwfSchemas } from "../schemas.js";
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ const DETAIL_SCHEMA = {
|
|||||||
turnCount: { type: "integer" as const },
|
turnCount: { type: "integer" as const },
|
||||||
turns: {
|
turns: {
|
||||||
type: "array" as const,
|
type: "array" as const,
|
||||||
items: { type: "string" as const, format: "ocas_ref" },
|
items: { type: "string" as const, format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
@@ -66,21 +66,13 @@ function generateContent(size: number, prefix = "Content"): string {
|
|||||||
// ── fixture ───────────────────────────────────────────────────────────────────
|
// ── fixture ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-step-read-test-"));
|
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-step-read-test-"));
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
await rm(tmpDir, { recursive: true, force: true });
|
||||||
// Restore original environment
|
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── step read tests ───────────────────────────────────────────────────────────
|
// ── step read tests ───────────────────────────────────────────────────────────
|
||||||
@@ -88,10 +80,7 @@ afterEach(async () => {
|
|||||||
describe("step read", () => {
|
describe("step read", () => {
|
||||||
test("test 1: basic single-step read with 3 turns", async () => {
|
test("test 1: basic single-step read with 3 turns", async () => {
|
||||||
const casDir = join(tmpDir, "cas");
|
const casDir = join(tmpDir, "cas");
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
const detailSchemas = await registerDetailSchemas(store);
|
const detailSchemas = await registerDetailSchemas(store);
|
||||||
@@ -157,11 +146,10 @@ describe("step read", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read step with large quota
|
// Read step with large quota
|
||||||
const markdown = await cmdStepRead(tmpDir, stepHash, 10000, false);
|
const markdown = await cmdStepRead(tmpDir, stepHash, 10000);
|
||||||
|
|
||||||
// Assert structure
|
// Assert structure
|
||||||
expect(markdown).toContain(`# Step ${stepHash}`);
|
expect(markdown).toContain(`# Step ${stepHash}`);
|
||||||
@@ -177,9 +165,7 @@ describe("step read", () => {
|
|||||||
|
|
||||||
test("test 2: quota enforcement - multiple turns", async () => {
|
test("test 2: quota enforcement - multiple turns", async () => {
|
||||||
const casDir = join(tmpDir, "cas");
|
const casDir = join(tmpDir, "cas");
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
const detailSchemas = await registerDetailSchemas(store);
|
const detailSchemas = await registerDetailSchemas(store);
|
||||||
@@ -245,11 +231,10 @@ describe("step read", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read step with limited quota (700 chars)
|
// Read step with limited quota (700 chars)
|
||||||
const markdown = await cmdStepRead(tmpDir, stepHash, 700, false);
|
const markdown = await cmdStepRead(tmpDir, stepHash, 700);
|
||||||
|
|
||||||
// Assert only most recent turns fit
|
// Assert only most recent turns fit
|
||||||
expect(markdown).toContain(`# Step ${stepHash}`);
|
expect(markdown).toContain(`# Step ${stepHash}`);
|
||||||
@@ -263,9 +248,7 @@ describe("step read", () => {
|
|||||||
|
|
||||||
test("test 3: minimal quota edge case - always show at least one turn", async () => {
|
test("test 3: minimal quota edge case - always show at least one turn", async () => {
|
||||||
const casDir = join(tmpDir, "cas");
|
const casDir = join(tmpDir, "cas");
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
const detailSchemas = await registerDetailSchemas(store);
|
const detailSchemas = await registerDetailSchemas(store);
|
||||||
@@ -327,11 +310,10 @@ describe("step read", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read step with minimal quota (1 char)
|
// Read step with minimal quota (1 char)
|
||||||
const markdown = await cmdStepRead(tmpDir, stepHash, 1, false);
|
const markdown = await cmdStepRead(tmpDir, stepHash, 1);
|
||||||
|
|
||||||
// Assert at least one turn is always shown
|
// Assert at least one turn is always shown
|
||||||
expect(markdown).toContain("LongTurn");
|
expect(markdown).toContain("LongTurn");
|
||||||
@@ -340,9 +322,7 @@ describe("step read", () => {
|
|||||||
|
|
||||||
test("test 4: step with no detail field", async () => {
|
test("test 4: step with no detail field", async () => {
|
||||||
const casDir = join(tmpDir, "cas");
|
const casDir = join(tmpDir, "cas");
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
|
|
||||||
@@ -385,11 +365,10 @@ describe("step read", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read step - should return metadata only (no error)
|
// Read step - should return metadata only (no error)
|
||||||
const markdown = await cmdStepRead(tmpDir, stepHash, 4000, false);
|
const markdown = await cmdStepRead(tmpDir, stepHash, 4000);
|
||||||
|
|
||||||
// Assert metadata is present
|
// Assert metadata is present
|
||||||
expect(markdown).toContain(`# Step ${stepHash}`);
|
expect(markdown).toContain(`# Step ${stepHash}`);
|
||||||
@@ -401,9 +380,7 @@ describe("step read", () => {
|
|||||||
|
|
||||||
test("test 5: step with detail but no turns array", async () => {
|
test("test 5: step with detail but no turns array", async () => {
|
||||||
const casDir = join(tmpDir, "cas");
|
const casDir = join(tmpDir, "cas");
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
await registerDetailSchemas(store);
|
await registerDetailSchemas(store);
|
||||||
@@ -464,11 +441,10 @@ describe("step read", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read step - should return metadata only (no error)
|
// Read step - should return metadata only (no error)
|
||||||
const markdown = await cmdStepRead(tmpDir, stepHash, 4000, false);
|
const markdown = await cmdStepRead(tmpDir, stepHash, 4000);
|
||||||
|
|
||||||
// Assert metadata is present
|
// Assert metadata is present
|
||||||
expect(markdown).toContain(`# Step ${stepHash}`);
|
expect(markdown).toContain(`# Step ${stepHash}`);
|
||||||
@@ -479,9 +455,7 @@ describe("step read", () => {
|
|||||||
|
|
||||||
test("test 6: displays role and tool calls in turn body", async () => {
|
test("test 6: displays role and tool calls in turn body", async () => {
|
||||||
const casDir = join(tmpDir, "cas");
|
const casDir = join(tmpDir, "cas");
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
const detailSchemas = await registerDetailSchemas(store);
|
const detailSchemas = await registerDetailSchemas(store);
|
||||||
@@ -541,10 +515,9 @@ describe("step read", () => {
|
|||||||
agent: "uwf-hermes",
|
agent: "uwf-hermes",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const markdown = await cmdStepRead(tmpDir, stepHash, 4000, false);
|
const markdown = await cmdStepRead(tmpDir, stepHash, 4000);
|
||||||
|
|
||||||
expect(markdown).toContain("**Turn role:** assistant");
|
expect(markdown).toContain("**Turn role:** assistant");
|
||||||
expect(markdown).toContain("**terminal**");
|
expect(markdown).toContain("**terminal**");
|
||||||
@@ -553,9 +526,7 @@ describe("step read", () => {
|
|||||||
|
|
||||||
test("test 7: turn content with special characters", async () => {
|
test("test 7: turn content with special characters", async () => {
|
||||||
const casDir = join(tmpDir, "cas");
|
const casDir = join(tmpDir, "cas");
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
const detailSchemas = await registerDetailSchemas(store);
|
const detailSchemas = await registerDetailSchemas(store);
|
||||||
@@ -617,11 +588,10 @@ describe("step read", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read step
|
// Read step
|
||||||
const markdown = await cmdStepRead(tmpDir, stepHash, 4000, false);
|
const markdown = await cmdStepRead(tmpDir, stepHash, 4000);
|
||||||
|
|
||||||
// Assert content is rendered correctly without corruption
|
// Assert content is rendered correctly without corruption
|
||||||
expect(markdown).toContain("`backticks`");
|
expect(markdown).toContain("`backticks`");
|
||||||
|
|||||||
@@ -1,372 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { bootstrap, type Hash, type JSONSchema, putSchema } from "@ocas/core";
|
|
||||||
import { createFsStore } from "@ocas/fs";
|
|
||||||
import type { CasRef, StepNodePayload } from "@uncaged/workflow-protocol";
|
|
||||||
import { cmdStepShow } from "../commands/step.js";
|
|
||||||
import { formatOutput } from "../format.js";
|
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
|
||||||
|
|
||||||
const TURN_SCHEMA: JSONSchema = {
|
|
||||||
title: "test-turn",
|
|
||||||
type: "object",
|
|
||||||
required: ["index", "role", "content"],
|
|
||||||
properties: {
|
|
||||||
index: { type: "integer" },
|
|
||||||
role: { type: "string", enum: ["assistant", "tool"] },
|
|
||||||
content: { type: "string" },
|
|
||||||
toolCalls: {
|
|
||||||
anyOf: [
|
|
||||||
{
|
|
||||||
type: "array",
|
|
||||||
items: {
|
|
||||||
type: "object",
|
|
||||||
required: ["name", "args"],
|
|
||||||
properties: {
|
|
||||||
name: { type: "string" },
|
|
||||||
args: { type: "string" },
|
|
||||||
},
|
|
||||||
additionalProperties: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ type: "null" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
additionalProperties: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
const DETAIL_SCHEMA: JSONSchema = {
|
|
||||||
title: "test-detail",
|
|
||||||
type: "object",
|
|
||||||
required: ["turns"],
|
|
||||||
properties: {
|
|
||||||
turns: {
|
|
||||||
type: "array",
|
|
||||||
items: { type: "string", format: "ocas_ref" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
additionalProperties: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
type TestSetup = {
|
|
||||||
store: ReturnType<typeof createFsStore>;
|
|
||||||
schemas: {
|
|
||||||
workflow: Hash;
|
|
||||||
startNode: Hash;
|
|
||||||
stepNode: Hash;
|
|
||||||
text: Hash;
|
|
||||||
};
|
|
||||||
turnType: Hash;
|
|
||||||
detailType: Hash;
|
|
||||||
};
|
|
||||||
|
|
||||||
async function setupTest(casDir: string): Promise<TestSetup> {
|
|
||||||
const store = createFsStore(casDir);
|
|
||||||
await bootstrap(store);
|
|
||||||
const schemas = await registerUwfSchemas(store);
|
|
||||||
const [turnType, detailType] = await Promise.all([
|
|
||||||
putSchema(store, TURN_SCHEMA),
|
|
||||||
putSchema(store, DETAIL_SCHEMA),
|
|
||||||
]);
|
|
||||||
return { store, schemas, turnType, detailType };
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createTestStep(
|
|
||||||
setup: TestSetup,
|
|
||||||
turnPayloads: Array<{
|
|
||||||
index: number;
|
|
||||||
role: string;
|
|
||||||
content: string;
|
|
||||||
toolCalls: Array<{ name: string; args: string }> | null;
|
|
||||||
}>,
|
|
||||||
): Promise<CasRef> {
|
|
||||||
const { store, schemas, turnType, detailType } = setup;
|
|
||||||
|
|
||||||
// Create turn nodes
|
|
||||||
const turnHashes: CasRef[] = [];
|
|
||||||
for (const payload of turnPayloads) {
|
|
||||||
const turnHash = await store.put(turnType, payload);
|
|
||||||
turnHashes.push(turnHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create detail node
|
|
||||||
const detailHash = await store.put(detailType, { turns: turnHashes });
|
|
||||||
|
|
||||||
// Create dummy start node
|
|
||||||
const startHash = await store.put(schemas.startNode, {
|
|
||||||
workflow: "0000000000000" as CasRef,
|
|
||||||
prompt: "test prompt",
|
|
||||||
cwd: "/tmp",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create dummy output node
|
|
||||||
const outputHash = await store.put(schemas.text, { $status: "done" });
|
|
||||||
|
|
||||||
// Create step node
|
|
||||||
const stepPayload: StepNodePayload = {
|
|
||||||
prev: null,
|
|
||||||
start: startHash,
|
|
||||||
role: "test-role",
|
|
||||||
agent: "test-agent",
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
edgePrompt: "",
|
|
||||||
startedAtMs: Date.now(),
|
|
||||||
completedAtMs: Date.now() + 1000,
|
|
||||||
assembledPrompt: null,
|
|
||||||
cwd: "/tmp",
|
|
||||||
};
|
|
||||||
return store.put(schemas.stepNode, stepPayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("cmdStepShow JSON serialization", () => {
|
|
||||||
let testDir: string;
|
|
||||||
let casDir: string;
|
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
testDir = await mkdtemp(join(tmpdir(), "uwf-test-"));
|
|
||||||
casDir = join(testDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await rm(testDir, { recursive: true, force: true });
|
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("escapes newlines in tool call args", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "Running command",
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: "echo 'line1'\necho 'line2'",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
expect(jsonOutput).toContain("\\n");
|
|
||||||
|
|
||||||
const parsed = JSON.parse(jsonOutput);
|
|
||||||
expect(parsed.turns[0].toolCalls[0].args).toContain("\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("escapes tabs in tool call args", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "",
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: "cat <<EOF\nfield1\tfield2\tfield3\nEOF",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
expect(jsonOutput).toContain("\\t");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("escapes carriage returns", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "Committing changes",
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: 'git commit -m "First line\r\nSecond line"',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
expect(jsonOutput).toContain("\\r\\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("escapes backslashes and quotes", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "",
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: 'echo "He said \\"hello\\""',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
const parsed = JSON.parse(jsonOutput);
|
|
||||||
expect(parsed.turns).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles Unicode control characters", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "",
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: "echo '\u0001\u001F'",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles nested CAS refs with control characters", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "First turn\nwith newline",
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: "cmd1\nline2",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
index: 1,
|
|
||||||
role: "assistant",
|
|
||||||
content: "Second turn\twith tab",
|
|
||||||
toolCalls: null,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
const parsed = JSON.parse(jsonOutput);
|
|
||||||
expect(parsed.turns).toHaveLength(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("YAML output format is unaffected", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "Running command",
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: "echo 'line1'\necho 'line2'",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const yamlOutput = formatOutput(result, "yaml");
|
|
||||||
|
|
||||||
expect(yamlOutput).toContain("turns:");
|
|
||||||
expect(yamlOutput.length).toBeGreaterThan(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles empty and null values", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
const stepHash = await createTestStep(setup, [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
role: "assistant",
|
|
||||||
content: "",
|
|
||||||
toolCalls: null,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
const parsed = JSON.parse(jsonOutput);
|
|
||||||
expect(parsed.turns).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles large step with multiple tool calls", async () => {
|
|
||||||
const setup = await setupTest(casDir);
|
|
||||||
|
|
||||||
const turns = [];
|
|
||||||
for (let i = 0; i < 25; i++) {
|
|
||||||
turns.push({
|
|
||||||
index: i,
|
|
||||||
role: "assistant" as const,
|
|
||||||
content: `Turn ${i}\nwith newline`,
|
|
||||||
toolCalls: [
|
|
||||||
{
|
|
||||||
name: "Bash",
|
|
||||||
args: `command${i}\nline2\tfield${i}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Read",
|
|
||||||
args: `/path/to/file${i}`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const stepHash = await createTestStep(setup, turns);
|
|
||||||
|
|
||||||
const startTime = Date.now();
|
|
||||||
const result = await cmdStepShow(testDir, stepHash);
|
|
||||||
const jsonOutput = formatOutput(result, "json");
|
|
||||||
const duration = Date.now() - startTime;
|
|
||||||
|
|
||||||
expect(duration).toBeLessThan(2000);
|
|
||||||
expect(() => JSON.parse(jsonOutput)).not.toThrow();
|
|
||||||
|
|
||||||
const parsed = JSON.parse(jsonOutput);
|
|
||||||
expect(parsed.turns).toHaveLength(25);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { bootstrap, putSchema } from "@ocas/core";
|
import { bootstrap, putSchema } from "@uncaged/json-cas";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
import { STEP_NODE_SCHEMA } from "@uncaged/workflow-protocol";
|
import { STEP_NODE_SCHEMA } from "@uncaged/workflow-protocol";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdStepList } from "../commands/step.js";
|
import { cmdStepList } from "../commands/step.js";
|
||||||
import { cmdThreadRead } from "../commands/thread.js";
|
import { cmdThreadRead } from "../commands/thread.js";
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
import { registerUwfSchemas } from "../schemas.js";
|
||||||
@@ -43,7 +43,7 @@ const DETAIL_SCHEMA = {
|
|||||||
turnCount: { type: "integer" as const },
|
turnCount: { type: "integer" as const },
|
||||||
turns: {
|
turns: {
|
||||||
type: "array" as const,
|
type: "array" as const,
|
||||||
items: { type: "string" as const, format: "ocas_ref" },
|
items: { type: "string" as const, format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
@@ -63,22 +63,13 @@ async function registerDetailSchemas(store: ReturnType<typeof createFsStore>) {
|
|||||||
// ── fixture ──────────────────────────────────────────────────────────────────
|
// ── fixture ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-step-timing-test-"));
|
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-step-timing-test-"));
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = join(tmpDir, "cas");
|
|
||||||
await mkdir(process.env.UNCAGED_CAS_DIR, { recursive: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
await rm(tmpDir, { recursive: true, force: true });
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── 1. Protocol types (compile-time) ─────────────────────────────────────────
|
// ── 1. Protocol types (compile-time) ─────────────────────────────────────────
|
||||||
@@ -94,8 +85,6 @@ describe("protocol types", () => {
|
|||||||
edgePrompt: "",
|
edgePrompt: "",
|
||||||
startedAtMs: 1000,
|
startedAtMs: 1000,
|
||||||
completedAtMs: 2000,
|
completedAtMs: 2000,
|
||||||
assembledPrompt: null,
|
|
||||||
cwd: "/test/path",
|
|
||||||
};
|
};
|
||||||
expect(record.startedAtMs).toBe(1000);
|
expect(record.startedAtMs).toBe(1000);
|
||||||
expect(record.completedAtMs).toBe(2000);
|
expect(record.completedAtMs).toBe(2000);
|
||||||
@@ -163,7 +152,6 @@ describe("StepNode JSON schema", () => {
|
|||||||
edgePrompt: "",
|
edgePrompt: "",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
expect(hash).toBeTruthy();
|
expect(hash).toBeTruthy();
|
||||||
});
|
});
|
||||||
@@ -251,8 +239,8 @@ describe("thread read timing", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
graph: {
|
graph: {
|
||||||
$START: { _: { role: "worker", prompt: "go", location: null } },
|
$START: { _: { role: "worker", prompt: "go" } },
|
||||||
worker: { _: { role: "$END", prompt: "", location: null } },
|
worker: { _: { role: "$END", prompt: "" } },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -317,8 +305,8 @@ describe("thread read timing", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
graph: {
|
graph: {
|
||||||
$START: { _: { role: "worker", prompt: "go", location: null } },
|
$START: { _: { role: "worker", prompt: "go" } },
|
||||||
worker: { _: { role: "$END", prompt: "", location: null } },
|
worker: { _: { role: "$END", prompt: "" } },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,224 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, rm } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { createUwfStore, getCasDir, getGlobalCasDir } from "../store.js";
|
|
||||||
|
|
||||||
describe("Global CAS directory", () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tmpDir = join(tmpdir(), `uwf-test-global-cas-${Date.now()}`);
|
|
||||||
await mkdir(tmpDir, { recursive: true });
|
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
if (tmpDir) {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("getGlobalCasDir returns default path when no env var set", () => {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
const casDir = getGlobalCasDir();
|
|
||||||
// Should return ~/.uncaged/json-cas
|
|
||||||
expect(casDir).toContain(".uncaged");
|
|
||||||
expect(casDir).toContain("json-cas");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("getGlobalCasDir respects UNCAGED_CAS_DIR environment variable", () => {
|
|
||||||
const customPath = join(tmpDir, "custom-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = customPath;
|
|
||||||
const casDir = getGlobalCasDir();
|
|
||||||
expect(casDir).toBe(customPath);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("getGlobalCasDir ignores empty UNCAGED_CAS_DIR", () => {
|
|
||||||
process.env.UNCAGED_CAS_DIR = "";
|
|
||||||
const casDir = getGlobalCasDir();
|
|
||||||
expect(casDir).toContain(".uncaged");
|
|
||||||
expect(casDir).toContain("json-cas");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("getCasDir is deprecated but still works for backward compatibility", () => {
|
|
||||||
const storageRoot = join(tmpDir, "storage");
|
|
||||||
const casDir = getCasDir(storageRoot);
|
|
||||||
expect(casDir).toBe(join(storageRoot, "cas"));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("createUwfStore uses global CAS directory", async () => {
|
|
||||||
const globalCasDir = join(tmpDir, "global-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = globalCasDir;
|
|
||||||
|
|
||||||
const storageRoot = join(tmpDir, "storage");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
|
|
||||||
// Verify the store was created in the global CAS directory
|
|
||||||
expect(uwf.storageRoot).toBe(storageRoot);
|
|
||||||
expect(uwf.store).toBeDefined();
|
|
||||||
expect(uwf.schemas).toBeDefined();
|
|
||||||
|
|
||||||
// The global CAS directory should be created
|
|
||||||
const { stat } = await import("node:fs/promises");
|
|
||||||
const stats = await stat(globalCasDir);
|
|
||||||
expect(stats.isDirectory()).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("createUwfStore creates global CAS directory if it does not exist", async () => {
|
|
||||||
const globalCasDir = join(tmpDir, "new-global-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = globalCasDir;
|
|
||||||
|
|
||||||
const storageRoot = join(tmpDir, "storage");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
|
|
||||||
await createUwfStore(storageRoot);
|
|
||||||
|
|
||||||
// Verify the directory was created
|
|
||||||
const { stat } = await import("node:fs/promises");
|
|
||||||
const stats = await stat(globalCasDir);
|
|
||||||
expect(stats.isDirectory()).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple uwfStore instances share the same global CAS filesystem", async () => {
|
|
||||||
const globalCasDir = join(tmpDir, "shared-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = globalCasDir;
|
|
||||||
|
|
||||||
const storageRoot1 = join(tmpDir, "storage1");
|
|
||||||
const storageRoot2 = join(tmpDir, "storage2");
|
|
||||||
await mkdir(storageRoot1, { recursive: true });
|
|
||||||
await mkdir(storageRoot2, { recursive: true });
|
|
||||||
|
|
||||||
const uwf1 = await createUwfStore(storageRoot1);
|
|
||||||
const uwf2 = await createUwfStore(storageRoot2);
|
|
||||||
|
|
||||||
// Both should use the same global CAS directory
|
|
||||||
expect(uwf1.store).toBeDefined();
|
|
||||||
expect(uwf2.store).toBeDefined();
|
|
||||||
|
|
||||||
// Store a node in the first store
|
|
||||||
const testData = { test: "data" };
|
|
||||||
const _hash = uwf1.store.put(uwf1.schemas.text, JSON.stringify(testData));
|
|
||||||
|
|
||||||
// Both stores share the same CAS filesystem directory
|
|
||||||
// Since schemas are registered idempotently, they should have the same hash
|
|
||||||
expect(uwf2.schemas.text).toBe(uwf1.schemas.text);
|
|
||||||
|
|
||||||
// Verify the CAS files are written to the shared directory
|
|
||||||
const { readdir } = await import("node:fs/promises");
|
|
||||||
const files = await readdir(globalCasDir);
|
|
||||||
expect(files.length).toBeGreaterThan(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("workflow metadata remains in storageRoot, not global CAS", async () => {
|
|
||||||
const globalCasDir = join(tmpDir, "global-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = globalCasDir;
|
|
||||||
|
|
||||||
const storageRoot = join(tmpDir, "storage");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
|
|
||||||
const _uwf = await createUwfStore(storageRoot);
|
|
||||||
|
|
||||||
// Write workflow registry file
|
|
||||||
const { saveWorkflowRegistry } = await import("../store.js");
|
|
||||||
await saveWorkflowRegistry(storageRoot, { "test-workflow": "ABC123" });
|
|
||||||
|
|
||||||
// Verify registry is in storageRoot, not global CAS
|
|
||||||
const { readFile } = await import("node:fs/promises");
|
|
||||||
const registryPath = join(storageRoot, "workflows.yaml");
|
|
||||||
const content = await readFile(registryPath, "utf8");
|
|
||||||
expect(content).toContain("test-workflow");
|
|
||||||
expect(content).toContain("ABC123");
|
|
||||||
|
|
||||||
// Verify registry is NOT in global CAS directory
|
|
||||||
const globalRegistryPath = join(globalCasDir, "workflows.yaml");
|
|
||||||
await expect(readFile(globalRegistryPath, "utf8")).rejects.toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("thread metadata remains in storageRoot", async () => {
|
|
||||||
const globalCasDir = join(tmpDir, "global-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = globalCasDir;
|
|
||||||
|
|
||||||
const storageRoot = join(tmpDir, "storage");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
|
|
||||||
await createUwfStore(storageRoot);
|
|
||||||
|
|
||||||
// Write threads index
|
|
||||||
const { saveThreadsIndex } = await import("../store.js");
|
|
||||||
await saveThreadsIndex(storageRoot, { "thread-123": "hash-456" });
|
|
||||||
|
|
||||||
// Verify threads.yaml is in storageRoot, not global CAS
|
|
||||||
const { readFile } = await import("node:fs/promises");
|
|
||||||
const threadsPath = join(storageRoot, "threads.yaml");
|
|
||||||
const content = await readFile(threadsPath, "utf8");
|
|
||||||
expect(content).toContain("thread-123");
|
|
||||||
expect(content).toContain("hash-456");
|
|
||||||
|
|
||||||
// Verify threads.yaml is NOT in global CAS directory
|
|
||||||
const globalThreadsPath = join(globalCasDir, "threads.yaml");
|
|
||||||
await expect(readFile(globalThreadsPath, "utf8")).rejects.toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("history remains in storageRoot", async () => {
|
|
||||||
const globalCasDir = join(tmpDir, "global-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = globalCasDir;
|
|
||||||
|
|
||||||
const storageRoot = join(tmpDir, "storage");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
|
|
||||||
await createUwfStore(storageRoot);
|
|
||||||
|
|
||||||
// Write history
|
|
||||||
const { appendThreadHistory } = await import("../store.js");
|
|
||||||
await appendThreadHistory(storageRoot, {
|
|
||||||
thread: "thread-123" as any,
|
|
||||||
workflow: "workflow-456",
|
|
||||||
head: "hash-789",
|
|
||||||
completedAt: Date.now(),
|
|
||||||
reason: "completed",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Verify history.jsonl is in storageRoot, not global CAS
|
|
||||||
const { readFile } = await import("node:fs/promises");
|
|
||||||
const historyPath = join(storageRoot, "history.jsonl");
|
|
||||||
const content = await readFile(historyPath, "utf8");
|
|
||||||
expect(content).toContain("thread-123");
|
|
||||||
expect(content).toContain("workflow-456");
|
|
||||||
|
|
||||||
// Verify history.jsonl is NOT in global CAS directory
|
|
||||||
const globalHistoryPath = join(globalCasDir, "history.jsonl");
|
|
||||||
await expect(readFile(globalHistoryPath, "utf8")).rejects.toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("CAS nodes are stored in global directory", async () => {
|
|
||||||
const globalCasDir = join(tmpDir, "global-cas");
|
|
||||||
process.env.UNCAGED_CAS_DIR = globalCasDir;
|
|
||||||
|
|
||||||
const storageRoot = join(tmpDir, "storage");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
|
|
||||||
// Store a CAS node
|
|
||||||
const testPayload = JSON.stringify({ test: "node" });
|
|
||||||
const _hash = uwf.store.put(uwf.schemas.text, testPayload);
|
|
||||||
|
|
||||||
// Verify the node is in global CAS directory
|
|
||||||
const { readdir } = await import("node:fs/promises");
|
|
||||||
const files = await readdir(globalCasDir);
|
|
||||||
expect(files.length).toBeGreaterThan(0);
|
|
||||||
|
|
||||||
// Verify the node is NOT in the old storageRoot/cas location
|
|
||||||
const oldCasDir = join(storageRoot, "cas");
|
|
||||||
await expect(readdir(oldCasDir)).rejects.toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { mkdtemp } from "node:fs/promises";
|
import { mkdtemp } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
import { appendThreadHistory, loadThreadHistory } from "../store.js";
|
import { appendThreadHistory, loadThreadHistory } from "../store.js";
|
||||||
|
|
||||||
describe("thread cancel status", () => {
|
describe("thread cancel status", () => {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
import { createThreadIndexEntry } from "@uncaged/workflow-protocol";
|
|
||||||
import { extractUlidTimestamp, generateUlid } from "@uncaged/workflow-util";
|
import { extractUlidTimestamp, generateUlid } from "@uncaged/workflow-util";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { createMarker, deleteMarker } from "../background/index.js";
|
import { createMarker, deleteMarker } from "../background/index.js";
|
||||||
import { cmdThreadList } from "../commands/thread.js";
|
import { cmdThreadList } from "../commands/thread.js";
|
||||||
import { parseTimeInput } from "../commands/thread-time-parser.js";
|
import { parseTimeInput } from "../commands/thread-time-parser.js";
|
||||||
@@ -16,8 +15,6 @@ import { appendThreadHistory, createUwfStore, saveThreadsIndex } from "../store.
|
|||||||
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
||||||
const casDir = join(storageRoot, "cas");
|
const casDir = join(storageRoot, "cas");
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
// Set UNCAGED_CAS_DIR to use the test's CAS directory
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
return createUwfStore(storageRoot);
|
return createUwfStore(storageRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,15 +43,11 @@ async function createTestThread(
|
|||||||
const startPayload = {
|
const startPayload = {
|
||||||
workflow: workflowHash,
|
workflow: workflowHash,
|
||||||
prompt: "test prompt",
|
prompt: "test prompt",
|
||||||
cwd: storageRoot,
|
|
||||||
};
|
};
|
||||||
const headHash = await uwf.store.put(uwf.schemas.startNode, startPayload);
|
const headHash = await uwf.store.put(uwf.schemas.startNode, startPayload);
|
||||||
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(storageRoot));
|
||||||
// Load existing index and add new thread
|
index[threadId] = headHash;
|
||||||
const existingIndex = await import("../store.js").then((m) => m.loadThreadsIndex(storageRoot));
|
await saveThreadsIndex(storageRoot, index);
|
||||||
existingIndex[threadId] = createThreadIndexEntry(headHash);
|
|
||||||
await saveThreadsIndex(storageRoot, existingIndex);
|
|
||||||
|
|
||||||
return threadId;
|
return threadId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +104,7 @@ describe("cmdThreadList status filter", () => {
|
|||||||
await markThreadRunning(tmpDir, thread2, workflowHash);
|
await markThreadRunning(tmpDir, thread2, workflowHash);
|
||||||
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
const thread3Head = index[thread3]!.head;
|
const thread3Head = index[thread3];
|
||||||
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
||||||
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
||||||
|
|
||||||
@@ -135,7 +128,7 @@ describe("cmdThreadList status filter", () => {
|
|||||||
await markThreadRunning(tmpDir, thread2, workflowHash);
|
await markThreadRunning(tmpDir, thread2, workflowHash);
|
||||||
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
const thread3Head = index[thread3]!.head;
|
const thread3Head = index[thread3];
|
||||||
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
||||||
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
||||||
|
|
||||||
@@ -159,7 +152,7 @@ describe("cmdThreadList status filter", () => {
|
|||||||
const thread3 = await createTestThread(uwf, tmpDir, workflowHash, Date.now() - 1000);
|
const thread3 = await createTestThread(uwf, tmpDir, workflowHash, Date.now() - 1000);
|
||||||
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
const thread3Head = index[thread3]!.head;
|
const thread3Head = index[thread3];
|
||||||
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
||||||
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
||||||
|
|
||||||
@@ -181,7 +174,7 @@ describe("cmdThreadList status filter", () => {
|
|||||||
await markThreadRunning(tmpDir, thread2, workflowHash);
|
await markThreadRunning(tmpDir, thread2, workflowHash);
|
||||||
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
const thread3Head = index[thread3]!.head;
|
const thread3Head = index[thread3];
|
||||||
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
||||||
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
||||||
|
|
||||||
@@ -353,7 +346,7 @@ describe("combined filters", () => {
|
|||||||
await markThreadRunning(tmpDir, thread2, workflowHash);
|
await markThreadRunning(tmpDir, thread2, workflowHash);
|
||||||
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
const thread3Head = index[thread3]!.head;
|
const thread3Head = index[thread3];
|
||||||
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
if (thread3Head === undefined) throw new Error("thread3 head not found");
|
||||||
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
await completeThread(tmpDir, thread3, workflowHash, thread3Head);
|
||||||
|
|
||||||
@@ -377,7 +370,7 @@ describe("combined filters", () => {
|
|||||||
const thread = await createTestThread(uwf, tmpDir, workflowHash, Date.now() + i * 1000);
|
const thread = await createTestThread(uwf, tmpDir, workflowHash, Date.now() + i * 1000);
|
||||||
threads.push(thread);
|
threads.push(thread);
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
const headHash = index[thread]!.head;
|
const headHash = index[thread];
|
||||||
if (headHash === undefined) throw new Error("head not found");
|
if (headHash === undefined) throw new Error("head not found");
|
||||||
await completeThread(tmpDir, thread, workflowHash, headHash);
|
await completeThread(tmpDir, thread, workflowHash, headHash);
|
||||||
}
|
}
|
||||||
@@ -426,7 +419,7 @@ describe("combined filters", () => {
|
|||||||
|
|
||||||
if (i % 2 === 0) {
|
if (i % 2 === 0) {
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
const headHash = index[thread]!.head;
|
const headHash = index[thread];
|
||||||
if (headHash === undefined) throw new Error("head not found");
|
if (headHash === undefined) throw new Error("head not found");
|
||||||
await completeThread(tmpDir, thread, workflowHash, headHash);
|
await completeThread(tmpDir, thread, workflowHash, headHash);
|
||||||
} else {
|
} else {
|
||||||
@@ -484,11 +477,7 @@ describe("edge cases", () => {
|
|||||||
const thread2 = await createTestThread(uwf, tmpDir, workflowHash, Date.now() - 1000);
|
const thread2 = await createTestThread(uwf, tmpDir, workflowHash, Date.now() - 1000);
|
||||||
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
const index = await import("../store.js").then((m) => m.loadThreadsIndex(tmpDir));
|
||||||
index["INVALID_ULID_FORMAT_HERE" as ThreadId] = {
|
index["INVALID_ULID_FORMAT_HERE" as ThreadId] = "01J6HMVRNQKJV2";
|
||||||
head: "01J6HMVRNQKJV2",
|
|
||||||
suspendedRole: null,
|
|
||||||
suspendMessage: null,
|
|
||||||
};
|
|
||||||
await saveThreadsIndex(tmpDir, index);
|
await saveThreadsIndex(tmpDir, index);
|
||||||
|
|
||||||
const afterMs = Date.now() - 3000;
|
const afterMs = Date.now() - 3000;
|
||||||
|
|||||||
@@ -1,188 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import type { CasRef, StartNodePayload, ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { cmdThreadStart } from "../commands/thread.js";
|
|
||||||
import { createUwfStore } from "../store.js";
|
|
||||||
|
|
||||||
describe("Thread and edge location integration", () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
let storageRoot: string;
|
|
||||||
let casDir: string;
|
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
async function setupTestEnv() {
|
|
||||||
tmpDir = join(tmpdir(), `uwf-test-location-${Date.now()}`);
|
|
||||||
storageRoot = join(tmpDir, "storage");
|
|
||||||
casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
|
|
||||||
// Set UNCAGED_CAS_DIR for this test
|
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function teardown() {
|
|
||||||
if (tmpDir) {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
// Restore original environment
|
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test("thread start captures cwd in StartNode", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowYaml = `
|
|
||||||
name: test-location
|
|
||||||
description: Test workflow for location feature
|
|
||||||
roles:
|
|
||||||
planner:
|
|
||||||
description: Plans the work
|
|
||||||
goal: Plan implementation
|
|
||||||
capabilities: ["planning"]
|
|
||||||
procedure: Plan
|
|
||||||
output: |
|
|
||||||
$status: "ready"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: planner
|
|
||||||
prompt: "Plan the work"
|
|
||||||
location: null
|
|
||||||
planner:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-location.yaml");
|
|
||||||
await writeFile(workflowPath, workflowYaml, "utf8");
|
|
||||||
|
|
||||||
const testCwd = "/test/project/path";
|
|
||||||
const result = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir, testCwd);
|
|
||||||
|
|
||||||
expect(result.thread).toBeDefined();
|
|
||||||
expect(result.workflow).toBeDefined();
|
|
||||||
|
|
||||||
// Verify StartNode has the cwd field
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(storageRoot));
|
|
||||||
const headHash = index[result.thread as ThreadId]!.head;
|
|
||||||
expect(headHash).toBeDefined();
|
|
||||||
|
|
||||||
const startNode = uwf.store.get(headHash as CasRef);
|
|
||||||
expect(startNode).not.toBe(null);
|
|
||||||
expect(startNode?.type).toBe(uwf.schemas.startNode);
|
|
||||||
|
|
||||||
const startPayload = startNode?.payload as StartNodePayload;
|
|
||||||
expect(startPayload.cwd).toBe(testCwd);
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("thread start validates cwd is absolute path", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowYaml = `
|
|
||||||
name: test-location
|
|
||||||
description: Test workflow
|
|
||||||
roles:
|
|
||||||
planner:
|
|
||||||
description: Plans
|
|
||||||
goal: Plan
|
|
||||||
capabilities: ["planning"]
|
|
||||||
procedure: Plan
|
|
||||||
output: |
|
|
||||||
$status: "ready"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: planner
|
|
||||||
prompt: "Plan"
|
|
||||||
location: null
|
|
||||||
planner:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-location.yaml");
|
|
||||||
await writeFile(workflowPath, workflowYaml, "utf8");
|
|
||||||
|
|
||||||
// Relative path should fail via fail() → process.exit (mocked in test preload)
|
|
||||||
await expect(
|
|
||||||
cmdThreadStart(storageRoot, workflowPath, "test", tmpDir, "relative/path"),
|
|
||||||
).rejects.toThrow();
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("thread start uses process.cwd() as default", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowYaml = `
|
|
||||||
name: test-default-cwd
|
|
||||||
description: Test default cwd
|
|
||||||
roles:
|
|
||||||
planner:
|
|
||||||
description: Plans
|
|
||||||
goal: Plan
|
|
||||||
capabilities: ["planning"]
|
|
||||||
procedure: Plan
|
|
||||||
output: |
|
|
||||||
$status: "ready"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: planner
|
|
||||||
prompt: "Plan"
|
|
||||||
location: null
|
|
||||||
planner:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-default-cwd.yaml");
|
|
||||||
await writeFile(workflowPath, workflowYaml, "utf8");
|
|
||||||
|
|
||||||
const result = await cmdThreadStart(storageRoot, workflowPath, "test", tmpDir);
|
|
||||||
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
const index = await import("../store.js").then((m) => m.loadThreadsIndex(storageRoot));
|
|
||||||
const headHash = index[result.thread as ThreadId]!.head;
|
|
||||||
|
|
||||||
const startNode = uwf.store.get(headHash as CasRef);
|
|
||||||
const startPayload = startNode?.payload as StartNodePayload;
|
|
||||||
|
|
||||||
// Should default to process.cwd()
|
|
||||||
expect(startPayload.cwd).toBe(process.cwd());
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { bootstrap, putSchema } from "@ocas/core";
|
import { bootstrap, putSchema } from "@uncaged/json-cas";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdThreadRead } from "../commands/thread.js";
|
import { cmdThreadRead } from "../commands/thread.js";
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
import { registerUwfSchemas } from "../schemas.js";
|
||||||
import { saveThreadsIndex } from "../store.js";
|
import { saveThreadsIndex } from "../store.js";
|
||||||
@@ -41,7 +41,7 @@ const DETAIL_SCHEMA = {
|
|||||||
turnCount: { type: "integer" as const },
|
turnCount: { type: "integer" as const },
|
||||||
turns: {
|
turns: {
|
||||||
type: "array" as const,
|
type: "array" as const,
|
||||||
items: { type: "string" as const, format: "ocas_ref" },
|
items: { type: "string" as const, format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
@@ -67,22 +67,13 @@ function generateContent(size: number, prefix = "Content"): string {
|
|||||||
// ── fixture ───────────────────────────────────────────────────────────────────
|
// ── fixture ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-quota-test-"));
|
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-quota-test-"));
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = join(tmpDir, "cas");
|
|
||||||
await mkdir(process.env.UNCAGED_CAS_DIR, { recursive: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
await rm(tmpDir, { recursive: true, force: true });
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── thread read quota enforcement ─────────────────────────────────────────────
|
// ── thread read quota enforcement ─────────────────────────────────────────────
|
||||||
@@ -152,7 +143,6 @@ describe("thread read --quota flag", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
steps.push(stepHash);
|
steps.push(stepHash);
|
||||||
}
|
}
|
||||||
@@ -235,7 +225,6 @@ describe("thread read --quota flag", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const step2Content = generateContent(600, "Second");
|
const step2Content = generateContent(600, "Second");
|
||||||
@@ -262,7 +251,6 @@ describe("thread read --quota flag", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01HX2Q3R4S5T6V7W8X9YZ1" as ThreadId;
|
const threadId = "01HX2Q3R4S5T6V7W8X9YZ1" as ThreadId;
|
||||||
@@ -348,7 +336,6 @@ describe("thread read --quota flag", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
steps.push(stepHash);
|
steps.push(stepHash);
|
||||||
}
|
}
|
||||||
@@ -428,7 +415,6 @@ describe("thread read --quota flag", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01HX2Q3R4S5T6V7W8X9YZ4" as ThreadId;
|
const threadId = "01HX2Q3R4S5T6V7W8X9YZ4" as ThreadId;
|
||||||
@@ -506,7 +492,6 @@ describe("thread read --quota flag", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
steps.push(stepHash);
|
steps.push(stepHash);
|
||||||
}
|
}
|
||||||
@@ -588,7 +573,6 @@ describe("thread read --quota flag", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
steps.push(stepHash);
|
steps.push(stepHash);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { bootstrap, putSchema } from "@ocas/core";
|
import { bootstrap, putSchema } from "@uncaged/json-cas";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdThreadRead, THREAD_READ_DEFAULT_QUOTA } from "../commands/thread.js";
|
import { cmdThreadRead, THREAD_READ_DEFAULT_QUOTA } from "../commands/thread.js";
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
import { registerUwfSchemas } from "../schemas.js";
|
||||||
import type { UwfStore } from "../store.js";
|
import type { UwfStore } from "../store.js";
|
||||||
@@ -42,7 +42,7 @@ const DETAIL_SCHEMA = {
|
|||||||
turnCount: { type: "integer" as const },
|
turnCount: { type: "integer" as const },
|
||||||
turns: {
|
turns: {
|
||||||
type: "array" as const,
|
type: "array" as const,
|
||||||
items: { type: "string" as const, format: "ocas_ref" },
|
items: { type: "string" as const, format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
@@ -53,8 +53,6 @@ const DETAIL_SCHEMA = {
|
|||||||
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
||||||
const casDir = join(storageRoot, "cas");
|
const casDir = join(storageRoot, "cas");
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
// Set UNCAGED_CAS_DIR to use the test's CAS directory
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
return { storageRoot, store, schemas };
|
return { storageRoot, store, schemas };
|
||||||
@@ -143,7 +141,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-claude-code",
|
agent: "uwf-claude-code",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000001" as ThreadId;
|
const threadId = "01JTEST0000000000000001" as ThreadId;
|
||||||
@@ -221,7 +218,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-claude-code",
|
agent: "uwf-claude-code",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000002" as ThreadId;
|
const threadId = "01JTEST0000000000000002" as ThreadId;
|
||||||
@@ -284,7 +280,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const step2 = await uwf.store.put(uwf.schemas.stepNode, {
|
const step2 = await uwf.store.put(uwf.schemas.stepNode, {
|
||||||
@@ -296,7 +291,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000003" as ThreadId;
|
const threadId = "01JTEST0000000000000003" as ThreadId;
|
||||||
@@ -351,7 +345,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000004" as ThreadId;
|
const threadId = "01JTEST0000000000000004" as ThreadId;
|
||||||
@@ -406,7 +399,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000005" as ThreadId;
|
const threadId = "01JTEST0000000000000005" as ThreadId;
|
||||||
@@ -461,7 +453,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000006" as ThreadId;
|
const threadId = "01JTEST0000000000000006" as ThreadId;
|
||||||
@@ -536,7 +527,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const step2 = await uwf.store.put(uwf.schemas.stepNode, {
|
const step2 = await uwf.store.put(uwf.schemas.stepNode, {
|
||||||
@@ -548,7 +538,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const step3 = await uwf.store.put(uwf.schemas.stepNode, {
|
const step3 = await uwf.store.put(uwf.schemas.stepNode, {
|
||||||
@@ -560,7 +549,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000007" as ThreadId;
|
const threadId = "01JTEST0000000000000007" as ThreadId;
|
||||||
@@ -641,7 +629,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const threadId = "01JTEST0000000000000008" as ThreadId;
|
const threadId = "01JTEST0000000000000008" as ThreadId;
|
||||||
@@ -698,7 +685,6 @@ describe("thread read XML tag isolation", () => {
|
|||||||
agent: "uwf-test",
|
agent: "uwf-test",
|
||||||
startedAtMs: 1000000000000,
|
startedAtMs: 1000000000000,
|
||||||
completedAtMs: 1000000005000,
|
completedAtMs: 1000000005000,
|
||||||
assembledPrompt: null,
|
|
||||||
})) as CasRef;
|
})) as CasRef;
|
||||||
steps.push(step);
|
steps.push(step);
|
||||||
prev = step;
|
prev = step;
|
||||||
|
|||||||
@@ -1,442 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { execFileSync } from "node:child_process";
|
|
||||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { putSchema } from "@ocas/core";
|
|
||||||
import { createFsStore } from "@ocas/fs";
|
|
||||||
import type { CasRef, StepNodePayload, ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { parse } from "yaml";
|
|
||||||
import { cmdThreadShow } from "../commands/thread.js";
|
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
|
||||||
import { saveThreadsIndex } from "../store.js";
|
|
||||||
|
|
||||||
const OUTPUT_SCHEMA = {
|
|
||||||
type: "object" as const,
|
|
||||||
properties: {
|
|
||||||
$status: { type: "string" as const },
|
|
||||||
question: { type: "string" as const },
|
|
||||||
},
|
|
||||||
required: ["$status"],
|
|
||||||
additionalProperties: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
const THREAD_ID = "01RESUMESTEPTEST0000000" as ThreadId;
|
|
||||||
const SUSPEND_MESSAGE = "Please clarify: Which API?";
|
|
||||||
|
|
||||||
type MockAgentMode = "suspend" | "ok";
|
|
||||||
|
|
||||||
let tmpDir: string;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-resume-test-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
async function setupSuspendedThread(mode: MockAgentMode): Promise<{
|
|
||||||
casDir: string;
|
|
||||||
mockAgentPath: string;
|
|
||||||
promptCapturePath: string;
|
|
||||||
}> {
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
|
|
||||||
const store = createFsStore(casDir);
|
|
||||||
const schemas = await registerUwfSchemas(store);
|
|
||||||
const outputSchemaHash = await putSchema(store, OUTPUT_SCHEMA);
|
|
||||||
|
|
||||||
const workflowHash = await store.put(schemas.workflow, {
|
|
||||||
name: "test-resume",
|
|
||||||
description: "resume command integration test",
|
|
||||||
roles: {
|
|
||||||
worker: {
|
|
||||||
description: "Worker role",
|
|
||||||
goal: "Work",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "work",
|
|
||||||
output: "result",
|
|
||||||
frontmatter: outputSchemaHash,
|
|
||||||
},
|
|
||||||
reviewer: {
|
|
||||||
description: "Reviewer role",
|
|
||||||
goal: "Review",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "review",
|
|
||||||
output: "result",
|
|
||||||
frontmatter: outputSchemaHash,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
$START: { _: { role: "worker", prompt: "Start work", location: null } },
|
|
||||||
worker: {
|
|
||||||
needs_input: {
|
|
||||||
role: "$SUSPEND",
|
|
||||||
prompt: "Please clarify: {{{question}}}",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
ok: { role: "reviewer", prompt: "Review the work", location: null },
|
|
||||||
},
|
|
||||||
reviewer: { _: { role: "$END", prompt: "Done", location: null } },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const startHash = await store.put(schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "Test resume task",
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveThreadsIndex(tmpDir, { [THREAD_ID]: startHash });
|
|
||||||
|
|
||||||
const outputHash = await store.put(outputSchemaHash, {
|
|
||||||
$status: "needs_input",
|
|
||||||
question: "Which API?",
|
|
||||||
});
|
|
||||||
const detailHash = await store.put(schemas.text, "mock detail");
|
|
||||||
|
|
||||||
const startedAtMs = 1716600000000;
|
|
||||||
const completedAtMs = 1716600001500;
|
|
||||||
|
|
||||||
const stepHash = await store.put(schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: null,
|
|
||||||
role: "worker",
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-mock",
|
|
||||||
edgePrompt: "Start work",
|
|
||||||
startedAtMs,
|
|
||||||
completedAtMs,
|
|
||||||
cwd: tmpDir,
|
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveThreadsIndex(tmpDir, {
|
|
||||||
[THREAD_ID]: {
|
|
||||||
head: stepHash,
|
|
||||||
suspendedRole: "worker",
|
|
||||||
suspendMessage: SUSPEND_MESSAGE,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const promptCapturePath = join(tmpDir, "captured-prompt.txt");
|
|
||||||
const mockAgentPath = join(tmpDir, "mock-agent.sh");
|
|
||||||
|
|
||||||
const frontmatter =
|
|
||||||
mode === "suspend" ? { $status: "needs_input", question: "Which API?" } : { $status: "ok" };
|
|
||||||
|
|
||||||
const adapterJson = JSON.stringify({
|
|
||||||
stepHash: await store.put(schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: stepHash,
|
|
||||||
role: "worker",
|
|
||||||
output: await store.put(outputSchemaHash, frontmatter),
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-mock",
|
|
||||||
edgePrompt: "resume prompt placeholder",
|
|
||||||
startedAtMs: completedAtMs + 1,
|
|
||||||
completedAtMs: completedAtMs + 2,
|
|
||||||
cwd: tmpDir,
|
|
||||||
assembledPrompt: null,
|
|
||||||
}),
|
|
||||||
detailHash,
|
|
||||||
role: "worker",
|
|
||||||
frontmatter,
|
|
||||||
body: "",
|
|
||||||
startedAtMs: completedAtMs + 1,
|
|
||||||
completedAtMs: completedAtMs + 2,
|
|
||||||
});
|
|
||||||
|
|
||||||
await writeFile(
|
|
||||||
mockAgentPath,
|
|
||||||
`#!/bin/sh
|
|
||||||
prompt=""
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
if [ "$1" = "--prompt" ]; then
|
|
||||||
prompt="$2"
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
printf '%s' "$prompt" > '${promptCapturePath}'
|
|
||||||
echo '${adapterJson}'
|
|
||||||
`,
|
|
||||||
{ mode: 0o755 },
|
|
||||||
);
|
|
||||||
|
|
||||||
const configPath = join(tmpDir, "config.yaml");
|
|
||||||
await writeFile(
|
|
||||||
configPath,
|
|
||||||
`defaultAgent: uwf-hermes\ndefaultModel: test-model\nagentOverrides: null\nagents: {}\nproviders: {}\nmodels: {}\n`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return { casDir, mockAgentPath, promptCapturePath };
|
|
||||||
}
|
|
||||||
|
|
||||||
function runUwf(
|
|
||||||
args: string[],
|
|
||||||
casDir: string,
|
|
||||||
): { stdout: string; stderr: string; status: number } {
|
|
||||||
const cliPath = join(import.meta.dirname, "..", "cli.js");
|
|
||||||
try {
|
|
||||||
const stdout = execFileSync("bun", ["run", cliPath, ...args], {
|
|
||||||
encoding: "utf8",
|
|
||||||
stdio: ["ignore", "pipe", "pipe"],
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
WORKFLOW_STORAGE_ROOT: tmpDir,
|
|
||||||
UNCAGED_CAS_DIR: casDir,
|
|
||||||
},
|
|
||||||
cwd: tmpDir,
|
|
||||||
timeout: 30000,
|
|
||||||
});
|
|
||||||
return { stdout, stderr: "", status: 0 };
|
|
||||||
} catch (error) {
|
|
||||||
const err = error as NodeJS.ErrnoException & {
|
|
||||||
stdout?: string | Buffer;
|
|
||||||
stderr?: string | Buffer;
|
|
||||||
status?: number;
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
stdout: typeof err.stdout === "string" ? err.stdout : (err.stdout?.toString("utf8") ?? ""),
|
|
||||||
stderr: typeof err.stderr === "string" ? err.stderr : (err.stderr?.toString("utf8") ?? ""),
|
|
||||||
status: err.status ?? 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("uwf thread resume", () => {
|
|
||||||
test("resume non-suspended thread returns error", async () => {
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
const store = createFsStore(casDir);
|
|
||||||
const schemas = await registerUwfSchemas(store);
|
|
||||||
|
|
||||||
const workflowHash = await store.put(schemas.workflow, {
|
|
||||||
name: "idle-workflow",
|
|
||||||
description: "idle thread",
|
|
||||||
roles: {
|
|
||||||
worker: {
|
|
||||||
description: "Worker",
|
|
||||||
goal: "Work",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "work",
|
|
||||||
output: "result",
|
|
||||||
frontmatter: await putSchema(store, OUTPUT_SCHEMA),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
$START: { _: { role: "worker", prompt: "Start", location: null } },
|
|
||||||
worker: { _: { role: "$END", prompt: "Done", location: null } },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const startHash = await store.put(schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "task",
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveThreadsIndex(tmpDir, { [THREAD_ID]: startHash });
|
|
||||||
|
|
||||||
const result = runUwf(["thread", "resume", THREAD_ID], casDir);
|
|
||||||
expect(result.status).not.toBe(0);
|
|
||||||
expect(result.stderr).toContain("thread is not suspended");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("resume suspended thread executes step and becomes idle", async () => {
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
const { casDir, mockAgentPath } = await setupSuspendedThread("ok");
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = runUwf(["thread", "resume", THREAD_ID, "--agent", mockAgentPath], casDir);
|
|
||||||
expect(result.status).toBe(0);
|
|
||||||
|
|
||||||
const cliOutput = JSON.parse(result.stdout.trim());
|
|
||||||
expect(cliOutput.status).toBe("idle");
|
|
||||||
expect(cliOutput.currentRole).toBe("reviewer");
|
|
||||||
expect(cliOutput.suspendedRole).toBeNull();
|
|
||||||
expect(cliOutput.suspendMessage).toBeNull();
|
|
||||||
expect(cliOutput.done).toBe(false);
|
|
||||||
|
|
||||||
const threadsYaml = await readFile(join(tmpDir, "threads.yaml"), "utf8");
|
|
||||||
const threadsIndex = parse(threadsYaml) as Record<string, unknown>;
|
|
||||||
expect(threadsIndex[THREAD_ID]).toBe(cliOutput.head);
|
|
||||||
|
|
||||||
const showResult = await cmdThreadShow(tmpDir, THREAD_ID);
|
|
||||||
expect(showResult.status).toBe("idle");
|
|
||||||
expect(showResult.suspendedRole).toBeNull();
|
|
||||||
expect(showResult.suspendMessage).toBeNull();
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("resume without -p uses suspend message as agent prompt", async () => {
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
const { casDir, mockAgentPath, promptCapturePath } = await setupSuspendedThread("ok");
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = runUwf(["thread", "resume", THREAD_ID, "--agent", mockAgentPath], casDir);
|
|
||||||
expect(result.status).toBe(0);
|
|
||||||
|
|
||||||
const capturedPrompt = await readFile(promptCapturePath, "utf8");
|
|
||||||
expect(capturedPrompt).toBe(SUSPEND_MESSAGE);
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("resume with -p appends supplementary info to agent prompt", async () => {
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
const { casDir, mockAgentPath, promptCapturePath } = await setupSuspendedThread("ok");
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const supplement = "Use the REST API.";
|
|
||||||
const result = runUwf(
|
|
||||||
["thread", "resume", THREAD_ID, "-p", supplement, "--agent", mockAgentPath],
|
|
||||||
casDir,
|
|
||||||
);
|
|
||||||
expect(result.status).toBe(0);
|
|
||||||
|
|
||||||
const capturedPrompt = await readFile(promptCapturePath, "utf8");
|
|
||||||
expect(capturedPrompt).toBe(`${SUSPEND_MESSAGE}\n\n${supplement}`);
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple suspend/resume cycles", async () => {
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
const { casDir, mockAgentPath, promptCapturePath } = await setupSuspendedThread("suspend");
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const firstResult = runUwf(["thread", "resume", THREAD_ID, "--agent", mockAgentPath], casDir);
|
|
||||||
expect(firstResult.status).toBe(0);
|
|
||||||
const firstResume = JSON.parse(firstResult.stdout.trim());
|
|
||||||
expect(firstResume.status).toBe("suspended");
|
|
||||||
expect(firstResume.suspendedRole).toBe("worker");
|
|
||||||
expect(firstResume.suspendMessage).toBe(SUSPEND_MESSAGE);
|
|
||||||
|
|
||||||
const threadsAfterFirst = parse(
|
|
||||||
await readFile(join(tmpDir, "threads.yaml"), "utf8"),
|
|
||||||
) as Record<string, unknown>;
|
|
||||||
expect(threadsAfterFirst[THREAD_ID]).toEqual({
|
|
||||||
head: firstResume.head,
|
|
||||||
suspendedRole: "worker",
|
|
||||||
suspendMessage: SUSPEND_MESSAGE,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mockAgentPath: okMockAgentPath } = await setupOkMockAgent(
|
|
||||||
casDir,
|
|
||||||
firstResume.head as CasRef,
|
|
||||||
);
|
|
||||||
|
|
||||||
const secondResult = runUwf(
|
|
||||||
["thread", "resume", THREAD_ID, "--agent", okMockAgentPath],
|
|
||||||
casDir,
|
|
||||||
);
|
|
||||||
expect(secondResult.status).toBe(0);
|
|
||||||
const secondResume = JSON.parse(secondResult.stdout.trim());
|
|
||||||
expect(secondResume.status).toBe("idle");
|
|
||||||
expect(secondResume.currentRole).toBe("reviewer");
|
|
||||||
expect(secondResume.suspendedRole).toBeNull();
|
|
||||||
expect(secondResume.suspendMessage).toBeNull();
|
|
||||||
|
|
||||||
const capturedPrompt = await readFile(promptCapturePath, "utf8");
|
|
||||||
expect(capturedPrompt).toBe(SUSPEND_MESSAGE);
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
async function setupOkMockAgent(
|
|
||||||
casDir: string,
|
|
||||||
prevHead: CasRef,
|
|
||||||
): Promise<{ mockAgentPath: string }> {
|
|
||||||
const store = createFsStore(casDir);
|
|
||||||
const schemas = await registerUwfSchemas(store);
|
|
||||||
const outputSchemaHash = await putSchema(store, OUTPUT_SCHEMA);
|
|
||||||
|
|
||||||
const prevNode = store.get(prevHead);
|
|
||||||
if (prevNode === null || prevNode.type !== schemas.stepNode) {
|
|
||||||
throw new Error(`expected StepNode at ${prevHead}`);
|
|
||||||
}
|
|
||||||
const prevPayload = prevNode.payload as StepNodePayload;
|
|
||||||
|
|
||||||
const outputHash = await store.put(outputSchemaHash, { $status: "ok" });
|
|
||||||
const detailHash = await store.put(schemas.text, "ok detail");
|
|
||||||
const startedAtMs = Date.now();
|
|
||||||
const completedAtMs = startedAtMs + 1;
|
|
||||||
|
|
||||||
const stepHash = await store.put(schemas.stepNode, {
|
|
||||||
start: prevPayload.start,
|
|
||||||
prev: prevHead,
|
|
||||||
role: "worker",
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-mock",
|
|
||||||
edgePrompt: "resume",
|
|
||||||
startedAtMs,
|
|
||||||
completedAtMs,
|
|
||||||
cwd: tmpDir,
|
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const promptCapturePath = join(tmpDir, "captured-prompt.txt");
|
|
||||||
const mockAgentPath = join(tmpDir, "mock-agent-ok.sh");
|
|
||||||
const adapterJson = JSON.stringify({
|
|
||||||
stepHash,
|
|
||||||
detailHash,
|
|
||||||
role: "worker",
|
|
||||||
frontmatter: { $status: "ok" },
|
|
||||||
body: "",
|
|
||||||
startedAtMs,
|
|
||||||
completedAtMs,
|
|
||||||
});
|
|
||||||
|
|
||||||
await writeFile(
|
|
||||||
mockAgentPath,
|
|
||||||
`#!/bin/sh
|
|
||||||
prompt=""
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
if [ "$1" = "--prompt" ]; then
|
|
||||||
prompt="$2"
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
printf '%s' "$prompt" > '${promptCapturePath}'
|
|
||||||
echo '${adapterJson}'
|
|
||||||
`,
|
|
||||||
{ mode: 0o755 },
|
|
||||||
);
|
|
||||||
|
|
||||||
return { mockAgentPath };
|
|
||||||
}
|
|
||||||
@@ -1,350 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { putSchema } from "@ocas/core";
|
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { createMarker, deleteMarker } from "../background/index.js";
|
|
||||||
import { cmdThreadShow, cmdThreadStart } from "../commands/thread.js";
|
|
||||||
import {
|
|
||||||
appendThreadHistory,
|
|
||||||
createUwfStore,
|
|
||||||
loadThreadsIndex,
|
|
||||||
saveThreadsIndex,
|
|
||||||
} from "../store.js";
|
|
||||||
|
|
||||||
const OUTPUT_SCHEMA = {
|
|
||||||
type: "object" as const,
|
|
||||||
properties: {
|
|
||||||
$status: { type: "string" as const },
|
|
||||||
question: { type: "string" as const },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const TEST_WORKFLOW_YAML = `
|
|
||||||
name: test-status
|
|
||||||
description: Test workflow for status field
|
|
||||||
roles:
|
|
||||||
planner:
|
|
||||||
description: Plans the work
|
|
||||||
goal: Plan implementation
|
|
||||||
capabilities: ["planning"]
|
|
||||||
procedure: Plan
|
|
||||||
output: |
|
|
||||||
$status: "ready"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: planner
|
|
||||||
prompt: "Plan the work"
|
|
||||||
location: null
|
|
||||||
planner:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
const SUSPEND_WORKFLOW_YAML = `
|
|
||||||
name: test-suspend-status
|
|
||||||
description: Test workflow for suspended status
|
|
||||||
roles:
|
|
||||||
worker:
|
|
||||||
description: Worker role
|
|
||||||
goal: Work
|
|
||||||
capabilities: ["coding"]
|
|
||||||
procedure: Work
|
|
||||||
output: |
|
|
||||||
$status: "needs_input"
|
|
||||||
question: "Which API?"
|
|
||||||
frontmatter:
|
|
||||||
oneOf:
|
|
||||||
- type: object
|
|
||||||
required: ["$status", "question"]
|
|
||||||
properties:
|
|
||||||
$status: { const: "needs_input" }
|
|
||||||
question: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: worker
|
|
||||||
prompt: "Start work"
|
|
||||||
location: null
|
|
||||||
worker:
|
|
||||||
needs_input:
|
|
||||||
role: $SUSPEND
|
|
||||||
prompt: "Please clarify: {{{question}}}"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
async function insertStepNode(
|
|
||||||
storageRoot: string,
|
|
||||||
threadId: ThreadId,
|
|
||||||
role: string,
|
|
||||||
outputPayload: Record<string, unknown>,
|
|
||||||
): Promise<void> {
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const headEntry = index[threadId];
|
|
||||||
if (headEntry === undefined) throw new Error(`thread ${threadId} not in index`);
|
|
||||||
const head = headEntry.head;
|
|
||||||
|
|
||||||
const outputSchemaHash = await putSchema(uwf.store, OUTPUT_SCHEMA);
|
|
||||||
const outputHash = await uwf.store.put(outputSchemaHash, outputPayload);
|
|
||||||
const detailHash = await uwf.store.put(uwf.schemas.text, "detail-placeholder");
|
|
||||||
|
|
||||||
const headNode = uwf.store.get(head);
|
|
||||||
if (headNode === null) throw new Error(`head ${head} not found`);
|
|
||||||
const isStart = headNode.type === uwf.schemas.startNode;
|
|
||||||
const startHash = isStart ? head : (headNode.payload as { start: CasRef }).start;
|
|
||||||
|
|
||||||
const stepHash = (await uwf.store.put(uwf.schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: isStart ? null : head,
|
|
||||||
role,
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-test",
|
|
||||||
edgePrompt: "edge",
|
|
||||||
startedAtMs: Date.now(),
|
|
||||||
completedAtMs: Date.now() + 1,
|
|
||||||
cwd: "/tmp",
|
|
||||||
assembledPrompt: null,
|
|
||||||
})) as CasRef;
|
|
||||||
|
|
||||||
index[threadId] = { head: stepHash, suspendedRole: null, suspendMessage: null };
|
|
||||||
await saveThreadsIndex(storageRoot, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("thread show status field", () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
let storageRoot: string;
|
|
||||||
|
|
||||||
async function setupTestEnv() {
|
|
||||||
tmpDir = join(tmpdir(), `uwf-test-status-${Date.now()}`);
|
|
||||||
storageRoot = join(tmpDir, "storage");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function teardown() {
|
|
||||||
if (tmpDir) {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test("active idle thread shows status 'idle'", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-status.yaml");
|
|
||||||
await writeFile(workflowPath, TEST_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
// Create a thread
|
|
||||||
const startResult = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir);
|
|
||||||
const threadId = startResult.thread as ThreadId;
|
|
||||||
|
|
||||||
// Show the thread (should be idle)
|
|
||||||
const result = await cmdThreadShow(storageRoot, threadId);
|
|
||||||
|
|
||||||
expect(result.status).toBe("idle");
|
|
||||||
expect(result.done).toBe(false);
|
|
||||||
expect(result.background).toBe(null);
|
|
||||||
expect(result.thread).toBe(threadId);
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("active running thread shows status 'running'", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-status.yaml");
|
|
||||||
await writeFile(workflowPath, TEST_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
// Create a thread
|
|
||||||
const startResult = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir);
|
|
||||||
const threadId = startResult.thread as ThreadId;
|
|
||||||
const workflow = startResult.workflow;
|
|
||||||
|
|
||||||
// Create a running marker
|
|
||||||
await createMarker(storageRoot, {
|
|
||||||
thread: threadId,
|
|
||||||
workflow,
|
|
||||||
pid: process.pid,
|
|
||||||
startedAt: Date.now(),
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await cmdThreadShow(storageRoot, threadId);
|
|
||||||
|
|
||||||
expect(result.status).toBe("running");
|
|
||||||
expect(result.done).toBe(false);
|
|
||||||
expect(result.background).toBe(null);
|
|
||||||
expect(result.thread).toBe(threadId);
|
|
||||||
} finally {
|
|
||||||
// Cleanup: delete marker
|
|
||||||
await deleteMarker(storageRoot, threadId);
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("completed thread shows status 'completed'", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-status.yaml");
|
|
||||||
await writeFile(workflowPath, TEST_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
// Create a thread
|
|
||||||
const startResult = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir);
|
|
||||||
const threadId = startResult.thread as ThreadId;
|
|
||||||
const workflow = startResult.workflow;
|
|
||||||
|
|
||||||
// Get the head hash before moving to history
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const head = index[threadId]!.head;
|
|
||||||
if (!head) throw new Error("Thread not found in index");
|
|
||||||
|
|
||||||
// Move thread to history with reason 'completed'
|
|
||||||
const { saveThreadsIndex } = await import("../store.js");
|
|
||||||
const newIndex = { ...index };
|
|
||||||
delete newIndex[threadId];
|
|
||||||
await saveThreadsIndex(storageRoot, newIndex);
|
|
||||||
|
|
||||||
await appendThreadHistory(storageRoot, {
|
|
||||||
thread: threadId,
|
|
||||||
workflow,
|
|
||||||
head,
|
|
||||||
completedAt: Date.now(),
|
|
||||||
reason: "completed",
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, threadId);
|
|
||||||
|
|
||||||
expect(result.status).toBe("completed");
|
|
||||||
expect(result.done).toBe(true);
|
|
||||||
expect(result.background).toBe(null);
|
|
||||||
expect(result.thread).toBe(threadId);
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("cancelled thread shows status 'cancelled'", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-status.yaml");
|
|
||||||
await writeFile(workflowPath, TEST_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
// Create a thread
|
|
||||||
const startResult = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir);
|
|
||||||
const threadId = startResult.thread as ThreadId;
|
|
||||||
const workflow = startResult.workflow;
|
|
||||||
|
|
||||||
// Get the head hash before moving to history
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const head = index[threadId]!.head;
|
|
||||||
if (!head) throw new Error("Thread not found in index");
|
|
||||||
|
|
||||||
// Move thread to history with reason 'cancelled'
|
|
||||||
const { saveThreadsIndex } = await import("../store.js");
|
|
||||||
const newIndex = { ...index };
|
|
||||||
delete newIndex[threadId];
|
|
||||||
await saveThreadsIndex(storageRoot, newIndex);
|
|
||||||
|
|
||||||
await appendThreadHistory(storageRoot, {
|
|
||||||
thread: threadId,
|
|
||||||
workflow,
|
|
||||||
head,
|
|
||||||
completedAt: Date.now(),
|
|
||||||
reason: "cancelled",
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, threadId);
|
|
||||||
|
|
||||||
expect(result.status).toBe("cancelled");
|
|
||||||
expect(result.done).toBe(true);
|
|
||||||
expect(result.background).toBe(null);
|
|
||||||
expect(result.thread).toBe(threadId);
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("legacy completed thread without reason shows status 'completed'", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-status.yaml");
|
|
||||||
await writeFile(workflowPath, TEST_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
// Create a thread
|
|
||||||
const startResult = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir);
|
|
||||||
const threadId = startResult.thread as ThreadId;
|
|
||||||
const workflow = startResult.workflow;
|
|
||||||
|
|
||||||
// Get the head hash before moving to history
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const head = index[threadId]!.head;
|
|
||||||
if (!head) throw new Error("Thread not found in index");
|
|
||||||
|
|
||||||
// Move thread to history with reason null (legacy format)
|
|
||||||
const { saveThreadsIndex } = await import("../store.js");
|
|
||||||
const newIndex = { ...index };
|
|
||||||
delete newIndex[threadId];
|
|
||||||
await saveThreadsIndex(storageRoot, newIndex);
|
|
||||||
|
|
||||||
await appendThreadHistory(storageRoot, {
|
|
||||||
thread: threadId,
|
|
||||||
workflow,
|
|
||||||
head,
|
|
||||||
completedAt: Date.now(),
|
|
||||||
reason: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, threadId);
|
|
||||||
|
|
||||||
expect(result.status).toBe("completed");
|
|
||||||
expect(result.done).toBe(true);
|
|
||||||
expect(result.background).toBe(null);
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("active suspended thread shows status 'suspended'", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const workflowPath = join(tmpDir, "test-suspend-status.yaml");
|
|
||||||
await writeFile(workflowPath, SUSPEND_WORKFLOW_YAML, "utf8");
|
|
||||||
|
|
||||||
const startResult = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir);
|
|
||||||
const threadId = startResult.thread as ThreadId;
|
|
||||||
|
|
||||||
await insertStepNode(storageRoot, threadId, "worker", {
|
|
||||||
$status: "needs_input",
|
|
||||||
question: "Which API?",
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await cmdThreadShow(storageRoot, threadId);
|
|
||||||
|
|
||||||
expect(result.status).toBe("suspended");
|
|
||||||
expect(result.done).toBe(false);
|
|
||||||
expect(result.currentRole).toBe(null);
|
|
||||||
expect(result.suspendedRole).toBe("worker");
|
|
||||||
expect(result.suspendMessage).toBe("Please clarify: Which API?");
|
|
||||||
expect(result.background).toBe(null);
|
|
||||||
expect(result.thread).toBe(threadId);
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
await teardown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { execFileSync } from "node:child_process";
|
|
||||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import type { CasRef, StartNodePayload, ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { cmdThreadStart } from "../commands/thread.js";
|
|
||||||
import { createUwfStore, loadThreadsIndex } from "../store.js";
|
|
||||||
|
|
||||||
describe("thread start --cwd CLI option", () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
let storageRoot: string;
|
|
||||||
let casDir: string;
|
|
||||||
let originalEnv: string | undefined;
|
|
||||||
|
|
||||||
async function setupTestEnv() {
|
|
||||||
tmpDir = join(tmpdir(), `uwf-test-cwd-cli-${Date.now()}`);
|
|
||||||
storageRoot = join(tmpDir, "storage");
|
|
||||||
casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(storageRoot, { recursive: true });
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
|
|
||||||
// Set UNCAGED_CAS_DIR for this test
|
|
||||||
originalEnv = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function teardown() {
|
|
||||||
if (tmpDir) {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
// Restore original environment
|
|
||||||
if (originalEnv === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalEnv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createTestWorkflow(): Promise<string> {
|
|
||||||
const workflowYaml = `
|
|
||||||
name: test-cwd-cli
|
|
||||||
description: Test workflow for CLI cwd option
|
|
||||||
roles:
|
|
||||||
planner:
|
|
||||||
description: Plans the work
|
|
||||||
goal: Plan implementation
|
|
||||||
capabilities: ["planning"]
|
|
||||||
procedure: Plan
|
|
||||||
output: |
|
|
||||||
$status: "ready"
|
|
||||||
frontmatter:
|
|
||||||
type: object
|
|
||||||
required: ["$status"]
|
|
||||||
properties:
|
|
||||||
$status: { type: string }
|
|
||||||
graph:
|
|
||||||
$START:
|
|
||||||
_:
|
|
||||||
role: planner
|
|
||||||
prompt: "Plan the work"
|
|
||||||
location: null
|
|
||||||
planner:
|
|
||||||
_:
|
|
||||||
role: $END
|
|
||||||
prompt: "Done"
|
|
||||||
location: null
|
|
||||||
`;
|
|
||||||
|
|
||||||
const workflowPath = join(tmpDir, "test-cwd-cli.yaml");
|
|
||||||
await writeFile(workflowPath, workflowYaml, "utf8");
|
|
||||||
return workflowPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getStartNodeCwd(threadId: string): Promise<string> {
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const headHash = index[threadId as ThreadId]!.head;
|
|
||||||
expect(headHash).toBeDefined();
|
|
||||||
|
|
||||||
const startNode = uwf.store.get(headHash as CasRef);
|
|
||||||
expect(startNode).not.toBe(null);
|
|
||||||
expect(startNode?.type).toBe(uwf.schemas.startNode);
|
|
||||||
|
|
||||||
const startPayload = startNode?.payload as StartNodePayload;
|
|
||||||
return startPayload.cwd;
|
|
||||||
}
|
|
||||||
|
|
||||||
test("thread start with custom cwd via cmdThreadStart", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = await createTestWorkflow();
|
|
||||||
const testCwd = "/test/custom/path";
|
|
||||||
|
|
||||||
const result = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir, testCwd);
|
|
||||||
|
|
||||||
expect(result.thread).toBeDefined();
|
|
||||||
const actualCwd = await getStartNodeCwd(result.thread);
|
|
||||||
expect(actualCwd).toBe(testCwd);
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("thread start without cwd defaults to process.cwd()", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = await createTestWorkflow();
|
|
||||||
|
|
||||||
// Call without cwd parameter (it defaults to process.cwd())
|
|
||||||
const result = await cmdThreadStart(storageRoot, workflowPath, "test prompt", tmpDir);
|
|
||||||
|
|
||||||
expect(result.thread).toBeDefined();
|
|
||||||
const actualCwd = await getStartNodeCwd(result.thread);
|
|
||||||
expect(actualCwd).toBe(process.cwd());
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("thread start with relative path fails", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = await createTestWorkflow();
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
cmdThreadStart(storageRoot, workflowPath, "test", tmpDir, "relative/path"),
|
|
||||||
).rejects.toThrow();
|
|
||||||
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("CLI accepts --cwd option without error", async () => {
|
|
||||||
await setupTestEnv();
|
|
||||||
|
|
||||||
const workflowPath = await createTestWorkflow();
|
|
||||||
const testCwd = "/test/cli/path";
|
|
||||||
const uwfBin = join(process.cwd(), "dist", "cli.js");
|
|
||||||
|
|
||||||
// Register the workflow
|
|
||||||
execFileSync("bun", [uwfBin, "workflow", "add", workflowPath], {
|
|
||||||
env: { ...process.env, UWF_STORAGE_ROOT: storageRoot, UNCAGED_CAS_DIR: casDir },
|
|
||||||
encoding: "utf8",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Verify CLI accepts --cwd option (no error thrown)
|
|
||||||
const output = execFileSync(
|
|
||||||
"bun",
|
|
||||||
[uwfBin, "thread", "start", "test-cwd-cli", "-p", "test prompt", "--cwd", testCwd],
|
|
||||||
{
|
|
||||||
env: { ...process.env, UWF_STORAGE_ROOT: storageRoot, UNCAGED_CAS_DIR: casDir },
|
|
||||||
encoding: "utf8",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = JSON.parse(output);
|
|
||||||
expect(result.thread).toBeDefined();
|
|
||||||
expect(result.workflow).toBeDefined();
|
|
||||||
|
|
||||||
// The fact that we got here without throwing means CLI accepted the --cwd option
|
|
||||||
// The actual cwd functionality is tested by the other tests using cmdThreadStart directly
|
|
||||||
await teardown();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { execFileSync } from "node:child_process";
|
import { execFileSync } from "node:child_process";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
const CLI_PATH = join(import.meta.dirname, "..", "cli.js");
|
const CLI_PATH = join(import.meta.dirname, "..", "cli.js");
|
||||||
|
|
||||||
|
|||||||
@@ -1,179 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { execFileSync } from "node:child_process";
|
|
||||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { putSchema } from "@ocas/core";
|
|
||||||
import { createFsStore } from "@ocas/fs";
|
|
||||||
import type { CasRef, StepNodePayload, ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { parse } from "yaml";
|
|
||||||
import { cmdThreadShow } from "../commands/thread.js";
|
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
|
||||||
import { saveThreadsIndex } from "../store.js";
|
|
||||||
|
|
||||||
const OUTPUT_SCHEMA = {
|
|
||||||
type: "object" as const,
|
|
||||||
properties: {
|
|
||||||
$status: { type: "string" as const },
|
|
||||||
question: { type: "string" as const },
|
|
||||||
},
|
|
||||||
required: ["$status"],
|
|
||||||
additionalProperties: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let tmpDir: string;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-suspend-step-test-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("suspend step CAS chain and threads.yaml metadata", () => {
|
|
||||||
test("thread exec records suspend step in CAS and suspend metadata in threads.yaml", async () => {
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const store = createFsStore(casDir);
|
|
||||||
const schemas = await registerUwfSchemas(store);
|
|
||||||
|
|
||||||
const outputSchemaHash = await putSchema(store, OUTPUT_SCHEMA);
|
|
||||||
|
|
||||||
const workflowHash = await store.put(schemas.workflow, {
|
|
||||||
name: "test-suspend-step",
|
|
||||||
description: "suspend step integration test",
|
|
||||||
roles: {
|
|
||||||
worker: {
|
|
||||||
description: "Worker role",
|
|
||||||
goal: "Work",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "work",
|
|
||||||
output: "result",
|
|
||||||
frontmatter: outputSchemaHash,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
$START: { _: { role: "worker", prompt: "Start work", location: null } },
|
|
||||||
worker: {
|
|
||||||
needs_input: {
|
|
||||||
role: "$SUSPEND",
|
|
||||||
prompt: "Please clarify: {{{question}}}",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const startHash = await store.put(schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "Test suspend task",
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
const threadId = "01SUSPENDSTEPTEST0000000" as ThreadId;
|
|
||||||
await saveThreadsIndex(tmpDir, { [threadId]: startHash });
|
|
||||||
|
|
||||||
const outputHash = await store.put(outputSchemaHash, {
|
|
||||||
$status: "needs_input",
|
|
||||||
question: "Which API?",
|
|
||||||
});
|
|
||||||
const detailHash = await store.put(schemas.text, "mock detail");
|
|
||||||
|
|
||||||
const startedAtMs = 1716600000000;
|
|
||||||
const completedAtMs = 1716600001500;
|
|
||||||
|
|
||||||
const stepHash = await store.put(schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: null,
|
|
||||||
role: "worker",
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-mock",
|
|
||||||
edgePrompt: "Start work",
|
|
||||||
startedAtMs,
|
|
||||||
completedAtMs,
|
|
||||||
cwd: tmpDir,
|
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const mockAgentPath = join(tmpDir, "mock-agent.sh");
|
|
||||||
const adapterJson = JSON.stringify({
|
|
||||||
stepHash,
|
|
||||||
detailHash,
|
|
||||||
role: "worker",
|
|
||||||
frontmatter: { $status: "needs_input", question: "Which API?" },
|
|
||||||
body: "",
|
|
||||||
startedAtMs,
|
|
||||||
completedAtMs,
|
|
||||||
});
|
|
||||||
await writeFile(mockAgentPath, `#!/bin/sh\necho '${adapterJson}'\n`, { mode: 0o755 });
|
|
||||||
|
|
||||||
const configPath = join(tmpDir, "config.yaml");
|
|
||||||
await writeFile(
|
|
||||||
configPath,
|
|
||||||
`defaultAgent: uwf-hermes\ndefaultModel: test-model\nagentOverrides: null\nagents: {}\nproviders: {}\nmodels: {}\n`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const cliPath = join(import.meta.dirname, "..", "cli.js");
|
|
||||||
const stdout = execFileSync(
|
|
||||||
"bun",
|
|
||||||
["run", cliPath, "thread", "exec", threadId, "--agent", mockAgentPath],
|
|
||||||
{
|
|
||||||
encoding: "utf8",
|
|
||||||
stdio: ["ignore", "pipe", "pipe"],
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
WORKFLOW_STORAGE_ROOT: tmpDir,
|
|
||||||
UNCAGED_CAS_DIR: casDir,
|
|
||||||
},
|
|
||||||
cwd: tmpDir,
|
|
||||||
timeout: 30000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const cliOutput = JSON.parse(stdout.trim());
|
|
||||||
expect(cliOutput.status).toBe("suspended");
|
|
||||||
expect(cliOutput.head).toBe(stepHash);
|
|
||||||
expect(cliOutput.suspendedRole).toBe("worker");
|
|
||||||
expect(cliOutput.suspendMessage).toBe("Please clarify: Which API?");
|
|
||||||
|
|
||||||
const storeAfter = createFsStore(casDir);
|
|
||||||
const stepNode = storeAfter.get(cliOutput.head as CasRef);
|
|
||||||
expect(stepNode).not.toBeNull();
|
|
||||||
const payload = stepNode!.payload as StepNodePayload;
|
|
||||||
expect(payload.role).toBe("worker");
|
|
||||||
expect(payload.output).toBe(outputHash);
|
|
||||||
|
|
||||||
const outputNode = storeAfter.get(outputHash);
|
|
||||||
expect(outputNode?.payload).toEqual({
|
|
||||||
$status: "needs_input",
|
|
||||||
question: "Which API?",
|
|
||||||
});
|
|
||||||
|
|
||||||
const threadsYaml = await readFile(join(tmpDir, "threads.yaml"), "utf8");
|
|
||||||
const threadsIndex = parse(threadsYaml) as Record<string, unknown>;
|
|
||||||
const threadEntry = threadsIndex[threadId];
|
|
||||||
expect(threadEntry).toEqual({
|
|
||||||
head: stepHash,
|
|
||||||
suspendedRole: "worker",
|
|
||||||
suspendMessage: "Please clarify: Which API?",
|
|
||||||
});
|
|
||||||
|
|
||||||
const showResult = await cmdThreadShow(tmpDir, threadId);
|
|
||||||
expect(showResult.status).toBe("suspended");
|
|
||||||
expect(showResult.suspendMessage).toBe("Please clarify: Which API?");
|
|
||||||
expect(showResult.suspendedRole).toBe("worker");
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,286 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { putSchema } from "@ocas/core";
|
|
||||||
import type { ThreadId } from "@uncaged/workflow-protocol";
|
|
||||||
import { createThreadIndexEntry, markThreadSuspended } from "@uncaged/workflow-protocol";
|
|
||||||
import { cmdThreadList, cmdThreadShow } from "../commands/thread.js";
|
|
||||||
import { createUwfStore, saveThreadsIndex } from "../store.js";
|
|
||||||
|
|
||||||
const OUTPUT_SCHEMA = {
|
|
||||||
type: "object" as const,
|
|
||||||
properties: {
|
|
||||||
$status: { type: "string" as const },
|
|
||||||
question: { type: "string" as const },
|
|
||||||
},
|
|
||||||
required: ["$status"],
|
|
||||||
additionalProperties: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let tmpDir: string;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-suspended-display-test-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await rm(tmpDir, { recursive: true, force: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("suspended thread display", () => {
|
|
||||||
test("thread list shows [suspended] marker for suspended threads", async () => {
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const uwf = await createUwfStore(tmpDir);
|
|
||||||
const outputSchemaHash = await putSchema(uwf.store, OUTPUT_SCHEMA);
|
|
||||||
|
|
||||||
// Create test workflow with suspend capability
|
|
||||||
const workflowHash = await uwf.store.put(uwf.schemas.workflow, {
|
|
||||||
name: "test-suspend-display",
|
|
||||||
description: "test suspended display",
|
|
||||||
roles: {
|
|
||||||
worker: {
|
|
||||||
description: "Worker role",
|
|
||||||
goal: "Work and potentially suspend",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "work",
|
|
||||||
output: "result",
|
|
||||||
frontmatter: outputSchemaHash,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
$START: { _: { role: "worker", prompt: "Start work", location: null } },
|
|
||||||
worker: {
|
|
||||||
needs_input: {
|
|
||||||
role: "$SUSPEND",
|
|
||||||
prompt: "Please provide more details: {{{question}}}",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const startHash = await uwf.store.put(uwf.schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "Test task requiring input",
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create suspended thread
|
|
||||||
const suspendedThreadId = "01SUSPENDEDTHREAD0000000" as ThreadId;
|
|
||||||
const outputHash = await uwf.store.put(outputSchemaHash, {
|
|
||||||
$status: "needs_input",
|
|
||||||
question: "What is the target API?",
|
|
||||||
});
|
|
||||||
const detailHash = await uwf.store.put(uwf.schemas.text, "mock detail");
|
|
||||||
|
|
||||||
const stepHash = await uwf.store.put(uwf.schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: null,
|
|
||||||
role: "worker",
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-mock",
|
|
||||||
edgePrompt: "Start work",
|
|
||||||
startedAtMs: 1716600000000,
|
|
||||||
completedAtMs: 1716600001500,
|
|
||||||
cwd: tmpDir,
|
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create suspended thread entry in threads.yaml
|
|
||||||
const suspendedEntry = markThreadSuspended(
|
|
||||||
createThreadIndexEntry(stepHash),
|
|
||||||
"worker",
|
|
||||||
"Please provide more details: What is the target API?",
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create normal (idle) thread
|
|
||||||
const idleThreadId = "01IDLETHREAD00000000000" as ThreadId;
|
|
||||||
const idleStartHash = await uwf.store.put(uwf.schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "Normal task",
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
const idleEntry = createThreadIndexEntry(idleStartHash);
|
|
||||||
|
|
||||||
await saveThreadsIndex(tmpDir, {
|
|
||||||
[suspendedThreadId]: suspendedEntry,
|
|
||||||
[idleThreadId]: idleEntry,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test thread list
|
|
||||||
const listResult = await cmdThreadList(tmpDir, null, null, null, null, null);
|
|
||||||
|
|
||||||
// Find the suspended and idle threads in results
|
|
||||||
const suspendedItem = listResult.find((item) => item.thread === suspendedThreadId);
|
|
||||||
const idleItem = listResult.find((item) => item.thread === idleThreadId);
|
|
||||||
|
|
||||||
expect(suspendedItem).toBeDefined();
|
|
||||||
expect(suspendedItem!.status).toBe("suspended");
|
|
||||||
expect(suspendedItem!.statusDisplay).toBe("suspended [suspended]");
|
|
||||||
|
|
||||||
expect(idleItem).toBeDefined();
|
|
||||||
expect(idleItem!.status).toBe("idle");
|
|
||||||
expect(idleItem!.statusDisplay).toBe("idle");
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("thread show displays suspend info and resume hint", async () => {
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const uwf = await createUwfStore(tmpDir);
|
|
||||||
const outputSchemaHash = await putSchema(uwf.store, OUTPUT_SCHEMA);
|
|
||||||
|
|
||||||
const workflowHash = await uwf.store.put(uwf.schemas.workflow, {
|
|
||||||
name: "test-suspend-show",
|
|
||||||
description: "test suspended show",
|
|
||||||
roles: {
|
|
||||||
worker: {
|
|
||||||
description: "Worker role",
|
|
||||||
goal: "Work and potentially suspend",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "work",
|
|
||||||
output: "result",
|
|
||||||
frontmatter: outputSchemaHash,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
$START: { _: { role: "worker", prompt: "Start work", location: null } },
|
|
||||||
worker: {
|
|
||||||
needs_input: {
|
|
||||||
role: "$SUSPEND",
|
|
||||||
prompt: "Need clarification: {{{question}}}",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const startHash = await uwf.store.put(uwf.schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "Test task",
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
const threadId = "01SUSPENDSHOW000000000" as ThreadId;
|
|
||||||
const outputHash = await uwf.store.put(outputSchemaHash, {
|
|
||||||
$status: "needs_input",
|
|
||||||
question: "Which database to use?",
|
|
||||||
});
|
|
||||||
const detailHash = await uwf.store.put(uwf.schemas.text, "mock detail");
|
|
||||||
|
|
||||||
const stepHash = await uwf.store.put(uwf.schemas.stepNode, {
|
|
||||||
start: startHash,
|
|
||||||
prev: null,
|
|
||||||
role: "worker",
|
|
||||||
output: outputHash,
|
|
||||||
detail: detailHash,
|
|
||||||
agent: "uwf-mock",
|
|
||||||
edgePrompt: "Start work",
|
|
||||||
startedAtMs: 1716600000000,
|
|
||||||
completedAtMs: 1716600001500,
|
|
||||||
cwd: tmpDir,
|
|
||||||
assembledPrompt: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const suspendedEntry = markThreadSuspended(
|
|
||||||
createThreadIndexEntry(stepHash),
|
|
||||||
"worker",
|
|
||||||
"Need clarification: Which database to use?",
|
|
||||||
);
|
|
||||||
|
|
||||||
await saveThreadsIndex(tmpDir, { [threadId]: suspendedEntry });
|
|
||||||
|
|
||||||
// Test thread show
|
|
||||||
const showResult = await cmdThreadShow(tmpDir, threadId);
|
|
||||||
|
|
||||||
expect(showResult.status).toBe("suspended");
|
|
||||||
expect(showResult.suspendedRole).toBe("worker");
|
|
||||||
expect(showResult.suspendMessage).toBe("Need clarification: Which database to use?");
|
|
||||||
expect(showResult.hint).toBe(
|
|
||||||
`Thread is suspended. Resume with: uwf thread resume ${threadId}`,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("non-suspended threads do not show suspend markers or hints", async () => {
|
|
||||||
const casDir = join(tmpDir, "cas");
|
|
||||||
await mkdir(casDir, { recursive: true });
|
|
||||||
const originalCasDir = process.env.UNCAGED_CAS_DIR;
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const uwf = await createUwfStore(tmpDir);
|
|
||||||
|
|
||||||
const workflowHash = await uwf.store.put(uwf.schemas.workflow, {
|
|
||||||
name: "test-normal",
|
|
||||||
description: "test normal thread",
|
|
||||||
roles: {
|
|
||||||
worker: {
|
|
||||||
description: "Worker role",
|
|
||||||
goal: "Work normally",
|
|
||||||
capabilities: [],
|
|
||||||
procedure: "work",
|
|
||||||
output: "result",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
$START: { _: { role: "worker", prompt: "Start work", location: null } },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const startHash = await uwf.store.put(uwf.schemas.startNode, {
|
|
||||||
workflow: workflowHash,
|
|
||||||
prompt: "Normal task",
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
const threadId = "01NORMALTHREAD000000000" as ThreadId;
|
|
||||||
await saveThreadsIndex(tmpDir, { [threadId]: createThreadIndexEntry(startHash) });
|
|
||||||
|
|
||||||
// Test thread show
|
|
||||||
const showResult = await cmdThreadShow(tmpDir, threadId);
|
|
||||||
|
|
||||||
expect(showResult.status).toBe("idle");
|
|
||||||
expect(showResult.suspendedRole).toBeNull();
|
|
||||||
expect(showResult.suspendMessage).toBeNull();
|
|
||||||
expect(showResult.hint).toBeNull();
|
|
||||||
|
|
||||||
// Test thread list
|
|
||||||
const listResult = await cmdThreadList(tmpDir, null, null, null, null, null);
|
|
||||||
const threadItem = listResult.find((item) => item.thread === threadId);
|
|
||||||
|
|
||||||
expect(threadItem).toBeDefined();
|
|
||||||
expect(threadItem!.status).toBe("idle");
|
|
||||||
expect(threadItem!.statusDisplay).toBe("idle");
|
|
||||||
} finally {
|
|
||||||
if (originalCasDir === undefined) {
|
|
||||||
delete process.env.UNCAGED_CAS_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.UNCAGED_CAS_DIR = originalCasDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { bootstrap, putSchema } from "@ocas/core";
|
import { bootstrap, putSchema } from "@uncaged/json-cas";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { cmdStepList, cmdStepShow } from "../commands/step.js";
|
import { cmdStepList, cmdStepShow } from "../commands/step.js";
|
||||||
import {
|
import {
|
||||||
cmdThreadRead,
|
cmdThreadRead,
|
||||||
@@ -47,7 +47,7 @@ const DETAIL_SCHEMA = {
|
|||||||
turnCount: { type: "integer" as const },
|
turnCount: { type: "integer" as const },
|
||||||
turns: {
|
turns: {
|
||||||
type: "array" as const,
|
type: "array" as const,
|
||||||
items: { type: "string" as const, format: "ocas_ref" },
|
items: { type: "string" as const, format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
@@ -58,8 +58,6 @@ const DETAIL_SCHEMA = {
|
|||||||
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
||||||
const casDir = join(storageRoot, "cas");
|
const casDir = join(storageRoot, "cas");
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
// Set UNCAGED_CAS_DIR to use the test's CAS directory
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
return { storageRoot, store, schemas };
|
return { storageRoot, store, schemas };
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import type { WorkflowPayload } from "@uncaged/workflow-protocol";
|
import type { WorkflowPayload } from "@uncaged/workflow-protocol";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
import { validateWorkflow } from "../validate-semantic.js";
|
import { validateWorkflow } from "../validate-semantic.js";
|
||||||
|
|
||||||
/** Build a valid two-role workflow that passes all checks. */
|
/** Build a valid two-role workflow that passes all checks. */
|
||||||
@@ -51,11 +51,11 @@ function makeWorkflow(overrides?: Partial<WorkflowPayload>): WorkflowPayload {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
graph: {
|
graph: {
|
||||||
$START: { _: { role: "writer", prompt: "Begin writing", location: null } },
|
$START: { _: { role: "writer", prompt: "Begin writing" } },
|
||||||
writer: { _: { role: "reviewer", prompt: "Review this: {{{plan}}}", location: null } },
|
writer: { _: { role: "reviewer", prompt: "Review this: {{{plan}}}" } },
|
||||||
reviewer: {
|
reviewer: {
|
||||||
approved: { role: "$END", prompt: "Done: {{{summary}}}", location: null },
|
approved: { role: "$END", prompt: "Done: {{{summary}}}" },
|
||||||
rejected: { role: "writer", prompt: "Fix: {{{reason}}}", location: null },
|
rejected: { role: "writer", prompt: "Fix: {{{reason}}}" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -67,7 +67,7 @@ function makeWorkflow(overrides?: Partial<WorkflowPayload>): WorkflowPayload {
|
|||||||
describe("Suite 1: Role Reference Integrity", () => {
|
describe("Suite 1: Role Reference Integrity", () => {
|
||||||
test("1.1 graph references unknown role", () => {
|
test("1.1 graph references unknown role", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.nonexistent = { _: { role: "$END", prompt: "done", location: null } };
|
wf.graph.nonexistent = { _: { role: "$END", prompt: "done" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes('unknown role "nonexistent"'))).toBe(true);
|
expect(errors.some((e) => e.includes('unknown role "nonexistent"'))).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -138,8 +138,8 @@ describe("Suite 2: Graph Structure", () => {
|
|||||||
test("2.2 $START has multiple status keys", () => {
|
test("2.2 $START has multiple status keys", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.$START = {
|
wf.graph.$START = {
|
||||||
_: { role: "writer", prompt: "Begin", location: null },
|
_: { role: "writer", prompt: "Begin" },
|
||||||
other: { role: "reviewer", prompt: "Also", location: null },
|
other: { role: "reviewer", prompt: "Also" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
@@ -149,7 +149,7 @@ describe("Suite 2: Graph Structure", () => {
|
|||||||
|
|
||||||
test("2.3 $START edge uses non-_ status", () => {
|
test("2.3 $START edge uses non-_ status", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.$START = { ready: { role: "writer", prompt: "Begin", location: null } };
|
wf.graph.$START = { ready: { role: "writer", prompt: "Begin" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
errors.some((e) => e.includes('$START must have exactly one edge with status "_"')),
|
errors.some((e) => e.includes('$START must have exactly one edge with status "_"')),
|
||||||
@@ -158,7 +158,7 @@ describe("Suite 2: Graph Structure", () => {
|
|||||||
|
|
||||||
test("2.4 $END has outgoing edges", () => {
|
test("2.4 $END has outgoing edges", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.$END = { _: { role: "writer", prompt: "Loop", location: null } };
|
wf.graph.$END = { _: { role: "writer", prompt: "Loop" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes("$END must not have outgoing edges"))).toBe(true);
|
expect(errors.some((e) => e.includes("$END must not have outgoing edges"))).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -177,7 +177,7 @@ describe("Suite 2: Graph Structure", () => {
|
|||||||
required: ["$status"],
|
required: ["$status"],
|
||||||
} as unknown as string,
|
} as unknown as string,
|
||||||
};
|
};
|
||||||
wf.graph.isolated = { _: { role: "$END", prompt: "done", location: null } };
|
wf.graph.isolated = { _: { role: "$END", prompt: "done" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes('role "isolated" is not reachable from $START'))).toBe(
|
expect(errors.some((e) => e.includes('role "isolated" is not reachable from $START'))).toBe(
|
||||||
true,
|
true,
|
||||||
@@ -186,7 +186,7 @@ describe("Suite 2: Graph Structure", () => {
|
|||||||
|
|
||||||
test("2.6 edge target references invalid role", () => {
|
test("2.6 edge target references invalid role", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.writer = { _: { role: "ghost", prompt: "Go to ghost", location: null } };
|
wf.graph.writer = { _: { role: "ghost", prompt: "Go to ghost" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes('unknown target role "ghost"'))).toBe(true);
|
expect(errors.some((e) => e.includes('unknown target role "ghost"'))).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -196,8 +196,8 @@ describe("Suite 3: Status-Edge Consistency", () => {
|
|||||||
test("3.1 single-exit role with multiple graph keys", () => {
|
test("3.1 single-exit role with multiple graph keys", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.writer = {
|
wf.graph.writer = {
|
||||||
_: { role: "reviewer", prompt: "Review", location: null },
|
_: { role: "reviewer", prompt: "Review" },
|
||||||
extra: { role: "$END", prompt: "Done", location: null },
|
extra: { role: "$END", prompt: "Done" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
@@ -209,7 +209,7 @@ describe("Suite 3: Status-Edge Consistency", () => {
|
|||||||
|
|
||||||
test("3.2 single-exit role missing _ key", () => {
|
test("3.2 single-exit role missing _ key", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.writer = { done: { role: "reviewer", prompt: "Review", location: null } };
|
wf.graph.writer = { done: { role: "reviewer", prompt: "Review" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
errors.some((e) => e.includes('role "writer" is single-exit but graph has no "_" key')),
|
errors.some((e) => e.includes('role "writer" is single-exit but graph has no "_" key')),
|
||||||
@@ -219,9 +219,9 @@ describe("Suite 3: Status-Edge Consistency", () => {
|
|||||||
test("3.3 multi-exit role with extra statuses", () => {
|
test("3.3 multi-exit role with extra statuses", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.reviewer = {
|
wf.graph.reviewer = {
|
||||||
approved: { role: "$END", prompt: "Done", location: null },
|
approved: { role: "$END", prompt: "Done" },
|
||||||
rejected: { role: "writer", prompt: "Fix", location: null },
|
rejected: { role: "writer", prompt: "Fix" },
|
||||||
timeout: { role: "$END", prompt: "Timed out", location: null },
|
timeout: { role: "$END", prompt: "Timed out" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
@@ -232,7 +232,7 @@ describe("Suite 3: Status-Edge Consistency", () => {
|
|||||||
test("3.4 multi-exit role missing a status", () => {
|
test("3.4 multi-exit role missing a status", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.reviewer = {
|
wf.graph.reviewer = {
|
||||||
approved: { role: "$END", prompt: "Done", location: null },
|
approved: { role: "$END", prompt: "Done" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
@@ -242,7 +242,7 @@ describe("Suite 3: Status-Edge Consistency", () => {
|
|||||||
|
|
||||||
test("3.5 multi-exit role with _ key", () => {
|
test("3.5 multi-exit role with _ key", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.reviewer = { _: { role: "$END", prompt: "Done", location: null } };
|
wf.graph.reviewer = { _: { role: "$END", prompt: "Done" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes('role "reviewer" is multi-exit but graph uses "_"'))).toBe(
|
expect(errors.some((e) => e.includes('role "reviewer" is multi-exit but graph uses "_"'))).toBe(
|
||||||
true,
|
true,
|
||||||
@@ -265,8 +265,8 @@ describe("Suite 3b: Enum-Based Multi-Exit", () => {
|
|||||||
} as unknown as string,
|
} as unknown as string,
|
||||||
};
|
};
|
||||||
wf.graph.reviewer = {
|
wf.graph.reviewer = {
|
||||||
approved: { role: "$END", prompt: "Done", location: null },
|
approved: { role: "$END", prompt: "Done" },
|
||||||
rejected: { role: "writer", prompt: "Fix: {{{comments}}}", location: null },
|
rejected: { role: "writer", prompt: "Fix: {{{comments}}}" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors).toEqual([]);
|
expect(errors).toEqual([]);
|
||||||
@@ -286,9 +286,9 @@ describe("Suite 3b: Enum-Based Multi-Exit", () => {
|
|||||||
} as unknown as string,
|
} as unknown as string,
|
||||||
};
|
};
|
||||||
wf.graph.reviewer = {
|
wf.graph.reviewer = {
|
||||||
approved: { role: "$END", prompt: "Done", location: null },
|
approved: { role: "$END", prompt: "Done" },
|
||||||
rejected: { role: "writer", prompt: "Fix", location: null },
|
rejected: { role: "writer", prompt: "Fix" },
|
||||||
timeout: { role: "$END", prompt: "Timed out", location: null },
|
timeout: { role: "$END", prompt: "Timed out" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes("extra status keys: timeout"))).toBe(true);
|
expect(errors.some((e) => e.includes("extra status keys: timeout"))).toBe(true);
|
||||||
@@ -308,7 +308,7 @@ describe("Suite 3b: Enum-Based Multi-Exit", () => {
|
|||||||
} as unknown as string,
|
} as unknown as string,
|
||||||
};
|
};
|
||||||
wf.graph.reviewer = {
|
wf.graph.reviewer = {
|
||||||
approved: { role: "$END", prompt: "Done", location: null },
|
approved: { role: "$END", prompt: "Done" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes("missing status keys: rejected"))).toBe(true);
|
expect(errors.some((e) => e.includes("missing status keys: rejected"))).toBe(true);
|
||||||
@@ -327,7 +327,7 @@ describe("Suite 3b: Enum-Based Multi-Exit", () => {
|
|||||||
required: ["$status", "plan"],
|
required: ["$status", "plan"],
|
||||||
} as unknown as string,
|
} as unknown as string,
|
||||||
};
|
};
|
||||||
wf.graph.writer = { _: { role: "reviewer", prompt: "Review: {{{plan}}}", location: null } };
|
wf.graph.writer = { _: { role: "reviewer", prompt: "Review: {{{plan}}}" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors).toEqual([]);
|
expect(errors).toEqual([]);
|
||||||
});
|
});
|
||||||
@@ -346,8 +346,8 @@ describe("Suite 3b: Enum-Based Multi-Exit", () => {
|
|||||||
} as unknown as string,
|
} as unknown as string,
|
||||||
};
|
};
|
||||||
wf.graph.reviewer = {
|
wf.graph.reviewer = {
|
||||||
approved: { role: "$END", prompt: "Done: {{{nonexistent}}}", location: null },
|
approved: { role: "$END", prompt: "Done: {{{nonexistent}}}" },
|
||||||
rejected: { role: "writer", prompt: "Fix: {{{comments}}}", location: null },
|
rejected: { role: "writer", prompt: "Fix: {{{comments}}}" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.some((e) => e.includes("nonexistent") && e.includes("not found"))).toBe(true);
|
expect(errors.some((e) => e.includes("nonexistent") && e.includes("not found"))).toBe(true);
|
||||||
@@ -357,7 +357,7 @@ describe("Suite 3b: Enum-Based Multi-Exit", () => {
|
|||||||
describe("Suite 4: Mustache Template Variable Existence", () => {
|
describe("Suite 4: Mustache Template Variable Existence", () => {
|
||||||
test("4.1 prompt references nonexistent variable (single-exit)", () => {
|
test("4.1 prompt references nonexistent variable (single-exit)", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.writer = { _: { role: "reviewer", prompt: "Review: {{{branch}}}", location: null } };
|
wf.graph.writer = { _: { role: "reviewer", prompt: "Review: {{{branch}}}" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
errors.some((e) =>
|
errors.some((e) =>
|
||||||
@@ -369,8 +369,8 @@ describe("Suite 4: Mustache Template Variable Existence", () => {
|
|||||||
test("4.2 prompt references nonexistent variable (multi-exit)", () => {
|
test("4.2 prompt references nonexistent variable (multi-exit)", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.reviewer = {
|
wf.graph.reviewer = {
|
||||||
approved: { role: "$END", prompt: "Done: {{{branch}}}", location: null },
|
approved: { role: "$END", prompt: "Done: {{{branch}}}" },
|
||||||
rejected: { role: "writer", prompt: "Fix: {{{reason}}}", location: null },
|
rejected: { role: "writer", prompt: "Fix: {{{reason}}}" },
|
||||||
};
|
};
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(
|
expect(
|
||||||
@@ -388,7 +388,7 @@ describe("Suite 4: Mustache Template Variable Existence", () => {
|
|||||||
|
|
||||||
test("4.4 $status variable is always valid", () => {
|
test("4.4 $status variable is always valid", () => {
|
||||||
const wf = makeWorkflow();
|
const wf = makeWorkflow();
|
||||||
wf.graph.writer = { _: { role: "reviewer", prompt: "Status: {{$status}}", location: null } };
|
wf.graph.writer = { _: { role: "reviewer", prompt: "Status: {{$status}}" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors).toEqual([]);
|
expect(errors).toEqual([]);
|
||||||
});
|
});
|
||||||
@@ -461,9 +461,9 @@ describe("Suite 6: Multiple Errors Collection", () => {
|
|||||||
} as unknown as string,
|
} as unknown as string,
|
||||||
};
|
};
|
||||||
// unknown graph reference
|
// unknown graph reference
|
||||||
wf.graph.nonexistent = { _: { role: "$END", prompt: "done", location: null } };
|
wf.graph.nonexistent = { _: { role: "$END", prompt: "done" } };
|
||||||
// bad mustache var
|
// bad mustache var
|
||||||
wf.graph.writer = { _: { role: "reviewer", prompt: "{{{badvar}}}", location: null } };
|
wf.graph.writer = { _: { role: "reviewer", prompt: "{{{badvar}}}" } };
|
||||||
const errors = validateWorkflow(wf);
|
const errors = validateWorkflow(wf);
|
||||||
expect(errors.length).toBeGreaterThanOrEqual(3);
|
expect(errors.length).toBeGreaterThanOrEqual(3);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
||||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
import type { CasRef, WorkflowPayload } from "@uncaged/workflow-protocol";
|
import type { CasRef, WorkflowPayload } from "@uncaged/workflow-protocol";
|
||||||
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { stringify } from "yaml";
|
import { stringify } from "yaml";
|
||||||
import { cmdThreadStart } from "../commands/thread.js";
|
import { cmdThreadStart } from "../commands/thread.js";
|
||||||
import { registerUwfSchemas } from "../schemas.js";
|
import { registerUwfSchemas } from "../schemas.js";
|
||||||
@@ -15,8 +15,6 @@ import { loadWorkflowRegistry, saveWorkflowRegistry } from "../store.js";
|
|||||||
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
async function makeUwfStore(storageRoot: string): Promise<UwfStore> {
|
||||||
const casDir = join(storageRoot, "cas");
|
const casDir = join(storageRoot, "cas");
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
// Set UNCAGED_CAS_DIR to use the test's CAS directory
|
|
||||||
process.env.UNCAGED_CAS_DIR = casDir;
|
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
return { storageRoot, store, schemas };
|
return { storageRoot, store, schemas };
|
||||||
@@ -43,8 +41,8 @@ function makeMinimalPayload(name: string, description: string): WorkflowPayload
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
graph: {
|
graph: {
|
||||||
$START: { _: { role: "worker", prompt: "start working", location: null } },
|
$START: { _: { role: "worker", prompt: "start working" } },
|
||||||
worker: { _: { role: "$END", prompt: "done", location: null } },
|
worker: { _: { role: "$END", prompt: "done" } },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -257,49 +255,6 @@ describe("Strategy 3: Local Discovery", () => {
|
|||||||
|
|
||||||
expect(result.workflow).toMatch(/^[0-9A-HJKMNP-TV-Z]{13}$/);
|
expect(result.workflow).toMatch(/^[0-9A-HJKMNP-TV-Z]{13}$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should find workflow in folder-based layout (name/index.yaml)", async () => {
|
|
||||||
await makeUwfStore(storageRoot);
|
|
||||||
const workflowDir = join(projectRoot, ".workflow", "solve-issue");
|
|
||||||
await mkdir(workflowDir, { recursive: true });
|
|
||||||
await writeFile(join(workflowDir, "index.yaml"), await createWorkflowYaml("solve-issue"));
|
|
||||||
|
|
||||||
const result = await cmdThreadStart(storageRoot, "solve-issue", "prompt", projectRoot);
|
|
||||||
|
|
||||||
expect(result.workflow).toMatch(/^[0-9A-HJKMNP-TV-Z]{13}$/);
|
|
||||||
const uwf = await makeUwfStore(storageRoot);
|
|
||||||
const node = uwf.store.get(result.workflow);
|
|
||||||
expect(node).not.toBeNull();
|
|
||||||
if (node !== null) {
|
|
||||||
expect((node.payload as WorkflowPayload).name).toBe("solve-issue");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should prefer flat file over folder-based layout", async () => {
|
|
||||||
await makeUwfStore(storageRoot);
|
|
||||||
const workflowDir = join(projectRoot, ".workflow");
|
|
||||||
await mkdir(workflowDir, { recursive: true });
|
|
||||||
await writeFile(
|
|
||||||
join(workflowDir, "solve-issue.yaml"),
|
|
||||||
await createWorkflowYaml("solve-issue", "flat"),
|
|
||||||
);
|
|
||||||
|
|
||||||
const folderDir = join(workflowDir, "solve-issue");
|
|
||||||
await mkdir(folderDir, { recursive: true });
|
|
||||||
await writeFile(
|
|
||||||
join(folderDir, "index.yaml"),
|
|
||||||
await createWorkflowYaml("solve-issue", "folder"),
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await cmdThreadStart(storageRoot, "solve-issue", "prompt", projectRoot);
|
|
||||||
|
|
||||||
const uwf = await makeUwfStore(storageRoot);
|
|
||||||
const node = uwf.store.get(result.workflow);
|
|
||||||
expect(node).not.toBeNull();
|
|
||||||
if (node !== null) {
|
|
||||||
expect((node.payload as WorkflowPayload).description).toBe("Test workflow (flat)");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Strategy 4: Global Registry Fallback ──────────────────────────────────────
|
// ── Strategy 4: Global Registry Fallback ──────────────────────────────────────
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import type { CasRef, ThreadId, ThreadStatus } from "@uncaged/workflow-protocol";
|
import type { CasRef, ThreadId } from "@uncaged/workflow-protocol";
|
||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import {
|
import {
|
||||||
cmdCasGet,
|
cmdCasGet,
|
||||||
@@ -15,28 +15,30 @@ import {
|
|||||||
} from "./commands/cas.js";
|
} from "./commands/cas.js";
|
||||||
import { cmdConfigGet, cmdConfigList, cmdConfigSet } from "./commands/config.js";
|
import { cmdConfigGet, cmdConfigList, cmdConfigSet } from "./commands/config.js";
|
||||||
import { cmdLogClean, cmdLogList, cmdLogShow } from "./commands/log.js";
|
import { cmdLogClean, cmdLogList, cmdLogShow } from "./commands/log.js";
|
||||||
import {
|
|
||||||
cmdPromptAdapter,
|
|
||||||
cmdPromptAuthor,
|
|
||||||
cmdPromptBootstrap,
|
|
||||||
cmdPromptDeveloper,
|
|
||||||
cmdPromptList,
|
|
||||||
cmdPromptSetup,
|
|
||||||
cmdPromptUsage,
|
|
||||||
cmdPromptUser,
|
|
||||||
} from "./commands/prompt.js";
|
|
||||||
import { cmdSetup, cmdSetupInteractive } from "./commands/setup.js";
|
import { cmdSetup, cmdSetupInteractive } from "./commands/setup.js";
|
||||||
|
import {
|
||||||
|
cmdSkillActor,
|
||||||
|
cmdSkillAdapter,
|
||||||
|
cmdSkillArchitecture,
|
||||||
|
cmdSkillAuthor,
|
||||||
|
cmdSkillCli,
|
||||||
|
cmdSkillDeveloper,
|
||||||
|
cmdSkillList,
|
||||||
|
cmdSkillModerator,
|
||||||
|
cmdSkillUser,
|
||||||
|
cmdSkillYaml,
|
||||||
|
} from "./commands/skill.js";
|
||||||
import { cmdStepFork, cmdStepList, cmdStepRead, cmdStepShow } from "./commands/step.js";
|
import { cmdStepFork, cmdStepList, cmdStepRead, cmdStepShow } from "./commands/step.js";
|
||||||
import {
|
import {
|
||||||
cmdThreadCancel,
|
cmdThreadCancel,
|
||||||
cmdThreadExec,
|
cmdThreadExec,
|
||||||
cmdThreadList,
|
cmdThreadList,
|
||||||
cmdThreadRead,
|
cmdThreadRead,
|
||||||
cmdThreadResume,
|
|
||||||
cmdThreadShow,
|
cmdThreadShow,
|
||||||
cmdThreadStart,
|
cmdThreadStart,
|
||||||
cmdThreadStop,
|
cmdThreadStop,
|
||||||
THREAD_READ_DEFAULT_QUOTA,
|
THREAD_READ_DEFAULT_QUOTA,
|
||||||
|
type ThreadStatus,
|
||||||
} from "./commands/thread.js";
|
} from "./commands/thread.js";
|
||||||
import { parseTimeInput } from "./commands/thread-time-parser.js";
|
import { parseTimeInput } from "./commands/thread-time-parser.js";
|
||||||
import { cmdWorkflowAdd, cmdWorkflowList, cmdWorkflowShow } from "./commands/workflow.js";
|
import { cmdWorkflowAdd, cmdWorkflowList, cmdWorkflowShow } from "./commands/workflow.js";
|
||||||
@@ -116,17 +118,10 @@ thread
|
|||||||
.description("Create a thread without executing")
|
.description("Create a thread without executing")
|
||||||
.argument("<workflow>", "Workflow name or hash")
|
.argument("<workflow>", "Workflow name or hash")
|
||||||
.requiredOption("-p, --prompt <text>", "User prompt")
|
.requiredOption("-p, --prompt <text>", "User prompt")
|
||||||
.option("--cwd <path>", "Working directory for thread execution (default: process.cwd())")
|
.action((workflow: string, opts: { prompt: string }) => {
|
||||||
.action((workflow: string, opts: { prompt: string; cwd: string | undefined }) => {
|
|
||||||
const storageRoot = resolveStorageRoot();
|
const storageRoot = resolveStorageRoot();
|
||||||
runAction(async () => {
|
runAction(async () => {
|
||||||
const result = await cmdThreadStart(
|
const result = await cmdThreadStart(storageRoot, workflow, opts.prompt, process.cwd());
|
||||||
storageRoot,
|
|
||||||
workflow,
|
|
||||||
opts.prompt,
|
|
||||||
process.cwd(),
|
|
||||||
opts.cwd ?? process.cwd(),
|
|
||||||
);
|
|
||||||
writeOutput(result);
|
writeOutput(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -192,11 +187,11 @@ function parseStatusFilter(status: string | undefined): ThreadStatus[] | null {
|
|||||||
if (raw === "active") return ["idle", "running"];
|
if (raw === "active") return ["idle", "running"];
|
||||||
|
|
||||||
const parts = raw.split(",").map((s) => s.trim());
|
const parts = raw.split(",").map((s) => s.trim());
|
||||||
const validStatuses: ThreadStatus[] = ["idle", "running", "suspended", "completed", "cancelled"];
|
const validStatuses: ThreadStatus[] = ["idle", "running", "completed", "cancelled"];
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
if (!validStatuses.includes(part as ThreadStatus)) {
|
if (!validStatuses.includes(part as ThreadStatus)) {
|
||||||
process.stderr.write(
|
process.stderr.write(
|
||||||
`Invalid status: ${part}. Must be one of: idle, running, suspended, completed, cancelled, active\n`,
|
`Invalid status: ${part}. Must be one of: idle, running, completed, cancelled, active\n`,
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -283,27 +278,6 @@ thread
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
thread
|
|
||||||
.command("resume")
|
|
||||||
.description("Resume a suspended thread and re-run the suspended role")
|
|
||||||
.argument("<thread-id>", "Thread ULID")
|
|
||||||
.option("-p, --prompt <text>", "Supplementary info to append to the resume prompt")
|
|
||||||
.option("--agent <cmd>", "Override agent command")
|
|
||||||
.action((threadId: string, opts: { prompt: string | undefined; agent: string | undefined }) => {
|
|
||||||
const storageRoot = resolveStorageRoot();
|
|
||||||
runAction(async () => {
|
|
||||||
const supplement = opts.prompt ?? null;
|
|
||||||
const agentOverride = opts.agent ?? null;
|
|
||||||
const result = await cmdThreadResume(
|
|
||||||
storageRoot,
|
|
||||||
threadId as ThreadId,
|
|
||||||
supplement,
|
|
||||||
agentOverride,
|
|
||||||
);
|
|
||||||
writeOutput(result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
thread
|
thread
|
||||||
.command("stop")
|
.command("stop")
|
||||||
.description("Stop background execution of a thread (keep thread active)")
|
.description("Stop background execution of a thread (keep thread active)")
|
||||||
@@ -388,8 +362,7 @@ step
|
|||||||
.description("Read a step's turns as human-readable markdown")
|
.description("Read a step's turns as human-readable markdown")
|
||||||
.argument("<step-hash>", "CAS hash of the StepNode")
|
.argument("<step-hash>", "CAS hash of the StepNode")
|
||||||
.option("--quota <chars>", "Max output characters", "4000")
|
.option("--quota <chars>", "Max output characters", "4000")
|
||||||
.option("--prompt", "Show the assembled prompt sent to the agent instead of turns")
|
.action((stepHash: string, opts: { quota: string }) => {
|
||||||
.action((stepHash: string, opts: { quota: string; prompt: boolean }) => {
|
|
||||||
const storageRoot = resolveStorageRoot();
|
const storageRoot = resolveStorageRoot();
|
||||||
runAction(async () => {
|
runAction(async () => {
|
||||||
const quota = Number.parseInt(opts.quota, 10);
|
const quota = Number.parseInt(opts.quota, 10);
|
||||||
@@ -397,12 +370,7 @@ step
|
|||||||
process.stderr.write("invalid --quota: must be a positive integer\n");
|
process.stderr.write("invalid --quota: must be a positive integer\n");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const markdown = await cmdStepRead(
|
const markdown = await cmdStepRead(storageRoot, stepHash as CasRef, quota);
|
||||||
storageRoot,
|
|
||||||
stepHash as CasRef,
|
|
||||||
quota,
|
|
||||||
opts.prompt === true,
|
|
||||||
);
|
|
||||||
process.stdout.write(markdown.endsWith("\n") ? markdown : `${markdown}\n`);
|
process.stdout.write(markdown.endsWith("\n") ? markdown : `${markdown}\n`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -516,63 +484,77 @@ For more information, see: uwf help thread list
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = program.command("prompt").description("Built-in prompt references for agents");
|
const skill = program.command("skill").description("Built-in skill references for agents");
|
||||||
prompt.addHelpCommand(false);
|
skill.addHelpCommand(false);
|
||||||
|
|
||||||
prompt
|
skill
|
||||||
.command("usage")
|
.command("cli")
|
||||||
.description("Print the complete skill content (all references combined)")
|
.description("Print a markdown reference of all uwf commands")
|
||||||
.action(() => {
|
.action(() => {
|
||||||
console.log(cmdPromptUsage());
|
console.log(cmdSkillCli());
|
||||||
});
|
});
|
||||||
|
|
||||||
prompt
|
skill
|
||||||
.command("setup")
|
.command("architecture")
|
||||||
.description("Print setup instructions for installing the uwf skill")
|
.description("Print the architecture reference")
|
||||||
.action(() => {
|
.action(() => {
|
||||||
console.log(cmdPromptSetup());
|
console.log(cmdSkillArchitecture());
|
||||||
});
|
});
|
||||||
|
|
||||||
prompt
|
skill
|
||||||
|
.command("yaml")
|
||||||
|
.description("Print the workflow YAML schema reference")
|
||||||
|
.action(() => {
|
||||||
|
console.log(cmdSkillYaml());
|
||||||
|
});
|
||||||
|
|
||||||
|
skill
|
||||||
|
.command("actor")
|
||||||
|
.description("Print the actor reference (frontmatter protocol + CAS)")
|
||||||
|
.action(() => {
|
||||||
|
console.log(cmdSkillActor());
|
||||||
|
});
|
||||||
|
|
||||||
|
skill
|
||||||
.command("adapter")
|
.command("adapter")
|
||||||
.description("Print the adapter reference (building agent adapters)")
|
.description("Print the adapter reference (building agent adapters)")
|
||||||
.action(() => {
|
.action(() => {
|
||||||
console.log(cmdPromptAdapter());
|
console.log(cmdSkillAdapter());
|
||||||
});
|
});
|
||||||
|
|
||||||
prompt
|
skill
|
||||||
.command("author")
|
.command("author")
|
||||||
.description("Print the author reference (workflow YAML design guide)")
|
.description("Print the author reference (workflow YAML design guide)")
|
||||||
.action(() => {
|
.action(() => {
|
||||||
console.log(cmdPromptAuthor());
|
console.log(cmdSkillAuthor());
|
||||||
});
|
});
|
||||||
|
|
||||||
prompt
|
skill
|
||||||
.command("developer")
|
.command("developer")
|
||||||
.description("Print the developer reference (coding conventions + architecture)")
|
.description("Print the developer reference (coding conventions + architecture)")
|
||||||
.action(() => {
|
.action(() => {
|
||||||
console.log(cmdPromptDeveloper());
|
console.log(cmdSkillDeveloper());
|
||||||
});
|
});
|
||||||
|
|
||||||
prompt
|
skill
|
||||||
|
.command("moderator")
|
||||||
|
.description("Print the moderator reference")
|
||||||
|
.action(() => {
|
||||||
|
console.log(cmdSkillModerator());
|
||||||
|
});
|
||||||
|
|
||||||
|
skill
|
||||||
.command("user")
|
.command("user")
|
||||||
.description("Print the user reference (CLI guide + typical workflows)")
|
.description("Print the user reference (CLI guide + typical workflows)")
|
||||||
.action(() => {
|
.action(() => {
|
||||||
console.log(cmdPromptUser());
|
console.log(cmdSkillUser());
|
||||||
});
|
});
|
||||||
|
|
||||||
prompt
|
skill
|
||||||
.command("bootstrap")
|
|
||||||
.description("Print the bootstrap skill YAML for Hermes agents")
|
|
||||||
.action(() => {
|
|
||||||
console.log(cmdPromptBootstrap());
|
|
||||||
});
|
|
||||||
|
|
||||||
prompt
|
|
||||||
.command("list")
|
.command("list")
|
||||||
.description("List all available prompt names")
|
.description("List all available skill names")
|
||||||
.action(() => {
|
.action(() => {
|
||||||
console.log(cmdPromptList().join("\n"));
|
console.log(cmdSkillList().join("\n"));
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
@@ -582,7 +564,7 @@ program
|
|||||||
.option("--base-url <url>", "OpenAI-compatible API base URL")
|
.option("--base-url <url>", "OpenAI-compatible API base URL")
|
||||||
.option("--api-key <key>", "API key")
|
.option("--api-key <key>", "API key")
|
||||||
.option("--model <name>", "Default model name")
|
.option("--model <name>", "Default model name")
|
||||||
.option("--agent <name>", "Default agent adapter (e.g. hermes → uwf-hermes)")
|
.option("--agent <name>", "Default agent alias")
|
||||||
.action(
|
.action(
|
||||||
(opts: {
|
(opts: {
|
||||||
provider?: string;
|
provider?: string;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
|
||||||
import type { JSONSchema, Store } from "@ocas/core";
|
import type { JSONSchema, Store } from "@uncaged/json-cas";
|
||||||
import { bootstrap, getSchema, putSchema, refs, walk } from "@ocas/core";
|
import { bootstrap, getSchema, putSchema, refs, walk } from "@uncaged/json-cas";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
|
|
||||||
import { TEXT_SCHEMA } from "../schemas.js";
|
import { TEXT_SCHEMA } from "../schemas.js";
|
||||||
|
|
||||||
@@ -85,17 +85,13 @@ export type SchemaListEntry = {
|
|||||||
|
|
||||||
export async function cmdCasSchemaList(storageRoot: string): Promise<SchemaListEntry[]> {
|
export async function cmdCasSchemaList(storageRoot: string): Promise<SchemaListEntry[]> {
|
||||||
const store = openStore(storageRoot);
|
const store = openStore(storageRoot);
|
||||||
const aliases = await bootstrap(store);
|
const metaHash = await bootstrap(store);
|
||||||
const metaHash = aliases["@ocas/schema"];
|
|
||||||
if (metaHash === undefined) {
|
|
||||||
throw new Error("Meta-schema not found in bootstrap result");
|
|
||||||
}
|
|
||||||
const entries: SchemaListEntry[] = [];
|
const entries: SchemaListEntry[] = [];
|
||||||
|
|
||||||
// Include meta-schema itself
|
// Include meta-schema itself
|
||||||
entries.push({ hash: metaHash, title: "(meta-schema)" });
|
entries.push({ hash: metaHash, title: "(meta-schema)" });
|
||||||
|
|
||||||
for (const { hash } of store.listByType(metaHash)) {
|
for (const hash of store.listByType(metaHash)) {
|
||||||
if (hash === metaHash) continue;
|
if (hash === metaHash) continue;
|
||||||
const node = store.get(hash);
|
const node = store.get(hash);
|
||||||
if (node !== null) {
|
if (node !== null) {
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import { parse, stringify } from "yaml";
|
|||||||
/**
|
/**
|
||||||
* Valid configuration key schema
|
* Valid configuration key schema
|
||||||
*/
|
*/
|
||||||
const VALID_CONFIG_KEYS: Record<
|
const VALID_CONFIG_KEYS: Record<string, { nested: boolean; knownFields?: string[] }> = {
|
||||||
string,
|
|
||||||
{ nested: boolean; knownFields?: string[]; minDepth?: number }
|
|
||||||
> = {
|
|
||||||
providers: {
|
providers: {
|
||||||
nested: true,
|
nested: true,
|
||||||
knownFields: ["baseUrl", "apiKey"],
|
knownFields: ["baseUrl", "apiKey"],
|
||||||
@@ -21,17 +18,6 @@ const VALID_CONFIG_KEYS: Record<
|
|||||||
nested: true,
|
nested: true,
|
||||||
knownFields: ["command", "args"],
|
knownFields: ["command", "args"],
|
||||||
},
|
},
|
||||||
agentOverrides: {
|
|
||||||
nested: true,
|
|
||||||
// agentOverrides.<workflowName>.<roleName> = agentAlias (string value)
|
|
||||||
// No knownFields — workflow/role names are user-defined
|
|
||||||
},
|
|
||||||
modelOverrides: {
|
|
||||||
nested: true,
|
|
||||||
minDepth: 2,
|
|
||||||
// modelOverrides.<scenario> = modelAlias (string value)
|
|
||||||
// No knownFields — scenarios are user-defined
|
|
||||||
},
|
|
||||||
defaultAgent: { nested: false },
|
defaultAgent: { nested: false },
|
||||||
defaultModel: { nested: false },
|
defaultModel: { nested: false },
|
||||||
};
|
};
|
||||||
@@ -57,9 +43,8 @@ function validateConfigKey(path: string[]): void {
|
|||||||
throw new Error(`${topLevel} is a scalar key and cannot have nested properties`);
|
throw new Error(`${topLevel} is a scalar key and cannot have nested properties`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nested keys must have at least minDepth segments (default 3)
|
// Nested keys must have at least 3 segments (e.g., providers.myProvider.baseUrl)
|
||||||
const minDepth = schema.minDepth ?? 3;
|
if (schema.nested && path.length < 3) {
|
||||||
if (schema.nested && path.length < minDepth) {
|
|
||||||
const fields = schema.knownFields?.join(", ") ?? "";
|
const fields = schema.knownFields?.join(", ") ?? "";
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Incomplete path for ${topLevel}. Must specify a field (e.g., ${topLevel}.<name>.<field>). Valid fields: ${fields}`,
|
`Incomplete path for ${topLevel}. Must specify a field (e.g., ${topLevel}.<name>.<field>). Valid fields: ${fields}`,
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
import {
|
|
||||||
generateAdapterReference,
|
|
||||||
generateAuthorReference,
|
|
||||||
generateBootstrapReference,
|
|
||||||
generateDeveloperReference,
|
|
||||||
generateUserReference,
|
|
||||||
} from "@uncaged/workflow-util";
|
|
||||||
|
|
||||||
export {
|
|
||||||
generateAdapterReference as cmdPromptAdapter,
|
|
||||||
generateAuthorReference as cmdPromptAuthor,
|
|
||||||
generateBootstrapReference as cmdPromptBootstrap,
|
|
||||||
generateDeveloperReference as cmdPromptDeveloper,
|
|
||||||
generateUserReference as cmdPromptUser,
|
|
||||||
};
|
|
||||||
|
|
||||||
const PROMPT_ENTRIES: ReadonlyArray<{ name: string; generate: () => string }> = [
|
|
||||||
{ name: "user", generate: generateUserReference },
|
|
||||||
{ name: "author", generate: generateAuthorReference },
|
|
||||||
{ name: "developer", generate: generateDeveloperReference },
|
|
||||||
{ name: "adapter", generate: generateAdapterReference },
|
|
||||||
{ name: "bootstrap", generate: generateBootstrapReference },
|
|
||||||
];
|
|
||||||
|
|
||||||
export function cmdPromptList(): ReadonlyArray<string> {
|
|
||||||
return PROMPT_ENTRIES.map((e) => e.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function cmdPromptUsage(): string {
|
|
||||||
return PROMPT_ENTRIES.map((e) => e.generate()).join("\n\n---\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function cmdPromptSetup(): string {
|
|
||||||
return `# uwf Skill Setup
|
|
||||||
|
|
||||||
You are being asked to install or update the uwf (United Workforce) skill
|
|
||||||
so that you know how to use the \`uwf\` CLI for workflow orchestration.
|
|
||||||
|
|
||||||
## Steps
|
|
||||||
|
|
||||||
1. **Check if uwf CLI is installed:**
|
|
||||||
\`\`\`bash
|
|
||||||
uwf --help
|
|
||||||
\`\`\`
|
|
||||||
If not installed: \`bun add -g @uncaged/cli-workflow\`
|
|
||||||
|
|
||||||
2. **Clean up old versions of the skill** (if any exist):
|
|
||||||
- Look for any existing uwf/workflow skill files in your skill directories
|
|
||||||
(e.g. \`~/.hermes/skills/uwf/SKILL.md\` or similar paths).
|
|
||||||
- If a skill exists, read its \`version\` from the YAML frontmatter.
|
|
||||||
- If the version matches the current CLI version (\`uwf --version\`), you're done — no update needed.
|
|
||||||
- If the version is older, **delete the old skill file** before proceeding.
|
|
||||||
|
|
||||||
3. **Get the usage skill content:**
|
|
||||||
\`\`\`bash
|
|
||||||
uwf prompt usage
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
4. **Create a SKILL.md file** in your skill directory (e.g. \`~/.hermes/skills/uwf/SKILL.md\`).
|
|
||||||
The output of \`uwf prompt usage\` is the skill body WITHOUT frontmatter.
|
|
||||||
You must prepend the following YAML frontmatter:
|
|
||||||
|
|
||||||
\`\`\`yaml
|
|
||||||
---
|
|
||||||
name: uwf
|
|
||||||
description: "Use when orchestrating multi-agent workflows with uwf (United Workforce). Covers CLI usage, workflow YAML authoring, moderator logic, and agent development."
|
|
||||||
version: <VERSION>
|
|
||||||
author: United Workforce
|
|
||||||
license: MIT
|
|
||||||
metadata:
|
|
||||||
hermes:
|
|
||||||
tags: [workflow, agents, orchestration, cli, yaml]
|
|
||||||
---
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
Replace \`<VERSION>\` with the installed CLI version (from \`uwf --version\`).
|
|
||||||
|
|
||||||
5. **Verify** the skill is loadable by your agent framework.
|
|
||||||
|
|
||||||
## Individual prompts
|
|
||||||
|
|
||||||
You can also get individual reference sections:
|
|
||||||
|
|
||||||
\`\`\`bash
|
|
||||||
uwf prompt list # list available prompt names
|
|
||||||
uwf prompt user # user reference (CLI guide + typical workflows)
|
|
||||||
uwf prompt author # author reference (workflow YAML design guide)
|
|
||||||
uwf prompt developer # developer reference (coding conventions + architecture)
|
|
||||||
uwf prompt adapter # adapter reference (building agent adapters)
|
|
||||||
uwf prompt bootstrap # bootstrap skill YAML for Hermes agents
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
- The skill content is bundled with the CLI and versioned with it — always use
|
|
||||||
\`uwf prompt usage\` to get the content matching your installed version.
|
|
||||||
- Do NOT hand-edit the skill body. If the CLI is updated, re-run \`uwf prompt setup\`
|
|
||||||
and follow the steps again.
|
|
||||||
- When upgrading, always delete the old skill first to avoid stale instructions.
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Store as CasStore, JSONSchema } from "@ocas/core";
|
import type { Store as CasStore, JSONSchema } from "@uncaged/json-cas";
|
||||||
import { getSchema } from "@ocas/core";
|
import { getSchema } from "@uncaged/json-cas";
|
||||||
import type {
|
import type {
|
||||||
CasRef,
|
CasRef,
|
||||||
StartNodePayload,
|
StartNodePayload,
|
||||||
@@ -88,7 +88,7 @@ function expandOutput(uwf: UwfStore, outputRef: CasRef): unknown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively expand all ocas_ref fields in a CAS node's payload,
|
* Recursively expand all cas_ref fields in a CAS node's payload,
|
||||||
* replacing hash strings with the referenced node's expanded payload.
|
* replacing hash strings with the referenced node's expanded payload.
|
||||||
*/
|
*/
|
||||||
function expandDeep(store: CasStore, hash: CasRef, visited?: Set<string>): unknown {
|
function expandDeep(store: CasStore, hash: CasRef, visited?: Set<string>): unknown {
|
||||||
@@ -120,7 +120,7 @@ function expandAnyOfField(
|
|||||||
): unknown {
|
): unknown {
|
||||||
if (!Array.isArray(schema.anyOf)) return value;
|
if (!Array.isArray(schema.anyOf)) return value;
|
||||||
for (const sub of schema.anyOf as JSONSchema[]) {
|
for (const sub of schema.anyOf as JSONSchema[]) {
|
||||||
if (sub.format === "ocas_ref" && typeof value === "string") {
|
if (sub.format === "cas_ref" && typeof value === "string") {
|
||||||
return expandDeep(store, value as CasRef, visited);
|
return expandDeep(store, value as CasRef, visited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,7 @@ function expandValue(
|
|||||||
value: unknown,
|
value: unknown,
|
||||||
visited: Set<string>,
|
visited: Set<string>,
|
||||||
): unknown {
|
): unknown {
|
||||||
if (schema.format === "ocas_ref") return expandCasRefField(store, value, visited);
|
if (schema.format === "cas_ref") return expandCasRefField(store, value, visited);
|
||||||
if (Array.isArray(schema.anyOf)) return expandAnyOfField(store, schema, value, visited);
|
if (Array.isArray(schema.anyOf)) return expandAnyOfField(store, schema, value, visited);
|
||||||
if (schema.type === "array") return expandArrayField(store, schema, value, visited);
|
if (schema.type === "array") return expandArrayField(store, schema, value, visited);
|
||||||
return expandObjectField(store, schema, value, visited);
|
return expandObjectField(store, schema, value, visited);
|
||||||
@@ -203,7 +203,7 @@ function collectOrderedSteps(
|
|||||||
|
|
||||||
async function resolveHeadHash(storageRoot: string, threadId: ThreadId): Promise<CasRef> {
|
async function resolveHeadHash(storageRoot: string, threadId: ThreadId): Promise<CasRef> {
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
const activeHead = index[threadId]?.head;
|
const activeHead = index[threadId];
|
||||||
if (activeHead !== undefined) {
|
if (activeHead !== undefined) {
|
||||||
return activeHead;
|
return activeHead;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
export {
|
||||||
|
generateActorReference as cmdSkillActor,
|
||||||
|
generateAdapterReference as cmdSkillAdapter,
|
||||||
|
generateArchitectureReference as cmdSkillArchitecture,
|
||||||
|
generateAuthorReference as cmdSkillAuthor,
|
||||||
|
generateCliReference as cmdSkillCli,
|
||||||
|
generateDeveloperReference as cmdSkillDeveloper,
|
||||||
|
generateModeratorReference as cmdSkillModerator,
|
||||||
|
generateUserReference as cmdSkillUser,
|
||||||
|
generateYamlReference as cmdSkillYaml,
|
||||||
|
} from "@uncaged/workflow-util";
|
||||||
|
|
||||||
|
const SKILL_NAMES = [
|
||||||
|
"cli",
|
||||||
|
"architecture",
|
||||||
|
"yaml",
|
||||||
|
"moderator",
|
||||||
|
"actor",
|
||||||
|
"user",
|
||||||
|
"author",
|
||||||
|
"developer",
|
||||||
|
"adapter",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export function cmdSkillList(): ReadonlyArray<string> {
|
||||||
|
return [...SKILL_NAMES];
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { BootstrapCapableStore } from "@ocas/core";
|
import type { BootstrapCapableStore } from "@uncaged/json-cas";
|
||||||
import type {
|
import type {
|
||||||
CasRef,
|
CasRef,
|
||||||
StartEntry,
|
StartEntry,
|
||||||
@@ -113,7 +113,7 @@ export async function cmdStepFork(
|
|||||||
|
|
||||||
const newThreadId = generateUlid(Date.now()) as ThreadId;
|
const newThreadId = generateUlid(Date.now()) as ThreadId;
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
index[newThreadId] = { head: stepHash, suspendedRole: null, suspendMessage: null };
|
index[newThreadId] = stepHash;
|
||||||
await saveThreadsIndex(storageRoot, index);
|
await saveThreadsIndex(storageRoot, index);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -289,7 +289,6 @@ export async function cmdStepRead(
|
|||||||
storageRoot: string,
|
storageRoot: string,
|
||||||
stepHash: CasRef,
|
stepHash: CasRef,
|
||||||
quota: number,
|
quota: number,
|
||||||
showPrompt: boolean,
|
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const uwf = await createUwfStore(storageRoot);
|
const uwf = await createUwfStore(storageRoot);
|
||||||
const node = uwf.store.get(stepHash);
|
const node = uwf.store.get(stepHash);
|
||||||
@@ -301,23 +300,6 @@ export async function cmdStepRead(
|
|||||||
}
|
}
|
||||||
const payload = node.payload as StepNodePayload;
|
const payload = node.payload as StepNodePayload;
|
||||||
|
|
||||||
// --prompt mode: show the assembled prompt that was sent to the agent
|
|
||||||
if (showPrompt) {
|
|
||||||
const promptRef = (payload as Record<string, unknown>).assembledPrompt;
|
|
||||||
if (typeof promptRef !== "string") {
|
|
||||||
return `# Step ${stepHash}\n\n_Prompt not recorded (legacy step)._`;
|
|
||||||
}
|
|
||||||
const promptNode = uwf.store.get(promptRef as CasRef);
|
|
||||||
if (promptNode === null) {
|
|
||||||
return `# Step ${stepHash}\n\n_Prompt CAS node not found: ${promptRef}_`;
|
|
||||||
}
|
|
||||||
const promptText =
|
|
||||||
typeof promptNode.payload === "string"
|
|
||||||
? promptNode.payload
|
|
||||||
: JSON.stringify(promptNode.payload);
|
|
||||||
return `# Step ${stepHash}\n\n**Role:** ${payload.role}\n**Agent:** ${payload.agent}\n\n## Prompt\n\n${promptText}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.detail === null) {
|
if (payload.detail === null) {
|
||||||
return formatStepMarkdown(stepHash, payload.role, payload.agent, [], []);
|
return formatStepMarkdown(stepHash, payload.role, payload.agent, [], []);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { execFileSync, spawn } from "node:child_process";
|
import { execFileSync, spawn } from "node:child_process";
|
||||||
import { access, readFile } from "node:fs/promises";
|
import { access, readFile } from "node:fs/promises";
|
||||||
import { dirname, isAbsolute, resolve as resolvePath } from "node:path";
|
import { dirname, isAbsolute, resolve as resolvePath } from "node:path";
|
||||||
import { validate } from "@ocas/core";
|
import { validate } from "@uncaged/json-cas";
|
||||||
import type {
|
import type {
|
||||||
AgentAlias,
|
AgentAlias,
|
||||||
AgentConfig,
|
AgentConfig,
|
||||||
@@ -11,31 +11,22 @@ import type {
|
|||||||
StepNodePayload,
|
StepNodePayload,
|
||||||
StepOutput,
|
StepOutput,
|
||||||
ThreadId,
|
ThreadId,
|
||||||
ThreadIndexEntry,
|
|
||||||
ThreadListItem,
|
ThreadListItem,
|
||||||
ThreadStatus,
|
|
||||||
ThreadsIndex,
|
ThreadsIndex,
|
||||||
WorkflowConfig,
|
WorkflowConfig,
|
||||||
WorkflowPayload,
|
WorkflowPayload,
|
||||||
} from "@uncaged/workflow-protocol";
|
} from "@uncaged/workflow-protocol";
|
||||||
import {
|
|
||||||
createThreadIndexEntry,
|
|
||||||
markThreadSuspended,
|
|
||||||
updateThreadHead,
|
|
||||||
} from "@uncaged/workflow-protocol";
|
|
||||||
import {
|
import {
|
||||||
createProcessLogger,
|
createProcessLogger,
|
||||||
extractUlidTimestamp,
|
extractUlidTimestamp,
|
||||||
generateUlid,
|
generateUlid,
|
||||||
type ProcessLogger,
|
type ProcessLogger,
|
||||||
} from "@uncaged/workflow-util";
|
} from "@uncaged/workflow-util";
|
||||||
import type { AdapterOutput } from "@uncaged/workflow-util-agent";
|
|
||||||
import { getEnvPath, loadWorkflowConfig } from "@uncaged/workflow-util-agent";
|
import { getEnvPath, loadWorkflowConfig } from "@uncaged/workflow-util-agent";
|
||||||
import { config as loadDotenv } from "dotenv";
|
import { config as loadDotenv } from "dotenv";
|
||||||
import { parse } from "yaml";
|
import { parse } from "yaml";
|
||||||
import { createMarker, deleteMarker, isThreadRunning } from "../background/index.js";
|
import { createMarker, deleteMarker, isThreadRunning } from "../background/index.js";
|
||||||
import { createIncludeTag } from "../include.js";
|
import { evaluate } from "../moderator/index.js";
|
||||||
import { evaluate, isSuspendResult } from "../moderator/index.js";
|
|
||||||
import {
|
import {
|
||||||
appendThreadHistory,
|
appendThreadHistory,
|
||||||
createUwfStore,
|
createUwfStore,
|
||||||
@@ -64,135 +55,6 @@ const END_ROLE = "$END";
|
|||||||
const START_ROLE = "$START";
|
const START_ROLE = "$START";
|
||||||
export const THREAD_READ_DEFAULT_QUOTA = 4000;
|
export const THREAD_READ_DEFAULT_QUOTA = 4000;
|
||||||
|
|
||||||
function buildStepOutputFromEvaluation(
|
|
||||||
workflowHash: CasRef,
|
|
||||||
threadId: ThreadId,
|
|
||||||
head: CasRef,
|
|
||||||
status: ThreadStatus,
|
|
||||||
evaluation: ReturnType<typeof evaluate>,
|
|
||||||
background: boolean | null,
|
|
||||||
): StepOutput {
|
|
||||||
const done = status === "completed";
|
|
||||||
let currentRole: string | null = null;
|
|
||||||
let suspendedRole: string | null = null;
|
|
||||||
let suspendMessage: string | null = null;
|
|
||||||
if (evaluation.ok) {
|
|
||||||
if (isSuspendResult(evaluation.value)) {
|
|
||||||
suspendedRole = evaluation.value.suspendedRole;
|
|
||||||
suspendMessage = evaluation.value.prompt;
|
|
||||||
} else if (evaluation.value.role !== END_ROLE) {
|
|
||||||
currentRole = evaluation.value.role;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
workflow: workflowHash,
|
|
||||||
thread: threadId,
|
|
||||||
head,
|
|
||||||
status,
|
|
||||||
currentRole,
|
|
||||||
suspendedRole,
|
|
||||||
suspendMessage,
|
|
||||||
done,
|
|
||||||
background,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveSuspendFieldsFromGraph(
|
|
||||||
uwf: UwfStore,
|
|
||||||
head: CasRef,
|
|
||||||
workflowRef: CasRef,
|
|
||||||
): { suspendedRole: string | null; suspendMessage: string | null } {
|
|
||||||
const chain = walkChain(uwf, head);
|
|
||||||
const { lastRole, lastOutput } = resolveEvaluateArgs(uwf, chain);
|
|
||||||
const workflow = loadWorkflowPayload(uwf, workflowRef);
|
|
||||||
const result = evaluate(workflow.graph, lastRole, lastOutput);
|
|
||||||
if (result.ok && isSuspendResult(result.value)) {
|
|
||||||
return {
|
|
||||||
suspendedRole: result.value.suspendedRole,
|
|
||||||
suspendMessage: result.value.prompt,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { suspendedRole: null, suspendMessage: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveSuspendFieldsForShow(
|
|
||||||
entry: ThreadIndexEntry,
|
|
||||||
status: ThreadStatus,
|
|
||||||
uwf: UwfStore,
|
|
||||||
head: CasRef,
|
|
||||||
workflowRef: CasRef,
|
|
||||||
): { suspendedRole: string | null; suspendMessage: string | null } {
|
|
||||||
if (status !== "suspended") {
|
|
||||||
return { suspendedRole: null, suspendMessage: null };
|
|
||||||
}
|
|
||||||
if (entry.suspendedRole !== null && entry.suspendMessage !== null) {
|
|
||||||
return { suspendedRole: entry.suspendedRole, suspendMessage: entry.suspendMessage };
|
|
||||||
}
|
|
||||||
const fromGraph = resolveSuspendFieldsFromGraph(uwf, head, workflowRef);
|
|
||||||
return {
|
|
||||||
suspendedRole: entry.suspendedRole ?? fromGraph.suspendedRole,
|
|
||||||
suspendMessage: entry.suspendMessage ?? fromGraph.suspendMessage,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function ensureThreadSuspendMetadata(
|
|
||||||
storageRoot: string,
|
|
||||||
threadId: ThreadId,
|
|
||||||
entry: ThreadIndexEntry,
|
|
||||||
suspendedRole: string,
|
|
||||||
suspendMessage: string,
|
|
||||||
): Promise<ThreadIndexEntry> {
|
|
||||||
if (entry.suspendedRole !== null && entry.suspendMessage !== null) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
const updated = markThreadSuspended(entry, suspendedRole, suspendMessage);
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
index[threadId] = updated;
|
|
||||||
await saveThreadsIndex(storageRoot, index);
|
|
||||||
return updated;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveActiveThreadStatus(
|
|
||||||
storageRoot: string,
|
|
||||||
threadId: ThreadId,
|
|
||||||
uwf: UwfStore,
|
|
||||||
head: CasRef,
|
|
||||||
workflowRef: CasRef,
|
|
||||||
): Promise<ThreadStatus> {
|
|
||||||
const runningMarker = await isThreadRunning(storageRoot, threadId);
|
|
||||||
if (runningMarker !== null) {
|
|
||||||
return "running";
|
|
||||||
}
|
|
||||||
|
|
||||||
const chain = walkChain(uwf, head);
|
|
||||||
const { lastRole, lastOutput } = resolveEvaluateArgs(uwf, chain);
|
|
||||||
const workflow = loadWorkflowPayload(uwf, workflowRef);
|
|
||||||
const result = evaluate(workflow.graph, lastRole, lastOutput);
|
|
||||||
if (result.ok && isSuspendResult(result.value)) {
|
|
||||||
return "suspended";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "idle";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Derive the current/next role from the workflow graph and chain state.
|
|
||||||
* Returns null when the next role is $END, thread is suspended, or evaluation fails.
|
|
||||||
*/
|
|
||||||
function resolveCurrentRole(uwf: UwfStore, head: CasRef, workflowRef: CasRef): string | null {
|
|
||||||
const chain = walkChain(uwf, head);
|
|
||||||
const { lastRole, lastOutput } = resolveEvaluateArgs(uwf, chain);
|
|
||||||
const workflow = loadWorkflowPayload(uwf, workflowRef);
|
|
||||||
const result = evaluate(workflow.graph, lastRole, lastOutput);
|
|
||||||
if (!result.ok) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (isSuspendResult(result.value) || result.value.role === END_ROLE) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return result.value.role;
|
|
||||||
}
|
|
||||||
|
|
||||||
const PL_THREAD_START = "7HNQ4B2X";
|
const PL_THREAD_START = "7HNQ4B2X";
|
||||||
const PL_MODERATOR = "M3K8V9T1";
|
const PL_MODERATOR = "M3K8V9T1";
|
||||||
const PL_AGENT_SPAWN = "R5J2W8N4";
|
const PL_AGENT_SPAWN = "R5J2W8N4";
|
||||||
@@ -200,25 +62,6 @@ const PL_AGENT_DONE = "C6P9E3H7";
|
|||||||
const PL_THREAD_ARCHIVED = "F4D8Q2K5";
|
const PL_THREAD_ARCHIVED = "F4D8Q2K5";
|
||||||
const PL_STEP_ERROR = "B8T5N1V6";
|
const PL_STEP_ERROR = "B8T5N1V6";
|
||||||
const PL_BACKGROUND_START = "X7Q4W9M2";
|
const PL_BACKGROUND_START = "X7Q4W9M2";
|
||||||
const PL_THREAD_RESUME = "K2R7M4N8";
|
|
||||||
|
|
||||||
type ResumeStepConfig = {
|
|
||||||
role: string;
|
|
||||||
prompt: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type AgentStepTarget = {
|
|
||||||
role: string;
|
|
||||||
edgePrompt: string;
|
|
||||||
effectiveCwd: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
function buildResumePrompt(graphPrompt: string, supplement: string | null): string {
|
|
||||||
if (supplement === null || supplement === "") {
|
|
||||||
return graphPrompt;
|
|
||||||
}
|
|
||||||
return `${graphPrompt}\n\n${supplement}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function failStep(plog: ProcessLogger, message: string): never {
|
function failStep(plog: ProcessLogger, message: string): never {
|
||||||
plog.log(PL_STEP_ERROR, message, null);
|
plog.log(PL_STEP_ERROR, message, null);
|
||||||
@@ -258,15 +101,6 @@ async function findWorkflowInDir(dir: string, name: string): Promise<string | nu
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const indexName of ["index.yaml", "index.yml"]) {
|
|
||||||
const candidate = resolvePath(dir, ".workflow", name, indexName);
|
|
||||||
try {
|
|
||||||
await access(candidate);
|
|
||||||
return candidate;
|
|
||||||
} catch {
|
|
||||||
/* not found */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check .workflows/ directory as fallback (legacy)
|
// Check .workflows/ directory as fallback (legacy)
|
||||||
for (const ext of [".yaml", ".yml"]) {
|
for (const ext of [".yaml", ".yml"]) {
|
||||||
@@ -275,15 +109,6 @@ async function findWorkflowInDir(dir: string, name: string): Promise<string | nu
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const indexName of ["index.yaml", "index.yml"]) {
|
|
||||||
const candidate = resolvePath(dir, ".workflows", name, indexName);
|
|
||||||
try {
|
|
||||||
await access(candidate);
|
|
||||||
return candidate;
|
|
||||||
} catch {
|
|
||||||
/* not found */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -330,7 +155,7 @@ async function materializeLocalWorkflow(uwf: UwfStore, filePath: string): Promis
|
|||||||
|
|
||||||
let raw: unknown;
|
let raw: unknown;
|
||||||
try {
|
try {
|
||||||
raw = parse(text, { customTags: [createIncludeTag(dirname(filePath))] }) as unknown;
|
raw = parse(text) as unknown;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
fail(`invalid YAML in ${filePath}: ${e instanceof Error ? e.message : String(e)}`);
|
fail(`invalid YAML in ${filePath}: ${e instanceof Error ? e.message : String(e)}`);
|
||||||
}
|
}
|
||||||
@@ -441,13 +266,7 @@ export async function cmdThreadStart(
|
|||||||
workflowId: string,
|
workflowId: string,
|
||||||
prompt: string,
|
prompt: string,
|
||||||
projectRoot: string,
|
projectRoot: string,
|
||||||
cwd: string = process.cwd(),
|
|
||||||
): Promise<StartOutput> {
|
): Promise<StartOutput> {
|
||||||
// Validate cwd is an absolute path
|
|
||||||
if (!isAbsolute(cwd)) {
|
|
||||||
fail("cwd must be an absolute path");
|
|
||||||
}
|
|
||||||
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
const uwf = await createUwfStore(storageRoot);
|
||||||
const workflowHash = await resolveWorkflowCasRef(uwf, storageRoot, workflowId, projectRoot);
|
const workflowHash = await resolveWorkflowCasRef(uwf, storageRoot, workflowId, projectRoot);
|
||||||
|
|
||||||
@@ -459,7 +278,6 @@ export async function cmdThreadStart(
|
|||||||
const startPayload: StartNodePayload = {
|
const startPayload: StartNodePayload = {
|
||||||
workflow: workflowHash,
|
workflow: workflowHash,
|
||||||
prompt,
|
prompt,
|
||||||
cwd,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const headHash = await uwf.store.put(uwf.schemas.startNode, startPayload);
|
const headHash = await uwf.store.put(uwf.schemas.startNode, startPayload);
|
||||||
@@ -469,7 +287,7 @@ export async function cmdThreadStart(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
index[threadId] = createThreadIndexEntry(headHash);
|
index[threadId] = headHash;
|
||||||
await saveThreadsIndex(storageRoot, index);
|
await saveThreadsIndex(storageRoot, index);
|
||||||
|
|
||||||
plog.log(
|
plog.log(
|
||||||
@@ -481,80 +299,42 @@ export async function cmdThreadStart(
|
|||||||
return { workflow: workflowHash, thread: threadId };
|
return { workflow: workflowHash, thread: threadId };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cmdThreadShow(
|
export async function cmdThreadShow(storageRoot: string, threadId: ThreadId): Promise<StepOutput> {
|
||||||
storageRoot: string,
|
|
||||||
threadId: ThreadId,
|
|
||||||
): Promise<ThreadShowOutput> {
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
const entry = index[threadId];
|
const activeHead = index[threadId];
|
||||||
if (entry !== undefined) {
|
if (activeHead !== undefined) {
|
||||||
const activeHead = entry.head;
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
const uwf = await createUwfStore(storageRoot);
|
||||||
const workflow = resolveWorkflowFromHead(uwf, activeHead);
|
const workflow = resolveWorkflowFromHead(uwf, activeHead);
|
||||||
if (workflow === null) {
|
if (workflow === null) {
|
||||||
fail(`failed to resolve workflow from head: ${activeHead}`);
|
fail(`failed to resolve workflow from head: ${activeHead}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await resolveActiveThreadStatus(
|
|
||||||
storageRoot,
|
|
||||||
threadId,
|
|
||||||
uwf,
|
|
||||||
activeHead,
|
|
||||||
workflow,
|
|
||||||
);
|
|
||||||
const currentRole = resolveCurrentRole(uwf, activeHead, workflow);
|
|
||||||
const suspendFields = resolveSuspendFieldsForShow(entry, status, uwf, activeHead, workflow);
|
|
||||||
|
|
||||||
const hint =
|
|
||||||
status === "suspended"
|
|
||||||
? `Thread is suspended. Resume with: uwf thread resume ${threadId}`
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
workflow,
|
workflow,
|
||||||
thread: threadId,
|
thread: threadId,
|
||||||
head: activeHead,
|
head: activeHead,
|
||||||
status,
|
|
||||||
currentRole,
|
|
||||||
suspendedRole: suspendFields.suspendedRole,
|
|
||||||
suspendMessage: suspendFields.suspendMessage,
|
|
||||||
done: false,
|
done: false,
|
||||||
background: null,
|
background: null,
|
||||||
hint,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const hist = await findThreadInHistory(storageRoot, threadId);
|
const hist = await findThreadInHistory(storageRoot, threadId);
|
||||||
if (hist !== null) {
|
if (hist !== null) {
|
||||||
const status: ThreadStatus = hist.reason === "cancelled" ? "cancelled" : "completed";
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
workflow: hist.workflow,
|
workflow: hist.workflow,
|
||||||
thread: threadId,
|
thread: threadId,
|
||||||
head: hist.head,
|
head: hist.head,
|
||||||
status,
|
|
||||||
currentRole: null,
|
|
||||||
suspendedRole: null,
|
|
||||||
suspendMessage: null,
|
|
||||||
done: true,
|
done: true,
|
||||||
background: null,
|
background: null,
|
||||||
hint: null,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fail(`thread not found: ${threadId}`);
|
fail(`thread not found: ${threadId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ThreadStatus = "idle" | "running" | "completed" | "cancelled";
|
||||||
|
|
||||||
export type ThreadListItemWithStatus = ThreadListItem & {
|
export type ThreadListItemWithStatus = ThreadListItem & {
|
||||||
status: ThreadStatus;
|
status: ThreadStatus;
|
||||||
currentRole: string | null;
|
|
||||||
/** Display label with status marker for suspended threads */
|
|
||||||
statusDisplay: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ThreadShowOutput = StepOutput & {
|
|
||||||
/** Hint message for suspended threads */
|
|
||||||
hint: string | null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function threadListItemFromActive(
|
async function threadListItemFromActive(
|
||||||
@@ -568,17 +348,11 @@ async function threadListItemFromActive(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await resolveActiveThreadStatus(storageRoot, threadId, uwf, head, workflow);
|
// Check if thread is currently running in background
|
||||||
const statusDisplay = status === "suspended" ? `${status} [suspended]` : status;
|
const runningMarker = await isThreadRunning(storageRoot, threadId);
|
||||||
|
const status: ThreadStatus = runningMarker !== null ? "running" : "idle";
|
||||||
|
|
||||||
return {
|
return { thread: threadId, workflow, head, status };
|
||||||
thread: threadId,
|
|
||||||
workflow,
|
|
||||||
head,
|
|
||||||
status,
|
|
||||||
currentRole: resolveCurrentRole(uwf, head, workflow),
|
|
||||||
statusDisplay,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function collectActiveThreads(
|
async function collectActiveThreads(
|
||||||
@@ -587,8 +361,13 @@ async function collectActiveThreads(
|
|||||||
index: ThreadsIndex,
|
index: ThreadsIndex,
|
||||||
): Promise<ThreadListItemWithStatus[]> {
|
): Promise<ThreadListItemWithStatus[]> {
|
||||||
const items: ThreadListItemWithStatus[] = [];
|
const items: ThreadListItemWithStatus[] = [];
|
||||||
for (const [threadId, entry] of Object.entries(index)) {
|
for (const [threadId, head] of Object.entries(index)) {
|
||||||
const item = await threadListItemFromActive(storageRoot, uwf, threadId as ThreadId, entry.head);
|
const item = await threadListItemFromActive(
|
||||||
|
storageRoot,
|
||||||
|
uwf,
|
||||||
|
threadId as ThreadId,
|
||||||
|
head as CasRef,
|
||||||
|
);
|
||||||
if (item !== null) {
|
if (item !== null) {
|
||||||
items.push(item);
|
items.push(item);
|
||||||
}
|
}
|
||||||
@@ -606,14 +385,11 @@ async function collectCompletedThreads(
|
|||||||
for (const entry of history) {
|
for (const entry of history) {
|
||||||
if (!activeIds.has(entry.thread) && !seen.has(entry.thread)) {
|
if (!activeIds.has(entry.thread) && !seen.has(entry.thread)) {
|
||||||
seen.add(entry.thread);
|
seen.add(entry.thread);
|
||||||
const status = entry.reason === "cancelled" ? "cancelled" : "completed";
|
|
||||||
items.push({
|
items.push({
|
||||||
thread: entry.thread,
|
thread: entry.thread,
|
||||||
workflow: entry.workflow,
|
workflow: entry.workflow,
|
||||||
head: entry.head,
|
head: entry.head,
|
||||||
status,
|
status: entry.reason === "cancelled" ? "cancelled" : "completed",
|
||||||
currentRole: null,
|
|
||||||
statusDisplay: status,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -996,8 +772,7 @@ function spawnAgent(
|
|||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
role: string,
|
role: string,
|
||||||
edgePrompt: string,
|
edgePrompt: string,
|
||||||
cwd: string,
|
): CasRef {
|
||||||
): AdapterOutput {
|
|
||||||
const argv = [...agent.args, "--thread", threadId, "--role", role, "--prompt", edgePrompt];
|
const argv = [...agent.args, "--thread", threadId, "--role", role, "--prompt", edgePrompt];
|
||||||
let stdout: string;
|
let stdout: string;
|
||||||
try {
|
try {
|
||||||
@@ -1005,7 +780,6 @@ function spawnAgent(
|
|||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
stdio: ["ignore", "pipe", "pipe"],
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
maxBuffer: 50 * 1024 * 1024, // 50 MB — stream-json output can be large
|
maxBuffer: 50 * 1024 * 1024, // 50 MB — stream-json output can be large
|
||||||
cwd,
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const err = e as NodeJS.ErrnoException & { stderr?: Buffer | string | null };
|
const err = e as NodeJS.ErrnoException & { stderr?: Buffer | string | null };
|
||||||
@@ -1020,22 +794,10 @@ function spawnAgent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const line = stdout.trim().split("\n").pop()?.trim() ?? "";
|
const line = stdout.trim().split("\n").pop()?.trim() ?? "";
|
||||||
let parsed: unknown;
|
if (!isCasRef(line)) {
|
||||||
try {
|
failStep(plog, `agent stdout is not a valid CAS hash: ${line || "(empty)"}`);
|
||||||
parsed = JSON.parse(line);
|
|
||||||
} catch {
|
|
||||||
failStep(plog, `agent stdout last line is not valid JSON: ${line || "(empty)"}`);
|
|
||||||
}
|
}
|
||||||
const obj = parsed as Record<string, unknown>;
|
return line;
|
||||||
if (
|
|
||||||
typeof obj !== "object" ||
|
|
||||||
obj === null ||
|
|
||||||
typeof obj.stepHash !== "string" ||
|
|
||||||
!isCasRef(obj.stepHash as string)
|
|
||||||
) {
|
|
||||||
failStep(plog, `agent stdout JSON missing valid stepHash: ${line}`);
|
|
||||||
}
|
|
||||||
return obj as unknown as AdapterOutput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function archiveThread(
|
async function archiveThread(
|
||||||
@@ -1056,65 +818,6 @@ async function archiveThread(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cmdThreadResume(
|
|
||||||
storageRoot: string,
|
|
||||||
threadId: ThreadId,
|
|
||||||
supplement: string | null,
|
|
||||||
agentOverride: string | null,
|
|
||||||
): Promise<StepOutput> {
|
|
||||||
const runningMarker = await isThreadRunning(storageRoot, threadId);
|
|
||||||
if (runningMarker !== null) {
|
|
||||||
fail(`thread already executing in background (PID: ${runningMarker.pid})`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const entry = index[threadId];
|
|
||||||
if (entry === undefined) {
|
|
||||||
fail(`thread not active: ${threadId}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
const headHash = entry.head;
|
|
||||||
const chain = walkChain(uwf, headHash);
|
|
||||||
const workflowHash = chain.start.workflow;
|
|
||||||
|
|
||||||
const status = await resolveActiveThreadStatus(
|
|
||||||
storageRoot,
|
|
||||||
threadId,
|
|
||||||
uwf,
|
|
||||||
headHash,
|
|
||||||
workflowHash,
|
|
||||||
);
|
|
||||||
if (status !== "suspended") {
|
|
||||||
fail(`thread is not suspended: ${threadId} (status: ${status})`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const suspendFields = resolveSuspendFieldsForShow(entry, status, uwf, headHash, workflowHash);
|
|
||||||
if (suspendFields.suspendedRole === null) {
|
|
||||||
fail(`thread is suspended but suspendedRole is missing: ${threadId}`);
|
|
||||||
}
|
|
||||||
if (suspendFields.suspendMessage === null) {
|
|
||||||
fail(`thread is suspended but suspendMessage is missing: ${threadId}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const resumePrompt = buildResumePrompt(suspendFields.suspendMessage, supplement);
|
|
||||||
const plog = createProcessLogger({
|
|
||||||
storageRoot,
|
|
||||||
context: { thread: threadId, workflow: workflowHash },
|
|
||||||
});
|
|
||||||
|
|
||||||
plog.log(
|
|
||||||
PL_THREAD_RESUME,
|
|
||||||
`resume role=${suspendFields.suspendedRole} supplement=${supplement !== null}`,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return cmdThreadStepOnce(storageRoot, threadId, agentOverride, plog, {
|
|
||||||
role: suspendFields.suspendedRole,
|
|
||||||
prompt: resumePrompt,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function cmdThreadExec(
|
export async function cmdThreadExec(
|
||||||
storageRoot: string,
|
storageRoot: string,
|
||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
@@ -1163,7 +866,7 @@ export async function cmdThreadExec(
|
|||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
const result = await cmdThreadStepOnce(storageRoot, threadId, agentOverride, plog);
|
const result = await cmdThreadStepOnce(storageRoot, threadId, agentOverride, plog);
|
||||||
results.push(result);
|
results.push(result);
|
||||||
if (result.done || result.status === "suspended") {
|
if (result.done) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1181,12 +884,12 @@ async function resolveActiveThreadWorkflowHash(
|
|||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
): Promise<CasRef> {
|
): Promise<CasRef> {
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
const entry = index[threadId];
|
const headHash = index[threadId];
|
||||||
if (entry === undefined) {
|
if (headHash === undefined) {
|
||||||
fail(`thread not active: ${threadId}`);
|
fail(`thread not active: ${threadId}`);
|
||||||
}
|
}
|
||||||
const uwf = await createUwfStore(storageRoot);
|
const uwf = await createUwfStore(storageRoot);
|
||||||
const chain = walkChain(uwf, entry.head);
|
const chain = walkChain(uwf, headHash);
|
||||||
return chain.start.workflow;
|
return chain.start.workflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1200,13 +903,10 @@ async function cmdThreadStepBackground(
|
|||||||
): Promise<StepOutput[]> {
|
): Promise<StepOutput[]> {
|
||||||
// Get current head to return to caller
|
// Get current head to return to caller
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
const entry = index[threadId];
|
const headHash = index[threadId];
|
||||||
if (entry === undefined) {
|
if (headHash === undefined) {
|
||||||
failStep(plog, `thread not active: ${threadId}`);
|
failStep(plog, `thread not active: ${threadId}`);
|
||||||
}
|
}
|
||||||
const headHash = entry.head;
|
|
||||||
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
|
|
||||||
// Spawn detached background process
|
// Spawn detached background process
|
||||||
const scriptPath = process.argv[1];
|
const scriptPath = process.argv[1];
|
||||||
@@ -1238,44 +938,30 @@ async function cmdThreadStepBackground(
|
|||||||
workflow: workflowHash,
|
workflow: workflowHash,
|
||||||
thread: threadId,
|
thread: threadId,
|
||||||
head: headHash,
|
head: headHash,
|
||||||
status: "running",
|
|
||||||
currentRole: resolveCurrentRole(uwf, headHash, workflowHash),
|
|
||||||
suspendedRole: null,
|
|
||||||
suspendMessage: null,
|
|
||||||
done: false,
|
done: false,
|
||||||
background: true,
|
background: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveResumeStepTarget(
|
async function cmdThreadStepOnce(
|
||||||
resume: ResumeStepConfig,
|
|
||||||
chain: ChainState,
|
|
||||||
threadCwd: string,
|
|
||||||
plog: ProcessLogger,
|
|
||||||
): AgentStepTarget {
|
|
||||||
const lastStep = chain.stepsNewestFirst[0];
|
|
||||||
plog.log(PL_MODERATOR, `resume role=${resume.role} prompt=${resume.prompt}`, null);
|
|
||||||
return {
|
|
||||||
role: resume.role,
|
|
||||||
edgePrompt: resume.prompt,
|
|
||||||
effectiveCwd: lastStep !== undefined && lastStep.cwd !== "" ? lastStep.cwd : threadCwd,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveModeratorStepTarget(
|
|
||||||
storageRoot: string,
|
storageRoot: string,
|
||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
entry: ThreadIndexEntry,
|
agentOverride: string | null,
|
||||||
headHash: CasRef,
|
|
||||||
workflowHash: CasRef,
|
|
||||||
workflow: WorkflowPayload,
|
|
||||||
uwf: UwfStore,
|
|
||||||
chain: ChainState,
|
|
||||||
threadCwd: string,
|
|
||||||
plog: ProcessLogger,
|
plog: ProcessLogger,
|
||||||
): Promise<StepOutput | AgentStepTarget> {
|
): Promise<StepOutput> {
|
||||||
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
|
const headHash = index[threadId];
|
||||||
|
if (headHash === undefined) {
|
||||||
|
failStep(plog, `thread not active: ${threadId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uwf = await createUwfStore(storageRoot);
|
||||||
|
const chain = walkChain(uwf, headHash);
|
||||||
|
const workflowHash = chain.start.workflow;
|
||||||
|
const workflow = loadWorkflowPayload(uwf, workflowHash);
|
||||||
const { lastRole, lastOutput } = resolveEvaluateArgs(uwf, chain);
|
const { lastRole, lastOutput } = resolveEvaluateArgs(uwf, chain);
|
||||||
|
|
||||||
const nextResult = evaluate(workflow.graph, lastRole, lastOutput);
|
const nextResult = evaluate(workflow.graph, lastRole, lastOutput);
|
||||||
if (!nextResult.ok) {
|
if (!nextResult.ok) {
|
||||||
failStep(plog, `moderator evaluate failed: ${nextResult.error.message}`);
|
failStep(plog, `moderator evaluate failed: ${nextResult.error.message}`);
|
||||||
@@ -1283,32 +969,10 @@ async function resolveModeratorStepTarget(
|
|||||||
|
|
||||||
plog.log(
|
plog.log(
|
||||||
PL_MODERATOR,
|
PL_MODERATOR,
|
||||||
`moderator ${
|
`moderator role=${nextResult.value.role} prompt=${nextResult.value.prompt}`,
|
||||||
isSuspendResult(nextResult.value)
|
|
||||||
? `action=suspend suspendedRole=${nextResult.value.suspendedRole}`
|
|
||||||
: `role=${nextResult.value.role}`
|
|
||||||
} prompt=${nextResult.value.prompt}`,
|
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isSuspendResult(nextResult.value)) {
|
|
||||||
await ensureThreadSuspendMetadata(
|
|
||||||
storageRoot,
|
|
||||||
threadId,
|
|
||||||
entry,
|
|
||||||
nextResult.value.suspendedRole,
|
|
||||||
nextResult.value.prompt,
|
|
||||||
);
|
|
||||||
return buildStepOutputFromEvaluation(
|
|
||||||
workflowHash,
|
|
||||||
threadId,
|
|
||||||
headHash,
|
|
||||||
"suspended",
|
|
||||||
nextResult,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextResult.value.role === END_ROLE) {
|
if (nextResult.value.role === END_ROLE) {
|
||||||
plog.log(PL_THREAD_ARCHIVED, `thread archived head=${headHash}`, null);
|
plog.log(PL_THREAD_ARCHIVED, `thread archived head=${headHash}`, null);
|
||||||
await archiveThread(storageRoot, threadId, workflowHash, headHash);
|
await archiveThread(storageRoot, threadId, workflowHash, headHash);
|
||||||
@@ -1316,34 +980,35 @@ async function resolveModeratorStepTarget(
|
|||||||
workflow: workflowHash,
|
workflow: workflowHash,
|
||||||
thread: threadId,
|
thread: threadId,
|
||||||
head: headHash,
|
head: headHash,
|
||||||
status: "completed",
|
|
||||||
currentRole: null,
|
|
||||||
suspendedRole: null,
|
|
||||||
suspendMessage: null,
|
|
||||||
done: true,
|
done: true,
|
||||||
background: null,
|
background: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const role = nextResult.value.role;
|
||||||
role: nextResult.value.role,
|
const edgePrompt = nextResult.value.prompt;
|
||||||
edgePrompt: nextResult.value.prompt,
|
const config = await loadWorkflowConfig(storageRoot);
|
||||||
effectiveCwd: nextResult.value.location !== null ? nextResult.value.location : threadCwd,
|
const agent = resolveAgentConfig(config, workflow, role, agentOverride);
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function finalizeAgentStep(
|
plog.log(PL_AGENT_SPAWN, `spawning agent command=${agent.command}`, {
|
||||||
storageRoot: string,
|
args: [...agent.args, threadId, role].join(" "),
|
||||||
threadId: ThreadId,
|
});
|
||||||
workflowHash: CasRef,
|
|
||||||
workflow: WorkflowPayload,
|
loadDotenv({ path: getEnvPath(storageRoot) });
|
||||||
newHead: CasRef,
|
const newHead = spawnAgent(plog, agent, threadId, role, edgePrompt);
|
||||||
uwfAfter: UwfStore,
|
|
||||||
plog: ProcessLogger,
|
plog.log(PL_AGENT_DONE, `agent returned head=${newHead}`, null);
|
||||||
): Promise<StepOutput> {
|
|
||||||
|
// Re-create store to pick up nodes written by the agent subprocess
|
||||||
|
const uwfAfter = await createUwfStore(storageRoot);
|
||||||
|
const newNode = uwfAfter.store.get(newHead);
|
||||||
|
if (newNode === null || newNode.type !== uwfAfter.schemas.stepNode) {
|
||||||
|
failStep(plog, `agent returned hash that is not a StepNode: ${newHead}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload threads index to avoid overwriting changes made by the agent subprocess
|
||||||
const freshIndex = await loadThreadsIndex(storageRoot);
|
const freshIndex = await loadThreadsIndex(storageRoot);
|
||||||
const priorEntry = freshIndex[threadId] ?? createThreadIndexEntry(newHead);
|
freshIndex[threadId] = newHead;
|
||||||
freshIndex[threadId] = updateThreadHead(priorEntry, newHead);
|
|
||||||
await saveThreadsIndex(storageRoot, freshIndex);
|
await saveThreadsIndex(storageRoot, freshIndex);
|
||||||
|
|
||||||
const chainAfter = walkChain(uwfAfter, newHead);
|
const chainAfter = walkChain(uwfAfter, newHead);
|
||||||
@@ -1356,112 +1021,24 @@ async function finalizeAgentStep(
|
|||||||
failStep(plog, `post-step moderator evaluate failed: ${afterResult.error.message}`);
|
failStep(plog, `post-step moderator evaluate failed: ${afterResult.error.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSuspendResult(afterResult.value)) {
|
|
||||||
freshIndex[threadId] = markThreadSuspended(
|
|
||||||
freshIndex[threadId] ?? createThreadIndexEntry(newHead),
|
|
||||||
afterResult.value.suspendedRole,
|
|
||||||
afterResult.value.prompt,
|
|
||||||
);
|
|
||||||
await saveThreadsIndex(storageRoot, freshIndex);
|
|
||||||
return buildStepOutputFromEvaluation(
|
|
||||||
workflowHash,
|
|
||||||
threadId,
|
|
||||||
newHead,
|
|
||||||
"suspended",
|
|
||||||
afterResult,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const done = afterResult.value.role === END_ROLE;
|
const done = afterResult.value.role === END_ROLE;
|
||||||
if (done) {
|
if (done) {
|
||||||
plog.log(PL_THREAD_ARCHIVED, `thread archived head=${newHead}`, null);
|
plog.log(PL_THREAD_ARCHIVED, `thread archived head=${newHead}`, null);
|
||||||
await archiveThread(storageRoot, threadId, workflowHash, newHead);
|
await archiveThread(storageRoot, threadId, workflowHash, newHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
const status: ThreadStatus = done ? "completed" : "idle";
|
|
||||||
const currentRole = done ? null : afterResult.value.role;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
workflow: workflowHash,
|
workflow: workflowHash,
|
||||||
thread: threadId,
|
thread: threadId,
|
||||||
head: newHead,
|
head: newHead,
|
||||||
status,
|
|
||||||
currentRole,
|
|
||||||
suspendedRole: null,
|
|
||||||
suspendMessage: null,
|
|
||||||
done,
|
done,
|
||||||
background: null,
|
background: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cmdThreadStepOnce(
|
|
||||||
storageRoot: string,
|
|
||||||
threadId: ThreadId,
|
|
||||||
agentOverride: string | null,
|
|
||||||
plog: ProcessLogger,
|
|
||||||
resume: ResumeStepConfig | null = null,
|
|
||||||
): Promise<StepOutput> {
|
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
|
||||||
const entry = index[threadId];
|
|
||||||
if (entry === undefined) {
|
|
||||||
failStep(plog, `thread not active: ${threadId}`);
|
|
||||||
}
|
|
||||||
const headHash = entry.head;
|
|
||||||
|
|
||||||
const uwf = await createUwfStore(storageRoot);
|
|
||||||
const chain = walkChain(uwf, headHash);
|
|
||||||
const workflowHash = chain.start.workflow;
|
|
||||||
const workflow = loadWorkflowPayload(uwf, workflowHash);
|
|
||||||
const threadCwd = chain.start.cwd;
|
|
||||||
|
|
||||||
const targetOrOutput =
|
|
||||||
resume !== null
|
|
||||||
? resolveResumeStepTarget(resume, chain, threadCwd, plog)
|
|
||||||
: await resolveModeratorStepTarget(
|
|
||||||
storageRoot,
|
|
||||||
threadId,
|
|
||||||
entry,
|
|
||||||
headHash,
|
|
||||||
workflowHash,
|
|
||||||
workflow,
|
|
||||||
uwf,
|
|
||||||
chain,
|
|
||||||
threadCwd,
|
|
||||||
plog,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ("status" in targetOrOutput) {
|
|
||||||
return targetOrOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { role, edgePrompt, effectiveCwd } = targetOrOutput;
|
|
||||||
|
|
||||||
const config = await loadWorkflowConfig(storageRoot);
|
|
||||||
const agent = resolveAgentConfig(config, workflow, role, agentOverride);
|
|
||||||
|
|
||||||
plog.log(PL_AGENT_SPAWN, `spawning agent command=${agent.command}`, {
|
|
||||||
args: [...agent.args, threadId, role].join(" "),
|
|
||||||
});
|
|
||||||
|
|
||||||
loadDotenv({ path: getEnvPath(storageRoot) });
|
|
||||||
const agentResult = spawnAgent(plog, agent, threadId, role, edgePrompt, effectiveCwd);
|
|
||||||
const newHead = agentResult.stepHash as CasRef;
|
|
||||||
|
|
||||||
plog.log(PL_AGENT_DONE, `agent returned head=${newHead}`, null);
|
|
||||||
|
|
||||||
const uwfAfter = await createUwfStore(storageRoot);
|
|
||||||
const newNode = uwfAfter.store.get(newHead);
|
|
||||||
if (newNode === null || newNode.type !== uwfAfter.schemas.stepNode) {
|
|
||||||
failStep(plog, `agent returned hash that is not a StepNode: ${newHead}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return finalizeAgentStep(storageRoot, threadId, workflowHash, workflow, newHead, uwfAfter, plog);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveHeadHash(storageRoot: string, threadId: ThreadId): Promise<CasRef> {
|
async function resolveHeadHash(storageRoot: string, threadId: ThreadId): Promise<CasRef> {
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
const activeHead = index[threadId]?.head;
|
const activeHead = index[threadId];
|
||||||
if (activeHead !== undefined) {
|
if (activeHead !== undefined) {
|
||||||
return activeHead;
|
return activeHead;
|
||||||
}
|
}
|
||||||
@@ -1514,8 +1091,8 @@ export type CancelOutput = {
|
|||||||
*/
|
*/
|
||||||
export async function cmdThreadStop(storageRoot: string, threadId: ThreadId): Promise<StopOutput> {
|
export async function cmdThreadStop(storageRoot: string, threadId: ThreadId): Promise<StopOutput> {
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
const entry = index[threadId];
|
const head = index[threadId];
|
||||||
if (entry === undefined) {
|
if (head === undefined) {
|
||||||
fail(`thread not active: ${threadId}`);
|
fail(`thread not active: ${threadId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1544,11 +1121,10 @@ export async function cmdThreadCancel(
|
|||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
): Promise<CancelOutput> {
|
): Promise<CancelOutput> {
|
||||||
const index = await loadThreadsIndex(storageRoot);
|
const index = await loadThreadsIndex(storageRoot);
|
||||||
const entry = index[threadId];
|
const head = index[threadId];
|
||||||
if (entry === undefined) {
|
if (head === undefined) {
|
||||||
fail(`thread not active: ${threadId}`);
|
fail(`thread not active: ${threadId}`);
|
||||||
}
|
}
|
||||||
const head = entry.head;
|
|
||||||
|
|
||||||
// Check if thread is running in background and terminate it
|
// Check if thread is running in background and terminate it
|
||||||
const runningMarker = await isThreadRunning(storageRoot, threadId);
|
const runningMarker = await isThreadRunning(storageRoot, threadId);
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
import { dirname, resolve as resolvePath } from "node:path";
|
|
||||||
|
|
||||||
import type { JSONSchema } from "@ocas/core";
|
import type { JSONSchema } from "@uncaged/json-cas";
|
||||||
import { putSchema, validate } from "@ocas/core";
|
import { putSchema, validate } from "@uncaged/json-cas";
|
||||||
import type { CasRef, RoleDefinition, Target, WorkflowPayload } from "@uncaged/workflow-protocol";
|
import type { CasRef, RoleDefinition, Target, WorkflowPayload } from "@uncaged/workflow-protocol";
|
||||||
import { parse } from "yaml";
|
import { parse } from "yaml";
|
||||||
import { createIncludeTag } from "../include.js";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createUwfStore,
|
createUwfStore,
|
||||||
@@ -63,7 +61,6 @@ function normalizeGraph(
|
|||||||
normalized[status] = {
|
normalized[status] = {
|
||||||
role: target.role,
|
role: target.role,
|
||||||
prompt: target.prompt,
|
prompt: target.prompt,
|
||||||
location: target.location ?? null,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
result[node] = normalized;
|
result[node] = normalized;
|
||||||
@@ -125,9 +122,7 @@ export async function cmdWorkflowAdd(
|
|||||||
|
|
||||||
let raw: unknown;
|
let raw: unknown;
|
||||||
try {
|
try {
|
||||||
raw = parse(text, {
|
raw = parse(text) as unknown;
|
||||||
customTags: [createIncludeTag(dirname(resolvePath(filePath)))],
|
|
||||||
}) as unknown;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
fail(`invalid YAML: ${e instanceof Error ? e.message : String(e)}`);
|
fail(`invalid YAML: ${e instanceof Error ? e.message : String(e)}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import { readFileSync } from "node:fs";
|
|
||||||
import { dirname, extname, resolve } from "node:path";
|
|
||||||
import { parse as parseYaml } from "yaml";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a YAML customTags entry for !include that resolves file paths
|
|
||||||
* relative to the given base directory.
|
|
||||||
*
|
|
||||||
* Security: resolved paths must stay within baseDir (path traversal prevention).
|
|
||||||
* Nested !include in .yaml/.yml files is supported (customTags passed recursively).
|
|
||||||
*/
|
|
||||||
export function createIncludeTag(baseDir: string) {
|
|
||||||
const resolvedBase = resolve(baseDir);
|
|
||||||
return {
|
|
||||||
tag: "!include",
|
|
||||||
resolve(str: string) {
|
|
||||||
const filePath = resolve(resolvedBase, str);
|
|
||||||
// Path traversal guard: resolved path must be inside baseDir
|
|
||||||
if (!filePath.startsWith(`${resolvedBase}/`) && filePath !== resolvedBase) {
|
|
||||||
throw new Error(
|
|
||||||
`!include path traversal blocked: "${str}" resolves outside base directory`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const content = readFileSync(filePath, "utf8");
|
|
||||||
const ext = extname(filePath).toLowerCase();
|
|
||||||
if (ext === ".json") {
|
|
||||||
return JSON.parse(content);
|
|
||||||
}
|
|
||||||
if (ext === ".yaml" || ext === ".yml") {
|
|
||||||
// Pass customTags recursively so nested !include works,
|
|
||||||
// scoped to the included file's directory
|
|
||||||
return parseYaml(content, { customTags: [createIncludeTag(dirname(filePath))] });
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { evaluate } from "../evaluate.js";
|
|
||||||
import { isSuspendResult } from "../types.js";
|
|
||||||
|
|
||||||
describe("Edge prompt template variable resolution", () => {
|
|
||||||
test("returns error when rendered prompt is empty string", () => {
|
|
||||||
const graph = {
|
|
||||||
$START: {
|
|
||||||
_: { role: "classifier", prompt: "{{{userPrompt}}}", location: null },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "$START", {});
|
|
||||||
|
|
||||||
expect(result.ok).toBe(false);
|
|
||||||
if (!result.ok) {
|
|
||||||
expect(result.error.message).toContain("prompt");
|
|
||||||
expect(result.error.message).toContain("empty");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns error when rendered prompt is whitespace-only", () => {
|
|
||||||
const graph = {
|
|
||||||
$START: {
|
|
||||||
_: { role: "classifier", prompt: " {{{userPrompt}}} ", location: null },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "$START", {});
|
|
||||||
|
|
||||||
expect(result.ok).toBe(false);
|
|
||||||
if (!result.ok) {
|
|
||||||
expect(result.error.message).toContain("prompt");
|
|
||||||
expect(result.error.message).toContain("empty");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("succeeds when all template variables resolve to non-empty values", () => {
|
|
||||||
const graph = {
|
|
||||||
$START: {
|
|
||||||
_: { role: "classifier", prompt: "{{{userPrompt}}}", location: null },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "$START", { userPrompt: "Fix the bug" });
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok) {
|
|
||||||
expect(result.value.prompt).toBe("Fix the bug");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("succeeds with static (no-variable) prompt", () => {
|
|
||||||
const graph = {
|
|
||||||
$START: {
|
|
||||||
_: { role: "classifier", prompt: "Classify this input", location: null },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "$START", {});
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok) {
|
|
||||||
expect(result.value.prompt).toBe("Classify this input");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("succeeds when prompt has mix of static text and unresolved variables", () => {
|
|
||||||
const graph = {
|
|
||||||
$START: {
|
|
||||||
_: { role: "classifier", prompt: "Please handle: {{{userPrompt}}}", location: null },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "$START", {});
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok) {
|
|
||||||
expect(result.value.prompt).toBe("Please handle: ");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns error when ALL variables missing and no static text remains", () => {
|
|
||||||
const graph = {
|
|
||||||
$START: {
|
|
||||||
_: { role: "classifier", prompt: "{{{a}}}{{{b}}}", location: null },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "$START", {});
|
|
||||||
|
|
||||||
expect(result.ok).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Moderator location resolution", () => {
|
|
||||||
test("returns null location when edge has no location field", () => {
|
|
||||||
const graph = {
|
|
||||||
planner: {
|
|
||||||
ready: {
|
|
||||||
role: "coder",
|
|
||||||
prompt: "Implement the code",
|
|
||||||
location: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "planner", { $status: "ready" });
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok && !isSuspendResult(result.value)) {
|
|
||||||
expect(result.value.location).toBe(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("resolves static location string", () => {
|
|
||||||
const graph = {
|
|
||||||
planner: {
|
|
||||||
ready: {
|
|
||||||
role: "coder",
|
|
||||||
prompt: "Implement the code",
|
|
||||||
location: "/static/path",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "planner", { $status: "ready" });
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok && !isSuspendResult(result.value)) {
|
|
||||||
expect(result.value.location).toBe("/static/path");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("resolves mustache template location", () => {
|
|
||||||
const graph = {
|
|
||||||
planner: {
|
|
||||||
ready: {
|
|
||||||
role: "coder",
|
|
||||||
prompt: "Implement the code",
|
|
||||||
location: "{{{repoPath}}}",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "planner", {
|
|
||||||
$status: "ready",
|
|
||||||
repoPath: "/home/user/repo",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok && !isSuspendResult(result.value)) {
|
|
||||||
expect(result.value.location).toBe("/home/user/repo");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("resolves mustache template with multiple variables", () => {
|
|
||||||
const graph = {
|
|
||||||
planner: {
|
|
||||||
ready: {
|
|
||||||
role: "coder",
|
|
||||||
prompt: "Implement the code",
|
|
||||||
location: "{{{basePath}}}/{{{projectName}}}",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "planner", {
|
|
||||||
$status: "ready",
|
|
||||||
basePath: "/home/user",
|
|
||||||
projectName: "myproject",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok && !isSuspendResult(result.value)) {
|
|
||||||
expect(result.value.location).toBe("/home/user/myproject");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles missing template variable gracefully", () => {
|
|
||||||
const graph = {
|
|
||||||
planner: {
|
|
||||||
ready: {
|
|
||||||
role: "coder",
|
|
||||||
prompt: "Implement the code",
|
|
||||||
location: "{{{repoPath}}}",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = evaluate(graph, "planner", { $status: "ready" });
|
|
||||||
|
|
||||||
expect(result.ok).toBe(true);
|
|
||||||
if (result.ok && !isSuspendResult(result.value)) {
|
|
||||||
// Mustache renders missing variables as empty string
|
|
||||||
expect(result.value.location).toBe("");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -7,7 +7,6 @@ import type { EvaluateResult, Result } from "./types.js";
|
|||||||
mustache.escape = (text: string) => text;
|
mustache.escape = (text: string) => text;
|
||||||
|
|
||||||
const START_ROLE = "$START";
|
const START_ROLE = "$START";
|
||||||
const SUSPEND_ROLE = "$SUSPEND";
|
|
||||||
const UNIT_STATUS = "_";
|
const UNIT_STATUS = "_";
|
||||||
|
|
||||||
type LastOutput = Record<string, unknown>;
|
type LastOutput = Record<string, unknown>;
|
||||||
@@ -44,27 +43,7 @@ export function evaluate(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const prompt = mustache.render(target.prompt, lastOutput);
|
const prompt = mustache.render(target.prompt, lastOutput);
|
||||||
if (prompt.trim() === "") {
|
return { ok: true, value: { role: target.role, prompt } };
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
error: new Error(
|
|
||||||
`edge prompt resolved to empty string for role "${target.role}" (template: "${target.prompt}"). Check that upstream output includes required variables.`,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (target.role === SUSPEND_ROLE) {
|
|
||||||
return {
|
|
||||||
ok: true,
|
|
||||||
value: {
|
|
||||||
action: "suspend",
|
|
||||||
suspendedRole: lastRole,
|
|
||||||
prompt,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const location = target.location !== null ? mustache.render(target.location, lastOutput) : null;
|
|
||||||
return { ok: true, value: { role: target.role, prompt, location } };
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
|
|||||||
@@ -1,7 +1,2 @@
|
|||||||
export { evaluate } from "./evaluate.js";
|
export { evaluate } from "./evaluate.js";
|
||||||
export type {
|
export type { EvaluateResult } from "./types.js";
|
||||||
EvaluateResult,
|
|
||||||
EvaluateRouteResult,
|
|
||||||
EvaluateSuspendResult,
|
|
||||||
} from "./types.js";
|
|
||||||
export { isSuspendResult } from "./types.js";
|
|
||||||
|
|||||||
@@ -1,24 +1,7 @@
|
|||||||
export type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
|
export type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
|
||||||
|
|
||||||
/** Moderator routes the thread to a real role (or `$END`). */
|
/** The result of moderator evaluation — which role to go to, and the edge prompt. */
|
||||||
export type EvaluateRouteResult = {
|
export type EvaluateResult = {
|
||||||
role: string;
|
role: string;
|
||||||
prompt: string;
|
prompt: string;
|
||||||
/** Resolved working directory from edge location field (null = inherit thread cwd). */
|
|
||||||
location: string | null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Moderator routes the thread to `$SUSPEND` — waiting for external input. */
|
|
||||||
export type EvaluateSuspendResult = {
|
|
||||||
action: "suspend";
|
|
||||||
/** Role whose output triggered the suspend transition. */
|
|
||||||
suspendedRole: string;
|
|
||||||
prompt: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** The result of moderator evaluation. */
|
|
||||||
export type EvaluateResult = EvaluateRouteResult | EvaluateSuspendResult;
|
|
||||||
|
|
||||||
export function isSuspendResult(result: EvaluateResult): result is EvaluateSuspendResult {
|
|
||||||
return "action" in result && result.action === "suspend";
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Hash, Store } from "@ocas/core";
|
import type { Hash, Store } from "@uncaged/json-cas";
|
||||||
import { putSchema } from "@ocas/core";
|
import { putSchema } from "@uncaged/json-cas";
|
||||||
import { START_NODE_SCHEMA, STEP_NODE_SCHEMA, WORKFLOW_SCHEMA } from "@uncaged/workflow-protocol";
|
import { START_NODE_SCHEMA, STEP_NODE_SCHEMA, WORKFLOW_SCHEMA } from "@uncaged/workflow-protocol";
|
||||||
|
|
||||||
export const TEXT_SCHEMA = { type: "string" as const };
|
export const TEXT_SCHEMA = { type: "string" as const };
|
||||||
|
|||||||
@@ -1,22 +1,10 @@
|
|||||||
import type { Dirent } from "node:fs";
|
import { appendFile, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
||||||
import { access, appendFile, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
||||||
import { homedir } from "node:os";
|
import { homedir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
|
||||||
import type { BootstrapCapableStore, Hash } from "@ocas/core";
|
import type { BootstrapCapableStore, Hash } from "@uncaged/json-cas";
|
||||||
import { createFsStore } from "@ocas/fs";
|
import { createFsStore } from "@uncaged/json-cas-fs";
|
||||||
import type {
|
import type { CasRef, ThreadId, ThreadListItem, ThreadsIndex } from "@uncaged/workflow-protocol";
|
||||||
CasRef,
|
|
||||||
ThreadId,
|
|
||||||
ThreadIndexEntry,
|
|
||||||
ThreadListItem,
|
|
||||||
ThreadsIndex,
|
|
||||||
} from "@uncaged/workflow-protocol";
|
|
||||||
import {
|
|
||||||
createThreadIndexEntry,
|
|
||||||
parseThreadsIndex,
|
|
||||||
serializeThreadsIndex,
|
|
||||||
} from "@uncaged/workflow-protocol";
|
|
||||||
import { parse, stringify } from "yaml";
|
import { parse, stringify } from "yaml";
|
||||||
|
|
||||||
import { registerUwfSchemas, type UwfSchemaHashes } from "./schemas.js";
|
import { registerUwfSchemas, type UwfSchemaHashes } from "./schemas.js";
|
||||||
@@ -31,38 +19,17 @@ export type ProjectWorkflowEntry = {
|
|||||||
filePath: string;
|
filePath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Extract workflow name from a YAML filename (strip .yaml/.yml extension). */
|
|
||||||
function stemFromYaml(name: string): string {
|
|
||||||
if (name.endsWith(".yaml")) return name.slice(0, -5);
|
|
||||||
if (name.endsWith(".yml")) return name.slice(0, -4);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check if a directory contains an index.yaml or index.yml workflow file. */
|
|
||||||
async function findIndexWorkflow(
|
|
||||||
dir: string,
|
|
||||||
dirName: string,
|
|
||||||
): Promise<ProjectWorkflowEntry | null> {
|
|
||||||
for (const indexName of ["index.yaml", "index.yml"]) {
|
|
||||||
const indexPath = join(dir, dirName, indexName);
|
|
||||||
try {
|
|
||||||
await access(indexPath);
|
|
||||||
return { name: dirName, filePath: indexPath };
|
|
||||||
} catch {
|
|
||||||
// not found, try next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan a single directory for workflow entries (flat YAML files + folder/index.yaml).
|
* Scan `<projectRoot>/.workflows/*.yaml` (non-recursive) and return discovered entries.
|
||||||
* Returns discovered entries. Returns empty array if directory does not exist.
|
* Returns an empty array if the directory does not exist.
|
||||||
*/
|
*/
|
||||||
async function scanWorkflowDir(dir: string): Promise<ProjectWorkflowEntry[]> {
|
export async function discoverProjectWorkflows(
|
||||||
let dirents: Dirent[];
|
projectRoot: string,
|
||||||
|
): Promise<ProjectWorkflowEntry[]> {
|
||||||
|
const dir = join(projectRoot, ".workflows");
|
||||||
|
let entries: string[];
|
||||||
try {
|
try {
|
||||||
dirents = await readdir(dir, { withFileTypes: true });
|
entries = await readdir(dir);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const err = e as NodeJS.ErrnoException;
|
const err = e as NodeJS.ErrnoException;
|
||||||
if (err.code === "ENOENT" || err.code === "ENOTDIR") {
|
if (err.code === "ENOENT" || err.code === "ENOTDIR") {
|
||||||
@@ -72,39 +39,16 @@ async function scanWorkflowDir(dir: string): Promise<ProjectWorkflowEntry[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result: ProjectWorkflowEntry[] = [];
|
const result: ProjectWorkflowEntry[] = [];
|
||||||
for (const entry of dirents) {
|
for (const entry of entries) {
|
||||||
if (entry.isFile() && (entry.name.endsWith(".yaml") || entry.name.endsWith(".yml"))) {
|
if (!entry.endsWith(".yaml") && !entry.endsWith(".yml")) {
|
||||||
result.push({ name: stemFromYaml(entry.name), filePath: join(dir, entry.name) });
|
continue;
|
||||||
} else if (entry.isDirectory()) {
|
|
||||||
const found = await findIndexWorkflow(dir, entry.name);
|
|
||||||
if (found !== null) {
|
|
||||||
result.push(found);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const stem = entry.endsWith(".yaml") ? entry.slice(0, -5) : entry.slice(0, -4);
|
||||||
|
result.push({ name: stem, filePath: join(dir, entry) });
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Scan `<projectRoot>/.workflow/` (preferred) and `.workflows/` (legacy) for workflow entries.
|
|
||||||
* .workflow/ takes priority: if a name is found in both, .workflow/ wins.
|
|
||||||
* Returns an empty array if neither directory exists.
|
|
||||||
*/
|
|
||||||
export async function discoverProjectWorkflows(
|
|
||||||
projectRoot: string,
|
|
||||||
): Promise<ProjectWorkflowEntry[]> {
|
|
||||||
const primary = await scanWorkflowDir(join(projectRoot, ".workflow"));
|
|
||||||
const legacy = await scanWorkflowDir(join(projectRoot, ".workflows"));
|
|
||||||
const seen = new Set(primary.map((e) => e.name));
|
|
||||||
const merged = [...primary];
|
|
||||||
for (const entry of legacy) {
|
|
||||||
if (!seen.has(entry.name)) {
|
|
||||||
merged.push(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return merged;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Default filesystem root for uwf data (`~/.uncaged/workflow`). */
|
/** Default filesystem root for uwf data (`~/.uncaged/workflow`). */
|
||||||
export function getDefaultStorageRoot(): string {
|
export function getDefaultStorageRoot(): string {
|
||||||
return join(homedir(), ".uncaged", "workflow");
|
return join(homedir(), ".uncaged", "workflow");
|
||||||
@@ -126,26 +70,10 @@ export function resolveStorageRoot(): string {
|
|||||||
return getDefaultStorageRoot();
|
return getDefaultStorageRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated: Use `getGlobalCasDir()` instead.
|
|
||||||
* Returns the old CAS directory for backward compatibility.
|
|
||||||
*/
|
|
||||||
export function getCasDir(storageRoot: string): string {
|
export function getCasDir(storageRoot: string): string {
|
||||||
return join(storageRoot, "cas");
|
return join(storageRoot, "cas");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the global CAS directory shared by all uwf and json-cas tools.
|
|
||||||
* Priority: UNCAGED_CAS_DIR environment variable → default ~/.uncaged/json-cas
|
|
||||||
*/
|
|
||||||
export function getGlobalCasDir(): string {
|
|
||||||
const envPath = process.env.UNCAGED_CAS_DIR;
|
|
||||||
if (envPath !== undefined && envPath !== "") {
|
|
||||||
return envPath;
|
|
||||||
}
|
|
||||||
return join(homedir(), ".uncaged", "json-cas");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getRegistryPath(storageRoot: string): string {
|
export function getRegistryPath(storageRoot: string): string {
|
||||||
return join(storageRoot, "workflows.yaml");
|
return join(storageRoot, "workflows.yaml");
|
||||||
}
|
}
|
||||||
@@ -170,7 +98,7 @@ export type UwfStore = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function createUwfStore(storageRoot: string): Promise<UwfStore> {
|
export async function createUwfStore(storageRoot: string): Promise<UwfStore> {
|
||||||
const casDir = getGlobalCasDir();
|
const casDir = getCasDir(storageRoot);
|
||||||
await mkdir(casDir, { recursive: true });
|
await mkdir(casDir, { recursive: true });
|
||||||
const store = createFsStore(casDir);
|
const store = createFsStore(casDir);
|
||||||
const schemas = await registerUwfSchemas(store);
|
const schemas = await registerUwfSchemas(store);
|
||||||
@@ -245,7 +173,16 @@ export async function loadThreadsIndex(storageRoot: string): Promise<ThreadsInde
|
|||||||
try {
|
try {
|
||||||
const text = await readFile(path, "utf8");
|
const text = await readFile(path, "utf8");
|
||||||
const raw = parse(text) as unknown;
|
const raw = parse(text) as unknown;
|
||||||
return parseThreadsIndex(raw);
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const index: ThreadsIndex = {};
|
||||||
|
for (const [threadId, head] of Object.entries(raw as Record<string, unknown>)) {
|
||||||
|
if (typeof head === "string") {
|
||||||
|
index[threadId as ThreadId] = head;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const err = e as NodeJS.ErrnoException;
|
const err = e as NodeJS.ErrnoException;
|
||||||
if (err.code === "ENOENT") {
|
if (err.code === "ENOENT") {
|
||||||
@@ -255,25 +192,10 @@ export async function loadThreadsIndex(storageRoot: string): Promise<ThreadsInde
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Accept legacy CasRef values for test convenience. */
|
export async function saveThreadsIndex(storageRoot: string, index: ThreadsIndex): Promise<void> {
|
||||||
export type ThreadsIndexInput = Record<ThreadId, ThreadIndexEntry | CasRef>;
|
|
||||||
|
|
||||||
function normalizeThreadsIndexInput(index: ThreadsIndexInput): ThreadsIndex {
|
|
||||||
const normalized: ThreadsIndex = {};
|
|
||||||
for (const [threadId, value] of Object.entries(index)) {
|
|
||||||
normalized[threadId as ThreadId] =
|
|
||||||
typeof value === "string" ? createThreadIndexEntry(value as CasRef) : value;
|
|
||||||
}
|
|
||||||
return normalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function saveThreadsIndex(
|
|
||||||
storageRoot: string,
|
|
||||||
index: ThreadsIndexInput,
|
|
||||||
): Promise<void> {
|
|
||||||
const path = getThreadsPath(storageRoot);
|
const path = getThreadsPath(storageRoot);
|
||||||
await mkdir(storageRoot, { recursive: true });
|
await mkdir(storageRoot, { recursive: true });
|
||||||
const text = stringify(serializeThreadsIndex(normalizeThreadsIndexInput(index)), { indent: 2 });
|
const text = stringify(index, { indent: 2 });
|
||||||
await writeFile(path, text, "utf8");
|
await writeFile(path, text, "utf8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import type { WorkflowPayload } from "@uncaged/workflow-protocol";
|
|||||||
|
|
||||||
type SchemaObj = Record<string, unknown>;
|
type SchemaObj = Record<string, unknown>;
|
||||||
|
|
||||||
const RESERVED_NAMES = new Set(["$START", "$END", "$SUSPEND"]);
|
const RESERVED_NAMES = new Set(["$START", "$END"]);
|
||||||
const PSEUDO_TARGETS = new Set(["$END", "$SUSPEND"]);
|
|
||||||
|
|
||||||
/** Extract mustache variable names from a prompt string. */
|
/** Extract mustache variable names from a prompt string. */
|
||||||
function extractMustacheVars(prompt: string): string[] {
|
function extractMustacheVars(prompt: string): string[] {
|
||||||
@@ -111,13 +110,9 @@ function checkGraphStructure(payload: WorkflowPayload, errors: string[]): void {
|
|||||||
errors.push("$END must not have outgoing edges");
|
errors.push("$END must not have outgoing edges");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (graphNodes.has("$SUSPEND")) {
|
|
||||||
errors.push("$SUSPEND must not have outgoing edges");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [node, statusMap] of Object.entries(payload.graph)) {
|
for (const [node, statusMap] of Object.entries(payload.graph)) {
|
||||||
for (const [status, target] of Object.entries(statusMap)) {
|
for (const [status, target] of Object.entries(statusMap)) {
|
||||||
if (!PSEUDO_TARGETS.has(target.role) && !roleNames.has(target.role)) {
|
if (target.role !== "$END" && !roleNames.has(target.role)) {
|
||||||
errors.push(`edge ${node}→${status}: unknown target role "${target.role}"`);
|
errors.push(`edge ${node}→${status}: unknown target role "${target.role}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +129,7 @@ function collectReachableRoles(graph: WorkflowPayload["graph"]): Set<string> {
|
|||||||
|
|
||||||
const queue: string[] = [];
|
const queue: string[] = [];
|
||||||
for (const target of Object.values(startEdges)) {
|
for (const target of Object.values(startEdges)) {
|
||||||
if (!PSEUDO_TARGETS.has(target.role) && !reachable.has(target.role)) {
|
if (target.role !== "$END" && !reachable.has(target.role)) {
|
||||||
reachable.add(target.role);
|
reachable.add(target.role);
|
||||||
queue.push(target.role);
|
queue.push(target.role);
|
||||||
}
|
}
|
||||||
@@ -145,7 +140,7 @@ function collectReachableRoles(graph: WorkflowPayload["graph"]): Set<string> {
|
|||||||
const edges = graph[current];
|
const edges = graph[current];
|
||||||
if (!edges) continue;
|
if (!edges) continue;
|
||||||
for (const target of Object.values(edges)) {
|
for (const target of Object.values(edges)) {
|
||||||
if (!PSEUDO_TARGETS.has(target.role) && !reachable.has(target.role)) {
|
if (target.role !== "$END" && !reachable.has(target.role)) {
|
||||||
reachable.add(target.role);
|
reachable.add(target.role);
|
||||||
queue.push(target.role);
|
queue.push(target.role);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { basename, dirname } from "node:path";
|
import { basename } from "node:path";
|
||||||
import type { CasRef, WorkflowPayload } from "@uncaged/workflow-protocol";
|
import type { CasRef, WorkflowPayload } from "@uncaged/workflow-protocol";
|
||||||
|
|
||||||
const CAS_REF_PATTERN = /^[0-9A-HJKMNP-TV-Z]{13}$/;
|
const CAS_REF_PATTERN = /^[0-9A-HJKMNP-TV-Z]{13}$/;
|
||||||
@@ -36,13 +36,8 @@ function isTarget(value: unknown): boolean {
|
|||||||
if (!isRecord(value)) {
|
if (!isRecord(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const hasValidLocation =
|
|
||||||
value.location === undefined || value.location === null || typeof value.location === "string";
|
|
||||||
return (
|
return (
|
||||||
typeof value.role === "string" &&
|
typeof value.role === "string" && typeof value.prompt === "string" && value.prompt.trim() !== ""
|
||||||
typeof value.prompt === "string" &&
|
|
||||||
value.prompt.trim() !== "" &&
|
|
||||||
hasValidLocation
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,15 +63,9 @@ function isGraph(value: unknown): boolean {
|
|||||||
*/
|
*/
|
||||||
export function workflowNameFromPath(filePath: string): string {
|
export function workflowNameFromPath(filePath: string): string {
|
||||||
const base = basename(filePath);
|
const base = basename(filePath);
|
||||||
const stem = base.endsWith(".yaml")
|
if (base.endsWith(".yaml")) return base.slice(0, -5);
|
||||||
? base.slice(0, -5)
|
if (base.endsWith(".yml")) return base.slice(0, -4);
|
||||||
: base.endsWith(".yml")
|
return base;
|
||||||
? base.slice(0, -4)
|
|
||||||
: base;
|
|
||||||
if (stem === "index") {
|
|
||||||
return basename(dirname(filePath));
|
|
||||||
}
|
|
||||||
return stem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,22 +95,5 @@ export function parseWorkflowPayload(raw: unknown): WorkflowPayload | null {
|
|||||||
if (!isStringRecord(raw.roles, isRoleDefinition) || !isGraph(raw.graph)) {
|
if (!isStringRecord(raw.roles, isRoleDefinition) || !isGraph(raw.graph)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return raw as WorkflowPayload;
|
||||||
// Normalize location field: undefined → null
|
|
||||||
const normalized = { ...raw } as WorkflowPayload;
|
|
||||||
for (const roleName of Object.keys(normalized.graph)) {
|
|
||||||
const statusMap = normalized.graph[roleName];
|
|
||||||
if (statusMap !== undefined) {
|
|
||||||
for (const status of Object.keys(statusMap)) {
|
|
||||||
const target = statusMap[status];
|
|
||||||
if (target !== undefined) {
|
|
||||||
if (target.location === undefined) {
|
|
||||||
target.location = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return normalized;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
include: ["src/__tests__/**/*.test.ts"],
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# @uncaged/workflow-agent-builtin
|
||||||
|
|
||||||
|
## 0.5.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-util@0.5.1
|
||||||
|
- @uncaged/workflow-util-agent@0.5.1
|
||||||
@@ -8,7 +8,7 @@ Layer 3 agent implementation. Runs an OpenAI-compatible chat completion loop wit
|
|||||||
|
|
||||||
Useful when you want a self-contained agent without an external CLI like Hermes or Claude Code.
|
Useful when you want a self-contained agent without an external CLI like Hermes or Claude Code.
|
||||||
|
|
||||||
**Dependencies:** `@ocas/core`, `@uncaged/workflow-util-agent`, `@uncaged/workflow-util`
|
**Dependencies:** `@uncaged/json-cas`, `@uncaged/workflow-util-agent`, `@uncaged/workflow-util`
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-agent-builtin",
|
"name": "@uncaged/workflow-agent-builtin",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"dist",
|
"dist",
|
||||||
@@ -18,12 +18,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublishOnly": "echo 'Use bun run release from repo root' && exit 1",
|
"test": "bun test",
|
||||||
"test": "bun test __tests__/",
|
"test:ci": "bun test"
|
||||||
"test:ci": "bun test __tests__/"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ocas/core": "^0.1.1",
|
"@uncaged/json-cas": "^0.5.3",
|
||||||
"@uncaged/workflow-util-agent": "workspace:^",
|
"@uncaged/workflow-util-agent": "workspace:^",
|
||||||
"@uncaged/workflow-util": "workspace:^"
|
"@uncaged/workflow-util": "workspace:^"
|
||||||
},
|
},
|
||||||
@@ -35,12 +34,12 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow.git",
|
"url": "https://github.com/shazhou-ww/uncaged-workflow.git",
|
||||||
"directory": "packages/workflow-agent-builtin"
|
"directory": "packages/workflow-agent-builtin"
|
||||||
},
|
},
|
||||||
"homepage": "https://git.shazhou.work/uncaged/workflow#readme",
|
"homepage": "https://github.com/shazhou-ww/uncaged-workflow#readme",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow/issues"
|
"url": "https://github.com/shazhou-ww/uncaged-workflow/issues"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Store } from "@ocas/core";
|
import type { Store } from "@uncaged/json-cas";
|
||||||
import { createLogger, generateUlid } from "@uncaged/workflow-util";
|
import { createLogger, generateUlid } from "@uncaged/workflow-util";
|
||||||
import {
|
import {
|
||||||
type AgentContext,
|
type AgentContext,
|
||||||
@@ -82,7 +82,7 @@ async function runBuiltinWithMessages(
|
|||||||
|
|
||||||
if (loopResult.turnCount === 0) {
|
if (loopResult.turnCount === 0) {
|
||||||
log("5RWTK9NB", "no turns produced, returning empty output");
|
log("5RWTK9NB", "no turns produced, returning empty output");
|
||||||
return { output: "", detailHash: "", sessionId: session.sessionId, assembledPrompt: "" };
|
return { output: "", detailHash: "", sessionId: session.sessionId };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read jsonl → persist turns to CAS → store detail
|
// Read jsonl → persist turns to CAS → store detail
|
||||||
@@ -94,12 +94,7 @@ async function runBuiltinWithMessages(
|
|||||||
session.startedAtMs,
|
session.startedAtMs,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return { output: stripPreamble(loopResult.finalText), detailHash, sessionId: session.sessionId };
|
||||||
output: stripPreamble(loopResult.finalText),
|
|
||||||
detailHash,
|
|
||||||
sessionId: session.sessionId,
|
|
||||||
assembledPrompt: "",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runBuiltin(ctx: AgentContext): Promise<AgentRunResult> {
|
async function runBuiltin(ctx: AgentContext): Promise<AgentRunResult> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { bootstrap, putSchema, type Store } from "@ocas/core";
|
import { bootstrap, putSchema, type Store } from "@uncaged/json-cas";
|
||||||
|
|
||||||
import { BUILTIN_DETAIL_SCHEMA, BUILTIN_TURN_SCHEMA } from "./schemas.js";
|
import { BUILTIN_DETAIL_SCHEMA, BUILTIN_TURN_SCHEMA } from "./schemas.js";
|
||||||
import { readSessionTurns } from "./session.js";
|
import { readSessionTurns } from "./session.js";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { JSONSchema } from "@ocas/core";
|
import type { JSONSchema } from "@uncaged/json-cas";
|
||||||
|
|
||||||
const BUILTIN_TOOL_CALL_SCHEMA: JSONSchema = {
|
const BUILTIN_TOOL_CALL_SCHEMA: JSONSchema = {
|
||||||
type: "object",
|
type: "object",
|
||||||
@@ -38,7 +38,7 @@ export const BUILTIN_DETAIL_SCHEMA: JSONSchema = {
|
|||||||
turnCount: { type: "integer" },
|
turnCount: { type: "integer" },
|
||||||
turns: {
|
turns: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: { type: "string", format: "ocas_ref" },
|
items: { type: "string", format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { JSONSchema } from "@ocas/core";
|
import type { JSONSchema } from "@uncaged/json-cas";
|
||||||
|
|
||||||
export type ToolContext = {
|
export type ToolContext = {
|
||||||
cwd: string;
|
cwd: string;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# @uncaged/workflow-agent-claude-code
|
||||||
|
|
||||||
|
## 0.5.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-util@0.5.1
|
||||||
|
- @uncaged/workflow-util-agent@0.5.1
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
Layer 3 agent implementation. Spawns the `claude` CLI with a composed system prompt (role definition, task, prior steps, edge prompt). Parses stream or JSON stdout, caches session IDs for multi-turn continuation, and stores raw output plus structured detail in CAS.
|
Layer 3 agent implementation. Spawns the `claude` CLI with a composed system prompt (role definition, task, prior steps, edge prompt). Parses stream or JSON stdout, caches session IDs for multi-turn continuation, and stores raw output plus structured detail in CAS.
|
||||||
|
|
||||||
**Dependencies:** `@ocas/core`, `@uncaged/workflow-util-agent`
|
**Dependencies:** `@uncaged/json-cas`, `@uncaged/workflow-util-agent`
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { createMemoryStore, walk } from "@ocas/core";
|
import { createMemoryStore, walk } from "@uncaged/json-cas";
|
||||||
import {
|
import {
|
||||||
parseClaudeCodeJsonOutput,
|
parseClaudeCodeJsonOutput,
|
||||||
parseClaudeCodeStreamOutput,
|
parseClaudeCodeStreamOutput,
|
||||||
@@ -301,179 +301,6 @@ describe("storeClaudeCodeDetail", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("parseClaudeCodeStreamOutput — incomplete output (no result line)", () => {
|
|
||||||
test("Test 1.1: parses stream with turns but no result line", () => {
|
|
||||||
const lines = [
|
|
||||||
JSON.stringify({
|
|
||||||
type: "system",
|
|
||||||
subtype: "init",
|
|
||||||
session_id: "sess-incomplete-1",
|
|
||||||
model: "claude-sonnet-4.5",
|
|
||||||
}),
|
|
||||||
JSON.stringify({
|
|
||||||
type: "assistant",
|
|
||||||
message: {
|
|
||||||
role: "assistant",
|
|
||||||
content: [{ type: "text", text: "Starting work..." }],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
JSON.stringify({
|
|
||||||
type: "assistant",
|
|
||||||
message: {
|
|
||||||
role: "assistant",
|
|
||||||
content: [{ type: "text", text: "This is the last assistant message." }],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
const stdout = lines.join("\n");
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(stdout);
|
|
||||||
|
|
||||||
expect(parsed).not.toBeNull();
|
|
||||||
expect(parsed!.subtype).toBe("incomplete");
|
|
||||||
expect(parsed!.result).toBe("This is the last assistant message.");
|
|
||||||
expect(parsed!.sessionId).toBe("sess-incomplete-1");
|
|
||||||
expect(parsed!.model).toBe("claude-sonnet-4.5");
|
|
||||||
expect(parsed!.turns).toHaveLength(2);
|
|
||||||
expect(parsed!.stopReason).toBe("incomplete_no_result_line");
|
|
||||||
expect(parsed!.numTurns).toBe(2);
|
|
||||||
expect(parsed!.durationMs).toBe(0);
|
|
||||||
expect(parsed!.totalCostUsd).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Test 1.2: parses stream with no turns and no result line", () => {
|
|
||||||
const lines = [
|
|
||||||
JSON.stringify({
|
|
||||||
type: "system",
|
|
||||||
session_id: "sess-no-turns",
|
|
||||||
model: "claude-opus-4",
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
const stdout = lines.join("\n");
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(stdout);
|
|
||||||
|
|
||||||
expect(parsed).not.toBeNull();
|
|
||||||
expect(parsed!.subtype).toBe("incomplete");
|
|
||||||
expect(parsed!.result).toBe("");
|
|
||||||
expect(parsed!.sessionId).toBe("sess-no-turns");
|
|
||||||
expect(parsed!.model).toBe("claude-opus-4");
|
|
||||||
expect(parsed!.turns).toHaveLength(0);
|
|
||||||
expect(parsed!.stopReason).toBe("incomplete_no_result_line");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Test 1.3: returns null for completely empty output", () => {
|
|
||||||
const parsed1 = parseClaudeCodeStreamOutput("");
|
|
||||||
expect(parsed1).toBeNull();
|
|
||||||
|
|
||||||
const parsed2 = parseClaudeCodeStreamOutput(" \n \n ");
|
|
||||||
expect(parsed2).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Test 1.4: returns null for malformed JSON lines only", () => {
|
|
||||||
const stdout = "not json\n{broken json\n[invalid";
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(stdout);
|
|
||||||
expect(parsed).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Test 6.1: extracts from last assistant text-only turn", () => {
|
|
||||||
const lines = [
|
|
||||||
JSON.stringify({ type: "system", session_id: "s1", model: "test" }),
|
|
||||||
JSON.stringify({
|
|
||||||
type: "assistant",
|
|
||||||
message: { role: "assistant", content: [{ type: "text", text: "First message" }] },
|
|
||||||
}),
|
|
||||||
JSON.stringify({
|
|
||||||
type: "assistant",
|
|
||||||
message: { role: "assistant", content: [{ type: "text", text: "Last message" }] },
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(lines.join("\n"));
|
|
||||||
expect(parsed).not.toBeNull();
|
|
||||||
expect(parsed!.result).toBe("Last message");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Test 6.2: extracts from last assistant turn with tool calls", () => {
|
|
||||||
const lines = [
|
|
||||||
JSON.stringify({ type: "system", session_id: "s1", model: "test" }),
|
|
||||||
JSON.stringify({
|
|
||||||
type: "assistant",
|
|
||||||
message: {
|
|
||||||
role: "assistant",
|
|
||||||
content: [
|
|
||||||
{ type: "text", text: "Text with tools" },
|
|
||||||
{ type: "tool_use", name: "Bash", input: { command: "ls" } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(lines.join("\n"));
|
|
||||||
expect(parsed).not.toBeNull();
|
|
||||||
expect(parsed!.result).toBe("Text with tools");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Test 6.3: returns empty string when no assistant turns", () => {
|
|
||||||
const lines = [JSON.stringify({ type: "system", session_id: "s1", model: "test" })];
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(lines.join("\n"));
|
|
||||||
expect(parsed).not.toBeNull();
|
|
||||||
expect(parsed!.result).toBe("");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Test 6.4: extracts from most recent assistant turn before tool_result", () => {
|
|
||||||
const lines = [
|
|
||||||
JSON.stringify({ type: "system", session_id: "s1", model: "test" }),
|
|
||||||
JSON.stringify({
|
|
||||||
type: "assistant",
|
|
||||||
message: { role: "assistant", content: [{ type: "text", text: "Before tool call" }] },
|
|
||||||
}),
|
|
||||||
JSON.stringify({
|
|
||||||
type: "user",
|
|
||||||
message: { role: "user", content: [{ type: "tool_result", content: "tool output" }] },
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(lines.join("\n"));
|
|
||||||
expect(parsed).not.toBeNull();
|
|
||||||
expect(parsed!.result).toBe("Before tool call");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("storeClaudeCodeDetail — incomplete results", () => {
|
|
||||||
test("Test 4.1: stores incomplete result as detail", async () => {
|
|
||||||
const store = createMemoryStore();
|
|
||||||
const incompleteParsed: ClaudeCodeParsedResult = {
|
|
||||||
type: "result",
|
|
||||||
subtype: "incomplete",
|
|
||||||
result: "Partial output",
|
|
||||||
sessionId: "sess-incomplete",
|
|
||||||
numTurns: 2,
|
|
||||||
totalCostUsd: 0,
|
|
||||||
durationMs: 0,
|
|
||||||
model: "claude-sonnet-4.5",
|
|
||||||
stopReason: "incomplete_no_result_line",
|
|
||||||
usage: {
|
|
||||||
inputTokens: 0,
|
|
||||||
outputTokens: 0,
|
|
||||||
cacheReadInputTokens: 0,
|
|
||||||
cacheCreationInputTokens: 0,
|
|
||||||
},
|
|
||||||
turns: [
|
|
||||||
{ index: 0, role: "assistant", content: "Turn 1", toolCalls: null },
|
|
||||||
{ index: 1, role: "assistant", content: "Partial output", toolCalls: null },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const { detailHash, output, sessionId } = await storeClaudeCodeDetail(store, incompleteParsed);
|
|
||||||
|
|
||||||
expect(detailHash).toHaveLength(13);
|
|
||||||
expect(output).toBe("Partial output");
|
|
||||||
expect(sessionId).toBe("sess-incomplete");
|
|
||||||
|
|
||||||
const node = await store.get(detailHash);
|
|
||||||
expect(node).not.toBeNull();
|
|
||||||
expect(node!.payload.subtype).toBe("incomplete");
|
|
||||||
expect(node!.payload.stopReason).toBe("incomplete_no_result_line");
|
|
||||||
expect(node!.payload.turns).toHaveLength(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("storeClaudeCodeRawOutput", () => {
|
describe("storeClaudeCodeRawOutput", () => {
|
||||||
test("stores raw text when JSON parsing fails", async () => {
|
test("stores raw text when JSON parsing fails", async () => {
|
||||||
const store = createMemoryStore();
|
const store = createMemoryStore();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-agent-claude-code",
|
"name": "@uncaged/workflow-agent-claude-code",
|
||||||
"version": "0.1.0",
|
"version": "0.5.1",
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"dist",
|
"dist",
|
||||||
@@ -18,12 +18,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublishOnly": "echo 'Use bun run release from repo root' && exit 1",
|
"test": "bun test",
|
||||||
"test": "bun test __tests__/",
|
"test:ci": "bun test"
|
||||||
"test:ci": "bun test __tests__/"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ocas/core": "^0.1.1",
|
"@uncaged/json-cas": "^0.5.3",
|
||||||
"@uncaged/workflow-util-agent": "workspace:^",
|
"@uncaged/workflow-util-agent": "workspace:^",
|
||||||
"@uncaged/workflow-util": "workspace:^"
|
"@uncaged/workflow-util": "workspace:^"
|
||||||
},
|
},
|
||||||
@@ -35,12 +34,12 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow.git",
|
"url": "https://github.com/shazhou-ww/uncaged-workflow.git",
|
||||||
"directory": "packages/workflow-agent-claude-code"
|
"directory": "packages/workflow-agent-claude-code"
|
||||||
},
|
},
|
||||||
"homepage": "https://git.shazhou.work/uncaged/workflow#readme",
|
"homepage": "https://github.com/shazhou-ww/uncaged-workflow#readme",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow/issues"
|
"url": "https://github.com/shazhou-ww/uncaged-workflow/issues"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { spawn } from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
import type { Store } from "@ocas/core";
|
import type { Store } from "@uncaged/json-cas";
|
||||||
import { createLogger } from "@uncaged/workflow-util";
|
import { createLogger } from "@uncaged/workflow-util";
|
||||||
import {
|
import {
|
||||||
type AgentContext,
|
type AgentContext,
|
||||||
@@ -48,9 +48,7 @@ export function buildClaudeCodePrompt(ctx: AgentContext): string {
|
|||||||
return parts.join("\n");
|
return parts.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawnClaude(
|
function spawnClaude(args: string[]): Promise<{ stdout: string; stderr: string }> {
|
||||||
args: string[],
|
|
||||||
): Promise<{ stdout: string; stderr: string; exitCode: number | null }> {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = spawn(CLAUDE_COMMAND, args, {
|
const child = spawn(CLAUDE_COMMAND, args, {
|
||||||
env: process.env,
|
env: process.env,
|
||||||
@@ -74,7 +72,7 @@ function spawnClaude(
|
|||||||
|
|
||||||
child.on("close", (code) => {
|
child.on("close", (code) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve({ stdout, stderr, exitCode: code });
|
resolve({ stdout, stderr });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const detail = stderr.trim() !== "" ? ` stderr=${stderr.trim()}` : "";
|
const detail = stderr.trim() !== "" ? ` stderr=${stderr.trim()}` : "";
|
||||||
@@ -83,9 +81,7 @@ function spawnClaude(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawnClaudeRun(
|
function spawnClaudeRun(prompt: string): Promise<{ stdout: string; stderr: string }> {
|
||||||
prompt: string,
|
|
||||||
): Promise<{ stdout: string; stderr: string; exitCode: number | null }> {
|
|
||||||
const args = [
|
const args = [
|
||||||
"-p",
|
"-p",
|
||||||
prompt,
|
prompt,
|
||||||
@@ -105,7 +101,7 @@ function spawnClaudeRun(
|
|||||||
function spawnClaudeResume(
|
function spawnClaudeResume(
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
message: string,
|
message: string,
|
||||||
): Promise<{ stdout: string; stderr: string; exitCode: number | null }> {
|
): Promise<{ stdout: string; stderr: string }> {
|
||||||
const args = [
|
const args = [
|
||||||
"-p",
|
"-p",
|
||||||
message,
|
message,
|
||||||
@@ -124,36 +120,16 @@ function spawnClaudeResume(
|
|||||||
return spawnClaude(args);
|
return spawnClaude(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processClaudeOutput(
|
async function processClaudeOutput(stdout: string, store: Store): Promise<AgentRunResult> {
|
||||||
stdout: string,
|
|
||||||
stderr: string,
|
|
||||||
exitCode: number | null,
|
|
||||||
store: Store,
|
|
||||||
assembledPrompt: string,
|
|
||||||
): Promise<AgentRunResult> {
|
|
||||||
const parsed = parseClaudeCodeStreamOutput(stdout);
|
const parsed = parseClaudeCodeStreamOutput(stdout);
|
||||||
|
|
||||||
if (parsed !== null) {
|
if (parsed !== null) {
|
||||||
const { detailHash, output, sessionId } = await storeClaudeCodeDetail(store, parsed);
|
const { detailHash, output, sessionId } = await storeClaudeCodeDetail(store, parsed);
|
||||||
|
return { output, detailHash, sessionId };
|
||||||
// Log incomplete results for visibility
|
|
||||||
if (parsed.subtype === "incomplete") {
|
|
||||||
log(
|
|
||||||
"7NQW8R4P",
|
|
||||||
`Claude Code exited with incomplete output (no result line). Exit code: ${exitCode ?? "null"}, stderr: ${stderr.slice(0, 200)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { output, detailHash, sessionId, assembledPrompt };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Truly unparseable output - provide enhanced error message
|
|
||||||
const exitInfo = exitCode !== null && exitCode !== 0 ? `Exit code: ${exitCode}\n` : "";
|
|
||||||
const stderrInfo = stderr.trim() !== "" ? `Stderr: ${stderr.slice(0, 200)}\n` : "";
|
|
||||||
const stdoutSnippet = stdout.slice(0, 200);
|
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Claude Code exited without producing parseable output.\n${exitInfo}${stderrInfo}Stdout (first 200 chars): ${stdoutSnippet}`,
|
`Claude Code returned unparseable output (first 200 chars): ${stdout.slice(0, 200)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +143,8 @@ async function runClaudeCode(ctx: AgentContext): Promise<AgentRunResult> {
|
|||||||
const cachedSessionId = await getCachedSessionId("claude-code", ctx.threadId, ctx.role);
|
const cachedSessionId = await getCachedSessionId("claude-code", ctx.threadId, ctx.role);
|
||||||
if (cachedSessionId !== null) {
|
if (cachedSessionId !== null) {
|
||||||
try {
|
try {
|
||||||
const { stdout, stderr, exitCode } = await spawnClaudeResume(cachedSessionId, fullPrompt);
|
const { stdout } = await spawnClaudeResume(cachedSessionId, fullPrompt);
|
||||||
const result = await processClaudeOutput(stdout, stderr, exitCode, ctx.store, fullPrompt);
|
const result = await processClaudeOutput(stdout, ctx.store);
|
||||||
if (result.sessionId !== undefined && result.sessionId !== "") {
|
if (result.sessionId !== undefined && result.sessionId !== "") {
|
||||||
await setCachedSessionId("claude-code", ctx.threadId, ctx.role, result.sessionId);
|
await setCachedSessionId("claude-code", ctx.threadId, ctx.role, result.sessionId);
|
||||||
}
|
}
|
||||||
@@ -176,14 +152,16 @@ async function runClaudeCode(ctx: AgentContext): Promise<AgentRunResult> {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
log(
|
log(
|
||||||
"5VKR8N3Q",
|
"5VKR8N3Q",
|
||||||
`resume failed for session ${cachedSessionId}, falling back to fresh run: ${err}`,
|
"resume failed for session %s, falling back to fresh run: %s",
|
||||||
|
cachedSessionId,
|
||||||
|
err,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { stdout, stderr, exitCode } = await spawnClaudeRun(fullPrompt);
|
const { stdout } = await spawnClaudeRun(fullPrompt);
|
||||||
const result = await processClaudeOutput(stdout, stderr, exitCode, ctx.store, fullPrompt);
|
const result = await processClaudeOutput(stdout, ctx.store);
|
||||||
if (result.sessionId !== undefined && result.sessionId !== "") {
|
if (result.sessionId !== undefined && result.sessionId !== "") {
|
||||||
await setCachedSessionId("claude-code", ctx.threadId, ctx.role, result.sessionId);
|
await setCachedSessionId("claude-code", ctx.threadId, ctx.role, result.sessionId);
|
||||||
}
|
}
|
||||||
@@ -195,8 +173,8 @@ async function continueClaudeCode(
|
|||||||
message: string,
|
message: string,
|
||||||
store: Store,
|
store: Store,
|
||||||
): Promise<AgentRunResult> {
|
): Promise<AgentRunResult> {
|
||||||
const { stdout, stderr, exitCode } = await spawnClaudeResume(sessionId, message);
|
const { stdout } = await spawnClaudeResume(sessionId, message);
|
||||||
return processClaudeOutput(stdout, stderr, exitCode, store, "");
|
return processClaudeOutput(stdout, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Agent CLI factory: parses argv, runs Claude Code, extracts output, writes StepNode. */
|
/** Agent CLI factory: parses argv, runs Claude Code, extracts output, writes StepNode. */
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { JSONSchema } from "@ocas/core";
|
import type { JSONSchema } from "@uncaged/json-cas";
|
||||||
|
|
||||||
export const CLAUDE_CODE_DETAIL_SCHEMA: JSONSchema = {
|
export const CLAUDE_CODE_DETAIL_SCHEMA: JSONSchema = {
|
||||||
title: "claude-code-detail",
|
title: "claude-code-detail",
|
||||||
@@ -34,7 +34,7 @@ export const CLAUDE_CODE_DETAIL_SCHEMA: JSONSchema = {
|
|||||||
},
|
},
|
||||||
turns: {
|
turns: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: { type: "string", format: "ocas_ref" },
|
items: { type: "string", format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { bootstrap, putSchema, type Store } from "@ocas/core";
|
import { bootstrap, putSchema, type Store } from "@uncaged/json-cas";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CLAUDE_CODE_DETAIL_SCHEMA,
|
CLAUDE_CODE_DETAIL_SCHEMA,
|
||||||
@@ -71,7 +71,6 @@ type ParseState = {
|
|||||||
turns: ClaudeCodeTurnPayload[];
|
turns: ClaudeCodeTurnPayload[];
|
||||||
resultLine: Record<string, unknown> | null;
|
resultLine: Record<string, unknown> | null;
|
||||||
model: string;
|
model: string;
|
||||||
sessionId: string;
|
|
||||||
turnIndex: number;
|
turnIndex: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -79,9 +78,6 @@ function processSystemLine(parsed: Record<string, unknown>, state: ParseState):
|
|||||||
if (typeof parsed.model === "string") {
|
if (typeof parsed.model === "string") {
|
||||||
state.model = parsed.model;
|
state.model = parsed.model;
|
||||||
}
|
}
|
||||||
if (typeof parsed.session_id === "string") {
|
|
||||||
state.sessionId = parsed.session_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function processAssistantLine(parsed: Record<string, unknown>, state: ParseState): void {
|
function processAssistantLine(parsed: Record<string, unknown>, state: ParseState): void {
|
||||||
@@ -128,52 +124,8 @@ function processLine(line: string, state: ParseState): void {
|
|||||||
else if (type === "result") state.resultLine = parsed;
|
else if (type === "result") state.resultLine = parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract output text from the last assistant turn.
|
|
||||||
* Used for best-effort extraction when no result line is present.
|
|
||||||
*/
|
|
||||||
function extractLastAssistantContent(turns: ClaudeCodeTurnPayload[]): string {
|
|
||||||
for (let i = turns.length - 1; i >= 0; i--) {
|
|
||||||
const turn = turns[i];
|
|
||||||
if (turn !== undefined && turn.role === "assistant" && turn.content !== "") {
|
|
||||||
return turn.content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function assembleResult(state: ParseState): ClaudeCodeParsedResult | null {
|
function assembleResult(state: ParseState): ClaudeCodeParsedResult | null {
|
||||||
// Handle incomplete result (no result line)
|
if (state.resultLine === null) return null;
|
||||||
if (state.resultLine === null) {
|
|
||||||
// Need at least a session_id from system line to be parseable
|
|
||||||
if (state.sessionId === "") {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Best-effort extraction: get output from last assistant turn
|
|
||||||
const result = extractLastAssistantContent(state.turns);
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "result",
|
|
||||||
subtype: "incomplete",
|
|
||||||
result,
|
|
||||||
sessionId: state.sessionId,
|
|
||||||
numTurns: state.turns.length,
|
|
||||||
totalCostUsd: 0,
|
|
||||||
durationMs: 0,
|
|
||||||
model: state.model,
|
|
||||||
stopReason: "incomplete_no_result_line",
|
|
||||||
usage: {
|
|
||||||
inputTokens: 0,
|
|
||||||
outputTokens: 0,
|
|
||||||
cacheReadInputTokens: 0,
|
|
||||||
cacheCreationInputTokens: 0,
|
|
||||||
},
|
|
||||||
turns: state.turns,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle complete result (has result line)
|
|
||||||
const sessionId = state.resultLine.session_id;
|
const sessionId = state.resultLine.session_id;
|
||||||
const result = state.resultLine.result;
|
const result = state.resultLine.result;
|
||||||
const subtype = state.resultLine.subtype;
|
const subtype = state.resultLine.subtype;
|
||||||
@@ -207,13 +159,7 @@ function assembleResult(state: ParseState): ClaudeCodeParsedResult | null {
|
|||||||
*/
|
*/
|
||||||
export function parseClaudeCodeStreamOutput(stdout: string): ClaudeCodeParsedResult | null {
|
export function parseClaudeCodeStreamOutput(stdout: string): ClaudeCodeParsedResult | null {
|
||||||
const lines = stdout.trim().split("\n");
|
const lines = stdout.trim().split("\n");
|
||||||
const state: ParseState = {
|
const state: ParseState = { turns: [], resultLine: null, model: "", turnIndex: 0 };
|
||||||
turns: [],
|
|
||||||
resultLine: null,
|
|
||||||
model: "",
|
|
||||||
sessionId: "",
|
|
||||||
turnIndex: 0,
|
|
||||||
};
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
processLine(line, state);
|
processLine(line, state);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export type ClaudeCodeResultSubtype = "success" | "error_max_turns" | "error_budget" | "incomplete";
|
export type ClaudeCodeResultSubtype = "success" | "error_max_turns" | "error_budget";
|
||||||
|
|
||||||
/** A single tool call within an assistant turn. */
|
/** A single tool call within an assistant turn. */
|
||||||
export type ClaudeCodeToolCall = {
|
export type ClaudeCodeToolCall = {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# @uncaged/workflow-agent-hermes
|
||||||
|
|
||||||
|
## 0.5.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-util@0.5.1
|
||||||
|
- @uncaged/workflow-protocol@0.5.1
|
||||||
|
- @uncaged/workflow-util-agent@0.5.1
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
# @uncaged/workflow-agent-hermes
|
# @uncaged/workflow-agent-hermes
|
||||||
|
|
||||||
`uwf-hermes` — an **agent adapter** that bridges the `uwf` workflow engine and the Hermes CLI.
|
`uwf-hermes` agent — spawns Hermes chat via ACP and captures session detail.
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
`uwf-hermes` is an adapter (not the Hermes CLI itself). The `uwf` engine speaks a generic agent protocol (stdin/stdout frontmatter contract); `uwf-hermes` translates that protocol into Hermes ACP (Agent Client Protocol) calls. Other adapters (e.g. `uwf-claude-code`, `uwf-cursor`) do the same for their respective CLIs.
|
Layer 3 agent implementation. Wraps the Hermes CLI using the Agent Client Protocol (ACP). On first visit to a role it sends a composed prompt (role definition, task, history, edge prompt); on continuation it resumes the cached session. Session transcripts and raw output are stored as CAS detail nodes.
|
||||||
|
|
||||||
On first visit to a role it sends a composed prompt (role definition, task, history, edge prompt); on continuation it resumes the cached session. Session transcripts and raw output are stored as CAS detail nodes.
|
**Dependencies:** `@uncaged/json-cas`, `@uncaged/workflow-util-agent`, `@uncaged/workflow-protocol`, `@uncaged/workflow-util`
|
||||||
|
|
||||||
**Dependencies:** `@ocas/core`, `@uncaged/workflow-util-agent`, `@uncaged/workflow-protocol`, `@uncaged/workflow-util`
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
|
||||||
import { readFileSync } from "node:fs";
|
|
||||||
import { join } from "node:path";
|
|
||||||
|
|
||||||
const PKG_ROOT = join(import.meta.dir, "..");
|
|
||||||
|
|
||||||
describe("Issue #551 — bin entry & engines", () => {
|
|
||||||
test("package.json declares bun in engines", () => {
|
|
||||||
const pkg = JSON.parse(readFileSync(join(PKG_ROOT, "package.json"), "utf-8"));
|
|
||||||
expect(pkg.engines).toBeDefined();
|
|
||||||
expect(pkg.engines.bun).toBeDefined();
|
|
||||||
expect(pkg.engines.bun).toMatch(/^>=?\s*[\d.]+/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("bin entry file has bun shebang", () => {
|
|
||||||
const pkg = JSON.parse(readFileSync(join(PKG_ROOT, "package.json"), "utf-8"));
|
|
||||||
const binPath = pkg.bin["uwf-hermes"];
|
|
||||||
const content = readFileSync(join(PKG_ROOT, binPath), "utf-8");
|
|
||||||
expect(content.startsWith("#!/usr/bin/env bun")).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("README.md explains uwf-hermes is an adapter", () => {
|
|
||||||
const readme = readFileSync(join(PKG_ROOT, "README.md"), "utf-8");
|
|
||||||
expect(readme.toLowerCase()).toContain("adapter");
|
|
||||||
expect(readme).toMatch(/uwf-hermes/);
|
|
||||||
expect(readme).toMatch(/hermes/);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -3,7 +3,7 @@ import { describe, expect, test } from "bun:test";
|
|||||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { createMemoryStore, refs, validate, walk } from "@ocas/core";
|
import { createMemoryStore, refs, validate, walk } from "@uncaged/json-cas";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
computeDurationMs,
|
computeDurationMs,
|
||||||
@@ -82,7 +82,7 @@ describe("computeDurationMs", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("storeHermesSessionDetail", () => {
|
describe("storeHermesSessionDetail", () => {
|
||||||
test("stores hermes-detail root with ocas_ref turns walkable", async () => {
|
test("stores hermes-detail root with cas_ref turns walkable", async () => {
|
||||||
const session: HermesSessionJson = {
|
const session: HermesSessionJson = {
|
||||||
session_id: "20260518_133159_6a84e8",
|
session_id: "20260518_133159_6a84e8",
|
||||||
model: "claude-opus-4.6",
|
model: "claude-opus-4.6",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-agent-hermes",
|
"name": "@uncaged/workflow-agent-hermes",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"dist",
|
"dist",
|
||||||
@@ -18,12 +18,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublishOnly": "echo 'Use bun run release from repo root' && exit 1",
|
"test": "bun test",
|
||||||
"test": "bun test __tests__/",
|
"test:ci": "bun test __tests__/*.test.ts"
|
||||||
"test:ci": "bun test __tests__/"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ocas/core": "^0.1.1",
|
"@uncaged/json-cas": "^0.5.3",
|
||||||
"@uncaged/workflow-util-agent": "workspace:^",
|
"@uncaged/workflow-util-agent": "workspace:^",
|
||||||
"@uncaged/workflow-protocol": "workspace:^",
|
"@uncaged/workflow-protocol": "workspace:^",
|
||||||
"@uncaged/workflow-util": "workspace:^"
|
"@uncaged/workflow-util": "workspace:^"
|
||||||
@@ -36,15 +35,12 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow.git",
|
"url": "https://github.com/shazhou-ww/uncaged-workflow.git",
|
||||||
"directory": "packages/workflow-agent-hermes"
|
"directory": "packages/workflow-agent-hermes"
|
||||||
},
|
},
|
||||||
"homepage": "https://git.shazhou.work/uncaged/workflow#readme",
|
"homepage": "https://github.com/shazhou-ww/uncaged-workflow#readme",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://git.shazhou.work/uncaged/workflow/issues"
|
"url": "https://github.com/shazhou-ww/uncaged-workflow/issues"
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"bun": ">= 1.0.0"
|
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Store } from "@ocas/core";
|
import type { Store } from "@uncaged/json-cas";
|
||||||
import { createLogger } from "@uncaged/workflow-util";
|
import { createLogger } from "@uncaged/workflow-util";
|
||||||
import {
|
import {
|
||||||
type AgentContext,
|
type AgentContext,
|
||||||
@@ -117,7 +117,7 @@ export function createHermesAgent(): () => Promise<void> {
|
|||||||
await setCachedSessionId(ctx.threadId, ctx.role, sessionId);
|
await setCachedSessionId(ctx.threadId, ctx.role, sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { output: text, detailHash, sessionId, assembledPrompt: fullPrompt };
|
return { output: text, detailHash, sessionId };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runHermes(ctx: AgentContext): Promise<AgentRunResult> {
|
async function runHermes(ctx: AgentContext): Promise<AgentRunResult> {
|
||||||
@@ -148,7 +148,7 @@ export function createHermesAgent(): () => Promise<void> {
|
|||||||
// so the agent sees the full conversation history (crucial for retries).
|
// so the agent sees the full conversation history (crucial for retries).
|
||||||
const { text, sessionId } = await client.prompt(message);
|
const { text, sessionId } = await client.prompt(message);
|
||||||
const { detailHash } = await storePromptResult(store, sessionId);
|
const { detailHash } = await storePromptResult(store, sessionId);
|
||||||
return { output: text, detailHash, sessionId, assembledPrompt: "" };
|
return { output: text, detailHash, sessionId };
|
||||||
}
|
}
|
||||||
|
|
||||||
const agentMain = createAgent({
|
const agentMain = createAgent({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { JSONSchema } from "@ocas/core";
|
import type { JSONSchema } from "@uncaged/json-cas";
|
||||||
|
|
||||||
const HERMES_TOOL_CALL_SCHEMA: JSONSchema = {
|
const HERMES_TOOL_CALL_SCHEMA: JSONSchema = {
|
||||||
type: "object",
|
type: "object",
|
||||||
@@ -39,7 +39,7 @@ export const HERMES_DETAIL_SCHEMA: JSONSchema = {
|
|||||||
turnCount: { type: "integer" },
|
turnCount: { type: "integer" },
|
||||||
turns: {
|
turns: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: { type: "string", format: "ocas_ref" },
|
items: { type: "string", format: "cas_ref" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { readFile } from "node:fs/promises";
|
|||||||
import { homedir } from "node:os";
|
import { homedir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
|
||||||
import { bootstrap, putSchema, type Store } from "@ocas/core";
|
import { bootstrap, putSchema, type Store } from "@uncaged/json-cas";
|
||||||
|
|
||||||
import { HERMES_DETAIL_SCHEMA, HERMES_RAW_OUTPUT_SCHEMA, HERMES_TURN_SCHEMA } from "./schemas.js";
|
import { HERMES_DETAIL_SCHEMA, HERMES_RAW_OUTPUT_SCHEMA, HERMES_TURN_SCHEMA } from "./schemas.js";
|
||||||
import type {
|
import type {
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun server.ts",
|
"dev": "bun server.ts",
|
||||||
"build": "vite build",
|
"build": "vite build"
|
||||||
"test": "bun test src/",
|
|
||||||
"test:ci": "bun test src/"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@base-ui/react": "^1.5.0",
|
"@base-ui/react": "^1.5.0",
|
||||||
@@ -33,8 +31,10 @@
|
|||||||
"@types/react": "^19.2.14",
|
"@types/react": "^19.2.14",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@vitejs/plugin-react": "^6.0.2",
|
"@vitejs/plugin-react": "^6.0.2",
|
||||||
|
"@vitest/ui": "^4.1.7",
|
||||||
"tailwindcss": "^4.2.4",
|
"tailwindcss": "^4.2.4",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
"vite": "^8.0.13"
|
"vite": "^8.0.13",
|
||||||
|
"vitest": "^4.1.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
|
||||||
import type { Edge, Node } from "@xyflow/react";
|
import type { Edge, Node } from "@xyflow/react";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
import { LayoutLR } from "../index.js";
|
import { LayoutLR } from "../index.js";
|
||||||
|
|
||||||
function makeNode(id: string): Node {
|
function makeNode(id: string): Node {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const editNodeViewModel = define.view("editNodeView", editNodeView, (set,
|
|||||||
function start(nodeId: string) {
|
function start(nodeId: string) {
|
||||||
const [nodes] = model.use(nodesModel);
|
const [nodes] = model.use(nodesModel);
|
||||||
const node = nodes.find((n) => n.id === nodeId);
|
const node = nodes.find((n) => n.id === nodeId);
|
||||||
if (node?.type !== "role") return;
|
if (!node || node.type !== "role") return;
|
||||||
set({ node: node as WorkNode<"role"> });
|
set({ node: node as WorkNode<"role"> });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
import { describe, expect, it } from "vitest";
|
||||||
import { transIn } from "../trans-in.js";
|
import { transIn } from "../trans-in.js";
|
||||||
import type { WorkFlowStep } from "../type.js";
|
import type { WorkFlowStep } from "../type.js";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
import { describe, expect, it } from "vitest";
|
||||||
import type { AnyWorkEdge, AnyWorkNode } from "../../type.js";
|
import type { AnyWorkEdge, AnyWorkNode } from "../../type.js";
|
||||||
import { validate } from "../validate.js";
|
import { validate } from "../validate.js";
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function traverse(
|
|||||||
visited.add(nodeId);
|
visited.add(nodeId);
|
||||||
|
|
||||||
const node = nodeMap.get(nodeId);
|
const node = nodeMap.get(nodeId);
|
||||||
if (node?.type !== "role") return;
|
if (!node || node.type !== "role") return;
|
||||||
|
|
||||||
const roleNode = node as WorkNode<"role">;
|
const roleNode = node as WorkNode<"role">;
|
||||||
const outEdges = outgoingEdges.get(nodeId) ?? [];
|
const outEdges = outgoingEdges.get(nodeId) ?? [];
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import path from "node:path";
|
||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
environment: "node",
|
||||||
|
include: ["src/**/__tests__/**/*.test.ts"],
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@": path.resolve(import.meta.dirname, "./src"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user