specweave 0.26.3 → 0.26.4

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 (41) hide show
  1. package/CLAUDE.md +172 -1413
  2. package/dist/src/cli/commands/plan/plan-orchestrator.js +2 -2
  3. package/dist/src/cli/commands/plan/plan-orchestrator.js.map +1 -1
  4. package/dist/src/cli/helpers/issue-tracker/github-multi-repo.d.ts.map +1 -1
  5. package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js +147 -55
  6. package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js.map +1 -1
  7. package/dist/src/config/types.d.ts +203 -1208
  8. package/dist/src/config/types.d.ts.map +1 -1
  9. package/dist/src/core/increment/completion-validator.d.ts +4 -0
  10. package/dist/src/core/increment/completion-validator.d.ts.map +1 -1
  11. package/dist/src/core/increment/completion-validator.js +36 -0
  12. package/dist/src/core/increment/completion-validator.js.map +1 -1
  13. package/dist/src/core/living-docs/living-docs-sync.d.ts.map +1 -1
  14. package/dist/src/core/living-docs/living-docs-sync.js +47 -13
  15. package/dist/src/core/living-docs/living-docs-sync.js.map +1 -1
  16. package/dist/src/core/us-sync-throttle.d.ts +113 -0
  17. package/dist/src/core/us-sync-throttle.d.ts.map +1 -0
  18. package/dist/src/core/us-sync-throttle.js +195 -0
  19. package/dist/src/core/us-sync-throttle.js.map +1 -0
  20. package/dist/src/init/architecture/types.d.ts +33 -140
  21. package/dist/src/init/architecture/types.d.ts.map +1 -1
  22. package/dist/src/init/compliance/types.d.ts +30 -27
  23. package/dist/src/init/compliance/types.d.ts.map +1 -1
  24. package/dist/src/init/repo/types.d.ts +11 -34
  25. package/dist/src/init/repo/types.d.ts.map +1 -1
  26. package/dist/src/init/research/src/config/types.d.ts +15 -82
  27. package/dist/src/init/research/src/config/types.d.ts.map +1 -1
  28. package/dist/src/init/research/types.d.ts +38 -93
  29. package/dist/src/init/research/types.d.ts.map +1 -1
  30. package/dist/src/init/team/types.d.ts +4 -42
  31. package/dist/src/init/team/types.d.ts.map +1 -1
  32. package/dist/src/utils/external-tool-drift-detector.d.ts +76 -0
  33. package/dist/src/utils/external-tool-drift-detector.d.ts.map +1 -0
  34. package/dist/src/utils/external-tool-drift-detector.js +235 -0
  35. package/dist/src/utils/external-tool-drift-detector.js.map +1 -0
  36. package/package.json +4 -4
  37. package/plugins/specweave/hooks/post-task-completion.sh +6 -6
  38. package/plugins/specweave/hooks/pre-increment-start.sh +6 -1
  39. package/plugins/specweave/lib/hooks/us-completion-orchestrator.js +62 -89
  40. package/plugins/specweave/lib/hooks/us-completion-orchestrator.ts +215 -0
  41. package/plugins/specweave-release/hooks/post-task-completion.sh +5 -1
@@ -1,96 +1,67 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * User Story Completion Orchestrator
4
- *
5
- * Orchestrates the sync cascade when user stories become complete:
6
- * 1. Detect newly completed user stories (all ACs satisfied)
7
- * 2. Update living docs for completed USs
8
- * 3. Trigger external tool sync (GitHub/JIRA/ADO)
9
- *
10
- * CRITICAL: This is the bridge between AC-level completion and US-level sync.
11
- * Called by consolidated-sync.js after AC sync completes.
12
- *
13
- * Architecture:
14
- * - Uses USCompletionDetector to find newly completed USs
15
- * - Uses LivingDocsSync to update living docs (which triggers external tools)
16
- * - Non-blocking: Errors logged but don't break workflow
17
- *
18
- * Integration:
19
- * - Called from consolidated-sync.js (OPERATION 6)
20
- * - Runs after AC sync (ensures ACs are up-to-date)
21
- * - Skipped if SKIP_US_SYNC=true (performance optimization)
22
- */
23
-
24
- // Import REAL implementations
25
- import { USCompletionDetector } from '../../../../dist/src/core/us-completion-detector.js';
26
- import { LivingDocsSync } from '../../../../dist/src/core/living-docs/living-docs-sync.js';
27
- import { consoleLogger } from '../vendor/utils/logger.js';
28
-
29
- /**
30
- * Detect and sync newly completed user stories
31
- *
32
- * @param incrementId - Increment ID (e.g., "0053-safe-feature-deletion")
33
- * @returns Result object with success status and sync details
34
- */
35
- export async function syncCompletedUserStories(incrementId) {
2
+ import { USCompletionDetector } from "../../../../dist/src/core/us-completion-detector.js";
3
+ import { LivingDocsSync } from "../../../../dist/src/core/living-docs/living-docs-sync.js";
4
+ import { USSyncThrottle } from "../../../../dist/src/core/us-sync-throttle.js";
5
+ import { consoleLogger } from "../vendor/utils/logger.js";
6
+ async function syncCompletedUserStories(incrementId) {
36
7
  try {
37
- console.log(`\nšŸŽÆ [6/6] Detecting completed user stories for ${incrementId}...`);
38
-
8
+ console.log(`
9
+ \u{1F3AF} [6/6] Detecting completed user stories for ${incrementId}...`);
39
10
  const projectRoot = process.cwd();
40
-
41
- // Skip if disabled (performance optimization)
42
- if (process.env.SKIP_US_SYNC === 'true') {
43
- console.log('ā„¹ļø User story sync skipped (SKIP_US_SYNC=true)');
44
- return { success: true, message: 'Sync skipped', skipped: true };
11
+ const throttle = USSyncThrottle.getInstance({ projectRoot });
12
+ if (throttle.shouldSkipSync(incrementId)) {
13
+ const timeSinceLastSync = throttle.getTimeSinceLastSync(incrementId);
14
+ const secondsRemaining = Math.ceil((6e4 - timeSinceLastSync) / 1e3);
15
+ console.log(`\u23ED\uFE0F US sync throttled (last sync ${Math.floor(timeSinceLastSync / 1e3)}s ago)`);
16
+ console.log(` \u2139\uFE0F Sync will be available in ${secondsRemaining}s`);
17
+ console.log(` \u{1F4A1} Manual sync: /specweave:sync-progress ${incrementId}`);
18
+ return {
19
+ success: true,
20
+ message: "Sync throttled",
21
+ throttled: true,
22
+ skipped: true
23
+ };
45
24
  }
46
-
47
- // 1. Initialize US completion detector
48
25
  const detector = new USCompletionDetector(projectRoot, {
49
26
  logger: consoleLogger
50
27
  });
51
-
52
- // 2. Detect newly completed user stories
53
28
  const newlyCompleted = await detector.getNewlyCompletedUSs(incrementId);
54
-
55
29
  if (newlyCompleted.length === 0) {
56
- console.log('āœ… No newly completed user stories detected (no sync needed)');
57
- return { success: true, newlyCompleted: [], message: 'No new completions' };
30
+ console.log("\u2705 No newly completed user stories detected (no sync needed)");
31
+ return {
32
+ success: true,
33
+ newlyCompleted: [],
34
+ message: "No new completions"
35
+ };
58
36
  }
59
-
60
- console.log(`\nšŸŽ‰ DETECTED ${newlyCompleted.length} NEWLY COMPLETED USER STORIES:`);
37
+ console.log(`
38
+ \u{1F389} DETECTED ${newlyCompleted.length} NEWLY COMPLETED USER STORIES:`);
61
39
  for (const us of newlyCompleted) {
62
40
  console.log(` ${us.usId}: ${us.title} (${us.completedACs}/${us.totalACs} ACs complete)`);
63
41
  }
64
-
65
- // 3. Save completion state (mark USs as complete to prevent re-sync)
66
42
  const allCompletions = await detector.detectCompletions(incrementId);
67
43
  await detector.saveCompletionState(incrementId, allCompletions);
68
-
69
- // 4. Trigger living docs sync (which will sync to external tools)
70
- console.log(`\nšŸ“š Syncing living docs for ${incrementId}...`);
71
-
44
+ console.log(`
45
+ \u{1F4DA} Syncing living docs for ${incrementId}...`);
72
46
  const livingDocsSync = new LivingDocsSync(projectRoot, {
73
47
  logger: consoleLogger
74
48
  });
75
-
76
49
  const syncResult = await livingDocsSync.syncIncrement(incrementId);
77
-
78
50
  if (syncResult.success) {
79
- console.log(`āœ… Living docs synced successfully`);
51
+ console.log(`\u2705 Living docs synced successfully`);
80
52
  console.log(` Feature: ${syncResult.featureId}`);
81
53
  console.log(` Files updated: ${syncResult.filesCreated.length + syncResult.filesUpdated.length}`);
82
-
83
- // External tool sync happens automatically inside livingDocsSync.syncIncrement()
84
- // It calls syncToExternalTools() which handles GitHub/JIRA/ADO
85
- console.log(`\nšŸ“” External tool sync completed (GitHub/JIRA/ADO updated if configured)`);
54
+ console.log(`
55
+ \u{1F4E1} External tool sync completed (GitHub/JIRA/ADO updated if configured)`);
56
+ throttle.recordSync(incrementId);
57
+ console.log(` \u23F1\uFE0F Throttle recorded (next sync allowed in 60s)`);
86
58
  } else {
87
- console.warn(`āš ļø Living docs sync had errors (see logs)`);
88
- console.warn(` Errors: ${syncResult.errors.join(', ')}`);
59
+ console.warn(`\u26A0\uFE0F Living docs sync had errors (see logs)`);
60
+ console.warn(` Errors: ${syncResult.errors.join(", ")}`);
89
61
  }
90
-
91
62
  return {
92
63
  success: true,
93
- newlyCompleted: newlyCompleted.map(us => ({
64
+ newlyCompleted: newlyCompleted.map((us) => ({
94
65
  usId: us.usId,
95
66
  title: us.title,
96
67
  totalACs: us.totalACs,
@@ -99,37 +70,39 @@ export async function syncCompletedUserStories(incrementId) {
99
70
  syncResult,
100
71
  message: `${newlyCompleted.length} user stories synced`
101
72
  };
102
-
103
73
  } catch (error) {
104
- // Non-blocking: Log error but don't break workflow
105
- console.error('āŒ Error in US completion orchestrator:', error.message);
106
- return { success: false, error: error.message };
74
+ console.error("\u274C Error in US completion orchestrator:", error.message);
75
+ return {
76
+ success: false,
77
+ error: error.message,
78
+ message: "Orchestrator error"
79
+ };
107
80
  }
108
81
  }
109
-
110
- // CLI Interface (for manual testing)
111
82
  const isMainModule = import.meta.url === `file://${process.argv[1]}`;
112
83
  if (isMainModule) {
113
84
  const incrementId = process.argv[2];
114
-
115
85
  if (!incrementId) {
116
- console.error('Usage: node us-completion-orchestrator.js <increment-id>');
117
- console.error('Example: node us-completion-orchestrator.js 0053-safe-feature-deletion');
86
+ console.error("Usage: node us-completion-orchestrator.js <increment-id>");
87
+ console.error("Example: node us-completion-orchestrator.js 0053-safe-feature-deletion");
118
88
  process.exit(1);
119
89
  }
120
-
121
- syncCompletedUserStories(incrementId)
122
- .then(result => {
123
- if (result.success) {
124
- console.log('\nāœ… US completion orchestration completed successfully');
125
- process.exit(0);
126
- } else {
127
- console.error('\nāŒ US completion orchestration failed');
128
- process.exit(1);
90
+ syncCompletedUserStories(incrementId).then((result) => {
91
+ if (result.success) {
92
+ console.log("\n\u2705 US completion orchestration completed successfully");
93
+ if (result.throttled) {
94
+ console.log(" (Throttled - no sync performed)");
129
95
  }
130
- })
131
- .catch(error => {
132
- console.error('\nāŒ Fatal error:', error);
96
+ process.exit(0);
97
+ } else {
98
+ console.error("\n\u274C US completion orchestration failed");
133
99
  process.exit(1);
134
- });
100
+ }
101
+ }).catch((error) => {
102
+ console.error("\n\u274C Fatal error:", error);
103
+ process.exit(1);
104
+ });
135
105
  }
106
+ export {
107
+ syncCompletedUserStories
108
+ };
@@ -0,0 +1,215 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * User Story Completion Orchestrator (v0.26.1 - Throttle Integration)
4
+ *
5
+ * Orchestrates the sync cascade when user stories become complete:
6
+ * 1. Detect newly completed user stories (all ACs satisfied)
7
+ * 2. Update living docs for completed USs
8
+ * 3. Trigger external tool sync (GitHub/JIRA/ADO)
9
+ *
10
+ * CRITICAL: This is the bridge between AC-level completion and US-level sync.
11
+ * Called by consolidated-sync.js after AC sync completes.
12
+ *
13
+ * Architecture (v0.26.1 Changes):
14
+ * - Uses USCompletionDetector to find newly completed USs
15
+ * - Uses LivingDocsSync to update living docs (which triggers external tools)
16
+ * - **NEW**: Uses USSyncThrottle to prevent spam (60s window)
17
+ * - Non-blocking: Errors logged but don't break workflow
18
+ *
19
+ * Integration:
20
+ * - Called from consolidated-sync.js (OPERATION 6)
21
+ * - Runs after AC sync (ensures ACs are up-to-date)
22
+ * - ~~Skipped if SKIP_US_SYNC=true (REMOVED in v0.26.1)~~
23
+ * - **NEW**: Throttled to once per 60 seconds per increment
24
+ *
25
+ * Safety:
26
+ * - fs.writeFile() verified to NOT trigger Claude Code hooks (test confirmed)
27
+ * - SKIP_EXTERNAL_SYNC still guards actual external tool sync
28
+ * - Throttle prevents rapid sync spam
29
+ * - Circuit breaker active at hook level
30
+ *
31
+ * See:
32
+ * - FS-WRITEFILE-HOOK-TEST-RESULTS-2025-11-24.md (test results)
33
+ * - ADR-0129: US Sync Guard Rails (long-term fix strategy)
34
+ * - src/core/us-sync-throttle.ts (throttle implementation)
35
+ */
36
+
37
+ // Import REAL implementations
38
+ import { USCompletionDetector } from '../../../../dist/src/core/us-completion-detector.js';
39
+ import { LivingDocsSync } from '../../../../dist/src/core/living-docs/living-docs-sync.js';
40
+ import { USSyncThrottle } from '../../../../dist/src/core/us-sync-throttle.js';
41
+ import { consoleLogger } from '../vendor/utils/logger.js';
42
+
43
+ export interface USSyncResult {
44
+ success: boolean;
45
+ newlyCompleted?: Array<{
46
+ usId: string;
47
+ title: string;
48
+ totalACs: number;
49
+ completedACs: number;
50
+ }>;
51
+ syncResult?: any;
52
+ message: string;
53
+ skipped?: boolean;
54
+ throttled?: boolean;
55
+ error?: string;
56
+ }
57
+
58
+ /**
59
+ * Detect and sync newly completed user stories
60
+ *
61
+ * v0.26.1: Now includes smart throttling (60s window) to prevent spam
62
+ *
63
+ * @param incrementId - Increment ID (e.g., "0053-safe-feature-deletion")
64
+ * @returns Result object with success status and sync details
65
+ */
66
+ export async function syncCompletedUserStories(incrementId: string): Promise<USSyncResult> {
67
+ try {
68
+ console.log(`\nšŸŽÆ [6/6] Detecting completed user stories for ${incrementId}...`);
69
+
70
+ const projectRoot = process.cwd();
71
+
72
+ // ========================================================================
73
+ // THROTTLE CHECK (v0.26.1 - NEW!)
74
+ // ========================================================================
75
+ // Prevent spam: Limit US sync to once per 60 seconds per increment
76
+ // Rationale:
77
+ // - Rapid task completions (10 in 5s) → 10 US sync attempts
78
+ // - Without throttle: 100+ GitHub API calls (rate limit risk)
79
+ // - With throttle: 1 US sync, 9 throttled (10 GitHub calls)
80
+ //
81
+ // Safety:
82
+ // - fs.writeFile() confirmed to NOT trigger hooks (no infinite loop risk)
83
+ // - SKIP_EXTERNAL_SYNC still guards external tool sync layer
84
+ // - Users can manually sync if needed: /specweave:sync-progress
85
+ //
86
+ // Trade-off:
87
+ // - Potential 60s delay for US completion visibility
88
+ // - Acceptable for UX (tasks complete immediately, US sync deferred)
89
+
90
+ const throttle = USSyncThrottle.getInstance({ projectRoot });
91
+
92
+ if (throttle.shouldSkipSync(incrementId)) {
93
+ const timeSinceLastSync = throttle.getTimeSinceLastSync(incrementId);
94
+ const secondsRemaining = Math.ceil((60000 - timeSinceLastSync) / 1000);
95
+
96
+ console.log(`ā­ļø US sync throttled (last sync ${Math.floor(timeSinceLastSync / 1000)}s ago)`);
97
+ console.log(` ā„¹ļø Sync will be available in ${secondsRemaining}s`);
98
+ console.log(` šŸ’” Manual sync: /specweave:sync-progress ${incrementId}`);
99
+
100
+ return {
101
+ success: true,
102
+ message: 'Sync throttled',
103
+ throttled: true,
104
+ skipped: true
105
+ };
106
+ }
107
+
108
+ // 1. Initialize US completion detector
109
+ const detector = new USCompletionDetector(projectRoot, {
110
+ logger: consoleLogger
111
+ });
112
+
113
+ // 2. Detect newly completed user stories
114
+ const newlyCompleted = await detector.getNewlyCompletedUSs(incrementId);
115
+
116
+ if (newlyCompleted.length === 0) {
117
+ console.log('āœ… No newly completed user stories detected (no sync needed)');
118
+
119
+ return {
120
+ success: true,
121
+ newlyCompleted: [],
122
+ message: 'No new completions'
123
+ };
124
+ }
125
+
126
+ console.log(`\nšŸŽ‰ DETECTED ${newlyCompleted.length} NEWLY COMPLETED USER STORIES:`);
127
+ for (const us of newlyCompleted) {
128
+ console.log(` ${us.usId}: ${us.title} (${us.completedACs}/${us.totalACs} ACs complete)`);
129
+ }
130
+
131
+ // 3. Save completion state (mark USs as complete to prevent re-sync)
132
+ const allCompletions = await detector.detectCompletions(incrementId);
133
+ await detector.saveCompletionState(incrementId, allCompletions);
134
+
135
+ // 4. Trigger living docs sync (which will sync to external tools)
136
+ console.log(`\nšŸ“š Syncing living docs for ${incrementId}...`);
137
+
138
+ const livingDocsSync = new LivingDocsSync(projectRoot, {
139
+ logger: consoleLogger
140
+ });
141
+
142
+ const syncResult = await livingDocsSync.syncIncrement(incrementId);
143
+
144
+ if (syncResult.success) {
145
+ console.log(`āœ… Living docs synced successfully`);
146
+ console.log(` Feature: ${syncResult.featureId}`);
147
+ console.log(` Files updated: ${syncResult.filesCreated.length + syncResult.filesUpdated.length}`);
148
+
149
+ // External tool sync happens automatically inside livingDocsSync.syncIncrement()
150
+ // It calls syncToExternalTools() which handles GitHub/JIRA/ADO
151
+ console.log(`\nšŸ“” External tool sync completed (GitHub/JIRA/ADO updated if configured)`);
152
+
153
+ // Record successful sync for throttling
154
+ throttle.recordSync(incrementId);
155
+ console.log(` ā±ļø Throttle recorded (next sync allowed in 60s)`);
156
+ } else {
157
+ console.warn(`āš ļø Living docs sync had errors (see logs)`);
158
+ console.warn(` Errors: ${syncResult.errors.join(', ')}`);
159
+
160
+ // Don't record sync on failure (allow immediate retry)
161
+ }
162
+
163
+ return {
164
+ success: true,
165
+ newlyCompleted: newlyCompleted.map(us => ({
166
+ usId: us.usId,
167
+ title: us.title,
168
+ totalACs: us.totalACs,
169
+ completedACs: us.completedACs
170
+ })),
171
+ syncResult,
172
+ message: `${newlyCompleted.length} user stories synced`
173
+ };
174
+
175
+ } catch (error: any) {
176
+ // Non-blocking: Log error but don't break workflow
177
+ console.error('āŒ Error in US completion orchestrator:', error.message);
178
+
179
+ return {
180
+ success: false,
181
+ error: error.message,
182
+ message: 'Orchestrator error'
183
+ };
184
+ }
185
+ }
186
+
187
+ // CLI Interface (for manual testing)
188
+ const isMainModule = import.meta.url === `file://${process.argv[1]}`;
189
+ if (isMainModule) {
190
+ const incrementId = process.argv[2];
191
+
192
+ if (!incrementId) {
193
+ console.error('Usage: node us-completion-orchestrator.js <increment-id>');
194
+ console.error('Example: node us-completion-orchestrator.js 0053-safe-feature-deletion');
195
+ process.exit(1);
196
+ }
197
+
198
+ syncCompletedUserStories(incrementId)
199
+ .then(result => {
200
+ if (result.success) {
201
+ console.log('\nāœ… US completion orchestration completed successfully');
202
+ if (result.throttled) {
203
+ console.log(' (Throttled - no sync performed)');
204
+ }
205
+ process.exit(0);
206
+ } else {
207
+ console.error('\nāŒ US completion orchestration failed');
208
+ process.exit(1);
209
+ }
210
+ })
211
+ .catch(error => {
212
+ console.error('\nāŒ Fatal error:', error);
213
+ process.exit(1);
214
+ });
215
+ }
@@ -6,7 +6,11 @@
6
6
  #
7
7
  # Integration: plugins/specweave-release/hooks/hooks.json
8
8
 
9
- set -euo pipefail
9
+ # CRITICAL (v0.25.2): NEVER use 'set -e' in hooks - causes Claude Code crashes
10
+ # See: CLAUDE.md Section 9a (Hook Safety Checklist), ADR-0060 (Hook Performance)
11
+ set +e # Allow commands to fail without terminating script
12
+ set -u # Fail on undefined variables
13
+ set -o pipefail # Fail if any command in pipeline fails
10
14
 
11
15
  # Constants
12
16
  SPECWEAVE_ROOT="${SPECWEAVE_ROOT:-$(pwd)}"