@episoda/cli 0.2.179 → 0.2.180

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.
@@ -3046,7 +3046,7 @@ var require_package = __commonJS({
3046
3046
  "package.json"(exports2, module2) {
3047
3047
  module2.exports = {
3048
3048
  name: "@episoda/cli",
3049
- version: "0.2.179",
3049
+ version: "0.2.180",
3050
3050
  description: "CLI tool for Episoda local development workflow orchestration",
3051
3051
  main: "dist/index.js",
3052
3052
  types: "dist/index.d.ts",
@@ -3072,6 +3072,7 @@ var require_package = __commonJS({
3072
3072
  author: "Episoda",
3073
3073
  license: "MIT",
3074
3074
  dependencies: {
3075
+ "@lydell/node-pty": "1.2.0-beta.3",
3075
3076
  chalk: "^4.1.2",
3076
3077
  commander: "^11.1.0",
3077
3078
  ora: "^5.4.1",
@@ -3082,8 +3083,8 @@ var require_package = __commonJS({
3082
3083
  },
3083
3084
  optionalDependencies: {
3084
3085
  "@anthropic-ai/claude-code": "^2.0.0",
3085
- "@openai/codex": "^0.86.0",
3086
- "@modelcontextprotocol/server-github": "^0.6.0"
3086
+ "@modelcontextprotocol/server-github": "^0.6.0",
3087
+ "@openai/codex": "^0.86.0"
3087
3088
  },
3088
3089
  devDependencies: {
3089
3090
  "@episoda/core": "workspace:*",
@@ -12869,6 +12870,113 @@ async function handleProjectSetup(params) {
12869
12870
  }
12870
12871
  }
12871
12872
 
12873
+ // src/daemon/handlers/pty-handler.ts
12874
+ var pty = __toESM(require("@lydell/node-pty"));
12875
+ var INACTIVITY_TIMEOUT_MS3 = 30 * 60 * 1e3;
12876
+ var sessions = /* @__PURE__ */ new Map();
12877
+ async function handlePtySpawn(payload, client) {
12878
+ const { moduleUid, agent_run_id, command, args, env, cwd, cols = 220, rows = 50 } = payload;
12879
+ if (sessions.has(agent_run_id)) {
12880
+ console.warn(`[PTY] Session already exists for agent_run_id ${agent_run_id}, ignoring spawn`);
12881
+ return;
12882
+ }
12883
+ console.log(`[PTY] Spawning PTY for ${moduleUid} / ${agent_run_id}: ${command} ${args.join(" ")}`);
12884
+ let proc;
12885
+ try {
12886
+ proc = pty.spawn(command, args, {
12887
+ name: "xterm-256color",
12888
+ cols,
12889
+ rows,
12890
+ cwd: cwd || process.cwd(),
12891
+ env: { ...process.env, ...env || {} }
12892
+ });
12893
+ } catch (err) {
12894
+ console.error(`[PTY] Failed to spawn PTY for ${agent_run_id}:`, err);
12895
+ await client.send({
12896
+ type: "pty_exit",
12897
+ moduleUid,
12898
+ agent_run_id,
12899
+ code: -1,
12900
+ durationMs: 0
12901
+ });
12902
+ return;
12903
+ }
12904
+ const session = {
12905
+ pty: proc,
12906
+ moduleUid,
12907
+ agent_run_id,
12908
+ startedAt: Date.now(),
12909
+ lastOutputAt: Date.now(),
12910
+ watchdogTimer: null
12911
+ };
12912
+ sessions.set(agent_run_id, session);
12913
+ const resetWatchdog = () => {
12914
+ session.lastOutputAt = Date.now();
12915
+ if (session.watchdogTimer) clearTimeout(session.watchdogTimer);
12916
+ session.watchdogTimer = setTimeout(() => {
12917
+ console.warn(`[PTY] Inactivity timeout for ${agent_run_id} after ${INACTIVITY_TIMEOUT_MS3 / 6e4}m \u2014 sending SIGTERM`);
12918
+ try {
12919
+ proc.kill();
12920
+ } catch {
12921
+ }
12922
+ }, INACTIVITY_TIMEOUT_MS3);
12923
+ };
12924
+ resetWatchdog();
12925
+ proc.onData((data) => {
12926
+ resetWatchdog();
12927
+ client.send({
12928
+ type: "pty_data",
12929
+ moduleUid,
12930
+ agent_run_id,
12931
+ data
12932
+ }).catch((err) => {
12933
+ console.error(`[PTY] Failed to send pty_data for ${agent_run_id}:`, err.message);
12934
+ });
12935
+ });
12936
+ proc.onExit(({ exitCode }) => {
12937
+ const durationMs = Date.now() - session.startedAt;
12938
+ if (session.watchdogTimer) clearTimeout(session.watchdogTimer);
12939
+ console.log(`[PTY] Process exited for ${agent_run_id} with code ${exitCode} after ${durationMs}ms`);
12940
+ sessions.delete(agent_run_id);
12941
+ client.send({
12942
+ type: "pty_exit",
12943
+ moduleUid,
12944
+ agent_run_id,
12945
+ code: exitCode,
12946
+ durationMs
12947
+ }).catch((err) => {
12948
+ console.error(`[PTY] Failed to send pty_exit for ${agent_run_id}:`, err.message);
12949
+ });
12950
+ });
12951
+ }
12952
+ function handlePtyResize(payload) {
12953
+ const { agent_run_id, cols, rows } = payload;
12954
+ const session = sessions.get(agent_run_id);
12955
+ if (!session) {
12956
+ console.warn(`[PTY] No session found for resize: ${agent_run_id}`);
12957
+ return;
12958
+ }
12959
+ try {
12960
+ session.pty.resize(cols, rows);
12961
+ } catch (err) {
12962
+ console.error(`[PTY] Resize error for ${agent_run_id}:`, err);
12963
+ }
12964
+ }
12965
+ function handlePtyKill(payload) {
12966
+ const { agent_run_id } = payload;
12967
+ const session = sessions.get(agent_run_id);
12968
+ if (!session) {
12969
+ console.warn(`[PTY] No session found for kill: ${agent_run_id}`);
12970
+ return;
12971
+ }
12972
+ try {
12973
+ session.pty.kill();
12974
+ } catch {
12975
+ }
12976
+ sessions.delete(agent_run_id);
12977
+ console.log(`[PTY] Killed session ${agent_run_id}`);
12978
+ }
12979
+
12872
12980
  // src/utils/dev-server.ts
12873
12981
  var import_child_process15 = require("child_process");
12874
12982
  var import_core14 = __toESM(require_dist());
@@ -13650,8 +13758,8 @@ var UpdateManager = class _UpdateManager {
13650
13758
  getActiveAgentSessionCount() {
13651
13759
  try {
13652
13760
  const agentManager = getAgentControlPlane();
13653
- const sessions = agentManager.getAllSessions();
13654
- return sessions.filter((session) => ["starting", "running", "stopping"].includes(session.status)).length;
13761
+ const sessions2 = agentManager.getAllSessions();
13762
+ return sessions2.filter((session) => ["starting", "running", "stopping"].includes(session.status)).length;
13655
13763
  } catch {
13656
13764
  return 0;
13657
13765
  }
@@ -14650,6 +14758,7 @@ var ProjectMessageRouter = class {
14650
14758
  this.registerCommandHandler(context);
14651
14759
  this.registerRemoteCommandHandler(context);
14652
14760
  this.registerTunnelCommandHandler(context);
14761
+ this.registerPtyCommandHandler(context);
14653
14762
  }
14654
14763
  registerCommandHandler({ projectId, projectPath, client, gitExecutor }) {
14655
14764
  client.on("command", async (message) => {
@@ -14898,6 +15007,30 @@ var ProjectMessageRouter = class {
14898
15007
  }
14899
15008
  });
14900
15009
  }
15010
+ // EP1441: PTY lifecycle handler
15011
+ registerPtyCommandHandler({ projectId, client }) {
15012
+ client.on("pty_spawn", async (message) => {
15013
+ if (message.type === "pty_spawn") {
15014
+ const payload = message.payload;
15015
+ console.log(`[Daemon] EP1441: Received pty_spawn for ${projectId}: ${payload.agent_run_id}`);
15016
+ client.updateActivity();
15017
+ await handlePtySpawn(payload, client);
15018
+ }
15019
+ });
15020
+ client.on("pty_resize", (message) => {
15021
+ if (message.type === "pty_resize") {
15022
+ const payload = message.payload;
15023
+ handlePtyResize(payload);
15024
+ }
15025
+ });
15026
+ client.on("pty_kill", (message) => {
15027
+ if (message.type === "pty_kill") {
15028
+ const payload = message.payload;
15029
+ console.log(`[Daemon] EP1441: Received pty_kill for agent_run_id ${payload.agent_run_id}`);
15030
+ handlePtyKill(payload);
15031
+ }
15032
+ });
15033
+ }
14901
15034
  };
14902
15035
 
14903
15036
  // src/daemon/daemon-api-client.ts