@phren/cli 0.3.25 → 0.3.26

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.
@@ -20,6 +20,9 @@ export declare function processTable(now?: number): Promise<ProcessRow[]>;
20
20
  export declare function isCodexDaemon(command: string): boolean;
21
21
  /** When a pane's agent started: its oldest foreground process. */
22
22
  export declare function startedAt(rows: ProcessRow[], pids: number[]): number | undefined;
23
+ /** A direct `codex resume <id>` launch, including its shell/npm wrapper.
24
+ * This is only a hint: the command line survives later /new and /resume. */
25
+ export declare function resumedConversation(rows: ProcessRow[], pids: number[]): string | undefined;
23
26
  /** True when this process runs under a Codex app-server daemon: a hook the
24
27
  * daemon ran carries the environment of the pane that started the daemon,
25
28
  * which is not the pane of the conversation it reports. */
@@ -55,5 +58,6 @@ export declare function sameDirectory(a: unknown, b: unknown): Promise<boolean>;
55
58
  export interface CodexPaneStart {
56
59
  key: string;
57
60
  start: number;
61
+ resumed?: string;
58
62
  }
59
63
  export declare function assignDaemonConversation(here: DaemonRollout[], self: CodexPaneStart, claimed: Set<string>, rivals: CodexPaneStart[], now?: number): string | undefined;
@@ -51,6 +51,15 @@ export function startedAt(rows, pids) {
51
51
  const times = rows.filter(row => pids.includes(row.pid)).map(row => row.startedAt);
52
52
  return times.length ? Math.min(...times) : undefined;
53
53
  }
54
+ /** A direct `codex resume <id>` launch, including its shell/npm wrapper.
55
+ * This is only a hint: the command line survives later /new and /resume. */
56
+ export function resumedConversation(rows, pids) {
57
+ const ids = new Set(rows.filter(row => pids.includes(row.pid)).flatMap(row => {
58
+ const match = /^(?:(?:\S*\/)?(?:sh|bash|zsh|node)\s+)?(?:\S*\/)?codex\s+resume\s+([a-f0-9-]{36})(?:\s|$)/i.exec(row.command);
59
+ return match && sessionId.safeParse(match[1]).success ? [match[1]] : [];
60
+ }));
61
+ return ids.size === 1 ? [...ids][0] : undefined;
62
+ }
54
63
  /** True when this process runs under a Codex app-server daemon: a hook the
55
64
  * daemon ran carries the environment of the pane that started the daemon,
56
65
  * which is not the pane of the conversation it reports. */
@@ -179,7 +188,15 @@ export function assignDaemonConversation(here, self, claimed, rivals, now = Date
179
188
  if (!rivals.length) {
180
189
  const pool = after(self.start);
181
190
  const held = pool.filter(r => r.held);
182
- return (held.length ? held : pool).sort((a, b) => b.activeAt - a.activeAt)[0]?.id;
191
+ const current = (held.length ? held : pool).sort((a, b) => b.activeAt - a.activeAt)[0]?.id;
192
+ if (current)
193
+ return current;
194
+ // An explicit resume may name a conversation older than this TUI. Only
195
+ // use it when the daemon holds exactly one unclaimed conversation that
196
+ // has advanced since launch, and no other pane in this folder competes.
197
+ // A later /new above takes precedence over the stale launch arguments.
198
+ const resumed = open.filter(r => r.held && r.activeAt >= self.start && r.activeAt <= now + 60_000);
199
+ return resumed.length === 1 && resumed[0].id === self.resumed ? self.resumed : undefined;
183
200
  }
184
201
  const order = [...rivals, self].sort((a, b) => b.start - a.start || (a.key < b.key ? 1 : a.key > b.key ? -1 : 0));
185
202
  const taken = new Set();
@@ -14,7 +14,7 @@ import { tabActivityKey } from "./tab-activity.js";
14
14
  import { intervalFromEnv } from "./limits.js";
15
15
  import { countHerdr, countIdentity } from "./metrics.js";
16
16
  import { phrenStoreRoot } from "./transcripts.js";
17
- import { assignDaemonConversation, daemonRollouts, processTable, sameDirectory, startedAt } from "./codex-daemon.js";
17
+ import { assignDaemonConversation, daemonRollouts, processTable, resumedConversation, sameDirectory, startedAt } from "./codex-daemon.js";
18
18
  import { codexServers } from "./codex-servers.js";
19
19
  // terminal.ts and terminal-tmux.ts import this module, so it reaches them at
20
20
  // call time; a static import back would be an import cycle.
@@ -503,7 +503,7 @@ async function codexDaemonIdentity(server, pane, pids) {
503
503
  if (peerStart !== undefined)
504
504
  rivals.push({ key: String(peer.pane_id), start: peerStart });
505
505
  }
506
- return { sessionId: assignDaemonConversation(here, { key: String(pane.pane_id), start }, claimed, rivals), known };
506
+ return { sessionId: assignDaemonConversation(here, { key: String(pane.pane_id), start, resumed: resumedConversation(rows, pids) }, claimed, rivals), known };
507
507
  }
508
508
  /** The Codex pane that shows `session`, for a lifecycle callback that ran
509
509
  * inside a Codex daemon and so cannot name its pane. Falls back to the only
@@ -25352,7 +25352,7 @@ var init_package_metadata = __esm({
25352
25352
  __dirname = path15.dirname(fileURLToPath2(import.meta.url));
25353
25353
  ROOT = path15.join(__dirname, "..");
25354
25354
  PACKAGE_JSON_PATH = path15.join(ROOT, "package.json");
25355
- BUNDLED_VERSION = true ? "0.3.25" : "0.0.0";
25355
+ BUNDLED_VERSION = true ? "0.3.26" : "0.0.0";
25356
25356
  PACKAGE_JSON = readPackageJson();
25357
25357
  PACKAGE_NAME = PACKAGE_JSON.name || "phren";
25358
25358
  VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
@@ -29492,6 +29492,13 @@ function startedAt(rows, pids) {
29492
29492
  const times = rows.filter((row) => pids.includes(row.pid)).map((row) => row.startedAt);
29493
29493
  return times.length ? Math.min(...times) : void 0;
29494
29494
  }
29495
+ function resumedConversation(rows, pids) {
29496
+ const ids = new Set(rows.filter((row) => pids.includes(row.pid)).flatMap((row) => {
29497
+ const match = /^(?:(?:\S*\/)?(?:sh|bash|zsh|node)\s+)?(?:\S*\/)?codex\s+resume\s+([a-f0-9-]{36})(?:\s|$)/i.exec(row.command);
29498
+ return match && sessionId.safeParse(match[1]).success ? [match[1]] : [];
29499
+ }));
29500
+ return ids.size === 1 ? [...ids][0] : void 0;
29501
+ }
29495
29502
  async function underCodexDaemon(env = process.env, pid = process.pid) {
29496
29503
  if (env.CODEX_INTERNAL_APP_SERVER_REMOTE_CONTROL_DISABLED !== void 0) return true;
29497
29504
  if (process.platform === "win32") return false;
@@ -29585,7 +29592,10 @@ function assignDaemonConversation(here, self, claimed, rivals, now = Date.now())
29585
29592
  if (!rivals.length) {
29586
29593
  const pool2 = after(self.start);
29587
29594
  const held = pool2.filter((r) => r.held);
29588
- return (held.length ? held : pool2).sort((a, b) => b.activeAt - a.activeAt)[0]?.id;
29595
+ const current2 = (held.length ? held : pool2).sort((a, b) => b.activeAt - a.activeAt)[0]?.id;
29596
+ if (current2) return current2;
29597
+ const resumed = open25.filter((r) => r.held && r.activeAt >= self.start && r.activeAt <= now + 6e4);
29598
+ return resumed.length === 1 && resumed[0].id === self.resumed ? self.resumed : void 0;
29589
29599
  }
29590
29600
  const order = [...rivals, self].sort((a, b) => b.start - a.start || (a.key < b.key ? 1 : a.key > b.key ? -1 : 0));
29591
29601
  const taken = /* @__PURE__ */ new Set();
@@ -36018,7 +36028,7 @@ async function codexDaemonIdentity(server, pane, pids) {
36018
36028
  const peerStart = startedAt(rows, peerPids);
36019
36029
  if (peerStart !== void 0) rivals.push({ key: String(peer.pane_id), start: peerStart });
36020
36030
  }
36021
- return { sessionId: assignDaemonConversation(here, { key: String(pane.pane_id), start }, claimed, rivals), known: known2 };
36031
+ return { sessionId: assignDaemonConversation(here, { key: String(pane.pane_id), start, resumed: resumedConversation(rows, pids) }, claimed, rivals), known: known2 };
36022
36032
  }
36023
36033
  async function paneForCodexSession(server, session, cwd) {
36024
36034
  const s = await snapshot(server);
@@ -61120,7 +61130,7 @@ async function readSecret(prompt) {
61120
61130
  // src/bridge/hook-main.ts
61121
61131
  init_utils_helpers();
61122
61132
  Object.assign(process.env, nonInteractiveGitEnv());
61123
- runBridge(process.argv.slice(2), "0.3.25").then((code) => {
61133
+ runBridge(process.argv.slice(2), "0.3.26").then((code) => {
61124
61134
  process.exitCode = code;
61125
61135
  }).catch((error62) => {
61126
61136
  console.error(error62 instanceof Error ? error62.message : "Phren Hook failed.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {