@ifi/pi-spec 0.2.14
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 +528 -0
- package/extension/assets/templates/agent-file-template.md +28 -0
- package/extension/assets/templates/checklist-template.md +40 -0
- package/extension/assets/templates/commands/analyze.md +187 -0
- package/extension/assets/templates/commands/checklist.md +298 -0
- package/extension/assets/templates/commands/clarify.md +184 -0
- package/extension/assets/templates/commands/constitution.md +84 -0
- package/extension/assets/templates/commands/implement.md +201 -0
- package/extension/assets/templates/commands/plan.md +96 -0
- package/extension/assets/templates/commands/specify.md +242 -0
- package/extension/assets/templates/commands/tasks.md +203 -0
- package/extension/assets/templates/constitution-template.md +50 -0
- package/extension/assets/templates/plan-template.md +104 -0
- package/extension/assets/templates/spec-template.md +115 -0
- package/extension/assets/templates/tasks-template.md +251 -0
- package/extension/git.ts +64 -0
- package/extension/index.ts +366 -0
- package/extension/prompts.ts +124 -0
- package/extension/scaffold.ts +151 -0
- package/extension/status.ts +231 -0
- package/extension/types.ts +93 -0
- package/extension/workspace.ts +242 -0
- package/package.json +50 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
description: "Task list template for feature implementation"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tasks: [FEATURE NAME]
|
|
7
|
+
|
|
8
|
+
**Input**: Design documents from `/specs/[###-feature-name]/`
|
|
9
|
+
**Prerequisites**: plan.md (required), spec.md (required for user stories), research.md, data-model.md, contracts/
|
|
10
|
+
|
|
11
|
+
**Tests**: The examples below include test tasks. Tests are OPTIONAL - only include them if explicitly requested in the feature specification.
|
|
12
|
+
|
|
13
|
+
**Organization**: Tasks are grouped by user story to enable independent implementation and testing of each story.
|
|
14
|
+
|
|
15
|
+
## Format: `[ID] [P?] [Story] Description`
|
|
16
|
+
|
|
17
|
+
- **[P]**: Can run in parallel (different files, no dependencies)
|
|
18
|
+
- **[Story]**: Which user story this task belongs to (e.g., US1, US2, US3)
|
|
19
|
+
- Include exact file paths in descriptions
|
|
20
|
+
|
|
21
|
+
## Path Conventions
|
|
22
|
+
|
|
23
|
+
- **Single project**: `src/`, `tests/` at repository root
|
|
24
|
+
- **Web app**: `backend/src/`, `frontend/src/`
|
|
25
|
+
- **Mobile**: `api/src/`, `ios/src/` or `android/src/`
|
|
26
|
+
- Paths shown below assume single project - adjust based on plan.md structure
|
|
27
|
+
|
|
28
|
+
<!--
|
|
29
|
+
============================================================================
|
|
30
|
+
IMPORTANT: The tasks below are SAMPLE TASKS for illustration purposes only.
|
|
31
|
+
|
|
32
|
+
The /speckit.tasks command MUST replace these with actual tasks based on:
|
|
33
|
+
- User stories from spec.md (with their priorities P1, P2, P3...)
|
|
34
|
+
- Feature requirements from plan.md
|
|
35
|
+
- Entities from data-model.md
|
|
36
|
+
- Endpoints from contracts/
|
|
37
|
+
|
|
38
|
+
Tasks MUST be organized by user story so each story can be:
|
|
39
|
+
- Implemented independently
|
|
40
|
+
- Tested independently
|
|
41
|
+
- Delivered as an MVP increment
|
|
42
|
+
|
|
43
|
+
DO NOT keep these sample tasks in the generated tasks.md file.
|
|
44
|
+
============================================================================
|
|
45
|
+
-->
|
|
46
|
+
|
|
47
|
+
## Phase 1: Setup (Shared Infrastructure)
|
|
48
|
+
|
|
49
|
+
**Purpose**: Project initialization and basic structure
|
|
50
|
+
|
|
51
|
+
- [ ] T001 Create project structure per implementation plan
|
|
52
|
+
- [ ] T002 Initialize [language] project with [framework] dependencies
|
|
53
|
+
- [ ] T003 [P] Configure linting and formatting tools
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Phase 2: Foundational (Blocking Prerequisites)
|
|
58
|
+
|
|
59
|
+
**Purpose**: Core infrastructure that MUST be complete before ANY user story can be implemented
|
|
60
|
+
|
|
61
|
+
**⚠️ CRITICAL**: No user story work can begin until this phase is complete
|
|
62
|
+
|
|
63
|
+
Examples of foundational tasks (adjust based on your project):
|
|
64
|
+
|
|
65
|
+
- [ ] T004 Setup database schema and migrations framework
|
|
66
|
+
- [ ] T005 [P] Implement authentication/authorization framework
|
|
67
|
+
- [ ] T006 [P] Setup API routing and middleware structure
|
|
68
|
+
- [ ] T007 Create base models/entities that all stories depend on
|
|
69
|
+
- [ ] T008 Configure error handling and logging infrastructure
|
|
70
|
+
- [ ] T009 Setup environment configuration management
|
|
71
|
+
|
|
72
|
+
**Checkpoint**: Foundation ready - user story implementation can now begin in parallel
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Phase 3: User Story 1 - [Title] (Priority: P1) 🎯 MVP
|
|
77
|
+
|
|
78
|
+
**Goal**: [Brief description of what this story delivers]
|
|
79
|
+
|
|
80
|
+
**Independent Test**: [How to verify this story works on its own]
|
|
81
|
+
|
|
82
|
+
### Tests for User Story 1 (OPTIONAL - only if tests requested) ⚠️
|
|
83
|
+
|
|
84
|
+
> **NOTE: Write these tests FIRST, ensure they FAIL before implementation**
|
|
85
|
+
|
|
86
|
+
- [ ] T010 [P] [US1] Contract test for [endpoint] in tests/contract/test_[name].py
|
|
87
|
+
- [ ] T011 [P] [US1] Integration test for [user journey] in tests/integration/test_[name].py
|
|
88
|
+
|
|
89
|
+
### Implementation for User Story 1
|
|
90
|
+
|
|
91
|
+
- [ ] T012 [P] [US1] Create [Entity1] model in src/models/[entity1].py
|
|
92
|
+
- [ ] T013 [P] [US1] Create [Entity2] model in src/models/[entity2].py
|
|
93
|
+
- [ ] T014 [US1] Implement [Service] in src/services/[service].py (depends on T012, T013)
|
|
94
|
+
- [ ] T015 [US1] Implement [endpoint/feature] in src/[location]/[file].py
|
|
95
|
+
- [ ] T016 [US1] Add validation and error handling
|
|
96
|
+
- [ ] T017 [US1] Add logging for user story 1 operations
|
|
97
|
+
|
|
98
|
+
**Checkpoint**: At this point, User Story 1 should be fully functional and testable independently
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Phase 4: User Story 2 - [Title] (Priority: P2)
|
|
103
|
+
|
|
104
|
+
**Goal**: [Brief description of what this story delivers]
|
|
105
|
+
|
|
106
|
+
**Independent Test**: [How to verify this story works on its own]
|
|
107
|
+
|
|
108
|
+
### Tests for User Story 2 (OPTIONAL - only if tests requested) ⚠️
|
|
109
|
+
|
|
110
|
+
- [ ] T018 [P] [US2] Contract test for [endpoint] in tests/contract/test_[name].py
|
|
111
|
+
- [ ] T019 [P] [US2] Integration test for [user journey] in tests/integration/test_[name].py
|
|
112
|
+
|
|
113
|
+
### Implementation for User Story 2
|
|
114
|
+
|
|
115
|
+
- [ ] T020 [P] [US2] Create [Entity] model in src/models/[entity].py
|
|
116
|
+
- [ ] T021 [US2] Implement [Service] in src/services/[service].py
|
|
117
|
+
- [ ] T022 [US2] Implement [endpoint/feature] in src/[location]/[file].py
|
|
118
|
+
- [ ] T023 [US2] Integrate with User Story 1 components (if needed)
|
|
119
|
+
|
|
120
|
+
**Checkpoint**: At this point, User Stories 1 AND 2 should both work independently
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Phase 5: User Story 3 - [Title] (Priority: P3)
|
|
125
|
+
|
|
126
|
+
**Goal**: [Brief description of what this story delivers]
|
|
127
|
+
|
|
128
|
+
**Independent Test**: [How to verify this story works on its own]
|
|
129
|
+
|
|
130
|
+
### Tests for User Story 3 (OPTIONAL - only if tests requested) ⚠️
|
|
131
|
+
|
|
132
|
+
- [ ] T024 [P] [US3] Contract test for [endpoint] in tests/contract/test_[name].py
|
|
133
|
+
- [ ] T025 [P] [US3] Integration test for [user journey] in tests/integration/test_[name].py
|
|
134
|
+
|
|
135
|
+
### Implementation for User Story 3
|
|
136
|
+
|
|
137
|
+
- [ ] T026 [P] [US3] Create [Entity] model in src/models/[entity].py
|
|
138
|
+
- [ ] T027 [US3] Implement [Service] in src/services/[service].py
|
|
139
|
+
- [ ] T028 [US3] Implement [endpoint/feature] in src/[location]/[file].py
|
|
140
|
+
|
|
141
|
+
**Checkpoint**: All user stories should now be independently functional
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
[Add more user story phases as needed, following the same pattern]
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Phase N: Polish & Cross-Cutting Concerns
|
|
150
|
+
|
|
151
|
+
**Purpose**: Improvements that affect multiple user stories
|
|
152
|
+
|
|
153
|
+
- [ ] TXXX [P] Documentation updates in docs/
|
|
154
|
+
- [ ] TXXX Code cleanup and refactoring
|
|
155
|
+
- [ ] TXXX Performance optimization across all stories
|
|
156
|
+
- [ ] TXXX [P] Additional unit tests (if requested) in tests/unit/
|
|
157
|
+
- [ ] TXXX Security hardening
|
|
158
|
+
- [ ] TXXX Run quickstart.md validation
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Dependencies & Execution Order
|
|
163
|
+
|
|
164
|
+
### Phase Dependencies
|
|
165
|
+
|
|
166
|
+
- **Setup (Phase 1)**: No dependencies - can start immediately
|
|
167
|
+
- **Foundational (Phase 2)**: Depends on Setup completion - BLOCKS all user stories
|
|
168
|
+
- **User Stories (Phase 3+)**: All depend on Foundational phase completion
|
|
169
|
+
- User stories can then proceed in parallel (if staffed)
|
|
170
|
+
- Or sequentially in priority order (P1 → P2 → P3)
|
|
171
|
+
- **Polish (Final Phase)**: Depends on all desired user stories being complete
|
|
172
|
+
|
|
173
|
+
### User Story Dependencies
|
|
174
|
+
|
|
175
|
+
- **User Story 1 (P1)**: Can start after Foundational (Phase 2) - No dependencies on other stories
|
|
176
|
+
- **User Story 2 (P2)**: Can start after Foundational (Phase 2) - May integrate with US1 but should be independently testable
|
|
177
|
+
- **User Story 3 (P3)**: Can start after Foundational (Phase 2) - May integrate with US1/US2 but should be independently testable
|
|
178
|
+
|
|
179
|
+
### Within Each User Story
|
|
180
|
+
|
|
181
|
+
- Tests (if included) MUST be written and FAIL before implementation
|
|
182
|
+
- Models before services
|
|
183
|
+
- Services before endpoints
|
|
184
|
+
- Core implementation before integration
|
|
185
|
+
- Story complete before moving to next priority
|
|
186
|
+
|
|
187
|
+
### Parallel Opportunities
|
|
188
|
+
|
|
189
|
+
- All Setup tasks marked [P] can run in parallel
|
|
190
|
+
- All Foundational tasks marked [P] can run in parallel (within Phase 2)
|
|
191
|
+
- Once Foundational phase completes, all user stories can start in parallel (if team capacity allows)
|
|
192
|
+
- All tests for a user story marked [P] can run in parallel
|
|
193
|
+
- Models within a story marked [P] can run in parallel
|
|
194
|
+
- Different user stories can be worked on in parallel by different team members
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Parallel Example: User Story 1
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# Launch all tests for User Story 1 together (if tests requested):
|
|
202
|
+
Task: "Contract test for [endpoint] in tests/contract/test_[name].py"
|
|
203
|
+
Task: "Integration test for [user journey] in tests/integration/test_[name].py"
|
|
204
|
+
|
|
205
|
+
# Launch all models for User Story 1 together:
|
|
206
|
+
Task: "Create [Entity1] model in src/models/[entity1].py"
|
|
207
|
+
Task: "Create [Entity2] model in src/models/[entity2].py"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Implementation Strategy
|
|
213
|
+
|
|
214
|
+
### MVP First (User Story 1 Only)
|
|
215
|
+
|
|
216
|
+
1. Complete Phase 1: Setup
|
|
217
|
+
2. Complete Phase 2: Foundational (CRITICAL - blocks all stories)
|
|
218
|
+
3. Complete Phase 3: User Story 1
|
|
219
|
+
4. **STOP and VALIDATE**: Test User Story 1 independently
|
|
220
|
+
5. Deploy/demo if ready
|
|
221
|
+
|
|
222
|
+
### Incremental Delivery
|
|
223
|
+
|
|
224
|
+
1. Complete Setup + Foundational → Foundation ready
|
|
225
|
+
2. Add User Story 1 → Test independently → Deploy/Demo (MVP!)
|
|
226
|
+
3. Add User Story 2 → Test independently → Deploy/Demo
|
|
227
|
+
4. Add User Story 3 → Test independently → Deploy/Demo
|
|
228
|
+
5. Each story adds value without breaking previous stories
|
|
229
|
+
|
|
230
|
+
### Parallel Team Strategy
|
|
231
|
+
|
|
232
|
+
With multiple developers:
|
|
233
|
+
|
|
234
|
+
1. Team completes Setup + Foundational together
|
|
235
|
+
2. Once Foundational is done:
|
|
236
|
+
- Developer A: User Story 1
|
|
237
|
+
- Developer B: User Story 2
|
|
238
|
+
- Developer C: User Story 3
|
|
239
|
+
3. Stories complete and integrate independently
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Notes
|
|
244
|
+
|
|
245
|
+
- [P] tasks = different files, no dependencies
|
|
246
|
+
- [Story] label maps task to specific user story for traceability
|
|
247
|
+
- Each user story should be independently completable and testable
|
|
248
|
+
- Verify tests fail before implementing
|
|
249
|
+
- Commit after each task or logical group
|
|
250
|
+
- Stop at any checkpoint to validate story independently
|
|
251
|
+
- Avoid: vague tasks, same file conflicts, cross-story dependencies that break independence
|
package/extension/git.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export interface GitClient {
|
|
4
|
+
getRepoRoot(cwd: string): string | null;
|
|
5
|
+
getCurrentBranch(repoRoot: string): string | null;
|
|
6
|
+
listBranches(repoRoot: string): string[];
|
|
7
|
+
isDirty(repoRoot: string): boolean;
|
|
8
|
+
createAndSwitchBranch(repoRoot: string, branchName: string): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function runGit(repoRoot: string, args: string[]): string {
|
|
12
|
+
return execFileSync("git", args, {
|
|
13
|
+
cwd: repoRoot,
|
|
14
|
+
encoding: "utf8",
|
|
15
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
16
|
+
}).trim();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createGitClient(): GitClient {
|
|
20
|
+
return {
|
|
21
|
+
getRepoRoot(cwd) {
|
|
22
|
+
try {
|
|
23
|
+
const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
24
|
+
cwd,
|
|
25
|
+
encoding: "utf8",
|
|
26
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
27
|
+
}).trim();
|
|
28
|
+
return root || null;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
getCurrentBranch(repoRoot) {
|
|
34
|
+
try {
|
|
35
|
+
const branch = runGit(repoRoot, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
36
|
+
return branch || null;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
listBranches(repoRoot) {
|
|
42
|
+
try {
|
|
43
|
+
const output = runGit(repoRoot, ["for-each-ref", "--format=%(refname:short)", "refs/heads", "refs/remotes"]);
|
|
44
|
+
return output
|
|
45
|
+
.split(/\r?\n/)
|
|
46
|
+
.map((line) => line.trim())
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.map((line) => line.replace(/^[^/]+\//, ""));
|
|
49
|
+
} catch {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
isDirty(repoRoot) {
|
|
54
|
+
try {
|
|
55
|
+
return runGit(repoRoot, ["status", "--short"]).length > 0;
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
createAndSwitchBranch(repoRoot, branchName) {
|
|
61
|
+
runGit(repoRoot, ["checkout", "-b", branchName]);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import { Text } from "@mariozechner/pi-tui";
|
|
3
|
+
import { createGitClient } from "./git.js";
|
|
4
|
+
import { buildWorkflowPrompt, getStepNotes } from "./prompts.js";
|
|
5
|
+
import {
|
|
6
|
+
ensureFeatureArtifacts,
|
|
7
|
+
ensurePlanArtifact,
|
|
8
|
+
ensureWorkflowScaffold,
|
|
9
|
+
formatCreatedFiles,
|
|
10
|
+
getWorkflowTemplatePath,
|
|
11
|
+
} from "./scaffold.js";
|
|
12
|
+
import {
|
|
13
|
+
buildWorkflowStatus,
|
|
14
|
+
formatFeatureList,
|
|
15
|
+
formatHelpReport,
|
|
16
|
+
formatWorkflowStatus,
|
|
17
|
+
summarizeChecklists,
|
|
18
|
+
} from "./status.js";
|
|
19
|
+
import { SPEC_SUBCOMMANDS, type SpecSubcommand, type WorkflowPaths, type WorkflowStep } from "./types.js";
|
|
20
|
+
import {
|
|
21
|
+
buildWorkflowPaths,
|
|
22
|
+
findRepoRoot,
|
|
23
|
+
getLatestFeatureDir,
|
|
24
|
+
listFeatureDirs,
|
|
25
|
+
prepareFeatureWorkspace,
|
|
26
|
+
resolveFeatureFromBranch,
|
|
27
|
+
} from "./workspace.js";
|
|
28
|
+
|
|
29
|
+
const REPORT_MESSAGE_TYPE = "pi-spec-report";
|
|
30
|
+
const PROMPT_OPTIONAL_STEPS = new Set<WorkflowStep>(["clarify", "tasks", "analyze", "implement"]);
|
|
31
|
+
|
|
32
|
+
function tokenize(input: string): { subcommand: SpecSubcommand | null; remainder: string } {
|
|
33
|
+
const trimmed = input.trim();
|
|
34
|
+
if (!trimmed) {
|
|
35
|
+
return { subcommand: "status", remainder: "" };
|
|
36
|
+
}
|
|
37
|
+
const [raw, ...rest] = trimmed.split(/\s+/);
|
|
38
|
+
const normalized = raw.toLowerCase();
|
|
39
|
+
if ((SPEC_SUBCOMMANDS as readonly string[]).includes(normalized)) {
|
|
40
|
+
return { subcommand: normalized as SpecSubcommand, remainder: rest.join(" ").trim() };
|
|
41
|
+
}
|
|
42
|
+
return { subcommand: null, remainder: trimmed };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function sendReport(pi: ExtensionAPI, content: string): void {
|
|
46
|
+
pi.sendMessage({ customType: REPORT_MESSAGE_TYPE, content, display: true });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isWorkflowStep(subcommand: SpecSubcommand): subcommand is WorkflowStep {
|
|
50
|
+
return ["constitution", "specify", "clarify", "checklist", "plan", "tasks", "analyze", "implement"].includes(
|
|
51
|
+
subcommand,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function promptForMissingInput(
|
|
56
|
+
ctx: ExtensionCommandContext,
|
|
57
|
+
title: string,
|
|
58
|
+
placeholder: string,
|
|
59
|
+
): Promise<string | undefined> {
|
|
60
|
+
if (!ctx.hasUI) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
if (typeof ctx.ui.editor === "function") {
|
|
64
|
+
const response = await ctx.ui.editor(title, placeholder);
|
|
65
|
+
return response?.trim() || undefined;
|
|
66
|
+
}
|
|
67
|
+
if (typeof ctx.ui.input === "function") {
|
|
68
|
+
const response = await ctx.ui.input(title, placeholder);
|
|
69
|
+
return response?.trim() || undefined;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function stepNeedsRequiredInput(step: WorkflowStep): boolean {
|
|
75
|
+
return !PROMPT_OPTIONAL_STEPS.has(step);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function resolveActiveFeatureName(
|
|
79
|
+
ctx: ExtensionCommandContext,
|
|
80
|
+
repoRoot: string,
|
|
81
|
+
currentBranch: string,
|
|
82
|
+
): Promise<string | undefined> {
|
|
83
|
+
const featureFromBranch = resolveFeatureFromBranch(repoRoot, currentBranch);
|
|
84
|
+
if (featureFromBranch) {
|
|
85
|
+
return featureFromBranch;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const features = listFeatureDirs(repoRoot);
|
|
89
|
+
if (features.length === 0) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
if (features.length === 1) {
|
|
93
|
+
return features[0];
|
|
94
|
+
}
|
|
95
|
+
if (!ctx.hasUI || typeof ctx.ui.select !== "function") {
|
|
96
|
+
return getLatestFeatureDir(repoRoot);
|
|
97
|
+
}
|
|
98
|
+
const selected = await ctx.ui.select("Select active spec feature", features);
|
|
99
|
+
return selected || undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function resolveFeaturePaths(
|
|
103
|
+
ctx: ExtensionCommandContext,
|
|
104
|
+
repoRoot: string,
|
|
105
|
+
currentBranch: string,
|
|
106
|
+
): Promise<WorkflowPaths | undefined> {
|
|
107
|
+
const featureName = await resolveActiveFeatureName(ctx, repoRoot, currentBranch);
|
|
108
|
+
if (!featureName) {
|
|
109
|
+
ctx.ui.notify("No active feature found. Run /spec specify <feature description> first.", "warning");
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return buildWorkflowPaths(repoRoot, featureName);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function queueWorkflow(
|
|
116
|
+
pi: ExtensionAPI,
|
|
117
|
+
step: WorkflowStep,
|
|
118
|
+
currentBranch: string,
|
|
119
|
+
paths: WorkflowPaths,
|
|
120
|
+
input: string,
|
|
121
|
+
): void {
|
|
122
|
+
const prompt = buildWorkflowPrompt({
|
|
123
|
+
step,
|
|
124
|
+
input,
|
|
125
|
+
paths,
|
|
126
|
+
currentBranch,
|
|
127
|
+
workflowTemplatePath: getWorkflowTemplatePath(paths, step),
|
|
128
|
+
stepNotes: getStepNotes(step),
|
|
129
|
+
checklists: step === "implement" ? summarizeChecklists(paths.checklistsDir) : undefined,
|
|
130
|
+
});
|
|
131
|
+
pi.sendUserMessage(prompt);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function collectStepInput(ctx: ExtensionCommandContext, step: WorkflowStep, existing: string): Promise<string> {
|
|
135
|
+
if (existing.trim() || !stepNeedsRequiredInput(step)) {
|
|
136
|
+
return existing.trim();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const titleByStep: Record<WorkflowStep, string> = {
|
|
140
|
+
constitution: "Describe the constitution principles",
|
|
141
|
+
specify: "Describe the feature to specify",
|
|
142
|
+
clarify: "Optional clarification focus",
|
|
143
|
+
checklist: "Optional checklist focus or domain",
|
|
144
|
+
plan: "Describe the technical context",
|
|
145
|
+
tasks: "Optional task-generation context",
|
|
146
|
+
analyze: "Optional analysis focus",
|
|
147
|
+
implement: "Optional implementation focus",
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
(await promptForMissingInput(ctx, titleByStep[step], "Write the details for this /spec step here")) ?? ""
|
|
152
|
+
).trim();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function makeEnv(ctx: ExtensionCommandContext, git = createGitClient()) {
|
|
156
|
+
const { repoRoot, hasGit } = findRepoRoot(ctx.cwd, git);
|
|
157
|
+
const currentBranch = git.getCurrentBranch(repoRoot) ?? process.env.SPECIFY_FEATURE ?? "main";
|
|
158
|
+
const basePaths = buildWorkflowPaths(repoRoot);
|
|
159
|
+
return { git, repoRoot, hasGit, currentBranch, basePaths };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function handleInit(pi: ExtensionAPI, repoRoot: string, created: string[]): void {
|
|
163
|
+
sendReport(
|
|
164
|
+
pi,
|
|
165
|
+
[
|
|
166
|
+
"# /spec init",
|
|
167
|
+
"",
|
|
168
|
+
`- Repository root: ${repoRoot}`,
|
|
169
|
+
formatCreatedFiles(created),
|
|
170
|
+
"",
|
|
171
|
+
"Next: `/spec constitution <principles>` or `/spec specify <feature description>`.",
|
|
172
|
+
].join("\n"),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function handleStatus(
|
|
177
|
+
pi: ExtensionAPI,
|
|
178
|
+
ctx: ExtensionCommandContext,
|
|
179
|
+
repoRoot: string,
|
|
180
|
+
currentBranch: string,
|
|
181
|
+
): Promise<void> {
|
|
182
|
+
const activeFeature = await resolveActiveFeatureName(ctx, repoRoot, currentBranch);
|
|
183
|
+
sendReport(
|
|
184
|
+
pi,
|
|
185
|
+
formatWorkflowStatus(
|
|
186
|
+
buildWorkflowStatus({
|
|
187
|
+
repoRoot,
|
|
188
|
+
currentBranch,
|
|
189
|
+
paths: buildWorkflowPaths(repoRoot, activeFeature),
|
|
190
|
+
activeFeature,
|
|
191
|
+
}),
|
|
192
|
+
),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function handleNext(
|
|
197
|
+
pi: ExtensionAPI,
|
|
198
|
+
ctx: ExtensionCommandContext,
|
|
199
|
+
repoRoot: string,
|
|
200
|
+
currentBranch: string,
|
|
201
|
+
): Promise<void> {
|
|
202
|
+
const activeFeature = await resolveActiveFeatureName(ctx, repoRoot, currentBranch);
|
|
203
|
+
const status = buildWorkflowStatus({
|
|
204
|
+
repoRoot,
|
|
205
|
+
currentBranch,
|
|
206
|
+
paths: buildWorkflowPaths(repoRoot, activeFeature),
|
|
207
|
+
activeFeature,
|
|
208
|
+
});
|
|
209
|
+
sendReport(pi, `# Next /spec steps\n\n${status.nextSteps.map((step) => `- ${step}`).join("\n")}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function handleSpecify(
|
|
213
|
+
pi: ExtensionAPI,
|
|
214
|
+
ctx: ExtensionCommandContext,
|
|
215
|
+
env: ReturnType<typeof makeEnv>,
|
|
216
|
+
input: string,
|
|
217
|
+
): void {
|
|
218
|
+
if (!input) {
|
|
219
|
+
ctx.ui.notify("/spec specify requires a feature description.", "warning");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
const prepared = prepareFeatureWorkspace({
|
|
225
|
+
repoRoot: env.repoRoot,
|
|
226
|
+
description: input,
|
|
227
|
+
git: env.git,
|
|
228
|
+
currentBranch: env.currentBranch,
|
|
229
|
+
hasGit: env.hasGit,
|
|
230
|
+
});
|
|
231
|
+
const paths = buildWorkflowPaths(env.repoRoot, prepared.branchName);
|
|
232
|
+
ensureWorkflowScaffold(paths);
|
|
233
|
+
ensureFeatureArtifacts(paths);
|
|
234
|
+
queueWorkflow(pi, "specify", prepared.branchName, paths, input);
|
|
235
|
+
sendReport(
|
|
236
|
+
pi,
|
|
237
|
+
[
|
|
238
|
+
"# /spec specify",
|
|
239
|
+
"",
|
|
240
|
+
`- Feature branch: ${prepared.branchName}`,
|
|
241
|
+
`- Feature number: ${prepared.featureNumber}`,
|
|
242
|
+
`- Feature directory: ${prepared.featureDir}`,
|
|
243
|
+
`- Spec file: ${prepared.specFile}`,
|
|
244
|
+
"",
|
|
245
|
+
"Queued the native specification workflow as a user message.",
|
|
246
|
+
].join("\n"),
|
|
247
|
+
);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
ctx.ui.notify(
|
|
250
|
+
`Failed to prepare feature workspace: ${error instanceof Error ? error.message : String(error)}`,
|
|
251
|
+
"error",
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function confirmChecklistOverride(ctx: ExtensionCommandContext, paths: WorkflowPaths): Promise<boolean> {
|
|
257
|
+
const checklists = summarizeChecklists(paths.checklistsDir);
|
|
258
|
+
if (
|
|
259
|
+
!(checklists.some((checklist) => checklist.incomplete > 0) && ctx.hasUI && typeof ctx.ui.confirm === "function")
|
|
260
|
+
) {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const proceed = await ctx.ui.confirm(
|
|
265
|
+
"Incomplete spec checklists",
|
|
266
|
+
`${checklists.map((checklist) => `${checklist.name}: ${checklist.incomplete} incomplete item(s)`).join("\n")}
|
|
267
|
+
|
|
268
|
+
Proceed with implementation anyway?`,
|
|
269
|
+
);
|
|
270
|
+
if (!proceed) {
|
|
271
|
+
ctx.ui.notify("Implementation cancelled until the checklist review is complete.", "info");
|
|
272
|
+
}
|
|
273
|
+
return proceed;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async function handleWorkflowStep(
|
|
277
|
+
pi: ExtensionAPI,
|
|
278
|
+
ctx: ExtensionCommandContext,
|
|
279
|
+
env: ReturnType<typeof makeEnv>,
|
|
280
|
+
step: WorkflowStep,
|
|
281
|
+
input: string,
|
|
282
|
+
): Promise<void> {
|
|
283
|
+
if (step === "specify") {
|
|
284
|
+
handleSpecify(pi, ctx, env, input);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const featurePaths =
|
|
289
|
+
step === "constitution"
|
|
290
|
+
? buildWorkflowPaths(env.repoRoot, await resolveActiveFeatureName(ctx, env.repoRoot, env.currentBranch))
|
|
291
|
+
: await resolveFeaturePaths(ctx, env.repoRoot, env.currentBranch);
|
|
292
|
+
ensureWorkflowScaffold(featurePaths ?? env.basePaths);
|
|
293
|
+
if (!featurePaths) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (step === "plan") {
|
|
298
|
+
ensurePlanArtifact(featurePaths);
|
|
299
|
+
}
|
|
300
|
+
if (step === "implement" && !(await confirmChecklistOverride(ctx, featurePaths))) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
queueWorkflow(pi, step, env.currentBranch, featurePaths, input);
|
|
305
|
+
ctx.ui.notify(`Queued /spec ${step} workflow.`, "info");
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export default function specExtension(pi: ExtensionAPI) {
|
|
309
|
+
pi.registerMessageRenderer(REPORT_MESSAGE_TYPE, (message, _options, theme) => {
|
|
310
|
+
const text = `${theme.fg("accent", theme.bold("spec"))}\n\n${String(message.content ?? "")}`;
|
|
311
|
+
return new Text(text, 0, 0);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
pi.registerCommand("spec", {
|
|
315
|
+
description:
|
|
316
|
+
"Native spec-kit workflow for pi (/spec init|constitution|specify|clarify|checklist|plan|tasks|analyze|implement)",
|
|
317
|
+
getArgumentCompletions(prefix) {
|
|
318
|
+
const trimmed = prefix.trimStart();
|
|
319
|
+
if (trimmed.includes(" ")) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
const values = SPEC_SUBCOMMANDS.filter((command) => command.startsWith(trimmed)).map((command) => ({
|
|
323
|
+
value: command,
|
|
324
|
+
label: command,
|
|
325
|
+
}));
|
|
326
|
+
return values.length > 0 ? values : null;
|
|
327
|
+
},
|
|
328
|
+
handler: async (rawArgs, ctx) => {
|
|
329
|
+
const { subcommand, remainder } = tokenize(rawArgs);
|
|
330
|
+
if (!subcommand) {
|
|
331
|
+
ctx.ui.notify(`Unknown /spec subcommand: ${rawArgs.trim()}`, "warning");
|
|
332
|
+
sendReport(pi, formatHelpReport());
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const env = makeEnv(ctx);
|
|
337
|
+
if (subcommand === "init") {
|
|
338
|
+
handleInit(pi, env.repoRoot, ensureWorkflowScaffold(env.basePaths));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (subcommand === "help") {
|
|
342
|
+
sendReport(pi, formatHelpReport());
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (subcommand === "list") {
|
|
346
|
+
sendReport(pi, formatFeatureList(env.repoRoot));
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (subcommand === "status") {
|
|
350
|
+
await handleStatus(pi, ctx, env.repoRoot, env.currentBranch);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (subcommand === "next") {
|
|
354
|
+
await handleNext(pi, ctx, env.repoRoot, env.currentBranch);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (!isWorkflowStep(subcommand)) {
|
|
358
|
+
sendReport(pi, formatHelpReport());
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const input = await collectStepInput(ctx, subcommand, remainder);
|
|
363
|
+
await handleWorkflowStep(pi, ctx, env, subcommand, input);
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
}
|