@phren/cli 0.3.10 → 0.3.12
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/agent-hook-stores.d.ts +3 -0
- package/dist/bridge/agent-hook-stores.js +5 -0
- package/dist/bridge/agent-hooks.d.ts +159 -5
- package/dist/bridge/agent-hooks.js +663 -49
- package/dist/bridge/approval-summary.d.ts +16 -0
- package/dist/bridge/approval-summary.js +133 -0
- package/dist/bridge/authority-command.d.ts +20 -0
- package/dist/bridge/authority-command.js +120 -0
- package/dist/bridge/authority.d.ts +223 -0
- package/dist/bridge/authority.js +231 -0
- package/dist/bridge/claude-account-setup.d.ts +14 -0
- package/dist/bridge/claude-account-setup.js +69 -0
- package/dist/bridge/claude-accounts.d.ts +49 -0
- package/dist/bridge/claude-accounts.js +195 -0
- package/dist/bridge/code-routes.js +2 -2
- package/dist/bridge/codex-app-server.d.ts +144 -0
- package/dist/bridge/codex-app-server.js +319 -0
- package/dist/bridge/codex-auth-refresh.d.ts +33 -0
- package/dist/bridge/codex-auth-refresh.js +71 -0
- package/dist/bridge/codex-question-reply.d.ts +16 -0
- package/dist/bridge/codex-question-reply.js +57 -0
- package/dist/bridge/codex-review-mode.d.ts +10 -0
- package/dist/bridge/codex-review-mode.js +74 -0
- package/dist/bridge/codex-servers.d.ts +217 -0
- package/dist/bridge/codex-servers.js +636 -0
- package/dist/bridge/command.js +94 -4
- package/dist/bridge/computer-identity.d.ts +75 -0
- package/dist/bridge/computer-identity.js +166 -0
- package/dist/bridge/conductor-group.d.ts +91 -8
- package/dist/bridge/conductor-group.js +105 -9
- package/dist/bridge/conductor-role.d.ts +94 -0
- package/dist/bridge/conductor-role.js +176 -0
- package/dist/bridge/conductor-sets.d.ts +20 -0
- package/dist/bridge/conductor-sets.js +59 -0
- package/dist/bridge/dispatch-command.d.ts +3 -0
- package/dist/bridge/dispatch-command.js +75 -11
- package/dist/bridge/dispatch-returns.d.ts +123 -19
- package/dist/bridge/dispatch-returns.js +357 -50
- package/dist/bridge/dispatch.d.ts +103 -2
- package/dist/bridge/dispatch.js +272 -40
- package/dist/bridge/fanout-messages.js +2 -2
- package/dist/bridge/fanouts.d.ts +7 -1
- package/dist/bridge/fanouts.js +40 -5
- package/dist/bridge/folder-trust.d.ts +56 -0
- package/dist/bridge/folder-trust.js +195 -0
- package/dist/bridge/grants.d.ts +22 -1
- package/dist/bridge/grants.js +57 -9
- package/dist/bridge/hand-off.d.ts +21 -9
- package/dist/bridge/hand-off.js +58 -45
- package/dist/bridge/harness-status.d.ts +11 -0
- package/dist/bridge/harness-status.js +32 -0
- package/dist/bridge/harnesses.d.ts +39 -0
- package/dist/bridge/harnesses.js +65 -0
- package/dist/bridge/health.d.ts +2 -0
- package/dist/bridge/health.js +1 -1
- package/dist/bridge/herdr.d.ts +11 -2
- package/dist/bridge/herdr.js +98 -23
- package/dist/bridge/hook-fast.d.ts +4 -0
- package/dist/bridge/hook-fast.js +68 -0
- package/dist/bridge/install.d.ts +16 -1
- package/dist/bridge/install.js +88 -21
- package/dist/bridge/launch-brief.d.ts +96 -0
- package/dist/bridge/launch-brief.js +164 -0
- package/dist/bridge/model-switch.d.ts +3 -0
- package/dist/bridge/model-switch.js +17 -1
- package/dist/bridge/models.d.ts +8 -4
- package/dist/bridge/models.js +24 -8
- package/dist/bridge/mux-wire.d.ts +9 -0
- package/dist/bridge/mux-wire.js +19 -0
- package/dist/bridge/opencode-pane-server.d.ts +113 -0
- package/dist/bridge/opencode-pane-server.js +332 -0
- package/dist/bridge/opencode-panes.d.ts +111 -0
- package/dist/bridge/opencode-panes.js +295 -0
- package/dist/bridge/pane-accounts.d.ts +8 -0
- package/dist/bridge/pane-accounts.js +46 -0
- package/dist/bridge/prompt-startup.d.ts +5 -0
- package/dist/bridge/prompt-startup.js +24 -0
- package/dist/bridge/protocol.d.ts +5 -0
- package/dist/bridge/protocol.js +4 -0
- package/dist/bridge/push.d.ts +5 -4
- package/dist/bridge/push.js +6 -4
- package/dist/bridge/questions.d.ts +37 -2
- package/dist/bridge/questions.js +158 -15
- package/dist/bridge/resources.d.ts +125 -0
- package/dist/bridge/resources.js +314 -0
- package/dist/bridge/schedule-format.d.ts +2 -0
- package/dist/bridge/schedule-format.js +3 -0
- package/dist/bridge/schedule-launch.d.ts +2 -1
- package/dist/bridge/schedule-launch.js +23 -53
- package/dist/bridge/schedule-watch.d.ts +10 -1
- package/dist/bridge/schedule-watch.js +54 -2
- package/dist/bridge/server-launch.d.ts +22 -5
- package/dist/bridge/server-launch.js +225 -29
- package/dist/bridge/server-overview.d.ts +8 -2
- package/dist/bridge/server-overview.js +26 -5
- package/dist/bridge/server-pane-routes.d.ts +2 -0
- package/dist/bridge/server-pane-routes.js +145 -15
- package/dist/bridge/server-routes.d.ts +11 -1
- package/dist/bridge/server-routes.js +195 -36
- package/dist/bridge/server-stream.d.ts +2 -0
- package/dist/bridge/server-stream.js +22 -8
- package/dist/bridge/server.d.ts +6 -1
- package/dist/bridge/server.js +47 -12
- package/dist/bridge/session-activity.d.ts +81 -0
- package/dist/bridge/session-activity.js +117 -0
- package/dist/bridge/session-rename.d.ts +48 -0
- package/dist/bridge/session-rename.js +190 -0
- package/dist/bridge/session-servers.js +2 -2
- package/dist/bridge/settings-switch.d.ts +60 -0
- package/dist/bridge/settings-switch.js +287 -0
- package/dist/bridge/speech-voice.d.ts +55 -0
- package/dist/bridge/speech-voice.js +132 -0
- package/dist/bridge/speech.d.ts +70 -11
- package/dist/bridge/speech.js +169 -41
- package/dist/bridge/terminal-herdr.js +9 -3
- package/dist/bridge/terminal-tmux.d.ts +3 -3
- package/dist/bridge/terminal-tmux.js +24 -9
- package/dist/bridge/terminal.d.ts +27 -4
- package/dist/bridge/terminal.js +8 -1
- package/dist/bridge/transcript-claude.js +62 -12
- package/dist/bridge/transcript-codex.d.ts +0 -2
- package/dist/bridge/transcript-codex.js +29 -4
- package/dist/bridge/transcript-preview.d.ts +1 -0
- package/dist/bridge/transcript-preview.js +24 -4
- package/dist/bridge/transcripts.d.ts +15 -2
- package/dist/bridge/transcripts.js +47 -16
- package/dist/bridge/turn-records.d.ts +85 -0
- package/dist/bridge/turn-records.js +143 -0
- package/dist/bridge/uploads.d.ts +3 -0
- package/dist/bridge/uploads.js +14 -0
- package/dist/bridge/usage.d.ts +73 -28
- package/dist/bridge/usage.js +313 -340
- package/dist/bridge-hook.mjs +24624 -18450
- package/dist/cli/claude-unmanaged.d.ts +12 -0
- package/dist/cli/claude-unmanaged.js +105 -0
- package/dist/cli/schedules.js +2 -1
- package/dist/cli/session-start.js +10 -1
- package/dist/cli/session-stop.js +9 -1
- package/dist/cli-registry.d.ts +2 -0
- package/dist/cli-registry.js +37 -5
- 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/data/task-receipts.d.ts +19 -0
- package/dist/data/task-receipts.js +68 -0
- package/dist/data/tasks.js +4 -1
- 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/generated/memory-ui-graph.browser.js +63 -63
- package/dist/graph-core/model.js +24 -3
- package/dist/graph-core/types.d.ts +4 -1
- package/dist/graph-core/types.js +1 -0
- package/dist/init/init-preset.js +7 -3
- package/dist/init/init-uninstall.js +2 -11
- package/dist/init/teardown.d.ts +3 -0
- package/dist/init/teardown.js +47 -0
- package/dist/link/context.js +21 -9
- package/dist/mcp/plugin-mode.js +1 -1
- package/dist/memory-ui-graph.runtime.js +63 -63
- package/dist/modules/code-package.d.ts +1 -0
- package/dist/modules/code-package.js +36 -7
- package/dist/modules/registry.js +14 -13
- package/dist/profile-store.d.ts +6 -0
- package/dist/profile-store.js +25 -1
- package/dist/shell/graph/glyphs.js +4 -0
- package/dist/shell/graph/graph-view.js +2 -0
- package/dist/status.js +7 -1
- package/dist/sync/task-claim.js +3 -2
- package/dist/task/lifecycle.js +25 -4
- package/dist/test-global-setup.js +5 -0
- package/dist/tools/dispatch.js +35 -2
- package/dist/tools/tasks.js +10 -1
- package/package.json +1 -1
- package/plugins/opencode/phren-transcript.js +87 -4
- package/starter/global/skills/conductor/SKILL.md +17 -2
- package/starter/global/skills/fanout/SKILL.md +3 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// What a pane's agent last said about its own turns, from its lifecycle hooks:
|
|
2
|
+
// when a prompt was submitted, when the turn stopped, what it stopped with and
|
|
3
|
+
// whether the harness still had background work in flight. Dispatch returns
|
|
4
|
+
// answer from this record first (dispatch-returns.ts `workerStates`): a
|
|
5
|
+
// worker is done only once a Stop arrived after its prompt, never because it
|
|
6
|
+
// has looked idle for a while.
|
|
7
|
+
//
|
|
8
|
+
// Claude, Codex, Copilot and phren-agent send SessionStart, UserPromptSubmit
|
|
9
|
+
// and Stop to the Hook (agent-hooks.ts), which records them here, one small
|
|
10
|
+
// file per pane beside its binding. OpenCode has no such hooks; phren's
|
|
11
|
+
// OpenCode plugin stamps its turns into the per-PID status file instead
|
|
12
|
+
// (`opencodeTurn`).
|
|
13
|
+
//
|
|
14
|
+
// The record is keyed by pane and holds the latest conversation there, with
|
|
15
|
+
// the dispatch id (PHREN_DISPATCH_ID) its SessionStart or first prompt named,
|
|
16
|
+
// so a dispatch placed on this computer is matched by id as well as by pane
|
|
17
|
+
// and conversation.
|
|
18
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import { opencodeTurnStamps } from "./harness-status.js";
|
|
22
|
+
import { briefId } from "./launch-brief.js";
|
|
23
|
+
import { atomicInPrivateDir, bridgeRoot, provider, serverName, sessionId } from "./protocol.js";
|
|
24
|
+
/** Longest final reply kept from a Stop payload, in UTF-8 bytes (the receipt's limit). */
|
|
25
|
+
export const TURN_REPLY_LIMIT = 4000;
|
|
26
|
+
const MAX_RECORD_BYTES = 16_384;
|
|
27
|
+
const stamp = z.object({ seq: z.number().int().min(0), at: z.string().datetime() }).strict();
|
|
28
|
+
const turnRecordSchema = z.object({
|
|
29
|
+
terminal: z.string().min(1).max(200), source: provider, session: sessionId,
|
|
30
|
+
/** Climbs with every recorded event, so prompt and stop are ordered without trusting the clock. */
|
|
31
|
+
seq: z.number().int().min(0),
|
|
32
|
+
/** The dispatch this conversation was launched for, as its hooks named it. */
|
|
33
|
+
dispatch: briefId.optional(),
|
|
34
|
+
startedAt: z.string().datetime().optional(),
|
|
35
|
+
prompt: stamp.optional(),
|
|
36
|
+
stop: stamp.extend({
|
|
37
|
+
/** Background tasks (shells, subagents, monitors) the harness still ran when the turn stopped. */
|
|
38
|
+
background: z.number().int().min(0).max(999).optional(),
|
|
39
|
+
reply: z.string().max(TURN_REPLY_LIMIT).optional(), truncated: z.boolean().optional(),
|
|
40
|
+
}).strict().optional(),
|
|
41
|
+
at: z.string().datetime(),
|
|
42
|
+
}).strict();
|
|
43
|
+
export const turnPath = (server, pane) => path.join(bridgeRoot(), "turns", encodeURIComponent(serverName.parse(server)), encodeURIComponent(pane) + ".json");
|
|
44
|
+
/** `value` cut to at most `limit` UTF-8 bytes on a character boundary. */
|
|
45
|
+
export function truncateUtf8(value, limit = TURN_REPLY_LIMIT) {
|
|
46
|
+
const bytes = Buffer.from(value);
|
|
47
|
+
if (bytes.length <= limit)
|
|
48
|
+
return { text: value, truncated: false };
|
|
49
|
+
let end = limit;
|
|
50
|
+
while (end > 0 && (bytes[end] & 0xc0) === 0x80)
|
|
51
|
+
end--;
|
|
52
|
+
return { text: bytes.subarray(0, end).toString("utf8"), truncated: true };
|
|
53
|
+
}
|
|
54
|
+
/** The record after one lifecycle event; undefined for events that say nothing about turns.
|
|
55
|
+
* Another conversation or terminal in the pane starts a fresh record. */
|
|
56
|
+
export function nextTurn(previous, event) {
|
|
57
|
+
if (!["SessionStart", "UserPromptSubmit", "Stop"].includes(event.event))
|
|
58
|
+
return undefined;
|
|
59
|
+
const at = new Date(event.at ?? Date.now()).toISOString();
|
|
60
|
+
const same = previous && previous.terminal === event.terminal && previous.source === event.source && previous.session === event.session;
|
|
61
|
+
const record = same ? structuredClone(previous) : { terminal: event.terminal, source: event.source, session: event.session, seq: 0, at };
|
|
62
|
+
record.seq++;
|
|
63
|
+
record.at = at;
|
|
64
|
+
if (event.dispatch && briefId.safeParse(event.dispatch).success)
|
|
65
|
+
record.dispatch ??= event.dispatch;
|
|
66
|
+
if (event.event === "SessionStart")
|
|
67
|
+
record.startedAt ??= at;
|
|
68
|
+
else if (event.event === "UserPromptSubmit")
|
|
69
|
+
record.prompt = { seq: record.seq, at };
|
|
70
|
+
else {
|
|
71
|
+
const reply = event.reply?.trim() ? truncateUtf8(event.reply.trim()) : undefined;
|
|
72
|
+
record.stop = { seq: record.seq, at, ...(event.background !== undefined ? { background: Math.min(999, Math.max(0, Math.floor(event.background))) } : {}),
|
|
73
|
+
...(reply ? { reply: reply.text, ...(reply.truncated ? { truncated: true } : {}) } : {}) };
|
|
74
|
+
}
|
|
75
|
+
return record;
|
|
76
|
+
}
|
|
77
|
+
/** Where the recorded conversation is: no prompt yet, a prompt with no Stop
|
|
78
|
+
* after it, or a turn that stopped. A Stop with no recorded prompt (hooks
|
|
79
|
+
* installed mid-conversation) still ended a turn. */
|
|
80
|
+
export function turnPhase(record) {
|
|
81
|
+
const { prompt, stop } = record;
|
|
82
|
+
if (prompt && (!stop || stop.seq < prompt.seq))
|
|
83
|
+
return { phase: "working", since: prompt.at };
|
|
84
|
+
if (!stop)
|
|
85
|
+
return { phase: "unprompted" };
|
|
86
|
+
return { phase: "ended", at: stop.at, ...(stop.background ? { background: stop.background } : {}),
|
|
87
|
+
...(stop.reply ? { reply: stop.reply, ...(stop.truncated ? { truncated: true } : {}) } : {}) };
|
|
88
|
+
}
|
|
89
|
+
/** The background tasks of a Stop at `stoppedAt` still running: the Stop's
|
|
90
|
+
* count less the tasks whose finish the transcript recorded after it
|
|
91
|
+
* (`FinalTurn.finishedTasks`). No turn ran since that Stop, so every task
|
|
92
|
+
* finishing after it is one the count included; a finish does not always
|
|
93
|
+
* bring a new Stop (its notification can wait in an idle session's queue). */
|
|
94
|
+
export function backgroundLeft(count, stoppedAt, finishedTasks = []) {
|
|
95
|
+
if (!count)
|
|
96
|
+
return 0;
|
|
97
|
+
const stopped = Date.parse(stoppedAt);
|
|
98
|
+
return Math.max(0, count - finishedTasks.filter(at => Date.parse(at) >= stopped).length);
|
|
99
|
+
}
|
|
100
|
+
async function readRecord(file) {
|
|
101
|
+
try {
|
|
102
|
+
const info = await lstat(file);
|
|
103
|
+
if (!info.isFile() || info.size > MAX_RECORD_BYTES)
|
|
104
|
+
return undefined;
|
|
105
|
+
const parsed = turnRecordSchema.safeParse(JSON.parse(await readFile(file, "utf8")));
|
|
106
|
+
return parsed.success ? parsed.data : undefined;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let writes = Promise.resolve();
|
|
113
|
+
/** Record one lifecycle event for `pane`. Writes run one at a time, so a Stop
|
|
114
|
+
* and the next prompt arriving together keep their order. */
|
|
115
|
+
export function noteTurn(server, pane, event) {
|
|
116
|
+
const run = writes.then(async () => {
|
|
117
|
+
const file = turnPath(server, pane);
|
|
118
|
+
const next = nextTurn(await readRecord(file), event);
|
|
119
|
+
if (next)
|
|
120
|
+
await atomicInPrivateDir(file, turnRecordSchema.parse(next));
|
|
121
|
+
return next;
|
|
122
|
+
});
|
|
123
|
+
writes = run.catch(() => undefined);
|
|
124
|
+
return run;
|
|
125
|
+
}
|
|
126
|
+
/** The recorded turns of `pane`'s latest conversation, if its hooks reported any. */
|
|
127
|
+
export function readTurn(server, pane) {
|
|
128
|
+
return readRecord(turnPath(server, pane));
|
|
129
|
+
}
|
|
130
|
+
/** OpenCode's turns for a pane running `pids`, from the stamps phren's OpenCode
|
|
131
|
+
* plugin writes on session.status busy / session.idle; undefined for an older
|
|
132
|
+
* plugin that writes none. `terminal` is the pane's, since the PIDs are. */
|
|
133
|
+
export async function opencodeTurn(pids, terminal) {
|
|
134
|
+
const stamps = await opencodeTurnStamps(pids);
|
|
135
|
+
if (!stamps)
|
|
136
|
+
return undefined;
|
|
137
|
+
const busy = stamps.busyAt ? Date.parse(stamps.busyAt) : NaN, idle = stamps.idleAt ? Date.parse(stamps.idleAt) : NaN;
|
|
138
|
+
const parsed = turnRecordSchema.safeParse({ terminal, source: "opencode", session: stamps.session, seq: 2, at: stamps.at,
|
|
139
|
+
...(Number.isFinite(busy) ? { prompt: { seq: 1, at: stamps.busyAt } } : {}),
|
|
140
|
+
// The plugin stamps idle after busy; an idle stamp older than the busy one belongs to an earlier turn.
|
|
141
|
+
...(Number.isFinite(idle) && !(idle < busy) ? { stop: { seq: 2, at: stamps.idleAt } } : {}) });
|
|
142
|
+
return parsed.success ? parsed.data : undefined;
|
|
143
|
+
}
|
package/dist/bridge/uploads.d.ts
CHANGED
|
@@ -15,3 +15,6 @@ export declare function listUploads(session: string): Promise<{
|
|
|
15
15
|
* any link) to a regular file inside the uploads folder whose bytes are
|
|
16
16
|
* an image; anything else — outside, traversal, a note — is 404. */
|
|
17
17
|
export declare function uploadImage(requested: string): Promise<Buffer>;
|
|
18
|
+
/** A file the phone uploaded for this conversation, by the path `/v1/upload`
|
|
19
|
+
* returned: it must resolve to a regular file inside uploads/<session>/. */
|
|
20
|
+
export declare function sessionUpload(session: string, requested: string): Promise<string>;
|
package/dist/bridge/uploads.js
CHANGED
|
@@ -85,3 +85,17 @@ export async function uploadImage(requested) {
|
|
|
85
85
|
throw missing;
|
|
86
86
|
return bytes;
|
|
87
87
|
}
|
|
88
|
+
/** A file the phone uploaded for this conversation, by the path `/v1/upload`
|
|
89
|
+
* returned: it must resolve to a regular file inside uploads/<session>/. */
|
|
90
|
+
export async function sessionUpload(session, requested) {
|
|
91
|
+
const refused = new BridgeError(400, "An attachment is not one of this conversation's uploads. Attach it again.");
|
|
92
|
+
if (!requested || requested.length > 4096 || !path.isAbsolute(requested))
|
|
93
|
+
throw refused;
|
|
94
|
+
const folder = await realpath(path.join(bridgeRoot(), "uploads", session)).catch(() => undefined);
|
|
95
|
+
const file = await realpath(requested).catch(() => undefined);
|
|
96
|
+
if (!folder || !file || !file.startsWith(folder + path.sep))
|
|
97
|
+
throw refused;
|
|
98
|
+
if (!(await stat(file)).isFile())
|
|
99
|
+
throw refused;
|
|
100
|
+
return file;
|
|
101
|
+
}
|
package/dist/bridge/usage.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { type AccountRef, type ClaudeHome } from "./claude-accounts.js";
|
|
2
3
|
export interface UsageWindow {
|
|
3
4
|
id: string;
|
|
4
5
|
name: string;
|
|
@@ -8,15 +9,22 @@ export interface UsageWindow {
|
|
|
8
9
|
usedUSD?: number;
|
|
9
10
|
limitUSD?: number;
|
|
10
11
|
usedTokens?: number;
|
|
12
|
+
/** ElevenLabs' character quota, next to its percentage. */
|
|
13
|
+
usedCharacters?: number;
|
|
14
|
+
limitCharacters?: number;
|
|
11
15
|
resetsAt?: string;
|
|
16
|
+
/** The service says this window is refusing requests now (OpenCode Go's `rate-limited`). */
|
|
17
|
+
limited?: boolean;
|
|
12
18
|
asOf?: string;
|
|
19
|
+
/** The window's reset time passed after its report: no percent is known, so none is sent. */
|
|
20
|
+
reset?: boolean;
|
|
13
21
|
}
|
|
14
22
|
export interface UsageSpend {
|
|
15
23
|
amountUSD: number;
|
|
16
24
|
period: "rolling_7_days" | "rolling_30_days" | "calendar_week";
|
|
17
25
|
}
|
|
18
26
|
export interface AccountUsage {
|
|
19
|
-
source: "codex" | "claude" | "opencode" | "opencode-go" | "openrouter";
|
|
27
|
+
source: "codex" | "claude" | "opencode" | "opencode-go" | "openrouter" | "copilot" | "elevenlabs";
|
|
20
28
|
windows: UsageWindow[];
|
|
21
29
|
updatedAt?: string;
|
|
22
30
|
message?: string;
|
|
@@ -27,6 +35,8 @@ export interface AccountUsage {
|
|
|
27
35
|
* or the OAuth usage endpoint. Per-model windows the status line never
|
|
28
36
|
* carries document their own age through each window's asOf instead. */
|
|
29
37
|
origin?: "status-line" | "oauth";
|
|
38
|
+
/** Which account this row is: a Claude home, or Codex's single one. Older phones ignore it. */
|
|
39
|
+
account?: AccountRef;
|
|
30
40
|
}
|
|
31
41
|
export declare function codexUsage(value: unknown, now?: Date): AccountUsage;
|
|
32
42
|
/** Parse OpenCode's own cost ledger. `stats --days 7` is a rolling local view. */
|
|
@@ -39,29 +49,39 @@ export declare function openCodeFailure(error: unknown): string;
|
|
|
39
49
|
export declare function readOpenRouterKey(): Promise<string | undefined>;
|
|
40
50
|
/** OpenCode Go's key stays local and is sent only to the Go gateway. */
|
|
41
51
|
export declare function readOpenCodeGoKey(): Promise<string | undefined>;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Go's own report of the plan, `GET /zen/go/v1/usage`:
|
|
54
|
+
* `{usage: {rolling|weekly|monthly: {status, percent, resetsAt}}}`. It is
|
|
55
|
+
* account-wide, so it already counts every computer's use, and it is what
|
|
56
|
+
* Go enforces: `status: "rate-limited"` is the window that refuses requests.
|
|
57
|
+
* It carries no dollar amounts, so none are shown.
|
|
58
|
+
*/
|
|
59
|
+
export declare function openCodeGoPlan(value: unknown): UsageWindow[];
|
|
60
|
+
export declare function fetchOpenCodeGoPlan(key: string, fetchImpl?: typeof fetch): Promise<UsageWindow[]>;
|
|
61
|
+
export interface GoRefusals {
|
|
62
|
+
count: number;
|
|
63
|
+
first: string;
|
|
64
|
+
last: string;
|
|
65
|
+
models: string[];
|
|
66
|
+
}
|
|
67
|
+
/** "Go usage limit exceeded" refusals in OpenCode's own log over the last
|
|
68
|
+
* `withinMs`. The first read of a log covers at most its last 64 MB. */
|
|
69
|
+
export declare function readGoRefusals(now?: Date, withinMs?: number, root?: string): Promise<GoRefusals | undefined>;
|
|
70
|
+
export declare function openCodeGoUsage(windows: UsageWindow[], refusals: GoRefusals | undefined, now: Date, hasKey: boolean, planError?: boolean): AccountUsage;
|
|
71
|
+
/** The accounts one caller can read: the sources it names, and Go's plan
|
|
72
|
+
* windows only for a caller that asked for them (`goPlan=1`). */
|
|
73
|
+
export declare function usageForCaller(accounts: AccountUsage[], sources: Set<string>, goPlan: boolean): AccountUsage[];
|
|
58
74
|
export declare function readOpenCodeGoUsage(now?: Date, options?: {
|
|
59
|
-
root?: string;
|
|
60
75
|
readKey?: () => Promise<string | undefined>;
|
|
61
76
|
fetchImpl?: typeof fetch;
|
|
77
|
+
readRefusals?: (now: Date) => Promise<GoRefusals | undefined>;
|
|
62
78
|
}): Promise<AccountUsage>;
|
|
63
79
|
/** OpenRouter reports the current UTC calendar week's charged usage per key. */
|
|
64
80
|
export declare function fetchOpenRouterUsage(key: string, fetchImpl?: typeof fetch, now?: Date): Promise<AccountUsage>;
|
|
81
|
+
/** ElevenLabs' subscription: characters used this billing period against the plan's limit. */
|
|
82
|
+
export declare function elevenLabsUsage(value: unknown, now?: Date): AccountUsage;
|
|
83
|
+
/** The key the Hook already uses for /v1/speech, sent only to ElevenLabs; the answer carries counts, never the key. */
|
|
84
|
+
export declare function fetchElevenLabsUsage(key: string, fetchImpl?: typeof fetch, now?: Date): Promise<AccountUsage>;
|
|
65
85
|
/** Claude Code's documented status-line payload: rate_limits carries the
|
|
66
86
|
* five_hour and seven_day windows (the 5h/7d unified limits) and, when the
|
|
67
87
|
* build emits them, per-model keys such as seven_day_fable. Every window
|
|
@@ -88,13 +108,31 @@ export declare function claudeOAuthUsage(value: unknown, now?: Date): AccountUsa
|
|
|
88
108
|
* Claude Code's own sign-in token, read locally and used only against
|
|
89
109
|
* Anthropic's usage endpoint — never persisted, logged, or sent elsewhere.
|
|
90
110
|
* The file is authoritative off macOS; macOS keeps it in the login keychain,
|
|
91
|
-
* with the file left stale after a refresh.
|
|
111
|
+
* with the file left stale after a refresh. A non-default `home` reads only its
|
|
112
|
+
* own file, and nothing on macOS (its keychain item name is unverified).
|
|
92
113
|
*/
|
|
93
|
-
export declare function readClaudeToken(execSecurity?: typeof execFile.__promisify__, platform?: NodeJS.Platform): Promise<string | undefined>;
|
|
114
|
+
export declare function readClaudeToken(execSecurity?: typeof execFile.__promisify__, platform?: NodeJS.Platform, home?: ClaudeHome): Promise<string | undefined>;
|
|
94
115
|
/** Fetch live limits; any failure falls back to the local snapshot. */
|
|
95
116
|
export declare function fetchClaudeUsage(token: string, fetchImpl?: typeof fetch, now?: Date): Promise<AccountUsage>;
|
|
96
117
|
/** Only initialize and read limits. Never create a thread, prompt, or login. */
|
|
97
118
|
export declare function readCodexLimits(executable?: string): Promise<AccountUsage>;
|
|
119
|
+
/**
|
|
120
|
+
* GitHub Copilot's own quota report (`gh api /copilot_internal/user`): one
|
|
121
|
+
* window per limited quota (premium requests, usually) with the monthly
|
|
122
|
+
* reset. Unlimited quotas are named in the message, not drawn as 0%.
|
|
123
|
+
*/
|
|
124
|
+
export declare function copilotUsage(value: unknown, now?: Date): AccountUsage;
|
|
125
|
+
/** Reads through the GitHub CLI's own sign-in; the token never reaches Phren. */
|
|
126
|
+
export declare function readCopilotUsage(now?: Date, run?: (file: string, args: string[]) => Promise<string>): Promise<AccountUsage>;
|
|
127
|
+
/** A Claude report older than this says nothing about the account now. */
|
|
128
|
+
export declare const CLAUDE_REPORT_MAX_AGE_MS: number;
|
|
129
|
+
/**
|
|
130
|
+
* What a saved Claude report still says at `now`: a window whose reset time
|
|
131
|
+
* has passed is reported as reset without its old percent, and a report
|
|
132
|
+
* older than three days is dropped, so a stale number never reaches the
|
|
133
|
+
* phone's cards, rings or widgets.
|
|
134
|
+
*/
|
|
135
|
+
export declare function settleClaudeUsage(usage: AccountUsage, now: number): AccountUsage;
|
|
98
136
|
export declare class AccountUsageReader {
|
|
99
137
|
private readCodex;
|
|
100
138
|
private now;
|
|
@@ -102,23 +140,30 @@ export declare class AccountUsageReader {
|
|
|
102
140
|
private readOpenCode;
|
|
103
141
|
private readOpenRouter;
|
|
104
142
|
private readOpenCodeGo;
|
|
143
|
+
private readCopilot;
|
|
144
|
+
private platform;
|
|
145
|
+
private readElevenLabs;
|
|
105
146
|
private cached?;
|
|
106
147
|
private pending?;
|
|
107
|
-
private claudeCached
|
|
108
|
-
private claudePending
|
|
109
|
-
private spendingCached
|
|
110
|
-
private spendingPending
|
|
111
|
-
constructor(readCodex?: typeof readCodexLimits, now?: () => number, readClaudeLive?: (now: Date) => Promise<AccountUsage | undefined>, readOpenCode?: (now: Date) => Promise<AccountUsage>, readOpenRouter?: (now: Date) => Promise<AccountUsage | undefined>, readOpenCodeGo?: (now: Date) => Promise<AccountUsage>);
|
|
112
|
-
|
|
148
|
+
private claudeCached;
|
|
149
|
+
private claudePending;
|
|
150
|
+
private spendingCached;
|
|
151
|
+
private spendingPending;
|
|
152
|
+
constructor(readCodex?: typeof readCodexLimits, now?: () => number, readClaudeLive?: (now: Date, home: ClaudeHome) => Promise<AccountUsage | undefined>, readOpenCode?: (now: Date) => Promise<AccountUsage>, readOpenRouter?: (now: Date) => Promise<AccountUsage | undefined>, readOpenCodeGo?: (now: Date) => Promise<AccountUsage>, readCopilot?: (now: Date) => Promise<AccountUsage>, platform?: NodeJS.Platform, readElevenLabs?: (now: Date) => Promise<AccountUsage | undefined>);
|
|
153
|
+
/** `allAccounts`: one Claude row per home. Otherwise only the default home's, as
|
|
154
|
+
* before accounts existed, since older phones refuse two rows of one source. */
|
|
155
|
+
read(sources?: Set<string>, allAccounts?: boolean): Promise<{
|
|
113
156
|
accounts: AccountUsage[];
|
|
114
157
|
}>;
|
|
158
|
+
/** ElevenLabs is read only when the caller shows it: every read spends a request against the key's quota. */
|
|
115
159
|
private spending;
|
|
116
160
|
/** Live first, so the phone's minute-by-minute poll keeps Claude current
|
|
117
|
-
* even when Claude Code is not running; the local snapshot is the backup.
|
|
161
|
+
* even when Claude Code is not running; the local snapshot is the backup.
|
|
162
|
+
* Off macOS a non-default home reads its own credentials file; on macOS it
|
|
163
|
+
* has no live read (the keychain item name for custom homes is unverified). */
|
|
118
164
|
private claude;
|
|
119
165
|
private snapshotClaude;
|
|
120
166
|
}
|
|
121
167
|
/** Wrap an existing status line, preserving its input, output and options. */
|
|
122
168
|
export declare function usageStatusLine(current: unknown, program: string, remove: boolean): unknown;
|
|
123
169
|
export declare function captureClaudeUsage(original: string): Promise<void>;
|
|
124
|
-
export {};
|