@phren/cli 0.3.65 → 0.3.67

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.
Files changed (37) hide show
  1. package/dist/bridge/account-choice.d.ts +12 -3
  2. package/dist/bridge/account-choice.js +133 -19
  3. package/dist/bridge/account-last-known.d.ts +27 -0
  4. package/dist/bridge/account-last-known.js +124 -0
  5. package/dist/bridge/changes.d.ts +22 -0
  6. package/dist/bridge/changes.js +323 -82
  7. package/dist/bridge/claude-accounts.d.ts +27 -0
  8. package/dist/bridge/claude-accounts.js +63 -8
  9. package/dist/bridge/dispatch-returns.d.ts +8 -0
  10. package/dist/bridge/dispatch-returns.js +20 -2
  11. package/dist/bridge/files.d.ts +1 -1
  12. package/dist/bridge/harnesses.js +8 -2
  13. package/dist/bridge/helper.d.ts +3 -2
  14. package/dist/bridge/helper.js +5 -4
  15. package/dist/bridge/machine-health-alerts.d.ts +20 -0
  16. package/dist/bridge/machine-health-alerts.js +47 -0
  17. package/dist/bridge/machine-health.d.ts +42 -0
  18. package/dist/bridge/machine-health.js +124 -0
  19. package/dist/bridge/machine-probes.d.ts +58 -0
  20. package/dist/bridge/machine-probes.js +306 -0
  21. package/dist/bridge/push.d.ts +10 -0
  22. package/dist/bridge/push.js +15 -0
  23. package/dist/bridge/resources.d.ts +5 -0
  24. package/dist/bridge/resources.js +16 -2
  25. package/dist/bridge/schedule-launch.js +2 -2
  26. package/dist/bridge/server-launch.js +3 -1
  27. package/dist/bridge/server.js +5 -1
  28. package/dist/bridge-hook.mjs +29235 -28083
  29. package/dist/computers/read.d.ts +18 -0
  30. package/dist/computers/read.js +18 -0
  31. package/dist/governance/policy.js +4 -3
  32. package/dist/governance/scores.js +2 -1
  33. package/dist/modules/registry.js +1 -1
  34. package/dist/tools/dispatch.js +16 -0
  35. package/dist/tools/helper.js +1 -1
  36. package/package.json +1 -1
  37. package/starter/global/skills/conductor/SKILL.md +6 -0
@@ -85,4 +85,22 @@ export declare function readUsage(options?: {
85
85
  hookError?: string;
86
86
  peerError?: string;
87
87
  }>;
88
+ export interface MachineHealthRow {
89
+ name: string;
90
+ local: boolean;
91
+ online: boolean;
92
+ /** Worst severity on this computer, `ok` when it reported none. */
93
+ worst?: "high" | "warn" | "info" | "ok";
94
+ findings?: NonNullable<ComputerResources["health"]>;
95
+ /** The computer's Hook predates health findings; nothing is known about it. */
96
+ unsupported?: true;
97
+ error?: string;
98
+ }
99
+ /** Each computer's health findings, worst computer first, and a one-line summary. */
100
+ export declare function machineHealthReport(computers: ComputerReport[]): {
101
+ computers: MachineHealthRow[];
102
+ high: number;
103
+ warn: number;
104
+ message: string;
105
+ };
88
106
  export {};
@@ -181,3 +181,21 @@ export async function readUsage(options = {}) {
181
181
  const combined = combineUsage(computers.flatMap(c => c.harnesses ? [c.harnesses] : []));
182
182
  return { computers, combined, ...(typeof answer.peerError === "string" ? { peerError: answer.peerError } : {}) };
183
183
  }
184
+ /** Each computer's health findings, worst computer first, and a one-line summary. */
185
+ export function machineHealthReport(computers) {
186
+ const order = { high: 0, warn: 1, info: 2, ok: 3 };
187
+ const rows = computers.map(c => {
188
+ if (!c.online || !c.resources)
189
+ return { name: c.name, local: c.local, online: false, error: c.error ?? "Unavailable" };
190
+ const findings = c.resources.health;
191
+ if (!findings)
192
+ return { name: c.name, local: c.local, online: true, unsupported: true };
193
+ return { name: c.name, local: c.local, online: true, worst: findings[0]?.severity ?? "ok", findings };
194
+ });
195
+ rows.sort((a, b) => (a.worst ? order[a.worst] : 4) - (b.worst ? order[b.worst] : 4));
196
+ const count = (s) => rows.reduce((n, r) => n + (r.findings?.filter(f => f.severity === s).length ?? 0), 0);
197
+ const high = count("high"), warn = count("warn");
198
+ const parts = rows.map(r => !r.online ? `${r.name} offline` : r.unsupported ? `${r.name} no health (older Hook)`
199
+ : r.worst === "ok" ? `${r.name} ok` : `${r.name}: ${r.findings.filter(f => f.severity !== "info").map(f => `${f.severity} ${f.title}`).join("; ") || "info only"}`);
200
+ return { computers: rows, high, warn, message: `${high} high, ${warn} warn across ${rows.length} computers. ${parts.join(". ")}.` };
201
+ }
@@ -8,6 +8,7 @@ import { storeAwareProjectPath } from "../store-routing.js";
8
8
  import { readProjectConfig } from "../project-config.js";
9
9
  import { getActiveProfileDefaults } from "../profile-store.js";
10
10
  import { runCustomHooks } from "../hooks.js";
11
+ import { renameOverSync } from "../phren-paths.js";
11
12
  import { METADATA_REGEX, isCitationLine, isArchiveStart as isArchiveStartMeta, isArchiveEnd as isArchiveEndMeta, stripLifecycleMetadata as stripLifecycleMetadataMeta, } from "../content/metadata.js";
12
13
  import { findingAgeLimitDays } from "../content/citation.js";
13
14
  import { VALID_FINDING_SENSITIVITY, VALID_PROACTIVITY_LEVELS, VALID_TASK_MODES, VALID_RISKY_SECTIONS, } from "./policy-constants.js";
@@ -504,7 +505,7 @@ function writeJsonFileUnlocked(filePath, data) {
504
505
  fs.mkdirSync(dir, { recursive: true });
505
506
  const tmpPath = path.join(dir, `.tmp-${crypto.randomUUID()}`);
506
507
  fs.writeFileSync(tmpPath, JSON.stringify(data, null, 2) + "\n");
507
- fs.renameSync(tmpPath, filePath);
508
+ renameOverSync(tmpPath, filePath);
508
509
  }
509
510
  function getRetentionPolicyGlobal(phrenPath) {
510
511
  const parsed = readJsonFile(govFile(phrenPath, "retention-policy"), {});
@@ -904,7 +905,7 @@ export function pruneDeadMemories(phrenPath, project, dryRun) {
904
905
  if (!dryRun) {
905
906
  const tmpFile = file + `.tmp-${crypto.randomUUID()}`;
906
907
  fs.writeFileSync(tmpFile, next.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n");
907
- fs.renameSync(tmpFile, file);
908
+ renameOverSync(tmpFile, file);
908
909
  }
909
910
  });
910
911
  }
@@ -1066,7 +1067,7 @@ export function consolidateProjectFindings(phrenPath, project, dryRun) {
1066
1067
  fs.copyFileSync(file, file + ".bak");
1067
1068
  const tmpFile = file + `.tmp-${crypto.randomUUID()}`;
1068
1069
  fs.writeFileSync(tmpFile, out.join("\n").trimEnd() + "\n");
1069
- fs.renameSync(tmpFile, file);
1070
+ renameOverSync(tmpFile, file);
1070
1071
  appendAuditLog(phrenPath, "consolidate_project", `project=${project} dates=${dates.length}`);
1071
1072
  return phrenOk(`Consolidated findings for ${project}.`);
1072
1073
  });
@@ -5,6 +5,7 @@ import { appendAuditLog, debugLog, isRecord, memoryScoresFile, memoryUsageLogFil
5
5
  import { withFileLock, isFiniteNumber, hasValidSchemaVersion } from "../shared/governance.js";
6
6
  import { errorMessage } from "../utils.js";
7
7
  import { logger } from "../logger.js";
8
+ import { renameOverSync } from "../phren-paths.js";
8
9
  const MAX_LOG_LINES = 1000;
9
10
  const GOVERNANCE_SCHEMA_VERSION = 1;
10
11
  const DEFAULT_MEMORY_SCORES_FILE = {
@@ -80,7 +81,7 @@ function writeScoresFile(phrenPath, scores) {
80
81
  schemaVersion: GOVERNANCE_SCHEMA_VERSION,
81
82
  entries: scores,
82
83
  }, null, 2) + "\n");
83
- fs.renameSync(tmpPath, file);
84
+ renameOverSync(tmpPath, file);
84
85
  });
85
86
  }
86
87
  let scoresCache = null;
@@ -130,7 +130,7 @@ export const BUILTIN_MODULES = [
130
130
  },
131
131
  {
132
132
  schemaVersion: 1, name: "conductor", version: VERSION, defaultEnabled: false, requires: ["memory", "hook"],
133
- tools: full(["dispatch", "dispatch_returns", "dispatch_approve", "hand_off", "live_sessions", "account_usage", "authority", "dispatch_report", "owner_inbox", "move_session", "helper"]), cliCommands: ["dispatch", "dispatch status", "dispatch returns", "dispatch sessions", "dispatch usage", "dispatch report", "hand-off", "move", "conductor", "conductor grants", "conductor status", "conductor make", "conductor stop", "conductor sets", "conductor integrator", "owner-inbox", "authority", "bridge enroll-computer"], agentHooks: [],
133
+ tools: full(["dispatch", "dispatch_returns", "dispatch_approve", "hand_off", "live_sessions", "account_usage", "machine_health", "authority", "dispatch_report", "owner_inbox", "move_session", "helper"]), cliCommands: ["dispatch", "dispatch status", "dispatch returns", "dispatch sessions", "dispatch usage", "dispatch report", "hand-off", "move", "conductor", "conductor grants", "conductor status", "conductor make", "conductor stop", "conductor sets", "conductor integrator", "owner-inbox", "authority", "bridge enroll-computer"], agentHooks: [],
134
134
  hookRoutes: [...routes("GET", ["/v1/dispatch", "/v1/dispatch/capacity", "/v1/conductor/move/status", "/v1/conductor/move/launch", "/v1/conductor/move/operation", "/v1/conductor/move/notification", "/v1/dispatch/brief", "/v1/conductor", "/v1/conductor/grants", "/v1/computers", "/v1/sets", "/v1/authority", "/v1/owner-inbox", "/v1/conductor/integrator"]),
135
135
  ...routes("POST", ["/v1/conductor/call", "/v1/conductor/move/prepare", "/v1/conductor/move/commit", "/v1/conductor/move/operate", "/v1/conductor/move/ack", "/v1/conductor/move/notice", "/v1/dispatch", "/v1/dispatch/workers", "/v1/dispatch/returns", "/v1/dispatch/approve", "/v1/dispatch/report", "/v1/dispatch/close", "/v1/dispatch/close-self", "/v1/owner-inbox", "/v1/conductor/integrator", "/v1/hand-off", "/v1/hand-off/status", "/v1/conductor/grants", "/v1/conductor/make", "/v1/conductor/stop", "/v1/sets/name", "/v1/sets/link", "/v1/authority", "/v1/authority/confirm"]), ...routes("DELETE", ["/v1/conductor/grants", "/v1/authority"])],
136
136
  capabilities: ["dispatch", "moveConductorToComputer", "conductorSets", "setLink", "ownerInbox", "workerReports", "queuedHandOff"], storeFiles: ["global/skills/conductor/**"],
@@ -5,6 +5,7 @@ import { hookRequest } from "../bridge/client.js";
5
5
  import { dispatchSchema } from "../bridge/dispatch.js";
6
6
  import { handOff, handOffSchema, listLiveSessions, moveSession, moveSessionSchema } from "../bridge/hand-off.js";
7
7
  import { readAccountUsage, usageSummary } from "../bridge/account-usage.js";
8
+ import { machineHealthReport, readComputers } from "../computers/read.js";
8
9
  import { terminalPaneFromEnv } from "../bridge/terminal.js";
9
10
  import { dispatchIdFromEnv } from "../bridge/launch-brief.js";
10
11
  import { approvalDecisions } from "../bridge/protocol.js";
@@ -122,6 +123,21 @@ export function register(server) {
122
123
  return mcpResponse({ ok: false, error: error instanceof Error ? error.message : "Could not read account usage." });
123
124
  }
124
125
  });
126
+ server.registerTool("machine_health", {
127
+ title: "◆ phren · machine health",
128
+ description: "Named health findings for this computer and every linked computer, worst computer first: swap, disk, load pileups, memory hogs and leaks, orphaned processes, simulator clones, restart loops, failed units, backup age, pending updates, crashes, OOM kills, GPU errors and stale locks. Each finding has id, check, severity (high, warn, info), title, detail and fix. A computer whose Hook predates health findings says unsupported; an unreachable one says offline. For the conductor's watchdog: act on or report high findings; warn is worth a mention. Read-only.",
129
+ inputSchema: {},
130
+ }, async () => {
131
+ try {
132
+ const read = await readComputers();
133
+ const report = machineHealthReport(read.computers);
134
+ const note = read.hookError ? ` ${read.hookError}` : read.peerError ? ` Linked computers were skipped: ${read.peerError}` : "";
135
+ return mcpResponse({ ok: true, data: report, message: `${report.message}${note}` });
136
+ }
137
+ catch (error) {
138
+ return mcpResponse({ ok: false, error: error instanceof Error ? error.message : "Could not read machine health." });
139
+ }
140
+ });
125
141
  server.registerTool("authority", {
126
142
  title: "◆ phren · release authority",
127
143
  description: "Read the owner's release authority policy: per project, which release-type actions (merge, publish, deploy, app-store, github-admin) are go and which are ask-first, and the highest permission mode an agent may start a worker in there. Quote the project's `line` in a brief that asks for release work, and declare those actions in dispatch's releaseActions. An ask-first action needs the owner's confirmation first; ask the owner, never try to confirm it yourself. Read-only: only the owner changes the policy. Without project, lists every project the policy names.",
@@ -7,7 +7,7 @@ import { mcpResponse, resolveStoreForProject } from "./types.js";
7
7
  export function register(server, ctx) {
8
8
  server.registerTool("helper", {
9
9
  title: "◆ phren · helper",
10
- description: `Run one small, self-contained task as a headless Claude Code run (claude -p) under the project's helper account and model (phren.project.yaml helper: { account, model }, model haiku by default), in your folder (a project checkout or worktree), and return its reply. Use it for narrow work you can describe fully in one prompt (summarize a file, draft a test, look something up); the helper sees no conversation, only the prompt and the folder. It bills the helper account, not yours: Claude Code's own subagents always run under your login. Read-only unless allowEdits (Bash and the edit tools are refused); no MCP servers. Stops after timeoutSeconds (default ${HELPER_TIMEOUT_DEFAULT_S}, at most ${HELPER_TIMEOUT_MAX_S}). Refused when the project has no helper account, the account's role is off, or its pool is not allowed for the project or this computer.`,
10
+ description: `Run one small, self-contained task as a headless Claude Code run (claude -p) under the project's helper account and model (phren.project.yaml helper: { account, model }, model haiku by default), in your folder (a project checkout or worktree), and return its reply. Use it for narrow work you can describe fully in one prompt (summarize a file, draft a test, look something up); the helper sees no conversation, only the prompt and the folder. It bills the helper account, not yours: Claude Code's own subagents always run under your login. Read-only unless allowEdits (Bash and the edit tools are refused); no MCP servers. Stops after timeoutSeconds (default ${HELPER_TIMEOUT_DEFAULT_S}, at most ${HELPER_TIMEOUT_MAX_S}). Refused when the project has no helper account, the account's role is not helpers, or its pool is not allowed for the project or this computer.`,
11
11
  inputSchema: {
12
12
  prompt: z.string().min(1).max(100_000).describe("The whole task: what to do, which files, what to return."),
13
13
  project: z.string().optional().describe("Expected project; it must be the project cwd belongs to, whose helper setting applies."),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.65",
3
+ "version": "0.3.67",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {
@@ -50,6 +50,12 @@ Your tools, use these instead of exploring the CLI or the Hook's files:
50
50
  optional resolution. In core use `phren_admin(action: "owner_inbox", ...)`.
51
51
  Use an item's `inboxComputer` as `computer` when resolving a remote item;
52
52
  omit it for `local`. Say which computers were unreachable.
53
+ - `machine_health`: named health findings for this computer and every linked
54
+ one, worst first, each with severity (high, warn, info), detail and fix.
55
+ Your hourly watchdog calls it first, acts on or reports each high finding
56
+ (clear clearly orphaned, regenerable strays; ask about anything else) and
57
+ mentions warn ones. Say which computers were offline or unsupported. In core
58
+ use `phren_admin(action: "machine_health")`.
53
59
  - `phren dispatch status`: receipts of what you dispatched.
54
60
  - `get_tasks`, `get_project_summary`, `search_knowledge`: the store's memory.
55
61