@zhuan-ai/zhuanspec 2.17.2 → 2.17.6

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/dist/cli/index.js CHANGED
@@ -45,6 +45,7 @@ program
45
45
  .description('Initialize ZhuanSpec in your project')
46
46
  .option('--tools <tools>', toolsOptionDescription)
47
47
  .option('--business-direction <direction>', 'Business direction for fetching project architecture (e.g., oms, ass)')
48
+ .option('--domain <domain>', 'Primary domain code; enables domain mode: syncs specs/<domain>/zhuanspec/ and generates project.md via spec-service-architecture skill')
48
49
  .action(async (targetPath = '.', options) => {
49
50
  try {
50
51
  // Validate that the path is a valid directory
@@ -71,6 +72,7 @@ program
71
72
  const initCommand = new InitCommand({
72
73
  tools: options?.tools,
73
74
  businessDirection: options?.businessDirection,
75
+ domain: options?.domain,
74
76
  });
75
77
  await initCommand.execute(targetPath);
76
78
  }
@@ -511,6 +511,17 @@ export class ArchiveCommand {
511
511
  if (explicitDirection && explicitDirection.trim()) {
512
512
  return explicitDirection.trim().toLowerCase();
513
513
  }
514
+ // domain mode: read .domain meta file (takes priority over .business-direction)
515
+ const domainFilePath = path.join(zhuanspecDir, '.domain');
516
+ try {
517
+ const fromDomain = (await fs.readFile(domainFilePath, 'utf-8')).trim();
518
+ if (fromDomain) {
519
+ return fromDomain.toLowerCase();
520
+ }
521
+ }
522
+ catch {
523
+ // Not domain mode, continue.
524
+ }
514
525
  const directionFilePath = path.join(zhuanspecDir, '.business-direction');
515
526
  try {
516
527
  const fromFile = (await fs.readFile(directionFilePath, 'utf-8')).trim();
@@ -29,13 +29,22 @@ type InitCommandOptions = {
29
29
  prompt?: ToolSelectionPrompt;
30
30
  tools?: string;
31
31
  businessDirection?: string;
32
+ domain?: string;
32
33
  };
33
34
  export declare class InitCommand {
34
35
  private readonly prompt;
35
36
  private readonly toolsArg?;
36
37
  private businessDirection?;
38
+ private readonly domain?;
37
39
  constructor(options?: InitCommandOptions);
38
40
  execute(targetPath: string): Promise<void>;
41
+ /**
42
+ * Domain mode initialization: clone remote repo and sync specs/<domain>/zhuanspec/ to local.
43
+ * project.md is generated by the spec-service-architecture skill (injected as post-init instruction).
44
+ */
45
+ private executeDomainSync;
46
+ private generateDomainProjectMdPlaceholder;
47
+ private syncBusinessDirectionAssets;
39
48
  private validate;
40
49
  private getConfiguration;
41
50
  private getSelectedTools;
package/dist/core/init.js CHANGED
@@ -269,10 +269,12 @@ export class InitCommand {
269
269
  prompt;
270
270
  toolsArg;
271
271
  businessDirection;
272
+ domain;
272
273
  constructor(options = {}) {
273
274
  this.prompt = options.prompt ?? ((config) => toolSelectionWizard(config));
274
275
  this.toolsArg = options.tools;
275
276
  this.businessDirection = options.businessDirection;
277
+ this.domain = options.domain?.trim().toLowerCase() || undefined;
276
278
  }
277
279
  async execute(targetPath) {
278
280
  const projectPath = path.resolve(targetPath);
@@ -308,63 +310,17 @@ export class InitCommand {
308
310
  }
309
311
  // Step 2: Select business direction and sync Claude assets BEFORE configureAITools
310
312
  // This ensures .claude directory is not deleted after slash commands are generated
311
- await this.promptForBusinessDirection();
312
- if (this.businessDirection) {
313
- const directionMetaPath = path.join(zhuanspecPath, '.business-direction');
314
- await FileSystemUtils.writeFile(directionMetaPath, `${this.businessDirection.toLowerCase()}\n`);
315
- const archSpinner = this.startSpinner(`正在获取 ${this.businessDirection} 业务架构文档...`);
316
- const architectureContent = await this.fetchArchitectureFile();
317
- if (architectureContent) {
318
- const projectMdPath = path.join(zhuanspecPath, 'project.md');
319
- const projectMdExists = await FileSystemUtils.fileExists(projectMdPath);
320
- await FileSystemUtils.writeFile(projectMdPath, architectureContent);
321
- archSpinner.stopAndPersist({
322
- symbol: PALETTE.white('▌'),
323
- text: PALETTE.white(projectMdExists
324
- ? `已使用 ${this.businessDirection} 业务架构文档覆盖 project.md`
325
- : `已应用 ${this.businessDirection} 业务架构文档到 project.md`),
326
- });
327
- }
328
- else {
329
- archSpinner.stopAndPersist({
330
- symbol: PALETTE.midGray('▌'),
331
- text: PALETTE.midGray(`未找到 ${this.businessDirection} 业务架构文档,使用默认模板`),
332
- });
333
- }
334
- const specTemplateSpinner = this.startSpinner(`正在同步 ${this.businessDirection} 业务规范模板...`);
335
- const syncResult = this.syncBusinessSpecTemplate(zhuanspecPath);
336
- if (syncResult.syncedSpecs || syncResult.syncedChanges || syncResult.syncedKnowledge) {
337
- const syncedParts = [];
338
- if (syncResult.syncedSpecs) {
339
- syncedParts.push('specs');
340
- }
341
- if (syncResult.syncedChanges) {
342
- syncedParts.push('changes');
343
- }
344
- if (syncResult.syncedKnowledge) {
345
- syncedParts.push('knowledge');
346
- }
347
- specTemplateSpinner.stopAndPersist({
348
- symbol: PALETTE.white('▌'),
349
- text: PALETTE.white(`已从远端模板同步 ${syncedParts.join('、')} 目录`),
350
- });
351
- }
352
- else {
353
- specTemplateSpinner.stopAndPersist({
354
- symbol: PALETTE.midGray('▌'),
355
- text: PALETTE.midGray(`未找到 ${this.businessDirection} 业务规范模板目录,保留默认模板`),
356
- });
357
- }
358
- // Sync Claude assets BEFORE configureAITools to avoid deletion
359
- const claudeAssetSpinner = this.startSpinner(`正在同步 ${this.businessDirection} 业务 Claude 规范资产...`);
360
- const claudeAssetResult = this.syncBusinessClaudeAssets(projectPath);
361
- const claudeMdText = this.describeClaudeAssetResult('CLAUDE.md', claudeAssetResult.claudeMd);
362
- const dotClaudeText = this.describeClaudeAssetResult('.claude', claudeAssetResult.dotClaude);
363
- claudeAssetSpinner.stopAndPersist({
364
- symbol: PALETTE.white('▌'),
365
- text: PALETTE.white(`Claude 规范资产同步完成:${claudeMdText};${dotClaudeText}`),
366
- });
313
+ if (this.domain) {
314
+ // Domain mode: use domain as business direction first, then let
315
+ // specs/<domain>/zhuanspec/ override same-path template files.
316
+ await this.executeDomainSync(projectPath, zhuanspecPath);
367
317
  }
318
+ else {
319
+ await this.promptForBusinessDirection();
320
+ if (this.businessDirection) {
321
+ await this.syncBusinessDirectionAssets(projectPath, zhuanspecPath);
322
+ }
323
+ } // end domain else
368
324
  // Step 3: Configure AI tools (after Claude assets sync to preserve generated files)
369
325
  const toolSpinner = this.startSpinner('正在配置 AI 工具...');
370
326
  const toolConfigResult = await this.configureAITools(projectPath, zhuanspecDir, config.aiTools);
@@ -377,6 +333,128 @@ export class InitCommand {
377
333
  // Success message
378
334
  this.displaySuccessMessage(selectedTools, created, refreshed, skippedExisting, skipped, extendMode, toolConfigResult.rootStubStatus, toolConfigResult.claudeHookSummary);
379
335
  }
336
+ /**
337
+ * Domain mode initialization: clone remote repo and sync specs/<domain>/zhuanspec/ to local.
338
+ * project.md is generated by the spec-service-architecture skill (injected as post-init instruction).
339
+ */
340
+ async executeDomainSync(projectPath, zhuanspecPath) {
341
+ const domain = this.domain;
342
+ this.businessDirection = domain;
343
+ // Save domain code to .domain meta file (used by archive for push routing)
344
+ const domainMetaPath = path.join(zhuanspecPath, '.domain');
345
+ await FileSystemUtils.writeFile(domainMetaPath, `${domain}\n`);
346
+ await this.syncBusinessDirectionAssets(projectPath, zhuanspecPath);
347
+ const syncSpinner = this.startSpinner(`正在从远端同步 ${domain} 主领域模板(specs/${domain}/zhuanspec/)...`);
348
+ const tempDir = this.cloneRemoteArchitectureRepoToTemp();
349
+ if (!tempDir) {
350
+ syncSpinner.stopAndPersist({
351
+ symbol: PALETTE.midGray('▌'),
352
+ text: PALETTE.midGray(`克隆远端仓库失败,跳过 ${domain} 主领域模板同步`),
353
+ });
354
+ }
355
+ else {
356
+ try {
357
+ const remoteZhuanspecDir = path.join(tempDir, 'specs', domain, 'zhuanspec');
358
+ if (!existsSync(remoteZhuanspecDir)) {
359
+ syncSpinner.stopAndPersist({
360
+ symbol: PALETTE.midGray('▌'),
361
+ text: PALETTE.midGray(`远端未找到 specs/${domain}/zhuanspec/ 目录,跳过模板同步`),
362
+ });
363
+ }
364
+ else {
365
+ // Sync all contents from specs/<domain>/zhuanspec/ into local zhuanspec/
366
+ this.copyDirectoryContentsIfExists(remoteZhuanspecDir, zhuanspecPath);
367
+ syncSpinner.stopAndPersist({
368
+ symbol: PALETTE.white('▌'),
369
+ text: PALETTE.white(`已从远端 specs/${domain}/zhuanspec/ 同步模板到本地 zhuanspec/`),
370
+ });
371
+ }
372
+ }
373
+ finally {
374
+ rmSync(tempDir, { recursive: true, force: true });
375
+ }
376
+ }
377
+ // project.md is generated by spec-service-architecture skill after init
378
+ // Write a placeholder so Claude knows to invoke the skill
379
+ const projectMdPath = path.join(zhuanspecPath, 'project.md');
380
+ if (!(await FileSystemUtils.fileExists(projectMdPath))) {
381
+ await this.generateDomainProjectMdPlaceholder(projectMdPath, domain);
382
+ }
383
+ // Remind user to run spec-service-architecture skill to generate project.md
384
+ console.log();
385
+ console.log(PALETTE.white('domain 模式提示'));
386
+ console.log(PALETTE.lightGray(` project.md 需由 @spec-service-architecture skill 生成,请在 AI 工具中执行:`));
387
+ console.log(PALETTE.midGray(` /spec-service-architecture`));
388
+ console.log(PALETTE.midGray(` 生成完成后,文件将保存为 zhuanspec/project.md`));
389
+ }
390
+ async generateDomainProjectMdPlaceholder(projectMdPath, domain) {
391
+ const placeholder = `# Project Architecture
392
+
393
+ <!-- 此文件由 domain 模式初始化,需通过 @spec-service-architecture skill 生成完整内容 -->
394
+ <!-- domain: ${domain} -->
395
+ <!-- 请在 AI 工具中执行 /spec-service-architecture,生成结果将覆盖此文件 -->
396
+ `;
397
+ await FileSystemUtils.writeFile(projectMdPath, placeholder);
398
+ }
399
+ async syncBusinessDirectionAssets(projectPath, zhuanspecPath) {
400
+ if (!this.businessDirection) {
401
+ return;
402
+ }
403
+ const directionMetaPath = path.join(zhuanspecPath, '.business-direction');
404
+ await FileSystemUtils.writeFile(directionMetaPath, `${this.businessDirection.toLowerCase()}\n`);
405
+ const archSpinner = this.startSpinner(`正在获取 ${this.businessDirection} 业务架构文档...`);
406
+ const architectureContent = await this.fetchArchitectureFile();
407
+ if (architectureContent) {
408
+ const projectMdPath = path.join(zhuanspecPath, 'project.md');
409
+ const projectMdExists = await FileSystemUtils.fileExists(projectMdPath);
410
+ await FileSystemUtils.writeFile(projectMdPath, architectureContent);
411
+ archSpinner.stopAndPersist({
412
+ symbol: PALETTE.white('▌'),
413
+ text: PALETTE.white(projectMdExists
414
+ ? `已使用 ${this.businessDirection} 业务架构文档覆盖 project.md`
415
+ : `已应用 ${this.businessDirection} 业务架构文档到 project.md`),
416
+ });
417
+ }
418
+ else {
419
+ archSpinner.stopAndPersist({
420
+ symbol: PALETTE.midGray('▌'),
421
+ text: PALETTE.midGray(`未找到 ${this.businessDirection} 业务架构文档,使用默认模板`),
422
+ });
423
+ }
424
+ const specTemplateSpinner = this.startSpinner(`正在同步 ${this.businessDirection} 业务规范模板...`);
425
+ const syncResult = this.syncBusinessSpecTemplate(zhuanspecPath);
426
+ if (syncResult.syncedSpecs || syncResult.syncedChanges || syncResult.syncedKnowledge) {
427
+ const syncedParts = [];
428
+ if (syncResult.syncedSpecs) {
429
+ syncedParts.push('specs');
430
+ }
431
+ if (syncResult.syncedChanges) {
432
+ syncedParts.push('changes');
433
+ }
434
+ if (syncResult.syncedKnowledge) {
435
+ syncedParts.push('knowledge');
436
+ }
437
+ specTemplateSpinner.stopAndPersist({
438
+ symbol: PALETTE.white('▌'),
439
+ text: PALETTE.white(`已从远端模板同步 ${syncedParts.join('、')} 目录`),
440
+ });
441
+ }
442
+ else {
443
+ specTemplateSpinner.stopAndPersist({
444
+ symbol: PALETTE.midGray('▌'),
445
+ text: PALETTE.midGray(`未找到 ${this.businessDirection} 业务规范模板目录,保留默认模板`),
446
+ });
447
+ }
448
+ // Sync Claude assets BEFORE configureAITools to avoid deletion
449
+ const claudeAssetSpinner = this.startSpinner(`正在同步 ${this.businessDirection} 业务 Claude 规范资产...`);
450
+ const claudeAssetResult = this.syncBusinessClaudeAssets(projectPath);
451
+ const claudeMdText = this.describeClaudeAssetResult('CLAUDE.md', claudeAssetResult.claudeMd);
452
+ const dotClaudeText = this.describeClaudeAssetResult('.claude', claudeAssetResult.dotClaude);
453
+ claudeAssetSpinner.stopAndPersist({
454
+ symbol: PALETTE.white('▌'),
455
+ text: PALETTE.white(`Claude 规范资产同步完成:${claudeMdText};${dotClaudeText}`),
456
+ });
457
+ }
380
458
  async validate(projectPath, _zhuanspecPath) {
381
459
  const extendMode = await FileSystemUtils.directoryExists(_zhuanspecPath);
382
460
  // Check write permissions
@@ -893,26 +893,9 @@ const designSteps = `**步骤**
893
893
  * 在 progress.json 的 events 字段追加:\`{ "event": "test-case-skipped", "timestamp": "<ISO>" }\`
894
894
  * 直接进入步骤 8
895
895
 
896
- 7.6. **涉及工程清单输出(阶段 6 定稿产物,必须生成)**:
897
- - 在技术方案定稿时,从 Skill 生成的 \`tech-spec.md\`、\`matched_services\` 和改动点定位结果中提取涉及工程
898
- - 输出到与技术方案同目录:
899
- \`zhuanspec/changes/{change-id}/techDesign/affected-projects.md\`
900
- - 只记录分析出的工程/服务名称,不展开改动原因、证据、置信度或实现细节
901
- - 固定使用 Markdown 列表:
902
- \`\`\`markdown
903
- # 涉及工程清单
904
-
905
- - user-service
906
- - order-service
907
- \`\`\`
908
- - 工程/服务必须来自项目知识定位或实际代码检索证据,禁止凭空补全
909
- - 如果无法定位任何工程,也必须生成 \`affected-projects.md\`,并写明"未定位到明确工程"
910
- - 该文件供后续 proposal/tasks/apply 阶段快速判断工程边界,禁止创建 proposal.md 或 tasks.md 来替代它
911
-
912
896
  8. **输出摘要**:
913
897
  - 告知用户生成的文档路径和实际调用的 Skill 名称
914
- - 告知用户涉及工程清单路径:\`zhuanspec/changes/{change-id}/techDesign/affected-projects.md\`
915
- - **明确说明**:techDesign 阶段仅保存进度数据(progress.json)、技术方案(含外部依赖矩阵)和涉及工程清单,不创建 proposal.md 和 tasks.md
898
+ - **明确说明**:techDesign 阶段仅保存进度数据(progress.json)和技术方案(含外部依赖矩阵),不创建 proposal.md 和 tasks.md
916
899
  - 如果步骤 7.5 生成了测试 case,额外提示:「✅ 已生成测试 case 源文件,后续 Propose 阶段将自动启用 TDD 模式并调用 tdd-testcase-generator 转换为研发 TDD testcase」
917
900
  - 提示 phase=techDesign
918
901
  - 提示下一步可以使用 \`/zhuanspec:proposal\` 创建变更提案(复用目录)`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhuan-ai/zhuanspec",
3
- "version": "2.17.2",
3
+ "version": "2.17.6",
4
4
  "description": "AI-native system for spec-driven development",
5
5
  "keywords": [
6
6
  "zhuanspec",
@@ -39,6 +39,26 @@
39
39
  "!dist/**/__tests__",
40
40
  "!dist/**/*.map"
41
41
  ],
42
+ "scripts": {
43
+ "lint": "eslint src/",
44
+ "build": "node build.js",
45
+ "dev": "tsc --watch",
46
+ "dev:cli": "pnpm build && node bin/zhuanspec.js",
47
+ "test": "vitest run",
48
+ "test:watch": "vitest",
49
+ "test:ui": "vitest --ui",
50
+ "test:coverage": "vitest --coverage",
51
+ "test:postinstall": "node scripts/postinstall.js",
52
+ "prepare": "npm run build",
53
+ "prepublishOnly": "npm run build",
54
+ "postinstall": "node scripts/postinstall.js",
55
+ "check:pack-version": "node scripts/pack-version-check.mjs",
56
+ "diagnose:cursor": "node scripts/diagnose-cursor-commands.js",
57
+ "release": "pnpm run release:ci",
58
+ "release:ci": "pnpm run check:pack-version && pnpm exec changeset publish",
59
+ "release:local": "pnpm exec changeset version && pnpm run check:pack-version && pnpm exec changeset publish",
60
+ "changeset": "changeset"
61
+ },
42
62
  "engines": {
43
63
  "node": ">=20.19.0"
44
64
  },
@@ -60,23 +80,5 @@
60
80
  "ora": "^8.2.0",
61
81
  "yaml": "^2.8.2",
62
82
  "zod": "^4.0.17"
63
- },
64
- "scripts": {
65
- "lint": "eslint src/",
66
- "build": "node build.js",
67
- "dev": "tsc --watch",
68
- "dev:cli": "pnpm build && node bin/zhuanspec.js",
69
- "test": "vitest run",
70
- "test:watch": "vitest",
71
- "test:ui": "vitest --ui",
72
- "test:coverage": "vitest --coverage",
73
- "test:postinstall": "node scripts/postinstall.js",
74
- "postinstall": "node scripts/postinstall.js",
75
- "check:pack-version": "node scripts/pack-version-check.mjs",
76
- "diagnose:cursor": "node scripts/diagnose-cursor-commands.js",
77
- "release": "pnpm run release:ci",
78
- "release:ci": "pnpm run check:pack-version && pnpm exec changeset publish",
79
- "release:local": "pnpm exec changeset version && pnpm run check:pack-version && pnpm exec changeset publish",
80
- "changeset": "changeset"
81
83
  }
82
- }
84
+ }