@triflux/remote 10.50.1 → 10.50.2

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.
@@ -1,62 +0,0 @@
1
- // cli-codex.mjs — Codex CLI adapter (Phase 0 PoC).
2
- //
3
- // 책임: agent 이름과 입력 파라미터를 받아 Codex 실행 계획(profile/effort/timeout/runMode)을
4
- // 산출한다. 실제 spawn 은 Phase 1 에서 이관된다 (현재는 tfx-route.sh 가 수행).
5
- //
6
- // 진입점: tfx-route.mjs → selectAdapter("codex") → plan({...}).
7
- // 출처: agent-route-policy.mjs 의 canonical Codex role policy.
8
- // timeoutSec은 lane 예상 소요 시간(advisory)이다. hard ceiling 집행은 Bash route가 소유한다.
9
-
10
- export const id = "codex";
11
- export const cliType = "codex";
12
- export const command = "codex";
13
-
14
- import {
15
- CODEX_AGENT_POLICY,
16
- resolveCodexAgentPolicy,
17
- resolveCodexAgentProfile,
18
- resolveNestedCodexAgentProfile,
19
- } from "./agent-route-policy.mjs";
20
-
21
- // Compatibility re-exports for launchers which historically imported these
22
- // helpers from this adapter. The policy module owns the semantics.
23
- export { resolveCodexAgentProfile, resolveNestedCodexAgentProfile };
24
-
25
- export function plan({
26
- agent,
27
- prompt = "",
28
- mcpProfile = "auto",
29
- timeoutSec,
30
- contextFile,
31
- profileOverride = "auto",
32
- retryProfile = null,
33
- nested = false,
34
- } = {}) {
35
- if (!agent) {
36
- throw new Error("[cli-codex] agent required");
37
- }
38
- const cfg = resolveCodexAgentPolicy(agent);
39
- const profile = resolveCodexAgentProfile(agent, {
40
- profileOverride,
41
- retryProfile,
42
- nested,
43
- });
44
- const effectiveTimeoutSec =
45
- Number.isFinite(timeoutSec) && timeoutSec > 0 ? timeoutSec : cfg.timeoutSec;
46
- return {
47
- command,
48
- subcommand: cfg.subcommand ?? "exec",
49
- profile,
50
- effort: profile,
51
- timeoutMs: effectiveTimeoutSec * 1000,
52
- runMode: cfg.runMode,
53
- opusOversight: cfg.opusOversight,
54
- mcpProfile: mcpProfile === "auto" ? cfg.mcpHint : mcpProfile,
55
- promptLength: prompt.length,
56
- contextFile: contextFile || null,
57
- };
58
- }
59
-
60
- export function describe() {
61
- return { id, cliType, command, agents: Object.keys(CODEX_AGENT_POLICY) };
62
- }
@@ -1,37 +0,0 @@
1
- // cli-gemini.mjs — legacy Gemini adapter alias.
2
- // The public "gemini" label remains accepted, but the executable plan is AGY.
3
-
4
- import * as agyAdapter from "./cli-agy.mjs";
5
-
6
- export const id = "gemini";
7
- export const cliType = "antigravity";
8
- export const command = "agy";
9
-
10
- export function plan({
11
- agent,
12
- prompt = "",
13
- mcpProfile = "auto",
14
- timeoutSec,
15
- contextFile,
16
- } = {}) {
17
- if (!agent) {
18
- throw new Error("[cli-gemini] agent required");
19
- }
20
- return agyAdapter.plan({
21
- agent: agent === "gemini" ? "antigravity" : agent,
22
- prompt,
23
- mcpProfile,
24
- timeoutSec,
25
- contextFile,
26
- });
27
- }
28
-
29
- export function describe() {
30
- return {
31
- id,
32
- cliType,
33
- command,
34
- aliases: ["gemini"],
35
- agents: ["gemini", "designer", "writer", "antigravity", "agy"],
36
- };
37
- }
@@ -1,14 +0,0 @@
1
- export function buildPreflightEnv(env = process.env) {
2
- return {
3
- ...env,
4
- GIT_TERMINAL_PROMPT: env.GIT_TERMINAL_PROMPT ?? "0",
5
- GIT_ASKPASS: env.GIT_ASKPASS ?? "false",
6
- npm_config_yes: env.npm_config_yes ?? "true",
7
- };
8
- }
9
-
10
- export function shouldWarnGhAuth(env = process.env, checks = {}) {
11
- if (!checks.ghExists) return false;
12
- if (env.GH_TOKEN || env.GITHUB_TOKEN) return false;
13
- return checks.ghAuthenticated === false;
14
- }
@@ -1,48 +0,0 @@
1
- import { spawn } from "node:child_process";
2
-
3
- export function parseHubPort(hubUrl = "") {
4
- try {
5
- const parsed = new URL(hubUrl);
6
- return parsed.port || "27888";
7
- } catch {
8
- return "27888";
9
- }
10
- }
11
-
12
- export async function restartHub({
13
- hubUrl = process.env.TFX_HUB_URL || "http://127.0.0.1:27888",
14
- hubServer,
15
- nodeBin = process.execPath,
16
- spawnFn = spawn,
17
- fetchFn = globalThis.fetch,
18
- sleepMs = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
19
- attempts = 8,
20
- } = {}) {
21
- if (!hubServer) return { ok: false, error: "hub_server_missing" };
22
- const port = parseHubPort(hubUrl);
23
- const child = spawnFn(nodeBin, [hubServer], {
24
- env: { ...process.env, TFX_HUB_PORT: port },
25
- stdio: "ignore",
26
- detached: true,
27
- });
28
- child.unref?.();
29
-
30
- for (let i = 0; i < attempts; i += 1) {
31
- await sleepMs(500);
32
- try {
33
- const response = await fetchFn(`${hubUrl.replace(/\/$/, "")}/status`);
34
- if (response?.ok) return { ok: true, pid: child.pid };
35
- } catch {
36
- // Keep polling until attempts are exhausted.
37
- }
38
- }
39
- return { ok: false, pid: child.pid };
40
- }
41
-
42
- export async function withHubRestart({ action, restart }) {
43
- const first = await action();
44
- if (first?.ok) return first;
45
- const restarted = await restart();
46
- if (!restarted?.ok) return first;
47
- return action();
48
- }
@@ -1,63 +0,0 @@
1
- import { appendFileSync, existsSync, readFileSync, rmSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
-
4
- const require = createRequire(import.meta.url);
5
- let treeKill = null;
6
- try {
7
- treeKill = require("tree-kill");
8
- } catch {
9
- treeKill = null;
10
- }
11
-
12
- function defaultIsAlive(pid) {
13
- try {
14
- process.kill(pid, 0);
15
- return true;
16
- } catch {
17
- return false;
18
- }
19
- }
20
-
21
- function defaultKillTree(pid) {
22
- return new Promise((resolve) => {
23
- if (treeKill) {
24
- treeKill(pid, "SIGTERM", () => resolve());
25
- return;
26
- }
27
- try {
28
- process.kill(pid, "SIGTERM");
29
- } catch {
30
- // Process already exited.
31
- }
32
- resolve();
33
- });
34
- }
35
-
36
- export class PidTracker {
37
- constructor(path, options = {}) {
38
- this.path = path;
39
- this.isAlive = options.isAlive ?? defaultIsAlive;
40
- this.killTree = options.killTree ?? defaultKillTree;
41
- }
42
-
43
- track(pid) {
44
- if (!pid) return;
45
- appendFileSync(this.path, `${pid}\n`);
46
- }
47
-
48
- list() {
49
- if (!existsSync(this.path)) return [];
50
- return readFileSync(this.path, "utf8")
51
- .split(/\r?\n/)
52
- .map((line) => Number(line.trim()))
53
- .filter((pid) => Number.isInteger(pid) && pid > 0);
54
- }
55
-
56
- async cleanup() {
57
- for (const pid of this.list()) {
58
- if (!this.isAlive(pid)) continue;
59
- await this.killTree(pid);
60
- }
61
- rmSync(this.path, { force: true });
62
- }
63
- }
@@ -1,47 +0,0 @@
1
- export const QUOTA_PATTERNS = [
2
- /usage limit exceeded/i,
3
- /rate limit exceeded/i,
4
- /rate limit reached/i,
5
- /try again at/i,
6
- /purchase more credits/i,
7
- /quota exceeded/i,
8
- /RESOURCE_EXHAUSTED/i,
9
- /rateLimitExceeded/i,
10
- /Too Many Requests/i,
11
- /rate_limit_error/i,
12
- /overloaded_error/i,
13
- /insufficient_quota/i,
14
- ];
15
-
16
- export class QuotaStreamBuffer {
17
- constructor({ maxBytes = 65536 } = {}) {
18
- this.maxBytes = maxBytes;
19
- this.text = "";
20
- }
21
-
22
- push(chunk) {
23
- this.text += Buffer.isBuffer(chunk)
24
- ? chunk.toString("utf8")
25
- : String(chunk);
26
- if (this.text.length > this.maxBytes) {
27
- this.text = this.text.slice(-this.maxBytes);
28
- }
29
- return detectQuotaText(this.text);
30
- }
31
- }
32
-
33
- export function detectQuotaText(text = "") {
34
- return QUOTA_PATTERNS.some((pattern) => pattern.test(text));
35
- }
36
-
37
- export function getRerouteTarget(cliType) {
38
- switch (cliType) {
39
- case "codex":
40
- case "gemini":
41
- return "antigravity";
42
- case "antigravity":
43
- return "codex";
44
- default:
45
- return null;
46
- }
47
- }
@@ -1,220 +0,0 @@
1
- import {
2
- access,
3
- mkdir,
4
- open,
5
- readdir,
6
- readFile,
7
- rename,
8
- rm,
9
- writeFile,
10
- } from "node:fs/promises";
11
- import { basename, join } from "node:path";
12
-
13
- const DEFAULT_STATE_DIR = join(process.cwd(), ".tfx", "state");
14
- const STOP_HOOKS = new Map();
15
-
16
- function stateFilePath(stateDir, skillName) {
17
- return join(stateDir, `${skillName}-active.json`);
18
- }
19
-
20
- function assertValidSkillName(skillName) {
21
- if (basename(skillName) !== skillName) {
22
- throw new Error(`Invalid skill name: ${skillName}`);
23
- }
24
- }
25
-
26
- function assertValidOnStop(onStop) {
27
- if (onStop !== undefined && typeof onStop !== "function") {
28
- throw new TypeError("onStop must be a function");
29
- }
30
- }
31
-
32
- async function readStateFile(filePath) {
33
- try {
34
- const raw = await readFile(filePath, "utf8");
35
- return JSON.parse(raw);
36
- } catch {
37
- return null;
38
- }
39
- }
40
-
41
- function rememberStopHook(filePath, onStop) {
42
- if (typeof onStop === "function") {
43
- STOP_HOOKS.set(filePath, onStop);
44
- return;
45
- }
46
- STOP_HOOKS.delete(filePath);
47
- }
48
-
49
- function logStopHookWarning(message, error) {
50
- if (error) {
51
- console.warn(message, error);
52
- return;
53
- }
54
- console.warn(message);
55
- }
56
-
57
- async function runStopHook(filePath, state, onStop) {
58
- if (!state?.hasStopHook) {
59
- STOP_HOOKS.delete(filePath);
60
- return;
61
- }
62
-
63
- const hook = onStop ?? STOP_HOOKS.get(filePath);
64
- STOP_HOOKS.delete(filePath);
65
-
66
- if (typeof hook !== "function") {
67
- return;
68
- }
69
-
70
- try {
71
- await hook({
72
- skillName: state.skillName,
73
- filePath,
74
- state,
75
- });
76
- } catch (error) {
77
- logStopHookWarning(
78
- `Failed to run stop-hook for skill: ${state.skillName}`,
79
- error,
80
- );
81
- }
82
- }
83
-
84
- /**
85
- * Activate a skill by writing its state file.
86
- * Throws if the skill is already active.
87
- *
88
- * @param {string} skillName
89
- * @param {{ stateDir?: string, onStop?: (() => Promise<void> | void) }} options
90
- */
91
- export async function activateSkill(
92
- skillName,
93
- { stateDir = DEFAULT_STATE_DIR, onStop } = {},
94
- ) {
95
- assertValidSkillName(skillName);
96
- assertValidOnStop(onStop);
97
-
98
- await mkdir(stateDir, { recursive: true });
99
-
100
- const filePath = stateFilePath(stateDir, skillName);
101
- const lockPath = `${filePath}.lock`;
102
- const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
103
- let lockHandle;
104
-
105
- try {
106
- lockHandle = await open(lockPath, "wx");
107
- try {
108
- await access(filePath);
109
- throw new Error(`Skill already active: ${skillName}`);
110
- } catch (error) {
111
- if (error?.message === `Skill already active: ${skillName}`) {
112
- throw error;
113
- }
114
- if (error?.code !== "ENOENT") {
115
- throw error;
116
- }
117
- }
118
-
119
- const state = {
120
- skillName,
121
- pid: process.pid,
122
- activatedAt: Date.now(),
123
- hasStopHook: typeof onStop === "function",
124
- };
125
- await writeFile(tmpPath, JSON.stringify(state), "utf8");
126
- await rename(tmpPath, filePath);
127
- rememberStopHook(filePath, onStop);
128
- } finally {
129
- await rm(tmpPath, { force: true }).catch(() => {});
130
- if (lockHandle) {
131
- await lockHandle.close().catch(() => {});
132
- }
133
- await rm(lockPath, { force: true }).catch(() => {});
134
- }
135
- }
136
-
137
- /**
138
- * Deactivate a skill by removing its state file.
139
- * Does not throw if the file does not exist.
140
- *
141
- * @param {string} skillName
142
- * @param {{ stateDir?: string, onStop?: (() => Promise<void> | void) }} options
143
- */
144
- export async function deactivateSkill(
145
- skillName,
146
- { stateDir = DEFAULT_STATE_DIR, onStop } = {},
147
- ) {
148
- assertValidOnStop(onStop);
149
-
150
- const filePath = stateFilePath(stateDir, skillName);
151
- const state = await readStateFile(filePath);
152
-
153
- try {
154
- await runStopHook(filePath, state, onStop);
155
- } finally {
156
- STOP_HOOKS.delete(filePath);
157
- await rm(filePath, { force: true }).catch(() => {});
158
- }
159
- }
160
-
161
- /**
162
- * Return all currently active skills by scanning *-active.json files.
163
- *
164
- * @param {{ stateDir?: string }} options
165
- * @returns {Promise<Array<{ skillName: string, pid: number, activatedAt: number, hasStopHook?: boolean }>>}
166
- */
167
- export async function getActiveSkills({ stateDir = DEFAULT_STATE_DIR } = {}) {
168
- let entries;
169
- try {
170
- entries = await readdir(stateDir);
171
- } catch {
172
- return [];
173
- }
174
-
175
- const results = [];
176
- for (const entry of entries) {
177
- if (!entry.endsWith("-active.json")) continue;
178
- const state = await readStateFile(join(stateDir, entry));
179
- if (state) {
180
- results.push(state);
181
- }
182
- }
183
- return results;
184
- }
185
-
186
- /**
187
- * Remove state files for skills whose processes are no longer alive.
188
- *
189
- * @param {{ stateDir?: string }} options
190
- * @returns {Promise<string[]>} list of pruned skill names
191
- */
192
- export async function pruneOrphanSkillStates({
193
- stateDir = DEFAULT_STATE_DIR,
194
- } = {}) {
195
- const active = await getActiveSkills({ stateDir });
196
- const pruned = [];
197
-
198
- for (const state of active) {
199
- let alive = true;
200
- try {
201
- process.kill(state.pid, 0);
202
- } catch {
203
- alive = false;
204
- }
205
-
206
- if (!alive) {
207
- const filePath = stateFilePath(stateDir, state.skillName);
208
- STOP_HOOKS.delete(filePath);
209
- if (state.hasStopHook) {
210
- logStopHookWarning(
211
- `Skipping stop-hook for orphaned skill state: ${state.skillName}`,
212
- );
213
- }
214
- await rm(filePath, { force: true }).catch(() => {});
215
- pruned.push(state.skillName);
216
- }
217
- }
218
-
219
- return pruned;
220
- }
@@ -1,75 +0,0 @@
1
- import { mkdirSync, writeFileSync } from "node:fs";
2
- import { join } from "node:path";
3
-
4
- function teamContext(env) {
5
- const team = env.TFX_TEAM_NAME || "";
6
- const taskId = env.TFX_TEAM_TASK_ID || "";
7
- if (!team || !taskId) return null;
8
- return {
9
- team,
10
- taskId,
11
- agent: env.TFX_TEAM_AGENT_NAME || "agent",
12
- lead: env.TFX_TEAM_LEAD_NAME || "team-lead",
13
- };
14
- }
15
-
16
- export async function claimTask({ env = process.env, bridge } = {}) {
17
- const ctx = teamContext(env);
18
- if (!ctx) return { skipped: true };
19
- const response = await bridge.claim({
20
- team: ctx.team,
21
- taskId: ctx.taskId,
22
- owner: ctx.agent,
23
- status: "in_progress",
24
- });
25
- if (response?.ok) return { claimed: true };
26
- const code = response?.error?.code;
27
- const before = response?.error?.details?.task_before ?? {};
28
- if (
29
- code === "CLAIM_CONFLICT" &&
30
- before.owner === ctx.agent &&
31
- before.status === "in_progress"
32
- ) {
33
- return { claimed: true, alreadyClaimed: true };
34
- }
35
- if (code === "CLAIM_CONFLICT") {
36
- return { claimed: false, conflict: true, owner: before.owner ?? null };
37
- }
38
- return { claimed: false, error: response?.error ?? null };
39
- }
40
-
41
- export async function completeTask({
42
- env = process.env,
43
- bridge,
44
- result = "success",
45
- summary = "작업 완료",
46
- now = () => new Date().toISOString(),
47
- } = {}) {
48
- const ctx = teamContext(env);
49
- if (!ctx) return { skipped: true };
50
- const trimmed = String(summary).slice(0, 4096);
51
- const response = await bridge.complete({
52
- team: ctx.team,
53
- taskId: ctx.taskId,
54
- agent: ctx.agent,
55
- result,
56
- summary: trimmed,
57
- });
58
-
59
- const resultDir =
60
- env.TFX_RESULT_DIR ||
61
- join(process.env.HOME || ".", ".claude", "tfx-results", ctx.team);
62
- mkdirSync(resultDir, { recursive: true });
63
- writeFileSync(
64
- join(resultDir, `${ctx.taskId}.json`),
65
- `${JSON.stringify({
66
- taskId: ctx.taskId,
67
- agent: ctx.agent,
68
- team: ctx.team,
69
- result,
70
- summary: trimmed,
71
- timestamp: now(),
72
- })}\n`,
73
- );
74
- return { completed: Boolean(response?.ok), response };
75
- }
@@ -1,66 +0,0 @@
1
- import { spawn } from "node:child_process";
2
-
3
- export function timeoutCodeForSignal(signal) {
4
- return signal ? 124 : null;
5
- }
6
-
7
- export function runWithTimeout(command, args = [], options = {}) {
8
- const {
9
- cwd = process.cwd(),
10
- env = process.env,
11
- input,
12
- timeoutMs = 0,
13
- stdio = "pipe",
14
- spawnFn = spawn,
15
- } = options;
16
-
17
- return new Promise((resolve, reject) => {
18
- const controller = new AbortController();
19
- let timedOut = false;
20
- const child = spawnFn(command, args, {
21
- cwd,
22
- env,
23
- stdio,
24
- signal: controller.signal,
25
- });
26
- const stdout = [];
27
- const stderr = [];
28
- let timer = null;
29
-
30
- if (child.stdout) child.stdout.on("data", (chunk) => stdout.push(chunk));
31
- if (child.stderr) child.stderr.on("data", (chunk) => stderr.push(chunk));
32
- child.on("error", (err) => {
33
- if (timedOut && err.name === "AbortError") return;
34
- reject(err);
35
- });
36
- child.on("exit", (code, signal) => {
37
- if (timer) clearTimeout(timer);
38
- resolve({
39
- code: timedOut ? 124 : (code ?? timeoutCodeForSignal(signal) ?? 1),
40
- signal,
41
- timedOut,
42
- stdout: Buffer.concat(stdout).toString("utf8"),
43
- stderr: Buffer.concat(stderr).toString("utf8"),
44
- });
45
- });
46
-
47
- if (timeoutMs > 0) {
48
- timer = setTimeout(() => {
49
- timedOut = true;
50
- controller.abort();
51
- if (child.pid) {
52
- try {
53
- process.kill(child.pid, "SIGTERM");
54
- } catch {
55
- // Process already exited.
56
- }
57
- }
58
- }, timeoutMs);
59
- timer.unref?.();
60
- }
61
-
62
- if (input !== undefined && child.stdin) {
63
- child.stdin.end(input);
64
- }
65
- });
66
- }
@@ -1,26 +0,0 @@
1
- import { mkdirSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- export function resolveTmpDir({ env = process.env, cwd = process.cwd() } = {}) {
6
- const candidate = env.TFX_TMP || tmpdir();
7
- try {
8
- mkdirSync(candidate, { recursive: true });
9
- return candidate;
10
- } catch {
11
- const fallback = join(cwd, ".tfx-tmp");
12
- try {
13
- mkdirSync(fallback, { recursive: true });
14
- } catch {
15
- // Bash printed the fallback path even when mkdir failed.
16
- }
17
- return fallback;
18
- }
19
- }
20
-
21
- export function resolveJobsDir({
22
- env = process.env,
23
- tmpDir = resolveTmpDir({ env }),
24
- } = {}) {
25
- return env.TFX_JOBS_DIR || join(tmpDir, "tfx-jobs");
26
- }