@phren/cli 0.3.36 → 0.3.39
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/dist/bridge/account-choice.d.ts +82 -0
- package/dist/bridge/account-choice.js +173 -0
- package/dist/bridge/account-failover.d.ts +61 -0
- package/dist/bridge/account-failover.js +189 -0
- package/dist/bridge/account-usage.d.ts +7 -2
- package/dist/bridge/account-usage.js +53 -8
- package/dist/bridge/agent-hooks.js +2 -0
- package/dist/bridge/changes.d.ts +5 -0
- package/dist/bridge/changes.js +4 -0
- package/dist/bridge/claude-accounts.d.ts +15 -4
- package/dist/bridge/claude-accounts.js +31 -16
- package/dist/bridge/claude-credits.d.ts +43 -0
- package/dist/bridge/claude-credits.js +236 -0
- package/dist/bridge/claude-question-dialog.js +6 -2
- package/dist/bridge/command.js +64 -3
- package/dist/bridge/device-enroll.d.ts +34 -0
- package/dist/bridge/device-enroll.js +57 -0
- package/dist/bridge/dispatch-command.d.ts +2 -0
- package/dist/bridge/dispatch-command.js +25 -1
- package/dist/bridge/dispatch-returns.d.ts +19 -0
- package/dist/bridge/dispatch-returns.js +93 -12
- package/dist/bridge/dispatch.d.ts +83 -3
- package/dist/bridge/dispatch.js +82 -10
- package/dist/bridge/file-range.d.ts +3 -0
- package/dist/bridge/file-range.js +5 -4
- package/dist/bridge/file-search.d.ts +37 -0
- package/dist/bridge/file-search.js +87 -0
- package/dist/bridge/file-write.d.ts +6 -0
- package/dist/bridge/file-write.js +120 -0
- package/dist/bridge/git-host-auth.d.ts +31 -0
- package/dist/bridge/git-host-auth.js +110 -0
- package/dist/bridge/git-host-gitboy.d.ts +46 -0
- package/dist/bridge/git-host-gitboy.js +296 -0
- package/dist/bridge/git-host-gitlab.d.ts +25 -0
- package/dist/bridge/git-host-gitlab.js +229 -0
- package/dist/bridge/git-host-http.d.ts +33 -0
- package/dist/bridge/git-host-http.js +70 -0
- package/dist/bridge/git-hosts.d.ts +92 -0
- package/dist/bridge/git-hosts.js +244 -0
- package/dist/bridge/git-publish.d.ts +15 -5
- package/dist/bridge/git-publish.js +69 -21
- package/dist/bridge/git-review.d.ts +23 -0
- package/dist/bridge/git-review.js +170 -0
- package/dist/bridge/git-sync.d.ts +14 -0
- package/dist/bridge/git-sync.js +143 -0
- package/dist/bridge/git.d.ts +20 -7
- package/dist/bridge/git.js +87 -68
- package/dist/bridge/gitboy-contract.d.ts +32 -0
- package/dist/bridge/gitboy-contract.js +46 -0
- package/dist/bridge/hand-off.d.ts +75 -3
- package/dist/bridge/hand-off.js +113 -27
- package/dist/bridge/health.d.ts +1 -1
- package/dist/bridge/health.js +5 -3
- package/dist/bridge/install.d.ts +14 -0
- package/dist/bridge/install.js +40 -1
- package/dist/bridge/launch-brief.d.ts +3 -0
- package/dist/bridge/launch-brief.js +16 -0
- package/dist/bridge/memory-store.d.ts +8 -0
- package/dist/bridge/memory-store.js +80 -2
- package/dist/bridge/pair.d.ts +6 -1
- package/dist/bridge/pair.js +74 -2
- package/dist/bridge/peers.js +4 -2
- package/dist/bridge/project-memory.d.ts +94 -0
- package/dist/bridge/project-memory.js +235 -0
- package/dist/bridge/push.d.ts +15 -0
- package/dist/bridge/push.js +39 -0
- package/dist/bridge/schedule-launch.js +5 -1
- package/dist/bridge/schedule-watch.d.ts +3 -0
- package/dist/bridge/schedule-watch.js +27 -1
- package/dist/bridge/scoped-gateway.d.ts +29 -0
- package/dist/bridge/scoped-gateway.js +239 -0
- package/dist/bridge/server-launch.d.ts +12 -0
- package/dist/bridge/server-launch.js +23 -12
- package/dist/bridge/server-pane-routes.js +54 -3
- package/dist/bridge/server-routes.d.ts +12 -0
- package/dist/bridge/server-routes.js +64 -5
- package/dist/bridge/server.js +50 -5
- package/dist/bridge/session-move.d.ts +288 -0
- package/dist/bridge/session-move.js +600 -0
- package/dist/bridge/subscription.d.ts +15 -0
- package/dist/bridge/subscription.js +23 -0
- package/dist/bridge/transport.js +21 -1
- package/dist/bridge/usage.d.ts +23 -4
- package/dist/bridge/usage.js +63 -11
- package/dist/bridge-hook.mjs +23280 -13252
- package/dist/cli/config.js +28 -2
- package/dist/cli-registry.js +10 -4
- package/dist/computers/command.js +3 -1
- package/dist/computers/read.d.ts +3 -0
- package/dist/computers/read.js +6 -0
- package/dist/content/summarize.d.ts +21 -0
- package/dist/content/summarize.js +56 -18
- package/dist/init/preferences.d.ts +6 -0
- package/dist/modules/registry.js +13 -13
- package/dist/project-config.d.ts +12 -0
- package/dist/project-config.js +29 -0
- package/dist/shared/retrieval.d.ts +1 -0
- package/dist/shared/retrieval.js +1 -1
- package/dist/sync/conflict-resolve.js +5 -6
- package/dist/tools/dispatch.js +20 -3
- package/dist/tools/finding.d.ts +25 -0
- package/dist/tools/finding.js +2 -1
- package/package.json +57 -1
package/dist/bridge/hand-off.js
CHANGED
|
@@ -4,12 +4,14 @@ import { terminalPaneFromEnv } from "./terminal.js";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { computerName } from "./computers.js";
|
|
6
6
|
import { hookRequest } from "./client.js";
|
|
7
|
-
import { projectName } from "./dispatch.js";
|
|
7
|
+
import { moveToSchema, projectName } from "./dispatch.js";
|
|
8
8
|
import { paneProject } from "./approval-summary.js";
|
|
9
9
|
import { isAccountSlug } from "./claude-accounts.js";
|
|
10
|
+
import { accountWindows } from "./account-choice.js";
|
|
11
|
+
import { resetsIn } from "../computers/read.js";
|
|
10
12
|
import { grantLabel, findGrant } from "./grants.js";
|
|
11
13
|
import { hookPeers, optionalHookPeers, peerRequest } from "./peers.js";
|
|
12
|
-
import { BridgeError, errorCode, object, objects, sessionId, targetSchema } from "./protocol.js";
|
|
14
|
+
import { BridgeError, errorCode, id, object, objects, sessionId, targetSchema } from "./protocol.js";
|
|
13
15
|
import { findPhrenPath } from "../phren-paths.js";
|
|
14
16
|
import { listMachines } from "../profile-store.js";
|
|
15
17
|
import { localNames } from "./computer-names.js";
|
|
@@ -61,30 +63,27 @@ async function targetFromOverview(request, session, server, account) {
|
|
|
61
63
|
}
|
|
62
64
|
/** A stable delivery id names a message on the receiving Hook. The Hook
|
|
63
65
|
* queues busy targets and retains outcomes across restarts. */
|
|
66
|
+
/** The Hook of `computer` (this one when undefined): its request function, and its peer when it is another computer. */
|
|
67
|
+
async function hookFor(computer) {
|
|
68
|
+
if (computer === undefined)
|
|
69
|
+
return { request: (route, body) => hookRequest(route, body) };
|
|
70
|
+
// No hooks.yaml only matters when the name turns out to be another computer.
|
|
71
|
+
let peersError;
|
|
72
|
+
const peers = await hookPeers().catch(error => { peersError = error; return []; });
|
|
73
|
+
// An alias or hostname (`Mac`, `Desk.local`) names the same computer as its hooks.yaml name.
|
|
74
|
+
const named = peers.some(candidate => candidate.name === computer) ? undefined : await linkedComputer(computer).catch(() => undefined);
|
|
75
|
+
if (named && "local" in named)
|
|
76
|
+
return { request: (route, body) => hookRequest(route, body) };
|
|
77
|
+
if (peersError)
|
|
78
|
+
throw peersError;
|
|
79
|
+
const found = peers.find(candidate => candidate.name === (named && "peer" in named ? named.peer : computer));
|
|
80
|
+
if (!found)
|
|
81
|
+
throw new BridgeError(404, "Unknown computer. Add its verified connection to hooks.yaml.");
|
|
82
|
+
return { peer: found, request: (route, body) => peerRequest(found, route, body) };
|
|
83
|
+
}
|
|
64
84
|
export async function handOff(input, options = {}) {
|
|
65
85
|
const data = handOffSchema.parse(input);
|
|
66
|
-
|
|
67
|
-
let peer;
|
|
68
|
-
if (data.computer === undefined)
|
|
69
|
-
request = (route, body) => hookRequest(route, body);
|
|
70
|
-
else {
|
|
71
|
-
// No hooks.yaml only matters when the name turns out to be another computer.
|
|
72
|
-
let peersError;
|
|
73
|
-
const peers = await hookPeers().catch(error => { peersError = error; return []; });
|
|
74
|
-
// An alias or hostname (`Mac`, `Desk.local`) names the same computer as its hooks.yaml name.
|
|
75
|
-
const named = peers.some(candidate => candidate.name === data.computer) ? undefined : await linkedComputer(data.computer).catch(() => undefined);
|
|
76
|
-
if (named && "local" in named)
|
|
77
|
-
request = (route, body) => hookRequest(route, body);
|
|
78
|
-
else {
|
|
79
|
-
if (peersError)
|
|
80
|
-
throw peersError;
|
|
81
|
-
const found = peers.find(candidate => candidate.name === (named && "peer" in named ? named.peer : data.computer));
|
|
82
|
-
if (!found)
|
|
83
|
-
throw new BridgeError(404, "Unknown computer. Add its verified connection to hooks.yaml.");
|
|
84
|
-
peer = found;
|
|
85
|
-
request = (route, body) => peerRequest(found, route, body);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
86
|
+
const { request, peer } = await hookFor(data.computer);
|
|
88
87
|
const resolved = data.target ? undefined : await targetFromOverview(request, data.session, peer?.server, data.account);
|
|
89
88
|
const target = data.target ?? resolved.target;
|
|
90
89
|
if (peer && target.server !== peer.server)
|
|
@@ -117,6 +116,79 @@ export async function handOff(input, options = {}) {
|
|
|
117
116
|
...(result.unsubmitted === true ? { unsubmitted: true } : {}),
|
|
118
117
|
...(label ? { label } : {}), ...(grant ? { granted: grantLabel(grant) } : {}) };
|
|
119
118
|
}
|
|
119
|
+
export const moveSessionSchema = z.object({
|
|
120
|
+
computer: computerName.optional().describe("Enrolled computer the session runs on. Omit for this computer."),
|
|
121
|
+
target: targetSchema.optional().describe("Complete live target of the session to move."),
|
|
122
|
+
session: sessionId.optional().describe("Session id to resolve through the Hook workspace overview."),
|
|
123
|
+
pane: id.optional().describe("Pane id (as Herdr or tmux shows it, e.g. wC9:p1) of the session to move, resolved through the Hook workspace overview."),
|
|
124
|
+
harness: moveToSchema.shape.harness,
|
|
125
|
+
account: moveToSchema.shape.account,
|
|
126
|
+
model: moveToSchema.shape.model,
|
|
127
|
+
effort: moveToSchema.shape.effort,
|
|
128
|
+
id: z.string().uuid().optional().describe("Move id: keep it on a retry, or pass it with status:true to read where the move is."),
|
|
129
|
+
status: z.boolean().optional().describe("Read the move's state without starting one; requires id."),
|
|
130
|
+
wait: z.boolean().optional().describe("Wait (up to five minutes) until the move finished or failed. Defaults to true."),
|
|
131
|
+
}).strict().superRefine((value, context) => {
|
|
132
|
+
if (!value.status && [value.target, value.session, value.pane].filter(item => item !== undefined).length !== 1)
|
|
133
|
+
context.addIssue({ code: "custom", message: "Provide exactly one of target, session or pane." });
|
|
134
|
+
if (value.status && !value.id)
|
|
135
|
+
context.addIssue({ code: "custom", message: "A status query requires id." });
|
|
136
|
+
});
|
|
137
|
+
const MOVE_WAIT_MS = 5 * 60_000;
|
|
138
|
+
/** The live session in a pane, by the pane id the terminal shows. */
|
|
139
|
+
async function paneTarget(request, pane, server) {
|
|
140
|
+
const found = await findInOverview(request, target => target.pane === pane, server);
|
|
141
|
+
if (!found)
|
|
142
|
+
throw new BridgeError(404, "No live session in that pane appears in the workspace overview.");
|
|
143
|
+
return found.target;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Moves a live session to another harness on its own computer (session-move.ts):
|
|
147
|
+
* the agent writes a hand-off and exits, and the new agent starts in its pane
|
|
148
|
+
* with it. Answers with the move record; a dispatched worker's receipt follows
|
|
149
|
+
* the move on its next poll.
|
|
150
|
+
*/
|
|
151
|
+
export async function moveSession(input, options = {}) {
|
|
152
|
+
const data = moveSessionSchema.parse(input);
|
|
153
|
+
const { request, peer } = await hookFor(data.computer);
|
|
154
|
+
const read = async (id) => object((await request(`/v1/sessions/move?id=${encodeURIComponent(id)}`)).move);
|
|
155
|
+
const settled = (move) => move.state === "moved" || move.state === "failed";
|
|
156
|
+
let move;
|
|
157
|
+
if (data.status)
|
|
158
|
+
move = await read(data.id);
|
|
159
|
+
else {
|
|
160
|
+
const target = data.target ?? (data.session ? (await targetFromOverview(request, data.session, peer?.server)).target : await paneTarget(request, data.pane, peer?.server));
|
|
161
|
+
if (peer && target.server !== peer.server)
|
|
162
|
+
throw new BridgeError(400, "The target belongs to a different Herdr server on that computer.");
|
|
163
|
+
const to = { harness: data.harness, ...(data.account ? { account: data.account } : {}), ...(data.model ? { model: data.model } : {}), ...(data.effort ? { effort: data.effort } : {}) };
|
|
164
|
+
move = object((await request("/v1/sessions/move", { target, to: moveToSchema.parse(to), ...(data.id ? { id: data.id } : {}) })).move);
|
|
165
|
+
if (data.wait !== false && typeof move.id === "string") {
|
|
166
|
+
const until = Date.now() + (options.waitMs ?? MOVE_WAIT_MS);
|
|
167
|
+
while (!settled(move) && Date.now() < until) {
|
|
168
|
+
await new Promise(resolve => setTimeout(resolve, options.pollMs ?? 3_000));
|
|
169
|
+
move = await read(String(move.id)).catch(() => move);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { ok: move.state !== "failed", move, settled: settled(move) };
|
|
174
|
+
}
|
|
175
|
+
const CLAUDE_USAGE_ROUTE = "/v1/usage?sources=claude&accounts=all";
|
|
176
|
+
/** Each Claude account's room in one computer's usage answer. */
|
|
177
|
+
export function claudeAccountRooms(answer, computer, now = Date.now()) {
|
|
178
|
+
const window = (room) => {
|
|
179
|
+
if (!room)
|
|
180
|
+
return undefined;
|
|
181
|
+
const until = room.resetsAt ? resetsIn(room.resetsAt, now) : undefined;
|
|
182
|
+
return { ...room, ...(until ? { resetsIn: until } : {}) };
|
|
183
|
+
};
|
|
184
|
+
return objects(answer.accounts).filter(row => row.source === "claude" && Array.isArray(row.windows)).map(row => {
|
|
185
|
+
const usage = row;
|
|
186
|
+
const { fiveHour, week } = accountWindows(usage, now);
|
|
187
|
+
const five = window(fiveHour), seven = window(week);
|
|
188
|
+
return { computer, account: usage.account?.id ?? "default", ...(usage.account?.label ? { label: usage.account.label } : {}),
|
|
189
|
+
...(usage.account?.email ? { email: usage.account.email } : {}), ...(five ? { fiveHour: five } : {}), ...(seven ? { week: seven } : {}) };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
120
192
|
function sessionsFrom(overview, computer, local, now = Date.now()) {
|
|
121
193
|
const sessions = [];
|
|
122
194
|
for (const group of objects(overview.groups))
|
|
@@ -165,7 +237,9 @@ export function notLinkedComputers(store, here, linked) {
|
|
|
165
237
|
export async function listLiveSessions(options = {}) {
|
|
166
238
|
const health = await hookRequest("/v1/health");
|
|
167
239
|
const here = typeof object(health.computer).name === "string" ? String(object(health.computer).name) : "this computer";
|
|
168
|
-
const
|
|
240
|
+
const [overview, localUsage] = await Promise.all([hookRequest("/v1/workspaces"), hookRequest(CLAUDE_USAGE_ROUTE, undefined, undefined, 10_000).catch(() => undefined)]);
|
|
241
|
+
const sessions = sessionsFrom(overview, here, true);
|
|
242
|
+
const claudeAccounts = localUsage ? claudeAccountRooms(localUsage, here) : [];
|
|
169
243
|
const { peers, peerError } = await optionalHookPeers();
|
|
170
244
|
const unreachable = [];
|
|
171
245
|
// Names each peer answers to (its hostname, Bonjour name), so a computer
|
|
@@ -174,8 +248,11 @@ export async function listLiveSessions(options = {}) {
|
|
|
174
248
|
await Promise.all(peers.map(async (peer) => {
|
|
175
249
|
try {
|
|
176
250
|
const route = peer.server && peer.server !== "default" ? `/v1/workspaces?server=${encodeURIComponent(peer.server)}` : "/v1/workspaces";
|
|
177
|
-
const [overview, health] = await Promise.all([peerRequest(peer, route), peerRequest(peer, "/v1/health").catch(() => ({}))
|
|
251
|
+
const [overview, health, usage] = await Promise.all([peerRequest(peer, route), peerRequest(peer, "/v1/health").catch(() => ({})),
|
|
252
|
+
peerRequest(peer, CLAUDE_USAGE_ROUTE, undefined, 10_000).catch(() => undefined)]);
|
|
178
253
|
sessions.push(...sessionsFrom(overview, peer.name, false));
|
|
254
|
+
if (usage)
|
|
255
|
+
claudeAccounts.push(...claudeAccountRooms(usage, peer.name));
|
|
179
256
|
const computer = object(object(health).computer);
|
|
180
257
|
peerNames.set(peer.name, [computer.name, ...(Array.isArray(computer.aliases) ? computer.aliases : [])].filter((name) => typeof name === "string"));
|
|
181
258
|
}
|
|
@@ -186,5 +263,14 @@ export async function listLiveSessions(options = {}) {
|
|
|
186
263
|
}));
|
|
187
264
|
const store = options.store !== undefined ? options.store : findPhrenPath();
|
|
188
265
|
const notLinked = notLinkedFrom(store, here, peers.map(peer => ({ name: peer.name, address: peer.address, names: peerNames.get(peer.name) })));
|
|
189
|
-
|
|
266
|
+
// Each Claude session carries its account's room, so the conductor and phone see how long it can keep working.
|
|
267
|
+
for (const session of sessions) {
|
|
268
|
+
if (session.agent !== "claude")
|
|
269
|
+
continue;
|
|
270
|
+
const room = claudeAccounts.find(item => item.computer === session.computer && item.account === (session.account ?? "default"));
|
|
271
|
+
if (room?.fiveHour || room?.week)
|
|
272
|
+
session.quota = { ...(room.fiveHour ? { fiveHour: room.fiveHour } : {}), ...(room.week ? { week: room.week } : {}) };
|
|
273
|
+
}
|
|
274
|
+
claudeAccounts.sort((a, b) => a.computer.localeCompare(b.computer) || a.account.localeCompare(b.account));
|
|
275
|
+
return { sessions, unreachable, notLinked, enrolled: peers.length, ...(claudeAccounts.length ? { claudeAccounts } : {}), ...(peerError ? { peerError } : {}) };
|
|
190
276
|
}
|
package/dist/bridge/health.d.ts
CHANGED
|
@@ -114,7 +114,7 @@ export interface HealthOptions {
|
|
|
114
114
|
devices: number;
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
/** `<tool> --version`, bounded to
|
|
117
|
+
/** `<tool> --version`, bounded to 8 seconds and remembered for 5 minutes. `args` come
|
|
118
118
|
* before `--version` for a tool behind a subcommand (`phren agent --version`). */
|
|
119
119
|
export declare function toolVersion(tool: string, executable?: string, args?: string[]): Promise<ToolVersion>;
|
|
120
120
|
/** Only for tests: forget cached versions. */
|
package/dist/bridge/health.js
CHANGED
|
@@ -35,11 +35,13 @@ export function describeTerminal(terminal) {
|
|
|
35
35
|
return `tmux (${names}); ${tmuxText}`;
|
|
36
36
|
return `none: Herdr is not running; ${tmuxText}`;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
// A busy computer can take seconds just to start a Node harness (OpenCode took
|
|
39
|
+
// 2.4 s on a 20-core box at load 17), so 3 s reported healthy installs as broken.
|
|
40
|
+
const VERSION_TIMEOUT_MS = 8_000;
|
|
39
41
|
const VERSION_CACHE_MS = 5 * 60_000;
|
|
40
42
|
const PEER_TIMEOUT_MS = 5_000;
|
|
41
43
|
const versionCache = new Map();
|
|
42
|
-
/** `<tool> --version`, bounded to
|
|
44
|
+
/** `<tool> --version`, bounded to 8 seconds and remembered for 5 minutes. `args` come
|
|
43
45
|
* before `--version` for a tool behind a subcommand (`phren agent --version`). */
|
|
44
46
|
export function toolVersion(tool, executable = tool, args = []) {
|
|
45
47
|
const cached = versionCache.get(tool);
|
|
@@ -53,7 +55,7 @@ export function toolVersion(tool, executable = tool, args = []) {
|
|
|
53
55
|
clearTimeout(timer);
|
|
54
56
|
resolve(result);
|
|
55
57
|
} };
|
|
56
|
-
const timer = setTimeout(() => { child.kill("SIGKILL"); finish({ tool, status: "error", detail:
|
|
58
|
+
const timer = setTimeout(() => { child.kill("SIGKILL"); finish({ tool, status: "error", detail: `--version did not answer within ${VERSION_TIMEOUT_MS / 1000} seconds` }); }, VERSION_TIMEOUT_MS);
|
|
57
59
|
const collect = (chunk) => { if (out.length < 4_096)
|
|
58
60
|
out += chunk.toString(); };
|
|
59
61
|
child.stdout.on("data", collect);
|
package/dist/bridge/install.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type ModuleSnapshot } from "../modules/runtime.js";
|
|
2
|
+
import type { GatewayScope } from "./scoped-gateway.js";
|
|
2
3
|
import { type CodexServerEntry } from "./codex-servers.js";
|
|
3
4
|
export declare const forcedCommand = "command=\"sh ~/.local/share/phren/bridge/dispatch\"";
|
|
5
|
+
/** A scoped key's forced command. A separate script, so a key added before
|
|
6
|
+
* the Hook can serve its scope fails closed instead of reaching `dispatch`. */
|
|
7
|
+
export declare const scopedForcedCommand: (scope: GatewayScope) => string;
|
|
4
8
|
export declare function upgradeKeys(text: string): {
|
|
5
9
|
text: string;
|
|
6
10
|
changed: number;
|
|
@@ -39,6 +43,16 @@ export declare function detectGateway(env?: NodeJS.ProcessEnv): Promise<GatewayK
|
|
|
39
43
|
* socket through a tiny forwarder, so a loaded machine never pays for a fresh
|
|
40
44
|
* node process; every other SSH command falls through to the node gateway. */
|
|
41
45
|
export declare function gatewayScript(gateway: GatewayKind, environment: GatewayEnvironment): string;
|
|
46
|
+
/** The enroll script, for an SSH session the user signed into with a password
|
|
47
|
+
* (the phone's "Password" sign-in): it adds one restricted phone key, then the
|
|
48
|
+
* phone connects with that key. It is never the forced command, so a phone key
|
|
49
|
+
* cannot use it to add more keys. */
|
|
50
|
+
export declare function enrollScript(environment: Pick<GatewayEnvironment, "root" | "herdr" | "store" | "profile" | "node" | "bundle">): string;
|
|
51
|
+
/** The scoped keys' forced command: always the node gateway (never the raw
|
|
52
|
+
* socat/nc pipe), told which scope the key holds. An unknown scope or an older
|
|
53
|
+
* bundle without `ssh-scoped` refuses. */
|
|
54
|
+
export declare function scopedGatewayScript(environment: Omit<GatewayEnvironment, "socket" | "timing">): string;
|
|
55
|
+
export declare const scopedGatewayPath: (root?: string) => string;
|
|
42
56
|
/** The commands that restart the Hook in `domain`, printed when launchd refuses. */
|
|
43
57
|
export declare function launchCommands(domain: string, plist: string): string[];
|
|
44
58
|
/** How long install waits for Codex turns that would stop with the Hook. */
|
package/dist/bridge/install.js
CHANGED
|
@@ -23,6 +23,9 @@ const exec = promisify(execFile);
|
|
|
23
23
|
const label = "com.phren.hook";
|
|
24
24
|
const unit = "phren-hook.service";
|
|
25
25
|
export const forcedCommand = 'command="sh ~/.local/share/phren/bridge/dispatch"';
|
|
26
|
+
/** A scoped key's forced command. A separate script, so a key added before
|
|
27
|
+
* the Hook can serve its scope fails closed instead of reaching `dispatch`. */
|
|
28
|
+
export const scopedForcedCommand = (scope) => `command="sh ~/.local/share/phren/bridge/dispatch-scoped ${scope}"`;
|
|
26
29
|
function keyOptions(line) {
|
|
27
30
|
const options = [];
|
|
28
31
|
let quoted = false, start = 0;
|
|
@@ -140,6 +143,36 @@ export PHREN_PROFILE=${quote(profile)}
|
|
|
140
143
|
${pipe}exec ${quote(node)} ${quote(bundle)} ssh
|
|
141
144
|
`;
|
|
142
145
|
}
|
|
146
|
+
/** The enroll script, for an SSH session the user signed into with a password
|
|
147
|
+
* (the phone's "Password" sign-in): it adds one restricted phone key, then the
|
|
148
|
+
* phone connects with that key. It is never the forced command, so a phone key
|
|
149
|
+
* cannot use it to add more keys. */
|
|
150
|
+
export function enrollScript(environment) {
|
|
151
|
+
const { root, herdr, store, profile, node, bundle } = environment;
|
|
152
|
+
return `#!/bin/sh
|
|
153
|
+
# Phren Hook enroll: adds this phone's restricted key to authorized_keys.
|
|
154
|
+
export PHREN_BRIDGE_HOME=${quote(root)}
|
|
155
|
+
export PHREN_HERDR_HOME=${quote(herdr)}
|
|
156
|
+
export PHREN_PATH=${quote(store)}
|
|
157
|
+
export PHREN_PROFILE=${quote(profile)}
|
|
158
|
+
exec ${quote(node)} ${quote(bundle)} enroll-device "$@"
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
/** The scoped keys' forced command: always the node gateway (never the raw
|
|
162
|
+
* socat/nc pipe), told which scope the key holds. An unknown scope or an older
|
|
163
|
+
* bundle without `ssh-scoped` refuses. */
|
|
164
|
+
export function scopedGatewayScript(environment) {
|
|
165
|
+
const { root, herdr, store, profile, node, bundle } = environment;
|
|
166
|
+
return `#!/bin/sh
|
|
167
|
+
# Phren Hook scoped gateway for keys limited to one route set (phren pair --scope).
|
|
168
|
+
export PHREN_BRIDGE_HOME=${quote(root)}
|
|
169
|
+
export PHREN_HERDR_HOME=${quote(herdr)}
|
|
170
|
+
export PHREN_PATH=${quote(store)}
|
|
171
|
+
export PHREN_PROFILE=${quote(profile)}
|
|
172
|
+
exec ${quote(node)} ${quote(bundle)} ssh-scoped "$1"
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
export const scopedGatewayPath = (root = bridgeRoot()) => path.join(root, "dispatch-scoped");
|
|
143
176
|
async function activate(version) {
|
|
144
177
|
const root = bridgeRoot();
|
|
145
178
|
const next = path.join(root, `current-${process.pid}`);
|
|
@@ -272,6 +305,12 @@ export async function install(version, noService = false, force = false) {
|
|
|
272
305
|
root, herdr, store: modules.store, profile: modules.profile, node: process.execPath,
|
|
273
306
|
bundle: path.join(root, "current/bridge-hook.mjs"), socket: socketPath(), timing: path.join(root, "gateway.json"),
|
|
274
307
|
}), 0o700);
|
|
308
|
+
await atomic(path.join(root, "enroll"), enrollScript({
|
|
309
|
+
root, herdr, store: modules.store, profile: modules.profile, node: process.execPath, bundle: path.join(root, "current/bridge-hook.mjs"),
|
|
310
|
+
}), 0o700);
|
|
311
|
+
await atomic(scopedGatewayPath(root), scopedGatewayScript({
|
|
312
|
+
root, herdr, store: modules.store, profile: modules.profile, node: process.execPath, bundle: path.join(root, "current/bridge-hook.mjs"),
|
|
313
|
+
}), 0o700);
|
|
275
314
|
await installAskpass(process.execPath, path.join(root, "current/bridge-hook.mjs"));
|
|
276
315
|
const environmentPath = [path.dirname(process.execPath), path.join(homedir(), ".local/bin"), "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin"].join(":");
|
|
277
316
|
const program = path.join(root, "current/bridge-hook.mjs");
|
|
@@ -373,7 +412,7 @@ export async function uninstall() {
|
|
|
373
412
|
await applyOpencodePlugin(true);
|
|
374
413
|
await removeAskpass();
|
|
375
414
|
// Preserve journal, settings, uploaded images, rollback version and SSH backups.
|
|
376
|
-
console.log("Phren Hook stopped and its background service removed. Remove phren-iphone, phren-android and phren-
|
|
415
|
+
console.log("Phren Hook stopped and its background service removed. Remove phren-iphone, phren-android, phren-computer, phren-gitboy and phren-gitboy-write keys from authorized_keys to revoke device access. Local data remains in " + bridgeRoot());
|
|
377
416
|
}
|
|
378
417
|
async function missingFile(operation) {
|
|
379
418
|
try {
|
|
@@ -51,6 +51,9 @@ export declare function briefLabel(id: string): Promise<string | undefined>;
|
|
|
51
51
|
* it in place left a moment where the folder was there and the file was not.
|
|
52
52
|
*/
|
|
53
53
|
export declare function writeLaunchBrief(brief: LaunchBrief, now?: number, label?: string): Promise<string>;
|
|
54
|
+
/** The text of a brief this computer wrote, for the dispatch that continues its worker on another
|
|
55
|
+
* account (account-failover.ts); undefined once pruned or for an id it never wrote. */
|
|
56
|
+
export declare function readLaunchBrief(id: string): Promise<string | undefined>;
|
|
54
57
|
export declare const arrivalSchema: z.ZodObject<{
|
|
55
58
|
started: z.ZodOptional<z.ZodObject<{
|
|
56
59
|
at: z.ZodString;
|
|
@@ -128,6 +128,22 @@ export async function writeLaunchBrief(brief, now = Date.now(), label) {
|
|
|
128
128
|
}
|
|
129
129
|
return file;
|
|
130
130
|
}
|
|
131
|
+
/** The text of a brief this computer wrote, for the dispatch that continues its worker on another
|
|
132
|
+
* account (account-failover.ts); undefined once pruned or for an id it never wrote. */
|
|
133
|
+
export async function readLaunchBrief(id) {
|
|
134
|
+
if (!briefId.safeParse(id).success)
|
|
135
|
+
return undefined;
|
|
136
|
+
const file = path.join(briefDirectory(id), "brief.md");
|
|
137
|
+
try {
|
|
138
|
+
const info = await lstat(file);
|
|
139
|
+
if (!info.isFile() || info.size > 65_536)
|
|
140
|
+
return undefined;
|
|
141
|
+
return await readFile(file, "utf8");
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
131
147
|
const arrivalEvent = z.object({ at: z.string().datetime(), target: targetSchema }).strict();
|
|
132
148
|
export const arrivalSchema = z.object({ started: arrivalEvent.optional(), accepted: arrivalEvent.optional() }).strict();
|
|
133
149
|
/** What the worker's own hooks have said about its brief: `started` at its
|
|
@@ -15,6 +15,13 @@ export declare function storeHead(store: string, indexFile?: string): Promise<{
|
|
|
15
15
|
/** The recursive tree for a head, with the fields the phone's GitTree decodes. */
|
|
16
16
|
export declare function storeTree(store: string, sha: string): Promise<Json>;
|
|
17
17
|
export declare function storeBlob(store: string, sha: string): Promise<Json>;
|
|
18
|
+
/**
|
|
19
|
+
* Many blobs in one answer (Phren desktop's store mirror): one
|
|
20
|
+
* `git cat-file --batch` for the whole request instead of three git processes
|
|
21
|
+
* per blob. Blobs past the byte budget, over the 4 MiB file limit or unknown
|
|
22
|
+
* come back as `{ sha, error }` for the client to fetch one by one or skip.
|
|
23
|
+
*/
|
|
24
|
+
export declare function storeBlobs(store: string, data: Json): Promise<Json>;
|
|
18
25
|
/** Resolve a store-relative path, refusing escapes, .git and symlinked parents. */
|
|
19
26
|
export declare function storeFile(store: string, relative: string): Promise<string>;
|
|
20
27
|
/** Write one file if it still has the sha the phone last saw (null: must not exist). */
|
|
@@ -24,6 +31,7 @@ export declare const STORE_ROUTES: {
|
|
|
24
31
|
readonly head: "/v1/store/head";
|
|
25
32
|
readonly tree: "/v1/store/tree";
|
|
26
33
|
readonly blob: "/v1/store/blob";
|
|
34
|
+
readonly blobs: "/v1/store/blobs";
|
|
27
35
|
readonly file: "/v1/store/file";
|
|
28
36
|
readonly delete: "/v1/store/delete";
|
|
29
37
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { lstat, mkdir, readFile, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
@@ -116,6 +116,82 @@ export async function storeBlob(store, sha) {
|
|
|
116
116
|
const { stdout } = await exec("git", ["-C", store, "cat-file", "blob", sha], { encoding: "buffer", maxBuffer: MAX_FILE, timeout: 60_000 });
|
|
117
117
|
return { sha, encoding: "base64", content: stdout.toString("base64") };
|
|
118
118
|
}
|
|
119
|
+
/** At most this many blobs and this much content (before base64) per batch answer. */
|
|
120
|
+
const BATCH_COUNT = 256;
|
|
121
|
+
const BATCH_BYTES = 9 * 1024 * 1024;
|
|
122
|
+
/**
|
|
123
|
+
* Many blobs in one answer (Phren desktop's store mirror): one
|
|
124
|
+
* `git cat-file --batch` for the whole request instead of three git processes
|
|
125
|
+
* per blob. Blobs past the byte budget, over the 4 MiB file limit or unknown
|
|
126
|
+
* come back as `{ sha, error }` for the client to fetch one by one or skip.
|
|
127
|
+
*/
|
|
128
|
+
export async function storeBlobs(store, data) {
|
|
129
|
+
const shas = z.array(z.string().regex(SHA)).min(1).max(BATCH_COUNT).parse(data.shas);
|
|
130
|
+
const unique = [...new Set(shas)];
|
|
131
|
+
// Sizes first (no content), so the budget is applied before anything is read.
|
|
132
|
+
const sizes = new Map();
|
|
133
|
+
for (const line of (await catFile(store, "--batch-check", unique)).toString("utf8").split("\n")) {
|
|
134
|
+
const [sha, type, size] = line.split(" ");
|
|
135
|
+
if (sha && type && type !== "missing")
|
|
136
|
+
sizes.set(sha, { type, size: Number(size) });
|
|
137
|
+
}
|
|
138
|
+
const blobs = [];
|
|
139
|
+
const wanted = [];
|
|
140
|
+
let budget = BATCH_BYTES;
|
|
141
|
+
for (const sha of unique) {
|
|
142
|
+
const info = sizes.get(sha);
|
|
143
|
+
if (!info || info.type !== "blob") {
|
|
144
|
+
blobs.push({ sha, error: "unknown" });
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (info.size > MAX_FILE) {
|
|
148
|
+
blobs.push({ sha, error: "too-large", size: info.size });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (info.size > budget) {
|
|
152
|
+
blobs.push({ sha, error: "later" });
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
budget -= info.size;
|
|
156
|
+
wanted.push(sha);
|
|
157
|
+
}
|
|
158
|
+
if (wanted.length) {
|
|
159
|
+
const out = await catFile(store, "--batch", wanted);
|
|
160
|
+
let offset = 0;
|
|
161
|
+
for (const sha of wanted) {
|
|
162
|
+
const newline = out.indexOf(10, offset);
|
|
163
|
+
if (newline < 0) {
|
|
164
|
+
blobs.push({ sha, error: "later" });
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const size = Number(out.subarray(offset, newline).toString("utf8").split(" ")[2]);
|
|
168
|
+
offset = newline + 1;
|
|
169
|
+
blobs.push({ sha, encoding: "base64", content: out.subarray(offset, offset + size).toString("base64") });
|
|
170
|
+
offset += size + 1;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { blobs };
|
|
174
|
+
}
|
|
175
|
+
/** Run one `git cat-file --batch[-check]` over these ids; output capped near the batch budget. */
|
|
176
|
+
function catFile(store, mode, shas) {
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
const child = spawn("git", ["-C", store, "cat-file", mode], { stdio: ["pipe", "pipe", "ignore"] });
|
|
179
|
+
const chunks = [];
|
|
180
|
+
let total = 0;
|
|
181
|
+
child.stdout.on("data", (chunk) => {
|
|
182
|
+
total += chunk.length;
|
|
183
|
+
if (total > BATCH_BYTES + BATCH_COUNT * 128) {
|
|
184
|
+
child.kill();
|
|
185
|
+
reject(new BridgeError(413, "The batch is too large."));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
chunks.push(chunk);
|
|
189
|
+
});
|
|
190
|
+
child.on("error", reject);
|
|
191
|
+
child.on("close", () => resolve(Buffer.concat(chunks)));
|
|
192
|
+
child.stdin.end(shas.map(sha => `${sha}\n`).join(""));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
119
195
|
/** Resolve a store-relative path, refusing escapes, .git and symlinked parents. */
|
|
120
196
|
export async function storeFile(store, relative) {
|
|
121
197
|
const normalized = path.posix.normalize(relative);
|
|
@@ -175,7 +251,7 @@ export function deleteStoreFile(store, data) {
|
|
|
175
251
|
return { ok: true };
|
|
176
252
|
});
|
|
177
253
|
}
|
|
178
|
-
export const STORE_ROUTES = { head: "/v1/store/head", tree: "/v1/store/tree", blob: "/v1/store/blob", file: "/v1/store/file", delete: "/v1/store/delete" };
|
|
254
|
+
export const STORE_ROUTES = { head: "/v1/store/head", tree: "/v1/store/tree", blob: "/v1/store/blob", blobs: "/v1/store/blobs", file: "/v1/store/file", delete: "/v1/store/delete" };
|
|
179
255
|
export async function storeRoute(store, method, url, data) {
|
|
180
256
|
if (method === "GET" && url.pathname === STORE_ROUTES.head)
|
|
181
257
|
return storeHead(store);
|
|
@@ -183,6 +259,8 @@ export async function storeRoute(store, method, url, data) {
|
|
|
183
259
|
return storeTree(store, url.searchParams.get("sha") ?? "");
|
|
184
260
|
if (method === "GET" && url.pathname === STORE_ROUTES.blob)
|
|
185
261
|
return storeBlob(store, url.searchParams.get("sha") ?? "");
|
|
262
|
+
if (method === "POST" && url.pathname === STORE_ROUTES.blobs)
|
|
263
|
+
return storeBlobs(store, data ?? {});
|
|
186
264
|
if (method === "POST" && url.pathname === STORE_ROUTES.file)
|
|
187
265
|
return putStoreFile(store, data ?? {});
|
|
188
266
|
if (method === "POST" && url.pathname === STORE_ROUTES.delete)
|
package/dist/bridge/pair.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type GatewayScope } from "./scoped-gateway.js";
|
|
1
2
|
export declare const PAIR_PORT = 47291;
|
|
2
3
|
export declare function newPairingCode(): string;
|
|
3
4
|
/** Codes are typed as ABC-234 or abc234; both mean the same code. */
|
|
@@ -42,5 +43,9 @@ export declare function startPairing(options: {
|
|
|
42
43
|
timeoutMs?: number;
|
|
43
44
|
sshDirectory?: string;
|
|
44
45
|
}): Promise<PairingSession>;
|
|
45
|
-
export declare const PAIR_USAGE = "phren pair [--minutes <1-30>] [--port <n>] [--no-install]";
|
|
46
|
+
export declare const PAIR_USAGE = "phren pair [--minutes <1-30>] [--port <n>] [--no-install] | phren pair --scope gitboy-read|gitboy-write --key <public-key-file|-> [--no-install]";
|
|
47
|
+
/** The authorized_keys line for a scoped key: no PTY, no forwarding, its own forced command. */
|
|
48
|
+
export declare function scopedKeyLine(scope: GatewayScope, publicKey: string): string;
|
|
49
|
+
/** Authorize a server's key for one scope. Options on the supplied line are discarded and rebuilt. */
|
|
50
|
+
export declare function acceptScopedKey(scope: GatewayScope, input: string, sshDirectory?: string): Promise<string>;
|
|
46
51
|
export declare function runPair(args: string[], version: string): Promise<number>;
|
package/dist/bridge/pair.js
CHANGED
|
@@ -9,7 +9,8 @@ import { promisify } from "node:util";
|
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { appendAuthorizedKey, publicComputerKey } from "./computers.js";
|
|
11
11
|
import { localHostKeyLine } from "./host-key.js";
|
|
12
|
-
import { forcedCommand, install } from "./install.js";
|
|
12
|
+
import { forcedCommand, install, scopedForcedCommand, scopedGatewayPath } from "./install.js";
|
|
13
|
+
import { isGatewayScope, SCOPE_KEY_COMMENT } from "./scoped-gateway.js";
|
|
13
14
|
import { BridgeError, bridgeRoot } from "./protocol.js";
|
|
14
15
|
// `phren pair` connects a phone in one scan. The QR code carries where to
|
|
15
16
|
// reach this computer, its SSH host key fingerprint and a one-time code. The
|
|
@@ -177,8 +178,79 @@ function sshHint() {
|
|
|
177
178
|
? "Turn on Remote Login: System Settings → General → Sharing → Remote Login."
|
|
178
179
|
: "Start the SSH server, for example: sudo systemctl enable --now sshd";
|
|
179
180
|
}
|
|
180
|
-
export const PAIR_USAGE = "phren pair [--minutes <1-30>] [--port <n>] [--no-install]";
|
|
181
|
+
export const PAIR_USAGE = "phren pair [--minutes <1-30>] [--port <n>] [--no-install] | phren pair --scope gitboy-read|gitboy-write --key <public-key-file|-> [--no-install]";
|
|
182
|
+
/** The authorized_keys line for a scoped key: no PTY, no forwarding, its own forced command. */
|
|
183
|
+
export function scopedKeyLine(scope, publicKey) {
|
|
184
|
+
return `restrict,${scopedForcedCommand(scope)} ${publicComputerKey(publicKey)} ${SCOPE_KEY_COMMENT[scope]}`;
|
|
185
|
+
}
|
|
186
|
+
/** Authorize a server's key for one scope. Options on the supplied line are discarded and rebuilt. */
|
|
187
|
+
export async function acceptScopedKey(scope, input, sshDirectory) {
|
|
188
|
+
const raw = input.trim().split("\n").map(line => line.trim()).filter(Boolean);
|
|
189
|
+
if (raw.length !== 1)
|
|
190
|
+
throw new BridgeError(400, "Supply one ed25519 public key.");
|
|
191
|
+
const at = raw[0].indexOf("ssh-ed25519 ");
|
|
192
|
+
if (at === -1)
|
|
193
|
+
throw new BridgeError(400, "Supply one ed25519 public key.");
|
|
194
|
+
const line = scopedKeyLine(scope, raw[0].slice(at));
|
|
195
|
+
const encoded = line.split(" ").at(-2);
|
|
196
|
+
await appendAuthorizedKey(line, existing => existing.split(/\s+/).includes(encoded), "This key is already authorized with different options. Remove its line from authorized_keys first.", sshDirectory);
|
|
197
|
+
return line;
|
|
198
|
+
}
|
|
199
|
+
async function runScopedPair(args, version) {
|
|
200
|
+
let scope, key, installHook = true;
|
|
201
|
+
for (let i = 0; i < args.length; i++) {
|
|
202
|
+
if (args[i] === "--scope" && args[i + 1])
|
|
203
|
+
scope = args[++i];
|
|
204
|
+
else if (args[i] === "--key" && args[i + 1])
|
|
205
|
+
key = args[++i];
|
|
206
|
+
else if (args[i] === "--no-install")
|
|
207
|
+
installHook = false;
|
|
208
|
+
else {
|
|
209
|
+
console.error(`Usage: ${PAIR_USAGE}`);
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!scope || !isGatewayScope(scope)) {
|
|
214
|
+
console.error(`Unknown scope${scope ? ` "${scope}"` : ""}. Supported: gitboy-read, gitboy-write.`);
|
|
215
|
+
return 1;
|
|
216
|
+
}
|
|
217
|
+
if (!key) {
|
|
218
|
+
console.error(`Usage: ${PAIR_USAGE}`);
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
if (!["darwin", "linux"].includes(process.platform)) {
|
|
222
|
+
console.error("Scoped keys support macOS and Linux.");
|
|
223
|
+
return 1;
|
|
224
|
+
}
|
|
225
|
+
if (!await lstat(scopedGatewayPath()).catch(() => undefined)) {
|
|
226
|
+
if (!installHook) {
|
|
227
|
+
console.error("This Phren Hook has no scoped gateway yet. Run phren bridge update first.");
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
console.log("Installing Phren Hook with the scoped gateway…");
|
|
231
|
+
await install(version);
|
|
232
|
+
}
|
|
233
|
+
let text;
|
|
234
|
+
if (key === "-") {
|
|
235
|
+
const chunks = [];
|
|
236
|
+
for await (const chunk of process.stdin)
|
|
237
|
+
chunks.push(chunk);
|
|
238
|
+
text = Buffer.concat(chunks).toString("utf8");
|
|
239
|
+
}
|
|
240
|
+
else
|
|
241
|
+
text = await readFile(key, "utf8");
|
|
242
|
+
const line = await acceptScopedKey(scope, text);
|
|
243
|
+
const fingerprint = await hostFingerprint();
|
|
244
|
+
console.log(`Authorized ${SCOPE_KEY_COMMENT[scope]} for ${scope}: ${scope === "gitboy-write" ? "POST /v1/projects/<project>/findings only" : "GET /v1/projects/<project>/memory, memory/files, memory/search and tasks only"}.`);
|
|
245
|
+
console.log(` ${line}`);
|
|
246
|
+
console.log(` SSH user: ${userInfo().username} host key: ${fingerprint ?? "unknown (no /etc/ssh/ssh_host_ed25519_key.pub)"}`);
|
|
247
|
+
console.log(` Addresses: ${(await pairingHosts()).join(", ") || "none found"}`);
|
|
248
|
+
console.log(` Revoke: remove the ${SCOPE_KEY_COMMENT[scope]} line from ${path.join(homedir(), ".ssh/authorized_keys")}.`);
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
181
251
|
export async function runPair(args, version) {
|
|
252
|
+
if (args.includes("--scope"))
|
|
253
|
+
return runScopedPair(args, version);
|
|
182
254
|
let minutes = 5, port, installHook = true;
|
|
183
255
|
for (let i = 0; i < args.length; i++) {
|
|
184
256
|
if (args[i] === "--minutes" && args[i + 1])
|
package/dist/bridge/peers.js
CHANGED
|
@@ -6,8 +6,10 @@ import { dump, load } from "js-yaml";
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
8
|
import { hookRequest } from "./client.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import { dispatchKeyPath, publicComputerKey } from "./computers.js";
|
|
10
|
+
// computerName comes from protocol.js, where it is defined: through computers.js it can still be
|
|
11
|
+
// undefined when an import cycle (usage -> account-choice -> health -> peers) loads this file first.
|
|
12
|
+
import { atomic, BridgeError, bridgeRoot, computerName, serverName, withErrorCode } from "./protocol.js";
|
|
11
13
|
const peerSchema = z.object({
|
|
12
14
|
name: computerName,
|
|
13
15
|
address: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9.:-]{0,252}$/),
|