@triflux/remote 10.35.2 → 10.35.3
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/collect.mjs +2 -1
- package/cto/lake-root.mjs +44 -0
- package/cto/status.mjs +3 -1
- package/hub/team/cto-auto-collect.mjs +17 -7
- package/package.json +1 -1
package/cto/collect.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import { basename, dirname, join, relative } from "node:path";
|
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
18
18
|
|
|
19
19
|
import { renderBrief } from "./brief.mjs";
|
|
20
|
+
import { resolveLakeRootDir } from "./lake-root.mjs";
|
|
20
21
|
|
|
21
22
|
const SCHEMA_VERSION = "cto-lake.v1";
|
|
22
23
|
const SOURCE_REGISTRY = [
|
|
@@ -785,7 +786,7 @@ function hasFlag(args, flag) {
|
|
|
785
786
|
}
|
|
786
787
|
|
|
787
788
|
export async function runCollect(args = [], opts = {}) {
|
|
788
|
-
const rootDir = opts.rootDir || process.cwd();
|
|
789
|
+
const rootDir = opts.rootDir || resolveLakeRootDir(process.cwd());
|
|
789
790
|
const lakeRoot = opts.lakeRoot || join(rootDir, ".triflux", "lake");
|
|
790
791
|
const stdout = opts.stdout || process.stdout;
|
|
791
792
|
const stderr = opts.stderr || process.stderr;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// cto/lake-root.mjs - resolve the git repo toplevel for the CTO lake.
|
|
2
|
+
//
|
|
3
|
+
// CTO lake (.triflux/lake/current.json) 는 repo 루트에 하나만 둔다. 그런데
|
|
4
|
+
// runStatus/runCollect/runDashboard 는 process.cwd() 를 기본 rootDir 로 쓰므로,
|
|
5
|
+
// repo 루트가 아닌 하위 폴더(예: packages/triflux)에서 `tfx cto` 를 부르면 lake
|
|
6
|
+
// 를 못 찾아 "run tfx cto collect" 가 반복되고, collect 는 엉뚱한 하위 폴더에
|
|
7
|
+
// 새 .triflux/lake 를 만든다. cwd 에서 `.git` 마커를 위로 탐색해 toplevel 로
|
|
8
|
+
// 올려 이 불일치를 없앤다.
|
|
9
|
+
//
|
|
10
|
+
// git worktree 는 자체 `.git` 파일을 가지므로 worktree 루트에서 멈춘다 — lake
|
|
11
|
+
// 격리(워크트리별 collect)가 그대로 유지된다. `.git` 을 못 찾으면 cwd 를 그대로
|
|
12
|
+
// 반환해 기존 동작을 보존한다.
|
|
13
|
+
|
|
14
|
+
import { existsSync as defaultExistsSync } from "node:fs";
|
|
15
|
+
import { dirname, join, parse } from "node:path";
|
|
16
|
+
|
|
17
|
+
const MAX_DEPTH = 64;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* cwd 에서 가장 가까운 git toplevel(`.git` 디렉토리 또는 파일이 있는 폴더)을
|
|
21
|
+
* 찾아 반환한다. 못 찾으면 cwd 를 그대로 돌려준다(기존 동작 보존).
|
|
22
|
+
*
|
|
23
|
+
* @param {string} cwd 시작 디렉토리(보통 process.cwd())
|
|
24
|
+
* @param {object} [opts]
|
|
25
|
+
* @param {(path: string) => boolean} [opts.existsSync] 테스트용 주입 seam
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
export function resolveLakeRootDir(cwd, opts = {}) {
|
|
29
|
+
const exists = opts?.existsSync || defaultExistsSync;
|
|
30
|
+
// 비문자열(객체/숫자 등 truthy 포함) 또는 빈 문자열이면 항상 "" 를 반환해
|
|
31
|
+
// @returns {string} 계약을 지킨다 — truthy 비문자열을 그대로 누설하지 않는다.
|
|
32
|
+
if (typeof cwd !== "string" || !cwd) return "";
|
|
33
|
+
|
|
34
|
+
let dir = cwd;
|
|
35
|
+
const { root } = parse(dir);
|
|
36
|
+
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
37
|
+
if (exists(join(dir, ".git"))) return dir;
|
|
38
|
+
if (dir === root) break;
|
|
39
|
+
const parent = dirname(dir);
|
|
40
|
+
if (parent === dir) break;
|
|
41
|
+
dir = parent;
|
|
42
|
+
}
|
|
43
|
+
return cwd;
|
|
44
|
+
}
|
package/cto/status.mjs
CHANGED
|
@@ -2,6 +2,8 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
|
|
5
|
+
import { resolveLakeRootDir } from "./lake-root.mjs";
|
|
6
|
+
|
|
5
7
|
const SCHEMA_VERSION = "cto-lake.v1";
|
|
6
8
|
const SYNAPSE_TIMEOUT_MS = 1500;
|
|
7
9
|
|
|
@@ -304,7 +306,7 @@ function renderHumanStatus(status) {
|
|
|
304
306
|
}
|
|
305
307
|
|
|
306
308
|
export async function runStatus(args = [], opts = {}) {
|
|
307
|
-
const rootDir = opts.rootDir || process.cwd();
|
|
309
|
+
const rootDir = opts.rootDir || resolveLakeRootDir(process.cwd());
|
|
308
310
|
const lakeRoot = opts.lakeRoot || join(rootDir, ".triflux", "lake");
|
|
309
311
|
const stdout = opts.stdout || process.stdout;
|
|
310
312
|
const jsonOut = opts.json === true || hasFlag(args, "--json");
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
|
+
import { resolveLakeRootDir } from "../../cto/lake-root.mjs";
|
|
5
|
+
|
|
4
6
|
const DEFAULT_DEBOUNCE_MS = 120_000;
|
|
5
7
|
const OFF_VALUES = new Set(["0", "false", "off", "no"]);
|
|
6
8
|
|
|
@@ -45,7 +47,7 @@ export function createCtoAutoCollector(opts = {}) {
|
|
|
45
47
|
const cwd = typeof session?.cwd === "string" ? session.cwd : "";
|
|
46
48
|
const worktree =
|
|
47
49
|
typeof session?.worktreePath === "string" ? session.worktreePath : "";
|
|
48
|
-
const projectRoot = worktree || cwd;
|
|
50
|
+
const projectRoot = resolveLakeRootDir(worktree || cwd);
|
|
49
51
|
if (!projectRoot)
|
|
50
52
|
return { triggered: false, reason: "missing-project-root" };
|
|
51
53
|
|
|
@@ -61,11 +63,19 @@ export function createCtoAutoCollector(opts = {}) {
|
|
|
61
63
|
{ sessionId, err: String(error?.message || error) },
|
|
62
64
|
"cto.auto_collect.query_failed",
|
|
63
65
|
);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return { triggered: false, reason: "no-peers" };
|
|
66
|
+
// peer 조회 실패는 collect 를 막지 않는다 — peer 정보는 이제 라벨 용도뿐이라
|
|
67
|
+
// registry 일시 장애에도 solo 로 진행해 collect 회복력을 유지한다.
|
|
68
|
+
peers = [];
|
|
68
69
|
}
|
|
70
|
+
// 단일 세션(peer 0개)도 허용한다 — 사용자 선택. peer 유무와 무관하게
|
|
71
|
+
// 아래 debounce + fresh-lake 게이트가 collect 빈도를 제어한다.
|
|
72
|
+
//
|
|
73
|
+
// 주의: peerCount 는 best-effort 라벨이다. querySessions 는 raw
|
|
74
|
+
// cwd/worktreePath 로 매칭하지만 projectRoot 는 resolved git toplevel 이라,
|
|
75
|
+
// 같은 repo 의 다른 하위 폴더 세션은 peer 로 안 잡혀 triggered-solo 로 보고될
|
|
76
|
+
// 수 있다. 즉 라벨은 repo-scoped 가 아니라 exact-cwd-scoped 다 — 향후 peer
|
|
77
|
+
// 기반 로직을 이 라벨 위에 다시 올릴 때 주의한다.
|
|
78
|
+
const peerCount = Array.isArray(peers) ? peers.length : 0;
|
|
69
79
|
|
|
70
80
|
const currentTime = now();
|
|
71
81
|
const last = lastCollectMs.get(projectRoot) || 0;
|
|
@@ -92,9 +102,9 @@ export function createCtoAutoCollector(opts = {}) {
|
|
|
92
102
|
inFlight.add(promise);
|
|
93
103
|
return {
|
|
94
104
|
triggered: true,
|
|
95
|
-
reason: "triggered",
|
|
105
|
+
reason: peerCount > 0 ? "triggered" : "triggered-solo",
|
|
96
106
|
projectRoot,
|
|
97
|
-
peerCount
|
|
107
|
+
peerCount,
|
|
98
108
|
};
|
|
99
109
|
}
|
|
100
110
|
|