@phren/cli 0.3.9 → 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.
- package/dist/bridge/fanout-messages.js +2 -2
- package/dist/bridge/fanouts.js +1 -1
- package/dist/bridge/resources.d.ts +119 -0
- package/dist/bridge/resources.js +298 -0
- package/dist/bridge/server-overview.d.ts +8 -2
- package/dist/bridge/server-overview.js +16 -3
- package/dist/bridge/server-routes.d.ts +4 -1
- package/dist/bridge/server-routes.js +34 -3
- package/dist/bridge/server.js +5 -2
- package/dist/bridge/transcript-claude.js +5 -0
- package/dist/bridge/transcript-codex.d.ts +20 -0
- package/dist/bridge/transcript-codex.js +177 -2
- package/dist/bridge/transcripts.js +6 -1
- package/dist/bridge/usage.d.ts +36 -20
- package/dist/bridge/usage.js +163 -301
- package/dist/bridge-hook.mjs +1132 -800
- package/dist/cli-registry.d.ts +2 -0
- package/dist/cli-registry.js +13 -0
- package/dist/computers/command.d.ts +6 -0
- package/dist/computers/command.js +152 -0
- package/dist/computers/mcp.d.ts +1 -0
- package/dist/computers/mcp.js +97 -0
- package/dist/computers/read.d.ts +85 -0
- package/dist/computers/read.js +177 -0
- package/dist/entrypoint.js +10 -0
- package/dist/fanout/adapters/claude.js +15 -2
- package/dist/fanout/adapters/types.d.ts +6 -0
- package/dist/fanout/launcher.d.ts +5 -1
- package/dist/fanout/launcher.js +34 -3
- package/dist/fanout/picker.js +3 -2
- package/dist/fanout/usage.js +1 -1
- package/dist/modules/registry.js +3 -3
- package/package.json +1 -1
- package/starter/global/skills/conductor/SKILL.md +4 -0
- package/starter/global/skills/fanout/SKILL.md +9 -0
package/dist/fanout/launcher.js
CHANGED
|
@@ -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
|
|
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);
|
package/dist/fanout/picker.js
CHANGED
|
@@ -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
|
-
|
|
43
|
-
const
|
|
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;
|
package/dist/fanout/usage.js
CHANGED
|
@@ -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
|
}
|
package/dist/modules/registry.js
CHANGED
|
@@ -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
|
@@ -95,6 +95,10 @@ otherwise use and report the remote configured default. Each remote lead owns
|
|
|
95
95
|
its local checkouts, fanout and provider rate limits. Where installed, local
|
|
96
96
|
workers use the fanout wrapper's `scripts/run.sh --provider codex|opencode
|
|
97
97
|
--label --worktree [--model] [--mode]` contract and parent-bound manifests.
|
|
98
|
+
Tell every lead the same: a worker started any other way (its own `opencode
|
|
99
|
+
run` or `codex exec`, a launch script, nohup) has no manifest, so the phone and
|
|
100
|
+
you cannot see, resume or review it. Workers that exist only as processes do
|
|
101
|
+
not count as dispatched.
|
|
98
102
|
|
|
99
103
|
Prefer handing work to a session that already owns the project and is idle or
|
|
100
104
|
doing related work; call `hand_off` in full or `phren_admin(action: "hand_off",
|
|
@@ -8,10 +8,19 @@ Give each writer a separate worktree and a concrete output to validate. A brief
|
|
|
8
8
|
should name the goal, owned files, constraints, tests, and completion report.
|
|
9
9
|
Include relevant findings and exact review issues; avoid sending the whole chat.
|
|
10
10
|
|
|
11
|
+
Start every worker through `phren fanout run`, never with `opencode run`,
|
|
12
|
+
`codex exec` or `claude -p` of your own (directly, in a loop, or from a script
|
|
13
|
+
with nohup). `phren fanout run` writes the job manifest that ties the worker to
|
|
14
|
+
your conversation; a worker without one is invisible to the phone, the
|
|
15
|
+
conductor and `phren fanout list`, and nothing can resume, review or archive it.
|
|
16
|
+
|
|
11
17
|
Enable Hook and fanout, then use `phren fanout run --tier narrow|wide|review
|
|
12
18
|
--label LABEL --worktree PATH < brief.txt`. The command chooses an eligible
|
|
13
19
|
provider using current usage, errors and concurrency. Use `phren fanout usage`
|
|
14
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.
|
|
15
24
|
|
|
16
25
|
Use `phren fanout list` to inspect jobs, `phren fanout resume JOB < feedback.txt`
|
|
17
26
|
to send a bounded follow-up, and `phren fanout review JOB` for a review round.
|