@phren/cli 0.3.10 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/dist/bridge/agent-hook-stores.d.ts +3 -0
  2. package/dist/bridge/agent-hook-stores.js +5 -0
  3. package/dist/bridge/agent-hooks.d.ts +159 -5
  4. package/dist/bridge/agent-hooks.js +663 -49
  5. package/dist/bridge/approval-summary.d.ts +16 -0
  6. package/dist/bridge/approval-summary.js +133 -0
  7. package/dist/bridge/authority-command.d.ts +20 -0
  8. package/dist/bridge/authority-command.js +120 -0
  9. package/dist/bridge/authority.d.ts +223 -0
  10. package/dist/bridge/authority.js +231 -0
  11. package/dist/bridge/claude-account-setup.d.ts +14 -0
  12. package/dist/bridge/claude-account-setup.js +69 -0
  13. package/dist/bridge/claude-accounts.d.ts +49 -0
  14. package/dist/bridge/claude-accounts.js +195 -0
  15. package/dist/bridge/code-routes.js +2 -2
  16. package/dist/bridge/codex-app-server.d.ts +144 -0
  17. package/dist/bridge/codex-app-server.js +319 -0
  18. package/dist/bridge/codex-auth-refresh.d.ts +33 -0
  19. package/dist/bridge/codex-auth-refresh.js +71 -0
  20. package/dist/bridge/codex-question-reply.d.ts +16 -0
  21. package/dist/bridge/codex-question-reply.js +57 -0
  22. package/dist/bridge/codex-review-mode.d.ts +10 -0
  23. package/dist/bridge/codex-review-mode.js +74 -0
  24. package/dist/bridge/codex-servers.d.ts +217 -0
  25. package/dist/bridge/codex-servers.js +636 -0
  26. package/dist/bridge/command.js +94 -4
  27. package/dist/bridge/computer-identity.d.ts +75 -0
  28. package/dist/bridge/computer-identity.js +166 -0
  29. package/dist/bridge/conductor-group.d.ts +91 -8
  30. package/dist/bridge/conductor-group.js +105 -9
  31. package/dist/bridge/conductor-role.d.ts +94 -0
  32. package/dist/bridge/conductor-role.js +176 -0
  33. package/dist/bridge/conductor-sets.d.ts +20 -0
  34. package/dist/bridge/conductor-sets.js +59 -0
  35. package/dist/bridge/dispatch-command.d.ts +3 -0
  36. package/dist/bridge/dispatch-command.js +75 -11
  37. package/dist/bridge/dispatch-returns.d.ts +123 -19
  38. package/dist/bridge/dispatch-returns.js +357 -50
  39. package/dist/bridge/dispatch.d.ts +103 -2
  40. package/dist/bridge/dispatch.js +272 -40
  41. package/dist/bridge/fanout-messages.js +2 -2
  42. package/dist/bridge/fanouts.d.ts +7 -1
  43. package/dist/bridge/fanouts.js +40 -5
  44. package/dist/bridge/folder-trust.d.ts +56 -0
  45. package/dist/bridge/folder-trust.js +195 -0
  46. package/dist/bridge/grants.d.ts +22 -1
  47. package/dist/bridge/grants.js +57 -9
  48. package/dist/bridge/hand-off.d.ts +21 -9
  49. package/dist/bridge/hand-off.js +58 -45
  50. package/dist/bridge/harness-status.d.ts +11 -0
  51. package/dist/bridge/harness-status.js +32 -0
  52. package/dist/bridge/harnesses.d.ts +39 -0
  53. package/dist/bridge/harnesses.js +65 -0
  54. package/dist/bridge/health.d.ts +2 -0
  55. package/dist/bridge/health.js +1 -1
  56. package/dist/bridge/herdr.d.ts +11 -2
  57. package/dist/bridge/herdr.js +98 -23
  58. package/dist/bridge/hook-fast.d.ts +4 -0
  59. package/dist/bridge/hook-fast.js +68 -0
  60. package/dist/bridge/install.d.ts +16 -1
  61. package/dist/bridge/install.js +88 -21
  62. package/dist/bridge/launch-brief.d.ts +96 -0
  63. package/dist/bridge/launch-brief.js +164 -0
  64. package/dist/bridge/model-switch.d.ts +3 -0
  65. package/dist/bridge/model-switch.js +17 -1
  66. package/dist/bridge/models.d.ts +8 -4
  67. package/dist/bridge/models.js +24 -8
  68. package/dist/bridge/mux-wire.d.ts +9 -0
  69. package/dist/bridge/mux-wire.js +19 -0
  70. package/dist/bridge/opencode-pane-server.d.ts +113 -0
  71. package/dist/bridge/opencode-pane-server.js +332 -0
  72. package/dist/bridge/opencode-panes.d.ts +111 -0
  73. package/dist/bridge/opencode-panes.js +295 -0
  74. package/dist/bridge/pane-accounts.d.ts +8 -0
  75. package/dist/bridge/pane-accounts.js +46 -0
  76. package/dist/bridge/prompt-startup.d.ts +5 -0
  77. package/dist/bridge/prompt-startup.js +24 -0
  78. package/dist/bridge/protocol.d.ts +5 -0
  79. package/dist/bridge/protocol.js +4 -0
  80. package/dist/bridge/push.d.ts +5 -4
  81. package/dist/bridge/push.js +6 -4
  82. package/dist/bridge/questions.d.ts +37 -2
  83. package/dist/bridge/questions.js +158 -15
  84. package/dist/bridge/resources.d.ts +125 -0
  85. package/dist/bridge/resources.js +314 -0
  86. package/dist/bridge/schedule-format.d.ts +2 -0
  87. package/dist/bridge/schedule-format.js +3 -0
  88. package/dist/bridge/schedule-launch.d.ts +2 -1
  89. package/dist/bridge/schedule-launch.js +23 -53
  90. package/dist/bridge/schedule-watch.d.ts +10 -1
  91. package/dist/bridge/schedule-watch.js +54 -2
  92. package/dist/bridge/server-launch.d.ts +22 -5
  93. package/dist/bridge/server-launch.js +225 -29
  94. package/dist/bridge/server-overview.d.ts +8 -2
  95. package/dist/bridge/server-overview.js +26 -5
  96. package/dist/bridge/server-pane-routes.d.ts +2 -0
  97. package/dist/bridge/server-pane-routes.js +145 -15
  98. package/dist/bridge/server-routes.d.ts +11 -1
  99. package/dist/bridge/server-routes.js +195 -36
  100. package/dist/bridge/server-stream.d.ts +2 -0
  101. package/dist/bridge/server-stream.js +22 -8
  102. package/dist/bridge/server.d.ts +6 -1
  103. package/dist/bridge/server.js +47 -12
  104. package/dist/bridge/session-activity.d.ts +81 -0
  105. package/dist/bridge/session-activity.js +117 -0
  106. package/dist/bridge/session-rename.d.ts +48 -0
  107. package/dist/bridge/session-rename.js +190 -0
  108. package/dist/bridge/session-servers.js +2 -2
  109. package/dist/bridge/settings-switch.d.ts +60 -0
  110. package/dist/bridge/settings-switch.js +287 -0
  111. package/dist/bridge/speech-voice.d.ts +55 -0
  112. package/dist/bridge/speech-voice.js +132 -0
  113. package/dist/bridge/speech.d.ts +70 -11
  114. package/dist/bridge/speech.js +169 -41
  115. package/dist/bridge/terminal-herdr.js +9 -3
  116. package/dist/bridge/terminal-tmux.d.ts +3 -3
  117. package/dist/bridge/terminal-tmux.js +24 -9
  118. package/dist/bridge/terminal.d.ts +27 -4
  119. package/dist/bridge/terminal.js +8 -1
  120. package/dist/bridge/transcript-claude.js +62 -12
  121. package/dist/bridge/transcript-codex.d.ts +0 -2
  122. package/dist/bridge/transcript-codex.js +29 -4
  123. package/dist/bridge/transcript-preview.d.ts +1 -0
  124. package/dist/bridge/transcript-preview.js +24 -4
  125. package/dist/bridge/transcripts.d.ts +15 -2
  126. package/dist/bridge/transcripts.js +47 -16
  127. package/dist/bridge/turn-records.d.ts +85 -0
  128. package/dist/bridge/turn-records.js +143 -0
  129. package/dist/bridge/uploads.d.ts +3 -0
  130. package/dist/bridge/uploads.js +14 -0
  131. package/dist/bridge/usage.d.ts +73 -28
  132. package/dist/bridge/usage.js +313 -340
  133. package/dist/bridge-hook.mjs +24624 -18450
  134. package/dist/cli/claude-unmanaged.d.ts +12 -0
  135. package/dist/cli/claude-unmanaged.js +105 -0
  136. package/dist/cli/schedules.js +2 -1
  137. package/dist/cli/session-start.js +10 -1
  138. package/dist/cli/session-stop.js +9 -1
  139. package/dist/cli-registry.d.ts +2 -0
  140. package/dist/cli-registry.js +37 -5
  141. package/dist/computers/command.d.ts +6 -0
  142. package/dist/computers/command.js +152 -0
  143. package/dist/computers/mcp.d.ts +1 -0
  144. package/dist/computers/mcp.js +97 -0
  145. package/dist/computers/read.d.ts +85 -0
  146. package/dist/computers/read.js +177 -0
  147. package/dist/data/task-receipts.d.ts +19 -0
  148. package/dist/data/task-receipts.js +68 -0
  149. package/dist/data/tasks.js +4 -1
  150. package/dist/entrypoint.js +10 -0
  151. package/dist/fanout/adapters/claude.js +15 -2
  152. package/dist/fanout/adapters/types.d.ts +6 -0
  153. package/dist/fanout/launcher.d.ts +5 -1
  154. package/dist/fanout/launcher.js +34 -3
  155. package/dist/fanout/picker.js +3 -2
  156. package/dist/fanout/usage.js +1 -1
  157. package/dist/generated/memory-ui-graph.browser.js +63 -63
  158. package/dist/graph-core/model.js +24 -3
  159. package/dist/graph-core/types.d.ts +4 -1
  160. package/dist/graph-core/types.js +1 -0
  161. package/dist/init/init-preset.js +7 -3
  162. package/dist/init/init-uninstall.js +2 -11
  163. package/dist/init/teardown.d.ts +3 -0
  164. package/dist/init/teardown.js +47 -0
  165. package/dist/link/context.js +21 -9
  166. package/dist/mcp/plugin-mode.js +1 -1
  167. package/dist/memory-ui-graph.runtime.js +63 -63
  168. package/dist/modules/code-package.d.ts +1 -0
  169. package/dist/modules/code-package.js +36 -7
  170. package/dist/modules/registry.js +14 -13
  171. package/dist/profile-store.d.ts +6 -0
  172. package/dist/profile-store.js +25 -1
  173. package/dist/shell/graph/glyphs.js +4 -0
  174. package/dist/shell/graph/graph-view.js +2 -0
  175. package/dist/status.js +7 -1
  176. package/dist/sync/task-claim.js +3 -2
  177. package/dist/task/lifecycle.js +25 -4
  178. package/dist/test-global-setup.js +5 -0
  179. package/dist/tools/dispatch.js +35 -2
  180. package/dist/tools/tasks.js +10 -1
  181. package/package.json +1 -1
  182. package/plugins/opencode/phren-transcript.js +87 -4
  183. package/starter/global/skills/conductor/SKILL.md +17 -2
  184. package/starter/global/skills/fanout/SKILL.md +3 -0
@@ -0,0 +1,16 @@
1
+ export type RequestKind = "command" | "tool" | "edit" | "question" | "other";
2
+ export interface ApprovalRequest {
3
+ tool?: string;
4
+ input?: unknown;
5
+ cwd?: string;
6
+ message?: string;
7
+ question?: boolean;
8
+ }
9
+ export declare function approvalTitle(agent: string, project?: string, computer?: string): string;
10
+ /** Sanitize the whole line before shortening it for the notification. */
11
+ export declare function redactApproval(value: string): string;
12
+ export declare function shortApproval(value: string): string;
13
+ export declare function approvalSummary(value: ApprovalRequest): {
14
+ request: string;
15
+ requestKind: RequestKind;
16
+ };
@@ -0,0 +1,133 @@
1
+ import path from "node:path";
2
+ const fallback = "Open Phren to review the request.";
3
+ const fields = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
4
+ const string = (value) => typeof value === "string" && value.trim() ? value : undefined;
5
+ const oneLine = (value) => value.replace(/\s+/g, " ").trim();
6
+ export function approvalTitle(agent, project, computer) {
7
+ const label = { claude: "Claude", codex: "Codex", opencode: "opencode", copilot: "Copilot" }[agent.toLowerCase()] ?? "Your agent";
8
+ return `${label}${project ? ` · ${project}` : ""}${computer ? ` on ${computer}` : ""}`;
9
+ }
10
+ /** Sanitize the whole line before shortening it for the notification. */
11
+ export function redactApproval(value) {
12
+ return value
13
+ .replace(/\b[A-Za-z][A-Za-z0-9+.-]*:\/\/[^\s'"<>]+/g, raw => {
14
+ try {
15
+ const suffix = /[),.;!?]+$/.exec(raw)?.[0] ?? "";
16
+ const url = new URL(raw.slice(0, raw.length - suffix.length));
17
+ return `${url.protocol}//${url.host}${url.pathname}${suffix}`;
18
+ }
19
+ catch {
20
+ return "…";
21
+ }
22
+ })
23
+ .replace(/\bAuthorization\s*:\s*Bearer\s+(\S+)/gi, (_whole, token) => `Authorization: Bearer …${/["']$/.test(token) ? token.slice(-1) : ""}`)
24
+ .replace(/(^|\s)(--(?:token|password|secret|api-key|access-token))(?:\s+|=)(?:"[^"]*"|'[^']*'|\S+)/gi, "$1$2 …")
25
+ // -p is a password only for MySQL-style clients (-pSECRET); elsewhere it is
26
+ // mkdir -p, ssh -p 22, git log -p, claude -p.
27
+ .replace(/(\b(?:mysql|mysqldump|mysqladmin|mariadb)\b[^\n]*?\s-p)(?:"[^"]*"|'[^']*'|\S+)/gi, "$1…")
28
+ // Environment assignments only: a word after a separator, not a --flag=value.
29
+ .replace(/(^|[\s;&|(])([A-Za-z_][A-Za-z0-9_]*)=(?:"[^"]*"|'[^']*'|[^\s;]+)/g, "$1$2=…")
30
+ .replace(/\b(?:gh[po]_[A-Za-z0-9_]+|github_pat_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]+|xox[abp]-[A-Za-z0-9-]+|AKIA[0-9A-Z]{16}|eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+|[A-Fa-f0-9]{32,}|[A-Za-z0-9_-]{32,})\b/g, "…");
31
+ }
32
+ export function shortApproval(value) {
33
+ const line = oneLine(redactApproval(value));
34
+ if (line.length <= 110)
35
+ return line;
36
+ const prefix = line.slice(0, 109);
37
+ const boundary = prefix.lastIndexOf(" ");
38
+ return (boundary >= 65 ? prefix.slice(0, boundary) : prefix).trimEnd() + "…";
39
+ }
40
+ /** A terminal approval dialog's command: Codex shows `$ <command>`, Claude's
41
+ * dialog a `Bash command` heading over it. */
42
+ function dialogCommand(text) {
43
+ if (!text)
44
+ return undefined;
45
+ return (/^\s*\$ (\S.*)$/m.exec(text) ?? /^\s*Bash command\s*\n+\s*(\S.*)$/m.exec(text))?.[1].trim();
46
+ }
47
+ function commandText(value) {
48
+ if (typeof value === "string") {
49
+ const wrapped = /^(?:\/[^\s]+\/)?(?:ba|z|fi)?sh\s+-[a-z]*c\s+(['"])([\s\S]*)\1$/i.exec(value.trim());
50
+ return wrapped ? wrapped[2] : value;
51
+ }
52
+ if (!Array.isArray(value))
53
+ return undefined;
54
+ const argv = value.filter((part) => typeof part === "string");
55
+ if (!argv.length)
56
+ return undefined;
57
+ const shell = /(?:^|\/)(?:ba|z|fi)?sh$/.test(argv[0]);
58
+ const option = argv.findIndex((part, index) => index > 0 && /^-[a-z]*c$/.test(part));
59
+ return shell && option >= 0 && argv[option + 1] ? argv[option + 1] : argv.join(" ");
60
+ }
61
+ function relativeFile(file, cwd) {
62
+ if (!cwd || !path.isAbsolute(file) || !path.isAbsolute(cwd))
63
+ return file;
64
+ const relative = path.relative(cwd, file);
65
+ return relative && relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative) ? relative.split(path.sep).join("/") : file;
66
+ }
67
+ export function approvalSummary(value) {
68
+ const input = fields(value.input), tool = value.tool ?? "";
69
+ let line, requestKind = "other";
70
+ if (value.question || /^AskUserQuestion$/i.test(tool)) {
71
+ const questions = Array.isArray(input.questions) ? input.questions : [];
72
+ line = string(fields(questions[0]).question) ?? string(input.question) ?? string(input.message) ?? value.message;
73
+ if (line)
74
+ requestKind = "question";
75
+ }
76
+ else {
77
+ const messageCommand = /^(?:bash|shell):\s*(.+)$/is.exec(value.message ?? "")?.[1];
78
+ // A terminal dialog read from the pane arrives as tool "Question".
79
+ const shown = tool === "Question" ? dialogCommand(value.message) : undefined;
80
+ const command = commandText(input.command ?? input.cmd ?? input.commandLine ?? (Array.isArray(value.input) ? value.input : undefined)) ?? messageCommand ?? shown;
81
+ if (command && (shown !== undefined || /^(?:Bash|Shell|exec_command|functions\.shell|bash|shell)$/i.test(tool) || input.command !== undefined || input.cmd !== undefined || input.commandLine !== undefined)) {
82
+ line = `Run: ${command}`;
83
+ requestKind = "command";
84
+ }
85
+ else {
86
+ const mcp = /^mcp__(.+?)__(.+)$/.exec(tool);
87
+ const sentence = /Allow the ([\w.-]+) MCP server to run tool ([\w.-]+)\?/i.exec(value.message ?? string(input.description) ?? "");
88
+ const server = mcp?.[1] ?? string(input.serverName) ?? string(input.server_name) ?? string(input.mcpServerName)
89
+ ?? string(input.server) ?? sentence?.[1];
90
+ const name = mcp?.[2] ?? string(input.toolName) ?? string(input.tool_name) ?? string(input.mcpToolName)
91
+ ?? string(input.tool) ?? sentence?.[2];
92
+ if (server && name) {
93
+ line = `${server} MCP: ${name}`;
94
+ requestKind = "tool";
95
+ }
96
+ else {
97
+ const patch = string(input.patch) ?? (typeof value.input === "string" ? value.input : undefined);
98
+ const changed = patch ? new Set([...patch.matchAll(/^\*\*\* (?:Add|Update|Delete) File: (.+)$|^diff --git a\/(.+?) b\/(.+)$/gm)]
99
+ .map(match => match[1] ?? match[3])).size : 0;
100
+ const file = string(input.file_path) ?? string(input.filePath) ?? string(input.path);
101
+ if (changed > 1)
102
+ line = `Apply patch: ${changed} files`;
103
+ else if (file && /(?:edit|write|patch|apply)/i.test(tool))
104
+ line = `${/write/i.test(tool) || /\*\*\* Add File:/.test(patch ?? "") ? "Write" : "Edit"}: ${relativeFile(file, value.cwd)}`;
105
+ else if (changed === 1 && patch) {
106
+ const match = /^\*\*\* (Add|Update|Delete) File: (.+)$/m.exec(patch);
107
+ line = match ? `${match[1] === "Add" ? "Write" : "Edit"}: ${relativeFile(match[2], value.cwd)}` : "Apply patch: 1 file";
108
+ }
109
+ if (line)
110
+ requestKind = "edit";
111
+ else {
112
+ const primary = string(input.path) ?? string(input.file_path) ?? string(input.pattern) ?? string(input.query)
113
+ ?? string(input.description) ?? string(input.question) ?? string(input.message) ?? value.message;
114
+ if (primary && tool === "Question") {
115
+ line = primary;
116
+ requestKind = "question";
117
+ }
118
+ else if (primary) {
119
+ const argument = tool && primary.toLowerCase().startsWith(`${tool.toLowerCase()}:`) ? primary.slice(tool.length + 1).trimStart() : primary;
120
+ line = `${tool && tool !== "action" ? tool : "Request"}: ${argument}`;
121
+ requestKind = "tool";
122
+ }
123
+ else if (tool && tool !== "action") {
124
+ line = tool;
125
+ requestKind = "tool";
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ const request = line ? shortApproval(line) : fallback;
132
+ return { request: request || fallback, requestKind: line ? requestKind : "other" };
133
+ }
@@ -0,0 +1,20 @@
1
+ import { type ProjectEntry } from "./authority.js";
2
+ /** The harness whose shell this is, when an agent runs the command. */
3
+ export declare function agentShell(env?: NodeJS.ProcessEnv): string | undefined;
4
+ export interface OwnerTerminal {
5
+ env: NodeJS.ProcessEnv;
6
+ interactive: boolean;
7
+ ask: (question: string) => Promise<string>;
8
+ }
9
+ /** Changes are the owner's: refused in an agent's shell or without a
10
+ * terminal, and made only after the owner types the project name. */
11
+ export declare function ownerConfirms(change: string, project: string, terminal: OwnerTerminal): Promise<void>;
12
+ /** The entry `set` saves: the current one with the flags applied. */
13
+ export declare function mergedEntry(current: ProjectEntry | undefined, values: {
14
+ default?: string;
15
+ go?: string;
16
+ ask?: string;
17
+ "max-permission-mode"?: string;
18
+ note?: string;
19
+ }): ProjectEntry;
20
+ export declare function runAuthority(args: string[], terminal?: OwnerTerminal): Promise<number>;
@@ -0,0 +1,120 @@
1
+ import { createInterface } from "node:readline/promises";
2
+ import { parseArgs } from "node:util";
3
+ import { clearProjectAuthority, confirmAuthority, confirmInputSchema, listConfirmations, projectAuthority, projectEntrySchema, readAuthority, releaseAction, setProjectAuthority, } from "./authority.js";
4
+ const USAGE = [
5
+ "Usage: phren authority [list]",
6
+ " phren authority show <project>",
7
+ " phren authority set <project> [--default go|ask] [--go <actions>] [--ask <actions>] [--max-permission-mode <mode>|none] [--note <text>]",
8
+ " phren authority clear <project>",
9
+ " phren authority confirm <project> <actions> [--minutes <n>]",
10
+ "Actions: merge, publish, deploy, app-store, github-admin (comma-separated).",
11
+ ].join("\n");
12
+ /** The harness whose shell this is, when an agent runs the command. */
13
+ export function agentShell(env = process.env) {
14
+ if (env.CLAUDECODE === "1" || env.CLAUDE_CODE_SESSION_ID)
15
+ return "Claude Code";
16
+ if (env.CODEX_THREAD_ID || env.CODEX_SESSION_ID)
17
+ return "Codex";
18
+ if (env.PHREN_FANOUT_JOB || env.PHREN_FANOUT_DIR)
19
+ return "a phren fan-out worker";
20
+ return undefined;
21
+ }
22
+ function processTerminal() {
23
+ return {
24
+ env: process.env,
25
+ interactive: !!process.stdin.isTTY && !!process.stdout.isTTY,
26
+ ask: async (question) => {
27
+ const lines = createInterface({ input: process.stdin, output: process.stderr });
28
+ try {
29
+ return await lines.question(question);
30
+ }
31
+ finally {
32
+ lines.close();
33
+ }
34
+ },
35
+ };
36
+ }
37
+ /** Changes are the owner's: refused in an agent's shell or without a
38
+ * terminal, and made only after the owner types the project name. */
39
+ export async function ownerConfirms(change, project, terminal) {
40
+ const agent = agentShell(terminal.env);
41
+ if (agent)
42
+ throw new Error(`The release authority policy is the owner's. ${agent} can read it (phren authority show ${project}) but not change it; ask the owner to run this in their own terminal or use the phone.`);
43
+ if (!terminal.interactive)
44
+ throw new Error("Changing the release authority policy needs an interactive terminal: the owner types the project name to confirm.");
45
+ const typed = await terminal.ask(`${change}\nType ${project} to confirm: `);
46
+ if (typed.trim() !== project)
47
+ throw new Error("Not confirmed; nothing changed.");
48
+ }
49
+ function actionList(value) {
50
+ if (value === undefined)
51
+ return [];
52
+ return value.split(",").map(item => item.trim()).filter(Boolean).map(item => releaseAction.parse(item));
53
+ }
54
+ /** The entry `set` saves: the current one with the flags applied. */
55
+ export function mergedEntry(current, values) {
56
+ const entry = { ...current, ...(current?.actions ? { actions: { ...current.actions } } : {}) };
57
+ if (values.default !== undefined)
58
+ entry.default = values.default;
59
+ const go = actionList(values.go), ask = actionList(values.ask);
60
+ const overlap = go.filter(action => ask.includes(action));
61
+ if (overlap.length)
62
+ throw new Error(`${overlap.join(", ")} cannot be both go and ask.`);
63
+ if (go.length || ask.length)
64
+ entry.actions = { ...entry.actions, ...Object.fromEntries([...go.map(a => [a, "go"]), ...ask.map(a => [a, "ask"])]) };
65
+ const mode = values["max-permission-mode"];
66
+ if (mode === "none")
67
+ delete entry.maxPermissionMode;
68
+ else if (mode !== undefined)
69
+ entry.maxPermissionMode = mode;
70
+ if (values.note === "")
71
+ delete entry.note;
72
+ else if (values.note !== undefined)
73
+ entry.note = values.note;
74
+ return entry;
75
+ }
76
+ export async function runAuthority(args, terminal = processTerminal()) {
77
+ const [action = "list", ...rest] = args;
78
+ const print = (value) => console.log(JSON.stringify(value, null, 2));
79
+ if (action === "list" && !rest.length) {
80
+ const policy = await readAuthority();
81
+ print({ source: policy.source, ...(policy.updatedAt ? { updatedAt: policy.updatedAt, updatedBy: policy.updatedBy } : {}),
82
+ projects: Object.keys(policy.projects).sort().map(name => projectAuthority(policy, name)), confirmations: await listConfirmations() });
83
+ return 0;
84
+ }
85
+ if (action === "show" && rest.length === 1) {
86
+ print(projectAuthority(await readAuthority(), rest[0]));
87
+ return 0;
88
+ }
89
+ if (action === "set") {
90
+ const { values, positionals } = parseArgs({ args: rest, allowPositionals: true, options: {
91
+ default: { type: "string" }, go: { type: "string" }, ask: { type: "string" }, "max-permission-mode": { type: "string" }, note: { type: "string" },
92
+ } });
93
+ if (positionals.length !== 1)
94
+ throw new Error(USAGE);
95
+ const project = positionals[0];
96
+ const entry = projectEntrySchema.parse(mergedEntry((await readAuthority()).projects[project], values));
97
+ // Validated before the owner is asked, so a typo never waits on a confirmation.
98
+ const preview = projectAuthority({ projects: { [project]: entry } }, project);
99
+ await ownerConfirms(`New policy: ${preview.line}`, project, terminal);
100
+ print(await setProjectAuthority({ project, ...entry }, "cli"));
101
+ return 0;
102
+ }
103
+ if (action === "clear" && rest.length === 1) {
104
+ await ownerConfirms(`Remove ${rest[0]} from the release authority policy (it becomes go for every release action).`, rest[0], terminal);
105
+ print(await clearProjectAuthority({ project: rest[0] }, "cli"));
106
+ return 0;
107
+ }
108
+ if (action === "confirm") {
109
+ const { values, positionals } = parseArgs({ args: rest, allowPositionals: true, options: { minutes: { type: "string" } } });
110
+ if (positionals.length !== 2)
111
+ throw new Error(USAGE);
112
+ const [project, actions] = positionals;
113
+ const minutes = values.minutes !== undefined ? Number(values.minutes) : undefined;
114
+ const input = confirmInputSchema.parse({ project, actions: actionList(actions), ...(minutes !== undefined ? { minutes } : {}) });
115
+ await ownerConfirms(`Let one agent dispatch to ${project} do ${input.actions.join(", ")} within ${minutes ?? 30} minutes.`, project, terminal);
116
+ print(await confirmAuthority(input, "cli"));
117
+ return 0;
118
+ }
119
+ throw new Error(USAGE);
120
+ }
@@ -0,0 +1,223 @@
1
+ import { z } from "zod";
2
+ import { type PermissionMode } from "./protocol.js";
3
+ /**
4
+ * The owner's release authority policy: per project, which release-type
5
+ * actions a conductor may send a worker to do on its own (`go`) and which need
6
+ * the owner's word each time (`ask`). It only restricts: nothing here lifts a
7
+ * worker's own permission checks. See docs/authority.md.
8
+ */
9
+ export declare const RELEASE_ACTIONS: readonly ["merge", "publish", "deploy", "app-store", "github-admin"];
10
+ export type ReleaseAction = typeof RELEASE_ACTIONS[number];
11
+ export declare const releaseAction: z.ZodEnum<{
12
+ "app-store": "app-store";
13
+ deploy: "deploy";
14
+ "github-admin": "github-admin";
15
+ merge: "merge";
16
+ publish: "publish";
17
+ }>;
18
+ declare const writer: z.ZodEnum<{
19
+ cli: "cli";
20
+ phone: "phone";
21
+ }>;
22
+ export type AuthorityWriter = z.infer<typeof writer>;
23
+ export declare const projectEntrySchema: z.ZodObject<{
24
+ default: z.ZodOptional<z.ZodEnum<{
25
+ ask: "ask";
26
+ go: "go";
27
+ }>>;
28
+ actions: z.ZodOptional<z.ZodObject<{
29
+ merge: z.ZodOptional<z.ZodEnum<{
30
+ ask: "ask";
31
+ go: "go";
32
+ }>>;
33
+ publish: z.ZodOptional<z.ZodEnum<{
34
+ ask: "ask";
35
+ go: "go";
36
+ }>>;
37
+ deploy: z.ZodOptional<z.ZodEnum<{
38
+ ask: "ask";
39
+ go: "go";
40
+ }>>;
41
+ "app-store": z.ZodOptional<z.ZodEnum<{
42
+ ask: "ask";
43
+ go: "go";
44
+ }>>;
45
+ "github-admin": z.ZodOptional<z.ZodEnum<{
46
+ ask: "ask";
47
+ go: "go";
48
+ }>>;
49
+ }, z.core.$strict>>;
50
+ maxPermissionMode: z.ZodOptional<z.ZodEnum<{
51
+ auto: "auto";
52
+ "auto-edits": "auto-edits";
53
+ "full-access": "full-access";
54
+ supervised: "supervised";
55
+ }>>;
56
+ note: z.ZodOptional<z.ZodString>;
57
+ }, z.core.$strict>;
58
+ export type ProjectEntry = z.infer<typeof projectEntrySchema>;
59
+ declare const fileSchema: z.ZodObject<{
60
+ projects: z.ZodRecord<z.ZodString, z.ZodObject<{
61
+ default: z.ZodOptional<z.ZodEnum<{
62
+ ask: "ask";
63
+ go: "go";
64
+ }>>;
65
+ actions: z.ZodOptional<z.ZodObject<{
66
+ merge: z.ZodOptional<z.ZodEnum<{
67
+ ask: "ask";
68
+ go: "go";
69
+ }>>;
70
+ publish: z.ZodOptional<z.ZodEnum<{
71
+ ask: "ask";
72
+ go: "go";
73
+ }>>;
74
+ deploy: z.ZodOptional<z.ZodEnum<{
75
+ ask: "ask";
76
+ go: "go";
77
+ }>>;
78
+ "app-store": z.ZodOptional<z.ZodEnum<{
79
+ ask: "ask";
80
+ go: "go";
81
+ }>>;
82
+ "github-admin": z.ZodOptional<z.ZodEnum<{
83
+ ask: "ask";
84
+ go: "go";
85
+ }>>;
86
+ }, z.core.$strict>>;
87
+ maxPermissionMode: z.ZodOptional<z.ZodEnum<{
88
+ auto: "auto";
89
+ "auto-edits": "auto-edits";
90
+ "full-access": "full-access";
91
+ supervised: "supervised";
92
+ }>>;
93
+ note: z.ZodOptional<z.ZodString>;
94
+ }, z.core.$strict>>;
95
+ updatedAt: z.ZodOptional<z.ZodString>;
96
+ updatedBy: z.ZodOptional<z.ZodEnum<{
97
+ cli: "cli";
98
+ phone: "phone";
99
+ }>>;
100
+ }, z.core.$strict>;
101
+ export type AuthorityFile = z.infer<typeof fileSchema>;
102
+ /** Used until the owner first writes the policy: hub and safety are ask-first,
103
+ * and Mina is go for App Store work (the owner's word, 2026-09-29). */
104
+ export declare const DEFAULT_AUTHORITY: AuthorityFile;
105
+ /** The permission ceiling of a project with any ask-first action that names none. */
106
+ export declare const ASK_FIRST_PERMISSION_MODE: PermissionMode;
107
+ export interface AuthorityPolicy extends AuthorityFile {
108
+ source: "file" | "defaults";
109
+ }
110
+ /** The saved policy, or the built-in defaults when the owner has written none.
111
+ * A file that is not private or does not parse is an error, never "no policy". */
112
+ export declare function readAuthority(root?: string): Promise<AuthorityPolicy>;
113
+ export interface ProjectAuthority {
114
+ project: string;
115
+ /** The policy names this project; an unlisted one is go for everything. */
116
+ listed: boolean;
117
+ go: ReleaseAction[];
118
+ ask: ReleaseAction[];
119
+ maxPermissionMode?: PermissionMode;
120
+ note?: string;
121
+ /** One sentence a conductor quotes in a brief. */
122
+ line: string;
123
+ }
124
+ export declare function projectAuthority(policy: Pick<AuthorityFile, "projects">, project: string): ProjectAuthority;
125
+ /** The lower of two permission ceilings; undefined is no ceiling. */
126
+ export declare function lowerMode(a: PermissionMode | undefined, b: PermissionMode | undefined): PermissionMode | undefined;
127
+ export declare const setAuthoritySchema: z.ZodObject<{
128
+ default: z.ZodOptional<z.ZodEnum<{
129
+ ask: "ask";
130
+ go: "go";
131
+ }>>;
132
+ actions: z.ZodOptional<z.ZodObject<{
133
+ merge: z.ZodOptional<z.ZodEnum<{
134
+ ask: "ask";
135
+ go: "go";
136
+ }>>;
137
+ publish: z.ZodOptional<z.ZodEnum<{
138
+ ask: "ask";
139
+ go: "go";
140
+ }>>;
141
+ deploy: z.ZodOptional<z.ZodEnum<{
142
+ ask: "ask";
143
+ go: "go";
144
+ }>>;
145
+ "app-store": z.ZodOptional<z.ZodEnum<{
146
+ ask: "ask";
147
+ go: "go";
148
+ }>>;
149
+ "github-admin": z.ZodOptional<z.ZodEnum<{
150
+ ask: "ask";
151
+ go: "go";
152
+ }>>;
153
+ }, z.core.$strict>>;
154
+ maxPermissionMode: z.ZodOptional<z.ZodEnum<{
155
+ auto: "auto";
156
+ "auto-edits": "auto-edits";
157
+ "full-access": "full-access";
158
+ supervised: "supervised";
159
+ }>>;
160
+ note: z.ZodOptional<z.ZodString>;
161
+ project: z.ZodString;
162
+ }, z.core.$strict>;
163
+ /** Replace one project's entry. The first write saves the defaults with it. */
164
+ export declare function setProjectAuthority(input: unknown, by: AuthorityWriter, root?: string): Promise<ProjectAuthority>;
165
+ /** Drop one project's entry, which makes it go for everything. */
166
+ export declare function clearProjectAuthority(input: unknown, by: AuthorityWriter, root?: string): Promise<ProjectAuthority>;
167
+ declare const confirmationSchema: z.ZodObject<{
168
+ id: z.ZodString;
169
+ project: z.ZodString;
170
+ actions: z.ZodArray<z.ZodEnum<{
171
+ "app-store": "app-store";
172
+ deploy: "deploy";
173
+ "github-admin": "github-admin";
174
+ merge: "merge";
175
+ publish: "publish";
176
+ }>>;
177
+ confirmedAt: z.ZodString;
178
+ expiresAt: z.ZodString;
179
+ by: z.ZodEnum<{
180
+ cli: "cli";
181
+ phone: "phone";
182
+ }>;
183
+ }, z.core.$strict>;
184
+ export type Confirmation = z.infer<typeof confirmationSchema>;
185
+ export declare const confirmInputSchema: z.ZodObject<{
186
+ project: z.ZodString;
187
+ actions: z.ZodArray<z.ZodEnum<{
188
+ "app-store": "app-store";
189
+ deploy: "deploy";
190
+ "github-admin": "github-admin";
191
+ merge: "merge";
192
+ publish: "publish";
193
+ }>>;
194
+ minutes: z.ZodOptional<z.ZodNumber>;
195
+ }, z.core.$strict>;
196
+ export declare const DEFAULT_CONFIRMATION_MINUTES = 30;
197
+ /** Confirmations still waiting to be used. */
198
+ export declare function listConfirmations(root?: string): Promise<Confirmation[]>;
199
+ /** The owner's word for one agent dispatch of these release actions to this project. */
200
+ export declare function confirmAuthority(input: unknown, by: AuthorityWriter, root?: string): Promise<Confirmation>;
201
+ /** Use up the oldest confirmation that covers every one of `actions` for
202
+ * `project`, or return undefined when none does. */
203
+ export declare function consumeConfirmation(project: string, actions: readonly ReleaseAction[], root?: string): Promise<Confirmation | undefined>;
204
+ export interface AuthorityCheck {
205
+ /** The permission mode the worker should start in, when the policy sets one the call did not. */
206
+ permissionMode?: PermissionMode;
207
+ authority: ProjectAuthority;
208
+ confirmation?: Confirmation;
209
+ }
210
+ /**
211
+ * What the policy asks of an agent's dispatch: refuse a mode above the
212
+ * project's ceiling (lowered further by `grantCeiling`), start one that named
213
+ * no mode at that ceiling, and refuse an ask-first release action the owner
214
+ * has not confirmed. Only an agent's call is checked; the owner's never is.
215
+ * The confirmation is used up only when everything else passed.
216
+ */
217
+ export declare function checkAgentDispatch(data: {
218
+ project: string;
219
+ harness: string;
220
+ permissionMode?: PermissionMode;
221
+ releaseActions?: readonly ReleaseAction[];
222
+ }, grantCeiling: PermissionMode, root?: string): Promise<AuthorityCheck>;
223
+ export {};