trickle-observe 0.2.92 → 0.2.93

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/dist/trace-var.js CHANGED
@@ -85,6 +85,47 @@ function initVarTracer(opts = {}) {
85
85
  if (debugMode) {
86
86
  console.log(`[trickle/vars] Variable tracing enabled → ${varsFilePath}`);
87
87
  }
88
+ // Capture console output to .trickle/console.jsonl for agent debugging
89
+ if (process.env.TRICKLE_CAPTURE_CONSOLE !== '0') {
90
+ patchConsole(dir);
91
+ }
92
+ }
93
+ /** Patch console.log/error/warn to also write to console.jsonl */
94
+ function patchConsole(dir) {
95
+ const consoleFile = path.join(dir, 'console.jsonl');
96
+ // Clear previous console log
97
+ try {
98
+ fs.writeFileSync(consoleFile, '');
99
+ }
100
+ catch {
101
+ return;
102
+ }
103
+ const origLog = console.log;
104
+ const origError = console.error;
105
+ const origWarn = console.warn;
106
+ function capture(level, args) {
107
+ try {
108
+ const message = args.map(a => typeof a === 'string' ? a : JSON.stringify(a)).join(' ');
109
+ // Skip trickle's own output
110
+ if (message.startsWith('[trickle'))
111
+ return;
112
+ const record = { level, message: message.substring(0, 500), timestamp: Date.now() };
113
+ fs.appendFileSync(consoleFile, JSON.stringify(record) + '\n');
114
+ }
115
+ catch { }
116
+ }
117
+ console.log = function (...args) {
118
+ capture('log', args);
119
+ return origLog.apply(console, args);
120
+ };
121
+ console.error = function (...args) {
122
+ capture('error', args);
123
+ return origError.apply(console, args);
124
+ };
125
+ console.warn = function (...args) {
126
+ capture('warn', args);
127
+ return origWarn.apply(console, args);
128
+ };
88
129
  }
89
130
  /**
90
131
  * Trace a variable's runtime value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trickle-observe",
3
- "version": "0.2.92",
3
+ "version": "0.2.93",
4
4
  "description": "Runtime type observability for JavaScript applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/trace-var.ts CHANGED
@@ -63,6 +63,47 @@ export function initVarTracer(opts: { debug?: boolean } = {}): void {
63
63
  if (debugMode) {
64
64
  console.log(`[trickle/vars] Variable tracing enabled → ${varsFilePath}`);
65
65
  }
66
+
67
+ // Capture console output to .trickle/console.jsonl for agent debugging
68
+ if (process.env.TRICKLE_CAPTURE_CONSOLE !== '0') {
69
+ patchConsole(dir);
70
+ }
71
+ }
72
+
73
+ /** Patch console.log/error/warn to also write to console.jsonl */
74
+ function patchConsole(dir: string): void {
75
+ const consoleFile = path.join(dir, 'console.jsonl');
76
+ // Clear previous console log
77
+ try { fs.writeFileSync(consoleFile, ''); } catch { return; }
78
+
79
+ const origLog = console.log;
80
+ const origError = console.error;
81
+ const origWarn = console.warn;
82
+
83
+ function capture(level: string, args: unknown[]): void {
84
+ try {
85
+ const message = args.map(a =>
86
+ typeof a === 'string' ? a : JSON.stringify(a)
87
+ ).join(' ');
88
+ // Skip trickle's own output
89
+ if (message.startsWith('[trickle')) return;
90
+ const record = { level, message: message.substring(0, 500), timestamp: Date.now() };
91
+ fs.appendFileSync(consoleFile, JSON.stringify(record) + '\n');
92
+ } catch {}
93
+ }
94
+
95
+ console.log = function (...args: unknown[]) {
96
+ capture('log', args);
97
+ return origLog.apply(console, args);
98
+ };
99
+ console.error = function (...args: unknown[]) {
100
+ capture('error', args);
101
+ return origError.apply(console, args);
102
+ };
103
+ console.warn = function (...args: unknown[]) {
104
+ capture('warn', args);
105
+ return origWarn.apply(console, args);
106
+ };
66
107
  }
67
108
 
68
109
  /**