@phren/cli 0.2.14 → 0.2.16
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/README.md +2 -2
- package/dist/agent-instructions.d.ts +12 -0
- package/dist/agent-instructions.js +52 -0
- package/dist/bridge/agent-hook-stores.d.ts +32 -0
- package/dist/bridge/agent-hook-stores.js +67 -0
- package/dist/bridge/agent-hooks.d.ts +193 -2
- package/dist/bridge/agent-hooks.js +1045 -38
- package/dist/bridge/canary.d.ts +27 -0
- package/dist/bridge/canary.js +189 -0
- package/dist/bridge/changes.d.ts +57 -0
- package/dist/bridge/changes.js +403 -0
- package/dist/bridge/client.d.ts +3 -0
- package/dist/bridge/client.js +36 -0
- package/dist/bridge/code-note.d.ts +22 -0
- package/dist/bridge/code-note.js +42 -0
- package/dist/bridge/code-routes.d.ts +133 -0
- package/dist/bridge/code-routes.js +319 -0
- package/dist/bridge/codex-threads.d.ts +27 -0
- package/dist/bridge/codex-threads.js +442 -0
- package/dist/bridge/command.d.ts +7 -0
- package/dist/bridge/command.js +50 -5
- package/dist/bridge/computer-names.d.ts +4 -0
- package/dist/bridge/computer-names.js +16 -0
- package/dist/bridge/computers.d.ts +9 -0
- package/dist/bridge/computers.js +111 -0
- package/dist/bridge/context.d.ts +14 -0
- package/dist/bridge/context.js +149 -0
- package/dist/bridge/dispatch-command.d.ts +3 -0
- package/dist/bridge/dispatch-command.js +93 -0
- package/dist/bridge/dispatch-hosts.d.ts +23 -0
- package/dist/bridge/dispatch-hosts.js +25 -0
- package/dist/bridge/dispatch-returns.d.ts +123 -0
- package/dist/bridge/dispatch-returns.js +279 -0
- package/dist/bridge/dispatch-tree.d.ts +54 -0
- package/dist/bridge/dispatch-tree.js +198 -0
- package/dist/bridge/dispatch.d.ts +207 -0
- package/dist/bridge/dispatch.js +261 -0
- package/dist/bridge/enroll.d.ts +31 -0
- package/dist/bridge/enroll.js +236 -0
- package/dist/bridge/fanout-messages.d.ts +74 -0
- package/dist/bridge/fanout-messages.js +230 -0
- package/dist/bridge/fanouts.d.ts +160 -0
- package/dist/bridge/fanouts.js +702 -0
- package/dist/bridge/file-range.d.ts +16 -0
- package/dist/bridge/file-range.js +90 -0
- package/dist/bridge/files.d.ts +20 -0
- package/dist/bridge/files.js +54 -0
- package/dist/bridge/git-publish.d.ts +23 -0
- package/dist/bridge/git-publish.js +145 -0
- package/dist/bridge/git-worktrees.d.ts +21 -0
- package/dist/bridge/git-worktrees.js +150 -0
- package/dist/bridge/git.d.ts +54 -0
- package/dist/bridge/git.js +552 -0
- package/dist/bridge/grants.d.ts +31 -0
- package/dist/bridge/grants.js +181 -0
- package/dist/bridge/hand-off.d.ts +79 -0
- package/dist/bridge/hand-off.js +151 -0
- package/dist/bridge/health.d.ts +128 -0
- package/dist/bridge/health.js +260 -0
- package/dist/bridge/herdr.d.ts +79 -6
- package/dist/bridge/herdr.js +292 -27
- package/dist/bridge/hook-main.js +2 -0
- package/dist/bridge/install.d.ts +32 -1
- package/dist/bridge/install.js +225 -38
- package/dist/bridge/launch-worktree.d.ts +21 -0
- package/dist/bridge/launch-worktree.js +70 -0
- package/dist/bridge/limits.d.ts +20 -0
- package/dist/bridge/limits.js +65 -0
- package/dist/bridge/locate.d.ts +16 -0
- package/dist/bridge/locate.js +75 -0
- package/dist/bridge/metrics.d.ts +29 -0
- package/dist/bridge/metrics.js +71 -0
- package/dist/bridge/model-switch.d.ts +35 -0
- package/dist/bridge/model-switch.js +250 -0
- package/dist/bridge/models.d.ts +46 -0
- package/dist/bridge/models.js +257 -0
- package/dist/bridge/opencode-approvals.d.ts +6 -0
- package/dist/bridge/opencode-approvals.js +60 -0
- package/dist/bridge/pane-text.d.ts +15 -0
- package/dist/bridge/pane-text.js +23 -0
- package/dist/bridge/peers.d.ts +27 -0
- package/dist/bridge/peers.js +130 -0
- package/dist/bridge/projects.d.ts +12 -1
- package/dist/bridge/projects.js +268 -20
- package/dist/bridge/protocol.d.ts +35 -2
- package/dist/bridge/protocol.js +42 -7
- package/dist/bridge/push.d.ts +83 -0
- package/dist/bridge/push.js +199 -0
- package/dist/bridge/questions.d.ts +38 -0
- package/dist/bridge/questions.js +205 -0
- package/dist/bridge/schedule-format.d.ts +103 -0
- package/dist/bridge/schedule-format.js +266 -0
- package/dist/bridge/schedule-launch.d.ts +11 -0
- package/dist/bridge/schedule-launch.js +169 -0
- package/dist/bridge/schedule-watch.d.ts +52 -0
- package/dist/bridge/schedule-watch.js +242 -0
- package/dist/bridge/schedules.d.ts +48 -0
- package/dist/bridge/schedules.js +205 -0
- package/dist/bridge/server-launch.d.ts +14 -0
- package/dist/bridge/server-launch.js +218 -0
- package/dist/bridge/server-overview.d.ts +45 -0
- package/dist/bridge/server-overview.js +102 -0
- package/dist/bridge/server-pane-routes.d.ts +29 -0
- package/dist/bridge/server-pane-routes.js +400 -0
- package/dist/bridge/server-routes.d.ts +106 -0
- package/dist/bridge/server-routes.js +538 -0
- package/dist/bridge/server-stream.d.ts +46 -0
- package/dist/bridge/server-stream.js +253 -0
- package/dist/bridge/server.d.ts +3 -15
- package/dist/bridge/server.js +162 -264
- package/dist/bridge/session-servers.d.ts +24 -0
- package/dist/bridge/session-servers.js +136 -0
- package/dist/bridge/side-questions.d.ts +74 -0
- package/dist/bridge/side-questions.js +252 -0
- package/dist/bridge/simulators.d.ts +28 -0
- package/dist/bridge/simulators.js +198 -0
- package/dist/bridge/speech-transcribe.d.ts +24 -0
- package/dist/bridge/speech-transcribe.js +124 -0
- package/dist/bridge/speech.d.ts +35 -0
- package/dist/bridge/speech.js +98 -0
- package/dist/bridge/steps.d.ts +13 -0
- package/dist/bridge/steps.js +222 -0
- package/dist/bridge/tab-activity.d.ts +18 -0
- package/dist/bridge/tab-activity.js +99 -0
- package/dist/bridge/terminal-choice.d.ts +64 -0
- package/dist/bridge/terminal-choice.js +281 -0
- package/dist/bridge/transcript-claude.d.ts +22 -0
- package/dist/bridge/transcript-claude.js +353 -0
- package/dist/bridge/transcript-codex.d.ts +30 -0
- package/dist/bridge/transcript-codex.js +282 -0
- package/dist/bridge/transcript-copilot.d.ts +4 -0
- package/dist/bridge/transcript-copilot.js +14 -0
- package/dist/bridge/transcript-opencode.d.ts +5 -0
- package/dist/bridge/transcript-opencode.js +26 -0
- package/dist/bridge/transcript-preview.d.ts +94 -0
- package/dist/bridge/transcript-preview.js +476 -0
- package/dist/bridge/transcripts.d.ts +81 -4
- package/dist/bridge/transcripts.js +332 -67
- package/dist/bridge/transport.d.ts +3 -0
- package/dist/bridge/transport.js +96 -15
- package/dist/bridge/uploads.d.ts +15 -0
- package/dist/bridge/uploads.js +44 -2
- package/dist/bridge/usage.d.ts +124 -0
- package/dist/bridge/usage.js +859 -0
- package/dist/bridge-hook.mjs +41246 -21385
- package/dist/cli/actions.js +14 -1
- package/dist/cli/config-proactivity.d.ts +3 -1
- package/dist/cli/config-proactivity.js +35 -3
- package/dist/cli/config.js +4 -1
- package/dist/cli/extract.js +3 -6
- package/dist/cli/govern.js +5 -2
- package/dist/cli/hooks-globs.js +1 -1
- package/dist/cli/hooks.d.ts +1 -1
- package/dist/cli/hooks.js +9 -7
- package/dist/cli/namespaces-projects.js +12 -6
- package/dist/cli/namespaces-store.js +37 -6
- package/dist/cli/namespaces-tasks.js +1 -1
- package/dist/cli/schedules.d.ts +1 -0
- package/dist/cli/schedules.js +164 -0
- package/dist/cli/session-background.js +1 -1
- package/dist/cli/session-git.d.ts +8 -5
- package/dist/cli/session-git.js +45 -120
- package/dist/cli/session-start.js +3 -1
- package/dist/cli/session-stop.js +19 -8
- package/dist/cli/team.js +13 -10
- package/dist/cli-handlers.d.ts +1 -1
- package/dist/cli-handlers.js +8 -4
- package/dist/cli-help.d.ts +5 -4
- package/dist/cli-help.js +15 -15
- package/dist/cli-registry.d.ts +4 -1
- package/dist/cli-registry.js +119 -6
- package/dist/content/archive.js +2 -2
- package/dist/content/citation.d.ts +11 -0
- package/dist/content/citation.js +18 -0
- package/dist/content/learning.js +2 -0
- package/dist/content/summarize.d.ts +14 -15
- package/dist/content/summarize.js +60 -5
- package/dist/content/validate.d.ts +3 -1
- package/dist/content/validate.js +26 -8
- package/dist/core/project-registry.d.ts +26 -0
- package/dist/core/project-registry.js +573 -0
- package/dist/core/project.js +2 -3
- package/dist/data/access.d.ts +7 -1
- package/dist/data/access.js +13 -3
- package/dist/data/tasks.d.ts +18 -3
- package/dist/data/tasks.js +8 -7
- package/dist/entrypoint.js +44 -10
- package/dist/fanout/adapters/claude.d.ts +2 -0
- package/dist/fanout/adapters/claude.js +7 -0
- package/dist/fanout/adapters/codex.d.ts +2 -0
- package/dist/fanout/adapters/codex.js +9 -0
- package/dist/fanout/adapters/opencode.d.ts +4 -0
- package/dist/fanout/adapters/opencode.js +9 -0
- package/dist/fanout/adapters/types.d.ts +21 -0
- package/dist/fanout/adapters/types.js +3 -0
- package/dist/fanout/command.d.ts +2 -0
- package/dist/fanout/command.js +78 -0
- package/dist/fanout/launcher.d.ts +27 -0
- package/dist/fanout/launcher.js +156 -0
- package/dist/fanout/opencode-serve.d.ts +24 -0
- package/dist/fanout/opencode-serve.js +191 -0
- package/dist/fanout/picker.d.ts +91 -0
- package/dist/fanout/picker.js +51 -0
- package/dist/fanout/usage.d.ts +5 -0
- package/dist/fanout/usage.js +51 -0
- package/dist/fanout/watchdog.d.ts +10 -0
- package/dist/fanout/watchdog.js +27 -0
- package/dist/filenames.d.ts +9 -0
- package/dist/filenames.js +11 -0
- package/dist/finding/context.js +4 -22
- package/dist/generated/memory-ui-graph.browser.js +279 -283
- package/dist/governance/policy-constants.d.ts +11 -0
- package/dist/governance/policy-constants.js +9 -0
- package/dist/governance/policy.d.ts +5 -8
- package/dist/governance/policy.js +7 -5
- package/dist/graph-core/camera.d.ts +24 -0
- package/dist/graph-core/camera.js +18 -0
- package/dist/graph-core/index.d.ts +2 -0
- package/dist/graph-core/index.js +2 -0
- package/dist/graph-core/labels.d.ts +77 -0
- package/dist/graph-core/labels.js +124 -0
- package/dist/graph-core/model.d.ts +13 -0
- package/dist/graph-core/model.js +33 -0
- package/dist/graph-core/types.d.ts +2 -0
- package/dist/home-paths.d.ts +7 -0
- package/dist/home-paths.js +21 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +13 -0
- package/dist/index.js +24 -2
- package/dist/init/guard-globals.d.ts +1 -1
- package/dist/init/guard-globals.js +4 -4
- package/dist/init/init-configure.js +3 -3
- package/dist/init/init-uninstall.js +2 -2
- package/dist/init/init-walkthrough.d.ts +2 -0
- package/dist/init/init-walkthrough.js +17 -6
- package/dist/init/init.js +26 -6
- package/dist/init/management-preset.d.ts +1 -1
- package/dist/init/management-preset.js +2 -2
- package/dist/init/preferences.js +1 -1
- package/dist/init/self-wiring.js +1 -1
- package/dist/init/setup.d.ts +3 -26
- package/dist/init/setup.js +49 -588
- package/dist/init/shared.js +2 -0
- package/dist/init/store-gitignore.d.ts +1 -1
- package/dist/init/store-gitignore.js +2 -0
- package/dist/init/teardown.d.ts +1 -1
- package/dist/init/teardown.js +2 -2
- package/dist/link/context.js +1 -1
- package/dist/link/doctor.d.ts +22 -1
- package/dist/link/doctor.js +100 -54
- package/dist/link/link.js +29 -61
- package/dist/link/refresh.js +2 -2
- package/dist/link/skills.js +26 -5
- package/dist/machine-identity.d.ts +3 -0
- package/dist/machine-identity.js +6 -0
- package/dist/mcp/profile.d.ts +2 -15
- package/dist/mcp/profile.js +64 -9
- package/dist/memory-ui-graph.runtime.js +279 -283
- package/dist/modules/code-package.d.ts +16 -0
- package/dist/modules/code-package.js +152 -0
- package/dist/modules/command.d.ts +2 -0
- package/dist/modules/command.js +67 -0
- package/dist/modules/config.d.ts +4 -0
- package/dist/modules/config.js +70 -0
- package/dist/modules/manifest.d.ts +41 -0
- package/dist/modules/manifest.js +1 -0
- package/dist/modules/provision.d.ts +3 -0
- package/dist/modules/provision.js +84 -0
- package/dist/modules/registry.d.ts +16 -0
- package/dist/modules/registry.js +250 -0
- package/dist/modules/runtime.d.ts +15 -0
- package/dist/modules/runtime.js +59 -0
- package/dist/package-metadata.js +10 -2
- package/dist/phren-dotenv.js +4 -2
- package/dist/phren-paths.d.ts +3 -2
- package/dist/phren-paths.js +4 -5
- package/dist/profile-store.js +4 -5
- package/dist/project-config.d.ts +19 -1
- package/dist/project-config.js +29 -3
- package/dist/project-topics.js +4 -4
- package/dist/provider-adapters.js +1 -4
- package/dist/query-correlation.js +6 -6
- package/dist/session/artifacts.js +5 -5
- package/dist/session/checkpoints.js +5 -0
- package/dist/session/utils.d.ts +2 -2
- package/dist/session/utils.js +6 -6
- package/dist/shared/content.d.ts +1 -1
- package/dist/shared/content.js +1 -1
- package/dist/shared/data-utils.js +1 -1
- package/dist/shared/fragment-graph.d.ts +1 -1
- package/dist/shared/fragment-graph.js +5 -5
- package/dist/shared/index.js +48 -7
- package/dist/shared/retrieval.d.ts +18 -1
- package/dist/shared/retrieval.js +100 -11
- package/dist/shared/search-fallback.js +4 -6
- package/dist/shared/sqljs.d.ts +2 -0
- package/dist/shared/sqljs.js +4 -2
- package/dist/shared.d.ts +0 -1
- package/dist/shared.js +0 -1
- package/dist/shell/input.d.ts +1 -5
- package/dist/shell/input.js +16 -10
- package/dist/shell/palette.d.ts +2 -2
- package/dist/shell/palette.js +3 -7
- package/dist/shell/render.d.ts +3 -1
- package/dist/shell/render.js +4 -4
- package/dist/shell/shell.js +4 -1
- package/dist/shell/types.d.ts +1 -0
- package/dist/shell/types.js +4 -0
- package/dist/shell/view.d.ts +0 -4
- package/dist/shell/view.js +19 -27
- package/dist/skill/registry.js +25 -17
- package/dist/skill/state.d.ts +3 -0
- package/dist/skill/state.js +13 -7
- package/dist/status.js +38 -17
- package/dist/store-registry.d.ts +44 -18
- package/dist/store-registry.js +169 -60
- package/dist/store-weight.d.ts +1 -6
- package/dist/store-weight.js +4 -2
- package/dist/sync/auth-doctor.d.ts +8 -0
- package/dist/sync/auth-doctor.js +27 -0
- package/dist/sync/auth.d.ts +27 -0
- package/dist/sync/auth.js +114 -0
- package/dist/sync/conflict-resolve.d.ts +9 -0
- package/dist/sync/conflict-resolve.js +146 -0
- package/dist/sync/git-state.d.ts +4 -0
- package/dist/sync/git-state.js +49 -0
- package/dist/sync/outcome.d.ts +34 -0
- package/dist/sync/outcome.js +57 -0
- package/dist/sync/pull.d.ts +15 -7
- package/dist/sync/pull.js +84 -35
- package/dist/sync/store-merge.d.ts +29 -0
- package/dist/sync/store-merge.js +137 -0
- package/dist/sync/task-merge.d.ts +22 -0
- package/dist/sync/task-merge.js +158 -0
- package/dist/task/github.js +1 -1
- package/dist/task/lifecycle.d.ts +5 -0
- package/dist/task/lifecycle.js +67 -23
- package/dist/terminal-text.d.ts +5 -0
- package/dist/terminal-text.js +11 -0
- package/dist/test-global-setup.js +7 -0
- package/dist/tool-registry.d.ts +1 -1
- package/dist/tool-registry.js +3 -1
- package/dist/tools/code.d.ts +3 -0
- package/dist/tools/code.js +178 -0
- package/dist/tools/config.js +5 -0
- package/dist/tools/data.js +14 -7
- package/dist/tools/dispatch.d.ts +2 -0
- package/dist/tools/dispatch.js +66 -0
- package/dist/tools/finding.js +43 -41
- package/dist/tools/ops.js +5 -2
- package/dist/tools/search.js +21 -8
- package/dist/tools/session.js +21 -22
- package/dist/tools/tasks.js +8 -2
- package/dist/tools/types.d.ts +2 -2
- package/dist/tools/types.js +2 -2
- package/dist/ui/assets.js +1 -1
- package/dist/ui/data.js +14 -15
- package/dist/ui/deep-void.d.ts +1 -1
- package/dist/ui/deep-void.js +0 -1
- package/dist/ui/graph-chrome.d.ts +1 -1
- package/dist/ui/graph-chrome.js +51 -0
- package/dist/ui/page.js +5 -5
- package/dist/ui/scripts.js +67 -30
- package/dist/ui/server.js +34 -6
- package/dist/update.js +1 -1
- package/dist/utils-fts.js +1 -0
- package/dist/utils-helpers.d.ts +7 -0
- package/dist/utils-helpers.js +17 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +45 -3
- package/plugins/opencode/phren-transcript.js +340 -0
- package/starter/README.md +4 -4
- package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
- package/starter/global/skills/conductor/SKILL.md +106 -0
- package/starter/global/skills/fanout/SKILL.md +20 -0
- package/starter/global/skills/phren-discover/SKILL.md +6 -6
- package/starter/global/skills/phren-init/SKILL.md +4 -4
- package/starter/global/skills/phren-sync/SKILL.md +3 -3
- package/starter/templates/frontend/reference/README.md +1 -1
- package/starter/templates/library/reference/README.md +1 -1
- package/starter/templates/monorepo/reference/README.md +1 -1
- package/starter/templates/python-project/reference/README.md +1 -1
- /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { chmod, lstat, mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { forcedCommand } from "./install.js";
|
|
7
|
+
import { BridgeError, bridgeRoot, computerName } from "./protocol.js";
|
|
8
|
+
const exec = promisify(execFile);
|
|
9
|
+
export { computerName };
|
|
10
|
+
export const dispatchKeyPath = (root = bridgeRoot()) => path.join(root, "id_ed25519_dispatch");
|
|
11
|
+
export function publicComputerKey(value) {
|
|
12
|
+
const match = /^ssh-ed25519 ([A-Za-z0-9+/]+={0,2})(?: [^\r\n]*)?$/.exec(value.trim());
|
|
13
|
+
if (!match)
|
|
14
|
+
throw new BridgeError(400, "Supply one ed25519 public key.");
|
|
15
|
+
const blob = Buffer.from(match[1], "base64");
|
|
16
|
+
if (blob.length !== 51 || blob.readUInt32BE(0) !== 11 || blob.subarray(4, 15).toString() !== "ssh-ed25519"
|
|
17
|
+
|| blob.readUInt32BE(15) !== 32 || blob.toString("base64") !== match[1]) {
|
|
18
|
+
throw new BridgeError(400, "Invalid ed25519 public key.");
|
|
19
|
+
}
|
|
20
|
+
return `ssh-ed25519 ${match[1]}`;
|
|
21
|
+
}
|
|
22
|
+
export function computerKeyLine(name, publicKey) {
|
|
23
|
+
return `restrict,pty,${forcedCommand} ${publicComputerKey(publicKey)} phren-computer:${computerName.parse(name)}`;
|
|
24
|
+
}
|
|
25
|
+
async function regularFile(file) {
|
|
26
|
+
const info = await lstat(file).catch((error) => {
|
|
27
|
+
if (error.code === "ENOENT")
|
|
28
|
+
return undefined;
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
if (!info)
|
|
32
|
+
return false;
|
|
33
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
34
|
+
throw new BridgeError(409, "Refusing an unexpected enrollment file.");
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/** Never replace a dispatch identity implicitly: every peer enrolled this key. */
|
|
38
|
+
export async function enrollComputer(name, root = bridgeRoot()) {
|
|
39
|
+
computerName.parse(name);
|
|
40
|
+
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
41
|
+
await chmod(root, 0o700);
|
|
42
|
+
const lock = path.join(root, "enroll-computer.lock");
|
|
43
|
+
try {
|
|
44
|
+
await mkdir(lock, { mode: 0o700 });
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new BridgeError(409, "Computer enrollment is already running; inspect enroll-computer.lock if interrupted.");
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const key = dispatchKeyPath(root);
|
|
51
|
+
if (!(await regularFile(key))) {
|
|
52
|
+
const temporary = await mkdtemp(path.join(root, "enroll-"));
|
|
53
|
+
try {
|
|
54
|
+
const generated = path.join(temporary, "key");
|
|
55
|
+
await exec("ssh-keygen", ["-q", "-t", "ed25519", "-N", "", "-C", "phren-computer", "-f", generated], { timeout: 10_000 });
|
|
56
|
+
await rename(generated, key);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await rm(temporary, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await chmod(key, 0o600);
|
|
63
|
+
const { stdout } = await exec("ssh-keygen", ["-y", "-P", "", "-f", key], { timeout: 10_000, maxBuffer: 4096 });
|
|
64
|
+
return computerKeyLine(name, stdout.trim());
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
await rm(lock, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Accept a public key, rebuilding the restrictions rather than trusting supplied options. */
|
|
71
|
+
export async function acceptComputer(name, input, sshDirectory = path.join(homedir(), ".ssh")) {
|
|
72
|
+
computerName.parse(name);
|
|
73
|
+
const prefix = `restrict,pty,${forcedCommand} `;
|
|
74
|
+
const raw = input.trim();
|
|
75
|
+
const publicKey = publicComputerKey(raw.startsWith(prefix) ? raw.slice(prefix.length) : raw);
|
|
76
|
+
const line = computerKeyLine(name, publicKey);
|
|
77
|
+
const directory = await lstat(sshDirectory).catch(() => undefined);
|
|
78
|
+
if (directory && (!directory.isDirectory() || directory.isSymbolicLink()))
|
|
79
|
+
throw new BridgeError(409, "Refusing an unexpected SSH directory.");
|
|
80
|
+
await mkdir(sshDirectory, { recursive: true, mode: 0o700 });
|
|
81
|
+
await chmod(sshDirectory, 0o700);
|
|
82
|
+
const lock = path.join(sshDirectory, ".phren-enroll.lock");
|
|
83
|
+
try {
|
|
84
|
+
await mkdir(lock, { mode: 0o700 });
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new BridgeError(409, "SSH enrollment is already running; inspect .phren-enroll.lock if interrupted.");
|
|
88
|
+
}
|
|
89
|
+
const file = path.join(sshDirectory, "authorized_keys");
|
|
90
|
+
const temporary = path.join(lock, "authorized_keys");
|
|
91
|
+
try {
|
|
92
|
+
const before = await regularFile(file) ? await readFile(file, "utf8") : "";
|
|
93
|
+
const lines = before.split("\n").filter(Boolean);
|
|
94
|
+
if (lines.includes(line)) {
|
|
95
|
+
await chmod(file, 0o600);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const encoded = publicKey.split(" ")[1];
|
|
99
|
+
if (lines.some(existing => existing.endsWith(` phren-computer:${name}`) || existing.split(/\s+/).includes(encoded))) {
|
|
100
|
+
throw new BridgeError(409, "This name or key is already enrolled differently. Revoke the old line explicitly first.");
|
|
101
|
+
}
|
|
102
|
+
await writeFile(temporary, before + (before && !before.endsWith("\n") ? "\n" : "") + line + "\n", { mode: 0o600, flag: "wx" });
|
|
103
|
+
const current = await regularFile(file) ? await readFile(file, "utf8") : "";
|
|
104
|
+
if (current !== before)
|
|
105
|
+
throw new BridgeError(409, "authorized_keys changed during enrollment. Try again.");
|
|
106
|
+
await rename(temporary, file);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
await rm(lock, { recursive: true, force: true });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Json } from "./protocol.js";
|
|
2
|
+
/** A bounded metadata cache avoids decoding unchanged transcripts. Reads
|
|
3
|
+
* inspect at most the final 256 KiB, without building the full chat index. */
|
|
4
|
+
export declare class ContextUsageReader {
|
|
5
|
+
private cache;
|
|
6
|
+
read(file: string, session: string): Promise<number | undefined>;
|
|
7
|
+
}
|
|
8
|
+
/** Resolve only exact foreground identities. A tab with multiple agent panes
|
|
9
|
+
* has no single context percentage, and unsupported providers stay unknown. */
|
|
10
|
+
export declare class WorkspaceContextUsage {
|
|
11
|
+
private reader;
|
|
12
|
+
private active?;
|
|
13
|
+
read(server: string, snapshot: Json): Promise<ReadonlyMap<Json, number>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { paneIdentity } from "./herdr.js";
|
|
4
|
+
import { object, objects } from "./protocol.js";
|
|
5
|
+
import { transcriptPath } from "./transcripts.js";
|
|
6
|
+
const MAX_TAIL_BYTES = 262_144;
|
|
7
|
+
const MAX_SESSIONS = 32;
|
|
8
|
+
const CONCURRENCY = 4;
|
|
9
|
+
const OVERVIEW_BUDGET_MS = 1500;
|
|
10
|
+
function count(value) {
|
|
11
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= 1_000_000_000_000 ? value : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Use the last response's complete token count, never cumulative session
|
|
14
|
+
* billing or a guessed model limit. A reset/compaction invalidates older usage. */
|
|
15
|
+
function codexContext(tail, startsAtBeginning) {
|
|
16
|
+
const rows = tail.toString("utf8").split("\n");
|
|
17
|
+
rows.pop(); // An unfinished trailing row is not yet an observation.
|
|
18
|
+
if (!startsAtBeginning)
|
|
19
|
+
rows.shift();
|
|
20
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
21
|
+
let raw;
|
|
22
|
+
try {
|
|
23
|
+
raw = object(JSON.parse(rows[i]));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (raw.type === "compacted")
|
|
29
|
+
return undefined;
|
|
30
|
+
const payload = object(raw.payload);
|
|
31
|
+
if (raw.type !== "event_msg" || payload.type !== "token_count")
|
|
32
|
+
continue;
|
|
33
|
+
const info = object(payload.info), usage = object(info.last_token_usage);
|
|
34
|
+
const used = count(usage.total_tokens), limit = count(info.model_context_window);
|
|
35
|
+
if (used === undefined || limit === undefined || limit === 0)
|
|
36
|
+
return undefined;
|
|
37
|
+
return Math.min(100, used / limit * 100);
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
/** A bounded metadata cache avoids decoding unchanged transcripts. Reads
|
|
42
|
+
* inspect at most the final 256 KiB, without building the full chat index. */
|
|
43
|
+
export class ContextUsageReader {
|
|
44
|
+
cache = new Map();
|
|
45
|
+
async read(file, session) {
|
|
46
|
+
const handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
47
|
+
try {
|
|
48
|
+
const metadata = await handle.stat();
|
|
49
|
+
if (!metadata.isFile())
|
|
50
|
+
return undefined;
|
|
51
|
+
const key = `codex:${session}:${file}`;
|
|
52
|
+
const stat = `${metadata.dev}:${metadata.ino}:${metadata.size}:${metadata.mtimeMs}:${metadata.ctimeMs}`;
|
|
53
|
+
const cached = this.cache.get(key);
|
|
54
|
+
this.cache.delete(key);
|
|
55
|
+
if (cached?.stat === stat) {
|
|
56
|
+
this.cache.set(key, cached);
|
|
57
|
+
return cached.percent;
|
|
58
|
+
}
|
|
59
|
+
const start = Math.max(0, metadata.size - MAX_TAIL_BYTES);
|
|
60
|
+
const tail = Buffer.alloc(metadata.size - start);
|
|
61
|
+
const { bytesRead } = await handle.read(tail, 0, tail.length, start);
|
|
62
|
+
if (bytesRead !== tail.length)
|
|
63
|
+
return undefined;
|
|
64
|
+
const after = await handle.stat();
|
|
65
|
+
if (after.size !== metadata.size || after.mtimeMs !== metadata.mtimeMs || after.ctimeMs !== metadata.ctimeMs)
|
|
66
|
+
return undefined;
|
|
67
|
+
const percent = codexContext(tail, start === 0);
|
|
68
|
+
this.cache.set(key, { stat, percent });
|
|
69
|
+
while (this.cache.size > MAX_SESSIONS)
|
|
70
|
+
this.cache.delete(this.cache.keys().next().value);
|
|
71
|
+
return percent;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await handle.close();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Resolve only exact foreground identities. A tab with multiple agent panes
|
|
79
|
+
* has no single context percentage, and unsupported providers stay unknown. */
|
|
80
|
+
export class WorkspaceContextUsage {
|
|
81
|
+
reader = new ContextUsageReader();
|
|
82
|
+
active;
|
|
83
|
+
async read(server, snapshot) {
|
|
84
|
+
// A timed-out batch may still be draining bounded filesystem/process work.
|
|
85
|
+
// Do not accumulate another batch or apply its observations to a new snapshot.
|
|
86
|
+
if (this.active)
|
|
87
|
+
return new Map();
|
|
88
|
+
const agentsByTab = new Map();
|
|
89
|
+
for (const pane of objects(snapshot.panes)) {
|
|
90
|
+
if (!pane.agent || typeof pane.workspace_id !== "string" || typeof pane.tab_id !== "string")
|
|
91
|
+
continue;
|
|
92
|
+
const key = JSON.stringify([pane.workspace_id, pane.tab_id]);
|
|
93
|
+
const agents = agentsByTab.get(key) ?? [];
|
|
94
|
+
agents.push(pane);
|
|
95
|
+
agentsByTab.set(key, agents);
|
|
96
|
+
}
|
|
97
|
+
const candidates = [];
|
|
98
|
+
for (const tab of objects(snapshot.tabs)) {
|
|
99
|
+
if (typeof tab.workspace_id !== "string" || typeof tab.tab_id !== "string")
|
|
100
|
+
continue;
|
|
101
|
+
const agents = agentsByTab.get(JSON.stringify([tab.workspace_id, tab.tab_id]));
|
|
102
|
+
if (agents?.length === 1 && agents[0].agent === "codex")
|
|
103
|
+
candidates.push(agents[0]);
|
|
104
|
+
if (candidates.length === MAX_SESSIONS)
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
const result = new Map();
|
|
108
|
+
const sessions = new Map();
|
|
109
|
+
let cursor = 0, expired = false;
|
|
110
|
+
let timer;
|
|
111
|
+
const deadline = new Promise(resolve => {
|
|
112
|
+
timer = setTimeout(() => { expired = true; resolve(); }, OVERVIEW_BUDGET_MS);
|
|
113
|
+
});
|
|
114
|
+
const batch = Promise.all(Array.from({ length: Math.min(CONCURRENCY, candidates.length) }, async () => {
|
|
115
|
+
while (!expired && cursor < candidates.length) {
|
|
116
|
+
const pane = candidates[cursor++];
|
|
117
|
+
try {
|
|
118
|
+
const session = await paneIdentity(server, pane);
|
|
119
|
+
if (expired)
|
|
120
|
+
return;
|
|
121
|
+
if (!session)
|
|
122
|
+
continue;
|
|
123
|
+
let reading = sessions.get(session);
|
|
124
|
+
if (!reading) {
|
|
125
|
+
reading = transcriptPath("codex", session).then(file => expired ? undefined : this.reader.read(file, session));
|
|
126
|
+
sessions.set(session, reading);
|
|
127
|
+
}
|
|
128
|
+
const percent = await reading;
|
|
129
|
+
if (!expired && percent !== undefined)
|
|
130
|
+
result.set(pane, percent);
|
|
131
|
+
}
|
|
132
|
+
catch { /* Unavailable identity or usage must not block the overview. */ }
|
|
133
|
+
}
|
|
134
|
+
})).then(() => { });
|
|
135
|
+
this.active = batch;
|
|
136
|
+
const release = () => { if (this.active === batch)
|
|
137
|
+
this.active = undefined; };
|
|
138
|
+
void batch.then(release, release);
|
|
139
|
+
try {
|
|
140
|
+
await Promise.race([batch, deadline]);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
expired = true;
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
}
|
|
146
|
+
// The response owns a snapshot, even when slow lookups finish after it returns.
|
|
147
|
+
return new Map(result);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { hookRequest } from "./client.js";
|
|
3
|
+
import { dispatchSchema } from "./dispatch.js";
|
|
4
|
+
import { handOff } from "./hand-off.js";
|
|
5
|
+
import { herdrPaneFromEnv } from "./herdr.js";
|
|
6
|
+
import { addGrant, grantSchema, listGrants, removeGrant } from "./grants.js";
|
|
7
|
+
import { sessionId } from "./protocol.js";
|
|
8
|
+
export async function runDispatch(args) {
|
|
9
|
+
if (args.length === 1 && args[0] === "status") {
|
|
10
|
+
console.log(JSON.stringify(await hookRequest("/v1/dispatch"), null, 2));
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
if (args.length === 1 && args[0] === "returns") {
|
|
14
|
+
console.log(JSON.stringify(await hookRequest("/v1/dispatch/returns", {}), null, 2));
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
if (args.length === 1 && args[0] === "sessions") {
|
|
18
|
+
const { listLiveSessions } = await import("./hand-off.js");
|
|
19
|
+
console.log(JSON.stringify(await listLiveSessions(), null, 2));
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: {
|
|
23
|
+
harness: { type: "string", default: "codex" }, model: { type: "string" }, prompt: { type: "string" }, label: { type: "string" },
|
|
24
|
+
"parent-provider": { type: "string" }, "parent-session": { type: "string" }, "parent-computer": { type: "string" },
|
|
25
|
+
"parent-server": { type: "string" }, "parent-workspace": { type: "string" }, "parent-tab": { type: "string" }, "parent-pane": { type: "string" },
|
|
26
|
+
} });
|
|
27
|
+
if (positionals.length !== 2)
|
|
28
|
+
throw new Error("Usage: phren dispatch <computer|anywhere> <project> --label <label> --prompt <brief> [--harness codex|claude|opencode] [--model <model>] [explicit parent flags]");
|
|
29
|
+
const parentValues = ["parent-provider", "parent-session", "parent-computer", "parent-server", "parent-workspace", "parent-tab", "parent-pane"];
|
|
30
|
+
const hasParent = parentValues.some(key => values[key] !== undefined);
|
|
31
|
+
const parent = hasParent ? {
|
|
32
|
+
provider: values["parent-provider"], session: values["parent-session"], computer: values["parent-computer"],
|
|
33
|
+
} : undefined;
|
|
34
|
+
const parentTarget = hasParent ? {
|
|
35
|
+
server: values["parent-server"], workspace: values["parent-workspace"], tab: values["parent-tab"], pane: values["parent-pane"],
|
|
36
|
+
source: values["parent-provider"], session: values["parent-session"],
|
|
37
|
+
} : undefined;
|
|
38
|
+
const ordinary = Object.fromEntries(Object.entries(values).filter(([key]) => !key.startsWith("parent-")));
|
|
39
|
+
const input = dispatchSchema.parse({ computer: positionals[0], project: positionals[1], ...ordinary,
|
|
40
|
+
...(parent ? { parent, parentTarget } : {}) });
|
|
41
|
+
// Run inside an agent's pane, the dispatch remembers that pane for return notices.
|
|
42
|
+
const origin = herdrPaneFromEnv();
|
|
43
|
+
const result = await hookRequest("/v1/dispatch", { ...input, ...(origin ? { origin } : {}) }, undefined, 180_000);
|
|
44
|
+
console.log(JSON.stringify(result, null, 2));
|
|
45
|
+
return result.ok === true ? 0 : 1;
|
|
46
|
+
}
|
|
47
|
+
export async function runHandOff(args) {
|
|
48
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: {
|
|
49
|
+
session: { type: "string" }, text: { type: "string" }, project: { type: "string" },
|
|
50
|
+
} });
|
|
51
|
+
if (positionals.length !== 1 || !values.session || !values.text)
|
|
52
|
+
throw new Error("Usage: phren hand-off <computer|local> --session <id> --text <prompt> [--project <slug>]");
|
|
53
|
+
const computer = positionals[0] === "local" ? undefined : positionals[0];
|
|
54
|
+
const result = await handOff({ ...(computer ? { computer } : {}), project: values.project, session: sessionId.parse(values.session), text: values.text });
|
|
55
|
+
console.log(JSON.stringify(result, null, 2));
|
|
56
|
+
return result.ok ? 0 : 1;
|
|
57
|
+
}
|
|
58
|
+
export async function runConductor(args) {
|
|
59
|
+
const [namespace, action = "list", ...rest] = args;
|
|
60
|
+
if (namespace !== "grants")
|
|
61
|
+
throw new Error("Usage: phren conductor grants [list|add|remove]");
|
|
62
|
+
if (action === "list") {
|
|
63
|
+
console.log(JSON.stringify(await listGrants(), null, 2));
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
if (action === "add") {
|
|
67
|
+
const { values } = parseArgs({ args: rest, allowPositionals: true, options: {
|
|
68
|
+
scope: { type: "string" }, actions: { type: "string" }, computers: { type: "string" }, until: { type: "string" },
|
|
69
|
+
} });
|
|
70
|
+
const actions = (values.actions ?? "dispatch,hand_off").split(",").map(value => value.trim()).filter(Boolean);
|
|
71
|
+
const grant = grantSchema.parse({
|
|
72
|
+
scope: values.scope ?? "global",
|
|
73
|
+
actions,
|
|
74
|
+
...(values.computers ? { computers: values.computers.split(",").map(value => value.trim()).filter(Boolean) } : {}),
|
|
75
|
+
...(values.until ? { until: values.until } : {}),
|
|
76
|
+
});
|
|
77
|
+
console.log(JSON.stringify(await addGrant(grant), null, 2));
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
if (action === "remove") {
|
|
81
|
+
const { values, positionals } = parseArgs({ args: rest, allowPositionals: true, options: {
|
|
82
|
+
scope: { type: "string" }, index: { type: "string" },
|
|
83
|
+
} });
|
|
84
|
+
const index = values.index !== undefined ? Number(values.index) : positionals[0] !== undefined ? Number(positionals[0]) : undefined;
|
|
85
|
+
if (index === undefined && !values.scope)
|
|
86
|
+
throw new Error("Usage: phren conductor grants remove <index>|--scope <scope>");
|
|
87
|
+
if (index !== undefined && !Number.isInteger(index))
|
|
88
|
+
throw new Error("Grant index must be an integer.");
|
|
89
|
+
console.log(JSON.stringify(await removeGrant(index !== undefined ? { index } : { scope: values.scope }), null, 2));
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
throw new Error("Usage: phren conductor grants [list|add|remove]");
|
|
93
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { hookRequest } from "./client.js";
|
|
2
|
+
import { peerRequest, type HookPeer } from "./peers.js";
|
|
3
|
+
import type { Json } from "./protocol.js";
|
|
4
|
+
/**
|
|
5
|
+
* Where a dispatch can be placed: an enrolled peer reached over its pinned SSH
|
|
6
|
+
* pipe, or this computer, reached through its own Hook's socket. The same
|
|
7
|
+
* Hook routes (capacity, launch, panes, prompt, workers) serve both, so this
|
|
8
|
+
* computer needs no hooks.yaml entry and no SSH enrollment of its own.
|
|
9
|
+
*/
|
|
10
|
+
export interface DispatchHost {
|
|
11
|
+
name: string;
|
|
12
|
+
server: string;
|
|
13
|
+
local: boolean;
|
|
14
|
+
/** Every name this computer answers to (local hosts only). */
|
|
15
|
+
names?: readonly string[];
|
|
16
|
+
request(route: string, data?: Json, timeout?: number): Promise<Json>;
|
|
17
|
+
}
|
|
18
|
+
/** This computer's own names: its hostname, the hostname's first label and
|
|
19
|
+
* its Bonjour name, plus "local". */
|
|
20
|
+
export declare function isLocalComputer(name: string, names?: readonly string[]): boolean;
|
|
21
|
+
export declare function peerHost(peer: HookPeer, request?: typeof peerRequest): DispatchHost;
|
|
22
|
+
/** This computer. `server` is the Herdr server its Hook reports first. */
|
|
23
|
+
export declare function localHost(server?: string, names?: readonly string[], request?: typeof hookRequest): DispatchHost;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { hookRequest } from "./client.js";
|
|
2
|
+
import { localNames } from "./computer-names.js";
|
|
3
|
+
import { peerRequest } from "./peers.js";
|
|
4
|
+
/** This computer's own names: its hostname, the hostname's first label and
|
|
5
|
+
* its Bonjour name, plus "local". */
|
|
6
|
+
export function isLocalComputer(name, names = localNames()) {
|
|
7
|
+
const wanted = name.trim().toLowerCase();
|
|
8
|
+
if (!wanted)
|
|
9
|
+
return false;
|
|
10
|
+
if (wanted === "local" || wanted === "localhost")
|
|
11
|
+
return true;
|
|
12
|
+
const first = wanted.split(".")[0];
|
|
13
|
+
return names.some(own => {
|
|
14
|
+
const value = own.toLowerCase();
|
|
15
|
+
return value === wanted || value.split(".")[0] === first;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function peerHost(peer, request = peerRequest) {
|
|
19
|
+
return { name: peer.name, server: peer.server, local: false, request: (route, data, timeout) => request(peer, route, data, timeout) };
|
|
20
|
+
}
|
|
21
|
+
/** This computer. `server` is the Herdr server its Hook reports first. */
|
|
22
|
+
export function localHost(server = "default", names = localNames(), request = hookRequest) {
|
|
23
|
+
const name = names.find(value => !value.includes(".")) ?? names[0] ?? "local";
|
|
24
|
+
return { name, server, local: true, names, request: (route, data) => request(route, data) };
|
|
25
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Receipt } from "./dispatch.js";
|
|
3
|
+
import { peerRequest, type HookPeer } from "./peers.js";
|
|
4
|
+
import { type Json, type Provider, type Target } from "./protocol.js";
|
|
5
|
+
import { type FinalTurn } from "./schedule-watch.js";
|
|
6
|
+
/**
|
|
7
|
+
* The conductor's returns loop. The worker's computer answers what its
|
|
8
|
+
* dispatched panes are doing from the Herdr snapshot its Hook already shares
|
|
9
|
+
* (`workerStates`); the dispatching Hook asks each peer once per poll for all
|
|
10
|
+
* of its open dispatches, records transitions in the receipts, and tells an
|
|
11
|
+
* idle dispatching agent that returns are waiting (`DispatchReturns`).
|
|
12
|
+
*/
|
|
13
|
+
/** Longest final reply kept in a receipt, in UTF-8 bytes. */
|
|
14
|
+
export declare const REPLY_LIMIT = 4000;
|
|
15
|
+
/** How often the dispatching Hook asks peers about open dispatches. */
|
|
16
|
+
export declare const POLL_MS = 15000;
|
|
17
|
+
/** Shortest gap between two notices typed into the same dispatching pane. */
|
|
18
|
+
export declare const NOTICE_MS = 120000;
|
|
19
|
+
/** Receipts older than this are no longer watched. */
|
|
20
|
+
export declare const WATCH_MS: number;
|
|
21
|
+
/** An idle worker that was never seen working and has no finished turn is
|
|
22
|
+
* counted as done after this long: the prompt may never have been taken. */
|
|
23
|
+
export declare const IDLE_GRACE_MS: number;
|
|
24
|
+
export declare const workerRequestSchema: z.ZodObject<{
|
|
25
|
+
targets: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
26
|
+
server: z.ZodString;
|
|
27
|
+
workspace: z.ZodString;
|
|
28
|
+
tab: z.ZodString;
|
|
29
|
+
pane: z.ZodString;
|
|
30
|
+
source: z.ZodEnum<{
|
|
31
|
+
claude: "claude";
|
|
32
|
+
codex: "codex";
|
|
33
|
+
copilot: "copilot";
|
|
34
|
+
opencode: "opencode";
|
|
35
|
+
phren: "phren";
|
|
36
|
+
}>;
|
|
37
|
+
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
38
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
39
|
+
server: z.ZodString;
|
|
40
|
+
workspace: z.ZodString;
|
|
41
|
+
tab: z.ZodString;
|
|
42
|
+
pane: z.ZodString;
|
|
43
|
+
source: z.ZodEnum<{
|
|
44
|
+
claude: "claude";
|
|
45
|
+
codex: "codex";
|
|
46
|
+
copilot: "copilot";
|
|
47
|
+
opencode: "opencode";
|
|
48
|
+
phren: "phren";
|
|
49
|
+
}>;
|
|
50
|
+
starting: z.ZodLiteral<true>;
|
|
51
|
+
startingToken: z.ZodString;
|
|
52
|
+
}, z.core.$strip>]>>;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
/** What a worker pane shows right now, as its own computer reads it. */
|
|
55
|
+
export interface WorkerObservation {
|
|
56
|
+
/** Herdr's status for the pane, or gone when the pane or its conversation is no longer there. */
|
|
57
|
+
state: "working" | "idle" | "done" | "blocked" | "unknown" | "gone" | "unavailable";
|
|
58
|
+
session?: string;
|
|
59
|
+
completed?: boolean;
|
|
60
|
+
reply?: string;
|
|
61
|
+
truncated?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface WorkerReaders {
|
|
64
|
+
snapshot: (server: string) => Promise<Json>;
|
|
65
|
+
identity: (server: string, pane: Json) => Promise<string | undefined>;
|
|
66
|
+
finalTurn: (source: Provider, session: string) => Promise<FinalTurn | undefined>;
|
|
67
|
+
}
|
|
68
|
+
/** `value` cut to at most `limit` UTF-8 bytes on a character boundary. */
|
|
69
|
+
export declare function truncateUtf8(value: string, limit?: number): {
|
|
70
|
+
text: string;
|
|
71
|
+
truncated: boolean;
|
|
72
|
+
};
|
|
73
|
+
/** Receiving side: the state of each dispatched pane, from the shared snapshot
|
|
74
|
+
* and, once the agent has stopped, the final reply in its transcript. */
|
|
75
|
+
export declare function workerStates(input: unknown, readers?: WorkerReaders): Promise<{
|
|
76
|
+
workers: WorkerObservation[];
|
|
77
|
+
}>;
|
|
78
|
+
/** Apply one observation to a receipt. Returns true when the receipt changed. */
|
|
79
|
+
export declare function observe(receipt: Receipt, value: unknown, now: number): boolean;
|
|
80
|
+
/** One line for the dispatching agent: who returned, how, and where to read it. */
|
|
81
|
+
export declare function noticeLine(receipts: readonly Receipt[]): string;
|
|
82
|
+
/** What `dispatch_returns` lists for one unread return. */
|
|
83
|
+
export declare function returnRow(receipt: Receipt): Json;
|
|
84
|
+
export interface DispatchReturnsOptions {
|
|
85
|
+
peers?: () => Promise<HookPeer[]>;
|
|
86
|
+
request?: typeof peerRequest;
|
|
87
|
+
/** Worker states on this computer, for dispatches placed here without SSH. */
|
|
88
|
+
localWorkers?: (input: Json) => Promise<{
|
|
89
|
+
workers: unknown[];
|
|
90
|
+
}>;
|
|
91
|
+
isLocal?: (computer: string) => boolean;
|
|
92
|
+
/** A recent Herdr snapshot of a local server, to see whether the dispatching agent is idle. */
|
|
93
|
+
snapshot?: (server: string) => Promise<Json>;
|
|
94
|
+
identity?: (server: string, pane: Json) => Promise<string | undefined>;
|
|
95
|
+
/** Types the notice into the dispatching agent, through the ordinary hand-off path. */
|
|
96
|
+
deliver?: (target: Target, text: string) => Promise<{
|
|
97
|
+
delivered: boolean;
|
|
98
|
+
}>;
|
|
99
|
+
now?: () => number;
|
|
100
|
+
}
|
|
101
|
+
/** Dispatching side: follows open dispatches and delivers their returns. */
|
|
102
|
+
export declare class DispatchReturns {
|
|
103
|
+
private readonly peers;
|
|
104
|
+
private readonly request;
|
|
105
|
+
private readonly localWorkers;
|
|
106
|
+
private readonly isLocal;
|
|
107
|
+
private readonly snapshot;
|
|
108
|
+
private readonly identity;
|
|
109
|
+
private readonly deliver;
|
|
110
|
+
private readonly now;
|
|
111
|
+
private lastPoll;
|
|
112
|
+
private readonly lastNotice;
|
|
113
|
+
private running?;
|
|
114
|
+
constructor(options?: DispatchReturnsOptions);
|
|
115
|
+
/** Called from the Hook's activity tick; polls and notifies at most every POLL_MS. */
|
|
116
|
+
tick(): Promise<void>;
|
|
117
|
+
/** Ask each peer, once, about every open dispatch placed on it. */
|
|
118
|
+
poll(): Promise<void>;
|
|
119
|
+
/** Type one line into each idle dispatching agent that has returns it was not told about. */
|
|
120
|
+
notify(): Promise<void>;
|
|
121
|
+
/** Every unread return, oldest first, marked read as it is handed over. */
|
|
122
|
+
take(): Promise<Json[]>;
|
|
123
|
+
}
|