instar 0.7.49 → 0.7.50

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.
@@ -63,6 +63,15 @@ export function createRoutes(ctx) {
63
63
  heapUsed: Math.round(mem.heapUsed / 1024 / 1024),
64
64
  heapTotal: Math.round(mem.heapTotal / 1024 / 1024),
65
65
  };
66
+ // System-wide memory state
67
+ const os = require('node:os');
68
+ const totalMem = os.totalmem();
69
+ const freeMem = os.freemem();
70
+ base.systemMemory = {
71
+ totalGB: Math.round(totalMem / (1024 ** 3) * 10) / 10,
72
+ freeGB: Math.round(freeMem / (1024 ** 3) * 10) / 10,
73
+ usedPercent: Math.round(((totalMem - freeMem) / totalMem) * 1000) / 10,
74
+ };
66
75
  // Job health summary
67
76
  if (ctx.scheduler) {
68
77
  const jobs = ctx.scheduler.getJobs();
@@ -1411,9 +1420,58 @@ export function createRoutes(ctx) {
1411
1420
  }
1412
1421
  }
1413
1422
  else if (ctx.sessionManager) {
1414
- // No telegram adapter with routing inject directly into any mapped session
1415
- ctx.sessionManager.injectTelegramMessage(`${ctx.config.projectName}-interface`, topicId, text);
1416
- res.json({ ok: true, forwarded: true, method: 'direct-inject' });
1423
+ // No TelegramAdapter (--no-telegram mode)route using topic-session registry on disk
1424
+ const registryPath = path.join(ctx.config.stateDir, 'topic-session-registry.json');
1425
+ let targetSession = null;
1426
+ try {
1427
+ if (fs.existsSync(registryPath)) {
1428
+ const registry = JSON.parse(fs.readFileSync(registryPath, 'utf-8'));
1429
+ targetSession = registry.topicToSession?.[String(topicId)] ?? null;
1430
+ }
1431
+ }
1432
+ catch { /* registry read failed — fall through to spawn */ }
1433
+ if (targetSession && ctx.sessionManager.isSessionAlive(targetSession)) {
1434
+ // Session exists and is alive — inject message
1435
+ console.log(`[telegram-forward] Injecting into ${targetSession}: "${text.slice(0, 80)}"`);
1436
+ ctx.sessionManager.injectTelegramMessage(targetSession, topicId, text);
1437
+ res.json({ ok: true, forwarded: true, method: 'registry-inject', session: targetSession });
1438
+ }
1439
+ else {
1440
+ // No session or session dead — auto-spawn a new one
1441
+ const topicName = targetSession || `topic-${topicId}`;
1442
+ console.log(`[telegram-forward] No live session for topic ${topicId}, spawning "${topicName}"...`);
1443
+ const contextLines = [
1444
+ `This session was auto-created for Telegram topic ${topicId}.`,
1445
+ ``,
1446
+ `CRITICAL: You MUST relay your response back to Telegram after responding.`,
1447
+ `Use the relay script:`,
1448
+ ``,
1449
+ `cat <<'EOF' | .claude/scripts/telegram-reply.sh ${topicId}`,
1450
+ `Your response text here`,
1451
+ `EOF`,
1452
+ ``,
1453
+ `Strip the [telegram:${topicId}] prefix before interpreting the message.`,
1454
+ `Only relay conversational text — not tool output or internal reasoning.`,
1455
+ ];
1456
+ const tmpDir = '/tmp/instar-telegram';
1457
+ fs.mkdirSync(tmpDir, { recursive: true });
1458
+ const ctxPath = path.join(tmpDir, `ctx-${topicId}-${Date.now()}.txt`);
1459
+ fs.writeFileSync(ctxPath, contextLines.join('\n'));
1460
+ const bootstrapMessage = `[telegram:${topicId}] ${text} (IMPORTANT: Read ${ctxPath} for Telegram relay instructions — you MUST relay your response back.)`;
1461
+ ctx.sessionManager.spawnInteractiveSession(bootstrapMessage, topicName, { telegramTopicId: topicId }).then((newSessionName) => {
1462
+ // Update registry on disk
1463
+ try {
1464
+ const reg = fs.existsSync(registryPath) ? JSON.parse(fs.readFileSync(registryPath, 'utf-8')) : { topicToSession: {}, topicToName: {} };
1465
+ reg.topicToSession[String(topicId)] = newSessionName;
1466
+ fs.writeFileSync(registryPath, JSON.stringify(reg, null, 2));
1467
+ }
1468
+ catch { /* non-critical */ }
1469
+ console.log(`[telegram-forward] Spawned "${newSessionName}" for topic ${topicId}`);
1470
+ }).catch((err) => {
1471
+ console.error(`[telegram-forward] Spawn failed:`, err);
1472
+ });
1473
+ res.json({ ok: true, forwarded: true, method: 'spawn', topicName });
1474
+ }
1417
1475
  }
1418
1476
  else {
1419
1477
  res.status(503).json({ error: 'No message routing available' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "0.7.49",
3
+ "version": "0.7.50",
4
4
  "description": "Persistent autonomy infrastructure for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",