specdx 0.2.0-alpha.1 → 0.2.0-alpha.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.
@@ -1,244 +0,0 @@
1
- ---
2
- name: sdx:start-task
3
- description: Load project spec context for a coding task using sdx pack
4
- ---
5
-
6
- # sdx:start-task
7
-
8
- You are about to begin a coding task within a project that uses **SDX (Spec Developer Experience)** to manage its specifications. SDX specs are structured markdown documents (RFCs, ADRs, runbooks, designs, etc.) that capture project decisions, architecture, and conventions.
9
-
10
- Your job is to load relevant spec context before starting work, so you have the full picture of what the project expects.
11
-
12
- ## Step 1: Pack the context
13
-
14
- Run the following command, replacing `<task-description>` with the user's task description:
15
-
16
- ```bash
17
- sdx pack --task "<task-description>" --format xml
18
- ```
19
-
20
- This will:
21
- - Scan the project's `specs/` directory (or configured spec paths)
22
- - Identify specs relevant to the task description using keyword matching and dependency analysis
23
- - Compress stale or resolved specs to save context tokens
24
- - Output a structured XML document with all relevant spec content
25
-
26
- ### Alternative formats
27
-
28
- If XML is too verbose for the model's context window, you can try:
29
-
30
- ```bash
31
- sdx pack --task "<task-description>" --format markdown
32
- ```
33
-
34
- Or for a minimal structured output:
35
-
36
- ```bash
37
- sdx pack --task "<task-description>" --format json
38
- ```
39
-
40
- ### Limiting token budget
41
-
42
- If the context is too large, you can set a token budget:
43
-
44
- ```bash
45
- sdx pack --task "<task-description>" --format xml --budget 8000
46
- ```
47
-
48
- ## Step 2: Read and internalize the packed context
49
-
50
- After running `sdx pack`, read the output carefully. The packed context includes:
51
-
52
- ### Spec metadata
53
- Each spec entry contains:
54
- - **id**: Unique identifier (e.g., `rfc-001`, `adr-012`)
55
- - **type**: The spec type (`rfc`, `adr`, `runbook`, `design`, `standard`, `custom`)
56
- - **title**: Human-readable title
57
- - **status**: Current lifecycle status (`draft`, `review`, `accepted`, `superseded`, `deprecated`, `withdrawn`)
58
- - **dependencies**: Other specs this one references or depends on
59
-
60
- ### Spec sections
61
- Each spec is broken into its constituent sections (e.g., Context, Decision, Consequences for an ADR). Sections from stale specs may be compressed to save tokens — these will be marked with a compression notice.
62
-
63
- ### Collapsed specs
64
- Some specs may be fully collapsed to a one-line summary (e.g., superseded ADRs). This is intentional — they provide awareness without consuming significant context.
65
-
66
- ## Step 3: Apply the context to your task
67
-
68
- When working on the task, you MUST:
69
-
70
- 1. **Reference specs by ID** — When your implementation relates to a spec, mention it explicitly (e.g., "Per ADR-012, we use PostgreSQL for persistence").
71
-
72
- 2. **Flag drift** — If you notice the codebase diverges from what a spec describes, call it out:
73
- - "NOTE: The code uses Redis here, but ADR-012 specifies PostgreSQL. This may be intentional drift or the ADR may need updating."
74
-
75
- 3. **Note gaps** — If the task requires decisions not covered by any spec, say so:
76
- - "GAP: No spec covers error retry strategy for this service. Consider authoring an ADR."
77
-
78
- 4. **Respect status** — Treat spec statuses appropriately:
79
- - `accepted` / `active`: These are current truth. Follow them.
80
- - `draft` / `review`: These are proposed but not finalized. Follow them tentatively but note they may change.
81
- - `superseded`: Check what supersedes it. Follow the newer spec.
82
- - `deprecated` / `withdrawn`: Do not follow these. Note if code still references them.
83
-
84
- 5. **Follow conventions** — Standards and runbooks often define coding conventions, naming patterns, deployment procedures, etc. Adhere to them.
85
-
86
- ## Step 4: Verify spec alignment before finishing
87
-
88
- Before completing the task, do a quick check:
89
-
90
- - [ ] Does the implementation align with all relevant accepted specs?
91
- - [ ] Are there any specs in `draft` or `review` that this work might affect?
92
- - [ ] Did you introduce any patterns not covered by existing specs?
93
- - [ ] If you found drift or gaps, did you document them in your response?
94
-
95
- ## Troubleshooting
96
-
97
- ### `sdx pack` returns no specs
98
- - Check that the project has an `sdx.config.ts` or `sdx.config.yaml` file
99
- - Verify specs exist in the configured `specsDir` (default: `specs/`)
100
- - Try a broader task description — the relevance matcher uses keywords from spec titles and content
101
-
102
- ### `sdx pack` returns too many specs
103
- - Use `--budget` to limit token count
104
- - Make the task description more specific
105
- - The packer prioritizes by relevance score; lower-scored specs are trimmed first
106
-
107
- ### Specs seem outdated
108
- - Check `updatedDate` in spec frontmatter
109
- - Run `sdx lint` to identify specs with structural or content issues
110
- - Suggest the user update stale specs
111
-
112
- ### Command not found
113
- - Ensure `specdx` is installed: `npm install -g specdx` or `npx specdx pack ...`
114
- - In a monorepo, it may be a devDependency: `npx sdx pack ...`
115
-
116
- ## Understanding the output formats
117
-
118
- ### XML format (recommended for Claude)
119
-
120
- The XML format wraps specs in tags that are easy for LLMs to parse:
121
-
122
- ```xml
123
- <sdx-context task="Add pagination to /api/users" specs="4" tokens="3200">
124
- <spec id="rfc-003" type="rfc" status="accepted" title="REST API Design Guidelines">
125
- <section heading="Pagination">
126
- All list endpoints MUST support cursor-based pagination...
127
- </section>
128
- </spec>
129
- <spec id="adr-002" type="adr" status="superseded" collapsed="true">
130
- [ADR] Use Express.js — superseded
131
- </spec>
132
- </sdx-context>
133
- ```
134
-
135
- Key attributes:
136
- - `specs` — total number of specs included
137
- - `tokens` — estimated token count of the full output
138
- - `collapsed="true"` — spec was reduced to a one-liner
139
-
140
- ### Markdown format
141
-
142
- The markdown format uses headings and horizontal rules to separate specs:
143
-
144
- ```markdown
145
- # SDX Context: Add pagination to /api/users
146
-
147
- ---
148
-
149
- ## rfc-003: REST API Design Guidelines
150
- **Type:** rfc | **Status:** accepted
151
-
152
- ### Pagination
153
- All list endpoints MUST support cursor-based pagination...
154
-
155
- ---
156
-
157
- ## adr-002: Use Express.js
158
- > [ADR] Use Express.js — superseded
159
- ```
160
-
161
- ### JSON format
162
-
163
- The JSON format is compact and machine-parseable:
164
-
165
- ```json
166
- {
167
- "task": "Add pagination to /api/users",
168
- "specs": [
169
- {
170
- "id": "rfc-003",
171
- "type": "rfc",
172
- "status": "accepted",
173
- "title": "REST API Design Guidelines",
174
- "sections": [{ "heading": "Pagination", "content": "..." }]
175
- }
176
- ]
177
- }
178
- ```
179
-
180
- ## How relevance scoring works
181
-
182
- The packer uses multiple signals to rank spec relevance:
183
-
184
- 1. **Keyword overlap** — Words from the task description are matched against spec titles, tags, and section headings. More matches = higher score.
185
- 2. **Type affinity** — ADRs and standards are weighted slightly higher because they represent binding decisions and rules.
186
- 3. **Status weighting** — `accepted` and `active` specs score higher than `draft` or `deprecated` ones.
187
- 4. **Dependency inclusion** — If a high-relevance spec depends on another spec, the dependency is pulled in automatically (transitive closure).
188
- 5. **Recency boost** — Recently updated specs get a small relevance boost.
189
-
190
- Specs below the relevance threshold are excluded entirely unless they are transitive dependencies of included specs.
191
-
192
- ## Example session
193
-
194
- User says: "Add pagination to the /api/users endpoint"
195
-
196
- 1. Run: `sdx pack --task "Add pagination to the /api/users endpoint" --format xml`
197
- 2. Read the output — you might see:
198
- - `rfc-003: REST API Design Guidelines` (status: accepted) — defines pagination patterns
199
- - `adr-007: Use cursor-based pagination` (status: accepted) — specific decision
200
- - `standard-001: API Response Envelope` (status: active) — response format requirements
201
- - `adr-002: Use Express.js` (status: superseded) — collapsed, just for awareness
202
- 3. Implement pagination following the cursor-based approach from ADR-007
203
- 4. Use the response envelope format from standard-001
204
- 5. Follow the REST conventions from RFC-003
205
- 6. Note in your response: "Implemented per ADR-007 (cursor-based pagination) and standard-001 (envelope format)"
206
-
207
- ## Example: handling drift
208
-
209
- User says: "Refactor the auth middleware to use JWT"
210
-
211
- 1. Run: `sdx pack --task "Refactor auth middleware to use JWT" --format xml`
212
- 2. Output includes:
213
- - `adr-003: Use session-based authentication` (status: accepted)
214
- - `standard-002: Security Standards` (status: active)
215
- 3. The task asks for JWT, but ADR-003 says session-based auth is the accepted approach.
216
- 4. Respond with: "DRIFT: This task requests JWT-based auth, but ADR-003 (accepted) specifies session-based authentication. Before proceeding, we should either: (a) create a new ADR superseding ADR-003 to adopt JWT, or (b) confirm this is a deliberate exception."
217
- 5. Do NOT silently ignore the spec. Always surface the conflict.
218
-
219
- ## Example: noting gaps
220
-
221
- User says: "Add rate limiting to the API gateway"
222
-
223
- 1. Run: `sdx pack --task "Add rate limiting to the API gateway" --format xml`
224
- 2. Output includes general API specs but nothing about rate limiting specifically.
225
- 3. Respond with: "GAP: No spec covers rate limiting strategy (algorithm, limits, response codes, retry headers). Recommend authoring an ADR before implementation to align on approach. In the meantime, proceeding with token bucket algorithm at 100 req/min as a reasonable default."
226
-
227
- ## Notes
228
-
229
- - The `sdx pack` command is read-only — it never modifies specs or project files
230
- - Token counts in the output are estimates based on the `cl100k_base` tokenizer
231
- - Compressed sections can be expanded by re-running without `--budget` or with a larger budget
232
- - If a spec has `dependencies`, the packer automatically includes those transitive dependencies
233
- - The packer respects `.sdxignore` patterns if present in the project root
234
- - Multiple `--task` flags are not supported; combine related work into one description
235
- - The `--format` flag defaults to `xml` if omitted
236
-
237
- ## When NOT to use this skill
238
-
239
- - For simple, self-contained tasks that don't touch architecture or conventions (e.g., fixing a typo)
240
- - When the user explicitly says to skip spec context
241
- - When running in a project that doesn't use SDX (no `sdx.config.*` file)
242
- - For tasks that only modify tests without changing production behavior
243
-
244
- In those cases, proceed directly with the task without running `sdx pack`.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/skills.ts","../../skills/src/install.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { installSkills } from \"@sdx/skills\";\n\nexport default defineCommand({\n meta: { name: \"skills\", description: \"Manage sdx skills for AI coding tools\" },\n subCommands: {\n install: defineCommand({\n meta: { name: \"install\", description: \"Install Claude Code skill files\" },\n args: {\n dir: {\n type: \"string\",\n description: \"Target directory (default: current directory)\",\n default: \".\",\n },\n },\n async run({ args }) {\n try {\n const result = await installSkills(args.dir);\n if (result.installed.length === 0 && result.updated.length === 0) {\n console.log(\" No skill files to install.\");\n return;\n }\n for (const file of result.installed) console.log(` ✓ Installed ${file}`);\n for (const file of result.updated) console.log(` ✓ Updated ${file}`);\n console.log(`\\n Skills installed to .claude/skills/`);\n } catch (err) {\n console.error(`\\n ✗ ${(err as Error).message}\\n`);\n process.exit(1);\n }\n },\n }),\n },\n});\n","import { mkdir, writeFile, readFile, stat } from \"node:fs/promises\";\nimport { statSync } from \"node:fs\";\nimport { join, dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport const SKILL_FILES = [\"sdx-start-task.md\", \"sdx-author-spec.md\"];\n\nexport interface InstallResult {\n installed: string[];\n updated: string[];\n}\n\nfunction getSkillSourceDir(): string {\n // When bundled: skills at __dirname/skills (sibling of bundle)\n // In dev: skills at __dirname/../skills (sibling of src/)\n const bundledPath = join(__dirname, \"skills\");\n try {\n statSync(bundledPath);\n return bundledPath;\n } catch {\n return join(__dirname, \"..\", \"skills\");\n }\n}\n\nexport async function installSkills(\n projectDir: string,\n): Promise<InstallResult> {\n const sourceDir = getSkillSourceDir();\n const skillsDir = join(projectDir, \".claude\", \"skills\");\n const installed: string[] = [];\n const updated: string[] = [];\n\n // Ensure .claude/skills/ directory exists\n await mkdir(skillsDir, { recursive: true });\n\n for (const file of SKILL_FILES) {\n const sourcePath = join(sourceDir, file);\n const targetPath = join(skillsDir, file);\n\n const content = await readFile(sourcePath, \"utf-8\");\n\n // Check if target already exists\n let exists = false;\n try {\n await stat(targetPath);\n exists = true;\n } catch {\n // File doesn't exist\n }\n\n await writeFile(targetPath, content, \"utf-8\");\n\n if (exists) {\n updated.push(file);\n } else {\n installed.push(file);\n }\n }\n\n return { installed, updated };\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;;;ACA9B,SAAS,OAAO,WAAW,UAAU,YAAY;AACjD,SAAS,gBAAgB;AACzB,SAAS,MAAM,eAAe;AAC9B,SAAS,qBAAqB;AAE9B,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAEjD,IAAM,cAAc,CAAC,qBAAqB,oBAAoB;AAOrE,SAAS,oBAAiB;AAGxB,QAAM,cAAc,KAAK,WAAW,QAAQ;AAC5C,MAAI;AACF,aAAS,WAAW;AACpB,WAAO;EACT,QAAQ;AACN,WAAO,KAAK,WAAW,MAAM,QAAQ;EACvC;AACF;AAEA,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;AAAA,QACvD,SAAS,KAAK;AACZ,kBAAQ,MAAM;AAAA,WAAU,IAAc,OAAO;AAAA,CAAI;AACjD,kBAAQ,KAAK,CAAC;AAAA,QAChB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF,CAAC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/validate.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { loadConfig, ConfigError } from \"@sdx/core\";\nimport { sharedArgs } from \"../shared-args.js\";\n\nexport default defineCommand({\n meta: { name: \"validate\", description: \"Validate spec.config.yaml\" },\n args: { ...sharedArgs },\n async run() {\n try {\n const config = await loadConfig(undefined, process.cwd());\n console.log(` ✓ Config valid. ${Object.keys(config.specs).length} specs defined.`);\n } catch (err) {\n if (err instanceof ConfigError) {\n console.error(` ✗ Config invalid: ${err.message}`);\n if (err.errors) {\n for (const e of err.errors) console.error(` - ${JSON.stringify(e)}`);\n }\n process.exit(1);\n }\n throw err;\n }\n },\n});\n"],"mappings":";;;;;;;;AAAA,SAAS,qBAAqB;AAI9B,IAAO,mBAAQ,cAAc;AAAA,EAC3B,MAAM,EAAE,MAAM,YAAY,aAAa,4BAA4B;AAAA,EACnE,MAAM,EAAE,GAAG,WAAW;AAAA,EACtB,MAAM,MAAM;AACV,QAAI;AACF,YAAM,SAAS,MAAM,WAAW,QAAW,QAAQ,IAAI,CAAC;AACxD,cAAQ,IAAI,0BAAqB,OAAO,KAAK,OAAO,KAAK,EAAE,MAAM,iBAAiB;AAAA,IACpF,SAAS,KAAK;AACZ,UAAI,eAAe,aAAa;AAC9B,gBAAQ,MAAM,4BAAuB,IAAI,OAAO,EAAE;AAClD,YAAI,IAAI,QAAQ;AACd,qBAAW,KAAK,IAAI,OAAQ,SAAQ,MAAM,SAAS,KAAK,UAAU,CAAC,CAAC,EAAE;AAAA,QACxE;AACA,gBAAQ,KAAK,CAAC;AAAA,MAChB;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF,CAAC;","names":[]}