@phren/cli 0.2.15 → 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.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 +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,64 @@
|
|
|
1
|
+
import { type Json } from "./protocol.js";
|
|
2
|
+
interface TerminalChoiceOption {
|
|
3
|
+
label: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
key: string;
|
|
6
|
+
hasKey?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** The actual question a terminal dialog is asking, when its command and
|
|
9
|
+
* options are visible to the Hook: a title, the command it is about, and one
|
|
10
|
+
* row per choice. For keyless rows, key identifies the option to the phone;
|
|
11
|
+
* the Hook navigates from highlightedIndex instead of typing that number. */
|
|
12
|
+
export interface TerminalChoice {
|
|
13
|
+
title?: string;
|
|
14
|
+
body?: string;
|
|
15
|
+
options: TerminalChoiceOption[];
|
|
16
|
+
highlightedIndex?: number;
|
|
17
|
+
}
|
|
18
|
+
/** The question a pane's terminal lines are asking, in the same shape a held
|
|
19
|
+
* permission request carries: every non-empty line above the first numbered
|
|
20
|
+
* row (the "$ command" line included, the "Press enter" hint dropped), joined
|
|
21
|
+
* with newlines, then one option per row. Keyless rows require exactly one
|
|
22
|
+
* readable cursor so the Hook can navigate without confirming another row. */
|
|
23
|
+
export declare function visibleTerminalChoice(text: string): TerminalChoice | undefined;
|
|
24
|
+
/** The pane's last non-empty line is a password read: sudo's "[sudo] password
|
|
25
|
+
* for user", or any "… Password:" prompt. */
|
|
26
|
+
export declare function passwordLine(text: string): boolean;
|
|
27
|
+
/** The numbered dialog Claude Code and opencode draw straight in the pane when
|
|
28
|
+
* a permission ask falls back to the terminal (no PermissionRequest hook
|
|
29
|
+
* fires): the last non-empty line above the first "1." row is the question,
|
|
30
|
+
* each row is an option keyed by its own number with its text cut at the first
|
|
31
|
+
* " · ", and a footer offering "Esc to cancel" gains the Escape option.
|
|
32
|
+
* Undefined without two numbered rows and a question. */
|
|
33
|
+
export declare function numberedDialog(text: string): TerminalChoice | undefined;
|
|
34
|
+
/** Read the question a terminal dialog is asking from the request it carries:
|
|
35
|
+
* an explicit options list, or numbered lines inside its text. Undefined when
|
|
36
|
+
* there are not at least two answerable choices. */
|
|
37
|
+
export declare function terminalChoice(input: unknown): TerminalChoice | undefined;
|
|
38
|
+
/** Normalize a held permission without turning its arguments into a question. */
|
|
39
|
+
export declare function permissionPrompt(tool: string, input: unknown, terminalText?: string): {
|
|
40
|
+
title?: string;
|
|
41
|
+
details: string;
|
|
42
|
+
choice?: TerminalChoice;
|
|
43
|
+
terminalOnly: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** Claude Code's AskUserQuestion input, normalized to the shape the phone
|
|
46
|
+
* already decodes for a held permission request: one question per entry with
|
|
47
|
+
* its header, multi-select flag and options. Undefined when nothing parses. */
|
|
48
|
+
export interface TerminalQuestion {
|
|
49
|
+
question: string;
|
|
50
|
+
header?: string;
|
|
51
|
+
multiSelect?: boolean;
|
|
52
|
+
options: {
|
|
53
|
+
label: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
preview?: string;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
58
|
+
export declare function terminalQuestions(input: unknown): TerminalQuestion[] | undefined;
|
|
59
|
+
/** The current question of a released AskUserQuestion as a terminal choice:
|
|
60
|
+
* its labels keyed "1".."n", and a "Done" Enter for a multi-select question
|
|
61
|
+
* whose answers are confirmed by leaving it. */
|
|
62
|
+
export declare function questionChoice(questions: TerminalQuestion[], index: number): TerminalChoice | undefined;
|
|
63
|
+
export declare function answeredQuestionInput(tool: string, input: unknown, updatedInput: unknown): Json;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BridgeError, object, objects } from "./protocol.js";
|
|
3
|
+
/** Reading the question a terminal dialog or held permission is asking:
|
|
4
|
+
* numbered option rows, the highlighted row, password reads, and a released
|
|
5
|
+
* AskUserQuestion's questions and answers. Pure functions over text and input. */
|
|
6
|
+
/** The terminal keys an agent's own dialog accepts. Kept in step with
|
|
7
|
+
* `ANSWER_KEYS` in server-pane-routes.ts; "p" is Codex's "don't ask again" answer. */
|
|
8
|
+
const choiceKeys = new Set(["Escape", "Enter", "Up", "Down", "Tab", "y", "n", "p", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
|
|
9
|
+
/** A question asks in a few lines; more than this is scrollback above it. */
|
|
10
|
+
const QUESTION_LINES = 12;
|
|
11
|
+
function choiceKey(value) {
|
|
12
|
+
if (typeof value !== "string")
|
|
13
|
+
return undefined;
|
|
14
|
+
const text = value.trim().toLowerCase();
|
|
15
|
+
if (!text)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (text === "esc" || text === "escape")
|
|
18
|
+
return "Escape";
|
|
19
|
+
if (text === "enter" || text === "return")
|
|
20
|
+
return "Enter";
|
|
21
|
+
if (text === "up" || text === "down" || text === "tab")
|
|
22
|
+
return text[0].toUpperCase() + text.slice(1);
|
|
23
|
+
return choiceKeys.has(text) ? text : undefined;
|
|
24
|
+
}
|
|
25
|
+
function commandText(value) {
|
|
26
|
+
if (typeof value === "string" && value.trim())
|
|
27
|
+
return value.trim();
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
const parts = value.filter((part) => typeof part === "string" && !!part.trim());
|
|
30
|
+
if (parts.length)
|
|
31
|
+
return parts.join(" ");
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function optionLabel(value) {
|
|
36
|
+
if (typeof value === "string")
|
|
37
|
+
return value.trim() || undefined;
|
|
38
|
+
const fields = object(value);
|
|
39
|
+
for (const key of ["label", "name", "title", "text", "value"]) {
|
|
40
|
+
if (typeof fields[key] === "string" && fields[key].trim())
|
|
41
|
+
return fields[key].trim();
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
function labeledOption(label, key) {
|
|
46
|
+
let resolved = choiceKey(key);
|
|
47
|
+
const trailing = /^(.+?)\s*\(([A-Za-z0-9]+)\)\s*$/.exec(label);
|
|
48
|
+
if (!resolved && trailing)
|
|
49
|
+
resolved = choiceKey(trailing[2]);
|
|
50
|
+
return resolved ? { label, key: resolved } : undefined;
|
|
51
|
+
}
|
|
52
|
+
function structuredOptions(value) {
|
|
53
|
+
if (!Array.isArray(value))
|
|
54
|
+
return [];
|
|
55
|
+
return value.flatMap(item => {
|
|
56
|
+
const label = optionLabel(item);
|
|
57
|
+
if (!label)
|
|
58
|
+
return [];
|
|
59
|
+
const fields = object(item);
|
|
60
|
+
const key = ["key", "shortcut", "hotkey", "accelerator", "value"].map(name => choiceKey(fields[name])).find(Boolean);
|
|
61
|
+
const option = labeledOption(label, key);
|
|
62
|
+
return option ? [{ ...option, ...(typeof fields.description === "string" && fields.description.trim() ? { description: fields.description.trim().slice(0, 4_000) } : {}) }] : [];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Numbered options as Codex draws them: "1. Yes, proceed (y)", with the
|
|
66
|
+
* cursor marker in front of the highlighted row. Harnesses draw that marker
|
|
67
|
+
* with whatever glyph they like (Codex uses "›"), and missing one costs
|
|
68
|
+
* the option twice over: the row is dropped and its text joins the question. The key in
|
|
69
|
+
* trailing parentheses (y, p, n, esc, enter, a digit) is the answer when
|
|
70
|
+
* present and is cut from the label. A row number alone is an identifier,
|
|
71
|
+
* not evidence that the terminal accepts it as a shortcut. */
|
|
72
|
+
function numberedOptions(text) {
|
|
73
|
+
return text.split(/\r?\n/).flatMap(line => {
|
|
74
|
+
const match = /^\s*([>❯›▸▶»•*])?\s*(\d+)[.)]\s+(.+?)\s*$/.exec(line);
|
|
75
|
+
if (!match)
|
|
76
|
+
return [];
|
|
77
|
+
const columns = /^(.+?)\s{2,}(.+)$/.exec(match[3].trim());
|
|
78
|
+
const label = columns?.[1] ?? match[3].trim();
|
|
79
|
+
const description = columns?.[2].trim();
|
|
80
|
+
const trailing = /^(.+?)\s*\(([A-Za-z0-9]+)\)\s*$/.exec(label);
|
|
81
|
+
const descriptionKey = description ? /^(.+?)\s*\(([A-Za-z0-9]+)\)\s*$/.exec(description) : null;
|
|
82
|
+
const labelKey = trailing ? choiceKey(trailing[2]) : undefined;
|
|
83
|
+
const endKey = descriptionKey ? choiceKey(descriptionKey[2]) : undefined;
|
|
84
|
+
const key = labelKey ?? endKey ?? choiceKey(match[2]);
|
|
85
|
+
return key ? [{ label: labelKey && trailing ? trailing[1].trim() : label, key,
|
|
86
|
+
highlighted: !!match[1], hasKey: !!(labelKey ?? endKey),
|
|
87
|
+
...(description ? { description: endKey && descriptionKey ? descriptionKey[1].trim() : description } : {}) }] : [];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** The question a pane's terminal lines are asking, in the same shape a held
|
|
91
|
+
* permission request carries: every non-empty line above the first numbered
|
|
92
|
+
* row (the "$ command" line included, the "Press enter" hint dropped), joined
|
|
93
|
+
* with newlines, then one option per row. Keyless rows require exactly one
|
|
94
|
+
* readable cursor so the Hook can navigate without confirming another row. */
|
|
95
|
+
export function visibleTerminalChoice(text) {
|
|
96
|
+
const parsed = numberedOptions(text);
|
|
97
|
+
const highlights = parsed.flatMap((option, index) => option.highlighted ? [index] : []);
|
|
98
|
+
const highlightedIndex = highlights.length === 1 ? highlights[0] : undefined;
|
|
99
|
+
if (parsed.some(option => !option.hasKey) && highlightedIndex === undefined)
|
|
100
|
+
return undefined;
|
|
101
|
+
const options = parsed.map(({ highlighted: _highlighted, ...option }) => option);
|
|
102
|
+
if (options.length < 2 || new Set(options.map(option => option.key)).size !== options.length)
|
|
103
|
+
return undefined;
|
|
104
|
+
const lines = text.split(/\r?\n/);
|
|
105
|
+
const firstOption = lines.findIndex(line => /^\s*[>❯›▸▶»•*]?\s*\d+[.)]\s+/.test(line));
|
|
106
|
+
const above = firstOption < 0 ? lines.slice(0, 1) : lines.slice(0, firstOption);
|
|
107
|
+
// Only the question's own block: everything above the last blank line is
|
|
108
|
+
// whatever the agent printed before it asked, and reading a pane of
|
|
109
|
+
// scrollback as the question is worse than reading none of it.
|
|
110
|
+
while (above.length && !above[above.length - 1].trim())
|
|
111
|
+
above.pop();
|
|
112
|
+
let start = above.length;
|
|
113
|
+
while (start > 0 && above[start - 1].trim())
|
|
114
|
+
start -= 1;
|
|
115
|
+
const menuStart = above.findIndex((line, index) => index >= above.length - QUESTION_LINES
|
|
116
|
+
&& /^\s*(?:select|choose) (?:model|reasoning (?:level|effort))\b/i.test(line));
|
|
117
|
+
const question = above.slice(menuStart >= 0 ? menuStart : Math.max(start, above.length - QUESTION_LINES));
|
|
118
|
+
const title = question.map(line => line.trim()).filter(line => line && !/^press enter\b/i.test(line)).join("\n").trim();
|
|
119
|
+
if (!title)
|
|
120
|
+
return undefined;
|
|
121
|
+
return { title: title.slice(0, 4_000), options: options.slice(0, 12),
|
|
122
|
+
...(highlightedIndex !== undefined ? { highlightedIndex } : {}) };
|
|
123
|
+
}
|
|
124
|
+
/** The pane's last non-empty line is a password read: sudo's "[sudo] password
|
|
125
|
+
* for user", or any "… Password:" prompt. */
|
|
126
|
+
export function passwordLine(text) {
|
|
127
|
+
if (text.includes("[sudo] password for"))
|
|
128
|
+
return true;
|
|
129
|
+
const last = text.split(/\r?\n/).map(line => line.trim()).filter(Boolean).pop() ?? "";
|
|
130
|
+
return /password[^\n]*:\s*$/i.test(last);
|
|
131
|
+
}
|
|
132
|
+
/** The numbered dialog Claude Code and opencode draw straight in the pane when
|
|
133
|
+
* a permission ask falls back to the terminal (no PermissionRequest hook
|
|
134
|
+
* fires): the last non-empty line above the first "1." row is the question,
|
|
135
|
+
* each row is an option keyed by its own number with its text cut at the first
|
|
136
|
+
* " · ", and a footer offering "Esc to cancel" gains the Escape option.
|
|
137
|
+
* Undefined without two numbered rows and a question. */
|
|
138
|
+
export function numberedDialog(text) {
|
|
139
|
+
const row = /^\s*[>❯›▸▶»•*]?\s*(\d+)\.\s+(.+?)\s*$/;
|
|
140
|
+
const lines = text.split(/\r?\n/);
|
|
141
|
+
const first = lines.findIndex(line => row.test(line));
|
|
142
|
+
if (first < 0)
|
|
143
|
+
return undefined;
|
|
144
|
+
const title = lines.slice(0, first).map(line => line.trim()).filter(Boolean).pop();
|
|
145
|
+
if (!title)
|
|
146
|
+
return undefined;
|
|
147
|
+
const options = [];
|
|
148
|
+
for (const line of lines.slice(first)) {
|
|
149
|
+
const match = row.exec(line);
|
|
150
|
+
if (!match)
|
|
151
|
+
continue;
|
|
152
|
+
const label = match[2].split(" · ")[0].trim();
|
|
153
|
+
if (label)
|
|
154
|
+
options.push({ label, key: match[1] });
|
|
155
|
+
}
|
|
156
|
+
if (options.length < 2)
|
|
157
|
+
return undefined;
|
|
158
|
+
if (lines.some(line => line.includes("Esc to cancel")))
|
|
159
|
+
options.push({ label: "Cancel", key: "Escape" });
|
|
160
|
+
return { title: title.slice(0, 4_000), options: options.slice(0, 12) };
|
|
161
|
+
}
|
|
162
|
+
/** Read the question a terminal dialog is asking from the request it carries:
|
|
163
|
+
* an explicit options list, or numbered lines inside its text. Undefined when
|
|
164
|
+
* there are not at least two answerable choices. */
|
|
165
|
+
export function terminalChoice(input) {
|
|
166
|
+
const fields = object(input), command = commandText(fields.command ?? fields.cmd);
|
|
167
|
+
let options = [fields.options, fields.choices, fields.actions, fields.answers].map(structuredOptions).find(list => list.length >= 2) ?? [];
|
|
168
|
+
if (options.length < 2) {
|
|
169
|
+
const text = [fields.question, fields.description, fields.justification, fields.prompt, fields.message, fields.text, fields.content, fields.display]
|
|
170
|
+
.filter((value) => typeof value === "string").join("\n");
|
|
171
|
+
const parsed = numberedOptions(text);
|
|
172
|
+
if (parsed.length >= 2)
|
|
173
|
+
options = parsed.map(({ highlighted: _highlighted, hasKey: _hasKey, ...option }) => option);
|
|
174
|
+
}
|
|
175
|
+
if (options.length < 2)
|
|
176
|
+
return undefined;
|
|
177
|
+
const title = [fields.question, fields.description, fields.justification, fields.prompt]
|
|
178
|
+
.find((value) => typeof value === "string" && !!value.trim() && value.trim() !== command);
|
|
179
|
+
if (!title && !command)
|
|
180
|
+
return undefined;
|
|
181
|
+
return { ...(title ? { title: String(title).slice(0, 4_000) } : {}), ...(command ? { body: command.slice(0, 4_000) } : {}), options: options.slice(0, 12) };
|
|
182
|
+
}
|
|
183
|
+
/** Keep structured tool arguments in details, never in the asking sentence. */
|
|
184
|
+
function permissionTitle(tool, input) {
|
|
185
|
+
const fields = object(input);
|
|
186
|
+
const sentence = [fields.question, fields.prompt, fields.description, fields.justification, fields.message]
|
|
187
|
+
.find((value) => typeof value === "string" && !!value.trim() && !/^[{[]/.test(value.trim()));
|
|
188
|
+
if (sentence)
|
|
189
|
+
return sentence.trim().slice(0, 4_000);
|
|
190
|
+
const mcp = /^mcp__([^_]+)__(.+)$/.exec(tool);
|
|
191
|
+
const server = mcp?.[1] ?? fields.server;
|
|
192
|
+
const name = mcp?.[2] ?? fields.tool;
|
|
193
|
+
if (typeof server === "string" && typeof name === "string")
|
|
194
|
+
return `Allow the ${server} MCP server to run tool ${name}?`;
|
|
195
|
+
return tool && tool !== "action" ? `Allow ${tool}?` : undefined;
|
|
196
|
+
}
|
|
197
|
+
function samePermission(choice, title, tool, input) {
|
|
198
|
+
const text = choice.title?.toLowerCase() ?? "";
|
|
199
|
+
if (title && text.includes(title.toLowerCase()))
|
|
200
|
+
return true;
|
|
201
|
+
const command = commandText(object(input).command ?? object(input).cmd);
|
|
202
|
+
if (command && text.includes(command.toLowerCase()))
|
|
203
|
+
return true;
|
|
204
|
+
const name = tool.split("__").pop();
|
|
205
|
+
return !!name && name !== "action" && text.includes(name.toLowerCase());
|
|
206
|
+
}
|
|
207
|
+
/** Normalize a held permission without turning its arguments into a question. */
|
|
208
|
+
export function permissionPrompt(tool, input, terminalText = "") {
|
|
209
|
+
const title = permissionTitle(tool, input);
|
|
210
|
+
const dialog = visibleTerminalChoice(terminalText);
|
|
211
|
+
const matched = dialog && samePermission(dialog, title, tool, input) ? dialog : undefined;
|
|
212
|
+
const sentence = matched?.title?.split("\n").find(line => /\?\s*$/.test(line) && !/^[{[]/.test(line.trim()));
|
|
213
|
+
const choice = matched ? { ...matched, title: sentence ?? title } : terminalChoice(input);
|
|
214
|
+
return { title: choice?.title ?? title, details: JSON.stringify(input ?? {}, null, 2).slice(0, 32_768),
|
|
215
|
+
...(choice ? { choice } : {}), terminalOnly: !choice };
|
|
216
|
+
}
|
|
217
|
+
export function terminalQuestions(input) {
|
|
218
|
+
const questions = objects(object(input).questions).flatMap(raw => {
|
|
219
|
+
const question = typeof raw.question === "string" ? raw.question.trim() : "";
|
|
220
|
+
if (!question || question.length > 4_000)
|
|
221
|
+
return [];
|
|
222
|
+
const options = objects(raw.options).flatMap(option => {
|
|
223
|
+
const label = typeof option.label === "string" ? option.label.trim() : "";
|
|
224
|
+
if (!label || label.length > 2_000)
|
|
225
|
+
return [];
|
|
226
|
+
return [{ label, ...(typeof option.description === "string" && option.description ? { description: option.description.slice(0, 4_000) } : {}),
|
|
227
|
+
...(typeof option.preview === "string" && option.preview ? { preview: option.preview.slice(0, 4_000) } : {}) }];
|
|
228
|
+
});
|
|
229
|
+
if (!options.length || options.length > 12)
|
|
230
|
+
return [];
|
|
231
|
+
return [{ question, ...(typeof raw.header === "string" && raw.header ? { header: raw.header.slice(0, 200) } : {}),
|
|
232
|
+
...(raw.multiSelect === true ? { multiSelect: true } : {}), options }];
|
|
233
|
+
});
|
|
234
|
+
return questions.length >= 1 && questions.length <= 8 ? questions : undefined;
|
|
235
|
+
}
|
|
236
|
+
/** The current question of a released AskUserQuestion as a terminal choice:
|
|
237
|
+
* its labels keyed "1".."n", and a "Done" Enter for a multi-select question
|
|
238
|
+
* whose answers are confirmed by leaving it. */
|
|
239
|
+
export function questionChoice(questions, index) {
|
|
240
|
+
const question = questions[index];
|
|
241
|
+
if (!question)
|
|
242
|
+
return undefined;
|
|
243
|
+
const options = question.options.map((option, position) => ({ label: option.label, key: String(position + 1) }));
|
|
244
|
+
if (question.multiSelect)
|
|
245
|
+
options.push({ label: "Done", key: "Enter" });
|
|
246
|
+
return { title: question.question, options: options.slice(0, 12) };
|
|
247
|
+
}
|
|
248
|
+
/** Claude Code's AskUserQuestion is answered by allowing the call with its own
|
|
249
|
+
* input plus `answers` keyed by question text (a label, or labels when the
|
|
250
|
+
* question is multiSelect; any other string is a typed "Other"). The phone may
|
|
251
|
+
* add answers and a free-text `response`; it may not rewrite the questions. */
|
|
252
|
+
const questionAnswers = z.looseObject({
|
|
253
|
+
answers: z.record(z.string().min(1).max(4000), z.union([z.string().max(4000), z.array(z.string().max(4000)).min(1).max(24)])).refine(a => Object.keys(a).length > 0),
|
|
254
|
+
response: z.string().max(4000).optional(),
|
|
255
|
+
});
|
|
256
|
+
function canonical(value) {
|
|
257
|
+
if (Array.isArray(value))
|
|
258
|
+
return "[" + value.map(canonical).join(",") + "]";
|
|
259
|
+
if (value !== null && typeof value === "object")
|
|
260
|
+
return "{" + Object.keys(value).sort().map(k => JSON.stringify(k) + ":" + canonical(value[k])).join(",") + "}";
|
|
261
|
+
return JSON.stringify(value) ?? "null";
|
|
262
|
+
}
|
|
263
|
+
export function answeredQuestionInput(tool, input, updatedInput) {
|
|
264
|
+
if (tool !== "AskUserQuestion")
|
|
265
|
+
throw new BridgeError(400, "Only a question can be answered with input.");
|
|
266
|
+
if (updatedInput === null || typeof updatedInput !== "object" || Array.isArray(updatedInput))
|
|
267
|
+
throw new BridgeError(400, "The answer is not an object.");
|
|
268
|
+
const raw = JSON.stringify(updatedInput);
|
|
269
|
+
if (Buffer.byteLength(raw) > 32_768)
|
|
270
|
+
throw new BridgeError(400, "The answer is too large.");
|
|
271
|
+
const parsed = questionAnswers.safeParse(updatedInput);
|
|
272
|
+
if (!parsed.success)
|
|
273
|
+
throw new BridgeError(400, "The answer must add an answers object.");
|
|
274
|
+
const { answers, response, ...rest } = parsed.data;
|
|
275
|
+
if (canonical(rest) !== canonical(object(input)))
|
|
276
|
+
throw new BridgeError(400, "The answer must keep the original questions.");
|
|
277
|
+
const asked = new Set(objects(object(input).questions).map(q => q.question).filter(q => typeof q === "string"));
|
|
278
|
+
if (Object.keys(answers).some(q => !asked.has(q)))
|
|
279
|
+
throw new BridgeError(400, "The answer names a question that was not asked.");
|
|
280
|
+
return { ...object(input), answers, ...(response === undefined ? {} : { response }) };
|
|
281
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Json } from "./protocol.js";
|
|
2
|
+
import type { ChildAgentRelation } from "./transcripts.js";
|
|
3
|
+
/** The checkout a Claude sub-agent edits in. Claude Code writes the isolated
|
|
4
|
+
* worktree into the child's `.meta.json`; an older child falls back to the
|
|
5
|
+
* `cwd` its own first rows record when that folder is a linked worktree (its
|
|
6
|
+
* `.git` is a file). A child working in the parent's checkout gets nothing,
|
|
7
|
+
* and a worktree already removed is not offered. */
|
|
8
|
+
export declare function claudeChildCheckout(file: string): Promise<Pick<ChildAgentRelation, "cwd" | "worktreeName" | "branch">>;
|
|
9
|
+
export declare function claudeChildAgents(file: string, session: string): Promise<ChildAgentRelation[]>;
|
|
10
|
+
export declare const harnessPreamble: (text: string) => boolean;
|
|
11
|
+
export declare function unwrapPastedContent(text: string): string;
|
|
12
|
+
/** A thinking block Claude marks as narration for the person watching: its
|
|
13
|
+
* signature is a length-prefixed field reading "narration" (private
|
|
14
|
+
* reasoning reads "thinking" and is stored without text). */
|
|
15
|
+
export declare function isNarration(block: Record<string, unknown>): boolean;
|
|
16
|
+
/** A phren UserPromptSubmit injection, as `{ type: "phren_hook_context",
|
|
17
|
+
* parentUuid, content }`, or undefined for any other row. */
|
|
18
|
+
export declare function phrenHookContext(raw: Json, includeSidechain?: boolean): Json | undefined;
|
|
19
|
+
/** Claude Code rows the phone may see: user, assistant and system turns with
|
|
20
|
+
* private reasoning redacted, queued phone messages, background task
|
|
21
|
+
* notifications and compaction markers. */
|
|
22
|
+
export declare function visibleClaudeEvent(raw: Json, includeSidechain?: boolean): Json | undefined;
|