@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ifiok Jr.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,528 @@
1
+ # @ifi/pi-spec
2
+
3
+ Native spec-driven workflow for pi, inspired by [github/spec-kit](https://github.com/github/spec-kit).
4
+
5
+ `@ifi/pi-spec` is a **pi extension package**, not a shell wrapper and not a general-purpose JavaScript
6
+ library. Its job is to bring the core spec-kit workflow into pi as a native TypeScript experience:
7
+
8
+ - one `/spec` command instead of a pile of separate commands and shell entrypoints
9
+ - deterministic local scaffolding under `.specify/`
10
+ - deterministic feature artifacts under `specs/###-feature-name/`
11
+ - native git/repo detection, branch naming, and feature numbering in TypeScript
12
+ - prompt handoff back into pi via `pi.sendUserMessage(...)`
13
+ - project-owned templates that can be customized locally after initialization
14
+
15
+ The package deliberately keeps the **mental model** of spec-kit, but replaces its shell orchestration with
16
+ normal pi tools and normal pi conversations.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ pi install npm:@ifi/pi-spec
22
+ ```
23
+
24
+ Or install the full oh-pi bundle:
25
+
26
+ ```bash
27
+ npx @ifi/oh-pi
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Purpose
33
+
34
+ The purpose of this package is to make **spec-first development** feel native inside pi.
35
+
36
+ In practice that means:
37
+
38
+ 1. **Requirements come first**
39
+ - You write or refine a spec before planning and implementation.
40
+ 2. **The workflow is explicit**
41
+ - `/spec specify`, `/spec plan`, `/spec tasks`, `/spec implement` are separate steps with clear outputs.
42
+ 3. **The repository owns the workflow state**
43
+ - Important artifacts live in normal files in your repo, not in hidden runtime state.
44
+ 4. **Pi stays in control of the work**
45
+ - Instead of calling external shell scripts, pi reads templates, edits files, runs tests, and explains what it did.
46
+ 5. **Teams can customize locally**
47
+ - The package seeds `.specify/templates/`, then gets out of the way.
48
+
49
+ ## Goals
50
+
51
+ The design goals for `@ifi/pi-spec` are:
52
+
53
+ - **Native pi UX** — use pi's existing tools, prompting, and slash-command system
54
+ - **Spec-kit compatibility of concepts** — keep the same major phases and familiar artifact layout
55
+ - **Type-safe implementation** — perform repo detection, path calculation, and branch generation in TypeScript
56
+ - **Idempotent scaffolding** — create missing files without constantly overwriting local customizations
57
+ - **Low surprise** — make state visible through files and `/spec status`
58
+ - **Good defaults, flexible templates** — ship usable templates while letting projects evolve them
59
+
60
+ ## Non-goals
61
+
62
+ This package intentionally does **not** try to be:
63
+
64
+ - a 1:1 shell-script port of upstream spec-kit internals
65
+ - a hidden autonomous pipeline that silently runs every step for you
66
+ - a generic npm library with a stable programmatic JS API
67
+ - a hook runner that auto-executes `.specify/extensions.yml` scripts behind your back
68
+
69
+ The stable API surface is the **slash command** and the **on-disk workflow structure**.
70
+
71
+ ---
72
+
73
+ ## The API I chose
74
+
75
+ ### Public API surface
76
+
77
+ The package has one primary public entrypoint:
78
+
79
+ ```text
80
+ /spec [subcommand] [freeform input]
81
+ ```
82
+
83
+ Supported subcommands:
84
+
85
+ ```text
86
+ /spec # same as /spec status
87
+ /spec help
88
+ /spec status
89
+ /spec init
90
+ /spec constitution [principles]
91
+ /spec specify <feature description>
92
+ /spec clarify [focus]
93
+ /spec checklist [domain]
94
+ /spec plan [technical context]
95
+ /spec tasks [context]
96
+ /spec analyze [focus]
97
+ /spec implement [focus]
98
+ /spec list
99
+ /spec next
100
+ ```
101
+
102
+ That is the **intentional public API**.
103
+
104
+ There is **not** a separate public JS/TS library API right now. Internal modules like
105
+ `workspace.ts`, `scaffold.ts`, or `prompts.ts` are implementation details for contributors, not a versioned
106
+ integration surface for consumers.
107
+
108
+ ### Why one `/spec` command is the right API
109
+
110
+ I chose **one command with subcommands** instead of many top-level commands like `/specify`, `/clarify`,
111
+ `/plan`, `/tasks`, etc. for a few reasons:
112
+
113
+ 1. **It matches the workflow mental model**
114
+ - All of these actions are part of one lifecycle.
115
+ - Grouping them under `/spec` makes that lifecycle obvious.
116
+
117
+ 2. **It avoids namespace clutter in pi**
118
+ - A spec workflow can easily consume half a dozen top-level slash commands.
119
+ - `/spec ...` keeps the command surface organized.
120
+
121
+ 3. **It is easier to discover**
122
+ - `/spec help`, `/spec status`, and `/spec next` make the system self-explanatory.
123
+ - Users only need to remember one root command.
124
+
125
+ 4. **It preserves upstream familiarity without copying the shell UX**
126
+ - The step names still map cleanly to spec-kit concepts.
127
+ - But the runtime behavior is pi-native instead of script-native.
128
+
129
+ 5. **It centralizes context resolution**
130
+ - Repo detection, active-feature resolution, scaffold creation, and prompt generation all happen in one place.
131
+ - That reduces edge cases and keeps behavior consistent.
132
+
133
+ ### Why the API is file-centric
134
+
135
+ The second part of the API is the **filesystem contract**:
136
+
137
+ - `.specify/` for reusable workflow state and templates
138
+ - `specs/###-feature-name/` for per-feature artifacts
139
+
140
+ I think this is the correct design because it keeps the workflow:
141
+
142
+ - reviewable in git
143
+ - easy to inspect manually
144
+ - easy to customize
145
+ - resilient across agent restarts
146
+ - tool-agnostic at the file layer
147
+
148
+ In other words, the source of truth is not some in-memory session object; it is the repo itself.
149
+
150
+ ---
151
+
152
+ ## Exact command behavior
153
+
154
+ Below is the practical contract for each subcommand.
155
+
156
+ | Command | Purpose | Model handoff | Filesystem side effects |
157
+ | --- | --- | --- | --- |
158
+ | `/spec` or `/spec status` | Show current workflow state | No | None |
159
+ | `/spec help` | Show available commands and guidance | No | None |
160
+ | `/spec init` | Create the base workflow scaffold | No | Creates missing `.specify/` files |
161
+ | `/spec constitution [principles]` | Create or revise the project constitution | Yes | Ensures base scaffold exists |
162
+ | `/spec specify <feature description>` | Create the next numbered feature workspace | Yes | Ensures scaffold, creates `specs/###-.../`, may create/switch git branch |
163
+ | `/spec clarify [focus]` | Ask and resolve high-impact ambiguities in the active spec | Yes | Ensures scaffold exists |
164
+ | `/spec checklist [domain]` | Generate or refine requirement-quality checklists | Yes | Ensures scaffold exists |
165
+ | `/spec plan [technical context]` | Build the implementation plan and design artifacts | Yes | Ensures scaffold, creates `plan.md` if missing |
166
+ | `/spec tasks [context]` | Generate an executable `tasks.md` | Yes | Ensures scaffold exists |
167
+ | `/spec analyze [focus]` | Run a read-only consistency review | Yes | Ensures scaffold exists |
168
+ | `/spec implement [focus]` | Execute tasks and update completion state | Yes | Ensures scaffold exists; prompts if checklists are incomplete |
169
+ | `/spec list` | List known feature directories | No | None |
170
+ | `/spec next` | Show the next recommended step | No | None |
171
+
172
+ ### Input rules
173
+
174
+ The command accepts **freeform text** after the subcommand.
175
+
176
+ Examples:
177
+
178
+ ```bash
179
+ /spec constitution Security-first, testable, low-complexity defaults
180
+ /spec specify Add usage-based billing alerts for workspace admins
181
+ /spec plan Use TypeScript, Vitest, and direct pi tool access
182
+ /spec analyze Focus on contradictions between spec.md and tasks.md
183
+ /spec implement Start with the MVP story and update tasks as you go
184
+ ```
185
+
186
+ Notes:
187
+
188
+ - `/spec specify` effectively requires a real feature description.
189
+ - Other workflow steps accept freeform guidance and can also run with minimal or no extra guidance.
190
+ - When pi has UI input capabilities available, the extension can prompt for missing input instead of failing immediately.
191
+
192
+ ### Active feature resolution
193
+
194
+ For steps that operate on a feature (`clarify`, `checklist`, `plan`, `tasks`, `analyze`, `implement`), the
195
+ extension resolves the active feature using this order:
196
+
197
+ 1. current branch name if it matches a numbered feature directory
198
+ 2. a single known feature directory, if there is only one
199
+ 3. a UI selection prompt, if multiple features exist and the UI supports selection
200
+ 4. otherwise the latest numbered feature directory
201
+
202
+ This keeps the common path simple while still working in multi-feature repos.
203
+
204
+ ---
205
+
206
+ ## Files and directories created by the package
207
+
208
+ ### Base workflow scaffold
209
+
210
+ `/spec init` creates the base workflow scaffold if it is missing.
211
+
212
+ ```text
213
+ .specify/
214
+ ├── README.md
215
+ ├── extensions.yml
216
+ ├── memory/
217
+ │ ├── constitution.md
218
+ │ └── pi-agent.md
219
+ └── templates/
220
+ ├── agent-file-template.md
221
+ ├── checklist-template.md
222
+ ├── constitution-template.md
223
+ ├── plan-template.md
224
+ ├── spec-template.md
225
+ ├── tasks-template.md
226
+ └── commands/
227
+ ├── analyze.md
228
+ ├── checklist.md
229
+ ├── clarify.md
230
+ ├── constitution.md
231
+ ├── implement.md
232
+ ├── plan.md
233
+ ├── specify.md
234
+ └── tasks.md
235
+ ```
236
+
237
+ What these are for:
238
+
239
+ - `.specify/README.md` — local explanation of the workflow as installed in this repo
240
+ - `.specify/extensions.yml` — compatibility/config surface; pi inspects it manually when relevant rather than auto-running hooks
241
+ - `.specify/memory/constitution.md` — canonical governance/principles file
242
+ - `.specify/memory/pi-agent.md` — pi-native replacement for agent-context update scripts
243
+ - `.specify/templates/` — local, editable workflow templates copied from the packaged defaults
244
+
245
+ ### Per-feature workspace
246
+
247
+ `/spec specify <description>` creates a numbered feature workspace:
248
+
249
+ ```text
250
+ specs/
251
+ └── 001-my-feature/
252
+ ├── spec.md
253
+ ├── checklists/
254
+ ├── plan.md
255
+ ├── research.md
256
+ ├── data-model.md
257
+ ├── quickstart.md
258
+ ├── contracts/
259
+ └── tasks.md
260
+ ```
261
+
262
+ Not every file exists immediately.
263
+
264
+ Current behavior:
265
+
266
+ - `spec.md` is scaffolded during `/spec specify`
267
+ - `plan.md` is scaffolded during `/spec plan` if it is missing
268
+ - other files are referenced by the workflow and created as the step needs them
269
+
270
+ ### Idempotency rules
271
+
272
+ Scaffolding is intentionally conservative:
273
+
274
+ - missing files are created
275
+ - existing files are left alone
276
+ - bundled templates are copied into the repo once, then become the repo's copies to edit
277
+
278
+ That is important because the package should seed a workflow, not keep fighting your local customization.
279
+
280
+ ---
281
+
282
+ ## How to use it in practice
283
+
284
+ ## 1) Initialize the workflow
285
+
286
+ ```bash
287
+ /spec init
288
+ ```
289
+
290
+ Use this when introducing the workflow to a repo for the first time.
291
+
292
+ What happens:
293
+
294
+ - `.specify/` is created if missing
295
+ - default templates are copied in
296
+ - constitution and pi-agent memory files are created if missing
297
+ - a report is rendered in pi explaining what was created
298
+
299
+ ## 2) Define the project's constitution
300
+
301
+ ```bash
302
+ /spec constitution Security-first, testable, backwards-compatible changes by default
303
+ ```
304
+
305
+ Use this to establish the rules the workflow should follow.
306
+
307
+ Typical outcomes:
308
+
309
+ - the constitution file is created or updated in `.specify/memory/constitution.md`
310
+ - related templates may be aligned with those rules
311
+ - future workflow steps can refer back to the same governance file
312
+
313
+ ## 3) Create a feature spec
314
+
315
+ ```bash
316
+ /spec specify Add SSO login for enterprise tenants
317
+ ```
318
+
319
+ What happens:
320
+
321
+ - the next feature number is computed
322
+ - a branch name is generated from the description
323
+ - `specs/###-feature-name/` is created
324
+ - `spec.md` is scaffolded
325
+ - if git is available and you are not already on that feature branch, the extension creates and switches to it
326
+ - pi receives a prompt instructing it to follow the local `specify` template using the prepared paths
327
+
328
+ This is the key step that turns a vague idea into a concrete feature workspace.
329
+
330
+ ## 4) Clarify open questions
331
+
332
+ ```bash
333
+ /spec clarify
334
+ ```
335
+
336
+ or
337
+
338
+ ```bash
339
+ /spec clarify Focus on tenant boundaries, auth edge cases, and failure states
340
+ ```
341
+
342
+ This step is meant to remove the highest-impact ambiguities before planning.
343
+
344
+ ## 5) Generate a requirement-quality checklist
345
+
346
+ ```bash
347
+ /spec checklist Authentication quality gates
348
+ ```
349
+
350
+ This is not supposed to generate implementation TODOs. It is meant to verify that the spec is precise,
351
+ complete, and testable.
352
+
353
+ ## 6) Build the implementation plan
354
+
355
+ ```bash
356
+ /spec plan Use TypeScript, Vitest, and existing auth services; avoid new infrastructure
357
+ ```
358
+
359
+ What happens:
360
+
361
+ - `plan.md` is created if missing
362
+ - pi is instructed to use the local `plan` workflow template
363
+ - `pi-agent.md` is treated as the pi-native context artifact instead of shell-generated agent files
364
+
365
+ ## 7) Generate tasks
366
+
367
+ ```bash
368
+ /spec tasks
369
+ ```
370
+
371
+ or
372
+
373
+ ```bash
374
+ /spec tasks Prioritize the MVP path and keep tasks grouped by user story
375
+ ```
376
+
377
+ This step should produce a `tasks.md` with a strict checkbox-oriented execution plan.
378
+
379
+ ## 8) Analyze for contradictions
380
+
381
+ ```bash
382
+ /spec analyze
383
+ ```
384
+
385
+ This step is intentionally read-only. It is there to catch inconsistencies between the spec, plan,
386
+ checklists, and tasks before coding begins.
387
+
388
+ ## 9) Implement
389
+
390
+ ```bash
391
+ /spec implement
392
+ ```
393
+
394
+ or
395
+
396
+ ```bash
397
+ /spec implement Start with story 1, update tasks.md as each item completes
398
+ ```
399
+
400
+ Behavior worth knowing:
401
+
402
+ - checklist files are summarized before implementation
403
+ - if incomplete checklist items exist and the UI supports confirmation, pi asks whether you want to continue
404
+ - the implementation prompt reminds pi to mark completed tasks as `[x]`
405
+
406
+ ## 10) Inspect progress any time
407
+
408
+ ```bash
409
+ /spec status
410
+ /spec next
411
+ /spec list
412
+ ```
413
+
414
+ Use these when you want visibility rather than action:
415
+
416
+ - `/spec status` shows artifact presence, checklist summaries, current branch, and known features
417
+ - `/spec next` recommends the next workflow command
418
+ - `/spec list` lists all numbered feature directories in `specs/`
419
+
420
+ ---
421
+
422
+ ## Example end-to-end session
423
+
424
+ ```bash
425
+ /spec init
426
+ /spec constitution Security-first, testable, low-complexity defaults
427
+ /spec specify Build a native spec workflow package for pi
428
+ /spec clarify
429
+ /spec checklist Requirements quality for the initial MVP
430
+ /spec plan Use TypeScript, Vitest, and direct pi tool access
431
+ /spec tasks Group work by independently testable user stories
432
+ /spec analyze
433
+ /spec implement
434
+ ```
435
+
436
+ That sequence is the intended happy path.
437
+
438
+ ---
439
+
440
+ ## Native behavior vs upstream spec-kit
441
+
442
+ This package is **inspired by** upstream spec-kit, but the runtime model is different on purpose.
443
+
444
+ ### What is preserved
445
+
446
+ - the phase names and overall lifecycle
447
+ - the numbered feature directory convention
448
+ - the use of templates to guide each phase
449
+ - the idea of constitution/spec/plan/tasks/checklist artifacts
450
+
451
+ ### What changed
452
+
453
+ - shell scripts are replaced with TypeScript helpers
454
+ - repo/branch/path preparation happens inside the extension
455
+ - workflow execution is handed back to pi as a normal prompt-driven task
456
+ - `.specify/memory/pi-agent.md` replaces agent-update shell behavior
457
+ - `.specify/extensions.yml` is preserved as a file, but not auto-executed as hooks
458
+
459
+ ### Why this is the correct adaptation for pi
460
+
461
+ Because pi already has:
462
+
463
+ - tools for file IO
464
+ - tools for running validation commands
465
+ - a conversation model for asking clarifying questions
466
+ - slash commands for entering workflows
467
+
468
+ Using shell wrappers would add indirection without adding capability. Native TypeScript makes the workflow:
469
+
470
+ - easier to test
471
+ - easier to reason about
472
+ - more portable across environments
473
+ - less dependent on shell behavior differences
474
+ - more aligned with how pi already works
475
+
476
+ ---
477
+
478
+ ## Internal implementation overview
479
+
480
+ These modules are useful for contributors, but they are **not** the promised external API.
481
+
482
+ - `extension/index.ts` — command registration, dispatch, prompting, and model handoff
483
+ - `extension/workspace.ts` — repo detection, feature numbering, branch slugging, and path building
484
+ - `extension/scaffold.ts` — idempotent scaffold/template creation
485
+ - `extension/prompts.ts` — native workflow prompt builder and step-specific notes
486
+ - `extension/status.ts` — status reporting and checklist summarization
487
+ - `extension/git.ts` — minimal git adapter used by the workflow
488
+ - `extension/assets/templates/` — vendored workflow and file templates adapted from spec-kit
489
+
490
+ I split the implementation this way because the workflow naturally has four concerns:
491
+
492
+ 1. command API and UX
493
+ 2. filesystem/workspace logic
494
+ 3. prompt-generation logic
495
+ 4. status/reporting logic
496
+
497
+ Keeping those concerns separate made the package easier to test thoroughly.
498
+
499
+ ---
500
+
501
+ ## Customization
502
+
503
+ After initialization, you can customize the workflow by editing files in your repo:
504
+
505
+ - `.specify/memory/constitution.md`
506
+ - `.specify/memory/pi-agent.md`
507
+ - `.specify/templates/*.md`
508
+ - `.specify/templates/commands/*.md`
509
+
510
+ This is another core design choice: the workflow should become **your repo's workflow**, not remain locked
511
+ inside the npm package.
512
+
513
+ ---
514
+
515
+ ## Summary
516
+
517
+ If I had to describe the package in one sentence:
518
+
519
+ > `@ifi/pi-spec` is a native pi implementation of a spec-first workflow whose public API is one `/spec`
520
+ > command plus a deterministic `.specify/` and `specs/###-feature-name/` file layout.
521
+
522
+ I think that is the correct API because it is:
523
+
524
+ - small enough to remember
525
+ - explicit enough to inspect
526
+ - compatible enough to feel familiar to spec-kit users
527
+ - native enough to feel right inside pi
528
+ - testable enough to maintain over time
@@ -0,0 +1,28 @@
1
+ # [PROJECT NAME] Development Guidelines
2
+
3
+ Auto-generated from all feature plans. Last updated: [DATE]
4
+
5
+ ## Active Technologies
6
+
7
+ [EXTRACTED FROM ALL PLAN.MD FILES]
8
+
9
+ ## Project Structure
10
+
11
+ ```text
12
+ [ACTUAL STRUCTURE FROM PLANS]
13
+ ```
14
+
15
+ ## Commands
16
+
17
+ [ONLY COMMANDS FOR ACTIVE TECHNOLOGIES]
18
+
19
+ ## Code Style
20
+
21
+ [LANGUAGE-SPECIFIC, ONLY FOR LANGUAGES IN USE]
22
+
23
+ ## Recent Changes
24
+
25
+ [LAST 3 FEATURES AND WHAT THEY ADDED]
26
+
27
+ <!-- MANUAL ADDITIONS START -->
28
+ <!-- MANUAL ADDITIONS END -->
@@ -0,0 +1,40 @@
1
+ # [CHECKLIST TYPE] Checklist: [FEATURE NAME]
2
+
3
+ **Purpose**: [Brief description of what this checklist covers]
4
+ **Created**: [DATE]
5
+ **Feature**: [Link to spec.md or relevant documentation]
6
+
7
+ **Note**: This checklist is generated by the `/speckit.checklist` command based on feature context and requirements.
8
+
9
+ <!--
10
+ ============================================================================
11
+ IMPORTANT: The checklist items below are SAMPLE ITEMS for illustration only.
12
+
13
+ The /speckit.checklist command MUST replace these with actual items based on:
14
+ - User's specific checklist request
15
+ - Feature requirements from spec.md
16
+ - Technical context from plan.md
17
+ - Implementation details from tasks.md
18
+
19
+ DO NOT keep these sample items in the generated checklist file.
20
+ ============================================================================
21
+ -->
22
+
23
+ ## [Category 1]
24
+
25
+ - [ ] CHK001 First checklist item with clear action
26
+ - [ ] CHK002 Second checklist item
27
+ - [ ] CHK003 Third checklist item
28
+
29
+ ## [Category 2]
30
+
31
+ - [ ] CHK004 Another category item
32
+ - [ ] CHK005 Item with specific criteria
33
+ - [ ] CHK006 Final item in this category
34
+
35
+ ## Notes
36
+
37
+ - Check items off as completed: `[x]`
38
+ - Add comments or findings inline
39
+ - Link to relevant resources or documentation
40
+ - Items are numbered sequentially for easy reference