@sweny-ai/core 0.1.94 → 0.1.96

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
- * Create an observer that prints each tool call's input and output to stderr
4
- * inline, in a human-readable format. Useful when debugging a node that's
5
- * failing — the default human output only shows step transitions, leaving
6
- * "why" invisible. Inputs and outputs are truncated to keep the log readable;
7
- * use `--stream` for the full untruncated NDJSON.
3
+ * Create an observer that prints, on `node:exit`:
4
+ * 1. Every tool call's input and output (truncated).
5
+ * 2. The node's structured output (`result.data`) — the payload that
6
+ * conditional edges route on. Without this, "validate → notify_halt"
7
+ * with no failing checks looks like a paradox; with it, you can see
8
+ * that the node emitted `{ status: "fail" }` and root-cause the wrong
9
+ * decision.
10
+ *
11
+ * Both kinds of tools are covered (skill-registered AND Claude Code's
12
+ * built-in Bash/Read/Edit/Write), because `result.toolCalls` is populated
13
+ * after the node completes regardless of how the call was dispatched.
14
+ *
15
+ * Truncation defaults to 4000 chars per side. Override with the
16
+ * `SWENY_VERBOSE_TRUNCATE` env var for ad-hoc debugging. Use `--stream` for
17
+ * the full untruncated NDJSON.
8
18
  */
9
19
  export declare function createVerboseToolObserver(): Observer;
@@ -1,5 +1,8 @@
1
1
  import chalk from "chalk";
2
- const TRUNCATE = 1200;
2
+ // Default truncation, large enough to fit a 14-item validation checklist JSON
3
+ // without losing the bottom (passed/failed totals). Overridable via env var
4
+ // for ad-hoc debugging when even this isn't enough.
5
+ const TRUNCATE = Number.parseInt(process.env.SWENY_VERBOSE_TRUNCATE ?? "4000", 10) || 4000;
3
6
  function truncate(s) {
4
7
  return s.length > TRUNCATE
5
8
  ? `${s.slice(0, TRUNCATE)}\n ${chalk.dim(`… [${s.length - TRUNCATE} more chars]`)}`
@@ -22,24 +25,46 @@ function fmt(v) {
22
25
  function indent(s) {
23
26
  return s.split("\n").join("\n ");
24
27
  }
28
+ function printCall(call) {
29
+ process.stderr.write(` ${chalk.dim("→")} ${chalk.cyan(call.tool)} ${chalk.dim("(input)")}\n`);
30
+ process.stderr.write(` ${chalk.dim(indent(truncate(fmt(call.input))))}\n`);
31
+ const status = call.status === "error" ? chalk.red("(output, error)") : chalk.dim("(output)");
32
+ process.stderr.write(` ${chalk.dim("←")} ${chalk.cyan(call.tool)} ${status}\n`);
33
+ process.stderr.write(` ${chalk.dim(indent(truncate(fmt(call.output))))}\n`);
34
+ }
35
+ function printData(node, data) {
36
+ if (!data || Object.keys(data).length === 0)
37
+ return;
38
+ process.stderr.write(` ${chalk.bold.dim(`${node}: output`)}\n`);
39
+ process.stderr.write(` ${chalk.dim(indent(truncate(fmt(data))))}\n`);
40
+ }
25
41
  /**
26
- * Create an observer that prints each tool call's input and output to stderr
27
- * inline, in a human-readable format. Useful when debugging a node that's
28
- * failing — the default human output only shows step transitions, leaving
29
- * "why" invisible. Inputs and outputs are truncated to keep the log readable;
30
- * use `--stream` for the full untruncated NDJSON.
42
+ * Create an observer that prints, on `node:exit`:
43
+ * 1. Every tool call's input and output (truncated).
44
+ * 2. The node's structured output (`result.data`) — the payload that
45
+ * conditional edges route on. Without this, "validate → notify_halt"
46
+ * with no failing checks looks like a paradox; with it, you can see
47
+ * that the node emitted `{ status: "fail" }` and root-cause the wrong
48
+ * decision.
49
+ *
50
+ * Both kinds of tools are covered (skill-registered AND Claude Code's
51
+ * built-in Bash/Read/Edit/Write), because `result.toolCalls` is populated
52
+ * after the node completes regardless of how the call was dispatched.
53
+ *
54
+ * Truncation defaults to 4000 chars per side. Override with the
55
+ * `SWENY_VERBOSE_TRUNCATE` env var for ad-hoc debugging. Use `--stream` for
56
+ * the full untruncated NDJSON.
31
57
  */
32
58
  export function createVerboseToolObserver() {
33
59
  return (event) => {
34
- switch (event.type) {
35
- case "tool:call":
36
- process.stderr.write(` ${chalk.dim("→")} ${chalk.cyan(event.tool)} ${chalk.dim("(input)")}\n`);
37
- process.stderr.write(` ${chalk.dim(indent(truncate(fmt(event.input))))}\n`);
38
- break;
39
- case "tool:result":
40
- process.stderr.write(` ${chalk.dim("←")} ${chalk.cyan(event.tool)} ${chalk.dim("(output)")}\n`);
41
- process.stderr.write(` ${chalk.dim(indent(truncate(fmt(event.output))))}\n`);
42
- break;
60
+ if (event.type !== "node:exit")
61
+ return;
62
+ const calls = event.result.toolCalls;
63
+ if (calls.length > 0) {
64
+ process.stderr.write(` ${chalk.bold.dim(`${event.node}: ${calls.length} tool call${calls.length === 1 ? "" : "s"}`)}\n`);
65
+ for (const call of calls)
66
+ printCall(call);
43
67
  }
68
+ printData(event.node, event.result.data);
44
69
  };
45
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sweny-ai/core",
3
- "version": "0.1.94",
3
+ "version": "0.1.96",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "sweny": "./dist/cli/main.js"