tycono 0.1.96-beta.52 → 0.1.96-beta.54
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/bin/tycono.ts +14 -25
- package/package.json +1 -1
- package/src/api/src/create-server.ts +4 -1
package/bin/tycono.ts
CHANGED
|
@@ -221,40 +221,29 @@ async function startServerForTui(): Promise<void> {
|
|
|
221
221
|
const origStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
222
222
|
const origLog = (...args: unknown[]) => origStdoutWrite(args.join(' ') + '\n');
|
|
223
223
|
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
console.
|
|
228
|
-
console.
|
|
229
|
-
console.
|
|
230
|
-
|
|
224
|
+
// Redirect ALL output to log file BEFORE importing server code
|
|
225
|
+
// Ink needs stdout clean — server must not write to stdout or stderr
|
|
226
|
+
console.log = (...a: unknown[]) => { logStream.write(a.join(' ') + '\n'); };
|
|
227
|
+
console.error = (...a: unknown[]) => { logStream.write(a.join(' ') + '\n'); };
|
|
228
|
+
console.warn = (...a: unknown[]) => { logStream.write(a.join(' ') + '\n'); };
|
|
229
|
+
console.info = (...a: unknown[]) => { logStream.write(a.join(' ') + '\n'); };
|
|
230
|
+
// Also redirect stderr.write — some code uses process.stderr directly
|
|
231
|
+
const origStderrWrite = process.stderr.write.bind(process.stderr);
|
|
232
|
+
process.stderr.write = ((chunk: any, ...args: any[]) => {
|
|
233
|
+
logStream.write(typeof chunk === 'string' ? chunk : chunk.toString());
|
|
234
|
+
return true;
|
|
235
|
+
}) as any;
|
|
231
236
|
|
|
232
237
|
const { createHttpServer } = await import('../src/api/src/create-server.js');
|
|
233
238
|
const server = createHttpServer();
|
|
234
239
|
|
|
235
|
-
const host = process.env.HOST || '0.0.0.0';
|
|
236
|
-
|
|
237
240
|
await new Promise<void>((resolve) => {
|
|
238
|
-
server.listen(port,
|
|
241
|
+
server.listen(port, '0.0.0.0', () => resolve());
|
|
239
242
|
});
|
|
240
243
|
|
|
241
244
|
origLog(` API server started on port ${port}`);
|
|
242
245
|
origLog(` Logs: ${logFile}`);
|
|
243
246
|
|
|
244
|
-
// Now hijack stdout.write AFTER server started but BEFORE Ink
|
|
245
|
-
// Block non-Ink output from reaching terminal
|
|
246
|
-
// Ink always writes ANSI escape sequences — server text output doesn't
|
|
247
|
-
process.stdout.write = ((chunk: any, ...args: any[]) => {
|
|
248
|
-
const str = typeof chunk === 'string' ? chunk : chunk.toString();
|
|
249
|
-
// Ink output: contains ANSI CSI sequences
|
|
250
|
-
if (str.includes('\x1b[') || str.includes('\x1b(')) {
|
|
251
|
-
return origStdoutWrite(chunk, ...args);
|
|
252
|
-
}
|
|
253
|
-
// Non-Ink (server log leaked): redirect to file
|
|
254
|
-
logStream.write(str);
|
|
255
|
-
return true;
|
|
256
|
-
}) as any;
|
|
257
|
-
|
|
258
247
|
// Graceful shutdown
|
|
259
248
|
const shutdown = () => {
|
|
260
249
|
server.close(() => process.exit(0));
|
|
@@ -263,7 +252,7 @@ async function startServerForTui(): Promise<void> {
|
|
|
263
252
|
process.on('SIGINT', shutdown);
|
|
264
253
|
process.on('SIGTERM', shutdown);
|
|
265
254
|
|
|
266
|
-
// Start TUI
|
|
255
|
+
// Start TUI — stdout.write is NOT intercepted, Ink has full control
|
|
267
256
|
const { startTui } = await import('../src/tui/index.tsx');
|
|
268
257
|
await startTui({ port });
|
|
269
258
|
}
|
package/package.json
CHANGED
|
@@ -227,8 +227,11 @@ export function createExpressApp(): express.Application {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
app.use((err: Error, req: express.Request, res: express.Response, _next: express.NextFunction) => {
|
|
230
|
-
console.error(`[ERROR] ${req.method} ${req.url} — ${err.message}`);
|
|
231
230
|
const status = err.name === 'FileNotFoundError' ? 404 : 500;
|
|
231
|
+
// Log errors to stderr (not stdout — Ink needs stdout clean)
|
|
232
|
+
if (status >= 500) {
|
|
233
|
+
process.stderr.write(`[ERROR] ${req.method} ${req.url} — ${err.message}\n`);
|
|
234
|
+
}
|
|
232
235
|
res.status(status).json({ error: err.message });
|
|
233
236
|
});
|
|
234
237
|
|