@triflux/core 10.50.2 → 10.52.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 (84) hide show
  1. package/hooks/agy-session-hook.mjs +11 -56
  2. package/hooks/codex-session-hook.mjs +11 -101
  3. package/hub/bridge.mjs +65 -1250
  4. package/hub/cli-adapter-base.mjs +12 -90
  5. package/hub/codex-adapter.mjs +0 -1
  6. package/hub/codex-preflight.mjs +5 -28
  7. package/hub/index.mjs +3 -19
  8. package/hub/lib/process-utils.mjs +1 -156
  9. package/hub/lib/spawn-trace.mjs +3 -2
  10. package/hub/lib/timeout-defaults.mjs +0 -1
  11. package/hub/team/claude-daemon-control.mjs +1 -2
  12. package/hub/team/claude-session-projection.mjs +5 -73
  13. package/hub/team/nativeProxy.mjs +759 -0
  14. package/hub/team/session-context.mjs +1 -1
  15. package/hud/cli-policy.mjs +0 -22
  16. package/hud/constants.mjs +13 -26
  17. package/hud/hud-qos-status.mjs +42 -54
  18. package/hud/providers/gemini.mjs +125 -20
  19. package/hud/renderers.mjs +101 -122
  20. package/hud/utils.mjs +10 -6
  21. package/package.json +2 -6
  22. package/scripts/lib/agent-route-policy.mjs +143 -62
  23. package/scripts/lib/cli-claude.mjs +0 -14
  24. package/scripts/lib/env-probe.mjs +2 -131
  25. package/scripts/lib/gemini-profiles.mjs +2 -69
  26. package/scripts/lib/legacy-mcp-cleanup.mjs +283 -0
  27. package/scripts/lib/machine-profile.mjs +3 -17
  28. package/scripts/lib/mcp-filter.mjs +109 -53
  29. package/scripts/lib/mcp-guard-engine.mjs +40 -98
  30. package/scripts/lib/mcp-health.mjs +2 -2
  31. package/scripts/lib/mcp-server-catalog.mjs +2 -2
  32. package/scripts/lib/psmux-info.mjs +11 -59
  33. package/scripts/lib/session-presence.mjs +2 -100
  34. package/scripts/lib/skill-template.mjs +0 -245
  35. package/hub/adaptive-diagnostic.mjs +0 -350
  36. package/hub/adaptive-inject.mjs +0 -224
  37. package/hub/adaptive-memory.mjs +0 -277
  38. package/hub/adaptive.mjs +0 -172
  39. package/hub/assign-callbacks.mjs +0 -170
  40. package/hub/delegator/contracts.mjs +0 -38
  41. package/hub/delegator/index.mjs +0 -14
  42. package/hub/delegator/schema/delegator-tools.schema.json +0 -250
  43. package/hub/delegator/service.mjs +0 -336
  44. package/hub/delegator/tool-definitions.mjs +0 -35
  45. package/hub/dynamic-routing-engine.mjs +0 -511
  46. package/hub/hitl.mjs +0 -202
  47. package/hub/lib/known-errors.json +0 -72
  48. package/hub/lib/memory-store.mjs +0 -1001
  49. package/hub/lib/phase-manager.mjs +0 -493
  50. package/hub/lib/risk-tier.mjs +0 -53
  51. package/hub/lib/ssh-command.mjs +0 -231
  52. package/hub/lib/staged-file-detect.mjs +0 -43
  53. package/hub/lib/state-snapshot.mjs +0 -293
  54. package/hub/lib/tfx-route-args.mjs +0 -353
  55. package/hub/lib/trace-recorder.mjs +0 -153
  56. package/hub/lib/uuidv7.mjs +0 -45
  57. package/hub/memory-doctor.mjs +0 -640
  58. package/hub/middleware/quota-middleware.mjs +0 -70
  59. package/hub/middleware/request-logger.mjs +0 -191
  60. package/hub/paths.mjs +0 -24
  61. package/hub/pipeline/index.mjs +0 -163
  62. package/hub/pipeline/state.mjs +0 -191
  63. package/hub/pipeline/transitions.mjs +0 -131
  64. package/hub/reflexion.mjs +0 -290
  65. package/hub/role-contract.mjs +0 -314
  66. package/hub/router.mjs +0 -2026
  67. package/hub/routing-snapshot.mjs +0 -261
  68. package/hub/session-fingerprint.mjs +0 -418
  69. package/hub/state.mjs +0 -300
  70. package/hub/team/synapse-http.mjs +0 -311
  71. package/hub/team-bridge.mjs +0 -27
  72. package/mesh/index.mjs +0 -69
  73. package/mesh/mesh-budget.mjs +0 -137
  74. package/mesh/mesh-heartbeat.mjs +0 -100
  75. package/mesh/mesh-protocol.mjs +0 -96
  76. package/mesh/mesh-queue.mjs +0 -163
  77. package/mesh/mesh-registry.mjs +0 -78
  78. package/mesh/mesh-router.mjs +0 -77
  79. package/scripts/lib/claudemd-scanner.mjs +0 -223
  80. package/scripts/lib/context.mjs +0 -67
  81. package/scripts/lib/dynamic-route-cli.mjs +0 -107
  82. package/scripts/lib/handoff.mjs +0 -187
  83. package/scripts/lib/logger.mjs +0 -122
  84. package/scripts/lib/stealth-fetch.mjs +0 -176
@@ -1,12 +1,7 @@
1
1
  // Codex와 Antigravity 세션 hook이 공유하는 presence 기록 함수.
2
- import { execFile, execFileSync } from "node:child_process";
2
+ import { execFileSync } from "node:child_process";
3
3
  import { join } from "node:path";
4
4
  import { resolveRoleControlSnapshot } from "../../hub/lib/cto-env.mjs";
5
- import {
6
- buildSynapseTaskSummary,
7
- heartbeatSynapseSession,
8
- registerSynapseSession,
9
- } from "../../hub/team/synapse-http.mjs";
10
5
 
11
6
  function parseStartPayload(stdinData) {
12
7
  try {
@@ -139,7 +134,7 @@ function commandUsesClaudePrintMode(command) {
139
134
  );
140
135
  }
141
136
 
142
- function shouldSkipInteractiveRegistration(payload, seams = {}) {
137
+ export function shouldSkipInteractiveRegistration(payload, seams = {}) {
143
138
  const declaredKind = String(
144
139
  payload?.sessionKind || payload?.session_kind || "",
145
140
  )
@@ -154,96 +149,3 @@ function shouldSkipInteractiveRegistration(payload, seams = {}) {
154
149
  commandUsesClaudePrintMode(command),
155
150
  );
156
151
  }
157
-
158
- /** git 조회는 세션 시작을 막지 않도록 비동기로 실행한다. */
159
- function gitContextAsync(cwd, gitRunner = defaultGitRunner) {
160
- const run = (args) =>
161
- new Promise((resolve) => {
162
- try {
163
- gitRunner(cwd, args, (out) => resolve(out));
164
- } catch {
165
- resolve("");
166
- }
167
- });
168
- return Promise.all([
169
- run(["rev-parse", "--show-toplevel"]),
170
- run(["rev-parse", "--abbrev-ref", "HEAD"]),
171
- ]).then(([toplevel, branch]) => ({
172
- worktreePath: toplevel || cwd,
173
- branch,
174
- }));
175
- }
176
-
177
- /** git 조회 실패는 빈 문자열로 처리한다. */
178
- function defaultGitRunner(cwd, args, cb) {
179
- execFile(
180
- "git",
181
- args,
182
- {
183
- cwd,
184
- encoding: "utf8",
185
- timeout: 1500,
186
- killSignal: "SIGKILL",
187
- windowsHide: true,
188
- },
189
- (err, stdout) => {
190
- cb(err ? "" : String(stdout || "").trim());
191
- },
192
- );
193
- }
194
-
195
- /** 세션을 즉시 등록하고 git 정보는 뒤이어 갱신한다. 훅 PID는 세션 PID가 아니다. */
196
- export function registerInteractiveSession(stdinData, seams = {}) {
197
- let ctoEvent = null;
198
- const register = seams.register || registerSynapseSession;
199
- const heartbeat = seams.heartbeat || heartbeatSynapseSession;
200
- const gitRunner = seams.gitRunner || defaultGitRunner;
201
- try {
202
- const payload = parseStartPayload(stdinData);
203
- const sessionId = String(payload?.session_id || "").trim();
204
- if (!sessionId) return null;
205
- if (shouldSkipInteractiveRegistration(payload, seams)) return null;
206
- const cwd = typeof payload?.cwd === "string" ? payload.cwd : process.cwd();
207
-
208
- register({
209
- sessionId,
210
- cwd,
211
- worktreePath: cwd,
212
- branch: "",
213
- host: "local",
214
- sessionKind: "interactive",
215
- isRemote: false,
216
- });
217
-
218
- ctoEvent = emitParticipantSessionStarted(stdinData, seams).catch(
219
- () => null,
220
- );
221
-
222
- gitContextAsync(cwd, gitRunner)
223
- .then(({ worktreePath, branch }) => {
224
- if (worktreePath === cwd && !branch) return;
225
- heartbeat(sessionId, { worktreePath, branch });
226
- })
227
- .catch(() => {});
228
- } catch {
229
- /* 세션 시작은 계속한다. */
230
- }
231
- return ctoEvent;
232
- }
233
-
234
- /** 사용자 활동을 갱신한다. 호출자는 종료 전에 전송을 완료해야 한다. */
235
- export function heartbeatInteractiveSession(stdinData, seams = {}) {
236
- const heartbeat = seams.heartbeat || heartbeatSynapseSession;
237
- try {
238
- const payload = parseStartPayload(stdinData);
239
- const sessionId = String(payload?.session_id || "").trim();
240
- if (!sessionId) return;
241
- const cwd = typeof payload?.cwd === "string" ? payload.cwd : process.cwd();
242
- const partial = { worktreePath: cwd, host: "local" };
243
- const prompt = typeof payload?.prompt === "string" ? payload.prompt : "";
244
- if (prompt) partial.taskSummary = buildSynapseTaskSummary(prompt);
245
- heartbeat(sessionId, partial);
246
- } catch {
247
- /* 프롬프트 처리는 계속한다. */
248
- }
249
- }
@@ -1,31 +1,5 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import {
3
- basename,
4
- extname,
5
- isAbsolute,
6
- join,
7
- relative,
8
- resolve,
9
- } from "node:path";
10
-
11
- const IF_TAG_RE = /{{\s*(#if\s+([A-Za-z0-9_.-]+)|\/if)\s*}}/g;
12
- const PARTIAL_RE = /{{>\s*([A-Za-z0-9_./-]+)\s*}}/g;
13
- const FILE_INCLUDE_RE = /{{#include\s+([A-Za-z0-9_./-]+)\s*}}/g;
14
- const VARIABLE_RE = /{{\s*([A-Za-z0-9_.-]+)\s*}}/g;
15
1
  const FRONTMATTER_RE = /^---\r?\n(?:([\s\S]*?)\r?\n)?---\r?\n?/;
16
2
 
17
- function isTruthy(value) {
18
- if (typeof value === "string") return value.trim().length > 0;
19
- return Boolean(value);
20
- }
21
-
22
- function normalizeVariable(context, key) {
23
- if (Object.hasOwn(context, key)) return context[key];
24
- const upper = key.toUpperCase();
25
- if (Object.hasOwn(context, upper)) return context[upper];
26
- return undefined;
27
- }
28
-
29
3
  function parseBoolean(raw) {
30
4
  if (typeof raw !== "string") return undefined;
31
5
  if (raw === "true") return true;
@@ -120,175 +94,6 @@ function parseFrontmatterBlock(block) {
120
94
  return data;
121
95
  }
122
96
 
123
- function evaluateConditionals(source, context) {
124
- const matcher = new RegExp(IF_TAG_RE.source, "g");
125
-
126
- function walk(startIndex, nested) {
127
- let output = "";
128
- let cursor = startIndex;
129
-
130
- while (true) {
131
- const found = matcher.exec(source);
132
- if (!found) {
133
- if (nested) throw new Error("Unclosed {{#if ...}} block in template");
134
- output += source.slice(cursor);
135
- return { output, index: source.length };
136
- }
137
-
138
- output += source.slice(cursor, found.index);
139
- cursor = matcher.lastIndex;
140
-
141
- const directive = found[1];
142
- const flag = found[2];
143
- if (directive.startsWith("#if")) {
144
- const nestedResult = walk(cursor, true);
145
- cursor = nestedResult.index;
146
- matcher.lastIndex = cursor;
147
- if (isTruthy(normalizeVariable(context, flag))) {
148
- output += nestedResult.output;
149
- }
150
- continue;
151
- }
152
-
153
- if (!nested) {
154
- throw new Error("Unexpected {{/if}} without matching {{#if ...}}");
155
- }
156
- return { output, index: cursor };
157
- }
158
- }
159
-
160
- return walk(0, false).output;
161
- }
162
-
163
- function renderPartials(source, context, partials, options, includeStack) {
164
- return source.replace(PARTIAL_RE, (_full, partialName) => {
165
- const partial = partials[partialName];
166
- if (partial == null) {
167
- throw new Error(`Missing partial: ${partialName}`);
168
- }
169
- if (includeStack.includes(partialName)) {
170
- const chain = [...includeStack, partialName].join(" -> ");
171
- throw new Error(`Circular partial include: ${chain}`);
172
- }
173
- return renderWithContext(partial, context, partials, options, [
174
- ...includeStack,
175
- partialName,
176
- ]);
177
- });
178
- }
179
-
180
- function normalizeIncludeName(includeName) {
181
- return includeName.replace(/\\/g, "/");
182
- }
183
-
184
- function resolveIncludeContent(includeName, options) {
185
- const normalizedName = normalizeIncludeName(includeName);
186
- if (Object.hasOwn(options.includes, normalizedName)) {
187
- return options.includes[normalizedName];
188
- }
189
- if (!options.includeBaseDir) {
190
- throw new Error(`Missing include: ${normalizedName}`);
191
- }
192
-
193
- const baseDir = resolve(options.includeBaseDir);
194
- const fullPath = resolve(baseDir, normalizedName);
195
- const relativePath = relative(baseDir, fullPath);
196
- const isInsideBaseDir =
197
- relativePath === "" ||
198
- (!relativePath.startsWith("..") && !isAbsolute(relativePath));
199
-
200
- if (!isInsideBaseDir || !existsSync(fullPath)) {
201
- throw new Error(`Missing include: ${normalizedName}`);
202
- }
203
-
204
- const content = readFileSync(fullPath, "utf8");
205
- options.includes[normalizedName] = content;
206
- return content;
207
- }
208
-
209
- function renderFileIncludes(source, context, partials, options, includeStack) {
210
- return source.replace(FILE_INCLUDE_RE, (_full, includeName) => {
211
- const normalizedName = normalizeIncludeName(includeName);
212
- const content = resolveIncludeContent(normalizedName, options);
213
- if (includeStack.includes(normalizedName)) {
214
- const chain = [...includeStack, normalizedName].join(" -> ");
215
- throw new Error(`Circular template include: ${chain}`);
216
- }
217
- return renderWithContext(content, context, partials, options, [
218
- ...includeStack,
219
- normalizedName,
220
- ]);
221
- });
222
- }
223
-
224
- function renderVariables(source, context) {
225
- return source.replace(VARIABLE_RE, (full, key) => {
226
- const value = normalizeVariable(context, key);
227
- if (value == null) {
228
- throw new Error(`Missing template variable: ${key}`);
229
- }
230
- return String(value);
231
- });
232
- }
233
-
234
- function renderWithContext(
235
- source,
236
- context,
237
- partials,
238
- options,
239
- includeStack = [],
240
- ) {
241
- const afterIf = evaluateConditionals(source, context);
242
- const afterPartials = renderPartials(
243
- afterIf,
244
- context,
245
- partials,
246
- options,
247
- includeStack,
248
- );
249
- const afterFileIncludes = renderFileIncludes(
250
- afterPartials,
251
- context,
252
- partials,
253
- options,
254
- includeStack,
255
- );
256
- return renderVariables(afterFileIncludes, context);
257
- }
258
-
259
- function readAllTemplateFiles(rootDir, currentDir = rootDir) {
260
- if (!rootDir || !existsSync(rootDir)) return [];
261
-
262
- const entries = readdirSync(currentDir, { withFileTypes: true }).sort(
263
- (left, right) => left.name.localeCompare(right.name),
264
- );
265
- const files = [];
266
-
267
- for (const entry of entries) {
268
- const fullPath = join(currentDir, entry.name);
269
- if (entry.isDirectory()) {
270
- files.push(...readAllTemplateFiles(rootDir, fullPath));
271
- continue;
272
- }
273
-
274
- if (!entry.isFile()) continue;
275
- if (!entry.name.endsWith(".md") && !entry.name.endsWith(".tmpl")) continue;
276
-
277
- const relativePath = relative(rootDir, fullPath).replace(/\\/g, "/");
278
- const content = readFileSync(fullPath, "utf8");
279
- files.push({ fullPath, relativePath, content });
280
- }
281
-
282
- return files;
283
- }
284
-
285
- function setPartial(partials, key, value) {
286
- if (!key) return;
287
- if (!Object.hasOwn(partials, key)) {
288
- partials[key] = value;
289
- }
290
- }
291
-
292
97
  export function parseFrontmatter(source) {
293
98
  const match = source.match(FRONTMATTER_RE);
294
99
  if (!match) return { data: {}, body: source };
@@ -297,53 +102,3 @@ export function parseFrontmatter(source) {
297
102
  const body = source.slice(match[0].length);
298
103
  return { data, body };
299
104
  }
300
-
301
- export function buildSkillTemplateContext({
302
- frontmatter = {},
303
- skillDirName = "",
304
- } = {}) {
305
- const context = { ...frontmatter };
306
- const skillName = String(frontmatter.name || skillDirName || "").trim();
307
- const skillDescription = String(frontmatter.description || "").trim();
308
-
309
- let deep = frontmatter.DEEP ?? frontmatter.deep;
310
- if (typeof deep === "string") {
311
- const parsed = parseBoolean(deep.trim().toLowerCase());
312
- deep = parsed ?? deep;
313
- }
314
- if (typeof deep !== "boolean") {
315
- deep = /(^|[-_])deep($|[-_])/i.test(skillName);
316
- }
317
-
318
- context.SKILL_NAME = skillName;
319
- context.SKILL_DESCRIPTION = skillDescription;
320
- context.DEEP = deep;
321
- return context;
322
- }
323
-
324
- export function loadTemplatePartials(partialsDir) {
325
- const files = readAllTemplateFiles(partialsDir);
326
- const partials = {};
327
-
328
- for (const file of files) {
329
- const extension = extname(file.relativePath);
330
- const withoutExt = extension
331
- ? file.relativePath.slice(0, -extension.length)
332
- : file.relativePath;
333
- const normalized = withoutExt.replace(/\\/g, "/");
334
- const base = basename(normalized);
335
-
336
- setPartial(partials, normalized, file.content);
337
- setPartial(partials, base, file.content);
338
- }
339
-
340
- return partials;
341
- }
342
-
343
- export function renderSkillTemplate(template, context = {}, options = {}) {
344
- const { partials = {}, includes = {}, includeBaseDir = "" } = options;
345
- return renderWithContext(template, context, partials, {
346
- includeBaseDir,
347
- includes: { ...includes },
348
- });
349
- }