@episoda/cli 0.2.196 → 0.2.198

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.196",
3049
+ version: "0.2.198",
3050
3050
  description: "CLI tool for Episoda local development workflow orchestration",
3051
3051
  main: "dist/index.js",
3052
3052
  types: "dist/index.d.ts",
@@ -12891,12 +12891,13 @@ async function handlePtySpawn(payload, client) {
12891
12891
  const { moduleUid, agent_run_id, command, args, stdin, env, cwd, cols = 220, rows = 50 } = payload;
12892
12892
  if (sessions.has(agent_run_id)) {
12893
12893
  console.warn(`[PTY] Session already exists for agent_run_id ${agent_run_id}, ignoring spawn`);
12894
- return;
12894
+ return { success: false, error: "PTY session already exists for this agent run." };
12895
12895
  }
12896
12896
  console.log(`[PTY] Spawning PTY for ${moduleUid} / ${agent_run_id}: ${command} ${args.join(" ")}`);
12897
- const bootstrap = createCredentialBootstrap(payload, agent_run_id);
12897
+ let bootstrap = null;
12898
12898
  let proc;
12899
12899
  try {
12900
+ bootstrap = createCredentialBootstrap(payload, agent_run_id);
12900
12901
  proc = pty.spawn(command, args, {
12901
12902
  name: "xterm-256color",
12902
12903
  cols,
@@ -12909,7 +12910,9 @@ async function handlePtySpawn(payload, client) {
12909
12910
  }
12910
12911
  });
12911
12912
  } catch (err) {
12912
- cleanupCredentialDirs(bootstrap.cleanupDirs);
12913
+ if (bootstrap) {
12914
+ cleanupCredentialDirs(bootstrap.cleanupDirs);
12915
+ }
12913
12916
  console.error(`[PTY] Failed to spawn PTY for ${agent_run_id}:`, err);
12914
12917
  await client.send({
12915
12918
  type: "pty_exit",
@@ -12918,7 +12921,10 @@ async function handlePtySpawn(payload, client) {
12918
12921
  code: -1,
12919
12922
  durationMs: 0
12920
12923
  });
12921
- return;
12924
+ return {
12925
+ success: false,
12926
+ error: err?.message || `Failed to spawn PTY command '${command}'`
12927
+ };
12922
12928
  }
12923
12929
  const session = {
12924
12930
  pty: proc,
@@ -12973,6 +12979,7 @@ async function handlePtySpawn(payload, client) {
12973
12979
  });
12974
12980
  syncCredentialUpdateAfterExit(session, agent_run_id, client);
12975
12981
  });
12982
+ return { success: true };
12976
12983
  }
12977
12984
  function handlePtyResize(payload) {
12978
12985
  const { agent_run_id, cols, rows } = payload;
@@ -13009,6 +13016,9 @@ function createCredentialBootstrap(payload, agentRunId) {
13009
13016
  if (!bootstrap?.oauth?.access_token) {
13010
13017
  return { env: {}, cleanupDirs: [] };
13011
13018
  }
13019
+ if (bootstrap.provider === "codex" && !bootstrap.oauth.refresh_token) {
13020
+ throw new Error("Codex PTY spawn aborted: refresh_token is missing from credential bundle. Please reconnect Codex in Settings.");
13021
+ }
13012
13022
  const baseDir = fs30.mkdtempSync(path30.join(os14.tmpdir(), `episoda-pty-${agentRunId}-`));
13013
13023
  const cleanupDirs = [baseDir];
13014
13024
  if (bootstrap.provider === "claude") {
@@ -13033,6 +13043,9 @@ function createCredentialBootstrap(payload, agentRunId) {
13033
13043
  const authPayload = {
13034
13044
  auth_mode: "chatgpt",
13035
13045
  OPENAI_API_KEY: null,
13046
+ // EP1473: Codex CLI 0.104.0+ requires last_refresh during token/model bootstrap.
13047
+ // Without it, Codex fails with "Token data is not available" before any work begins.
13048
+ last_refresh: (/* @__PURE__ */ new Date()).toISOString(),
13036
13049
  tokens: {
13037
13050
  access_token: bootstrap.oauth.access_token,
13038
13051
  refresh_token: bootstrap.oauth.refresh_token,
@@ -15150,18 +15163,35 @@ var ProjectMessageRouter = class {
15150
15163
  if (message.type === "pty_spawn") {
15151
15164
  const payload = message.payload;
15152
15165
  let resolvedPayload = payload;
15153
- if (!payload.cwd && payload.moduleUid) {
15154
- const worktreeInfo = await getWorktreeInfoForModule(payload.moduleUid);
15155
- if (worktreeInfo?.path) {
15156
- resolvedPayload = {
15157
- ...payload,
15158
- cwd: worktreeInfo.path
15159
- };
15166
+ let result = { success: false, error: "PTY spawn failed" };
15167
+ try {
15168
+ if (!payload.cwd && payload.moduleUid) {
15169
+ const worktreeInfo = await getWorktreeInfoForModule(payload.moduleUid);
15170
+ if (worktreeInfo?.path) {
15171
+ resolvedPayload = {
15172
+ ...payload,
15173
+ cwd: worktreeInfo.path
15174
+ };
15175
+ }
15160
15176
  }
15177
+ console.log(`[Daemon] EP1441: Received pty_spawn for ${projectId}: ${payload.agent_run_id}`);
15178
+ client.updateActivity();
15179
+ result = await handlePtySpawn(resolvedPayload, client);
15180
+ } catch (error) {
15181
+ result = {
15182
+ success: false,
15183
+ error: error instanceof Error ? error.message : String(error)
15184
+ };
15185
+ console.error(`[Daemon] EP1471: PTY spawn failed for ${payload.agent_run_id}:`, error);
15161
15186
  }
15162
- console.log(`[Daemon] EP1441: Received pty_spawn for ${projectId}: ${payload.agent_run_id}`);
15163
- client.updateActivity();
15164
- await handlePtySpawn(resolvedPayload, client);
15187
+ await client.send({
15188
+ type: "pty_spawn_ack",
15189
+ requestId: message.id,
15190
+ moduleUid: resolvedPayload.moduleUid,
15191
+ agent_run_id: resolvedPayload.agent_run_id,
15192
+ success: result.success,
15193
+ error: result.error
15194
+ });
15165
15195
  }
15166
15196
  });
15167
15197
  client.on("pty_resize", (message) => {