@brierb/brier-cli 0.0.5 → 0.0.6
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 +21 -6
- package/dist/runtimes.js +13 -0
- package/dist/tunnel/TunnelClient.js +1 -0
- package/package.json +1 -1
- package/types/runtimes.d.ts +6 -0
- package/types/types.d.ts +3 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { logger } from '../logger.js';
|
|
3
|
-
import { RUNTIME_COMMANDS } from '../runtimes.js';
|
|
3
|
+
import { RUNTIME_COMMANDS, RUNTIME_PROMPT_FLAGS } from '../runtimes.js';
|
|
4
4
|
const MAX_CONCURRENT = 3;
|
|
5
5
|
export const createTaskExecutor = (callbacks) => {
|
|
6
6
|
const processes = new Map();
|
|
@@ -8,9 +8,19 @@ export const createTaskExecutor = (callbacks) => {
|
|
|
8
8
|
if (task.command)
|
|
9
9
|
return task.command;
|
|
10
10
|
const mapped = RUNTIME_COMMANDS[task.runtime];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
return mapped ?? null;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* 拼执行参数:
|
|
15
|
+
* - prompt 模式(AI runtime):命令前缀 flags + prompt 原文
|
|
16
|
+
* - 命令模式:透传服务端给的 args
|
|
17
|
+
*/
|
|
18
|
+
const buildArgs = (task) => {
|
|
19
|
+
if (task.prompt) {
|
|
20
|
+
const flags = RUNTIME_PROMPT_FLAGS[task.runtime] ?? [];
|
|
21
|
+
return [...flags, task.prompt];
|
|
22
|
+
}
|
|
23
|
+
return task.args ?? [];
|
|
14
24
|
};
|
|
15
25
|
const execute = (task) => {
|
|
16
26
|
if (processes.has(task.taskId)) {
|
|
@@ -22,11 +32,16 @@ export const createTaskExecutor = (callbacks) => {
|
|
|
22
32
|
return;
|
|
23
33
|
}
|
|
24
34
|
const cmd = resolveCommand(task);
|
|
35
|
+
if (!cmd) {
|
|
36
|
+
callbacks.onError(task.taskId, `Cannot resolve command for runtime: ${task.runtime} (no command provided)`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const args = buildArgs(task);
|
|
25
40
|
const childEnv = task.env ? { ...process.env, ...task.env } : process.env;
|
|
26
|
-
logger.info(`Task ${task.taskId} starting: ${cmd} ${
|
|
41
|
+
logger.info(`Task ${task.taskId} starting: ${cmd} ${args.join(' ')}`, task.runtime);
|
|
27
42
|
let child;
|
|
28
43
|
try {
|
|
29
|
-
child = spawn(cmd,
|
|
44
|
+
child = spawn(cmd, args, {
|
|
30
45
|
cwd: task.cwd,
|
|
31
46
|
env: childEnv,
|
|
32
47
|
stdio: ['pipe', 'pipe', 'pipe'],
|
package/dist/runtimes.js
CHANGED
|
@@ -14,3 +14,16 @@ export const RUNTIME_REGISTRY = [
|
|
|
14
14
|
{ name: 'Cody', command: 'cody', fallbacks: ['~/.local/bin/cody'] },
|
|
15
15
|
];
|
|
16
16
|
export const RUNTIME_COMMANDS = Object.fromEntries(RUNTIME_REGISTRY.map((r) => [r.name, r.command]));
|
|
17
|
+
/**
|
|
18
|
+
* AI runtime 单次(非交互)执行参数模板:命令前缀 flags,后面紧跟 prompt。
|
|
19
|
+
* 服务端 task-start 携带 prompt 时,CLI 用它拼出
|
|
20
|
+
* `spawn(<command>, [...flags, prompt])`;未列出的 runtime 按裸参数执行。
|
|
21
|
+
*/
|
|
22
|
+
export const RUNTIME_PROMPT_FLAGS = {
|
|
23
|
+
'OpenCode': ['run'],
|
|
24
|
+
'Claude Code': ['-p'],
|
|
25
|
+
'Codex CLI': ['exec'],
|
|
26
|
+
'Gemini CLI': ['-p'],
|
|
27
|
+
'Aider': ['--message'],
|
|
28
|
+
'Goose': ['run'],
|
|
29
|
+
};
|
package/package.json
CHANGED
package/types/runtimes.d.ts
CHANGED
|
@@ -6,3 +6,9 @@ export interface RuntimeEntry {
|
|
|
6
6
|
}
|
|
7
7
|
export declare const RUNTIME_REGISTRY: readonly RuntimeEntry[];
|
|
8
8
|
export declare const RUNTIME_COMMANDS: Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* AI runtime 单次(非交互)执行参数模板:命令前缀 flags,后面紧跟 prompt。
|
|
11
|
+
* 服务端 task-start 携带 prompt 时,CLI 用它拼出
|
|
12
|
+
* `spawn(<command>, [...flags, prompt])`;未列出的 runtime 按裸参数执行。
|
|
13
|
+
*/
|
|
14
|
+
export declare const RUNTIME_PROMPT_FLAGS: Record<string, readonly string[]>;
|
package/types/types.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export type ServerMessage = {
|
|
|
45
45
|
args: string[];
|
|
46
46
|
cwd?: string;
|
|
47
47
|
env?: Record<string, string>;
|
|
48
|
+
prompt?: string;
|
|
48
49
|
} | {
|
|
49
50
|
type: 'task-cancel';
|
|
50
51
|
taskId: string;
|
|
@@ -58,6 +59,8 @@ export interface TaskInfo {
|
|
|
58
59
|
args: string[];
|
|
59
60
|
cwd?: string;
|
|
60
61
|
env?: Record<string, string>;
|
|
62
|
+
/** 自然语言指令(AI runtime 模式:拼到 runtime 命令参数中执行) */
|
|
63
|
+
prompt?: string;
|
|
61
64
|
}
|
|
62
65
|
export interface DaemonConfig {
|
|
63
66
|
serverUrl: string;
|