Skip to content

Commit 705f505

Browse files
committed
Bump version to 0.2.19-fork in package.json. Enhance debugging in InternalClient and SubprocessCLITransport by logging raw JSONL messages written to stdin when debug mode is enabled. This improves traceability of data being sent to subprocesses, aiding in debugging and monitoring of the SDK's behavior.
1 parent b68ff8d commit 705f505

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botanicastudios/claude-code-sdk-ts",
3-
"version": "0.2.18-fork",
3+
"version": "0.2.19-fork",
44
"description": "Unofficial TypeScript port of the official Python Claude Code SDK",
55
"type": "module",
66
"main": "dist/index.cjs",

src/_internal/client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,18 @@ export class InternalClient {
104104
}
105105
};
106106

107+
const jsonlString = JSON.stringify(jsonlMessage) + '\n';
108+
107109
this.debugLog(
108110
'DEBUG: Writing JSONL to stdin:',
109111
JSON.stringify(jsonlMessage).substring(0, 100) + '...'
110112
);
111113

112-
this.transport.writeToStdin(JSON.stringify(jsonlMessage) + '\n');
114+
if (this.options.debug) {
115+
this.debugLog('DEBUG stdin (raw):', jsonlString);
116+
}
117+
118+
this.transport.writeToStdin(jsonlString);
113119

114120
this.debugLog('DEBUG: Successfully wrote JSONL message to stdin');
115121
}

src/_internal/transport/subprocess-cli.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,18 @@ export class SubprocessCLITransport {
102102
}
103103
};
104104

105+
const jsonlString = JSON.stringify(jsonlMessage) + '\n';
106+
105107
this.debugLog(
106108
'DEBUG: [Transport] Writing JSONL to process stdin:',
107109
JSON.stringify(jsonlMessage).substring(0, 150) + '...'
108110
);
109111

110-
this.process.stdin.write(JSON.stringify(jsonlMessage) + '\n');
112+
if (this.options.debug) {
113+
this.debugLog('DEBUG stdin (raw):', jsonlString);
114+
}
115+
116+
this.process.stdin.write(jsonlString);
111117

112118
this.debugLog('DEBUG: [Transport] Successfully wrote JSONL to stdin');
113119
} else {
@@ -116,6 +122,11 @@ export class SubprocessCLITransport {
116122
'DEBUG: [Transport] Writing raw data to stdin:',
117123
data.substring(0, 100) + '...'
118124
);
125+
126+
if (this.options.debug) {
127+
this.debugLog('DEBUG stdin (raw):', data);
128+
}
129+
119130
this.process.stdin.write(data);
120131
}
121132
} catch (error) {
@@ -355,6 +366,20 @@ export class SubprocessCLITransport {
355366
this.debugLog('DEBUG: Process exited:', { code, signal });
356367
});
357368

369+
// Log all stderr output when debug is enabled
370+
if (this.process.stderr && this.options.debug) {
371+
this.process.stderr.on('data', (chunk: Buffer) => {
372+
this.debugLog('DEBUG stderr (raw):', chunk.toString());
373+
});
374+
}
375+
376+
// Log all stdout output when debug is enabled
377+
if (this.process.stdout && this.options.debug) {
378+
this.process.stdout.on('data', (chunk: Buffer) => {
379+
this.debugLog('DEBUG stdout (raw):', chunk.toString());
380+
});
381+
}
382+
358383
// Send prompt via stdin
359384
if (this.process.stdin) {
360385
if (this.streamingMode) {
@@ -367,6 +392,8 @@ export class SubprocessCLITransport {
367392
}
368393
};
369394

395+
const initialJsonlString = JSON.stringify(jsonlMessage) + '\n';
396+
370397
this.debugLog(
371398
'DEBUG: [Transport] Sending initial JSONL message in streaming mode',
372399
{
@@ -378,12 +405,22 @@ export class SubprocessCLITransport {
378405
}
379406
);
380407

381-
this.process.stdin.write(JSON.stringify(jsonlMessage) + '\n');
408+
if (this.options.debug) {
409+
this.debugLog('DEBUG stdin (raw):', initialJsonlString);
410+
}
411+
412+
this.process.stdin.write(initialJsonlString);
382413
// Keep stdin open for potential streaming input and for keepAlive behavior
383414
// stdin will be closed when we receive a result message (if keepAlive=false) or explicitly via end()
384415
} else {
385416
// For simple queries, send as plain text and close stdin
386-
this.process.stdin.write(this.prompt + '\n');
417+
const promptString = this.prompt + '\n';
418+
419+
if (this.options.debug) {
420+
this.debugLog('DEBUG stdin (raw):', promptString);
421+
}
422+
423+
this.process.stdin.write(promptString);
387424
this.process.stdin.end();
388425
}
389426
}

0 commit comments

Comments
 (0)