aegisai-harness 0.75.0 → 0.76.0

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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to AegisAi Harness are documented here.
4
4
 
5
- ## [0.75.0] - 2026-11-24
5
+ ## [0.76.0] - 2026-11-25
6
6
 
7
7
  ### Fixed
8
8
  - Installation: Windows installer now preflights Node.js 22.13+ with actionable messages; launcher no longer hides npm failures, uses `--omit=dev`, and records a dependency marker. Inno uninstall removes stale `node_modules`/lockfiles; `install.ps1` preserves `data/` and handles GitHub source zips.
package/README.md CHANGED
@@ -10,7 +10,7 @@ A **feature-rich, local-only AI agent harness** — OpenCode-class runtime, but
10
10
  offline-first: no cloud dependencies, no telemetry. 66 milestones, ~200 modules,
11
11
  257 tests, CI green.
12
12
 
13
- > Status: v0.75.0 (see [ROADMAP.md](./ROADMAP.md)).
13
+ > Status: v0.76.0 (see [ROADMAP.md](./ROADMAP.md)).
14
14
  > **Successor to [aegisai-next](https://github.com/user6811992/aegisai-next)** — that project is deprecated; all features have been ported here.
15
15
  > **Live docs:** https://user6811992.github.io/aegisai-harness/
16
16
 
package/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # AegisAi Harness — agent-readable catalog
2
2
 
3
- A feature-rich, local-only AI agent harness. CLI-first, offline-first. v0.75.0.
3
+ A feature-rich, local-only AI agent harness. CLI-first, offline-first. v0.76.0.
4
4
 
5
5
  ## Capabilities
6
6
  - Multi-backend LLM adapter (Ollama + OpenAI-compatible + 18 providers)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aegisai-harness",
3
- "version": "0.75.0",
3
+ "version": "0.76.0",
4
4
  "description": "AegisAi Harness — feature-rich, local-only AI agent harness",
5
5
  "type": "commonjs",
6
6
  "main": "src/index.js",
@@ -4,13 +4,13 @@
4
4
  [Setup]
5
5
  AppId={{8F3D1B2A-6C4E-4B9A-9D21-AE615A010001}}
6
6
  AppName=AegisAi Harness
7
- AppVersion=0.75.0
7
+ AppVersion=0.76.0
8
8
  AppPublisher=AegisAi
9
9
  AppPublisherURL=https://github.com/user6811992/aegisai-harness
10
10
  DefaultDirName={autopf}\AegisAiHarness
11
11
  DefaultGroupName=AegisAi Harness
12
12
  OutputDir=..\..\dist
13
- OutputBaseFilename=AegisAi-Harness-0.75.0-Setup
13
+ OutputBaseFilename=AegisAi-Harness-0.76.0-Setup
14
14
  Compression=lzma2
15
15
  SolidCompression=yes
16
16
  PrivilegesRequired=lowest
package/public/app.js CHANGED
@@ -480,6 +480,7 @@ function App() {
480
480
  setMessages((m) => [...m, { role: 'assistant', content: '' }]);
481
481
  try {
482
482
  const r = await apiFetch('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: text, stream: true }) });
483
+ if (r.status === 401) { window.dispatchEvent(new CustomEvent('aegisai-unauthorized')); throw new Error('unauthorized'); }
483
484
  if (!r.ok) throw new Error('HTTP ' + r.status);
484
485
  const reader = r.body.getReader();
485
486
  const decoder = new TextDecoder();
@@ -504,12 +505,23 @@ function App() {
504
505
  });
505
506
  } else if (data.type === 'tool_call') {
506
507
  toast('Tool: ' + data.name, 'info');
508
+ } else if (data.type === 'error') {
509
+ throw new Error(data.message || 'stream error');
507
510
  } else if (data.type === 'done') {
508
511
  if (data.toolLog) setToolLog(data.toolLog);
512
+ // Fall back to the authoritative reply if no token frames arrived.
513
+ if (!fullReply && data.reply) {
514
+ fullReply = data.reply;
515
+ setMessages((m) => {
516
+ const updated = [...m];
517
+ updated[updated.length - 1] = { role: 'assistant', content: fullReply };
518
+ return updated;
519
+ });
520
+ }
509
521
  updateCtx();
510
522
  toast('Response received', 'success');
511
523
  }
512
- } catch (e) {}
524
+ } catch (e) { if (e && e.message && e.message !== 'Unexpected end of JSON input') throw e; }
513
525
  }
514
526
  }
515
527
  } catch (e) {
@@ -601,7 +613,24 @@ function App() {
601
613
  }
602
614
 
603
615
  if (view === 'onboarding') {
604
- return html`<${OnboardingWizard} onComplete=${() => setView('chat')} />`;
616
+ return html`
617
+ <div class="app" data-theme=${theme}>
618
+ <${ToastContainer} />
619
+ ${needAuth ? html`
620
+ <div class="modal-backdrop">
621
+ <div class="modal" onClick=${(e) => e.stopPropagation()}>
622
+ <h2>Authentication Required</h2>
623
+ <p>The server requires an access token. Enter it below.</p>
624
+ <input type="password" value=${tokenInput} onInput=${(e) => setTokenInput(e.target.value)} placeholder="Access token" style="width:100%" />
625
+ <div class="modal-actions">
626
+ <button class="btn-primary" onClick=${() => { setAuthToken(tokenInput.trim()); setNeedAuth(false); setTokenInput(''); toast('Token set', 'success'); updateCtx(); }}>Use Token</button>
627
+ </div>
628
+ </div>
629
+ </div>
630
+ ` : null}
631
+ <${OnboardingWizard} onComplete=${() => { setNeedAuth(false); setView('chat'); updateCtx(); }} />
632
+ </div>
633
+ `;
605
634
  }
606
635
 
607
636
  return html`
package/src/index.js CHANGED
@@ -114,6 +114,7 @@ async function main() {
114
114
  tui.addMessage('assistant', (r.final && r.final.final) || '(no reply)');
115
115
  } catch (e) { tui.addMessage('assistant', 'Error: ' + (e.message || e)); }
116
116
  });
117
+ tui.on('exit', () => { try { process.exit(0); } catch (e) {} });
117
118
  return;
118
119
  }
119
120
 
@@ -159,6 +160,24 @@ async function main() {
159
160
  const sessionToolLogs = new Map(); // session id -> last tool log (for /api/context)
160
161
  const sessionUpdated = new Map(); // session id -> ISO timestamp
161
162
  const warnMissing = (v) => String(v || 'default');
163
+
164
+ // Session persistence: in-memory cache + SQLite fallback so history survives restarts.
165
+ let dbMod = null;
166
+ function dbSafe() { if (!dbMod) { try { dbMod = require('./storage/db'); dbMod.get(); } catch (e) { dbMod = null; } } return dbMod; }
167
+ function rememberSession(sid, msgs) {
168
+ sessions.set(sid, msgs);
169
+ sessionUpdated.set(sid, new Date().toISOString());
170
+ try {
171
+ const firstUser = (msgs || []).find((m) => m.role === 'user');
172
+ const d = dbSafe();
173
+ if (d) d.saveSession({ id: sid, title: firstUser ? String(firstUser.content || '').slice(0, 60) : sid, messages: msgs });
174
+ } catch (e) {}
175
+ }
176
+ function getSessionMessages(sid) {
177
+ if (sessions.has(sid)) return sessions.get(sid);
178
+ try { const d = dbSafe(); const s = d && d.getSession(sid); if (s) { sessions.set(sid, s.messages || []); return s.messages || []; } } catch (e) {}
179
+ return [];
180
+ }
162
181
  const pendingActions = new Map();
163
182
 
164
183
  function readJson(req) {
@@ -183,8 +202,16 @@ async function main() {
183
202
  }
184
203
 
185
204
  const handleRequest = async (req, res) => {
186
- // CORS headers (needed for browser fetch with application/json content type)
187
- res.setHeader('Access-Control-Allow-Origin', '*');
205
+ // CORS: never wildcard. Reflect only same-host origins; reject cross-site.
206
+ const origin = req.headers.origin;
207
+ const hostHdr = req.headers.host || '';
208
+ if (origin) {
209
+ let originHost = '';
210
+ try { originHost = new URL(origin).host; } catch (e) { originHost = ''; }
211
+ if (originHost && originHost !== hostHdr) { sendJson(res, 403, { error: 'cross-origin request blocked' }); return; }
212
+ res.setHeader('Access-Control-Allow-Origin', origin);
213
+ res.setHeader('Vary', 'Origin');
214
+ }
188
215
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
189
216
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
190
217
  if (req.method === 'OPTIONS') { res.writeHead(204); res.end(); return; }
@@ -216,32 +243,37 @@ async function main() {
216
243
  if (req.method === 'POST' && req.url.split('?')[0] === '/api/chat') {
217
244
  const parsed = await readJson(req);
218
245
  const sid = parsed.sessionId || 'default';
219
- const history = Array.isArray(parsed.history) ? parsed.history : (sessions.get(sid) || []);
246
+ const history = Array.isArray(parsed.history) ? parsed.history : getSessionMessages(sid);
220
247
  const stream = parsed.stream === true;
221
248
  const autoApprove = process.env.AEGISAI_WEB_AUTO_APPROVE === 'true';
222
249
  if (stream) {
223
- res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*' });
250
+ res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' });
224
251
  let fullReply = '';
225
- const result = await runAgent({
226
- model: parsed.model || process.env.AEGISAI_MODEL || 'llama3.2:3b',
227
- messages: history.concat([{ role: 'user', content: parsed.message || '' }]),
228
- projectRoot: process.cwd(),
229
- onEvent: (e) => {
230
- if (e.type === 'token') { fullReply += (e.content || ''); res.write('data: ' + JSON.stringify({ type: 'token', content: e.content || '' }) + '\n\n'); }
231
- else if (e.type === 'tool_call') { res.write('data: ' + JSON.stringify({ type: 'tool_call', name: e.name, args: e.args }) + '\n\n'); }
232
- else if (e.type === 'tool_result') { res.write('data: ' + JSON.stringify({ type: 'tool_result', preview: (e.preview || '').slice(0, 200) }) + '\n\n'); }
233
- else if (e.type === 'status') { res.write('data: ' + JSON.stringify({ type: 'status', message: e.message }) + '\n\n'); }
234
- },
235
- autoApprove,
236
- approvalHandler: async () => false,
237
- });
238
- const reply = (result.final && result.final.final) || fullReply;
239
- const updated = history.concat([{ role: 'user', content: parsed.message || '' }, { role: 'assistant', content: reply }]);
240
- sessions.set(sid, updated);
241
- sessionToolLogs.set(sid, result.toolLog || []);
242
- sessionUpdated.set(sid, new Date().toISOString());
243
- res.write('data: ' + JSON.stringify({ type: 'done', reply, toolLog: result.toolLog || [] }) + '\n\n');
244
- res.end();
252
+ const writeEvent = (obj) => { try { if (!res.writableEnded && !res.destroyed) res.write('data: ' + JSON.stringify(obj) + '\n\n'); } catch (e) {} };
253
+ try {
254
+ const result = await runAgent({
255
+ model: parsed.model || process.env.AEGISAI_MODEL || 'llama3.2:3b',
256
+ messages: history.concat([{ role: 'user', content: parsed.message || '' }]),
257
+ projectRoot: process.cwd(),
258
+ onEvent: (e) => {
259
+ if (e.type === 'token') { fullReply += (e.content || ''); writeEvent({ type: 'token', content: e.content || '' }); }
260
+ else if (e.type === 'tool_call') { writeEvent({ type: 'tool_call', name: e.name, args: e.args }); }
261
+ else if (e.type === 'tool_result') { writeEvent({ type: 'tool_result', preview: (e.preview || '').slice(0, 200) }); }
262
+ else if (e.type === 'status') { writeEvent({ type: 'status', message: e.message }); }
263
+ },
264
+ autoApprove,
265
+ approvalHandler: async () => false,
266
+ });
267
+ const reply = (result.final && result.final.final) || fullReply;
268
+ const updated = history.concat([{ role: 'user', content: parsed.message || '' }, { role: 'assistant', content: reply }]);
269
+ rememberSession(sid, updated);
270
+ sessionToolLogs.set(sid, result.toolLog || []);
271
+ writeEvent({ type: 'done', reply, toolLog: result.toolLog || [] });
272
+ } catch (err) {
273
+ // Headers already sent: emit an SSE error frame instead of a JSON 500.
274
+ writeEvent({ type: 'error', message: String((err && err.message) || err) });
275
+ }
276
+ try { if (!res.writableEnded) res.end(); } catch (e) {}
245
277
  return;
246
278
  }
247
279
  const result = await runAgent({
@@ -255,7 +287,7 @@ async function main() {
255
287
  });
256
288
  const reply = (result.final && result.final.final) || '';
257
289
  const updated = history.concat([{ role: 'user', content: parsed.message || '' }, { role: 'assistant', content: reply }]);
258
- sessions.set(sid, updated);
290
+ rememberSession(sid, updated);
259
291
  sessionToolLogs.set(sid, result.toolLog || []);
260
292
  sessionUpdated.set(sid, new Date().toISOString());
261
293
  sendJson(res, 200, { reply, toolLog: result.toolLog || [], pendingActions: pendingActions.get(sid) || [] });
@@ -309,7 +341,7 @@ async function main() {
309
341
  if (req.method === 'POST' && req.url.split('?')[0] === '/api/export') {
310
342
  const parsed = await readJson(req);
311
343
  const sid = parsed.sessionId || 'default';
312
- const history = sessions.get(sid) || [];
344
+ const history = getSessionMessages(sid);
313
345
  const format = parsed.format || 'markdown';
314
346
  const meta = { title: parsed.title, model: process.env.AEGISAI_MODEL || 'llama3.2:3b', date: new Date().toISOString() };
315
347
  const result = require('./conversation_export').exportToFile(history.map((m) => ({ role: m.role, content: m.content })), meta, format, null);
@@ -451,21 +483,29 @@ async function main() {
451
483
  const wantId = u.searchParams.get('id');
452
484
  if (wantId) {
453
485
  const sid = warnMissing(wantId);
454
- const msgs = sessions.get(sid) || [];
486
+ const msgs = getSessionMessages(sid);
455
487
  sendJson(res, 200, { id: sid, messages: msgs });
456
488
  return;
457
489
  }
458
- const list = [];
490
+ const byId = new Map();
491
+ // Persisted sessions first (survive restarts).
492
+ try {
493
+ const d = dbSafe();
494
+ for (const s of (d ? d.listSessions() : [])) {
495
+ byId.set(s.id, { id: s.id, title: s.title || s.id, messages: (s.messages || []).length, updated: s.updated || null });
496
+ }
497
+ } catch (e) {}
498
+ // Merge live in-memory sessions (fresher).
459
499
  for (const [id, msgs] of sessions.entries()) {
460
500
  const firstUser = (msgs || []).find((m) => m.role === 'user');
461
- list.push({
501
+ byId.set(id, {
462
502
  id,
463
503
  title: firstUser ? String(firstUser.content || '').slice(0, 60) : id,
464
504
  messages: (msgs || []).length,
465
- updated: sessionUpdated.get(id) || null,
505
+ updated: sessionUpdated.get(id) || (byId.get(id) || {}).updated || null,
466
506
  });
467
507
  }
468
- list.sort((a, b) => String(b.updated || '').localeCompare(String(a.updated || '')));
508
+ const list = Array.from(byId.values()).sort((a, b) => String(b.updated || '').localeCompare(String(a.updated || '')));
469
509
  sendJson(res, 200, { sessions: list });
470
510
  return;
471
511
  }
@@ -565,7 +605,7 @@ async function main() {
565
605
  }
566
606
  if (req.method === 'POST' && req.url.split('?')[0] === '/api/config') {
567
607
  const parsed = await readJson(req);
568
- if (parsed.projectRootAllowlist) process.env.AEGISAI_PROJECT_ROOT_ALLOWLIST = parsed.projectRootAllowlist;
608
+ if (parsed.projectRootAllowlist !== undefined) process.env.AEGISAI_PROJECT_ROOT_ALLOWLIST = parsed.projectRootAllowlist;
569
609
  if (parsed.sttUrl !== undefined) process.env.STT_URL = parsed.sttUrl;
570
610
  if (parsed.ttsUrl !== undefined) process.env.TTS_URL = parsed.ttsUrl;
571
611
  for (const k of ['BACKEND_TYPE', 'BACKEND_URL', 'AEGISAI_MODEL', 'AEGISAI_TOKEN', 'AEGISAI_WEB_AUTO_APPROVE', 'REA_BIN', 'GHIDRA_MCP_URL', 'CRAFT_BIN']) {
@@ -654,37 +694,91 @@ async function main() {
654
694
  if (proxyFlag) {
655
695
  const http = require('http');
656
696
  const port = parseInt(process.env.AEGISAI_PROXY_PORT || '4000', 10);
697
+ const host = process.env.HOST || '127.0.0.1';
698
+ const MAX_BODY = parseInt(process.env.AEGISAI_PROXY_MAX_BODY || String(10 * 1024 * 1024), 10);
699
+ const proxyToken = () => process.env.AEGISAI_TOKEN || process.env.LOCALAI_TOKEN || '';
700
+ const sendErr = (res, status, message, type) => {
701
+ try { res.writeHead(status, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: { message, type: type || 'invalid_request_error' } })); } catch (e) {}
702
+ };
657
703
  const server = http.createServer(async (req, res) => {
658
- if (req.method === 'POST' && req.url.includes('/chat/completions')) {
704
+ const urlPath = req.url.split('?')[0];
705
+ // Auth when a token is configured.
706
+ const expected = proxyToken();
707
+ if (expected) {
708
+ const supplied = (req.headers['authorization'] || '').replace(/^Bearer\s+/i, '') || new URL(req.url, 'http://x').searchParams.get('token') || '';
709
+ if (!tokenMatches(supplied, expected)) { sendErr(res, 401, 'unauthorized', 'authentication_error'); return; }
710
+ }
711
+ if (req.method === 'GET' && (urlPath === '/v1/models' || urlPath === '/models')) {
712
+ let ids = [];
713
+ try { const r = await require('./backends').backendListModels(); ids = (r.models || []).map((m) => m.name || m); } catch (e) {}
714
+ if (!ids.length) ids = [process.env.AEGISAI_MODEL || 'llama3.2:3b'];
715
+ res.writeHead(200, { 'Content-Type': 'application/json' });
716
+ res.end(JSON.stringify({ object: 'list', data: ids.map((id) => ({ id, object: 'model', owned_by: 'aegisai' })) }));
717
+ return;
718
+ }
719
+ if (req.method === 'POST' && (urlPath === '/v1/chat/completions' || urlPath === '/chat/completions')) {
659
720
  let body = '';
660
- let aborted = false;
661
- req.on('aborted', () => { aborted = true; });
662
- req.on('close', () => { if (!req.complete) aborted = true; });
663
- req.on('data', (c) => { body += c; });
721
+ let bytes = 0;
722
+ let tooBig = false;
723
+ req.on('data', (c) => {
724
+ if (tooBig) return;
725
+ bytes += c.length;
726
+ if (bytes > MAX_BODY) { tooBig = true; sendErr(res, 413, 'request body too large'); return; }
727
+ body += c;
728
+ });
664
729
  req.on('end', async () => {
730
+ if (tooBig) return;
731
+ let parsed;
732
+ try { parsed = JSON.parse(body); } catch (e) { sendErr(res, 400, 'invalid JSON body'); return; }
733
+ const model = parsed.model || process.env.AEGISAI_MODEL || 'llama3.2:3b';
734
+ if (parsed.stream) {
735
+ let headersSent = false;
736
+ const send = (obj) => {
737
+ try {
738
+ if (!headersSent) { res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' }); headersSent = true; }
739
+ if (!res.writableEnded) res.write('data: ' + JSON.stringify(obj) + '\n\n');
740
+ } catch (e) {}
741
+ };
742
+ try {
743
+ let text = '';
744
+ await runAgent({
745
+ model,
746
+ messages: parsed.messages || [],
747
+ projectRoot: process.cwd(),
748
+ onEvent: (e) => {
749
+ if (e.type === 'token' && e.content) {
750
+ text += e.content;
751
+ send({ id: 'chatcmpl-x', object: 'chat.completion.chunk', created: Math.floor(Date.now() / 1000), model, choices: [{ index: 0, delta: { content: e.content }, finish_reason: null }] });
752
+ }
753
+ },
754
+ autoApprove: true,
755
+ });
756
+ send({ id: 'chatcmpl-x', object: 'chat.completion.chunk', created: Math.floor(Date.now() / 1000), model, choices: [{ index: 0, delta: {}, finish_reason: 'stop' }] });
757
+ try { if (!res.writableEnded) { res.write('data: [DONE]\n\n'); res.end(); } } catch (e) {}
758
+ } catch (e) {
759
+ if (!headersSent) sendErr(res, 500, String(e.message || e), 'server_error');
760
+ else { try { res.write('data: [DONE]\n\n'); res.end(); } catch (_) {} }
761
+ }
762
+ return;
763
+ }
665
764
  try {
666
- const parsed = JSON.parse(body);
667
- if (aborted) return;
668
765
  const result = await runAgent({
669
- model: parsed.model || process.env.AEGISAI_MODEL || 'llama3.2:3b',
766
+ model,
670
767
  messages: parsed.messages || [],
671
768
  projectRoot: process.cwd(),
672
769
  onEvent: () => {},
673
770
  autoApprove: true,
674
771
  });
675
- const resp = { id: 'chatcmpl-' + Date.now(), object: 'chat.completion', created: Math.floor(Date.now() / 1000), model: parsed.model, choices: [{ index: 0, message: { role: 'assistant', content: (result.final && result.final.final) || '' }, finish_reason: 'stop' }] };
772
+ const resp = { id: 'chatcmpl-' + Date.now(), object: 'chat.completion', created: Math.floor(Date.now() / 1000), model, choices: [{ index: 0, message: { role: 'assistant', content: (result.final && result.final.final) || '' }, finish_reason: 'stop' }] };
676
773
  res.writeHead(200, { 'Content-Type': 'application/json' });
677
774
  res.end(JSON.stringify(resp));
678
- } catch (e) {
679
- res.writeHead(500, { 'Content-Type': 'application/json' });
680
- res.end(JSON.stringify({ error: String(e.message || e) }));
681
- }
775
+ } catch (e) { sendErr(res, 500, String(e.message || e), 'server_error'); }
682
776
  });
683
- } else {
684
- res.writeHead(404); res.end();
777
+ return;
685
778
  }
779
+ sendErr(res, 404, 'not found', 'invalid_request_error');
686
780
  });
687
- server.listen(port, () => console.log('Proxy listening on :' + port));
781
+ server.listen(port, host, () => console.log('Proxy listening on http://' + host + ':' + port));
688
782
  return;
689
783
  }
690
784
 
package/src/storage/db.js CHANGED
@@ -167,7 +167,7 @@ function rowToSession(r) {
167
167
  try { messages = JSON.parse(r.messages || '[]'); } catch (e) { messages = []; }
168
168
  return { id: r.id, title: r.title, updated: r.updated, parent_id: r.parent_id, branch_from: r.branch_from, messages };
169
169
  }
170
- function listSessions() { return all('SELECT id, title, updated, parent_id, branch_from FROM sessions ORDER BY updated DESC').map(rowToSession); }
170
+ function listSessions() { return all('SELECT * FROM sessions ORDER BY updated DESC').map(rowToSession); }
171
171
  function getSession(id) { const row = one('SELECT * FROM sessions WHERE id = ?', [id]); return row ? rowToSession(row) : null; }
172
172
  function saveSession(s) {
173
173
  const id = s.id || ('sess_' + Date.now());
package/src/tui.js CHANGED
@@ -28,19 +28,30 @@ class Tui extends EventEmitter {
28
28
  }
29
29
  start() {
30
30
  this.running = true;
31
+ this._stopped = false;
31
32
  process.stdout.write(ANSI.hideCursor + ANSI.clear);
32
33
  this.render();
33
34
  this.rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true, prompt: '' });
34
35
  process.stdin.setRawMode && process.stdin.setRawMode(true);
35
- process.stdin.on('data', (d) => this.handleKey(d));
36
- process.on('SIGWINCH', () => this.render());
37
- process.on('SIGINT', () => this.stop());
36
+ this._onData = (d) => this.handleKey(d);
37
+ this._onResize = () => this.render();
38
+ this._onSigint = () => this.stop();
39
+ process.stdin.on('data', this._onData);
40
+ process.on('SIGWINCH', this._onResize);
41
+ process.on('SIGINT', this._onSigint);
38
42
  }
39
43
  stop() {
44
+ if (this._stopped) return;
45
+ this._stopped = true;
40
46
  this.running = false;
47
+ // Detach listeners so the process can exit after Ctrl+C.
48
+ try { if (this._onData) process.stdin.off('data', this._onData); } catch (e) {}
49
+ try { if (this._onResize) process.off('SIGWINCH', this._onResize); } catch (e) {}
50
+ try { if (this._onSigint) process.off('SIGINT', this._onSigint); } catch (e) {}
51
+ try { process.stdin.pause(); } catch (e) {}
41
52
  process.stdin.setRawMode && process.stdin.setRawMode(false);
42
53
  process.stdout.write(ANSI.showCursor + ANSI.clear + ANSI.reset);
43
- if (this.rl) this.rl.close();
54
+ if (this.rl) { try { this.rl.close(); } catch (e) {} this.rl = null; }
44
55
  this.emit('exit');
45
56
  }
46
57
  handleKey(d) {
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // src/version.js — single runtime source for the version string.
2
2
  // Kept separate from package.json so bundled/npm-installed copies behave the same.
3
- const VERSION = '0.75.0';
3
+ const VERSION = '0.76.0';
4
4
  module.exports = { VERSION, version: VERSION };