@calmo/task-runner 1.2.2 → 1.2.3
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/.gemini/commands/openspec/apply.toml +21 -0
- package/.gemini/commands/openspec/archive.toml +25 -0
- package/.gemini/commands/openspec/proposal.toml +26 -0
- package/AGENTS.md +18 -0
- package/CHANGELOG.md +16 -0
- package/GEMINI.md +8 -0
- package/coverage/coverage-final.json +4 -4
- package/coverage/index.html +9 -9
- package/coverage/lcov-report/index.html +9 -9
- package/coverage/lcov-report/src/EventBus.ts.html +4 -4
- package/coverage/lcov-report/src/TaskGraphValidator.ts.html +35 -5
- package/coverage/lcov-report/src/TaskRunner.ts.html +7 -109
- package/coverage/lcov-report/src/WorkflowExecutor.ts.html +166 -109
- package/coverage/lcov-report/src/contracts/RunnerEvents.ts.html +1 -1
- package/coverage/lcov-report/src/contracts/index.html +1 -1
- package/coverage/lcov-report/src/index.html +16 -16
- package/coverage/lcov.info +120 -144
- package/coverage/src/EventBus.ts.html +4 -4
- package/coverage/src/TaskGraphValidator.ts.html +35 -5
- package/coverage/src/TaskRunner.ts.html +7 -109
- package/coverage/src/WorkflowExecutor.ts.html +166 -109
- package/coverage/src/contracts/RunnerEvents.ts.html +1 -1
- package/coverage/src/contracts/index.html +1 -1
- package/coverage/src/index.html +16 -16
- package/dist/TaskGraphValidator.d.ts +6 -0
- package/dist/TaskGraphValidator.js +9 -0
- package/dist/TaskGraphValidator.js.map +1 -1
- package/dist/TaskRunner.js +1 -32
- package/dist/TaskRunner.js.map +1 -1
- package/dist/WorkflowExecutor.d.ts +9 -0
- package/dist/WorkflowExecutor.js +74 -54
- package/dist/WorkflowExecutor.js.map +1 -1
- package/dist/contracts/ITaskGraphValidator.d.ts +6 -0
- package/openspec/AGENTS.md +456 -0
- package/openspec/changes/add-external-task-cancellation/proposal.md +14 -0
- package/openspec/changes/add-external-task-cancellation/tasks.md +10 -0
- package/openspec/project.md +31 -0
- package/package.json +1 -1
- package/src/TaskGraphValidator.ts +10 -0
- package/src/TaskRunner.ts +1 -35
- package/src/WorkflowExecutor.ts +81 -62
- package/src/contracts/ITaskGraphValidator.ts +7 -0
- package/test-report.xml +47 -39
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
# OpenSpec Instructions
|
|
2
|
+
|
|
3
|
+
Instructions for AI coding assistants using OpenSpec for spec-driven development.
|
|
4
|
+
|
|
5
|
+
## TL;DR Quick Checklist
|
|
6
|
+
|
|
7
|
+
- Search existing work: `openspec spec list --long`, `openspec list` (use `rg` only for full-text search)
|
|
8
|
+
- Decide scope: new capability vs modify existing capability
|
|
9
|
+
- Pick a unique `change-id`: kebab-case, verb-led (`add-`, `update-`, `remove-`, `refactor-`)
|
|
10
|
+
- Scaffold: `proposal.md`, `tasks.md`, `design.md` (only if needed), and delta specs per affected capability
|
|
11
|
+
- Write deltas: use `## ADDED|MODIFIED|REMOVED|RENAMED Requirements`; include at least one `#### Scenario:` per requirement
|
|
12
|
+
- Validate: `openspec validate [change-id] --strict --no-interactive` and fix issues
|
|
13
|
+
- Request approval: Do not start implementation until proposal is approved
|
|
14
|
+
|
|
15
|
+
## Three-Stage Workflow
|
|
16
|
+
|
|
17
|
+
### Stage 1: Creating Changes
|
|
18
|
+
Create proposal when you need to:
|
|
19
|
+
- Add features or functionality
|
|
20
|
+
- Make breaking changes (API, schema)
|
|
21
|
+
- Change architecture or patterns
|
|
22
|
+
- Optimize performance (changes behavior)
|
|
23
|
+
- Update security patterns
|
|
24
|
+
|
|
25
|
+
Triggers (examples):
|
|
26
|
+
- "Help me create a change proposal"
|
|
27
|
+
- "Help me plan a change"
|
|
28
|
+
- "Help me create a proposal"
|
|
29
|
+
- "I want to create a spec proposal"
|
|
30
|
+
- "I want to create a spec"
|
|
31
|
+
|
|
32
|
+
Loose matching guidance:
|
|
33
|
+
- Contains one of: `proposal`, `change`, `spec`
|
|
34
|
+
- With one of: `create`, `plan`, `make`, `start`, `help`
|
|
35
|
+
|
|
36
|
+
Skip proposal for:
|
|
37
|
+
- Bug fixes (restore intended behavior)
|
|
38
|
+
- Typos, formatting, comments
|
|
39
|
+
- Dependency updates (non-breaking)
|
|
40
|
+
- Configuration changes
|
|
41
|
+
- Tests for existing behavior
|
|
42
|
+
|
|
43
|
+
**Workflow**
|
|
44
|
+
1. Review `openspec/project.md`, `openspec list`, and `openspec list --specs` to understand current context.
|
|
45
|
+
2. Choose a unique verb-led `change-id` and scaffold `proposal.md`, `tasks.md`, optional `design.md`, and spec deltas under `openspec/changes/<id>/`.
|
|
46
|
+
3. Draft spec deltas using `## ADDED|MODIFIED|REMOVED Requirements` with at least one `#### Scenario:` per requirement.
|
|
47
|
+
4. Run `openspec validate <id> --strict --no-interactive` and resolve any issues before sharing the proposal.
|
|
48
|
+
|
|
49
|
+
### Stage 2: Implementing Changes
|
|
50
|
+
Track these steps as TODOs and complete them one by one.
|
|
51
|
+
1. **Read proposal.md** - Understand what's being built
|
|
52
|
+
2. **Read design.md** (if exists) - Review technical decisions
|
|
53
|
+
3. **Read tasks.md** - Get implementation checklist
|
|
54
|
+
4. **Implement tasks sequentially** - Complete in order
|
|
55
|
+
5. **Confirm completion** - Ensure every item in `tasks.md` is finished before updating statuses
|
|
56
|
+
6. **Update checklist** - After all work is done, set every task to `- [x]` so the list reflects reality
|
|
57
|
+
7. **Approval gate** - Do not start implementation until the proposal is reviewed and approved
|
|
58
|
+
|
|
59
|
+
### Stage 3: Archiving Changes
|
|
60
|
+
After deployment, create separate PR to:
|
|
61
|
+
- Move `changes/[name]/` → `changes/archive/YYYY-MM-DD-[name]/`
|
|
62
|
+
- Update `specs/` if capabilities changed
|
|
63
|
+
- Use `openspec archive <change-id> --skip-specs --yes` for tooling-only changes (always pass the change ID explicitly)
|
|
64
|
+
- Run `openspec validate --strict --no-interactive` to confirm the archived change passes checks
|
|
65
|
+
|
|
66
|
+
## Before Any Task
|
|
67
|
+
|
|
68
|
+
**Context Checklist:**
|
|
69
|
+
- [ ] Read relevant specs in `specs/[capability]/spec.md`
|
|
70
|
+
- [ ] Check pending changes in `changes/` for conflicts
|
|
71
|
+
- [ ] Read `openspec/project.md` for conventions
|
|
72
|
+
- [ ] Run `openspec list` to see active changes
|
|
73
|
+
- [ ] Run `openspec list --specs` to see existing capabilities
|
|
74
|
+
|
|
75
|
+
**Before Creating Specs:**
|
|
76
|
+
- Always check if capability already exists
|
|
77
|
+
- Prefer modifying existing specs over creating duplicates
|
|
78
|
+
- Use `openspec show [spec]` to review current state
|
|
79
|
+
- If request is ambiguous, ask 1–2 clarifying questions before scaffolding
|
|
80
|
+
|
|
81
|
+
### Search Guidance
|
|
82
|
+
- Enumerate specs: `openspec spec list --long` (or `--json` for scripts)
|
|
83
|
+
- Enumerate changes: `openspec list` (or `openspec change list --json` - deprecated but available)
|
|
84
|
+
- Show details:
|
|
85
|
+
- Spec: `openspec show <spec-id> --type spec` (use `--json` for filters)
|
|
86
|
+
- Change: `openspec show <change-id> --json --deltas-only`
|
|
87
|
+
- Full-text search (use ripgrep): `rg -n "Requirement:|Scenario:" openspec/specs`
|
|
88
|
+
|
|
89
|
+
## Quick Start
|
|
90
|
+
|
|
91
|
+
### CLI Commands
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Essential commands
|
|
95
|
+
openspec list # List active changes
|
|
96
|
+
openspec list --specs # List specifications
|
|
97
|
+
openspec show [item] # Display change or spec
|
|
98
|
+
openspec validate [item] # Validate changes or specs
|
|
99
|
+
openspec archive <change-id> [--yes|-y] # Archive after deployment (add --yes for non-interactive runs)
|
|
100
|
+
|
|
101
|
+
# Project management
|
|
102
|
+
openspec init [path] # Initialize OpenSpec
|
|
103
|
+
openspec update [path] # Update instruction files
|
|
104
|
+
|
|
105
|
+
# Interactive mode
|
|
106
|
+
openspec show # Prompts for selection
|
|
107
|
+
openspec validate # Bulk validation mode
|
|
108
|
+
|
|
109
|
+
# Debugging
|
|
110
|
+
openspec show [change] --json --deltas-only
|
|
111
|
+
openspec validate [change] --strict --no-interactive
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Command Flags
|
|
115
|
+
|
|
116
|
+
- `--json` - Machine-readable output
|
|
117
|
+
- `--type change|spec` - Disambiguate items
|
|
118
|
+
- `--strict` - Comprehensive validation
|
|
119
|
+
- `--no-interactive` - Disable prompts
|
|
120
|
+
- `--skip-specs` - Archive without spec updates
|
|
121
|
+
- `--yes`/`-y` - Skip confirmation prompts (non-interactive archive)
|
|
122
|
+
|
|
123
|
+
## Directory Structure
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
openspec/
|
|
127
|
+
├── project.md # Project conventions
|
|
128
|
+
├── specs/ # Current truth - what IS built
|
|
129
|
+
│ └── [capability]/ # Single focused capability
|
|
130
|
+
│ ├── spec.md # Requirements and scenarios
|
|
131
|
+
│ └── design.md # Technical patterns
|
|
132
|
+
├── changes/ # Proposals - what SHOULD change
|
|
133
|
+
│ ├── [change-name]/
|
|
134
|
+
│ │ ├── proposal.md # Why, what, impact
|
|
135
|
+
│ │ ├── tasks.md # Implementation checklist
|
|
136
|
+
│ │ ├── design.md # Technical decisions (optional; see criteria)
|
|
137
|
+
│ │ └── specs/ # Delta changes
|
|
138
|
+
│ │ └── [capability]/
|
|
139
|
+
│ │ └── spec.md # ADDED/MODIFIED/REMOVED
|
|
140
|
+
│ └── archive/ # Completed changes
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Creating Change Proposals
|
|
144
|
+
|
|
145
|
+
### Decision Tree
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
New request?
|
|
149
|
+
├─ Bug fix restoring spec behavior? → Fix directly
|
|
150
|
+
├─ Typo/format/comment? → Fix directly
|
|
151
|
+
├─ New feature/capability? → Create proposal
|
|
152
|
+
├─ Breaking change? → Create proposal
|
|
153
|
+
├─ Architecture change? → Create proposal
|
|
154
|
+
└─ Unclear? → Create proposal (safer)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Proposal Structure
|
|
158
|
+
|
|
159
|
+
1. **Create directory:** `changes/[change-id]/` (kebab-case, verb-led, unique)
|
|
160
|
+
|
|
161
|
+
2. **Write proposal.md:**
|
|
162
|
+
```markdown
|
|
163
|
+
# Change: [Brief description of change]
|
|
164
|
+
|
|
165
|
+
## Why
|
|
166
|
+
[1-2 sentences on problem/opportunity]
|
|
167
|
+
|
|
168
|
+
## What Changes
|
|
169
|
+
- [Bullet list of changes]
|
|
170
|
+
- [Mark breaking changes with **BREAKING**]
|
|
171
|
+
|
|
172
|
+
## Impact
|
|
173
|
+
- Affected specs: [list capabilities]
|
|
174
|
+
- Affected code: [key files/systems]
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
3. **Create spec deltas:** `specs/[capability]/spec.md`
|
|
178
|
+
```markdown
|
|
179
|
+
## ADDED Requirements
|
|
180
|
+
### Requirement: New Feature
|
|
181
|
+
The system SHALL provide...
|
|
182
|
+
|
|
183
|
+
#### Scenario: Success case
|
|
184
|
+
- **WHEN** user performs action
|
|
185
|
+
- **THEN** expected result
|
|
186
|
+
|
|
187
|
+
## MODIFIED Requirements
|
|
188
|
+
### Requirement: Existing Feature
|
|
189
|
+
[Complete modified requirement]
|
|
190
|
+
|
|
191
|
+
## REMOVED Requirements
|
|
192
|
+
### Requirement: Old Feature
|
|
193
|
+
**Reason**: [Why removing]
|
|
194
|
+
**Migration**: [How to handle]
|
|
195
|
+
```
|
|
196
|
+
If multiple capabilities are affected, create multiple delta files under `changes/[change-id]/specs/<capability>/spec.md`—one per capability.
|
|
197
|
+
|
|
198
|
+
4. **Create tasks.md:**
|
|
199
|
+
```markdown
|
|
200
|
+
## 1. Implementation
|
|
201
|
+
- [ ] 1.1 Create database schema
|
|
202
|
+
- [ ] 1.2 Implement API endpoint
|
|
203
|
+
- [ ] 1.3 Add frontend component
|
|
204
|
+
- [ ] 1.4 Write tests
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
5. **Create design.md when needed:**
|
|
208
|
+
Create `design.md` if any of the following apply; otherwise omit it:
|
|
209
|
+
- Cross-cutting change (multiple services/modules) or a new architectural pattern
|
|
210
|
+
- New external dependency or significant data model changes
|
|
211
|
+
- Security, performance, or migration complexity
|
|
212
|
+
- Ambiguity that benefits from technical decisions before coding
|
|
213
|
+
|
|
214
|
+
Minimal `design.md` skeleton:
|
|
215
|
+
```markdown
|
|
216
|
+
## Context
|
|
217
|
+
[Background, constraints, stakeholders]
|
|
218
|
+
|
|
219
|
+
## Goals / Non-Goals
|
|
220
|
+
- Goals: [...]
|
|
221
|
+
- Non-Goals: [...]
|
|
222
|
+
|
|
223
|
+
## Decisions
|
|
224
|
+
- Decision: [What and why]
|
|
225
|
+
- Alternatives considered: [Options + rationale]
|
|
226
|
+
|
|
227
|
+
## Risks / Trade-offs
|
|
228
|
+
- [Risk] → Mitigation
|
|
229
|
+
|
|
230
|
+
## Migration Plan
|
|
231
|
+
[Steps, rollback]
|
|
232
|
+
|
|
233
|
+
## Open Questions
|
|
234
|
+
- [...]
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Spec File Format
|
|
238
|
+
|
|
239
|
+
### Critical: Scenario Formatting
|
|
240
|
+
|
|
241
|
+
**CORRECT** (use #### headers):
|
|
242
|
+
```markdown
|
|
243
|
+
#### Scenario: User login success
|
|
244
|
+
- **WHEN** valid credentials provided
|
|
245
|
+
- **THEN** return JWT token
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**WRONG** (don't use bullets or bold):
|
|
249
|
+
```markdown
|
|
250
|
+
- **Scenario: User login** ❌
|
|
251
|
+
**Scenario**: User login ❌
|
|
252
|
+
### Scenario: User login ❌
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Every requirement MUST have at least one scenario.
|
|
256
|
+
|
|
257
|
+
### Requirement Wording
|
|
258
|
+
- Use SHALL/MUST for normative requirements (avoid should/may unless intentionally non-normative)
|
|
259
|
+
|
|
260
|
+
### Delta Operations
|
|
261
|
+
|
|
262
|
+
- `## ADDED Requirements` - New capabilities
|
|
263
|
+
- `## MODIFIED Requirements` - Changed behavior
|
|
264
|
+
- `## REMOVED Requirements` - Deprecated features
|
|
265
|
+
- `## RENAMED Requirements` - Name changes
|
|
266
|
+
|
|
267
|
+
Headers matched with `trim(header)` - whitespace ignored.
|
|
268
|
+
|
|
269
|
+
#### When to use ADDED vs MODIFIED
|
|
270
|
+
- ADDED: Introduces a new capability or sub-capability that can stand alone as a requirement. Prefer ADDED when the change is orthogonal (e.g., adding "Slash Command Configuration") rather than altering the semantics of an existing requirement.
|
|
271
|
+
- MODIFIED: Changes the behavior, scope, or acceptance criteria of an existing requirement. Always paste the full, updated requirement content (header + all scenarios). The archiver will replace the entire requirement with what you provide here; partial deltas will drop previous details.
|
|
272
|
+
- RENAMED: Use when only the name changes. If you also change behavior, use RENAMED (name) plus MODIFIED (content) referencing the new name.
|
|
273
|
+
|
|
274
|
+
Common pitfall: Using MODIFIED to add a new concern without including the previous text. This causes loss of detail at archive time. If you aren’t explicitly changing the existing requirement, add a new requirement under ADDED instead.
|
|
275
|
+
|
|
276
|
+
Authoring a MODIFIED requirement correctly:
|
|
277
|
+
1) Locate the existing requirement in `openspec/specs/<capability>/spec.md`.
|
|
278
|
+
2) Copy the entire requirement block (from `### Requirement: ...` through its scenarios).
|
|
279
|
+
3) Paste it under `## MODIFIED Requirements` and edit to reflect the new behavior.
|
|
280
|
+
4) Ensure the header text matches exactly (whitespace-insensitive) and keep at least one `#### Scenario:`.
|
|
281
|
+
|
|
282
|
+
Example for RENAMED:
|
|
283
|
+
```markdown
|
|
284
|
+
## RENAMED Requirements
|
|
285
|
+
- FROM: `### Requirement: Login`
|
|
286
|
+
- TO: `### Requirement: User Authentication`
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Troubleshooting
|
|
290
|
+
|
|
291
|
+
### Common Errors
|
|
292
|
+
|
|
293
|
+
**"Change must have at least one delta"**
|
|
294
|
+
- Check `changes/[name]/specs/` exists with .md files
|
|
295
|
+
- Verify files have operation prefixes (## ADDED Requirements)
|
|
296
|
+
|
|
297
|
+
**"Requirement must have at least one scenario"**
|
|
298
|
+
- Check scenarios use `#### Scenario:` format (4 hashtags)
|
|
299
|
+
- Don't use bullet points or bold for scenario headers
|
|
300
|
+
|
|
301
|
+
**Silent scenario parsing failures**
|
|
302
|
+
- Exact format required: `#### Scenario: Name`
|
|
303
|
+
- Debug with: `openspec show [change] --json --deltas-only`
|
|
304
|
+
|
|
305
|
+
### Validation Tips
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
# Always use strict mode for comprehensive checks
|
|
309
|
+
openspec validate [change] --strict --no-interactive
|
|
310
|
+
|
|
311
|
+
# Debug delta parsing
|
|
312
|
+
openspec show [change] --json | jq '.deltas'
|
|
313
|
+
|
|
314
|
+
# Check specific requirement
|
|
315
|
+
openspec show [spec] --json -r 1
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Happy Path Script
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
# 1) Explore current state
|
|
322
|
+
openspec spec list --long
|
|
323
|
+
openspec list
|
|
324
|
+
# Optional full-text search:
|
|
325
|
+
# rg -n "Requirement:|Scenario:" openspec/specs
|
|
326
|
+
# rg -n "^#|Requirement:" openspec/changes
|
|
327
|
+
|
|
328
|
+
# 2) Choose change id and scaffold
|
|
329
|
+
CHANGE=add-two-factor-auth
|
|
330
|
+
mkdir -p openspec/changes/$CHANGE/{specs/auth}
|
|
331
|
+
printf "## Why\n...\n\n## What Changes\n- ...\n\n## Impact\n- ...\n" > openspec/changes/$CHANGE/proposal.md
|
|
332
|
+
printf "## 1. Implementation\n- [ ] 1.1 ...\n" > openspec/changes/$CHANGE/tasks.md
|
|
333
|
+
|
|
334
|
+
# 3) Add deltas (example)
|
|
335
|
+
cat > openspec/changes/$CHANGE/specs/auth/spec.md << 'EOF'
|
|
336
|
+
## ADDED Requirements
|
|
337
|
+
### Requirement: Two-Factor Authentication
|
|
338
|
+
Users MUST provide a second factor during login.
|
|
339
|
+
|
|
340
|
+
#### Scenario: OTP required
|
|
341
|
+
- **WHEN** valid credentials are provided
|
|
342
|
+
- **THEN** an OTP challenge is required
|
|
343
|
+
EOF
|
|
344
|
+
|
|
345
|
+
# 4) Validate
|
|
346
|
+
openspec validate $CHANGE --strict --no-interactive
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Multi-Capability Example
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
openspec/changes/add-2fa-notify/
|
|
353
|
+
├── proposal.md
|
|
354
|
+
├── tasks.md
|
|
355
|
+
└── specs/
|
|
356
|
+
├── auth/
|
|
357
|
+
│ └── spec.md # ADDED: Two-Factor Authentication
|
|
358
|
+
└── notifications/
|
|
359
|
+
└── spec.md # ADDED: OTP email notification
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
auth/spec.md
|
|
363
|
+
```markdown
|
|
364
|
+
## ADDED Requirements
|
|
365
|
+
### Requirement: Two-Factor Authentication
|
|
366
|
+
...
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
notifications/spec.md
|
|
370
|
+
```markdown
|
|
371
|
+
## ADDED Requirements
|
|
372
|
+
### Requirement: OTP Email Notification
|
|
373
|
+
...
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## Best Practices
|
|
377
|
+
|
|
378
|
+
### Simplicity First
|
|
379
|
+
- Default to <100 lines of new code
|
|
380
|
+
- Single-file implementations until proven insufficient
|
|
381
|
+
- Avoid frameworks without clear justification
|
|
382
|
+
- Choose boring, proven patterns
|
|
383
|
+
|
|
384
|
+
### Complexity Triggers
|
|
385
|
+
Only add complexity with:
|
|
386
|
+
- Performance data showing current solution too slow
|
|
387
|
+
- Concrete scale requirements (>1000 users, >100MB data)
|
|
388
|
+
- Multiple proven use cases requiring abstraction
|
|
389
|
+
|
|
390
|
+
### Clear References
|
|
391
|
+
- Use `file.ts:42` format for code locations
|
|
392
|
+
- Reference specs as `specs/auth/spec.md`
|
|
393
|
+
- Link related changes and PRs
|
|
394
|
+
|
|
395
|
+
### Capability Naming
|
|
396
|
+
- Use verb-noun: `user-auth`, `payment-capture`
|
|
397
|
+
- Single purpose per capability
|
|
398
|
+
- 10-minute understandability rule
|
|
399
|
+
- Split if description needs "AND"
|
|
400
|
+
|
|
401
|
+
### Change ID Naming
|
|
402
|
+
- Use kebab-case, short and descriptive: `add-two-factor-auth`
|
|
403
|
+
- Prefer verb-led prefixes: `add-`, `update-`, `remove-`, `refactor-`
|
|
404
|
+
- Ensure uniqueness; if taken, append `-2`, `-3`, etc.
|
|
405
|
+
|
|
406
|
+
## Tool Selection Guide
|
|
407
|
+
|
|
408
|
+
| Task | Tool | Why |
|
|
409
|
+
|------|------|-----|
|
|
410
|
+
| Find files by pattern | Glob | Fast pattern matching |
|
|
411
|
+
| Search code content | Grep | Optimized regex search |
|
|
412
|
+
| Read specific files | Read | Direct file access |
|
|
413
|
+
| Explore unknown scope | Task | Multi-step investigation |
|
|
414
|
+
|
|
415
|
+
## Error Recovery
|
|
416
|
+
|
|
417
|
+
### Change Conflicts
|
|
418
|
+
1. Run `openspec list` to see active changes
|
|
419
|
+
2. Check for overlapping specs
|
|
420
|
+
3. Coordinate with change owners
|
|
421
|
+
4. Consider combining proposals
|
|
422
|
+
|
|
423
|
+
### Validation Failures
|
|
424
|
+
1. Run with `--strict` flag
|
|
425
|
+
2. Check JSON output for details
|
|
426
|
+
3. Verify spec file format
|
|
427
|
+
4. Ensure scenarios properly formatted
|
|
428
|
+
|
|
429
|
+
### Missing Context
|
|
430
|
+
1. Read project.md first
|
|
431
|
+
2. Check related specs
|
|
432
|
+
3. Review recent archives
|
|
433
|
+
4. Ask for clarification
|
|
434
|
+
|
|
435
|
+
## Quick Reference
|
|
436
|
+
|
|
437
|
+
### Stage Indicators
|
|
438
|
+
- `changes/` - Proposed, not yet built
|
|
439
|
+
- `specs/` - Built and deployed
|
|
440
|
+
- `archive/` - Completed changes
|
|
441
|
+
|
|
442
|
+
### File Purposes
|
|
443
|
+
- `proposal.md` - Why and what
|
|
444
|
+
- `tasks.md` - Implementation steps
|
|
445
|
+
- `design.md` - Technical decisions
|
|
446
|
+
- `spec.md` - Requirements and behavior
|
|
447
|
+
|
|
448
|
+
### CLI Essentials
|
|
449
|
+
```bash
|
|
450
|
+
openspec list # What's in progress?
|
|
451
|
+
openspec show [item] # View details
|
|
452
|
+
openspec validate --strict --no-interactive # Is it correct?
|
|
453
|
+
openspec archive <change-id> [--yes|-y] # Mark complete (add --yes for automation)
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Remember: Specs are truth. Changes are proposals. Keep them in sync.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Change: Add External Task Cancellation
|
|
2
|
+
|
|
3
|
+
## Why
|
|
4
|
+
Once `TaskRunner.execute()` is called, there is no way to cancel the operation externally. If a task hangs or if the user wants to abort the workflow (e.g., in a CLI or UI context), the runner continues until completion or failure. This limits the responsiveness and control users have over long-running operations.
|
|
5
|
+
|
|
6
|
+
## What Changes
|
|
7
|
+
- The `TaskRunner.execute()` method will be updated to accept an optional configuration object.
|
|
8
|
+
- This configuration object will support an `AbortSignal` for external cancellation.
|
|
9
|
+
- The configuration object will also support a global timeout for the entire workflow.
|
|
10
|
+
- Tasks will be able to respond to cancellation signals and report their status accordingly.
|
|
11
|
+
|
|
12
|
+
## Impact
|
|
13
|
+
- Affected specs: `001-generic-task-runner` (specifically the `TaskRunner`'s `execute` method behavior)
|
|
14
|
+
- Affected code: `src/TaskRunner.ts`, `src/contracts/RunnerEvents.ts` (for cancellation events), potentially `src/TaskStep.ts` (to propagate `AbortSignal` to individual steps).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
## Implementation
|
|
2
|
+
- [ ] 1.1 Update `TaskRunner.execute` signature to accept an optional config object.
|
|
3
|
+
- [ ] 1.2 Implement logic within `TaskRunner` to listen for `AbortSignal` and initiate cancellation.
|
|
4
|
+
- [ ] 1.3 Implement global timeout mechanism using `AbortController` and `setTimeout`.
|
|
5
|
+
- [ ] 1.4 Propagate `AbortSignal` to individual `TaskStep` executions.
|
|
6
|
+
- [ ] 1.5 Ensure `TaskRunner` correctly handles tasks that are already aborted before execution.
|
|
7
|
+
- [ ] 1.6 Update `TaskResult` and `RunnerEvents` to reflect cancellation status.
|
|
8
|
+
- [ ] 1.7 Add unit tests for `AbortSignal` cancellation scenarios.
|
|
9
|
+
- [ ] 1.8 Add unit tests for global timeout scenarios.
|
|
10
|
+
- [ ] 1.9 Add integration tests covering both `AbortSignal` and timeout interactions.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Project: Task Runner
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
The 'task-runner' project is a TypeScript-based utility designed to manage and execute tasks. It incorporates features such as task cancellation, pre-execution validation, and concurrency control, providing a robust framework for workflow automation.
|
|
5
|
+
|
|
6
|
+
## Tech Stack
|
|
7
|
+
- **Languages:** TypeScript 5.9.3
|
|
8
|
+
- **Testing:** Vitest 4.0.17
|
|
9
|
+
- **Core APIs:** AbortSignal/AbortController (Standard Web APIs for cancellation)
|
|
10
|
+
- **Package Manager:** pnpm
|
|
11
|
+
|
|
12
|
+
## Architecture
|
|
13
|
+
The project follows a modular architecture with distinct components for managing different aspects of task execution:
|
|
14
|
+
- `EventBus.ts`: Handles event propagation within the system.
|
|
15
|
+
- `TaskGraph.ts`: Represents the structure and dependencies of tasks.
|
|
16
|
+
- `TaskGraphValidator.ts`: Ensures the validity of task graphs before execution.
|
|
17
|
+
- `TaskRunner.ts`: Orchestrates the execution of tasks.
|
|
18
|
+
- `WorkflowExecutor.ts`: Manages the overall workflow.
|
|
19
|
+
- `contracts/`: Defines interfaces and types for various components, promoting loose coupling and clear API boundaries.
|
|
20
|
+
|
|
21
|
+
## Conventions
|
|
22
|
+
- **Coding Style:** Adheres to standard TypeScript conventions, enforced by ESLint and Prettier.
|
|
23
|
+
- **Commit Messages:** Follows conventional commits enforced by Commitlint.
|
|
24
|
+
- **Git Hooks:** Utilizes Husky for pre-commit and commit-msg hooks.
|
|
25
|
+
- **Testing:** Uses Vitest for unit and integration testing.
|
|
26
|
+
|
|
27
|
+
## Build/Test/Run Commands
|
|
28
|
+
- **Install Dependencies:** `pnpm install`
|
|
29
|
+
- **Build Project:** `pnpm build`
|
|
30
|
+
- **Run Tests:** `pnpm test`
|
|
31
|
+
- **Lint Code:** `pnpm lint`
|
package/package.json
CHANGED
|
@@ -93,6 +93,16 @@ export class TaskGraphValidator implements ITaskGraphValidator {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Creates a human-readable error message from a validation result.
|
|
98
|
+
* @param result The validation result containing errors.
|
|
99
|
+
* @returns A formatted error string.
|
|
100
|
+
*/
|
|
101
|
+
createErrorMessage(result: ValidationResult): string {
|
|
102
|
+
const errorDetails = result.errors.map(e => e.message);
|
|
103
|
+
return `Task graph validation failed: ${errorDetails.join("; ")}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
96
106
|
private detectCycle(
|
|
97
107
|
taskId: string,
|
|
98
108
|
path: string[],
|
package/src/TaskRunner.ts
CHANGED
|
@@ -65,41 +65,7 @@ export class TaskRunner<TContext> {
|
|
|
65
65
|
|
|
66
66
|
const validationResult = this.validator.validate(taskGraph);
|
|
67
67
|
if (!validationResult.isValid) {
|
|
68
|
-
|
|
69
|
-
const affectedTasks = new Set<string>();
|
|
70
|
-
const errorDetails: string[] = [];
|
|
71
|
-
|
|
72
|
-
for (const error of validationResult.errors) {
|
|
73
|
-
errorDetails.push(error.message);
|
|
74
|
-
switch (error.type) {
|
|
75
|
-
case "cycle": {
|
|
76
|
-
// details is { cyclePath: string[] }
|
|
77
|
-
const path = (error.details as { cyclePath: string[] }).cyclePath;
|
|
78
|
-
// The last element duplicates the first in the path representation, so valid unique tasks are slice(0, -1) or just all as Set handles uniq
|
|
79
|
-
path.forEach((t) => affectedTasks.add(t));
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
case "missing_dependency": {
|
|
83
|
-
// details is { taskId: string, missingDependencyId: string }
|
|
84
|
-
const d = error.details as { taskId: string };
|
|
85
|
-
affectedTasks.add(d.taskId);
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
case "duplicate_task": {
|
|
89
|
-
const d = error.details as { taskId: string };
|
|
90
|
-
affectedTasks.add(d.taskId);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Legacy error format: "Circular dependency or missing dependency detected. Unable to run tasks: A, B"
|
|
97
|
-
const taskList = Array.from(affectedTasks).join(", ");
|
|
98
|
-
const legacyMessage = `Circular dependency or missing dependency detected. Unable to run tasks: ${taskList}`;
|
|
99
|
-
const detailedMessage = `Task graph validation failed: ${errorDetails.join("; ")}`;
|
|
100
|
-
|
|
101
|
-
// Combine them to satisfy both legacy tests (checking for legacy message) and new requirements (clear details)
|
|
102
|
-
throw new Error(`${legacyMessage} | ${detailedMessage}`);
|
|
68
|
+
throw new Error(this.validator.createErrorMessage(validationResult));
|
|
103
69
|
}
|
|
104
70
|
|
|
105
71
|
const executor = new WorkflowExecutor(this.context, this.eventBus);
|