@cocorograph/hub-agent 0.7.8 → 0.7.9
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
|
@@ -23,8 +23,15 @@
|
|
|
23
23
|
* で別途 hydrate 済みのため、tail は新規分だけでよい (二重 push は frontend が uuid で排除)。
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
import { readFile } from "node:fs/promises"
|
|
27
|
+
|
|
26
28
|
import { watchSessionFile } from "./claude-history-watch.mjs"
|
|
27
29
|
import { jsonlPath } from "./claude-history.mjs"
|
|
30
|
+
import {
|
|
31
|
+
MASK_ENABLED,
|
|
32
|
+
collectToolUseNames,
|
|
33
|
+
createEventMasker,
|
|
34
|
+
} from "./tool-result-mask.mjs"
|
|
28
35
|
|
|
29
36
|
/** watcher 鮮度 (ms)。ブラウザのハートビート間隔 (5s) の 3 倍を既定とする。 */
|
|
30
37
|
const WATCHER_TTL_MS = Number(process.env.COCKPIT_JSONL_WATCH_TTL_MS) || 15_000
|
|
@@ -84,6 +91,14 @@ export class JsonlLiveWatchers {
|
|
|
84
91
|
// 起動処理中に別経路で登録済みになっていないか再チェック。
|
|
85
92
|
if (this._entries.has(session_id)) return
|
|
86
93
|
const filePath = jsonlPath({ cwd, session_id, projectsRoot })
|
|
94
|
+
// マスク (2026-06-23): TUI ライブ閲覧で逐次 push する tool_result の秘匿情報 / 非公開
|
|
95
|
+
// スキルプロンプト本文を伏せる。この経路は SDK チャットブリッジ (_emit) とは別系統で、
|
|
96
|
+
// フックを通さず jsonl を直接 tail するため、ここで独自にマスクしないと素通しになる。
|
|
97
|
+
// tail は fromEnd=true で監視開始後の追記のみを拾うので、開始前に書かれた tool_use の
|
|
98
|
+
// id→name を既存 jsonl から事前シードし、スキル tool_result の判定取りこぼしを防ぐ。
|
|
99
|
+
const masker = MASK_ENABLED
|
|
100
|
+
? createEventMasker(await this._seedToolNames(filePath))
|
|
101
|
+
: null
|
|
87
102
|
const watcher = watchSessionFile({
|
|
88
103
|
filePath,
|
|
89
104
|
fromEnd: true,
|
|
@@ -94,7 +109,7 @@ export class JsonlLiveWatchers {
|
|
|
94
109
|
type: "claude.jsonl.event",
|
|
95
110
|
session_id,
|
|
96
111
|
cwd,
|
|
97
|
-
event,
|
|
112
|
+
event: masker ? masker(event) : event,
|
|
98
113
|
})
|
|
99
114
|
} catch (err) {
|
|
100
115
|
this.logger?.warn(
|
|
@@ -136,6 +151,30 @@ export class JsonlLiveWatchers {
|
|
|
136
151
|
}
|
|
137
152
|
}
|
|
138
153
|
|
|
154
|
+
/**
|
|
155
|
+
* 既存 jsonl を 1 度だけ読み、tool_use_id→name を集めた Map を返す (マスカーのシード用)。
|
|
156
|
+
* 読めない / 未存在なら空 Map。watcher 起動の冷経路で 1 回だけ走るので全文読みでよい。
|
|
157
|
+
* @param {string} filePath
|
|
158
|
+
* @returns {Promise<Map<string,string>>}
|
|
159
|
+
*/
|
|
160
|
+
async _seedToolNames(filePath) {
|
|
161
|
+
const seed = new Map()
|
|
162
|
+
try {
|
|
163
|
+
const text = await readFile(filePath, "utf-8")
|
|
164
|
+
for (const line of text.split("\n")) {
|
|
165
|
+
if (!line || !line.includes('"tool_use"')) continue
|
|
166
|
+
try {
|
|
167
|
+
collectToolUseNames(JSON.parse(line), seed)
|
|
168
|
+
} catch {
|
|
169
|
+
/* ignore broken line */
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch {
|
|
173
|
+
/* ファイル未存在等: シードなしで続行 */
|
|
174
|
+
}
|
|
175
|
+
return seed
|
|
176
|
+
}
|
|
177
|
+
|
|
139
178
|
async _resolveProjectsRoot() {
|
|
140
179
|
try {
|
|
141
180
|
const r = this.getProjectsRoot?.()
|
package/src/tool-result-mask.mjs
CHANGED
|
@@ -229,10 +229,13 @@ export function collectToolUseNames(obj, toolNames) {
|
|
|
229
229
|
* 別イベントで届くため、id→name を内部 Map に蓄積しながら 1 イベントずつマスクする。
|
|
230
230
|
* 1 セッション 1 インスタンスで使う (stream と watch は同一セッション内で直列化される)。
|
|
231
231
|
*
|
|
232
|
+
* @param {Map<string,string>} [initialToolNames] tool_use_id→name の事前シード。jsonl を
|
|
233
|
+
* 途中から tail する経路 (JsonlLiveWatchers) で、tail 開始前に書かれた tool_use の名前を
|
|
234
|
+
* 先に流し込み、スキル tool_result の判定を取りこぼさないために使う。
|
|
232
235
|
* @returns {(event: object) => object} マスク済みイベント (変化なしなら同一参照)
|
|
233
236
|
*/
|
|
234
|
-
export function createEventMasker() {
|
|
235
|
-
const toolNames = new Map()
|
|
237
|
+
export function createEventMasker(initialToolNames) {
|
|
238
|
+
const toolNames = initialToolNames instanceof Map ? initialToolNames : new Map()
|
|
236
239
|
return function maskEvent(event) {
|
|
237
240
|
if (!MASK_ENABLED) return event
|
|
238
241
|
return maskMessageObject(event, toolNames)
|