@monoes/monomindcli 1.10.39 → 1.10.40

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.
@@ -1005,6 +1005,53 @@ export async function startServer({ port = 4242, projectDir, openBrowser = true
1005
1005
  return;
1006
1006
  }
1007
1007
 
1008
+ // ---------------------------------------------------------- GET /api/session-errors
1009
+ if (req.method === 'GET' && url === '/api/session-errors') {
1010
+ const qs = new URL(req.url, 'http://localhost').searchParams;
1011
+ const d = path.resolve(qs.get('dir') || projectDir || process.cwd());
1012
+ const sessionId = qs.get('id') || '';
1013
+ const slug = d.replace(/\//g, '-');
1014
+ const projectClaudeDir = path.join(os.homedir(), '.claude', 'projects', slug);
1015
+ try {
1016
+ const files = fs.readdirSync(projectClaudeDir).filter(f => f.endsWith('.jsonl'));
1017
+ let fp = null;
1018
+ // Find the file matching sessionId
1019
+ for (const f of files) {
1020
+ if (f.includes(sessionId) || sessionId === f.replace('.jsonl', '')) { fp = path.join(projectClaudeDir, f); break; }
1021
+ }
1022
+ if (!fp) {
1023
+ // fallback: find by scanning
1024
+ for (const f of files) {
1025
+ const raw = fs.readFileSync(path.join(projectClaudeDir, f), 'utf8');
1026
+ const lines = raw.trim().split('\n').filter(Boolean);
1027
+ if (lines.length > 0) {
1028
+ try { const first = JSON.parse(lines[0]); if (first.sessionId === sessionId) { fp = path.join(projectClaudeDir, f); break; } } catch {}
1029
+ }
1030
+ }
1031
+ }
1032
+ if (!fp) { res.writeHead(404); res.end(JSON.stringify({ errors: [] })); return; }
1033
+ const raw = fs.readFileSync(fp, 'utf8');
1034
+ const lines = raw.trim().split('\n').filter(Boolean);
1035
+ const errors = [];
1036
+ for (const line of lines) {
1037
+ try {
1038
+ const obj = JSON.parse(line);
1039
+ const content = obj.message?.content;
1040
+ if (!Array.isArray(content)) continue;
1041
+ for (const block of content) {
1042
+ if (block.type === 'tool_result' && block.is_error) {
1043
+ const errText = Array.isArray(block.content) ? block.content.map(c => c.text || '').join('') : String(block.content || '');
1044
+ if (errText) errors.push({ toolUseId: block.tool_use_id || '', text: errText.slice(0, 500) });
1045
+ }
1046
+ }
1047
+ } catch {}
1048
+ }
1049
+ res.writeHead(200, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' });
1050
+ res.end(JSON.stringify({ errors: errors.slice(0, 50) }));
1051
+ } catch (err) { res.writeHead(500); res.end(JSON.stringify({ errors: [], error: err.message })); }
1052
+ return;
1053
+ }
1054
+
1008
1055
  // ---------------------------------------------------------- GET /api/events-stream (SSE)
1009
1056
  if (req.method === 'GET' && url.startsWith('/api/events-stream')) {
1010
1057
  const qs = new URL(req.url, 'http://localhost').searchParams;