dxkj 0.1.1 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dxkj",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "dxkj CLI — browse and install prompts/skills/agents/plugins/tools from the dxkj catalog, plus an opencode plugin shell.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/src/cli.js CHANGED
@@ -7,8 +7,7 @@ import { validateItem, formatReport } from './lib/validator.js';
7
7
  import { renderList, renderDetail } from './lib/format.js';
8
8
  import { resolveTargetDir } from './lib/targets.js';
9
9
  import { downloadToTemp, extractZip, writeManifest, cleanup } from './lib/installer.js';
10
-
11
- const VERSION = '0.1.0';
10
+ import { VERSION } from './lib/version.js';
12
11
 
13
12
  const OPTIONS = {
14
13
  source: { type: 'string' },
@@ -3,6 +3,7 @@ import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { pipeline } from 'node:stream/promises';
5
5
  import AdmZip from 'adm-zip';
6
+ import { USER_AGENT } from './version.js';
6
7
 
7
8
  export const MANIFEST = '.dxkj.json';
8
9
 
@@ -12,7 +13,7 @@ export async function downloadToTemp(url) {
12
13
  const target = path.join(tmp, 'package.zip');
13
14
 
14
15
  if (/^https?:\/\//i.test(url)) {
15
- const res = await fetch(url, { headers: { 'User-Agent': 'dxkj-cli/0.1.0' } });
16
+ const res = await fetch(url, { headers: { 'User-Agent': USER_AGENT } });
16
17
  if (!res.ok) throw new Error(`下载失败 HTTP ${res.status}:${url}`);
17
18
  await pipeline(res.body, fs.createWriteStream(target));
18
19
  } else {
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { loadConfig, resolveServerUrl, REGISTRY_PATH } from './config.js';
4
+ import { USER_AGENT } from './version.js';
4
5
 
5
6
  /** 去除 Windows 写文件常见的 UTF-8 BOM,避免 JSON.parse 失败 */
6
7
  export function stripBom(text) {
@@ -52,7 +53,7 @@ export async function loadRegistry(opts = {}, cfg = loadConfig()) {
52
53
  try {
53
54
  const res = await fetch(source, {
54
55
  signal: controller.signal,
55
- headers: { 'User-Agent': 'dxkj-cli/0.1.0', Accept: 'application/json' }
56
+ headers: { 'User-Agent': USER_AGENT, Accept: 'application/json' }
56
57
  });
57
58
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
58
59
  json = await res.json();
@@ -0,0 +1,8 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ /** 版本号唯一来源:package.json,避免与硬编码漂移 */
4
+ export const VERSION = JSON.parse(
5
+ readFileSync(new URL('../../package.json', import.meta.url), 'utf-8')
6
+ ).version;
7
+
8
+ export const USER_AGENT = `dxkj-cli/${VERSION}`;