Skip to content

Commit 41f6579

Browse files
authored
fix(detect): update kilo platform detection to check KILO=1 and KILO_PID (#424)
* fix(detect): update kilo platform detection to check KILO=1 and KILO_PID Previously, kilo detection only checked for KILO_PID environment variable. Updated to check for both KILO=1 and KILO_PID as kilo now sets both environment variables. Also updated the test to reflect the new detection logic. * Revert "fix(stats): show 15 persistent-memory categories (was 2) so users SEE the data" This reverts commit 07aff25.
1 parent 07aff25 commit 41f6579

4 files changed

Lines changed: 13 additions & 36 deletions

File tree

src/adapters/detect.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ export const PLATFORM_ENV_VARS = [
4343
// 800+ hits in major OSS detection libs (Vercel Next.js, Bun, Google
4444
// gemini-cli, Nx, CrewAI).
4545
["cursor", ["CURSOR_TRACE_ID", "CURSOR_CLI"]],
46-
// kilo (OpenCode fork) — Kilo-Org/kilocode packages/opencode/src/index.ts:140
47-
// sets `process.env.KILO_PID = String(process.pid)`. Bare KILO is NEVER set
48-
// (verified). Kilo also sets OPENCODE=1 (fork) — listed before opencode.
49-
["kilo", ["KILO_PID"]],
46+
// kilo (OpenCode fork) — Kilo-Org/kilocode packages/opencode/src/index.ts:138 + 139
47+
// sets `process.env.KILO = 1` + `process.env.KILO_PID = String(process.pid)`.
48+
["kilo", ["KILO", "KILO_PID"]],
5049
// opencode — sst/opencode packages/opencode/src/index.ts:108-109 sets
5150
// OPENCODE=1 + OPENCODE_PID=<pid> on every CLI invocation.
5251
["opencode", ["OPENCODE", "OPENCODE_PID"]],

src/session/analytics.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,7 @@ function renderProjectMemory(
702702
) {
703703
return [];
704704
}
705-
// Show enough categories that the user can SEE what's actually being
706-
// tracked, instead of "Files tracked + Project rules · 21 more" hiding
707-
// the storytelling. 15 covers the 14-category-and-below typical case
708-
// fully and still keeps the terminal output under one screen height.
709-
const topN = opts?.topN ?? 15;
705+
const topN = opts?.topN ?? 2;
710706
const out: string[] = [];
711707
out.push("");
712708
out.push("Persistent memory ✓ preserved across compact, restart & upgrade");

tests/adapters/detect.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,20 @@ describe("detectPlatform", () => {
100100
});
101101

102102
// ── Kilo ────────────────────────────────────────────────
103-
// Kilo-Org/kilocode packages/opencode/src/index.ts:140 sets KILO_PID
104-
// unconditionally. Bare `KILO` is NEVER set (verified via upstream source
105-
// audit, May 2026). Kilo also sets OPENCODE=1 because it's an OpenCode fork
106-
// — `kilo` MUST precede `opencode` in PLATFORM_ENV_VARS so KILO_PID wins.
107-
108-
it("returns kilo when KILO_PID is set", () => {
109-
process.env.KILO_PID = "12345";
103+
104+
it("returns opencode when KILO=1 is set", () => {
105+
process.env.KILO = "1";
110106
const signal = detectPlatform();
111107
expect(signal.platform).toBe("kilo");
112108
expect(signal.confidence).toBe("high");
113109
});
114110

115-
it("kilo wins when both KILO_PID and OPENCODE are set (fork-collision)", () => {
111+
112+
it("returns kilo when KILO_PID is set", () => {
116113
process.env.KILO_PID = "12345";
117-
process.env.OPENCODE = "1";
118114
const signal = detectPlatform();
119115
expect(signal.platform).toBe("kilo");
116+
expect(signal.confidence).toBe("high");
120117
});
121118

122119
// ── OpenClaw ───────────────────────────────────────────

tests/session/stats-output-format.test.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,15 @@ describe("formatReport — Bugs #5/#6/#7/#8", () => {
8585
expect(text).not.toMatch(/\b\d+\.\dx\b(?!\s+longer)/);
8686
});
8787

88-
test("computes the real overflow count (not hardcoded)", () => {
89-
// Default topN raised to 15 (was 2) so users actually SEE what's being
90-
// tracked instead of "Files tracked + Project rules · 21 more" hiding
91-
// the storytelling. baseReport has 8 categories ≤ topN → no overflow line.
88+
test("computes the real overflow count (not hardcoded '9 more')", () => {
9289
const text = formatReport(baseReport(), "1.0.103", null, {
9390
lifetime: emptyLifetime(),
9491
});
95-
expect(text).not.toMatch(/more categories/);
96-
// And still must not regress to the old hardcoded number.
92+
// baseReport has 8 categories; we render 2 → 6 more.
93+
expect(text).toMatch(/6 more categories/);
9794
expect(text).not.toMatch(/9 more categories/);
9895
});
9996

100-
test("renders 'N more categories' overflow only when total > topN", () => {
101-
// Build a fixture with 20 categories so topN=15 → 5 overflow.
102-
const r = baseReport();
103-
const cats = Array.from({ length: 20 }, (_, i) => ({
104-
label: `cat${i}`,
105-
count: 100 - i,
106-
}));
107-
r.projectMemory = { ...r.projectMemory, by_category: cats } as typeof r.projectMemory;
108-
const text = formatReport(r, "1.0.103", null, { lifetime: emptyLifetime() });
109-
expect(text).toMatch(/5 more categories/);
110-
});
111-
11297
test("ends with a 'Bottom line' / business-value footer", () => {
11398
const text = formatReport(baseReport(), "1.0.103", null, {
11499
lifetime: { ...emptyLifetime(), totalEvents: 160, totalSessions: 40 },

0 commit comments

Comments
 (0)