pwsh-guide 0.2.0 → 0.2.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/README.md CHANGED
@@ -18,6 +18,8 @@ npx pwsh-guide init
18
18
  npx pwsh-guide refresh
19
19
  # 只输出探测 JSON,不写文件
20
20
  npx pwsh-guide init --dry-run
21
+ # 查看版本
22
+ npx pwsh-guide --version
21
23
  ```
22
24
 
23
25
  生成的 skill 位于 `.agents/skills/pwsh-guide/`:
package/bin/pwsh-guide.js CHANGED
@@ -4,19 +4,24 @@
4
4
  import { parseArgs } from 'node:util';
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
7
8
  import { probeEnvironment } from '../src/probe.js';
8
9
  import { resolveSkillDir } from '../src/detect.js';
9
10
  import { renderSkill, renderEnvironment, renderCommands } from '../src/render.js';
10
11
 
12
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
+ const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf8'));
14
+
11
15
  const USAGE = `pwsh-guide - 生成项目级 Shell 操作指南 Agent Skill(跨平台:Windows PowerShell / macOS / Linux)
12
16
 
13
17
  用法:
14
18
  pwsh-guide init 探测环境并在 .agents/skills/pwsh-guide/ 生成 skill
15
- pwsh-guide refresh 重新探测并更新 references(SKILL.md 保持不变)
19
+ pwsh-guide refresh 重新探测并重新生成 SKILL.md 与 references
16
20
  pwsh-guide init --dry-run 仅输出探测结果,不写任何文件
17
21
 
18
22
  选项:
19
23
  --dry-run 只输出探测 JSON(用于调试)
24
+ -v, --version 显示版本号
20
25
  -h, --help 显示本帮助
21
26
  `;
22
27
 
@@ -25,10 +30,16 @@ async function main() {
25
30
  allowPositionals: true,
26
31
  options: {
27
32
  'dry-run': { type: 'boolean', default: false },
33
+ version: { type: 'boolean', short: 'v', default: false },
28
34
  help: { type: 'boolean', short: 'h', default: false },
29
35
  },
30
36
  });
31
37
 
38
+ if (values.version) {
39
+ console.log(pkg.version);
40
+ return;
41
+ }
42
+
32
43
  const command = positionals[0] ?? 'help';
33
44
  if (values.help || command === 'help') {
34
45
  console.log(USAGE);
@@ -65,10 +76,8 @@ async function main() {
65
76
  const refsDir = path.join(skillDir, 'references');
66
77
  fs.mkdirSync(refsDir, { recursive: true });
67
78
 
68
- if (command === 'init') {
69
- fs.writeFileSync(path.join(skillDir, 'SKILL.md'), renderSkill(env), 'utf8');
70
- console.log(`[pwsh-guide] 已生成 ${path.join(skillDir, 'SKILL.md')}`);
71
- }
79
+ fs.writeFileSync(path.join(skillDir, 'SKILL.md'), renderSkill(env), 'utf8');
80
+ console.log(`[pwsh-guide] 已更新 ${path.join(skillDir, 'SKILL.md')}`);
72
81
  fs.writeFileSync(path.join(refsDir, 'environment.md'), renderEnvironment(env), 'utf8');
73
82
  fs.writeFileSync(path.join(refsDir, 'commands.md'), renderCommands(env), 'utf8');
74
83
  console.log(`[pwsh-guide] 已更新 ${path.join(refsDir, 'environment.md')}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pwsh-guide",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Generate a project-level Agent Skill: probe the current environment (Windows PowerShell / macOS / Linux shell) and produce a reliable command guide (SKILL.md + references) for agents such as Codex and Claude Code.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/probe.js CHANGED
@@ -30,6 +30,22 @@ const MARKER_NAMES = [
30
30
  const IGNORED_SUBDIRS = new Set(['.git', '.venv', 'venv', 'node_modules']);
31
31
  const VERSION_TIMEOUT_MS = 5000;
32
32
 
33
+ // `--version` 输出命中这些模式时视为错误信息而非版本号(如 Windows py 启动器未安装 Python)
34
+ const VERSION_ERROR_PATTERNS = [
35
+ /not found/i,
36
+ /not installed/i,
37
+ /no installed/i,
38
+ /not recognized/i,
39
+ /command not found/i,
40
+ /内部或外部命令/,
41
+ /找不到/,
42
+ ];
43
+
44
+ function isPlausibleVersion(text) {
45
+ if (!text) return false;
46
+ return !VERSION_ERROR_PATTERNS.some((re) => re.test(text));
47
+ }
48
+
33
49
  export async function probeEnvironment(cwd) {
34
50
  const platform = process.platform; // 'win32' | 'darwin' | 'linux'(其它平台按 unix 处理)
35
51
  const family = platform === 'win32' ? 'powershell' : 'unix';
@@ -124,7 +140,8 @@ async function probeTools() {
124
140
  results.push({ name, version: null, source: null });
125
141
  continue;
126
142
  }
127
- const version = await runVersionCommand(toolPath);
143
+ const rawVersion = await runVersionCommand(toolPath);
144
+ const version = isPlausibleVersion(rawVersion) ? rawVersion : null;
128
145
  results.push({ name, version, source: toolPath });
129
146
  }
130
147
  return results;