@ranger1/dx 0.1.12 → 0.1.14

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.
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync } from 'node:fs'
2
- import { resolve } from 'node:path'
2
+ import { resolve, join, isAbsolute } from 'node:path'
3
3
  import { homedir } from 'node:os'
4
4
  import { spawn, spawnSync } from 'node:child_process'
5
5
  import { logger } from '../../logger.js'
@@ -41,6 +41,36 @@ function expandHomePath(input) {
41
41
  return raw
42
42
  }
43
43
 
44
+ function isBareFilename(input) {
45
+ const raw = String(input ?? '')
46
+ if (!raw) return false
47
+ if (raw.startsWith('.')) return false
48
+ return !raw.includes('/') && !raw.includes('\\')
49
+ }
50
+
51
+ function resolvePromptPath(promptFile) {
52
+ const projectRoot = process.env.DX_PROJECT_ROOT || process.cwd()
53
+ const expanded = expandHomePath(promptFile)
54
+
55
+ if (isAbsolute(expanded)) return [expanded]
56
+
57
+ const dxDir = join(projectRoot, 'dx')
58
+ const candidates = []
59
+
60
+ // 仅文件名:优先在 dx/prompts 下找(不破坏历史:仍保留 project root fallback)
61
+ if (isBareFilename(expanded)) {
62
+ candidates.push(join(dxDir, 'prompts', expanded))
63
+ candidates.push(resolve(projectRoot, expanded))
64
+ candidates.push(resolve(dxDir, expanded))
65
+ return candidates
66
+ }
67
+
68
+ // 相对路径:优先保持与历史一致(相对 project root),找不到再 fallback 到 dx/ 下
69
+ candidates.push(resolve(projectRoot, expanded))
70
+ candidates.push(resolve(dxDir, expanded))
71
+ return candidates
72
+ }
73
+
44
74
  export async function handleAi(cli, args = []) {
45
75
  const name = args[0]
46
76
  if (!name) {
@@ -80,10 +110,16 @@ export async function handleAi(cli, args = []) {
80
110
  return
81
111
  }
82
112
 
83
- const promptPath = resolve(process.cwd(), expandHomePath(promptFile))
84
- if (!existsSync(promptPath)) {
113
+ const promptCandidates = resolvePromptPath(promptFile)
114
+ const promptPath = promptCandidates.find(p => existsSync(p)) || promptCandidates[0]
115
+ if (!promptPath || !existsSync(promptPath)) {
85
116
  logger.error(`未找到提示词文件: ${promptFile}`)
86
- logger.info(`解析后的路径: ${promptPath}`)
117
+ if (promptCandidates.length <= 1) {
118
+ logger.info(`解析后的路径: ${promptPath}`)
119
+ } else {
120
+ logger.info('解析后的候选路径:')
121
+ for (const p of promptCandidates) logger.info(`- ${p}`)
122
+ }
87
123
  process.exitCode = 1
88
124
  return
89
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {