@brierb/brier-cli 0.0.11 → 0.0.12
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/dist/daemon/TaskExecutor.js +15 -4
- package/package.json +1 -1
|
@@ -118,8 +118,11 @@ export const createTaskExecutor = (callbacks) => {
|
|
|
118
118
|
* pty 模式:伪终端交互子进程。
|
|
119
119
|
* CLI 检测到 tty 后进入交互模式(会提问、渲染进度、等待输入);
|
|
120
120
|
* 屏幕字节经 onData 上行(含 ANSI),用户输入经 writeInput 写入(模拟击键)。
|
|
121
|
+
*
|
|
122
|
+
* 与 pipe 模式的关键差异:prompt 任务不再把 prompt 拼成命令行参数,
|
|
123
|
+
* 而是启动后作为“用户输入”敲进终端(交互式 CLI 从会话里读取首条消息)。
|
|
121
124
|
*/
|
|
122
|
-
const executePty = (task, cmd, args, childEnv) => {
|
|
125
|
+
const executePty = (task, cmd, args, childEnv, initialInput) => {
|
|
123
126
|
let handle;
|
|
124
127
|
try {
|
|
125
128
|
handle = pty.spawn(cmd, args, {
|
|
@@ -136,6 +139,10 @@ export const createTaskExecutor = (callbacks) => {
|
|
|
136
139
|
}
|
|
137
140
|
ptyProcs.set(task.taskId, handle);
|
|
138
141
|
logger.info(`Task ${task.taskId} started in pty mode: ${cmd} ${args.join(' ')}`, task.runtime);
|
|
142
|
+
// prompt 作为首条会话消息敲入(补回车触发提交);无 prompt(command 模式)不注入
|
|
143
|
+
if (initialInput) {
|
|
144
|
+
handle.write(initialInput);
|
|
145
|
+
}
|
|
139
146
|
handle.onData((data) => {
|
|
140
147
|
// pty 只有一路输出(合并 stdout/stderr 的终端字节流),统一按 stdout 上行;
|
|
141
148
|
// 前端如需区分文本/控制序列,属于展示层解析,不在执行层拆流。
|
|
@@ -168,13 +175,17 @@ export const createTaskExecutor = (callbacks) => {
|
|
|
168
175
|
callbacks.onError(task.taskId, `Cannot resolve command for runtime: ${task.runtime} (no command provided)`);
|
|
169
176
|
return;
|
|
170
177
|
}
|
|
171
|
-
const args = buildArgs(task);
|
|
172
178
|
const childEnv = buildEnv(task);
|
|
173
179
|
if (task.execMode === 'pty') {
|
|
174
|
-
|
|
180
|
+
// 交互模式:prompt 不拼参数,作为首条输入敲入;command 模式透传 args
|
|
181
|
+
const args = task.prompt ? [] : (task.args ?? []);
|
|
182
|
+
const initialInput = task.prompt !== undefined && task.prompt.trim() !== ''
|
|
183
|
+
? `${task.prompt.replace(/\r?\n/g, '\r')}\r`
|
|
184
|
+
: undefined;
|
|
185
|
+
executePty(task, cmd, args, childEnv, initialInput);
|
|
175
186
|
return;
|
|
176
187
|
}
|
|
177
|
-
executePipe(task, cmd,
|
|
188
|
+
executePipe(task, cmd, buildArgs(task), childEnv);
|
|
178
189
|
};
|
|
179
190
|
const writeInput = (taskId, data) => {
|
|
180
191
|
if (!data)
|