@phren/cli 0.3.40 → 0.3.41
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/health.d.ts +15 -0
- package/dist/bridge/health.js +32 -2
- package/dist/bridge/server-routes.js +4 -2
- package/dist/bridge/server.js +4 -1
- package/dist/bridge-hook.mjs +21846 -21259
- package/dist/cli/govern.js +8 -2
- package/dist/cli/session-git.js +1 -0
- package/dist/cli/session-start.js +18 -10
- package/dist/cli/session-stop.js +12 -1
- package/dist/governance/policy.d.ts +3 -0
- package/dist/governance/policy.js +4 -0
- package/dist/link/doctor.js +57 -0
- package/dist/sync/auth-heal.d.ts +15 -0
- package/dist/sync/auth-heal.js +94 -0
- package/dist/sync/auth.js +19 -5
- package/dist/sync/conflict-resolve.d.ts +1 -1
- package/dist/sync/conflict-resolve.js +28 -8
- package/dist/sync/maintenance-writer.d.ts +7 -0
- package/dist/sync/maintenance-writer.js +37 -0
- package/dist/sync/pull.d.ts +2 -0
- package/dist/sync/pull.js +5 -3
- package/dist/sync/store-cleanup.d.ts +11 -0
- package/dist/sync/store-cleanup.js +117 -0
- package/dist/sync/store-merge.d.ts +4 -0
- package/dist/sync/store-merge.js +14 -1
- package/dist/sync/store-sync.d.ts +60 -0
- package/dist/sync/store-sync.js +182 -0
- package/dist/sync/task-merge.d.ts +5 -0
- package/dist/sync/task-merge.js +57 -15
- package/package.json +1 -1
package/dist/bridge/health.d.ts
CHANGED
|
@@ -18,8 +18,17 @@ export interface StoreSync {
|
|
|
18
18
|
lastPushAt?: string;
|
|
19
19
|
lastSuccessfulPushAt?: string;
|
|
20
20
|
consecutiveFailures?: number;
|
|
21
|
+
lastSuccessfulPullAt?: string;
|
|
22
|
+
/** The newest successful pull or push. */
|
|
23
|
+
lastSyncedAt?: string;
|
|
24
|
+
/** Both the store and its remote have commits the other lacks. */
|
|
25
|
+
diverged?: boolean;
|
|
26
|
+
/** No successful sync for over STORE_STALE_MS while the store has a remote. */
|
|
27
|
+
stale?: boolean;
|
|
21
28
|
/** The last sync failure in plain words, only while the store is failing. */
|
|
22
29
|
error?: string;
|
|
30
|
+
/** One line a computer list shows as is when the store needs attention. */
|
|
31
|
+
warning?: string;
|
|
23
32
|
degraded: boolean;
|
|
24
33
|
}
|
|
25
34
|
export interface LastScheduledRun {
|
|
@@ -121,6 +130,12 @@ export declare function toolVersion(tool: string, executable?: string, args?: st
|
|
|
121
130
|
export declare function clearVersionCache(): void;
|
|
122
131
|
/** Branch and ahead/behind against the upstream as last fetched; nothing is fetched here. */
|
|
123
132
|
export declare function storeSync(store: string): Promise<StoreSync[]>;
|
|
133
|
+
/**
|
|
134
|
+
* The degraded stores' warnings for the overview: the last answer at once,
|
|
135
|
+
* refreshed in the background once a minute old, so the overview never
|
|
136
|
+
* waits on Git.
|
|
137
|
+
*/
|
|
138
|
+
export declare function cachedStoreWarnings(store: string, now?: number): string[];
|
|
124
139
|
/** The newest run in schedule-runs.jsonl, with its schedule's name when the project still has it. */
|
|
125
140
|
export declare function lastScheduledRun(store: string, runsFile?: string): Promise<LastScheduledRun | null>;
|
|
126
141
|
/** This computer's public SSH host key, the pin a peer's hooks.yaml holds for it. */
|
package/dist/bridge/health.js
CHANGED
|
@@ -13,6 +13,7 @@ import { BridgeError, bridgeRoot, errorCode } from "./protocol.js";
|
|
|
13
13
|
import { canonicalComputer, latestScheduleBatch, readScheduleDocument, readScheduleRuns, scheduleRunsFile } from "./schedules.js";
|
|
14
14
|
import { countGit } from "./metrics.js";
|
|
15
15
|
import { tmuxHealth } from "./terminal-tmux.js";
|
|
16
|
+
import { lastSyncedAt, STORE_STALE_MS, storeWarning } from "../sync/store-sync.js";
|
|
16
17
|
const exec = promisify(execFile);
|
|
17
18
|
/** The running servers the Hook lists (Herdr's, else tmux's) and tmux's own state. */
|
|
18
19
|
export async function terminalHealth() {
|
|
@@ -126,14 +127,43 @@ export async function storeSync(store) {
|
|
|
126
127
|
result.lastSuccessfulPushAt = sync.lastSuccessfulPushAt;
|
|
127
128
|
if (sync?.consecutiveFailures)
|
|
128
129
|
result.consecutiveFailures = sync.consecutiveFailures;
|
|
130
|
+
if (sync?.lastSuccessfulPullAt)
|
|
131
|
+
result.lastSuccessfulPullAt = sync.lastSuccessfulPullAt;
|
|
132
|
+
const synced = lastSyncedAt(sync);
|
|
133
|
+
if (synced)
|
|
134
|
+
result.lastSyncedAt = synced;
|
|
129
135
|
const failing = sync?.lastPushStatus !== undefined && FAILED_PUSH_STATUSES.has(sync.lastPushStatus);
|
|
130
136
|
const pullFailed = sync?.lastPullStatus === "error";
|
|
131
137
|
if (failing || pullFailed)
|
|
132
|
-
result.error = plainError(sync?.lastPushDetail || sync?.lastPullDetail) ?? `Last sync: ${sync?.lastPushStatus ?? "pull failed"}`;
|
|
133
|
-
|
|
138
|
+
result.error = plainError(sync?.lastError || sync?.lastPushDetail || sync?.lastPullDetail) ?? `Last sync: ${sync?.lastPushStatus ?? "pull failed"}`;
|
|
139
|
+
if (upstream) {
|
|
140
|
+
result.diverged = (result.ahead ?? 0) > 0 && (result.behind ?? 0) > 0;
|
|
141
|
+
result.stale = !synced || Date.now() - Date.parse(synced) > STORE_STALE_MS;
|
|
142
|
+
}
|
|
143
|
+
result.degraded = assessSyncOutage(sync).degraded || result.diverged === true || result.stale === true;
|
|
144
|
+
const warning = storeWarning(result);
|
|
145
|
+
if (warning && result.degraded)
|
|
146
|
+
result.warning = warning;
|
|
134
147
|
return result;
|
|
135
148
|
}));
|
|
136
149
|
}
|
|
150
|
+
const warningCache = new Map();
|
|
151
|
+
/**
|
|
152
|
+
* The degraded stores' warnings for the overview: the last answer at once,
|
|
153
|
+
* refreshed in the background once a minute old, so the overview never
|
|
154
|
+
* waits on Git.
|
|
155
|
+
*/
|
|
156
|
+
export function cachedStoreWarnings(store, now = Date.now()) {
|
|
157
|
+
const entry = warningCache.get(store) ?? { at: 0, value: [] };
|
|
158
|
+
warningCache.set(store, entry);
|
|
159
|
+
if (now - entry.at > 60_000 && !entry.refreshing) {
|
|
160
|
+
entry.refreshing = storeSync(store)
|
|
161
|
+
.then(stores => { entry.value = stores.flatMap(item => item.warning ? [item.warning] : []); entry.at = Date.now(); })
|
|
162
|
+
.catch(() => { entry.at = Date.now(); })
|
|
163
|
+
.finally(() => { entry.refreshing = undefined; });
|
|
164
|
+
}
|
|
165
|
+
return entry.value;
|
|
166
|
+
}
|
|
137
167
|
/** The newest run in schedule-runs.jsonl, with its schedule's name when the project still has it. */
|
|
138
168
|
export async function lastScheduledRun(store, runsFile = scheduleRunsFile()) {
|
|
139
169
|
const runs = await readScheduleRuns(runsFile).catch(() => []);
|
|
@@ -40,7 +40,7 @@ import { listUploads, removeUpload, saveUpload, uploadImage } from "./uploads.js
|
|
|
40
40
|
import { currentModel, currentStep } from "./steps.js";
|
|
41
41
|
import { capacityRoom, usageForCaller } from "./usage.js";
|
|
42
42
|
import { readFinalTurn } from "./schedule-watch.js";
|
|
43
|
-
import { healthDetails, listsCaller } from "./health.js";
|
|
43
|
+
import { cachedStoreWarnings, healthDetails, listsCaller } from "./health.js";
|
|
44
44
|
import { defaultPhrenPath } from "../shared.js";
|
|
45
45
|
import { loadCodePackage, loadedFrom } from "../modules/code-package.js";
|
|
46
46
|
import { gitRepository, paneRoute, uploadBody } from "./server-pane-routes.js";
|
|
@@ -266,7 +266,9 @@ export function workspacesReader(ctx) {
|
|
|
266
266
|
expired = true;
|
|
267
267
|
clearTimeout(timer);
|
|
268
268
|
const mux = terminalMux(server);
|
|
269
|
-
|
|
269
|
+
// A diverged or long-unsynced store, for the computer list (health.ts storeWarning).
|
|
270
|
+
const storeWarnings = cachedStoreWarnings(defaultPhrenPath());
|
|
271
|
+
return { ...workspaces, kind: mux.kind, mux, phren: info, ...(storeWarnings.length ? { storeWarnings } : {}) };
|
|
270
272
|
};
|
|
271
273
|
}
|
|
272
274
|
/** One read-only GET to every linked peer, each answer or its error by computer name. */
|
package/dist/bridge/server.js
CHANGED
|
@@ -63,6 +63,7 @@ import { targetTranscriptPath } from "./transcripts.js";
|
|
|
63
63
|
import { codexAppServerEnabled, codexServers } from "./codex-servers.js";
|
|
64
64
|
import { CodexAuthKeeper, codexAuthRefreshEnabled } from "./codex-auth-refresh.js";
|
|
65
65
|
import { localNames } from "./computer-names.js";
|
|
66
|
+
import { startStoreSyncLoop } from "../sync/store-sync.js";
|
|
66
67
|
export { capabilities, capabilitiesForModules, requireRoute } from "./server-routes.js";
|
|
67
68
|
export { streamCloseReason } from "./server-stream.js";
|
|
68
69
|
export { herdrAgentName, launchSession } from "./server-launch.js";
|
|
@@ -299,6 +300,8 @@ export async function serve(version, options = {}) {
|
|
|
299
300
|
const codexAuthTimer = codexAuth ? setInterval(() => { void codexAuth.tick().catch(() => { }); }, 60 * 60_000) : undefined;
|
|
300
301
|
if (codexAuth)
|
|
301
302
|
setTimeout(() => { void codexAuth.tick().catch(() => { }); }, 60_000).unref();
|
|
303
|
+
// Every store converges with its remote even when no agent session runs here (store-sync.ts).
|
|
304
|
+
const storeSync = startStoreSyncLoop(scheduleStore);
|
|
302
305
|
const canaryTimer = setInterval(() => { countTick("canary"); void dailyCanaryDue().then(due => due ? canary("daily") : undefined).catch(() => { }); }, 10 * 60_000);
|
|
303
306
|
let recording = false;
|
|
304
307
|
const activityTimer = setInterval(() => {
|
|
@@ -346,7 +349,7 @@ export async function serve(version, options = {}) {
|
|
|
346
349
|
})().finally(() => { recording = false; }).catch(() => { });
|
|
347
350
|
}, 5000);
|
|
348
351
|
await new Promise(resolve => {
|
|
349
|
-
const stop = () => { fanoutMessages.close(); stopRetention(); clearInterval(scheduleTimer); clearInterval(canaryTimer); clearInterval(codexAuthTimer); clearInterval(activityTimer); scheduler?.close(); codeReindexer?.close(); codexServers.close(); agentHooks.close(); ws.clients.forEach(c => c.terminate()); ws.close(); http.close(() => resolve()); http.closeAllConnections(); };
|
|
352
|
+
const stop = () => { storeSync.stop(); fanoutMessages.close(); stopRetention(); clearInterval(scheduleTimer); clearInterval(canaryTimer); clearInterval(codexAuthTimer); clearInterval(activityTimer); scheduler?.close(); codeReindexer?.close(); codexServers.close(); agentHooks.close(); ws.clients.forEach(c => c.terminate()); ws.close(); http.close(() => resolve()); http.closeAllConnections(); };
|
|
350
353
|
process.once("SIGTERM", stop);
|
|
351
354
|
process.once("SIGINT", stop);
|
|
352
355
|
});
|