@house365/comate 0.9.16 → 0.9.18

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/bin/cli.mjs CHANGED
@@ -6,15 +6,54 @@
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { dirname } from 'node:path';
8
8
  import { readFileSync } from 'node:fs';
9
+ import { get } from 'node:https';
9
10
 
10
11
  import { run, skillsInvocation, SKILLS_TIMEOUT_MS } from './init.mjs';
11
12
 
13
+ // Check npm registry for the latest version and notify if an update is available.
14
+ async function checkForUpdates(currentVersion) {
15
+ return new Promise((resolve) => {
16
+ const req = get('https://registry.npmjs.org/@house365/comate/latest', { timeout: 3000 }, (res) => {
17
+ if (res.statusCode !== 200) {
18
+ resolve();
19
+ return;
20
+ }
21
+ let data = '';
22
+ res.on('data', (chunk) => { data += chunk; });
23
+ res.on('end', () => {
24
+ try {
25
+ const pkg = JSON.parse(data);
26
+ const latestVersion = pkg.version;
27
+ if (latestVersion && latestVersion !== currentVersion) {
28
+ console.log('');
29
+ console.log(`\x1b[33m🔔 有新版本可用:${latestVersion} (当前版本:${currentVersion})\x1b[0m`);
30
+ console.log(`\x1b[36m更新命令:npm install -g @house365/comate@latest\x1b[0m`);
31
+ console.log('');
32
+ }
33
+ } catch {
34
+ // Ignore parse errors
35
+ }
36
+ resolve();
37
+ });
38
+ });
39
+ req.on('error', () => resolve());
40
+ req.on('timeout', () => {
41
+ req.destroy();
42
+ resolve();
43
+ });
44
+ });
45
+ }
46
+
12
47
  const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)));
13
48
  const args = process.argv.slice(2);
14
49
  const packageVersion = JSON.parse(readFileSync(`${pkgRoot}/package.json`, 'utf8')).version;
15
50
 
16
51
  if (args[0] === '--version' || args[0] === '-v') {
17
52
  console.log(packageVersion);
53
+ // Check for updates in the background, non-blocking
54
+ checkForUpdates(packageVersion).catch(() => {
55
+ // Silently ignore network errors
56
+ });
18
57
  process.exit(0);
19
58
  }
20
59
 
@@ -28,6 +67,11 @@ if (args[0] === 'doctor') {
28
67
  process.exit(doctor(args.slice(1)));
29
68
  }
30
69
 
70
+ if (args[0] === 'update') {
71
+ const { update } = await import('./update.mjs');
72
+ process.exit(await update(packageVersion));
73
+ }
74
+
31
75
  if (args[0] === 'usage') {
32
76
  const { usage } = await import('./usage.mjs');
33
77
  process.exit(await usage(args.slice(1), { pkgRoot }));
@@ -39,6 +83,7 @@ if (args[0] === '--help' || args[0] === '-h') {
39
83
  用法:
40
84
  comate init 安装 comate 和依赖到用户级,并在当前项目创建 openspec/
41
85
  comate doctor 健康检查
86
+ comate update 更新 comate 到最新版本
42
87
  comate usage 查看本项目 token 用量(--global 看全部;参数透传给 ccusage)
43
88
 
44
89
  装好后在 agent 中输入 /comate 开始使用。`);
package/bin/update.mjs ADDED
@@ -0,0 +1,89 @@
1
+ // comate update — upgrade comate to the latest version from npm
2
+ import { get } from 'node:https';
3
+ import { spawn } from 'node:child_process';
4
+
5
+ // Fetch the latest version from npm registry
6
+ function fetchLatestVersion() {
7
+ return new Promise((resolve, reject) => {
8
+ const req = get('https://registry.npmjs.org/@house365/comate/latest', { timeout: 5000 }, (res) => {
9
+ if (res.statusCode !== 200) {
10
+ reject(new Error(`获取版本信息失败: HTTP ${res.statusCode}`));
11
+ return;
12
+ }
13
+ let data = '';
14
+ res.on('data', (chunk) => { data += chunk; });
15
+ res.on('end', () => {
16
+ try {
17
+ const pkg = JSON.parse(data);
18
+ resolve(pkg.version);
19
+ } catch (err) {
20
+ reject(new Error('解析版本信息失败'));
21
+ }
22
+ });
23
+ });
24
+ req.on('error', (err) => reject(new Error(`网络错误: ${err.message}`)));
25
+ req.on('timeout', () => {
26
+ req.destroy();
27
+ reject(new Error('请求超时'));
28
+ });
29
+ });
30
+ }
31
+
32
+ // Run npm install -g with live output
33
+ function runNpmInstall(packageName) {
34
+ return new Promise((resolve) => {
35
+ console.log(`\n正在更新 ${packageName}...\n`);
36
+
37
+ const isWindows = process.platform === 'win32';
38
+ const npmCmd = isWindows ? 'npm.cmd' : 'npm';
39
+
40
+ const child = spawn(npmCmd, ['install', '-g', packageName], {
41
+ stdio: 'inherit',
42
+ shell: isWindows,
43
+ });
44
+
45
+ child.on('close', (code) => {
46
+ resolve(code === 0);
47
+ });
48
+
49
+ child.on('error', (err) => {
50
+ console.error(`\n执行失败: ${err.message}`);
51
+ resolve(false);
52
+ });
53
+ });
54
+ }
55
+
56
+ export async function update(currentVersion) {
57
+ console.log(`当前版本: ${currentVersion}`);
58
+ console.log('正在检查最新版本...');
59
+
60
+ let latestVersion;
61
+ try {
62
+ latestVersion = await fetchLatestVersion();
63
+ } catch (err) {
64
+ console.error(`\n❌ ${err.message}`);
65
+ console.log('\n你也可以手动更新:');
66
+ console.log(' npm install -g @house365/comate@latest');
67
+ return 1;
68
+ }
69
+
70
+ console.log(`最新版本: ${latestVersion}`);
71
+
72
+ if (latestVersion === currentVersion) {
73
+ console.log('\n✅ 已是最新版本,无需更新。');
74
+ return 0;
75
+ }
76
+
77
+ console.log(`\n🔔 发现新版本: ${currentVersion} → ${latestVersion}`);
78
+
79
+ const success = await runNpmInstall('@house365/comate@latest');
80
+
81
+ if (success) {
82
+ console.log(`\n✅ 更新成功!comate 已升级到 ${latestVersion}`);
83
+ return 0;
84
+ } else {
85
+ console.log('\n❌ 更新失败。你可以手动执行:');
86
+ console.log(' npm install -g @house365/comate@latest');
87
+ return 1;
88
+ }
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@house365/comate",
3
- "version": "0.9.16",
3
+ "version": "0.9.18",
4
4
  "description": "comate —— SDD (规约驱动开发) 的 AI 开发编排器(Agent Skills)",
5
5
  "type": "module",
6
6
  "license": "MIT",