@triflux/remote 10.33.1 → 10.35.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.
package/cto/status.mjs CHANGED
@@ -29,7 +29,61 @@ function toIsoTime(value) {
29
29
  return null;
30
30
  }
31
31
 
32
+ function shortHash(value) {
33
+ const str = String(value ?? "");
34
+ let h = 5381;
35
+ for (let i = 0; i < str.length; i++) {
36
+ h = (h * 33) ^ str.charCodeAt(i);
37
+ }
38
+ return (h >>> 0).toString(36);
39
+ }
40
+
41
+ function pathLabel(value) {
42
+ const str = String(value ?? "").replace(/[/\\]+$/u, "");
43
+ if (!str) return "";
44
+ const segments = str.split(/[/\\]+/u);
45
+ return segments[segments.length - 1] || "";
46
+ }
47
+
48
+ export function deriveRepoRootFromCwd(cwd) {
49
+ if (typeof cwd !== "string" || !cwd) return "";
50
+ if (cwd.includes("\\") || /^[A-Za-z]:/u.test(cwd)) return cwd;
51
+
52
+ const normalized = cwd.replace(/\/+$/u, "");
53
+ const claudeMarker = "/.claude/worktrees/";
54
+ const claudeIndex = normalized.indexOf(claudeMarker);
55
+ if (claudeIndex > 0) {
56
+ const suffix = normalized.slice(claudeIndex + claudeMarker.length);
57
+ if (/^[^/]+(?:\/|$)/u.test(suffix)) {
58
+ return normalized.slice(0, claudeIndex);
59
+ }
60
+ }
61
+
62
+ const codexMarker = "/.codex-swarm/";
63
+ const codexIndex = normalized.indexOf(codexMarker);
64
+ if (codexIndex > 0) {
65
+ const suffix = normalized.slice(codexIndex + codexMarker.length);
66
+ if (/^wt-[^/]+(?:\/|$)/u.test(suffix)) {
67
+ return normalized.slice(0, codexIndex);
68
+ }
69
+ }
70
+
71
+ return cwd;
72
+ }
73
+
74
+ function redactedCwdFields(cwd) {
75
+ if (typeof cwd !== "string" || !cwd) return {};
76
+ const repoRoot = deriveRepoRootFromCwd(cwd);
77
+ return {
78
+ cwdLabel: pathLabel(cwd),
79
+ cwdHash: shortHash(cwd),
80
+ repoRootLabel: pathLabel(repoRoot),
81
+ repoRootHash: shortHash(repoRoot),
82
+ };
83
+ }
84
+
32
85
  function normalizeLiveSession(session) {
86
+ const cwd = typeof session?.cwd === "string" ? session.cwd : "";
33
87
  return {
34
88
  sessionId: String(session?.sessionId || ""),
35
89
  host: typeof session?.host === "string" ? session.host : "local",
@@ -48,6 +102,7 @@ function normalizeLiveSession(session) {
48
102
  started_at: toIsoTime(
49
103
  session?.started_at ?? session?.startedAt ?? session?.lastHeartbeat,
50
104
  ),
105
+ ...redactedCwdFields(cwd),
51
106
  };
52
107
  }
53
108
 
@@ -164,7 +219,27 @@ function deriveActiveShards(current, overlay) {
164
219
  return shards.map(normalizeActiveShard).filter((shard) => shard.shard_name);
165
220
  }
166
221
 
222
+ function deriveLiveSessionGroups(liveSessions) {
223
+ const groups = new Map();
224
+ for (const session of liveSessions || []) {
225
+ if (!session?.repoRootHash) continue;
226
+ if (!groups.has(session.repoRootHash)) {
227
+ groups.set(session.repoRootHash, {
228
+ repoRootLabel: session.repoRootLabel || "",
229
+ repoRootHash: session.repoRootHash,
230
+ session_count: 0,
231
+ sessions: [],
232
+ });
233
+ }
234
+ const group = groups.get(session.repoRootHash);
235
+ group.session_count += 1;
236
+ group.sessions.push(session.sessionId);
237
+ }
238
+ return [...groups.values()];
239
+ }
240
+
167
241
  function projectStatus(current, overlay) {
242
+ const liveSessions = overlay.live_sessions;
168
243
  return {
169
244
  schema_version: current?.schema_version || SCHEMA_VERSION,
170
245
  generated_at: current?.generated_at || null,
@@ -172,7 +247,8 @@ function projectStatus(current, overlay) {
172
247
  sources: current?.sources || {},
173
248
  summary: current?.summary || {},
174
249
  ledger_tail: Array.isArray(current?.ledger_tail) ? current.ledger_tail : [],
175
- live_sessions: overlay.live_sessions,
250
+ live_sessions: liveSessions,
251
+ live_session_groups: deriveLiveSessionGroups(liveSessions),
176
252
  active_shards: deriveActiveShards(current, overlay),
177
253
  };
178
254
  }
@@ -15,15 +15,21 @@ const EPHEMERAL_ENV_KEYS = [
15
15
  "TFX_TEAM_AGENT_NAME",
16
16
  "TFX_EPHEMERAL",
17
17
  ];
18
+ const WORKTREE_CWD_PATTERNS = [
19
+ /\/\.claude\/worktrees\//u,
20
+ /\/\.worktrees\//u,
21
+ /\/\.codex-swarm\/wt-[^/]+(?:\/|$)/u,
22
+ /(^|\/)wt-[^/]+(?:\/|$)/u,
23
+ ];
18
24
 
19
- function parsePositiveInt(value) {
25
+ function parsePositivePort(value) {
20
26
  const parsed = Number.parseInt(String(value ?? ""), 10);
21
27
  return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
22
28
  }
23
29
 
24
- function parsePortFromUrl(value) {
30
+ function parsePortFromHubUrl(value) {
25
31
  try {
26
- return parsePositiveInt(new URL(String(value)).port);
32
+ return parsePositivePort(new URL(String(value)).port);
27
33
  } catch {
28
34
  return null;
29
35
  }
@@ -40,12 +46,7 @@ export function isWorktreeOrEphemeralHubContext({
40
46
  env = process.env,
41
47
  } = {}) {
42
48
  const normalizedCwd = String(cwd || "").replace(/\\/g, "/");
43
- if (
44
- normalizedCwd.includes("/.claude/worktrees/") ||
45
- normalizedCwd.includes("/.worktrees/") ||
46
- normalizedCwd.includes("/.codex-swarm/wt-") ||
47
- /(^|\/)wt-[^/]+(?:\/|$)/u.test(normalizedCwd)
48
- ) {
49
+ if (WORKTREE_CWD_PATTERNS.some((pattern) => pattern.test(normalizedCwd))) {
49
50
  return true;
50
51
  }
51
52
  return EPHEMERAL_ENV_KEYS.some((key) => String(env?.[key] || "").length > 0);
@@ -57,11 +58,16 @@ export function resolveHubPortForContext({
57
58
  cwd = process.cwd(),
58
59
  defaultPort = HUB_DEFAULT_PORT,
59
60
  } = {}) {
60
- const envPort = parsePositiveInt(port) ?? parsePositiveInt(env?.TFX_HUB_PORT);
61
- const urlPort = parsePortFromUrl(env?.TFX_HUB_URL);
61
+ const envPort =
62
+ parsePositivePort(port) ?? parsePositivePort(env?.TFX_HUB_PORT);
63
+ const urlPort = parsePortFromHubUrl(env?.TFX_HUB_URL);
62
64
  const resolvedPort = envPort ?? urlPort ?? defaultPort;
63
65
  if (
64
66
  resolvedPort !== defaultPort &&
67
+ // Test-only opt-in seam: TFX_HUB_ALLOW_EPHEMERAL_PORT=1 lets an ephemeral
68
+ // context (worktree cwd / TFX_TEAM_* env) honor the resolved port instead
69
+ // of clamping to the canonical default. Default-off — production unchanged.
70
+ String(env?.TFX_HUB_ALLOW_EPHEMERAL_PORT ?? "") !== "1" &&
65
71
  isWorktreeOrEphemeralHubContext({ cwd, env })
66
72
  ) {
67
73
  return defaultPort;
@@ -181,7 +187,7 @@ export async function reapExistingHubProcesses({
181
187
  typeof readPidFileFn === "function"
182
188
  ? readPidFileFn()
183
189
  : { pid: readPidFilePid({ pidFilePath }) };
184
- const pidFilePid = parsePositiveInt(pidFileInfo?.pid);
190
+ const pidFilePid = parsePositivePort(pidFileInfo?.pid);
185
191
  const defaultPortPids = [
186
192
  ...new Set(
187
193
  (typeof findListeningPidsForPortFn === "function"
package/hub/server.mjs CHANGED
@@ -246,7 +246,9 @@ async function parseBody(req) {
246
246
  return JSON.parse(Buffer.concat(chunks).toString());
247
247
  }
248
248
 
249
- const PID_DIR = join(homedir(), ".claude", "cache", "tfx-hub");
249
+ const PID_DIR =
250
+ process.env.TFX_HUB_PID_DIR?.trim() ||
251
+ join(homedir(), ".claude", "cache", "tfx-hub");
250
252
  const PID_FILE = join(PID_DIR, "hub.pid");
251
253
  const TOKEN_FILE = join(homedir(), ".claude", ".tfx-hub-token");
252
254
 
@@ -1004,7 +1006,7 @@ export async function startHub({
1004
1006
  // DB를 npm 패키지 밖에 저장하여 npm update 시 EBUSY 방지
1005
1007
  // 기존: PROJECT_ROOT/.tfx/state/state.db (패키지 내부 → 락 충돌)
1006
1008
  // 변경: ~/.claude/cache/tfx-hub/state.db (패키지 외부 → 안전)
1007
- const hubCacheDir = join(homedir(), ".claude", "cache", "tfx-hub");
1009
+ const hubCacheDir = PID_DIR;
1008
1010
  mkdirSync(hubCacheDir, { recursive: true });
1009
1011
  dbPath = join(hubCacheDir, "state.db");
1010
1012
  }
@@ -2461,6 +2463,7 @@ export async function startHub({
2461
2463
  hubLog.warn(
2462
2464
  {
2463
2465
  failed: failed.length,
2466
+ failedCount: failed.length,
2464
2467
  processes: failed,
2465
2468
  caller: "startup",
2466
2469
  },
@@ -22,10 +22,23 @@ function formatLeaseFiles(leaseFiles) {
22
22
  return normalized.map((file) => `- ${file}`).join("\n");
23
23
  }
24
24
 
25
- export function buildLeaseScopedAcceptanceAppendix({ leaseFiles = [] } = {}) {
25
+ function normalizeWorktreePath(worktreePath) {
26
+ return typeof worktreePath === "string" ? worktreePath.trim() : "";
27
+ }
28
+
29
+ export function buildLeaseScopedAcceptanceAppendix({
30
+ leaseFiles = [],
31
+ worktreePath,
32
+ } = {}) {
33
+ const normalizedWorktreePath = normalizeWorktreePath(worktreePath);
34
+ const rootLine = normalizedWorktreePath
35
+ ? `작업 루트(절대경로): ${normalizedWorktreePath} — 아래 lease 경로와 모든 상대경로는 이 루트 기준으로만 해석한다.\n`
36
+ : "";
37
+
26
38
  return `
27
39
 
28
40
  ## Lease-scoped Acceptance / Lint Guard (자동 삽입됨)
41
+ ${rootLine}- 위 PRD 본문의 모든 제약과 acceptance 기준은 이 appendix 이후에도 그대로 유효하다.
29
42
  - 이 shard 의 파일 lease:
30
43
  ${formatLeaseFiles(leaseFiles)}
31
44
  - Acceptance, lint, and format checks are scoped to files changed by this shard; if that set is unclear, use only the lease list above.
@@ -51,7 +64,10 @@ ${SENTINEL_END}
51
64
  규약:
52
65
  - 두 sentinel 마커는 각자 자기 줄에 단독으로 출력 (앞뒤 newline)
53
66
  - 마커 사이 본문은 단일 JSON object (배열/primitive 금지)
54
- - commits_made 비어 있어도 (no-op shard)
67
+ - status 값은 ok | failed | blocked 중 하나
68
+ - payload 출력 직전 \`git log -1 --format=%H\` 로 보고할 sha 가 실재하는지 검증하라
69
+ - 코드 변경이 기대되는 shard 에서 변경/커밋을 못 했으면 status:failed 와 함께 reason 필드로 사유를 보고하라 — 그 경우 빈 commits_made 에 status:ok 는 금지
70
+ - no-op shard 는 status:ok + 빈 commits_made 배열 허용
55
71
  - 마커 쌍은 stdout 에 정확히 한 번만 출력해야 함. 재emit 시 conductor 는 첫 BEGIN..END 한 쌍만 채택하며, 이후 stdout 은 무시한다.
56
72
  - ${SENTINEL_BEGIN} 만 출력하고 ${SENTINEL_END} 누락 시 conductor 가 truncation 으로 명확히 reject
57
73
  `;
@@ -60,14 +76,17 @@ ${SENTINEL_END}
60
76
  * Append the Completion Protocol section to a PRD prompt.
61
77
  *
62
78
  * @param {string|null|undefined} prdPrompt — original PRD body
63
- * @param {{ leaseFiles?: string[] }} [opts] — shard file lease for scoped acceptance
79
+ * @param {{ leaseFiles?: string[], worktreePath?: string }} [opts] — shard file lease and absolute worktree root for scoped acceptance
64
80
  * @returns {string} prompt with appendix
65
81
  */
66
82
  export function buildWorkerPrompt(prdPrompt, opts = {}) {
67
83
  const body = typeof prdPrompt === "string" ? prdPrompt : "";
68
84
  return (
69
85
  body +
70
- buildLeaseScopedAcceptanceAppendix({ leaseFiles: opts.leaseFiles }) +
86
+ buildLeaseScopedAcceptanceAppendix({
87
+ leaseFiles: opts.leaseFiles,
88
+ worktreePath: opts.worktreePath,
89
+ }) +
71
90
  COMPLETION_PROTOCOL_APPENDIX
72
91
  );
73
92
  }