@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,207 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type DispatchHost } from "./dispatch-hosts.js";
|
|
3
|
+
import { type Json, type Provider, type Target } from "./protocol.js";
|
|
4
|
+
export declare const projectName: z.ZodString;
|
|
5
|
+
export declare const dispatchSchema: z.ZodObject<{
|
|
6
|
+
computer: z.ZodUnion<readonly [z.ZodLiteral<"anywhere">, z.ZodString]>;
|
|
7
|
+
project: z.ZodString;
|
|
8
|
+
harness: z.ZodEnum<{
|
|
9
|
+
claude: "claude";
|
|
10
|
+
codex: "codex";
|
|
11
|
+
opencode: "opencode";
|
|
12
|
+
}>;
|
|
13
|
+
model: z.ZodOptional<z.ZodString>;
|
|
14
|
+
prompt: z.ZodString;
|
|
15
|
+
label: z.ZodString;
|
|
16
|
+
parent: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
provider: z.ZodEnum<{
|
|
18
|
+
claude: "claude";
|
|
19
|
+
codex: "codex";
|
|
20
|
+
copilot: "copilot";
|
|
21
|
+
opencode: "opencode";
|
|
22
|
+
phren: "phren";
|
|
23
|
+
}>;
|
|
24
|
+
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
25
|
+
computer: z.ZodString;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
parentTarget: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
server: z.ZodString;
|
|
29
|
+
workspace: z.ZodString;
|
|
30
|
+
tab: z.ZodString;
|
|
31
|
+
pane: z.ZodString;
|
|
32
|
+
source: z.ZodEnum<{
|
|
33
|
+
claude: "claude";
|
|
34
|
+
codex: "codex";
|
|
35
|
+
copilot: "copilot";
|
|
36
|
+
opencode: "opencode";
|
|
37
|
+
phren: "phren";
|
|
38
|
+
}>;
|
|
39
|
+
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
40
|
+
}, z.core.$strip>>;
|
|
41
|
+
}, z.core.$strict>;
|
|
42
|
+
export type DispatchInput = z.infer<typeof dispatchSchema>;
|
|
43
|
+
/** The local pane that asked for the dispatch, where return notices go. */
|
|
44
|
+
export declare const originPaneSchema: z.ZodObject<{
|
|
45
|
+
server: z.ZodString;
|
|
46
|
+
workspace: z.ZodString;
|
|
47
|
+
tab: z.ZodString;
|
|
48
|
+
pane: z.ZodString;
|
|
49
|
+
}, z.core.$strict>;
|
|
50
|
+
export type OriginPane = z.infer<typeof originPaneSchema>;
|
|
51
|
+
export declare const workerStates: readonly ["working", "done", "needs-you", "blocked", "gone"];
|
|
52
|
+
export type WorkerState = typeof workerStates[number];
|
|
53
|
+
declare const receiptSchema: z.ZodObject<{
|
|
54
|
+
computer: z.ZodUnion<readonly [z.ZodLiteral<"anywhere">, z.ZodString]>;
|
|
55
|
+
project: z.ZodString;
|
|
56
|
+
harness: z.ZodEnum<{
|
|
57
|
+
claude: "claude";
|
|
58
|
+
codex: "codex";
|
|
59
|
+
opencode: "opencode";
|
|
60
|
+
}>;
|
|
61
|
+
model: z.ZodOptional<z.ZodString>;
|
|
62
|
+
label: z.ZodString;
|
|
63
|
+
parent: z.ZodOptional<z.ZodObject<{
|
|
64
|
+
provider: z.ZodEnum<{
|
|
65
|
+
claude: "claude";
|
|
66
|
+
codex: "codex";
|
|
67
|
+
copilot: "copilot";
|
|
68
|
+
opencode: "opencode";
|
|
69
|
+
phren: "phren";
|
|
70
|
+
}>;
|
|
71
|
+
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
72
|
+
computer: z.ZodString;
|
|
73
|
+
}, z.core.$strict>>;
|
|
74
|
+
parentTarget: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
server: z.ZodString;
|
|
76
|
+
workspace: z.ZodString;
|
|
77
|
+
tab: z.ZodString;
|
|
78
|
+
pane: z.ZodString;
|
|
79
|
+
source: z.ZodEnum<{
|
|
80
|
+
claude: "claude";
|
|
81
|
+
codex: "codex";
|
|
82
|
+
copilot: "copilot";
|
|
83
|
+
opencode: "opencode";
|
|
84
|
+
phren: "phren";
|
|
85
|
+
}>;
|
|
86
|
+
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
87
|
+
}, z.core.$strip>>;
|
|
88
|
+
id: z.ZodString;
|
|
89
|
+
createdAt: z.ZodString;
|
|
90
|
+
updatedAt: z.ZodString;
|
|
91
|
+
computerId: z.ZodOptional<z.ZodString>;
|
|
92
|
+
state: z.ZodEnum<{
|
|
93
|
+
accepted: "accepted";
|
|
94
|
+
failed: "failed";
|
|
95
|
+
launching: "launching";
|
|
96
|
+
sending: "sending";
|
|
97
|
+
uncertain: "uncertain";
|
|
98
|
+
}>;
|
|
99
|
+
target: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
100
|
+
server: z.ZodString;
|
|
101
|
+
workspace: z.ZodString;
|
|
102
|
+
tab: z.ZodString;
|
|
103
|
+
pane: z.ZodString;
|
|
104
|
+
source: z.ZodEnum<{
|
|
105
|
+
claude: "claude";
|
|
106
|
+
codex: "codex";
|
|
107
|
+
copilot: "copilot";
|
|
108
|
+
opencode: "opencode";
|
|
109
|
+
phren: "phren";
|
|
110
|
+
}>;
|
|
111
|
+
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
112
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
113
|
+
server: z.ZodString;
|
|
114
|
+
workspace: z.ZodString;
|
|
115
|
+
tab: z.ZodString;
|
|
116
|
+
pane: z.ZodString;
|
|
117
|
+
source: z.ZodEnum<{
|
|
118
|
+
claude: "claude";
|
|
119
|
+
codex: "codex";
|
|
120
|
+
copilot: "copilot";
|
|
121
|
+
opencode: "opencode";
|
|
122
|
+
phren: "phren";
|
|
123
|
+
}>;
|
|
124
|
+
starting: z.ZodLiteral<true>;
|
|
125
|
+
startingToken: z.ZodString;
|
|
126
|
+
}, z.core.$strip>]>>;
|
|
127
|
+
error: z.ZodOptional<z.ZodString>;
|
|
128
|
+
granted: z.ZodOptional<z.ZodString>;
|
|
129
|
+
skipped: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
130
|
+
computer: z.ZodString;
|
|
131
|
+
reason: z.ZodString;
|
|
132
|
+
}, z.core.$strict>>>;
|
|
133
|
+
origin: z.ZodOptional<z.ZodObject<{
|
|
134
|
+
server: z.ZodString;
|
|
135
|
+
workspace: z.ZodString;
|
|
136
|
+
tab: z.ZodString;
|
|
137
|
+
pane: z.ZodString;
|
|
138
|
+
agent: z.ZodEnum<{
|
|
139
|
+
claude: "claude";
|
|
140
|
+
codex: "codex";
|
|
141
|
+
copilot: "copilot";
|
|
142
|
+
opencode: "opencode";
|
|
143
|
+
phren: "phren";
|
|
144
|
+
}>;
|
|
145
|
+
terminal: z.ZodString;
|
|
146
|
+
}, z.core.$strict>>;
|
|
147
|
+
worker: z.ZodOptional<z.ZodObject<{
|
|
148
|
+
state: z.ZodEnum<{
|
|
149
|
+
blocked: "blocked";
|
|
150
|
+
done: "done";
|
|
151
|
+
gone: "gone";
|
|
152
|
+
"needs-you": "needs-you";
|
|
153
|
+
working: "working";
|
|
154
|
+
}>;
|
|
155
|
+
since: z.ZodString;
|
|
156
|
+
checkedAt: z.ZodString;
|
|
157
|
+
sawWorking: z.ZodBoolean;
|
|
158
|
+
}, z.core.$strict>>;
|
|
159
|
+
returned: z.ZodOptional<z.ZodObject<{
|
|
160
|
+
state: z.ZodEnum<{
|
|
161
|
+
blocked: "blocked";
|
|
162
|
+
done: "done";
|
|
163
|
+
gone: "gone";
|
|
164
|
+
"needs-you": "needs-you";
|
|
165
|
+
}>;
|
|
166
|
+
at: z.ZodString;
|
|
167
|
+
reply: z.ZodOptional<z.ZodString>;
|
|
168
|
+
truncated: z.ZodOptional<z.ZodBoolean>;
|
|
169
|
+
question: z.ZodOptional<z.ZodString>;
|
|
170
|
+
turn: z.ZodOptional<z.ZodString>;
|
|
171
|
+
read: z.ZodBoolean;
|
|
172
|
+
notifiedAt: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.core.$strict>>;
|
|
174
|
+
}, z.core.$strict>;
|
|
175
|
+
export type Receipt = z.infer<typeof receiptSchema>;
|
|
176
|
+
export declare function dispatchProjectDirectory(project: unknown): Promise<string>;
|
|
177
|
+
/**
|
|
178
|
+
* Change one settled receipt: read it, let `change` edit it, and write it back
|
|
179
|
+
* when `change` returns true. Updates run one at a time in this process, and a
|
|
180
|
+
* receipt still being placed (launching or sending) is never touched.
|
|
181
|
+
*/
|
|
182
|
+
export declare function updateReceipt(receiptID: string, change: (receipt: Receipt) => boolean): Promise<Receipt | undefined>;
|
|
183
|
+
/** One bounded line for a log or a receipt: a Bridge message, an errno code, or the error's first line. */
|
|
184
|
+
export declare function failureReason(error: unknown): string;
|
|
185
|
+
export declare function dispatchStatus(): Promise<Receipt[]>;
|
|
186
|
+
export interface DispatchIdentity {
|
|
187
|
+
computerID: string;
|
|
188
|
+
validateParentTarget: (target: Target) => Promise<unknown>;
|
|
189
|
+
/** The agent and terminal running in a local pane, or undefined when the pane has no agent. */
|
|
190
|
+
originAgent?: (pane: OriginPane) => Promise<{
|
|
191
|
+
agent: Provider;
|
|
192
|
+
terminal: string;
|
|
193
|
+
} | undefined>;
|
|
194
|
+
}
|
|
195
|
+
export declare class DispatchService {
|
|
196
|
+
private readonly identity?;
|
|
197
|
+
private readonly local;
|
|
198
|
+
private active;
|
|
199
|
+
/** `local` is this computer as a dispatch destination (its own Hook's
|
|
200
|
+
* socket); tests replace it so they never reach a real Hook. */
|
|
201
|
+
constructor(identity?: DispatchIdentity | undefined, local?: () => DispatchHost);
|
|
202
|
+
/** `originValue` is the local pane the request came from, as its agent's
|
|
203
|
+
* Herdr variables name it; a pane without a running agent is left out. */
|
|
204
|
+
dispatch(input: unknown, originValue?: unknown): Promise<Json>;
|
|
205
|
+
private origin;
|
|
206
|
+
}
|
|
207
|
+
export {};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { logger } from "../logger.js";
|
|
6
|
+
import { readProjectConfig } from "../project-config.js";
|
|
7
|
+
import { computerName } from "./computers.js";
|
|
8
|
+
import { dispatchParentSchema, validateDispatchParent } from "./dispatch-tree.js";
|
|
9
|
+
import { grantLabel, listGrants, matchGrant } from "./grants.js";
|
|
10
|
+
import { hookPeers } from "./peers.js";
|
|
11
|
+
import { isLocalComputer, localHost, peerHost } from "./dispatch-hosts.js";
|
|
12
|
+
import { atomic, BridgeError, bridgeRoot, id, PROTOCOL, provider, serverName, startingTargetSchema, targetSchema } from "./protocol.js";
|
|
13
|
+
import { phrenStoreRoot } from "./transcripts.js";
|
|
14
|
+
const text = (max) => z.string().min(1).max(max).refine(value => !!value.trim() && !/[\x00-\x1f\x7f]/.test(value));
|
|
15
|
+
export const projectName = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/);
|
|
16
|
+
export const dispatchSchema = z.object({
|
|
17
|
+
computer: z.union([z.literal("anywhere"), computerName]).describe("Enrolled computer name, or anywhere for the least busy connected computer."),
|
|
18
|
+
project: projectName.describe("Project slug registered on the receiving computer."),
|
|
19
|
+
harness: z.enum(["codex", "claude", "opencode"]).describe("Agent harness on the receiving computer."),
|
|
20
|
+
model: text(200).optional().describe("Explicit model, otherwise the remote harness default."),
|
|
21
|
+
prompt: z.string().min(1).max(32768).refine(value => !/[\x00-\x08\x0b-\x1f\x7f]/.test(value)).describe("Worker brief, at most 32768 characters."),
|
|
22
|
+
label: text(200).describe("Short task label."),
|
|
23
|
+
parent: dispatchParentSchema.optional().describe("Explicit local conversation parent for work-tree attachment."),
|
|
24
|
+
parentTarget: targetSchema.optional().describe("Complete live target for the explicit parent."),
|
|
25
|
+
}).strict();
|
|
26
|
+
const remoteTarget = z.union([targetSchema, startingTargetSchema]);
|
|
27
|
+
/** The local pane that asked for the dispatch, where return notices go. */
|
|
28
|
+
export const originPaneSchema = z.object({ server: serverName, workspace: id, tab: id, pane: id }).strict();
|
|
29
|
+
export const workerStates = ["working", "done", "needs-you", "blocked", "gone"];
|
|
30
|
+
const timestamp = z.string().datetime();
|
|
31
|
+
const receiptSchema = dispatchSchema.omit({ prompt: true }).extend({
|
|
32
|
+
id: z.string().uuid(), createdAt: z.string().datetime(), updatedAt: z.string().datetime(),
|
|
33
|
+
computerId: z.string().uuid().optional(),
|
|
34
|
+
state: z.enum(["launching", "sending", "accepted", "uncertain", "failed"]),
|
|
35
|
+
target: remoteTarget.optional(), error: z.string().max(500).optional(),
|
|
36
|
+
granted: z.string().max(200).optional().describe("Scope of the conductor grant that allowed this call."),
|
|
37
|
+
skipped: z.array(z.object({ computer: computerName, reason: z.string().max(200) }).strict()).max(32).optional()
|
|
38
|
+
.describe("Computers left out of anywhere placement, with the reason each could not report capacity."),
|
|
39
|
+
origin: originPaneSchema.extend({ agent: provider, terminal: z.string().min(1).max(200) }).strict().optional()
|
|
40
|
+
.describe("The local agent pane that placed this dispatch; return notices go there."),
|
|
41
|
+
worker: z.object({ state: z.enum(workerStates), since: timestamp, checkedAt: timestamp, sawWorking: z.boolean() }).strict().optional()
|
|
42
|
+
.describe("The worker pane's last observed state."),
|
|
43
|
+
returned: z.object({
|
|
44
|
+
state: z.enum(["done", "needs-you", "blocked", "gone"]), at: timestamp,
|
|
45
|
+
reply: z.string().max(4000).optional(), truncated: z.boolean().optional(), question: z.string().max(200).optional(),
|
|
46
|
+
turn: z.string().regex(/^[a-f0-9]{16}$/).optional(), read: z.boolean(), notifiedAt: timestamp.optional(),
|
|
47
|
+
}).strict().optional().describe("The latest return: the worker finished, needs the owner, is blocked or is gone."),
|
|
48
|
+
});
|
|
49
|
+
export async function dispatchProjectDirectory(project) {
|
|
50
|
+
const name = projectName.parse(project);
|
|
51
|
+
const source = readProjectConfig(phrenStoreRoot(), name).sourcePath;
|
|
52
|
+
if (typeof source !== "string" || !path.isAbsolute(source) || /[\x00-\x1f\x7f]/.test(source))
|
|
53
|
+
throw new BridgeError(404, "Project has no absolute sourcePath on this computer.");
|
|
54
|
+
const directory = await realpath(source).catch(() => undefined);
|
|
55
|
+
if (!directory || !(await stat(directory)).isDirectory())
|
|
56
|
+
throw new BridgeError(404, "Project is not on this computer.");
|
|
57
|
+
return directory;
|
|
58
|
+
}
|
|
59
|
+
async function save(receipt) {
|
|
60
|
+
const root = path.join(bridgeRoot(), "dispatches");
|
|
61
|
+
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
62
|
+
await atomic(path.join(root, `${receipt.id}.json`), receipt);
|
|
63
|
+
}
|
|
64
|
+
const MAX_RECEIPT_BYTES = 65_536;
|
|
65
|
+
let receiptUpdates = Promise.resolve();
|
|
66
|
+
/**
|
|
67
|
+
* Change one settled receipt: read it, let `change` edit it, and write it back
|
|
68
|
+
* when `change` returns true. Updates run one at a time in this process, and a
|
|
69
|
+
* receipt still being placed (launching or sending) is never touched.
|
|
70
|
+
*/
|
|
71
|
+
export function updateReceipt(receiptID, change) {
|
|
72
|
+
const run = receiptUpdates.then(async () => {
|
|
73
|
+
const file = path.join(bridgeRoot(), "dispatches", `${z.string().uuid().parse(receiptID)}.json`);
|
|
74
|
+
const info = await lstat(file).catch(() => undefined);
|
|
75
|
+
if (!info?.isFile() || info.isSymbolicLink() || info.size > MAX_RECEIPT_BYTES)
|
|
76
|
+
return undefined;
|
|
77
|
+
const receipt = receiptSchema.parse(JSON.parse(await readFile(file, "utf8")));
|
|
78
|
+
if (["launching", "sending"].includes(receipt.state))
|
|
79
|
+
return undefined;
|
|
80
|
+
if (!change(receipt))
|
|
81
|
+
return receipt;
|
|
82
|
+
receipt.updatedAt = new Date().toISOString();
|
|
83
|
+
await atomic(file, receiptSchema.parse(receipt));
|
|
84
|
+
return receipt;
|
|
85
|
+
});
|
|
86
|
+
receiptUpdates = run.catch(() => undefined);
|
|
87
|
+
return run;
|
|
88
|
+
}
|
|
89
|
+
/** No ledger yet is normal; any other read failure is logged before it reads as empty. */
|
|
90
|
+
async function receiptNames(root) {
|
|
91
|
+
try {
|
|
92
|
+
return await readdir(root);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error.code !== "ENOENT")
|
|
96
|
+
logger.warn("dispatch", `Could not list dispatch receipts: ${failureReason(error)}`);
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** One bounded line for a log or a receipt: a Bridge message, an errno code, or the error's first line. */
|
|
101
|
+
export function failureReason(error) {
|
|
102
|
+
if (error instanceof z.ZodError)
|
|
103
|
+
return "The remote Hook sent an unexpected reply (protocol mismatch).";
|
|
104
|
+
const code = error?.code;
|
|
105
|
+
const message = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
106
|
+
return `${typeof code === "string" && !(error instanceof BridgeError) ? `${code}: ` : ""}${message}`.replace(/[\x00-\x1f\x7f]/g, " ").slice(0, 200);
|
|
107
|
+
}
|
|
108
|
+
export async function dispatchStatus() {
|
|
109
|
+
const root = path.join(bridgeRoot(), "dispatches");
|
|
110
|
+
const names = (await receiptNames(root)).filter(name => /^[a-f0-9-]{36}\.json$/.test(name)).slice(0, 1024);
|
|
111
|
+
const receipts = [];
|
|
112
|
+
for (const name of names) {
|
|
113
|
+
try {
|
|
114
|
+
const file = path.join(root, name);
|
|
115
|
+
const info = await lstat(file);
|
|
116
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > MAX_RECEIPT_BYTES)
|
|
117
|
+
continue;
|
|
118
|
+
const receipt = receiptSchema.parse(JSON.parse(await readFile(file, "utf8")));
|
|
119
|
+
// A service restart cannot prove whether an in-flight mutation arrived.
|
|
120
|
+
if (["launching", "sending"].includes(receipt.state))
|
|
121
|
+
receipt.state = "uncertain";
|
|
122
|
+
receipts.push(receipt);
|
|
123
|
+
}
|
|
124
|
+
catch { /* Interrupted or old receipts do not become live dispatches. */ }
|
|
125
|
+
}
|
|
126
|
+
return receipts.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
127
|
+
}
|
|
128
|
+
async function capacity(host) {
|
|
129
|
+
const value = await host.request("/v1/dispatch/capacity");
|
|
130
|
+
const result = z.object({ product: z.literal("phren-hook"), protocol: z.literal(PROTOCOL), working: z.number().int().nonnegative(),
|
|
131
|
+
servers: z.array(z.string()), computer: z.object({ id: z.string().uuid() }).passthrough() }).parse(value);
|
|
132
|
+
// This computer places on whichever Herdr server its own Hook runs.
|
|
133
|
+
if (host.local && !result.servers.includes(host.server) && result.servers[0])
|
|
134
|
+
host.server = result.servers[0];
|
|
135
|
+
if (!result.servers.includes(host.server))
|
|
136
|
+
throw new BridgeError(503, "Herdr is not running on the selected computer. Headless dispatch is not installed yet.");
|
|
137
|
+
return { working: result.working, computerId: result.computer.id };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A freshly started agent may not have written its session yet when the launch
|
|
141
|
+
* returns, so the launch carries no target. Ask the remote pane for its session
|
|
142
|
+
* for a few seconds before giving up; the pane ids from the launch are enough
|
|
143
|
+
* to find it.
|
|
144
|
+
*/
|
|
145
|
+
async function settledTarget(peer, launched, harness) {
|
|
146
|
+
const workspace = launched.workspaceId, tab = launched.tabId, pane = launched.paneId;
|
|
147
|
+
if (typeof workspace !== "string" || typeof tab !== "string" || typeof pane !== "string")
|
|
148
|
+
return undefined;
|
|
149
|
+
for (let attempt = 0; attempt < 15; attempt++) {
|
|
150
|
+
await new Promise(resolve => setTimeout(resolve, 1_000));
|
|
151
|
+
try {
|
|
152
|
+
const result = await peer.request(`/v1/workspaces/panes?server=${encodeURIComponent(peer.server)}&groupId=${encodeURIComponent(workspace)}&childId=${encodeURIComponent(tab)}`);
|
|
153
|
+
const found = (Array.isArray(result.panes) ? result.panes : []).find((p) => p && typeof p === "object" && p.id === pane);
|
|
154
|
+
const session = found?.sessionId;
|
|
155
|
+
if (typeof session === "string" && session)
|
|
156
|
+
return { server: peer.server, workspace, tab, pane, source: harness, session };
|
|
157
|
+
}
|
|
158
|
+
catch { /* The pane list can lag the launch; try again. */ }
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
export class DispatchService {
|
|
163
|
+
identity;
|
|
164
|
+
local;
|
|
165
|
+
active = false;
|
|
166
|
+
/** `local` is this computer as a dispatch destination (its own Hook's
|
|
167
|
+
* socket); tests replace it so they never reach a real Hook. */
|
|
168
|
+
constructor(identity, local = () => localHost()) {
|
|
169
|
+
this.identity = identity;
|
|
170
|
+
this.local = local;
|
|
171
|
+
}
|
|
172
|
+
/** `originValue` is the local pane the request came from, as its agent's
|
|
173
|
+
* Herdr variables name it; a pane without a running agent is left out. */
|
|
174
|
+
async dispatch(input, originValue) {
|
|
175
|
+
const data = dispatchSchema.parse(input);
|
|
176
|
+
if (this.active)
|
|
177
|
+
throw new BridgeError(429, "A dispatch is already being placed. Try again after its receipt arrives.");
|
|
178
|
+
this.active = true;
|
|
179
|
+
try {
|
|
180
|
+
if (data.parent !== undefined || data.parentTarget !== undefined) {
|
|
181
|
+
if (!this.identity)
|
|
182
|
+
throw new BridgeError(503, "This Hook cannot validate a dispatch parent.");
|
|
183
|
+
await validateDispatchParent(data, this.identity.computerID, this.identity.validateParentTarget);
|
|
184
|
+
}
|
|
185
|
+
if ((await receiptNames(path.join(bridgeRoot(), "dispatches"))).length >= 1024)
|
|
186
|
+
throw new BridgeError(429, "Dispatch history is full. Archive old receipts before dispatching again.");
|
|
187
|
+
// This computer needs no hooks.yaml entry, so a missing file only
|
|
188
|
+
// matters when the dispatch names another computer.
|
|
189
|
+
const here = this.local();
|
|
190
|
+
const toLocal = data.computer !== "anywhere" && isLocalComputer(data.computer, here.names);
|
|
191
|
+
const enrolled = await hookPeers().catch(error => { if (toLocal || data.computer === "anywhere")
|
|
192
|
+
return []; throw error; });
|
|
193
|
+
const peers = [...enrolled.map(candidate => peerHost(candidate)), here];
|
|
194
|
+
let peer;
|
|
195
|
+
let remoteComputerID;
|
|
196
|
+
const skipped = [];
|
|
197
|
+
if (data.computer === "anywhere") {
|
|
198
|
+
const available = await Promise.all(peers.map(async (candidate) => {
|
|
199
|
+
try {
|
|
200
|
+
return { peer: candidate, ...await capacity(candidate) };
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
// A peer that cannot report capacity sits out this placement, and the receipt says why.
|
|
204
|
+
skipped.push({ computer: candidate.name, reason: failureReason(error) });
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
}));
|
|
208
|
+
skipped.sort((a, b) => a.computer.localeCompare(b.computer));
|
|
209
|
+
const selected = available.filter((item) => !!item)
|
|
210
|
+
.sort((a, b) => a.working - b.working || a.peer.name.localeCompare(b.peer.name))[0];
|
|
211
|
+
peer = selected?.peer;
|
|
212
|
+
remoteComputerID = selected?.computerId;
|
|
213
|
+
if (!peer)
|
|
214
|
+
throw new BridgeError(503, "No enrolled computer with a running Herdr is connected.", skipped.length ? { skipped } : undefined);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
peer = toLocal ? peers.find(candidate => candidate.local) : peers.find(candidate => !candidate.local && candidate.name === data.computer);
|
|
218
|
+
if (!peer)
|
|
219
|
+
throw new BridgeError(404, "Unknown computer. Add its verified connection to hooks.yaml.");
|
|
220
|
+
remoteComputerID = (await capacity(peer)).computerId;
|
|
221
|
+
}
|
|
222
|
+
const grant = matchGrant(await listGrants(), { action: "dispatch", project: data.project, computer: peer.name });
|
|
223
|
+
const origin = await this.origin(originValue);
|
|
224
|
+
// Prompts are sent over the pipe, never stored in the dispatch ledger.
|
|
225
|
+
const { prompt, ...metadata } = data;
|
|
226
|
+
const receipt = { ...metadata, computer: peer.name, computerId: remoteComputerID, id: randomUUID(),
|
|
227
|
+
createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), state: "launching",
|
|
228
|
+
...(grant ? { granted: grantLabel(grant) } : {}), ...(skipped.length ? { skipped } : {}), ...(origin ? { origin } : {}) };
|
|
229
|
+
await save(receipt);
|
|
230
|
+
try {
|
|
231
|
+
const launched = await peer.request(`/v1/workspaces/launch?server=${encodeURIComponent(peer.server)}`, { project: data.project, kind: data.harness, model: data.model, label: data.label });
|
|
232
|
+
const target = remoteTarget.parse(launched.target ?? await settledTarget(peer, launched, data.harness));
|
|
233
|
+
if (target.source !== data.harness || target.server !== peer.server)
|
|
234
|
+
throw new BridgeError(502, "The remote Hook returned a different launch target.");
|
|
235
|
+
receipt.target = target;
|
|
236
|
+
receipt.state = "sending";
|
|
237
|
+
receipt.updatedAt = new Date().toISOString();
|
|
238
|
+
await save(receipt);
|
|
239
|
+
const result = await peer.request("/v1/prompt", { target: receipt.target, text: prompt });
|
|
240
|
+
receipt.state = result.ok === true && result.deliveryUncertain !== true ? "accepted" : "uncertain";
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
receipt.state = receipt.state === "launching" && error instanceof BridgeError && [400, 404, 429].includes(error.status) ? "failed" : "uncertain";
|
|
244
|
+
receipt.error = error instanceof BridgeError ? error.message.slice(0, 500) : "Remote delivery was not confirmed. Inspect this dispatch before retrying.";
|
|
245
|
+
}
|
|
246
|
+
receipt.updatedAt = new Date().toISOString();
|
|
247
|
+
await save(receipt);
|
|
248
|
+
return { ok: receipt.state === "accepted", ...receipt };
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
this.active = false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async origin(value) {
|
|
255
|
+
const pane = originPaneSchema.safeParse(value);
|
|
256
|
+
if (!pane.success || !this.identity?.originAgent)
|
|
257
|
+
return undefined;
|
|
258
|
+
const running = await this.identity.originAgent(pane.data).catch(() => undefined);
|
|
259
|
+
return running ? { ...pane.data, ...running } : undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Json } from "./protocol.js";
|
|
2
|
+
/**
|
|
3
|
+
* "Add project" from the phone: the repositories on this computer that phren
|
|
4
|
+
* does not track yet, and enrolling one — an existing checkout, or a fresh
|
|
5
|
+
* clone — the way `phren add` would from its folder. The store is committed
|
|
6
|
+
* and pushed afterwards when it has a remote, since the phone reads the store
|
|
7
|
+
* through GitHub and would otherwise never see the new project.
|
|
8
|
+
*/
|
|
9
|
+
export interface RepoCandidate {
|
|
10
|
+
directory: string;
|
|
11
|
+
name: string;
|
|
12
|
+
source: "activity" | "herdr" | "search";
|
|
13
|
+
registered: boolean;
|
|
14
|
+
lastSeen?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Git checkouts on this computer, newest activity first, then Herdr's
|
|
17
|
+
* saved workspaces, then one level under the usual project roots. */
|
|
18
|
+
export declare function candidateRepos(activity: Json[], env?: NodeJS.ProcessEnv): Promise<RepoCandidate[]>;
|
|
19
|
+
export interface EnrollInput {
|
|
20
|
+
directory?: string;
|
|
21
|
+
cloneUrl?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Enrolled {
|
|
24
|
+
ok: true;
|
|
25
|
+
project: string;
|
|
26
|
+
directory: string;
|
|
27
|
+
cloned: boolean;
|
|
28
|
+
store: "pushed" | "committed" | "unchanged" | "error";
|
|
29
|
+
storeDetail?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function enrollProject(input: EnrollInput, env?: NodeJS.ProcessEnv): Promise<Enrolled>;
|