@cocorograph/hub-agent 0.6.30 → 0.6.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocorograph/hub-agent",
3
- "version": "0.6.30",
3
+ "version": "0.6.32",
4
4
  "description": "Hub Hosted Cockpit のローカル常駐 agent。Hub と outbound WSS で接続し、ローカルの tmux/pty を中継する。",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -13,7 +13,7 @@
13
13
  * - 上限 MAX_HISTORY_LINES (デフォルト 500) で末尾から切る
14
14
  * - ファイル不在 (新規セッション) なら空配列を返す (エラーにしない)
15
15
  */
16
- import { readFile, readdir, stat } from "node:fs/promises"
16
+ import { open, readFile, readdir, stat } from "node:fs/promises"
17
17
  import os from "node:os"
18
18
  import path from "node:path"
19
19
 
@@ -150,13 +150,22 @@ export async function fetchSessionHistory({ cwd, session_id, maxLines, projectsR
150
150
  * @returns {Promise<string>} 先頭 user メッセージの冒頭 (最大 80 文字)、無ければ ""
151
151
  */
152
152
  async function extractPreview(filePath) {
153
+ // P-perf: ファイル全体を readFile してから 64KB に slice すると、肥大化した jsonl で
154
+ // listSessions がセッション数分フル読み込みして重くなる。fd で先頭 64KB だけ読む。
155
+ // preview (最初の user メッセージ冒頭 80 文字) は必ず先頭付近にあるので十分。
156
+ // 64KB 境界でマルチバイト文字 / 行が切れても、末尾の壊れた行は JSON.parse 失敗で
157
+ // skip されるため実害はない。
153
158
  let text
159
+ let handle
154
160
  try {
155
- const buf = await readFile(filePath, "utf-8")
156
- // 先頭 64KB だけ見る (preview には十分)
157
- text = buf.length > 65536 ? buf.slice(0, 65536) : buf
161
+ handle = await open(filePath, "r")
162
+ const buf = Buffer.allocUnsafe(65536)
163
+ const { bytesRead } = await handle.read(buf, 0, buf.length, 0)
164
+ text = buf.toString("utf-8", 0, bytesRead)
158
165
  } catch {
159
166
  return ""
167
+ } finally {
168
+ await handle?.close()
160
169
  }
161
170
  for (const line of text.split("\n")) {
162
171
  if (!line) continue