feat(adaptation): enhance platform detection and cache path handling …#376
feat(adaptation): enhance platform detection and cache path handling …#376mikij wants to merge 2 commits intomksglu:nextfrom
Conversation
ccdd4b3 to
8dbb2c4
Compare
|
@mksglu this is test run result from main |
862e570 to
23fdc97
Compare
…for OpenCode/KiloCode
5406a20 to
c1a9ae4
Compare
…jection for OpenCode/KiloCode Extract tool-naming and routing-block logic into dedicated source modules (src/tool-naming.ts, src/routing-block.ts) and update OpenCode adapter to enable sessionStart and canInjectSessionContext capabilities. Implement experimental.chat.messages.transform hook to automatically inject context window protection routing block into user messages, replacing the previous static hook approach. Update hook files to import from build outputs.
|
Opened PR today. It is approved so hopefully it will be merged soon. |
|
It was merged a several minutes ago. But it will be part of some 7.2.34+ version of KiloCode (latest is 7.2.33 and it was released just before my commit was merged) |
|
Mickey — real work in here. Thank you. Let me give you a piece-by-piece take so you can see exactly what we're keeping and why. What you got right (adopting into the architectural PR):
What we're not adopting (and why — happy to discuss):
Why we're not merging this directly: your PR ran into the same root cause as #379 and #370 — v1.0.100's "Unified Persistent Memory" hardcoded You'll be Closing in favor of the unified fix. Thanks for digging into this. |
v1.0.100's "Unified Persistent Memory" feature was Claude-centric.
Auto-memory, prior session, and persist memory all hardcoded ~/.claude/,
breaking 13 of 14 platforms. Plus a worktree filename mismatch broke
Claude Code too on worktree sessions.
Architectural fix: adds 3 methods to HookAdapter interface so every
adapter declares its own conventions:
- getConfigDir() — ~/.claude, ~/.codex, ~/.qwen, ~/.gemini, etc.
- getInstructionFiles() — ['CLAUDE.md'], ['AGENTS.md'], ['QWEN.md'], etc.
- getMemoryDir() — ~/.claude/memory, ~/.codex/memories, etc.
BaseAdapter ships sensible defaults derived from sessionDirSegments;
only the 11 non-Claude adapters override (Claude inherits).
Wiring changes:
- searchAutoMemory() now accepts an adapter, dispatches via methods
- ctx_search timeline uses _detectedAdapter.getConfigDir()
- ctx_search timeline SessionDB filename now includes worktree suffix
(matches what session-snapshot/session-extract write to)
- extract.ts rule detection covers AGENTS.md, GEMINI.md, QWEN.md,
KIRO.md, copilot-instructions.md, context-mode.mdc, and any
*.md inside a memory/memories directory
Bonus fixes (from PR #376):
- OpenCode/KiloCode cache path: now packages/context-mode@latest/
layout (silently changed by upstream late 2024 — broke doctor/upgrade)
- OpenCode SessionStart equivalent via experimental.chat.messages.transform
— prior-session continuity now works on OpenCode/KiloCode
Tests added (8 new files, 65 new tests, all green):
- tests/adapters/base-adapter-memory.test.ts (4)
- tests/adapters/claude-code-memory.test.ts (3)
- tests/adapters/memory-conventions.test.ts (36)
- tests/core/auto-memory-adapter.test.ts (5)
- tests/core/cache-plugin-root.test.ts (2)
- tests/core/server-timeline-adapter.test.ts (3)
- tests/opencode-session-start.test.ts (2)
- tests/session/extract-rule-detection.test.ts (10)
Closes architectural root cause of #367 follow-ups.
Supersedes #379 (Codex), #370 (Qwen), #376 (OpenCode/KiloCode portions).
Co-Authored-By: Marcus Neufeldt <MarcusNeufeldt@users.noreply.github.com>
Co-Authored-By: btxbtxbtx <btxbtxbtx@users.noreply.github.com>
Co-Authored-By: Mickey Lazarevic <mikij@users.noreply.github.com>
|
@mksglu Have a question about this function: function getPlatform(): AdapterPlatformType {
const [ kiloEnv ] = PLATFORM_ENV_VARS.filter(p => p[0]==="kilo");
const [platform, vars] = kiloEnv;
for (const _var of vars){
if (process.env[_var]) {
return platform;
}
}
return "opencode";
}I think this is more robust way to check for KiloCode platform and as you did not mention this, I want to ask did you miss it or also did not want to include for some reason? |
checking |
…code-plugin DRY PR #376 follow-up. mikij flagged that src/opencode-plugin.ts hardcoded a KILO_PID-only check that violated DRY against PLATFORM_ENV_VARS. Audit of the canonical list itself surfaced the broader problem: half of the entries were unverified placeholders, 4 platforms (antigravity, zed, pi, openclaw) were entirely missing or incorrectly listed, and the plugin paradigm's fallback to "opencode" was blind (didn't actively check OPENCODE env vars). What ships - Re-audited every entry against the platform's own runtime source code: - kilo: dropped bare `KILO` (Kilo-Org/kilocode never sets it; only KILO_PID is set unconditionally at packages/opencode/src/index.ts:140). - jetbrains-copilot: dropped IDEA_HOME and JETBRAINS_CLIENT_ID (no source-line evidence in any JetBrains repo). Kept IDEA_INITIAL_DIRECTORY. - qwen-code: dropped QWEN_SESSION_ID (0 hits in QwenLM/qwen-code). - openclaw: removed entirely from env-var tier (runtime never sets OPENCLAW_HOME/OPENCLAW_CLI). Detection falls through to ~/.openclaw/ config-dir tier, which already worked. - Added 3 new platforms with verified env vars: - antigravity: ANTIGRAVITY_CLI_ALIAS — verified in Google's google-gemini/gemini-cli packages/core/src/ide/detect-ide.ts (canonical IDE detection map). Listed before vscode-copilot since Antigravity is an Electron/VSCode fork. - zed: ZED_SESSION_ID + ZED_TERM — verified in zed-industries/zed crates/terminal/src/terminal.rs `insert_zed_terminal_env()` and cross-confirmed by Google's gemini-cli detect-ide.ts. - pi: PI_PROJECT_DIR — confirmed by our own consumers at src/pi-extension.ts:154 and src/server.ts:153. - Reordered fork pairs so collision detection works: - kilo before opencode (Kilo sets OPENCODE=1 because it's an OpenCode fork). - cursor + antigravity before vscode-copilot (both inherit VSCODE_PID). - src/opencode-plugin.ts getPlatform() rewritten to iterate PLATFORM_ENV_VARS instead of hardcoding KILO_PID. Filters to kilo+opencode so a stray CLAUDE_PROJECT_DIR can't leak into the plugin's platform decision. Symmetric: actively checks BOTH platform's env vars instead of blind fallback. Per-line JSDoc credits PR #376 (mikij). Tests - tests/adapters/detect.test.ts: removed 5 broken assertions for unverified env vars; added 4 assertions for new platforms (antigravity, zed×2, pi) and a fork-collision test (KILO_PID + OPENCODE both set → kilo wins). - tests/adapters/detect-config-dir.test.ts: rewrote priority chain from OPENCLAW/CODEX assertions to fork-collision assertions (KILO/OPENCODE, CURSOR/VSCODE, ANTIGRAVITY/VSCODE, CURSOR/CODEX). Verification - 451/451 adapter + plugin tests pass on next worktree. - Typecheck clean. Co-Authored-By: Mickey Lazarevic <noreply@github.com>
|
@mikij — you were right. Landed the full fix on `next` as commit 4e75d11 with you credited as Co-Author. What ended up in the fixYour point about `getPlatform()` ( Audited every entry against the platform's own runtime source code. Highlights: Removed / corrected (no source-line evidence):
Added (with verified source citations):
Reordered fork pairs so collision detection works:
function getPlatform(): AdapterPlatformType {
for (const [platform, vars] of PLATFORM_ENV_VARS) {
if (platform !== "kilo" && platform !== "opencode") continue;
if (vars.some((v) => process.env[v])) {
return platform as AdapterPlatformType;
}
}
return "opencode";
}Tests
451/451 adapter + plugin tests pass on Thanks again for surfacing this — both the immediate bug and the broader audit it triggered. Happy to credit you for any follow-up contributions. |


…for OpenCode/KiloCode
What / Why / How
context-mode upgrade local) which copies current git branch instead of cloning latest GH published version.This fails in doctor:
Addition:
Affected platforms
Test plan
Checklist
npm testpassesnpm run typecheckpassesnextbranch (unless hotfix)Cross-platform notes
Our CI runs on Ubuntu, macOS, and Windows.
path.join()/path.resolve(), never hardcode/separatorsreadFileSync(0)breaks on Windowsos.tmpdir(), never hardcode/tmp