universal-dev-standards 6.15.0 → 6.16.0-beta.2

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/bin/uds.js +2 -0
  2. package/bundled/locales/zh-CN/CHANGELOG.md +34 -4
  3. package/bundled/locales/zh-CN/CLAUDE.md +2 -2
  4. package/bundled/locales/zh-CN/README.md +17 -14
  5. package/bundled/locales/zh-CN/SECURITY.md +1 -0
  6. package/bundled/locales/zh-CN/docs/CHEATSHEET.md +1 -1
  7. package/bundled/locales/zh-CN/docs/CLI-INIT-OPTIONS.md +24 -2
  8. package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +3 -1
  9. package/bundled/locales/zh-TW/CHANGELOG.md +34 -4
  10. package/bundled/locales/zh-TW/CLAUDE.md +2 -2
  11. package/bundled/locales/zh-TW/README.md +17 -14
  12. package/bundled/locales/zh-TW/SECURITY.md +1 -0
  13. package/bundled/locales/zh-TW/docs/CHEATSHEET.md +1 -1
  14. package/bundled/locales/zh-TW/docs/CLI-INIT-OPTIONS.md +24 -2
  15. package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +3 -1
  16. package/package.json +3 -3
  17. package/src/commands/skills.js +9 -0
  18. package/src/commands/update.js +223 -2
  19. package/src/reconciler/desired-state-calculator.js +11 -2
  20. package/src/utils/optional-skills-report.js +86 -0
  21. package/src/utils/optional-skills.js +20 -0
  22. package/src/utils/skill-selection.js +137 -0
  23. package/src/utils/skills-installer.js +11 -4
  24. package/standards-registry.json +7 -7
  25. package/src/core/agent-communication-protocol.js +0 -257
  26. package/src/flow/condition-evaluator.js +0 -86
  27. package/src/flow/flow-bundler.js +0 -80
  28. package/src/flow/flow-commands.js +0 -107
  29. package/src/flow/flow-engine.js +0 -154
  30. package/src/flow/flow-inheritance.js +0 -100
  31. package/src/flow/flow-parser.js +0 -104
  32. package/src/flow/flow-validator.js +0 -37
  33. package/src/flow/gate-checker.js +0 -82
  34. package/src/flow/gate-loader.js +0 -52
  35. package/src/missions/MissionManager.js +0 -533
  36. package/src/utils/e2e-analyzer.js +0 -471
  37. package/src/utils/e2e-detector.js +0 -132
  38. package/src/utils/hook-stats.js +0 -151
  39. package/src/utils/workflow-executor.js +0 -870
  40. package/src/utils/workflows-installer.js +0 -545
  41. package/src/vibe/auto-sweep.js +0 -349
@@ -1,471 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync } from 'fs';
2
- import { dirname, basename, join } from 'path';
3
-
4
- /**
5
- * Parse Gherkin feature content and extract scenarios with their steps
6
- * @param {string} content - Feature file content
7
- * @returns {{ name: string, steps: string[] }[]}
8
- */
9
- export function parseFeatureScenarios(content) {
10
- const scenarios = [];
11
- const lines = content.split('\n');
12
- let current = null;
13
-
14
- for (const raw of lines) {
15
- const line = raw.trim();
16
-
17
- if (line.startsWith('Scenario:') || line.startsWith('Scenario Outline:')) {
18
- if (current) scenarios.push(current);
19
- const name = line.replace(/^Scenario( Outline)?:\s*/, '');
20
- current = { name, steps: [] };
21
- } else if (current && /^(Given|When|Then|And|But)\s/.test(line)) {
22
- current.steps.push(line);
23
- }
24
- }
25
-
26
- if (current) scenarios.push(current);
27
- return scenarios;
28
- }
29
-
30
- // Keywords that indicate different test levels
31
- const E2E_KEYWORDS = [
32
- 'user', 'login', 'logged in', 'navigat', 'page', 'click', 'submit',
33
- 'form', 'display', 'screen', 'browser', 'UI', 'dashboard',
34
- 'runs "', 'executes', 'command', 'uds ', 'CLI',
35
- 'checkout', 'cart', 'registration', 'sign up'
36
- ];
37
-
38
- const INTEGRATION_KEYWORDS = [
39
- 'API', 'database', 'DB', 'request', 'response', 'endpoint',
40
- 'service', 'gateway', 'handler', 'writes to', 'reads from',
41
- 'POST', 'GET', 'PUT', 'DELETE', 'persist', 'calls'
42
- ];
43
-
44
- const UNIT_KEYWORDS = [
45
- 'sorted', 'calculated', 'formatted', 'parsed', 'validated',
46
- 'result is', 'output', 'returns', 'algorithm', 'compute',
47
- 'string', 'number', 'list', 'array', 'object',
48
- 'true', 'false', 'pattern', 'matches'
49
- ];
50
-
51
- /**
52
- * Classify a single scenario into e2e-suitable, unit-suitable, or integration-suitable
53
- * @param {{ name: string, steps: string[] }} scenario
54
- * @returns {{ category: string, reason: string }}
55
- */
56
- export function classifyScenario(scenario) {
57
- const text = [scenario.name, ...scenario.steps].join(' ').toLowerCase();
58
-
59
- // Score each category
60
- const e2eScore = scoreKeywords(text, E2E_KEYWORDS);
61
- const integrationScore = scoreKeywords(text, INTEGRATION_KEYWORDS);
62
- const unitScore = scoreKeywords(text, UNIT_KEYWORDS);
63
-
64
- // Multi-step flows (4+ steps) lean toward E2E
65
- const stepBonus = scenario.steps.length >= 4 ? 2 : 0;
66
- const adjustedE2e = e2eScore + stepBonus;
67
-
68
- if (adjustedE2e > integrationScore && adjustedE2e > unitScore) {
69
- return {
70
- category: 'e2e-suitable',
71
- reason: 'Multi-step user flow or UI interaction detected'
72
- };
73
- }
74
-
75
- if (integrationScore > unitScore) {
76
- return {
77
- category: 'integration-suitable',
78
- reason: 'Cross-component interaction without user-facing flow'
79
- };
80
- }
81
-
82
- return {
83
- category: 'unit-suitable',
84
- reason: 'Pure logic, computation, or single-function behavior'
85
- };
86
- }
87
-
88
- function scoreKeywords(text, keywords) {
89
- return keywords.reduce((score, kw) => {
90
- return score + (text.includes(kw.toLowerCase()) ? 1 : 0);
91
- }, 0);
92
- }
93
-
94
- /**
95
- * Analyze a feature file: parse, classify all scenarios
96
- * @param {string} filePath - Path to .feature file
97
- * @returns {{ classifications: object[], message?: string, error?: string, availableFiles?: string[] }}
98
- */
99
- export function analyzeFeatureFile(filePath) {
100
- if (!existsSync(filePath)) {
101
- const dir = dirname(filePath);
102
- let availableFiles;
103
- try {
104
- const files = readdirSync(dir).filter(f => f.endsWith('.feature'));
105
- if (files.length > 0) {
106
- availableFiles = files;
107
- }
108
- } catch {
109
- // directory doesn't exist
110
- }
111
-
112
- return {
113
- error: `找不到檔案:${filePath}`,
114
- classifications: [],
115
- ...(availableFiles ? { availableFiles } : {})
116
- };
117
- }
118
-
119
- const content = readFileSync(filePath, 'utf-8');
120
- const scenarios = parseFeatureScenarios(content);
121
-
122
- if (scenarios.length === 0) {
123
- return {
124
- classifications: [],
125
- message: '此 feature 檔案不包含可分析的 Scenario'
126
- };
127
- }
128
-
129
- const classifications = scenarios.map(s => ({
130
- scenario: s.name,
131
- ...classifyScenario(s)
132
- }));
133
-
134
- return { classifications };
135
- }
136
-
137
- // ============================================================
138
- // REQ-3: 既有模式分析
139
- // ============================================================
140
-
141
- /**
142
- * Analyze existing E2E test files to extract coding patterns
143
- * @param {string} e2eDir - Path to E2E test directory
144
- * @returns {{ imports: string[], helpers: string[], testFramework: string, summary: string, useDefault: boolean }}
145
- */
146
- export function analyzeExistingPatterns(e2eDir) {
147
- const empty = { imports: [], helpers: [], testFramework: 'unknown', summary: '', useDefault: true };
148
-
149
- if (!existsSync(e2eDir)) return empty;
150
-
151
- const testFiles = safeReaddir(e2eDir).filter(f => f.endsWith('.test.js') || f.endsWith('.test.ts'));
152
- if (testFiles.length === 0) return empty;
153
-
154
- const importSources = new Set();
155
- const helpers = new Set();
156
- let testFramework = 'unknown';
157
-
158
- for (const file of testFiles) {
159
- const content = readFileSync(join(e2eDir, file), 'utf-8');
160
-
161
- // Extract import sources (non-framework)
162
- const importMatches = content.matchAll(/from\s+['"]([^'"]+)['"]/g);
163
- for (const m of importMatches) {
164
- const src = m[1];
165
- if (!src.includes('vitest') && !src.includes('jest') && !src.includes('mocha')) {
166
- importSources.add(src);
167
- }
168
- if (src.includes('vitest')) testFramework = 'vitest';
169
- else if (src.includes('jest')) testFramework = 'jest';
170
- }
171
-
172
- // Extract named imports (helpers)
173
- const namedImports = content.matchAll(/import\s*\{([^}]+)\}\s*from\s*['"](?!vitest|jest)[^'"]+['"]/g);
174
- for (const m of namedImports) {
175
- m[1].split(',').map(h => h.trim()).filter(Boolean).forEach(h => helpers.add(h));
176
- }
177
- }
178
-
179
- const importList = [...importSources];
180
- const helperList = [...helpers];
181
-
182
- return {
183
- imports: importList,
184
- helpers: helperList,
185
- testFramework,
186
- summary: `Found ${testFiles.length} E2E tests using ${testFramework}. Common imports: ${importList.join(', ')}`,
187
- useDefault: false
188
- };
189
- }
190
-
191
- // ============================================================
192
- // REQ-4: E2E 測試骨架生成
193
- // ============================================================
194
-
195
- /**
196
- * Detect the project ecosystem based on manifest files
197
- * @param {string} [projectPath='.'] - Path to the project root
198
- * @returns {'node'|'python'|'go'|'java'|'rust'|'ruby'}
199
- */
200
- function detectEcosystem(projectPath = '.') {
201
- const p = (f) => join(projectPath, f);
202
- if (existsSync(p('package.json'))) return 'node';
203
- if (existsSync(p('requirements.txt')) || existsSync(p('pyproject.toml'))) return 'python';
204
- if (existsSync(p('go.mod'))) return 'go';
205
- if (existsSync(p('pom.xml')) || existsSync(p('build.gradle'))) return 'java';
206
- if (existsSync(p('Cargo.toml'))) return 'rust';
207
- if (existsSync(p('Gemfile'))) return 'ruby';
208
- return 'node'; // fallback
209
- }
210
-
211
- const SKELETON_TEMPLATES = {
212
- vitest: {
213
- header: (specId) => `/**
214
- * [Generated] E2E tests for ${specId}
215
- * [TODO] Fill in test implementations
216
- */
217
-
218
- import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
219
- `,
220
- setup: () => `
221
- // [TODO] Setup fixtures and test data
222
- let testDir;
223
-
224
- beforeAll(async () => {
225
- // [TODO] Initialize test fixture (DB seed, temp files, etc.)
226
- });
227
-
228
- beforeEach(async () => {
229
- // [TODO] Reset state before each test
230
- });
231
-
232
- afterEach(async () => {
233
- // [TODO] Cleanup after each test
234
- });
235
- `,
236
- test: (scenario) => `
237
- // @${scenario.specId} @${scenario.ac}
238
- it('${scenario.name}', async () => {
239
- // Arrange
240
- // [TODO] Setup test preconditions
241
-
242
- // Act
243
- // [TODO] Execute the user flow
244
-
245
- // Assert
246
- // [TODO] Verify expected outcomes
247
- });
248
- `
249
- },
250
-
251
- playwright: {
252
- header: (specId) => `/**
253
- * [Generated] E2E tests for ${specId}
254
- * [TODO] Fill in test implementations
255
- */
256
-
257
- import { test, expect } from '@playwright/test';
258
- `,
259
- setup: () => `
260
- // [TODO] Setup fixtures and test data
261
-
262
- test.beforeAll(async () => {
263
- // [TODO] Initialize test fixture (DB seed, API mock, etc.)
264
- });
265
-
266
- test.beforeEach(async ({ page }) => {
267
- // [TODO] Navigate to starting page
268
- });
269
- `,
270
- test: (scenario) => `
271
- // @${scenario.specId} @${scenario.ac}
272
- test('${scenario.name}', async ({ page }) => {
273
- // Arrange
274
- // [TODO] Setup test preconditions
275
-
276
- // Act
277
- // [TODO] Execute the user flow
278
-
279
- // Assert
280
- // [TODO] Verify expected outcomes
281
- });
282
- `
283
- },
284
-
285
- cypress: {
286
- header: (specId) => `/**
287
- * [Generated] E2E tests for ${specId}
288
- * [TODO] Fill in test implementations
289
- */
290
- `,
291
- setup: () => `
292
- // [TODO] Setup fixtures and test data
293
-
294
- before(() => {
295
- // [TODO] Initialize test fixture (DB seed, API mock, etc.)
296
- });
297
-
298
- beforeEach(() => {
299
- // [TODO] Visit starting page
300
- // cy.visit('/');
301
- });
302
- `,
303
- test: (scenario) => `
304
- // @${scenario.specId} @${scenario.ac}
305
- it('${scenario.name}', () => {
306
- // Arrange
307
- // [TODO] Setup test preconditions
308
-
309
- // Act
310
- // [TODO] Execute the user flow
311
- // cy.get('[data-testid="..."]').click();
312
-
313
- // Assert
314
- // [TODO] Verify expected outcomes
315
- // cy.contains('expected text').should('be.visible');
316
- });
317
- `
318
- },
319
-
320
- // Python (pytest-playwright)
321
- 'pytest-playwright': {
322
- header: (specId) => `# [Generated] E2E tests for ${specId}
323
- # [TODO] Fill in test implementations
324
-
325
- import pytest
326
- from playwright.sync_api import Page
327
- `,
328
- setup: () => `
329
- # [TODO] Setup fixtures and test data
330
- `,
331
- test: (scenario) => `
332
- # @${scenario.specId} @${scenario.ac}
333
- def test_${scenario.name.toLowerCase().replace(/\s+/g, '_')}(page: Page):
334
- # Arrange
335
- # [TODO] Setup test preconditions
336
-
337
- # Act
338
- # [TODO] Execute the user flow
339
-
340
- # Assert
341
- # [TODO] Verify expected outcomes
342
- `
343
- },
344
-
345
- // Go (chromedp)
346
- chromedp: {
347
- header: (specId) => `// [Generated] E2E tests for ${specId}
348
- // [TODO] Fill in test implementations
349
-
350
- package e2e_test
351
-
352
- import (
353
- \t"context"
354
- \t"testing"
355
- \t"github.com/chromedp/chromedp"
356
- )
357
- `,
358
- setup: () => `
359
- // [TODO] Setup shared test context if needed
360
- `,
361
- test: (scenario) => `
362
- // @${scenario.specId} @${scenario.ac}
363
- func Test${scenario.name.replace(/\s+/g, '')}(t *testing.T) {
364
- \tctx, cancel := chromedp.NewContext(context.Background())
365
- \tdefer cancel()
366
-
367
- \t// Arrange
368
- \t// [TODO] Setup test preconditions
369
-
370
- \t// Act
371
- \t// [TODO] Add chromedp tasks
372
-
373
- \t// Assert
374
- \t// [TODO] Verify expected outcomes
375
- }
376
- `
377
- }
378
- };
379
-
380
- /**
381
- * Generate E2E test skeleton from classified scenarios
382
- * @param {{ name: string, category: string, specId?: string, ac?: string }[]} scenarios
383
- * @param {{ framework: string }} options
384
- * @returns {string}
385
- */
386
- export function generateE2eSkeleton(scenarios, { framework = 'vitest', projectPath } = {}) {
387
- // If no framework is explicitly specified (using default), detect ecosystem and adjust
388
- const resolvedFramework = (() => {
389
- if (framework !== 'vitest') return framework; // caller specified explicitly
390
- const ecosystem = detectEcosystem(projectPath);
391
- if (ecosystem === 'python') return 'pytest-playwright';
392
- if (ecosystem === 'go') return 'chromedp';
393
- return framework;
394
- })();
395
- const template = SKELETON_TEMPLATES[resolvedFramework] || SKELETON_TEMPLATES.vitest;
396
- const specId = scenarios[0]?.specId || 'SPEC-XXX';
397
-
398
- let output = template.header(specId);
399
- output += template.setup();
400
-
401
- if (resolvedFramework === 'vitest') {
402
- output += `\ndescribe('E2E: ${specId}', () => {`;
403
- } else if (resolvedFramework === 'cypress') {
404
- output += `\ndescribe('E2E: ${specId}', () => {`;
405
- }
406
-
407
- for (const s of scenarios) {
408
- output += template.test(s);
409
- }
410
-
411
- if (resolvedFramework === 'vitest' || resolvedFramework === 'cypress') {
412
- output += '});\n';
413
- }
414
-
415
- return output;
416
- }
417
-
418
- /**
419
- * Check if a file path looks like a SDD spec file
420
- * @param {string} filePath
421
- * @returns {boolean}
422
- */
423
- export function isSpecFile(filePath) {
424
- const name = basename(filePath);
425
- return name.startsWith('SPEC-') && name.endsWith('.md');
426
- }
427
-
428
- // ============================================================
429
- // REQ-5: 覆蓋差距分析
430
- // ============================================================
431
-
432
- /**
433
- * Analyze coverage gap between BDD features and E2E tests
434
- * @param {string} featuresDir - Path to features directory
435
- * @param {string} e2eDir - Path to E2E tests directory
436
- * @returns {{ total: number, covered: number, missing: string[], suggestions: string[] }}
437
- */
438
- export function analyzeCoverageGap(featuresDir, e2eDir) {
439
- const featureFiles = safeReaddir(featuresDir).filter(f => f.endsWith('.feature'));
440
- const e2eFiles = safeReaddir(e2eDir).filter(f => f.includes('.e2e.test.') || f.includes('.e2e.spec.'));
441
-
442
- // Extract spec IDs from e2e test filenames
443
- const coveredPrefixes = new Set(
444
- e2eFiles.map(f => f.replace(/\.e2e\.(test|spec)\.(js|ts|mjs)$/, ''))
445
- );
446
-
447
- const missing = featureFiles.filter(f => {
448
- const prefix = f.replace(/\.feature$/, '');
449
- return !coveredPrefixes.has(prefix);
450
- });
451
-
452
- const suggestions = [];
453
- if (missing.length > 0) {
454
- suggestions.push(`${missing.length} feature(s) 缺少 E2E 覆蓋。執行 /ac-coverage-assistant 取得 AC 層級追蹤。`);
455
- }
456
-
457
- return {
458
- total: featureFiles.length,
459
- covered: featureFiles.length - missing.length,
460
- missing,
461
- suggestions
462
- };
463
- }
464
-
465
- function safeReaddir(dir) {
466
- try {
467
- return readdirSync(dir);
468
- } catch {
469
- return [];
470
- }
471
- }
@@ -1,132 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync } from 'fs';
2
- import { join } from 'path';
3
-
4
- const SUPPORTED_FRAMEWORKS = [
5
- // JavaScript/TypeScript
6
- 'playwright', 'cypress', 'vitest', 'webdriverio',
7
- // Python
8
- 'pytest-playwright', 'selenium-python', 'robot-framework', 'behave',
9
- // Java
10
- 'selenium-java', 'playwright-java', 'gauge',
11
- // Go
12
- 'chromedp', 'rod',
13
- // C#
14
- 'playwright-dotnet', 'selenium-dotnet',
15
- // Ruby
16
- 'capybara', 'watir',
17
- ];
18
-
19
- /**
20
- * Detect E2E testing frameworks in the project
21
- * @param {string} projectPath - Path to the project
22
- * @returns {{ detected: string[], promptRequired: boolean, options?: string[] }}
23
- */
24
- export function detectE2eFramework(projectPath) {
25
- const detected = [];
26
-
27
- // Python ecosystem detection
28
- const pythonFiles = ['requirements.txt', 'pyproject.toml'];
29
- for (const pyFile of pythonFiles) {
30
- const pyPath = join(projectPath, pyFile);
31
- if (existsSync(pyPath)) {
32
- try {
33
- const content = readFileSync(pyPath, 'utf-8');
34
- if (content.includes('pytest-playwright')) detected.push('pytest-playwright');
35
- if (content.includes('selenium')) detected.push('selenium-python');
36
- if (content.includes('robotframework')) detected.push('robot-framework');
37
- if (content.includes('behave')) detected.push('behave');
38
- } catch {
39
- // Ignore read errors
40
- }
41
- break;
42
- }
43
- }
44
-
45
- // Go ecosystem detection
46
- const goModPath = join(projectPath, 'go.mod');
47
- if (existsSync(goModPath)) {
48
- try {
49
- const content = readFileSync(goModPath, 'utf-8');
50
- if (content.includes('chromedp')) detected.push('chromedp');
51
- if (content.includes('/rod')) detected.push('rod');
52
- } catch {
53
- // Ignore read errors
54
- }
55
- }
56
-
57
- // Java ecosystem detection
58
- for (const javaFile of ['pom.xml', 'build.gradle']) {
59
- const javaPath = join(projectPath, javaFile);
60
- if (existsSync(javaPath)) {
61
- try {
62
- const content = readFileSync(javaPath, 'utf-8');
63
- if (content.includes('selenium')) detected.push('selenium-java');
64
- if (content.includes('playwright')) detected.push('playwright-java');
65
- if (content.includes('gauge')) detected.push('gauge');
66
- } catch {
67
- // Ignore read errors
68
- }
69
- break;
70
- }
71
- }
72
-
73
- // Ruby ecosystem detection
74
- const gemfilePath = join(projectPath, 'Gemfile');
75
- if (existsSync(gemfilePath)) {
76
- try {
77
- const content = readFileSync(gemfilePath, 'utf-8');
78
- if (content.includes('capybara')) detected.push('capybara');
79
- if (content.includes('watir')) detected.push('watir');
80
- } catch {
81
- // Ignore read errors
82
- }
83
- }
84
-
85
- // JavaScript/TypeScript ecosystem detection
86
- const packagePath = join(projectPath, 'package.json');
87
- if (existsSync(packagePath)) {
88
- try {
89
- const pkg = JSON.parse(readFileSync(packagePath, 'utf-8'));
90
- const deps = { ...pkg.dependencies, ...pkg.devDependencies };
91
-
92
- if (deps['@playwright/test']) {
93
- detected.push('playwright');
94
- }
95
-
96
- if (deps['cypress'] && hasCypressConfig(projectPath)) {
97
- detected.push('cypress');
98
- }
99
-
100
- if (deps['vitest'] && hasE2eDirectory(projectPath)) {
101
- detected.push('vitest');
102
- }
103
- } catch {
104
- // Ignore parse errors
105
- }
106
- }
107
-
108
- const promptRequired = detected.length === 0 || detected.length > 1;
109
-
110
- return {
111
- detected,
112
- promptRequired,
113
- ...(detected.length === 0 ? { options: SUPPORTED_FRAMEWORKS } : {})
114
- };
115
- }
116
-
117
- function hasCypressConfig(projectPath) {
118
- return ['cypress.config.js', 'cypress.config.ts', 'cypress.config.mjs', 'cypress.config.cjs']
119
- .some(f => existsSync(join(projectPath, f)));
120
- }
121
-
122
- function hasE2eDirectory(projectPath) {
123
- const candidates = ['tests/e2e', 'test/e2e', 'e2e'];
124
- return candidates.some(d => {
125
- const dirPath = join(projectPath, d);
126
- try {
127
- return existsSync(dirPath) && readdirSync(dirPath) !== undefined;
128
- } catch {
129
- return false;
130
- }
131
- });
132
- }