@phren/cli 0.2.15 → 0.3.0
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 +195 -2
- package/dist/bridge/agent-hooks.js +1049 -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 +23 -0
- package/dist/bridge/code-note.js +51 -0
- package/dist/bridge/code-routes.d.ts +151 -0
- package/dist/bridge/code-routes.js +442 -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 +125 -0
- package/dist/bridge/dispatch-returns.js +283 -0
- package/dist/bridge/dispatch-tree.d.ts +54 -0
- package/dist/bridge/dispatch-tree.js +198 -0
- package/dist/bridge/dispatch.d.ts +210 -0
- package/dist/bridge/dispatch.js +286 -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 +28 -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 +61 -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 +54 -0
- package/dist/bridge/schedule-watch.js +255 -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 +36 -0
- package/dist/bridge/server-pane-routes.js +479 -0
- package/dist/bridge/server-routes.d.ts +108 -0
- package/dist/bridge/server-routes.js +556 -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 +96 -0
- package/dist/bridge/transcript-preview.js +491 -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 +46545 -21051
- package/dist/cli/actions.js +14 -1
- package/dist/cli/config-policy.js +25 -0
- 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.d.ts +0 -8
- package/dist/cli/extract.js +4 -7
- 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 +17 -4
- package/dist/content/validate.js +200 -122
- 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 +16 -1
- package/dist/data/access.js +31 -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 +525 -419
- 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 +11 -8
- 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 -15
- package/dist/hooks.js +14 -1
- 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 +15 -5
- package/dist/init/init-walkthrough.js +1 -1
- 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 +68 -593
- package/dist/init/shared.js +2 -0
- package/dist/init/store-gitignore.d.ts +1 -6
- package/dist/init/store-gitignore.js +2 -8
- package/dist/init/teardown.d.ts +1 -1
- package/dist/init/teardown.js +2 -2
- package/dist/link/context-imports.d.ts +15 -0
- package/dist/link/context-imports.js +101 -0
- package/dist/link/context.js +1 -1
- package/dist/link/doctor.d.ts +22 -1
- package/dist/link/doctor.js +128 -58
- 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 -19
- package/dist/mcp/profile.js +64 -22
- package/dist/memory-ui-graph.runtime.js +525 -419
- package/dist/modules/code-package.d.ts +16 -0
- package/dist/modules/code-package.js +160 -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 +43 -8
- package/dist/project-config.d.ts +19 -1
- package/dist/project-config.js +29 -3
- package/dist/project-topics.d.ts +1 -0
- package/dist/project-topics.js +13 -10
- 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 -3
- package/dist/shared/retrieval.js +101 -12
- 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 +186 -0
- package/dist/tools/config.js +8 -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.d.ts +11 -0
- package/dist/tools/finding.js +180 -123
- 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 +52 -7
- package/dist/update.js +22 -11
- 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 +49 -7
- 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
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ synthesize?: boolean - Generate a synthesis paragraph from top results usi
|
|
|
77
77
|
|
|
78
78
|
### get_project_summary
|
|
79
79
|
|
|
80
|
-
Returns a project's summary.md content, path to its
|
|
80
|
+
Returns a project's summary.md content, path to its AGENTS.md, and a list of indexed files.
|
|
81
81
|
|
|
82
82
|
```
|
|
83
83
|
name: string - Project name (e.g. "my-app", "backend")
|
|
@@ -98,7 +98,7 @@ No parameters.
|
|
|
98
98
|
5. Builds an in-memory SQLite FTS5 index with Porter stemming
|
|
99
99
|
6. Serves tools over stdio using the MCP protocol
|
|
100
100
|
|
|
101
|
-
File types are derived from filenames and directories: `
|
|
101
|
+
File types are derived from filenames and directories: `AGENTS.md` -> "claude", `summary.md` -> "summary", `FINDINGS.md` -> "findings", `tasks.md` -> "task", files under `notes/` -> "notes", files under `reference/` -> "reference", files under `skills/` -> "skill".
|
|
102
102
|
|
|
103
103
|
## Development
|
|
104
104
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const AGENT_INSTRUCTIONS_FILENAME = "AGENTS.md";
|
|
2
|
+
export declare const LEGACY_AGENT_INSTRUCTIONS_FILENAME = "CLAUDE.md";
|
|
3
|
+
/** Resolve instructions without changing the store. New files always win. */
|
|
4
|
+
export declare function resolveAgentInstructionsPath(scopeDir: string): string | null;
|
|
5
|
+
/**
|
|
6
|
+
* Copy legacy instructions to AGENTS.md once. The legacy source is retained so
|
|
7
|
+
* an interrupted upgrade, older Phren client, or hand-written Claude setup
|
|
8
|
+
* cannot lose data. When both files exist AGENTS.md remains authoritative and
|
|
9
|
+
* neither file is modified.
|
|
10
|
+
*/
|
|
11
|
+
export declare function migrateLegacyAgentInstructions(scopeDir: string): boolean;
|
|
12
|
+
export declare function migrateStoreAgentInstructions(phrenPath: string): string[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { atomicWriteText, debugLog } from "./shared.js";
|
|
4
|
+
import { errorMessage } from "./utils.js";
|
|
5
|
+
export const AGENT_INSTRUCTIONS_FILENAME = "AGENTS.md";
|
|
6
|
+
export const LEGACY_AGENT_INSTRUCTIONS_FILENAME = "CLAUDE.md";
|
|
7
|
+
/** Resolve instructions without changing the store. New files always win. */
|
|
8
|
+
export function resolveAgentInstructionsPath(scopeDir) {
|
|
9
|
+
const canonical = path.join(scopeDir, AGENT_INSTRUCTIONS_FILENAME);
|
|
10
|
+
if (fs.existsSync(canonical))
|
|
11
|
+
return canonical;
|
|
12
|
+
const legacy = path.join(scopeDir, LEGACY_AGENT_INSTRUCTIONS_FILENAME);
|
|
13
|
+
return fs.existsSync(legacy) ? legacy : null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Copy legacy instructions to AGENTS.md once. The legacy source is retained so
|
|
17
|
+
* an interrupted upgrade, older Phren client, or hand-written Claude setup
|
|
18
|
+
* cannot lose data. When both files exist AGENTS.md remains authoritative and
|
|
19
|
+
* neither file is modified.
|
|
20
|
+
*/
|
|
21
|
+
export function migrateLegacyAgentInstructions(scopeDir) {
|
|
22
|
+
const canonical = path.join(scopeDir, AGENT_INSTRUCTIONS_FILENAME);
|
|
23
|
+
const legacy = path.join(scopeDir, LEGACY_AGENT_INSTRUCTIONS_FILENAME);
|
|
24
|
+
if (fs.existsSync(canonical) || !fs.existsSync(legacy))
|
|
25
|
+
return false;
|
|
26
|
+
try {
|
|
27
|
+
atomicWriteText(canonical, fs.readFileSync(legacy, "utf8"));
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
debugLog(`agent instructions migration failed for ${scopeDir}: ${errorMessage(err)}`);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function migrateStoreAgentInstructions(phrenPath) {
|
|
36
|
+
const migrated = [];
|
|
37
|
+
let entries;
|
|
38
|
+
try {
|
|
39
|
+
entries = fs.readdirSync(phrenPath, { withFileTypes: true });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return migrated;
|
|
43
|
+
}
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
if (!entry.isDirectory() || entry.name.startsWith("."))
|
|
46
|
+
continue;
|
|
47
|
+
const scopeDir = path.join(phrenPath, entry.name);
|
|
48
|
+
if (migrateLegacyAgentInstructions(scopeDir))
|
|
49
|
+
migrated.push(`${entry.name}/${AGENT_INSTRUCTIONS_FILENAME}`);
|
|
50
|
+
}
|
|
51
|
+
return migrated;
|
|
52
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Json } from "./protocol.js";
|
|
2
|
+
/** Small stores the agent callback socket keeps: the recorded pane binding
|
|
3
|
+
* files, push-notification answer bindings, and overview watch leases. */
|
|
4
|
+
export declare const localSocket: () => string;
|
|
5
|
+
export declare const bindingPath: (server: string, pane: string) => string;
|
|
6
|
+
export declare function recordedSession(server: string, pane: Json, pids: number[]): Promise<string | undefined>;
|
|
7
|
+
export interface PushBinding {
|
|
8
|
+
action: string;
|
|
9
|
+
expiresAt: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class PushBindingStore {
|
|
12
|
+
private now;
|
|
13
|
+
private limit;
|
|
14
|
+
private values;
|
|
15
|
+
constructor(now?: () => number, limit?: number);
|
|
16
|
+
add(binding: string, value: PushBinding): void;
|
|
17
|
+
consume(binding: string): PushBinding | undefined;
|
|
18
|
+
/** The binding's action without spending it: a tap that opens the app. */
|
|
19
|
+
peek(binding: string): PushBinding | undefined;
|
|
20
|
+
dropAction(action: string): void;
|
|
21
|
+
clear(): void;
|
|
22
|
+
get size(): number;
|
|
23
|
+
}
|
|
24
|
+
/** An explicit foreground overview poll renews interest for a bounded interval.
|
|
25
|
+
* A disconnected phone never leaves future terminal prompts waiting forever. */
|
|
26
|
+
export declare class ApprovalWatchLeases {
|
|
27
|
+
private now;
|
|
28
|
+
private servers;
|
|
29
|
+
constructor(now?: () => number);
|
|
30
|
+
renew(server: string): void;
|
|
31
|
+
has(server: string): boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { bridgeRoot, object, serverName, sessionId } from "./protocol.js";
|
|
4
|
+
/** Small stores the agent callback socket keeps: the recorded pane binding
|
|
5
|
+
* files, push-notification answer bindings, and overview watch leases. */
|
|
6
|
+
export const localSocket = () => path.join(bridgeRoot(), "agent.sock");
|
|
7
|
+
export const bindingPath = (server, pane) => path.join(bridgeRoot(), "bindings", encodeURIComponent(serverName.parse(server)), encodeURIComponent(pane) + ".json");
|
|
8
|
+
export async function recordedSession(server, pane, pids) {
|
|
9
|
+
try {
|
|
10
|
+
const value = object(JSON.parse(await readFile(bindingPath(server, String(pane.pane_id)), "utf8")));
|
|
11
|
+
if (value.terminal !== pane.terminal_id || value.source !== pane.agent || !Array.isArray(value.pids) || !value.pids.some(p => pids.includes(Number(p))))
|
|
12
|
+
return undefined;
|
|
13
|
+
return sessionId.parse(value.session);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class PushBindingStore {
|
|
20
|
+
now;
|
|
21
|
+
limit;
|
|
22
|
+
values = new Map();
|
|
23
|
+
constructor(now = Date.now, limit = 128) {
|
|
24
|
+
this.now = now;
|
|
25
|
+
this.limit = limit;
|
|
26
|
+
}
|
|
27
|
+
add(binding, value) {
|
|
28
|
+
for (const [key, item] of this.values)
|
|
29
|
+
if (item.expiresAt <= this.now())
|
|
30
|
+
this.values.delete(key);
|
|
31
|
+
while (this.values.size >= this.limit)
|
|
32
|
+
this.values.delete(this.values.keys().next().value);
|
|
33
|
+
this.values.set(binding, value);
|
|
34
|
+
}
|
|
35
|
+
consume(binding) {
|
|
36
|
+
const value = this.values.get(binding);
|
|
37
|
+
this.values.delete(binding);
|
|
38
|
+
return value && value.expiresAt > this.now() ? value : undefined;
|
|
39
|
+
}
|
|
40
|
+
/** The binding's action without spending it: a tap that opens the app. */
|
|
41
|
+
peek(binding) {
|
|
42
|
+
const value = this.values.get(binding);
|
|
43
|
+
return value && value.expiresAt > this.now() ? value : undefined;
|
|
44
|
+
}
|
|
45
|
+
dropAction(action) { for (const [key, value] of this.values)
|
|
46
|
+
if (value.action === action)
|
|
47
|
+
this.values.delete(key); }
|
|
48
|
+
clear() { this.values.clear(); }
|
|
49
|
+
get size() { return this.values.size; }
|
|
50
|
+
}
|
|
51
|
+
/** An explicit foreground overview poll renews interest for a bounded interval.
|
|
52
|
+
* A disconnected phone never leaves future terminal prompts waiting forever. */
|
|
53
|
+
export class ApprovalWatchLeases {
|
|
54
|
+
now;
|
|
55
|
+
servers = new Map();
|
|
56
|
+
constructor(now = Date.now) {
|
|
57
|
+
this.now = now;
|
|
58
|
+
}
|
|
59
|
+
renew(server) {
|
|
60
|
+
for (const [key, expiry] of this.servers)
|
|
61
|
+
if (expiry <= this.now())
|
|
62
|
+
this.servers.delete(key);
|
|
63
|
+
if (this.servers.has(server) || this.servers.size < 64)
|
|
64
|
+
this.servers.set(server, this.now() + 25_000);
|
|
65
|
+
}
|
|
66
|
+
has(server) { return (this.servers.get(server) || 0) > this.now(); }
|
|
67
|
+
}
|
|
@@ -1,14 +1,207 @@
|
|
|
1
|
+
import { type ModuleSnapshot } from "../modules/runtime.js";
|
|
2
|
+
import { type ServerResponse } from "node:http";
|
|
1
3
|
import { type Json, type Provider, type Target } from "./protocol.js";
|
|
2
|
-
|
|
4
|
+
import { ToolChanges } from "./changes.js";
|
|
5
|
+
import { ApprovalPushService } from "./push.js";
|
|
6
|
+
import { type TerminalChoice } from "./terminal-choice.js";
|
|
7
|
+
import { ApprovalWatchLeases } from "./agent-hook-stores.js";
|
|
8
|
+
export { permissionPrompt, terminalChoice, visibleTerminalChoice, type TerminalChoice, type TerminalQuestion } from "./terminal-choice.js";
|
|
9
|
+
export { ApprovalWatchLeases, PushBindingStore, recordedSession } from "./agent-hook-stores.js";
|
|
10
|
+
interface Pending {
|
|
11
|
+
target: Target;
|
|
12
|
+
response: ServerResponse;
|
|
13
|
+
tool: string;
|
|
14
|
+
input: unknown;
|
|
15
|
+
message: string;
|
|
16
|
+
title?: string;
|
|
17
|
+
choice?: TerminalChoice;
|
|
18
|
+
expiresAt: string;
|
|
19
|
+
timer: NodeJS.Timeout;
|
|
20
|
+
conductor?: {
|
|
21
|
+
action: "dispatch" | "hand_off";
|
|
22
|
+
project?: string;
|
|
23
|
+
computer?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** A conductor `dispatch` or `hand_off` permission ask the Hook can answer
|
|
27
|
+
* itself under a standing grant, or offer the phone two grant-writing answers. */
|
|
28
|
+
export declare function conductorCall(tool: string, input: unknown): Pending["conductor"] | undefined;
|
|
29
|
+
export type DeliveryOutcome = "delivered" | "blocked" | "pending";
|
|
3
30
|
/** This socket is deliberately separate from the phone's HTTP pipe. Only local
|
|
4
31
|
* agent callbacks can register identities or create an approval request. */
|
|
5
32
|
export declare class AgentHooks {
|
|
33
|
+
readonly push: ApprovalPushService;
|
|
34
|
+
private modules?;
|
|
35
|
+
readonly changes: ToolChanges;
|
|
6
36
|
private pending;
|
|
37
|
+
/** Prompts Phren has typed into a pane, by their text, until the agent that
|
|
38
|
+
* actually receives one reports in through UserPromptSubmit. Herdr writes
|
|
39
|
+
* to a pane, not a conversation; the receiving agent's hook is the only
|
|
40
|
+
* party that knows which conversation consumed the text, so it is the one
|
|
41
|
+
* that can refuse it when that is not the conversation the phone meant. */
|
|
42
|
+
private deliveries;
|
|
43
|
+
/** The permission request a conversation is drawing in its own terminal
|
|
44
|
+
* because nobody was there to hold it: what the phone shows above its
|
|
45
|
+
* answer keys until the pane stops waiting. `dialog` marks a choice parsed
|
|
46
|
+
* from the pane's own numbered lines, whose answers gain an Enter, and
|
|
47
|
+
* `questions` carries a released AskUserQuestion's normalized question set
|
|
48
|
+
* with the index currently being answered. */
|
|
49
|
+
private terminalPrompts;
|
|
50
|
+
/** The last time each pane's terminal lines were read for a dialog, so a
|
|
51
|
+
* status tick reads them at most once per three seconds per pane. */
|
|
52
|
+
private dialogReads;
|
|
53
|
+
/** Panes whose last read terminal line is a password prompt, so the status
|
|
54
|
+
* frame can offer the phone's secret sheet only when one is really asking. */
|
|
55
|
+
private passwords;
|
|
56
|
+
/** Conversations Claude Code is compacting, by target, until the new context
|
|
57
|
+
* starts. The phone shows the state instead of the summary row's text. */
|
|
58
|
+
private compactingSince;
|
|
59
|
+
/** Panes where Phren just typed a bare slash command: the agent is drawing
|
|
60
|
+
* that command's menu, which Herdr reports as an idle agent, so keys are
|
|
61
|
+
* allowed there for a short while to walk and confirm it. The command text
|
|
62
|
+
* and a one-shot confirmation attempt ride with the window. */
|
|
63
|
+
private menus;
|
|
7
64
|
private watching;
|
|
65
|
+
readonly overview: ApprovalWatchLeases;
|
|
8
66
|
private server?;
|
|
67
|
+
private pushBindings;
|
|
68
|
+
/** Held asks that were pushed: action -> when the notification expires. */
|
|
69
|
+
private pushedHolds;
|
|
70
|
+
/** Pushed asks whose hold ended with the request left in the terminal. */
|
|
71
|
+
private releasedHolds;
|
|
72
|
+
/** Terminal dialogs pushed to phones: by pane, the dialog last pushed; by
|
|
73
|
+
* action, what an answer from the notification types. */
|
|
74
|
+
private dialogPushes;
|
|
75
|
+
private dialogActions;
|
|
76
|
+
/** opencode permission asks seen on disk, by request id. */
|
|
77
|
+
private opencode;
|
|
78
|
+
private closed;
|
|
79
|
+
private opencodeSweep?;
|
|
80
|
+
private opencodeLive;
|
|
81
|
+
private fanoutLive;
|
|
82
|
+
private fanoutSweeping;
|
|
83
|
+
private opencodeWatcher?;
|
|
84
|
+
private opencodePoll?;
|
|
85
|
+
private opencodeDebounce?;
|
|
86
|
+
/** Fan-out jobs already pushed as blocked, by job id and blocked timestamp. */
|
|
87
|
+
private fanoutSeen;
|
|
88
|
+
private fanoutTimer?;
|
|
89
|
+
private fanoutArchiveTimer?;
|
|
90
|
+
constructor(push?: ApprovalPushService, modules?: ModuleSnapshot | undefined);
|
|
91
|
+
private approvalsDirectory;
|
|
92
|
+
private scheduleOpencodeSweep;
|
|
93
|
+
/** Read every live opencode request file, map it to a target through the
|
|
94
|
+
* recorded bindings or Herdr's explicit opencode session id, and register it
|
|
95
|
+
* for a push and a push-binding answer. A file that vanished or expired is
|
|
96
|
+
* forgotten. */
|
|
97
|
+
sweepOpencodeApprovals(): Promise<void>;
|
|
98
|
+
private readOpencodeApprovals;
|
|
99
|
+
/** A session's exact pane. A recorded binding carries the full target; when
|
|
100
|
+
* there is none, Herdr's explicit session identity names the pane. */
|
|
101
|
+
private resolveTarget;
|
|
102
|
+
/** Push once for each fan-out job whose blocked.json the plugin wrote. */
|
|
103
|
+
private sweepBlockedFanouts;
|
|
104
|
+
/** Move finished fan-out folders older than a day into the archive; one log
|
|
105
|
+
* line records a sweep that moved or deleted anything, and a sweep that
|
|
106
|
+
* fails never takes the Hook down. */
|
|
107
|
+
private sweepFanoutArchive;
|
|
9
108
|
watch(target: Target): () => void;
|
|
109
|
+
/** Register a prompt about to be typed into `target`'s pane. The returned
|
|
110
|
+
* promise settles "delivered" once that conversation's own hook submits the
|
|
111
|
+
* text, "blocked" if another conversation in the pane tried to, or "pending"
|
|
112
|
+
* after `waitMs`: a busy agent queues typed input and submits it only when
|
|
113
|
+
* its turn ends, so the record outlives the wait (up to ten minutes) and a
|
|
114
|
+
* late submission to the wrong conversation is still refused. */
|
|
115
|
+
expectDelivery(target: Target, text: string, waitMs?: number): Promise<DeliveryOutcome>;
|
|
116
|
+
/** A prompt Phren typed into `target` that its conversation has not submitted yet. */
|
|
117
|
+
deliveryPending(target: Target, text: string): boolean;
|
|
118
|
+
/** Wait again for a delivery `expectDelivery` already reported pending,
|
|
119
|
+
* after the Hook pressed Enter a second time. */
|
|
120
|
+
awaitLateDelivery(target: Target, text: string, waitMs?: number): Promise<DeliveryOutcome>;
|
|
121
|
+
/** The conversation `target` just submitted `prompt`. Nothing Phren typed
|
|
122
|
+
* matches: a locally typed prompt, always allowed. Otherwise the oldest
|
|
123
|
+
* matching delivery decides: its own conversation consumes it; any other
|
|
124
|
+
* conversation is told to drop it, so the text is never spoken to the
|
|
125
|
+
* wrong agent and the phone can safely send it again. */
|
|
126
|
+
private submitted;
|
|
127
|
+
private rememberTerminalPrompt;
|
|
128
|
+
/** The request the agent is showing in its terminal, if one fell through
|
|
129
|
+
* in the last fifteen minutes; the caller only asks while the pane waits. */
|
|
130
|
+
terminalPrompt(target: Target): Json | undefined;
|
|
131
|
+
clearTerminalPrompt(target: Target): void;
|
|
132
|
+
/** True while the pane's own terminal is reading a password. */
|
|
133
|
+
passwordPrompt(target: Target): boolean;
|
|
134
|
+
/** Claude Code's auto-mode fallback, opencode and Codex draw a numbered
|
|
135
|
+
* dialog in the pane with no PermissionRequest hook behind it. While the pane
|
|
136
|
+
* waits with nothing else to ask, read its last lines (at most once per
|
|
137
|
+
* three seconds per pane) and publish the dialog as a terminal choice; drop
|
|
138
|
+
* it when the pane leaves waiting or the dialog lines vanish. A remembered
|
|
139
|
+
* permission request that is not a dialog keeps the slot untouched. The same
|
|
140
|
+
* read notes whether the terminal is reading a password. */
|
|
141
|
+
syncTerminalDialog(target: Target, active: boolean): Promise<void>;
|
|
142
|
+
/** Resolve a phone option identifier. Real shortcuts retain their key path;
|
|
143
|
+
* keyless rows are reached and verified before returning Enter to the route. */
|
|
144
|
+
dialogAnswerKeys<K extends string>(target: Target, keys: readonly K[]): Promise<(K | "Enter")[]>;
|
|
145
|
+
moveDialogHighlight(target: Target, expected: TerminalChoice, key: string, beforeKeys?: () => Promise<void>): Promise<void>;
|
|
146
|
+
/** Answer one question of a released AskUserQuestion with the option's own
|
|
147
|
+
* digit: send the chosen digit(s), then Tab to advance to the next
|
|
148
|
+
* question or Enter after the last. The stored question index moves with
|
|
149
|
+
* them and a finished set is cleared. Undefined when the prompt is not a
|
|
150
|
+
* question, so an ordinary key falls through to the usual handling. */
|
|
151
|
+
questionAnswerKeys(target: Target, keys: readonly string[]): string[] | undefined;
|
|
152
|
+
private startCompacting;
|
|
153
|
+
private stopCompacting;
|
|
154
|
+
/** True while Claude Code is compacting `target`; a boundary older than ten
|
|
155
|
+
* minutes is stale, so a missed SessionStart cannot pin the state forever. */
|
|
156
|
+
compacting(target: Target): boolean;
|
|
157
|
+
menuOpened(target: Target, command?: string): void;
|
|
158
|
+
menuOpen(target: Target): boolean;
|
|
159
|
+
/** The bare slash command that opened this pane's current menu window. */
|
|
160
|
+
menuCommand(target: Target): string | undefined;
|
|
161
|
+
menuClosed(target: Target): void;
|
|
162
|
+
/** Read what the pane draws, stripping ANSI unless placeholder styling is needed. */
|
|
163
|
+
paneLines(target: Target, stripAnsi?: boolean): Promise<string>;
|
|
164
|
+
/** After the phone walks Codex's /permissions menu onto Full Access, the
|
|
165
|
+
* agent draws a second "Enable full access?" confirmation. Watch the pane's
|
|
166
|
+
* terminal lines for it, answer with its own numbered choice, and only then
|
|
167
|
+
* close the menu window. A confirmation that never arrives within three
|
|
168
|
+
* seconds is left open as the visible prompt, published as the terminal
|
|
169
|
+
* choice the phone draws as a question card. Runs at most once per window. */
|
|
170
|
+
walkMenuConfirmation(target: Target): Promise<{
|
|
171
|
+
menuClosed: boolean;
|
|
172
|
+
waiting?: {
|
|
173
|
+
message: string;
|
|
174
|
+
choice?: TerminalChoice;
|
|
175
|
+
};
|
|
176
|
+
}>;
|
|
10
177
|
approval(target: Target): Json | undefined;
|
|
11
|
-
|
|
178
|
+
private opencodeApproval;
|
|
179
|
+
/** Live fan-out worker asks shown on this parent conversation, oldest first. */
|
|
180
|
+
private fanoutHeld;
|
|
181
|
+
pendingPanes(server: string, state: Json): Set<string>;
|
|
182
|
+
/** Hands the owner's answer to the fan-out launcher waiting on the worker's session. */
|
|
183
|
+
private answerFanout;
|
|
184
|
+
answer(target: Target, id: string, decision: unknown, updatedInput?: unknown): Promise<void>;
|
|
185
|
+
/** A held approval that is really a terminal dialog, answered from the
|
|
186
|
+
* phone with its own keys: let the callback fall back to the terminal at
|
|
187
|
+
* once instead of leaving the card up until the 55-second timer. */
|
|
188
|
+
releaseChoice(target: Target): void;
|
|
189
|
+
answerPush(binding: string, decision: unknown): Promise<void>;
|
|
190
|
+
/** Where a pushed ask lives, without answering it: the phone opens that
|
|
191
|
+
* session's details when the notification itself is tapped. */
|
|
192
|
+
pushTarget(binding: string): Target | undefined;
|
|
193
|
+
/** Every waiting pane on this computer, each Hook tick, whether or not a
|
|
194
|
+
* phone watches: an approval an agent draws as a numbered dialog in its
|
|
195
|
+
* terminal (Claude's fallback prompts, Codex, OpenCode, Copilot) has no
|
|
196
|
+
* hook behind it, so this is the only way it reaches a phone with phren
|
|
197
|
+
* closed. Each dialog is pushed once; a pane that stops waiting drops it. */
|
|
198
|
+
observeWaitingPanes(server: string, panes: Json[], resolve: (pane: Json) => Promise<Target | undefined>): Promise<void>;
|
|
199
|
+
private adoptReleasedHold;
|
|
200
|
+
private dropDialogPush;
|
|
201
|
+
/** Approve picks the dialog's yes/allow row (else its first), Deny its
|
|
202
|
+
* no/deny row (else Escape), typed as the pane's own keys. */
|
|
203
|
+
private answerDialog;
|
|
204
|
+
private dropPushBindings;
|
|
12
205
|
start(): Promise<void>;
|
|
13
206
|
close(): void;
|
|
14
207
|
}
|