@ranger1/dx 0.1.13 → 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.
- package/lib/cli/commands/ai.js +40 -4
- package/package.json +1 -1
package/lib/cli/commands/ai.js
CHANGED
|
@@ -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
|
|
84
|
-
|
|
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
|
-
|
|
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
|
}
|