@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.
- 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/usage.d.ts +36 -20
- package/dist/bridge/usage.js +163 -301
- package/dist/bridge-hook.mjs +974 -793
- 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/fanout/SKILL.md +3 -0
package/dist/bridge/server.js
CHANGED
|
@@ -29,6 +29,7 @@ import { ModelCatalog } from "./models.js";
|
|
|
29
29
|
import { ModelSwitcher } from "./model-switch.js";
|
|
30
30
|
import { SideQuestions } from "./side-questions.js";
|
|
31
31
|
import { AccountUsageReader } from "./usage.js";
|
|
32
|
+
import { ResourceMonitor } from "./resources.js";
|
|
32
33
|
import { createScheduleLauncher, Scheduler, scheduleRunsFile } from "./schedules.js";
|
|
33
34
|
import { dailyCanaryDue, runCanary } from "./canary.js";
|
|
34
35
|
import { defaultPhrenPath } from "../shared.js";
|
|
@@ -81,6 +82,7 @@ export async function serve(version) {
|
|
|
81
82
|
const sideQuestions = new SideQuestions();
|
|
82
83
|
const contextUsage = new WorkspaceContextUsage();
|
|
83
84
|
const accountUsage = new AccountUsageReader();
|
|
85
|
+
const resources = new ResourceMonitor();
|
|
84
86
|
const tabActivity = new TabActivityStore();
|
|
85
87
|
const codexQuestions = new CodexQuestions();
|
|
86
88
|
const scheduleStore = defaultPhrenPath();
|
|
@@ -139,9 +141,10 @@ export async function serve(version) {
|
|
|
139
141
|
read: workspacesReader({ modules, info, agentHooks, journal, tabActivity, contextUsage }),
|
|
140
142
|
info: () => ({ ...info, capabilities: info.capabilities }),
|
|
141
143
|
renew: server => agentHooks.overview.renew(server),
|
|
144
|
+
resources: () => resources.read(),
|
|
142
145
|
});
|
|
143
146
|
const http = createServer(createRouteHandler({ version, modules, info, computerID, scheduleStore, scheduler, dispatches, agentHooks,
|
|
144
|
-
journal, tabActivity, contextUsage, modelCatalog, modelSwitcher, sideQuestions, accountUsage, codexQuestions, launches, locatedDirectories,
|
|
147
|
+
journal, tabActivity, contextUsage, modelCatalog, modelSwitcher, sideQuestions, accountUsage, resources, codexQuestions, launches, locatedDirectories,
|
|
145
148
|
fanoutMessages, canary, streams, returns }));
|
|
146
149
|
http.requestTimeout = 20_000;
|
|
147
150
|
http.headersTimeout = 10_000;
|
|
@@ -165,7 +168,7 @@ export async function serve(version) {
|
|
|
165
168
|
ws.clients.delete(oldest);
|
|
166
169
|
}
|
|
167
170
|
if (overviewServer !== undefined) {
|
|
168
|
-
overview(client, overviewServer, url.searchParams.get("watchApprovals") === "1");
|
|
171
|
+
overview(client, overviewServer, url.searchParams.get("watchApprovals") === "1", url.searchParams.get("resources") === "1");
|
|
169
172
|
return;
|
|
170
173
|
}
|
|
171
174
|
if (url.pathname === "/v1/speech/transcribe") {
|
|
@@ -297,6 +297,11 @@ export function phrenHookContext(raw, includeSidechain = false) {
|
|
|
297
297
|
* private reasoning redacted, queued phone messages, background task
|
|
298
298
|
* notifications and compaction markers. */
|
|
299
299
|
export function visibleClaudeEvent(raw, includeSidechain = false) {
|
|
300
|
+
// A follow-up the phone sent a Claude fan-out worker, written into its
|
|
301
|
+
// event log by the Hook before the resumed run.
|
|
302
|
+
if (raw.type === "phren/fanout-message" && typeof raw.text === "string") {
|
|
303
|
+
return { type: "user", timestamp: raw.timestamp, message: { role: "user", content: raw.text.slice(0, 65_536) } };
|
|
304
|
+
}
|
|
300
305
|
// A queued phone message carries the same wrapper; unwrap before the
|
|
301
306
|
// digest so enqueue and remove keep matching keys.
|
|
302
307
|
if (raw.type === "queue-operation" && typeof raw.content === "string")
|
package/dist/bridge/usage.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface UsageWindow {
|
|
|
9
9
|
limitUSD?: number;
|
|
10
10
|
usedTokens?: number;
|
|
11
11
|
resetsAt?: string;
|
|
12
|
+
/** The service says this window is refusing requests now (OpenCode Go's `rate-limited`). */
|
|
13
|
+
limited?: boolean;
|
|
12
14
|
asOf?: string;
|
|
13
15
|
}
|
|
14
16
|
export interface UsageSpend {
|
|
@@ -16,7 +18,7 @@ export interface UsageSpend {
|
|
|
16
18
|
period: "rolling_7_days" | "rolling_30_days" | "calendar_week";
|
|
17
19
|
}
|
|
18
20
|
export interface AccountUsage {
|
|
19
|
-
source: "codex" | "claude" | "opencode" | "opencode-go" | "openrouter";
|
|
21
|
+
source: "codex" | "claude" | "opencode" | "opencode-go" | "openrouter" | "copilot";
|
|
20
22
|
windows: UsageWindow[];
|
|
21
23
|
updatedAt?: string;
|
|
22
24
|
message?: string;
|
|
@@ -39,26 +41,32 @@ export declare function openCodeFailure(error: unknown): string;
|
|
|
39
41
|
export declare function readOpenRouterKey(): Promise<string | undefined>;
|
|
40
42
|
/** OpenCode Go's key stays local and is sent only to the Go gateway. */
|
|
41
43
|
export declare function readOpenCodeGoKey(): Promise<string | undefined>;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Go's own report of the plan, `GET /zen/go/v1/usage`:
|
|
46
|
+
* `{usage: {rolling|weekly|monthly: {status, percent, resetsAt}}}`. It is
|
|
47
|
+
* account-wide, so it already counts every computer's use, and it is what
|
|
48
|
+
* Go enforces: `status: "rate-limited"` is the window that refuses requests.
|
|
49
|
+
* It carries no dollar amounts, so none are shown.
|
|
50
|
+
*/
|
|
51
|
+
export declare function openCodeGoPlan(value: unknown): UsageWindow[];
|
|
52
|
+
export declare function fetchOpenCodeGoPlan(key: string, fetchImpl?: typeof fetch): Promise<UsageWindow[]>;
|
|
53
|
+
export interface GoRefusals {
|
|
54
|
+
count: number;
|
|
55
|
+
first: string;
|
|
56
|
+
last: string;
|
|
57
|
+
models: string[];
|
|
58
|
+
}
|
|
59
|
+
/** "Go usage limit exceeded" refusals in OpenCode's own log over the last
|
|
60
|
+
* `withinMs`. The first read of a log covers at most its last 64 MB. */
|
|
61
|
+
export declare function readGoRefusals(now?: Date, withinMs?: number, root?: string): Promise<GoRefusals | undefined>;
|
|
62
|
+
export declare function openCodeGoUsage(windows: UsageWindow[], refusals: GoRefusals | undefined, now: Date, hasKey: boolean, planError?: boolean): AccountUsage;
|
|
63
|
+
/** The accounts one caller can read: the sources it names, and Go's plan
|
|
64
|
+
* windows only for a caller that asked for them (`goPlan=1`). */
|
|
65
|
+
export declare function usageForCaller(accounts: AccountUsage[], sources: Set<string>, goPlan: boolean): AccountUsage[];
|
|
58
66
|
export declare function readOpenCodeGoUsage(now?: Date, options?: {
|
|
59
|
-
root?: string;
|
|
60
67
|
readKey?: () => Promise<string | undefined>;
|
|
61
68
|
fetchImpl?: typeof fetch;
|
|
69
|
+
readRefusals?: (now: Date) => Promise<GoRefusals | undefined>;
|
|
62
70
|
}): Promise<AccountUsage>;
|
|
63
71
|
/** OpenRouter reports the current UTC calendar week's charged usage per key. */
|
|
64
72
|
export declare function fetchOpenRouterUsage(key: string, fetchImpl?: typeof fetch, now?: Date): Promise<AccountUsage>;
|
|
@@ -95,6 +103,14 @@ export declare function readClaudeToken(execSecurity?: typeof execFile.__promisi
|
|
|
95
103
|
export declare function fetchClaudeUsage(token: string, fetchImpl?: typeof fetch, now?: Date): Promise<AccountUsage>;
|
|
96
104
|
/** Only initialize and read limits. Never create a thread, prompt, or login. */
|
|
97
105
|
export declare function readCodexLimits(executable?: string): Promise<AccountUsage>;
|
|
106
|
+
/**
|
|
107
|
+
* GitHub Copilot's own quota report (`gh api /copilot_internal/user`): one
|
|
108
|
+
* window per limited quota (premium requests, usually) with the monthly
|
|
109
|
+
* reset. Unlimited quotas are named in the message, not drawn as 0%.
|
|
110
|
+
*/
|
|
111
|
+
export declare function copilotUsage(value: unknown, now?: Date): AccountUsage;
|
|
112
|
+
/** Reads through the GitHub CLI's own sign-in; the token never reaches Phren. */
|
|
113
|
+
export declare function readCopilotUsage(now?: Date, run?: (file: string, args: string[]) => Promise<string>): Promise<AccountUsage>;
|
|
98
114
|
export declare class AccountUsageReader {
|
|
99
115
|
private readCodex;
|
|
100
116
|
private now;
|
|
@@ -102,13 +118,14 @@ export declare class AccountUsageReader {
|
|
|
102
118
|
private readOpenCode;
|
|
103
119
|
private readOpenRouter;
|
|
104
120
|
private readOpenCodeGo;
|
|
121
|
+
private readCopilot;
|
|
105
122
|
private cached?;
|
|
106
123
|
private pending?;
|
|
107
124
|
private claudeCached?;
|
|
108
125
|
private claudePending?;
|
|
109
126
|
private spendingCached?;
|
|
110
127
|
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>);
|
|
128
|
+
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>, readCopilot?: (now: Date) => Promise<AccountUsage>);
|
|
112
129
|
read(): Promise<{
|
|
113
130
|
accounts: AccountUsage[];
|
|
114
131
|
}>;
|
|
@@ -121,4 +138,3 @@ export declare class AccountUsageReader {
|
|
|
121
138
|
/** Wrap an existing status line, preserving its input, output and options. */
|
|
122
139
|
export declare function usageStatusLine(current: unknown, program: string, remove: boolean): unknown;
|
|
123
140
|
export declare function captureClaudeUsage(original: string): Promise<void>;
|
|
124
|
-
export {};
|