Compare commits
263 Commits
d3786253ef
...
v0.3.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7451cb7170 | ||
|
|
83ccfece81 | ||
|
|
68bf179407 | ||
|
|
c35c05d02c | ||
|
|
3adae6c475 | ||
|
|
c4753b51de | ||
|
|
e7a73e7322 | ||
|
|
e8ec84668f | ||
|
|
8d9cf4b283 | ||
|
|
a8cb38fe27 | ||
|
|
dd83e0f4ee | ||
|
|
3923aafb71 | ||
|
|
8fcfadcb04 | ||
|
|
7c023c6beb | ||
|
|
e7bb8db7c1 | ||
|
|
727da0c6d0 | ||
|
|
257ee05ac6 | ||
|
|
b9f3505738 | ||
|
|
be56792c6e | ||
|
|
9daaae2d43 | ||
|
|
c85d02a3ef | ||
|
|
df6f792214 | ||
|
|
967ebd7a84 | ||
|
|
3bc44289b9 | ||
|
|
17f6bae573 | ||
|
|
baa8bdcfda | ||
|
|
33492c49fa | ||
|
|
63a90195e7 | ||
|
|
7bd390c762 | ||
|
|
0d581ab459 | ||
|
|
42f88cc172 | ||
|
|
945648bf6e | ||
|
|
bc5a3da2c0 | ||
|
|
04e841643e | ||
|
|
3d97b0b95a | ||
|
|
8f4cb9475c | ||
|
|
8f63cfda07 | ||
|
|
1b3843d913 | ||
|
|
4c898996a2 | ||
|
|
281531624d | ||
|
|
b09a2cbdf9 | ||
|
|
a0c1457757 | ||
|
|
e818ac986d | ||
|
|
b29f6628f8 | ||
|
|
4dc4fef83b | ||
|
|
7ef85c459c | ||
|
|
f6058a50b9 | ||
|
|
d347ba084d | ||
|
|
b50d007b40 | ||
|
|
ed3d7311d1 | ||
|
|
e7aef3edc7 | ||
|
|
d5a93fe726 | ||
|
|
7e45a1fba0 | ||
|
|
ad348e813f | ||
|
|
de5dcceeaf | ||
|
|
53fdcfec75 | ||
|
|
bad680cf24 | ||
|
|
a5e64ded83 | ||
|
|
77e368d354 | ||
|
|
db92a78d2b | ||
|
|
420deebdb4 | ||
|
|
0a6de3717a | ||
|
|
15645a2a3e | ||
|
|
eab65de723 | ||
|
|
81a5660f11 | ||
|
|
4bf01c6cca | ||
|
|
a799009720 | ||
|
|
549c23bd77 | ||
|
|
34be4d1e75 | ||
|
|
a390861520 | ||
|
|
ce9bdbbb9d | ||
|
|
5f4591f496 | ||
|
|
dc7968ffbc | ||
|
|
5fedd9130a | ||
|
|
c7e371c124 | ||
|
|
8748d7d49a | ||
|
|
825d36c204 | ||
|
|
65a8feff17 | ||
|
|
60dabae795 | ||
|
|
1bae7bd223 | ||
|
|
a0091e81f9 | ||
|
|
beb5ea9f53 | ||
|
|
89e96dc0a6 | ||
|
|
0c686ba170 | ||
|
|
74dc42c1fc | ||
|
|
a3d22fd874 | ||
|
|
8561910cd8 | ||
|
|
e569c1bcad | ||
|
|
4dcb24d5dd | ||
|
|
59f37e13b9 | ||
|
|
3a1d7012b4 | ||
|
|
41b24e4b7a | ||
|
|
06948dae74 | ||
|
|
bbd4aee828 | ||
|
|
d40f007818 | ||
|
|
3819a02159 | ||
|
|
9b65845c90 | ||
|
|
28176727d7 | ||
|
|
1d59cdcc25 | ||
|
|
edc6b9ea05 | ||
|
|
8e4a8ce57a | ||
|
|
c863ee4135 | ||
|
|
dd4a1140fe | ||
|
|
895317330b | ||
|
|
11e32f9802 | ||
|
|
8b7ff6383f | ||
|
|
964a8bfcff | ||
|
|
978b84893c | ||
|
|
7dd6821dc5 | ||
|
|
6abf5c87b2 | ||
|
|
b682c67f97 | ||
|
|
81309a5559 | ||
|
|
2006ad6d8c | ||
|
|
41bafb80e4 | ||
|
|
569380e133 | ||
|
|
10a5bea2b1 | ||
|
|
110815c1c5 | ||
|
|
29fc761980 | ||
|
|
d537aceb63 | ||
|
|
72b89c8ccc | ||
|
|
e19de02967 | ||
|
|
1c5f13e7eb | ||
|
|
816c771a2a | ||
|
|
642a8486cd | ||
|
|
605bcadea7 | ||
|
|
ccc1ead8c9 | ||
|
|
8bbbe8fbdd | ||
|
|
d9775834ed | ||
|
|
c32f0dce45 | ||
|
|
d864941665 | ||
|
|
9c2d831c65 | ||
|
|
2ab91f933f | ||
|
|
1fcb8cb332 | ||
|
|
3439c16e66 | ||
|
|
ce93987da8 | ||
|
|
bd7b7cc34a | ||
|
|
855452b4a2 | ||
|
|
1fcfa9123f | ||
|
|
e66b811436 | ||
|
|
8d5fa85a3a | ||
|
|
a4e7a23ca6 | ||
|
|
b67eea7b9a | ||
|
|
4a89b46857 | ||
|
|
047bf83b76 | ||
|
|
62aa142409 | ||
|
|
c93a2e80f9 | ||
|
|
9176fe3303 | ||
|
|
296a59def3 | ||
|
|
90bb2fb137 | ||
|
|
bc0bb91a83 | ||
|
|
0b39b2acfc | ||
|
|
75c27f5853 | ||
|
|
349866606c | ||
|
|
901f7a65d3 | ||
|
|
c52b41b99c | ||
|
|
ec76005c63 | ||
|
|
1736f8d924 | ||
|
|
f8b5e11c27 | ||
|
|
12c500ee90 | ||
|
|
81c9cf797f | ||
|
|
d18c1105c7 | ||
|
|
ca8e6dc51c | ||
|
|
30ad59c6eb | ||
|
|
123f140244 | ||
|
|
8db23f77cd | ||
|
|
6bfa10b0e5 | ||
|
|
65036b2ce7 | ||
|
|
76d73b2d0b | ||
|
|
78618a1b76 | ||
|
|
47e07b23d1 | ||
|
|
45ae7b8f01 | ||
|
|
e1c30b5953 | ||
|
|
b0d9fb4f39 | ||
|
|
dcc11c2b0f | ||
|
|
7f21454880 | ||
|
|
a893a1cef7 | ||
|
|
3fb48cdf51 | ||
|
|
f1bb1216bf | ||
|
|
b3faf7b810 | ||
|
|
89e4ee1c9c | ||
|
|
4df39eb1f2 | ||
|
|
a7d23143ef | ||
|
|
f72666b39e | ||
|
|
1f8ffee38e | ||
|
|
798f841b9a | ||
|
|
25c3dbb3d1 | ||
|
|
71cbc21b01 | ||
|
|
6deeba81a8 | ||
|
|
b862a7a6d0 | ||
|
|
fe1f76957d | ||
|
|
266e676dd4 | ||
|
|
402159c19a | ||
|
|
6d1b36e515 | ||
|
|
81d4889cee | ||
|
|
0eb2cd8ec3 | ||
|
|
b251ed7421 | ||
|
|
4a600e9954 | ||
|
|
cfb810b061 | ||
|
|
71bd999586 | ||
|
|
10d0cdeeae | ||
|
|
6e375aaab5 | ||
|
|
e7edf9a8d5 | ||
|
|
20431f625b | ||
|
|
d35f0f19fb | ||
|
|
4303b33b90 | ||
|
|
f9c0d24d7a | ||
|
|
ec3277234c | ||
|
|
0a28aae041 | ||
|
|
a7a8358cbb | ||
|
|
6b6cb525a7 | ||
|
|
27465b1130 | ||
|
|
e74c370c7e | ||
|
|
8defd5c671 | ||
|
|
a5c4fb553a | ||
|
|
a7772d1421 | ||
|
|
ed967403fb | ||
|
|
998b188ac7 | ||
|
|
115c9fd6df | ||
|
|
86694a4383 | ||
|
|
7b324ea96e | ||
|
|
744a12eeea | ||
|
|
cffe63680d | ||
|
|
f5fffd64b8 | ||
|
|
ad68bc912f | ||
|
|
d02d53d112 | ||
|
|
3ce7276e89 | ||
|
|
6d87e64859 | ||
|
|
83db282892 | ||
|
|
f5d5196bf5 | ||
|
|
7ec869baa8 | ||
|
|
1a257b3057 | ||
|
|
b9fd87ed7c | ||
|
|
fda763d3f0 | ||
|
|
77d89b17e8 | ||
|
|
df0fa46591 | ||
|
|
1f5d70ce0d | ||
|
|
0d46c86469 | ||
|
|
a439f8fdcb | ||
|
|
1adddf4e4c | ||
|
|
23484716e2 | ||
|
|
92085f9071 | ||
|
|
ce899b569e | ||
|
|
da7216630b | ||
|
|
b57c270144 | ||
|
|
230b8fdc35 | ||
|
|
75b2446801 | ||
|
|
96779c9caf | ||
|
|
bf5d9ff6b1 | ||
|
|
c551faeea3 | ||
|
|
3f38f90a50 | ||
|
|
26a1328c89 | ||
|
|
21b45b8dd7 | ||
|
|
3a860bd2d5 | ||
|
|
c2c95c18b4 | ||
|
|
e3a301009b | ||
|
|
c90bdc8907 | ||
|
|
dba12a38c2 | ||
|
|
4b60452b27 | ||
|
|
d2f677ae0c | ||
|
|
427bb6929a | ||
|
|
78c04ee576 | ||
|
|
3309d26142 | ||
|
|
5a4a2aaa17 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
# Claude Code
|
||||
.claude/settings.local.json
|
||||
.mcp.json
|
||||
|
||||
# Local environment (secrets)
|
||||
.env
|
||||
@@ -25,6 +26,7 @@ frontend/node_modules
|
||||
frontend/dist
|
||||
frontend/dist-ssr
|
||||
frontend/test-results
|
||||
frontend/serve
|
||||
frontend/*.local
|
||||
server/target
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"story-kit": {
|
||||
"type": "http",
|
||||
"url": "http://localhost:3001/mcp"
|
||||
}
|
||||
}
|
||||
}
|
||||
6
.story_kit/.gitignore
vendored
6
.story_kit/.gitignore
vendored
@@ -4,10 +4,16 @@ bot.toml
|
||||
# Matrix SDK state store
|
||||
matrix_store/
|
||||
matrix_device_id
|
||||
matrix_history.json
|
||||
|
||||
# Agent worktrees and merge workspace (managed by the server, not tracked in git)
|
||||
worktrees/
|
||||
merge_workspace/
|
||||
|
||||
# Intermediate pipeline stages (transient, not committed per spike 92)
|
||||
work/2_current/
|
||||
work/3_qa/
|
||||
work/4_merge/
|
||||
|
||||
# Coverage reports (generated by cargo-llvm-cov, not tracked in git)
|
||||
coverage/
|
||||
|
||||
@@ -18,7 +18,7 @@ When you start a new session with this project:
|
||||
This returns the full tool catalog (create stories, spawn agents, record tests, manage worktrees, etc.). Familiarize yourself with the available tools before proceeding. These tools allow you to directly manipulate the workflow and spawn subsidiary agents without manual file manipulation.
|
||||
2. **Read Context:** Check `.story_kit/specs/00_CONTEXT.md` for high-level project goals.
|
||||
3. **Read Stack:** Check `.story_kit/specs/tech/STACK.md` for technical constraints and patterns.
|
||||
4. **Check Work Items:** Look at `.story_kit/work/1_upcoming/` and `.story_kit/work/2_current/` to see what work is pending.
|
||||
4. **Check Work Items:** Look at `.story_kit/work/1_backlog/` and `.story_kit/work/2_current/` to see what work is pending.
|
||||
|
||||
|
||||
---
|
||||
@@ -52,7 +52,7 @@ project_root/
|
||||
├── README.md # This document
|
||||
├── project.toml # Agent configuration (roles, models, prompts)
|
||||
├── work/ # Unified work item pipeline (stories, bugs, spikes)
|
||||
│ ├── 1_upcoming/ # New work items awaiting implementation
|
||||
│ ├── 1_backlog/ # New work items awaiting implementation
|
||||
│ ├── 2_current/ # Work in progress
|
||||
│ ├── 3_qa/ # QA review
|
||||
│ ├── 4_merge/ # Ready to merge to master
|
||||
@@ -78,7 +78,7 @@ All work items (stories, bugs, spikes) live in the same `work/` pipeline. Items
|
||||
|
||||
Items move through stages by moving the file between directories:
|
||||
|
||||
`1_upcoming` → `2_current` → `3_qa` → `4_merge` → `5_done` → `6_archived`
|
||||
`1_backlog` → `2_current` → `3_qa` → `4_merge` → `5_done` → `6_archived`
|
||||
|
||||
Items in `5_done` are auto-swept to `6_archived` after 4 hours by the server.
|
||||
|
||||
@@ -87,7 +87,7 @@ Items in `5_done` are auto-swept to `6_archived` after 4 hours by the server.
|
||||
The server watches `.story_kit/work/` for changes. When a file is created, moved, or modified, the watcher auto-commits with a deterministic message and broadcasts a WebSocket notification to the frontend. This means:
|
||||
|
||||
* MCP tools only need to write/move files — the watcher handles git commits
|
||||
* IDE drag-and-drop works (drag a story from `1_upcoming/` to `2_current/`)
|
||||
* IDE drag-and-drop works (drag a story from `1_backlog/` to `2_current/`)
|
||||
* The frontend updates automatically without manual refresh
|
||||
|
||||
---
|
||||
@@ -156,7 +156,7 @@ Not everything needs to be a full story. Simple bugs can skip the story process:
|
||||
* Performance issues with known fixes
|
||||
|
||||
### Bug Process
|
||||
1. **Document Bug:** Create a bug file in `work/1_upcoming/` named `{id}_bug_{slug}.md` with:
|
||||
1. **Document Bug:** Create a bug file in `work/1_backlog/` named `{id}_bug_{slug}.md` with:
|
||||
* **Symptom:** What the user observes
|
||||
* **Root Cause:** Technical explanation (if known)
|
||||
* **Reproduction Steps:** How to trigger the bug
|
||||
@@ -186,7 +186,7 @@ Not everything needs a story or bug fix. Spikes are time-boxed investigations to
|
||||
* Need to validate performance constraints
|
||||
|
||||
### Spike Process
|
||||
1. **Document Spike:** Create a spike file in `work/1_upcoming/` named `{id}_spike_{slug}.md` with:
|
||||
1. **Document Spike:** Create a spike file in `work/1_backlog/` named `{id}_spike_{slug}.md` with:
|
||||
* **Question:** What you need to answer
|
||||
* **Hypothesis:** What you expect to be true
|
||||
* **Timebox:** Strict limit for the research
|
||||
@@ -209,7 +209,7 @@ When the LLM context window fills up (or the chat gets slow/confused):
|
||||
1. **Stop Coding.**
|
||||
2. **Instruction:** Tell the user to open a new chat.
|
||||
3. **Handoff:** The only context the new LLM needs is in the `specs/` folder and `.mcp.json`.
|
||||
* *Prompt for New Session:* "I am working on Project X. Read `.mcp.json` to discover available tools, then read `specs/00_CONTEXT.md` and `specs/tech/STACK.md`. Then look at `work/1_upcoming/` and `work/2_current/` to see what is pending."
|
||||
* *Prompt for New Session:* "I am working on Project X. Read `.mcp.json` to discover available tools, then read `specs/00_CONTEXT.md` and `specs/tech/STACK.md`. Then look at `work/1_backlog/` and `work/2_current/` to see what is pending."
|
||||
|
||||
|
||||
---
|
||||
@@ -221,7 +221,7 @@ If a user hands you this document and says "Apply this process to my project":
|
||||
1. **Check for MCP Tools:** Look for `.mcp.json` in the project root. If it exists, you have programmatic access to workflow tools and agent spawning capabilities.
|
||||
2. **Analyze the Request:** Ask for the high-level goal ("What are we building?") and the tech preferences ("Rust or Python?").
|
||||
3. **Git Check:** Check if the directory is a git repository (`git status`). If not, run `git init`.
|
||||
4. **Scaffold:** Run commands to create the `work/` and `specs/` folders with the 6-stage pipeline (`work/1_upcoming/` through `work/6_archived/`).
|
||||
4. **Scaffold:** Run commands to create the `work/` and `specs/` folders with the 6-stage pipeline (`work/1_backlog/` through `work/6_archived/`).
|
||||
5. **Draft Context:** Write `specs/00_CONTEXT.md` based on the user's answer.
|
||||
6. **Draft Stack:** Write `specs/tech/STACK.md` based on best practices for that language.
|
||||
7. **Wait:** Ask the user for "Story #1".
|
||||
|
||||
@@ -13,3 +13,7 @@ enabled = false
|
||||
|
||||
# Maximum conversation turns to remember per room (default: 20).
|
||||
# history_size = 20
|
||||
|
||||
# Rooms where the bot responds to all messages (not just addressed ones).
|
||||
# This list is updated automatically when users toggle ambient mode at runtime.
|
||||
# ambient_rooms = ["!roomid:example.com"]
|
||||
|
||||
7
.story_kit/problems.md
Normal file
7
.story_kit/problems.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Problems
|
||||
|
||||
Recurring issues observed during pipeline operation. Review periodically and create stories for systemic problems.
|
||||
|
||||
## 2026-03-18: Agent committed directly to master instead of worktree
|
||||
|
||||
Commit `5f4591f` ("fix: update should_commit_stage test to match 5_done") was made directly on master by an agent (likely mergemaster). Agents should only commit to their feature branch or merge-queue branch, never to master directly. The commit content was correct but the target branch was wrong. Suspect the agent ran `git commit` in the project root instead of the merge worktree directory.
|
||||
@@ -34,7 +34,7 @@ You have these tools via the story-kit MCP server:
|
||||
## Your Workflow
|
||||
1. Read CLAUDE.md and .story_kit/README.md to understand the project and dev process
|
||||
2. Read the story file from .story_kit/work/ to understand requirements
|
||||
3. Move it to work/2_current/ if it is in work/1_upcoming/
|
||||
3. Move it to work/2_current/ if it is in work/1_backlog/
|
||||
4. Start coder-1 on the story: call start_agent with story_id="{{story_id}}" and agent_name="coder-1"
|
||||
5. Wait for completion: call wait_for_agent with story_id="{{story_id}}" and agent_name="coder-1". The server automatically runs acceptance gates (cargo clippy + tests) when the coder process exits. wait_for_agent returns when the coder reaches a terminal state.
|
||||
6. Check the result: inspect the "completion" field in the wait_for_agent response — if gates_passed is true, the work is done; if false, review the gate_output and decide whether to start a fresh coder.
|
||||
@@ -102,7 +102,7 @@ Read CLAUDE.md first, then .story_kit/README.md to understand the dev process.
|
||||
- URL to visit in the browser
|
||||
- Things to check in the UI
|
||||
- curl commands to exercise relevant API endpoints
|
||||
- Kill the test server when done: `pkill -f story-kit || true`
|
||||
- Kill the test server when done: `pkill -f 'target.*story-kit' || true` (NEVER use `pkill -f story-kit` — it kills the vite dev server)
|
||||
|
||||
### 4. Produce Structured Report
|
||||
Print your QA report to stdout before your process exits. The server will automatically run acceptance gates. Use this format:
|
||||
@@ -179,7 +179,7 @@ Read CLAUDE.md first, then .story_kit/README.md to understand the dev process.
|
||||
- URL to visit in the browser
|
||||
- Things to check in the UI
|
||||
- curl commands to exercise relevant API endpoints
|
||||
- Kill the test server when done: `pkill -f story-kit || true`
|
||||
- Kill the test server when done: `pkill -f 'target.*story-kit' || true` (NEVER use `pkill -f story-kit` — it kills the vite dev server)
|
||||
|
||||
### 4. Produce Structured Report
|
||||
Print your QA report to stdout before your process exits. The server will automatically run acceptance gates. Use this format:
|
||||
@@ -220,7 +220,7 @@ role = "Merges completed coder work into master, runs quality gates, archives st
|
||||
model = "opus"
|
||||
max_turns = 30
|
||||
max_budget_usd = 5.00
|
||||
prompt = """You are the mergemaster agent for story {{story_id}}. Your job is to merge the completed coder work into master using the merge_agent_work MCP tool.
|
||||
prompt = """You are the mergemaster agent for story {{story_id}}. Your job is to merge the completed coder work into master.
|
||||
|
||||
Read CLAUDE.md first, then .story_kit/README.md to understand the dev process.
|
||||
|
||||
@@ -229,20 +229,43 @@ Read CLAUDE.md first, then .story_kit/README.md to understand the dev process.
|
||||
2. Review the result: check success, had_conflicts, conflicts_resolved, gates_passed, and gate_output
|
||||
3. If merge succeeded and gates passed: report success to the human
|
||||
4. If conflicts were auto-resolved (conflicts_resolved=true) and gates passed: report success, noting which conflicts were resolved
|
||||
5. If conflicts could not be auto-resolved: call report_merge_failure(story_id='{{story_id}}', reason='<conflict details>') and report to the human. Master is untouched.
|
||||
6. If merge failed for any other reason: call report_merge_failure(story_id='{{story_id}}', reason='<details>') and report to the human.
|
||||
7. If gates failed after merge: attempt to fix minor issues (see below), then re-trigger merge_agent_work. After 2 fix attempts, call report_merge_failure and stop.
|
||||
5. If conflicts could not be auto-resolved: **resolve them yourself** in the merge worktree (see below)
|
||||
6. If merge failed for any other reason: call report_merge_failure(story_id='{{story_id}}', reason='<details>') and report to the human
|
||||
7. If gates failed after merge: attempt to fix the issues yourself in the merge worktree, then re-trigger merge_agent_work. After 3 fix attempts, call report_merge_failure and stop.
|
||||
|
||||
## How Conflict Resolution Works
|
||||
The merge pipeline uses a temporary merge-queue branch and worktree to isolate merges from master. Simple additive conflicts (both branches adding code at the same location) are resolved automatically by keeping both additions. Complex conflicts (modifying the same lines differently) are reported without touching master.
|
||||
## Resolving Complex Conflicts Yourself
|
||||
|
||||
## Fixing Minor Gate Failures
|
||||
If quality gates fail (cargo clippy, cargo test, npm run build, npm test), attempt to fix minor issues yourself before reporting to the human.
|
||||
When the auto-resolver fails, you have access to the merge worktree at `.story_kit/merge_workspace/`. Go in there and resolve the conflicts manually:
|
||||
|
||||
**Fix yourself (up to 2 attempts total):**
|
||||
1. Run `git diff --name-only --diff-filter=U` in the merge worktree to list conflicted files
|
||||
2. **Build context before touching code.** Run `git log --oneline master...HEAD` on the feature branch to see its commits. Then run `git log --oneline --since="$(git log -1 --format=%ci <feature-branch-base-commit>)" master` to see what landed on master since the branch was created. Read the story files in `.story_kit/work/` for any recently merged stories that touch the same files — this tells you WHY master changed and what must be preserved.
|
||||
3. Read each conflicted file and understand both sides of the conflict
|
||||
4. **Understand intent, not just syntax.** The feature branch may be behind master — master's version of shared infrastructure is almost always correct. The feature branch's contribution is the NEW functionality it adds. Your job is to integrate the new into master's structure, not pick one side.
|
||||
5. Resolve by integrating the feature's new functionality into master's code structure
|
||||
5. Stage resolved files with `git add`
|
||||
6. Run `cargo check` (and `npm run build` if frontend changed) to verify compilation
|
||||
7. If it compiles, commit and re-trigger merge_agent_work
|
||||
|
||||
### Common conflict patterns in this project:
|
||||
|
||||
**Story file rename/rename conflicts:** Both branches moved the story .md file to different pipeline directories. Resolution: `git rm` both sides — story files in `work/2_current/`, `work/3_qa/`, `work/4_merge/` are gitignored and don't need to be committed.
|
||||
|
||||
**bot.rs tokio::select! conflicts:** Master has a `tokio::select!` loop in `handle_message()` that handles permission forwarding (story 275). Feature branches created before story 275 have a simpler direct `provider.chat_stream().await` call. Resolution: KEEP master's tokio::select! loop. Integrate only the feature's new logic (e.g. typing indicators, new callbacks) into the existing loop structure. Do NOT replace the loop with the old direct call.
|
||||
|
||||
**Duplicate functions/imports:** The auto-resolver keeps both sides, producing duplicates. Resolution: keep one copy (prefer master's version), delete the duplicate.
|
||||
|
||||
**Formatting-only conflicts:** Both sides reformatted the same code differently. Resolution: pick either side (prefer master).
|
||||
|
||||
## Fixing Gate Failures
|
||||
|
||||
If quality gates fail (cargo clippy, cargo test, npm run build, npm test), attempt to fix issues yourself in the merge worktree.
|
||||
|
||||
**Fix yourself (up to 3 attempts total):**
|
||||
- Syntax errors (missing semicolons, brackets, commas)
|
||||
- Duplicate definitions from merge artifacts
|
||||
- Simple type annotation errors
|
||||
- Unused import warnings flagged by clippy
|
||||
- Mismatched braces from bad conflict resolution
|
||||
- Trivial formatting issues that block compilation or linting
|
||||
|
||||
**Report to human without attempting a fix:**
|
||||
@@ -250,17 +273,14 @@ If quality gates fail (cargo clippy, cargo test, npm run build, npm test), attem
|
||||
- Missing function implementations
|
||||
- Architectural changes required
|
||||
- Non-trivial refactoring needed
|
||||
- Anything requiring understanding of broader system context
|
||||
|
||||
**Max retry limit:** If gates still fail after 2 fix attempts, call report_merge_failure to record the failure, then stop immediately and report the full gate output to the human. Do not retry further.
|
||||
**Max retry limit:** If gates still fail after 3 fix attempts, call report_merge_failure to record the failure, then stop immediately and report the full gate output to the human.
|
||||
|
||||
## CRITICAL Rules
|
||||
- NEVER manually move story files between pipeline stages (e.g. from 4_merge/ to 5_done/)
|
||||
- NEVER call accept_story — only merge_agent_work can move stories to done after a successful merge
|
||||
- When merge fails, ALWAYS call report_merge_failure to record the failure — do NOT improvise with file moves
|
||||
- Only use MCP tools (merge_agent_work, report_merge_failure) to drive the merge process
|
||||
- Only attempt fixes that are clearly minor and low-risk
|
||||
- When merge fails after exhausting your fix attempts, ALWAYS call report_merge_failure
|
||||
- Report conflict resolution outcomes clearly
|
||||
- Report gate failures with full output so the human can act if needed
|
||||
- The server automatically runs acceptance gates when your process exits"""
|
||||
system_prompt = "You are the mergemaster agent. Your primary responsibility is to trigger the merge_agent_work MCP tool and report the results. CRITICAL: Never manually move story files or call accept_story. When merge fails, call report_merge_failure to record the failure. For minor gate failures (syntax errors, unused imports, missing semicolons), attempt to fix them yourself — but stop after 2 attempts, call report_merge_failure, and report to the human. For complex failures or unresolvable conflicts, call report_merge_failure and report clearly so the human can act. The merge pipeline automatically resolves simple additive conflicts."
|
||||
system_prompt = "You are the mergemaster agent. Your primary job is to merge feature branches to master. First try the merge_agent_work MCP tool. If the auto-resolver fails on complex conflicts, resolve them yourself in the merge worktree — you are an opus-class agent capable of understanding both sides of a conflict and producing correct merged code. Common patterns: keep master's tokio::select! permission loop in bot.rs, discard story file rename conflicts (gitignored), remove duplicate definitions. After resolving, verify compilation before re-triggering merge. CRITICAL: Never manually move story files or call accept_story. After 3 failed fix attempts, call report_merge_failure and stop."
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: "Upgrade libsqlite3-sys"
|
||||
---
|
||||
|
||||
# Refactor 260: Upgrade libsqlite3-sys
|
||||
|
||||
## Description
|
||||
|
||||
Upgrade the `libsqlite3-sys` dependency from `0.35.0` to `0.37.0`. The crate is used with `features = ["bundled"]` for static builds.
|
||||
|
||||
## Version Notes
|
||||
|
||||
- Current: `libsqlite3-sys 0.35.0` (pinned transitively by `matrix-sdk 0.16.0` → `matrix-sdk-sqlite` → `rusqlite 0.37.x`)
|
||||
- Target: `libsqlite3-sys 0.37.0`
|
||||
- Latest upstream rusqlite: `0.39.0`
|
||||
- **Blocker**: `matrix-sdk 0.16.0` pins `rusqlite 0.37.x` which pins `libsqlite3-sys 0.35.0`. A clean upgrade requires either waiting for matrix-sdk to bump their rusqlite dep, or upgrading matrix-sdk itself.
|
||||
- **Reverted 2026-03-17**: A previous coder vendored the entire rusqlite crate with a fake `0.37.99` version and patched its libsqlite3-sys dep. This was too hacky — reverted to clean `0.35.0`.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] `libsqlite3-sys` is upgraded to `0.37.0` via a clean dependency path (no vendored forks)
|
||||
- [ ] `cargo build` succeeds
|
||||
- [ ] All tests pass
|
||||
- [ ] No `[patch.crates-io]` hacks or vendored crates
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: "Long-running supervisor agent with periodic pipeline polling"
|
||||
agent: coder-opus
|
||||
---
|
||||
|
||||
# Story 280: Long-running supervisor agent with periodic pipeline polling
|
||||
|
||||
## User Story
|
||||
|
||||
As a project owner, I want a long-running supervisor agent (opus) that automatically monitors the pipeline, assigns agents, resolves stuck items, and handles routine operational tasks, so that I don't have to manually check status, kick agents, or babysit the pipeline in every conversation.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Server can start a persistent supervisor agent that stays alive across the session (not per-story)
|
||||
- [ ] Server prods the supervisor periodically (default 30s, configurable in project.toml) with a pipeline status update
|
||||
- [ ] Supervisor auto-assigns agents to unassigned items in current/qa/merge stages
|
||||
- [ ] Supervisor detects stuck agents (no progress for configurable timeout) and restarts them
|
||||
- [ ] Supervisor detects merge failures and sends stories back to current for rebase when appropriate
|
||||
- [ ] Supervisor can be chatted with via Matrix (timmy relays to supervisor) or via the web UI
|
||||
- [ ] Supervisor logs its decisions so the human can review what it did and why
|
||||
- [ ] Polling interval is configurable in project.toml (e.g. supervisor_poll_interval_secs = 30)
|
||||
- [ ] Supervisor logs persistent/recurring problems to `.story_kit/problems.md` with timestamp, description, and frequency — humans review this file periodically to create stories for systemic issues
|
||||
|
||||
## Notes
|
||||
|
||||
- **2026-03-18**: Moved back to current from merge. Previous attempt went through the full pipeline but the squash-merge produced an empty diff — no code was actually implemented. Needs a real implementation.
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- Supervisor accepting or merging stories to master (human job)
|
||||
- Supervisor making architectural decisions
|
||||
- Replacing the existing per-story agent spawning — supervisor coordinates on top of it
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
name: "Show server logs in web UI"
|
||||
---
|
||||
|
||||
# Story 292: Show server logs in web UI
|
||||
|
||||
## User Story
|
||||
|
||||
As a project owner using the web UI, I want to see live server logs in the interface, so that I can debug agent behavior and pipeline issues without needing terminal access.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Web UI has a server logs panel accessible from the main interface
|
||||
- [ ] Logs stream in real-time via WebSocket or SSE
|
||||
- [ ] Logs can be filtered by keyword (same as get_server_logs MCP tool's filter param)
|
||||
- [ ] Log entries show timestamp and severity level
|
||||
- [ ] Panel doesn't interfere with the existing pipeline board and work item views
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -1,55 +0,0 @@
|
||||
---
|
||||
name: "Stop auto-committing intermediate pipeline moves"
|
||||
---
|
||||
|
||||
# Spike 92: Stop auto-committing intermediate pipeline moves
|
||||
|
||||
## Goal
|
||||
|
||||
Determine how to stop the filesystem watcher from auto-committing every pipeline stage move (upcoming -> current -> qa -> merge -> done -> archive) while still committing at terminal states (creation in upcoming, acceptance in done and archived). This keeps git history clean while preserving cross-machine portability for completed work.
|
||||
|
||||
## Context
|
||||
|
||||
The watcher in `server/src/io/watcher.rs` currently auto-commits every file change in `.story_kit/work/`. A single story run generates 5+ commits just from pipeline moves:
|
||||
- `story-kit: create 42_story_foo`
|
||||
- `story-kit: start 42_story_foo`
|
||||
- `story-kit: queue 42_story_foo for QA`
|
||||
- `story-kit: queue 42_story_foo for merge`
|
||||
- `story-kit: accept 42_story_foo`
|
||||
|
||||
Since story runs complete relatively quickly, the intermediate state (current/qa/merge) is transient and doesn't need to be committed. Only creation and archival are meaningful checkpoints.
|
||||
|
||||
## Questions to Answer
|
||||
|
||||
1. Can we filter `stage_metadata()` to only commit for `1_upcoming` and `5_archived` stages while still broadcasting `WatcherEvent`s for all stages (so the frontend stays in sync)?
|
||||
2. Should we keep `git add -A .story_kit/work/` for the committed stages, or narrow it to only the specific file?
|
||||
3. What happens if the server crashes mid-pipeline? Uncommitted moves are lost — is this acceptable given the story can just be re-run?
|
||||
4. Should intermediate moves be `.gitignore`d at the directory level, or is filtering in the watcher sufficient?
|
||||
5. Do any other parts of the system (agent worktree setup, merge_agent_work, sparse checkout) depend on intermediate pipeline files being committed to master?
|
||||
|
||||
## Approach to Investigate
|
||||
|
||||
### Option A: Filter in `flush_pending()`
|
||||
- In `flush_pending()`, still broadcast the `WatcherEvent` for all stages
|
||||
- Only call `git_add_work_and_commit()` for stages `1_upcoming` and `5_archived`
|
||||
- Simplest change — ~5 lines modified in `watcher.rs`
|
||||
|
||||
### Option B: Two-tier watcher
|
||||
- Split into "commit-worthy" events (create, archive) and "notify-only" events (start, qa, merge)
|
||||
- Commit-worthy events go through git
|
||||
- Notify-only events just broadcast to WebSocket clients
|
||||
- More explicit but same end result as Option A
|
||||
|
||||
### Option C: .gitignore intermediate directories
|
||||
- Add `2_current/`, `3_qa/`, `4_merge/` to `.gitignore`
|
||||
- Watcher still sees events (gitignore doesn't affect filesystem watching)
|
||||
- Git naturally ignores them
|
||||
- Risk: harder to debug, `git status` won't show pipeline state
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Spike document updated with findings and recommendation
|
||||
- [ ] If Option A is viable: prototype the change and verify git log is clean during a full story run
|
||||
- [ ] Confirm frontend still receives real-time pipeline updates for all stages
|
||||
- [ ] Confirm no other system depends on intermediate pipeline commits being on master
|
||||
- [ ] Identify any edge cases (server crash, manual git operations, multi-machine sync)
|
||||
@@ -1,17 +0,0 @@
|
||||
---
|
||||
name: "Upgrade libsqlite3-sys"
|
||||
---
|
||||
|
||||
# Refactor 260: Upgrade libsqlite3-sys
|
||||
|
||||
## Description
|
||||
|
||||
Upgrade the `libsqlite3-sys` dependency from `0.35.0` to `0.37.0`. The crate is used with `features = ["bundled"]` for static builds.
|
||||
|
||||
A previous manual attempt to upgrade failed on compile, so the agent should investigate compatibility with our current `matrix-sdk-sqlite` dependency and resolve any breaking changes.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] `libsqlite3-sys` is upgraded to `0.37.0`
|
||||
- [ ] `cargo build` succeeds
|
||||
- [ ] All tests pass
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: "Matrix bot sends typing indicator while waiting for Claude response"
|
||||
---
|
||||
|
||||
# Story 273: Matrix bot sends typing indicator while waiting for Claude response
|
||||
|
||||
## User Story
|
||||
|
||||
As a user chatting with the Matrix bot, I want to see a typing indicator in Element while the bot is processing my message, so that I know it received my request and is working on a response.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Bot sets m.typing on the room as soon as it starts the Claude API call
|
||||
- [ ] Typing indicator is cleared when the first response chunk is sent to the room
|
||||
- [ ] Typing indicator is cleared on error so it doesn't get stuck
|
||||
- [ ] No visible delay between sending a message and seeing the typing indicator
|
||||
|
||||
## Notes
|
||||
|
||||
- **2026-03-18**: Moved back to current from done. Previous attempt went through the full pipeline but merged with an empty diff — no typing indicator code was actually implemented. Needs a real implementation this time.
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: "Matrix bot ambient mode toggle via chat command"
|
||||
---
|
||||
|
||||
# Story 282: Matrix bot ambient mode toggle via chat command
|
||||
|
||||
## User Story
|
||||
|
||||
As a user chatting with Timmy in a Matrix room, I want to toggle between "addressed mode" (bot only responds when mentioned by name) and "ambient mode" (bot responds to all messages) via a chat command, so that I don't have to @-mention the bot on every message when I'm the only one around.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Matrix bot defaults to addressed mode — only forwards messages containing the bot's name to Claude
|
||||
- [ ] Chat command "{bot_name} ambient on" switches to ambient mode — bot forwards all room messages to Claude (bot name comes from display_name in bot.toml)
|
||||
- [ ] Chat command "{bot_name} ambient off" switches back to addressed mode
|
||||
- [ ] Mode is persisted per-room in bot.toml so it survives bot restarts
|
||||
- [ ] bot.toml.example includes the ambient_mode setting with a comment explaining it
|
||||
- [ ] Bot confirms the mode switch with a short response in chat
|
||||
- [ ] When other users join or are active, user can flip back to addressed mode to avoid noise
|
||||
- [ ] Ambient mode applies per-room (not globally across all rooms)
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: "Pipeline does not check manual_qa flag before advancing from QA to merge"
|
||||
---
|
||||
|
||||
# Bug 283: Pipeline does not check manual_qa flag before advancing from QA to merge
|
||||
|
||||
## Description
|
||||
|
||||
Story 247 added the manual_qa front matter field and the MCP tooling to set it, but the pipeline in pool.rs never actually checks the flag. After QA passes gates and coverage, stories move straight to merge regardless of manual_qa setting.
|
||||
|
||||
## How to Reproduce
|
||||
|
||||
1. Create a story with manual_qa: true in front matter
|
||||
2. Let it go through the coder and QA stages
|
||||
3. Observe that it moves directly to merge without waiting for human approval
|
||||
|
||||
## Actual Result
|
||||
|
||||
Stories always advance from QA to merge automatically, ignoring the manual_qa flag.
|
||||
|
||||
## Expected Result
|
||||
|
||||
Stories with manual_qa: true should pause after QA passes and wait for human approval before moving to merge. Stories with manual_qa: false (the default) should advance automatically as they do now.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Pipeline checks manual_qa front matter field after QA gates pass
|
||||
- [ ] manual_qa defaults to false — stories advance automatically unless explicitly opted in
|
||||
- [ ] Stories with manual_qa: true wait in 3_qa for human approval via accept_story or the UI
|
||||
- [ ] Stories with manual_qa: false proceed directly from QA to merge as before
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: "Matrix bot status command shows pipeline and agent availability"
|
||||
---
|
||||
|
||||
# Story 284: Matrix bot status command shows pipeline and agent availability
|
||||
|
||||
## User Story
|
||||
|
||||
As a user in a Matrix room, I want to type "{bot_name} status" and get a formatted summary of the full pipeline (upcoming through done) with agent assignments, plus which agents are currently free, so that I can check project status without leaving chat.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Chat command "{bot_name} status" triggers a pipeline status display (bot name comes from display_name in bot.toml)
|
||||
- [ ] Output shows all stages: upcoming, current, qa, merge, done — with story names and IDs
|
||||
- [ ] Each active story shows its assigned agent name and model
|
||||
- [ ] Output includes a section showing which agents are free (not currently assigned to any story)
|
||||
- [ ] Response is formatted for readability in Matrix (monospace or markdown as appropriate)
|
||||
- [ ] Command is handled at the bot level — does not require a full Claude invocation
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
name: "Matrix bot help command lists available bot commands"
|
||||
---
|
||||
|
||||
# Story 285: Matrix bot help command lists available bot commands
|
||||
|
||||
## User Story
|
||||
|
||||
As a user in a Matrix room, I want to type "{bot_name} help" and get a list of all available bot commands with brief descriptions, so that I can discover what the bot can do without having to ask or remember.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Chat command "{bot_name} help" displays a list of all available bot-level commands (bot name comes from display_name in bot.toml)
|
||||
- [ ] Each command is shown with a short description of what it does
|
||||
- [ ] Help output is formatted for readability in Matrix
|
||||
- [ ] Help command is handled at the bot level — does not require a full Claude invocation
|
||||
- [ ] Help list automatically includes new commands as they are added (driven by a registry or similar, not a hardcoded string)
|
||||
|
||||
## Notes
|
||||
|
||||
- **2026-03-18**: Moved back to current from done. Previous attempt committed code directly to master (commit a32cfbd) instead of the worktree, and the help command is not functional in the running server. Needs a clean implementation this time.
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: "Server self-rebuild and restart via MCP tool"
|
||||
---
|
||||
|
||||
# Story 286: Server self-rebuild and restart via MCP tool
|
||||
|
||||
## User Story
|
||||
|
||||
As a project owner away from my terminal, I want to tell the bot to restart the server so that it picks up new code changes, without needing physical access to the machine.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] MCP tool `rebuild_and_restart` triggers a cargo build of the server
|
||||
- [ ] If the build fails, server stays up and returns the build error
|
||||
- [ ] If the build succeeds, server re-execs itself with the new binary using std::os::unix::process::CommandExt::exec()
|
||||
- [ ] Server logs the restart so it's traceable
|
||||
- [ ] Matrix bot reconnects automatically after the server comes back up
|
||||
- [ ] Running agents are gracefully stopped before re-exec
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: "Rename upcoming pipeline stage to backlog"
|
||||
---
|
||||
|
||||
# Story 287: Rename upcoming pipeline stage to backlog
|
||||
|
||||
## User Story
|
||||
|
||||
As a project owner, I want the "upcoming" pipeline stage renamed to "backlog" throughout the codebase, UI, and directory structure, so that the terminology better reflects that these items are not necessarily coming up next.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Directory renamed from 1_upcoming to 1_backlog
|
||||
- [ ] All server code references updated (watcher, lifecycle, MCP tools, workflow, etc.)
|
||||
- [ ] Frontend UI labels updated
|
||||
- [ ] MCP tool descriptions and outputs use "backlog" instead of "upcoming"
|
||||
- [ ] Existing story/bug files moved to the new directory
|
||||
- [ ] Git commit messages use "backlog" for new items going forward
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
name: "Ambient mode state lost on server restart"
|
||||
---
|
||||
|
||||
# Bug 288: Ambient mode state lost on server restart
|
||||
|
||||
## Description
|
||||
|
||||
Story 282 implemented ambient mode toggle but only in-memory. The acceptance criterion requiring persistence in bot.toml was not implemented. Every server restart (including rebuild_and_restart) clears ambient mode for all rooms.
|
||||
|
||||
## How to Reproduce
|
||||
|
||||
1. Type "timmy ambient on" — get confirmation
|
||||
2. Restart server (or rebuild_and_restart)
|
||||
3. Send unaddressed message — bot ignores it, ambient mode is gone
|
||||
|
||||
## Actual Result
|
||||
|
||||
Ambient mode state is lost on server restart.
|
||||
|
||||
## Expected Result
|
||||
|
||||
Ambient mode per-room state is persisted in bot.toml and restored on startup.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Ambient mode per-room state is saved to bot.toml when toggled
|
||||
- [ ] Ambient mode state is restored from bot.toml on server startup
|
||||
- [ ] bot.toml.example includes the ambient_rooms setting with a comment
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
name: "rebuild_and_restart MCP tool does not rebuild"
|
||||
agent: coder-opus
|
||||
---
|
||||
|
||||
# Bug 289: rebuild_and_restart MCP tool does not rebuild
|
||||
|
||||
## Description
|
||||
|
||||
The rebuild_and_restart MCP tool re-execs the server binary but does not run cargo build first. It restarts with the old binary, so code changes are not picked up.
|
||||
|
||||
## How to Reproduce
|
||||
|
||||
1. Make a code change to the server
|
||||
2. Call rebuild_and_restart via MCP
|
||||
3. Observe the server restarts but the code change is not reflected
|
||||
|
||||
## Actual Result
|
||||
|
||||
Server re-execs with the old binary. Code changes are not compiled.
|
||||
|
||||
## Expected Result
|
||||
|
||||
Server runs cargo build --release (or cargo build) before re-execing, so the new binary includes the latest code changes.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Bug is fixed and verified
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: "Remove agent thinking traces from agents sidebar"
|
||||
---
|
||||
|
||||
# Story 290: Remove agent thinking traces from agents sidebar
|
||||
|
||||
## User Story
|
||||
|
||||
As a user viewing an expanded work item in the web UI, I want to see the live agent output stream (thinking traces, tool calls, progress) for the agent working on that story, so that I can monitor progress in context rather than in the agents sidebar.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Agent thinking traces are removed from the agents sidebar panel — they should only appear in the work item detail panel (which already has SSE streaming wired up in `WorkItemDetailPanel.tsx`)
|
||||
|
||||
## Notes
|
||||
|
||||
The detail panel (`WorkItemDetailPanel.tsx`) already has agent log streaming implemented — SSE subscription, real-time output, status badges, etc. The only remaining work is removing the thinking traces from the agents sidebar (`AgentPanel.tsx` or similar) so they don't appear in both places.
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- Replacing the agents sidebar entirely — it still shows agent names, status, and assignments
|
||||
- Historical agent output (only live stream while agent is running)
|
||||
@@ -1,25 +0,0 @@
|
||||
---
|
||||
name: "Human QA gate with rejection flow"
|
||||
---
|
||||
|
||||
# Story 247: Human QA gate with rejection flow
|
||||
|
||||
## User Story
|
||||
|
||||
As the project owner, I want stories to require my manual approval after machine QA before they can be merged, so that features that compile and pass tests but do not actually work correctly are caught before reaching master.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Story files support a manual_qa front matter field (defaults to true)
|
||||
- [ ] After machine QA passes in 3_qa, stories with manual_qa: true wait for human approval before moving to 4_merge
|
||||
- [ ] The UI shows a clear way to launch the app from the worktree for manual testing (single button click), with automatic port conflict handling via .story_kit_port
|
||||
- [ ] Frontend and backend are pre-compiled during machine QA so the app is ready to run instantly for manual testing
|
||||
- [ ] Only one QA app instance runs at a time — do not automatically spin up multiple instances
|
||||
- [ ] Human can approve a story from 3_qa to move it to 4_merge
|
||||
- [ ] Human can reject a story from 3_qa back to 2_current with notes about what is broken
|
||||
- [ ] Rejection notes are written into the story file so the coder can see what needs fixing
|
||||
- [ ] Stories with manual_qa: false skip the human gate and proceed directly from machine QA to 4_merge
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
name: "Matrix bot self-signs device keys at startup for verified encryption"
|
||||
agent: mergemaster
|
||||
---
|
||||
|
||||
# Story 263: Matrix bot self-signs device keys at startup for verified encryption
|
||||
|
||||
## User Story
|
||||
|
||||
As a Matrix room participant, I want the bot's messages to not show "encrypted by a device not verified by its owner" warnings, so that I have confidence the bot's encryption is fully verified.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] At startup the bot checks whether its own device keys have been self-signed (cross-signed by its own user identity)
|
||||
- [ ] If the device keys are not self-signed, the bot signs them automatically
|
||||
- [ ] After signing, the bot uploads the new signatures to the homeserver
|
||||
- [ ] After a clean start (fresh matrix_store / device_id) the bot's messages no longer show the 'encrypted by a device not verified by its owner' warning
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
name: "Claude Code session ID not persisted across browser refresh"
|
||||
---
|
||||
|
||||
# Bug 264: Claude Code session ID not persisted across browser refresh
|
||||
|
||||
## Description
|
||||
|
||||
The Claude Code provider uses a session_id to resume conversations via `--resume <id>`. This session_id is stored in React state (`claudeSessionId`) but is NOT persisted to localStorage. After a browser refresh, the session_id is lost (`null`), so Claude Code cannot resume the prior session.
|
||||
|
||||
A fallback exists (`build_claude_code_context_prompt` in `server/src/llm/chat.rs:188`) that injects prior messages as flattened text inside a `<conversation_history>` block, but this loses structure (tool calls, tool results, reasoning) and Claude Code treats it as informational text rather than actual conversation turns. In practice, the LLM does not retain meaningful context after refresh.
|
||||
|
||||
This is the root cause behind bug 245 (chat history persistence regression). The localStorage message persistence from story 145 works correctly for the UI, but the LLM context is not properly restored because the session cannot be resumed.
|
||||
|
||||
Key files:
|
||||
- `frontend/src/components/Chat.tsx:174` — `claudeSessionId` is ephemeral React state
|
||||
- `frontend/src/components/Chat.tsx:553` — session_id only sent when non-null
|
||||
- `server/src/llm/chat.rs:278` — backend branches on session_id presence
|
||||
- `server/src/llm/providers/claude_code.rs:44` — `--resume` flag passed to Claude CLI
|
||||
|
||||
## How to Reproduce
|
||||
|
||||
1. Open the Story Kit web UI and select claude-code-pty as the model
|
||||
2. Have a multi-turn conversation with the agent
|
||||
3. Refresh the browser (F5 or Cmd+R)
|
||||
4. Send a new message referencing the prior conversation
|
||||
5. The LLM has no knowledge of the prior conversation
|
||||
|
||||
## Actual Result
|
||||
|
||||
After refresh, claudeSessionId is null. Claude Code spawns a fresh session without --resume. The fallback text injection is too lossy to provide meaningful context. The LLM behaves as if the conversation never happened.
|
||||
|
||||
## Expected Result
|
||||
|
||||
After refresh, the Claude Code session is resumed via --resume, giving the LLM full context of the prior conversation including tool calls, reasoning, and all turns.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] claudeSessionId is persisted to localStorage (scoped by project path) and restored on component mount
|
||||
- [ ] After browser refresh, the next chat message includes session_id in the ProviderConfig
|
||||
- [ ] Claude Code receives --resume with the persisted session_id after refresh
|
||||
- [ ] Clearing the session (clear button) also clears the persisted session_id
|
||||
- [ ] After server restart with session files intact on disk, conversation resumes correctly
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
name: "Spikes skip merge and stop for human review"
|
||||
agent: coder-opus
|
||||
---
|
||||
|
||||
# Story 265: Spikes skip merge and stop for human review
|
||||
|
||||
## User Story
|
||||
|
||||
As a user, I want spike work items to stop after QA instead of auto-advancing to the merge stage, so that I can review the spike's findings and prototype code in the worktree before deciding what to do with them.
|
||||
|
||||
## Context
|
||||
|
||||
Spikes are investigative — their value is the findings and any prototype code, not a merge to master. The user needs to:
|
||||
- Read the spike document with findings
|
||||
- Review prototype code in the worktree
|
||||
- Optionally build and run the prototype to validate the approach
|
||||
- Then manually decide: archive the spike and create follow-up stories, or reject and re-investigate
|
||||
|
||||
Currently all work items follow the same pipeline: coder → QA → merge → done. Spikes should diverge after QA and wait for human review instead of auto-advancing to merge.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Items with `_spike_` in the filename skip the merge stage after QA passes
|
||||
- [ ] After QA, spike items remain accessible for human review (worktree preserved, not cleaned up)
|
||||
- [ ] Spikes do not auto-advance to `4_merge/` — they stay in `3_qa/` or move to a review-hold state
|
||||
- [ ] The human can manually archive the spike when done reviewing
|
||||
- [ ] Non-spike items (stories, bugs, refactors) continue through the full pipeline as before
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- New UI for spike review (manual file inspection is fine)
|
||||
- Changes to the spike creation flow
|
||||
@@ -0,0 +1,60 @@
|
||||
---
|
||||
name: "Matrix bot structured conversation history"
|
||||
agent: coder-opus
|
||||
---
|
||||
|
||||
# Story 266: Matrix bot structured conversation history
|
||||
|
||||
## User Story
|
||||
|
||||
As a user chatting with the Matrix bot, I want it to remember and own its prior responses naturally, so that conversations feel like talking to one continuous entity rather than a new instance each message.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Conversation history is passed as structured API messages (user/assistant turns) rather than a flattened text prefix
|
||||
- [ ] Claude recognises its prior responses as its own, maintaining consistent personality across a conversation
|
||||
- [ ] Per-room history survives server restarts (persisted to disk or database)
|
||||
- [ ] Rolling window trimming still applies to keep context bounded
|
||||
- [ ] Multi-user rooms still attribute messages to the correct sender
|
||||
|
||||
## Investigation Notes (2026-03-18)
|
||||
|
||||
The current implementation attempts session resumption via `--resume <session_id>` but it's not working:
|
||||
|
||||
### Code path: how session resumption is supposed to work
|
||||
|
||||
1. `server/src/matrix/bot.rs:671-676` — `handle_message()` reads `conv.session_id` from the per-room `RoomConversation` to get the resume ID.
|
||||
2. `server/src/matrix/bot.rs:717` — passes `resume_session_id` to `provider.chat_stream()`.
|
||||
3. `server/src/llm/providers/claude_code.rs:57` — `chat_stream()` stores it as `resume_id`.
|
||||
4. `server/src/llm/providers/claude_code.rs:170-173` — if `resume_session_id` is `Some`, appends `--resume <id>` to the `claude -p` command.
|
||||
5. `server/src/llm/providers/claude_code.rs:348` — `process_json_event()` looks for `json["session_id"]` in each streamed NDJSON event and sends it via a oneshot channel (`sid_tx`).
|
||||
6. `server/src/llm/providers/claude_code.rs:122` — after the PTY exits, `sid_rx.await.ok()` captures the session ID (or `None` if never sent).
|
||||
7. `server/src/matrix/bot.rs:785-787` — stores `new_session_id` back into `conv.session_id` and persists via `save_history()`.
|
||||
|
||||
### What's broken
|
||||
|
||||
- **No session_id captured:** `.story_kit/matrix_history.json` contains conversation entries but no `session_id`. `RoomConversation.session_id` is always `None`.
|
||||
- **Root cause:** `claude -p --output-format stream-json` may not emit a `session_id` in its NDJSON events, or the parser at step 5 isn't matching the actual event shape. The oneshot channel never fires.
|
||||
- **Effect:** Every message spawns a fresh Claude Code process with no `--resume` flag. Each turn is a blank slate.
|
||||
- **History persistence works fine** — serialization round-trips correctly (test at `bot.rs:1335-1339`). The problem is purely that `--resume` is never invoked.
|
||||
|
||||
### Debugging steps
|
||||
|
||||
1. Run `claude -p "hello" --output-format stream-json --verbose 2>/dev/null` manually and inspect the NDJSON for a `session_id` field. Check what event type carries it and whether the key name matches what `process_json_event()` expects.
|
||||
2. If `session_id` is present but nested differently (e.g. inside an `event` wrapper), fix the JSON path at `claude_code.rs:348`.
|
||||
3. If `-p` mode doesn't emit `session_id` at all, consider an alternative: pass conversation history as a structured prompt prefix, or switch to the Claude API directly.
|
||||
|
||||
### Previous attempt failed (2026-03-18)
|
||||
|
||||
A sonnet coder attempted this story but did NOT fix the root cause. It rewrote the `chat_stream()` call in `bot.rs` to look identical to what was already there — it never investigated why `session_id` isn't being captured. The merge auto-resolver then jammed the duplicate call inside the `tokio::select!` permission loop, producing mismatched braces. The broken merge was reverted.
|
||||
|
||||
**What the coder must actually do:**
|
||||
|
||||
1. **Do NOT rewrite the `chat_stream()` call or the `tokio::select!` loop in `bot.rs`.** That code is correct and handles permission forwarding (story 275). Do not touch it.
|
||||
2. **The bug is in `claude_code.rs`, not `bot.rs`.** The `process_json_event()` function at line ~348 looks for `json["session_id"]` but it's likely never finding it. Start by running step 1 above to see what the actual NDJSON output looks like.
|
||||
3. **If `claude -p` doesn't emit `session_id` at all**, the `--resume` approach won't work. In that case, the fix is to pass conversation history as a prompt prefix (prepend prior turns to the user message) or use `--continue` instead of `--resume`, or call the Claude API directly instead of shelling out to the CLI.
|
||||
4. **Rebase onto current master before starting.** Master has changed significantly (spike 92, story 275 permission handling, gitignore changes).
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: "MCP update_story tool should support front matter fields"
|
||||
---
|
||||
|
||||
# Story 267: MCP update_story tool should support front matter fields
|
||||
|
||||
## User Story
|
||||
|
||||
As an operator using the MCP tools, I want update_story to accept optional front matter fields (like agent, manual_qa, etc.) so that I can update story metadata without editing files by hand.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] update_story MCP tool accepts optional agent parameter to set/change the agent front matter field
|
||||
- [ ] update_story MCP tool accepts optional arbitrary front matter key-value pairs
|
||||
- [ ] Front matter updates are auto-committed via the filesystem watcher like other story mutations
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: "Upgrade tokio-tungstenite to 0.29.0"
|
||||
---
|
||||
|
||||
# Refactor 268: Upgrade tokio-tungstenite to 0.29.0
|
||||
|
||||
## Current State
|
||||
|
||||
- TBD
|
||||
|
||||
## Desired State
|
||||
|
||||
Upgrade tokio-tungstenite from 0.28.0 to 0.29.0 in workspace Cargo.toml and fix any breaking API changes.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] tokio-tungstenite = "0.29.0" in workspace Cargo.toml
|
||||
- [ ] All code compiles without errors
|
||||
- [ ] All tests pass
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: "@ file references in web UI chat input"
|
||||
---
|
||||
|
||||
# Story 269: @ file references in web UI chat input
|
||||
|
||||
## User Story
|
||||
|
||||
As a user chatting in the web UI, I want to type @ to get an autocomplete overlay listing project files, so that I can reference specific files in my messages the same way Zed and Claude Code do.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Typing @ in the chat input triggers a file picker overlay
|
||||
- [ ] Overlay searches project files with fuzzy matching as the user types after @
|
||||
- [ ] Selecting a file inserts a reference into the message (e.g. @path/to/file.rs)
|
||||
- [ ] The referenced file contents are included as context when the message is sent to the LLM
|
||||
- [ ] Overlay is dismissable with Escape
|
||||
- [ ] Multiple @ references can be used in a single message
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: "QA test server overwrites root .mcp.json with wrong port"
|
||||
---
|
||||
|
||||
# Bug 270: QA test server overwrites root .mcp.json with wrong port
|
||||
|
||||
## Description
|
||||
|
||||
When the QA agent starts a test server in a worktree (e.g. on port 3012), that server auto-detects the shared project root and calls open_project, which writes .mcp.json with the test server's port. This clobbers the root .mcp.json that should always point to the main server (port 3001).
|
||||
|
||||
Root cause: open_project in server/src/io/fs.rs:527 unconditionally calls write_mcp_json(&p, port) with its own port. Because worktrees share .story_kit/ with the real project, the test server resolves to the real project root and overwrites the root .mcp.json instead of writing to its own worktree directory.
|
||||
|
||||
Fix: Remove the write_mcp_json call from open_project entirely. Worktree .mcp.json files are already written correctly during worktree creation (worktree.rs:81,97), and the root .mcp.json is committed in git. open_project should not touch it.
|
||||
|
||||
## How to Reproduce
|
||||
|
||||
1. QA agent starts on a story\n2. QA agent starts a test server in the worktree on a non-default port (e.g. 3012)\n3. Test server auto-opens the project root\n4. Root .mcp.json is overwritten with test port
|
||||
|
||||
## Actual Result
|
||||
|
||||
Root .mcp.json contains the QA test server's port (e.g. 3012) instead of the main server's port (3001). Interactive Claude sessions lose MCP connectivity.
|
||||
|
||||
## Expected Result
|
||||
|
||||
Root .mcp.json always points to the primary server's port. Test servers started by QA agents should not overwrite it.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] QA test servers do not overwrite root .mcp.json
|
||||
- [ ] Root .mcp.json always reflects the primary server's port
|
||||
- [ ] Worktree .mcp.json files are only written during worktree creation
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: "Show assigned agent in expanded work item view"
|
||||
---
|
||||
|
||||
# Story 271: Show assigned agent in expanded work item view
|
||||
|
||||
## User Story
|
||||
|
||||
As a project owner viewing an expanded work item in the web UI, I want to see which agent (e.g. coder-opus) has been assigned via front matter, so that I know which coder is working on or will pick up the story.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Expanded work item view displays the agent front matter field if set
|
||||
- [ ] Shows the specific agent name (e.g. 'coder-opus') not just 'assigned'
|
||||
- [ ] If no agent is set in front matter, the field is omitted or shows unassigned
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: "Clear merge error front matter when story leaves merge stage"
|
||||
---
|
||||
|
||||
# Story 272: Clear merge error front matter when story leaves merge stage
|
||||
|
||||
## User Story
|
||||
|
||||
As an operator, I want merge error front matter to be automatically removed when a story is moved out of the merge stage via MCP, so that stale error metadata doesn't persist when the story is retried.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] When a story with merge_error front matter is moved out of 4_merge via MCP, the merge_error field is automatically stripped
|
||||
- [ ] Works for all destinations: back to 2_current, back to 1_upcoming, or forward to 5_done
|
||||
- [ ] Stories without merge_error front matter are unaffected
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: "MCP pipeline status tool with agent assignments"
|
||||
---
|
||||
|
||||
# Story 274: MCP pipeline status tool with agent assignments
|
||||
|
||||
## User Story
|
||||
|
||||
As a user checking pipeline status, I want an MCP tool that returns a structured status report including which agent is assigned to each work item, so that I can quickly see what's active and spot stuck items.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] New MCP tool (e.g. `get_pipeline_status`) returns all work items across all active pipeline stages (current, qa, merge, done) with their stage, name, and assigned agent
|
||||
- [ ] Upcoming backlog items are included with count or listing
|
||||
- [ ] Agent assignment info comes from story front matter (`agent` field) and/or the running agent list
|
||||
- [ ] Response is structured/deterministic (not free-form prose)
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: "Matrix bot surfaces Claude Code permission prompts to chat"
|
||||
agent: coder-opus
|
||||
---
|
||||
|
||||
# Story 275: Matrix bot surfaces Claude Code permission prompts to chat
|
||||
|
||||
## User Story
|
||||
|
||||
As a user chatting with the Matrix bot, I want to see permission prompts from Claude Code in the chat and be able to approve or deny them, so that headless Claude Code sessions don't silently hang when they need authorization to proceed.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] When Claude Code hits a permission prompt during a bot-initiated session, the bot sends the prompt text to the Matrix room as a message
|
||||
- [ ] The user can approve or deny the permission by replying in chat (e.g. yes/no or a reaction)
|
||||
- [ ] The bot relays the user decision back to the Claude Code subprocess so execution continues
|
||||
- [ ] If the user does not respond within a configurable timeout, the permission is denied (fail-closed)
|
||||
- [ ] The bot does not hang or timeout silently when a permission prompt is pending - the user always sees what is happening
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: "Detect and log when root .mcp.json port is modified"
|
||||
---
|
||||
|
||||
# Story 276: Detect and log when root .mcp.json port is modified
|
||||
|
||||
## User Story
|
||||
|
||||
As a ..., I want ..., so that ...
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] TODO
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: "Matrix bot uses its configured name instead of \"Claude\""
|
||||
---
|
||||
|
||||
# Story 277: Matrix bot uses its configured name instead of "Claude"
|
||||
|
||||
## User Story
|
||||
|
||||
As a Matrix user, I want the bot to identify itself by its configured name (e.g., "Timmy") rather than "Claude", so that the bot feels like a distinct personality in the chat.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] The Matrix bot refers to itself by its configured display name (e.g., 'Timmy') in conversations, not 'Claude'
|
||||
- [ ] The bot's self-referencing name is derived from configuration, not hardcoded
|
||||
- [ ] If no custom name is configured, the bot falls back to a sensible default
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: "Auto-assign agents to pipeline items on server startup"
|
||||
---
|
||||
|
||||
# Story 278: Auto-assign agents to pipeline items on server startup
|
||||
|
||||
## User Story
|
||||
|
||||
As a ..., I want ..., so that ...
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] TODO
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: "Auto-assign should respect agent stage when front matter specifies agent"
|
||||
---
|
||||
|
||||
# Story 279: Auto-assign should respect agent stage when front matter specifies agent
|
||||
|
||||
## User Story
|
||||
|
||||
As a project operator, I want auto-assign to respect the pipeline stage when a story's front matter specifies a preferred agent, so that a coder agent isn't assigned to do QA work just because the story originally requested that coder.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] When a story in `3_qa/` has `agent: coder-opus` in front matter, auto-assign skips the preferred agent (stage mismatch) and assigns a free QA-stage agent instead
|
||||
- [ ] When a story in `2_current/` has `agent: coder-opus` in front matter, auto-assign still respects the preference (stage matches)
|
||||
- [ ] When the preferred agent's stage mismatches, auto-assign logs a message indicating the stage mismatch and fallback
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- Changing the front matter `agent` field automatically when a story advances stages
|
||||
- Adding per-stage agent preferences to front matter
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: "Matrix bot announces itself when it comes online"
|
||||
---
|
||||
|
||||
# Story 281: Matrix bot announces itself when it comes online
|
||||
|
||||
## User Story
|
||||
|
||||
As a user in the Matrix room, I want Timmy to post a message when he starts up, so that I know the bot is online and ready to accept commands.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Bot sends a brief greeting message to each configured room on startup (e.g. 'Timmy is online.')
|
||||
- [ ] Message uses the configured display_name, not a hardcoded name
|
||||
- [ ] Message is only sent once per startup, not on reconnects or sync resumptions
|
||||
- [ ] Bot does not announce if it was already running (e.g. after a brief network blip)
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- TBD
|
||||
@@ -0,0 +1,119 @@
|
||||
---
|
||||
name: "Stop auto-committing intermediate pipeline moves"
|
||||
agent: "coder-opus"
|
||||
review_hold: true
|
||||
---
|
||||
|
||||
# Spike 92: Stop auto-committing intermediate pipeline moves
|
||||
|
||||
## Goal
|
||||
|
||||
Determine how to stop the filesystem watcher from auto-committing every pipeline stage move (upcoming -> current -> qa -> merge -> done -> archive) while still committing at terminal states (creation in upcoming, acceptance in done and archived). This keeps git history clean while preserving cross-machine portability for completed work.
|
||||
|
||||
## Context
|
||||
|
||||
The watcher in `server/src/io/watcher.rs` currently auto-commits every file change in `.story_kit/work/`. A single story run generates 5+ commits just from pipeline moves:
|
||||
- `story-kit: create 42_story_foo`
|
||||
- `story-kit: start 42_story_foo`
|
||||
- `story-kit: queue 42_story_foo for QA`
|
||||
- `story-kit: queue 42_story_foo for merge`
|
||||
- `story-kit: accept 42_story_foo`
|
||||
|
||||
Since story runs complete relatively quickly, the intermediate state (current/qa/merge) is transient and doesn't need to be committed. Only creation and archival are meaningful checkpoints.
|
||||
|
||||
## Questions to Answer
|
||||
|
||||
1. Can we filter `stage_metadata()` to only commit for `1_upcoming` and `6_archived` stages while still broadcasting `WatcherEvent`s for all stages (so the frontend stays in sync)?
|
||||
2. Should we keep `git add -A .story_kit/work/` for the committed stages, or narrow it to only the specific file?
|
||||
3. What happens if the server crashes mid-pipeline? Uncommitted moves are lost — is this acceptable given the story can just be re-run?
|
||||
4. Should intermediate moves be `.gitignore`d at the directory level, or is filtering in the watcher sufficient?
|
||||
5. Do any other parts of the system (agent worktree setup, merge_agent_work, sparse checkout) depend on intermediate pipeline files being committed to master?
|
||||
|
||||
## Findings
|
||||
|
||||
### Q1: Can we filter to only commit terminal stages?
|
||||
|
||||
**Yes.** The fix is in `flush_pending()`, not `stage_metadata()`. We add a `should_commit_stage()` predicate that returns `true` only for `1_upcoming` and `6_archived`. The event broadcast path is decoupled from the commit path — `flush_pending()` always broadcasts a `WatcherEvent` regardless of whether it commits.
|
||||
|
||||
Prototype implemented: added `COMMIT_WORTHY_STAGES` constant and `should_commit_stage()` function. The change is ~15 lines including the constant, predicate, and conditional in `flush_pending()`.
|
||||
|
||||
### Q2: Keep `git add -A .story_kit/work/` or narrow to specific file?
|
||||
|
||||
**Keep `git add -A .story_kit/work/`.** When committing a terminal stage (e.g. `6_archived`), the file has been moved from a previous stage (e.g. `5_done`). Using `-A` on the whole work directory captures both the addition in the new stage and the deletion from the old stage in a single commit. Narrowing to the specific file would miss the deletion side of the move.
|
||||
|
||||
### Q3: Server crash mid-pipeline — acceptable?
|
||||
|
||||
**Yes.** If the server crashes while a story is in `2_current`, `3_qa`, or `4_merge`, the file is lost from git but:
|
||||
- The story file still exists on the filesystem (it's just not committed)
|
||||
- The agent's work is in its own feature branch/worktree (independent of pipeline file state)
|
||||
- The story can be re-queued from `1_upcoming` which IS committed
|
||||
- Pipeline state is transient by nature — it reflects "what's happening right now", not permanent record
|
||||
|
||||
### Q4: `.gitignore` vs watcher filtering?
|
||||
|
||||
**Watcher filtering is sufficient.** `.gitignore` approach (Option C) has downsides:
|
||||
- `git status` won't show pipeline state, making debugging harder
|
||||
- If you ever need to commit an intermediate state (e.g. for a new feature), you'd have to fight `.gitignore`
|
||||
- Watcher filtering is explicit and easy to understand — a constant lists the commit-worthy stages
|
||||
- No risk of accidentally ignoring files that should be tracked
|
||||
|
||||
### Q5: Dependencies on intermediate pipeline commits?
|
||||
|
||||
**None found.** Thorough investigation confirmed:
|
||||
|
||||
1. **`merge_agent_work`** (`agents/merge.rs`): Creates a temporary `merge-queue/` branch and worktree. Reads the feature branch, not pipeline files. After merge, calls `move_story_to_archived()` which is a filesystem operation.
|
||||
|
||||
2. **Agent worktree setup** (`worktree.rs`): Creates worktrees from feature branches. Sparse checkout is a no-op (disabled). Does not read pipeline file state from git.
|
||||
|
||||
3. **MCP tool handlers** (`agents/lifecycle.rs`): `move_story_to_current()`, `move_story_to_merge()`, `move_story_to_qa()`, `move_story_to_archived()` — all pure filesystem `fs::rename()` operations. None perform git commits.
|
||||
|
||||
4. **Frontend** (`http/workflow.rs`): `load_pipeline_state()` reads directories from the filesystem directly via `fs::read_dir()`. Never calls git. WebSocket events keep the frontend in sync.
|
||||
|
||||
5. **No git inspection commands** reference pipeline stage directories anywhere in the codebase.
|
||||
|
||||
### Edge Cases
|
||||
|
||||
- **Multi-machine sync:** Only `1_upcoming` and `6_archived` are committed. If you push/pull, you'll see story creation and archival but not intermediate pipeline state. This is correct — intermediate state is machine-local runtime state.
|
||||
- **Manual git operations:** `git status` will show uncommitted files in intermediate stages. This is actually helpful for debugging — you can see what's in the pipeline without grepping git log.
|
||||
- **Sweep (5_done → 6_archived):** The sweep moves files to `6_archived`, which triggers a watcher event that WILL commit (since `6_archived` is a terminal stage). This naturally captures the final state.
|
||||
|
||||
## Approach to Investigate
|
||||
|
||||
### Option A: Filter in `flush_pending()` ← **RECOMMENDED**
|
||||
- In `flush_pending()`, still broadcast the `WatcherEvent` for all stages
|
||||
- Only call `git_add_work_and_commit()` for stages `1_upcoming` and `6_archived`
|
||||
- Simplest change — ~15 lines modified in `watcher.rs`
|
||||
|
||||
### Option B: Two-tier watcher
|
||||
- Split into "commit-worthy" events (create, archive) and "notify-only" events (start, qa, merge)
|
||||
- Commit-worthy events go through git
|
||||
- Notify-only events just broadcast to WebSocket clients
|
||||
- More explicit but same end result as Option A
|
||||
|
||||
### Option C: .gitignore intermediate directories
|
||||
- Add `2_current/`, `3_qa/`, `4_merge/` to `.gitignore`
|
||||
- Watcher still sees events (gitignore doesn't affect filesystem watching)
|
||||
- Git naturally ignores them
|
||||
- Risk: harder to debug, `git status` won't show pipeline state
|
||||
|
||||
## Recommendation
|
||||
|
||||
**Option A is viable and implemented.** The prototype is in `server/src/io/watcher.rs`:
|
||||
- Added `COMMIT_WORTHY_STAGES` constant: `["1_upcoming", "6_archived"]`
|
||||
- Added `should_commit_stage()` predicate
|
||||
- Modified `flush_pending()` to conditionally commit based on stage, while always broadcasting events
|
||||
- All 872 tests pass, clippy clean
|
||||
|
||||
A full story run will now produce only 2 pipeline commits instead of 5+:
|
||||
- `story-kit: create 42_story_foo` (creation in `1_upcoming`)
|
||||
- `story-kit: accept 42_story_foo` (archival in `6_archived`)
|
||||
|
||||
The intermediate moves (`start`, `queue for QA`, `queue for merge`, `done`) are still broadcast to WebSocket clients for real-time frontend updates, but no longer clutter git history.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [x] Spike document updated with findings and recommendation
|
||||
- [x] If Option A is viable: prototype the change and verify git log is clean during a full story run
|
||||
- [x] Confirm frontend still receives real-time pipeline updates for all stages
|
||||
- [x] Confirm no other system depends on intermediate pipeline commits being on master
|
||||
- [x] Identify any edge cases (server crash, manual git operations, multi-machine sync)
|
||||
64
Cargo.lock
generated
64
Cargo.lock
generated
@@ -1048,12 +1048,6 @@ version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.2"
|
||||
@@ -1313,7 +1307,7 @@ version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash 0.1.5",
|
||||
"foldhash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1321,17 +1315,14 @@ name = "hashbrown"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
||||
dependencies = [
|
||||
"foldhash 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashlink"
|
||||
version = "0.11.0"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea0b22561a9c04a7cb1a302c013e0259cd3b4bb619f145b32f72b8b4bcbed230"
|
||||
checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
|
||||
dependencies = [
|
||||
"hashbrown 0.16.1",
|
||||
"hashbrown 0.15.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1957,9 +1948,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libsqlite3-sys"
|
||||
version = "0.37.0"
|
||||
version = "0.35.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f111c8c41e7c61a49cd34e44c7619462967221a6443b0ec299e0ac30cfb9b1"
|
||||
checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
@@ -3329,16 +3320,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rsqlite-vfs"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8a1f2315036ef6b1fbacd1972e8ee7688030b0a2121edfc2a6550febd41574d"
|
||||
dependencies = [
|
||||
"hashbrown 0.16.1",
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.14.1"
|
||||
@@ -3516,7 +3497,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rusqlite"
|
||||
version = "0.37.99"
|
||||
version = "0.37.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f"
|
||||
dependencies = [
|
||||
"bitflags 2.11.0",
|
||||
"fallible-iterator",
|
||||
@@ -3524,7 +3507,6 @@ dependencies = [
|
||||
"hashlink",
|
||||
"libsqlite3-sys",
|
||||
"smallvec",
|
||||
"sqlite-wasm-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3995,18 +3977,6 @@ dependencies = [
|
||||
"der",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite-wasm-rs"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f4206ed3a67690b9c29b77d728f6acc3ce78f16bf846d83c94f76400320181b"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"js-sys",
|
||||
"rsqlite-vfs",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sse-codec"
|
||||
version = "0.3.2"
|
||||
@@ -4027,7 +3997,7 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
||||
|
||||
[[package]]
|
||||
name = "story-kit"
|
||||
version = "0.1.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"async-stream",
|
||||
"async-trait",
|
||||
@@ -4048,7 +4018,6 @@ dependencies = [
|
||||
"portable-pty",
|
||||
"pulldown-cmark",
|
||||
"reqwest 0.13.2",
|
||||
"rusqlite",
|
||||
"rust-embed",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -4056,7 +4025,7 @@ dependencies = [
|
||||
"strip-ansi-escapes",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tokio-tungstenite 0.28.0",
|
||||
"tokio-tungstenite 0.29.0",
|
||||
"toml 1.0.6+spec-1.1.0",
|
||||
"uuid",
|
||||
"wait-timeout",
|
||||
@@ -4364,14 +4333,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-tungstenite"
|
||||
version = "0.28.0"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d25a406cddcc431a75d3d9afc6a7c0f7428d4891dd973e4d54c56b46127bf857"
|
||||
checksum = "8f72a05e828585856dacd553fba484c242c46e391fb0e58917c942ee9202915c"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"log",
|
||||
"tokio",
|
||||
"tungstenite 0.28.0",
|
||||
"tungstenite 0.29.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4593,9 +4562,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tungstenite"
|
||||
version = "0.28.0"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8628dcc84e5a09eb3d8423d6cb682965dea9133204e8fb3efee74c2a0c259442"
|
||||
checksum = "6c01152af293afb9c7c2a57e4b559c5620b421f6d133261c60dd2d0cdb38e6b8"
|
||||
dependencies = [
|
||||
"bytes 1.11.1",
|
||||
"data-encoding",
|
||||
@@ -4605,7 +4574,6 @@ dependencies = [
|
||||
"rand 0.9.2",
|
||||
"sha1",
|
||||
"thiserror 2.0.18",
|
||||
"utf-8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -26,7 +26,7 @@ tempfile = "3"
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync"] }
|
||||
toml = "1.0.6"
|
||||
uuid = { version = "1.22.0", features = ["v4", "serde"] }
|
||||
tokio-tungstenite = "0.28.0"
|
||||
tokio-tungstenite = "0.29.0"
|
||||
walkdir = "2.5.0"
|
||||
filetime = "0.2"
|
||||
matrix-sdk = { version = "0.16.0", default-features = false, features = [
|
||||
@@ -37,9 +37,3 @@ matrix-sdk = { version = "0.16.0", default-features = false, features = [
|
||||
pulldown-cmark = { version = "0.13.1", default-features = false, features = [
|
||||
"html",
|
||||
] }
|
||||
|
||||
[patch.crates-io]
|
||||
# Patch rusqlite 0.37.x (used by matrix-sdk-sqlite) with a local fork that requires
|
||||
# libsqlite3-sys 0.37.0 instead of 0.35.0, enabling a single unified libsqlite3-sys
|
||||
# 0.37.0 in the dependency graph with the "bundled" feature for static builds.
|
||||
rusqlite = { path = "vendor/rusqlite" }
|
||||
|
||||
@@ -262,7 +262,7 @@ describe("ChatWebSocket", () => {
|
||||
|
||||
// Server pushes pipeline_state on fresh connection
|
||||
const freshState = {
|
||||
upcoming: [{ story_id: "1_story_test", name: "Test", error: null }],
|
||||
backlog: [{ story_id: "1_story_test", name: "Test", error: null }],
|
||||
current: [],
|
||||
qa: [],
|
||||
merge: [],
|
||||
|
||||
@@ -36,7 +36,7 @@ export interface PipelineStageItem {
|
||||
}
|
||||
|
||||
export interface PipelineState {
|
||||
upcoming: PipelineStageItem[];
|
||||
backlog: PipelineStageItem[];
|
||||
current: PipelineStageItem[];
|
||||
qa: PipelineStageItem[];
|
||||
merge: PipelineStageItem[];
|
||||
@@ -50,7 +50,7 @@ export type WsResponse =
|
||||
| { type: "error"; message: string }
|
||||
| {
|
||||
type: "pipeline_state";
|
||||
upcoming: PipelineStageItem[];
|
||||
backlog: PipelineStageItem[];
|
||||
current: PipelineStageItem[];
|
||||
qa: PipelineStageItem[];
|
||||
merge: PipelineStageItem[];
|
||||
@@ -115,6 +115,7 @@ export interface WorkItemContent {
|
||||
content: string;
|
||||
stage: string;
|
||||
name: string | null;
|
||||
agent: string | null;
|
||||
}
|
||||
|
||||
export interface TestCaseResult {
|
||||
@@ -277,6 +278,9 @@ export const api = {
|
||||
getHomeDirectory(baseUrl?: string) {
|
||||
return requestJson<string>("/io/fs/home", {}, baseUrl);
|
||||
},
|
||||
listProjectFiles(baseUrl?: string) {
|
||||
return requestJson<string[]>("/io/fs/files", {}, baseUrl);
|
||||
},
|
||||
searchFiles(query: string, baseUrl?: string) {
|
||||
return requestJson<SearchResult[]>(
|
||||
"/fs/search",
|
||||
@@ -394,7 +398,7 @@ export class ChatWebSocket {
|
||||
if (data.type === "error") this.onError?.(data.message);
|
||||
if (data.type === "pipeline_state")
|
||||
this.onPipelineState?.({
|
||||
upcoming: data.upcoming,
|
||||
backlog: data.backlog,
|
||||
current: data.current,
|
||||
qa: data.qa,
|
||||
merge: data.merge,
|
||||
|
||||
@@ -213,7 +213,7 @@ describe("RosterBadge availability state", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Thinking traces hidden from agent stream UI", () => {
|
||||
describe("Agent output not shown in sidebar (story 290)", () => {
|
||||
beforeAll(() => {
|
||||
Element.prototype.scrollIntoView = vi.fn();
|
||||
});
|
||||
@@ -224,7 +224,51 @@ describe("Thinking traces hidden from agent stream UI", () => {
|
||||
mockedSubscribeAgentStream.mockReturnValue(() => {});
|
||||
});
|
||||
|
||||
// AC1: thinking block is never rendered even when thinking events arrive
|
||||
// AC1: output events do not appear in the agents sidebar
|
||||
it("does not render agent output when output event arrives", async () => {
|
||||
let emitEvent: ((e: AgentEvent) => void) | null = null;
|
||||
mockedSubscribeAgentStream.mockImplementation(
|
||||
(_storyId, _agentName, onEvent) => {
|
||||
emitEvent = onEvent;
|
||||
return () => {};
|
||||
},
|
||||
);
|
||||
|
||||
const agentList: AgentInfo[] = [
|
||||
{
|
||||
story_id: "290_output",
|
||||
agent_name: "coder-1",
|
||||
status: "running",
|
||||
session_id: null,
|
||||
worktree_path: "/tmp/wt",
|
||||
base_branch: "master",
|
||||
log_session_id: null,
|
||||
},
|
||||
];
|
||||
mockedAgents.listAgents.mockResolvedValue(agentList);
|
||||
|
||||
const { container } = render(<AgentPanel />);
|
||||
await screen.findByTestId("roster-badge-coder-1");
|
||||
|
||||
await act(async () => {
|
||||
emitEvent?.({
|
||||
type: "output",
|
||||
story_id: "290_output",
|
||||
agent_name: "coder-1",
|
||||
text: "doing some work...",
|
||||
});
|
||||
});
|
||||
|
||||
// No output elements in the sidebar
|
||||
expect(
|
||||
container.querySelector('[data-testid^="agent-output-"]'),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid^="agent-stream-"]'),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
// AC1: thinking events do not appear in the agents sidebar
|
||||
it("does not render thinking block when thinking event arrives", async () => {
|
||||
let emitEvent: ((e: AgentEvent) => void) | null = null;
|
||||
mockedSubscribeAgentStream.mockImplementation(
|
||||
@@ -236,7 +280,7 @@ describe("Thinking traces hidden from agent stream UI", () => {
|
||||
|
||||
const agentList: AgentInfo[] = [
|
||||
{
|
||||
story_id: "218_thinking",
|
||||
story_id: "290_thinking",
|
||||
agent_name: "coder-1",
|
||||
status: "running",
|
||||
session_id: null,
|
||||
@@ -253,109 +297,16 @@ describe("Thinking traces hidden from agent stream UI", () => {
|
||||
await act(async () => {
|
||||
emitEvent?.({
|
||||
type: "thinking",
|
||||
story_id: "218_thinking",
|
||||
story_id: "290_thinking",
|
||||
agent_name: "coder-1",
|
||||
text: "Let me consider the problem carefully...",
|
||||
});
|
||||
});
|
||||
|
||||
// AC1: thinking block must not be present
|
||||
// No thinking block or output in sidebar
|
||||
expect(screen.queryByTestId("thinking-block")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
// AC2: after thinking events, only regular output is rendered
|
||||
it("renders regular output but not thinking block when both arrive", async () => {
|
||||
let emitEvent: ((e: AgentEvent) => void) | null = null;
|
||||
mockedSubscribeAgentStream.mockImplementation(
|
||||
(_storyId, _agentName, onEvent) => {
|
||||
emitEvent = onEvent;
|
||||
return () => {};
|
||||
},
|
||||
);
|
||||
|
||||
const agentList: AgentInfo[] = [
|
||||
{
|
||||
story_id: "218_output",
|
||||
agent_name: "coder-1",
|
||||
status: "running",
|
||||
session_id: null,
|
||||
worktree_path: "/tmp/wt",
|
||||
base_branch: "master",
|
||||
log_session_id: null,
|
||||
},
|
||||
];
|
||||
mockedAgents.listAgents.mockResolvedValue(agentList);
|
||||
|
||||
render(<AgentPanel />);
|
||||
await screen.findByTestId("roster-badge-coder-1");
|
||||
|
||||
// Thinking event — must be ignored visually
|
||||
await act(async () => {
|
||||
emitEvent?.({
|
||||
type: "thinking",
|
||||
story_id: "218_output",
|
||||
agent_name: "coder-1",
|
||||
text: "thinking deeply",
|
||||
});
|
||||
});
|
||||
|
||||
// AC3: output event still renders correctly (no regression)
|
||||
await act(async () => {
|
||||
emitEvent?.({
|
||||
type: "output",
|
||||
story_id: "218_output",
|
||||
agent_name: "coder-1",
|
||||
text: "Here is the result.",
|
||||
});
|
||||
});
|
||||
|
||||
// AC1: no thinking block
|
||||
expect(screen.queryByTestId("thinking-block")).not.toBeInTheDocument();
|
||||
|
||||
// AC2+AC3: output area renders the text but NOT thinking text
|
||||
const outputArea = screen.getByTestId("agent-output-coder-1");
|
||||
expect(outputArea).toBeInTheDocument();
|
||||
expect(outputArea.textContent).toContain("Here is the result.");
|
||||
expect(outputArea.textContent).not.toContain("thinking deeply");
|
||||
});
|
||||
|
||||
// AC3: output-only event stream (no thinking) still works
|
||||
it("renders output event text without a thinking block", async () => {
|
||||
let emitEvent: ((e: AgentEvent) => void) | null = null;
|
||||
mockedSubscribeAgentStream.mockImplementation(
|
||||
(_storyId, _agentName, onEvent) => {
|
||||
emitEvent = onEvent;
|
||||
return () => {};
|
||||
},
|
||||
);
|
||||
|
||||
const agentList: AgentInfo[] = [
|
||||
{
|
||||
story_id: "218_noThink",
|
||||
agent_name: "coder-1",
|
||||
status: "running",
|
||||
session_id: null,
|
||||
worktree_path: "/tmp/wt",
|
||||
base_branch: "master",
|
||||
log_session_id: null,
|
||||
},
|
||||
];
|
||||
mockedAgents.listAgents.mockResolvedValue(agentList);
|
||||
|
||||
render(<AgentPanel />);
|
||||
await screen.findByTestId("roster-badge-coder-1");
|
||||
|
||||
await act(async () => {
|
||||
emitEvent?.({
|
||||
type: "output",
|
||||
story_id: "218_noThink",
|
||||
agent_name: "coder-1",
|
||||
text: "plain output line",
|
||||
});
|
||||
});
|
||||
|
||||
expect(screen.queryByTestId("thinking-block")).not.toBeInTheDocument();
|
||||
const outputArea = screen.getByTestId("agent-output-coder-1");
|
||||
expect(outputArea.textContent).toContain("plain output line");
|
||||
expect(
|
||||
screen.queryByText("Let me consider the problem carefully..."),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,6 @@ const { useCallback, useEffect, useRef, useState } = React;
|
||||
interface AgentState {
|
||||
agentName: string;
|
||||
status: AgentStatusValue;
|
||||
log: string[];
|
||||
sessionId: string | null;
|
||||
worktreePath: string | null;
|
||||
baseBranch: string | null;
|
||||
@@ -120,7 +119,6 @@ export function AgentPanel({
|
||||
const current = prev[key] ?? {
|
||||
agentName,
|
||||
status: "pending" as AgentStatusValue,
|
||||
log: [],
|
||||
sessionId: null,
|
||||
worktreePath: null,
|
||||
baseBranch: null,
|
||||
@@ -144,14 +142,6 @@ export function AgentPanel({
|
||||
},
|
||||
};
|
||||
}
|
||||
case "output":
|
||||
return {
|
||||
...prev,
|
||||
[key]: {
|
||||
...current,
|
||||
log: [...current.log, event.text ?? ""],
|
||||
},
|
||||
};
|
||||
case "done":
|
||||
return {
|
||||
...prev,
|
||||
@@ -168,17 +158,12 @@ export function AgentPanel({
|
||||
[key]: {
|
||||
...current,
|
||||
status: "failed",
|
||||
log: [
|
||||
...current.log,
|
||||
`[ERROR] ${event.message ?? "Unknown error"}`,
|
||||
],
|
||||
terminalAt: current.terminalAt ?? Date.now(),
|
||||
},
|
||||
};
|
||||
case "thinking":
|
||||
// Thinking traces are internal model state — never display them.
|
||||
return prev;
|
||||
default:
|
||||
// output, thinking, and other events are not displayed in the sidebar.
|
||||
// Agent output streams appear in the work item detail panel instead.
|
||||
return prev;
|
||||
}
|
||||
});
|
||||
@@ -204,7 +189,6 @@ export function AgentPanel({
|
||||
agentMap[key] = {
|
||||
agentName: a.agent_name,
|
||||
status: a.status,
|
||||
log: [],
|
||||
sessionId: a.session_id,
|
||||
worktreePath: a.worktree_path,
|
||||
baseBranch: a.base_branch,
|
||||
@@ -261,9 +245,6 @@ export function AgentPanel({
|
||||
}
|
||||
};
|
||||
|
||||
// Agents that have streaming content to show
|
||||
const activeAgents = Object.values(agents).filter((a) => a.log.length > 0);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
@@ -420,35 +401,6 @@ export function AgentPanel({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Per-agent streaming output */}
|
||||
{activeAgents.map((agent) => (
|
||||
<div
|
||||
key={`stream-${agent.agentName}`}
|
||||
data-testid={`agent-stream-${agent.agentName}`}
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "4px",
|
||||
}}
|
||||
>
|
||||
{agent.log.length > 0 && (
|
||||
<div
|
||||
data-testid={`agent-output-${agent.agentName}`}
|
||||
style={{
|
||||
fontSize: "0.8em",
|
||||
fontFamily: "monospace",
|
||||
color: "#ccc",
|
||||
whiteSpace: "pre-wrap",
|
||||
wordBreak: "break-word",
|
||||
lineHeight: "1.5",
|
||||
}}
|
||||
>
|
||||
{agent.log.join("")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{actionError && (
|
||||
<div
|
||||
style={{
|
||||
|
||||
@@ -26,6 +26,8 @@ type WsHandlers = {
|
||||
) => void;
|
||||
};
|
||||
let capturedWsHandlers: WsHandlers | null = null;
|
||||
// Captures the last sendChat call's arguments for assertion.
|
||||
let lastSendChatArgs: { messages: Message[]; config: unknown } | null = null;
|
||||
|
||||
vi.mock("../api/client", () => {
|
||||
const api = {
|
||||
@@ -36,13 +38,17 @@ vi.mock("../api/client", () => {
|
||||
setModelPreference: vi.fn(),
|
||||
cancelChat: vi.fn(),
|
||||
setAnthropicApiKey: vi.fn(),
|
||||
readFile: vi.fn(),
|
||||
listProjectFiles: vi.fn(),
|
||||
};
|
||||
class ChatWebSocket {
|
||||
connect(handlers: WsHandlers) {
|
||||
capturedWsHandlers = handlers;
|
||||
}
|
||||
close() {}
|
||||
sendChat() {}
|
||||
sendChat(messages: Message[], config: unknown) {
|
||||
lastSendChatArgs = { messages, config };
|
||||
}
|
||||
cancel() {}
|
||||
}
|
||||
return { api, ChatWebSocket };
|
||||
@@ -56,6 +62,8 @@ const mockedApi = {
|
||||
setModelPreference: vi.mocked(api.setModelPreference),
|
||||
cancelChat: vi.mocked(api.cancelChat),
|
||||
setAnthropicApiKey: vi.mocked(api.setAnthropicApiKey),
|
||||
readFile: vi.mocked(api.readFile),
|
||||
listProjectFiles: vi.mocked(api.listProjectFiles),
|
||||
};
|
||||
|
||||
function setupMocks() {
|
||||
@@ -64,6 +72,8 @@ function setupMocks() {
|
||||
mockedApi.getAnthropicModels.mockResolvedValue([]);
|
||||
mockedApi.getModelPreference.mockResolvedValue(null);
|
||||
mockedApi.setModelPreference.mockResolvedValue(true);
|
||||
mockedApi.readFile.mockResolvedValue("");
|
||||
mockedApi.listProjectFiles.mockResolvedValue([]);
|
||||
mockedApi.cancelChat.mockResolvedValue(true);
|
||||
mockedApi.setAnthropicApiKey.mockResolvedValue(true);
|
||||
}
|
||||
@@ -580,6 +590,66 @@ describe("Chat localStorage persistence (Story 145)", () => {
|
||||
expect(storedAfterRemount).toEqual(history);
|
||||
});
|
||||
|
||||
it("Bug 245: after refresh, sendChat includes full prior history", async () => {
|
||||
// Step 1: Render, populate messages via onUpdate, then unmount (simulate refresh)
|
||||
const { unmount } = render(
|
||||
<Chat projectPath={PROJECT_PATH} onCloseProject={vi.fn()} />,
|
||||
);
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
const priorHistory: Message[] = [
|
||||
{ role: "user", content: "What is Rust?" },
|
||||
{ role: "assistant", content: "Rust is a systems programming language." },
|
||||
];
|
||||
act(() => {
|
||||
capturedWsHandlers?.onUpdate(priorHistory);
|
||||
});
|
||||
|
||||
// Verify localStorage has the prior history
|
||||
const stored = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "[]");
|
||||
expect(stored).toEqual(priorHistory);
|
||||
|
||||
unmount();
|
||||
|
||||
// Step 2: Remount (simulates page reload) — messages load from localStorage
|
||||
capturedWsHandlers = null;
|
||||
lastSendChatArgs = null;
|
||||
render(<Chat projectPath={PROJECT_PATH} onCloseProject={vi.fn()} />);
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
// Verify prior messages are displayed
|
||||
expect(await screen.findByText("What is Rust?")).toBeInTheDocument();
|
||||
|
||||
// Step 3: Send a new message — sendChat should include the full prior history
|
||||
const input = screen.getByPlaceholderText("Send a message...");
|
||||
await act(async () => {
|
||||
fireEvent.change(input, { target: { value: "Tell me more" } });
|
||||
});
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(input, { key: "Enter", shiftKey: false });
|
||||
});
|
||||
|
||||
// Verify sendChat was called with ALL prior messages + the new one
|
||||
expect(lastSendChatArgs).not.toBeNull();
|
||||
const args = lastSendChatArgs as unknown as {
|
||||
messages: Message[];
|
||||
config: unknown;
|
||||
};
|
||||
expect(args.messages).toHaveLength(3);
|
||||
expect(args.messages[0]).toEqual({
|
||||
role: "user",
|
||||
content: "What is Rust?",
|
||||
});
|
||||
expect(args.messages[1]).toEqual({
|
||||
role: "assistant",
|
||||
content: "Rust is a systems programming language.",
|
||||
});
|
||||
expect(args.messages[2]).toEqual({
|
||||
role: "user",
|
||||
content: "Tell me more",
|
||||
});
|
||||
});
|
||||
|
||||
it("AC5: uses project-scoped storage key", async () => {
|
||||
const otherKey = "storykit-chat-history:/other/project";
|
||||
localStorage.setItem(
|
||||
@@ -1215,3 +1285,175 @@ describe("Remove bubble styling from streaming messages (Story 163)", () => {
|
||||
expect(styleAttr).not.toContain("background: transparent");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Bug 264: Claude Code session ID persisted across browser refresh", () => {
|
||||
const PROJECT_PATH = "/tmp/project";
|
||||
const SESSION_KEY = `storykit-claude-session-id:${PROJECT_PATH}`;
|
||||
const STORAGE_KEY = `storykit-chat-history:${PROJECT_PATH}`;
|
||||
|
||||
beforeEach(() => {
|
||||
capturedWsHandlers = null;
|
||||
lastSendChatArgs = null;
|
||||
localStorage.clear();
|
||||
setupMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
it("AC1: session_id is persisted to localStorage when onSessionId fires", async () => {
|
||||
render(<Chat projectPath={PROJECT_PATH} onCloseProject={vi.fn()} />);
|
||||
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
act(() => {
|
||||
capturedWsHandlers?.onSessionId("test-session-abc");
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(localStorage.getItem(SESSION_KEY)).toBe("test-session-abc");
|
||||
});
|
||||
});
|
||||
|
||||
it("AC2: after remount, next sendChat includes session_id from localStorage", async () => {
|
||||
// Step 1: Render, receive a session ID, then unmount (simulate refresh)
|
||||
localStorage.setItem(SESSION_KEY, "persisted-session-xyz");
|
||||
localStorage.setItem(
|
||||
STORAGE_KEY,
|
||||
JSON.stringify([
|
||||
{ role: "user", content: "Prior message" },
|
||||
{ role: "assistant", content: "Prior reply" },
|
||||
]),
|
||||
);
|
||||
|
||||
const { unmount } = render(
|
||||
<Chat projectPath={PROJECT_PATH} onCloseProject={vi.fn()} />,
|
||||
);
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
unmount();
|
||||
|
||||
// Step 2: Remount (simulates page reload)
|
||||
capturedWsHandlers = null;
|
||||
lastSendChatArgs = null;
|
||||
render(<Chat projectPath={PROJECT_PATH} onCloseProject={vi.fn()} />);
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
// Prior messages should be visible
|
||||
expect(await screen.findByText("Prior message")).toBeInTheDocument();
|
||||
|
||||
// Step 3: Send a new message — config should include session_id
|
||||
const input = screen.getByPlaceholderText("Send a message...");
|
||||
await act(async () => {
|
||||
fireEvent.change(input, { target: { value: "Continue" } });
|
||||
});
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(input, { key: "Enter", shiftKey: false });
|
||||
});
|
||||
|
||||
expect(lastSendChatArgs).not.toBeNull();
|
||||
expect(
|
||||
(
|
||||
(
|
||||
lastSendChatArgs as unknown as {
|
||||
messages: Message[];
|
||||
config: unknown;
|
||||
}
|
||||
)?.config as Record<string, unknown>
|
||||
).session_id,
|
||||
).toBe("persisted-session-xyz");
|
||||
});
|
||||
|
||||
it("AC3: clearing the session also clears the persisted session_id", async () => {
|
||||
localStorage.setItem(SESSION_KEY, "session-to-clear");
|
||||
|
||||
const confirmSpy = vi.spyOn(window, "confirm").mockReturnValue(true);
|
||||
|
||||
render(<Chat projectPath={PROJECT_PATH} onCloseProject={vi.fn()} />);
|
||||
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
const newSessionBtn = screen.getByText(/New Session/);
|
||||
await act(async () => {
|
||||
fireEvent.click(newSessionBtn);
|
||||
});
|
||||
|
||||
expect(localStorage.getItem(SESSION_KEY)).toBeNull();
|
||||
|
||||
confirmSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("AC1: storage key is scoped to project path", async () => {
|
||||
const otherPath = "/other/project";
|
||||
const otherKey = `storykit-claude-session-id:${otherPath}`;
|
||||
localStorage.setItem(otherKey, "other-session");
|
||||
|
||||
render(<Chat projectPath={PROJECT_PATH} onCloseProject={vi.fn()} />);
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
act(() => {
|
||||
capturedWsHandlers?.onSessionId("my-session");
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(localStorage.getItem(SESSION_KEY)).toBe("my-session");
|
||||
});
|
||||
|
||||
// Other project's session should be untouched
|
||||
expect(localStorage.getItem(otherKey)).toBe("other-session");
|
||||
});
|
||||
});
|
||||
|
||||
describe("File reference expansion (Story 269 AC4)", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
capturedWsHandlers = null;
|
||||
lastSendChatArgs = null;
|
||||
setupMocks();
|
||||
});
|
||||
|
||||
it("includes file contents as context when message contains @file reference", async () => {
|
||||
mockedApi.readFile.mockResolvedValue('fn main() { println!("hello"); }');
|
||||
|
||||
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
const input = screen.getByPlaceholderText("Send a message...");
|
||||
await act(async () => {
|
||||
fireEvent.change(input, { target: { value: "explain @src/main.rs" } });
|
||||
});
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(input, { key: "Enter", shiftKey: false });
|
||||
});
|
||||
|
||||
await waitFor(() => expect(lastSendChatArgs).not.toBeNull());
|
||||
const sentMessages = (
|
||||
lastSendChatArgs as NonNullable<typeof lastSendChatArgs>
|
||||
).messages;
|
||||
const userMsg = sentMessages[sentMessages.length - 1];
|
||||
expect(userMsg.content).toContain("explain @src/main.rs");
|
||||
expect(userMsg.content).toContain("[File: src/main.rs]");
|
||||
expect(userMsg.content).toContain("fn main()");
|
||||
});
|
||||
|
||||
it("sends message without modification when no @file references are present", async () => {
|
||||
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
|
||||
await waitFor(() => expect(capturedWsHandlers).not.toBeNull());
|
||||
|
||||
const input = screen.getByPlaceholderText("Send a message...");
|
||||
await act(async () => {
|
||||
fireEvent.change(input, { target: { value: "hello world" } });
|
||||
});
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(input, { key: "Enter", shiftKey: false });
|
||||
});
|
||||
|
||||
await waitFor(() => expect(lastSendChatArgs).not.toBeNull());
|
||||
const sentMessages = (
|
||||
lastSendChatArgs as NonNullable<typeof lastSendChatArgs>
|
||||
).messages;
|
||||
const userMsg = sentMessages[sentMessages.length - 1];
|
||||
expect(userMsg.content).toBe("hello world");
|
||||
expect(mockedApi.readFile).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -165,13 +165,22 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
|
||||
const [apiKeyInput, setApiKeyInput] = useState("");
|
||||
const [hasAnthropicKey, setHasAnthropicKey] = useState(false);
|
||||
const [pipeline, setPipeline] = useState<PipelineState>({
|
||||
upcoming: [],
|
||||
backlog: [],
|
||||
current: [],
|
||||
qa: [],
|
||||
merge: [],
|
||||
done: [],
|
||||
});
|
||||
const [claudeSessionId, setClaudeSessionId] = useState<string | null>(null);
|
||||
const [claudeSessionId, setClaudeSessionId] = useState<string | null>(() => {
|
||||
try {
|
||||
return (
|
||||
localStorage.getItem(`storykit-claude-session-id:${projectPath}`) ??
|
||||
null
|
||||
);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
const [activityStatus, setActivityStatus] = useState<string | null>(null);
|
||||
const [permissionQueue, setPermissionQueue] = useState<
|
||||
{
|
||||
@@ -247,6 +256,21 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
|
||||
};
|
||||
}, [messages, streamingContent, model]);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (claudeSessionId !== null) {
|
||||
localStorage.setItem(
|
||||
`storykit-claude-session-id:${projectPath}`,
|
||||
claudeSessionId,
|
||||
);
|
||||
} else {
|
||||
localStorage.removeItem(`storykit-claude-session-id:${projectPath}`);
|
||||
}
|
||||
} catch {
|
||||
// Ignore — quota or security errors.
|
||||
}
|
||||
}, [claudeSessionId, projectPath]);
|
||||
|
||||
useEffect(() => {
|
||||
api
|
||||
.getOllamaModels()
|
||||
@@ -530,7 +554,26 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const userMsg: Message = { role: "user", content: messageText };
|
||||
// Expand @file references: append file contents as context
|
||||
const fileRefs = [...messageText.matchAll(/(^|[\s\n])@([^\s@]+)/g)].map(
|
||||
(m) => m[2],
|
||||
);
|
||||
let expandedText = messageText;
|
||||
if (fileRefs.length > 0) {
|
||||
const expansions = await Promise.allSettled(
|
||||
fileRefs.map(async (ref) => {
|
||||
const contents = await api.readFile(ref);
|
||||
return { ref, contents };
|
||||
}),
|
||||
);
|
||||
for (const result of expansions) {
|
||||
if (result.status === "fulfilled") {
|
||||
expandedText += `\n\n[File: ${result.value.ref}]\n\`\`\`\n${result.value.contents}\n\`\`\``;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const userMsg: Message = { role: "user", content: expandedText };
|
||||
const newHistory = [...messages, userMsg];
|
||||
|
||||
setMessages(newHistory);
|
||||
@@ -664,6 +707,11 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
|
||||
setLoading(false);
|
||||
setActivityStatus(null);
|
||||
setClaudeSessionId(null);
|
||||
try {
|
||||
localStorage.removeItem(`storykit-claude-session-id:${projectPath}`);
|
||||
} catch {
|
||||
// Ignore — quota or security errors.
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -969,8 +1017,8 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
|
||||
onItemClick={(item) => setSelectedWorkItemId(item.story_id)}
|
||||
/>
|
||||
<StagePanel
|
||||
title="Upcoming"
|
||||
items={pipeline.upcoming}
|
||||
title="Backlog"
|
||||
items={pipeline.backlog}
|
||||
onItemClick={(item) => setSelectedWorkItemId(item.story_id)}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import * as React from "react";
|
||||
import { api } from "../api/client";
|
||||
|
||||
const { forwardRef, useEffect, useImperativeHandle, useRef, useState } = React;
|
||||
const {
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
useState,
|
||||
} = React;
|
||||
|
||||
export interface ChatInputHandle {
|
||||
appendToInput(text: string): void;
|
||||
@@ -14,6 +22,97 @@ interface ChatInputProps {
|
||||
onRemoveQueuedMessage: (id: string) => void;
|
||||
}
|
||||
|
||||
/** Fuzzy-match: returns true if all chars of `query` appear in order in `str`. */
|
||||
function fuzzyMatch(str: string, query: string): boolean {
|
||||
if (!query) return true;
|
||||
const lower = str.toLowerCase();
|
||||
const q = query.toLowerCase();
|
||||
let qi = 0;
|
||||
for (let i = 0; i < lower.length && qi < q.length; i++) {
|
||||
if (lower[i] === q[qi]) qi++;
|
||||
}
|
||||
return qi === q.length;
|
||||
}
|
||||
|
||||
/** Score a fuzzy match: lower is better. Exact prefix match wins, then shorter paths. */
|
||||
function fuzzyScore(str: string, query: string): number {
|
||||
const lower = str.toLowerCase();
|
||||
const q = query.toLowerCase();
|
||||
// Prefer matches where query appears as a contiguous substring
|
||||
if (lower.includes(q)) return lower.indexOf(q);
|
||||
return str.length;
|
||||
}
|
||||
|
||||
interface FilePickerOverlayProps {
|
||||
query: string;
|
||||
files: string[];
|
||||
selectedIndex: number;
|
||||
onSelect: (file: string) => void;
|
||||
onDismiss: () => void;
|
||||
anchorRef: React.RefObject<HTMLTextAreaElement | null>;
|
||||
}
|
||||
|
||||
function FilePickerOverlay({
|
||||
query,
|
||||
files,
|
||||
selectedIndex,
|
||||
onSelect,
|
||||
}: FilePickerOverlayProps) {
|
||||
const filtered = files
|
||||
.filter((f) => fuzzyMatch(f, query))
|
||||
.sort((a, b) => fuzzyScore(a, query) - fuzzyScore(b, query))
|
||||
.slice(0, 10);
|
||||
|
||||
if (filtered.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="file-picker-overlay"
|
||||
style={{
|
||||
position: "absolute",
|
||||
bottom: "100%",
|
||||
left: 0,
|
||||
right: 0,
|
||||
background: "#1e1e1e",
|
||||
border: "1px solid #444",
|
||||
borderRadius: "8px",
|
||||
marginBottom: "6px",
|
||||
overflow: "hidden",
|
||||
zIndex: 100,
|
||||
boxShadow: "0 4px 16px rgba(0,0,0,0.4)",
|
||||
maxHeight: "240px",
|
||||
overflowY: "auto",
|
||||
}}
|
||||
>
|
||||
{filtered.map((file, idx) => (
|
||||
<button
|
||||
key={file}
|
||||
type="button"
|
||||
data-testid={`file-picker-item-${idx}`}
|
||||
onClick={() => onSelect(file)}
|
||||
style={{
|
||||
display: "block",
|
||||
width: "100%",
|
||||
textAlign: "left",
|
||||
padding: "8px 14px",
|
||||
background: idx === selectedIndex ? "#2d4a6e" : "transparent",
|
||||
border: "none",
|
||||
color: idx === selectedIndex ? "#ececec" : "#aaa",
|
||||
cursor: "pointer",
|
||||
fontFamily: "monospace",
|
||||
fontSize: "0.85rem",
|
||||
whiteSpace: "nowrap",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
}}
|
||||
>
|
||||
{file}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||
function ChatInput(
|
||||
{ loading, queuedMessages, onSubmit, onCancel, onRemoveQueuedMessage },
|
||||
@@ -22,6 +121,12 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||
const [input, setInput] = useState("");
|
||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
// File picker state
|
||||
const [projectFiles, setProjectFiles] = useState<string[]>([]);
|
||||
const [pickerQuery, setPickerQuery] = useState<string | null>(null);
|
||||
const [pickerSelectedIndex, setPickerSelectedIndex] = useState(0);
|
||||
const [pickerAtStart, setPickerAtStart] = useState(0);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
appendToInput(text: string) {
|
||||
setInput((prev) => (prev ? `${prev}\n${text}` : text));
|
||||
@@ -32,10 +137,118 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||
inputRef.current?.focus();
|
||||
}, []);
|
||||
|
||||
// Compute filtered files for current picker query
|
||||
const filteredFiles =
|
||||
pickerQuery !== null
|
||||
? projectFiles
|
||||
.filter((f) => fuzzyMatch(f, pickerQuery))
|
||||
.sort(
|
||||
(a, b) => fuzzyScore(a, pickerQuery) - fuzzyScore(b, pickerQuery),
|
||||
)
|
||||
.slice(0, 10)
|
||||
: [];
|
||||
|
||||
const dismissPicker = useCallback(() => {
|
||||
setPickerQuery(null);
|
||||
setPickerSelectedIndex(0);
|
||||
}, []);
|
||||
|
||||
const selectFile = useCallback(
|
||||
(file: string) => {
|
||||
// Replace the @query portion with @file
|
||||
const before = input.slice(0, pickerAtStart);
|
||||
const cursorPos = inputRef.current?.selectionStart ?? input.length;
|
||||
const after = input.slice(cursorPos);
|
||||
setInput(`${before}@${file}${after}`);
|
||||
dismissPicker();
|
||||
// Restore focus after state update
|
||||
setTimeout(() => inputRef.current?.focus(), 0);
|
||||
},
|
||||
[input, pickerAtStart, dismissPicker],
|
||||
);
|
||||
|
||||
const handleInputChange = useCallback(
|
||||
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const val = e.target.value;
|
||||
setInput(val);
|
||||
|
||||
const cursor = e.target.selectionStart ?? val.length;
|
||||
// Find the last @ before the cursor that starts a reference token
|
||||
const textUpToCursor = val.slice(0, cursor);
|
||||
// Match @ not preceded by non-whitespace (i.e. @ at start or after space/newline)
|
||||
const atMatch = textUpToCursor.match(/(^|[\s\n])@([^\s@]*)$/);
|
||||
|
||||
if (atMatch) {
|
||||
const query = atMatch[2];
|
||||
const atPos = textUpToCursor.lastIndexOf("@");
|
||||
setPickerAtStart(atPos);
|
||||
setPickerQuery(query);
|
||||
setPickerSelectedIndex(0);
|
||||
|
||||
// Lazily load files on first trigger
|
||||
if (projectFiles.length === 0) {
|
||||
api
|
||||
.listProjectFiles()
|
||||
.then(setProjectFiles)
|
||||
.catch(() => {});
|
||||
}
|
||||
} else {
|
||||
if (pickerQuery !== null) dismissPicker();
|
||||
}
|
||||
},
|
||||
[projectFiles.length, pickerQuery, dismissPicker],
|
||||
);
|
||||
|
||||
const handleKeyDown = useCallback(
|
||||
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (pickerQuery !== null && filteredFiles.length > 0) {
|
||||
if (e.key === "ArrowDown") {
|
||||
e.preventDefault();
|
||||
setPickerSelectedIndex((i) =>
|
||||
Math.min(i + 1, filteredFiles.length - 1),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (e.key === "ArrowUp") {
|
||||
e.preventDefault();
|
||||
setPickerSelectedIndex((i) => Math.max(i - 1, 0));
|
||||
return;
|
||||
}
|
||||
if (e.key === "Enter" || e.key === "Tab") {
|
||||
e.preventDefault();
|
||||
selectFile(filteredFiles[pickerSelectedIndex] ?? filteredFiles[0]);
|
||||
return;
|
||||
}
|
||||
if (e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
dismissPicker();
|
||||
return;
|
||||
}
|
||||
} else if (e.key === "Escape" && pickerQuery !== null) {
|
||||
e.preventDefault();
|
||||
dismissPicker();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSubmit();
|
||||
}
|
||||
},
|
||||
[
|
||||
pickerQuery,
|
||||
filteredFiles,
|
||||
pickerSelectedIndex,
|
||||
selectFile,
|
||||
dismissPicker,
|
||||
],
|
||||
);
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!input.trim()) return;
|
||||
onSubmit(input);
|
||||
setInput("");
|
||||
dismissPicker();
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -135,24 +348,30 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
{/* Input row */}
|
||||
{/* Input row with file picker overlay */}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "8px",
|
||||
alignItems: "center",
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
{pickerQuery !== null && (
|
||||
<FilePickerOverlay
|
||||
query={pickerQuery}
|
||||
files={projectFiles}
|
||||
selectedIndex={pickerSelectedIndex}
|
||||
onSelect={selectFile}
|
||||
onDismiss={dismissPicker}
|
||||
anchorRef={inputRef}
|
||||
/>
|
||||
)}
|
||||
<textarea
|
||||
ref={inputRef}
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSubmit();
|
||||
}
|
||||
}}
|
||||
onChange={handleInputChange}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Send a message..."
|
||||
rows={1}
|
||||
style={{
|
||||
|
||||
194
frontend/src/components/ChatInputFilePicker.test.tsx
Normal file
194
frontend/src/components/ChatInputFilePicker.test.tsx
Normal file
@@ -0,0 +1,194 @@
|
||||
import {
|
||||
act,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
} from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { api } from "../api/client";
|
||||
import { ChatInput } from "./ChatInput";
|
||||
|
||||
vi.mock("../api/client", () => ({
|
||||
api: {
|
||||
listProjectFiles: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const mockedListProjectFiles = vi.mocked(api.listProjectFiles);
|
||||
|
||||
const defaultProps = {
|
||||
loading: false,
|
||||
queuedMessages: [],
|
||||
onSubmit: vi.fn(),
|
||||
onCancel: vi.fn(),
|
||||
onRemoveQueuedMessage: vi.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockedListProjectFiles.mockResolvedValue([
|
||||
"src/main.rs",
|
||||
"src/lib.rs",
|
||||
"frontend/index.html",
|
||||
"README.md",
|
||||
]);
|
||||
});
|
||||
|
||||
describe("File picker overlay (Story 269 AC1)", () => {
|
||||
it("shows file picker overlay when @ is typed", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "@" } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-overlay")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("does not show file picker overlay for text without @", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "hello world" } });
|
||||
});
|
||||
|
||||
expect(screen.queryByTestId("file-picker-overlay")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("File picker fuzzy matching (Story 269 AC2)", () => {
|
||||
it("filters files by query typed after @", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "@main" } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-overlay")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// main.rs should be visible, README.md should not
|
||||
expect(screen.getByText("src/main.rs")).toBeInTheDocument();
|
||||
expect(screen.queryByText("README.md")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows all files when @ is typed with no query", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "@" } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-overlay")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// All 4 files should be visible
|
||||
expect(screen.getByText("src/main.rs")).toBeInTheDocument();
|
||||
expect(screen.getByText("src/lib.rs")).toBeInTheDocument();
|
||||
expect(screen.getByText("README.md")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("File picker selection (Story 269 AC3)", () => {
|
||||
it("clicking a file inserts @path into the message", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "@" } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-item-0")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByTestId("file-picker-item-0"));
|
||||
});
|
||||
|
||||
// Picker should be dismissed and the file reference inserted
|
||||
expect(screen.queryByTestId("file-picker-overlay")).not.toBeInTheDocument();
|
||||
expect((textarea as HTMLTextAreaElement).value).toMatch(/^@\S+/);
|
||||
});
|
||||
|
||||
it("Enter key selects highlighted file and inserts it into message", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "@main" } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-overlay")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(textarea, { key: "Enter" });
|
||||
});
|
||||
|
||||
expect(screen.queryByTestId("file-picker-overlay")).not.toBeInTheDocument();
|
||||
expect((textarea as HTMLTextAreaElement).value).toContain("@src/main.rs");
|
||||
});
|
||||
});
|
||||
|
||||
describe("File picker dismiss (Story 269 AC5)", () => {
|
||||
it("Escape key dismisses the file picker", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "@" } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-overlay")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(textarea, { key: "Escape" });
|
||||
});
|
||||
|
||||
expect(screen.queryByTestId("file-picker-overlay")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Multiple @ references (Story 269 AC6)", () => {
|
||||
it("typing @ after a completed reference triggers picker again", async () => {
|
||||
render(<ChatInput {...defaultProps} />);
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
// First reference
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "@main" } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-overlay")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Select file
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(textarea, { key: "Enter" });
|
||||
});
|
||||
|
||||
// Type a second @
|
||||
await act(async () => {
|
||||
const current = (textarea as HTMLTextAreaElement).value;
|
||||
fireEvent.change(textarea, { target: { value: `${current} @` } });
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("file-picker-overlay")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -9,7 +9,7 @@ import { StagePanel } from "./StagePanel";
|
||||
|
||||
function makePipeline(overrides: Partial<PipelineState> = {}): PipelineState {
|
||||
return {
|
||||
upcoming: [],
|
||||
backlog: [],
|
||||
current: [],
|
||||
qa: [],
|
||||
merge: [],
|
||||
|
||||
@@ -115,7 +115,7 @@ export function LozengeFlyProvider({
|
||||
const assignedAgentNames = useMemo(() => {
|
||||
const names = new Set<string>();
|
||||
for (const item of [
|
||||
...pipeline.upcoming,
|
||||
...pipeline.backlog,
|
||||
...pipeline.current,
|
||||
...pipeline.qa,
|
||||
...pipeline.merge,
|
||||
@@ -165,13 +165,13 @@ export function LozengeFlyProvider({
|
||||
|
||||
const prev = prevPipelineRef.current;
|
||||
const allPrev = [
|
||||
...prev.upcoming,
|
||||
...prev.backlog,
|
||||
...prev.current,
|
||||
...prev.qa,
|
||||
...prev.merge,
|
||||
];
|
||||
const allCurr = [
|
||||
...pipeline.upcoming,
|
||||
...pipeline.backlog,
|
||||
...pipeline.current,
|
||||
...pipeline.qa,
|
||||
...pipeline.merge,
|
||||
|
||||
@@ -37,6 +37,7 @@ const DEFAULT_CONTENT = {
|
||||
content: "# Big Title\n\nSome content here.",
|
||||
stage: "current",
|
||||
name: "Big Title Story",
|
||||
agent: null,
|
||||
};
|
||||
|
||||
const sampleTestResults: TestResultsResponse = {
|
||||
@@ -436,6 +437,60 @@ describe("WorkItemDetailPanel - Agent Logs", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("WorkItemDetailPanel - Assigned Agent", () => {
|
||||
it("shows assigned agent name when agent front matter field is set", async () => {
|
||||
mockedGetWorkItemContent.mockResolvedValue({
|
||||
...DEFAULT_CONTENT,
|
||||
agent: "coder-opus",
|
||||
});
|
||||
|
||||
render(
|
||||
<WorkItemDetailPanel
|
||||
storyId="271_story_test"
|
||||
pipelineVersion={0}
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const agentEl = await screen.findByTestId("detail-panel-assigned-agent");
|
||||
expect(agentEl).toHaveTextContent("coder-opus");
|
||||
});
|
||||
|
||||
it("omits assigned agent field when no agent is set in front matter", async () => {
|
||||
render(
|
||||
<WorkItemDetailPanel
|
||||
storyId="271_story_test"
|
||||
pipelineVersion={0}
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await screen.findByTestId("detail-panel-content");
|
||||
expect(
|
||||
screen.queryByTestId("detail-panel-assigned-agent"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the specific agent name not just 'assigned'", async () => {
|
||||
mockedGetWorkItemContent.mockResolvedValue({
|
||||
...DEFAULT_CONTENT,
|
||||
agent: "coder-haiku",
|
||||
});
|
||||
|
||||
render(
|
||||
<WorkItemDetailPanel
|
||||
storyId="271_story_test"
|
||||
pipelineVersion={0}
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const agentEl = await screen.findByTestId("detail-panel-assigned-agent");
|
||||
expect(agentEl).toHaveTextContent("coder-haiku");
|
||||
expect(agentEl).not.toHaveTextContent("assigned");
|
||||
});
|
||||
});
|
||||
|
||||
describe("WorkItemDetailPanel - Test Results", () => {
|
||||
it("shows empty test results message when no results exist", async () => {
|
||||
mockedGetTestResults.mockResolvedValue(null);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { api } from "../api/client";
|
||||
const { useEffect, useRef, useState } = React;
|
||||
|
||||
const STAGE_LABELS: Record<string, string> = {
|
||||
upcoming: "Upcoming",
|
||||
backlog: "Backlog",
|
||||
current: "Current",
|
||||
qa: "QA",
|
||||
merge: "To Merge",
|
||||
@@ -113,6 +113,7 @@ export function WorkItemDetailPanel({
|
||||
const [content, setContent] = useState<string | null>(null);
|
||||
const [stage, setStage] = useState<string>("");
|
||||
const [name, setName] = useState<string | null>(null);
|
||||
const [assignedAgent, setAssignedAgent] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [agentInfo, setAgentInfo] = useState<AgentInfo | null>(null);
|
||||
@@ -133,6 +134,7 @@ export function WorkItemDetailPanel({
|
||||
setContent(data.content);
|
||||
setStage(data.stage);
|
||||
setName(data.name);
|
||||
setAssignedAgent(data.agent);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
setError(err instanceof Error ? err.message : "Failed to load content");
|
||||
@@ -278,6 +280,14 @@ export function WorkItemDetailPanel({
|
||||
{stageLabel}
|
||||
</div>
|
||||
)}
|
||||
{assignedAgent ? (
|
||||
<div
|
||||
data-testid="detail-panel-assigned-agent"
|
||||
style={{ fontSize: "0.75em", color: "#888" }}
|
||||
>
|
||||
Agent: {assignedAgent}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@@ -410,75 +420,96 @@ export function WorkItemDetailPanel({
|
||||
}}
|
||||
>
|
||||
{/* Agent Logs section */}
|
||||
<div
|
||||
data-testid={
|
||||
agentInfo ? "agent-logs-section" : "placeholder-agent-logs"
|
||||
}
|
||||
style={{
|
||||
border: "1px solid #2a2a2a",
|
||||
borderRadius: "8px",
|
||||
padding: "10px 12px",
|
||||
background: "#161616",
|
||||
}}
|
||||
>
|
||||
{!agentInfo && (
|
||||
<div
|
||||
data-testid="placeholder-agent-logs"
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
marginBottom: agentInfo ? "6px" : "4px",
|
||||
border: "1px solid #2a2a2a",
|
||||
borderRadius: "8px",
|
||||
padding: "10px 12px",
|
||||
background: "#161616",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
fontWeight: 600,
|
||||
fontSize: "0.8em",
|
||||
color: agentInfo ? "#888" : "#555",
|
||||
color: "#555",
|
||||
marginBottom: "4px",
|
||||
}}
|
||||
>
|
||||
Agent Logs
|
||||
</div>
|
||||
{agentInfo && agentStatus && (
|
||||
<div
|
||||
data-testid="agent-status-badge"
|
||||
style={{
|
||||
fontSize: "0.7em",
|
||||
color: STATUS_COLORS[agentStatus],
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{agentInfo.agent_name} — {agentStatus}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{agentInfo && agentLog.length > 0 ? (
|
||||
<div
|
||||
data-testid="agent-log-output"
|
||||
style={{
|
||||
fontSize: "0.75em",
|
||||
fontFamily: "monospace",
|
||||
color: "#ccc",
|
||||
whiteSpace: "pre-wrap",
|
||||
wordBreak: "break-word",
|
||||
lineHeight: "1.5",
|
||||
maxHeight: "200px",
|
||||
overflowY: "auto",
|
||||
}}
|
||||
>
|
||||
{agentLog.join("")}
|
||||
</div>
|
||||
) : agentInfo ? (
|
||||
<div style={{ fontSize: "0.75em", color: "#444" }}>
|
||||
{agentStatus === "running" || agentStatus === "pending"
|
||||
? "Waiting for output..."
|
||||
: "No output."}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ fontSize: "0.75em", color: "#444" }}>
|
||||
Coming soon
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{agentInfo && (
|
||||
<div
|
||||
data-testid="agent-logs-section"
|
||||
style={{
|
||||
border: "1px solid #2a2a2a",
|
||||
borderRadius: "8px",
|
||||
padding: "10px 12px",
|
||||
background: "#161616",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
marginBottom: "6px",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
fontWeight: 600,
|
||||
fontSize: "0.8em",
|
||||
color: "#888",
|
||||
}}
|
||||
>
|
||||
Agent Logs
|
||||
</div>
|
||||
{agentStatus && (
|
||||
<div
|
||||
data-testid="agent-status-badge"
|
||||
style={{
|
||||
fontSize: "0.7em",
|
||||
color: STATUS_COLORS[agentStatus],
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{agentInfo.agent_name} — {agentStatus}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{agentLog.length > 0 ? (
|
||||
<div
|
||||
data-testid="agent-log-output"
|
||||
style={{
|
||||
fontSize: "0.75em",
|
||||
fontFamily: "monospace",
|
||||
color: "#ccc",
|
||||
whiteSpace: "pre-wrap",
|
||||
wordBreak: "break-word",
|
||||
lineHeight: "1.5",
|
||||
maxHeight: "200px",
|
||||
overflowY: "auto",
|
||||
}}
|
||||
>
|
||||
{agentLog.join("")}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ fontSize: "0.75em", color: "#444" }}>
|
||||
{agentStatus === "running" || agentStatus === "pending"
|
||||
? "Waiting for output..."
|
||||
: "No output."}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Placeholder sections for future content */}
|
||||
{(
|
||||
|
||||
@@ -16,8 +16,25 @@ export default defineConfig(() => {
|
||||
"/api": {
|
||||
target: `http://127.0.0.1:${String(backendPort)}`,
|
||||
timeout: 120000,
|
||||
configure: (proxy) => {
|
||||
proxy.on("error", (_err) => {
|
||||
// Swallow proxy errors (e.g. ECONNREFUSED during backend restart)
|
||||
// so the vite dev server doesn't crash.
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
ignored: [
|
||||
"**/.story_kit/**",
|
||||
"**/target/**",
|
||||
"**/.git/**",
|
||||
"**/server/**",
|
||||
"**/Cargo.*",
|
||||
"**/vendor/**",
|
||||
"**/node_modules/**",
|
||||
],
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: "dist",
|
||||
|
||||
@@ -71,20 +71,93 @@ ls -lh "${DIST}"/
|
||||
echo "==> Generating changelog..."
|
||||
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
||||
if [ -n "$PREV_TAG" ]; then
|
||||
CHANGELOG=$(git log "${PREV_TAG}..HEAD" --pretty=format:"- %s" --no-merges)
|
||||
LOG_RANGE="${PREV_TAG}..HEAD"
|
||||
RANGE="${PREV_TAG}...${TAG}"
|
||||
else
|
||||
CHANGELOG=$(git log --pretty=format:"- %s" --no-merges)
|
||||
LOG_RANGE=""
|
||||
RANGE="initial...${TAG}"
|
||||
fi
|
||||
|
||||
if [ -z "$CHANGELOG" ]; then
|
||||
CHANGELOG="- No changes since last release"
|
||||
# Extract completed stories/bugs/refactors from "story-kit: merge <id>" commits.
|
||||
# Deduplicate (a story may have been merged more than once after reverts).
|
||||
if [ -n "$LOG_RANGE" ]; then
|
||||
MERGED_RAW=$(git log "$LOG_RANGE" --pretty=format:"%s" --no-merges \
|
||||
| grep "^story-kit: merge " | sed 's/^story-kit: merge //' | sort -u)
|
||||
else
|
||||
MERGED_RAW=$(git log --pretty=format:"%s" --no-merges \
|
||||
| grep "^story-kit: merge " | sed 's/^story-kit: merge //' | sort -u)
|
||||
fi
|
||||
|
||||
RELEASE_BODY="## What's Changed
|
||||
# Categorise merged work items and format names.
|
||||
FEATURES=""
|
||||
FIXES=""
|
||||
REFACTORS=""
|
||||
while IFS= read -r item; do
|
||||
[ -z "$item" ] && continue
|
||||
# Strip the numeric prefix and type to get the human name.
|
||||
name=$(echo "$item" | sed -E 's/^[0-9]+_(story|bug|refactor|spike)_//' | tr '_' ' ')
|
||||
# Capitalise first letter.
|
||||
name="$(echo "${name:0:1}" | tr '[:lower:]' '[:upper:]')${name:1}"
|
||||
case "$item" in
|
||||
*_bug_*) FIXES="${FIXES}- ${name}\n" ;;
|
||||
*_refactor_*) REFACTORS="${REFACTORS}- ${name}\n" ;;
|
||||
*) FEATURES="${FEATURES}- ${name}\n" ;;
|
||||
esac
|
||||
done <<< "$MERGED_RAW"
|
||||
|
||||
${CHANGELOG}
|
||||
# Collect non-automation manual commits (direct fixes, version bumps, etc).
|
||||
if [ -n "$LOG_RANGE" ]; then
|
||||
MANUAL=$(git log "$LOG_RANGE" --pretty=format:"%s" --no-merges \
|
||||
| grep -v "^story-kit: " \
|
||||
| grep -v "^Revert \"story-kit: " \
|
||||
| grep -v "^Bump version" \
|
||||
| sed 's/^/- /')
|
||||
else
|
||||
MANUAL=$(git log --pretty=format:"%s" --no-merges \
|
||||
| grep -v "^story-kit: " \
|
||||
| grep -v "^Revert \"story-kit: " \
|
||||
| grep -v "^Bump version" \
|
||||
| sed 's/^/- /')
|
||||
fi
|
||||
|
||||
# Assemble the release body.
|
||||
RELEASE_BODY="## What's Changed"
|
||||
|
||||
if [ -n "$FEATURES" ]; then
|
||||
RELEASE_BODY="${RELEASE_BODY}
|
||||
|
||||
### Features
|
||||
$(echo -e "$FEATURES")"
|
||||
fi
|
||||
|
||||
if [ -n "$FIXES" ]; then
|
||||
RELEASE_BODY="${RELEASE_BODY}
|
||||
|
||||
### Bug Fixes
|
||||
$(echo -e "$FIXES")"
|
||||
fi
|
||||
|
||||
if [ -n "$REFACTORS" ]; then
|
||||
RELEASE_BODY="${RELEASE_BODY}
|
||||
|
||||
### Refactors
|
||||
$(echo -e "$REFACTORS")"
|
||||
fi
|
||||
|
||||
if [ -n "$MANUAL" ]; then
|
||||
RELEASE_BODY="${RELEASE_BODY}
|
||||
|
||||
### Other Changes
|
||||
${MANUAL}"
|
||||
fi
|
||||
|
||||
if [ -z "$FEATURES" ] && [ -z "$FIXES" ] && [ -z "$REFACTORS" ] && [ -z "$MANUAL" ]; then
|
||||
RELEASE_BODY="${RELEASE_BODY}
|
||||
|
||||
- No changes since last release"
|
||||
fi
|
||||
|
||||
RELEASE_BODY="${RELEASE_BODY}
|
||||
|
||||
**Full diff:** ${GITEA_URL}/${REPO}/compare/${RANGE}"
|
||||
|
||||
|
||||
@@ -8,8 +8,12 @@ echo "=== Running Rust tests ==="
|
||||
cargo test --manifest-path "$PROJECT_ROOT/Cargo.toml"
|
||||
|
||||
echo "=== Running frontend unit tests ==="
|
||||
cd "$PROJECT_ROOT/frontend"
|
||||
npm test
|
||||
if [ -d "$PROJECT_ROOT/frontend" ]; then
|
||||
cd "$PROJECT_ROOT/frontend"
|
||||
npm test
|
||||
else
|
||||
echo "Skipping frontend tests (no frontend directory)"
|
||||
fi
|
||||
|
||||
# Disabled: e2e tests may be causing merge pipeline hangs (no running server
|
||||
# in merge workspace → Playwright blocks indefinitely). Re-enable once confirmed.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "story-kit"
|
||||
version = "0.1.0"
|
||||
version = "0.3.1"
|
||||
edition = "2024"
|
||||
build = "build.rs"
|
||||
|
||||
@@ -32,10 +32,7 @@ matrix-sdk = { workspace = true }
|
||||
pulldown-cmark = { workspace = true }
|
||||
|
||||
# Force bundled SQLite so static musl builds don't need a system libsqlite3
|
||||
libsqlite3-sys = { version = "0.37.0", features = ["bundled"] }
|
||||
# Enable fallible_uint feature to restore u64/usize ToSql/FromSql impls needed
|
||||
# by matrix-sdk-sqlite (removed in rusqlite 0.38+ without this feature flag)
|
||||
rusqlite = { version = "0.37.99", features = ["fallible_uint"] }
|
||||
libsqlite3-sys = { version = "0.35.0", features = ["bundled"] }
|
||||
wait-timeout = "0.2.1"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -4,8 +4,7 @@ use std::process::Command;
|
||||
use crate::io::story_metadata::clear_front_matter_field;
|
||||
use crate::slog;
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn item_type_from_id(item_id: &str) -> &'static str {
|
||||
pub(super) fn item_type_from_id(item_id: &str) -> &'static str {
|
||||
// New format: {digits}_{type}_{slug}
|
||||
let after_num = item_id.trim_start_matches(|c: char| c.is_ascii_digit());
|
||||
if after_num.starts_with("_bug_") {
|
||||
@@ -17,9 +16,9 @@ fn item_type_from_id(item_id: &str) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the source directory path for a work item (always work/1_upcoming/).
|
||||
/// Return the source directory path for a work item (always work/1_backlog/).
|
||||
fn item_source_dir(project_root: &Path, _item_id: &str) -> PathBuf {
|
||||
project_root.join(".story_kit").join("work").join("1_upcoming")
|
||||
project_root.join(".story_kit").join("work").join("1_backlog")
|
||||
}
|
||||
|
||||
/// Return the done directory path for a work item (always work/5_done/).
|
||||
@@ -27,10 +26,10 @@ fn item_archive_dir(project_root: &Path, _item_id: &str) -> PathBuf {
|
||||
project_root.join(".story_kit").join("work").join("5_done")
|
||||
}
|
||||
|
||||
/// Move a work item (story, bug, or spike) from `work/1_upcoming/` to `work/2_current/`.
|
||||
/// Move a work item (story, bug, or spike) from `work/1_backlog/` to `work/2_current/`.
|
||||
///
|
||||
/// Idempotent: if the item is already in `2_current/`, returns Ok without committing.
|
||||
/// If the item is not found in `1_upcoming/`, logs a warning and returns Ok.
|
||||
/// If the item is not found in `1_backlog/`, logs a warning and returns Ok.
|
||||
pub fn move_story_to_current(project_root: &Path, story_id: &str) -> Result<(), String> {
|
||||
let sk = project_root.join(".story_kit").join("work");
|
||||
let current_dir = sk.join("2_current");
|
||||
@@ -220,16 +219,16 @@ pub fn move_story_to_qa(project_root: &Path, story_id: &str) -> Result<(), Strin
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Move a bug from `work/2_current/` or `work/1_upcoming/` to `work/5_done/` and auto-commit.
|
||||
/// Move a bug from `work/2_current/` or `work/1_backlog/` to `work/5_done/` and auto-commit.
|
||||
///
|
||||
/// * If the bug is in `2_current/`, it is moved to `5_done/` and committed.
|
||||
/// * If the bug is still in `1_upcoming/` (never started), it is moved directly to `5_done/`.
|
||||
/// * If the bug is still in `1_backlog/` (never started), it is moved directly to `5_done/`.
|
||||
/// * If the bug is already in `5_done/`, this is a no-op (idempotent).
|
||||
/// * If the bug is not found anywhere, an error is returned.
|
||||
pub fn close_bug_to_archive(project_root: &Path, bug_id: &str) -> Result<(), String> {
|
||||
let sk = project_root.join(".story_kit").join("work");
|
||||
let current_path = sk.join("2_current").join(format!("{bug_id}.md"));
|
||||
let upcoming_path = sk.join("1_upcoming").join(format!("{bug_id}.md"));
|
||||
let backlog_path = sk.join("1_backlog").join(format!("{bug_id}.md"));
|
||||
let archive_dir = item_archive_dir(project_root, bug_id);
|
||||
let archive_path = archive_dir.join(format!("{bug_id}.md"));
|
||||
|
||||
@@ -239,11 +238,11 @@ pub fn close_bug_to_archive(project_root: &Path, bug_id: &str) -> Result<(), Str
|
||||
|
||||
let source_path = if current_path.exists() {
|
||||
current_path.clone()
|
||||
} else if upcoming_path.exists() {
|
||||
upcoming_path.clone()
|
||||
} else if backlog_path.exists() {
|
||||
backlog_path.clone()
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Bug '{bug_id}' not found in work/2_current/ or work/1_upcoming/. Cannot close bug."
|
||||
"Bug '{bug_id}' not found in work/2_current/ or work/1_backlog/. Cannot close bug."
|
||||
));
|
||||
};
|
||||
|
||||
@@ -270,15 +269,15 @@ mod tests {
|
||||
use std::fs;
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path();
|
||||
let upcoming = root.join(".story_kit/work/1_upcoming");
|
||||
let backlog = root.join(".story_kit/work/1_backlog");
|
||||
let current = root.join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(upcoming.join("10_story_foo.md"), "test").unwrap();
|
||||
fs::write(backlog.join("10_story_foo.md"), "test").unwrap();
|
||||
|
||||
move_story_to_current(root, "10_story_foo").unwrap();
|
||||
|
||||
assert!(!upcoming.join("10_story_foo.md").exists());
|
||||
assert!(!backlog.join("10_story_foo.md").exists());
|
||||
assert!(current.join("10_story_foo.md").exists());
|
||||
}
|
||||
|
||||
@@ -296,25 +295,25 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_story_to_current_noop_when_not_in_upcoming() {
|
||||
fn move_story_to_current_noop_when_not_in_backlog() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
assert!(move_story_to_current(tmp.path(), "99_missing").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_bug_to_current_moves_from_upcoming() {
|
||||
fn move_bug_to_current_moves_from_backlog() {
|
||||
use std::fs;
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path();
|
||||
let upcoming = root.join(".story_kit/work/1_upcoming");
|
||||
let backlog = root.join(".story_kit/work/1_backlog");
|
||||
let current = root.join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(upcoming.join("1_bug_test.md"), "# Bug 1\n").unwrap();
|
||||
fs::write(backlog.join("1_bug_test.md"), "# Bug 1\n").unwrap();
|
||||
|
||||
move_story_to_current(root, "1_bug_test").unwrap();
|
||||
|
||||
assert!(!upcoming.join("1_bug_test.md").exists());
|
||||
assert!(!backlog.join("1_bug_test.md").exists());
|
||||
assert!(current.join("1_bug_test.md").exists());
|
||||
}
|
||||
|
||||
@@ -336,17 +335,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn close_bug_moves_from_upcoming_when_not_started() {
|
||||
fn close_bug_moves_from_backlog_when_not_started() {
|
||||
use std::fs;
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path();
|
||||
let upcoming = root.join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join("3_bug_test.md"), "# Bug 3\n").unwrap();
|
||||
let backlog = root.join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(backlog.join("3_bug_test.md"), "# Bug 3\n").unwrap();
|
||||
|
||||
close_bug_to_archive(root, "3_bug_test").unwrap();
|
||||
|
||||
assert!(!upcoming.join("3_bug_test.md").exists());
|
||||
assert!(!backlog.join("3_bug_test.md").exists());
|
||||
assert!(root.join(".story_kit/work/5_done/3_bug_test.md").exists());
|
||||
}
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ impl AgentPool {
|
||||
let event_log: Arc<Mutex<Vec<AgentEvent>>> = Arc::new(Mutex::new(Vec::new()));
|
||||
let log_session_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
// Move story from upcoming/ to current/ before checking agent
|
||||
// Move story from backlog/ to current/ before checking agent
|
||||
// availability so that auto_assign_available_work can pick it up even
|
||||
// when all coders are currently busy (story 203). This is idempotent:
|
||||
// if the story is already in 2_current/ or a later stage, the call is
|
||||
@@ -889,21 +889,39 @@ impl AgentPool {
|
||||
};
|
||||
|
||||
if coverage_passed {
|
||||
slog!(
|
||||
"[pipeline] QA passed gates and coverage for '{story_id}'. Moving to merge."
|
||||
);
|
||||
if let Err(e) = super::lifecycle::move_story_to_merge(&project_root, story_id) {
|
||||
slog_error!("[pipeline] Failed to move '{story_id}' to 4_merge/: {e}");
|
||||
return;
|
||||
// Spikes skip merge — they stay in 3_qa/ for human review.
|
||||
if super::lifecycle::item_type_from_id(story_id) == "spike" {
|
||||
// Mark the spike as held for review so auto-assign won't
|
||||
// restart QA on it.
|
||||
let qa_dir = project_root.join(".story_kit/work/3_qa");
|
||||
let spike_path = qa_dir.join(format!("{story_id}.md"));
|
||||
if let Err(e) = crate::io::story_metadata::write_review_hold(&spike_path) {
|
||||
slog_error!("[pipeline] Failed to set review_hold on '{story_id}': {e}");
|
||||
}
|
||||
slog!(
|
||||
"[pipeline] QA passed for spike '{story_id}'. \
|
||||
Stopping for human review (skipping merge). \
|
||||
Worktree preserved at: {worktree_path:?}"
|
||||
);
|
||||
// Free up the QA slot without advancing the spike.
|
||||
self.auto_assign_available_work(&project_root).await;
|
||||
} else {
|
||||
slog!(
|
||||
"[pipeline] QA passed gates and coverage for '{story_id}'. Moving to merge."
|
||||
);
|
||||
if let Err(e) = super::lifecycle::move_story_to_merge(&project_root, story_id) {
|
||||
slog_error!("[pipeline] Failed to move '{story_id}' to 4_merge/: {e}");
|
||||
return;
|
||||
}
|
||||
if let Err(e) = self
|
||||
.start_agent(&project_root, story_id, Some("mergemaster"), None)
|
||||
.await
|
||||
{
|
||||
slog_error!("[pipeline] Failed to start mergemaster for '{story_id}': {e}");
|
||||
}
|
||||
// QA slot is now free — pick up any other unassigned work in 3_qa/.
|
||||
self.auto_assign_available_work(&project_root).await;
|
||||
}
|
||||
if let Err(e) = self
|
||||
.start_agent(&project_root, story_id, Some("mergemaster"), None)
|
||||
.await
|
||||
{
|
||||
slog_error!("[pipeline] Failed to start mergemaster for '{story_id}': {e}");
|
||||
}
|
||||
// QA slot is now free — pick up any other unassigned work in 3_qa/.
|
||||
self.auto_assign_available_work(&project_root).await;
|
||||
} else {
|
||||
slog!(
|
||||
"[pipeline] QA coverage gate failed for '{story_id}'. Restarting QA."
|
||||
@@ -1275,11 +1293,6 @@ impl AgentPool {
|
||||
.and_then(|jobs| jobs.get(story_id).cloned())
|
||||
}
|
||||
|
||||
/// Return the port this server is running on.
|
||||
pub fn port(&self) -> u16 {
|
||||
self.port
|
||||
}
|
||||
|
||||
/// Get project root helper.
|
||||
pub fn get_project_root(
|
||||
&self,
|
||||
@@ -1417,7 +1430,7 @@ impl AgentPool {
|
||||
///
|
||||
/// Scans `work/2_current/`, `work/3_qa/`, and `work/4_merge/` for items that have no
|
||||
/// active agent and assigns the first free agent of the appropriate role. Items in
|
||||
/// `work/1_upcoming/` are never auto-started.
|
||||
/// `work/1_backlog/` are never auto-started.
|
||||
///
|
||||
/// Respects the configured agent roster: the maximum number of concurrently active agents
|
||||
/// per role is bounded by the count of agents of that role defined in `project.toml`.
|
||||
@@ -1444,15 +1457,23 @@ impl AgentPool {
|
||||
}
|
||||
|
||||
for story_id in &items {
|
||||
// Items marked with review_hold (e.g. spikes after QA passes) stay
|
||||
// in their current stage for human review — don't auto-assign agents.
|
||||
if has_review_hold(project_root, stage_dir, story_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Re-acquire the lock on each iteration to see state changes
|
||||
// from previous start_agent calls in the same pass.
|
||||
let preferred_agent =
|
||||
read_story_front_matter_agent(project_root, stage_dir, story_id);
|
||||
|
||||
// Outcome: (already_assigned, chosen_agent, preferred_busy)
|
||||
// Outcome: (already_assigned, chosen_agent, preferred_busy, stage_mismatch)
|
||||
// preferred_busy=true means the story has a specific agent requested but it is
|
||||
// currently occupied — the story should wait rather than fall back.
|
||||
let (already_assigned, free_agent, preferred_busy) = {
|
||||
// stage_mismatch=true means the preferred agent's stage doesn't match the
|
||||
// pipeline stage, so we fell back to a generic stage agent.
|
||||
let (already_assigned, free_agent, preferred_busy, stage_mismatch) = {
|
||||
let agents = match self.agents.lock() {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
@@ -1462,18 +1483,29 @@ impl AgentPool {
|
||||
};
|
||||
let assigned = is_story_assigned_for_stage(&config, &agents, story_id, stage);
|
||||
if assigned {
|
||||
(true, None, false)
|
||||
(true, None, false, false)
|
||||
} else if let Some(ref pref) = preferred_agent {
|
||||
// Story has a front-matter agent preference.
|
||||
if is_agent_free(&agents, pref) {
|
||||
(false, Some(pref.clone()), false)
|
||||
// Verify the preferred agent's stage matches the current
|
||||
// pipeline stage — a coder shouldn't be assigned to QA.
|
||||
let pref_stage_matches = config
|
||||
.find_agent(pref)
|
||||
.map(|cfg| agent_config_stage(cfg) == *stage)
|
||||
.unwrap_or(false);
|
||||
if !pref_stage_matches {
|
||||
// Stage mismatch — fall back to any free agent for this stage.
|
||||
let free = find_free_agent_for_stage(&config, &agents, stage)
|
||||
.map(|s| s.to_string());
|
||||
(false, free, false, true)
|
||||
} else if is_agent_free(&agents, pref) {
|
||||
(false, Some(pref.clone()), false, false)
|
||||
} else {
|
||||
(false, None, true)
|
||||
(false, None, true, false)
|
||||
}
|
||||
} else {
|
||||
let free = find_free_agent_for_stage(&config, &agents, stage)
|
||||
.map(|s| s.to_string());
|
||||
(false, free, false)
|
||||
(false, free, false, false)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1492,6 +1524,13 @@ impl AgentPool {
|
||||
continue;
|
||||
}
|
||||
|
||||
if stage_mismatch {
|
||||
slog!(
|
||||
"[auto-assign] Preferred agent '{}' stage mismatch for '{story_id}' in {stage_dir}/; falling back to stage-appropriate agent.",
|
||||
preferred_agent.as_deref().unwrap_or("?")
|
||||
);
|
||||
}
|
||||
|
||||
match free_agent {
|
||||
Some(agent_name) => {
|
||||
slog!(
|
||||
@@ -1564,7 +1603,7 @@ impl AgentPool {
|
||||
// Determine which active stage the story is in.
|
||||
let stage_dir = match find_active_story_stage(project_root, story_id) {
|
||||
Some(s) => s,
|
||||
None => continue, // Not in any active stage (upcoming/archived or unknown).
|
||||
None => continue, // Not in any active stage (backlog/archived or unknown).
|
||||
};
|
||||
|
||||
// 4_merge/ is left for auto_assign to handle with a fresh mergemaster.
|
||||
@@ -1707,7 +1746,25 @@ impl AgentPool {
|
||||
};
|
||||
|
||||
if coverage_passed {
|
||||
if let Err(e) = super::lifecycle::move_story_to_merge(project_root, story_id) {
|
||||
// Spikes skip the merge stage — stay in 3_qa/ for human review.
|
||||
if super::lifecycle::item_type_from_id(story_id) == "spike" {
|
||||
let spike_path = project_root
|
||||
.join(".story_kit/work/3_qa")
|
||||
.join(format!("{story_id}.md"));
|
||||
if let Err(e) = crate::io::story_metadata::write_review_hold(&spike_path) {
|
||||
eprintln!(
|
||||
"[startup:reconcile] Failed to set review_hold on spike '{story_id}': {e}"
|
||||
);
|
||||
}
|
||||
eprintln!(
|
||||
"[startup:reconcile] Spike '{story_id}' passed QA — holding for human review."
|
||||
);
|
||||
let _ = progress_tx.send(ReconciliationEvent {
|
||||
story_id: story_id.clone(),
|
||||
status: "review_hold".to_string(),
|
||||
message: "Spike passed QA — waiting for human review.".to_string(),
|
||||
});
|
||||
} else if let Err(e) = super::lifecycle::move_story_to_merge(project_root, story_id) {
|
||||
eprintln!(
|
||||
"[startup:reconcile] Failed to move '{story_id}' to 4_merge/: {e}"
|
||||
);
|
||||
@@ -1922,6 +1979,24 @@ fn read_story_front_matter_agent(project_root: &Path, stage_dir: &str, story_id:
|
||||
parse_front_matter(&contents).ok()?.agent
|
||||
}
|
||||
|
||||
/// Return `true` if the story file in the given stage has `review_hold: true` in its front matter.
|
||||
fn has_review_hold(project_root: &Path, stage_dir: &str, story_id: &str) -> bool {
|
||||
use crate::io::story_metadata::parse_front_matter;
|
||||
let path = project_root
|
||||
.join(".story_kit")
|
||||
.join("work")
|
||||
.join(stage_dir)
|
||||
.join(format!("{story_id}.md"));
|
||||
let contents = match std::fs::read_to_string(path) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return false,
|
||||
};
|
||||
parse_front_matter(&contents)
|
||||
.ok()
|
||||
.and_then(|m| m.review_hold)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Return `true` if `agent_name` has no active (pending/running) entry in the pool.
|
||||
fn is_agent_free(agents: &HashMap<String, StoryAgent>, agent_name: &str) -> bool {
|
||||
!agents.values().any(|a| {
|
||||
@@ -2653,8 +2728,8 @@ mod tests {
|
||||
fs::write(current.join("173_story_test.md"), "test").unwrap();
|
||||
// Ensure 3_qa/ exists for the move target
|
||||
fs::create_dir_all(root.join(".story_kit/work/3_qa")).unwrap();
|
||||
// Ensure 1_upcoming/ exists (start_agent calls move_story_to_current)
|
||||
fs::create_dir_all(root.join(".story_kit/work/1_upcoming")).unwrap();
|
||||
// Ensure 1_backlog/ exists (start_agent calls move_story_to_current)
|
||||
fs::create_dir_all(root.join(".story_kit/work/1_backlog")).unwrap();
|
||||
|
||||
// Write a project.toml with a qa agent so start_agent can resolve it.
|
||||
fs::create_dir_all(root.join(".story_kit")).unwrap();
|
||||
@@ -3423,14 +3498,14 @@ stage = "coder"
|
||||
}
|
||||
|
||||
/// Story 203: when all coders are busy the story file must be moved from
|
||||
/// 1_upcoming/ to 2_current/ so that auto_assign_available_work can pick
|
||||
/// 1_backlog/ to 2_current/ so that auto_assign_available_work can pick
|
||||
/// it up once a coder finishes.
|
||||
#[tokio::test]
|
||||
async fn start_agent_moves_story_to_current_when_coders_busy() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
let upcoming = sk.join("work/1_upcoming");
|
||||
std::fs::create_dir_all(&upcoming).unwrap();
|
||||
let backlog = sk.join("work/1_backlog");
|
||||
std::fs::create_dir_all(&backlog).unwrap();
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
r#"
|
||||
@@ -3440,9 +3515,9 @@ stage = "coder"
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
// Place the story in 1_upcoming/.
|
||||
// Place the story in 1_backlog/.
|
||||
std::fs::write(
|
||||
upcoming.join("story-3.md"),
|
||||
backlog.join("story-3.md"),
|
||||
"---\nname: Story 3\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -3472,10 +3547,10 @@ stage = "coder"
|
||||
current_path.exists(),
|
||||
"story should be in 2_current/ after busy error, but was not"
|
||||
);
|
||||
let upcoming_path = upcoming.join("story-3.md");
|
||||
let backlog_path = backlog.join("story-3.md");
|
||||
assert!(
|
||||
!upcoming_path.exists(),
|
||||
"story should no longer be in 1_upcoming/"
|
||||
!backlog_path.exists(),
|
||||
"story should no longer be in 1_backlog/"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3699,7 +3774,7 @@ stage = "coder"
|
||||
|
||||
// Create the story in upcoming so `move_story_to_current` succeeds,
|
||||
// but do NOT init a git repo — `create_worktree` will fail in the spawn.
|
||||
let upcoming = root.join(".story_kit/work/1_upcoming");
|
||||
let upcoming = root.join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(
|
||||
upcoming.join("50_story_test.md"),
|
||||
@@ -3849,7 +3924,7 @@ stage = "coder"
|
||||
let root = tmp.path().to_path_buf();
|
||||
|
||||
let sk_dir = root.join(".story_kit");
|
||||
fs::create_dir_all(sk_dir.join("work/1_upcoming")).unwrap();
|
||||
fs::create_dir_all(sk_dir.join("work/1_backlog")).unwrap();
|
||||
fs::write(
|
||||
root.join(".story_kit/project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\n",
|
||||
@@ -3858,12 +3933,12 @@ stage = "coder"
|
||||
// Both stories must exist in upcoming so move_story_to_current can run
|
||||
// (only the winner reaches that point, but we set both up defensively).
|
||||
fs::write(
|
||||
root.join(".story_kit/work/1_upcoming/86_story_foo.md"),
|
||||
root.join(".story_kit/work/1_backlog/86_story_foo.md"),
|
||||
"---\nname: Foo\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
root.join(".story_kit/work/1_upcoming/130_story_bar.md"),
|
||||
root.join(".story_kit/work/1_backlog/130_story_bar.md"),
|
||||
"---\nname: Bar\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -4063,14 +4138,14 @@ stage = "coder"
|
||||
let root = tmp.path();
|
||||
|
||||
let sk_dir = root.join(".story_kit");
|
||||
fs::create_dir_all(sk_dir.join("work/1_upcoming")).unwrap();
|
||||
fs::create_dir_all(sk_dir.join("work/1_backlog")).unwrap();
|
||||
fs::write(
|
||||
root.join(".story_kit/project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\n\n[[agent]]\nname = \"coder-2\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
root.join(".story_kit/work/1_upcoming/99_story_baz.md"),
|
||||
root.join(".story_kit/work/1_backlog/99_story_baz.md"),
|
||||
"---\nname: Baz\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -4621,4 +4696,202 @@ stage = "coder"
|
||||
"story should be in 2_current/ or 3_qa/ after reconciliation"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_review_hold_returns_true_when_set() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let qa_dir = tmp.path().join(".story_kit/work/3_qa");
|
||||
std::fs::create_dir_all(&qa_dir).unwrap();
|
||||
let spike_path = qa_dir.join("10_spike_research.md");
|
||||
std::fs::write(
|
||||
&spike_path,
|
||||
"---\nname: Research spike\nreview_hold: true\n---\n# Spike\n",
|
||||
)
|
||||
.unwrap();
|
||||
assert!(has_review_hold(tmp.path(), "3_qa", "10_spike_research"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_review_hold_returns_false_when_not_set() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let qa_dir = tmp.path().join(".story_kit/work/3_qa");
|
||||
std::fs::create_dir_all(&qa_dir).unwrap();
|
||||
let spike_path = qa_dir.join("10_spike_research.md");
|
||||
std::fs::write(
|
||||
&spike_path,
|
||||
"---\nname: Research spike\n---\n# Spike\n",
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!has_review_hold(tmp.path(), "3_qa", "10_spike_research"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_review_hold_returns_false_when_file_missing() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
assert!(!has_review_hold(tmp.path(), "3_qa", "99_spike_missing"));
|
||||
}
|
||||
|
||||
/// Story 265: auto_assign_available_work must skip spikes in 3_qa/ that
|
||||
/// have review_hold: true set in their front matter.
|
||||
#[tokio::test]
|
||||
async fn auto_assign_skips_spikes_with_review_hold() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path();
|
||||
|
||||
// Create project.toml with a QA agent.
|
||||
let sk = root.join(".story_kit");
|
||||
std::fs::create_dir_all(&sk).unwrap();
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
"[[agents]]\nname = \"qa\"\nrole = \"qa\"\nmodel = \"test\"\nprompt = \"test\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Put a spike in 3_qa/ with review_hold: true.
|
||||
let qa_dir = root.join(".story_kit/work/3_qa");
|
||||
std::fs::create_dir_all(&qa_dir).unwrap();
|
||||
std::fs::write(
|
||||
qa_dir.join("20_spike_test.md"),
|
||||
"---\nname: Test Spike\nreview_hold: true\n---\n# Spike\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (watcher_tx, _) = broadcast::channel::<WatcherEvent>(4);
|
||||
let pool = AgentPool::new(3001, watcher_tx);
|
||||
|
||||
pool.auto_assign_available_work(root).await;
|
||||
|
||||
// No agent should have been started for the spike.
|
||||
let agents = pool.agents.lock().unwrap();
|
||||
assert!(
|
||||
agents.is_empty(),
|
||||
"No agents should be assigned to a spike with review_hold"
|
||||
);
|
||||
}
|
||||
|
||||
// ── Story 279: auto-assign respects agent stage from front matter ──────────
|
||||
|
||||
/// When a story in 3_qa/ has `agent: coder-1` in its front matter but
|
||||
/// coder-1 is a coder-stage agent, auto-assign must NOT assign coder-1.
|
||||
/// Instead it should fall back to a free QA-stage agent.
|
||||
#[tokio::test]
|
||||
async fn auto_assign_ignores_coder_preference_when_story_is_in_qa_stage() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
let qa_dir = sk.join("work/3_qa");
|
||||
std::fs::create_dir_all(&qa_dir).unwrap();
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n\n\
|
||||
[[agent]]\nname = \"qa-1\"\nstage = \"qa\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
// Story in 3_qa/ with a preferred coder-stage agent.
|
||||
std::fs::write(
|
||||
qa_dir.join("story-qa1.md"),
|
||||
"---\nname: QA Story\nagent: coder-1\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
|
||||
pool.auto_assign_available_work(tmp.path()).await;
|
||||
|
||||
let agents = pool.agents.lock().unwrap();
|
||||
// coder-1 must NOT have been assigned (wrong stage for 3_qa/).
|
||||
let coder_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "coder-1" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
!coder_assigned,
|
||||
"coder-1 should not be assigned to a QA-stage story"
|
||||
);
|
||||
// qa-1 should have been assigned instead.
|
||||
let qa_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "qa-1" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
qa_assigned,
|
||||
"qa-1 should be assigned as fallback for the QA-stage story"
|
||||
);
|
||||
}
|
||||
|
||||
/// When a story in 2_current/ has `agent: coder-1` in its front matter and
|
||||
/// coder-1 is a coder-stage agent, auto-assign must respect the preference
|
||||
/// and assign coder-1 (not fall back to some other coder).
|
||||
#[tokio::test]
|
||||
async fn auto_assign_respects_coder_preference_when_story_is_in_current_stage() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
let current_dir = sk.join("work/2_current");
|
||||
std::fs::create_dir_all(¤t_dir).unwrap();
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n\n\
|
||||
[[agent]]\nname = \"coder-2\"\nstage = \"coder\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
// Story in 2_current/ with a preferred coder-1 agent.
|
||||
std::fs::write(
|
||||
current_dir.join("story-pref.md"),
|
||||
"---\nname: Coder Story\nagent: coder-1\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
|
||||
pool.auto_assign_available_work(tmp.path()).await;
|
||||
|
||||
let agents = pool.agents.lock().unwrap();
|
||||
// coder-1 should have been picked (it matches the stage and is preferred).
|
||||
let coder1_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "coder-1" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
coder1_assigned,
|
||||
"coder-1 should be assigned when it matches the stage and is preferred"
|
||||
);
|
||||
// coder-2 must NOT be assigned (not preferred).
|
||||
let coder2_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "coder-2" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
!coder2_assigned,
|
||||
"coder-2 should not be assigned when coder-1 is explicitly preferred"
|
||||
);
|
||||
}
|
||||
|
||||
/// When the preferred agent's stage mismatches and no other agent of the
|
||||
/// correct stage is available, auto-assign must not start any agent for that
|
||||
/// story (no panic, no error).
|
||||
#[tokio::test]
|
||||
async fn auto_assign_stage_mismatch_with_no_fallback_starts_no_agent() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
let qa_dir = sk.join("work/3_qa");
|
||||
std::fs::create_dir_all(&qa_dir).unwrap();
|
||||
// Only a coder agent is configured — no QA agent exists.
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
// Story in 3_qa/ requests coder-1 (wrong stage) and no QA agent exists.
|
||||
std::fs::write(
|
||||
qa_dir.join("story-noqa.md"),
|
||||
"---\nname: QA Story No Agent\nagent: coder-1\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
|
||||
// Must not panic.
|
||||
pool.auto_assign_available_work(tmp.path()).await;
|
||||
|
||||
let agents = pool.agents.lock().unwrap();
|
||||
assert!(
|
||||
agents.is_empty(),
|
||||
"No agent should be started when no stage-appropriate agent is available"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ struct WorkItemContentResponse {
|
||||
content: String,
|
||||
stage: String,
|
||||
name: Option<String>,
|
||||
agent: Option<String>,
|
||||
}
|
||||
|
||||
/// A single test case result for the OpenAPI response.
|
||||
@@ -338,7 +339,7 @@ impl AgentsApi {
|
||||
.map_err(bad_request)?;
|
||||
|
||||
let stages = [
|
||||
("1_upcoming", "upcoming"),
|
||||
("1_backlog", "backlog"),
|
||||
("2_current", "current"),
|
||||
("3_qa", "qa"),
|
||||
("4_merge", "merge"),
|
||||
@@ -354,13 +355,14 @@ impl AgentsApi {
|
||||
if file_path.exists() {
|
||||
let content = std::fs::read_to_string(&file_path)
|
||||
.map_err(|e| bad_request(format!("Failed to read work item: {e}")))?;
|
||||
let name = crate::io::story_metadata::parse_front_matter(&content)
|
||||
.ok()
|
||||
.and_then(|m| m.name);
|
||||
let metadata = crate::io::story_metadata::parse_front_matter(&content).ok();
|
||||
let name = metadata.as_ref().and_then(|m| m.name.clone());
|
||||
let agent = metadata.and_then(|m| m.agent);
|
||||
return Ok(Json(WorkItemContentResponse {
|
||||
content,
|
||||
stage: stage_name.to_string(),
|
||||
name,
|
||||
agent,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -807,12 +809,12 @@ allowed_tools = ["Read", "Bash"]
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_work_item_content_returns_content_from_upcoming() {
|
||||
async fn get_work_item_content_returns_content_from_backlog() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let root = tmp.path();
|
||||
make_stage_dir(root, "1_upcoming");
|
||||
make_stage_dir(root, "1_backlog");
|
||||
std::fs::write(
|
||||
root.join(".story_kit/work/1_upcoming/42_story_foo.md"),
|
||||
root.join(".story_kit/work/1_backlog/42_story_foo.md"),
|
||||
"---\nname: \"Foo Story\"\n---\n\n# Story 42: Foo Story\n\nSome content.",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -826,7 +828,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
.unwrap()
|
||||
.0;
|
||||
assert!(result.content.contains("Some content."));
|
||||
assert_eq!(result.stage, "upcoming");
|
||||
assert_eq!(result.stage, "backlog");
|
||||
assert_eq!(result.name, Some("Foo Story".to_string()));
|
||||
}
|
||||
|
||||
@@ -1111,7 +1113,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let root = tmp.path().to_path_buf();
|
||||
// Create work dirs including 2_current for the story file.
|
||||
for stage in &["1_upcoming", "2_current", "5_done", "6_archived"] {
|
||||
for stage in &["1_backlog", "2_current", "5_done", "6_archived"] {
|
||||
std::fs::create_dir_all(root.join(".story_kit").join("work").join(stage)).unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,15 @@ impl IoApi {
|
||||
Ok(Json(home))
|
||||
}
|
||||
|
||||
/// List all files in the project recursively, respecting .gitignore.
|
||||
#[oai(path = "/io/fs/files", method = "get")]
|
||||
async fn list_project_files(&self) -> OpenApiResult<Json<Vec<String>>> {
|
||||
let files = io_fs::list_project_files(&self.ctx.state)
|
||||
.await
|
||||
.map_err(bad_request)?;
|
||||
Ok(Json(files))
|
||||
}
|
||||
|
||||
/// Search the currently open project for files containing the provided query string.
|
||||
#[oai(path = "/io/search", method = "post")]
|
||||
async fn search_files(
|
||||
@@ -316,6 +325,53 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// --- list_project_files ---
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_returns_file_paths() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
std::fs::create_dir(dir.path().join("src")).unwrap();
|
||||
std::fs::write(dir.path().join("src/main.rs"), "fn main() {}").unwrap();
|
||||
std::fs::write(dir.path().join("README.md"), "# readme").unwrap();
|
||||
|
||||
let api = make_api(&dir);
|
||||
let result = api.list_project_files().await.unwrap();
|
||||
let files = &result.0;
|
||||
|
||||
assert!(files.contains(&"README.md".to_string()));
|
||||
assert!(files.contains(&"src/main.rs".to_string()));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_excludes_directories() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
std::fs::create_dir(dir.path().join("subdir")).unwrap();
|
||||
std::fs::write(dir.path().join("file.txt"), "").unwrap();
|
||||
|
||||
let api = make_api(&dir);
|
||||
let result = api.list_project_files().await.unwrap();
|
||||
let files = &result.0;
|
||||
|
||||
assert!(files.contains(&"file.txt".to_string()));
|
||||
// Directories should not appear
|
||||
assert!(!files.iter().any(|f| f == "subdir"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_returns_sorted_paths() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
std::fs::write(dir.path().join("z_last.txt"), "").unwrap();
|
||||
std::fs::write(dir.path().join("a_first.txt"), "").unwrap();
|
||||
|
||||
let api = make_api(&dir);
|
||||
let result = api.list_project_files().await.unwrap();
|
||||
let files = &result.0;
|
||||
|
||||
let a_idx = files.iter().position(|f| f == "a_first.txt").unwrap();
|
||||
let z_idx = files.iter().position(|f| f == "z_last.txt").unwrap();
|
||||
assert!(a_idx < z_idx);
|
||||
}
|
||||
|
||||
// --- list_directory (project-scoped) ---
|
||||
|
||||
#[tokio::test]
|
||||
@@ -345,4 +401,5 @@ mod tests {
|
||||
let result = api.list_directory(payload).await;
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::agents::{close_bug_to_archive, feature_branch_has_unmerged_changes, move_story_to_archived, move_story_to_merge, move_story_to_qa, PipelineStage};
|
||||
use crate::agents::{close_bug_to_archive, feature_branch_has_unmerged_changes, move_story_to_archived, move_story_to_merge, move_story_to_qa, AgentStatus, PipelineStage};
|
||||
use crate::config::ProjectConfig;
|
||||
use crate::log_buffer;
|
||||
use crate::slog;
|
||||
@@ -8,7 +8,7 @@ use crate::http::settings::get_editor_command_from_store;
|
||||
use crate::http::workflow::{
|
||||
add_criterion_to_file, check_criterion_in_file, create_bug_file, create_refactor_file,
|
||||
create_spike_file, create_story_file, list_bug_files, list_refactor_files,
|
||||
load_upcoming_stories, update_story_in_file, validate_story_dirs,
|
||||
load_pipeline_state, load_upcoming_stories, update_story_in_file, validate_story_dirs,
|
||||
};
|
||||
use crate::worktree;
|
||||
use crate::io::story_metadata::{parse_front_matter, parse_unchecked_todos, write_merge_failure};
|
||||
@@ -19,6 +19,7 @@ use poem::web::Data;
|
||||
use poem::{Body, Request, Response};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -638,7 +639,7 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
},
|
||||
{
|
||||
"name": "update_story",
|
||||
"description": "Update the user story text and/or description of an existing story file. Replaces the content of the '## User Story' and/or '## Description' section in place. Auto-commits via the filesystem watcher.",
|
||||
"description": "Update an existing story file. Can replace the '## User Story' and/or '## Description' section content, and/or set YAML front matter fields (e.g. agent, manual_qa). Auto-commits via the filesystem watcher.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -653,6 +654,17 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "New description text to replace the '## Description' section content"
|
||||
},
|
||||
"agent": {
|
||||
"type": "string",
|
||||
"description": "Set or change the 'agent' YAML front matter field"
|
||||
},
|
||||
"front_matter": {
|
||||
"type": "object",
|
||||
"description": "Arbitrary YAML front matter key-value pairs to set or update",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["story_id"]
|
||||
@@ -660,7 +672,7 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
},
|
||||
{
|
||||
"name": "create_spike",
|
||||
"description": "Create a spike file in .story_kit/work/1_upcoming/ with a deterministic filename and YAML front matter. Returns the spike_id.",
|
||||
"description": "Create a spike file in .story_kit/work/1_backlog/ with a deterministic filename and YAML front matter. Returns the spike_id.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -678,7 +690,7 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
},
|
||||
{
|
||||
"name": "create_bug",
|
||||
"description": "Create a bug file in work/1_upcoming/ with a deterministic filename and auto-commit to master. Returns the bug_id.",
|
||||
"description": "Create a bug file in work/1_backlog/ with a deterministic filename and auto-commit to master. Returns the bug_id.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -713,7 +725,7 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
},
|
||||
{
|
||||
"name": "list_bugs",
|
||||
"description": "List all open bugs in work/1_upcoming/ matching the _bug_ naming convention.",
|
||||
"description": "List all open bugs in work/1_backlog/ matching the _bug_ naming convention.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
@@ -721,7 +733,7 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
},
|
||||
{
|
||||
"name": "create_refactor",
|
||||
"description": "Create a refactor work item in work/1_upcoming/ with a deterministic filename and YAML front matter. Returns the refactor_id.",
|
||||
"description": "Create a refactor work item in work/1_backlog/ with a deterministic filename and YAML front matter. Returns the refactor_id.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -744,7 +756,7 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
},
|
||||
{
|
||||
"name": "list_refactors",
|
||||
"description": "List all open refactors in work/1_upcoming/ matching the _refactor_ naming convention.",
|
||||
"description": "List all open refactors in work/1_backlog/ matching the _refactor_ naming convention.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
@@ -752,7 +764,7 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
},
|
||||
{
|
||||
"name": "close_bug",
|
||||
"description": "Archive a bug from work/2_current/ or work/1_upcoming/ to work/5_done/ and auto-commit to master.",
|
||||
"description": "Archive a bug from work/2_current/ or work/1_backlog/ to work/5_done/ and auto-commit to master.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -850,6 +862,14 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
"required": ["story_id"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_pipeline_status",
|
||||
"description": "Return a structured snapshot of the full work item pipeline. Includes all active stages (current, qa, merge, done) with each item's stage, name, and assigned agent. Also includes upcoming backlog items.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_server_logs",
|
||||
"description": "Return recent server log lines captured in the in-process ring buffer. Useful for diagnosing runtime behaviour such as WebSocket events, MCP call flow, and filesystem watcher activity.",
|
||||
@@ -871,6 +891,14 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "rebuild_and_restart",
|
||||
"description": "Rebuild the server binary from source and re-exec with the new binary. Gracefully stops all running agents before restart. If the build fails, the server stays up and returns the build error.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "prompt_permission",
|
||||
"description": "Present a permission request to the user via the web UI. Used by Claude Code's --permission-prompt-tool to delegate permission decisions to the frontend dialog. Returns on approval; returns an error on denial.",
|
||||
@@ -951,8 +979,12 @@ async fn handle_tools_call(
|
||||
"report_merge_failure" => tool_report_merge_failure(&args, ctx),
|
||||
// QA tools
|
||||
"request_qa" => tool_request_qa(&args, ctx).await,
|
||||
// Pipeline status
|
||||
"get_pipeline_status" => tool_get_pipeline_status(ctx),
|
||||
// Diagnostics
|
||||
"get_server_logs" => tool_get_server_logs(&args),
|
||||
// Server lifecycle
|
||||
"rebuild_and_restart" => tool_rebuild_and_restart(ctx).await,
|
||||
// Permission bridge (Claude Code → frontend dialog)
|
||||
"prompt_permission" => tool_prompt_permission(&args, ctx).await,
|
||||
_ => Err(format!("Unknown tool: {tool_name}")),
|
||||
@@ -990,7 +1022,7 @@ fn tool_create_story(args: &Value, ctx: &AppContext) -> Result<String, String> {
|
||||
.get("acceptance_criteria")
|
||||
.and_then(|v| serde_json::from_value(v.clone()).ok());
|
||||
// Spike 61: write the file only — the filesystem watcher detects the new
|
||||
// .md file in work/1_upcoming/ and auto-commits with a deterministic message.
|
||||
// .md file in work/1_backlog/ and auto-commits with a deterministic message.
|
||||
let commit = false;
|
||||
|
||||
let root = ctx.state.get_project_root()?;
|
||||
@@ -1032,6 +1064,47 @@ fn tool_list_upcoming(ctx: &AppContext) -> Result<String, String> {
|
||||
.map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
fn tool_get_pipeline_status(ctx: &AppContext) -> Result<String, String> {
|
||||
let state = load_pipeline_state(ctx)?;
|
||||
|
||||
fn map_items(items: &[crate::http::workflow::UpcomingStory], stage: &str) -> Vec<Value> {
|
||||
items
|
||||
.iter()
|
||||
.map(|s| {
|
||||
json!({
|
||||
"story_id": s.story_id,
|
||||
"name": s.name,
|
||||
"stage": stage,
|
||||
"agent": s.agent.as_ref().map(|a| json!({
|
||||
"agent_name": a.agent_name,
|
||||
"model": a.model,
|
||||
"status": a.status,
|
||||
})),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
let mut active: Vec<Value> = Vec::new();
|
||||
active.extend(map_items(&state.current, "current"));
|
||||
active.extend(map_items(&state.qa, "qa"));
|
||||
active.extend(map_items(&state.merge, "merge"));
|
||||
active.extend(map_items(&state.done, "done"));
|
||||
|
||||
let backlog: Vec<Value> = state
|
||||
.backlog
|
||||
.iter()
|
||||
.map(|s| json!({ "story_id": s.story_id, "name": s.name }))
|
||||
.collect();
|
||||
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"active": active,
|
||||
"backlog": backlog,
|
||||
"backlog_count": backlog.len(),
|
||||
}))
|
||||
.map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
fn tool_get_story_todos(args: &Value, ctx: &AppContext) -> Result<String, String> {
|
||||
let story_id = args
|
||||
.get("story_id")
|
||||
@@ -1544,8 +1617,24 @@ fn tool_update_story(args: &Value, ctx: &AppContext) -> Result<String, String> {
|
||||
let user_story = args.get("user_story").and_then(|v| v.as_str());
|
||||
let description = args.get("description").and_then(|v| v.as_str());
|
||||
|
||||
// Collect front matter fields: explicit `agent` param + arbitrary `front_matter` object.
|
||||
let mut front_matter: HashMap<String, String> = HashMap::new();
|
||||
if let Some(agent) = args.get("agent").and_then(|v| v.as_str()) {
|
||||
front_matter.insert("agent".to_string(), agent.to_string());
|
||||
}
|
||||
if let Some(obj) = args.get("front_matter").and_then(|v| v.as_object()) {
|
||||
for (k, v) in obj {
|
||||
let val = match v {
|
||||
Value::String(s) => s.clone(),
|
||||
other => other.to_string(),
|
||||
};
|
||||
front_matter.insert(k.clone(), val);
|
||||
}
|
||||
}
|
||||
let front_matter_opt = if front_matter.is_empty() { None } else { Some(&front_matter) };
|
||||
|
||||
let root = ctx.state.get_project_root()?;
|
||||
update_story_in_file(&root, story_id, user_story, description)?;
|
||||
update_story_in_file(&root, story_id, user_story, description, front_matter_opt)?;
|
||||
|
||||
Ok(format!("Updated story '{story_id}'."))
|
||||
}
|
||||
@@ -1788,6 +1877,13 @@ fn tool_report_merge_failure(args: &Value, ctx: &AppContext) -> Result<String, S
|
||||
slog!("[mergemaster] Merge failure reported for '{story_id}': {reason}");
|
||||
ctx.agents.set_merge_failure_reported(story_id);
|
||||
|
||||
// Broadcast the failure so the Matrix notification listener can post an
|
||||
// error message to configured rooms without coupling this tool to the bot.
|
||||
let _ = ctx.watcher_tx.send(crate::io::watcher::WatcherEvent::MergeFailure {
|
||||
story_id: story_id.to_string(),
|
||||
reason: reason.to_string(),
|
||||
});
|
||||
|
||||
// Persist the failure reason to the story file's front matter so it
|
||||
// survives server restarts and is visible in the web UI.
|
||||
if let Ok(project_root) = ctx.state.get_project_root() {
|
||||
@@ -2022,6 +2118,100 @@ fn add_permission_rule(project_root: &std::path::Path, rule: &str) -> Result<(),
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Rebuild the server binary and re-exec.
|
||||
///
|
||||
/// 1. Gracefully stops all running agents (kills PTY children).
|
||||
/// 2. Runs `cargo build [-p story-kit]` from the workspace root, matching
|
||||
/// the current build profile (debug or release).
|
||||
/// 3. If the build fails, returns the build error (server stays up).
|
||||
/// 4. If the build succeeds, re-execs the process with the new binary via
|
||||
/// `std::os::unix::process::CommandExt::exec()`.
|
||||
async fn tool_rebuild_and_restart(ctx: &AppContext) -> Result<String, String> {
|
||||
slog!("[rebuild] Rebuild and restart requested via MCP tool");
|
||||
|
||||
// 1. Gracefully stop all running agents.
|
||||
let running_agents = ctx.agents.list_agents().unwrap_or_default();
|
||||
let running_count = running_agents
|
||||
.iter()
|
||||
.filter(|a| a.status == AgentStatus::Running)
|
||||
.count();
|
||||
if running_count > 0 {
|
||||
slog!("[rebuild] Stopping {running_count} running agent(s) before rebuild");
|
||||
}
|
||||
ctx.agents.kill_all_children();
|
||||
|
||||
// 2. Find the workspace root (parent of the server binary's source).
|
||||
// CARGO_MANIFEST_DIR at compile time points to the `server/` crate;
|
||||
// the workspace root is its parent.
|
||||
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let workspace_root = manifest_dir
|
||||
.parent()
|
||||
.ok_or_else(|| "Cannot determine workspace root from CARGO_MANIFEST_DIR".to_string())?;
|
||||
|
||||
slog!(
|
||||
"[rebuild] Building server from workspace root: {}",
|
||||
workspace_root.display()
|
||||
);
|
||||
|
||||
// 3. Build the server binary, matching the current build profile so the
|
||||
// re-exec via current_exe() picks up the new binary.
|
||||
let build_args: Vec<&str> = if cfg!(debug_assertions) {
|
||||
vec!["build", "-p", "story-kit"]
|
||||
} else {
|
||||
vec!["build", "--release", "-p", "story-kit"]
|
||||
};
|
||||
slog!("[rebuild] cargo {}", build_args.join(" "));
|
||||
let output = tokio::task::spawn_blocking({
|
||||
let workspace_root = workspace_root.to_path_buf();
|
||||
move || {
|
||||
std::process::Command::new("cargo")
|
||||
.args(&build_args)
|
||||
.current_dir(&workspace_root)
|
||||
.output()
|
||||
}
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("Build task panicked: {e}"))?
|
||||
.map_err(|e| format!("Failed to run cargo build: {e}"))?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
slog!("[rebuild] Build failed:\n{stderr}");
|
||||
return Err(format!("Build failed:\n{stderr}"));
|
||||
}
|
||||
|
||||
slog!("[rebuild] Build succeeded, re-execing with new binary");
|
||||
|
||||
// 4. Re-exec with the new binary.
|
||||
// Collect current argv so we preserve any CLI arguments (e.g. project path).
|
||||
let current_exe = std::env::current_exe()
|
||||
.map_err(|e| format!("Cannot determine current executable: {e}"))?;
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
// Remove the port file before re-exec so the new process can write its own.
|
||||
if let Ok(root) = ctx.state.get_project_root() {
|
||||
let port_file = root.join(".story_kit_port");
|
||||
if port_file.exists() {
|
||||
let _ = std::fs::remove_file(&port_file);
|
||||
}
|
||||
}
|
||||
// Also check cwd for port file.
|
||||
let cwd_port_file = std::path::Path::new(".story_kit_port");
|
||||
if cwd_port_file.exists() {
|
||||
let _ = std::fs::remove_file(cwd_port_file);
|
||||
}
|
||||
|
||||
// Use exec() to replace the current process.
|
||||
// This never returns on success.
|
||||
use std::os::unix::process::CommandExt;
|
||||
let err = std::process::Command::new(¤t_exe)
|
||||
.args(&args[1..])
|
||||
.exec();
|
||||
|
||||
// If we get here, exec() failed.
|
||||
Err(format!("Failed to exec new binary: {err}"))
|
||||
}
|
||||
|
||||
/// MCP tool called by Claude Code via `--permission-prompt-tool`.
|
||||
///
|
||||
/// Forwards the permission request through the shared channel to the active
|
||||
@@ -2195,7 +2385,9 @@ mod tests {
|
||||
assert!(names.contains(&"request_qa"));
|
||||
assert!(names.contains(&"get_server_logs"));
|
||||
assert!(names.contains(&"prompt_permission"));
|
||||
assert_eq!(tools.len(), 34);
|
||||
assert!(names.contains(&"get_pipeline_status"));
|
||||
assert!(names.contains(&"rebuild_and_restart"));
|
||||
assert_eq!(tools.len(), 36);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2262,6 +2454,81 @@ mod tests {
|
||||
assert!(result.unwrap_err().contains("Missing required argument"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_get_pipeline_status_returns_structured_response() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path();
|
||||
|
||||
for (stage, id, name) in &[
|
||||
("1_backlog", "10_story_upcoming", "Upcoming Story"),
|
||||
("2_current", "20_story_current", "Current Story"),
|
||||
("3_qa", "30_story_qa", "QA Story"),
|
||||
("4_merge", "40_story_merge", "Merge Story"),
|
||||
("5_done", "50_story_done", "Done Story"),
|
||||
] {
|
||||
let dir = root.join(".story_kit/work").join(stage);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
std::fs::write(
|
||||
dir.join(format!("{id}.md")),
|
||||
format!("---\nname: \"{name}\"\n---\n"),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let ctx = test_ctx(root);
|
||||
let result = tool_get_pipeline_status(&ctx).unwrap();
|
||||
let parsed: Value = serde_json::from_str(&result).unwrap();
|
||||
|
||||
// Active stages include current, qa, merge, done
|
||||
let active = parsed["active"].as_array().unwrap();
|
||||
assert_eq!(active.len(), 4);
|
||||
|
||||
let stages: Vec<&str> = active.iter().map(|i| i["stage"].as_str().unwrap()).collect();
|
||||
assert!(stages.contains(&"current"));
|
||||
assert!(stages.contains(&"qa"));
|
||||
assert!(stages.contains(&"merge"));
|
||||
assert!(stages.contains(&"done"));
|
||||
|
||||
// Backlog
|
||||
let backlog = parsed["backlog"].as_array().unwrap();
|
||||
assert_eq!(backlog.len(), 1);
|
||||
assert_eq!(backlog[0]["story_id"], "10_story_upcoming");
|
||||
assert_eq!(parsed["backlog_count"], 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_get_pipeline_status_includes_agent_assignment() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = tmp.path();
|
||||
|
||||
let current = root.join(".story_kit/work/2_current");
|
||||
std::fs::create_dir_all(¤t).unwrap();
|
||||
std::fs::write(
|
||||
current.join("20_story_active.md"),
|
||||
"---\nname: \"Active Story\"\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let ctx = test_ctx(root);
|
||||
ctx.agents.inject_test_agent(
|
||||
"20_story_active",
|
||||
"coder-1",
|
||||
crate::agents::AgentStatus::Running,
|
||||
);
|
||||
|
||||
let result = tool_get_pipeline_status(&ctx).unwrap();
|
||||
let parsed: Value = serde_json::from_str(&result).unwrap();
|
||||
|
||||
let active = parsed["active"].as_array().unwrap();
|
||||
assert_eq!(active.len(), 1);
|
||||
let item = &active[0];
|
||||
assert_eq!(item["story_id"], "20_story_active");
|
||||
assert_eq!(item["stage"], "current");
|
||||
assert!(!item["agent"].is_null(), "agent should be present");
|
||||
assert_eq!(item["agent"]["agent_name"], "coder-1");
|
||||
assert_eq!(item["agent"]["status"], "running");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_get_story_todos_missing_file() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
@@ -2542,8 +2809,8 @@ mod tests {
|
||||
let t = tool.unwrap();
|
||||
let desc = t["description"].as_str().unwrap();
|
||||
assert!(
|
||||
desc.contains("work/1_upcoming/"),
|
||||
"create_bug description should reference work/1_upcoming/, got: {desc}"
|
||||
desc.contains("work/1_backlog/"),
|
||||
"create_bug description should reference work/1_backlog/, got: {desc}"
|
||||
);
|
||||
assert!(
|
||||
!desc.contains(".story_kit/bugs"),
|
||||
@@ -2567,8 +2834,8 @@ mod tests {
|
||||
let t = tool.unwrap();
|
||||
let desc = t["description"].as_str().unwrap();
|
||||
assert!(
|
||||
desc.contains("work/1_upcoming/"),
|
||||
"list_bugs description should reference work/1_upcoming/, got: {desc}"
|
||||
desc.contains("work/1_backlog/"),
|
||||
"list_bugs description should reference work/1_backlog/, got: {desc}"
|
||||
);
|
||||
assert!(
|
||||
!desc.contains(".story_kit/bugs"),
|
||||
@@ -2652,7 +2919,7 @@ mod tests {
|
||||
assert!(result.contains("1_bug_login_crash"));
|
||||
let bug_file = tmp
|
||||
.path()
|
||||
.join(".story_kit/work/1_upcoming/1_bug_login_crash.md");
|
||||
.join(".story_kit/work/1_backlog/1_bug_login_crash.md");
|
||||
assert!(bug_file.exists());
|
||||
}
|
||||
|
||||
@@ -2668,15 +2935,15 @@ mod tests {
|
||||
#[test]
|
||||
fn tool_list_bugs_returns_open_bugs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
std::fs::create_dir_all(&upcoming_dir).unwrap();
|
||||
let backlog_dir = tmp.path().join(".story_kit/work/1_backlog");
|
||||
std::fs::create_dir_all(&backlog_dir).unwrap();
|
||||
std::fs::write(
|
||||
upcoming_dir.join("1_bug_crash.md"),
|
||||
backlog_dir.join("1_bug_crash.md"),
|
||||
"# Bug 1: App Crash\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
upcoming_dir.join("2_bug_typo.md"),
|
||||
backlog_dir.join("2_bug_typo.md"),
|
||||
"# Bug 2: Typo in Header\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -2704,9 +2971,9 @@ mod tests {
|
||||
fn tool_close_bug_moves_to_archive() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo_in(tmp.path());
|
||||
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
std::fs::create_dir_all(&upcoming_dir).unwrap();
|
||||
let bug_file = upcoming_dir.join("1_bug_crash.md");
|
||||
let backlog_dir = tmp.path().join(".story_kit/work/1_backlog");
|
||||
std::fs::create_dir_all(&backlog_dir).unwrap();
|
||||
let bug_file = backlog_dir.join("1_bug_crash.md");
|
||||
std::fs::write(&bug_file, "# Bug 1: Crash\n").unwrap();
|
||||
// Stage the file so it's tracked
|
||||
std::process::Command::new("git")
|
||||
@@ -2776,7 +3043,7 @@ mod tests {
|
||||
assert!(result.contains("1_spike_compare_encoders"));
|
||||
let spike_file = tmp
|
||||
.path()
|
||||
.join(".story_kit/work/1_upcoming/1_spike_compare_encoders.md");
|
||||
.join(".story_kit/work/1_backlog/1_spike_compare_encoders.md");
|
||||
assert!(spike_file.exists());
|
||||
let contents = std::fs::read_to_string(&spike_file).unwrap();
|
||||
assert!(contents.starts_with("---\nname: \"Compare Encoders\"\n---"));
|
||||
@@ -2791,7 +3058,7 @@ mod tests {
|
||||
let result = tool_create_spike(&json!({"name": "My Spike"}), &ctx).unwrap();
|
||||
assert!(result.contains("1_spike_my_spike"));
|
||||
|
||||
let spike_file = tmp.path().join(".story_kit/work/1_upcoming/1_spike_my_spike.md");
|
||||
let spike_file = tmp.path().join(".story_kit/work/1_backlog/1_spike_my_spike.md");
|
||||
assert!(spike_file.exists());
|
||||
let contents = std::fs::read_to_string(&spike_file).unwrap();
|
||||
assert!(contents.starts_with("---\nname: \"My Spike\"\n---"));
|
||||
@@ -4007,4 +4274,56 @@ stage = "coder"
|
||||
assert_eq!(servers.len(), 1);
|
||||
assert_eq!(servers[0], "story-kit");
|
||||
}
|
||||
|
||||
// ── rebuild_and_restart ──────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn rebuild_and_restart_in_tools_list() {
|
||||
let resp = handle_tools_list(Some(json!(1)));
|
||||
let tools = resp.result.unwrap()["tools"].as_array().unwrap().clone();
|
||||
let tool = tools.iter().find(|t| t["name"] == "rebuild_and_restart");
|
||||
assert!(
|
||||
tool.is_some(),
|
||||
"rebuild_and_restart missing from tools list"
|
||||
);
|
||||
let t = tool.unwrap();
|
||||
assert!(t["description"].as_str().unwrap().contains("Rebuild"));
|
||||
assert!(t["inputSchema"].is_object());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rebuild_and_restart_kills_agents_before_build() {
|
||||
// Verify that calling rebuild_and_restart on an empty pool doesn't
|
||||
// panic and proceeds to the build step. We can't test exec() in a
|
||||
// unit test, but we can verify the build attempt happens.
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
|
||||
// The build will succeed (we're running in the real workspace) and
|
||||
// then exec() will be called — which would replace our test process.
|
||||
// So we only test that the function *runs* without panicking up to
|
||||
// the agent-kill step. We do this by checking the pool is empty.
|
||||
assert_eq!(ctx.agents.list_agents().unwrap().len(), 0);
|
||||
ctx.agents.kill_all_children(); // should not panic on empty pool
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rebuild_uses_matching_build_profile() {
|
||||
// The build must use the same profile (debug/release) as the running
|
||||
// binary, otherwise cargo build outputs to a different target dir and
|
||||
// current_exe() still points at the old binary.
|
||||
let build_args: Vec<&str> = if cfg!(debug_assertions) {
|
||||
vec!["build", "-p", "story-kit"]
|
||||
} else {
|
||||
vec!["build", "--release", "-p", "story-kit"]
|
||||
};
|
||||
|
||||
// Tests always run in debug mode, so --release must NOT be present.
|
||||
assert!(
|
||||
!build_args.contains(&"--release"),
|
||||
"In debug builds, rebuild must not pass --release (would put \
|
||||
the binary in target/release/ while current_exe() points to \
|
||||
target/debug/)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ impl ProjectApi {
|
||||
payload.0.path,
|
||||
&self.ctx.state,
|
||||
self.ctx.store.as_ref(),
|
||||
self.ctx.agents.port(),
|
||||
)
|
||||
.await
|
||||
.map_err(bad_request)?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::agents::AgentStatus;
|
||||
use crate::http::context::AppContext;
|
||||
use crate::io::story_metadata::{parse_front_matter, write_coverage_baseline};
|
||||
use crate::io::story_metadata::{parse_front_matter, set_front_matter_field, write_coverage_baseline};
|
||||
use crate::workflow::{StoryTestResults, TestCaseResult, TestStatus};
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
@@ -35,7 +35,7 @@ pub struct StoryValidationResult {
|
||||
/// Full pipeline state across all stages.
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct PipelineState {
|
||||
pub upcoming: Vec<UpcomingStory>,
|
||||
pub backlog: Vec<UpcomingStory>,
|
||||
pub current: Vec<UpcomingStory>,
|
||||
pub qa: Vec<UpcomingStory>,
|
||||
pub merge: Vec<UpcomingStory>,
|
||||
@@ -46,7 +46,7 @@ pub struct PipelineState {
|
||||
pub fn load_pipeline_state(ctx: &AppContext) -> Result<PipelineState, String> {
|
||||
let agent_map = build_active_agent_map(ctx);
|
||||
Ok(PipelineState {
|
||||
upcoming: load_stage_items(ctx, "1_upcoming", &HashMap::new())?,
|
||||
backlog: load_stage_items(ctx, "1_backlog", &HashMap::new())?,
|
||||
current: load_stage_items(ctx, "2_current", &agent_map)?,
|
||||
qa: load_stage_items(ctx, "3_qa", &agent_map)?,
|
||||
merge: load_stage_items(ctx, "4_merge", &agent_map)?,
|
||||
@@ -130,7 +130,7 @@ fn load_stage_items(
|
||||
}
|
||||
|
||||
pub fn load_upcoming_stories(ctx: &AppContext) -> Result<Vec<UpcomingStory>, String> {
|
||||
load_stage_items(ctx, "1_upcoming", &HashMap::new())
|
||||
load_stage_items(ctx, "1_backlog", &HashMap::new())
|
||||
}
|
||||
|
||||
/// Shared create-story logic used by both the OpenApi and MCP handlers.
|
||||
@@ -152,11 +152,11 @@ pub fn create_story_file(
|
||||
}
|
||||
|
||||
let filename = format!("{story_number}_story_{slug}.md");
|
||||
let upcoming_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
||||
fs::create_dir_all(&upcoming_dir)
|
||||
.map_err(|e| format!("Failed to create upcoming directory: {e}"))?;
|
||||
let backlog_dir = root.join(".story_kit").join("work").join("1_backlog");
|
||||
fs::create_dir_all(&backlog_dir)
|
||||
.map_err(|e| format!("Failed to create backlog directory: {e}"))?;
|
||||
|
||||
let filepath = upcoming_dir.join(&filename);
|
||||
let filepath = backlog_dir.join(&filename);
|
||||
if filepath.exists() {
|
||||
return Err(format!("Story file already exists: {filename}"));
|
||||
}
|
||||
@@ -206,7 +206,7 @@ pub fn create_story_file(
|
||||
|
||||
// ── Bug file helpers ──────────────────────────────────────────────
|
||||
|
||||
/// Create a bug file in `work/1_upcoming/` with a deterministic filename and auto-commit.
|
||||
/// Create a bug file in `work/1_backlog/` with a deterministic filename and auto-commit.
|
||||
///
|
||||
/// Returns the bug_id (e.g. `"4_bug_login_crash"`).
|
||||
pub fn create_bug_file(
|
||||
@@ -226,9 +226,9 @@ pub fn create_bug_file(
|
||||
}
|
||||
|
||||
let filename = format!("{bug_number}_bug_{slug}.md");
|
||||
let bugs_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
||||
let bugs_dir = root.join(".story_kit").join("work").join("1_backlog");
|
||||
fs::create_dir_all(&bugs_dir)
|
||||
.map_err(|e| format!("Failed to create upcoming directory: {e}"))?;
|
||||
.map_err(|e| format!("Failed to create backlog directory: {e}"))?;
|
||||
|
||||
let filepath = bugs_dir.join(&filename);
|
||||
if filepath.exists() {
|
||||
@@ -276,7 +276,7 @@ pub fn create_bug_file(
|
||||
|
||||
// ── Spike file helpers ────────────────────────────────────────────
|
||||
|
||||
/// Create a spike file in `work/1_upcoming/` with a deterministic filename.
|
||||
/// Create a spike file in `work/1_backlog/` with a deterministic filename.
|
||||
///
|
||||
/// Returns the spike_id (e.g. `"4_spike_filesystem_watcher_architecture"`).
|
||||
pub fn create_spike_file(
|
||||
@@ -292,11 +292,11 @@ pub fn create_spike_file(
|
||||
}
|
||||
|
||||
let filename = format!("{spike_number}_spike_{slug}.md");
|
||||
let upcoming_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
||||
fs::create_dir_all(&upcoming_dir)
|
||||
.map_err(|e| format!("Failed to create upcoming directory: {e}"))?;
|
||||
let backlog_dir = root.join(".story_kit").join("work").join("1_backlog");
|
||||
fs::create_dir_all(&backlog_dir)
|
||||
.map_err(|e| format!("Failed to create backlog directory: {e}"))?;
|
||||
|
||||
let filepath = upcoming_dir.join(&filename);
|
||||
let filepath = backlog_dir.join(&filename);
|
||||
if filepath.exists() {
|
||||
return Err(format!("Spike file already exists: {filename}"));
|
||||
}
|
||||
@@ -338,7 +338,7 @@ pub fn create_spike_file(
|
||||
Ok(spike_id)
|
||||
}
|
||||
|
||||
/// Create a refactor work item file in `work/1_upcoming/`.
|
||||
/// Create a refactor work item file in `work/1_backlog/`.
|
||||
///
|
||||
/// Returns the refactor_id (e.g. `"5_refactor_split_agents_rs"`).
|
||||
pub fn create_refactor_file(
|
||||
@@ -355,11 +355,11 @@ pub fn create_refactor_file(
|
||||
}
|
||||
|
||||
let filename = format!("{refactor_number}_refactor_{slug}.md");
|
||||
let upcoming_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
||||
fs::create_dir_all(&upcoming_dir)
|
||||
.map_err(|e| format!("Failed to create upcoming directory: {e}"))?;
|
||||
let backlog_dir = root.join(".story_kit").join("work").join("1_backlog");
|
||||
fs::create_dir_all(&backlog_dir)
|
||||
.map_err(|e| format!("Failed to create backlog directory: {e}"))?;
|
||||
|
||||
let filepath = upcoming_dir.join(&filename);
|
||||
let filepath = backlog_dir.join(&filename);
|
||||
if filepath.exists() {
|
||||
return Err(format!("Refactor file already exists: {filename}"));
|
||||
}
|
||||
@@ -427,18 +427,18 @@ fn extract_bug_name(path: &Path) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
/// List all open bugs — files in `work/1_upcoming/` matching the `_bug_` naming pattern.
|
||||
/// List all open bugs — files in `work/1_backlog/` matching the `_bug_` naming pattern.
|
||||
///
|
||||
/// Returns a sorted list of `(bug_id, name)` pairs.
|
||||
pub fn list_bug_files(root: &Path) -> Result<Vec<(String, String)>, String> {
|
||||
let upcoming_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
||||
if !upcoming_dir.exists() {
|
||||
let backlog_dir = root.join(".story_kit").join("work").join("1_backlog");
|
||||
if !backlog_dir.exists() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let mut bugs = Vec::new();
|
||||
for entry in
|
||||
fs::read_dir(&upcoming_dir).map_err(|e| format!("Failed to read upcoming directory: {e}"))?
|
||||
fs::read_dir(&backlog_dir).map_err(|e| format!("Failed to read backlog directory: {e}"))?
|
||||
{
|
||||
let entry = entry.map_err(|e| format!("Failed to read entry: {e}"))?;
|
||||
let path = entry.path();
|
||||
@@ -477,18 +477,18 @@ fn is_refactor_item(stem: &str) -> bool {
|
||||
after_num.starts_with("_refactor_")
|
||||
}
|
||||
|
||||
/// List all open refactors — files in `work/1_upcoming/` matching the `_refactor_` naming pattern.
|
||||
/// List all open refactors — files in `work/1_backlog/` matching the `_refactor_` naming pattern.
|
||||
///
|
||||
/// Returns a sorted list of `(refactor_id, name)` pairs.
|
||||
pub fn list_refactor_files(root: &Path) -> Result<Vec<(String, String)>, String> {
|
||||
let upcoming_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
||||
if !upcoming_dir.exists() {
|
||||
let backlog_dir = root.join(".story_kit").join("work").join("1_backlog");
|
||||
if !backlog_dir.exists() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let mut refactors = Vec::new();
|
||||
for entry in fs::read_dir(&upcoming_dir)
|
||||
.map_err(|e| format!("Failed to read upcoming directory: {e}"))?
|
||||
for entry in fs::read_dir(&backlog_dir)
|
||||
.map_err(|e| format!("Failed to read backlog directory: {e}"))?
|
||||
{
|
||||
let entry = entry.map_err(|e| format!("Failed to read entry: {e}"))?;
|
||||
let path = entry.path();
|
||||
@@ -525,11 +525,11 @@ pub fn list_refactor_files(root: &Path) -> Result<Vec<(String, String)>, String>
|
||||
|
||||
/// Locate a work item file by searching all active pipeline stages.
|
||||
///
|
||||
/// Searches in priority order: 2_current, 1_upcoming, 3_qa, 4_merge, 5_done, 6_archived.
|
||||
/// Searches in priority order: 2_current, 1_backlog, 3_qa, 4_merge, 5_done, 6_archived.
|
||||
fn find_story_file(project_root: &Path, story_id: &str) -> Result<PathBuf, String> {
|
||||
let filename = format!("{story_id}.md");
|
||||
let sk = project_root.join(".story_kit").join("work");
|
||||
for stage in &["2_current", "1_upcoming", "3_qa", "4_merge", "5_done", "6_archived"] {
|
||||
for stage in &["2_current", "1_backlog", "3_qa", "4_merge", "5_done", "6_archived"] {
|
||||
let path = sk.join(stage).join(&filename);
|
||||
if path.exists() {
|
||||
return Ok(path);
|
||||
@@ -706,10 +706,13 @@ pub fn update_story_in_file(
|
||||
story_id: &str,
|
||||
user_story: Option<&str>,
|
||||
description: Option<&str>,
|
||||
front_matter: Option<&HashMap<String, String>>,
|
||||
) -> Result<(), String> {
|
||||
if user_story.is_none() && description.is_none() {
|
||||
let has_front_matter_updates = front_matter.map(|m| !m.is_empty()).unwrap_or(false);
|
||||
if user_story.is_none() && description.is_none() && !has_front_matter_updates {
|
||||
return Err(
|
||||
"At least one of 'user_story' or 'description' must be provided.".to_string(),
|
||||
"At least one of 'user_story', 'description', or 'front_matter' must be provided."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -717,6 +720,13 @@ pub fn update_story_in_file(
|
||||
let mut contents = fs::read_to_string(&filepath)
|
||||
.map_err(|e| format!("Failed to read story file: {e}"))?;
|
||||
|
||||
if let Some(fields) = front_matter {
|
||||
for (key, value) in fields {
|
||||
let yaml_value = format!("\"{}\"", value.replace('"', "\\\"").replace('\n', " ").replace('\r', ""));
|
||||
contents = set_front_matter_field(&contents, key, &yaml_value);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(us) = user_story {
|
||||
contents = replace_section_content(&contents, "User Story", us)?;
|
||||
}
|
||||
@@ -768,7 +778,7 @@ fn next_item_number(root: &std::path::Path) -> Result<u32, String> {
|
||||
let work_base = root.join(".story_kit").join("work");
|
||||
let mut max_num: u32 = 0;
|
||||
|
||||
for subdir in &["1_upcoming", "2_current", "3_qa", "4_merge", "5_done", "6_archived"] {
|
||||
for subdir in &["1_backlog", "2_current", "3_qa", "4_merge", "5_done", "6_archived"] {
|
||||
let dir = work_base.join(subdir);
|
||||
if !dir.exists() {
|
||||
continue;
|
||||
@@ -963,10 +973,10 @@ pub fn validate_story_dirs(
|
||||
) -> Result<Vec<StoryValidationResult>, String> {
|
||||
let mut results = Vec::new();
|
||||
|
||||
// Directories to validate: work/2_current/ + work/1_upcoming/
|
||||
// Directories to validate: work/2_current/ + work/1_backlog/
|
||||
let dirs_to_validate: Vec<PathBuf> = vec![
|
||||
root.join(".story_kit").join("work").join("2_current"),
|
||||
root.join(".story_kit").join("work").join("1_upcoming"),
|
||||
root.join(".story_kit").join("work").join("1_backlog"),
|
||||
];
|
||||
|
||||
for dir in &dirs_to_validate {
|
||||
@@ -1032,7 +1042,7 @@ mod tests {
|
||||
let root = tmp.path().to_path_buf();
|
||||
|
||||
for (stage, id) in &[
|
||||
("1_upcoming", "10_story_upcoming"),
|
||||
("1_backlog", "10_story_upcoming"),
|
||||
("2_current", "20_story_current"),
|
||||
("3_qa", "30_story_qa"),
|
||||
("4_merge", "40_story_merge"),
|
||||
@@ -1050,8 +1060,8 @@ mod tests {
|
||||
let ctx = crate::http::context::AppContext::new_test(root);
|
||||
let state = load_pipeline_state(&ctx).unwrap();
|
||||
|
||||
assert_eq!(state.upcoming.len(), 1);
|
||||
assert_eq!(state.upcoming[0].story_id, "10_story_upcoming");
|
||||
assert_eq!(state.backlog.len(), 1);
|
||||
assert_eq!(state.backlog[0].story_id, "10_story_upcoming");
|
||||
|
||||
assert_eq!(state.current.len(), 1);
|
||||
assert_eq!(state.current[0].story_id, "20_story_current");
|
||||
@@ -1154,15 +1164,15 @@ mod tests {
|
||||
#[test]
|
||||
fn load_upcoming_parses_metadata() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(
|
||||
upcoming.join("31_story_view_upcoming.md"),
|
||||
backlog.join("31_story_view_upcoming.md"),
|
||||
"---\nname: View Upcoming\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
upcoming.join("32_story_worktree.md"),
|
||||
backlog.join("32_story_worktree.md"),
|
||||
"---\nname: Worktree Orchestration\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1179,11 +1189,11 @@ mod tests {
|
||||
#[test]
|
||||
fn load_upcoming_skips_non_md_files() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join(".gitkeep"), "").unwrap();
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(backlog.join(".gitkeep"), "").unwrap();
|
||||
fs::write(
|
||||
upcoming.join("31_story_example.md"),
|
||||
backlog.join("31_story_example.md"),
|
||||
"---\nname: A Story\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1198,16 +1208,16 @@ mod tests {
|
||||
fn validate_story_dirs_valid_files() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(
|
||||
current.join("28_story_todos.md"),
|
||||
"---\nname: Show TODOs\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
upcoming.join("36_story_front_matter.md"),
|
||||
backlog.join("36_story_front_matter.md"),
|
||||
"---\nname: Enforce Front Matter\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1292,7 +1302,7 @@ mod tests {
|
||||
#[test]
|
||||
fn next_item_number_empty_dirs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let base = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let base = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&base).unwrap();
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 1);
|
||||
}
|
||||
@@ -1300,13 +1310,13 @@ mod tests {
|
||||
#[test]
|
||||
fn next_item_number_scans_all_dirs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
let archived = tmp.path().join(".story_kit/work/5_done");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::create_dir_all(&archived).unwrap();
|
||||
fs::write(upcoming.join("10_story_foo.md"), "").unwrap();
|
||||
fs::write(backlog.join("10_story_foo.md"), "").unwrap();
|
||||
fs::write(current.join("20_story_bar.md"), "").unwrap();
|
||||
fs::write(archived.join("15_story_baz.md"), "").unwrap();
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 21);
|
||||
@@ -1324,9 +1334,9 @@ mod tests {
|
||||
#[test]
|
||||
fn create_story_writes_correct_content() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join("36_story_existing.md"), "").unwrap();
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(backlog.join("36_story_existing.md"), "").unwrap();
|
||||
|
||||
let number = next_item_number(tmp.path()).unwrap();
|
||||
assert_eq!(number, 37);
|
||||
@@ -1335,7 +1345,7 @@ mod tests {
|
||||
assert_eq!(slug, "my_new_feature");
|
||||
|
||||
let filename = format!("{number}_{slug}.md");
|
||||
let filepath = upcoming.join(&filename);
|
||||
let filepath = backlog.join(&filename);
|
||||
|
||||
let mut content = String::new();
|
||||
content.push_str("---\n");
|
||||
@@ -1367,10 +1377,10 @@ mod tests {
|
||||
let result = create_story_file(tmp.path(), name, None, None, false);
|
||||
assert!(result.is_ok(), "create_story_file failed: {result:?}");
|
||||
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
let story_id = result.unwrap();
|
||||
let filename = format!("{story_id}.md");
|
||||
let contents = fs::read_to_string(upcoming.join(&filename)).unwrap();
|
||||
let contents = fs::read_to_string(backlog.join(&filename)).unwrap();
|
||||
|
||||
let meta = parse_front_matter(&contents).expect("front matter should be valid YAML");
|
||||
assert_eq!(meta.name.as_deref(), Some(name));
|
||||
@@ -1379,10 +1389,10 @@ mod tests {
|
||||
#[test]
|
||||
fn create_story_rejects_duplicate() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
|
||||
let filepath = upcoming.join("1_story_my_feature.md");
|
||||
let filepath = backlog.join("1_story_my_feature.md");
|
||||
fs::write(&filepath, "existing").unwrap();
|
||||
|
||||
// Simulate the check
|
||||
@@ -1501,17 +1511,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_story_file_searches_current_then_upcoming() {
|
||||
fn find_story_file_searches_current_then_backlog() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
|
||||
// Only in upcoming
|
||||
fs::write(upcoming.join("6_test.md"), "").unwrap();
|
||||
// Only in backlog
|
||||
fs::write(backlog.join("6_test.md"), "").unwrap();
|
||||
let found = find_story_file(tmp.path(), "6_test").unwrap();
|
||||
assert!(found.ends_with("1_upcoming/6_test.md") || found.ends_with("1_upcoming\\6_test.md"));
|
||||
assert!(found.ends_with("1_backlog/6_test.md") || found.ends_with("1_backlog\\6_test.md"));
|
||||
|
||||
// Also in current — current should win
|
||||
fs::write(current.join("6_test.md"), "").unwrap();
|
||||
@@ -1597,7 +1607,7 @@ mod tests {
|
||||
let content = "---\nname: T\n---\n\n## User Story\n\nOld text\n\n## Acceptance Criteria\n\n- [ ] AC\n";
|
||||
fs::write(&filepath, content).unwrap();
|
||||
|
||||
update_story_in_file(tmp.path(), "20_test", Some("New user story text"), None).unwrap();
|
||||
update_story_in_file(tmp.path(), "20_test", Some("New user story text"), None, None).unwrap();
|
||||
|
||||
let result = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(result.contains("New user story text"), "new text should be present");
|
||||
@@ -1614,7 +1624,7 @@ mod tests {
|
||||
let content = "---\nname: T\n---\n\n## Description\n\nOld description\n\n## Acceptance Criteria\n\n- [ ] AC\n";
|
||||
fs::write(&filepath, content).unwrap();
|
||||
|
||||
update_story_in_file(tmp.path(), "21_test", None, Some("New description")).unwrap();
|
||||
update_story_in_file(tmp.path(), "21_test", None, Some("New description"), None).unwrap();
|
||||
|
||||
let result = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(result.contains("New description"), "new description present");
|
||||
@@ -1628,7 +1638,7 @@ mod tests {
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(current.join("22_test.md"), "---\nname: T\n---\n").unwrap();
|
||||
|
||||
let result = update_story_in_file(tmp.path(), "22_test", None, None);
|
||||
let result = update_story_in_file(tmp.path(), "22_test", None, None, None);
|
||||
assert!(result.is_err());
|
||||
assert!(result.unwrap_err().contains("At least one"));
|
||||
}
|
||||
@@ -1644,11 +1654,65 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let result = update_story_in_file(tmp.path(), "23_test", Some("new text"), None);
|
||||
let result = update_story_in_file(tmp.path(), "23_test", Some("new text"), None, None);
|
||||
assert!(result.is_err());
|
||||
assert!(result.unwrap_err().contains("User Story"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_story_sets_agent_front_matter_field() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let filepath = current.join("24_test.md");
|
||||
fs::write(&filepath, "---\nname: T\n---\n\n## User Story\n\nSome story\n").unwrap();
|
||||
|
||||
let mut fields = HashMap::new();
|
||||
fields.insert("agent".to_string(), "dev".to_string());
|
||||
update_story_in_file(tmp.path(), "24_test", None, None, Some(&fields)).unwrap();
|
||||
|
||||
let result = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(result.contains("agent: \"dev\""), "agent field should be set");
|
||||
assert!(result.contains("name: T"), "name field preserved");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_story_sets_arbitrary_front_matter_fields() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let filepath = current.join("25_test.md");
|
||||
fs::write(&filepath, "---\nname: T\n---\n\n## User Story\n\nSome story\n").unwrap();
|
||||
|
||||
let mut fields = HashMap::new();
|
||||
fields.insert("manual_qa".to_string(), "true".to_string());
|
||||
fields.insert("priority".to_string(), "high".to_string());
|
||||
update_story_in_file(tmp.path(), "25_test", None, None, Some(&fields)).unwrap();
|
||||
|
||||
let result = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(result.contains("manual_qa: \"true\""), "manual_qa field should be set");
|
||||
assert!(result.contains("priority: \"high\""), "priority field should be set");
|
||||
assert!(result.contains("name: T"), "name field preserved");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_story_front_matter_only_no_section_required() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
// File without a User Story section — front matter update should succeed
|
||||
let filepath = current.join("26_test.md");
|
||||
fs::write(&filepath, "---\nname: T\n---\n\nNo sections here.\n").unwrap();
|
||||
|
||||
let mut fields = HashMap::new();
|
||||
fields.insert("agent".to_string(), "dev".to_string());
|
||||
let result = update_story_in_file(tmp.path(), "26_test", None, None, Some(&fields));
|
||||
assert!(result.is_ok(), "front-matter-only update should not require body sections");
|
||||
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(contents.contains("agent: \"dev\""));
|
||||
}
|
||||
|
||||
// ── Bug file helper tests ──────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
@@ -1660,19 +1724,19 @@ mod tests {
|
||||
#[test]
|
||||
fn next_item_number_increments_from_existing_bugs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join("1_bug_crash.md"), "").unwrap();
|
||||
fs::write(upcoming.join("3_bug_another.md"), "").unwrap();
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(backlog.join("1_bug_crash.md"), "").unwrap();
|
||||
fs::write(backlog.join("3_bug_another.md"), "").unwrap();
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_item_number_scans_archived_too() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
let archived = tmp.path().join(".story_kit/work/5_done");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::create_dir_all(&archived).unwrap();
|
||||
fs::write(archived.join("5_bug_old.md"), "").unwrap();
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 6);
|
||||
@@ -1688,11 +1752,11 @@ mod tests {
|
||||
#[test]
|
||||
fn list_bug_files_excludes_archive_subdir() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let backlog_dir = tmp.path().join(".story_kit/work/1_backlog");
|
||||
let archived_dir = tmp.path().join(".story_kit/work/5_done");
|
||||
fs::create_dir_all(&upcoming_dir).unwrap();
|
||||
fs::create_dir_all(&backlog_dir).unwrap();
|
||||
fs::create_dir_all(&archived_dir).unwrap();
|
||||
fs::write(upcoming_dir.join("1_bug_open.md"), "# Bug 1: Open Bug\n").unwrap();
|
||||
fs::write(backlog_dir.join("1_bug_open.md"), "# Bug 1: Open Bug\n").unwrap();
|
||||
fs::write(archived_dir.join("2_bug_closed.md"), "# Bug 2: Closed Bug\n").unwrap();
|
||||
|
||||
let result = list_bug_files(tmp.path()).unwrap();
|
||||
@@ -1704,11 +1768,11 @@ mod tests {
|
||||
#[test]
|
||||
fn list_bug_files_sorted_by_id() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming_dir).unwrap();
|
||||
fs::write(upcoming_dir.join("3_bug_third.md"), "# Bug 3: Third\n").unwrap();
|
||||
fs::write(upcoming_dir.join("1_bug_first.md"), "# Bug 1: First\n").unwrap();
|
||||
fs::write(upcoming_dir.join("2_bug_second.md"), "# Bug 2: Second\n").unwrap();
|
||||
let backlog_dir = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog_dir).unwrap();
|
||||
fs::write(backlog_dir.join("3_bug_third.md"), "# Bug 3: Third\n").unwrap();
|
||||
fs::write(backlog_dir.join("1_bug_first.md"), "# Bug 1: First\n").unwrap();
|
||||
fs::write(backlog_dir.join("2_bug_second.md"), "# Bug 2: Second\n").unwrap();
|
||||
|
||||
let result = list_bug_files(tmp.path()).unwrap();
|
||||
assert_eq!(result.len(), 3);
|
||||
@@ -1746,7 +1810,7 @@ mod tests {
|
||||
|
||||
let filepath = tmp
|
||||
.path()
|
||||
.join(".story_kit/work/1_upcoming/1_bug_login_crash.md");
|
||||
.join(".story_kit/work/1_backlog/1_bug_login_crash.md");
|
||||
assert!(filepath.exists());
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(
|
||||
@@ -1790,7 +1854,7 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let filepath = tmp.path().join(".story_kit/work/1_upcoming/1_bug_some_bug.md");
|
||||
let filepath = tmp.path().join(".story_kit/work/1_backlog/1_bug_some_bug.md");
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(
|
||||
contents.starts_with("---\nname: \"Some Bug\"\n---"),
|
||||
@@ -1812,7 +1876,7 @@ mod tests {
|
||||
|
||||
let filepath = tmp
|
||||
.path()
|
||||
.join(".story_kit/work/1_upcoming/1_spike_filesystem_watcher_architecture.md");
|
||||
.join(".story_kit/work/1_backlog/1_spike_filesystem_watcher_architecture.md");
|
||||
assert!(filepath.exists());
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(
|
||||
@@ -1836,7 +1900,7 @@ mod tests {
|
||||
create_spike_file(tmp.path(), "FS Watcher Spike", Some(description)).unwrap();
|
||||
|
||||
let filepath =
|
||||
tmp.path().join(".story_kit/work/1_upcoming/1_spike_fs_watcher_spike.md");
|
||||
tmp.path().join(".story_kit/work/1_backlog/1_spike_fs_watcher_spike.md");
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(contents.contains(description));
|
||||
}
|
||||
@@ -1846,7 +1910,7 @@ mod tests {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
create_spike_file(tmp.path(), "My Spike", None).unwrap();
|
||||
|
||||
let filepath = tmp.path().join(".story_kit/work/1_upcoming/1_spike_my_spike.md");
|
||||
let filepath = tmp.path().join(".story_kit/work/1_backlog/1_spike_my_spike.md");
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
// Should have placeholder TBD in Question section
|
||||
assert!(contents.contains("## Question\n\n- TBD\n"));
|
||||
@@ -1867,10 +1931,10 @@ mod tests {
|
||||
let result = create_spike_file(tmp.path(), name, None);
|
||||
assert!(result.is_ok(), "create_spike_file failed: {result:?}");
|
||||
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
let spike_id = result.unwrap();
|
||||
let filename = format!("{spike_id}.md");
|
||||
let contents = fs::read_to_string(upcoming.join(&filename)).unwrap();
|
||||
let contents = fs::read_to_string(backlog.join(&filename)).unwrap();
|
||||
|
||||
let meta = parse_front_matter(&contents).expect("front matter should be valid YAML");
|
||||
assert_eq!(meta.name.as_deref(), Some(name));
|
||||
@@ -1879,9 +1943,9 @@ mod tests {
|
||||
#[test]
|
||||
fn create_spike_file_increments_from_existing_items() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join("5_story_existing.md"), "").unwrap();
|
||||
let backlog = tmp.path().join(".story_kit/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(backlog.join("5_story_existing.md"), "").unwrap();
|
||||
|
||||
let spike_id = create_spike_file(tmp.path(), "My Spike", None).unwrap();
|
||||
assert!(spike_id.starts_with("6_spike_"), "expected spike number 6, got: {spike_id}");
|
||||
|
||||
@@ -79,7 +79,7 @@ enum WsResponse {
|
||||
},
|
||||
/// Full pipeline state pushed on connect and after every work-item watcher event.
|
||||
PipelineState {
|
||||
upcoming: Vec<crate::http::workflow::UpcomingStory>,
|
||||
backlog: Vec<crate::http::workflow::UpcomingStory>,
|
||||
current: Vec<crate::http::workflow::UpcomingStory>,
|
||||
qa: Vec<crate::http::workflow::UpcomingStory>,
|
||||
merge: Vec<crate::http::workflow::UpcomingStory>,
|
||||
@@ -150,6 +150,9 @@ impl From<WatcherEvent> for Option<WsResponse> {
|
||||
}),
|
||||
WatcherEvent::ConfigChanged => Some(WsResponse::AgentConfigChanged),
|
||||
WatcherEvent::AgentStateChanged => Some(WsResponse::AgentStateChanged),
|
||||
// MergeFailure is handled by the Matrix notification listener only;
|
||||
// no WebSocket message is needed for the frontend.
|
||||
WatcherEvent::MergeFailure { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +160,7 @@ impl From<WatcherEvent> for Option<WsResponse> {
|
||||
impl From<PipelineState> for WsResponse {
|
||||
fn from(s: PipelineState) -> Self {
|
||||
WsResponse::PipelineState {
|
||||
upcoming: s.upcoming,
|
||||
backlog: s.backlog,
|
||||
current: s.current,
|
||||
qa: s.qa,
|
||||
merge: s.merge,
|
||||
@@ -692,7 +695,7 @@ mod tests {
|
||||
agent: None,
|
||||
};
|
||||
let resp = WsResponse::PipelineState {
|
||||
upcoming: vec![story],
|
||||
backlog: vec![story],
|
||||
current: vec![],
|
||||
qa: vec![],
|
||||
merge: vec![],
|
||||
@@ -700,8 +703,8 @@ mod tests {
|
||||
};
|
||||
let json = serde_json::to_value(&resp).unwrap();
|
||||
assert_eq!(json["type"], "pipeline_state");
|
||||
assert_eq!(json["upcoming"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(json["upcoming"][0]["story_id"], "10_story_test");
|
||||
assert_eq!(json["backlog"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(json["backlog"][0]["story_id"], "10_story_test");
|
||||
assert!(json["current"].as_array().unwrap().is_empty());
|
||||
assert!(json["done"].as_array().unwrap().is_empty());
|
||||
}
|
||||
@@ -821,7 +824,7 @@ mod tests {
|
||||
#[test]
|
||||
fn pipeline_state_converts_to_ws_response() {
|
||||
let state = PipelineState {
|
||||
upcoming: vec![UpcomingStory {
|
||||
backlog: vec![UpcomingStory {
|
||||
story_id: "1_story_a".to_string(),
|
||||
name: Some("Story A".to_string()),
|
||||
error: None,
|
||||
@@ -848,8 +851,8 @@ mod tests {
|
||||
let resp: WsResponse = state.into();
|
||||
let json = serde_json::to_value(&resp).unwrap();
|
||||
assert_eq!(json["type"], "pipeline_state");
|
||||
assert_eq!(json["upcoming"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(json["upcoming"][0]["story_id"], "1_story_a");
|
||||
assert_eq!(json["backlog"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(json["backlog"][0]["story_id"], "1_story_a");
|
||||
assert_eq!(json["current"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(json["current"][0]["story_id"], "2_story_b");
|
||||
assert!(json["qa"].as_array().unwrap().is_empty());
|
||||
@@ -861,7 +864,7 @@ mod tests {
|
||||
#[test]
|
||||
fn empty_pipeline_state_converts_to_ws_response() {
|
||||
let state = PipelineState {
|
||||
upcoming: vec![],
|
||||
backlog: vec![],
|
||||
current: vec![],
|
||||
qa: vec![],
|
||||
merge: vec![],
|
||||
@@ -870,7 +873,7 @@ mod tests {
|
||||
let resp: WsResponse = state.into();
|
||||
let json = serde_json::to_value(&resp).unwrap();
|
||||
assert_eq!(json["type"], "pipeline_state");
|
||||
assert!(json["upcoming"].as_array().unwrap().is_empty());
|
||||
assert!(json["backlog"].as_array().unwrap().is_empty());
|
||||
assert!(json["current"].as_array().unwrap().is_empty());
|
||||
assert!(json["qa"].as_array().unwrap().is_empty());
|
||||
assert!(json["merge"].as_array().unwrap().is_empty());
|
||||
@@ -988,7 +991,7 @@ mod tests {
|
||||
#[test]
|
||||
fn pipeline_state_with_agent_converts_correctly() {
|
||||
let state = PipelineState {
|
||||
upcoming: vec![],
|
||||
backlog: vec![],
|
||||
current: vec![UpcomingStory {
|
||||
story_id: "10_story_x".to_string(),
|
||||
name: Some("Story X".to_string()),
|
||||
@@ -1043,7 +1046,7 @@ mod tests {
|
||||
let root = tmp.path().to_path_buf();
|
||||
|
||||
// Create minimal pipeline dirs so load_pipeline_state succeeds.
|
||||
for stage in &["1_upcoming", "2_current", "3_qa", "4_merge"] {
|
||||
for stage in &["1_backlog", "2_current", "3_qa", "4_merge"] {
|
||||
std::fs::create_dir_all(root.join(".story_kit").join("work").join(stage)).unwrap();
|
||||
}
|
||||
|
||||
@@ -1152,7 +1155,7 @@ mod tests {
|
||||
|
||||
assert_eq!(initial["type"], "pipeline_state");
|
||||
// All stages should be empty arrays since no .md files were created.
|
||||
assert!(initial["upcoming"].as_array().unwrap().is_empty());
|
||||
assert!(initial["backlog"].as_array().unwrap().is_empty());
|
||||
assert!(initial["current"].as_array().unwrap().is_empty());
|
||||
assert!(initial["qa"].as_array().unwrap().is_empty());
|
||||
assert!(initial["merge"].as_array().unwrap().is_empty());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::state::SessionState;
|
||||
use crate::store::StoreOps;
|
||||
use crate::worktree::write_mcp_json as worktree_write_mcp_json;
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use std::fs;
|
||||
@@ -410,7 +409,7 @@ fn scaffold_story_kit(root: &Path) -> Result<(), String> {
|
||||
|
||||
// Create the work/ pipeline directories, each with a .gitkeep so empty dirs survive git clone
|
||||
let work_stages = [
|
||||
"1_upcoming",
|
||||
"1_backlog",
|
||||
"2_current",
|
||||
"3_qa",
|
||||
"4_merge",
|
||||
@@ -515,17 +514,12 @@ pub async fn open_project(
|
||||
path: String,
|
||||
state: &SessionState,
|
||||
store: &dyn StoreOps,
|
||||
port: u16,
|
||||
) -> Result<String, String> {
|
||||
let p = PathBuf::from(&path);
|
||||
|
||||
ensure_project_root_with_story_kit(p.clone()).await?;
|
||||
validate_project_path(p.clone()).await?;
|
||||
|
||||
// Write .mcp.json so that claude-code can connect to the MCP server.
|
||||
// Best-effort: failure should not prevent the project from opening.
|
||||
let _ = worktree_write_mcp_json(&p, port);
|
||||
|
||||
{
|
||||
// TRACE:MERGE-DEBUG — remove once root cause is found
|
||||
crate::slog!("[MERGE-DEBUG] open_project: setting project_root to {:?}", p);
|
||||
@@ -727,6 +721,42 @@ pub async fn create_directory_absolute(path: String) -> Result<bool, String> {
|
||||
.map_err(|e| format!("Task failed: {}", e))?
|
||||
}
|
||||
|
||||
/// List all files in the project recursively, respecting .gitignore.
|
||||
/// Returns relative paths from the project root (files only, not directories).
|
||||
pub async fn list_project_files(state: &SessionState) -> Result<Vec<String>, String> {
|
||||
let root = state.get_project_root()?;
|
||||
list_project_files_impl(root).await
|
||||
}
|
||||
|
||||
pub async fn list_project_files_impl(root: PathBuf) -> Result<Vec<String>, String> {
|
||||
use ignore::WalkBuilder;
|
||||
|
||||
let root_clone = root.clone();
|
||||
let files = tokio::task::spawn_blocking(move || {
|
||||
let mut result = Vec::new();
|
||||
let walker = WalkBuilder::new(&root_clone).git_ignore(true).build();
|
||||
|
||||
for entry in walker.flatten() {
|
||||
if entry.file_type().map(|ft| ft.is_file()).unwrap_or(false) {
|
||||
let relative = entry
|
||||
.path()
|
||||
.strip_prefix(&root_clone)
|
||||
.unwrap_or(entry.path())
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
result.push(relative);
|
||||
}
|
||||
}
|
||||
|
||||
result.sort();
|
||||
result
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("Task failed: {e}"))?;
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -777,7 +807,6 @@ mod tests {
|
||||
project_dir.to_string_lossy().to_string(),
|
||||
&state,
|
||||
&store,
|
||||
3001,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -787,7 +816,11 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn open_project_writes_mcp_json_to_project_root() {
|
||||
async fn open_project_does_not_write_mcp_json() {
|
||||
// open_project must NOT overwrite .mcp.json — test servers started by QA
|
||||
// agents share the real project root, so writing here would clobber the
|
||||
// root .mcp.json with the wrong port. .mcp.json is written once during
|
||||
// worktree creation (worktree.rs) and should not be touched again.
|
||||
let dir = tempdir().unwrap();
|
||||
let project_dir = dir.path().join("myproject");
|
||||
fs::create_dir_all(&project_dir).unwrap();
|
||||
@@ -798,17 +831,14 @@ mod tests {
|
||||
project_dir.to_string_lossy().to_string(),
|
||||
&state,
|
||||
&store,
|
||||
4242,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mcp_path = project_dir.join(".mcp.json");
|
||||
assert!(mcp_path.exists(), ".mcp.json should be written to project root");
|
||||
let content = fs::read_to_string(&mcp_path).unwrap();
|
||||
assert!(
|
||||
content.contains("http://localhost:4242/mcp"),
|
||||
".mcp.json should contain the correct port"
|
||||
!mcp_path.exists(),
|
||||
"open_project must not write .mcp.json — that would overwrite the root with the wrong port"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -868,7 +898,6 @@ mod tests {
|
||||
project_dir.to_string_lossy().to_string(),
|
||||
&state,
|
||||
&store,
|
||||
3001,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -1056,7 +1085,7 @@ mod tests {
|
||||
let dir = tempdir().unwrap();
|
||||
scaffold_story_kit(dir.path()).unwrap();
|
||||
|
||||
let stages = ["1_upcoming", "2_current", "3_qa", "4_merge", "5_done", "6_archived"];
|
||||
let stages = ["1_backlog", "2_current", "3_qa", "4_merge", "5_done", "6_archived"];
|
||||
for stage in &stages {
|
||||
let path = dir.path().join(".story_kit/work").join(stage);
|
||||
assert!(path.is_dir(), "work/{} should be a directory", stage);
|
||||
@@ -1329,7 +1358,6 @@ mod tests {
|
||||
project_dir.to_string_lossy().to_string(),
|
||||
&state,
|
||||
&store,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -1353,7 +1381,6 @@ mod tests {
|
||||
project_dir.to_string_lossy().to_string(),
|
||||
&state,
|
||||
&store,
|
||||
0,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -1588,4 +1615,68 @@ mod tests {
|
||||
"scaffold should not overwrite existing project.toml"
|
||||
);
|
||||
}
|
||||
|
||||
// --- list_project_files_impl ---
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_returns_all_files() {
|
||||
let dir = tempdir().unwrap();
|
||||
fs::create_dir(dir.path().join("src")).unwrap();
|
||||
fs::write(dir.path().join("src/main.rs"), "fn main() {}").unwrap();
|
||||
fs::write(dir.path().join("README.md"), "# readme").unwrap();
|
||||
|
||||
let files = list_project_files_impl(dir.path().to_path_buf())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(files.contains(&"README.md".to_string()));
|
||||
assert!(files.contains(&"src/main.rs".to_string()));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_excludes_dirs_from_output() {
|
||||
let dir = tempdir().unwrap();
|
||||
fs::create_dir(dir.path().join("subdir")).unwrap();
|
||||
fs::write(dir.path().join("file.txt"), "").unwrap();
|
||||
|
||||
let files = list_project_files_impl(dir.path().to_path_buf())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(files.contains(&"file.txt".to_string()));
|
||||
assert!(!files.iter().any(|f| f == "subdir"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_returns_sorted() {
|
||||
let dir = tempdir().unwrap();
|
||||
fs::write(dir.path().join("z.txt"), "").unwrap();
|
||||
fs::write(dir.path().join("a.txt"), "").unwrap();
|
||||
|
||||
let files = list_project_files_impl(dir.path().to_path_buf())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let a_idx = files.iter().position(|f| f == "a.txt").unwrap();
|
||||
let z_idx = files.iter().position(|f| f == "z.txt").unwrap();
|
||||
assert!(a_idx < z_idx);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_with_state() {
|
||||
let dir = tempdir().unwrap();
|
||||
fs::write(dir.path().join("hello.rs"), "").unwrap();
|
||||
let state = make_state_with_root(dir.path().to_path_buf());
|
||||
|
||||
let files = list_project_files(&state).await.unwrap();
|
||||
|
||||
assert!(files.contains(&"hello.rs".to_string()));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_project_files_errors_without_project() {
|
||||
let state = SessionState::default();
|
||||
let result = list_project_files(&state).await;
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ pub struct StoryMetadata {
|
||||
pub coverage_baseline: Option<String>,
|
||||
pub merge_failure: Option<String>,
|
||||
pub agent: Option<String>,
|
||||
pub review_hold: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -31,6 +32,7 @@ struct FrontMatter {
|
||||
coverage_baseline: Option<String>,
|
||||
merge_failure: Option<String>,
|
||||
agent: Option<String>,
|
||||
review_hold: Option<bool>,
|
||||
}
|
||||
|
||||
pub fn parse_front_matter(contents: &str) -> Result<StoryMetadata, StoryMetaError> {
|
||||
@@ -64,6 +66,7 @@ fn build_metadata(front: FrontMatter) -> StoryMetadata {
|
||||
coverage_baseline: front.coverage_baseline,
|
||||
merge_failure: front.merge_failure,
|
||||
agent: front.agent,
|
||||
review_hold: front.review_hold,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +101,17 @@ pub fn write_merge_failure(path: &Path, reason: &str) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write `review_hold: true` to the YAML front matter of a story file.
|
||||
///
|
||||
/// Used to mark spikes that have passed QA and are waiting for human review.
|
||||
pub fn write_review_hold(path: &Path) -> Result<(), String> {
|
||||
let contents =
|
||||
fs::read_to_string(path).map_err(|e| format!("Failed to read story file: {e}"))?;
|
||||
let updated = set_front_matter_field(&contents, "review_hold", "true");
|
||||
fs::write(path, &updated).map_err(|e| format!("Failed to write story file: {e}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a key from the YAML front matter of a story file on disk.
|
||||
///
|
||||
/// If front matter is present and contains the key, the line is removed.
|
||||
@@ -147,7 +161,7 @@ fn remove_front_matter_field(contents: &str, key: &str) -> String {
|
||||
/// Insert or update a key: value pair in the YAML front matter of a markdown string.
|
||||
///
|
||||
/// If no front matter (opening `---`) is found, returns the content unchanged.
|
||||
fn set_front_matter_field(contents: &str, key: &str, value: &str) -> String {
|
||||
pub fn set_front_matter_field(contents: &str, key: &str, value: &str) -> String {
|
||||
let mut lines: Vec<String> = contents.lines().map(String::from).collect();
|
||||
if lines.is_empty() || lines[0].trim() != "---" {
|
||||
return contents.to_string();
|
||||
@@ -328,4 +342,29 @@ workflow: tdd
|
||||
let input = " - [ ] Indented item\n";
|
||||
assert_eq!(parse_unchecked_todos(input), vec!["Indented item"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_review_hold_from_front_matter() {
|
||||
let input = "---\nname: Spike\nreview_hold: true\n---\n# Spike\n";
|
||||
let meta = parse_front_matter(input).expect("front matter");
|
||||
assert_eq!(meta.review_hold, Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_hold_defaults_to_none() {
|
||||
let input = "---\nname: Story\n---\n# Story\n";
|
||||
let meta = parse_front_matter(input).expect("front matter");
|
||||
assert_eq!(meta.review_hold, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_review_hold_sets_field() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let path = tmp.path().join("spike.md");
|
||||
std::fs::write(&path, "---\nname: My Spike\n---\n# Spike\n").unwrap();
|
||||
write_review_hold(&path).unwrap();
|
||||
let contents = std::fs::read_to_string(&path).unwrap();
|
||||
assert!(contents.contains("review_hold: true"));
|
||||
assert!(contents.contains("name: My Spike"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
//! the event so connected clients stay in sync.
|
||||
|
||||
use crate::config::{ProjectConfig, WatcherConfig};
|
||||
use crate::io::story_metadata::clear_front_matter_field;
|
||||
use crate::slog;
|
||||
use notify::{EventKind, RecommendedWatcher, RecursiveMode, Watcher, recommended_watcher};
|
||||
use serde::Serialize;
|
||||
@@ -50,6 +51,14 @@ pub enum WatcherEvent {
|
||||
/// Triggers a pipeline state refresh so the frontend can update agent
|
||||
/// assignments without waiting for a filesystem event.
|
||||
AgentStateChanged,
|
||||
/// A story encountered a failure (e.g. merge failure).
|
||||
/// Triggers an error notification to configured Matrix rooms.
|
||||
MergeFailure {
|
||||
/// Work item ID (e.g. `"42_story_my_feature"`).
|
||||
story_id: String,
|
||||
/// Human-readable description of the failure.
|
||||
reason: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Return `true` if `path` is the root-level `.story_kit/project.toml`, i.e.
|
||||
@@ -69,7 +78,7 @@ pub fn is_config_file(path: &Path, git_root: &Path) -> bool {
|
||||
/// Map a pipeline directory name to a (action, commit-message-prefix) pair.
|
||||
fn stage_metadata(stage: &str, item_id: &str) -> Option<(&'static str, String)> {
|
||||
let (action, prefix) = match stage {
|
||||
"1_upcoming" => ("create", format!("story-kit: create {item_id}")),
|
||||
"1_backlog" => ("create", format!("story-kit: create {item_id}")),
|
||||
"2_current" => ("start", format!("story-kit: start {item_id}")),
|
||||
"3_qa" => ("qa", format!("story-kit: queue {item_id} for QA")),
|
||||
"4_merge" => ("merge", format!("story-kit: queue {item_id} for merge")),
|
||||
@@ -102,7 +111,7 @@ fn stage_for_path(path: &Path) -> Option<String> {
|
||||
.parent()
|
||||
.and_then(|p| p.file_name())
|
||||
.and_then(|n| n.to_str())?;
|
||||
matches!(stage, "1_upcoming" | "2_current" | "3_qa" | "4_merge" | "5_done" | "6_archived")
|
||||
matches!(stage, "1_backlog" | "2_current" | "3_qa" | "4_merge" | "5_done" | "6_archived")
|
||||
.then(|| stage.to_string())
|
||||
}
|
||||
|
||||
@@ -146,11 +155,25 @@ fn git_add_work_and_commit(git_root: &Path, message: &str) -> Result<bool, Strin
|
||||
Err(format!("git commit failed: {stderr}"))
|
||||
}
|
||||
|
||||
/// Stages that represent meaningful git checkpoints (creation and archival).
|
||||
/// Intermediate stages (current, qa, merge, done) are transient pipeline state
|
||||
/// that don't need to be committed — they're only relevant while the server is
|
||||
/// running and are broadcast to WebSocket clients for real-time UI updates.
|
||||
const COMMIT_WORTHY_STAGES: &[&str] = &["1_backlog", "5_done", "6_archived"];
|
||||
|
||||
/// Return `true` if changes in `stage` should be committed to git.
|
||||
fn should_commit_stage(stage: &str) -> bool {
|
||||
COMMIT_WORTHY_STAGES.contains(&stage)
|
||||
}
|
||||
|
||||
/// Process a batch of pending (path → stage) entries: commit and broadcast.
|
||||
///
|
||||
/// Only files that still exist on disk are used to derive the commit message
|
||||
/// (they represent the destination of a move or a new file). Deletions are
|
||||
/// captured by `git add -A .story_kit/work/` automatically.
|
||||
///
|
||||
/// Only terminal stages (`1_backlog` and `6_archived`) trigger git commits.
|
||||
/// All stages broadcast a [`WatcherEvent`] so the frontend stays in sync.
|
||||
fn flush_pending(
|
||||
pending: &HashMap<PathBuf, String>,
|
||||
git_root: &Path,
|
||||
@@ -182,27 +205,46 @@ fn flush_pending(
|
||||
("remove", item.to_string(), format!("story-kit: remove {item}"))
|
||||
};
|
||||
|
||||
slog!("[watcher] flush: {commit_msg}");
|
||||
match git_add_work_and_commit(git_root, &commit_msg) {
|
||||
Ok(committed) => {
|
||||
if committed {
|
||||
slog!("[watcher] committed: {commit_msg}");
|
||||
} else {
|
||||
slog!("[watcher] skipped (already committed): {commit_msg}");
|
||||
}
|
||||
let stage = additions.first().map_or("unknown", |(_, s)| s);
|
||||
let evt = WatcherEvent::WorkItem {
|
||||
stage: stage.to_string(),
|
||||
item_id,
|
||||
action: action.to_string(),
|
||||
commit_msg,
|
||||
};
|
||||
let _ = event_tx.send(evt);
|
||||
}
|
||||
Err(e) => {
|
||||
slog!("[watcher] git error: {e}");
|
||||
// Strip stale merge_failure front matter from any story that has left 4_merge/.
|
||||
for (path, stage) in &additions {
|
||||
if *stage != "4_merge"
|
||||
&& let Err(e) = clear_front_matter_field(path, "merge_failure")
|
||||
{
|
||||
slog!("[watcher] Warning: could not clear merge_failure from {}: {e}", path.display());
|
||||
}
|
||||
}
|
||||
|
||||
// Only commit for terminal stages; intermediate moves are broadcast-only.
|
||||
let dest_stage = additions.first().map_or("unknown", |(_, s)| *s);
|
||||
let should_commit = should_commit_stage(dest_stage);
|
||||
|
||||
if should_commit {
|
||||
slog!("[watcher] flush: {commit_msg}");
|
||||
match git_add_work_and_commit(git_root, &commit_msg) {
|
||||
Ok(committed) => {
|
||||
if committed {
|
||||
slog!("[watcher] committed: {commit_msg}");
|
||||
} else {
|
||||
slog!("[watcher] skipped (already committed): {commit_msg}");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
slog!("[watcher] git error: {e}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
slog!("[watcher] flush (broadcast-only): {commit_msg}");
|
||||
}
|
||||
|
||||
// Always broadcast the event so connected WebSocket clients stay in sync.
|
||||
let evt = WatcherEvent::WorkItem {
|
||||
stage: dest_stage.to_string(),
|
||||
item_id,
|
||||
action: action.to_string(),
|
||||
commit_msg,
|
||||
};
|
||||
let _ = event_tx.send(evt);
|
||||
}
|
||||
|
||||
/// Scan `work/5_done/` and move any `.md` files whose mtime is older than
|
||||
@@ -529,7 +571,50 @@ mod tests {
|
||||
// ── flush_pending ─────────────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn flush_pending_commits_and_broadcasts_work_item_for_addition() {
|
||||
fn flush_pending_commits_and_broadcasts_for_terminal_stage() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
init_git_repo(tmp.path());
|
||||
let stage_dir = make_stage_dir(tmp.path(), "1_backlog");
|
||||
let story_path = stage_dir.join("42_story_foo.md");
|
||||
fs::write(&story_path, "---\nname: test\n---\n").unwrap();
|
||||
|
||||
let (tx, mut rx) = tokio::sync::broadcast::channel(16);
|
||||
let mut pending = HashMap::new();
|
||||
pending.insert(story_path, "1_backlog".to_string());
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
let evt = rx.try_recv().expect("expected a broadcast event");
|
||||
match evt {
|
||||
WatcherEvent::WorkItem {
|
||||
stage,
|
||||
item_id,
|
||||
action,
|
||||
commit_msg,
|
||||
} => {
|
||||
assert_eq!(stage, "1_backlog");
|
||||
assert_eq!(item_id, "42_story_foo");
|
||||
assert_eq!(action, "create");
|
||||
assert_eq!(commit_msg, "story-kit: create 42_story_foo");
|
||||
}
|
||||
other => panic!("unexpected event: {other:?}"),
|
||||
}
|
||||
|
||||
// Verify the file was actually committed.
|
||||
let log = std::process::Command::new("git")
|
||||
.args(["log", "--oneline", "-1"])
|
||||
.current_dir(tmp.path())
|
||||
.output()
|
||||
.expect("git log");
|
||||
let log_msg = String::from_utf8_lossy(&log.stdout);
|
||||
assert!(
|
||||
log_msg.contains("story-kit: create 42_story_foo"),
|
||||
"terminal stage should produce a git commit"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_pending_broadcasts_without_commit_for_intermediate_stage() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
init_git_repo(tmp.path());
|
||||
let stage_dir = make_stage_dir(tmp.path(), "2_current");
|
||||
@@ -542,6 +627,7 @@ mod tests {
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
// Event should still be broadcast for frontend sync.
|
||||
let evt = rx.try_recv().expect("expected a broadcast event");
|
||||
match evt {
|
||||
WatcherEvent::WorkItem {
|
||||
@@ -557,12 +643,24 @@ mod tests {
|
||||
}
|
||||
other => panic!("unexpected event: {other:?}"),
|
||||
}
|
||||
|
||||
// Verify NO git commit was made (only the initial empty commit should exist).
|
||||
let log = std::process::Command::new("git")
|
||||
.args(["log", "--oneline"])
|
||||
.current_dir(tmp.path())
|
||||
.output()
|
||||
.expect("git log");
|
||||
let log_msg = String::from_utf8_lossy(&log.stdout);
|
||||
assert!(
|
||||
!log_msg.contains("story-kit:"),
|
||||
"intermediate stage should NOT produce a git commit"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_pending_broadcasts_for_all_pipeline_stages() {
|
||||
let stages = [
|
||||
("1_upcoming", "create", "story-kit: create 10_story_x"),
|
||||
("1_backlog", "create", "story-kit: create 10_story_x"),
|
||||
("3_qa", "qa", "story-kit: queue 10_story_x for QA"),
|
||||
("4_merge", "merge", "story-kit: queue 10_story_x for merge"),
|
||||
("5_done", "done", "story-kit: done 10_story_x"),
|
||||
@@ -582,6 +680,7 @@ mod tests {
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
// All stages should broadcast events regardless of commit behavior.
|
||||
let evt = rx.try_recv().expect("expected broadcast for stage {stage}");
|
||||
match evt {
|
||||
WatcherEvent::WorkItem {
|
||||
@@ -664,6 +763,128 @@ mod tests {
|
||||
assert!(rx.try_recv().is_err(), "no event for empty pending map");
|
||||
}
|
||||
|
||||
// ── flush_pending clears merge_failure ─────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn flush_pending_clears_merge_failure_when_leaving_merge_stage() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
init_git_repo(tmp.path());
|
||||
let stage_dir = make_stage_dir(tmp.path(), "2_current");
|
||||
let story_path = stage_dir.join("50_story_retry.md");
|
||||
fs::write(
|
||||
&story_path,
|
||||
"---\nname: Retry Story\nmerge_failure: \"conflicts detected\"\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (tx, _rx) = tokio::sync::broadcast::channel(16);
|
||||
let mut pending = HashMap::new();
|
||||
pending.insert(story_path.clone(), "2_current".to_string());
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
let contents = fs::read_to_string(&story_path).unwrap();
|
||||
assert!(
|
||||
!contents.contains("merge_failure"),
|
||||
"merge_failure should be stripped when story lands in 2_current"
|
||||
);
|
||||
assert!(contents.contains("name: Retry Story"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_pending_clears_merge_failure_when_moving_to_backlog() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
init_git_repo(tmp.path());
|
||||
let stage_dir = make_stage_dir(tmp.path(), "1_backlog");
|
||||
let story_path = stage_dir.join("51_story_reset.md");
|
||||
fs::write(
|
||||
&story_path,
|
||||
"---\nname: Reset Story\nmerge_failure: \"gate failed\"\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (tx, _rx) = tokio::sync::broadcast::channel(16);
|
||||
let mut pending = HashMap::new();
|
||||
pending.insert(story_path.clone(), "1_backlog".to_string());
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
let contents = fs::read_to_string(&story_path).unwrap();
|
||||
assert!(
|
||||
!contents.contains("merge_failure"),
|
||||
"merge_failure should be stripped when story lands in 1_backlog"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_pending_clears_merge_failure_when_moving_to_done() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
init_git_repo(tmp.path());
|
||||
let stage_dir = make_stage_dir(tmp.path(), "5_done");
|
||||
let story_path = stage_dir.join("52_story_done.md");
|
||||
fs::write(
|
||||
&story_path,
|
||||
"---\nname: Done Story\nmerge_failure: \"stale error\"\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (tx, _rx) = tokio::sync::broadcast::channel(16);
|
||||
let mut pending = HashMap::new();
|
||||
pending.insert(story_path.clone(), "5_done".to_string());
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
let contents = fs::read_to_string(&story_path).unwrap();
|
||||
assert!(
|
||||
!contents.contains("merge_failure"),
|
||||
"merge_failure should be stripped when story lands in 5_done"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_pending_preserves_merge_failure_when_in_merge_stage() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
init_git_repo(tmp.path());
|
||||
let stage_dir = make_stage_dir(tmp.path(), "4_merge");
|
||||
let story_path = stage_dir.join("53_story_merging.md");
|
||||
fs::write(
|
||||
&story_path,
|
||||
"---\nname: Merging Story\nmerge_failure: \"conflicts\"\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (tx, _rx) = tokio::sync::broadcast::channel(16);
|
||||
let mut pending = HashMap::new();
|
||||
pending.insert(story_path.clone(), "4_merge".to_string());
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
let contents = fs::read_to_string(&story_path).unwrap();
|
||||
assert!(
|
||||
contents.contains("merge_failure"),
|
||||
"merge_failure should be preserved when story is in 4_merge"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_pending_no_op_when_no_merge_failure() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
init_git_repo(tmp.path());
|
||||
let stage_dir = make_stage_dir(tmp.path(), "2_current");
|
||||
let story_path = stage_dir.join("54_story_clean.md");
|
||||
let original = "---\nname: Clean Story\n---\n# Story\n";
|
||||
fs::write(&story_path, original).unwrap();
|
||||
|
||||
let (tx, _rx) = tokio::sync::broadcast::channel(16);
|
||||
let mut pending = HashMap::new();
|
||||
pending.insert(story_path.clone(), "2_current".to_string());
|
||||
|
||||
flush_pending(&pending, tmp.path(), &tx);
|
||||
|
||||
let contents = fs::read_to_string(&story_path).unwrap();
|
||||
assert_eq!(contents, original, "file without merge_failure should be unchanged");
|
||||
}
|
||||
|
||||
// ── stage_for_path (additional edge cases) ────────────────────────────────
|
||||
|
||||
#[test]
|
||||
@@ -713,6 +934,20 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_commit_stage_only_for_terminal_stages() {
|
||||
// Terminal stages — should commit.
|
||||
assert!(should_commit_stage("1_backlog"));
|
||||
assert!(should_commit_stage("5_done"));
|
||||
assert!(should_commit_stage("6_archived"));
|
||||
// Intermediate stages — broadcast-only, no commit.
|
||||
assert!(!should_commit_stage("2_current"));
|
||||
assert!(!should_commit_stage("3_qa"));
|
||||
assert!(!should_commit_stage("4_merge"));
|
||||
// Unknown — no commit.
|
||||
assert!(!should_commit_stage("unknown"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stage_metadata_returns_correct_actions() {
|
||||
let (action, msg) = stage_metadata("2_current", "42_story_foo").unwrap();
|
||||
|
||||
@@ -179,6 +179,44 @@ pub fn set_anthropic_api_key(store: &dyn StoreOps, api_key: String) -> Result<()
|
||||
set_anthropic_api_key_impl(store, &api_key)
|
||||
}
|
||||
|
||||
/// Build a prompt for Claude Code that includes prior conversation history.
|
||||
///
|
||||
/// When a Claude Code session cannot be resumed (no session_id), we embed
|
||||
/// the prior messages as a structured preamble so the LLM retains context.
|
||||
/// If there is only one user message (the current one), the content is
|
||||
/// returned as-is with no preamble.
|
||||
fn build_claude_code_context_prompt(messages: &[Message], latest_user_content: &str) -> String {
|
||||
// Collect prior messages (everything except the trailing user message).
|
||||
let prior: Vec<&Message> = messages
|
||||
.iter()
|
||||
.rev()
|
||||
.skip(1) // skip the latest user message
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.rev()
|
||||
.collect();
|
||||
|
||||
if prior.is_empty() {
|
||||
return latest_user_content.to_string();
|
||||
}
|
||||
|
||||
let mut parts = Vec::new();
|
||||
parts.push("<conversation_history>".to_string());
|
||||
for msg in &prior {
|
||||
let label = match msg.role {
|
||||
Role::User => "User",
|
||||
Role::Assistant => "Assistant",
|
||||
Role::Tool => "Tool",
|
||||
Role::System => continue,
|
||||
};
|
||||
parts.push(format!("[{}]: {}", label, msg.content));
|
||||
}
|
||||
parts.push("</conversation_history>".to_string());
|
||||
parts.push(String::new());
|
||||
parts.push(latest_user_content.to_string());
|
||||
parts.join("\n")
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn chat<F, U, T, A>(
|
||||
messages: Vec<Message>,
|
||||
@@ -224,13 +262,25 @@ where
|
||||
if is_claude_code {
|
||||
use crate::llm::providers::claude_code::ClaudeCodeProvider;
|
||||
|
||||
let user_message = messages
|
||||
let latest_user_content = messages
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|m| m.role == Role::User)
|
||||
.map(|m| m.content.clone())
|
||||
.ok_or_else(|| "No user message found".to_string())?;
|
||||
|
||||
// When resuming with a session_id, Claude Code loads its own transcript
|
||||
// from disk — the latest user message is sufficient. Without a
|
||||
// session_id (e.g. after a page refresh) the prior conversation context
|
||||
// would be lost because Claude Code only receives a single prompt
|
||||
// string. In that case, prepend the conversation history so the LLM
|
||||
// retains full context even though the session cannot be resumed.
|
||||
let user_message = if config.session_id.is_some() {
|
||||
latest_user_content
|
||||
} else {
|
||||
build_claude_code_context_prompt(&messages, &latest_user_content)
|
||||
};
|
||||
|
||||
let project_root = state
|
||||
.get_project_root()
|
||||
.unwrap_or_else(|_| std::path::PathBuf::from("."));
|
||||
@@ -244,6 +294,7 @@ where
|
||||
&user_message,
|
||||
&project_root.to_string_lossy(),
|
||||
config.session_id.as_deref(),
|
||||
None,
|
||||
&mut cancel_rx,
|
||||
|token| on_token(token),
|
||||
|thinking| on_thinking(thinking),
|
||||
@@ -404,7 +455,7 @@ where
|
||||
}
|
||||
|
||||
Ok(ChatResult {
|
||||
messages: new_messages,
|
||||
messages: current_history[2..].to_vec(),
|
||||
session_id: None,
|
||||
})
|
||||
}
|
||||
@@ -1095,4 +1146,102 @@ mod tests {
|
||||
let result = execute_tool(&call, &state).await;
|
||||
assert!(result.starts_with("Error:"), "unexpected result: {result}");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// build_claude_code_context_prompt (Bug 245)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn context_prompt_single_message_returns_content_as_is() {
|
||||
let messages = vec![Message {
|
||||
role: Role::User,
|
||||
content: "hello".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
}];
|
||||
let result = build_claude_code_context_prompt(&messages, "hello");
|
||||
assert_eq!(result, "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_prompt_includes_prior_conversation() {
|
||||
let messages = vec![
|
||||
Message {
|
||||
role: Role::User,
|
||||
content: "What is Rust?".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
},
|
||||
Message {
|
||||
role: Role::Assistant,
|
||||
content: "Rust is a systems language.".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
},
|
||||
Message {
|
||||
role: Role::User,
|
||||
content: "Tell me more".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
},
|
||||
];
|
||||
let result = build_claude_code_context_prompt(&messages, "Tell me more");
|
||||
assert!(
|
||||
result.contains("<conversation_history>"),
|
||||
"should have history preamble"
|
||||
);
|
||||
assert!(
|
||||
result.contains("[User]: What is Rust?"),
|
||||
"should include prior user message"
|
||||
);
|
||||
assert!(
|
||||
result.contains("[Assistant]: Rust is a systems language."),
|
||||
"should include prior assistant message"
|
||||
);
|
||||
assert!(
|
||||
result.contains("</conversation_history>"),
|
||||
"should close history block"
|
||||
);
|
||||
assert!(
|
||||
result.ends_with("Tell me more"),
|
||||
"should end with latest user message"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_prompt_skips_system_messages() {
|
||||
let messages = vec![
|
||||
Message {
|
||||
role: Role::System,
|
||||
content: "You are a helpful assistant.".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
},
|
||||
Message {
|
||||
role: Role::User,
|
||||
content: "hi".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
},
|
||||
Message {
|
||||
role: Role::Assistant,
|
||||
content: "hello".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
},
|
||||
Message {
|
||||
role: Role::User,
|
||||
content: "bye".to_string(),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
},
|
||||
];
|
||||
let result = build_claude_code_context_prompt(&messages, "bye");
|
||||
assert!(
|
||||
!result.contains("helpful assistant"),
|
||||
"should not include system messages"
|
||||
);
|
||||
assert!(result.contains("[User]: hi"));
|
||||
assert!(result.contains("[Assistant]: hello"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ impl ClaudeCodeProvider {
|
||||
user_message: &str,
|
||||
project_root: &str,
|
||||
session_id: Option<&str>,
|
||||
system_prompt: Option<&str>,
|
||||
cancel_rx: &mut watch::Receiver<bool>,
|
||||
mut on_token: F,
|
||||
mut on_thinking: T,
|
||||
@@ -55,6 +56,7 @@ impl ClaudeCodeProvider {
|
||||
let message = user_message.to_string();
|
||||
let cwd = project_root.to_string();
|
||||
let resume_id = session_id.map(|s| s.to_string());
|
||||
let sys_prompt = system_prompt.map(|s| s.to_string());
|
||||
let cancelled = Arc::new(AtomicBool::new(false));
|
||||
let cancelled_clone = cancelled.clone();
|
||||
|
||||
@@ -79,6 +81,7 @@ impl ClaudeCodeProvider {
|
||||
&message,
|
||||
&cwd,
|
||||
resume_id.as_deref(),
|
||||
sys_prompt.as_deref(),
|
||||
cancelled,
|
||||
token_tx,
|
||||
thinking_tx,
|
||||
@@ -120,6 +123,7 @@ impl ClaudeCodeProvider {
|
||||
.map_err(|e| format!("PTY task panicked: {e}"))??;
|
||||
|
||||
let captured_session_id = sid_rx.await.ok();
|
||||
slog!("[pty-debug] RECEIVED session_id: {:?}", captured_session_id);
|
||||
let structured_messages: Vec<Message> = msg_rx.try_iter().collect();
|
||||
|
||||
Ok(ClaudeCodeResult {
|
||||
@@ -146,6 +150,7 @@ fn run_pty_session(
|
||||
user_message: &str,
|
||||
cwd: &str,
|
||||
resume_session_id: Option<&str>,
|
||||
_system_prompt: Option<&str>,
|
||||
cancelled: Arc<AtomicBool>,
|
||||
token_tx: tokio::sync::mpsc::UnboundedSender<String>,
|
||||
thinking_tx: tokio::sync::mpsc::UnboundedSender<String>,
|
||||
@@ -184,6 +189,8 @@ fn run_pty_session(
|
||||
// a tool requires user approval, instead of using PTY stdin/stdout.
|
||||
cmd.arg("--permission-prompt-tool");
|
||||
cmd.arg("mcp__story-kit__prompt_permission");
|
||||
// Note: --system is not a valid Claude Code CLI flag. System-level
|
||||
// instructions (like bot name) are prepended to the user prompt instead.
|
||||
cmd.cwd(cwd);
|
||||
// Keep TERM reasonable but disable color
|
||||
cmd.env("NO_COLOR", "1");
|
||||
@@ -346,6 +353,7 @@ fn process_json_event(
|
||||
// Capture session_id from the first event that carries it
|
||||
if let Some(tx) = sid_tx.take() {
|
||||
if let Some(sid) = json.get("session_id").and_then(|s| s.as_str()) {
|
||||
slog!("[pty-debug] CAPTURED session_id: {}", sid);
|
||||
let _ = tx.send(sid.to_string());
|
||||
} else {
|
||||
*sid_tx = Some(tx);
|
||||
|
||||
@@ -58,7 +58,6 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
explicit_root.to_string_lossy().to_string(),
|
||||
&app_state,
|
||||
store.as_ref(),
|
||||
port,
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -81,7 +80,6 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
project_root.to_string_lossy().to_string(),
|
||||
&app_state,
|
||||
store.as_ref(),
|
||||
port,
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|e| {
|
||||
@@ -169,6 +167,10 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
// Clone watcher_tx for the Matrix bot before it is moved into AppContext.
|
||||
let watcher_tx_for_bot = watcher_tx.clone();
|
||||
// Wrap perm_rx in Arc<Mutex> so it can be shared with both the WebSocket
|
||||
// handler (via AppContext) and the Matrix bot.
|
||||
let perm_rx = Arc::new(tokio::sync::Mutex::new(perm_rx));
|
||||
let perm_rx_for_bot = Arc::clone(&perm_rx);
|
||||
|
||||
// Capture project root, agents Arc, and reconciliation sender before ctx
|
||||
// is consumed by build_routes.
|
||||
@@ -185,7 +187,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
watcher_tx,
|
||||
reconciliation_tx,
|
||||
perm_tx,
|
||||
perm_rx: Arc::new(tokio::sync::Mutex::new(perm_rx)),
|
||||
perm_rx,
|
||||
};
|
||||
|
||||
let app = build_routes(ctx);
|
||||
@@ -194,7 +196,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
// Optional Matrix bot: connect to the homeserver and start listening for
|
||||
// messages if `.story_kit/bot.toml` is present and enabled.
|
||||
if let Some(ref root) = startup_root {
|
||||
matrix::spawn_bot(root, watcher_tx_for_bot);
|
||||
matrix::spawn_bot(root, watcher_tx_for_bot, perm_rx_for_bot, Arc::clone(&startup_agents));
|
||||
}
|
||||
|
||||
// On startup:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
318
server/src/matrix/commands.rs
Normal file
318
server/src/matrix/commands.rs
Normal file
@@ -0,0 +1,318 @@
|
||||
//! Bot-level command registry for the Matrix bot.
|
||||
//!
|
||||
//! Commands registered here are handled directly by the bot without invoking
|
||||
//! the LLM. The registry is the single source of truth — the `help` command
|
||||
//! iterates it automatically so new commands appear in the help output as soon
|
||||
//! as they are added.
|
||||
|
||||
/// A bot-level command that is handled without LLM invocation.
|
||||
pub struct BotCommand {
|
||||
/// The command keyword (e.g., `"help"`). Always lowercase.
|
||||
pub name: &'static str,
|
||||
/// Short description shown in help output.
|
||||
pub description: &'static str,
|
||||
/// Handler that produces the response text (Markdown).
|
||||
pub handler: fn(&CommandContext) -> String,
|
||||
}
|
||||
|
||||
/// Context passed to command handlers.
|
||||
pub struct CommandContext<'a> {
|
||||
/// The bot's display name (e.g., "Timmy").
|
||||
pub bot_name: &'a str,
|
||||
/// Any text after the command keyword, trimmed.
|
||||
#[allow(dead_code)]
|
||||
pub args: &'a str,
|
||||
}
|
||||
|
||||
/// Returns the full list of registered bot commands.
|
||||
///
|
||||
/// Add new commands here — they will automatically appear in `help` output.
|
||||
pub fn commands() -> &'static [BotCommand] {
|
||||
&[BotCommand {
|
||||
name: "help",
|
||||
description: "Show this list of available commands",
|
||||
handler: handle_help,
|
||||
}]
|
||||
}
|
||||
|
||||
/// Try to match a user message against a registered bot command.
|
||||
///
|
||||
/// The message is expected to be the raw body text from Matrix (e.g.,
|
||||
/// `"@timmy help"`). The bot mention prefix is stripped before matching.
|
||||
///
|
||||
/// Returns `Some(response)` if a command matched, `None` otherwise (the
|
||||
/// caller should fall through to the LLM).
|
||||
pub fn try_handle_command(
|
||||
bot_name: &str,
|
||||
bot_user_id: &str,
|
||||
message: &str,
|
||||
) -> Option<String> {
|
||||
let command_text = strip_bot_mention(message, bot_name, bot_user_id);
|
||||
let trimmed = command_text.trim();
|
||||
if trimmed.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let (cmd_name, args) = match trimmed.split_once(char::is_whitespace) {
|
||||
Some((c, a)) => (c, a.trim()),
|
||||
None => (trimmed, ""),
|
||||
};
|
||||
let cmd_lower = cmd_name.to_ascii_lowercase();
|
||||
|
||||
let ctx = CommandContext {
|
||||
bot_name,
|
||||
args,
|
||||
};
|
||||
|
||||
commands()
|
||||
.iter()
|
||||
.find(|c| c.name == cmd_lower)
|
||||
.map(|c| (c.handler)(&ctx))
|
||||
}
|
||||
|
||||
/// Strip the bot mention prefix from a raw message body.
|
||||
///
|
||||
/// Handles these forms (case-insensitive where applicable):
|
||||
/// - `@bot_localpart:server.com rest` → `rest`
|
||||
/// - `@bot_localpart rest` → `rest`
|
||||
/// - `DisplayName rest` → `rest`
|
||||
fn strip_bot_mention<'a>(message: &'a str, bot_name: &str, bot_user_id: &str) -> &'a str {
|
||||
let trimmed = message.trim();
|
||||
|
||||
// Try full Matrix user ID (e.g. "@timmy:homeserver.local")
|
||||
if let Some(rest) = strip_prefix_ci(trimmed, bot_user_id) {
|
||||
return rest;
|
||||
}
|
||||
|
||||
// Try @localpart (e.g. "@timmy")
|
||||
if let Some(localpart) = bot_user_id.split(':').next()
|
||||
&& let Some(rest) = strip_prefix_ci(trimmed, localpart)
|
||||
{
|
||||
return rest;
|
||||
}
|
||||
|
||||
// Try display name (e.g. "Timmy")
|
||||
if let Some(rest) = strip_prefix_ci(trimmed, bot_name) {
|
||||
return rest;
|
||||
}
|
||||
|
||||
trimmed
|
||||
}
|
||||
|
||||
/// Case-insensitive prefix strip that also requires the match to end at a
|
||||
/// word boundary (whitespace, punctuation, or end-of-string).
|
||||
fn strip_prefix_ci<'a>(text: &'a str, prefix: &str) -> Option<&'a str> {
|
||||
if text.len() < prefix.len() {
|
||||
return None;
|
||||
}
|
||||
if !text[..prefix.len()].eq_ignore_ascii_case(prefix) {
|
||||
return None;
|
||||
}
|
||||
let rest = &text[prefix.len()..];
|
||||
// Must be at end or followed by non-alphanumeric
|
||||
match rest.chars().next() {
|
||||
None => Some(rest), // exact match, empty remainder
|
||||
Some(c) if c.is_alphanumeric() || c == '-' || c == '_' => None, // not a word boundary
|
||||
_ => Some(rest),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Built-in command handlers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
fn handle_help(ctx: &CommandContext) -> String {
|
||||
let mut output = format!("**{} Commands**\n\n", ctx.bot_name);
|
||||
for cmd in commands() {
|
||||
output.push_str(&format!("- **{}** — {}\n", cmd.name, cmd.description));
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// -- strip_bot_mention --------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn strip_mention_full_user_id() {
|
||||
let rest = strip_bot_mention(
|
||||
"@timmy:homeserver.local help",
|
||||
"Timmy",
|
||||
"@timmy:homeserver.local",
|
||||
);
|
||||
assert_eq!(rest.trim(), "help");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_mention_localpart() {
|
||||
let rest = strip_bot_mention("@timmy help me", "Timmy", "@timmy:homeserver.local");
|
||||
assert_eq!(rest.trim(), "help me");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_mention_display_name() {
|
||||
let rest = strip_bot_mention("Timmy help", "Timmy", "@timmy:homeserver.local");
|
||||
assert_eq!(rest.trim(), "help");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_mention_display_name_case_insensitive() {
|
||||
let rest = strip_bot_mention("timmy help", "Timmy", "@timmy:homeserver.local");
|
||||
assert_eq!(rest.trim(), "help");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_mention_no_match_returns_original() {
|
||||
let rest = strip_bot_mention("hello world", "Timmy", "@timmy:homeserver.local");
|
||||
assert_eq!(rest, "hello world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_mention_does_not_match_longer_name() {
|
||||
// "@timmybot" should NOT match "@timmy"
|
||||
let rest = strip_bot_mention("@timmybot help", "Timmy", "@timmy:homeserver.local");
|
||||
assert_eq!(rest, "@timmybot help");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_mention_comma_after_name() {
|
||||
let rest = strip_bot_mention("@timmy, help", "Timmy", "@timmy:homeserver.local");
|
||||
assert_eq!(rest.trim().trim_start_matches(',').trim(), "help");
|
||||
}
|
||||
|
||||
// -- try_handle_command -------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn help_command_matches() {
|
||||
let result = try_handle_command("Timmy", "@timmy:homeserver.local", "@timmy help");
|
||||
assert!(result.is_some(), "help command should match");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_command_case_insensitive() {
|
||||
let result = try_handle_command("Timmy", "@timmy:homeserver.local", "@timmy HELP");
|
||||
assert!(result.is_some(), "HELP should match case-insensitively");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_command_returns_none() {
|
||||
let result = try_handle_command(
|
||||
"Timmy",
|
||||
"@timmy:homeserver.local",
|
||||
"@timmy what is the weather?",
|
||||
);
|
||||
assert!(result.is_none(), "non-command should return None");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_output_contains_all_commands() {
|
||||
let result = try_handle_command("Timmy", "@timmy:homeserver.local", "@timmy help");
|
||||
let output = result.unwrap();
|
||||
for cmd in commands() {
|
||||
assert!(
|
||||
output.contains(cmd.name),
|
||||
"help output must include command '{}'",
|
||||
cmd.name
|
||||
);
|
||||
assert!(
|
||||
output.contains(cmd.description),
|
||||
"help output must include description for '{}'",
|
||||
cmd.name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_output_uses_bot_name() {
|
||||
let result = try_handle_command("HAL", "@hal:example.com", "@hal help");
|
||||
let output = result.unwrap();
|
||||
assert!(
|
||||
output.contains("HAL Commands"),
|
||||
"help output should use bot name: {output}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_output_formatted_as_markdown() {
|
||||
let result = try_handle_command("Timmy", "@timmy:homeserver.local", "@timmy help");
|
||||
let output = result.unwrap();
|
||||
assert!(
|
||||
output.contains("**help**"),
|
||||
"command name should be bold: {output}"
|
||||
);
|
||||
assert!(
|
||||
output.contains("- **"),
|
||||
"commands should be in a list: {output}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_message_after_mention_returns_none() {
|
||||
let result = try_handle_command("Timmy", "@timmy:homeserver.local", "@timmy");
|
||||
assert!(
|
||||
result.is_none(),
|
||||
"bare mention with no command should fall through to LLM"
|
||||
);
|
||||
}
|
||||
|
||||
// -- strip_prefix_ci ----------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn strip_prefix_ci_basic() {
|
||||
assert_eq!(strip_prefix_ci("Hello world", "hello"), Some(" world"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_prefix_ci_no_match() {
|
||||
assert_eq!(strip_prefix_ci("goodbye", "hello"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_prefix_ci_word_boundary_required() {
|
||||
assert_eq!(strip_prefix_ci("helloworld", "hello"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_prefix_ci_exact_match() {
|
||||
assert_eq!(strip_prefix_ci("hello", "hello"), Some(""));
|
||||
}
|
||||
|
||||
// -- commands registry --------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn commands_registry_is_not_empty() {
|
||||
assert!(
|
||||
!commands().is_empty(),
|
||||
"command registry must contain at least one command"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_command_names_are_lowercase() {
|
||||
for cmd in commands() {
|
||||
assert_eq!(
|
||||
cmd.name,
|
||||
cmd.name.to_ascii_lowercase(),
|
||||
"command name '{}' must be lowercase",
|
||||
cmd.name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_commands_have_descriptions() {
|
||||
for cmd in commands() {
|
||||
assert!(
|
||||
!cmd.description.is_empty(),
|
||||
"command '{}' must have a description",
|
||||
cmd.name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@ fn default_history_size() -> usize {
|
||||
20
|
||||
}
|
||||
|
||||
fn default_permission_timeout_secs() -> u64 {
|
||||
120
|
||||
}
|
||||
|
||||
/// Configuration for the Matrix bot, read from `.story_kit/bot.toml`.
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct BotConfig {
|
||||
@@ -35,11 +39,25 @@ pub struct BotConfig {
|
||||
/// dropped. Defaults to 20.
|
||||
#[serde(default = "default_history_size")]
|
||||
pub history_size: usize,
|
||||
/// Timeout in seconds for permission prompts surfaced to the Matrix room.
|
||||
/// If the user does not respond within this window the permission is denied
|
||||
/// (fail-closed). Defaults to 120 seconds.
|
||||
#[serde(default = "default_permission_timeout_secs")]
|
||||
pub permission_timeout_secs: u64,
|
||||
/// Previously used to select an Anthropic model. Now ignored — the bot
|
||||
/// uses Claude Code which manages its own model selection. Kept for
|
||||
/// backwards compatibility so existing bot.toml files still parse.
|
||||
#[allow(dead_code)]
|
||||
pub model: Option<String>,
|
||||
/// Display name the bot uses to identify itself in conversations.
|
||||
/// If unset, the bot falls back to "Assistant".
|
||||
#[serde(default)]
|
||||
pub display_name: Option<String>,
|
||||
/// Room IDs where ambient mode is active (bot responds to all messages).
|
||||
/// Updated at runtime when the user toggles ambient mode — do not edit
|
||||
/// manually while the bot is running.
|
||||
#[serde(default)]
|
||||
pub ambient_rooms: Vec<String>,
|
||||
}
|
||||
|
||||
impl BotConfig {
|
||||
@@ -84,6 +102,46 @@ impl BotConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// Persist the current set of ambient room IDs back to `bot.toml`.
|
||||
///
|
||||
/// Reads the existing file as a TOML document, updates the `ambient_rooms`
|
||||
/// array, and writes the result back. Errors are logged but not propagated
|
||||
/// so a persistence failure never interrupts the bot's message handling.
|
||||
pub fn save_ambient_rooms(project_root: &Path, room_ids: &[String]) {
|
||||
let path = project_root.join(".story_kit").join("bot.toml");
|
||||
let content = match std::fs::read_to_string(&path) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
eprintln!("[matrix-bot] save_ambient_rooms: failed to read bot.toml: {e}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let mut doc: toml::Value = match toml::from_str(&content) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
eprintln!("[matrix-bot] save_ambient_rooms: failed to parse bot.toml: {e}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
if let toml::Value::Table(ref mut t) = doc {
|
||||
let arr = toml::Value::Array(
|
||||
room_ids
|
||||
.iter()
|
||||
.map(|s| toml::Value::String(s.clone()))
|
||||
.collect(),
|
||||
);
|
||||
t.insert("ambient_rooms".to_string(), arr);
|
||||
}
|
||||
match toml::to_string_pretty(&doc) {
|
||||
Ok(new_content) => {
|
||||
if let Err(e) = std::fs::write(&path, new_content) {
|
||||
eprintln!("[matrix-bot] save_ambient_rooms: failed to write bot.toml: {e}");
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("[matrix-bot] save_ambient_rooms: failed to serialise bot.toml: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -256,6 +314,88 @@ history_size = 50
|
||||
assert_eq!(config.history_size, 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_reads_display_name() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"
|
||||
homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
display_name = "Timmy"
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert_eq!(config.display_name.as_deref(), Some("Timmy"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_display_name_defaults_to_none_when_absent() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"
|
||||
homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert!(config.display_name.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_uses_default_permission_timeout() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"
|
||||
homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert_eq!(config.permission_timeout_secs, 120);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_respects_custom_permission_timeout() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"
|
||||
homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
permission_timeout_secs = 60
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert_eq!(config.permission_timeout_secs, 60);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_ignores_legacy_require_verified_devices_key() {
|
||||
// Old bot.toml files that still have `require_verified_devices = true`
|
||||
@@ -283,4 +423,90 @@ require_verified_devices = true
|
||||
"bot.toml with legacy require_verified_devices key must still load"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_reads_ambient_rooms() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"
|
||||
homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
ambient_rooms = ["!abc:example.com"]
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert_eq!(config.ambient_rooms, vec!["!abc:example.com"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_ambient_rooms_defaults_to_empty_when_absent() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"
|
||||
homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert!(config.ambient_rooms.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_ambient_rooms_persists_to_bot_toml() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
save_ambient_rooms(tmp.path(), &["!abc:example.com".to_string()]);
|
||||
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert_eq!(config.ambient_rooms, vec!["!abc:example.com"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_ambient_rooms_clears_when_empty() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
fs::create_dir_all(&sk).unwrap();
|
||||
fs::write(
|
||||
sk.join("bot.toml"),
|
||||
r#"homeserver = "https://matrix.example.com"
|
||||
username = "@bot:example.com"
|
||||
password = "secret"
|
||||
room_ids = ["!abc:example.com"]
|
||||
enabled = true
|
||||
ambient_rooms = ["!abc:example.com"]
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
save_ambient_rooms(tmp.path(), &[]);
|
||||
|
||||
let config = BotConfig::load(tmp.path()).unwrap();
|
||||
assert!(config.ambient_rooms.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,18 @@
|
||||
//! `bot.toml`. Each room maintains its own independent conversation history.
|
||||
|
||||
mod bot;
|
||||
pub mod commands;
|
||||
mod config;
|
||||
pub mod notifications;
|
||||
|
||||
pub use config::BotConfig;
|
||||
|
||||
use crate::agents::AgentPool;
|
||||
use crate::http::context::PermissionForward;
|
||||
use crate::io::watcher::WatcherEvent;
|
||||
use std::path::Path;
|
||||
use tokio::sync::broadcast;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{Mutex as TokioMutex, broadcast, mpsc};
|
||||
|
||||
/// Attempt to start the Matrix bot.
|
||||
///
|
||||
@@ -35,8 +39,17 @@ use tokio::sync::broadcast;
|
||||
/// posts stage-transition messages to all configured rooms whenever a work
|
||||
/// item moves between pipeline stages.
|
||||
///
|
||||
/// `perm_rx` is the permission-request receiver shared with the MCP
|
||||
/// `prompt_permission` tool. The bot locks it during active chat sessions
|
||||
/// to surface permission prompts to the Matrix room and relay user decisions.
|
||||
///
|
||||
/// Must be called from within a Tokio runtime context (e.g., from `main`).
|
||||
pub fn spawn_bot(project_root: &Path, watcher_tx: broadcast::Sender<WatcherEvent>) {
|
||||
pub fn spawn_bot(
|
||||
project_root: &Path,
|
||||
watcher_tx: broadcast::Sender<WatcherEvent>,
|
||||
perm_rx: Arc<TokioMutex<mpsc::UnboundedReceiver<PermissionForward>>>,
|
||||
agents: Arc<AgentPool>,
|
||||
) {
|
||||
let config = match BotConfig::load(project_root) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
@@ -54,7 +67,7 @@ pub fn spawn_bot(project_root: &Path, watcher_tx: broadcast::Sender<WatcherEvent
|
||||
let root = project_root.to_path_buf();
|
||||
let watcher_rx = watcher_tx.subscribe();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = bot::run_bot(config, root, watcher_rx).await {
|
||||
if let Err(e) = bot::run_bot(config, root, watcher_rx, perm_rx, agents).await {
|
||||
crate::slog!("[matrix-bot] Fatal error: {e}");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ use tokio::sync::broadcast;
|
||||
/// Human-readable display name for a pipeline stage directory.
|
||||
pub fn stage_display_name(stage: &str) -> &'static str {
|
||||
match stage {
|
||||
"1_upcoming" => "Upcoming",
|
||||
"1_backlog" => "Backlog",
|
||||
"2_current" => "Current",
|
||||
"3_qa" => "QA",
|
||||
"4_merge" => "Merge",
|
||||
@@ -27,11 +27,11 @@ pub fn stage_display_name(stage: &str) -> &'static str {
|
||||
|
||||
/// Infer the previous pipeline stage for a given destination stage.
|
||||
///
|
||||
/// Returns `None` for `1_upcoming` since items are created there (not
|
||||
/// Returns `None` for `1_backlog` since items are created there (not
|
||||
/// transitioned from another stage).
|
||||
pub fn inferred_from_stage(to_stage: &str) -> Option<&'static str> {
|
||||
match to_stage {
|
||||
"2_current" => Some("Upcoming"),
|
||||
"2_current" => Some("Backlog"),
|
||||
"3_qa" => Some("Current"),
|
||||
"4_merge" => Some("QA"),
|
||||
"5_done" => Some("Merge"),
|
||||
@@ -81,6 +81,24 @@ pub fn format_stage_notification(
|
||||
(plain, html)
|
||||
}
|
||||
|
||||
/// Format an error notification message for a story failure.
|
||||
///
|
||||
/// Returns `(plain_text, html)` suitable for `RoomMessageEventContent::text_html`.
|
||||
pub fn format_error_notification(
|
||||
item_id: &str,
|
||||
story_name: Option<&str>,
|
||||
reason: &str,
|
||||
) -> (String, String) {
|
||||
let number = extract_story_number(item_id).unwrap_or(item_id);
|
||||
let name = story_name.unwrap_or(item_id);
|
||||
|
||||
let plain = format!("\u{274c} #{number} {name} \u{2014} {reason}");
|
||||
let html = format!(
|
||||
"\u{274c} <strong>#{number}</strong> <em>{name}</em> \u{2014} {reason}"
|
||||
);
|
||||
(plain, html)
|
||||
}
|
||||
|
||||
/// Spawn a background task that listens for watcher events and posts
|
||||
/// stage-transition notifications to all configured Matrix rooms.
|
||||
pub fn spawn_notification_listener(
|
||||
@@ -126,6 +144,32 @@ pub fn spawn_notification_listener(
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(WatcherEvent::MergeFailure {
|
||||
ref story_id,
|
||||
ref reason,
|
||||
}) => {
|
||||
let story_name =
|
||||
read_story_name(&project_root, "4_merge", story_id);
|
||||
let (plain, html) = format_error_notification(
|
||||
story_id,
|
||||
story_name.as_deref(),
|
||||
reason,
|
||||
);
|
||||
|
||||
slog!("[matrix-bot] Sending error notification: {plain}");
|
||||
|
||||
for room_id in &room_ids {
|
||||
if let Some(room) = client.get_room(room_id) {
|
||||
let content =
|
||||
RoomMessageEventContent::text_html(plain.clone(), html.clone());
|
||||
if let Err(e) = room.send(content).await {
|
||||
slog!(
|
||||
"[matrix-bot] Failed to send error notification to {room_id}: {e}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(_) => {} // Ignore non-work-item events
|
||||
Err(broadcast::error::RecvError::Lagged(n)) => {
|
||||
slog!(
|
||||
@@ -151,7 +195,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn stage_display_name_maps_all_known_stages() {
|
||||
assert_eq!(stage_display_name("1_upcoming"), "Upcoming");
|
||||
assert_eq!(stage_display_name("1_backlog"), "Backlog");
|
||||
assert_eq!(stage_display_name("2_current"), "Current");
|
||||
assert_eq!(stage_display_name("3_qa"), "QA");
|
||||
assert_eq!(stage_display_name("4_merge"), "Merge");
|
||||
@@ -164,7 +208,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn inferred_from_stage_returns_previous_stage() {
|
||||
assert_eq!(inferred_from_stage("2_current"), Some("Upcoming"));
|
||||
assert_eq!(inferred_from_stage("2_current"), Some("Backlog"));
|
||||
assert_eq!(inferred_from_stage("3_qa"), Some("Current"));
|
||||
assert_eq!(inferred_from_stage("4_merge"), Some("QA"));
|
||||
assert_eq!(inferred_from_stage("5_done"), Some("Merge"));
|
||||
@@ -172,8 +216,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inferred_from_stage_returns_none_for_upcoming() {
|
||||
assert_eq!(inferred_from_stage("1_upcoming"), None);
|
||||
fn inferred_from_stage_returns_none_for_backlog() {
|
||||
assert_eq!(inferred_from_stage("1_backlog"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -246,6 +290,42 @@ mod tests {
|
||||
assert_eq!(name, None);
|
||||
}
|
||||
|
||||
// ── format_error_notification ────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn format_error_notification_with_story_name() {
|
||||
let (plain, html) =
|
||||
format_error_notification("262_story_bot_errors", Some("Bot error notifications"), "merge conflict in src/main.rs");
|
||||
assert_eq!(
|
||||
plain,
|
||||
"\u{274c} #262 Bot error notifications \u{2014} merge conflict in src/main.rs"
|
||||
);
|
||||
assert_eq!(
|
||||
html,
|
||||
"\u{274c} <strong>#262</strong> <em>Bot error notifications</em> \u{2014} merge conflict in src/main.rs"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_error_notification_without_story_name_falls_back_to_item_id() {
|
||||
let (plain, _html) =
|
||||
format_error_notification("42_bug_fix_thing", None, "tests failed");
|
||||
assert_eq!(
|
||||
plain,
|
||||
"\u{274c} #42 42_bug_fix_thing \u{2014} tests failed"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_error_notification_non_numeric_id_uses_full_id() {
|
||||
let (plain, _html) =
|
||||
format_error_notification("abc_story_thing", Some("Some Story"), "clippy errors");
|
||||
assert_eq!(
|
||||
plain,
|
||||
"\u{274c} #abc_story_thing Some Story \u{2014} clippy errors"
|
||||
);
|
||||
}
|
||||
|
||||
// ── format_stage_notification ───────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
|
||||
1
vendor/rusqlite/.cargo-ok
vendored
1
vendor/rusqlite/.cargo-ok
vendored
@@ -1 +0,0 @@
|
||||
{"v":1}
|
||||
6
vendor/rusqlite/.cargo_vcs_info.json
vendored
6
vendor/rusqlite/.cargo_vcs_info.json
vendored
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "2a1790a69107cd03dae85d501dcbdb11c5b32ef3"
|
||||
},
|
||||
"path_in_vcs": ""
|
||||
}
|
||||
3
vendor/rusqlite/.gitignore
vendored
3
vendor/rusqlite/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
/target/
|
||||
/doc/
|
||||
Cargo.lock
|
||||
350
vendor/rusqlite/Cargo.toml
vendored
350
vendor/rusqlite/Cargo.toml
vendored
@@ -1,350 +0,0 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "rusqlite"
|
||||
version = "0.37.99"
|
||||
authors = ["The rusqlite developers"]
|
||||
build = false
|
||||
exclude = [
|
||||
"/.github/*",
|
||||
"/.gitattributes",
|
||||
"/appveyor.yml",
|
||||
"/Changelog.md",
|
||||
"/clippy.toml",
|
||||
"/codecov.yml",
|
||||
"**/*.sh",
|
||||
]
|
||||
autolib = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
autobenches = false
|
||||
description = "Ergonomic wrapper for SQLite"
|
||||
documentation = "https://docs.rs/rusqlite/"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"sqlite",
|
||||
"database",
|
||||
"ffi",
|
||||
]
|
||||
categories = ["database"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/rusqlite/rusqlite"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [
|
||||
"modern-full",
|
||||
"rusqlite-macros",
|
||||
]
|
||||
all-features = false
|
||||
no-default-features = false
|
||||
default-target = "x86_64-unknown-linux-gnu"
|
||||
rustdoc-args = [
|
||||
"--cfg",
|
||||
"docsrs",
|
||||
]
|
||||
|
||||
[package.metadata.playground]
|
||||
features = ["bundled-full"]
|
||||
all-features = false
|
||||
|
||||
[badges.appveyor]
|
||||
repository = "rusqlite/rusqlite"
|
||||
|
||||
[badges.codecov]
|
||||
repository = "rusqlite/rusqlite"
|
||||
|
||||
[badges.maintenance]
|
||||
status = "actively-developed"
|
||||
|
||||
[features]
|
||||
array = [
|
||||
"vtab",
|
||||
"pointer",
|
||||
]
|
||||
backup = []
|
||||
blob = []
|
||||
buildtime_bindgen = [
|
||||
"libsqlite3-sys/buildtime_bindgen",
|
||||
"sqlite-wasm-rs/bindgen",
|
||||
]
|
||||
bundled = [
|
||||
"libsqlite3-sys/bundled",
|
||||
"modern_sqlite",
|
||||
]
|
||||
bundled-full = [
|
||||
"modern-full",
|
||||
"bundled",
|
||||
]
|
||||
bundled-sqlcipher = [
|
||||
"libsqlite3-sys/bundled-sqlcipher",
|
||||
"bundled",
|
||||
]
|
||||
bundled-sqlcipher-vendored-openssl = [
|
||||
"libsqlite3-sys/bundled-sqlcipher-vendored-openssl",
|
||||
"bundled-sqlcipher",
|
||||
]
|
||||
bundled-windows = ["libsqlite3-sys/bundled-windows"]
|
||||
cache = ["hashlink"]
|
||||
collation = []
|
||||
column_decltype = []
|
||||
column_metadata = ["libsqlite3-sys/column_metadata"]
|
||||
csvtab = [
|
||||
"csv",
|
||||
"vtab",
|
||||
]
|
||||
default = ["cache"]
|
||||
extra_check = []
|
||||
fallible_uint = []
|
||||
functions = []
|
||||
hooks = []
|
||||
i128_blob = []
|
||||
in_gecko = [
|
||||
"modern_sqlite",
|
||||
"libsqlite3-sys/in_gecko",
|
||||
]
|
||||
limits = []
|
||||
load_extension = []
|
||||
loadable_extension = ["libsqlite3-sys/loadable_extension"]
|
||||
modern-full = [
|
||||
"array",
|
||||
"backup",
|
||||
"blob",
|
||||
"modern_sqlite",
|
||||
"chrono",
|
||||
"collation",
|
||||
"column_metadata",
|
||||
"column_decltype",
|
||||
"csvtab",
|
||||
"extra_check",
|
||||
"functions",
|
||||
"hooks",
|
||||
"i128_blob",
|
||||
"jiff",
|
||||
"limits",
|
||||
"load_extension",
|
||||
"serde_json",
|
||||
"serialize",
|
||||
"series",
|
||||
"time",
|
||||
"trace",
|
||||
"unlock_notify",
|
||||
"url",
|
||||
"uuid",
|
||||
"vtab",
|
||||
"window",
|
||||
]
|
||||
modern_sqlite = ["libsqlite3-sys/bundled_bindings"]
|
||||
pointer = []
|
||||
preupdate_hook = [
|
||||
"libsqlite3-sys/preupdate_hook",
|
||||
"hooks",
|
||||
]
|
||||
serialize = []
|
||||
series = ["vtab"]
|
||||
session = [
|
||||
"libsqlite3-sys/session",
|
||||
"hooks",
|
||||
]
|
||||
sqlcipher = ["libsqlite3-sys/sqlcipher"]
|
||||
trace = []
|
||||
unlock_notify = ["libsqlite3-sys/unlock_notify"]
|
||||
vtab = []
|
||||
wasm32-wasi-vfs = ["libsqlite3-sys/wasm32-wasi-vfs"]
|
||||
window = ["functions"]
|
||||
with-asan = ["libsqlite3-sys/with-asan"]
|
||||
|
||||
[lib]
|
||||
name = "rusqlite"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[example]]
|
||||
name = "load_extension"
|
||||
path = "examples/load_extension.rs"
|
||||
required-features = [
|
||||
"load_extension",
|
||||
"bundled",
|
||||
"functions",
|
||||
"trace",
|
||||
]
|
||||
|
||||
[[example]]
|
||||
name = "loadable_extension"
|
||||
crate-type = ["cdylib"]
|
||||
path = "examples/loadable_extension.rs"
|
||||
required-features = [
|
||||
"loadable_extension",
|
||||
"functions",
|
||||
"trace",
|
||||
]
|
||||
|
||||
[[example]]
|
||||
name = "owning_rows"
|
||||
path = "examples/owning_rows.rs"
|
||||
|
||||
[[example]]
|
||||
name = "owning_statement"
|
||||
path = "examples/owning_statement.rs"
|
||||
|
||||
[[example]]
|
||||
name = "persons"
|
||||
path = "examples/persons/main.rs"
|
||||
|
||||
[[test]]
|
||||
name = "auto_ext"
|
||||
path = "tests/auto_ext.rs"
|
||||
|
||||
[[test]]
|
||||
name = "config_log"
|
||||
path = "tests/config_log.rs"
|
||||
harness = false
|
||||
|
||||
[[test]]
|
||||
name = "deny_single_threaded_sqlite_config"
|
||||
path = "tests/deny_single_threaded_sqlite_config.rs"
|
||||
|
||||
[[test]]
|
||||
name = "vtab"
|
||||
path = "tests/vtab.rs"
|
||||
|
||||
[[bench]]
|
||||
name = "cache"
|
||||
path = "benches/cache.rs"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "exec"
|
||||
path = "benches/exec.rs"
|
||||
harness = false
|
||||
|
||||
[dependencies.bitflags]
|
||||
version = "2.6.0"
|
||||
|
||||
[dependencies.chrono]
|
||||
version = "0.4.42"
|
||||
features = ["clock"]
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.csv]
|
||||
version = "1.1"
|
||||
optional = true
|
||||
|
||||
[dependencies.fallible-iterator]
|
||||
version = "0.3"
|
||||
|
||||
[dependencies.fallible-streaming-iterator]
|
||||
version = "0.1"
|
||||
|
||||
[dependencies.hashlink]
|
||||
version = "0.11"
|
||||
optional = true
|
||||
|
||||
[dependencies.jiff]
|
||||
version = "0.2"
|
||||
features = ["std"]
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.rusqlite-macros]
|
||||
version = "0.4.2"
|
||||
optional = true
|
||||
|
||||
[dependencies.serde_json]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
|
||||
[dependencies.smallvec]
|
||||
version = "1.6.1"
|
||||
|
||||
[dependencies.time]
|
||||
version = "0.3.47"
|
||||
features = [
|
||||
"formatting",
|
||||
"macros",
|
||||
"parsing",
|
||||
]
|
||||
optional = true
|
||||
|
||||
[dependencies.url]
|
||||
version = "2.1"
|
||||
optional = true
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
|
||||
[dev-dependencies.bencher]
|
||||
version = "0.1"
|
||||
|
||||
[dev-dependencies.doc-comment]
|
||||
version = "0.3"
|
||||
|
||||
[dev-dependencies.regex]
|
||||
version = "1.5.5"
|
||||
|
||||
[dev-dependencies.self_cell]
|
||||
version = "1.1.0"
|
||||
|
||||
[dev-dependencies.tempfile]
|
||||
version = "3.1.0"
|
||||
|
||||
[dev-dependencies.unicase]
|
||||
version = "2.6.0"
|
||||
|
||||
[dev-dependencies.uuid]
|
||||
version = "1.0"
|
||||
features = ["v4"]
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies.chrono]
|
||||
version = "0.4.42"
|
||||
features = ["wasmbind"]
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies.jiff]
|
||||
version = "0.2"
|
||||
features = ["js"]
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies.sqlite-wasm-rs]
|
||||
version = "0.5.1"
|
||||
default-features = false
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies.time]
|
||||
version = "0.3.47"
|
||||
features = ["wasm-bindgen"]
|
||||
optional = true
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies.uuid]
|
||||
version = "1.0"
|
||||
features = ["js"]
|
||||
optional = true
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies.getrandom]
|
||||
version = "0.4"
|
||||
features = ["wasm_js"]
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies.uuid]
|
||||
version = "1.0"
|
||||
features = ["js"]
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies.wasm-bindgen]
|
||||
version = "0.2.104"
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies.wasm-bindgen-test]
|
||||
version = "0.3.54"
|
||||
|
||||
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies.libsqlite3-sys]
|
||||
version = "0.37.0"
|
||||
242
vendor/rusqlite/Cargo.toml.orig
generated
vendored
242
vendor/rusqlite/Cargo.toml.orig
generated
vendored
@@ -1,242 +0,0 @@
|
||||
[package]
|
||||
name = "rusqlite"
|
||||
# Note: Update version in README.md when you change this.
|
||||
version = "0.37.99"
|
||||
authors = ["The rusqlite developers"]
|
||||
edition = "2021"
|
||||
description = "Ergonomic wrapper for SQLite"
|
||||
repository = "https://github.com/rusqlite/rusqlite"
|
||||
documentation = "https://docs.rs/rusqlite/"
|
||||
readme = "README.md"
|
||||
keywords = ["sqlite", "database", "ffi"]
|
||||
license = "MIT"
|
||||
categories = ["database"]
|
||||
|
||||
exclude = [
|
||||
"/.github/*",
|
||||
"/.gitattributes",
|
||||
"/appveyor.yml",
|
||||
"/Changelog.md",
|
||||
"/clippy.toml",
|
||||
"/codecov.yml",
|
||||
"**/*.sh",
|
||||
]
|
||||
|
||||
[badges]
|
||||
appveyor = { repository = "rusqlite/rusqlite" }
|
||||
codecov = { repository = "rusqlite/rusqlite" }
|
||||
maintenance = { status = "actively-developed" }
|
||||
|
||||
[lib]
|
||||
name = "rusqlite"
|
||||
|
||||
[workspace]
|
||||
members = ["libsqlite3-sys"]
|
||||
|
||||
[features]
|
||||
# if not SQLITE_OMIT_LOAD_EXTENSION
|
||||
load_extension = []
|
||||
# hot-backup interface
|
||||
backup = []
|
||||
# if not SQLITE_OMIT_INCRBLOB
|
||||
# sqlite3_blob
|
||||
blob = []
|
||||
# Prepared statements cache by connection (like https://www.sqlite.org/tclsqlite.html#cache)
|
||||
cache = ["hashlink"]
|
||||
# sqlite3_create_collation_v2
|
||||
collation = []
|
||||
# sqlite3_create_function_v2
|
||||
functions = []
|
||||
# sqlite3_log / sqlite3_trace_v2
|
||||
trace = []
|
||||
# Use bundled SQLite sources (instead of the one provided by your OS / distribution)
|
||||
bundled = ["libsqlite3-sys/bundled", "modern_sqlite"]
|
||||
# Use SQLCipher instead of SQLite
|
||||
bundled-sqlcipher = ["libsqlite3-sys/bundled-sqlcipher", "bundled"]
|
||||
bundled-sqlcipher-vendored-openssl = [
|
||||
"libsqlite3-sys/bundled-sqlcipher-vendored-openssl",
|
||||
"bundled-sqlcipher",
|
||||
]
|
||||
buildtime_bindgen = ["libsqlite3-sys/buildtime_bindgen", "sqlite-wasm-rs/bindgen"]
|
||||
# sqlite3_limit
|
||||
limits = []
|
||||
# Used to generate a cdylib
|
||||
loadable_extension = ["libsqlite3-sys/loadable_extension"]
|
||||
# sqlite3_commit_hook, sqlite3_rollback_hook, ...
|
||||
hooks = []
|
||||
# if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
preupdate_hook = ["libsqlite3-sys/preupdate_hook", "hooks"]
|
||||
# u64, usize, NonZeroU64, NonZeroUsize
|
||||
fallible_uint = []
|
||||
i128_blob = []
|
||||
sqlcipher = ["libsqlite3-sys/sqlcipher"]
|
||||
# SQLITE_ENABLE_UNLOCK_NOTIFY
|
||||
unlock_notify = ["libsqlite3-sys/unlock_notify"]
|
||||
# if not SQLITE_OMIT_VIRTUALTABLE
|
||||
# sqlite3_vtab
|
||||
vtab = []
|
||||
csvtab = ["csv", "vtab"]
|
||||
# Port of Carray() table-valued function
|
||||
array = ["vtab", "pointer"]
|
||||
# if SQLITE_ENABLE_SESSION
|
||||
# session extension
|
||||
session = ["libsqlite3-sys/session", "hooks"]
|
||||
# if not SQLITE_OMIT_WINDOWFUNC
|
||||
# sqlite3_create_window_function
|
||||
window = ["functions"]
|
||||
# Port of generate_series table-valued function
|
||||
series = ["vtab"]
|
||||
# check for invalid query.
|
||||
extra_check = []
|
||||
# ]3.34.1, last]
|
||||
modern_sqlite = ["libsqlite3-sys/bundled_bindings"]
|
||||
in_gecko = ["modern_sqlite", "libsqlite3-sys/in_gecko"]
|
||||
bundled-windows = ["libsqlite3-sys/bundled-windows"]
|
||||
# Build bundled sqlite with -fsanitize=address
|
||||
with-asan = ["libsqlite3-sys/with-asan"]
|
||||
# if SQLITE_ENABLE_COLUMN_METADATA
|
||||
column_metadata = ["libsqlite3-sys/column_metadata"]
|
||||
# if not SQLITE_OMIT_DECLTYPE
|
||||
column_decltype = []
|
||||
wasm32-wasi-vfs = ["libsqlite3-sys/wasm32-wasi-vfs"]
|
||||
# if not SQLITE_OMIT_DESERIALIZE
|
||||
serialize = []
|
||||
# pointer passing interfaces: 3.20.0
|
||||
pointer = []
|
||||
|
||||
# Helper feature for enabling most non-build-related optional features
|
||||
# or dependencies (except `session`). This is useful for running tests / clippy
|
||||
# / etc. New features and optional dependencies that don't conflict with anything
|
||||
# else should be added here.
|
||||
modern-full = [
|
||||
"array",
|
||||
"backup",
|
||||
"blob",
|
||||
"modern_sqlite",
|
||||
"chrono",
|
||||
"collation",
|
||||
"column_metadata",
|
||||
"column_decltype",
|
||||
"csvtab",
|
||||
"extra_check",
|
||||
"functions",
|
||||
"hooks",
|
||||
"i128_blob",
|
||||
"jiff",
|
||||
"limits",
|
||||
"load_extension",
|
||||
"serde_json",
|
||||
"serialize",
|
||||
"series",
|
||||
"time",
|
||||
"trace",
|
||||
"unlock_notify",
|
||||
"url",
|
||||
"uuid",
|
||||
"vtab",
|
||||
"window",
|
||||
]
|
||||
|
||||
bundled-full = ["modern-full", "bundled"]
|
||||
default = ["cache"]
|
||||
|
||||
[dependencies]
|
||||
# Jiff Date/Time/Timestamp persistence
|
||||
jiff = { version = "0.2", optional = true, default-features = false, features = [
|
||||
"std",
|
||||
] }
|
||||
# Date/Time/Timestamp persistence
|
||||
time = { version = "0.3.47", features = [
|
||||
"formatting",
|
||||
"macros",
|
||||
"parsing",
|
||||
], optional = true }
|
||||
bitflags = "2.6.0"
|
||||
# LRU cache of statement
|
||||
hashlink = { version = "0.11", optional = true }
|
||||
# Chrono Date/Time/Timestamp persistence
|
||||
chrono = { version = "0.4.42", optional = true, default-features = false, features = [
|
||||
"clock",
|
||||
] }
|
||||
# JSON persistence
|
||||
serde_json = { version = "1.0", optional = true }
|
||||
# Virtual table
|
||||
csv = { version = "1.1", optional = true }
|
||||
# Url persistence
|
||||
url = { version = "2.1", optional = true }
|
||||
fallible-iterator = "0.3"
|
||||
fallible-streaming-iterator = "0.1"
|
||||
# Uuid persistence
|
||||
uuid = { version = "1.0", optional = true }
|
||||
smallvec = "1.6.1"
|
||||
# WIP comptime checks
|
||||
rusqlite-macros = { path = "rusqlite-macros", version = "0.4.2", optional = true }
|
||||
|
||||
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
|
||||
libsqlite3-sys = { path = "libsqlite3-sys", version = "0.37.0" }
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
|
||||
sqlite-wasm-rs = { version = "0.5.1", default-features = false }
|
||||
chrono = { version = "0.4.42", optional = true, default-features = false, features = ["wasmbind"] }
|
||||
jiff = { version = "0.2", optional = true, default-features = false, features = ["js"] }
|
||||
time = { version = "0.3.47", optional = true, features = ["wasm-bindgen"] }
|
||||
uuid = { version = "1.0", optional = true, features = ["js"] }
|
||||
|
||||
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies]
|
||||
# Something is dependent on them, we use feature to override it.
|
||||
uuid = { version = "1.0", features = ["js"] }
|
||||
getrandom = { version = "0.4", features = ["wasm_js"] }
|
||||
wasm-bindgen-test = "0.3.54"
|
||||
wasm-bindgen = "0.2.104"
|
||||
|
||||
[dev-dependencies]
|
||||
doc-comment = "0.3"
|
||||
tempfile = "3.1.0"
|
||||
regex = "1.5.5"
|
||||
uuid = { version = "1.0", features = ["v4"] }
|
||||
unicase = "2.6.0"
|
||||
self_cell = "1.1.0"
|
||||
# Use `bencher` over criterion because it builds much faster,
|
||||
# and we don't have many benchmarks
|
||||
bencher = "0.1"
|
||||
|
||||
[[test]]
|
||||
name = "auto_ext"
|
||||
|
||||
[[test]]
|
||||
name = "config_log"
|
||||
harness = false
|
||||
|
||||
[[test]]
|
||||
name = "deny_single_threaded_sqlite_config"
|
||||
|
||||
[[test]]
|
||||
name = "vtab"
|
||||
|
||||
[[bench]]
|
||||
name = "cache"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "exec"
|
||||
harness = false
|
||||
|
||||
[[example]]
|
||||
name = "loadable_extension"
|
||||
crate-type = ["cdylib"]
|
||||
required-features = ["loadable_extension", "functions", "trace"]
|
||||
|
||||
[[example]]
|
||||
name = "load_extension"
|
||||
required-features = ["load_extension", "bundled", "functions", "trace"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["modern-full", "rusqlite-macros"]
|
||||
all-features = false
|
||||
no-default-features = false
|
||||
default-target = "x86_64-unknown-linux-gnu"
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[package.metadata.playground]
|
||||
features = ["bundled-full"]
|
||||
all-features = false
|
||||
19
vendor/rusqlite/LICENSE
vendored
19
vendor/rusqlite/LICENSE
vendored
@@ -1,19 +0,0 @@
|
||||
Copyright (c) 2014 The rusqlite developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
259
vendor/rusqlite/README.md
vendored
259
vendor/rusqlite/README.md
vendored
@@ -1,259 +0,0 @@
|
||||
# Rusqlite
|
||||
|
||||
[](https://crates.io/crates/rusqlite)
|
||||
[](https://docs.rs/rusqlite)
|
||||
[](https://github.com/rusqlite/rusqlite/actions)
|
||||
[](https://ci.appveyor.com/project/rusqlite/rusqlite)
|
||||
[](https://codecov.io/gh/rusqlite/rusqlite)
|
||||
[](https://deps.rs/repo/github/rusqlite/rusqlite)
|
||||
[](https://discord.gg/nFYfGPB8g4)
|
||||
|
||||
Rusqlite is an ergonomic wrapper for using SQLite from Rust.
|
||||
|
||||
Historically, the API was based on the one from [`rust-postgres`](https://github.com/sfackler/rust-postgres). However, the two have diverged in many ways, and no compatibility between the two is intended.
|
||||
|
||||
## Usage
|
||||
|
||||
In your Cargo.toml:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
# `bundled` causes us to automatically compile and link in an up to date
|
||||
# version of SQLite for you. This avoids many common build issues, and
|
||||
# avoids depending on the version of SQLite on the users system (or your
|
||||
# system), which may be old or missing. It's the right choice for most
|
||||
# programs that control their own SQLite databases.
|
||||
#
|
||||
# That said, it's not ideal for all scenarios and in particular, generic
|
||||
# libraries built around `rusqlite` should probably not enable it, which
|
||||
# is why it is not a default feature -- it could become hard to disable.
|
||||
rusqlite = { version = "0.39.0", features = ["bundled"] }
|
||||
```
|
||||
|
||||
Simple example usage:
|
||||
|
||||
```rust
|
||||
use rusqlite::{Connection, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Person {
|
||||
id: i32,
|
||||
name: String,
|
||||
data: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let conn = Connection::open_in_memory()?;
|
||||
|
||||
conn.execute(
|
||||
"CREATE TABLE person (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
data BLOB
|
||||
)",
|
||||
(), // empty list of parameters.
|
||||
)?;
|
||||
let me = Person {
|
||||
id: 0,
|
||||
name: "Steven".to_string(),
|
||||
data: None,
|
||||
};
|
||||
conn.execute(
|
||||
"INSERT INTO person (name, data) VALUES (?1, ?2)",
|
||||
(&me.name, &me.data),
|
||||
)?;
|
||||
|
||||
let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
|
||||
let person_iter = stmt.query_map([], |row| {
|
||||
Ok(Person {
|
||||
id: row.get(0)?,
|
||||
name: row.get(1)?,
|
||||
data: row.get(2)?,
|
||||
})
|
||||
})?;
|
||||
|
||||
for person in person_iter {
|
||||
println!("Found person {:?}", person.unwrap());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
### Supported SQLite Versions
|
||||
|
||||
The base `rusqlite` package supports SQLite version 3.34.1 or newer. If you need
|
||||
support for older versions, please file an issue. Some cargo features require a
|
||||
newer SQLite version; see details below.
|
||||
|
||||
### Optional Features
|
||||
|
||||
Rusqlite provides several features that are behind [Cargo
|
||||
features](https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section). They are:
|
||||
|
||||
* [`load_extension`](https://docs.rs/rusqlite/~0/rusqlite/struct.LoadExtensionGuard.html)
|
||||
allows loading dynamic library-based SQLite extensions.
|
||||
* `loadable_extension` to program [loadable extension](https://sqlite.org/loadext.html) in Rust.
|
||||
* [`backup`](https://docs.rs/rusqlite/~0/rusqlite/backup/index.html)
|
||||
allows use of SQLite's online backup API.
|
||||
* [`functions`](https://docs.rs/rusqlite/~0/rusqlite/functions/index.html)
|
||||
allows you to load Rust closures into SQLite connections for use in queries.
|
||||
* `window` for [window function](https://www.sqlite.org/windowfunctions.html) support (`fun(...) OVER ...`). (Implies `functions`.)
|
||||
* [`trace`](https://docs.rs/rusqlite/~0/rusqlite/trace/index.html)
|
||||
allows hooks into SQLite's tracing and profiling APIs.
|
||||
* [`blob`](https://docs.rs/rusqlite/~0/rusqlite/blob/index.html)
|
||||
gives `std::io::{Read, Write, Seek}` access to SQL BLOBs.
|
||||
* [`limits`](https://docs.rs/rusqlite/~0/rusqlite/struct.Connection.html#method.limit)
|
||||
allows you to set and retrieve SQLite's per connection limits.
|
||||
* `serde_json` implements [`FromSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.FromSql.html)
|
||||
and [`ToSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.ToSql.html) for the
|
||||
`Value` type from the [`serde_json` crate](https://crates.io/crates/serde_json).
|
||||
* `chrono` implements [`FromSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.FromSql.html)
|
||||
and [`ToSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.ToSql.html) for various
|
||||
types from the [`chrono` crate](https://crates.io/crates/chrono).
|
||||
* `time` implements [`FromSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.FromSql.html)
|
||||
and [`ToSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.ToSql.html) for various
|
||||
types from the [`time` crate](https://crates.io/crates/time).
|
||||
* `jiff` implements [`FromSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.FromSql.html)
|
||||
and [`ToSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.ToSql.html) for the
|
||||
`Value` type from the [`jiff` crate](https://crates.io/crates/jiff).
|
||||
* `url` implements [`FromSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.FromSql.html)
|
||||
and [`ToSql`](https://docs.rs/rusqlite/~0/rusqlite/types/trait.ToSql.html) for the
|
||||
`Url` type from the [`url` crate](https://crates.io/crates/url).
|
||||
* `bundled` uses a bundled version of SQLite. This is a good option for cases where linking to SQLite is complicated, such as Windows.
|
||||
* `sqlcipher` looks for the SQLCipher library to link against instead of SQLite. This feature overrides `bundled`.
|
||||
* `bundled-sqlcipher` uses a bundled version of SQLCipher. This searches for and links against a system-installed crypto library to provide the crypto implementation.
|
||||
* `bundled-sqlcipher-vendored-openssl` allows using bundled-sqlcipher with a vendored version of OpenSSL (via the `openssl-sys` crate) as the crypto provider.
|
||||
- As the name implies this depends on the `bundled-sqlcipher` feature, and automatically turns it on.
|
||||
- If turned on, this uses the [`openssl-sys`](https://crates.io/crates/openssl-sys) crate, with the `vendored` feature enabled in order to build and bundle the OpenSSL crypto library.
|
||||
* `hooks` for [Commit, Rollback](http://sqlite.org/c3ref/commit_hook.html) and [Data Change](http://sqlite.org/c3ref/update_hook.html) notification callbacks.
|
||||
* `preupdate_hook` for [preupdate](https://sqlite.org/c3ref/preupdate_count.html) notification callbacks. (Implies `hooks`.)
|
||||
* `unlock_notify` for [Unlock](https://sqlite.org/unlock_notify.html) notification.
|
||||
* `vtab` for [virtual table](https://sqlite.org/vtab.html) support (allows you to write virtual table implementations in Rust). Currently, only read-only virtual tables are supported.
|
||||
* `series` exposes [`generate_series(...)`](https://www.sqlite.org/series.html) Table-Valued Function. (Implies `vtab`.)
|
||||
* [`csvtab`](https://sqlite.org/csv.html), CSV virtual table written in Rust. (Implies `vtab`.)
|
||||
* [`array`](https://sqlite.org/carray.html), The `rarray()` Table-Valued Function. (Implies `vtab`.)
|
||||
* `fallible_uint` allows storing values of type `u64`, `usize`, `NonZeroU64`, `NonZeroUsize` but only if <= `i64::MAX`.
|
||||
* `i128_blob` allows storing values of type `i128` type in SQLite databases. Internally, the data is stored as a 16 byte big-endian blob, with the most significant bit flipped, which allows ordering and comparison between different blobs storing i128s to work as expected.
|
||||
* `uuid` allows storing and retrieving `Uuid` values from the [`uuid`](https://docs.rs/uuid/) crate using blobs.
|
||||
* [`session`](https://sqlite.org/sessionintro.html), Session module extension. Requires `buildtime_bindgen` feature. (Implies `hooks`.)
|
||||
* `extra_check` fails when a query passed to `execute` is readonly and has a column count > 0.
|
||||
* `column_decltype` provides `columns()` method for Statements and Rows; omit if linking to a version of SQLite/SQLCipher compiled with `-DSQLITE_OMIT_DECLTYPE`.
|
||||
* `collation` exposes [`sqlite3_create_collation_v2`](https://sqlite.org/c3ref/create_collation.html).
|
||||
* `serialize` exposes [`sqlite3_serialize`](http://sqlite.org/c3ref/serialize.html) (3.23.0).
|
||||
* `rusqlite-macros` enables the use of the [`prepare_and_bind`](https://docs.rs/rusqlite/~0/rusqlite/macro.prepare_and_bind.html)
|
||||
and [`prepare_cached_and_bind`](https://docs.rs/rusqlite/~0/rusqlite/macro.prepare_cached_and_bind.html)
|
||||
procedural macros, which allow capturing identifiers in SQL statements.
|
||||
|
||||
|
||||
## Notes on building rusqlite and libsqlite3-sys
|
||||
|
||||
`libsqlite3-sys` is a separate crate from `rusqlite` that provides the Rust
|
||||
declarations for SQLite's C API. By default, `libsqlite3-sys` attempts to find a SQLite library that already exists on your system using pkg-config, or a
|
||||
[Vcpkg](https://github.com/Microsoft/vcpkg) installation for MSVC ABI builds.
|
||||
|
||||
You can adjust this behavior in a number of ways:
|
||||
|
||||
* If you use the `bundled`, `bundled-sqlcipher`, or `bundled-sqlcipher-vendored-openssl` features, `libsqlite3-sys` will use the
|
||||
[cc](https://crates.io/crates/cc) crate to compile SQLite or SQLCipher from source and
|
||||
link against that. This source is embedded in the `libsqlite3-sys` crate and
|
||||
is currently SQLite 3.51.3 (as of `rusqlite` 0.39.0 / `libsqlite3-sys`
|
||||
0.37.0). This is probably the simplest solution to any build problems. You can enable this by adding the following in your `Cargo.toml` file:
|
||||
```toml
|
||||
[dependencies.rusqlite]
|
||||
version = "0.39.0"
|
||||
features = ["bundled"]
|
||||
```
|
||||
* When using any of the `bundled` features, the build script will honor `SQLITE_MAX_VARIABLE_NUMBER` and `SQLITE_MAX_EXPR_DEPTH` variables. It will also honor a `LIBSQLITE3_FLAGS` variable, which can have a format like `"-USQLITE_ALPHA -DSQLITE_BETA SQLITE_GAMMA ..."`. That would disable the `SQLITE_ALPHA` flag, and set the `SQLITE_BETA` and `SQLITE_GAMMA` flags. (The initial `-D` can be omitted, as on the last one.)
|
||||
* When using `bundled-sqlcipher` (and not also using `bundled-sqlcipher-vendored-openssl`), `libsqlite3-sys` will need to
|
||||
link against crypto libraries on the system. If the build script can find a `libcrypto` from OpenSSL or LibreSSL (it will consult `OPENSSL_LIB_DIR`/`OPENSSL_INCLUDE_DIR` and `OPENSSL_DIR` environment variables), it will use that. If building on and for Macs, and none of those variables are set, it will use the system's SecurityFramework instead.
|
||||
|
||||
* When linking against a SQLite (or SQLCipher) library already on the system (so *not* using any of the `bundled` features), you can set the `SQLITE3_LIB_DIR` (or `SQLCIPHER_LIB_DIR`) environment variable to point to a directory containing the library. You can also set the `SQLITE3_INCLUDE_DIR` (or `SQLCIPHER_INCLUDE_DIR`) variable to point to the directory containing `sqlite3.h`.
|
||||
* Installing the sqlite3 development packages will usually be all that is required, but
|
||||
the build helpers for [pkg-config](https://github.com/alexcrichton/pkg-config-rs)
|
||||
and [vcpkg](https://github.com/mcgoo/vcpkg-rs) have some additional configuration
|
||||
options. The default when using vcpkg is to dynamically link,
|
||||
which must be enabled by setting `VCPKGRS_DYNAMIC=1` environment variable before build.
|
||||
`vcpkg install sqlite3:x64-windows` will install the required library.
|
||||
* When linking against a SQLite (or SQLCipher) library already on the system, you can set the `SQLITE3_STATIC` (or `SQLCIPHER_STATIC`) environment variable to 1 to request that the library be statically instead of dynamically linked.
|
||||
|
||||
|
||||
### Binding generation
|
||||
|
||||
We use [bindgen](https://crates.io/crates/bindgen) to generate the Rust
|
||||
declarations from SQLite's C header file. `bindgen`
|
||||
[recommends](https://github.com/servo/rust-bindgen#library-usage-with-buildrs)
|
||||
running this as part of the build process of libraries that used this. We tried
|
||||
this briefly (`rusqlite` 0.10.0, specifically), but it had some annoyances:
|
||||
|
||||
* The build time for `libsqlite3-sys` (and therefore `rusqlite`) increased
|
||||
dramatically.
|
||||
* Running `bindgen` requires a relatively-recent version of Clang, which many
|
||||
systems do not have installed by default.
|
||||
* Running `bindgen` also requires the SQLite header file to be present.
|
||||
|
||||
As of `rusqlite` 0.10.1, we avoid running `bindgen` at build-time by shipping
|
||||
pregenerated bindings for several versions of SQLite. When compiling
|
||||
`rusqlite`, we use your selected Cargo features to pick the bindings for the
|
||||
minimum SQLite version that supports your chosen features. If you are using
|
||||
`libsqlite3-sys` directly, you can use the same features to choose which
|
||||
pregenerated bindings are chosen:
|
||||
|
||||
* `min_sqlite_version_3_34_1` - SQLite 3.34.1 bindings (this is the default)
|
||||
|
||||
If you use any of the `bundled` features, you will get pregenerated bindings for the
|
||||
bundled version of SQLite/SQLCipher. If you need other specific pregenerated binding
|
||||
versions, please file an issue. If you want to run `bindgen` at buildtime to
|
||||
produce your own bindings, use the `buildtime_bindgen` Cargo feature.
|
||||
|
||||
If you enable the `modern_sqlite` feature, we'll use the bindings we would have
|
||||
included with the bundled build. You generally should have `buildtime_bindgen`
|
||||
enabled if you turn this on, as otherwise you'll need to keep the version of
|
||||
SQLite you link with in sync with what rusqlite would have bundled, (usually the
|
||||
most recent release of SQLite). Failing to do this will cause a runtime error.
|
||||
|
||||
## Contributing
|
||||
|
||||
Rusqlite has many features, and many of them impact the build configuration in
|
||||
incompatible ways. This is unfortunate, and makes testing changes hard.
|
||||
|
||||
To help here: you generally should ensure that you run tests/lint for
|
||||
`--features bundled`, and `--features "bundled-full session buildtime_bindgen"`.
|
||||
|
||||
If running bindgen is problematic for you, `--features bundled-full` enables
|
||||
bundled and all features which don't require binding generation, and can be used
|
||||
instead.
|
||||
|
||||
### Checklist
|
||||
|
||||
- Run `cargo fmt` to ensure your Rust code is correctly formatted.
|
||||
- Ensure `cargo clippy --workspace --features bundled` passes without warnings.
|
||||
- Ensure `cargo clippy --workspace --features "bundled-full session buildtime_bindgen"` passes without warnings.
|
||||
- Ensure `cargo test --workspace --features bundled` reports no failures.
|
||||
- Ensure `cargo test --workspace --features "bundled-full session buildtime_bindgen"` reports no failures.
|
||||
|
||||
## Author
|
||||
|
||||
Rusqlite is the product of hard work by a number of people. A list is available
|
||||
here: https://github.com/rusqlite/rusqlite/graphs/contributors
|
||||
|
||||
## Community
|
||||
|
||||
Feel free to join the [Rusqlite Discord Server](https://discord.gg/nFYfGPB8g4) to discuss or get help with `rusqlite` or `libsqlite3-sys`.
|
||||
|
||||
## License
|
||||
|
||||
Rusqlite and libsqlite3-sys are available under the MIT license. See the LICENSE file for more info.
|
||||
|
||||
### Licenses of Bundled Software
|
||||
|
||||
Depending on the set of enabled cargo `features`, rusqlite and libsqlite3-sys will also bundle other libraries, which have their own licensing terms:
|
||||
|
||||
- If `--features=bundled-sqlcipher` is enabled, the vendored source of [SQLcipher](https://github.com/sqlcipher/sqlcipher) will be compiled and statically linked in. SQLcipher is distributed under a BSD-style license, as described [here](libsqlite3-sys/sqlcipher/LICENSE).
|
||||
|
||||
- If `--features=bundled` is enabled, the vendored source of SQLite will be compiled and linked in. SQLite is in the public domain, as described [here](https://www.sqlite.org/copyright.html).
|
||||
|
||||
Both of these are quite permissive, have no bearing on the license of the code in `rusqlite` or `libsqlite3-sys` themselves, and can be entirely ignored if you do not use the feature in question.
|
||||
|
||||
## Minimum supported Rust version (MSRV)
|
||||
|
||||
Latest stable Rust version at the time of release. It might compile with older versions.
|
||||
18
vendor/rusqlite/benches/cache.rs
vendored
18
vendor/rusqlite/benches/cache.rs
vendored
@@ -1,18 +0,0 @@
|
||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
||||
use rusqlite::Connection;
|
||||
|
||||
fn bench_no_cache(b: &mut Bencher) {
|
||||
let db = Connection::open_in_memory().unwrap();
|
||||
db.set_prepared_statement_cache_capacity(0);
|
||||
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
|
||||
b.iter(|| db.prepare(sql).unwrap());
|
||||
}
|
||||
|
||||
fn bench_cache(b: &mut Bencher) {
|
||||
let db = Connection::open_in_memory().unwrap();
|
||||
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
|
||||
b.iter(|| db.prepare_cached(sql).unwrap());
|
||||
}
|
||||
|
||||
benchmark_group!(cache_benches, bench_no_cache, bench_cache);
|
||||
benchmark_main!(cache_benches);
|
||||
17
vendor/rusqlite/benches/exec.rs
vendored
17
vendor/rusqlite/benches/exec.rs
vendored
@@ -1,17 +0,0 @@
|
||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
||||
use rusqlite::Connection;
|
||||
|
||||
fn bench_execute(b: &mut Bencher) {
|
||||
let db = Connection::open_in_memory().unwrap();
|
||||
let sql = "PRAGMA user_version=1";
|
||||
b.iter(|| db.execute(sql, []).unwrap());
|
||||
}
|
||||
|
||||
fn bench_execute_batch(b: &mut Bencher) {
|
||||
let db = Connection::open_in_memory().unwrap();
|
||||
let sql = "PRAGMA user_version=1";
|
||||
b.iter(|| db.execute_batch(sql).unwrap());
|
||||
}
|
||||
|
||||
benchmark_group!(exec_benches, bench_execute, bench_execute_batch);
|
||||
benchmark_main!(exec_benches);
|
||||
405
vendor/rusqlite/bindings.md
vendored
405
vendor/rusqlite/bindings.md
vendored
@@ -1,405 +0,0 @@
|
||||
# List of SQLite functions supported
|
||||
|
||||
- [ ] `sqlite3_version`
|
||||
- [X] `sqlite3_libversion`
|
||||
- [ ] `sqlite3_sourceid`
|
||||
- [X] `sqlite3_libversion_number`
|
||||
|
||||
- [ ] `sqlite3_compileoption_used`
|
||||
- [ ] `sqlite3_compileoption_get`
|
||||
|
||||
- [X] `sqlite3_threadsafe` (internal use only)
|
||||
|
||||
- [X] `sqlite3_close`
|
||||
- [ ] `sqlite3_close_v2`
|
||||
|
||||
- [ ] `sqlite3_exec`
|
||||
|
||||
- [ ] `sqlite3_initialize`
|
||||
- [ ] `sqlite3_shutdown`
|
||||
- [ ] `sqlite3_os_init`
|
||||
- [ ] `sqlite3_os_end`
|
||||
|
||||
- [ ] `sqlite3_config` (partially, `fn` callback for SQLITE_CONFIG_LOG) (cannot be used by a loadable extension)
|
||||
- [X] `sqlite3_db_config`
|
||||
|
||||
- [X] `sqlite3_extended_result_codes` (not public, internal use only)
|
||||
|
||||
- [X] `sqlite3_last_insert_rowid`
|
||||
- [ ] `sqlite3_set_last_insert_rowid`
|
||||
|
||||
- [X] `sqlite3_changes`
|
||||
- [X] `sqlite3_changes64`
|
||||
- [X] `sqlite3_total_changes`
|
||||
- [X] `sqlite3_total_changes64`
|
||||
|
||||
- [X] `sqlite3_interrupt`
|
||||
- [X] `sqlite3_is_interrupted`
|
||||
|
||||
- [ ] `sqlite3_complete`
|
||||
|
||||
- [X] `sqlite3_busy_handler` (`fn` callback)
|
||||
- [X] `sqlite3_busy_timeout`
|
||||
|
||||
- [ ] `sqlite3_get_table`
|
||||
|
||||
- [ ] `sqlite3_mprintf`
|
||||
- [ ] `sqlite3_vmprintf`
|
||||
- [ ] `sqlite3_snprintf`
|
||||
- [ ] `sqlite3_vsnprintf`
|
||||
|
||||
- [ ] `sqlite3_malloc`
|
||||
- [X] `sqlite3_malloc64` (not public, internal use only)
|
||||
- [ ] `sqlite3_realloc`
|
||||
- [ ] `sqlite3_realloc64`
|
||||
- [X] `sqlite3_free` (not public, internal use only)
|
||||
- [ ] `sqlite3_msize`
|
||||
|
||||
- [ ] `sqlite3_memory_used`
|
||||
- [ ] `sqlite3_memory_highwater`
|
||||
|
||||
- [ ] `sqlite3_randomness`
|
||||
|
||||
- [X] `sqlite3_set_authorizer` (`FnMut` callback, reference kept)
|
||||
- [X] `sqlite3_trace` deprecated (`fn` callback)
|
||||
- [X] `sqlite3_profile` deprecated (`fn` callback)
|
||||
- [X] `sqlite3_trace_v2` (`fn` callback, no context data)
|
||||
- [X] `sqlite3_progress_handler` (`FnMut` callback, reference kept)
|
||||
|
||||
- [ ] `sqlite3_open`
|
||||
- [X] `sqlite3_open_v2`
|
||||
- [ ] `sqlite3_uri_parameter`
|
||||
- [ ] `sqlite3_uri_boolean`
|
||||
- [ ] `sqlite3_uri_int64`
|
||||
- [ ] `sqlite3_uri_key`
|
||||
|
||||
- [ ] `sqlite3_filename_database`
|
||||
- [ ] `sqlite3_filename_journal`
|
||||
- [ ] `sqlite3_filename_wal`
|
||||
- [ ] `sqlite3_database_file_object`
|
||||
- [ ] `sqlite3_create_filename`
|
||||
- [ ] `sqlite3_free_filename`
|
||||
|
||||
- [X] `sqlite3_errcode`
|
||||
- [X] `sqlite3_extended_errcode`
|
||||
- [X] `sqlite3_errmsg` (not public, internal use only)
|
||||
- [X] `sqlite3_errstr` (not public, internal use only)
|
||||
- [X] `sqlite3_error_offset`
|
||||
|
||||
- [X] `sqlite3_limit`
|
||||
|
||||
- [ ] `sqlite3_prepare`
|
||||
- [X] `sqlite3_prepare_v2`
|
||||
- [X] `sqlite3_prepare_v3`
|
||||
|
||||
- [X] `sqlite3_sql` (not public, internal use only)
|
||||
- [X] `sqlite3_expanded_sql`
|
||||
- [ ] `sqlite3_normalized_sql`
|
||||
|
||||
- [X] `sqlite3_stmt_readonly`
|
||||
- [X] `sqlite3_stmt_isexplain`
|
||||
- [ ] `sqlite3_stmt_explain`
|
||||
- [X] `sqlite3_stmt_busy`
|
||||
|
||||
- [ ] `sqlite3_bind_blob`
|
||||
- [X] `sqlite3_bind_blob64`
|
||||
- [X] `sqlite3_bind_double`
|
||||
- [ ] `sqlite3_bind_int`
|
||||
- [X] `sqlite3_bind_int64`
|
||||
- [X] `sqlite3_bind_null`
|
||||
- [ ] `sqlite3_bind_text`
|
||||
- [X] `sqlite3_bind_text64`
|
||||
- [ ] `sqlite3_bind_value`
|
||||
- [X] `sqlite3_bind_pointer`
|
||||
- [X] `sqlite3_bind_zeroblob`
|
||||
- [ ] `sqlite3_bind_zeroblob64`
|
||||
|
||||
- [X] `sqlite3_bind_parameter_count`
|
||||
- [X] `sqlite3_bind_parameter_name`
|
||||
- [X] `sqlite3_bind_parameter_index`
|
||||
- [X] `sqlite3_clear_bindings`
|
||||
|
||||
- [X] `sqlite3_column_count`
|
||||
- [ ] `sqlite3_data_count`
|
||||
- [X] `sqlite3_column_name`
|
||||
- [X] `sqlite3_column_database_name`
|
||||
- [X] `sqlite3_column_table_name`
|
||||
- [X] `sqlite3_column_origin_name`
|
||||
- [X] `sqlite3_column_decltype`
|
||||
|
||||
- [X] `sqlite3_step`
|
||||
|
||||
- [X] `sqlite3_column_blob`
|
||||
- [X] `sqlite3_column_double`
|
||||
- [ ] `sqlite3_column_int`
|
||||
- [X] `sqlite3_column_int64`
|
||||
- [X] `sqlite3_column_text`
|
||||
- [X] `sqlite3_column_value` (not public, internal use only)
|
||||
- [X] `sqlite3_column_bytes` (not public, internal use only)
|
||||
- [X] `sqlite3_column_type`
|
||||
|
||||
- [X] `sqlite3_finalize`
|
||||
- [X] `sqlite3_reset` (not public, internal use only)
|
||||
|
||||
- [ ] `sqlite3_create_function`
|
||||
- [X] `sqlite3_create_function_v2` (Boxed callback, destroyed by SQLite)
|
||||
- [X] `sqlite3_create_window_function` (Boxed callback, destroyed by SQLite)
|
||||
|
||||
- [X] `sqlite3_value_blob`
|
||||
- [X] `sqlite3_value_double`
|
||||
- [ ] `sqlite3_value_int`
|
||||
- [X] `sqlite3_value_int64`
|
||||
- [X] `sqlite3_value_pointer`
|
||||
- [X] `sqlite3_value_text`
|
||||
- [X] `sqlite3_value_bytes` (not public, internal use only)
|
||||
- [X] `sqlite3_value_type`
|
||||
- [ ] `sqlite3_value_numeric_type`
|
||||
- [X] `sqlite3_value_nochange`
|
||||
- [ ] `sqlite3_value_frombind`
|
||||
- [ ] `sqlite3_value_encoding`
|
||||
- [X] `sqlite3_value_subtype`
|
||||
|
||||
- [ ] `sqlite3_value_dup`
|
||||
- [ ] `sqlite3_value_free`
|
||||
|
||||
- [X] `sqlite3_aggregate_context` (not public, internal use only)
|
||||
- [X] `sqlite3_user_data` (not public, internal use only)
|
||||
- [X] `sqlite3_context_db_handle` (Connection ref)
|
||||
- [X] `sqlite3_get_auxdata`
|
||||
- [X] `sqlite3_set_auxdata`
|
||||
- [ ] `sqlite3_get_clientdata`
|
||||
- [ ] `sqlite3_set_clientdata`
|
||||
|
||||
- [ ] `sqlite3_result_blob`
|
||||
- [X] `sqlite3_result_blob64`
|
||||
- [X] `sqlite3_result_double`
|
||||
- [X] `sqlite3_result_error`
|
||||
- [X] `sqlite3_result_error_toobig`
|
||||
- [X] `sqlite3_result_error_nomem`
|
||||
- [X] `sqlite3_result_error_code`
|
||||
- [ ] `sqlite3_result_int`
|
||||
- [X] `sqlite3_result_int64`
|
||||
- [X] `sqlite3_result_null`
|
||||
- [ ] `sqlite3_result_text`
|
||||
- [X] `sqlite3_result_text64`
|
||||
- [X] `sqlite3_result_value`
|
||||
- [X] `sqlite3_result_pointer`
|
||||
- [X] `sqlite3_result_zeroblob`
|
||||
- [ ] `sqlite3_result_zeroblob64`
|
||||
- [X] `sqlite3_result_subtype`
|
||||
|
||||
- [ ] `sqlite3_create_collation`
|
||||
- [X] `sqlite3_create_collation_v2` (Boxed callback, destroyed by SQLite)
|
||||
- [X] `sqlite3_collation_needed` (`fn` callback)
|
||||
|
||||
- [ ] `sqlite3_sleep`
|
||||
|
||||
- [X] `sqlite3_get_autocommit`
|
||||
|
||||
- [X] `sqlite3_db_handle` (not public, internal use only, Connection ref)
|
||||
- [X] `sqlite3_db_name`
|
||||
- [X] `sqlite3_db_filename`
|
||||
- [X] `sqlite3_db_readonly`
|
||||
- [X] `sqlite3_txn_state`
|
||||
- [X] `sqlite3_next_stmt` (not public, internal use only)
|
||||
|
||||
- [X] `sqlite3_commit_hook` (`FnMut` callback, reference kept)
|
||||
- [X] `sqlite3_rollback_hook` (`FnMut` callback, reference kept)
|
||||
- [ ] `sqlite3_autovacuum_pages`
|
||||
- [X] `sqlite3_update_hook` (`FnMut` callback, reference kept)
|
||||
|
||||
- [ ] `sqlite3_enable_shared_cache`
|
||||
- [ ] `sqlite3_release_memory`
|
||||
- [X] `sqlite3_db_release_memory`
|
||||
- [ ] `sqlite3_soft_heap_limit64`
|
||||
- [ ] `sqlite3_hard_heap_limit64`
|
||||
|
||||
- [X] `sqlite3_table_column_metadata`
|
||||
|
||||
- [X] `sqlite3_load_extension`
|
||||
- [X] `sqlite3_enable_load_extension` (cannot be used by a loadable extension)
|
||||
- [X] `sqlite3_auto_extension` (`fn` callbak with Connection ref)
|
||||
- [X] `sqlite3_cancel_auto_extension`
|
||||
- [X] `sqlite3_reset_auto_extension`
|
||||
|
||||
- [ ] `sqlite3_create_module`
|
||||
- [X] `sqlite3_create_module_v2`
|
||||
- [ ] `sqlite3_drop_modules`
|
||||
- [X] `sqlite3_declare_vtab`
|
||||
- [ ] `sqlite3_overload_function`
|
||||
|
||||
- [X] `sqlite3_blob_open`
|
||||
- [X] `sqlite3_blob_reopen`
|
||||
- [X] `sqlite3_blob_close`
|
||||
- [X] `sqlite3_blob_bytes`
|
||||
- [X] `sqlite3_blob_read`
|
||||
- [X] `sqlite3_blob_write`
|
||||
|
||||
- [ ] `sqlite3_vfs_find`
|
||||
- [ ] `sqlite3_vfs_register`
|
||||
- [ ] `sqlite3_vfs_unregister`
|
||||
|
||||
- [ ] `sqlite3_mutex_alloc`
|
||||
- [ ] `sqlite3_mutex_free`
|
||||
- [ ] `sqlite3_mutex_enter`
|
||||
- [ ] `sqlite3_mutex_try`
|
||||
- [ ] `sqlite3_mutex_leave`
|
||||
- [ ] `sqlite3_mutex_held`
|
||||
- [ ] `sqlite3_mutex_notheld`
|
||||
- [ ] `sqlite3_db_mutex`
|
||||
|
||||
- [X] `sqlite3_file_control` (not public, internal use only)
|
||||
- [ ] `sqlite3_test_control`
|
||||
|
||||
- [ ] `sqlite3_keyword_count`
|
||||
- [ ] `sqlite3_keyword_name`
|
||||
- [ ] `sqlite3_keyword_check`
|
||||
|
||||
- [ ] `sqlite3_str_new`
|
||||
- [ ] `sqlite3_str_finish`
|
||||
- [ ] `sqlite3_str_append`
|
||||
- [ ] `sqlite3_str_reset`
|
||||
- [ ] `sqlite3_str_errcode`
|
||||
- [ ] `sqlite3_str_length`
|
||||
- [ ] `sqlite3_str_value`
|
||||
|
||||
- [ ] `sqlite3_status`
|
||||
- [ ] `sqlite3_status64`
|
||||
- [ ] `sqlite3_db_status`
|
||||
- [X] `sqlite3_stmt_status`
|
||||
|
||||
- [X] `sqlite3_backup_init`
|
||||
- [X] `sqlite3_backup_step`
|
||||
- [X] `sqlite3_backup_finish`
|
||||
- [X] `sqlite3_backup_remaining`
|
||||
- [X] `sqlite3_backup_pagecount`
|
||||
|
||||
- [X] `sqlite3_unlock_notify` (`fn` callback, internal use only)
|
||||
|
||||
- [ ] `sqlite3_stricmp`
|
||||
- [ ] `sqlite3_strnicmp`
|
||||
- [ ] `sqlite3_strglob`
|
||||
- [ ] `sqlite3_strlike`
|
||||
|
||||
- [X] `sqlite3_log`
|
||||
|
||||
- [X] `sqlite3_wal_hook` (`fn` callback with Connection ref)
|
||||
- [ ] `sqlite3_wal_autocheckpoint`
|
||||
- [X] `sqlite3_wal_checkpoint`
|
||||
- [X] `sqlite3_wal_checkpoint_v2`
|
||||
|
||||
- [X] `sqlite3_vtab_config`
|
||||
- [X] `sqlite3_vtab_on_conflict`
|
||||
- [X] `sqlite3_vtab_nochange`
|
||||
- [X] `sqlite3_vtab_collation`
|
||||
- [X] `sqlite3_vtab_distinct`
|
||||
- [X] `sqlite3_vtab_in`
|
||||
- [X] `sqlite3_vtab_in_first`
|
||||
- [X] `sqlite3_vtab_in_next`
|
||||
- [X] `sqlite3_vtab_rhs_value`
|
||||
|
||||
- [ ] `sqlite3_stmt_scanstatus`
|
||||
- [ ] `sqlite3_stmt_scanstatus_v2`
|
||||
- [ ] `sqlite3_stmt_scanstatus_reset`
|
||||
|
||||
- [X] `sqlite3_db_cacheflush`
|
||||
|
||||
- [X] `sqlite3_preupdate_hook` (`FnMut` callback with Connection ref, reference kept) (cannot be used by a loadable extension)
|
||||
- [X] `sqlite3_preupdate_old`
|
||||
- [X] `sqlite3_preupdate_count`
|
||||
- [X] `sqlite3_preupdate_depth`
|
||||
- [X] `sqlite3_preupdate_new`
|
||||
- [ ] `sqlite3_preupdate_blobwrite`
|
||||
|
||||
- [ ] `sqlite3_system_errno`
|
||||
|
||||
- [ ] `sqlite3_snapshot_get`
|
||||
- [ ] `sqlite3_snapshot_open`
|
||||
- [ ] `sqlite3_snapshot_free`
|
||||
- [ ] `sqlite3_snapshot_cmp`
|
||||
- [ ] `sqlite3_snapshot_recover`
|
||||
|
||||
- [X] `sqlite3_serialize`
|
||||
- [X] `sqlite3_deserialize`
|
||||
|
||||
- [ ] `sqlite3_rtree_geometry_callback`
|
||||
- [ ] `sqlite3_rtree_query_callback`
|
||||
|
||||
- [X] `sqlite3session_create`
|
||||
- [X] `sqlite3session_delete`
|
||||
- [ ] `sqlite3session_object_config`
|
||||
- [X] `sqlite3session_enable`
|
||||
- [X] `sqlite3session_indirect`
|
||||
- [X] `sqlite3session_attach`
|
||||
- [X] `sqlite3session_table_filter` (Boxed callback, reference kept)
|
||||
- [X] `sqlite3session_changeset`
|
||||
- [ ] `sqlite3session_changeset_size`
|
||||
- [X] `sqlite3session_diff`
|
||||
- [X] `sqlite3session_patchset`
|
||||
- [X] `sqlite3session_isempty`
|
||||
- [ ] `sqlite3session_memory_used`
|
||||
- [X] `sqlite3changeset_start`
|
||||
- [ ] `sqlite3changeset_start_v2`
|
||||
- [X] `sqlite3changeset_next`
|
||||
- [X] `sqlite3changeset_op`
|
||||
- [X] `sqlite3changeset_pk`
|
||||
- [X] `sqlite3changeset_old`
|
||||
- [X] `sqlite3changeset_new`
|
||||
- [X] `sqlite3changeset_conflict`
|
||||
- [X] `sqlite3changeset_fk_conflicts`
|
||||
- [X] `sqlite3changeset_finalize`
|
||||
- [X] `sqlite3changeset_invert`
|
||||
- [X] `sqlite3changeset_concat`
|
||||
- [ ] `sqlite3changeset_upgrade`
|
||||
- [X] `sqlite3changegroup_new`
|
||||
- [ ] `sqlite3changegroup_schema`
|
||||
- [X] `sqlite3changegroup_add`
|
||||
- [ ] `sqlite3changegroup_add_change`
|
||||
- [X] `sqlite3changegroup_output`
|
||||
- [X] `sqlite3changegroup_delete`
|
||||
- [X] `sqlite3changeset_apply`
|
||||
- [ ] `sqlite3changeset_apply_v2`
|
||||
- [ ] `sqlite3rebaser_create`
|
||||
- [ ] `sqlite3rebaser_configure`
|
||||
- [ ] `sqlite3rebaser_rebase`
|
||||
- [ ] `sqlite3rebaser_delete`
|
||||
- [X] `sqlite3changeset_apply_strm`
|
||||
- [ ] `sqlite3changeset_apply_v2_strm`
|
||||
- [X] `sqlite3changeset_concat_strm`
|
||||
- [X] `sqlite3changeset_invert_strm`
|
||||
- [X] `sqlite3changeset_start_strm`
|
||||
- [ ] `sqlite3changeset_start_v2_strm`
|
||||
- [X] `sqlite3session_changeset_strm`
|
||||
- [X] `sqlite3session_patchset_strm`
|
||||
- [X] `sqlite3changegroup_add_strm`
|
||||
- [X] `sqlite3changegroup_add_strm`
|
||||
- [X] `sqlite3changegroup_output_strm`
|
||||
- [ ] `sqlite3rebaser_rebase_strm`
|
||||
- [ ] `sqlite3session_config`
|
||||
|
||||
## List of virtual table methods supported
|
||||
|
||||
- [X] `xCreate`
|
||||
- [X] `xConnect`
|
||||
- [X] `xBestIndex`
|
||||
- [X] `xDisconnect`
|
||||
- [X] `xDestroy`
|
||||
- [X] `xOpen`
|
||||
- [X] `xClose`
|
||||
- [X] `xFilter`
|
||||
- [X] `xNext`
|
||||
- [X] `xEof`
|
||||
- [X] `xColumn`
|
||||
- [X] `xRowid`
|
||||
- [X] `xUpdate`
|
||||
- [X] `xBegin`
|
||||
- [X] `xSync`
|
||||
- [X] `xCommit`
|
||||
- [X] `xRollback`
|
||||
- [ ] `xFindFunction`
|
||||
- [ ] `xRename`
|
||||
- [ ] `xSavepoint`
|
||||
- [ ] `xRelease`
|
||||
- [ ] `xRollbackTo`
|
||||
- [ ] `xShadowName`
|
||||
- [ ] `xIntegrity`
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user