requirementbot 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +197 -2
- package/bin/requirementbot.js +21 -0
- package/package.json +53 -4
- package/prompts/README.md +18 -0
- package/prompts/check.md +15 -0
- package/prompts/fix.md +4 -0
- package/prompts/from-code.md +12 -0
- package/prompts/from-docs.md +11 -0
- package/prompts/from-issues.md +14 -0
- package/prompts/mdq.md +8 -0
- package/prompts/partials/non-interactive.md +1 -0
- package/prompts/partials/subagents.md +1 -0
- package/prompts/report.md +8 -0
- package/prompts/system.md +9 -0
- package/skills/SOURCE.md +14 -0
- package/skills/catalog-features/SKILL.md +168 -0
- package/skills/catalog-features/references/layout.md +87 -0
- package/skills/detect-product-mismatches/SKILL.md +147 -0
- package/skills/detect-product-mismatches/references/features.md +84 -0
- package/skills/detect-product-mismatches/references/layout.md +99 -0
- package/skills/pull-request-diff-analyzer/SKILL.md +141 -0
- package/skills/qa-explain-behavior/SKILL.md +112 -0
- package/skills/qa-explain-behavior/references/answer-shapes.md +116 -0
- package/skills/qa-explain-behavior/references/examples.md +157 -0
- package/skills/qa-pr-requirements-analyzer/SKILL.md +149 -0
- package/skills/qa-pr-requirements-analyzer/references/summary-example.md +54 -0
- package/skills/qa-requirement-reviewer/SKILL.md +126 -0
- package/skills/qa-requirement-reviewer/references/requirements_reviewer_examples.md +128 -0
- package/skills/qa-thinking/SKILL.md +46 -0
- package/skills/requirements-from-code/SKILL.md +114 -0
- package/skills/requirements-from-code/references/behaviors.md +42 -0
- package/skills/requirements-from-code/references/layout.md +100 -0
- package/skills/requirements-from-expected/SKILL.md +116 -0
- package/skills/requirements-from-expected/references/behaviors.md +49 -0
- package/skills/requirements-from-expected/references/layout.md +74 -0
- package/skills/requirements-from-expected/references/merge.md +34 -0
- package/skills/write-user-story/SKILL.md +42 -0
- package/src/agent/agent.js +278 -0
- package/src/agent/auth.js +209 -0
- package/src/agent/prompt.js +36 -0
- package/src/branding.js +27 -0
- package/src/cli.js +26 -0
- package/src/commands/agent-command.js +61 -0
- package/src/commands/check.js +26 -0
- package/src/commands/command.js +40 -0
- package/src/commands/connect.js +33 -0
- package/src/commands/disconnect.js +18 -0
- package/src/commands/generate-from-code.js +20 -0
- package/src/commands/generate-from-docs.js +38 -0
- package/src/commands/generate-from-issues.js +41 -0
- package/src/commands/index.js +40 -0
- package/src/commands/login.js +44 -0
- package/src/commands/logout.js +17 -0
- package/src/commands/models.js +11 -0
- package/src/commands/pull.js +15 -0
- package/src/commands/push.js +29 -0
- package/src/commands/query.js +31 -0
- package/src/commands/report.js +23 -0
- package/src/commands/skills.js +20 -0
- package/src/commands/sources.js +16 -0
- package/src/commands/update-from-code.js +7 -0
- package/src/commands/update-from-docs.js +7 -0
- package/src/commands/update-from-issues.js +7 -0
- package/src/config.js +90 -0
- package/src/files.js +25 -0
- package/src/github.js +50 -0
- package/src/http.js +19 -0
- package/src/requirements.js +139 -0
- package/src/sources/adf.js +48 -0
- package/src/sources/github.js +81 -0
- package/src/sources/index.js +41 -0
- package/src/sources/jira.js +135 -0
- package/src/sources/pages.js +67 -0
- package/src/sources/source.js +60 -0
- package/src/transports/confluence.js +114 -0
- package/src/transports/git.js +90 -0
- package/src/transports/github.js +42 -0
- package/src/transports/index.js +36 -0
- package/src/transports/notion.js +108 -0
- package/src/transports/page-tree.js +119 -0
- package/src/transports/transport.js +41 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: requirements-from-expected
|
|
3
|
+
description: >-
|
|
4
|
+
Builds product requirements from a source that says what was intended to be built: issue tracker, requirements, user docs, or similar. Or updates them after the source changed.
|
|
5
|
+
Records mismatches inside that source: items that contradict each other.
|
|
6
|
+
Use when the user asks to build or update the requirements/wiki/feature pages from issues, tickets, requirements, specs, PRDs, or user docs.
|
|
7
|
+
metadata:
|
|
8
|
+
author: Testomat.io
|
|
9
|
+
version: 1.0.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Requirements from expected
|
|
13
|
+
|
|
14
|
+
Requirements of **what the source says the product does**: one page per feature, listing its behaviors, and mismatches between items of the source.
|
|
15
|
+
|
|
16
|
+
One feature is often described by many items (an epic, its stories and sub-tasks, bugs, later issues that change it). The feature page states its **current state**: every item in scope merged, the newest one winning ([references/merge.md](references/merge.md)).
|
|
17
|
+
|
|
18
|
+
Output folder: `requirements/expected/{source-name}/`
|
|
19
|
+
- `expected` is a strict name: the requirements are always a `{source-name}` folder inside `requirements/expected/`, never anywhere else
|
|
20
|
+
- `requirements/` is in the repo root, or given by the calling skill or the user; `{source-name}` as `catalog-features` names it, or given the same way
|
|
21
|
+
- all paths are relative inside the output folder
|
|
22
|
+
|
|
23
|
+
**Mismatch** is a contradiction inside this source: two current items say different things about the same behavior. Mismatches with other sources → `detect-product-mismatches`.
|
|
24
|
+
|
|
25
|
+
## Modes
|
|
26
|
+
|
|
27
|
+
| Mode | When |
|
|
28
|
+
| -------- | ------------------------------------------------------------------------ |
|
|
29
|
+
| `build` | No `features/` in the output folder, or the user asks to rebuild |
|
|
30
|
+
| `update` | `features/` exists: change only what the source changed since last sync |
|
|
31
|
+
|
|
32
|
+
`update`: a changed item → rebuild the current state of every feature it touches from all of that feature's items, not only the changed one.
|
|
33
|
+
|
|
34
|
+
## Steps
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
- [ ] 1. Catalog
|
|
38
|
+
- [ ] 2. Indexes
|
|
39
|
+
- [ ] 3. Feature pages (one subagent per area)
|
|
40
|
+
- [ ] 4. Verify (fresh subagents)
|
|
41
|
+
- [ ] 5. Merge
|
|
42
|
+
- [ ] 6. Validate
|
|
43
|
+
- [ ] 7. Report
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Read [references/behaviors.md](references/behaviors.md), [references/merge.md](references/merge.md) and [references/layout.md](references/layout.md) before writing files.
|
|
47
|
+
|
|
48
|
+
## Rules
|
|
49
|
+
|
|
50
|
+
- **Read-only on the source.** Never edit issues, pages, or documents.
|
|
51
|
+
- Behaviors come only from source items in scope (`catalog-features` › Status): built issues, current pages. Never from unresolved issues, drafts, deprecated pages.
|
|
52
|
+
- A feature page states the current state, never the history of changes: merge every item of the feature ([merge.md](references/merge.md)).
|
|
53
|
+
- `History: Yes` (issue tracker): the newest item wins (resolution date, else last update, else creation date). An older contradicting item is superseded: not a behavior, not a mismatch. Same date → mismatch.
|
|
54
|
+
- Write only keys and URLs that exist in the source. Never guess or build them.
|
|
55
|
+
- Name areas and features from the product and user's perspective. Domain terms (prefer the user docs' terms), one term per concept across the requirements.
|
|
56
|
+
|
|
57
|
+
## 1. Catalog
|
|
58
|
+
|
|
59
|
+
Run `catalog-features` skill on the source: same mode, role Expected, source folder = this output folder. The catalog goes to `features/.catalog/`, the source items to `.source/`.
|
|
60
|
+
|
|
61
|
+
## 2. Indexes
|
|
62
|
+
|
|
63
|
+
Write the `features/` indexes before any feature page ([layout.md](references/layout.md)).
|
|
64
|
+
|
|
65
|
+
## 3. Feature pages
|
|
66
|
+
|
|
67
|
+
One subagent per area, in parallel (`update`: affected areas only). Each subagent gets: the area, its subareas and catalog features (feature YAMLs), the source items in `.source/`, the source's type and history, the Domain from `features/.catalog/README.md`, the rules above, [references/behaviors.md](references/behaviors.md), [references/merge.md](references/merge.md), [references/layout.md](references/layout.md). `update` also: the area's existing pages and mismatches, and its changed source items.
|
|
68
|
+
|
|
69
|
+
Subagent, per feature, starting from its catalog links:
|
|
70
|
+
|
|
71
|
+
1. Collects every item of the feature, reads each one whole, and applies them in date order ([merge.md](references/merge.md)). Fixes the area's catalog when items belong to another feature or features must be merged or split.
|
|
72
|
+
2. Writes the feature page ([layout.md](references/layout.md) › Feature page): Description, Behaviors in their current state ([behaviors.md](references/behaviors.md)), each linked to the item that set it; History.
|
|
73
|
+
3. Returns one mismatch per contradiction: every section of a mismatch page ([layout.md](references/layout.md) › Mismatch page).
|
|
74
|
+
|
|
75
|
+
Subagent writes only inside its area, in `features/` and `features/.catalog/`. Anything outside the area → return it.
|
|
76
|
+
|
|
77
|
+
Subagent returns: files added, changed, and removed; mismatches (`update`: also resolved ones); open questions; catalog errors; terms the Domain lacks.
|
|
78
|
+
|
|
79
|
+
## 4. Verify
|
|
80
|
+
|
|
81
|
+
One fresh subagent per batch of features made from two or more items (`update`: changed ones), with the same inputs as step 3. It rebuilds each feature's current state from `.source/` on its own ([merge.md](references/merge.md)), compares it with the page, and fixes the page: missing or extra items, superseded behaviors still listed, changes not applied, wrong links. Returns what it fixed and what it can't decide (→ open question).
|
|
82
|
+
|
|
83
|
+
## 5. Merge
|
|
84
|
+
|
|
85
|
+
1. Apply the changes subagents returned outside their areas. Terms the Domain lacks → add to the Domain in `features/.catalog/README.md`.
|
|
86
|
+
2. Update every `README.md` in `features/` to list the feature pages that now exist. Write the output `README.md`: source name, scope, date, a link and purpose for each folder (not `.catalog/`), open questions.
|
|
87
|
+
3. Write the mismatch pages. Same contradiction from several areas → one page. `update`: remove resolved mismatches.
|
|
88
|
+
4. In `mismatches/README.md`, write the mismatches list ([layout.md](references/layout.md)).
|
|
89
|
+
5. Add a link and purpose for these requirements to the index `requirements/README.md`, when missing.
|
|
90
|
+
|
|
91
|
+
## 6. Validate
|
|
92
|
+
|
|
93
|
+
```markdown
|
|
94
|
+
Structure
|
|
95
|
+
- [ ] Output folder is `requirements/expected/{source-name}/`
|
|
96
|
+
- [ ] Output README.md is a summary and sitemap with source, scope, date
|
|
97
|
+
- [ ] Every catalog feature has a feature page; `features/` mirrors the catalog's areas and subareas
|
|
98
|
+
|
|
99
|
+
Content
|
|
100
|
+
- [ ] Every feature page has a Description and at least one behavior under Behaviors; every behavior passes the check in [references/behaviors.md](references/behaviors.md) and links its source items
|
|
101
|
+
- [ ] No behavior from an item out of scope or superseded
|
|
102
|
+
- [ ] Every feature passes the check in [references/merge.md](references/merge.md): every item in History, one behavior per point, the newest item wins
|
|
103
|
+
- [ ] Every item in scope with behaviors is in some feature's History; `.source/README.md` maps it to that feature
|
|
104
|
+
- [ ] Every contradiction between current items has a mismatch page
|
|
105
|
+
- [ ] update: resolved mismatches removed; nothing left for items gone from scope
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 7. Report
|
|
109
|
+
|
|
110
|
+
Where to start. Results (`update`: features added, changed, removed). Features merged from the most items. Fixes made in Verify. Mismatches, highest user impact first. Catalog errors. Open questions.
|
|
111
|
+
|
|
112
|
+
## Next actions
|
|
113
|
+
|
|
114
|
+
- Compare with code and other sources → `detect-product-mismatches`
|
|
115
|
+
- Review contradicting requirements → `qa-requirement-reviewer`
|
|
116
|
+
- Test cases for a feature → `qa-write-test-cases`
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Behaviors
|
|
2
|
+
|
|
3
|
+
A behavior is one observable statement about what the source says the product does: what someone who uses it (end user, admin, API client, integrated system) can do, see, or get, and when. Feature pages list them under Behaviors.
|
|
4
|
+
|
|
5
|
+
## From source items
|
|
6
|
+
|
|
7
|
+
| Source | Behaviors from | Not behaviors |
|
|
8
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| Issue tracker | Stories and feature issues: acceptance criteria, then the description. Epics: their scope. Bugs: the expected result | A bug's reported actual result; tasks, spikes, chores, tech debt |
|
|
10
|
+
| Requirements | Functional requirements, business rules, acceptance criteria, flows; one behavior per table row and per meaningful matrix cell; exclusions as negative ones | Future phases, nice-to-have, MoSCoW Could and Won't; goals, rationale, personas, metrics, open questions |
|
|
11
|
+
| User docs | Guides, how-tos, limits, notes and warnings; badges (plan, edition, role, platform) as conditions; navigation steps | Screenshots and videos |
|
|
12
|
+
|
|
13
|
+
- Comments and later edits may change the body ("dropped", "moved to PROJ-456", "decided: 3 retries, not 5"): state the final behavior, never the comment.
|
|
14
|
+
- Acceptance criteria may sit in a custom field, a description heading, a checklist, or sub-tasks: find the convention in the first items.
|
|
15
|
+
|
|
16
|
+
## Shape
|
|
17
|
+
|
|
18
|
+
- One behavior per bullet, one sentence, present tense.
|
|
19
|
+
- No `should`, `shall`, `must`, `will`: state it as a fact.
|
|
20
|
+
- Name who acts or what changes, in domain terms. Never "the system", "it", or "we".
|
|
21
|
+
- Outcome is what the actor can observe (screen, response, file, email, notification), not how the product gets there.
|
|
22
|
+
- Conditions stay in the behavior: role, platform, setting, state.
|
|
23
|
+
- Negative behaviors count: `Viewer cannot delete a project.`
|
|
24
|
+
- Split on "and" when each part can be checked on its own.
|
|
25
|
+
- Each behavior links the item that set its current form: key and URL, or page title and URL ([merge.md](merge.md)).
|
|
26
|
+
|
|
27
|
+
## Values and words
|
|
28
|
+
|
|
29
|
+
- Values as the source states them, with units. No value in the source → none in the behavior. Never round, convert, or fill one in; a vague behavior stays vague (open question).
|
|
30
|
+
- UI labels and messages verbatim, in quotes; navigation paths with `›`.
|
|
31
|
+
- No class, function, table, or library names. Protocol details (endpoints, status codes, fields) only when the API is what users use.
|
|
32
|
+
- Restate, never paste. Never people or customer data.
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
| Source says | Behavior |
|
|
37
|
+
| --------------------------------------------------------------------- | ------------------------------------------------------------------- |
|
|
38
|
+
| The system shall allow users to store payment methods (max 5). | `Customer can save up to 5 cards.` |
|
|
39
|
+
| AC: if the card is declined, show "Payment failed. Try another card." | `Declined card: Customer sees "Payment failed. Try another card."` |
|
|
40
|
+
| Enterprise customers get SSO; Pro is coming soon. | `Enterprise plan: SSO sign-in is available.` (Pro: future, dropped) |
|
|
41
|
+
| Session times out after a while. | `Session expires after inactivity.` (no value invented) |
|
|
42
|
+
| Bug: saving the same card twice creates a duplicate; expected: one. | `Saving the same card again keeps one saved card.` |
|
|
43
|
+
|
|
44
|
+
## Check
|
|
45
|
+
|
|
46
|
+
- [ ] Every behavior the feature's source items state is listed, from items in scope only
|
|
47
|
+
- [ ] One observable behavior per bullet, present tense, who or what named
|
|
48
|
+
- [ ] Values as the source states them; none invented
|
|
49
|
+
- [ ] Domain terms; every behavior links its source items
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Requirements layout
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
requirements/expected/{source-name}/ # output folder
|
|
5
|
+
README.md # source, scope, date, sitemap, open questions
|
|
6
|
+
features/
|
|
7
|
+
README.md # areas
|
|
8
|
+
.catalog/ # catalog-features
|
|
9
|
+
{area}/ # as in the catalog, any depth
|
|
10
|
+
README.md # subareas and features
|
|
11
|
+
{feature}.md # feature page
|
|
12
|
+
.source/ # catalog-features
|
|
13
|
+
mismatches/ # contradictions inside this source
|
|
14
|
+
README.md # list, highest impact first; none → say so
|
|
15
|
+
{mismatch}.md
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Every README: breadcrumb, then links to its children.
|
|
19
|
+
|
|
20
|
+
## Feature page
|
|
21
|
+
|
|
22
|
+
- Breadcrumb, description, status (from the feature YAML).
|
|
23
|
+
- `## Behaviors`: current state ([behaviors.md](behaviors.md), [merge.md](merge.md)).
|
|
24
|
+
- `## History` (`History: Yes`): date, item, what it changed; oldest first.
|
|
25
|
+
|
|
26
|
+
```markdown
|
|
27
|
+
## Behaviors
|
|
28
|
+
|
|
29
|
+
- Customer can save up to 10 cards. ([PAY-140](https://example.atlassian.net/browse/PAY-140))
|
|
30
|
+
|
|
31
|
+
## History
|
|
32
|
+
|
|
33
|
+
| Date | Item | Change |
|
|
34
|
+
| ---------- | ------------------------------------------------------- | ---------------------------- |
|
|
35
|
+
| 2026-01-15 | [PAY-100](https://example.atlassian.net/browse/PAY-100) | Save a card, up to 5 cards |
|
|
36
|
+
| 2026-10-02 | [PAY-140](https://example.atlassian.net/browse/PAY-140) | Card limit 5 → 10 |
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Mismatch page
|
|
40
|
+
|
|
41
|
+
- `# Title`: the behavior, as the user meets it.
|
|
42
|
+
- `Feature:` link to its feature page.
|
|
43
|
+
- `## Difference`: one-sentence summary, then one bullet per item: item, its behavior.
|
|
44
|
+
- `## Impact`: **High** / **Medium** / **Low**, then who meets it and what they see.
|
|
45
|
+
- `## Solution`: which item to correct, or the options for the product owner.
|
|
46
|
+
- `## Sources`: one row per item: item, says, link, updated.
|
|
47
|
+
|
|
48
|
+
```markdown
|
|
49
|
+
# Saved card limit
|
|
50
|
+
|
|
51
|
+
Feature: [Checkout › Save card](../features/checkout/save-card.md)
|
|
52
|
+
|
|
53
|
+
## Difference
|
|
54
|
+
|
|
55
|
+
Two current pages give different limits: 5 and 10.
|
|
56
|
+
|
|
57
|
+
- **"Saved cards":** Customer can save up to 5 cards.
|
|
58
|
+
- **"Plans and limits":** Customer can save up to 10 cards.
|
|
59
|
+
|
|
60
|
+
## Impact
|
|
61
|
+
|
|
62
|
+
Medium. Customers get different answers depending on the page they read.
|
|
63
|
+
|
|
64
|
+
## Solution
|
|
65
|
+
|
|
66
|
+
Decide the limit, then correct the other page.
|
|
67
|
+
|
|
68
|
+
## Sources
|
|
69
|
+
|
|
70
|
+
| Item | Says | Link | Updated |
|
|
71
|
+
| ---------------- | -------------- | ------------------------------------------- | ---------- |
|
|
72
|
+
| Saved cards | Up to 5 cards | [Saved cards](https://example.com/...) | 2026-04-02 |
|
|
73
|
+
| Plans and limits | Up to 10 cards | [Plans and limits](https://example.com/...) | 2026-05-19 |
|
|
74
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Merge items into the current state
|
|
2
|
+
|
|
3
|
+
Many items describe one feature. The feature page states its **current state**: every item in scope applied, one version per behavior.
|
|
4
|
+
|
|
5
|
+
## 1. Collect
|
|
6
|
+
|
|
7
|
+
- The feature YAML links, plus each item's `parent`, `subtasks`, `links` in `.source/`, both ways.
|
|
8
|
+
- Later items that change the feature: bugs, follow-ups, pages on the same topic.
|
|
9
|
+
- Out of scope items: skip.
|
|
10
|
+
- Catalog wrong (item missing, misplaced, features to merge or split) → fix it, report a catalog error.
|
|
11
|
+
|
|
12
|
+
## 2. Read
|
|
13
|
+
|
|
14
|
+
Each item whole, comments included. Decisions inside comments. Highlight if decision from comment contradicts the item's current state.
|
|
15
|
+
|
|
16
|
+
Date: resolution, else last update, else creation.
|
|
17
|
+
|
|
18
|
+
## 3. Apply
|
|
19
|
+
|
|
20
|
+
`History: Yes`: oldest first; a later item adds, replaces, or removes behaviors. Replaced ones are superseded, not mismatches. Same date, can't tell which is newer → mismatch.
|
|
21
|
+
|
|
22
|
+
`History: No`: all current pages count the same. Same point, different values → mismatch.
|
|
23
|
+
|
|
24
|
+
## 4. Write
|
|
25
|
+
|
|
26
|
+
- `## Behaviors`: current state only; each behavior links the item that set it.
|
|
27
|
+
- `## History` (`History: Yes`): one row per item, oldest first: date, item, what it changed.
|
|
28
|
+
|
|
29
|
+
## Check
|
|
30
|
+
|
|
31
|
+
- [ ] Every collected item is in History
|
|
32
|
+
- [ ] One behavior per point; each from the newest item that set it
|
|
33
|
+
- [ ] Every comment decision applied
|
|
34
|
+
- [ ] Ties are mismatches, not picks
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: write-user-story
|
|
3
|
+
description: Write user stories, and acceptance criteria (which represent requirements) from a feature idea, ticket, notes, or existing behavior. Use when the user asks to write, draft, or rewrite/edit/improve requirements, a spec, BRD, user stories, use cases, or acceptance criteria.
|
|
4
|
+
metadata:
|
|
5
|
+
author: Testomat.io
|
|
6
|
+
version: 1.0.0
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Write User Story
|
|
10
|
+
|
|
11
|
+
Turn source material into user story (or multiple stories). Acceptance criteria on each story are the requirements — testable, atomic rules the story must satisfy.
|
|
12
|
+
|
|
13
|
+
If the source of data is a PR, use `qa-pr-requirements-analyzer` skill.
|
|
14
|
+
If the source is a ticket in issue tracking system, ask for MCP connection.
|
|
15
|
+
|
|
16
|
+
## Rules
|
|
17
|
+
|
|
18
|
+
User story must be (at least, but not limited to):
|
|
19
|
+
|
|
20
|
+
- **Atomic** — one actor, one capability.
|
|
21
|
+
- **Clear** — no vague words (`fast`, `relevant`, `user-friendly`, `should work`, `as needed`).
|
|
22
|
+
- **Complete** — actor, trigger, outcome, business rules; empty, error, and permission paths covered in AC.
|
|
23
|
+
- **Consistent** — same terms throughout; no contradictions.
|
|
24
|
+
- **Testable** — every story has acceptance criteria with a measurable pass/fail.
|
|
25
|
+
|
|
26
|
+
Follow these rules:
|
|
27
|
+
|
|
28
|
+
- Follow other best practices for writing user stories.
|
|
29
|
+
- Describe **what**, not how. No UI widgets, API implementation details or frameworks unless the user asked for that.
|
|
30
|
+
- Flag assumptions and open questions. Never silently invent missing rules. Do NOT: guess, imagine, assume. Always ask the user for clarification if something is unclear.
|
|
31
|
+
|
|
32
|
+
## Output
|
|
33
|
+
|
|
34
|
+
Default: requirement (description) + acceptance criteria. Match the user's format if they specify one. (Other sections depending on context provided by the user).
|
|
35
|
+
|
|
36
|
+
Each requirement has at least one AC. Mark AC with a short unique id (e.g. `AC-1`). (Better to set ids at the end of the line to make the output more readable.)
|
|
37
|
+
|
|
38
|
+
## Next actions
|
|
39
|
+
|
|
40
|
+
- Review for gaps and testability → `qa-requirement-reviewer`
|
|
41
|
+
- Risk scenarios → `qa-thinking`
|
|
42
|
+
- Test cases from these user stories → `qa-write-test-cases`
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, sep } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import {
|
|
5
|
+
createAgentSession,
|
|
6
|
+
createCodemodeExtension,
|
|
7
|
+
createMcpExtension,
|
|
8
|
+
createToolSearchExtension,
|
|
9
|
+
DefaultResourceLoader,
|
|
10
|
+
SessionManager,
|
|
11
|
+
SettingsManager,
|
|
12
|
+
} from '@earendil-works/pi-coding-agent';
|
|
13
|
+
import chalk from 'chalk';
|
|
14
|
+
import { brand, log, muted, warn } from '../branding.js';
|
|
15
|
+
import { Config, PROMPTS_DIR, SKILLS_DIR } from '../config.js';
|
|
16
|
+
import { Auth } from './auth.js';
|
|
17
|
+
import { Prompt } from './prompt.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A non-interactive pi agent with requirementbot branding, bundled skills, subagents, MCP and mdq.
|
|
21
|
+
* Progress goes to stderr; `run()` resolves with the final assistant text.
|
|
22
|
+
*/
|
|
23
|
+
export class Agent {
|
|
24
|
+
/** How many automatically picked models a run may try before giving up. */
|
|
25
|
+
static MAX_MODEL_ATTEMPTS = 8;
|
|
26
|
+
|
|
27
|
+
static PREFERRED_MODELS = [
|
|
28
|
+
/^anthropic\/claude-sonnet/,
|
|
29
|
+
/^anthropic\/claude-opus/,
|
|
30
|
+
/^openrouter\/anthropic\/claude-sonnet/,
|
|
31
|
+
/^openrouter\/anthropic\/claude-opus/,
|
|
32
|
+
/^openai\/gpt-\d/,
|
|
33
|
+
/^google\/gemini-.*pro/,
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {{ cwd: string, model?: string, thinking?: string, mcp?: boolean, session?: boolean, verbose?: boolean, quiet?: boolean }} options
|
|
38
|
+
*/
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.dir = Config.agentDir();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Models that have credentials configured, as `provider/id`. */
|
|
45
|
+
static async models() {
|
|
46
|
+
const agent = new Agent({ cwd: process.cwd() });
|
|
47
|
+
return (await Auth.available(await agent.modelRuntime())).map((m) => `${m.provider}/${m.id}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Run a prompt. Each follow-up gets the last answer and may return another prompt for the same session.
|
|
52
|
+
* @param {string|Prompt} prompt
|
|
53
|
+
* @param {{ followUps?: ((answer: string) => Promise<string|Prompt|undefined>)[] }} [options]
|
|
54
|
+
*/
|
|
55
|
+
async run(prompt, { followUps = [] } = {}) {
|
|
56
|
+
const rejected = [];
|
|
57
|
+
for (let attempt = 1; ; attempt++) {
|
|
58
|
+
try {
|
|
59
|
+
return await this.runOnce(prompt, followUps, rejected);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
// A model picked automatically may be refused by the account (access, billing): try the next one.
|
|
62
|
+
// A model named with -m is never swapped.
|
|
63
|
+
if (!(err instanceof ModelRejected) || this.options.model || attempt >= Agent.MAX_MODEL_ATTEMPTS) throw err;
|
|
64
|
+
warn(`${err.provider}/${err.id} was refused: ${ModelRejected.summary(err.message)}. Trying the next model`);
|
|
65
|
+
rejected.push(err);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async runOnce(prompt, followUps, rejected) {
|
|
71
|
+
const session = await this.createSession((m) => rejected.some((r) => r.covers(m)));
|
|
72
|
+
const { provider, id } = session.model || {};
|
|
73
|
+
if (!this.options.quiet) log(`model ${muted(`${provider}/${id}`)}`);
|
|
74
|
+
|
|
75
|
+
let failed;
|
|
76
|
+
let progressed = false;
|
|
77
|
+
const unsubscribe = session.subscribe((event) => {
|
|
78
|
+
if (event.type === 'tool_execution_start' || (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta')) progressed = true;
|
|
79
|
+
failed = this.onEvent(event, failed);
|
|
80
|
+
});
|
|
81
|
+
const interrupt = () => session.abort();
|
|
82
|
+
process.once('SIGINT', interrupt);
|
|
83
|
+
try {
|
|
84
|
+
await session.prompt(String(prompt));
|
|
85
|
+
if (failed && !progressed) throw new ModelRejected(provider, id, failed);
|
|
86
|
+
for (const next of followUps) {
|
|
87
|
+
if (failed) break;
|
|
88
|
+
const text = await next(session.getLastAssistantText() || '');
|
|
89
|
+
if (text) await session.prompt(String(text));
|
|
90
|
+
}
|
|
91
|
+
} finally {
|
|
92
|
+
process.off('SIGINT', interrupt);
|
|
93
|
+
unsubscribe();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const answer = session.getLastAssistantText() || '';
|
|
97
|
+
session.dispose();
|
|
98
|
+
if (failed) throw new Error(failed);
|
|
99
|
+
return answer;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Print progress for one session event; returns the current failure, if any. */
|
|
103
|
+
onEvent(event, failed) {
|
|
104
|
+
const { quiet, verbose } = this.options;
|
|
105
|
+
if (event.type === 'tool_execution_start' && !quiet) this.printTool(event);
|
|
106
|
+
if (event.type === 'tool_execution_end' && event.isError && verbose) process.stderr.write(chalk.red(` ✗ ${event.toolName} failed\n`));
|
|
107
|
+
if (event.type === 'message_update' && verbose && event.assistantMessageEvent.type === 'text_delta') {
|
|
108
|
+
process.stderr.write(muted(event.assistantMessageEvent.delta));
|
|
109
|
+
}
|
|
110
|
+
if (event.type === 'auto_retry_start' && !quiet) log(muted(`retrying after error (${event.attempt})`));
|
|
111
|
+
if (event.type === 'message_end' && event.message?.role === 'assistant' && !event.parentToolCallId) {
|
|
112
|
+
return event.message.stopReason === 'error' ? event.message.errorMessage || 'model request failed' : undefined;
|
|
113
|
+
}
|
|
114
|
+
return failed;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
printTool(event) {
|
|
118
|
+
const args = event.args || {};
|
|
119
|
+
const raw = args.path || args.file_path || args.command || args.agent || args.task || args.code || args.query || '';
|
|
120
|
+
const text = typeof raw === 'string' ? raw : JSON.stringify(raw);
|
|
121
|
+
const line = this.options.verbose ? text : text.split('\n')[0];
|
|
122
|
+
const short = !this.options.verbose && line.length > 100 ? `${line.slice(0, 97)}...` : line;
|
|
123
|
+
process.stderr.write(`${event.parentToolCallId ? ' ' : ' '}${brand('›')} ${event.toolName} ${muted(short)}\n`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {(model: { provider: string, id: string }) => boolean} [skip] models not to pick automatically */
|
|
127
|
+
async createSession(skip = () => false) {
|
|
128
|
+
const { cwd, thinking, session: persist } = this.options;
|
|
129
|
+
mkdirSync(this.dir, { recursive: true });
|
|
130
|
+
this.addMdqToPath();
|
|
131
|
+
|
|
132
|
+
const resourceLoader = await this.resourceLoader();
|
|
133
|
+
const modelRuntime = await this.modelRuntime();
|
|
134
|
+
const { session } = await createAgentSession({
|
|
135
|
+
cwd,
|
|
136
|
+
agentDir: this.dir,
|
|
137
|
+
model: await this.resolveModel(modelRuntime, skip),
|
|
138
|
+
thinkingLevel: thinking,
|
|
139
|
+
modelRuntime,
|
|
140
|
+
resourceLoader,
|
|
141
|
+
settingsManager: SettingsManager.inMemory({ compaction: { enabled: true }, retry: { enabled: true, maxRetries: 3 } }),
|
|
142
|
+
sessionManager: persist ? SessionManager.create(cwd, join(cwd, Config.DIR_NAME, 'sessions')) : SessionManager.inMemory(cwd),
|
|
143
|
+
});
|
|
144
|
+
await session.bindExtensions({});
|
|
145
|
+
return session;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async resourceLoader() {
|
|
149
|
+
const { cwd, mcp = true } = this.options;
|
|
150
|
+
const extensionFactories = [createCodemodeExtension(), createToolSearchExtension()];
|
|
151
|
+
if (mcp) extensionFactories.push(createMcpExtension({ loadConfig: () => this.mcpServers() }));
|
|
152
|
+
const loader = new DefaultResourceLoader({
|
|
153
|
+
cwd,
|
|
154
|
+
agentDir: this.dir,
|
|
155
|
+
additionalSkillPaths: [SKILLS_DIR],
|
|
156
|
+
additionalExtensionPaths: [Agent.packageRoot('pi-subagents')],
|
|
157
|
+
extensionFactories,
|
|
158
|
+
skillsOverride: ({ skills, diagnostics }) => ({ skills: skills.filter((skill) => this.isOwnSkill(skill)), diagnostics }),
|
|
159
|
+
systemPromptOverride: (base) => base?.replace('operating inside pi, a coding agent harness', 'operating as requirementbot, a requirements agent by Testomat.io'),
|
|
160
|
+
appendSystemPromptOverride: () => [String(new Prompt('system'))],
|
|
161
|
+
agentsFilesOverride: ({ agentsFiles }) => ({ agentsFiles: [...agentsFiles, { path: join(PROMPTS_DIR, 'mdq.md'), content: String(new Prompt('mdq')) }] }),
|
|
162
|
+
});
|
|
163
|
+
await loader.reload();
|
|
164
|
+
return loader;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
modelRuntime() {
|
|
168
|
+
return Auth.runtime();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async resolveModel(runtime, skip = () => false) {
|
|
172
|
+
const spec = this.options.model;
|
|
173
|
+
if (spec) {
|
|
174
|
+
const slash = spec.indexOf('/');
|
|
175
|
+
if (slash < 0) throw new Error(`Model must be "provider/id", got "${spec}"`);
|
|
176
|
+
const found = runtime.getModel(spec.slice(0, slash), spec.slice(slash + 1));
|
|
177
|
+
if (!found) throw new Error(`Unknown model "${spec}". Run "requirementbot models" to list available models.`);
|
|
178
|
+
return found;
|
|
179
|
+
}
|
|
180
|
+
const available = await Auth.available(runtime);
|
|
181
|
+
if (!available.length) {
|
|
182
|
+
throw new Error('No model credentials found. Set ANTHROPIC_API_KEY, OPENAI_API_KEY, OPENROUTER_API_KEY or another provider key, or sign in with pi: run "pi", then "/login".');
|
|
183
|
+
}
|
|
184
|
+
const pick = Agent.candidates(available).find((m) => !skip(m));
|
|
185
|
+
if (!pick) throw new Error('Every available model was refused. Choose one with -m, or check the account\'s billing.');
|
|
186
|
+
return pick;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Available models in the order they are tried: preferred families newest first, then the rest. */
|
|
190
|
+
static candidates(available) {
|
|
191
|
+
const ordered = [];
|
|
192
|
+
for (const pattern of Agent.PREFERRED_MODELS) {
|
|
193
|
+
ordered.push(...available
|
|
194
|
+
.filter((m) => !m.id.includes(':') && pattern.test(`${m.provider}/${m.id}`))
|
|
195
|
+
.sort((a, b) => b.id.localeCompare(a.id, undefined, { numeric: true })));
|
|
196
|
+
}
|
|
197
|
+
return [...new Set([...ordered, ...available])];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Bundled skills, pi-subagents skills and project skills; not the user's global skills. */
|
|
201
|
+
isOwnSkill(skill) {
|
|
202
|
+
return [SKILLS_DIR, Agent.packageRoot('pi-subagents'), this.options.cwd].some((root) => skill.filePath.startsWith(root + sep));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** MCP servers from `~/.requirementbot/agent/mcp.json` and the project's `.requirementbot/mcp.json`. */
|
|
206
|
+
mcpServers() {
|
|
207
|
+
const servers = new Map();
|
|
208
|
+
const errors = [];
|
|
209
|
+
const projectConfig = join(this.options.cwd, Config.DIR_NAME, 'mcp.json');
|
|
210
|
+
let autoEnableCodemode;
|
|
211
|
+
for (const [path, scope] of [[join(this.dir, 'mcp.json'), 'global'], [projectConfig, 'project']]) {
|
|
212
|
+
if (!existsSync(path)) continue;
|
|
213
|
+
try {
|
|
214
|
+
const data = JSON.parse(readFileSync(path, 'utf8'));
|
|
215
|
+
if (data.autoEnableCodemode !== undefined) autoEnableCodemode = data.autoEnableCodemode;
|
|
216
|
+
for (const [name, config] of Object.entries(data.mcpServers || {})) servers.set(name, { name, config, source: path, scope });
|
|
217
|
+
} catch (err) {
|
|
218
|
+
errors.push(`${path}: ${err.message}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return { servers: [...servers.values()], autoEnableCodemode, errors, projectConfig };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Writes `mdq-cli` and `mdq` launchers and puts them on PATH, however the package was installed. */
|
|
225
|
+
addMdqToPath() {
|
|
226
|
+
const binDir = join(this.dir, 'bin');
|
|
227
|
+
mkdirSync(binDir, { recursive: true });
|
|
228
|
+
const script = join(Agent.packageRoot('mdq-cli'), 'bin', 'mdq.js');
|
|
229
|
+
for (const name of ['mdq-cli', 'mdq']) {
|
|
230
|
+
const path = join(binDir, name);
|
|
231
|
+
writeFileSync(path, `#!/bin/sh\nexec "${process.execPath}" "${script}" "$@"\n`);
|
|
232
|
+
chmodSync(path, 0o755);
|
|
233
|
+
}
|
|
234
|
+
const parts = (process.env.PATH || '').split(':');
|
|
235
|
+
if (!parts.includes(binDir)) process.env.PATH = [binDir, ...parts].join(':');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static packageRoot(name) {
|
|
239
|
+
let dir = dirname(fileURLToPath(import.meta.resolve(name)));
|
|
240
|
+
while (!existsSync(join(dir, 'package.json')) || JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).name !== name) {
|
|
241
|
+
const parent = dirname(dir);
|
|
242
|
+
if (parent === dir) throw new Error(`Cannot find package ${name}`);
|
|
243
|
+
dir = parent;
|
|
244
|
+
}
|
|
245
|
+
return dir;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The first request failed before the model did anything. When the error names the model (e.g. "the
|
|
251
|
+
* 'gpt-6-sol' model is not supported"), only that model is skipped; otherwise the whole provider is
|
|
252
|
+
* (e.g. an account without credit).
|
|
253
|
+
*/
|
|
254
|
+
export class ModelRejected extends Error {
|
|
255
|
+
constructor(provider, id, message) {
|
|
256
|
+
super(message);
|
|
257
|
+
this.provider = provider;
|
|
258
|
+
this.id = id;
|
|
259
|
+
this.wholeProvider = !message.includes(id);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The readable part of a provider error: the `message` inside a JSON body, without a final period. */
|
|
263
|
+
static summary(message) {
|
|
264
|
+
const json = message.match(/\{[\s\S]*\}/)?.[0];
|
|
265
|
+
let text = message;
|
|
266
|
+
try {
|
|
267
|
+
const body = JSON.parse(json);
|
|
268
|
+
text = body?.error?.message || body?.message || message;
|
|
269
|
+
} catch {
|
|
270
|
+
// not JSON: keep the message as it is
|
|
271
|
+
}
|
|
272
|
+
return text.trim().replace(/\.+$/, '');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
covers(model) {
|
|
276
|
+
return model.provider === this.provider && (this.wholeProvider || model.id === this.id);
|
|
277
|
+
}
|
|
278
|
+
}
|