@phren/cli 0.3.45 → 0.3.46
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-asks.d.ts +34 -0
- package/dist/bridge/agent-hook-asks.js +72 -0
- package/dist/bridge/agent-hook-callback.d.ts +22 -0
- package/dist/bridge/agent-hook-callback.js +114 -0
- package/dist/bridge/agent-hooks.d.ts +7 -74
- package/dist/bridge/agent-hooks.js +22 -186
- package/dist/bridge/claude-question-dialog.d.ts +6 -0
- package/dist/bridge/claude-question-dialog.js +29 -7
- package/dist/bridge/codex-app-server.d.ts +5 -0
- package/dist/bridge/codex-app-server.js +15 -0
- package/dist/bridge/codex-auth-refresh.js +7 -0
- package/dist/bridge/dispatch-command.js +7 -1
- package/dist/bridge/file-write.js +3 -1
- package/dist/bridge/git-host-auth.d.ts +6 -0
- package/dist/bridge/git-host-auth.js +45 -0
- package/dist/bridge/git-publish.d.ts +1 -1
- package/dist/bridge/git-publish.js +75 -8
- package/dist/bridge/git-review.js +23 -2
- package/dist/bridge/git.d.ts +5 -1
- package/dist/bridge/git.js +103 -8
- package/dist/bridge/health.d.ts +1 -0
- package/dist/bridge/health.js +8 -5
- package/dist/bridge/lookup-cache.d.ts +17 -0
- package/dist/bridge/lookup-cache.js +70 -0
- package/dist/bridge/memory-store.js +40 -14
- package/dist/bridge/pair.js +4 -0
- package/dist/bridge/peers.js +36 -0
- package/dist/bridge/projects.d.ts +14 -0
- package/dist/bridge/projects.js +48 -1
- package/dist/bridge/prompt-deliveries.d.ts +38 -3
- package/dist/bridge/prompt-deliveries.js +196 -36
- package/dist/bridge/schedule-format.d.ts +4 -0
- package/dist/bridge/schedule-format.js +34 -0
- package/dist/bridge/schedule-problems.js +4 -0
- package/dist/bridge/scoped-gateway.d.ts +1 -0
- package/dist/bridge/scoped-gateway.js +10 -1
- package/dist/bridge/server-launch.js +6 -2
- package/dist/bridge/session-servers.js +3 -0
- package/dist/bridge/{codex-thread-origin.d.ts → thread-origin.d.ts} +8 -0
- package/dist/bridge/{codex-thread-origin.js → thread-origin.js} +24 -6
- package/dist/bridge/usage.d.ts +4 -0
- package/dist/bridge/usage.js +22 -8
- package/dist/bridge-hook.mjs +1137 -468
- package/dist/cli/namespaces-tasks.js +19 -5
- package/dist/cli/ops.d.ts +1 -1
- package/dist/cli/ops.js +2 -2
- package/dist/cli/schedules.js +16 -9
- package/dist/content/summarize.js +46 -6
- package/dist/content/validate.d.ts +3 -1
- package/dist/content/validate.js +33 -4
- package/dist/data/access.d.ts +8 -1
- package/dist/data/access.js +27 -9
- package/dist/data/notes.d.ts +2 -0
- package/dist/data/notes.js +2 -1
- package/dist/entrypoint.js +2 -1
- package/dist/generated/memory-ui-graph.browser.js +1 -1
- package/dist/governance/locks.js +17 -1
- package/dist/governance/policy.js +37 -23
- package/dist/memory-ui-graph.runtime.js +1 -1
- package/dist/sync/conflict-resolve.d.ts +1 -1
- package/dist/sync/conflict-resolve.js +91 -8
- package/dist/task/lifecycle.js +2 -1
- package/package.json +1 -1
|
@@ -11,15 +11,19 @@ import path from "node:path";
|
|
|
11
11
|
export async function codexForeignThread(transcriptPath) {
|
|
12
12
|
if (typeof transcriptPath !== "string" || !path.isAbsolute(transcriptPath) || !/^rollout-.*\.jsonl$/.test(path.basename(transcriptPath)))
|
|
13
13
|
return false;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
return foreignMeta(await readHead(transcriptPath, 4096));
|
|
15
|
+
}
|
|
16
|
+
/** The first `bytes` of a transcript; "" when it cannot be read. */
|
|
17
|
+
async function readHead(file, bytes) {
|
|
18
|
+
const handle = await open(file, "r").catch(() => undefined);
|
|
19
|
+
if (!handle)
|
|
20
|
+
return "";
|
|
17
21
|
try {
|
|
18
|
-
const buffer = Buffer.alloc(
|
|
19
|
-
return
|
|
22
|
+
const buffer = Buffer.alloc(bytes), { bytesRead } = await handle.read(buffer, 0, bytes, 0);
|
|
23
|
+
return buffer.subarray(0, bytesRead).toString("utf8");
|
|
20
24
|
}
|
|
21
25
|
finally {
|
|
22
|
-
await
|
|
26
|
+
await handle.close();
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
/** The session_meta fields come before its long instructions, so the head of
|
|
@@ -29,3 +33,17 @@ export function foreignMeta(head) {
|
|
|
29
33
|
return false;
|
|
30
34
|
return /"originator"\s*:\s*"codex_exec"/.test(head) || /"source"\s*:\s*"exec"/.test(head) || /"source"\s*:\s*\{\s*"subagent"/.test(head);
|
|
31
35
|
}
|
|
36
|
+
/** Whether a Claude hook callback comes from a headless run (`claude -p`, the
|
|
37
|
+
* Agent SDK) started inside the pane: it inherits HERDR_* and
|
|
38
|
+
* PHREN_DISPATCH_ID, so its callbacks name the pane and overwrite the parent's
|
|
39
|
+
* turn record. Interactive transcripts say `"entrypoint":"cli"`, headless ones
|
|
40
|
+
* `sdk-cli`/`sdk-ts`/`sdk-py`, on the first user row. A transcript that cannot
|
|
41
|
+
* be read, or has a long first prompt, counts as the pane's own. */
|
|
42
|
+
export async function claudeHeadlessThread(transcriptPath) {
|
|
43
|
+
if (typeof transcriptPath !== "string" || !path.isAbsolute(transcriptPath) || !transcriptPath.endsWith(".jsonl"))
|
|
44
|
+
return false;
|
|
45
|
+
return headlessEntrypoint(await readHead(transcriptPath, 32_768));
|
|
46
|
+
}
|
|
47
|
+
export function headlessEntrypoint(head) {
|
|
48
|
+
return /"entrypoint"\s*:\s*"sdk-[a-z]+"/.test(head);
|
|
49
|
+
}
|
package/dist/bridge/usage.d.ts
CHANGED
|
@@ -175,6 +175,10 @@ export declare function settleClaudeUsage(usage: AccountUsage, now: number): Acc
|
|
|
175
175
|
/** `opencode stats` scans OpenCode's whole database, several CPU-seconds on a
|
|
176
176
|
* busy machine, for a rolling seven-day cost that barely moves in a minute. */
|
|
177
177
|
export declare const OPENCODE_STATS_REUSE_MS: number;
|
|
178
|
+
/** Longest one reader may hold its shared slot. A read that never settles (a
|
|
179
|
+
* child whose grandchild keeps stdout open, say) would otherwise block every
|
|
180
|
+
* later poll until the Hook restarts. */
|
|
181
|
+
export declare const USAGE_READ_LIMIT_MS = 30000;
|
|
178
182
|
export declare class AccountUsageReader {
|
|
179
183
|
private readCodex;
|
|
180
184
|
private now;
|
package/dist/bridge/usage.js
CHANGED
|
@@ -771,6 +771,16 @@ export function settleClaudeUsage(usage, now) {
|
|
|
771
771
|
/** `opencode stats` scans OpenCode's whole database, several CPU-seconds on a
|
|
772
772
|
* busy machine, for a rolling seven-day cost that barely moves in a minute. */
|
|
773
773
|
export const OPENCODE_STATS_REUSE_MS = 10 * 60_000;
|
|
774
|
+
/** Longest one reader may hold its shared slot. A read that never settles (a
|
|
775
|
+
* child whose grandchild keeps stdout open, say) would otherwise block every
|
|
776
|
+
* later poll until the Hook restarts. */
|
|
777
|
+
export const USAGE_READ_LIMIT_MS = 30_000;
|
|
778
|
+
function bounded(read, fallback, ms = USAGE_READ_LIMIT_MS) {
|
|
779
|
+
let timer;
|
|
780
|
+
const late = new Promise(resolve => { timer = setTimeout(() => resolve(fallback()), ms); timer.unref?.(); });
|
|
781
|
+
return Promise.race([read, late]).finally(() => clearTimeout(timer));
|
|
782
|
+
}
|
|
783
|
+
const unanswered = (source, name) => ({ source, windows: [], message: `${name} did not answer in time on this computer. Phren will ask again shortly.` });
|
|
774
784
|
export class AccountUsageReader {
|
|
775
785
|
readCodex;
|
|
776
786
|
now;
|
|
@@ -812,7 +822,7 @@ export class AccountUsageReader {
|
|
|
812
822
|
/** Codex and every Claude home, without the spend readers: what a dispatch capacity probe asks. */
|
|
813
823
|
async limits(allAccounts = true) {
|
|
814
824
|
if (!this.cached || this.now() - this.cached.at >= 60_000) {
|
|
815
|
-
this.pending ??= this.readCodex().then(value => { this.cached = { at: this.now(), value }; return value; }).finally(() => { this.pending = undefined; });
|
|
825
|
+
this.pending ??= bounded(this.readCodex(), () => unanswered("codex", "Codex")).then(value => { this.cached = { at: this.now(), value }; return value; }).finally(() => { this.pending = undefined; });
|
|
816
826
|
}
|
|
817
827
|
const codex = this.pending ?? Promise.resolve(this.cached.value);
|
|
818
828
|
// Every home, default first; the labels and keys are read once per poll.
|
|
@@ -822,7 +832,7 @@ export class AccountUsageReader {
|
|
|
822
832
|
const email = claudeAccountEmail(home);
|
|
823
833
|
const credits = claudeCredits(home.id);
|
|
824
834
|
// Claude Code's own answer only when the profile can't name the plan, or a credit asks whether this is a Console login.
|
|
825
|
-
const auth = credits.length || claudePlanUnknown(home) ? await this.readAuth(home).catch(() => undefined) : undefined;
|
|
835
|
+
const auth = credits.length || claudePlanUnknown(home) ? await bounded(this.readAuth(home).catch(() => undefined), () => undefined) : undefined;
|
|
826
836
|
const fallback = auth?.console ? "Console" : auth?.plan ? claudePlan({ subscriptionType: auth.plan }) : undefined;
|
|
827
837
|
const subscription = claudeAccountSubscription(home, now, fallback);
|
|
828
838
|
const usage = settleClaudeUsage(await this.claude(home), this.now());
|
|
@@ -840,9 +850,10 @@ export class AccountUsageReader {
|
|
|
840
850
|
if (!cached || this.now() - cached.at >= 60_000) {
|
|
841
851
|
const at = this.now();
|
|
842
852
|
if (!this.spendingPending.has(key)) {
|
|
843
|
-
const pending = Promise.all([this.openCode(at), this.readOpenCodeGo(new Date(at)),
|
|
844
|
-
|
|
845
|
-
|
|
853
|
+
const pending = Promise.all([this.openCode(at), bounded(this.readOpenCodeGo(new Date(at)), () => unanswered("opencode-go", "OpenCode Go")),
|
|
854
|
+
bounded(this.readOpenRouter(new Date(at)), () => undefined),
|
|
855
|
+
includeCopilot ? bounded(this.readCopilot(new Date(at)), () => unanswered("copilot", "GitHub Copilot")) : Promise.resolve(undefined),
|
|
856
|
+
includeElevenLabs ? bounded(this.readElevenLabs(new Date(at)).catch(() => undefined), () => undefined) : Promise.resolve(undefined)])
|
|
846
857
|
.then(([openCode, openCodeGo, openRouter, copilot, elevenLabs]) => [openCode, openCodeGo, ...(openRouter ? [openRouter] : []), ...(copilot ? [copilot] : []), ...(elevenLabs ? [elevenLabs] : [])])
|
|
847
858
|
.then(value => { this.spendingCached.set(key, { at, value }); return value; })
|
|
848
859
|
.finally(() => { this.spendingPending.delete(key); });
|
|
@@ -855,8 +866,11 @@ export class AccountUsageReader {
|
|
|
855
866
|
openCode(at) {
|
|
856
867
|
if (this.openCodeCached && at - this.openCodeCached.at < OPENCODE_STATS_REUSE_MS)
|
|
857
868
|
return Promise.resolve(this.openCodeCached.value);
|
|
858
|
-
|
|
859
|
-
|
|
869
|
+
let late = false;
|
|
870
|
+
this.openCodePending ??= bounded(this.readOpenCode(new Date(at)), () => { late = true; return unanswered("opencode", "opencode stats"); })
|
|
871
|
+
// A late answer is not kept for the ten minutes a real one is.
|
|
872
|
+
.then(value => { if (!late)
|
|
873
|
+
this.openCodeCached = { at, value }; return value; })
|
|
860
874
|
.finally(() => { this.openCodePending = undefined; });
|
|
861
875
|
return this.openCodePending;
|
|
862
876
|
}
|
|
@@ -870,7 +884,7 @@ export class AccountUsageReader {
|
|
|
870
884
|
if (!cached || this.now() - cached.at >= 60_000) {
|
|
871
885
|
const at = this.now();
|
|
872
886
|
if (!this.claudePending.has(home.dir))
|
|
873
|
-
this.claudePending.set(home.dir, this.readClaudeLive(new Date(at), home)
|
|
887
|
+
this.claudePending.set(home.dir, bounded(this.readClaudeLive(new Date(at), home), () => undefined)
|
|
874
888
|
.then(value => { this.claudeCached.set(home.dir, { at, value }); return value; })
|
|
875
889
|
.catch(() => { this.claudeCached.set(home.dir, { at, value: undefined }); return undefined; })
|
|
876
890
|
.finally(() => { this.claudePending.delete(home.dir); }));
|