@triflux/core 10.43.0 → 10.45.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.
Files changed (41) hide show
  1. package/hooks/codex-session-hook.mjs +67 -1
  2. package/hooks/cto-north-star-brief.mjs +3 -16
  3. package/hooks/error-context.mjs +3 -6
  4. package/hooks/hook-manager.mjs +1 -1
  5. package/hooks/hook-registry.json +0 -11
  6. package/hooks/keyword-rules.json +147 -23
  7. package/hooks/permission-safe-allow.mjs +36 -2
  8. package/hooks/session-start-fast.mjs +50 -1
  9. package/hooks/session-start-lake.mjs +3 -16
  10. package/hub/bridge.mjs +111 -5
  11. package/hub/cli-adapter-base.mjs +11 -2
  12. package/hub/codex-adapter.mjs +3 -0
  13. package/hub/gemini-adapter.mjs +29 -11
  14. package/hub/intent.mjs +24 -32
  15. package/hub/lib/memory-store.mjs +66 -30
  16. package/hub/lib/tfx-route-args.mjs +41 -4
  17. package/hub/reflexion.mjs +0 -57
  18. package/hub/router.mjs +474 -24
  19. package/hub/team/claude-daemon-control.mjs +2 -0
  20. package/hub/team/intervention.mjs +1 -1
  21. package/hub/team/retry-state-machine.mjs +41 -13
  22. package/hub/team/synapse-http.mjs +149 -4
  23. package/hud/cli-policy.mjs +69 -0
  24. package/hud/constants.mjs +20 -17
  25. package/hud/context-monitor.mjs +31 -21
  26. package/hud/hud-qos-status.mjs +81 -91
  27. package/hud/providers/claude.mjs +150 -84
  28. package/hud/providers/codex.mjs +10 -1
  29. package/hud/renderers.mjs +21 -59
  30. package/hud/utils.mjs +1 -15
  31. package/package.json +1 -1
  32. package/scripts/lib/agent-route-policy.mjs +367 -0
  33. package/scripts/lib/cli-agy.mjs +24 -4
  34. package/scripts/lib/cli-codex.mjs +22 -160
  35. package/scripts/lib/codex-profile-config.mjs +48 -4
  36. package/scripts/lib/gemini-profiles.mjs +113 -29
  37. package/scripts/lib/keyword-rules.mjs +24 -0
  38. package/scripts/lib/logger.mjs +60 -43
  39. package/scripts/lib/machine-profile.mjs +293 -0
  40. package/scripts/lib/mcp-health.mjs +44 -18
  41. package/hub/log-retention.mjs +0 -726
package/hud/renderers.mjs CHANGED
@@ -22,11 +22,9 @@ import {
22
22
  import {
23
23
  ACCOUNT_LABEL_WIDTH,
24
24
  FIVE_HOUR_MS,
25
- LEGACY_SV_ACCUMULATOR,
26
25
  ONE_DAY_MS,
27
26
  PROVIDER_PREFIX_WIDTH,
28
27
  SEVEN_DAY_MS,
29
- SV_ACCUMULATOR_PATH,
30
28
  TEAM_STATE_PATH,
31
29
  } from "./constants.mjs";
32
30
  import { buildContextUsageView } from "./context-monitor.mjs";
@@ -40,13 +38,11 @@ import {
40
38
  formatResetRemaining,
41
39
  formatResetRemainingDayHour,
42
40
  formatSavings,
43
- formatSvPct,
44
41
  formatTimeCell,
45
42
  formatTimeCellDH,
46
43
  formatTokenCount,
47
44
  padAnsiRight,
48
45
  readJson,
49
- readJsonMigrate,
50
46
  stripAnsi,
51
47
  truncateAnsi,
52
48
  } from "./utils.mjs";
@@ -88,25 +84,6 @@ export function readLatestBenchmarkDiff() {
88
84
  }
89
85
  }
90
86
 
91
- // 토큰 절약액 누적치 읽기 (tfx-auto token tracker)
92
- export function readTokenSavings() {
93
- const savingsPath = join(
94
- homedir(),
95
- ".omc",
96
- "state",
97
- "tfx-auto-tokens",
98
- "savings-total.json",
99
- );
100
- const data = readJson(savingsPath, null);
101
- if (!data || data.totalSaved === 0) return null;
102
- return data;
103
- }
104
-
105
- // sv-accumulator.json에서 누적 토큰/비용 읽기
106
- export function readSvAccumulator() {
107
- return readJsonMigrate(SV_ACCUMULATOR_PATH, LEGACY_SV_ACCUMULATOR, null);
108
- }
109
-
110
87
  /**
111
88
  * 파이프라인 벤치마크 diff 결과를 HUD 요약 문자열로 포맷
112
89
  */
@@ -279,9 +256,12 @@ export function getMicroLine(
279
256
  codexBuckets,
280
257
  geminiSession,
281
258
  geminiBucket,
282
- combinedSvPct,
283
259
  geminiMarker = "g",
260
+ options = {},
284
261
  ) {
262
+ // showCodex / showGemini 는 machine profile 의 TFX_DISABLE_* 게이트다. 기본값이
263
+ // true 라 8번째 인자를 주지 않는 기존 호출은 그대로 동작한다.
264
+ const { showCodex = true, showGemini = true } = options;
285
265
  const ctxView = contextView || buildContextUsageView({}, null);
286
266
  // Claude 5h/1w
287
267
  const cF =
@@ -325,34 +305,27 @@ export function getMicroLine(
325
305
  gVal = dim("--");
326
306
  }
327
307
 
328
- // sv
329
- const sv = formatSvPct(combinedSvPct).trim();
330
-
331
308
  const cols = getTerminalColumns() || 120;
332
- const line =
333
- `${bold(claudeOrange("c"))}${dim(":")}${cVal} ` +
334
- `${bold(codexWhite("x"))}${dim(":")}${xVal} ` +
335
- `${bold(geminiBlue(geminiMarker))}${dim(":")}${gVal} ` +
336
- `${dim("sv:")}${sv} ` +
337
- `${dim("CTX:")}${colorByPercent(ctxView.percent, ctxView.display)}`;
338
- return truncateAnsi(line, cols);
309
+ // 세그먼트를 모아 join 한다. 차단된 프로바이더를 뺄 때 공백이 겹치지 않는다.
310
+ const segments = [`${bold(claudeOrange("c"))}${dim(":")}${cVal}`];
311
+ if (showCodex) {
312
+ segments.push(`${bold(codexWhite("x"))}${dim(":")}${xVal}`);
313
+ }
314
+ if (showGemini) {
315
+ segments.push(`${bold(geminiBlue(geminiMarker))}${dim(":")}${gVal}`);
316
+ }
317
+ segments.push(
318
+ `${dim("CTX:")}${colorByPercent(ctxView.percent, ctxView.display)}`,
319
+ );
320
+ return truncateAnsi(segments.join(" "), cols);
339
321
  }
340
322
 
341
323
  // ============================================================================
342
324
  // Claude 행 렌더러
343
325
  // ============================================================================
344
- export function getClaudeRows(
345
- currentTier,
346
- contextView,
347
- claudeUsage,
348
- combinedSvPct,
349
- ) {
326
+ export function getClaudeRows(currentTier, contextView, claudeUsage) {
350
327
  const ctxView = contextView || buildContextUsageView({}, null);
351
328
  const prefix = `${bold(claudeOrange("c"))}:`;
352
- // 절약 퍼센트
353
- const svStr = formatSvPct(combinedSvPct);
354
- const svSuffix = `${dim("sv:")}${svStr}`;
355
-
356
329
  // API 실측 데이터
357
330
  const fiveHourPercent = claudeUsage?.fiveHourPercent ?? null;
358
331
  const weeklyPercent = claudeUsage?.weeklyPercent ?? null;
@@ -418,7 +391,7 @@ export function getClaudeRows(
418
391
  const warning = ctxView.warningTag
419
392
  ? ` ${dim("|")} ${yellow(ctxView.warningTag)}`
420
393
  : "";
421
- const contextSection = `${svSuffix} ${dim("|")} ${dim("CTX:")}${colorByPercent(ctxView.percent, ctxView.display)}${warning}`;
394
+ const contextSection = `${dim("CTX:")}${colorByPercent(ctxView.percent, ctxView.display)}${warning}`;
422
395
  return [{ prefix, left: quotaSection, right: contextSection }];
423
396
  }
424
397
 
@@ -428,7 +401,7 @@ export function getClaudeRows(
428
401
  const warning = ctxView.warningTag
429
402
  ? ` ${dim("|")} ${yellow(ctxView.warningTag)}`
430
403
  : "";
431
- const contextSection = `${svSuffix} ${dim("|")} ${dim("CTX:")}${colorByPercent(ctxView.percent, ctxView.display)}${warning}`;
404
+ const contextSection = `${dim("CTX:")}${colorByPercent(ctxView.percent, ctxView.display)}${warning}`;
432
405
  return [{ prefix, left: quotaSection, right: contextSection }];
433
406
  }
434
407
 
@@ -513,7 +486,6 @@ export function getProviderRow(
513
486
  accountsState,
514
487
  realQuota,
515
488
  codexEmail,
516
- savingsMultiplier,
517
489
  modelLabel,
518
490
  ) {
519
491
  const accountLabel = fitText(
@@ -521,10 +493,6 @@ export function getProviderRow(
521
493
  ACCOUNT_LABEL_WIDTH,
522
494
  );
523
495
 
524
- // 절약 퍼센트 섹션
525
- const svPct =
526
- savingsMultiplier != null ? Math.round(savingsMultiplier * 100) : null;
527
- const svStr = formatSvPct(svPct);
528
496
  const _modelLabelStr = modelLabel ? ` ${markerColor(modelLabel)}` : "";
529
497
 
530
498
  // 프로바이더별 색상 프로필
@@ -708,10 +676,7 @@ export function getProviderRow(
708
676
  quotaSection = `${dim("5h:")}${dim(formatPlaceholderPercentCell())} ${dim(formatTimeCell("n/a"))} ${dim("1w:")}${dim(formatPlaceholderPercentCell())} ${dim(formatTimeCellDH("--d--h"))}`;
709
677
  }
710
678
  const prefix = `${bold(markerColor(`${marker}`))}:`;
711
- const compactRight = [
712
- svStr ? `${dim("sv:")}${svStr}` : "",
713
- accountLabel ? markerColor(accountLabel) : "",
714
- ]
679
+ const compactRight = [accountLabel ? markerColor(accountLabel) : ""]
715
680
  .filter(Boolean)
716
681
  .join(" ");
717
682
  return { prefix, left: quotaSection, right: compactRight };
@@ -800,11 +765,8 @@ export function getProviderRow(
800
765
 
801
766
  const prefix = `${bold(markerColor(`${marker}`))}:`;
802
767
  const accountSection = `${markerColor(accountLabel)}`;
803
- const svSection = svStr ? `${dim("sv:")}${svStr}` : "";
804
768
  const modelLabelSection = modelLabel ? markerColor(modelLabel) : "";
805
- const rightParts = [svSection, accountSection, modelLabelSection].filter(
806
- Boolean,
807
- );
769
+ const rightParts = [accountSection, modelLabelSection].filter(Boolean);
808
770
  return {
809
771
  prefix,
810
772
  left: quotaSection,
package/hud/utils.mjs CHANGED
@@ -5,11 +5,7 @@
5
5
  import { createHash } from "node:crypto";
6
6
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
7
7
  import { dirname } from "node:path";
8
- import {
9
- PERCENT_CELL_WIDTH,
10
- SV_CELL_WIDTH,
11
- TIME_CELL_INNER_WIDTH,
12
- } from "./constants.mjs";
8
+ import { PERCENT_CELL_WIDTH, TIME_CELL_INNER_WIDTH } from "./constants.mjs";
13
9
 
14
10
  export async function readStdinJson() {
15
11
  if (process.stdin.isTTY) return {};
@@ -338,16 +334,6 @@ export function createHttpsPost(https, timeoutMs) {
338
334
  };
339
335
  }
340
336
 
341
- // sv 퍼센트 포맷 (1000+ → k 표기, 5자 고정폭)
342
- export function formatSvPct(value) {
343
- if (value == null) return "--%".padStart(SV_CELL_WIDTH);
344
- if (value >= 10000)
345
- return `${Math.round(value / 1000)}k%`.padStart(SV_CELL_WIDTH);
346
- if (value >= 1000)
347
- return `${(value / 1000).toFixed(1)}k%`.padStart(SV_CELL_WIDTH);
348
- return `${value}%`.padStart(SV_CELL_WIDTH);
349
- }
350
-
351
337
  export function formatSavings(dollars) {
352
338
  if (dollars >= 100) return `$${Math.round(dollars)}`;
353
339
  if (dollars >= 10) return `$${dollars.toFixed(1)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triflux/core",
3
- "version": "10.43.0",
3
+ "version": "10.45.0",
4
4
  "description": "triflux core — CLI routing, pipeline, adapters. Zero native dependencies.",
5
5
  "type": "module",
6
6
  "main": "hub/index.mjs",
@@ -0,0 +1,367 @@
1
+ // Canonical Codex role policy. Concrete model IDs stay in profile config files.
2
+
3
+ import {
4
+ normalizeCodexProfileName,
5
+ resolveCodexProfileConfigValues,
6
+ } from "./codex-profile-config.mjs";
7
+
8
+ const policy = {
9
+ executor: {
10
+ profile: "gpt56_terra_high",
11
+ timeoutSec: 1080,
12
+ runMode: "fg",
13
+ opusOversight: false,
14
+ mcpHint: "implement",
15
+ subcommand: "exec",
16
+ },
17
+ codex: {
18
+ profile: "gpt56_terra_high",
19
+ timeoutSec: 1080,
20
+ runMode: "fg",
21
+ opusOversight: false,
22
+ mcpHint: "implement",
23
+ subcommand: "exec",
24
+ },
25
+ "build-fixer": {
26
+ profile: "gpt56_luna_low",
27
+ timeoutSec: 540,
28
+ runMode: "fg",
29
+ opusOversight: false,
30
+ mcpHint: "implement",
31
+ subcommand: "exec",
32
+ },
33
+ cleanup: {
34
+ profile: "gpt56_terra_med",
35
+ timeoutSec: 540,
36
+ runMode: "fg",
37
+ opusOversight: false,
38
+ mcpHint: "implement",
39
+ subcommand: "exec",
40
+ },
41
+ deslop: {
42
+ profile: "gpt56_terra_med",
43
+ timeoutSec: 540,
44
+ runMode: "fg",
45
+ opusOversight: false,
46
+ mcpHint: "implement",
47
+ subcommand: "exec",
48
+ },
49
+ debugger: {
50
+ profile: "gpt6_astra_xhigh",
51
+ timeoutSec: 900,
52
+ runMode: "bg",
53
+ opusOversight: false,
54
+ mcpHint: "implement",
55
+ subcommand: "exec",
56
+ },
57
+ "deep-executor": {
58
+ profile: "gpt6_astra_xhigh",
59
+ timeoutSec: 3600,
60
+ runMode: "bg",
61
+ opusOversight: true,
62
+ mcpHint: "implement",
63
+ subcommand: "exec",
64
+ },
65
+ architect: {
66
+ profile: "gpt6_astra_xhigh",
67
+ timeoutSec: 3600,
68
+ runMode: "bg",
69
+ opusOversight: true,
70
+ mcpHint: "analyze",
71
+ subcommand: "exec",
72
+ },
73
+ critic: {
74
+ profile: "gpt6_astra_xhigh",
75
+ timeoutSec: 3600,
76
+ runMode: "bg",
77
+ opusOversight: true,
78
+ mcpHint: "analyze",
79
+ subcommand: "exec",
80
+ },
81
+ planner: {
82
+ profile: "gpt6_astra_xhigh",
83
+ timeoutSec: 3600,
84
+ runMode: "fg",
85
+ opusOversight: true,
86
+ mcpHint: "analyze",
87
+ subcommand: "exec",
88
+ },
89
+ analyst: {
90
+ profile: "gpt6_astra_xhigh",
91
+ timeoutSec: 3600,
92
+ runMode: "fg",
93
+ opusOversight: true,
94
+ mcpHint: "analyze",
95
+ subcommand: "exec",
96
+ },
97
+ "code-reviewer": {
98
+ profile: "gpt56_terra_high",
99
+ timeoutSec: 1800,
100
+ runMode: "bg",
101
+ opusOversight: false,
102
+ mcpHint: "review",
103
+ subcommand: "review",
104
+ },
105
+ "quality-reviewer": {
106
+ profile: "gpt56_terra_high",
107
+ timeoutSec: 1800,
108
+ runMode: "bg",
109
+ opusOversight: false,
110
+ mcpHint: "review",
111
+ subcommand: "review",
112
+ },
113
+ "security-reviewer": {
114
+ profile: "gpt6_astra_xhigh",
115
+ timeoutSec: 1800,
116
+ runMode: "bg",
117
+ opusOversight: true,
118
+ mcpHint: "review",
119
+ subcommand: "review",
120
+ },
121
+ scientist: {
122
+ profile: "gpt56_terra_high",
123
+ timeoutSec: 1440,
124
+ runMode: "bg",
125
+ opusOversight: false,
126
+ mcpHint: "analyze",
127
+ subcommand: "exec",
128
+ },
129
+ "document-specialist": {
130
+ profile: "gpt56_terra_high",
131
+ timeoutSec: 1440,
132
+ runMode: "bg",
133
+ opusOversight: false,
134
+ mcpHint: "analyze",
135
+ subcommand: "exec",
136
+ },
137
+ "scientist-deep": {
138
+ profile: "gpt6_astra_xhigh",
139
+ timeoutSec: 3600,
140
+ runMode: "bg",
141
+ opusOversight: false,
142
+ mcpHint: "analyze",
143
+ subcommand: "exec",
144
+ },
145
+ verifier: {
146
+ profile: "gpt56_terra_high",
147
+ timeoutSec: 1200,
148
+ runMode: "fg",
149
+ opusOversight: false,
150
+ mcpHint: "review",
151
+ subcommand: "review",
152
+ },
153
+ "test-engineer": {
154
+ profile: "gpt56_terra_high",
155
+ timeoutSec: 1200,
156
+ runMode: "bg",
157
+ opusOversight: false,
158
+ mcpHint: "implement",
159
+ subcommand: "exec",
160
+ },
161
+ "qa-tester": {
162
+ profile: "gpt56_terra_high",
163
+ timeoutSec: 1200,
164
+ runMode: "bg",
165
+ opusOversight: false,
166
+ mcpHint: "review",
167
+ subcommand: "review",
168
+ },
169
+ spark: {
170
+ profile: "gpt56_luna_low",
171
+ timeoutSec: 180,
172
+ runMode: "fg",
173
+ opusOversight: false,
174
+ mcpHint: "implement",
175
+ subcommand: "exec",
176
+ },
177
+ // These entries are only for explicit direct-Codex overrides. agent-map.json
178
+ // remains the provider-selection authority for their normal execution.
179
+ designer: {
180
+ profile: "gpt6_astra_xhigh",
181
+ timeoutSec: 900,
182
+ runMode: "bg",
183
+ opusOversight: false,
184
+ mcpHint: "implement",
185
+ subcommand: "exec",
186
+ },
187
+ writer: {
188
+ profile: "gpt56_luna_low",
189
+ timeoutSec: 900,
190
+ runMode: "bg",
191
+ opusOversight: false,
192
+ mcpHint: "implement",
193
+ subcommand: "exec",
194
+ },
195
+ };
196
+
197
+ function freezePolicy(entry) {
198
+ return Object.freeze({ ...entry });
199
+ }
200
+
201
+ export const CODEX_AGENT_POLICY = Object.freeze(
202
+ Object.fromEntries(
203
+ Object.entries(policy).map(([agent, entry]) => [
204
+ agent,
205
+ freezePolicy(entry),
206
+ ]),
207
+ ),
208
+ );
209
+ export const DEFAULT_CODEX_AGENT = "executor";
210
+
211
+ export const CANONICAL_CODEX_PROFILE_OVERRIDES = Object.freeze(
212
+ new Set([
213
+ "gpt56_luna_low",
214
+ "gpt56_terra_med",
215
+ "gpt56_terra_high",
216
+ "gpt6_astra_xhigh",
217
+ "gpt6_astra_max",
218
+ "gpt6_astra_ultra",
219
+ ]),
220
+ );
221
+ export const ULTRA_ELIGIBLE_CODEX_AGENTS = Object.freeze(
222
+ new Set(["deep-executor", "scientist-deep"]),
223
+ );
224
+
225
+ const NESTED_GLOBAL_PROFILE_OVERRIDES = new Set([
226
+ "max",
227
+ "ultra",
228
+ "gpt6_astra_max",
229
+ "gpt6_astra_ultra",
230
+ ]);
231
+
232
+ export function resolveCodexAgentPolicy(agent) {
233
+ return freezePolicy(
234
+ CODEX_AGENT_POLICY[agent] ?? CODEX_AGENT_POLICY[DEFAULT_CODEX_AGENT],
235
+ );
236
+ }
237
+
238
+ /**
239
+ * Resolves a requested Codex profile against the canonical role policy.
240
+ *
241
+ * `retryProfile` intentionally wins over `profileOverride`: retry snapshots
242
+ * represent an already-selected escalation step and must not be replaced by a
243
+ * later process-level `TFX_CODEX_PROFILE`. Ultra is reserved for an eligible
244
+ * top-level role; every nested/sandboxed or ineligible request is max.
245
+ */
246
+ export function resolveCodexAgentProfile(
247
+ agent,
248
+ {
249
+ profileOverride = "auto",
250
+ retryProfile = null,
251
+ nested = false,
252
+ allowCustom = false,
253
+ } = {},
254
+ ) {
255
+ const defaultProfile = resolveCodexAgentPolicy(agent).profile;
256
+ const retryRequested = String(retryProfile ?? "").trim();
257
+ const requested = normalizeCodexProfileName(
258
+ retryRequested || String(profileOverride || "auto").trim(),
259
+ );
260
+ if (!requested || requested === "auto") return defaultProfile;
261
+
262
+ const canonical =
263
+ requested === "max"
264
+ ? "gpt6_astra_max"
265
+ : requested === "ultra"
266
+ ? "gpt6_astra_ultra"
267
+ : requested;
268
+ if (!CANONICAL_CODEX_PROFILE_OVERRIDES.has(canonical)) {
269
+ if (allowCustom) return requested;
270
+ throw new Error(
271
+ `[agent-route-policy] unsupported profile override: ${requested}`,
272
+ );
273
+ }
274
+ if (canonical !== "gpt6_astra_ultra") return canonical;
275
+ return nested || !ULTRA_ELIGIBLE_CODEX_AGENTS.has(agent)
276
+ ? "gpt6_astra_max"
277
+ : canonical;
278
+ }
279
+
280
+ /**
281
+ * Nested headless, team, worker, and delegator launches always select an
282
+ * explicit role profile rather than inheriting the global Codex config. A
283
+ * custom profile that resolves to ultra is also downgraded to max.
284
+ */
285
+ export function resolveNestedCodexAgentProfile(
286
+ agent,
287
+ {
288
+ profileOverride = "auto",
289
+ globalProfile = "auto",
290
+ retryProfile = null,
291
+ codexHome,
292
+ } = {},
293
+ ) {
294
+ const explicitProfile = String(profileOverride || "auto").trim();
295
+ const globalOverride = normalizeCodexProfileName(
296
+ String(globalProfile || "auto").trim(),
297
+ );
298
+ // Headless lanes must select their role policy explicitly. Only the max and
299
+ // ultra exception lanes may cross the process environment boundary.
300
+ const effectiveOverride =
301
+ explicitProfile !== "auto"
302
+ ? explicitProfile
303
+ : NESTED_GLOBAL_PROFILE_OVERRIDES.has(globalOverride)
304
+ ? globalOverride
305
+ : "auto";
306
+ const fallback = resolveCodexAgentProfile(agent);
307
+ const candidate = resolveCodexAgentProfile(agent, {
308
+ profileOverride: effectiveOverride,
309
+ retryProfile,
310
+ nested: true,
311
+ allowCustom: true,
312
+ });
313
+ const { effort } = resolveCodexProfileConfigValues(candidate, { codexHome });
314
+ if (!effort) return fallback;
315
+ return effort.toLowerCase() === "ultra" ? "gpt6_astra_max" : candidate;
316
+ }
317
+
318
+ export function describeCodexAgentPolicy() {
319
+ return {
320
+ defaultAgent: DEFAULT_CODEX_AGENT,
321
+ agents: Object.keys(CODEX_AGENT_POLICY),
322
+ };
323
+ }
324
+
325
+ function parseCliArgs(argv) {
326
+ const args = [...argv];
327
+ let format = "json";
328
+ let agent = DEFAULT_CODEX_AGENT;
329
+ while (args.length > 0) {
330
+ const flag = args.shift();
331
+ if (flag === "--format") format = args.shift() || "";
332
+ else if (flag === "--agent") agent = args.shift() || "";
333
+ else throw new Error(`unknown argument: ${flag}`);
334
+ }
335
+ if (!new Set(["json", "tsv"]).has(format)) {
336
+ throw new Error(`unsupported format: ${format}`);
337
+ }
338
+ return { format, agent };
339
+ }
340
+
341
+ function runCli() {
342
+ const { format, agent } = parseCliArgs(process.argv.slice(2));
343
+ const resolved = resolveCodexAgentPolicy(agent);
344
+ if (format === "tsv") {
345
+ process.stdout.write(
346
+ [
347
+ resolved.profile,
348
+ resolved.timeoutSec,
349
+ resolved.runMode,
350
+ resolved.opusOversight,
351
+ resolved.mcpHint,
352
+ resolved.subcommand,
353
+ ].join("\t"),
354
+ );
355
+ return;
356
+ }
357
+ process.stdout.write(`${JSON.stringify(resolved)}\n`);
358
+ }
359
+
360
+ if (import.meta.url === new URL(process.argv[1], "file:").href) {
361
+ try {
362
+ runCli();
363
+ } catch (error) {
364
+ process.stderr.write(`[agent-route-policy] ${error.message}\n`);
365
+ process.exitCode = 1;
366
+ }
367
+ }
@@ -1,12 +1,18 @@
1
1
  // cli-agy.mjs — Antigravity (agy) CLI adapter (Phase 0 PoC).
2
2
  //
3
- // 책임: agy --print 는 stdin-only 이므로 plan() 에서 stdinMode="pipe" 시그널을 반환한다.
4
- // positional prompt 패턴은 환영 메시지 폴백을 유발하므로 사용 금지.
3
+ // 책임: agy 1.1.27 부터 --print 는 값(프롬프트)이 필수이고 stdin 프롬프트는 거부되므로
4
+ // plan() 은 프롬프트를 args 의 --print 값으로 넣고 stdinMode="argv" 를 돌려준다.
5
+ // --print 뒤에 다른 플래그가 오면 그 플래그를 프롬프트로 삼키므로 항상 마지막에 둔다.
5
6
  //
6
7
  // 출처: scripts/tfx-route.sh route_agent() L1052-L1059, run_codex_exec() L2036-L2046.
7
8
  // .claude/rules/tfx-update-logic.md Antigravity CLI 1.0.0 정밀 sanity matrix.
8
9
  // timeoutSec은 lane 예상 소요 시간(advisory)이다. hard ceiling 집행은 Bash route가 소유한다.
9
10
 
11
+ import {
12
+ resolveGeminiModel,
13
+ resolveGeminiProfileForPurpose,
14
+ } from "./gemini-profiles.mjs";
15
+
10
16
  export const id = "agy";
11
17
  export const cliType = "antigravity";
12
18
  export const command = "agy";
@@ -38,6 +44,7 @@ export function plan({
38
44
  mcpProfile = "auto",
39
45
  timeoutSec,
40
46
  contextFile,
47
+ geminiProfilesPath,
41
48
  } = {}) {
42
49
  if (!agent) {
43
50
  throw new Error("[cli-agy] agent required");
@@ -49,8 +56,21 @@ export function plan({
49
56
  command,
50
57
  profile: cfg.profile,
51
58
  effort: cfg.profile,
52
- args: ["--print", "--dangerously-skip-permissions"],
53
- stdinMode: "pipe",
59
+ // effort 는 역할별 SSOT(gemini-profiles.mjs): designer → High, writer → Medium ...
60
+ geminiProfile: resolveGeminiProfileForPurpose(agent),
61
+ model: resolveGeminiModel(resolveGeminiProfileForPurpose(agent), {
62
+ profilesPath: geminiProfilesPath,
63
+ }),
64
+ args: [
65
+ "--dangerously-skip-permissions",
66
+ "--model",
67
+ resolveGeminiModel(resolveGeminiProfileForPurpose(agent), {
68
+ profilesPath: geminiProfilesPath,
69
+ }),
70
+ "--print",
71
+ prompt,
72
+ ],
73
+ stdinMode: "argv",
54
74
  timeoutMs: effectiveTimeoutSec * 1000,
55
75
  runMode: cfg.runMode,
56
76
  opusOversight: cfg.opusOversight,