@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
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { spawn } from "node:child_process";
3
4
  import { argv, exit, stdin, stdout } from "node:process";
4
- import { pathToFileURL } from "node:url";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
6
  import { drainPendingSynapse as defaultDrainPendingSynapse } from "../hub/team/synapse-http.mjs";
6
7
  import {
7
8
  heartbeatInteractiveSession as defaultHeartbeatInteractiveSession,
@@ -51,6 +52,66 @@ function normalizeMode(mode, payload) {
51
52
  return "";
52
53
  }
53
54
 
55
+ /**
56
+ * Start a detached bridge call so Codex/OMX presence reaches both the Synapse
57
+ * session registry and the hub agents table. This is intentionally independent
58
+ * of the legacy session-start work below: a missing or unavailable hub must
59
+ * never delay or fail SessionStart.
60
+ */
61
+ export function launchCodexPresenceRegistration(payload, opts = {}) {
62
+ try {
63
+ const sessionId = String(payload?.session_id || "").trim();
64
+ if (!sessionId) return false;
65
+
66
+ const cwd =
67
+ typeof payload?.cwd === "string" && payload.cwd.trim()
68
+ ? payload.cwd
69
+ : process.cwd();
70
+ const bridgePath =
71
+ opts.bridgePath ||
72
+ fileURLToPath(new URL("../hub/bridge.mjs", import.meta.url));
73
+ const spawnFn = opts.spawnFn || spawn;
74
+ const canonicalSessionId = String(process.env.OMX_SESSION_ID || "").trim();
75
+ const tmuxSession = String(
76
+ process.env.OMX_TMUX_SESSION_NAME || process.env.OMX_TMUX_SESSION || "",
77
+ ).trim();
78
+ const tmuxPane = String(process.env.TMUX_PANE || "").trim();
79
+ const args = [
80
+ bridgePath,
81
+ "register",
82
+ "--session-id",
83
+ sessionId,
84
+ "--cwd",
85
+ cwd,
86
+ "--worktree-path",
87
+ cwd,
88
+ "--session-kind",
89
+ "interactive",
90
+ "--host",
91
+ "local",
92
+ "--codex-session-id",
93
+ sessionId,
94
+ ];
95
+ if (canonicalSessionId && canonicalSessionId !== sessionId) {
96
+ args.push("--omx-session-id", canonicalSessionId);
97
+ }
98
+ if (tmuxSession) args.push("--tmux-session", tmuxSession);
99
+ if (tmuxPane) args.push("--tmux-pane", tmuxPane);
100
+
101
+ const child = spawnFn(process.execPath, args, {
102
+ detached: true,
103
+ stdio: "ignore",
104
+ windowsHide: true,
105
+ env: process.env,
106
+ });
107
+ child?.once?.("error", () => {});
108
+ child?.unref?.();
109
+ return true;
110
+ } catch {
111
+ return false;
112
+ }
113
+ }
114
+
54
115
  function swallowStdoutWrite(_chunk, encodingOrCallback, callback) {
55
116
  const done =
56
117
  typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
@@ -91,10 +152,15 @@ export async function runCodexSessionHook(stdinData, opts = {}) {
91
152
  opts.heartbeatInteractiveSession || defaultHeartbeatInteractiveSession;
92
153
  const drainPendingSynapse =
93
154
  opts.drainPendingSynapse || defaultDrainPendingSynapse;
155
+ const launchPresenceRegistration =
156
+ opts.launchPresenceRegistration || launchCodexPresenceRegistration;
94
157
 
95
158
  try {
96
159
  await runHookSideEffectsWithStdoutSuppressed(async () => {
97
160
  if (mode === "register") {
161
+ try {
162
+ launchPresenceRegistration(parsed.payload);
163
+ } catch {}
98
164
  try {
99
165
  await hubEnsureRun(stdinData);
100
166
  } catch {}
@@ -11,6 +11,8 @@ import {
11
11
  } from "node:fs";
12
12
  import { dirname, join, resolve } from "node:path";
13
13
 
14
+ import { resolveRoleControlSnapshot } from "../hub/lib/cto-env.mjs";
15
+
14
16
  const MAX_CONTEXT_BYTES = 2048;
15
17
  const HEADER = "[CTO NORTH STAR - READ ONLY]";
16
18
  const INSTRUCTION =
@@ -45,21 +47,6 @@ function sha256(input) {
45
47
  return createHash("sha256").update(input).digest("hex");
46
48
  }
47
49
 
48
- function ctoNorthStarEnabled() {
49
- switch (process.env.TFX_CTO_NORTH_STAR || "1") {
50
- case "0":
51
- case "false":
52
- case "FALSE":
53
- case "off":
54
- case "OFF":
55
- case "no":
56
- case "NO":
57
- return false;
58
- default:
59
- return true;
60
- }
61
- }
62
-
63
50
  function wrapBrief(brief) {
64
51
  return [HEADER, INSTRUCTION, BEGIN, brief, END].join("\n");
65
52
  }
@@ -89,7 +76,7 @@ function writeMarker(markerPath, state) {
89
76
  }
90
77
 
91
78
  function main() {
92
- if (!ctoNorthStarEnabled()) return;
79
+ if (!resolveRoleControlSnapshot().north_star_enabled) return;
93
80
 
94
81
  const input = readStdinJson();
95
82
  if (input.hook_event_name && input.hook_event_name !== "UserPromptSubmit") {
@@ -129,9 +129,8 @@ function main() {
129
129
  JSON.stringify(input.tool_result || ""),
130
130
  ].join("\n");
131
131
 
132
- // ── reflexion 적응형 학습: safety-guard/headless-guard 차단을 패널티로 기록 ──
133
- const isSafetyBlock =
134
- /\[(?:safety-guard|headless-guard)\].*(?:BLOCKED|차단)/i.test(errorText);
132
+ // ── reflexion 적응형 학습: safety-guard 차단을 패널티로 기록 ──
133
+ const isSafetyBlock = /\[safety-guard\].*(?:BLOCKED|차단)/i.test(errorText);
135
134
  if (isSafetyBlock) {
136
135
  try {
137
136
  const home = process.env.HOME || process.env.USERPROFILE || "";
@@ -147,9 +146,7 @@ function main() {
147
146
  errorText.match(/\[.*?\]\s*(.{0,120})/)?.[1] ||
148
147
  errorText.slice(0, 120),
149
148
  command_preview: command.slice(0, 200),
150
- source: errorText.includes("safety-guard")
151
- ? "safety-guard"
152
- : "headless-guard",
149
+ source: "safety-guard",
153
150
  };
154
151
  writeFileSync(penaltyFile, JSON.stringify(entry) + "\n", { flag: "a" });
155
152
  } catch {
@@ -113,7 +113,7 @@ function identifySource(cmd) {
113
113
  if (/oh-my-claudecode|omc/i.test(cmd)) return "omc";
114
114
  if (/session-vault/i.test(cmd)) return "session-vault";
115
115
  if (/compact-helper/i.test(cmd)) return "compact-helper";
116
- if (/headless-guard|tfx-gate/i.test(cmd)) return "omc";
116
+ if (/tfx-gate/i.test(cmd)) return "omc";
117
117
  if (/mcp-cleanup/i.test(cmd)) return "system";
118
118
  return "unknown";
119
119
  }
@@ -68,17 +68,6 @@
68
68
  "blocking": true,
69
69
  "description": "git commit 전 교차 리뷰 미검증 파일 차단/경고"
70
70
  },
71
- {
72
- "id": "omc-headless-guard",
73
- "source": "omc",
74
- "matcher": "Bash|Agent",
75
- "command": "bash \"${HOME}/.claude/scripts/headless-guard-fast.sh\"",
76
- "priority": 50,
77
- "enabled": true,
78
- "timeout": 3,
79
- "blocking": false,
80
- "description": "primary multiplexer headless 가드"
81
- },
82
71
  {
83
72
  "id": "omc-tfx-gate-activate",
84
73
  "source": "omc",
@@ -55,7 +55,7 @@
55
55
  "flags": "i"
56
56
  }
57
57
  ],
58
- "skill": "tfx-swarm",
58
+ "skill": "tfx-auto",
59
59
  "priority": 1,
60
60
  "supersedes": ["tfx-codex"],
61
61
  "exclusive": false,
@@ -96,6 +96,102 @@
96
96
  "state": null,
97
97
  "mcp_route": null
98
98
  },
99
+ {
100
+ "id": "tfx-review",
101
+ "patterns": [
102
+ {
103
+ "source": "\\btfx[\\s-]?review\\b",
104
+ "flags": "i"
105
+ }
106
+ ],
107
+ "skill": "tfx-review",
108
+ "priority": 1,
109
+ "supersedes": ["tfx-unified"],
110
+ "exclusive": false,
111
+ "state": null,
112
+ "mcp_route": null,
113
+ "explicit": true
114
+ },
115
+ {
116
+ "id": "tfx-analysis",
117
+ "patterns": [
118
+ {
119
+ "source": "\\btfx[\\s-]?analysis\\b",
120
+ "flags": "i"
121
+ }
122
+ ],
123
+ "skill": "tfx-analysis",
124
+ "priority": 1,
125
+ "supersedes": ["tfx-unified"],
126
+ "exclusive": false,
127
+ "state": null,
128
+ "mcp_route": null,
129
+ "explicit": true
130
+ },
131
+ {
132
+ "id": "tfx-plan",
133
+ "patterns": [
134
+ {
135
+ "source": "\\btfx[\\s-]?plan\\b",
136
+ "flags": "i"
137
+ }
138
+ ],
139
+ "skill": "tfx-plan",
140
+ "priority": 1,
141
+ "supersedes": ["tfx-unified"],
142
+ "exclusive": false,
143
+ "state": null,
144
+ "mcp_route": null,
145
+ "explicit": true
146
+ },
147
+ {
148
+ "id": "tfx-qa",
149
+ "patterns": [
150
+ {
151
+ "source": "\\btfx[\\s-]?qa\\b",
152
+ "flags": "i"
153
+ }
154
+ ],
155
+ "skill": "tfx-qa",
156
+ "priority": 1,
157
+ "supersedes": ["tfx-unified"],
158
+ "exclusive": false,
159
+ "state": null,
160
+ "mcp_route": null,
161
+ "explicit": true
162
+ },
163
+ {
164
+ "id": "tfx-research",
165
+ "patterns": [
166
+ {
167
+ "source": "\\btfx[\\s-]?research\\b",
168
+ "flags": "i"
169
+ }
170
+ ],
171
+ "skill": "tfx-research",
172
+ "priority": 1,
173
+ "supersedes": ["tfx-unified"],
174
+ "exclusive": false,
175
+ "state": null,
176
+ "mcp_route": null,
177
+ "explicit": true
178
+ },
179
+ {
180
+ "id": "tfx-find",
181
+ "patterns": [
182
+ {
183
+ "source": "\\btfx[\\s-]?find\\b",
184
+ "flags": "i"
185
+ }
186
+ ],
187
+ "skill": "tfx-find",
188
+ "priority": 1,
189
+ "supersedes": ["tfx-unified"],
190
+ "exclusive": false,
191
+ "state": null,
192
+ "mcp_route": null,
193
+ "explicit": true
194
+ },
99
195
  {
100
196
  "id": "tfx-unified",
101
197
  "patterns": [
@@ -127,10 +223,6 @@
127
223
  "source": "(?:찾아봐|조사해|검색해)",
128
224
  "flags": "i"
129
225
  },
130
- {
131
- "source": "(?:정리해|슬롭|클린업)",
132
- "flags": "i"
133
- },
134
226
  {
135
227
  "source": "(?:병렬|동시에|parallel|concurrent)",
136
228
  "flags": "i"
@@ -155,6 +247,41 @@
155
247
  "state": null,
156
248
  "mcp_route": null
157
249
  },
250
+ {
251
+ "id": "host-ai-slop-cleaner",
252
+ "patterns": [
253
+ {
254
+ "source": "(?:AI\\s*슬롭|ai\\s*slop|anti[\\s-]?slop|deslop)",
255
+ "flags": "i"
256
+ },
257
+ {
258
+ "source": "(?:슬롭|클린업)",
259
+ "flags": "i"
260
+ }
261
+ ],
262
+ "skill": "ai-slop-cleaner",
263
+ "priority": 1,
264
+ "supersedes": [],
265
+ "exclusive": false,
266
+ "state": null,
267
+ "mcp_route": null
268
+ },
269
+ {
270
+ "id": "tfx-prune",
271
+ "patterns": [
272
+ {
273
+ "source": "\\btfx[\\s-]?prune\\b",
274
+ "flags": "i"
275
+ }
276
+ ],
277
+ "skill": "tfx-prune",
278
+ "priority": 1,
279
+ "supersedes": ["tfx-unified"],
280
+ "exclusive": false,
281
+ "state": null,
282
+ "mcp_route": null,
283
+ "explicit": true
284
+ },
158
285
  {
159
286
  "id": "tfx-codex",
160
287
  "patterns": [
@@ -285,6 +412,7 @@
285
412
  }
286
413
  ],
287
414
  "skill": "tfx-wt",
415
+ "platform": ["win32"],
288
416
  "priority": 1,
289
417
  "supersedes": ["tfx-unified"],
290
418
  "exclusive": false,
@@ -304,6 +432,7 @@
304
432
  }
305
433
  ],
306
434
  "skill": "tfx-wt",
435
+ "platform": ["win32"],
307
436
  "priority": 1,
308
437
  "supersedes": ["tfx-unified"],
309
438
  "exclusive": false,
@@ -323,6 +452,7 @@
323
452
  }
324
453
  ],
325
454
  "skill": "tfx-wt",
455
+ "platform": ["win32"],
326
456
  "priority": 1,
327
457
  "supersedes": ["tfx-unified"],
328
458
  "exclusive": false,
@@ -342,6 +472,7 @@
342
472
  }
343
473
  ],
344
474
  "skill": "tfx-wt",
475
+ "platform": ["win32"],
345
476
  "priority": 1,
346
477
  "supersedes": ["tfx-unified"],
347
478
  "exclusive": false,
@@ -554,11 +685,11 @@
554
685
  "flags": "i"
555
686
  },
556
687
  {
557
- "source": "\\b(?:checkpoint|resume|pick\\s*up|where\\s*was\\s*I)\\b",
688
+ "source": "\\b(?:resume|pick\\s*up|where\\s*was\\s*I)\\b",
558
689
  "flags": "i"
559
690
  }
560
691
  ],
561
- "skill": "checkpoint",
692
+ "skill": "gstack-context-restore",
562
693
  "priority": 5,
563
694
  "supersedes": [],
564
695
  "exclusive": false,
@@ -586,19 +717,18 @@
586
717
  },
587
718
  {
588
719
  "id": "gstack-ship",
589
- "disabled": true,
590
720
  "patterns": [
591
721
  {
592
722
  "source": "(?:배포해|PR\\s*만들|릴리스\\s*해|머지하고\\s*배포)",
593
723
  "flags": "i"
594
724
  },
595
725
  {
596
- "source": "\\bship\\b(?!.*tfx)",
726
+ "source": "(?<![\\w-])ship\\b(?!.*tfx)",
597
727
  "flags": "i"
598
728
  }
599
729
  ],
600
730
  "skill": "ship",
601
- "priority": 5,
731
+ "priority": 1,
602
732
  "supersedes": [],
603
733
  "exclusive": false,
604
734
  "state": null,
@@ -627,12 +757,12 @@
627
757
  "id": "gstack-cso",
628
758
  "patterns": [
629
759
  {
630
- "source": "(?:보안\\s*(?:감사|점검|리뷰|스캔)|\\bcso\\b|\\bOWASP\\b|\\bSTRIDE\\b)",
760
+ "source": "(?:보안\\s*(?:감사|점검|리뷰|검토|스캔)|\\bcso\\b|\\bOWASP\\b|\\bSTRIDE\\b)",
631
761
  "flags": "i"
632
762
  }
633
763
  ],
634
764
  "skill": "cso",
635
- "priority": 5,
765
+ "priority": 1,
636
766
  "supersedes": [],
637
767
  "exclusive": false,
638
768
  "state": null,
@@ -651,7 +781,7 @@
651
781
  }
652
782
  ],
653
783
  "skill": "qa",
654
- "priority": 5,
784
+ "priority": 1,
655
785
  "supersedes": [],
656
786
  "exclusive": false,
657
787
  "state": null,
@@ -722,14 +852,6 @@
722
852
  "source": "/ship\\b",
723
853
  "flags": "i"
724
854
  },
725
- {
726
- "source": "\\brelease\\b",
727
- "flags": "i"
728
- },
729
- {
730
- "source": "\\bpublish\\b",
731
- "flags": "i"
732
- },
733
855
  {
734
856
  "source": "배포(?!자|사|장|처)",
735
857
  "flags": ""
@@ -744,11 +866,13 @@
744
866
  }
745
867
  ],
746
868
  "skill": "tfx-ship",
747
- "priority": 3,
869
+ "priority": 1,
748
870
  "supersedes": ["gstack-ship"],
749
871
  "exclusive": false,
750
872
  "state": null,
751
- "mcp_route": null
873
+ "mcp_route": null,
874
+ "repo_scope": ["triflux"],
875
+ "explicit": true
752
876
  }
753
877
  ]
754
878
  }
@@ -3,6 +3,8 @@
3
3
  import { stdin, stdout } from "node:process";
4
4
 
5
5
  const META_PATTERNS = [/&&/, /\|\|/, /[;|<>`]/, /\$\(/];
6
+ const SHELL_EXPANSION_PATTERN =
7
+ /(?:^|[^\\])\$(?:[A-Za-z_][A-Za-z0-9_]*|\{[^}]*\}|[?*#@$!0-9-])|(?:^|\s)~[A-Za-z0-9_-]*(?=\/|$)/;
6
8
  const RISKY_PATTERNS = [
7
9
  /(^|\s)rm(\s|$)/,
8
10
  /(^|\s)mv(\s|$)/,
@@ -19,6 +21,25 @@ const RISKY_PATTERNS = [
19
21
  /(^|\s)pnpm\s+publish(\s|$)/,
20
22
  /(^|\s)yarn\s+publish(\s|$)/,
21
23
  ];
24
+ const SEARCH_EXTERNAL_INPUT_FLAGS = new Set([
25
+ "--exclude-from",
26
+ "--file",
27
+ "--files-from",
28
+ "--ignore-file",
29
+ "--pre",
30
+ "--pre-glob",
31
+ ]);
32
+ const FIND_SIDE_EFFECT_OPERATORS = new Set([
33
+ "-delete",
34
+ "-exec",
35
+ "-execdir",
36
+ "-fprint",
37
+ "-fprint0",
38
+ "-fprintf",
39
+ "-fls",
40
+ "-ok",
41
+ "-okdir",
42
+ ]);
22
43
 
23
44
  function silentlyExit() {
24
45
  process.exit(0);
@@ -57,10 +78,21 @@ function isRepoRelativePath(value) {
57
78
  function hasUnsafeSurface(command) {
58
79
  return (
59
80
  META_PATTERNS.some((pattern) => pattern.test(command)) ||
81
+ SHELL_EXPANSION_PATTERN.test(command) ||
60
82
  RISKY_PATTERNS.some((pattern) => pattern.test(command))
61
83
  );
62
84
  }
63
85
 
86
+ function isExternalSearchInputFlag(word) {
87
+ return (
88
+ SEARCH_EXTERNAL_INPUT_FLAGS.has(word) ||
89
+ [...SEARCH_EXTERNAL_INPUT_FLAGS].some((flag) =>
90
+ word.startsWith(`${flag}=`),
91
+ ) ||
92
+ /^-[^-]*f/.test(word)
93
+ );
94
+ }
95
+
64
96
  function allowGit(words, command) {
65
97
  if (command === "git status" || command === "git status --short")
66
98
  return "git status";
@@ -97,8 +129,7 @@ function allowListing(words) {
97
129
 
98
130
  if (words[0] === "find") {
99
131
  const args = words.slice(1);
100
- if (args.some((word) => word === "-delete" || word.startsWith("-exec")))
101
- return null;
132
+ if (args.some((word) => FIND_SIDE_EFFECT_OPERATORS.has(word))) return null;
102
133
  const firstOption = args.findIndex((word) => word.startsWith("-"));
103
134
  const pathArgs = (
104
135
  firstOption === -1 ? args : args.slice(0, firstOption)
@@ -118,7 +149,10 @@ function allowSearch(words) {
118
149
  if (
119
150
  args.some(
120
151
  (word) =>
152
+ isExternalSearchInputFlag(word) ||
121
153
  word.startsWith("/") ||
154
+ word.startsWith("~") ||
155
+ word.startsWith("$") ||
122
156
  word === ".." ||
123
157
  word.startsWith("../") ||
124
158
  word.includes("/../"),
@@ -20,6 +20,10 @@ import {
20
20
  registerSynapseSession,
21
21
  } from "../hub/team/synapse-http.mjs";
22
22
  import { createModuleLogger } from "../scripts/lib/logger.mjs";
23
+ import {
24
+ formatCliPolicyLine,
25
+ resolveCliPolicy,
26
+ } from "../scripts/lib/machine-profile.mjs";
23
27
 
24
28
  const __dirname = dirname(fileURLToPath(import.meta.url));
25
29
  const SCRIPTS = join(__dirname, "..", "scripts");
@@ -314,6 +318,36 @@ export function heartbeatInteractiveSession(stdinData, seams = {}) {
314
318
  }
315
319
  }
316
320
 
321
+ /**
322
+ * TFX_DISABLE_* SSOT 를 읽어 세션 문맥에 넣을 cli-policy 한 줄을 만든다.
323
+ *
324
+ * 형식은 scripts/lib/machine-profile.mjs 의 formatCliPolicyLine 이 고정한다.
325
+ * 리더는 파일 하나를 동기 읽기하므로 ms 단위이고, 어떤 실패도 빈 문자열로
326
+ * 흡수해서 SessionStart 가 이 단계 때문에 죽지 않게 한다.
327
+ *
328
+ * 프로파일 파싱 경고나 0/1 밖의 값이 있으면 둘째 줄로 함께 노출한다. 경고를
329
+ * 삼키면 잘못 적은 프로파일이 조용히 "허용"으로 읽혀서 원인을 못 찾는다.
330
+ *
331
+ * @param {NodeJS.ProcessEnv} [env] 판독할 환경변수
332
+ * @param {{ resolve?: Function }} [opts] resolve 는 리더 대체 주입용 테스트 시임
333
+ * @returns {string} 한 줄 또는 두 줄, 실패 시 빈 문자열
334
+ */
335
+ export function buildCliPolicyContext(env = process.env, opts = {}) {
336
+ try {
337
+ const resolvePolicy = opts.resolve || resolveCliPolicy;
338
+ const policy = resolvePolicy(env, opts);
339
+ if (!policy) return "";
340
+ const line = formatCliPolicyLine(policy);
341
+ const warnings = Array.isArray(policy.warnings) ? policy.warnings : [];
342
+ if (warnings.length === 0) return line;
343
+ // 경고에 줄바꿈이 섞이면 additionalContext 에 라벨 없는 줄이 생기므로 한 줄로 접는다.
344
+ const folded = warnings.join("; ").replace(/[\r\n]+/gu, " ");
345
+ return `${line}\ncli-policy-warning: ${folded}`;
346
+ } catch {
347
+ return "";
348
+ }
349
+ }
350
+
317
351
  /**
318
352
  * BLOCKING 훅을 순차 실행. 하나라도 throw하면 로그만 남기고 계속.
319
353
  * @param {string} stdinData
@@ -388,6 +422,21 @@ async function runBlocking(stdinData) {
388
422
  );
389
423
  }
390
424
 
425
+ // 4. cli-policy: TFX_DISABLE_* SSOT 를 세션 문맥에 한 줄로 주입
426
+ try {
427
+ const t0 = performance.now();
428
+ const line = buildCliPolicyContext();
429
+ const dur = performance.now() - t0;
430
+ timings.push({ hook: "cli-policy", dur_ms: Math.round(dur) });
431
+ if (line) output.stdout += line + "\n";
432
+ log.info({ hook: "cli-policy", dur_ms: Math.round(dur) }, "hook.completed");
433
+ } catch (err) {
434
+ log.error(
435
+ { hook: "cli-policy", err: String(err.message || err) },
436
+ "hook.failed",
437
+ );
438
+ }
439
+
391
440
  return { ...output, timings };
392
441
  }
393
442
 
@@ -509,7 +558,7 @@ export async function execute(stdinData, externalHooks = []) {
509
558
  log.info(
510
559
  {
511
560
  total_ms: Math.round(totalDur),
512
- blocking_count: 3,
561
+ blocking_count: 4,
513
562
  deferred_count: 2,
514
563
  bg_count: 1,
515
564
  },
@@ -4,6 +4,8 @@
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { join, resolve } from "node:path";
6
6
 
7
+ import { resolveRoleControlSnapshot } from "../hub/lib/cto-env.mjs";
8
+
7
9
  const MAX_CONTEXT_BYTES = 2048;
8
10
  const HEADER = "[CTO NORTH STAR - READ ONLY]";
9
11
  const INSTRUCTION =
@@ -34,21 +36,6 @@ function capUtf8(input, maxBytes) {
34
36
  return output;
35
37
  }
36
38
 
37
- function ctoNorthStarEnabled() {
38
- switch (process.env.TFX_CTO_NORTH_STAR || "1") {
39
- case "0":
40
- case "false":
41
- case "FALSE":
42
- case "off":
43
- case "OFF":
44
- case "no":
45
- case "NO":
46
- return false;
47
- default:
48
- return true;
49
- }
50
- }
51
-
52
39
  function wrapBrief(brief) {
53
40
  return [HEADER, INSTRUCTION, BEGIN, brief, END].join("\n");
54
41
  }
@@ -60,7 +47,7 @@ function buildAdditionalContext(brief) {
60
47
  }
61
48
 
62
49
  function main() {
63
- if (!ctoNorthStarEnabled()) return;
50
+ if (!resolveRoleControlSnapshot().north_star_enabled) return;
64
51
 
65
52
  const input = readStdinJson();
66
53
  if (input.hook_event_name && input.hook_event_name !== "SessionStart") {