claude-cache-keepalive 0.1.6 → 0.1.7

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/README.md CHANGED
@@ -23,8 +23,8 @@ This puts a `cwarm` command on your PATH (npm creates both the Unix and Windows
23
23
  ## Usage
24
24
 
25
25
  ```sh
26
- cwarm # = claude --continue, inside the keepalive host
27
- cwarm new # any claude args are passed straight through
26
+ cwarm # = plain `claude`, inside the keepalive host (no implicit --continue)
27
+ cwarm --continue # resume your last session; any claude args pass straight through
28
28
  cwarm resume
29
29
  cwarm -p "..."
30
30
  cwarm --version # (passed through → prints claude's version)
@@ -101,13 +101,46 @@ Environment variables (mostly for testing / advanced use):
101
101
  > ⚠️ **誠實說明**:保溫=閒置時送一則小訊息(`hi`),會消耗你的方案用量、並在對話留下 `hi` 紀錄。只在長時間閒置後才觸發(1h cache 約 58 分、5m cache 約 4 分)且有冷卻,屬保守設計、明確 opt‑in。不接受這個取捨就別用。
102
102
 
103
103
  - **安裝**:`npm install -g claude-cache-keepalive`
104
- - **使用**:`cwarm`(=`claude --continue` 跑在保溫 host 裡;其餘參數原樣轉給 claude)
104
+ - **使用**:`cwarm`(=乾淨的 `claude` 跑在保溫 host 裡,不再隱含 `--continue`;要接續上次打 `cwarm --continue`,其餘參數原樣轉給 claude)
105
105
  - **暫停**:`touch ~/.claude/cwarm.disabled`;**紀錄**:`~/.claude/cwarm-keepalive.log`
106
106
  - **選配 statusline**(顯示 `♻️ cache 58m12s` 倒數;會先備份、包裝既有 statusline、可一鍵還原):`cwarm setup` / `cwarm setup --remove`
107
107
  - **限制**:不能 detach(關視窗=結束,但縮小/背景照常保溫)。
108
108
 
109
+ ### 運作原理
110
+
111
+ - **PTY host**:`cwarm` 把 `claude` spawn 在一個它自己擁有的 pseudo-terminal 裡,透明地把你的鍵盤 ↔ claude ↔ 畫面(含視窗 resize)接起來。這跟 tmux/expect/VS Code 終端的做法相同,也是唯一穩健、能把輸入注入終端程式的方式。
112
+ - **閒置偵測**:閒置=距你上次**訊息**多久,量自 `~/.claude/projects/` 底下最新的 transcript 檔。這才是決定 cache 年齡的訊號——捲動、用方向鍵讀、打到一半沒送出,都是終端輸入但不會刷新 cache,所以不該算成活動。(早期版本計時鍵盤輸入,會讓你在閱讀時 cache 冷掉。)
113
+ - **TTL 感知(實測,非猜測)**:cache TTL 直接讀自 transcript 的 `message.usage.cache_creation`,不從訂閱方案推斷——最近有寫 `ephemeral_1h_input_tokens` → 1h cache(閒置約 58 分才注入、冷卻 1h);只有 `ephemeral_5m_input_tokens`(或還沒證據)→ 5m cache(保守,約 4 分注入、冷卻 5m)。這能撐過 client 版本、環境變數、伺服器旗標的變動(例如 Pro 帳號也可能拿到 1h cache)。
114
+ - **提示安全注入**:keepalive 只在 PTY **靜止一小段時間後**才觸發(`CWARM_QUIET_MS`,預設 2.5 秒)。必答提示(工具權限、`AskUserQuestion`、計畫批准)的 spinner 會一直動,忙著跑工具時也持續輸出,兩者都「不安靜」,所以 keepalive 不會送進去(不會誤選選單預設項、也不會打斷長工具執行)。而且注入時會**先送 `Esc`** 退回輸入框,那個 Enter 永遠落不到提示上。(提示真的卡住時 cache 本來就無法保溫,等你回答後會自動恢復。)
115
+ - **與焦點/縮小無關**:注入是行程內部的 `pty.write`,跟視窗狀態無關。只有關閉視窗(結束 host 行程)才會停。
116
+
117
+ ### 設定
118
+
119
+ 環境變數(多為測試/進階用途):
120
+
121
+ | 變數 | 意義 |
122
+ |-----|------|
123
+ | `CWARM_MSG` | keepalive 訊息(預設 `hi`) |
124
+ | `CWARM_TICK_MS` | 檢查間隔(預設 `20000`) |
125
+ | `CWARM_QUIET_MS` | 畫面需靜止多久才注入(預設 `2500`) |
126
+ | `CWARM_ESC_DELAY_MS` | `Esc` 與訊息之間的間隔(預設 `250`) |
127
+ | `CWARM_THRESHOLD_S` | 覆寫閒置門檻(秒) |
128
+ | `CWARM_TTL_S` | 覆寫冷卻(秒) |
129
+ | `CWARM_CLAUDE` | `claude` 執行檔路徑(否則用 `which`/`where` 自動偵測) |
130
+ | `CLAUDE_CONFIG_DIR` | Claude 設定目錄(預設 `~/.claude`) |
131
+
132
+ ### 平台支援
133
+
134
+ - **Windows**(Git Bash/PowerShell/cmd/Windows Terminal):已驗證,含非 ASCII(中日韓)輸入。
135
+ - **Linux arm64/aarch64**:已在 Raspberry Pi 4(Debian、Node 22)驗證——全域安裝(node-pty 乾淨編譯)、`cwarm` 啟動、即時 keepalive 注入都確認可用。x64 預期相同。
136
+ - **macOS**:同樣的跨平台機制(node-pty + 你 shell 裡的 `claude`);預期可用,尚未實測,歡迎回報。
137
+
109
138
  ## Changelog
110
139
 
140
+ ### 0.1.7
141
+ - **Change:** `cwarm` no longer implicitly adds `--continue`. It is now a fully transparent pass‑through — `cwarm [args]` is exactly `claude [args]`, so bare `cwarm` starts a clean session. To resume your last session, run `cwarm --continue`. (Previously bare `cwarm` auto‑resumed.)
142
+ - **變更:** `cwarm` 不再隱含補上 `--continue`,改為完全透傳——`cwarm [參數]` 就等於 `claude [參數]`,所以單獨打 `cwarm` 會開全新 session。要接續上次請打 `cwarm --continue`。(先前單獨打 `cwarm` 會自動接續。)
143
+
111
144
  ### 0.1.6
112
145
  - **Docs:** every changelog entry now carries a Traditional Chinese version alongside the English. No code change.
113
146
  - **文件:** 每條 changelog 現在都在英文旁附上繁體中文。無程式碼變動。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-cache-keepalive",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Keep Claude Code's prompt cache warm while idle, by running claude inside a PTY host and injecting a tiny keepalive when you step away. Cross-platform, no tmux required.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.mjs CHANGED
@@ -12,14 +12,16 @@ if (first === 'setup') {
12
12
  printHelp();
13
13
  process.exit(0);
14
14
  } else {
15
- startHost({ args: argv }); // 無參數時 host 內部預設 --continue
15
+ startHost({ args: argv }); // 完全透傳給 claude;不帶參數就是乾淨的 claude(不再隱含 --continue
16
16
  }
17
17
 
18
18
  function printHelp() {
19
19
  process.stdout.write(`cwarm — keep Claude Code's prompt cache warm while idle.
20
20
 
21
21
  Usage:
22
- cwarm [claude args...] Launch claude (default: --continue) inside the keepalive host.
22
+ cwarm [claude args...] Launch claude inside the keepalive host. Args pass straight
23
+ through, so \`cwarm\` === plain \`claude\`; use \`cwarm --continue\`
24
+ to resume your last session.
23
25
  cwarm setup Optionally install the cache-countdown statusline (opt-in).
24
26
  cwarm setup --remove Remove the statusline this tool installed.
25
27
  cwarm help Show this help.
package/src/host.mjs CHANGED
@@ -35,7 +35,9 @@ export function startHost(opts = {}) {
35
35
  const LOG = path.join(claudeDir, 'cwarm-keepalive.log');
36
36
  const DISABLE = path.join(claudeDir, 'cwarm.disabled');
37
37
 
38
- const args = opts.args && opts.args.length ? opts.args : ['--continue'];
38
+ // 完全透傳:cwarm [args] === claude [args]。不帶參數就是乾淨的 `claude`(全新 session);
39
+ // 要接續上次請自己打 `cwarm --continue`。不再隱含補 --continue。
40
+ const args = opts.args || [];
39
41
  const { file, args: spawnArgs } = spawnSpec(resolveClaude(), args);
40
42
 
41
43
  const ptyProc = pty.spawn(file, spawnArgs, {