@phren/cli 0.3.10 → 0.3.11

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.
@@ -39,11 +39,37 @@ export function swiftBuildCount() {
39
39
  const output = execFileSync("ps", ["-axo", "comm="], { encoding: "utf8", timeout: 5_000 });
40
40
  return output.split("\n").filter(line => path.basename(line.trim()) === "xcodebuild").length;
41
41
  }
42
+ /** The nearest codex or claude process above this one. Each agent sets its
43
+ * own id for the commands it runs and inherits the other's, so a Claude
44
+ * started from Codex has both; the process tree says which one launched. */
45
+ export function nearestAgent(pid = process.ppid) {
46
+ if (process.platform === "win32")
47
+ return undefined;
48
+ for (let depth = 0; depth < 16 && pid > 1; depth++) {
49
+ let row;
50
+ try {
51
+ row = execFileSync("ps", ["-o", "ppid=,comm=", "-p", String(pid)], { encoding: "utf8", timeout: 2_000 }).trim();
52
+ }
53
+ catch {
54
+ return undefined;
55
+ }
56
+ const match = /^(\d+)\s+(.+)$/.exec(row);
57
+ if (!match)
58
+ return undefined;
59
+ const name = path.basename(match[2].trim());
60
+ if (name === "claude")
61
+ return "claude";
62
+ if (name === "codex" || name.startsWith("codex-"))
63
+ return "codex";
64
+ pid = Number(match[1]);
65
+ }
66
+ return undefined;
67
+ }
42
68
  export function writeManifest(job, manifest) {
43
69
  atomicWriteText(path.join(job, "manifest.json"), JSON.stringify(manifestSchema.parse(manifest)) + "\n");
44
70
  fs.chmodSync(path.join(job, "manifest.json"), 0o600);
45
71
  }
46
- export function createJob(options, env = process.env) {
72
+ export function createJob(options, env = process.env, nearest = nearestAgent) {
47
73
  if (!options.label.trim() || options.label.length > 200)
48
74
  throw new Error("Choose a label of 1 to 200 characters.");
49
75
  const worktree = fs.realpathSync(options.worktree);
@@ -53,7 +79,10 @@ export function createJob(options, env = process.env) {
53
79
  const root = jobsRoot(options.store), job = path.join(root, id);
54
80
  fs.mkdirSync(job, { recursive: true, mode: 0o700 });
55
81
  fs.chmodSync(root, 0o700);
56
- const codexParent = uuid(env.CODEX_THREAD_ID || env.CODEX_SESSION_ID), claudeParent = uuid(env.CLAUDE_CODE_SESSION_ID);
82
+ const claudeParent = uuid(env.CLAUDE_CODE_SESSION_ID);
83
+ let codexParent = uuid(env.CODEX_THREAD_ID || env.CODEX_SESSION_ID);
84
+ if (codexParent && claudeParent && nearest() === "claude")
85
+ codexParent = undefined;
57
86
  const now = new Date().toISOString();
58
87
  const manifest = { schemaVersion: 1, id, provider: options.provider, taskLabel: options.label,
59
88
  cwd: worktree, worktree, model: options.model, eventLog: "events.jsonl", createdAt: now, startedAt: now, updatedAt: now,
@@ -77,6 +106,7 @@ export async function launch(options, reservation = createJob(options)) {
77
106
  stdio: ["pipe", "pipe", "pipe"], detached: process.platform !== "win32",
78
107
  });
79
108
  let pending = "", stderr = "", cancelled = false;
109
+ let refused;
80
110
  const watchdog = new LoopWatchdog();
81
111
  const kill = () => { try {
82
112
  if (process.platform !== "win32" && child.pid)
@@ -103,6 +133,7 @@ export async function launch(options, reservation = createJob(options)) {
103
133
  const event = JSON.parse(line);
104
134
  watchdog.observe(event);
105
135
  record(adapter.session(event));
136
+ refused ??= adapter.refusal?.(event);
106
137
  }
107
138
  catch { /* Partial or non-JSON provider output. */ }
108
139
  }
@@ -143,7 +174,7 @@ export async function launch(options, reservation = createJob(options)) {
143
174
  process.off(signal, cancel);
144
175
  fs.closeSync(out);
145
176
  fs.closeSync(err);
146
- const blockedFile = path.join(job, "blocked.json"), refusal = stderrRefusal(stderr);
177
+ const blockedFile = path.join(job, "blocked.json"), refusal = refused ?? stderrRefusal(stderr);
147
178
  if (refusal && !fs.existsSync(blockedFile))
148
179
  atomicWriteText(blockedFile, JSON.stringify({ ...refusal, at: new Date().toISOString() }));
149
180
  const blocked = fs.existsSync(blockedFile);
@@ -39,8 +39,9 @@ export function pick(options) {
39
39
  const account = options.usage.find(a => a.source === key);
40
40
  const model = candidate.model.split("/").slice(1).join("/");
41
41
  const windowPrefix = `opencode-go:${model.replace(/[^A-Za-z0-9]+/g, "_").replace(/^_|_$/g, "")}:`;
42
- const windows = account?.windows.filter(w => key !== "opencode-go" || !model || w.id.startsWith(windowPrefix) || w.id.startsWith(`${model}/`) || w.id === model) ?? [];
43
- const exhausted = windows.find(w => (w.usedPercent ?? 0) >= policy.threshold && (!w.resetsAt || !Number.isFinite(Date.parse(w.resetsAt)) || Date.parse(w.resetsAt) > now));
42
+ // Go's plan windows (`opencode-go:plan:*`) bind every Go model.
43
+ const windows = account?.windows.filter(w => key !== "opencode-go" || !model || w.id.startsWith("opencode-go:plan:") || w.id.startsWith(windowPrefix) || w.id.startsWith(`${model}/`) || w.id === model) ?? [];
44
+ const exhausted = windows.find(w => (w.limited || (w.usedPercent ?? 0) >= policy.threshold) && (!w.resetsAt || !Number.isFinite(Date.parse(w.resetsAt)) || Date.parse(w.resetsAt) > now));
44
45
  if (exhausted) {
45
46
  rejected.push(`${key} ${exhausted.name} at ${exhausted.usedPercent} percent`);
46
47
  continue;
@@ -5,7 +5,7 @@ import { hookRequest } from "../bridge/client.js";
5
5
  import { AccountUsageReader } from "../bridge/usage.js";
6
6
  export async function readUsage() {
7
7
  try {
8
- const value = await hookRequest("/v1/usage?sources=codex,claude,opencode,opencode-go,openrouter", undefined, undefined, 2_000);
8
+ const value = await hookRequest("/v1/usage?sources=codex,claude,opencode,opencode-go,openrouter&goPlan=1", undefined, undefined, 2_000);
9
9
  if (Array.isArray(value.accounts))
10
10
  return value.accounts;
11
11
  }
@@ -69,7 +69,7 @@ export const BUILTIN_MODULES = [
69
69
  cliCommands: [
70
70
  "bridge", "bridge install", "bridge update", "bridge uninstall", "bridge rollback", "bridge status",
71
71
  "bridge doctor", "bridge usage", "bridge usage-statusline", "bridge hook", "bridge serve", "bridge ssh", "pair",
72
- "bridge fanouts archive", "canary",
72
+ "bridge fanouts archive", "canary", "computers", "computers mcp", "usage",
73
73
  ],
74
74
  agentHooks: [
75
75
  { agents: ["codex", "claude"], events: ["SessionStart", "UserPromptSubmit", "Stop", "PermissionRequest"], handler: "bridge-hook.mjs hook <agent>" },
@@ -80,7 +80,7 @@ export const BUILTIN_MODULES = [
80
80
  ...routes("GET", [
81
81
  "/v1/health", "/v1/health/details", "/v1/health/peers", "/v1/muxes", "/v1/activity", "/v1/metrics", "/v1/web-servers", "/v1/simulators",
82
82
  "/v1/simulators/screenshot", "/v1/simulators/apps", "/v1/files", "/v1/models", "/v1/projects/files",
83
- "/v1/uploads/image", "/v1/files/range", "/v1/usage", "/v1/push/status", "/v1/projects/locate", "/v1/projects/repos",
83
+ "/v1/uploads/image", "/v1/files/range", "/v1/usage", "/v1/resources", "/v1/push/status", "/v1/projects/locate", "/v1/projects/repos",
84
84
  "/v1/workspaces", "/v1/workspaces/panes", "/v1/transcripts/blob", "/v1/transcripts/history",
85
85
  "/v1/subagents", "/v1/subagents/transcript", "/v1/subagents/messages",
86
86
  ]),
@@ -96,7 +96,7 @@ export const BUILTIN_MODULES = [
96
96
  capabilities: [
97
97
  "hook", "transcript", "progress", "images", "prompt", "stop", "terminal", "shell", "herdr",
98
98
  "webServers", "webPreview", "activity", "approvals", "questions", "accountUsage", "providers",
99
- "files", "repositoryFiles", "subagents", "sideQuestions", "approvalPush", "simulators", "overviewStream", "speech", "speechTimestamps", "transcribe", "promptOnce",
99
+ "files", "repositoryFiles", "subagents", "sideQuestions", "approvalPush", "simulators", "overviewStream", "speech", "speechTimestamps", "transcribe", "promptOnce", "resources",
100
100
  ],
101
101
  storeFiles: [".runtime/sessions/opencode-*.events.jsonl", ".runtime/approvals/opencode-*.json"],
102
102
  localFiles: ["<bridge>/installed.json", "<bridge>/versions/**", "<bridge>/current", "<bridge>/dispatch", "<bridge>/computer-id", "<bridge>/canary.json", "<bridge>/canary-daily"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,6 +18,9 @@ Enable Hook and fanout, then use `phren fanout run --tier narrow|wide|review
18
18
  --label LABEL --worktree PATH < brief.txt`. The command chooses an eligible
19
19
  provider using current usage, errors and concurrency. Use `phren fanout usage`
20
20
  to inspect it, and `--provider`/`--model` for an explicit choice subject to caps.
21
+ A Codex agent that wants a Claude worker or reviewer runs `phren fanout run
22
+ --provider claude --model opus` (add `--tier review` for a read-only one); it
23
+ shows under the Codex conversation like any other worker.
21
24
 
22
25
  Use `phren fanout list` to inspect jobs, `phren fanout resume JOB < feedback.txt`
23
26
  to send a bounded follow-up, and `phren fanout review JOB` for a review round.