@sweny-ai/core 0.1.94 → 0.1.95
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.
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { Observer } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Create an observer that prints each tool call's input and output to stderr
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* "why" invisible.
|
|
7
|
-
*
|
|
4
|
+
* in a human-readable form. Useful when debugging a node that fails or routes
|
|
5
|
+
* unexpectedly — the default human output only shows step transitions,
|
|
6
|
+
* leaving "why" invisible.
|
|
7
|
+
*
|
|
8
|
+
* Emission strategy: print the full call list on `node:exit` rather than per
|
|
9
|
+
* `tool:call`/`tool:result` event. The reason: the executor's tool:call and
|
|
10
|
+
* tool:result events fire only for skill-registered tools, not for the
|
|
11
|
+
* Claude Code subprocess's built-in tools (Bash, Read, Edit, etc.). Those
|
|
12
|
+
* built-in tools — the ones agents actually use most — land in
|
|
13
|
+
* `result.toolCalls` only after the node completes. Walking result.toolCalls
|
|
14
|
+
* on node:exit covers both kinds and avoids partial visibility.
|
|
15
|
+
*
|
|
16
|
+
* Inputs and outputs are truncated; use `--stream` for full untruncated
|
|
17
|
+
* NDJSON.
|
|
8
18
|
*/
|
|
9
19
|
export declare function createVerboseToolObserver(): Observer;
|
|
@@ -22,24 +22,40 @@ function fmt(v) {
|
|
|
22
22
|
function indent(s) {
|
|
23
23
|
return s.split("\n").join("\n ");
|
|
24
24
|
}
|
|
25
|
+
function printCall(call) {
|
|
26
|
+
process.stderr.write(` ${chalk.dim("→")} ${chalk.cyan(call.tool)} ${chalk.dim("(input)")}\n`);
|
|
27
|
+
process.stderr.write(` ${chalk.dim(indent(truncate(fmt(call.input))))}\n`);
|
|
28
|
+
const status = call.status === "error" ? chalk.red("(output, error)") : chalk.dim("(output)");
|
|
29
|
+
process.stderr.write(` ${chalk.dim("←")} ${chalk.cyan(call.tool)} ${status}\n`);
|
|
30
|
+
process.stderr.write(` ${chalk.dim(indent(truncate(fmt(call.output))))}\n`);
|
|
31
|
+
}
|
|
25
32
|
/**
|
|
26
33
|
* Create an observer that prints each tool call's input and output to stderr
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* "why" invisible.
|
|
30
|
-
*
|
|
34
|
+
* in a human-readable form. Useful when debugging a node that fails or routes
|
|
35
|
+
* unexpectedly — the default human output only shows step transitions,
|
|
36
|
+
* leaving "why" invisible.
|
|
37
|
+
*
|
|
38
|
+
* Emission strategy: print the full call list on `node:exit` rather than per
|
|
39
|
+
* `tool:call`/`tool:result` event. The reason: the executor's tool:call and
|
|
40
|
+
* tool:result events fire only for skill-registered tools, not for the
|
|
41
|
+
* Claude Code subprocess's built-in tools (Bash, Read, Edit, etc.). Those
|
|
42
|
+
* built-in tools — the ones agents actually use most — land in
|
|
43
|
+
* `result.toolCalls` only after the node completes. Walking result.toolCalls
|
|
44
|
+
* on node:exit covers both kinds and avoids partial visibility.
|
|
45
|
+
*
|
|
46
|
+
* Inputs and outputs are truncated; use `--stream` for full untruncated
|
|
47
|
+
* NDJSON.
|
|
31
48
|
*/
|
|
32
49
|
export function createVerboseToolObserver() {
|
|
33
50
|
return (event) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
break;
|
|
51
|
+
if (event.type !== "node:exit")
|
|
52
|
+
return;
|
|
53
|
+
const calls = event.result.toolCalls;
|
|
54
|
+
if (calls.length === 0)
|
|
55
|
+
return;
|
|
56
|
+
process.stderr.write(` ${chalk.bold.dim(`${event.node}: ${calls.length} tool call${calls.length === 1 ? "" : "s"}`)}\n`);
|
|
57
|
+
for (const call of calls) {
|
|
58
|
+
printCall(call);
|
|
43
59
|
}
|
|
44
60
|
};
|
|
45
61
|
}
|