@dmsdc-ai/aigentry-telepty 0.1.73 → 0.1.75

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.
Files changed (3) hide show
  1. package/cli.js +4 -6
  2. package/daemon.js +35 -7
  3. package/package.json +1 -1
package/cli.js CHANGED
@@ -871,21 +871,19 @@ async function main() {
871
871
  const isCr = msg.data === '\r';
872
872
  if (isCr && injectQueue.length > 0) {
873
873
  // CR with pending queued text — queue CR too and flush immediately.
874
- // Prevents the busy-session bug where CR fires before queued text,
875
- // causing empty submit followed by orphaned text without Return.
876
874
  injectQueue.push(msg.data);
877
875
  if (queueFlushTimer) { clearTimeout(queueFlushTimer); queueFlushTimer = null; }
878
876
  flushInjectQueue();
879
- } else if (isCr && isIdle()) {
880
- // CR when idlewrite immediately
877
+ } else if (isCr) {
878
+ // CR always written immediately never idle-gated
881
879
  child.write(msg.data);
882
- } else if (!isCr && isIdle()) {
880
+ } else if (isIdle()) {
883
881
  // Text when idle — write immediately
884
882
  child.write(msg.data);
885
883
  promptReady = false;
886
884
  lastInjectTextTime = Date.now();
887
885
  } else {
888
- // Not idle (user typing or CLI busy) — queue for safe delivery
886
+ // Text when not idle — queue for safe delivery
889
887
  injectQueue.push(msg.data);
890
888
  scheduleIdleFlush();
891
889
  }
package/daemon.js CHANGED
@@ -342,13 +342,17 @@ app.post('/api/sessions/register', (req, res) => {
342
342
  if (backend) existing.backend = backend;
343
343
  if (cmux_workspace_id) existing.cmuxWorkspaceId = cmux_workspace_id;
344
344
  if (cmux_surface_id) existing.cmuxSurfaceId = cmux_surface_id;
345
- console.log(`[REGISTER] Re-registered session ${session_id} (updated metadata)`);
346
- return res.status(200).json({ session_id, type: 'wrapped', command: existing.command, cwd: existing.cwd, reregistered: true });
345
+ if (req.body.delivery_type) existing.type = req.body.delivery_type;
346
+ if (req.body.delivery_endpoint) existing.deliveryEndpoint = req.body.delivery_endpoint;
347
+ if (req.body.delivery_type === 'aterm') existing.ready = true;
348
+ console.log(`[REGISTER] Re-registered session ${session_id} (type: ${existing.type}, updated metadata)`);
349
+ return res.status(200).json({ session_id, type: existing.type, command: existing.command, cwd: existing.cwd, reregistered: true });
347
350
  }
348
351
 
352
+ const { delivery_type, delivery_endpoint } = req.body;
349
353
  const sessionRecord = {
350
354
  id: session_id,
351
- type: 'wrapped',
355
+ type: delivery_type || 'wrapped',
352
356
  ptyProcess: null,
353
357
  ownerWs: null,
354
358
  command: command || 'wrapped',
@@ -356,12 +360,13 @@ app.post('/api/sessions/register', (req, res) => {
356
360
  backend: backend || 'kitty',
357
361
  cmuxWorkspaceId: cmux_workspace_id || null,
358
362
  cmuxSurfaceId: cmux_surface_id || null,
363
+ deliveryEndpoint: delivery_endpoint || null,
359
364
  createdAt: new Date().toISOString(),
360
365
  lastActivityAt: new Date().toISOString(),
361
366
  clients: new Set(),
362
367
  isClosing: false,
363
368
  outputRing: [],
364
- ready: false,
369
+ ready: delivery_type === 'aterm', // aterm sessions are always ready (aterm manages readiness)
365
370
  };
366
371
  // Check for existing session with same base alias and emit replaced event
367
372
  const baseAlias = session_id.replace(/-\d+$/, '');
@@ -421,7 +426,8 @@ app.get('/api/sessions', (req, res) => {
421
426
  lastActivityAt: session.lastActivityAt || null,
422
427
  idleSeconds,
423
428
  active_clients: session.clients.size,
424
- ready: session.ready || false
429
+ ready: session.ready || false,
430
+ deliveryEndpoint: session.deliveryEndpoint || null
425
431
  };
426
432
  });
427
433
  if (idleGt !== null) {
@@ -884,7 +890,19 @@ app.post('/api/sessions/:id/inject', (req, res) => {
884
890
  // Always inject text WITHOUT \r first, then send \r separately after delay
885
891
  // This two-step approach works for ALL CLIs (claude, codex, gemini)
886
892
  function writeToSession(data) {
887
- if (session.type === 'wrapped') {
893
+ if (session.type === 'aterm' && session.deliveryEndpoint) {
894
+ // Route to aterm PtyManager — fire-and-forget, aterm handles delivery
895
+ try {
896
+ const url = session.deliveryEndpoint;
897
+ fetch(url, {
898
+ method: 'POST',
899
+ headers: { 'Content-Type': 'application/json' },
900
+ body: JSON.stringify({ text: data, session_id: id }),
901
+ signal: AbortSignal.timeout(5000)
902
+ }).catch(() => {});
903
+ return true;
904
+ } catch { return false; }
905
+ } else if (session.type === 'wrapped') {
888
906
  if (session.ownerWs && session.ownerWs.readyState === 1) {
889
907
  session.ownerWs.send(JSON.stringify({ type: 'inject', data }));
890
908
  return true;
@@ -897,7 +915,17 @@ app.post('/api/sessions/:id/inject', (req, res) => {
897
915
  }
898
916
 
899
917
  let submitResult = null;
900
- if (session.type === 'wrapped') {
918
+ if (session.type === 'aterm' && session.deliveryEndpoint) {
919
+ // aterm sessions: deliver text + CR via aterm PtyManager endpoint
920
+ const wsOk = writeToSession(finalPrompt);
921
+ if (!wsOk) {
922
+ return res.status(503).json({ error: 'aterm endpoint not reachable' });
923
+ }
924
+ if (!no_enter) {
925
+ setTimeout(() => writeToSession('\r'), 300);
926
+ submitResult = { deferred: true, strategy: 'aterm_endpoint' };
927
+ }
928
+ } else if (session.type === 'wrapped') {
901
929
  // For wrapped sessions: try cmux send (daemon-level auto-detect),
902
930
  // then kitty send-text (bypasses allow bridge queue),
903
931
  // then WS as fallback, then submit via consistent path for CR.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmsdc-ai/aigentry-telepty",
3
- "version": "0.1.73",
3
+ "version": "0.1.75",
4
4
  "main": "daemon.js",
5
5
  "bin": {
6
6
  "aigentry-telepty": "install.js",