triflux 7.3.2 → 7.4.0

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/hub/team/pane.mjs CHANGED
@@ -1,150 +1,154 @@
1
- // hub/team/pane.mjs — pane별 CLI 실행 + stdin 주입
2
- // 의존성: child_process, fs, os, path (Node.js 내장)만 사용
3
- import { writeFileSync, unlinkSync, mkdirSync } from "node:fs";
4
- import { join } from "node:path";
5
- import { tmpdir } from "node:os";
6
- import { detectMultiplexer, tmuxExec } from "./session.mjs";
7
- import { psmuxExec } from "./psmux.mjs";
8
-
9
- function quoteArg(value) {
10
- return `"${String(value).replace(/"/g, '\\"')}"`;
11
- }
12
-
13
- function getPsmuxSessionName(target) {
14
- return String(target).split(":")[0]?.trim() || "";
15
- }
16
-
17
- /** Windows 경로를 멀티플렉서용 경로로 변환 */
18
- function toMuxPath(p) {
19
- if (process.platform !== "win32") return p;
20
-
21
- const mux = detectMultiplexer();
22
-
23
- // psmux는 Windows 네이티브 경로 그대로 사용
24
- if (mux === "psmux") return p;
25
-
26
- const normalized = p.replace(/\\/g, "/");
27
- const m = normalized.match(/^([A-Za-z]):\/(.*)$/);
28
- if (!m) return normalized;
29
-
30
- const drive = m[1].toLowerCase();
31
- const rest = m[2];
32
-
33
- // wsl tmux는 /mnt/c/... 경로를 사용
34
- if (mux === "wsl-tmux") {
35
- return `/mnt/${drive}/${rest}`;
36
- }
37
-
38
- // Git Bash/MSYS tmux는 /c/... 경로를 사용
39
- return `/${drive}/${rest}`;
40
- }
41
-
42
- /** 멀티플렉서 커맨드 실행 (session.mjs와 동일 패턴) */
43
- function muxExec(args, opts = {}) {
44
- const exec = detectMultiplexer() === "psmux" ? psmuxExec : tmuxExec;
45
- return exec(args, {
46
- encoding: "utf8",
47
- timeout: 10000,
48
- stdio: ["pipe", "pipe", "pipe"],
49
- windowsHide: true,
50
- ...opts,
51
- });
52
- }
53
-
54
- /**
55
- * CLI 에이전트 시작 커맨드 생성
56
- * @param {'codex'|'gemini'|'claude'} cli
57
- * @param {{ trustMode?: boolean }} [options]
58
- * @returns {string} 실행할 커맨드
59
- */
60
- export function buildCliCommand(cli, options = {}) {
61
- const { trustMode = false } = options;
62
-
63
- switch (cli) {
64
- case "codex":
65
- // trust 모드에서는 승인/샌드박스 우회 + alt-screen 비활성화
66
- return trustMode
67
- ? "codex --dangerously-bypass-approvals-and-sandbox --no-alt-screen"
68
- : "codex";
69
- case "gemini":
70
- // interactive 모드 — MCP는 ~/.gemini/settings.json에 사전 등록
71
- return "gemini";
72
- case "claude":
73
- // interactive 모드
74
- return "claude";
75
- default:
76
- return cli; // 커스텀 CLI 허용
77
- }
78
- }
79
-
80
- /**
81
- * pane에 CLI 시작
82
- * @param {string} target — 예: tfx-multi-abc:0.1
83
- * @param {string} command — 실행할 커맨드
84
- */
85
- export function startCliInPane(target, command) {
86
- // CLI 시작도 buffer paste를 재사용해 셸/플랫폼별 quoting 차이를 제거한다.
87
- injectPrompt(target, command);
88
- }
89
-
90
- /**
91
- * pane에 프롬프트 주입 (load-buffer + paste-buffer 방식)
92
- * 멀티라인 + 특수문자 안전, 크기 제한 없음
93
- * @param {string} target — 예: tfx-multi-abc:0.1
94
- * @param {string} prompt — 주입할 텍스트
95
- */
96
- /**
97
- * pane에 프롬프트 주입
98
- * @param {string} target예: tfx-multi-abc:0.1
99
- * @param {string} prompt — 주입할 텍스트
100
- * @param {object} [opts]
101
- * @param {boolean} [opts.useFileRef] — true면 TUI용 @file 참조 방식 (psmux 전용)
102
- */
103
- export function injectPrompt(target, prompt, { useFileRef = false } = {}) {
104
- const tmpDir = join(tmpdir(), "tfx-multi");
105
- mkdirSync(tmpDir, { recursive: true });
106
-
107
- const safeTarget = target.replace(/[:.]/g, "-");
108
- const tmpFile = join(tmpDir, `prompt-${safeTarget}-${Date.now()}.txt`);
109
-
110
- // psmux + TUI 앱: @file 참조로 주입 (paste-buffer는 TUI와 호환 안 됨)
111
- if (detectMultiplexer() === "psmux" && useFileRef) {
112
- writeFileSync(tmpFile, prompt, "utf8");
113
- const filePath = tmpFile.replace(/\\/g, "/");
114
- psmuxExec(["select-pane", "-t", target]);
115
- psmuxExec(["send-keys", "-t", target, "-l", `@${filePath}`]);
116
- psmuxExec(["send-keys", "-t", target, "Enter"]);
117
- // TUI가 파일을 읽을 시간을 주고 정리
118
- setTimeout(() => { try { unlinkSync(tmpFile); } catch {} }, 10000);
119
- return;
120
- }
121
-
122
- try {
123
- writeFileSync(tmpFile, prompt, "utf8");
124
-
125
- if (detectMultiplexer() === "psmux") {
126
- const sessionName = getPsmuxSessionName(target);
127
- psmuxExec(["load-buffer", "-t", sessionName, toMuxPath(tmpFile)]);
128
- psmuxExec(["select-pane", "-t", target]);
129
- psmuxExec(["paste-buffer", "-t", target]);
130
- psmuxExec(["send-keys", "-t", target, "Enter"]);
131
- return;
132
- }
133
-
134
- // tmux load-buffer → paste-buffer Enter
135
- muxExec(`load-buffer ${quoteArg(toMuxPath(tmpFile))}`);
136
- muxExec(`paste-buffer -t ${target}`);
137
- muxExec(`send-keys -t ${target} Enter`);
138
- } finally {
139
- try { unlinkSync(tmpFile); } catch {}
140
- }
141
- }
142
-
143
- /**
144
- * pane에 키 입력 전송
145
- * @param {string} target — 예: tfx-multi-abc:0.1
146
- * @param {string} keys — tmux 키 표현 (예: 'C-c', 'Enter')
147
- */
148
- export function sendKeys(target, keys) {
149
- muxExec(`send-keys -t ${target} ${keys}`);
150
- }
1
+ // hub/team/pane.mjs — pane별 CLI 실행 + stdin 주입
2
+ // 의존성: child_process, fs, os, path (Node.js 내장)만 사용
3
+ import { writeFileSync, unlinkSync, mkdirSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { tmpdir } from "node:os";
6
+ import { detectMultiplexer, tmuxExec } from "./session.mjs";
7
+ import { psmuxExec } from "./psmux.mjs";
8
+ import { FEATURES } from "./codex-compat.mjs";
9
+
10
+ function quoteArg(value) {
11
+ return `"${String(value).replace(/"/g, '\\"')}"`;
12
+ }
13
+
14
+ function getPsmuxSessionName(target) {
15
+ return String(target).split(":")[0]?.trim() || "";
16
+ }
17
+
18
+ /** Windows 경로를 멀티플렉서용 경로로 변환 */
19
+ function toMuxPath(p) {
20
+ if (process.platform !== "win32") return p;
21
+
22
+ const mux = detectMultiplexer();
23
+
24
+ // psmux는 Windows 네이티브 경로 그대로 사용
25
+ if (mux === "psmux") return p;
26
+
27
+ const normalized = p.replace(/\\/g, "/");
28
+ const m = normalized.match(/^([A-Za-z]):\/(.*)$/);
29
+ if (!m) return normalized;
30
+
31
+ const drive = m[1].toLowerCase();
32
+ const rest = m[2];
33
+
34
+ // wsl tmux /mnt/c/... 경로를 사용
35
+ if (mux === "wsl-tmux") {
36
+ return `/mnt/${drive}/${rest}`;
37
+ }
38
+
39
+ // Git Bash/MSYS tmux는 /c/... 경로를 사용
40
+ return `/${drive}/${rest}`;
41
+ }
42
+
43
+ /** 멀티플렉서 커맨드 실행 (session.mjs와 동일 패턴) */
44
+ function muxExec(args, opts = {}) {
45
+ const exec = detectMultiplexer() === "psmux" ? psmuxExec : tmuxExec;
46
+ return exec(args, {
47
+ encoding: "utf8",
48
+ timeout: 10000,
49
+ stdio: ["pipe", "pipe", "pipe"],
50
+ windowsHide: true,
51
+ ...opts,
52
+ });
53
+ }
54
+
55
+ /**
56
+ * CLI 에이전트 시작 커맨드 생성
57
+ * @param {'codex'|'gemini'|'claude'} cli
58
+ * @param {{ trustMode?: boolean }} [options]
59
+ * @returns {string} 실행할 셸 커맨드
60
+ */
61
+ export function buildCliCommand(cli, options = {}) {
62
+ const { trustMode = false } = options;
63
+
64
+ switch (cli) {
65
+ case "codex":
66
+ // trust 모드에서는 exec 서브커맨드(0.117.0+) 또는 구버전 플래그 사용
67
+ if (trustMode) {
68
+ return FEATURES.execSubcommand
69
+ ? "codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check"
70
+ : "codex --dangerously-bypass-approvals-and-sandbox --no-alt-screen";
71
+ }
72
+ return "codex";
73
+ case "gemini":
74
+ // interactive 모드 — MCP는 ~/.gemini/settings.json에 사전 등록
75
+ return "gemini";
76
+ case "claude":
77
+ // interactive 모드
78
+ return "claude";
79
+ default:
80
+ return cli; // 커스텀 CLI 허용
81
+ }
82
+ }
83
+
84
+ /**
85
+ * pane에 CLI 시작
86
+ * @param {string} target 예: tfx-multi-abc:0.1
87
+ * @param {string} command — 실행할 커맨드
88
+ */
89
+ export function startCliInPane(target, command) {
90
+ // CLI 시작도 buffer paste를 재사용해 셸/플랫폼별 quoting 차이를 제거한다.
91
+ injectPrompt(target, command);
92
+ }
93
+
94
+ /**
95
+ * pane에 프롬프트 주입 (load-buffer + paste-buffer 방식)
96
+ * 멀티라인 + 특수문자 안전, 크기 제한 없음
97
+ * @param {string} target — 예: tfx-multi-abc:0.1
98
+ * @param {string} prompt주입할 텍스트
99
+ */
100
+ /**
101
+ * pane에 프롬프트 주입
102
+ * @param {string} target — 예: tfx-multi-abc:0.1
103
+ * @param {string} prompt 주입할 텍스트
104
+ * @param {object} [opts]
105
+ * @param {boolean} [opts.useFileRef] true TUI용 @file 참조 방식 (psmux 전용)
106
+ */
107
+ export function injectPrompt(target, prompt, { useFileRef = false } = {}) {
108
+ const tmpDir = join(tmpdir(), "tfx-multi");
109
+ mkdirSync(tmpDir, { recursive: true });
110
+
111
+ const safeTarget = target.replace(/[:.]/g, "-");
112
+ const tmpFile = join(tmpDir, `prompt-${safeTarget}-${Date.now()}.txt`);
113
+
114
+ // psmux + TUI 앱: @file 참조로 주입 (paste-buffer는 TUI와 호환 안 됨)
115
+ if (detectMultiplexer() === "psmux" && useFileRef) {
116
+ writeFileSync(tmpFile, prompt, "utf8");
117
+ const filePath = tmpFile.replace(/\\/g, "/");
118
+ psmuxExec(["select-pane", "-t", target]);
119
+ psmuxExec(["send-keys", "-t", target, "-l", `@${filePath}`]);
120
+ psmuxExec(["send-keys", "-t", target, "Enter"]);
121
+ // TUI가 파일을 읽을 시간을 주고 정리
122
+ setTimeout(() => { try { unlinkSync(tmpFile); } catch {} }, 10000);
123
+ return;
124
+ }
125
+
126
+ try {
127
+ writeFileSync(tmpFile, prompt, "utf8");
128
+
129
+ if (detectMultiplexer() === "psmux") {
130
+ const sessionName = getPsmuxSessionName(target);
131
+ psmuxExec(["load-buffer", "-t", sessionName, toMuxPath(tmpFile)]);
132
+ psmuxExec(["select-pane", "-t", target]);
133
+ psmuxExec(["paste-buffer", "-t", target]);
134
+ psmuxExec(["send-keys", "-t", target, "Enter"]);
135
+ return;
136
+ }
137
+
138
+ // tmux load-buffer → paste-buffer → Enter
139
+ muxExec(`load-buffer ${quoteArg(toMuxPath(tmpFile))}`);
140
+ muxExec(`paste-buffer -t ${target}`);
141
+ muxExec(`send-keys -t ${target} Enter`);
142
+ } finally {
143
+ try { unlinkSync(tmpFile); } catch {}
144
+ }
145
+ }
146
+
147
+ /**
148
+ * pane에 입력 전송
149
+ * @param {string} target — 예: tfx-multi-abc:0.1
150
+ * @param {string} keys — tmux 키 표현 (예: 'C-c', 'Enter')
151
+ */
152
+ export function sendKeys(target, keys) {
153
+ muxExec(`send-keys -t ${target} ${keys}`);
154
+ }