a4phone 1.7.0 → 1.7.1
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/a4p.mjs +3 -1
- package/package.json +1 -1
- package/src/resume.mjs +44 -4
package/bin/a4p.mjs
CHANGED
|
@@ -165,7 +165,9 @@ if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
|
|
|
165
165
|
console.error(result.reason);
|
|
166
166
|
process.exit(1);
|
|
167
167
|
}
|
|
168
|
-
console.log(
|
|
168
|
+
console.log(result.code === 0
|
|
169
|
+
? '续聊完成(退出码 0),结果已推送手机。'
|
|
170
|
+
: `续聊未成功(退出码 ${result.code}),详情已推送手机。`);
|
|
169
171
|
} else if (cmd === 'last') {
|
|
170
172
|
const { loadLastSession } = await import('../src/config.mjs');
|
|
171
173
|
const last = loadLastSession();
|
package/package.json
CHANGED
package/src/resume.mjs
CHANGED
|
@@ -139,6 +139,35 @@ export function forkCodexSession({ sessionId, transcriptPath }) {
|
|
|
139
139
|
return { newId, newTranscriptPath: dst };
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// 命令是否可在 PATH 上执行(Windows 需匹配 PATHEXT 后缀,如 qoder.cmd)
|
|
143
|
+
export function commandAvailable(command) {
|
|
144
|
+
if (!command) return false;
|
|
145
|
+
if (path.isAbsolute(command)) { try { return fs.existsSync(command); } catch { return false; } }
|
|
146
|
+
const exts = process.platform === 'win32'
|
|
147
|
+
? (process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';')
|
|
148
|
+
: [''];
|
|
149
|
+
for (const dir of (process.env.PATH || '').split(path.delimiter).filter(Boolean)) {
|
|
150
|
+
for (const ext of exts) {
|
|
151
|
+
const p = path.join(dir, command + ext);
|
|
152
|
+
try {
|
|
153
|
+
if (process.platform === 'win32') { if (fs.statSync(p).isFile()) return true; }
|
|
154
|
+
else { fs.accessSync(p, fs.constants.X_OK); return true; }
|
|
155
|
+
} catch {}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 续聊命令缺失时的可操作提示
|
|
162
|
+
function missingCommandHint(agent, command) {
|
|
163
|
+
if (agent === 'Qoder') {
|
|
164
|
+
return '续聊未执行:未找到 qoder 命令。Qoder 远程续聊需要独立 CLI——'
|
|
165
|
+
+ 'npm install -g @qoder-ai/qodercli@latest,并执行 qoder login 登录(任务完成通知、提问作答、'
|
|
166
|
+
+ '权限审批不依赖 CLI,仍由桌面端 Hook 正常工作)。';
|
|
167
|
+
}
|
|
168
|
+
return `续聊未执行:未找到 ${command} 命令,请确认对应 CLI 已安装且在 PATH 上。`;
|
|
169
|
+
}
|
|
170
|
+
|
|
142
171
|
// 等待 CLI 进程结束,返回 { ok, code, stdout, stderr, reason, timedOut }
|
|
143
172
|
// opts.wrapCmd=false:直接 spawn command(Windows 下跳过 cmd /c 包装,避免参数引号被破坏)
|
|
144
173
|
// opts.writeStdin=false:不写 stdin(如 ZCode 用 --prompt 传消息)
|
|
@@ -221,9 +250,10 @@ async function runZcodeResume(text, { config, onLog, last }) {
|
|
|
221
250
|
? `续聊超时已中断(以下为超时前已生成的回复)\n\n${reply}`
|
|
222
251
|
: `续聊超时,未获取到回复。`;
|
|
223
252
|
} else {
|
|
253
|
+
const label = proc.code === 0 ? '续聊已完成' : '续聊未成功';
|
|
224
254
|
message = reply
|
|
225
|
-
?
|
|
226
|
-
:
|
|
255
|
+
? `${label}(退出码 ${proc.code})\n\n${reply}`
|
|
256
|
+
: `${label}(退出码 ${proc.code},无文本输出)`;
|
|
227
257
|
}
|
|
228
258
|
await sendNotification({ ...config, title: 'ZCode', message });
|
|
229
259
|
return { ok: true, code: proc.code };
|
|
@@ -283,6 +313,15 @@ export async function runResume(text, { config = null, onLog = (s) => {} } = {})
|
|
|
283
313
|
let replyFile = path.join(os.tmpdir(), `a4p-reply-${process.pid}-${Date.now()}.txt`);
|
|
284
314
|
let { command, args, newSessionId } = buildResumeArgs(agent, sessionId, cwd, replyFile);
|
|
285
315
|
|
|
316
|
+
// 命令不在 PATH 时 cmd.exe 只返回非 0 退出码 + 本地化乱码报错,
|
|
317
|
+
// 旧逻辑会把它当"续聊完成"推给手机,故启动前先预检
|
|
318
|
+
if (!commandAvailable(command)) {
|
|
319
|
+
const reason = missingCommandHint(agent, command);
|
|
320
|
+
if (lockedOut) setMode(prevMode);
|
|
321
|
+
onLog(reason);
|
|
322
|
+
return { ok: false, reason };
|
|
323
|
+
}
|
|
324
|
+
|
|
286
325
|
let proc = await spawnCli({
|
|
287
326
|
command,
|
|
288
327
|
args,
|
|
@@ -351,9 +390,10 @@ export async function runResume(text, { config = null, onLog = (s) => {} } = {})
|
|
|
351
390
|
? `续聊超时已中断(以下为超时前已生成的回复)\n\n${reply}`
|
|
352
391
|
: `续聊超时,未获取到回复。`;
|
|
353
392
|
} else {
|
|
393
|
+
const label = proc.code === 0 ? '续聊已完成' : '续聊未成功';
|
|
354
394
|
message = reply
|
|
355
|
-
?
|
|
356
|
-
:
|
|
395
|
+
? `${label}(退出码 ${proc.code})\n\n${reply}`
|
|
396
|
+
: `${label}(退出码 ${proc.code},无文本输出)`;
|
|
357
397
|
}
|
|
358
398
|
await sendNotification({ ...config, title: name, message });
|
|
359
399
|
return { ok: true, code: proc.code };
|