@phren/cli 0.3.51 → 0.3.53
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/gitboy-webhooks.d.ts +25 -0
- package/dist/bridge/gitboy-webhooks.js +200 -0
- package/dist/bridge/server-launch.js +61 -2
- package/dist/bridge/server-routes.d.ts +4 -0
- package/dist/bridge/server-routes.js +8 -1
- package/dist/bridge/server.js +7 -2
- package/dist/bridge/session-move.js +3 -1
- package/dist/bridge/store-pull.d.ts +22 -0
- package/dist/bridge/store-pull.js +62 -0
- package/dist/bridge-hook.mjs +2696 -2059
- package/dist/modules/registry.js +2 -2
- package/dist/sync/gitboy-webhook.js +2 -2
- package/dist/sync/pull-now.d.ts +11 -0
- package/dist/sync/pull-now.js +64 -0
- package/dist/sync/pull.d.ts +1 -1
- package/dist/sync/pull.js +4 -4
- package/package.json +1 -1
package/dist/modules/registry.js
CHANGED
|
@@ -40,7 +40,7 @@ export const BUILTIN_MODULES = [
|
|
|
40
40
|
{ agents: ["claude", "codex", "copilot", "cursor"], events: ["Stop"], handler: "phren hook-stop" },
|
|
41
41
|
{ agents: ["claude"], events: ["PostToolUse"], handler: "phren hook-tool" },
|
|
42
42
|
],
|
|
43
|
-
hookRoutes: [...routes("GET", ["/v1/store/head", "/v1/store/tree", "/v1/store/blob"]), ...routes("POST", ["/v1/store/blobs", "/v1/store/file", "/v1/store/delete"])],
|
|
43
|
+
hookRoutes: [...routes("GET", ["/v1/store/head", "/v1/store/tree", "/v1/store/blob"]), ...routes("POST", ["/v1/store/pull-now", "/v1/store/blobs", "/v1/store/file", "/v1/store/delete"])],
|
|
44
44
|
capabilities: ["memory", "memoryStore", "memoryStoreBatch", "projectMemory"],
|
|
45
45
|
storeFiles: [
|
|
46
46
|
"phren.root.yaml", "machines.yaml", "profiles/*.yaml", ".config/modules.yaml", ".config/*.json",
|
|
@@ -101,7 +101,7 @@ export const BUILTIN_MODULES = [
|
|
|
101
101
|
"files", "repositoryFiles", "fileResolution", "subagents", "sideQuestions", "approvalPush", "simulators", "overviewStream", "speech", "speechTimestamps", "speechTimestampStream", "speechLive", "speechVoices", "speechFormats", "transcribe", "promptOnce", "promptStatus", "deliveryFrames", "resources", "sessionRename", "sudo", "sudoOutcome", "previewDeltas", "quickChat", "agentFolder", "launchPermissionMode", "sessionMove", "moveNewChat", "moveConductor",
|
|
102
102
|
],
|
|
103
103
|
storeFiles: [".runtime/sessions/opencode-*.events.jsonl", ".runtime/approvals/opencode-*.json"],
|
|
104
|
-
localFiles: ["<bridge>/installed.json", "<bridge>/versions/**", "<bridge>/current", "<bridge>/dispatch", "<bridge>/askpass", "<bridge>/computer-id", "<bridge>/canary.json", "<bridge>/canary-daily", "<bridge>/moves/*.json"],
|
|
104
|
+
localFiles: ["<bridge>/gitboy-webhooks.json", "<bridge>/installed.json", "<bridge>/versions/**", "<bridge>/current", "<bridge>/dispatch", "<bridge>/askpass", "<bridge>/computer-id", "<bridge>/canary.json", "<bridge>/canary-daily", "<bridge>/moves/*.json"],
|
|
105
105
|
phoneScreens: [{ screen: "LiveSessionsView", capability: "hook" }, { screen: "AgentChatView", capability: "transcript" }],
|
|
106
106
|
skills: [],
|
|
107
107
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transport-agnostic core for gitboy push webhooks: signature checks, push payload parsing,
|
|
3
|
-
* matching a push to a store's branch, and delivery de-duplication.
|
|
4
|
-
*
|
|
3
|
+
* matching a push to a store's branch, and delivery de-duplication. Used by the optional
|
|
4
|
+
* Hook receiver; periodic polling (pull.ts) stays the fallback.
|
|
5
5
|
*/
|
|
6
6
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
7
7
|
const SIGNATURE_PREFIX = "sha256=";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type PullResult } from "./pull.js";
|
|
2
|
+
/** One running pull and one pending wakeup per store; also respects sibling-process locks. */
|
|
3
|
+
export declare class ImmediatePulls {
|
|
4
|
+
private readonly pull;
|
|
5
|
+
private readonly intervalMs;
|
|
6
|
+
private readonly states;
|
|
7
|
+
private stopped;
|
|
8
|
+
constructor(pull?: (store: string) => Promise<PullResult>, intervalMs?: number);
|
|
9
|
+
request(store: string): void;
|
|
10
|
+
stop(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { pollStore } from "./pull.js";
|
|
2
|
+
/** One running pull and one pending wakeup per store; also respects sibling-process locks. */
|
|
3
|
+
export class ImmediatePulls {
|
|
4
|
+
pull;
|
|
5
|
+
intervalMs;
|
|
6
|
+
states = new Map();
|
|
7
|
+
stopped = false;
|
|
8
|
+
constructor(pull = store => pollStore(store, 0, undefined, Date.now(), true), intervalMs = 10_000) {
|
|
9
|
+
this.pull = pull;
|
|
10
|
+
this.intervalMs = intervalMs;
|
|
11
|
+
}
|
|
12
|
+
request(store) {
|
|
13
|
+
if (this.stopped)
|
|
14
|
+
return;
|
|
15
|
+
let state = this.states.get(store);
|
|
16
|
+
if (!state) {
|
|
17
|
+
state = { pending: false, running: false, last: -Infinity, retries: 0 };
|
|
18
|
+
this.states.set(store, state);
|
|
19
|
+
}
|
|
20
|
+
state.pending = true;
|
|
21
|
+
state.retries = 0;
|
|
22
|
+
if (state.running || state.timer)
|
|
23
|
+
return;
|
|
24
|
+
const run = async () => {
|
|
25
|
+
state.timer = undefined;
|
|
26
|
+
if (this.stopped)
|
|
27
|
+
return;
|
|
28
|
+
state.pending = false;
|
|
29
|
+
state.running = true;
|
|
30
|
+
state.last = Date.now();
|
|
31
|
+
try {
|
|
32
|
+
const result = await this.pull(store);
|
|
33
|
+
// A sibling process may own either coordination lock. Keep one wakeup until it releases.
|
|
34
|
+
if (result.status === "deferred" && (result.detail === "Coordinated pull is running."
|
|
35
|
+
|| result.detail === "Periodic pull deferred: another Phren Git operation is running."
|
|
36
|
+
|| result.detail === "Periodic pull deferred: a Git operation is in progress.")) {
|
|
37
|
+
if (state.retries < 2) {
|
|
38
|
+
state.retries++;
|
|
39
|
+
state.pending = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
state.retries = 0;
|
|
44
|
+
}
|
|
45
|
+
catch { /* The next nudge or fallback poll retries failures. */ }
|
|
46
|
+
finally {
|
|
47
|
+
state.running = false;
|
|
48
|
+
if (state.pending && !this.stopped)
|
|
49
|
+
schedule();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const schedule = () => {
|
|
53
|
+
const delay = Math.max(0, state.last + this.intervalMs * Math.max(1, state.retries) - Date.now());
|
|
54
|
+
state.timer = setTimeout(() => { void run(); }, delay);
|
|
55
|
+
state.timer.unref();
|
|
56
|
+
};
|
|
57
|
+
schedule();
|
|
58
|
+
}
|
|
59
|
+
stop() {
|
|
60
|
+
this.stopped = true;
|
|
61
|
+
for (const state of this.states.values())
|
|
62
|
+
clearTimeout(state.timer);
|
|
63
|
+
}
|
|
64
|
+
}
|
package/dist/sync/pull.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface PullResult {
|
|
|
27
27
|
*/
|
|
28
28
|
export declare function readPollState(phrenPath: string): PollState;
|
|
29
29
|
/** Shared timestamps + a process lock give all MCP clients one check per store/interval. */
|
|
30
|
-
export declare function pollStore(phrenPath: string, seconds: number, git?: RunGit, now?: number): Promise<PullResult>;
|
|
30
|
+
export declare function pollStore(phrenPath: string, seconds: number, git?: RunGit, now?: number, immediate?: boolean): Promise<PullResult>;
|
|
31
31
|
interface PollingOptions {
|
|
32
32
|
onChange: () => Promise<void>;
|
|
33
33
|
/** Share the MCP write queue so background updates cannot overlap its writes. */
|
package/dist/sync/pull.js
CHANGED
|
@@ -104,13 +104,13 @@ function logPeriodicSync(phrenPath, detail) {
|
|
|
104
104
|
appendSyncLog(phrenPath, "periodic-pull", detail);
|
|
105
105
|
}
|
|
106
106
|
/** Shared timestamps + a process lock give all MCP clients one check per store/interval. */
|
|
107
|
-
export async function pollStore(phrenPath, seconds, git = runPollGit, now = Date.now()) {
|
|
107
|
+
export async function pollStore(phrenPath, seconds, git = runPollGit, now = Date.now(), immediate = false) {
|
|
108
108
|
const skipped = { status: "not-due", detail: "Periodic check not due." };
|
|
109
|
-
if (!seconds || !periodicPullEnabled(phrenPath) || !fs.existsSync(path.join(phrenPath, ".git")))
|
|
109
|
+
if ((!seconds && !immediate) || !periodicPullEnabled(phrenPath) || !fs.existsSync(path.join(phrenPath, ".git")))
|
|
110
110
|
return skipped;
|
|
111
111
|
const releasePoll = tryFileLock(runtimeFile(phrenPath, "pull-poll"));
|
|
112
112
|
if (!releasePoll)
|
|
113
|
-
return skipped;
|
|
113
|
+
return immediate ? { status: "deferred", detail: "Coordinated pull is running." } : skipped;
|
|
114
114
|
try {
|
|
115
115
|
const auth = activeStoreAuthFailure(phrenPath);
|
|
116
116
|
if (authBackoffActive(auth, now))
|
|
@@ -119,7 +119,7 @@ export async function pollStore(phrenPath, seconds, git = runPollGit, now = Date
|
|
|
119
119
|
const previous = readPollState(phrenPath);
|
|
120
120
|
const failures = Math.min(10, Math.max(0, Number(previous.failures) || 0));
|
|
121
121
|
const delay = Math.min(seconds * 2 ** failures, Math.max(seconds, 1800)) * 1000;
|
|
122
|
-
if (typeof previous.checkedAt === "number" && now >= previous.checkedAt && now - previous.checkedAt < delay)
|
|
122
|
+
if (!immediate && typeof previous.checkedAt === "number" && now >= previous.checkedAt && now - previous.checkedAt < delay)
|
|
123
123
|
return skipped;
|
|
124
124
|
const finish = async (result, verifiedRemote = false) => {
|
|
125
125
|
atomicWriteText(runtimeFile(phrenPath, "pull-poll.json"), JSON.stringify({
|