adspecs 0.1.30 → 0.1.31

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.
@@ -10,7 +10,7 @@
10
10
  {
11
11
  "name": "adspecs",
12
12
  "description": "AI Coding研发协同开发插件",
13
- "version": "0.1.30",
13
+ "version": "0.1.31",
14
14
  "source": "./",
15
15
  "author": {
16
16
  "name": "Qingwen Chen",
@@ -2,7 +2,7 @@
2
2
  "name": "adspecs",
3
3
  "displayName": "adspecs AI Plugin",
4
4
  "description": "AI first工程规范驱动开发插件",
5
- "version": "0.1.30",
5
+ "version": "0.1.31",
6
6
  "author": {
7
7
  "name": "Qingwen Chen",
8
8
  "email": "cqinwn@qq.com",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adspecs",
3
3
  "displayName": "adspecs AI 工程规范驱动开发插件",
4
- "version": "0.1.30",
4
+ "version": "0.1.31",
5
5
  "description": "AI-first specification-driven development plugin for ECP platform full-lifecycle development",
6
6
  "descriptionZh": "AI优先的工程规范驱动开发插件,覆盖需求分析、PRD、系统设计、任务拆解、TDD、代码评审、Wiki同步全流程",
7
7
  "author": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adspecs",
3
3
  "displayName": "adspecs AI 工程规范驱动开发插件",
4
- "version": "0.1.30",
4
+ "version": "0.1.31",
5
5
  "description": "AI-first specification-driven development plugin for ECP platform full-lifecycle development",
6
6
  "descriptionZh": "AI优先的工程规范驱动开发插件,覆盖需求分析、PRD、系统设计、任务拆解、TDD、代码评审、Wiki同步全流程",
7
7
  "author": {
package/bin/adspecs.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
4
  const { Command } = require('commander');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adspecs",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "description": "AI first 工程规范驱动开发插件 — 支持 npm 安装和 CLI 初始化",
5
5
  "bin": {
6
6
  "adspecs": "bin/adspecs.js"
@@ -137,6 +137,22 @@ try {
137
137
  } catch {
138
138
  // codebuddy plugin list 失败 → 静默跳过
139
139
  }
140
+ } else {
141
+ // 5. WorkBuddy — 无 codebuddy CLI 时的回退方案
142
+ // 手工注册:创建 marketplace 目录 → junction 链接 → known_marketplaces.json → enabledPlugins
143
+ try {
144
+ var wkHome = path.join(require('os').homedir(), '.workbuddy');
145
+ if (fs.existsSync(wkHome)) {
146
+ var utilsPath = path.join(installDir, 'src', 'utils');
147
+ var { registerWorkBuddyPlugin } = require(utilsPath);
148
+ var wbResult = registerWorkBuddyPlugin(installDir, 'adspecs');
149
+ if (wbResult.success) {
150
+ refreshedPlatforms.push('WorkBuddy');
151
+ }
152
+ }
153
+ } catch {
154
+ // 注册失败 → 静默跳过(非 WorkBuddy 用户无需处理)
155
+ }
140
156
  }
141
157
 
142
158
  // 输出一行提示(仅当有平台被刷新)
@@ -147,34 +147,23 @@ async function installForWorkBuddy(pluginName, scope) {
147
147
  }
148
148
  }
149
149
  } else {
150
- // 方式 B:回退为手工配置 enabledPlugins(无 CLI 时)
150
+ // 方式 B:回退为手工配置(无 CLI 时)
151
+ // 完整注册:创建 marketplace 目录 → junction 链接 → known_marketplaces.json → enabledPlugins
151
152
  console.log(chalk.yellow(' ⚠ 未检测到 codebuddy CLI,使用手工配置方式'));
152
- const workbuddyHome = path.join(os.homedir(), '.workbuddy');
153
- const settingsPath = path.join(workbuddyHome, 'settings.json');
154
-
155
- // 确保 .workbuddy 目录存在
156
- fs.mkdirSync(workbuddyHome, { recursive: true });
153
+ console.log('');
157
154
 
158
- // 读取或创建 settings.json
159
- let settings = {};
160
- if (fs.existsSync(settingsPath)) {
161
- try { settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch (_e) { /* use default */ }
162
- }
163
- if (!settings.enabledPlugins) settings.enabledPlugins = {};
155
+ const { registerWorkBuddyPlugin } = require('../utils');
156
+ const result = registerWorkBuddyPlugin(PLUGIN_DIR, pluginName);
164
157
 
165
- var registryKey;
166
- if (scope === 'project') {
167
- registryKey = `${pluginName}@${PLUGIN_DIR.replace(/\\/g, '/')}`;
158
+ if (result.success) {
159
+ console.log(chalk.green(' ✅ 已完成 WorkBuddy 插件注册'));
160
+ console.log(chalk.gray(' 📁 插件目录:'));
161
+ console.log(chalk.gray(` ${PLUGIN_DIR}`));
162
+ console.log(chalk.gray(' 📁 marketplace:'));
163
+ console.log(chalk.gray(` ~/.workbuddy/plugins/marketplaces/local/`));
168
164
  } else {
169
- registryKey = `${pluginName}@local`;
165
+ throw new Error(`WorkBuddy 插件注册失败: ${result.reason}`);
170
166
  }
171
-
172
- settings.enabledPlugins[registryKey] = true;
173
-
174
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf8');
175
- console.log(chalk.green(` ✅ 已在 settings.json 中启用插件 (${registryKey})`));
176
- console.log(chalk.gray(' 📁 请确保 WorkBuddy 可访问以下目录:'));
177
- console.log(chalk.gray(` ${PLUGIN_DIR}`));
178
167
  console.log(chalk.gray(' 请重启 WorkBuddy 使 skills 与 hooks 生效。'));
179
168
  }
180
169
  }
@@ -345,23 +334,7 @@ async function installQoderProject(pluginName, qoderManifest) {
345
334
  }
346
335
  }
347
336
 
348
- /**
349
- * 递归复制目录(排除指定目录名)
350
- */
351
- function copyDirRecursive(src, dest, excludeDirs) {
352
- fs.mkdirSync(dest, { recursive: true });
353
- const entries = fs.readdirSync(src, { withFileTypes: true });
354
- for (const entry of entries) {
355
- if (excludeDirs && excludeDirs.includes(entry.name)) continue;
356
- const srcPath = path.join(src, entry.name);
357
- const destPath = path.join(dest, entry.name);
358
- if (entry.isDirectory()) {
359
- copyDirRecursive(srcPath, destPath, excludeDirs);
360
- } else {
361
- fs.copyFileSync(srcPath, destPath);
362
- }
363
- }
364
- }
337
+ const { copyDirRecursive } = require('../utils');
365
338
 
366
339
  /**
367
340
  * Qoder 用户级卸载 — 移除链接 + 注册表条目 + 启用配置
@@ -530,13 +503,31 @@ async function uninstallWorkBuddy(pluginName, scope) {
530
503
  }
531
504
  }
532
505
  } else {
533
- // 回退:手工清除 enabledPlugins 条目
534
- const settingsPath = path.join(os.homedir(), '.workbuddy', 'settings.json');
506
+ // 回退:手工清除 marketplace 注册 + junction 链接 + enabledPlugins 条目
507
+ const workbuddyHome = path.join(os.homedir(), '.workbuddy');
508
+ const localMarketplaceDir = path.join(workbuddyHome, 'plugins', 'marketplaces', 'local');
509
+ const pluginLinkPath = path.join(localMarketplaceDir, pluginName);
510
+ const settingsPath = path.join(workbuddyHome, 'settings.json');
511
+ const knownMarketplacesPath = path.join(workbuddyHome, 'plugins', 'known_marketplaces.json');
512
+
513
+ let cleaned = false;
514
+
515
+ // 1. 移除 junction / 目录
516
+ if (fs.existsSync(pluginLinkPath)) {
517
+ try {
518
+ fs.rmSync(pluginLinkPath, { recursive: true, force: true });
519
+ console.log(chalk.green(' ✅ 已移除插件链接'));
520
+ cleaned = true;
521
+ } catch (err) {
522
+ console.log(chalk.yellow(` ⚠ 移除插件链接失败: ${err.message}`));
523
+ }
524
+ }
525
+
526
+ // 2. 从 settings.json 移除
535
527
  if (fs.existsSync(settingsPath)) {
536
528
  let settings = {};
537
529
  try { settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch (_e) { /* use default */ }
538
530
  if (settings.enabledPlugins) {
539
- // 移除所有 adspecs 相关条目
540
531
  const keysBefore = Object.keys(settings.enabledPlugins).length;
541
532
  for (var key in settings.enabledPlugins) {
542
533
  if (key.startsWith(pluginName + '@')) {
@@ -546,12 +537,29 @@ async function uninstallWorkBuddy(pluginName, scope) {
546
537
  const keysAfter = Object.keys(settings.enabledPlugins).length;
547
538
  if (keysBefore > keysAfter) {
548
539
  fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf8');
549
- console.log(chalk.green(` ✅ 已从 settings.json 移除插件配置`));
540
+ console.log(chalk.green(' ✅ 已从 settings.json 移除插件配置'));
541
+ cleaned = true;
550
542
  } else {
551
- console.log(chalk.yellow(` ⏭ 未在 settings.json 中找到插件配置`));
543
+ console.log(chalk.yellow(' ⏭ 未在 settings.json 中找到插件配置'));
552
544
  }
553
545
  }
554
546
  }
547
+
548
+ // 3. 从 known_marketplaces.json 移除 local marketplace
549
+ if (fs.existsSync(knownMarketplacesPath)) {
550
+ let knownMarketplaces = {};
551
+ try { knownMarketplaces = JSON.parse(fs.readFileSync(knownMarketplacesPath, 'utf8')); } catch (_e) { /* use default */ }
552
+ if (knownMarketplaces.local) {
553
+ delete knownMarketplaces.local;
554
+ fs.writeFileSync(knownMarketplacesPath, JSON.stringify(knownMarketplaces, null, 4) + '\n', 'utf8');
555
+ console.log(chalk.green(' ✅ 已从 known_marketplaces.json 移除 local marketplace'));
556
+ cleaned = true;
557
+ }
558
+ }
559
+
560
+ if (!cleaned) {
561
+ console.log(chalk.yellow(' ⏭ 未找到需要清理的插件配置'));
562
+ }
555
563
  }
556
564
  console.log(chalk.gray(' 请重启 WorkBuddy 使变更生效。'));
557
565
  }
@@ -83,8 +83,8 @@ module.exports = async function update(options) {
83
83
  console.log('');
84
84
  console.log(' 🔄 插件注册刷新:');
85
85
  console.log(' Claude Code — postinstall 钩子已自动刷新命令行插件注册');
86
- console.log(' Qoder 通过 .qoder-plugin/ 清单自动发现,无需手动刷新');
87
- console.log(' WorkBuddy — 通过 .workbuddy-plugin/ 清单自动发现,无需手动刷新');
86
+ console.log(' Qoder / CodeBuddy / WorkBuddy — postinstall 钩子已自动刷新插件注册');
87
+ console.log(' 如未自动刷新,请执行 adspecs plugin install --platform <platform>');
88
88
  console.log('');
89
89
  console.log(` 验证: ${chalk.gray('adspecs --version')}`);
90
90
  console.log('');
package/src/utils.js CHANGED
@@ -9,6 +9,7 @@
9
9
 
10
10
  const path = require('path');
11
11
  const fs = require('fs');
12
+ const os = require('os');
12
13
 
13
14
  /**
14
15
  * 获取插件根目录(即 adspecs/ 目录)
@@ -70,6 +71,119 @@ function safeWriteJson(filePath, data) {
70
71
  fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf8');
71
72
  }
72
73
 
74
+ /**
75
+ * 递归复制目录(排除指定目录名)
76
+ * @param {string} src
77
+ * @param {string} dest
78
+ * @param {string[]} excludeDirs
79
+ */
80
+ function copyDirRecursive(src, dest, excludeDirs) {
81
+ fs.mkdirSync(dest, { recursive: true });
82
+ const entries = fs.readdirSync(src, { withFileTypes: true });
83
+ for (const entry of entries) {
84
+ if (excludeDirs && excludeDirs.includes(entry.name)) continue;
85
+ const srcPath = path.join(src, entry.name);
86
+ const destPath = path.join(dest, entry.name);
87
+ if (entry.isDirectory()) {
88
+ copyDirRecursive(srcPath, destPath, excludeDirs);
89
+ } else {
90
+ fs.copyFileSync(srcPath, destPath);
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * 注册 WorkBuddy 本地插件 marketplace
97
+ *
98
+ * 手工方式完成完整注册,无需 codebuddy CLI:
99
+ * 1. 创建 ~/.workbuddy/plugins/marketplaces/local/ 目录
100
+ * 2. 创建 junction 链接(或回退复制)指向插件目录
101
+ * 3. 在 known_marketplaces.json 中注册 local marketplace
102
+ * 4. 在 settings.json 的 enabledPlugins 中启用插件
103
+ *
104
+ * @param {string} pluginDir - adspecs 插件根目录
105
+ * @param {string} [pluginName='adspecs'] - 插件名称
106
+ * @returns {{success: boolean, reason?: string}}
107
+ */
108
+ function registerWorkBuddyPlugin(pluginDir, pluginName) {
109
+ pluginName = pluginName || 'adspecs';
110
+
111
+ const workbuddyHome = path.join(os.homedir(), '.workbuddy');
112
+
113
+ // 检查 WorkBuddy 配置目录是否存在
114
+ if (!fs.existsSync(workbuddyHome)) {
115
+ return { success: false, reason: '未检测到 WorkBuddy 配置目录 (~/.workbuddy)' };
116
+ }
117
+
118
+ const localMarketplaceDir = path.join(workbuddyHome, 'plugins', 'marketplaces', 'local');
119
+ const pluginLinkPath = path.join(localMarketplaceDir, pluginName);
120
+ const settingsPath = path.join(workbuddyHome, 'settings.json');
121
+ const knownMarketplacesPath = path.join(workbuddyHome, 'plugins', 'known_marketplaces.json');
122
+
123
+ try {
124
+ // 1. 创建 local marketplace 目录
125
+ fs.mkdirSync(localMarketplaceDir, { recursive: true });
126
+
127
+ // 2. 创建 junction / symlink(已存在则先移除重建)
128
+ if (fs.existsSync(pluginLinkPath)) {
129
+ try { fs.rmSync(pluginLinkPath, { recursive: true, force: true }); } catch (_err) {
130
+ try { fs.unlinkSync(pluginLinkPath); } catch (_e) { /* ignore */ }
131
+ }
132
+ }
133
+ try {
134
+ fs.symlinkSync(pluginDir, pluginLinkPath, 'junction');
135
+ } catch (_symlinkErr) {
136
+ // junction 创建失败 → 回退为复制关键目录
137
+ fs.mkdirSync(pluginLinkPath, { recursive: true });
138
+ const entriesToCopy = ['.workbuddy-plugin', 'skills', 'hooks', 'references', 'commands'];
139
+ for (const entry of entriesToCopy) {
140
+ const srcPath = path.join(pluginDir, entry);
141
+ if (!fs.existsSync(srcPath)) continue;
142
+ const destPath = path.join(pluginLinkPath, entry);
143
+ if (fs.lstatSync(srcPath).isDirectory()) {
144
+ copyDirRecursive(srcPath, destPath, ['node_modules']);
145
+ } else {
146
+ fs.copyFileSync(srcPath, destPath);
147
+ }
148
+ }
149
+ // 同步复制根目录关键文件
150
+ for (const file of ['package.json', 'CLAUDE.md', 'README.md']) {
151
+ const srcFile = path.join(pluginDir, file);
152
+ if (fs.existsSync(srcFile)) {
153
+ fs.copyFileSync(srcFile, path.join(pluginLinkPath, file));
154
+ }
155
+ }
156
+ }
157
+
158
+ // 3. 注册 local marketplace
159
+ let knownMarketplaces = safeReadJson(knownMarketplacesPath, {});
160
+ const now = new Date().toISOString();
161
+
162
+ knownMarketplaces.local = {
163
+ type: 'directory',
164
+ source: {
165
+ source: 'directory',
166
+ path: localMarketplaceDir
167
+ },
168
+ installLocation: localMarketplaceDir,
169
+ autoUpdate: false,
170
+ description: 'Local plugins',
171
+ lastUpdated: now
172
+ };
173
+ safeWriteJson(knownMarketplacesPath, knownMarketplaces);
174
+
175
+ // 4. 启用插件
176
+ let settings = safeReadJson(settingsPath, {});
177
+ if (!settings.enabledPlugins) settings.enabledPlugins = {};
178
+ settings.enabledPlugins[`${pluginName}@local`] = true;
179
+ safeWriteJson(settingsPath, settings);
180
+
181
+ return { success: true };
182
+ } catch (err) {
183
+ return { success: false, reason: err.message };
184
+ }
185
+ }
186
+
73
187
  module.exports = {
74
188
  getPluginDir,
75
189
  getPkg,
@@ -77,4 +191,6 @@ module.exports = {
77
191
  isInsidePlugin,
78
192
  safeReadJson,
79
193
  safeWriteJson,
194
+ copyDirRecursive,
195
+ registerWorkBuddyPlugin,
80
196
  };