@triflux/core 10.51.0 → 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 (55) hide show
  1. package/hub/bridge.mjs +65 -1172
  2. package/hub/index.mjs +2 -18
  3. package/hub/lib/process-utils.mjs +1 -33
  4. package/hub/team/claude-daemon-control.mjs +1 -2
  5. package/hub/team/claude-session-projection.mjs +5 -73
  6. package/hub/team/nativeProxy.mjs +759 -0
  7. package/hub/team/session-context.mjs +1 -1
  8. package/hud/constants.mjs +2 -0
  9. package/hud/hud-qos-status.mjs +21 -5
  10. package/hud/providers/gemini.mjs +20 -0
  11. package/hud/renderers.mjs +79 -46
  12. package/hud/utils.mjs +9 -5
  13. package/package.json +2 -4
  14. package/scripts/lib/agent-route-policy.mjs +0 -67
  15. package/scripts/lib/cli-claude.mjs +0 -12
  16. package/scripts/lib/env-probe.mjs +0 -70
  17. package/scripts/lib/legacy-mcp-cleanup.mjs +283 -0
  18. package/scripts/lib/mcp-guard-engine.mjs +40 -98
  19. package/scripts/lib/session-presence.mjs +1 -99
  20. package/hub/adaptive-diagnostic.mjs +0 -350
  21. package/hub/adaptive-inject.mjs +0 -224
  22. package/hub/adaptive-memory.mjs +0 -277
  23. package/hub/adaptive.mjs +0 -172
  24. package/hub/assign-callbacks.mjs +0 -170
  25. package/hub/delegator/contracts.mjs +0 -38
  26. package/hub/delegator/index.mjs +0 -14
  27. package/hub/delegator/schema/delegator-tools.schema.json +0 -250
  28. package/hub/delegator/service.mjs +0 -336
  29. package/hub/delegator/tool-definitions.mjs +0 -35
  30. package/hub/hitl.mjs +0 -202
  31. package/hub/lib/known-errors.json +0 -72
  32. package/hub/lib/memory-store.mjs +0 -1001
  33. package/hub/lib/phase-manager.mjs +0 -493
  34. package/hub/lib/state-snapshot.mjs +0 -293
  35. package/hub/lib/trace-recorder.mjs +0 -153
  36. package/hub/lib/uuidv7.mjs +0 -45
  37. package/hub/memory-doctor.mjs +0 -640
  38. package/hub/middleware/quota-middleware.mjs +0 -70
  39. package/hub/middleware/request-logger.mjs +0 -191
  40. package/hub/paths.mjs +0 -24
  41. package/hub/pipeline/index.mjs +0 -163
  42. package/hub/pipeline/state.mjs +0 -191
  43. package/hub/pipeline/transitions.mjs +0 -131
  44. package/hub/reflexion.mjs +0 -290
  45. package/hub/role-contract.mjs +0 -312
  46. package/hub/router.mjs +0 -2026
  47. package/hub/session-fingerprint.mjs +0 -418
  48. package/hub/state.mjs +0 -300
  49. package/hub/team/synapse-http.mjs +0 -311
  50. package/hub/team-bridge.mjs +0 -27
  51. package/scripts/lib/claudemd-scanner.mjs +0 -26
  52. package/scripts/lib/context.mjs +0 -51
  53. package/scripts/lib/handoff.mjs +0 -187
  54. package/scripts/lib/logger.mjs +0 -122
  55. package/scripts/lib/stealth-fetch.mjs +0 -176
@@ -1,250 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://triflux.dev/schema/hub/delegator-tools.schema.json",
4
- "title": "Triflux Delegator MCP Tool Schemas",
5
- "$defs": {
6
- "Provider": {
7
- "type": "string",
8
- "enum": ["auto", "codex", "antigravity", "gemini"]
9
- },
10
- "Mode": {
11
- "type": "string",
12
- "enum": ["sync", "async"]
13
- },
14
- "JobStatus": {
15
- "type": "string",
16
- "enum": ["queued", "running", "waiting_reply", "completed", "failed"]
17
- },
18
- "McpProfile": {
19
- "type": "string",
20
- "enum": [
21
- "auto",
22
- "default",
23
- "executor",
24
- "designer",
25
- "explore",
26
- "reviewer",
27
- "writer",
28
- "none",
29
- "implement",
30
- "analyze",
31
- "review",
32
- "docs",
33
- "minimal"
34
- ]
35
- },
36
- "SearchTool": {
37
- "type": "string",
38
- "enum": ["exa", "brave-search", "tavily"]
39
- },
40
- "NullableDateTime": {
41
- "type": ["string", "null"],
42
- "format": "date-time"
43
- },
44
- "NullableString": {
45
- "type": ["string", "null"]
46
- },
47
- "DelegateInput": {
48
- "type": "object",
49
- "additionalProperties": false,
50
- "required": ["prompt"],
51
- "properties": {
52
- "prompt": {
53
- "type": "string",
54
- "minLength": 1
55
- },
56
- "provider": {
57
- "$ref": "#/$defs/Provider",
58
- "default": "auto"
59
- },
60
- "mode": {
61
- "$ref": "#/$defs/Mode",
62
- "default": "sync"
63
- },
64
- "agent_type": {
65
- "type": "string",
66
- "default": "executor",
67
- "minLength": 1
68
- },
69
- "cwd": {
70
- "type": "string",
71
- "minLength": 1
72
- },
73
- "timeout_ms": {
74
- "type": "integer",
75
- "minimum": 1
76
- },
77
- "session_key": {
78
- "type": "string",
79
- "minLength": 1
80
- },
81
- "thread_id": {
82
- "type": "string",
83
- "minLength": 1
84
- },
85
- "reset_session": {
86
- "type": "boolean",
87
- "default": false
88
- },
89
- "mcp_profile": {
90
- "$ref": "#/$defs/McpProfile",
91
- "default": "auto"
92
- },
93
- "search_tool": {
94
- "$ref": "#/$defs/SearchTool"
95
- },
96
- "context_file": {
97
- "type": "string",
98
- "minLength": 1
99
- },
100
- "model": {
101
- "type": "string",
102
- "minLength": 1
103
- },
104
- "developer_instructions": {
105
- "type": "string",
106
- "minLength": 1
107
- },
108
- "compact_prompt": {
109
- "type": "string",
110
- "minLength": 1
111
- }
112
- }
113
- },
114
- "DelegateReplyInput": {
115
- "type": "object",
116
- "additionalProperties": false,
117
- "required": ["job_id", "reply"],
118
- "properties": {
119
- "job_id": {
120
- "type": "string",
121
- "minLength": 1
122
- },
123
- "reply": {
124
- "type": "string",
125
- "minLength": 1
126
- },
127
- "done": {
128
- "type": "boolean",
129
- "default": false
130
- }
131
- }
132
- },
133
- "StatusInput": {
134
- "type": "object",
135
- "additionalProperties": false,
136
- "required": ["job_id"],
137
- "properties": {
138
- "job_id": {
139
- "type": "string",
140
- "minLength": 1
141
- }
142
- }
143
- },
144
- "DelegateOutput": {
145
- "type": "object",
146
- "additionalProperties": false,
147
- "required": [
148
- "ok",
149
- "job_id",
150
- "status",
151
- "mode",
152
- "provider_requested",
153
- "provider_resolved",
154
- "agent_type",
155
- "transport",
156
- "created_at",
157
- "started_at",
158
- "updated_at",
159
- "completed_at",
160
- "thread_id",
161
- "session_key",
162
- "conversation_open"
163
- ],
164
- "properties": {
165
- "ok": {
166
- "type": "boolean"
167
- },
168
- "job_id": {
169
- "type": "string",
170
- "minLength": 1
171
- },
172
- "status": {
173
- "$ref": "#/$defs/JobStatus"
174
- },
175
- "mode": {
176
- "$ref": "#/$defs/Mode"
177
- },
178
- "provider_requested": {
179
- "$ref": "#/$defs/Provider"
180
- },
181
- "provider_resolved": {
182
- "type": ["string", "null"]
183
- },
184
- "agent_type": {
185
- "type": "string",
186
- "minLength": 1
187
- },
188
- "transport": {
189
- "type": "string",
190
- "minLength": 1
191
- },
192
- "created_at": {
193
- "type": "string",
194
- "format": "date-time"
195
- },
196
- "started_at": {
197
- "$ref": "#/$defs/NullableDateTime"
198
- },
199
- "updated_at": {
200
- "type": "string",
201
- "format": "date-time"
202
- },
203
- "completed_at": {
204
- "$ref": "#/$defs/NullableDateTime"
205
- },
206
- "output": {
207
- "type": "string"
208
- },
209
- "stderr": {
210
- "type": "string"
211
- },
212
- "error": {
213
- "type": "string"
214
- },
215
- "thread_id": {
216
- "$ref": "#/$defs/NullableString"
217
- },
218
- "session_key": {
219
- "$ref": "#/$defs/NullableString"
220
- },
221
- "conversation_open": {
222
- "type": "boolean"
223
- }
224
- }
225
- }
226
- },
227
- "x-triflux-mcp-tools": [
228
- {
229
- "name": "delegate",
230
- "description": "Create a new delegator job and optionally wait for the first result.",
231
- "inputSchemaDef": "DelegateInput",
232
- "outputSchemaDef": "DelegateOutput",
233
- "pipeAction": "delegator_delegate"
234
- },
235
- {
236
- "name": "delegate-reply",
237
- "description": "Send a follow-up reply into an existing delegator conversation job.",
238
- "inputSchemaDef": "DelegateReplyInput",
239
- "outputSchemaDef": "DelegateOutput",
240
- "pipeAction": "delegator_reply"
241
- },
242
- {
243
- "name": "status",
244
- "description": "Read the latest snapshot for an existing delegator job.",
245
- "inputSchemaDef": "StatusInput",
246
- "outputSchemaDef": "DelegateOutput",
247
- "pipeAction": "delegator_status"
248
- }
249
- ]
250
- }
@@ -1,336 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
-
3
- import {
4
- DELEGATOR_JOB_STATUSES,
5
- DELEGATOR_MODES,
6
- DELEGATOR_PROVIDERS,
7
- } from "./contracts.mjs";
8
- import { getDelegatorMcpToolDefinitions } from "./tool-definitions.mjs";
9
-
10
- function deepClone(value) {
11
- if (value == null) return value;
12
- return JSON.parse(JSON.stringify(value));
13
- }
14
-
15
- function assertKnown(enumValues, value, fieldName) {
16
- if (value == null) return;
17
- if (!enumValues.includes(value)) {
18
- throw new Error(`Unsupported ${fieldName}: ${value}`);
19
- }
20
- }
21
-
22
- function normalizeProvider(provider = "auto") {
23
- const value = provider || "auto";
24
- return value === "gemini" ? "antigravity" : value;
25
- }
26
-
27
- export class DelegatorService {
28
- constructor({
29
- idFactory = randomUUID,
30
- now = () => new Date(),
31
- worker = null,
32
- } = {}) {
33
- this.idFactory = idFactory;
34
- this.now = now;
35
- this.jobs = new Map();
36
- this.worker = worker;
37
- this._workerJobMap = new Map();
38
- }
39
-
40
- listToolDefinitions() {
41
- return getDelegatorMcpToolDefinitions();
42
- }
43
-
44
- createJobSnapshot(input = {}) {
45
- const timestamp = this.now().toISOString();
46
- const jobId = input.job_id || this.idFactory();
47
- const mode = input.mode || "sync";
48
- const providerRequested = normalizeProvider(input.provider);
49
-
50
- assertKnown(DELEGATOR_MODES, mode, "mode");
51
- assertKnown(DELEGATOR_PROVIDERS, providerRequested, "provider");
52
-
53
- return {
54
- ok: true,
55
- job_id: jobId,
56
- status: "queued",
57
- mode,
58
- provider_requested: providerRequested,
59
- provider_resolved: null,
60
- agent_type: input.agent_type || "executor",
61
- transport: "resident-pending",
62
- created_at: timestamp,
63
- started_at: null,
64
- updated_at: timestamp,
65
- completed_at: null,
66
- output: "",
67
- stderr: "",
68
- error: "",
69
- thread_id: input.thread_id || null,
70
- session_key: input.session_key || null,
71
- conversation_open: false,
72
- };
73
- }
74
-
75
- recordJob(snapshot) {
76
- if (!snapshot?.job_id) {
77
- throw new Error("job_id is required");
78
- }
79
- assertKnown(DELEGATOR_JOB_STATUSES, snapshot.status, "status");
80
- this.jobs.set(snapshot.job_id, deepClone(snapshot));
81
- return this.getStatusSnapshot(snapshot.job_id);
82
- }
83
-
84
- getStatusSnapshot(jobId) {
85
- const snapshot = this.jobs.get(jobId);
86
- return snapshot ? deepClone(snapshot) : null;
87
- }
88
-
89
- // -- 필드 정규화 헬퍼 --
90
-
91
- _normalizeInput(input = {}) {
92
- return {
93
- prompt: input.prompt,
94
- provider: normalizeProvider(input.provider),
95
- mode: input.mode || "sync",
96
- agent_type: input.agent_type || input.agentType || "executor",
97
- cwd: input.cwd || null,
98
- timeout_ms: input.timeout_ms || input.timeoutMs || null,
99
- session_key: input.session_key || input.sessionKey || null,
100
- thread_id: input.thread_id || input.threadId || null,
101
- reset_session: input.reset_session ?? input.resetSession ?? false,
102
- mcp_profile: input.mcp_profile || input.mcpProfile || "auto",
103
- search_tool: input.search_tool || input.searchTool || null,
104
- context_file: input.context_file || input.contextFile || null,
105
- model: input.model || null,
106
- developer_instructions:
107
- input.developer_instructions || input.developerInstructions || null,
108
- compact_prompt: input.compact_prompt || input.compactPrompt || null,
109
- };
110
- }
111
-
112
- _toWorkerArgs(normalized) {
113
- return {
114
- prompt: normalized.prompt,
115
- provider: normalized.provider,
116
- mode: normalized.mode,
117
- agentType: normalized.agent_type,
118
- cwd: normalized.cwd,
119
- timeoutMs: normalized.timeout_ms,
120
- sessionKey: normalized.session_key,
121
- threadId: normalized.thread_id,
122
- resetSession: normalized.reset_session,
123
- mcpProfile: normalized.mcp_profile,
124
- searchTool: normalized.search_tool,
125
- contextFile: normalized.context_file,
126
- model: normalized.model,
127
- developerInstructions: normalized.developer_instructions,
128
- compactPrompt: normalized.compact_prompt,
129
- };
130
- }
131
-
132
- _applyWorkerResult(jobId, workerResult) {
133
- const snapshot = this.jobs.get(jobId);
134
- if (!snapshot) return null;
135
-
136
- const timestamp = this.now().toISOString();
137
- const ok = workerResult.ok !== false;
138
-
139
- snapshot.ok = ok;
140
- snapshot.status = workerResult.status || (ok ? "completed" : "failed");
141
- snapshot.provider_resolved =
142
- workerResult.providerResolved || workerResult.provider_resolved || null;
143
- snapshot.transport = workerResult.transport || snapshot.transport;
144
- snapshot.output = workerResult.output || "";
145
- snapshot.stderr = workerResult.stderr || "";
146
- snapshot.error = workerResult.error || "";
147
- snapshot.thread_id =
148
- workerResult.threadId || workerResult.thread_id || null;
149
- snapshot.session_key =
150
- workerResult.sessionKey || workerResult.session_key || null;
151
- snapshot.conversation_open =
152
- workerResult.conversationOpen ?? workerResult.conversation_open ?? false;
153
- snapshot.started_at = snapshot.started_at || timestamp;
154
- snapshot.updated_at = timestamp;
155
- if (snapshot.status === "completed" || snapshot.status === "failed") {
156
- snapshot.completed_at = timestamp;
157
- }
158
-
159
- this.jobs.set(jobId, deepClone(snapshot));
160
- return deepClone(snapshot);
161
- }
162
-
163
- _failJob(jobId, error) {
164
- const snapshot = this.jobs.get(jobId);
165
- if (snapshot) {
166
- const timestamp = this.now().toISOString();
167
- snapshot.ok = false;
168
- snapshot.status = "failed";
169
- snapshot.error = error;
170
- snapshot.updated_at = timestamp;
171
- snapshot.completed_at = timestamp;
172
- this.jobs.set(jobId, deepClone(snapshot));
173
- return deepClone(snapshot);
174
- }
175
- return this._errorSnapshot(jobId, error);
176
- }
177
-
178
- _errorSnapshot(jobId, error) {
179
- const timestamp = this.now().toISOString();
180
- return {
181
- ok: false,
182
- job_id: jobId || "unknown",
183
- status: "failed",
184
- mode: "sync",
185
- provider_requested: "auto",
186
- provider_resolved: null,
187
- agent_type: "executor",
188
- transport: "resident-pending",
189
- created_at: timestamp,
190
- started_at: null,
191
- updated_at: timestamp,
192
- completed_at: timestamp,
193
- output: "",
194
- stderr: "",
195
- error,
196
- thread_id: null,
197
- session_key: null,
198
- conversation_open: false,
199
- };
200
- }
201
-
202
- // -- 위임/응답/상태 메서드 --
203
-
204
- async delegate(input = {}) {
205
- const normalized = this._normalizeInput(input);
206
-
207
- if (
208
- !normalized.prompt ||
209
- typeof normalized.prompt !== "string" ||
210
- !normalized.prompt.trim()
211
- ) {
212
- return this._errorSnapshot(null, "prompt is required");
213
- }
214
-
215
- const snapshot = this.createJobSnapshot(normalized);
216
- this.recordJob(snapshot);
217
-
218
- if (!this.worker) {
219
- return this._failJob(snapshot.job_id, "worker가 설정되지 않았습니다");
220
- }
221
-
222
- const workerArgs = this._toWorkerArgs(normalized);
223
-
224
- try {
225
- const workerResult = await this.worker.delegate(workerArgs, null);
226
-
227
- // worker job ID 매핑 (reply/status에서 사용)
228
- const workerJobId = workerResult.jobId || workerResult.job_id;
229
- if (workerJobId) {
230
- this._workerJobMap.set(snapshot.job_id, workerJobId);
231
- }
232
-
233
- return this._applyWorkerResult(snapshot.job_id, workerResult);
234
- } catch (err) {
235
- return this._failJob(
236
- snapshot.job_id,
237
- err instanceof Error ? err.message : String(err),
238
- );
239
- }
240
- }
241
-
242
- async reply(input = {}) {
243
- const jobId = input.job_id || input.jobId;
244
- if (!jobId) {
245
- return this._errorSnapshot("unknown", "job_id is required");
246
- }
247
-
248
- const snapshot = this.jobs.get(jobId);
249
- if (!snapshot) {
250
- return this._errorSnapshot(jobId, "job not found");
251
- }
252
-
253
- if (!snapshot.conversation_open) {
254
- return this._failJob(jobId, "conversation is not open");
255
- }
256
-
257
- if (!this.worker) {
258
- return this._failJob(jobId, "worker가 설정되지 않았습니다");
259
- }
260
-
261
- const workerJobId = this._workerJobMap.get(jobId);
262
- if (!workerJobId) {
263
- return this._failJob(jobId, "worker job 매핑을 찾을 수 없습니다");
264
- }
265
-
266
- try {
267
- const workerResult = await this.worker.reply(
268
- {
269
- job_id: workerJobId,
270
- reply: input.reply,
271
- done: input.done ?? false,
272
- },
273
- null,
274
- );
275
-
276
- return this._applyWorkerResult(jobId, workerResult);
277
- } catch (err) {
278
- return this._failJob(
279
- jobId,
280
- err instanceof Error ? err.message : String(err),
281
- );
282
- }
283
- }
284
-
285
- async status({ job_id: jobId, jobId: jobIdAlias } = {}) {
286
- const resolvedId = jobId || jobIdAlias;
287
- const snapshot = this.getStatusSnapshot(resolvedId);
288
-
289
- if (!snapshot) {
290
- const timestamp = this.now().toISOString();
291
- return {
292
- ok: false,
293
- job_id: resolvedId || "unknown-job",
294
- status: "failed",
295
- mode: "async",
296
- provider_requested: "auto",
297
- provider_resolved: null,
298
- agent_type: "executor",
299
- transport: "resident-pending",
300
- created_at: timestamp,
301
- started_at: null,
302
- updated_at: timestamp,
303
- completed_at: null,
304
- output: "",
305
- stderr: "",
306
- error: "job not found",
307
- thread_id: null,
308
- session_key: null,
309
- conversation_open: false,
310
- };
311
- }
312
-
313
- // running/queued 상태이면 worker에서 최신 상태 갱신
314
- if (
315
- this.worker &&
316
- (snapshot.status === "running" || snapshot.status === "queued")
317
- ) {
318
- const workerJobId = this._workerJobMap.get(resolvedId);
319
- if (workerJobId) {
320
- try {
321
- const workerResult = await this.worker.getJobStatus(
322
- workerJobId,
323
- null,
324
- );
325
- if (workerResult && workerResult.ok !== undefined) {
326
- return this._applyWorkerResult(resolvedId, workerResult);
327
- }
328
- } catch {
329
- // worker 상태 확인 실패 시 캐시된 snapshot 반환
330
- }
331
- }
332
- }
333
-
334
- return snapshot;
335
- }
336
- }
@@ -1,35 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
-
3
- import { DELEGATOR_SCHEMA_URL } from "./contracts.mjs";
4
-
5
- let schemaBundleCache = null;
6
-
7
- function deepClone(value) {
8
- if (value == null) return value;
9
- return JSON.parse(JSON.stringify(value));
10
- }
11
-
12
- export function loadDelegatorSchemaBundle() {
13
- if (schemaBundleCache) {
14
- return schemaBundleCache;
15
- }
16
-
17
- schemaBundleCache = JSON.parse(readFileSync(DELEGATOR_SCHEMA_URL, "utf8"));
18
- return schemaBundleCache;
19
- }
20
-
21
- export function getDelegatorMcpToolDefinitions() {
22
- const bundle = loadDelegatorSchemaBundle();
23
- const defs = bundle.$defs || {};
24
- const tools = Array.isArray(bundle["x-triflux-mcp-tools"])
25
- ? bundle["x-triflux-mcp-tools"]
26
- : [];
27
-
28
- return tools.map((tool) => ({
29
- name: tool.name,
30
- description: tool.description,
31
- inputSchema: deepClone(defs[tool.inputSchemaDef]),
32
- outputSchema: deepClone(defs[tool.outputSchemaDef]),
33
- pipeAction: tool.pipeAction,
34
- }));
35
- }