triflux 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.
Files changed (117) hide show
  1. package/CLAUDE.md +5 -5
  2. package/README.ko.md +5 -6
  3. package/README.md +5 -6
  4. package/bin/triflux.mjs +3 -72
  5. package/cto/collect.mjs +16 -174
  6. package/cto/current.schema.json +4 -16
  7. package/cto/events.mjs +13 -294
  8. package/cto/hygiene.mjs +26 -346
  9. package/cto/index.mjs +5 -25
  10. package/cto/lake-root.mjs +114 -16
  11. package/cto/status.mjs +31 -78
  12. package/hub/lib/cto-env.mjs +0 -23
  13. package/hub/paths.mjs +0 -6
  14. package/hub/pipeline/index.mjs +0 -190
  15. package/hub/pipeline/transitions.mjs +0 -10
  16. package/hub/reflexion.mjs +1 -84
  17. package/hub/store-adapter.mjs +1 -1
  18. package/hub/team/conductor.mjs +1 -1
  19. package/hub/team/execution-mode.mjs +1 -1
  20. package/hub/team/headless.mjs +1 -1
  21. package/hub/team/psmux.mjs +16 -402
  22. package/hub/team/session.mjs +1 -28
  23. package/hub/team/terminal-opener.mjs +11 -35
  24. package/hud/cli-policy.mjs +1 -5
  25. package/hud/colors.mjs +0 -13
  26. package/hud/constants.mjs +4 -135
  27. package/hud/context-monitor.mjs +3 -64
  28. package/hud/hud-qos-status.mjs +43 -225
  29. package/hud/providers/claude.mjs +4 -16
  30. package/hud/providers/gemini.mjs +7 -698
  31. package/hud/renderers.mjs +40 -294
  32. package/hud/terminal.mjs +1 -63
  33. package/hud/utils.mjs +0 -24
  34. package/package.json +2 -4
  35. package/scripts/__tests__/release-governance.test.mjs +0 -1
  36. package/scripts/lib/gemini-profiles.mjs +1 -1
  37. package/scripts/lib/legacy-mcp-cleanup.mjs +14 -3
  38. package/scripts/lib/psmux-info.mjs +18 -49
  39. package/scripts/lib/skill-template.mjs +0 -26
  40. package/scripts/pack.mjs +2 -21
  41. package/scripts/release/bump-version.mjs +8 -31
  42. package/scripts/release/lib.mjs +6 -13
  43. package/scripts/release/prepare.mjs +1 -5
  44. package/scripts/setup.mjs +26 -30
  45. package/scripts/tfx-route-post.mjs +0 -1
  46. package/scripts/tfx-route.sh +0 -9
  47. package/skills/tfx-auto/SKILL.md +1 -3
  48. package/skills/tfx-ship/SKILL.md +1 -1
  49. package/bin/tfx-profile.mjs +0 -7
  50. package/cto/dashboard.mjs +0 -474
  51. package/cto/hygiene-actions.mjs +0 -355
  52. package/cto/hygiene-notify.mjs +0 -170
  53. package/cto/steward.mjs +0 -362
  54. package/hub/codex-compat.mjs +0 -12
  55. package/hub/fullcycle.mjs +0 -113
  56. package/hub/gemini-adapter.mjs +0 -174
  57. package/hub/intent.mjs +0 -321
  58. package/hub/lib/mcp-response-cache.mjs +0 -239
  59. package/hub/lib/path-utils.mjs +0 -165
  60. package/hub/lib/timeline-adapter.mjs +0 -190
  61. package/hub/log-retention.mjs +0 -726
  62. package/hub/pipeline/gates/confidence.mjs +0 -75
  63. package/hub/pipeline/gates/consensus.mjs +0 -106
  64. package/hub/pipeline/gates/index.mjs +0 -9
  65. package/hub/pipeline/gates/selfcheck.mjs +0 -120
  66. package/hub/quality/deslop.mjs +0 -274
  67. package/hub/research.mjs +0 -155
  68. package/hub/role-control-events.mjs +0 -113
  69. package/hub/routing/complexity.mjs +0 -269
  70. package/hub/routing/index.mjs +0 -122
  71. package/hub/routing/q-learning.mjs +0 -387
  72. package/hub/token-mode.mjs +0 -228
  73. package/hub/workers/gemini-worker.mjs +0 -217
  74. package/hud/mission-board.mjs +0 -56
  75. package/hud/providers/cto.mjs +0 -76
  76. package/references/cli-parameter-reference.md +0 -240
  77. package/scripts/__tests__/gen-skill-manifest.test.mjs +0 -81
  78. package/scripts/__tests__/skill-template.test.mjs +0 -293
  79. package/scripts/__tests__/smoke.test.mjs +0 -26
  80. package/scripts/__tests__/tfx-route-bash-node-parity.test.mjs +0 -223
  81. package/scripts/__tests__/tfx-route-node-entry.test.mjs +0 -449
  82. package/scripts/__tests__/tfx-route-phase1-modules.test.mjs +0 -268
  83. package/scripts/cache-buildup.mjs +0 -30
  84. package/scripts/cli-route.sh +0 -3
  85. package/scripts/gen-skill-manifest.mjs +0 -87
  86. package/scripts/lib/agent-json.mjs +0 -27
  87. package/scripts/lib/async.mjs +0 -174
  88. package/scripts/lib/cli-agy.mjs +0 -85
  89. package/scripts/lib/cli-codex.mjs +0 -62
  90. package/scripts/lib/cli-gemini.mjs +0 -37
  91. package/scripts/lib/env.mjs +0 -14
  92. package/scripts/lib/hub.mjs +0 -48
  93. package/scripts/lib/pid.mjs +0 -63
  94. package/scripts/lib/quota.mjs +0 -47
  95. package/scripts/lib/skill-state.mjs +0 -220
  96. package/scripts/lib/team.mjs +0 -75
  97. package/scripts/lib/timeout.mjs +0 -66
  98. package/scripts/lib/tmp.mjs +0 -26
  99. package/scripts/lib/toml.mjs +0 -132
  100. package/scripts/preinstall.mjs +0 -128
  101. package/scripts/session-spawn-helper.mjs +0 -261
  102. package/scripts/test-tfx-route-no-claude-native.mjs +0 -63
  103. package/scripts/tfx-batch-stats.mjs +0 -117
  104. package/scripts/tfx-route.mjs +0 -314
  105. package/scripts/token-snapshot.mjs +0 -696
  106. package/skills/tfx-auto/skill.json +0 -5
  107. package/skills/tfx-doctor/skill.json +0 -5
  108. package/skills/tfx-harness/skill.json +0 -5
  109. package/skills/tfx-live/skill.json +0 -5
  110. package/skills/tfx-remote/skill.json +0 -5
  111. package/skills/tfx-research/skill.json +0 -6
  112. package/skills/tfx-review/skill.json +0 -6
  113. package/skills/tfx-setup/skill.json +0 -5
  114. package/skills/tfx-ship/skill.json +0 -5
  115. package/skills/tfx-wt/skill.json +0 -5
  116. package/tui/codex-profile.mjs +0 -421
  117. package/tui/gemini-profile.mjs +0 -286
package/cto/events.mjs CHANGED
@@ -6,12 +6,13 @@ import {
6
6
  unlinkSync,
7
7
  } from "node:fs";
8
8
  import { basename, join } from "node:path";
9
- import { resolveLakeRootDir } from "./lake-root.mjs";
9
+ import { pathLabel, shortHash, toIsoTime } from "./lake-root.mjs";
10
10
 
11
11
  export const CTO_EVENT_SCHEMA_VERSION = "cto-event.v1";
12
12
  export const DEFAULT_CTO_EVENT_SOURCE = "tfx_cto_event";
13
13
 
14
14
  export const CTO_EVENT_TYPES = Object.freeze([
15
+ "collect",
15
16
  "session_started",
16
17
  "session_heartbeat",
17
18
  "session_stale",
@@ -42,98 +43,6 @@ export const CTO_HYGIENE_STATUSES = Object.freeze([
42
43
  const EVENT_TYPE_SET = new Set(CTO_EVENT_TYPES);
43
44
  const STATUS_SET = new Set(CTO_HYGIENE_STATUSES);
44
45
 
45
- const EVENT_PRESETS = Object.freeze({
46
- "context-save": {
47
- event: "checkpoint_saved",
48
- source: "gstack_context_save",
49
- actor: { cli: "gstack context-save" },
50
- ownerSurface: "gstack context-save -> tfx cto event context-save",
51
- },
52
- "checkpoint-saved": {
53
- event: "checkpoint_saved",
54
- ownerSurface: "checkpoint wrapper -> tfx cto event checkpoint-saved",
55
- },
56
- "context-restore": {
57
- event: "checkpoint_restored",
58
- source: "gstack_context_restore",
59
- actor: { cli: "gstack context-restore" },
60
- ownerSurface: "gstack context-restore -> tfx cto event context-restore",
61
- },
62
- "checkpoint-restored": {
63
- event: "checkpoint_restored",
64
- ownerSurface: "checkpoint wrapper -> tfx cto event checkpoint-restored",
65
- },
66
- "pr-created": {
67
- event: "pr_created",
68
- source: "tfx_pr_lifecycle",
69
- actor: { cli: "gh pr create" },
70
- ownerSurface: "gh pr create/merge/close -> tfx cto event pr-created",
71
- },
72
- "pr-merged": {
73
- event: "pr_merged_or_closed",
74
- source: "tfx_pr_lifecycle",
75
- status: "completed",
76
- actor: { cli: "gh pr merge" },
77
- ownerSurface:
78
- "gh pr create/merge/close -> tfx cto event pr-merged-or-closed",
79
- },
80
- "pr-closed": {
81
- event: "pr_merged_or_closed",
82
- source: "tfx_pr_lifecycle",
83
- status: "completed",
84
- actor: { cli: "gh pr close" },
85
- ownerSurface:
86
- "gh pr create/merge/close -> tfx cto event pr-merged-or-closed",
87
- },
88
- "pr-merged-or-closed": {
89
- event: "pr_merged_or_closed",
90
- source: "tfx_pr_lifecycle",
91
- actor: { cli: "gh pr merge/close" },
92
- ownerSurface:
93
- "gh pr create/merge/close -> tfx cto event pr-merged-or-closed",
94
- },
95
- });
96
-
97
- const OPTION_KEYS = Object.freeze({
98
- event: "event",
99
- "event-type": "event",
100
- source: "source",
101
- summary: "summary",
102
- now: "now",
103
- ts: "ts",
104
- status: "status",
105
- "session-id": "session_id",
106
- "parent-session-id": "parent_session_id",
107
- "restored-from-session-id": "restored_from_session_id",
108
- "checkpoint-id": "checkpoint_id",
109
- "artifact-path": "artifact_path",
110
- artifact: "artifact_path",
111
- "task-id": "task_id",
112
- branch: "branch",
113
- "last-seen-at": "last_seen_at",
114
- "stale-reason": "stale_reason",
115
- "hygiene-key": "hygiene_key",
116
- "hygiene-kind": "hygiene_kind",
117
- "hygiene-id": "hygiene_id",
118
- "hygiene-action": "hygiene_action",
119
- "project-root": "project_root",
120
- "worktree-path": "worktree_path",
121
- worktree: "worktree_path",
122
- issue: "issue_refs",
123
- "issue-ref": "issue_refs",
124
- "issue-refs": "issue_refs",
125
- pr: "pr_refs",
126
- "pr-ref": "pr_refs",
127
- "pr-refs": "pr_refs",
128
- "actor-cli": "actor.cli",
129
- "actor-session-id": "actor.session_id",
130
- "actor-agent-id": "actor.agent_id",
131
- "actor-host": "actor.host",
132
- "owner-surface": "owner_surface",
133
- });
134
-
135
- const COLLECTION_KEYS = new Set(["issue_refs", "pr_refs"]);
136
-
137
46
  function sleep(ms) {
138
47
  return new Promise((resolve) => setTimeout(resolve, ms));
139
48
  }
@@ -144,31 +53,6 @@ function maybeString(value) {
144
53
  return trimmed || null;
145
54
  }
146
55
 
147
- function toIsoTime(value) {
148
- if (typeof value === "string" && value.trim()) return value;
149
- if (value instanceof Date) return value.toISOString();
150
- if (typeof value === "number" && Number.isFinite(value)) {
151
- return new Date(value).toISOString();
152
- }
153
- return new Date().toISOString();
154
- }
155
-
156
- function shortHash(value) {
157
- const str = String(value ?? "");
158
- let h = 5381;
159
- for (let i = 0; i < str.length; i += 1) {
160
- h = (h * 33) ^ str.charCodeAt(i);
161
- }
162
- return (h >>> 0).toString(36);
163
- }
164
-
165
- function pathLabel(value) {
166
- const str = String(value ?? "").replace(/[/\\]+$/u, "");
167
- if (!str) return null;
168
- const segments = str.split(/[/\\]+/u);
169
- return segments[segments.length - 1] || null;
170
- }
171
-
172
56
  function normalizeNumericRefs(values) {
173
57
  const rawValues = Array.isArray(values)
174
58
  ? values
@@ -200,124 +84,6 @@ function normalizeActor(actor) {
200
84
  return Object.keys(normalized).length > 0 ? normalized : null;
201
85
  }
202
86
 
203
- function optionName(raw) {
204
- return String(raw || "")
205
- .replace(/^--?/u, "")
206
- .trim();
207
- }
208
-
209
- function appendCollection(target, key, value) {
210
- const values = String(value ?? "")
211
- .split(",")
212
- .map((item) => item.trim())
213
- .filter(Boolean);
214
- if (values.length === 0) return;
215
- if (!Array.isArray(target[key])) target[key] = [];
216
- target[key].push(...values);
217
- }
218
-
219
- function putPathValue(target, keyPath, value) {
220
- if (keyPath.startsWith("actor.")) {
221
- const key = keyPath.slice("actor.".length);
222
- target.actor ||= {};
223
- target.actor[key] = value;
224
- return;
225
- }
226
- if (COLLECTION_KEYS.has(keyPath)) {
227
- appendCollection(target, keyPath, value);
228
- return;
229
- }
230
- target[keyPath] = value;
231
- }
232
-
233
- function parseEventArgs(args = []) {
234
- const fields = {};
235
- const positional = [];
236
- let json = false;
237
-
238
- for (let i = 0; i < args.length; i += 1) {
239
- const arg = args[i];
240
- if (arg === "--json") {
241
- json = true;
242
- continue;
243
- }
244
- if (!arg?.startsWith?.("--")) {
245
- positional.push(arg);
246
- continue;
247
- }
248
-
249
- const eqIndex = arg.indexOf("=");
250
- const rawName = eqIndex >= 0 ? arg.slice(0, eqIndex) : arg;
251
- const name = optionName(rawName);
252
- const mapped = OPTION_KEYS[name];
253
- if (!mapped) {
254
- throw new Error(`unknown tfx cto event option: --${name}`);
255
- }
256
-
257
- let value = eqIndex >= 0 ? arg.slice(eqIndex + 1) : null;
258
- if (value === null) {
259
- const next = args[i + 1];
260
- if (typeof next === "string" && !next.startsWith("--")) {
261
- value = next;
262
- i += 1;
263
- } else {
264
- value = "true";
265
- }
266
- }
267
- putPathValue(fields, mapped, value);
268
- }
269
-
270
- return {
271
- presetName: positional[0] || null,
272
- extraPositionals: positional.slice(1),
273
- fields,
274
- json,
275
- };
276
- }
277
-
278
- function mergeActor(defaultActor, overrideActor) {
279
- const actor = { ...(defaultActor || {}), ...(overrideActor || {}) };
280
- return Object.keys(actor).length > 0 ? actor : undefined;
281
- }
282
-
283
- function defaultEventSummary(input) {
284
- if (input.event === "checkpoint_saved") {
285
- return `context-save checkpoint ${input.checkpoint_id}`;
286
- }
287
- if (input.event === "checkpoint_restored") {
288
- return `context-restore checkpoint ${input.checkpoint_id}`;
289
- }
290
- if (input.event === "pr_created") {
291
- const [pr] = normalizeNumericRefs(input.pr_refs);
292
- return pr ? `PR #${pr} created` : "PR created";
293
- }
294
- if (input.event === "pr_merged_or_closed") {
295
- const [pr] = normalizeNumericRefs(input.pr_refs);
296
- return pr ? `PR #${pr} merged or closed` : "PR merged or closed";
297
- }
298
- return undefined;
299
- }
300
-
301
- function validateRunEventInput(input) {
302
- if (!input.event) {
303
- throw new Error("tfx cto event requires a preset or --event <event_type>");
304
- }
305
-
306
- if (
307
- ["checkpoint_saved", "checkpoint_restored"].includes(input.event) &&
308
- !maybeString(input.checkpoint_id)
309
- ) {
310
- throw new Error(`tfx cto event ${input.event} requires --checkpoint-id`);
311
- }
312
-
313
- if (
314
- ["pr_created", "pr_merged_or_closed"].includes(input.event) &&
315
- normalizeNumericRefs(input.pr_refs).length === 0
316
- ) {
317
- throw new Error(`tfx cto event ${input.event} requires --pr`);
318
- }
319
- }
320
-
321
87
  function putString(target, key, value) {
322
88
  const normalized = maybeString(value);
323
89
  if (normalized) target[key] = normalized;
@@ -341,7 +107,16 @@ export function normalizeCtoEvent(input = {}) {
341
107
  throw new Error(`invalid CTO status: ${status}`);
342
108
  }
343
109
 
344
- const ts = toIsoTime(input.now ?? input.ts);
110
+ const ts = toIsoTime(input.now ?? input.ts) || new Date().toISOString();
111
+ if (eventType === "collect") {
112
+ return {
113
+ ts,
114
+ event: eventType,
115
+ source: maybeString(input.source) || "tfx_cto_collect",
116
+ summary: maybeString(input.summary) || eventType,
117
+ ref: input.ref ?? null,
118
+ };
119
+ }
345
120
  const ref = {
346
121
  schema_version: CTO_EVENT_SCHEMA_VERSION,
347
122
  event_type: eventType,
@@ -416,7 +191,7 @@ export async function appendCtoEvent(lakeRoot, input, opts = {}) {
416
191
 
417
192
  if (fd === null) {
418
193
  stderr.write(
419
- "[tfx cto event] warning: ledger lock timeout; skipped ledger append\n",
194
+ "[tfx cto] warning: ledger lock timeout; skipped ledger append\n",
420
195
  );
421
196
  return { appended: false, event };
422
197
  }
@@ -431,59 +206,3 @@ export async function appendCtoEvent(lakeRoot, input, opts = {}) {
431
206
  } catch {}
432
207
  }
433
208
  }
434
-
435
- export async function runEvent(args = [], opts = {}) {
436
- const parsed = parseEventArgs(args);
437
- if (parsed.extraPositionals.length > 0) {
438
- throw new Error(
439
- `unexpected tfx cto event argument: ${parsed.extraPositionals[0]}`,
440
- );
441
- }
442
- const preset = parsed.presetName ? EVENT_PRESETS[parsed.presetName] : null;
443
- if (parsed.presetName && !preset && !parsed.fields.event) {
444
- throw new Error(`unknown tfx cto event preset: ${parsed.presetName}`);
445
- }
446
-
447
- const rootDir = opts.rootDir || resolveLakeRootDir(process.cwd());
448
- const lakeRoot = opts.lakeRoot || join(rootDir, ".triflux", "lake");
449
- const stdout = opts.stdout || process.stdout;
450
- const jsonOut = opts.json === true || parsed.json;
451
- const ownerSurface =
452
- parsed.fields.owner_surface ||
453
- preset?.ownerSurface ||
454
- "external wrapper -> tfx cto event --event";
455
-
456
- const input = {
457
- ...(preset || {}),
458
- ...parsed.fields,
459
- actor: mergeActor(preset?.actor, parsed.fields.actor),
460
- };
461
- delete input.ownerSurface;
462
- delete input.owner_surface;
463
- if (!input.project_root) input.project_root = rootDir;
464
- if (!input.summary) input.summary = defaultEventSummary(input);
465
-
466
- validateRunEventInput(input);
467
-
468
- const result = await appendCtoEvent(lakeRoot, input, {
469
- stderr: opts.stderr,
470
- lockRetries: opts.ledgerLockRetries,
471
- lockRetryDelayMs: opts.ledgerLockRetryDelayMs,
472
- });
473
- const payload = {
474
- appended: result.appended,
475
- owner_surface: ownerSurface,
476
- event: result.event,
477
- };
478
-
479
- if (jsonOut) {
480
- stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
481
- } else {
482
- const status = result.appended ? "appended" : "skipped";
483
- stdout.write(
484
- `[tfx cto event] ${status} ${result.event.event} via ${ownerSurface}\n`,
485
- );
486
- }
487
-
488
- return payload;
489
- }