pikiclaw 0.3.52 → 0.3.53
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.
|
@@ -131,6 +131,11 @@ process.stdin.on("end", () => {
|
|
|
131
131
|
tool_name: typeof payload.tool_name === "string" ? payload.tool_name : null,
|
|
132
132
|
tool_input: payload.tool_input || null,
|
|
133
133
|
tool_response: payload.tool_response || null,
|
|
134
|
+
// Claude Code tags sub-agent tool calls with agent_id so the parent can
|
|
135
|
+
// tell them apart from main-thread calls. Forwarding it lets the driver
|
|
136
|
+
// route the hook to the right sub-agent card instead of the parent's
|
|
137
|
+
// 执行 list.
|
|
138
|
+
agent_id: typeof payload.agent_id === "string" ? payload.agent_id : null,
|
|
134
139
|
}) + "\\n";
|
|
135
140
|
try { fs.appendFileSync(toolEventsFile, line); } catch (_) {}
|
|
136
141
|
process.stdout.write(JSON.stringify({ continue: true }) + "\\n");
|
|
@@ -250,6 +255,26 @@ function applyHookToolEvent(ev, s) {
|
|
|
250
255
|
const toolName = String(ev?.tool_name || '').trim();
|
|
251
256
|
if (!toolName || !toolUseId)
|
|
252
257
|
return false;
|
|
258
|
+
// Sub-agent tool calls fire the parent's Pre/PostToolUse hooks too (one
|
|
259
|
+
// hook pipeline per CLI process). Claude Code tags those payloads with
|
|
260
|
+
// `agent_id`; route them to the matching sub-agent's tool list instead of
|
|
261
|
+
// appending to the parent's recentActivity. Without this every Task spawn
|
|
262
|
+
// floods the parent's 执行 card with the children's tool stream while the
|
|
263
|
+
// sub-agent cards sit empty until the sidecar JSONL flushes at Stop.
|
|
264
|
+
const subAgentId = typeof ev?.agent_id === 'string' && ev.agent_id ? ev.agent_id : '';
|
|
265
|
+
if (subAgentId) {
|
|
266
|
+
if (ev.event === 'PreToolUse') {
|
|
267
|
+
const parentToolUseId = s.subAgentIdToParent?.get(subAgentId);
|
|
268
|
+
const sub = parentToolUseId ? s.subAgents?.get(parentToolUseId) : undefined;
|
|
269
|
+
if (sub && !sub.tools.some((t) => t.id === toolUseId)) {
|
|
270
|
+
const summary = toolName === 'TodoWrite'
|
|
271
|
+
? 'Update plan'
|
|
272
|
+
: summarizeClaudeToolUse(toolName, ev.tool_input || {});
|
|
273
|
+
sub.tools.push({ id: toolUseId, name: toolName, summary });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
253
278
|
if (ev.event === 'PreToolUse') {
|
|
254
279
|
if (s.seenClaudeToolIds.has(toolUseId))
|
|
255
280
|
return false;
|
|
@@ -835,6 +860,14 @@ export async function doClaudeTuiStream(opts) {
|
|
|
835
860
|
catch {
|
|
836
861
|
continue;
|
|
837
862
|
}
|
|
863
|
+
// A Task PreToolUse and the first sub-agent tool PreToolUse can land in
|
|
864
|
+
// the same tick batch. If the sub-agent's hook arrives before we've
|
|
865
|
+
// discovered its sidecar (and thus before s.subAgentIdToParent knows
|
|
866
|
+
// its agent_id), refresh discovery so the hook resolves its parent on
|
|
867
|
+
// this pass instead of leaking through unattributed.
|
|
868
|
+
const subAgentId = typeof ev?.agent_id === 'string' ? ev.agent_id : '';
|
|
869
|
+
if (subAgentId && !s.subAgentIdToParent?.has(subAgentId))
|
|
870
|
+
tryDiscoverSubAgents();
|
|
838
871
|
try {
|
|
839
872
|
if (applyHookToolEvent(ev, s))
|
|
840
873
|
any = true;
|
|
@@ -880,6 +913,15 @@ export async function doClaudeTuiStream(opts) {
|
|
|
880
913
|
continue;
|
|
881
914
|
const sidecarPath = path.join(sidecarDir, `${stem}.jsonl`);
|
|
882
915
|
trackedSubAgents.set(stem, { sidecarPath, offset: 0, parentToolUseId });
|
|
916
|
+
// `stem` is "agent-<id>"; Claude Code's hook payload `agent_id` carries
|
|
917
|
+
// just the raw id. Keep both keys so applyHookToolEvent can attribute
|
|
918
|
+
// sub-agent tool hooks to the parent's Task tool_use no matter which
|
|
919
|
+
// form arrives.
|
|
920
|
+
const rawAgentId = stem.startsWith('agent-') ? stem.slice('agent-'.length) : stem;
|
|
921
|
+
if (!s.subAgentIdToParent)
|
|
922
|
+
s.subAgentIdToParent = new Map();
|
|
923
|
+
s.subAgentIdToParent.set(rawAgentId, parentToolUseId);
|
|
924
|
+
s.subAgentIdToParent.set(stem, parentToolUseId);
|
|
883
925
|
agentLog(`[claude-tui] subagent sidecar discovered ${stem} parent=${parentToolUseId.slice(0, 14)}`);
|
|
884
926
|
}
|
|
885
927
|
};
|
package/package.json
CHANGED