@sudocode-ai/local-server 0.1.7 → 0.1.8
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 +6 -0
- package/dist/errors/agent-errors.d.ts +43 -0
- package/dist/errors/agent-errors.d.ts.map +1 -0
- package/dist/errors/agent-errors.js +69 -0
- package/dist/errors/agent-errors.js.map +1 -0
- package/dist/execution/adapters/claude-adapter.d.ts +63 -0
- package/dist/execution/adapters/claude-adapter.d.ts.map +1 -0
- package/dist/execution/adapters/claude-adapter.js +82 -0
- package/dist/execution/adapters/claude-adapter.js.map +1 -0
- package/dist/execution/adapters/codex-adapter.d.ts +67 -0
- package/dist/execution/adapters/codex-adapter.d.ts.map +1 -0
- package/dist/execution/adapters/codex-adapter.js +183 -0
- package/dist/execution/adapters/codex-adapter.js.map +1 -0
- package/dist/execution/adapters/codex-config-builder.d.ts +30 -0
- package/dist/execution/adapters/codex-config-builder.d.ts.map +1 -0
- package/dist/execution/adapters/codex-config-builder.js +110 -0
- package/dist/execution/adapters/codex-config-builder.js.map +1 -0
- package/dist/execution/adapters/copilot-adapter.d.ts +94 -0
- package/dist/execution/adapters/copilot-adapter.d.ts.map +1 -0
- package/dist/execution/adapters/copilot-adapter.js +163 -0
- package/dist/execution/adapters/copilot-adapter.js.map +1 -0
- package/dist/execution/adapters/copilot-config-builder.d.ts +48 -0
- package/dist/execution/adapters/copilot-config-builder.d.ts.map +1 -0
- package/dist/execution/adapters/copilot-config-builder.js +125 -0
- package/dist/execution/adapters/copilot-config-builder.js.map +1 -0
- package/dist/execution/adapters/cursor-adapter.d.ts +66 -0
- package/dist/execution/adapters/cursor-adapter.d.ts.map +1 -0
- package/dist/execution/adapters/cursor-adapter.js +121 -0
- package/dist/execution/adapters/cursor-adapter.js.map +1 -0
- package/dist/execution/adapters/cursor-config-builder.d.ts +29 -0
- package/dist/execution/adapters/cursor-config-builder.d.ts.map +1 -0
- package/dist/execution/adapters/cursor-config-builder.js +49 -0
- package/dist/execution/adapters/cursor-config-builder.js.map +1 -0
- package/dist/execution/adapters/shared/config-presets.d.ts +102 -0
- package/dist/execution/adapters/shared/config-presets.d.ts.map +1 -0
- package/dist/execution/adapters/shared/config-presets.js +205 -0
- package/dist/execution/adapters/shared/config-presets.js.map +1 -0
- package/dist/execution/adapters/shared/config-utils.d.ts +95 -0
- package/dist/execution/adapters/shared/config-utils.d.ts.map +1 -0
- package/dist/execution/adapters/shared/config-utils.js +163 -0
- package/dist/execution/adapters/shared/config-utils.js.map +1 -0
- package/dist/execution/adapters/shared/index.d.ts +8 -0
- package/dist/execution/adapters/shared/index.d.ts.map +1 -0
- package/dist/execution/adapters/shared/index.js +8 -0
- package/dist/execution/adapters/shared/index.js.map +1 -0
- package/dist/execution/executors/agent-executor-wrapper.d.ts +153 -0
- package/dist/execution/executors/agent-executor-wrapper.d.ts.map +1 -0
- package/dist/execution/executors/agent-executor-wrapper.js +652 -0
- package/dist/execution/executors/agent-executor-wrapper.js.map +1 -0
- package/dist/execution/executors/executor-factory.d.ts +95 -0
- package/dist/execution/executors/executor-factory.d.ts.map +1 -0
- package/dist/execution/executors/executor-factory.js +120 -0
- package/dist/execution/executors/executor-factory.js.map +1 -0
- package/dist/execution/output/ag-ui-adapter.d.ts +0 -2
- package/dist/execution/output/ag-ui-adapter.d.ts.map +1 -1
- package/dist/execution/output/ag-ui-adapter.js +0 -2
- package/dist/execution/output/ag-ui-adapter.js.map +1 -1
- package/dist/execution/output/index.d.ts +0 -3
- package/dist/execution/output/index.d.ts.map +1 -1
- package/dist/execution/output/index.js +0 -2
- package/dist/execution/output/index.js.map +1 -1
- package/dist/execution/output/normalized-to-ag-ui-adapter.d.ts +108 -0
- package/dist/execution/output/normalized-to-ag-ui-adapter.d.ts.map +1 -0
- package/dist/execution/output/normalized-to-ag-ui-adapter.js +321 -0
- package/dist/execution/output/normalized-to-ag-ui-adapter.js.map +1 -0
- package/dist/execution/process/builders/claude.d.ts +24 -57
- package/dist/execution/process/builders/claude.d.ts.map +1 -1
- package/dist/execution/process/builders/claude.js +153 -19
- package/dist/execution/process/builders/claude.js.map +1 -1
- package/dist/execution/transport/ipc-transport-manager.d.ts +74 -0
- package/dist/execution/transport/ipc-transport-manager.d.ts.map +1 -0
- package/dist/execution/transport/ipc-transport-manager.js +104 -0
- package/dist/execution/transport/ipc-transport-manager.js.map +1 -0
- package/dist/execution/transport/transport-manager.d.ts.map +1 -1
- package/dist/execution/transport/transport-manager.js +3 -0
- package/dist/execution/transport/transport-manager.js.map +1 -1
- package/dist/execution/worktree/conflict-detector.d.ts +85 -0
- package/dist/execution/worktree/conflict-detector.d.ts.map +1 -0
- package/dist/execution/worktree/conflict-detector.js +129 -0
- package/dist/execution/worktree/conflict-detector.js.map +1 -0
- package/dist/execution/worktree/git-cli.d.ts +9 -0
- package/dist/execution/worktree/git-cli.d.ts.map +1 -1
- package/dist/execution/worktree/git-cli.js +10 -0
- package/dist/execution/worktree/git-cli.js.map +1 -1
- package/dist/execution/worktree/git-sync-cli.d.ts +187 -0
- package/dist/execution/worktree/git-sync-cli.d.ts.map +1 -0
- package/dist/execution/worktree/git-sync-cli.js +350 -0
- package/dist/execution/worktree/git-sync-cli.js.map +1 -0
- package/dist/execution/worktree/manager.d.ts +18 -0
- package/dist/execution/worktree/manager.d.ts.map +1 -1
- package/dist/execution/worktree/manager.js +9 -3
- package/dist/execution/worktree/manager.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +132 -211
- package/dist/index.js.map +1 -1
- package/dist/middleware/project-context.d.ts +37 -0
- package/dist/middleware/project-context.d.ts.map +1 -0
- package/dist/middleware/project-context.js +91 -0
- package/dist/middleware/project-context.js.map +1 -0
- package/dist/public/assets/index-Bb_W5bUr.css +1 -0
- package/dist/public/assets/index-CFKL113G.js +710 -0
- package/dist/public/assets/index-CFKL113G.js.map +1 -0
- package/dist/public/assets/{react-vendor-ByUx1V_q.js → react-vendor-DiL5hC7l.js} +2 -2
- package/dist/public/assets/{react-vendor-ByUx1V_q.js.map → react-vendor-DiL5hC7l.js.map} +1 -1
- package/dist/public/assets/ui-vendor-B4WMPEfa.js +54 -0
- package/dist/public/assets/ui-vendor-B4WMPEfa.js.map +1 -0
- package/dist/public/index.html +4 -4
- package/dist/routes/agents.d.ts +3 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/agents.js +62 -0
- package/dist/routes/agents.js.map +1 -0
- package/dist/routes/config.d.ts +3 -0
- package/dist/routes/config.d.ts.map +1 -0
- package/dist/routes/config.js +25 -0
- package/dist/routes/config.js.map +1 -0
- package/dist/routes/editors.d.ts +15 -0
- package/dist/routes/editors.d.ts.map +1 -0
- package/dist/routes/editors.js +98 -0
- package/dist/routes/editors.js.map +1 -0
- package/dist/routes/executions-stream.d.ts +8 -5
- package/dist/routes/executions-stream.d.ts.map +1 -1
- package/dist/routes/executions-stream.js +10 -6
- package/dist/routes/executions-stream.js.map +1 -1
- package/dist/routes/executions.d.ts +6 -10
- package/dist/routes/executions.d.ts.map +1 -1
- package/dist/routes/executions.js +506 -54
- package/dist/routes/executions.js.map +1 -1
- package/dist/routes/feedback.d.ts +3 -2
- package/dist/routes/feedback.d.ts.map +1 -1
- package/dist/routes/feedback.js +12 -10
- package/dist/routes/feedback.js.map +1 -1
- package/dist/routes/files.d.ts +18 -0
- package/dist/routes/files.d.ts.map +1 -0
- package/dist/routes/files.js +89 -0
- package/dist/routes/files.js.map +1 -0
- package/dist/routes/issues.d.ts +3 -2
- package/dist/routes/issues.d.ts.map +1 -1
- package/dist/routes/issues.js +19 -18
- package/dist/routes/issues.js.map +1 -1
- package/dist/routes/projects.d.ts +11 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/projects.js +447 -0
- package/dist/routes/projects.js.map +1 -0
- package/dist/routes/relationships.d.ts +3 -2
- package/dist/routes/relationships.d.ts.map +1 -1
- package/dist/routes/relationships.js +12 -10
- package/dist/routes/relationships.js.map +1 -1
- package/dist/routes/repo-info.d.ts +3 -0
- package/dist/routes/repo-info.d.ts.map +1 -0
- package/dist/routes/repo-info.js +126 -0
- package/dist/routes/repo-info.js.map +1 -0
- package/dist/routes/specs.d.ts +3 -2
- package/dist/routes/specs.d.ts.map +1 -1
- package/dist/routes/specs.js +19 -18
- package/dist/routes/specs.js.map +1 -1
- package/dist/services/agent-registry.d.ts +140 -0
- package/dist/services/agent-registry.d.ts.map +1 -0
- package/dist/services/agent-registry.js +272 -0
- package/dist/services/agent-registry.js.map +1 -0
- package/dist/services/editor-service.d.ts +57 -0
- package/dist/services/editor-service.d.ts.map +1 -0
- package/dist/services/editor-service.js +204 -0
- package/dist/services/editor-service.js.map +1 -0
- package/dist/services/execution-changes-service.d.ts +92 -0
- package/dist/services/execution-changes-service.d.ts.map +1 -0
- package/dist/services/execution-changes-service.js +546 -0
- package/dist/services/execution-changes-service.js.map +1 -0
- package/dist/services/execution-lifecycle.d.ts +1 -0
- package/dist/services/execution-lifecycle.d.ts.map +1 -1
- package/dist/services/execution-lifecycle.js +37 -7
- package/dist/services/execution-lifecycle.js.map +1 -1
- package/dist/services/execution-logs-store.d.ts +75 -0
- package/dist/services/execution-logs-store.d.ts.map +1 -1
- package/dist/services/execution-logs-store.js +142 -2
- package/dist/services/execution-logs-store.js.map +1 -1
- package/dist/services/execution-service.d.ts +50 -58
- package/dist/services/execution-service.d.ts.map +1 -1
- package/dist/services/execution-service.js +433 -469
- package/dist/services/execution-service.js.map +1 -1
- package/dist/services/execution-worker-pool.d.ts +116 -0
- package/dist/services/execution-worker-pool.d.ts.map +1 -0
- package/dist/services/execution-worker-pool.js +326 -0
- package/dist/services/execution-worker-pool.js.map +1 -0
- package/dist/services/executions.d.ts +3 -0
- package/dist/services/executions.d.ts.map +1 -1
- package/dist/services/executions.js +11 -17
- package/dist/services/executions.js.map +1 -1
- package/dist/services/export.d.ts +8 -2
- package/dist/services/export.d.ts.map +1 -1
- package/dist/services/export.js +29 -23
- package/dist/services/export.js.map +1 -1
- package/dist/services/file-search/git-ls-files-strategy.d.ts +72 -0
- package/dist/services/file-search/git-ls-files-strategy.d.ts.map +1 -0
- package/dist/services/file-search/git-ls-files-strategy.js +176 -0
- package/dist/services/file-search/git-ls-files-strategy.js.map +1 -0
- package/dist/services/file-search/index.d.ts +9 -0
- package/dist/services/file-search/index.d.ts.map +1 -0
- package/dist/services/file-search/index.js +10 -0
- package/dist/services/file-search/index.js.map +1 -0
- package/dist/services/file-search/registry.d.ts +97 -0
- package/dist/services/file-search/registry.d.ts.map +1 -0
- package/dist/services/file-search/registry.js +140 -0
- package/dist/services/file-search/registry.js.map +1 -0
- package/dist/services/file-search/strategy.d.ts +58 -0
- package/dist/services/file-search/strategy.d.ts.map +1 -0
- package/dist/services/file-search/strategy.js +8 -0
- package/dist/services/file-search/strategy.js.map +1 -0
- package/dist/services/project-context.d.ts +69 -0
- package/dist/services/project-context.d.ts.map +1 -0
- package/dist/services/project-context.js +113 -0
- package/dist/services/project-context.js.map +1 -0
- package/dist/services/project-manager.d.ts +95 -0
- package/dist/services/project-manager.d.ts.map +1 -0
- package/dist/services/project-manager.js +388 -0
- package/dist/services/project-manager.js.map +1 -0
- package/dist/services/project-registry.d.ts +98 -0
- package/dist/services/project-registry.d.ts.map +1 -0
- package/dist/services/project-registry.js +289 -0
- package/dist/services/project-registry.js.map +1 -0
- package/dist/services/prompt-resolver.d.ts +97 -0
- package/dist/services/prompt-resolver.d.ts.map +1 -0
- package/dist/services/prompt-resolver.js +377 -0
- package/dist/services/prompt-resolver.js.map +1 -0
- package/dist/services/repo-info.d.ts +12 -0
- package/dist/services/repo-info.d.ts.map +1 -1
- package/dist/services/repo-info.js +46 -0
- package/dist/services/repo-info.js.map +1 -1
- package/dist/services/watcher.d.ts +3 -4
- package/dist/services/watcher.d.ts.map +1 -1
- package/dist/services/watcher.js +18 -35
- package/dist/services/watcher.js.map +1 -1
- package/dist/services/websocket.d.ts +30 -16
- package/dist/services/websocket.d.ts.map +1 -1
- package/dist/services/websocket.js +102 -37
- package/dist/services/websocket.js.map +1 -1
- package/dist/services/worktree-sync-service.d.ts +228 -0
- package/dist/services/worktree-sync-service.d.ts.map +1 -0
- package/dist/services/worktree-sync-service.js +563 -0
- package/dist/services/worktree-sync-service.js.map +1 -0
- package/dist/types/editor.d.ts +49 -0
- package/dist/types/editor.d.ts.map +1 -0
- package/dist/types/editor.js +50 -0
- package/dist/types/editor.js.map +1 -0
- package/dist/types/project.d.ts +58 -0
- package/dist/types/project.d.ts.map +1 -0
- package/dist/types/project.js +10 -0
- package/dist/types/project.js.map +1 -0
- package/dist/utils/executable-check.d.ts +36 -0
- package/dist/utils/executable-check.d.ts.map +1 -0
- package/dist/utils/executable-check.js +79 -0
- package/dist/utils/executable-check.js.map +1 -0
- package/dist/workers/execution-worker.d.ts +18 -0
- package/dist/workers/execution-worker.d.ts.map +1 -0
- package/dist/workers/execution-worker.js +340 -0
- package/dist/workers/execution-worker.js.map +1 -0
- package/dist/workers/worker-ipc.d.ts +84 -0
- package/dist/workers/worker-ipc.d.ts.map +1 -0
- package/dist/workers/worker-ipc.js +29 -0
- package/dist/workers/worker-ipc.js.map +1 -0
- package/package.json +6 -5
- package/dist/execution/output/ag-ui-integration.d.ts +0 -96
- package/dist/execution/output/ag-ui-integration.d.ts.map +0 -1
- package/dist/execution/output/ag-ui-integration.js +0 -96
- package/dist/execution/output/ag-ui-integration.js.map +0 -1
- package/dist/execution/output/claude-code-output-processor.d.ts +0 -321
- package/dist/execution/output/claude-code-output-processor.d.ts.map +0 -1
- package/dist/execution/output/claude-code-output-processor.js +0 -769
- package/dist/execution/output/claude-code-output-processor.js.map +0 -1
- package/dist/public/assets/index-B3SEMufD.js +0 -580
- package/dist/public/assets/index-B3SEMufD.js.map +0 -1
- package/dist/public/assets/index-D2YGL3gX.css +0 -1
- package/dist/public/assets/ui-vendor-CotR6bx9.js +0 -54
- package/dist/public/assets/ui-vendor-CotR6bx9.js.map +0 -1
|
@@ -1,769 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Code Output Processor
|
|
3
|
-
*
|
|
4
|
-
* Implements the IOutputProcessor interface specifically for parsing
|
|
5
|
-
* Claude Code's stream-json output format in real-time.
|
|
6
|
-
*
|
|
7
|
-
* This processor is tailored to Claude Code's CLI output and handles its
|
|
8
|
-
* specific message structure, tool calling patterns, and metadata format.
|
|
9
|
-
*
|
|
10
|
-
* @module execution/output/claude-code-output-processor
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* ClaudeCodeOutputProcessor - Parses Claude Code's stream-json output
|
|
14
|
-
*
|
|
15
|
-
* This processor is specifically designed for Claude Code's output format.
|
|
16
|
-
* It handles line-by-line parsing of Claude's stream-json messages,
|
|
17
|
-
* extracting tool calls, file changes, and usage metrics in real-time.
|
|
18
|
-
*
|
|
19
|
-
* **Claude Code Specific Features:**
|
|
20
|
-
* - Parses Claude's message.content array structure
|
|
21
|
-
* - Handles tool_use and tool_result content types
|
|
22
|
-
* - Extracts usage metrics from result messages
|
|
23
|
-
* - Processes Claude-specific error formats
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const processor = new ClaudeCodeOutputProcessor();
|
|
28
|
-
*
|
|
29
|
-
* processor.onToolCall((toolCall) => {
|
|
30
|
-
* console.log(`Claude called tool: ${toolCall.name}`, toolCall.input);
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // Process Claude Code's stream-json output
|
|
34
|
-
* await processor.processLine('{"type":"assistant","message":{"content":[...]}}');
|
|
35
|
-
* const metrics = processor.getMetrics();
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export class ClaudeCodeOutputProcessor {
|
|
39
|
-
// Internal state
|
|
40
|
-
_metrics;
|
|
41
|
-
_toolCalls;
|
|
42
|
-
_fileChanges;
|
|
43
|
-
// Event handlers
|
|
44
|
-
_toolCallHandlers = [];
|
|
45
|
-
_fileChangeHandlers = [];
|
|
46
|
-
_progressHandlers = [];
|
|
47
|
-
_errorHandlers = [];
|
|
48
|
-
_messageHandlers = [];
|
|
49
|
-
_usageHandlers = [];
|
|
50
|
-
// Processing state
|
|
51
|
-
_lineNumber = 0;
|
|
52
|
-
constructor() {
|
|
53
|
-
// Initialize metrics with empty state
|
|
54
|
-
this._metrics = {
|
|
55
|
-
totalMessages: 0,
|
|
56
|
-
toolCalls: [],
|
|
57
|
-
fileChanges: [],
|
|
58
|
-
usage: {
|
|
59
|
-
inputTokens: 0,
|
|
60
|
-
outputTokens: 0,
|
|
61
|
-
cacheTokens: 0,
|
|
62
|
-
totalTokens: 0,
|
|
63
|
-
cost: 0,
|
|
64
|
-
provider: "anthropic",
|
|
65
|
-
model: "claude", // Will be updated when we parse actual model info
|
|
66
|
-
},
|
|
67
|
-
errors: [],
|
|
68
|
-
startedAt: new Date(),
|
|
69
|
-
lastUpdate: new Date(),
|
|
70
|
-
};
|
|
71
|
-
this._toolCalls = new Map();
|
|
72
|
-
this._fileChanges = [];
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Process a single line of Claude Code's stream-json output
|
|
76
|
-
*
|
|
77
|
-
* Parses the JSON line and routes to appropriate handler based on message type.
|
|
78
|
-
* Handles malformed JSON gracefully and skips empty lines.
|
|
79
|
-
*
|
|
80
|
-
* @param line - Raw JSON line from Claude Code CLI output
|
|
81
|
-
*/
|
|
82
|
-
async processLine(line) {
|
|
83
|
-
this._lineNumber++;
|
|
84
|
-
// Skip empty lines
|
|
85
|
-
const trimmed = line.trim();
|
|
86
|
-
if (!trimmed) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
// Parse JSON
|
|
91
|
-
const data = JSON.parse(trimmed);
|
|
92
|
-
// Detect message type (Claude-specific structure)
|
|
93
|
-
const messageType = this._detectMessageType(data);
|
|
94
|
-
// Create OutputMessage
|
|
95
|
-
const message = this._parseMessage(data, messageType);
|
|
96
|
-
// Update metrics
|
|
97
|
-
this._metrics.totalMessages++;
|
|
98
|
-
this._metrics.lastUpdate = new Date();
|
|
99
|
-
// Route to message-specific handlers
|
|
100
|
-
switch (message.type) {
|
|
101
|
-
case "tool_use":
|
|
102
|
-
this._handleToolUse(message);
|
|
103
|
-
break;
|
|
104
|
-
case "tool_result":
|
|
105
|
-
this._handleToolResult(message);
|
|
106
|
-
break;
|
|
107
|
-
case "text":
|
|
108
|
-
this._handleText(message);
|
|
109
|
-
break;
|
|
110
|
-
case "usage":
|
|
111
|
-
this._handleUsage(message);
|
|
112
|
-
break;
|
|
113
|
-
case "error":
|
|
114
|
-
this._handleError(message);
|
|
115
|
-
break;
|
|
116
|
-
case "unknown":
|
|
117
|
-
// Already tracked in metrics, no special handling needed
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
// Emit progress event
|
|
121
|
-
this._emitProgress();
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
// Handle malformed JSON
|
|
125
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
126
|
-
const errorInfo = {
|
|
127
|
-
message: `Failed to parse Claude Code output line ${this._lineNumber}: ${errorMessage}`,
|
|
128
|
-
timestamp: new Date(),
|
|
129
|
-
details: {
|
|
130
|
-
line: trimmed,
|
|
131
|
-
error: errorMessage,
|
|
132
|
-
lineNumber: this._lineNumber,
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
this._metrics.errors.push(errorInfo);
|
|
136
|
-
this._emitError(errorInfo);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Get current processing metrics
|
|
141
|
-
*
|
|
142
|
-
* @returns Current aggregate metrics
|
|
143
|
-
*/
|
|
144
|
-
getMetrics() {
|
|
145
|
-
return {
|
|
146
|
-
...this._metrics,
|
|
147
|
-
// Return current arrays (not references to internal state)
|
|
148
|
-
toolCalls: [...this._metrics.toolCalls],
|
|
149
|
-
fileChanges: [...this._metrics.fileChanges],
|
|
150
|
-
errors: [...this._metrics.errors],
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Get all tool calls recorded during processing
|
|
155
|
-
*
|
|
156
|
-
* @returns Array of all tool calls
|
|
157
|
-
*/
|
|
158
|
-
getToolCalls() {
|
|
159
|
-
return Array.from(this._toolCalls.values());
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Get all file changes detected during processing
|
|
163
|
-
*
|
|
164
|
-
* @returns Array of all file changes
|
|
165
|
-
*/
|
|
166
|
-
getFileChanges() {
|
|
167
|
-
return [...this._fileChanges];
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Register a callback for tool call events
|
|
171
|
-
*
|
|
172
|
-
* @param handler - Function to call when a tool is invoked
|
|
173
|
-
*/
|
|
174
|
-
onToolCall(handler) {
|
|
175
|
-
this._toolCallHandlers.push(handler);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Register a callback for file change events
|
|
179
|
-
*
|
|
180
|
-
* @param handler - Function to call when a file is modified
|
|
181
|
-
*/
|
|
182
|
-
onFileChange(handler) {
|
|
183
|
-
this._fileChangeHandlers.push(handler);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Register a callback for progress update events
|
|
187
|
-
*
|
|
188
|
-
* @param handler - Function to call when metrics are updated
|
|
189
|
-
*/
|
|
190
|
-
onProgress(handler) {
|
|
191
|
-
this._progressHandlers.push(handler);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Register a callback for error events
|
|
195
|
-
*
|
|
196
|
-
* @param handler - Function to call when an error occurs
|
|
197
|
-
*/
|
|
198
|
-
onError(handler) {
|
|
199
|
-
this._errorHandlers.push(handler);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Register a callback for message events
|
|
203
|
-
*
|
|
204
|
-
* @param handler - Function to call when a text message is received
|
|
205
|
-
*/
|
|
206
|
-
onMessage(handler) {
|
|
207
|
-
this._messageHandlers.push(handler);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Register a callback for usage metric updates
|
|
211
|
-
*
|
|
212
|
-
* @param handler - Function to call when usage metrics are updated
|
|
213
|
-
*/
|
|
214
|
-
onUsage(handler) {
|
|
215
|
-
this._usageHandlers.push(handler);
|
|
216
|
-
}
|
|
217
|
-
// ============================================================================
|
|
218
|
-
// Query Methods - Data Aggregation and Filtering
|
|
219
|
-
// ============================================================================
|
|
220
|
-
/**
|
|
221
|
-
* Get tool calls filtered by tool name
|
|
222
|
-
*
|
|
223
|
-
* @param toolName - Name of the tool to filter by (e.g., 'Bash', 'Read', 'Write')
|
|
224
|
-
* @returns Array of tool calls matching the tool name
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```typescript
|
|
228
|
-
* const bashCalls = processor.getToolCallsByName('Bash');
|
|
229
|
-
* console.log(`Executed ${bashCalls.length} bash commands`);
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
getToolCallsByName(toolName) {
|
|
233
|
-
return this.getToolCalls().filter((call) => call.name === toolName);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Get file changes filtered by file path
|
|
237
|
-
*
|
|
238
|
-
* @param path - File path to filter by (exact match)
|
|
239
|
-
* @returns Array of file changes to the specified path
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```typescript
|
|
243
|
-
* const changes = processor.getFileChangesByPath('src/index.ts');
|
|
244
|
-
* console.log(`File modified ${changes.length} times`);
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
getFileChangesByPath(path) {
|
|
248
|
-
return this.getFileChanges().filter((change) => change.path === path);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Get file changes filtered by operation type
|
|
252
|
-
*
|
|
253
|
-
* @param operation - Operation type to filter by ('read', 'write', 'edit')
|
|
254
|
-
* @returns Array of file changes with the specified operation
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* ```typescript
|
|
258
|
-
* const writes = processor.getFileChangesByOperation('write');
|
|
259
|
-
* console.log(`Wrote to ${writes.length} files`);
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
getFileChangesByOperation(operation) {
|
|
263
|
-
return this.getFileChanges().filter((change) => change.operation === operation);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Get only failed tool calls
|
|
267
|
-
*
|
|
268
|
-
* @returns Array of tool calls with status='error'
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
271
|
-
* ```typescript
|
|
272
|
-
* const failures = processor.getFailedToolCalls();
|
|
273
|
-
* failures.forEach(call => {
|
|
274
|
-
* console.error(`${call.name} failed:`, call.error);
|
|
275
|
-
* });
|
|
276
|
-
* ```
|
|
277
|
-
*/
|
|
278
|
-
getFailedToolCalls() {
|
|
279
|
-
return this.getToolCalls().filter((call) => call.status === "error");
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Get only successful tool calls
|
|
283
|
-
*
|
|
284
|
-
* @returns Array of tool calls with status='success'
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* ```typescript
|
|
288
|
-
* const successes = processor.getSuccessfulToolCalls();
|
|
289
|
-
* console.log(`${successes.length} tool calls succeeded`);
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
|
-
getSuccessfulToolCalls() {
|
|
293
|
-
return this.getToolCalls().filter((call) => call.status === "success");
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Get total cost of execution in USD
|
|
297
|
-
*
|
|
298
|
-
* @returns Total cost based on token usage
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```typescript
|
|
302
|
-
* const cost = processor.getTotalCost();
|
|
303
|
-
* console.log(`Execution cost: $${cost.toFixed(2)}`);
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
getTotalCost() {
|
|
307
|
-
return this._metrics.usage.cost || 0;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Get execution summary with aggregate statistics
|
|
311
|
-
*
|
|
312
|
-
* Provides a high-level overview of the execution including:
|
|
313
|
-
* - Tool call counts by type
|
|
314
|
-
* - File operation counts by type
|
|
315
|
-
* - Success rates
|
|
316
|
-
* - Token usage and costs
|
|
317
|
-
* - Duration
|
|
318
|
-
*
|
|
319
|
-
* @returns Complete execution summary
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* ```typescript
|
|
323
|
-
* const summary = processor.getExecutionSummary();
|
|
324
|
-
* console.log('Execution Summary:', {
|
|
325
|
-
* duration: `${summary.duration}ms`,
|
|
326
|
-
* cost: `$${summary.totalCost.toFixed(2)}`,
|
|
327
|
-
* successRate: `${summary.successRate.toFixed(1)}%`,
|
|
328
|
-
* toolCalls: summary.toolCallsByType,
|
|
329
|
-
* });
|
|
330
|
-
* ```
|
|
331
|
-
*/
|
|
332
|
-
getExecutionSummary() {
|
|
333
|
-
const toolCalls = this.getToolCalls();
|
|
334
|
-
const fileChanges = this.getFileChanges();
|
|
335
|
-
// Calculate tool calls by type
|
|
336
|
-
const toolCallsByType = {};
|
|
337
|
-
for (const call of toolCalls) {
|
|
338
|
-
toolCallsByType[call.name] = (toolCallsByType[call.name] || 0) + 1;
|
|
339
|
-
}
|
|
340
|
-
// Calculate file operations by type
|
|
341
|
-
const fileOperationsByType = {};
|
|
342
|
-
for (const change of fileChanges) {
|
|
343
|
-
fileOperationsByType[change.operation] =
|
|
344
|
-
(fileOperationsByType[change.operation] || 0) + 1;
|
|
345
|
-
}
|
|
346
|
-
// Calculate success rate
|
|
347
|
-
const completedCalls = toolCalls.filter((call) => call.status === "success" || call.status === "error");
|
|
348
|
-
const successfulCalls = toolCalls.filter((call) => call.status === "success");
|
|
349
|
-
const successRate = completedCalls.length > 0
|
|
350
|
-
? (successfulCalls.length / completedCalls.length) * 100
|
|
351
|
-
: 0;
|
|
352
|
-
// Calculate duration
|
|
353
|
-
const endTime = this._metrics.endedAt || new Date();
|
|
354
|
-
const duration = endTime.getTime() - this._metrics.startedAt.getTime();
|
|
355
|
-
return {
|
|
356
|
-
totalMessages: this._metrics.totalMessages,
|
|
357
|
-
toolCallsByType,
|
|
358
|
-
fileOperationsByType,
|
|
359
|
-
successRate,
|
|
360
|
-
totalTokens: {
|
|
361
|
-
input: this._metrics.usage.inputTokens,
|
|
362
|
-
output: this._metrics.usage.outputTokens,
|
|
363
|
-
cache: this._metrics.usage.cacheTokens,
|
|
364
|
-
},
|
|
365
|
-
totalCost: this._metrics.usage.cost || 0,
|
|
366
|
-
duration,
|
|
367
|
-
startTime: this._metrics.startedAt,
|
|
368
|
-
endTime: this._metrics.endedAt,
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
// ============================================================================
|
|
372
|
-
// Private methods - Message Type Handlers
|
|
373
|
-
// ============================================================================
|
|
374
|
-
/**
|
|
375
|
-
* Handle tool_use message from Claude Code
|
|
376
|
-
*
|
|
377
|
-
* Creates a new ToolCall entry with pending status and emits onToolCall event.
|
|
378
|
-
* Also detects potential file operations based on tool name.
|
|
379
|
-
*
|
|
380
|
-
* @param message - Parsed tool_use message
|
|
381
|
-
*/
|
|
382
|
-
_handleToolUse(message) {
|
|
383
|
-
if (message.type !== "tool_use")
|
|
384
|
-
return;
|
|
385
|
-
const toolCall = {
|
|
386
|
-
id: message.id,
|
|
387
|
-
name: message.name,
|
|
388
|
-
input: message.input,
|
|
389
|
-
status: "pending",
|
|
390
|
-
timestamp: message.timestamp,
|
|
391
|
-
};
|
|
392
|
-
// Store in map for fast lookup
|
|
393
|
-
this._toolCalls.set(toolCall.id, toolCall);
|
|
394
|
-
// Update metrics
|
|
395
|
-
this._metrics.toolCalls.push(toolCall);
|
|
396
|
-
// Emit tool call event
|
|
397
|
-
for (const handler of this._toolCallHandlers) {
|
|
398
|
-
try {
|
|
399
|
-
handler(toolCall);
|
|
400
|
-
}
|
|
401
|
-
catch (error) {
|
|
402
|
-
console.error("Tool call handler error:", error);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Handle tool_result message from Claude Code
|
|
408
|
-
*
|
|
409
|
-
* Updates the corresponding ToolCall with result/error status.
|
|
410
|
-
* Detects file changes from Read/Write/Edit tools and emits onFileChange event.
|
|
411
|
-
*
|
|
412
|
-
* @param message - Parsed tool_result message
|
|
413
|
-
*/
|
|
414
|
-
_handleToolResult(message) {
|
|
415
|
-
if (message.type !== "tool_result")
|
|
416
|
-
return;
|
|
417
|
-
// Find the corresponding tool call
|
|
418
|
-
const toolCall = this._toolCalls.get(message.toolUseId);
|
|
419
|
-
if (!toolCall) {
|
|
420
|
-
// Tool call not found - might be from before we started processing
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
// Update tool call status
|
|
424
|
-
toolCall.status = message.isError ? "error" : "success";
|
|
425
|
-
toolCall.result = message.result;
|
|
426
|
-
toolCall.error = message.isError ? String(message.result) : undefined;
|
|
427
|
-
toolCall.completedAt = message.timestamp;
|
|
428
|
-
// Detect file changes from file operation tools
|
|
429
|
-
const fileOperationTools = ["Read", "Write", "Edit", "Glob"];
|
|
430
|
-
if (fileOperationTools.includes(toolCall.name)) {
|
|
431
|
-
const fileChange = this._detectFileChange(toolCall, message);
|
|
432
|
-
if (fileChange) {
|
|
433
|
-
this._fileChanges.push(fileChange);
|
|
434
|
-
this._metrics.fileChanges.push(fileChange);
|
|
435
|
-
// Emit file change event
|
|
436
|
-
for (const handler of this._fileChangeHandlers) {
|
|
437
|
-
try {
|
|
438
|
-
handler(fileChange);
|
|
439
|
-
}
|
|
440
|
-
catch (error) {
|
|
441
|
-
console.error("File change handler error:", error);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Handle text message from Claude Code
|
|
449
|
-
*
|
|
450
|
-
* Emits message events to registered handlers.
|
|
451
|
-
*
|
|
452
|
-
* @param message - Parsed text message
|
|
453
|
-
*/
|
|
454
|
-
_handleText(message) {
|
|
455
|
-
if (message.type !== "text")
|
|
456
|
-
return;
|
|
457
|
-
// Emit message event to all registered handlers
|
|
458
|
-
for (const handler of this._messageHandlers) {
|
|
459
|
-
try {
|
|
460
|
-
handler(message);
|
|
461
|
-
}
|
|
462
|
-
catch (error) {
|
|
463
|
-
console.error("Message handler error:", error);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Handle usage message from Claude Code
|
|
469
|
-
*
|
|
470
|
-
* Updates usage metrics with token counts and calculates cost.
|
|
471
|
-
* Emits usage events to registered handlers.
|
|
472
|
-
*
|
|
473
|
-
* @param message - Parsed usage message
|
|
474
|
-
*/
|
|
475
|
-
_handleUsage(message) {
|
|
476
|
-
if (message.type !== "usage")
|
|
477
|
-
return;
|
|
478
|
-
// Aggregate usage metrics
|
|
479
|
-
this._metrics.usage.inputTokens += message.tokens.input;
|
|
480
|
-
this._metrics.usage.outputTokens += message.tokens.output;
|
|
481
|
-
this._metrics.usage.cacheTokens += message.tokens.cache;
|
|
482
|
-
this._metrics.usage.totalTokens =
|
|
483
|
-
this._metrics.usage.inputTokens + this._metrics.usage.outputTokens;
|
|
484
|
-
// Calculate cost (Claude Sonnet 4 pricing as of 2025)
|
|
485
|
-
// Input: $3/million tokens, Output: $15/million tokens, Cache: $0.30/million tokens
|
|
486
|
-
const inputCost = (this._metrics.usage.inputTokens / 1_000_000) * 3.0;
|
|
487
|
-
const outputCost = (this._metrics.usage.outputTokens / 1_000_000) * 15.0;
|
|
488
|
-
const cacheCost = (this._metrics.usage.cacheTokens / 1_000_000) * 0.3;
|
|
489
|
-
this._metrics.usage.cost = inputCost + outputCost + cacheCost;
|
|
490
|
-
// Emit usage event to all registered handlers
|
|
491
|
-
for (const handler of this._usageHandlers) {
|
|
492
|
-
try {
|
|
493
|
-
handler(this._metrics.usage);
|
|
494
|
-
}
|
|
495
|
-
catch (error) {
|
|
496
|
-
console.error("Usage handler error:", error);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Handle error message from Claude Code
|
|
502
|
-
*
|
|
503
|
-
* Tracks error in metrics and emits onError event.
|
|
504
|
-
*
|
|
505
|
-
* @param message - Parsed error message
|
|
506
|
-
*/
|
|
507
|
-
_handleError(message) {
|
|
508
|
-
if (message.type !== "error")
|
|
509
|
-
return;
|
|
510
|
-
const errorInfo = {
|
|
511
|
-
message: message.message,
|
|
512
|
-
timestamp: message.timestamp,
|
|
513
|
-
details: message.details,
|
|
514
|
-
};
|
|
515
|
-
// Already added to metrics.errors in processLine's catch block if it's a parse error
|
|
516
|
-
// Add this error if it's from Claude Code itself
|
|
517
|
-
if (!this._metrics.errors.find((e) => e.timestamp === message.timestamp)) {
|
|
518
|
-
this._metrics.errors.push(errorInfo);
|
|
519
|
-
}
|
|
520
|
-
// Emit error event
|
|
521
|
-
this._emitError(errorInfo);
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Detect file change from a tool call
|
|
525
|
-
*
|
|
526
|
-
* Analyzes tool calls to file operation tools (Read/Write/Edit) and
|
|
527
|
-
* extracts file change information.
|
|
528
|
-
*
|
|
529
|
-
* @param toolCall - The completed tool call
|
|
530
|
-
* @param message - The tool result message
|
|
531
|
-
* @returns FileChange object if file operation detected, null otherwise
|
|
532
|
-
*/
|
|
533
|
-
_detectFileChange(toolCall, message) {
|
|
534
|
-
// Extract file path from tool input
|
|
535
|
-
const filePath = toolCall.input.file_path || toolCall.input.path;
|
|
536
|
-
if (!filePath || typeof filePath !== "string") {
|
|
537
|
-
return null;
|
|
538
|
-
}
|
|
539
|
-
// Map tool name to operation
|
|
540
|
-
let operation;
|
|
541
|
-
switch (toolCall.name) {
|
|
542
|
-
case "Read":
|
|
543
|
-
case "Glob": // Glob reads files too
|
|
544
|
-
operation = "read";
|
|
545
|
-
break;
|
|
546
|
-
case "Write":
|
|
547
|
-
operation = "write";
|
|
548
|
-
break;
|
|
549
|
-
case "Edit":
|
|
550
|
-
operation = "edit";
|
|
551
|
-
break;
|
|
552
|
-
default:
|
|
553
|
-
return null;
|
|
554
|
-
}
|
|
555
|
-
return {
|
|
556
|
-
path: filePath,
|
|
557
|
-
operation,
|
|
558
|
-
timestamp: message.timestamp,
|
|
559
|
-
toolCallId: toolCall.id,
|
|
560
|
-
metadata: {
|
|
561
|
-
toolName: toolCall.name,
|
|
562
|
-
success: toolCall.status === "success",
|
|
563
|
-
},
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
// ============================================================================
|
|
567
|
-
// Private methods - Claude Code Specific Parsing
|
|
568
|
-
// ============================================================================
|
|
569
|
-
/**
|
|
570
|
-
* Detect the type of message from parsed Claude Code JSON data
|
|
571
|
-
*
|
|
572
|
-
* Claude Code uses a specific structure with type and message.content fields.
|
|
573
|
-
* This method understands Claude's output format.
|
|
574
|
-
*
|
|
575
|
-
* @param data - Parsed JSON object from Claude Code
|
|
576
|
-
* @returns Message type
|
|
577
|
-
*/
|
|
578
|
-
_detectMessageType(data) {
|
|
579
|
-
// Check for explicit type field
|
|
580
|
-
if (data.type === "error") {
|
|
581
|
-
return "error";
|
|
582
|
-
}
|
|
583
|
-
// Check for result message (contains usage information)
|
|
584
|
-
if (data.type === "result" && data.usage) {
|
|
585
|
-
return "usage";
|
|
586
|
-
}
|
|
587
|
-
// Check message content for tool_use or tool_result
|
|
588
|
-
// Claude structures content as an array or single object
|
|
589
|
-
if (data.message?.content) {
|
|
590
|
-
const content = Array.isArray(data.message.content)
|
|
591
|
-
? data.message.content[0]
|
|
592
|
-
: data.message.content;
|
|
593
|
-
if (content?.type === "tool_use") {
|
|
594
|
-
return "tool_use";
|
|
595
|
-
}
|
|
596
|
-
if (content?.type === "tool_result") {
|
|
597
|
-
return "tool_result";
|
|
598
|
-
}
|
|
599
|
-
// Text content
|
|
600
|
-
if (typeof content === "string" || content?.type === "text") {
|
|
601
|
-
return "text";
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
// Default to unknown
|
|
605
|
-
return "unknown";
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* Parse raw Claude Code JSON data into an OutputMessage
|
|
609
|
-
*
|
|
610
|
-
* @param data - Parsed JSON object from Claude Code
|
|
611
|
-
* @param type - Detected message type
|
|
612
|
-
* @returns Structured OutputMessage
|
|
613
|
-
*/
|
|
614
|
-
_parseMessage(data, type) {
|
|
615
|
-
const timestamp = new Date();
|
|
616
|
-
switch (type) {
|
|
617
|
-
case "text": {
|
|
618
|
-
const content = this._extractTextContent(data);
|
|
619
|
-
return {
|
|
620
|
-
type: "text",
|
|
621
|
-
content,
|
|
622
|
-
timestamp,
|
|
623
|
-
metadata: { raw: data, source: "claude-code" },
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
case "tool_use": {
|
|
627
|
-
const toolUse = this._extractToolUse(data);
|
|
628
|
-
return {
|
|
629
|
-
type: "tool_use",
|
|
630
|
-
id: toolUse.id,
|
|
631
|
-
name: toolUse.name,
|
|
632
|
-
input: toolUse.input,
|
|
633
|
-
timestamp,
|
|
634
|
-
metadata: { raw: data, source: "claude-code" },
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
case "tool_result": {
|
|
638
|
-
const toolResult = this._extractToolResult(data);
|
|
639
|
-
return {
|
|
640
|
-
type: "tool_result",
|
|
641
|
-
toolUseId: toolResult.toolUseId,
|
|
642
|
-
result: toolResult.result,
|
|
643
|
-
isError: toolResult.isError,
|
|
644
|
-
timestamp,
|
|
645
|
-
metadata: { raw: data, source: "claude-code" },
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
case "usage": {
|
|
649
|
-
const usage = this._extractUsage(data);
|
|
650
|
-
return {
|
|
651
|
-
type: "usage",
|
|
652
|
-
tokens: usage,
|
|
653
|
-
timestamp,
|
|
654
|
-
metadata: { raw: data, source: "claude-code" },
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
case "error": {
|
|
658
|
-
return {
|
|
659
|
-
type: "error",
|
|
660
|
-
message: data.error?.message || data.message || "Unknown error",
|
|
661
|
-
details: data.error || data,
|
|
662
|
-
timestamp,
|
|
663
|
-
metadata: { raw: data, source: "claude-code" },
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
case "unknown":
|
|
667
|
-
default: {
|
|
668
|
-
return {
|
|
669
|
-
type: "unknown",
|
|
670
|
-
raw: JSON.stringify(data),
|
|
671
|
-
timestamp,
|
|
672
|
-
metadata: { raw: data, source: "claude-code" },
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Extract text content from Claude Code message data
|
|
679
|
-
*
|
|
680
|
-
* Claude can return content as a string or an array of content blocks.
|
|
681
|
-
* This method handles both formats.
|
|
682
|
-
*/
|
|
683
|
-
_extractTextContent(data) {
|
|
684
|
-
if (typeof data.message?.content === "string") {
|
|
685
|
-
return data.message.content;
|
|
686
|
-
}
|
|
687
|
-
if (Array.isArray(data.message?.content)) {
|
|
688
|
-
const textContent = data.message.content
|
|
689
|
-
.filter((item) => item.type === "text" || typeof item === "string")
|
|
690
|
-
.map((item) => (typeof item === "string" ? item : item.text))
|
|
691
|
-
.join("");
|
|
692
|
-
return textContent;
|
|
693
|
-
}
|
|
694
|
-
return "";
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* Extract tool use information from Claude Code message data
|
|
698
|
-
*
|
|
699
|
-
* Claude includes tool_use blocks in the message.content array.
|
|
700
|
-
*/
|
|
701
|
-
_extractToolUse(data) {
|
|
702
|
-
const content = Array.isArray(data.message?.content)
|
|
703
|
-
? data.message.content.find((c) => c.type === "tool_use")
|
|
704
|
-
: data.message?.content;
|
|
705
|
-
return {
|
|
706
|
-
id: content?.id || "unknown",
|
|
707
|
-
name: content?.name || "unknown",
|
|
708
|
-
input: content?.input || {},
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Extract tool result information from Claude Code message data
|
|
713
|
-
*
|
|
714
|
-
* Claude includes tool_result blocks with execution results.
|
|
715
|
-
*/
|
|
716
|
-
_extractToolResult(data) {
|
|
717
|
-
const content = Array.isArray(data.message?.content)
|
|
718
|
-
? data.message.content.find((c) => c.type === "tool_result")
|
|
719
|
-
: data.message?.content;
|
|
720
|
-
return {
|
|
721
|
-
toolUseId: content?.tool_use_id || "unknown",
|
|
722
|
-
result: content?.content || content?.result || null,
|
|
723
|
-
isError: content?.is_error || false,
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Extract usage information from Claude Code result message
|
|
728
|
-
*
|
|
729
|
-
* Claude provides token usage in result messages with detailed breakdowns.
|
|
730
|
-
*/
|
|
731
|
-
_extractUsage(data) {
|
|
732
|
-
const usage = data.usage || {};
|
|
733
|
-
return {
|
|
734
|
-
input: usage.input_tokens || 0,
|
|
735
|
-
output: usage.output_tokens || 0,
|
|
736
|
-
cache: usage.cache_creation_input_tokens || usage.cache_read_input_tokens || 0,
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Emit progress event to all registered handlers
|
|
741
|
-
*/
|
|
742
|
-
_emitProgress() {
|
|
743
|
-
const metrics = this.getMetrics();
|
|
744
|
-
for (const handler of this._progressHandlers) {
|
|
745
|
-
try {
|
|
746
|
-
handler(metrics);
|
|
747
|
-
}
|
|
748
|
-
catch (error) {
|
|
749
|
-
// Ignore handler errors to prevent cascade failures
|
|
750
|
-
console.error("Progress handler error:", error);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* Emit error event to all registered handlers
|
|
756
|
-
*/
|
|
757
|
-
_emitError(error) {
|
|
758
|
-
for (const handler of this._errorHandlers) {
|
|
759
|
-
try {
|
|
760
|
-
handler(error);
|
|
761
|
-
}
|
|
762
|
-
catch (handlerError) {
|
|
763
|
-
// Ignore handler errors to prevent cascade failures
|
|
764
|
-
console.error("Error handler error:", handlerError);
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
//# sourceMappingURL=claude-code-output-processor.js.map
|