specweave 1.0.126 → 1.0.129

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.
Files changed (57) hide show
  1. package/CLAUDE.md +26 -26
  2. package/bin/specweave.js +29 -0
  3. package/dist/src/cli/commands/detect-intent.d.ts +57 -0
  4. package/dist/src/cli/commands/detect-intent.d.ts.map +1 -0
  5. package/dist/src/cli/commands/detect-intent.js +169 -0
  6. package/dist/src/cli/commands/detect-intent.js.map +1 -0
  7. package/dist/src/cli/commands/detect-project.d.ts +49 -4
  8. package/dist/src/cli/commands/detect-project.d.ts.map +1 -1
  9. package/dist/src/cli/commands/detect-project.js +147 -63
  10. package/dist/src/cli/commands/detect-project.js.map +1 -1
  11. package/dist/src/cli/commands/init.d.ts.map +1 -1
  12. package/dist/src/cli/commands/init.js +12 -8
  13. package/dist/src/cli/commands/init.js.map +1 -1
  14. package/dist/src/cli/commands/load-plugins.d.ts +3 -1
  15. package/dist/src/cli/commands/load-plugins.d.ts.map +1 -1
  16. package/dist/src/cli/commands/load-plugins.js +52 -35
  17. package/dist/src/cli/commands/load-plugins.js.map +1 -1
  18. package/dist/src/cli/commands/refresh-marketplace.d.ts.map +1 -1
  19. package/dist/src/cli/commands/refresh-marketplace.js +4 -3
  20. package/dist/src/cli/commands/refresh-marketplace.js.map +1 -1
  21. package/dist/src/cli/helpers/init/path-utils.d.ts +3 -0
  22. package/dist/src/cli/helpers/init/path-utils.d.ts.map +1 -1
  23. package/dist/src/cli/helpers/init/path-utils.js +9 -2
  24. package/dist/src/cli/helpers/init/path-utils.js.map +1 -1
  25. package/dist/src/cli/helpers/init/plugin-installer.js +2 -1
  26. package/dist/src/cli/helpers/init/plugin-installer.js.map +1 -1
  27. package/dist/src/cli/helpers/init/types.d.ts +5 -0
  28. package/dist/src/cli/helpers/init/types.d.ts.map +1 -1
  29. package/dist/src/core/auto/config.d.ts.map +1 -1
  30. package/dist/src/core/auto/config.js +11 -0
  31. package/dist/src/core/auto/config.js.map +1 -1
  32. package/dist/src/core/auto/types.d.ts +4 -0
  33. package/dist/src/core/auto/types.d.ts.map +1 -1
  34. package/dist/src/core/auto/types.js +4 -0
  35. package/dist/src/core/auto/types.js.map +1 -1
  36. package/dist/src/core/lazy-loading/cache-manager.d.ts +2 -2
  37. package/dist/src/core/lazy-loading/cache-manager.js +3 -3
  38. package/dist/src/core/lazy-loading/cache-manager.js.map +1 -1
  39. package/dist/src/core/lazy-loading/keyword-detector.d.ts +3 -2
  40. package/dist/src/core/lazy-loading/keyword-detector.d.ts.map +1 -1
  41. package/dist/src/core/lazy-loading/keyword-detector.js +136 -2
  42. package/dist/src/core/lazy-loading/keyword-detector.js.map +1 -1
  43. package/dist/src/core/lazy-loading/project-detector.d.ts +49 -0
  44. package/dist/src/core/lazy-loading/project-detector.d.ts.map +1 -0
  45. package/dist/src/core/lazy-loading/project-detector.js +348 -0
  46. package/dist/src/core/lazy-loading/project-detector.js.map +1 -0
  47. package/dist/src/sync/external-issue-auto-creator.d.ts.map +1 -1
  48. package/dist/src/sync/external-issue-auto-creator.js +11 -1
  49. package/dist/src/sync/external-issue-auto-creator.js.map +1 -1
  50. package/package.json +1 -1
  51. package/plugins/specweave/hooks/stop-auto.sh +221 -16
  52. package/plugins/specweave/hooks/user-prompt-submit.sh +79 -2
  53. package/plugins/specweave/hooks/v2/detectors/us-completion-detector.sh +70 -38
  54. package/plugins/specweave/hooks/v2/dispatchers/session-start.sh +70 -1
  55. package/plugins/specweave/hooks/v2/queue/processor.sh +6 -4
  56. package/plugins/specweave/lib/hooks/sync-living-docs.js +6 -1
  57. package/src/templates/CLAUDE.md.template +35 -26
package/CLAUDE.md CHANGED
@@ -1,10 +1,10 @@
1
- <!-- SW:META template="claude" version="1.0.125" sections="header,start,autodetect,metarule,rules,workflow,reflect,context,lsp,structure,taskformat,secrets,syncing,mapping,testing,api,limits,troubleshooting,lazyloading,principles,linking,mcp,autoexecute,auto,docs" -->
1
+ <!-- SW:META template="claude" version="1.0.126" sections="header,start,autodetect,metarule,rules,workflow,reflect,context,lsp,structure,taskformat,secrets,syncing,mapping,testing,api,limits,troubleshooting,lazyloading,principles,linking,mcp,autoexecute,auto,docs" -->
2
2
 
3
- <!-- SW:SECTION:header version="1.0.125" -->
3
+ <!-- SW:SECTION:header version="1.0.126" -->
4
4
  **Framework**: SpecWeave | **Truth**: `spec.md` + `tasks.md`
5
5
  <!-- SW:END:header -->
6
6
 
7
- <!-- SW:SECTION:start version="1.0.125" -->
7
+ <!-- SW:SECTION:start version="1.0.126" -->
8
8
  ## Getting Started
9
9
 
10
10
  **Initial increment**: `0001-project-setup` (auto-created by `specweave init`)
@@ -14,7 +14,7 @@
14
14
  2. **Customize**: Edit spec.md and use for setup tasks
15
15
  <!-- SW:END:start -->
16
16
 
17
- <!-- SW:SECTION:autodetect version="1.0.125" -->
17
+ <!-- SW:SECTION:autodetect version="1.0.126" -->
18
18
  ## Auto-Detection
19
19
 
20
20
  SpecWeave auto-detects product descriptions and routes to `/sw:increment`:
@@ -24,7 +24,7 @@ SpecWeave auto-detects product descriptions and routes to `/sw:increment`:
24
24
  **Opt-out phrases**: "Just brainstorm first" | "Don't plan yet" | "Quick discussion" | "Let's explore ideas"
25
25
  <!-- SW:END:autodetect -->
26
26
 
27
- <!-- SW:SECTION:metarule version="1.0.125" -->
27
+ <!-- SW:SECTION:metarule version="1.0.126" -->
28
28
  ## Meta-Rule: Think-Before-Act
29
29
 
30
30
  **Satisfy dependencies BEFORE dependent operations.**
@@ -35,7 +35,7 @@ SpecWeave auto-detects product descriptions and routes to `/sw:increment`:
35
35
  ```
36
36
  <!-- SW:END:metarule -->
37
37
 
38
- <!-- SW:SECTION:rules version="1.0.125" -->
38
+ <!-- SW:SECTION:rules version="1.0.126" -->
39
39
  ## Rules
40
40
 
41
41
  1. **Files** → `.specweave/increments/####-name/` (spec.md, plan.md, tasks.md at root; reports/, scripts/, logs/ subfolders)
@@ -48,7 +48,7 @@ SpecWeave auto-detects product descriptions and routes to `/sw:increment`:
48
48
  8. **⛔ Marketplace refresh**: ALWAYS use `specweave refresh-marketplace` CLI command. NEVER suggest `scripts/refresh-marketplace.sh` - end users don't have the scripts folder (npm global install).
49
49
  <!-- SW:END:rules -->
50
50
 
51
- <!-- SW:SECTION:workflow version="1.0.125" -->
51
+ <!-- SW:SECTION:workflow version="1.0.126" -->
52
52
  ## Workflow
53
53
 
54
54
  `/sw:increment "X"` → `/sw:do` → `/sw:progress` → `/sw:done 0001`
@@ -68,7 +68,7 @@ SpecWeave auto-detects product descriptions and routes to `/sw:increment`:
68
68
  **Natural language**: "Let's build X" → `/sw:increment` | "What's status?" → `/sw:progress` | "We're done" → `/sw:done` | "Ship while sleeping" → `/sw:auto`
69
69
  <!-- SW:END:workflow -->
70
70
 
71
- <!-- SW:SECTION:reflect version="1.0.125" -->
71
+ <!-- SW:SECTION:reflect version="1.0.126" -->
72
72
  ## Self-Improving Skills (Reflect)
73
73
 
74
74
  **Learn once, never repeat.** Claude learns from corrections and patterns across sessions.
@@ -112,7 +112,7 @@ ls ~/.specweave/memory/*.md 2>/dev/null
112
112
  **Enable auto-learning**: `/sw:reflect-on` → Stop hook analyzes sessions automatically
113
113
  <!-- SW:END:reflect -->
114
114
 
115
- <!-- SW:SECTION:context version="1.0.125" -->
115
+ <!-- SW:SECTION:context version="1.0.126" -->
116
116
  ## Living Docs Context
117
117
 
118
118
  **Before implementing features**: Check existing docs for patterns and decisions.
@@ -132,7 +132,7 @@ grep -ril "keyword" .specweave/docs/internal/
132
132
  **Use `/sw:context <topic>`** to load relevant living docs into conversation.
133
133
  <!-- SW:END:context -->
134
134
 
135
- <!-- SW:SECTION:lsp version="1.0.125" -->
135
+ <!-- SW:SECTION:lsp version="1.0.126" -->
136
136
  ## LSP-Enhanced Exploration
137
137
 
138
138
  **USE LSP ACTIVELY** for semantic code understanding (100x faster than grep).
@@ -149,7 +149,7 @@ go install golang.org/x/tools/gopls@latest # Go
149
149
  **Best Practices**: ALWAYS use `findReferences` before refactoring | Use `goToDefinition` instead of grep | Combine with Explore agent
150
150
  <!-- SW:END:lsp -->
151
151
 
152
- <!-- SW:SECTION:structure version="1.0.125" -->
152
+ <!-- SW:SECTION:structure version="1.0.126" -->
153
153
  ## Structure
154
154
 
155
155
  ```
@@ -219,7 +219,7 @@ my-project/
219
219
  ```
220
220
  <!-- SW:END:structure -->
221
221
 
222
- <!-- SW:SECTION:taskformat version="1.0.125" -->
222
+ <!-- SW:SECTION:taskformat version="1.0.126" -->
223
223
  ## Task Format
224
224
 
225
225
  ```markdown
@@ -229,7 +229,7 @@ my-project/
229
229
  ```
230
230
  <!-- SW:END:taskformat -->
231
231
 
232
- <!-- SW:SECTION:secrets version="1.0.125" -->
232
+ <!-- SW:SECTION:secrets version="1.0.126" -->
233
233
  ## Secrets Check
234
234
 
235
235
  **BEFORE CLI tools**: Check existing config first!
@@ -243,7 +243,7 @@ gh auth status
243
243
  **SECURITY**: NEVER use `grep TOKEN .env` without `-q` flag - it exposes credentials in terminal!
244
244
  <!-- SW:END:secrets -->
245
245
 
246
- <!-- SW:SECTION:syncing version="1.0.125" -->
246
+ <!-- SW:SECTION:syncing version="1.0.126" -->
247
247
  ## External Sync (GitHub/JIRA/ADO)
248
248
 
249
249
  **After increment creation**: Run `/sw-github:sync {id}` to create issues!
@@ -271,7 +271,7 @@ Living docs sync ≠ External sync. They are separate:
271
271
  **Verify tokens**: `grep -q GITHUB_TOKEN .env && echo "Token configured"` | `gh auth status`
272
272
  <!-- SW:END:syncing -->
273
273
 
274
- <!-- SW:SECTION:mapping version="1.0.125" -->
274
+ <!-- SW:SECTION:mapping version="1.0.126" -->
275
275
  ## GitHub Mapping
276
276
 
277
277
  | SpecWeave | GitHub |
@@ -281,7 +281,7 @@ Living docs sync ≠ External sync. They are separate:
281
281
  | Task T-XXX | Checkbox |
282
282
  <!-- SW:END:mapping -->
283
283
 
284
- <!-- SW:SECTION:testing version="1.0.125" -->
284
+ <!-- SW:SECTION:testing version="1.0.126" -->
285
285
  ## Testing
286
286
 
287
287
  BDD in tasks.md | Unit >80% | `.test.ts` (Vitest)
@@ -293,7 +293,7 @@ vi.mock('fs', () => ({ readFile: vi.fn() }));
293
293
  ```
294
294
  <!-- SW:END:testing -->
295
295
 
296
- <!-- SW:SECTION:api version="1.0.125" -->
296
+ <!-- SW:SECTION:api version="1.0.126" -->
297
297
  ## API Development (OpenAPI-First)
298
298
 
299
299
  **For API projects only.** OpenAPI = source of truth → Postman derived from it.
@@ -312,13 +312,13 @@ vi.mock('fs', () => ({ readFile: vi.fn() }));
312
312
  **Import**: Postman → Import collection + env → Fill secrets → Select env
313
313
  <!-- SW:END:api -->
314
314
 
315
- <!-- SW:SECTION:limits version="1.0.125" -->
315
+ <!-- SW:SECTION:limits version="1.0.126" -->
316
316
  ## Limits
317
317
 
318
318
  **Max 1500 lines/file** — extract before adding
319
319
  <!-- SW:END:limits -->
320
320
 
321
- <!-- SW:SECTION:troubleshooting version="1.0.125" -->
321
+ <!-- SW:SECTION:troubleshooting version="1.0.126" -->
322
322
  ## Troubleshooting
323
323
 
324
324
  | Issue | Fix |
@@ -340,7 +340,7 @@ vi.mock('fs', () => ({ readFile: vi.fn() }));
340
340
  | Need all plugins loaded | `specweave load-plugins all` (~60K tokens) |
341
341
  <!-- SW:END:troubleshooting -->
342
342
 
343
- <!-- SW:SECTION:lazyloading version="1.0.125" -->
343
+ <!-- SW:SECTION:lazyloading version="1.0.126" -->
344
344
  ## Lazy Plugin Loading
345
345
 
346
346
  **By default, SpecWeave installs 2 essential plugins** (~3K tokens total):
@@ -386,7 +386,7 @@ specweave init --full . # Install all plugins immediately
386
386
  ```
387
387
  <!-- SW:END:lazyloading -->
388
388
 
389
- <!-- SW:SECTION:principles version="1.0.125" -->
389
+ <!-- SW:SECTION:principles version="1.0.126" -->
390
390
  ## Principles
391
391
 
392
392
  1. **Spec-first**: `/sw:increment` before coding
@@ -396,7 +396,7 @@ specweave init --full . # Install all plugins immediately
396
396
  5. **Clean**: All files in increment folders
397
397
  <!-- SW:END:principles -->
398
398
 
399
- <!-- SW:SECTION:linking version="1.0.125" -->
399
+ <!-- SW:SECTION:linking version="1.0.126" -->
400
400
  ## Bidirectional Linking
401
401
 
402
402
  Tasks ↔ User Stories auto-linked via AC-IDs: `AC-US1-01` → `US-001`
@@ -404,7 +404,7 @@ Tasks ↔ User Stories auto-linked via AC-IDs: `AC-US1-01` → `US-001`
404
404
  Task format: `**AC**: AC-US1-01, AC-US1-02` (CRITICAL for linking)
405
405
  <!-- SW:END:linking -->
406
406
 
407
- <!-- SW:SECTION:mcp version="1.0.125" -->
407
+ <!-- SW:SECTION:mcp version="1.0.126" -->
408
408
  ## External Service Connection
409
409
 
410
410
  **Priority**: MCP Server → REST API → CLI → Direct Connection
@@ -429,7 +429,7 @@ wrangler whoami 2>/dev/null
429
429
  ```
430
430
  <!-- SW:END:mcp -->
431
431
 
432
- <!-- SW:SECTION:autoexecute version="1.0.125" -->
432
+ <!-- SW:SECTION:autoexecute version="1.0.126" -->
433
433
  ## Auto-Execute Rule
434
434
 
435
435
  **NEVER** output "Manual Step Required" when credentials exist. **EXECUTE DIRECTLY.**
@@ -444,7 +444,7 @@ wrangler whoami 2>/dev/null && gh auth status 2>/dev/null
444
444
  ```
445
445
  <!-- SW:END:autoexecute -->
446
446
 
447
- <!-- SW:SECTION:auto version="1.0.125" -->
447
+ <!-- SW:SECTION:auto version="1.0.126" -->
448
448
  ## Auto Mode (Autonomous Execution)
449
449
 
450
450
  **Continuous execution until all tasks complete.**
@@ -521,7 +521,7 @@ wrangler whoami 2>/dev/null && gh auth status 2>/dev/null
521
521
  **Circuit Breaker**: External API fails 3x? Queue & continue
522
522
  <!-- SW:END:auto -->
523
523
 
524
- <!-- SW:SECTION:docs version="1.0.125" -->
524
+ <!-- SW:SECTION:docs version="1.0.126" -->
525
525
  ## Docs
526
526
 
527
527
  [spec-weave.com](https://spec-weave.com) | `.specweave/docs/internal/`
package/bin/specweave.js CHANGED
@@ -850,6 +850,7 @@ const loadPluginsCmd = program
850
850
  .option('-f, --force', 'Force reinstall even if already loaded')
851
851
  .option('-b, --background', 'Run installation in background')
852
852
  .option('-v, --verbose', 'Show detailed output')
853
+ .option('-s, --silent', 'Silent mode - no stdout output (for hooks)')
853
854
  .option('--list-groups', 'Show available plugin groups')
854
855
  .action(async (group, options) => {
855
856
  if (options.listGroups) {
@@ -891,6 +892,34 @@ Examples:
891
892
  $ specweave load-plugins ml --background # Load ML plugins in background
892
893
  `);
893
894
 
895
+ // Detect intent command - Hook helper for automatic plugin loading
896
+ program
897
+ .command('detect-intent <prompt>')
898
+ .description('Detect SpecWeave intent from a prompt and optionally install plugins')
899
+ .option('--install', 'Also install detected plugins after detection')
900
+ .option('--silent', 'Silent mode - no stdout output (for hooks)')
901
+ .action(async (prompt, options) => {
902
+ const { detectIntentCommand } = await import('../dist/src/cli/commands/detect-intent.js');
903
+ const result = await detectIntentCommand(prompt, options);
904
+ // Exit code: 0 if plugins detected, 1 if none
905
+ process.exit(result.detected ? 0 : 1);
906
+ });
907
+
908
+ // Detect project command - Analyze project files and suggest plugins
909
+ program
910
+ .command('detect-project [path]')
911
+ .description('Detect project type from files and suggest plugins to install')
912
+ .option('--name <name>', 'Increment name for legacy name-based detection')
913
+ .option('--description <text>', 'Description for legacy name-based detection')
914
+ .option('--install', 'Also install detected plugins after detection')
915
+ .option('--silent', 'Silent mode - no stdout output (for hooks)')
916
+ .action(async (path, options) => {
917
+ const { detectProjectCommand } = await import('../dist/src/cli/commands/detect-project.js');
918
+ const result = await detectProjectCommand(path, options);
919
+ // Exit code: 0 if types detected, 1 if none
920
+ process.exit(result.types.length > 0 ? 0 : 1);
921
+ });
922
+
894
923
  // Unload plugins command - Lazy loading: remove plugin groups from active
895
924
  const unloadPluginsCmd = program
896
925
  .command('unload-plugins [group]')
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Detect Intent CLI Command
3
+ *
4
+ * Detects SpecWeave intent from a user prompt and optionally installs matching plugins.
5
+ * Used by hooks for automatic plugin loading on user-prompt-submit.
6
+ *
7
+ * Usage:
8
+ * specweave detect-intent "prompt text" # Returns JSON with detected plugins
9
+ * specweave detect-intent "prompt text" --install # Also installs detected plugins
10
+ * specweave detect-intent "prompt text" --install --silent # Silent mode for hooks
11
+ *
12
+ * @module cli/commands/detect-intent
13
+ */
14
+ import { Command } from 'commander';
15
+ export interface DetectIntentOptions {
16
+ /** Also install detected plugins after detection */
17
+ install?: boolean;
18
+ /** Silent mode - no stdout output (for hooks) */
19
+ silent?: boolean;
20
+ /** Output format - json or text */
21
+ json?: boolean;
22
+ /** Confidence threshold for auto-install (0-1, default 0.6) */
23
+ threshold?: number;
24
+ }
25
+ export interface DetectIntentResult {
26
+ /** Whether any plugins were detected */
27
+ detected: boolean;
28
+ /** List of detected plugin names to install */
29
+ plugins: string[];
30
+ /** Confidence score (0-1) */
31
+ confidence: number;
32
+ /** Keywords that matched */
33
+ matchedKeywords: string[];
34
+ /** Detection latency in milliseconds */
35
+ latencyMs?: number;
36
+ /** Whether plugins were installed (when --install used) */
37
+ installed?: boolean;
38
+ /** Installation result message (when --install used) */
39
+ installMessage?: string;
40
+ }
41
+ /**
42
+ * Detect intent from a user prompt
43
+ *
44
+ * @param prompt - User's input prompt to analyze
45
+ * @param options - Command options
46
+ * @returns Detection result with plugins to install
47
+ */
48
+ export declare function detectIntentCommand(prompt: string, options?: DetectIntentOptions): Promise<DetectIntentResult>;
49
+ /**
50
+ * Create the detect-intent command for Commander
51
+ */
52
+ export declare function createDetectIntentCommand(): Command;
53
+ /**
54
+ * Export for direct CLI invocation
55
+ */
56
+ export declare function main(): Promise<void>;
57
+ //# sourceMappingURL=detect-intent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-intent.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/detect-intent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mCAAmC;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,QAAQ,EAAE,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wDAAwD;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAwF7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CA6BnD;AAED;;GAEG;AACH,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAgC1C"}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Detect Intent CLI Command
3
+ *
4
+ * Detects SpecWeave intent from a user prompt and optionally installs matching plugins.
5
+ * Used by hooks for automatic plugin loading on user-prompt-submit.
6
+ *
7
+ * Usage:
8
+ * specweave detect-intent "prompt text" # Returns JSON with detected plugins
9
+ * specweave detect-intent "prompt text" --install # Also installs detected plugins
10
+ * specweave detect-intent "prompt text" --install --silent # Silent mode for hooks
11
+ *
12
+ * @module cli/commands/detect-intent
13
+ */
14
+ import { Command } from 'commander';
15
+ import chalk from 'chalk';
16
+ import { detectSpecWeaveIntent } from '../../core/lazy-loading/keyword-detector.js';
17
+ import { PluginCacheManager } from '../../core/lazy-loading/cache-manager.js';
18
+ import { logInfo, logError, logWarn } from '../../core/lazy-loading/failure-logger.js';
19
+ /** Default confidence threshold for auto-install (T-017) */
20
+ const DEFAULT_INSTALL_THRESHOLD = 0.6;
21
+ /**
22
+ * Detect intent from a user prompt
23
+ *
24
+ * @param prompt - User's input prompt to analyze
25
+ * @param options - Command options
26
+ * @returns Detection result with plugins to install
27
+ */
28
+ export async function detectIntentCommand(prompt, options = {}) {
29
+ const startTime = performance.now();
30
+ // Run detection
31
+ const detection = detectSpecWeaveIntent(prompt);
32
+ // Map matched keywords to plugins
33
+ const plugins = detection.suggestedPlugins;
34
+ const result = {
35
+ detected: detection.detected,
36
+ plugins,
37
+ confidence: detection.confidence,
38
+ matchedKeywords: detection.matchedKeywords,
39
+ latencyMs: detection.latencyMs,
40
+ };
41
+ // Handle installation if requested (T-017: confidence threshold check)
42
+ const installThreshold = options.threshold ?? DEFAULT_INSTALL_THRESHOLD;
43
+ if (options.install && plugins.length > 0) {
44
+ // T-017: Only auto-install if confidence meets threshold
45
+ if (detection.confidence < installThreshold) {
46
+ result.installed = false;
47
+ result.installMessage = `Confidence ${detection.confidence.toFixed(2)} below threshold ${installThreshold} - plugins suggested but not installed`;
48
+ logWarn('detect-intent', 'Low confidence - skipping install', {
49
+ confidence: detection.confidence,
50
+ threshold: installThreshold,
51
+ plugins,
52
+ matchedKeywords: detection.matchedKeywords,
53
+ });
54
+ }
55
+ else {
56
+ try {
57
+ const cacheManager = new PluginCacheManager();
58
+ // Filter to only plugins not already loaded
59
+ const unloadedPlugins = plugins.filter((p) => !cacheManager.isPluginLoaded(p));
60
+ if (unloadedPlugins.length > 0) {
61
+ const installResult = await cacheManager.installPlugins({
62
+ plugins: unloadedPlugins,
63
+ force: false, // Don't force reinstall
64
+ });
65
+ result.installed = installResult.success;
66
+ result.installMessage = installResult.success
67
+ ? `Installed ${installResult.pluginsAffected} plugin(s) in ${Math.round(installResult.durationMs)}ms`
68
+ : installResult.error;
69
+ logInfo('detect-intent', 'Plugins installed', {
70
+ plugins: unloadedPlugins,
71
+ success: installResult.success,
72
+ durationMs: installResult.durationMs,
73
+ confidence: detection.confidence,
74
+ });
75
+ }
76
+ else {
77
+ result.installed = true;
78
+ result.installMessage = 'All plugins already loaded';
79
+ }
80
+ }
81
+ catch (error) {
82
+ const err = error instanceof Error ? error : new Error(String(error));
83
+ result.installed = false;
84
+ result.installMessage = err.message;
85
+ logError('detect-intent', 'Installation failed', err, {
86
+ plugins,
87
+ prompt: prompt.substring(0, 100),
88
+ });
89
+ }
90
+ }
91
+ }
92
+ // Output result (unless silent mode)
93
+ if (!options.silent) {
94
+ console.log(JSON.stringify(result, null, 2));
95
+ }
96
+ // Log for analytics
97
+ logInfo('detect-intent', 'Detection complete', {
98
+ detected: result.detected,
99
+ plugins: result.plugins,
100
+ confidence: result.confidence,
101
+ latencyMs: result.latencyMs,
102
+ installed: result.installed,
103
+ });
104
+ return result;
105
+ }
106
+ /**
107
+ * Create the detect-intent command for Commander
108
+ */
109
+ export function createDetectIntentCommand() {
110
+ const cmd = new Command('detect-intent');
111
+ cmd
112
+ .description('Detect SpecWeave intent from a prompt and optionally install plugins')
113
+ .argument('<prompt>', 'User prompt text to analyze')
114
+ .option('--install', 'Also install detected plugins after detection')
115
+ .option('--silent', 'Silent mode - no stdout output (for hooks)')
116
+ .option('--json', 'Output as JSON (default when not silent)')
117
+ .option('--threshold <number>', 'Confidence threshold for auto-install (0-1, default 0.6)', parseFloat)
118
+ .action(async (prompt, options) => {
119
+ try {
120
+ const result = await detectIntentCommand(prompt, options);
121
+ // Exit code: 0 if plugins detected, 1 if none
122
+ process.exit(result.detected ? 0 : 1);
123
+ }
124
+ catch (error) {
125
+ const err = error instanceof Error ? error : new Error(String(error));
126
+ if (!options.silent) {
127
+ console.error(chalk.red(`Error: ${err.message}`));
128
+ }
129
+ logError('detect-intent', 'Command failed', err);
130
+ process.exit(1);
131
+ }
132
+ });
133
+ return cmd;
134
+ }
135
+ /**
136
+ * Export for direct CLI invocation
137
+ */
138
+ export async function main() {
139
+ const args = process.argv.slice(2);
140
+ // Parse arguments manually for standalone execution
141
+ let prompt = '';
142
+ let install = false;
143
+ let silent = false;
144
+ for (let i = 0; i < args.length; i++) {
145
+ if (args[i] === '--install') {
146
+ install = true;
147
+ }
148
+ else if (args[i] === '--silent') {
149
+ silent = true;
150
+ }
151
+ else if (!args[i].startsWith('--')) {
152
+ prompt = args[i];
153
+ }
154
+ }
155
+ if (!prompt) {
156
+ if (!silent) {
157
+ console.error('Usage: specweave detect-intent <prompt> [--install] [--silent]');
158
+ console.error('');
159
+ console.error('Examples:');
160
+ console.error(' specweave detect-intent "release npm version"');
161
+ console.error(' specweave detect-intent "deploy to kubernetes" --install');
162
+ console.error(' specweave detect-intent "create react component" --install --silent');
163
+ }
164
+ process.exit(1);
165
+ }
166
+ const result = await detectIntentCommand(prompt, { install, silent });
167
+ process.exit(result.detected ? 0 : 1);
168
+ }
169
+ //# sourceMappingURL=detect-intent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-intent.js","sourceRoot":"","sources":["../../../../src/cli/commands/detect-intent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAoB,MAAM,6CAA6C,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAC;AAEvF,4DAA4D;AAC5D,MAAM,yBAAyB,GAAG,GAAG,CAAC;AA8BtC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAc,EACd,UAA+B,EAAE;IAEjC,MAAM,SAAS,GAAG,WAAW,CAA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OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACjE,OAAO,CAAC,KAAK,CAAC,4DAA4D,CAAC,CAAC;YAC5E,OAAO,CAAC,KAAK,CAAC,uEAAuE,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACtE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -1,9 +1,54 @@
1
- #!/usr/bin/env node
2
1
  /**
3
2
  * Detect Project CLI
4
3
  *
5
- * Detects which project (backend, frontend, mobile, etc.) a feature belongs to
6
- * based on keywords in the increment name or description.
4
+ * Two modes of operation:
5
+ * 1. FILE-BASED (default): Analyzes project files to detect type (React, Express, K8s, etc.)
6
+ * and suggests plugins to install.
7
+ * Usage: specweave detect-project [path]
8
+ *
9
+ * 2. NAME-BASED (legacy): Detects which project config an increment name belongs to.
10
+ * Usage: specweave detect-project --name "increment name"
11
+ *
12
+ * @module cli/commands/detect-project
13
+ */
14
+ import { Command } from 'commander';
15
+ export interface DetectProjectOptions {
16
+ /** Increment name for legacy name-based detection */
17
+ name?: string;
18
+ /** Description for legacy name-based detection */
19
+ description?: string;
20
+ /** Also install detected plugins after detection */
21
+ install?: boolean;
22
+ /** Silent mode - no stdout output (for hooks) */
23
+ silent?: boolean;
24
+ }
25
+ export interface DetectProjectResult {
26
+ /** Detection mode used */
27
+ mode: 'file-based' | 'name-based';
28
+ /** Detected project types (react, express, etc.) */
29
+ types: string[];
30
+ /** Recommended plugins to install */
31
+ plugins: string[];
32
+ /** Detection latency in milliseconds */
33
+ latencyMs?: number;
34
+ /** Whether plugins were installed (when --install used) */
35
+ installed?: boolean;
36
+ /** Installation result message (when --install used) */
37
+ installMessage?: string;
38
+ /** Legacy: detected project name from config (name-based mode only) */
39
+ project?: string;
40
+ /** Legacy: project display name (name-based mode only) */
41
+ projectName?: string;
42
+ /** Legacy: confidence score (name-based mode only) */
43
+ confidence?: number;
44
+ }
45
+ /**
46
+ * Main detect-project command handler
47
+ */
48
+ export declare function detectProjectCommand(pathOrNothing: string | undefined, options?: DetectProjectOptions): Promise<DetectProjectResult>;
49
+ /**
50
+ * Create the detect-project command for Commander
7
51
  */
8
- export {};
52
+ export declare function createDetectProjectCommand(): Command;
53
+ export { detectProjectCommand as main };
9
54
  //# sourceMappingURL=detect-project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"detect-project.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/detect-project.ts"],"names":[],"mappings":";AAEA;;;;;GAKG"}
1
+ {"version":3,"file":"detect-project.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/detect-project.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,MAAM,WAAW,oBAAoB;IACnC,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,0BAA0B;IAC1B,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC;IAClC,oDAAoD;IACpD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,qCAAqC;IACrC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wDAAwD;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAmHD;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CA2B9B;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,OAAO,CA6BpD;AAID,OAAO,EAAE,oBAAoB,IAAI,IAAI,EAAE,CAAC"}