Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

feat: name linked computers without exposing hosts [E19,H16]

Corey Olsonffd8d3cd092b
diff --git a/relay/auth.js b/relay/auth.js
index dd0eb746..18e1bbe8 100644
--- a/relay/auth.js
+++ b/relay/auth.js
@@ -4,6 +4,7 @@ import { chmodSync, mkdirSync } from 'node:fs';
import { dirname } from 'node:path';
import { DatabaseSync } from 'node:sqlite';
import { Refused } from '../src/refused.js';
+import { computerName } from '../src/computer-name.js';
import { repositoryName } from './github.js';
import { approvalContext } from '../src/relay-approval.js';
import { VERIFIER_STANDING_ENGINE } from '../src/machine.js';
@@ -70,7 +71,7 @@ export function createRelayAuth({ database, github, now = Date.now, sessionTTL =
db.exec('ALTER TABLE relay_credentials ADD COLUMN created INTEGER');
}
// A joined computer's host name and last contact let its owner recognise it in relay devices.
- for (const column of ['host TEXT', 'seen INTEGER']) {
+ for (const column of ['host TEXT', 'seen INTEGER', 'name TEXT']) {
if (!db.prepare('PRAGMA table_info(relay_credentials)').all().some((entry) => entry.name === column.split(' ')[0])) {
db.exec('ALTER TABLE relay_credentials ADD COLUMN ' + column);
}
@@ -648,9 +649,10 @@ export function createRelayAuth({ database, github, now = Date.now, sessionTTL =
return { board, approvers: approvers.length ? [...approvers].sort() : null };
},
/** Give a foreground person one board-bound machine delegate, never another person credential. */
- async issueMachine(token, { board, machine, host, expiresIn = MAX_TTL }) {
+ async issueMachine(token, { board, machine, host, name, expiresIn = MAX_TTL }) {
identifier(board, 'BAD_BOARD');
identifier(machine, 'BAD_MACHINE');
+ const label = computerName(name);
if (host !== undefined && (typeof host !== 'string' || !host.trim() || host.length > 255 || /[\u0000-\u001f\u007f]/u.test(host))) {
throw new Refused('BAD_REQUEST', 'send the joining computer’s host name as plain text of at most 255 characters');
}
@@ -660,6 +662,7 @@ export function createRelayAuth({ database, github, now = Date.now, sessionTTL =
credential(token);
const issued = issue(principal.user, 'machine', board, machine, expiresIn);
if (host !== undefined) db.prepare('UPDATE relay_credentials SET host=? WHERE id=?').run(host, issued.id);
+ if (label !== undefined) db.prepare('UPDATE relay_credentials SET name=? WHERE id=?').run(label, issued.id);
return { ...issued, board, machine };
},
/** List live computer identities only for this board's machine or a freshly authorized person. */
@@ -669,8 +672,8 @@ export function createRelayAuth({ database, github, now = Date.now, sessionTTL =
if (!['session', 'machine'].includes(principal.kind)) throw new Refused('HUMAN_REQUIRED', 'use this board’s machine credential or the signed-in phone to list joined computers');
credential(token);
// Each computer is listed once, by the host name it sent when it joined, with its first join and last contact.
- return db.prepare("SELECT agent AS machine, MAX(host) AS host, MIN(created) AS created, MAX(seen) AS seen FROM relay_credentials WHERE board=? AND kind='machine' AND revoked=0 AND expires>? GROUP BY agent ORDER BY agent")
- .all(board, now()).map(row => ({ machine: row.machine, host: row.host ?? null, created: row.created ?? null, seen: row.seen ?? null }));
+ return db.prepare("SELECT agent AS machine, MAX(name) AS name, MIN(created) AS created, MAX(seen) AS seen FROM relay_credentials WHERE board=? AND kind='machine' AND revoked=0 AND expires>? GROUP BY agent ORDER BY agent")
+ .all(board, now()).map(row => ({ machine: row.machine, name: row.name ?? null, created: row.created ?? null, seen: row.seen ?? null }));
},
/**
* Mint an agent credential scoped to one board (#579). The machine credential, or a person,
diff --git a/src/commands/relay.js b/src/commands/relay.js
index f6c30fea..28c746f9 100644
--- a/src/commands/relay.js
+++ b/src/commands/relay.js
@@ -74,7 +74,7 @@ export async function run(io, { first, second, rest, values }) {
}
if (values.all) {
if (first !== 'on' || second || rest.length) throw new Refused('USAGE', 'pullboard relay on --all [--url <address>]');
- return await relayOnAllCommand(values.url, io);
+ return await relayOnAllCommand(values.url, io, { name: values.name });
}
if (['tokens', 'revoke'].includes(first)) {
if (rest.length || values.url || (first === 'tokens' && second) || (first === 'revoke' && !second)) {
@@ -102,13 +102,13 @@ export async function run(io, { first, second, rest, values }) {
if (first === 'join') {
if (!second || rest.length) throw new Refused('USAGE', 'pullboard relay join <code> [--url <address>]');
const ctx = context(io);
- return await relayJoin(ctx.info.root, second, values.url, io);
+ return await relayJoin(ctx.info.root, second, values.url, io, { name: values.name });
}
if (second || rest.length || (first && !['on', 'off', 'status'].includes(first)) || (values.url && first !== 'on')) throw new Refused('USAGE', 'pullboard relay [status|on|off] [--url <address>]');
const ctx = context(io);
// pullboard relay status is the named form of plain pullboard relay: the same sync and report.
if (!first || first === 'status') await relayRead(ctx.info.root, io);
- const result = first === 'on' ? await relayOn(ctx.info.root, values.url, io)
+ const result = first === 'on' ? await relayOn(ctx.info.root, values.url, io, { name: values.name })
: first === 'off' ? await relayOff(ctx.info.root, io) : relayStatus(ctx.info.root);
io.result?.(result);
const boardName = listApiProjects().find((project) => project.root === ctx.info.root)?.name ?? basename(ctx.info.root);
diff --git a/src/commands/takeover.js b/src/commands/takeover.js
index 405ea87e..822cf732 100644
--- a/src/commands/takeover.js
+++ b/src/commands/takeover.js
@@ -17,8 +17,9 @@ const TAKEN = new WeakMap();
/** The coordinator move's arguments: this checkout's relay machine id names it in the hold. */
function takeArgs(root) {
- const machine = relayMachineContext(root)?.machine;
- return [{ agentId: COORDINATOR, ...(typeof machine === 'string' ? { machine } : {}) }];
+ const state = relayMachineContext(root);
+ const machine = state?.machine;
+ return [{ agentId: COORDINATOR, ...(typeof machine === 'string' ? { machine } : {}), ...(state?.computerName === undefined ? {} : { name: state.computerName }) }];
}
/**
diff --git a/src/computer-name-engine.js b/src/computer-name-engine.js
new file mode 100644
index 00000000..9fddd5b2
--- /dev/null
+++ b/src/computer-name-engine.js
@@ -0,0 +1,3 @@
+/** Person-given labels in ordered coordinator holds, preserving older receipts [E19,H16]. */
+import { unassignedEngine } from './engine-next.js';
+export const COMPUTER_NAME_ENGINE = unassignedEngine();
diff --git a/src/computer-name.js b/src/computer-name.js
new file mode 100644
index 00000000..81cc99b8
--- /dev/null
+++ b/src/computer-name.js
@@ -0,0 +1,11 @@
+/** Explicit computer display names; never derive them from a host or filesystem path [E19]. */
+import { Refused } from './refused.js';
+
+/** Validate a person's optional label before linking or consuming a pairing code. */
+export function computerName(value) {
+ if (value === undefined) return undefined;
+ if (typeof value !== 'string' || !value.trim() || value.trim().length > 80 || /[\u0000-\u001f\u007f/\\]/u.test(value)) {
+ throw new Refused('BAD_COMPUTER_NAME', 'give this computer a name of 1 to 80 characters, without control characters or path separators; retry with --name "<name>"');
+ }
+ return value.trim();
+}
diff --git a/src/coordinator-hold.js b/src/coordinator-hold.js
index 74ffe128..f295b495 100644
--- a/src/coordinator-hold.js
+++ b/src/coordinator-hold.js
@@ -18,6 +18,9 @@ import { COORDINATOR } from './config.js';
import { COORDINATOR_HOLD_ENGINE } from './coordinator-hold-engine.js';
import { Refused } from './refused.js';
import { credentialActor } from './relay-sender.js';
+import { computerName } from './computer-name.js';
+import { COMPUTER_NAME_ENGINE } from './computer-name-engine.js';
+import { ENGINE_VERSION } from './machine.js';
export { COORDINATOR_HOLD_ENGINE };
const HOLDER_KEY = 'coordinator_holder';
@@ -33,7 +36,8 @@ const UNHELD_OPERATIONS = new Set(['register', 'ensureCoordinator', 'takeCoordin
* @param {unknown} machine the link's relay machine id
* @returns {string}
*/
-export function computerLabel(machine) {
+export function computerLabel(machine, name) {
+ if (name !== undefined) return computerName(name);
return typeof machine === 'string' && MACHINE.test(machine) ? `computer ${machine.slice(-8)}` : 'another main checkout';
}
@@ -49,8 +53,11 @@ function machineOf(machine) {
* @param {unknown} machine the sending link's relay machine id
* @returns {any} the same move
*/
-export function stampCoordinatorHolder(move, machine) {
- if (credentialActor(move) === COORDINATOR && typeof machine === 'string' && MACHINE.test(machine)) move.holder = machine;
+export function stampCoordinatorHolder(move, machine, name) {
+ if (credentialActor(move) === COORDINATOR && typeof machine === 'string' && MACHINE.test(machine)) {
+ move.holder = machine;
+ if (move.engine >= COMPUTER_NAME_ENGINE && name !== undefined) move.holderName = computerName(name);
+ }
return move;
}
@@ -66,15 +73,15 @@ export function coordinatorHolder(board) {
try {
const value = JSON.parse(row.meta_value);
return typeof value?.lineage === 'string'
- ? { machine: machineOf(value.machine), lineage: value.lineage, label: computerLabel(value.machine), at: String(value.at ?? '') } : null;
+ ? { machine: machineOf(value.machine), lineage: value.lineage, label: computerLabel(value.machine, value.name), at: String(value.at ?? '') } : null;
} catch { return null; }
}
/** Record a holder in the caller's transaction and return its name. */
-function saveHolder(board, machine, lineage, at) {
+function saveHolder(board, machine, lineage, at, name) {
board.db.prepare('INSERT INTO board_meta (meta_key, meta_value) VALUES (?, ?) ON CONFLICT(meta_key) DO UPDATE SET meta_value = excluded.meta_value')
- .run(HOLDER_KEY, JSON.stringify({ machine: machineOf(machine), lineage, at }));
- return computerLabel(machine);
+ .run(HOLDER_KEY, JSON.stringify({ machine: machineOf(machine), lineage, at, ...(name === undefined ? {} : { name: computerName(name) }) }));
+ return computerLabel(machine, name);
}
/**
@@ -89,11 +96,12 @@ function saveHolder(board, machine, lineage, at) {
export function requireCoordinatorHold(board, move, lineage, at) {
if (!lineage || !(move.engine >= COORDINATOR_HOLD_ENGINE) || UNHELD_OPERATIONS.has(move.operation)) return;
const holder = coordinatorHolder(board);
- if (!holder) { saveHolder(board, move.holder, lineage, at); return; }
+ const name = move.engine >= COMPUTER_NAME_ENGINE ? move.holderName : undefined;
+ if (!holder) { saveHolder(board, move.holder, lineage, at, name); return; }
const machine = machineOf(move.holder);
if (holder.lineage === lineage && (!machine || !holder.machine || machine === holder.machine)) return;
// The holding checkout signed in again, so its credential lineage changed: the hold follows the checkout.
- if (machine && machine === holder.machine) { saveHolder(board, machine, lineage, holder.at); return; }
+ if (machine && machine === holder.machine) { saveHolder(board, machine, lineage, holder.at, name); return; }
throw new Refused('COORDINATOR_HELD',
`this board's coordinator is held by ${holder.label}, so this main checkout cannot act as coordinator; to coordinate from here, run pullboard takeover in this main checkout`);
}
@@ -106,7 +114,7 @@ export function requireCoordinatorHold(board, move, lineage, at) {
* @param {{ agentId: string, machine?: string }} options
* @returns {{ holder: string, previous: string | null }}
*/
-export function takeCoordinator(board, { agentId, machine }) {
+export function takeCoordinator(board, { agentId, machine, name }) {
if (agentId !== COORDINATOR) throw new Refused('COORDINATOR_ONLY', 'only the coordinator takes over the coordinator; run pullboard takeover in the main checkout');
const lineage = board.verifierStanding?.lineage;
if (!lineage) {
@@ -115,7 +123,8 @@ export function takeCoordinator(board, { agentId, machine }) {
return atomic(board, () => {
const previous = coordinatorHolder(board);
const at = board.clock?.now?.().toISOString?.() ?? new Date().toISOString();
- const holder = saveHolder(board, machine, lineage, at);
+ const label = (board.executionEngineVersion ?? ENGINE_VERSION) >= COMPUTER_NAME_ENGINE ? name : undefined;
+ const holder = saveHolder(board, machine, lineage, at, label);
logEvent(board, COORDINATOR, 'coordinator-takeover', null, { holder, previous: previous?.label ?? null, engine: COORDINATOR_HOLD_ENGINE });
return { holder, previous: previous?.label ?? null };
});
diff --git a/src/help.js b/src/help.js
index d627754c..16a6d024 100644
--- a/src/help.js
+++ b/src/help.js
@@ -53,11 +53,11 @@ Set up
behind the session secret in its printed address
pullboard mcp MCP tools over stdio for this worktree's agent, started by its MCP client:
board status, show, shout and capture an idea; a person's move is refused
- pullboard relay [status|on|off|pair|join <code>] [--url <address>] link, inspect or unlink this board's sealed relay
+ pullboard relay [status|on|off|pair|join <code>] [--url <address>] [--name <computer>] link, inspect or unlink this board's sealed relay
on signs in through GitHub; the address defaults to https://app.pullboard.dev
pair prints a one-use machine code; join stores it in another clone
pullboard relay pair --new-browser sign in and pair one more browser; existing browsers stay paired
- pullboard relay on --all [--url <address>] link every registered project after one sign-in; pair the phone once
+ pullboard relay on --all [--url <address>] [--name <computer>] link every registered project after one sign-in; pair the phone once
keep this command open until pairing finishes; later projects link on registration
pullboard relay devices [--verbose] paired phones and joined computers by name, with paired date, last seen and boards
--verbose adds each id and phone key fingerprint
diff --git a/src/moves/takeCoordinator.js b/src/moves/takeCoordinator.js
index fb5ad5b0..a52b1a56 100644
--- a/src/moves/takeCoordinator.js
+++ b/src/moves/takeCoordinator.js
@@ -3,9 +3,11 @@ import { RIGOR_AUTO_ENGINE } from '../rigor-auto-engine.js';
import { COORDINATOR_HOLD_ENGINE } from '../coordinator-hold-engine.js';
import { LANDING_LEASE_ENGINE } from '../landing-lease-engine.js';
import { BOARD_SENTINEL_ENGINE } from '../sentinel-engine.js';
+import { COMPUTER_NAME_ENGINE } from '../computer-name-engine.js';
/** Preserve this operation's historical first-matching engine conditions [H16]. */
function minimumEngine(args, board, at) {
+ if (args[0]?.name !== undefined) return COMPUTER_NAME_ENGINE;
if (typeof args[1]?.cause === 'string' && args[1].cause.startsWith('conflict:')) return RIGOR_AUTO_ENGINE;
if (args[0]?.landingFence !== undefined) return LANDING_LEASE_ENGINE;
if (typeof args[1]?.cause === 'string' && args[1].cause.startsWith('sentinel:')) return BOARD_SENTINEL_ENGINE;
diff --git a/src/next-step-defaults.js b/src/next-step-defaults.js
index e75f3dca..bbaa5d38 100644
--- a/src/next-step-defaults.js
+++ b/src/next-step-defaults.js
@@ -1,5 +1,6 @@
/** General CLI recovery text; operation-owned codes live in src/moves/ [P4,C7]. */
export const DEFAULT_NEXT_STEPS = Object.freeze({
+ "BAD_COMPUTER_NAME": "retry relay on or relay join with --name containing 1 to 80 characters and no control characters or path separators",
"GIT_SYNC_LOG": "restore the append-only refs/pullboard/board history on origin before running pullboard sync",
"GIT_SYNC_REMOTE": "restore read/write access to origin, then retry the original command or run pullboard sync; keep its pending sealed move",
"GIT_SYNC_LOCAL_CHANGED": "run pullboard export to preserve local moves, then ask the coordinator to reconcile the local and remote prefixes before syncing",
diff --git a/src/relay-pairing-client.js b/src/relay-pairing-client.js
index 220fd6e1..71879a48 100644
--- a/src/relay-pairing-client.js
+++ b/src/relay-pairing-client.js
@@ -9,7 +9,7 @@ import {
rmSync,
writeFileSync,
} from 'node:fs';
-import { hostname } from 'node:os';
+import { computerName } from './computer-name.js';
import {
dirname,
join,
@@ -222,7 +222,8 @@ function requireMissingKey(board) {
}
/** Consume a printed one-time code, restore the board and save this device's own link. */
-export async function relayJoin(root, code, address, io) {
+export async function relayJoin(root, code, address, io, { name } = {}) {
+ const label = computerName(name);
requirePersonChannel(io.personChannel);
const parsed = parsePairingCode(code);
const url = relayOrigin(address || DEFAULT_RELAY);
@@ -238,8 +239,8 @@ export async function relayJoin(root, code, address, io) {
const file = linkFile(root);
if (existsSync(file)) throw new Refused('RELAY_LINKED', 'this clone already has relay link metadata; use a fresh clone to join another device');
const machine = updateRelayMachine(state => state.machine);
- // The linked computer lists this one by its host name, in relay devices and before relay off.
- const issued = await relayRequest(url, signed.token, '/auth/machines', { board: bundle.board, machine, host: hostname() });
+ // Only a person's explicit label travels to other computers; never send this host or path.
+ const issued = await relayRequest(url, signed.token, '/auth/machines', { board: bundle.board, machine, ...(label === undefined ? {} : { name: label }) });
if (!TOKEN.test(issued.token) || issued.board !== bundle.board || issued.machine !== machine) throw new Refused('RELAY_RESPONSE', 'the relay did not issue this joined board’s machine credential; pair again');
let keyStorage;
try {
@@ -252,6 +253,7 @@ export async function relayJoin(root, code, address, io) {
version: 1, board: bundle.board, url: bundle.url, repository: bundle.repository,
mode: bundle.mode,
token: issued.token, tokenId: issued.id, machine, account: signed.user.id, keyStorage,
+ ...(label === undefined ? {} : { computerName: label }),
sequence: bundle.sequence, cursor: bundle.cursor,
});
} catch (error) {
diff --git a/src/relay-roster.js b/src/relay-roster.js
index 4af22951..8f4bd086 100644
--- a/src/relay-roster.js
+++ b/src/relay-roster.js
@@ -1,6 +1,7 @@
/** Who reads this computer's linked boards: paired phones and joined computers, by name [H17]. */
import { listApiProjects } from './projects.js';
import { readRelayMachine } from './relay-machine.js';
+import { computerName } from './computer-name.js';
import {
relayMachineContext,
relayRosterRead,
@@ -34,15 +35,15 @@ export async function joinedComputers(state) {
if (!Array.isArray(document?.machines)) return [];
return document.machines.filter(entry => MACHINE.test(entry?.machine ?? '') && entry.machine !== state.machine).map(entry => ({
machine: entry.machine,
- host: typeof entry.host === 'string' && entry.host ? entry.host : null,
+ name: typeof entry.name === 'string' ? computerName(entry.name) : null,
created: Number.isSafeInteger(entry.created) ? entry.created : null,
seen: Number.isSafeInteger(entry.seen) ? entry.seen : null,
}));
}
/** Name a joined computer by its host, or by the end of its id when it joined before hosts were recorded. */
-function computerName(computer) {
- return computer.host ?? 'computer ' + computer.machine.slice(-8);
+function computerDisplayName(computer) {
+ return computer.name ?? 'computer ' + computer.machine.slice(-8);
}
/** List the phones that hold one linked board's key, by id, with the relay's last seen and revoked status. */
@@ -85,7 +86,7 @@ export async function relayRoster({ verbose = false } = {}) {
for (const board of boards) {
for (const entry of await joinedComputers(board.state)) {
const known = computers.get(entry.machine) ?? { ...entry, boards: [] };
- known.host ??= entry.host;
+ known.name ??= entry.name;
known.created = Math.min(known.created ?? Infinity, entry.created ?? Infinity);
known.seen = Math.max(known.seen ?? -Infinity, entry.seen ?? -Infinity);
known.boards.push(board.name);
@@ -116,7 +117,7 @@ export function rosterLines(roster, { verbose = false } = {}) {
if (verbose) lines.push(` ${phone.deviceId}${phone.fingerprint ? ' fingerprint ' + phone.fingerprint : ''}`);
}
for (const computer of roster.computers) {
- lines.push(`${computerName(computer)} (computer): joined ${computer.created === null ? 'on an unknown date' : day(computer.created)}, last seen ${moment(computer.seen)}; ${reads(computer.boards)}`);
+ lines.push(`${computerDisplayName(computer)} (computer): joined ${computer.created === null ? 'on an unknown date' : day(computer.created)}, last seen ${moment(computer.seen)}; ${reads(computer.boards)}`);
if (verbose) lines.push(` ${computer.machine}`);
}
if (!lines.length) lines.push('No phones or computers are paired yet. Pair a phone with pullboard relay on --all, or another computer with pullboard relay pair.');
diff --git a/src/relay-setup.js b/src/relay-setup.js
index 86f4241d..de531833 100644
--- a/src/relay-setup.js
+++ b/src/relay-setup.js
@@ -1,5 +1,6 @@
/** Set up a machine once, enroll its phone in the foreground and link later registrations [H5,H17]. */
import { join } from 'node:path';
+import { computerName } from './computer-name.js';
import { randomUUID } from 'node:crypto';
import { createInterface } from 'node:readline';
import * as store from './board.js';
@@ -399,7 +400,8 @@ async function pairFirstDevice(session, board, linked, io, { signal, onPairingUR
}
/** Explicit foreground sign-in repairs links; only board machine credentials survive this command. */
-export async function relayOnAll(address, io, { signal, onPairingURL, onSignIn, onLinking, onBoardOutcome, pairAdditional = false } = {}) {
+export async function relayOnAll(address, io, { signal, onPairingURL, onSignIn, onLinking, onBoardOutcome, pairAdditional = false, name } = {}) {
+ const label = computerName(name);
requirePersonChannel(io.personChannel);
// A cancelled or declined sign-in must not migrate machine state or scrub existing board links.
const owner = relayMachineOwner();
@@ -423,6 +425,7 @@ export async function relayOnAll(address, io, { signal, onPairingURL, onSignIn,
// From this synchronous commit point onward the first board-link attempt is underway; later
// cancellation must not claim that already-started link writes were rolled back.
onLinking?.();
+ if (label !== undefined) updateRelayMachine(machine => { machine.computerName = label; });
// The view's sign-in links every board itself; a terminal run waits for cards already on the phone.
const waiting = onPairingURL ? [] : waitingLinkApprovals(session);
const waitingIds = new Set(waiting.map(entry => entry.context.id));
@@ -449,13 +452,13 @@ export async function relayOnAll(address, io, { signal, onPairingURL, onSignIn,
* @param {{pairAdditional?: boolean}} options - Explicitly enroll one more browser; default setup stays idempotent.
* @returns {Promise<number>}
*/
-export async function relayOnAllCommand(address, io, { pairAdditional = false } = {}) {
+export async function relayOnAllCommand(address, io, { pairAdditional = false, name } = {}) {
const controller = new AbortController();
const cancelSignIn = () => controller.abort();
process.once('SIGINT', cancelSignIn);
process.once('SIGTERM', cancelSignIn);
let result;
- try { result = await relayOnAll(address, io, { signal: controller.signal, pairAdditional }); }
+ try { result = await relayOnAll(address, io, { signal: controller.signal, pairAdditional, name }); }
finally { process.off('SIGINT', cancelSignIn); process.off('SIGTERM', cancelSignIn); }
io.result?.(result);
if (result.outcome) {
diff --git a/src/relay.js b/src/relay.js
index 23b1e2c1..c5c8a5fd 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -131,6 +131,7 @@ import {
queueMove,
} from './relay-outbox.js';
import { stampCoordinatorHolder } from './coordinator-hold.js';
+import { computerName } from './computer-name.js';
import { relayFiles } from './local-state.js';
import {
archiveRelinkOutbox,
@@ -1166,7 +1167,7 @@ export async function relayOperation(root, operation, args, io, command, applyLo
try {
if (!move) {
const sent = withSeatName(root, operation, args);
- move = stampCoordinatorHolder(localRecords(root, (board) => prepareEngineMove(board, operation, sent, io.personRequestMoveId ? { id: io.personRequestMoveId } : {})), state.machine);
+ move = stampCoordinatorHolder(localRecords(root, (board) => prepareEngineMove(board, operation, sent, io.personRequestMoveId ? { id: io.personRequestMoveId } : {})), state.machine, state.computerName);
requestedMove = move;
if (io.personRequest) move.personRequest = structuredClone(io.personRequest);
const problem = move.personRequest && localRecords(root, board => requestMoveProblem(board, move, { checkExecutorLease: false }));
@@ -1568,7 +1569,8 @@ async function deviceSignIn(url, io, { signal, intent, onSignIn } = {}) {
}
/** Explicitly sign in through the relay and persist a sealed initial snapshot before uploading it. */
-export async function relayOn(root, address, io, { session, credential, quiet = false, strict = false } = {}) {
+export async function relayOn(root, address, io, { session, credential, quiet = false, strict = false, name } = {}) {
+ const label = computerName(name);
const remoteShell = io.personChannel !== 'view' && isRemoteShell();
const reusableSession = remoteShell ? undefined : session;
const reusableCredential = remoteShell ? undefined : credential;
@@ -1619,7 +1621,8 @@ export async function relayOn(root, address, io, { session, credential, quiet =
saveLink(file, state);
}
const machine = updateRelayMachine(settings => settings.machine);
- const issued = reusableCredential ?? await request({ ...state, token: signed.token }, '/auth/machines', { method: 'POST', body: { board: state.board, machine } }, io);
+ const named = computerName(label ?? state.computerName ?? readRelayMachine().computerName);
+ const issued = reusableCredential ?? await request({ ...state, token: signed.token }, '/auth/machines', { method: 'POST', body: { board: state.board, machine, ...(named === undefined ? {} : { name: named }) } }, io);
if (!/^pm_[A-Za-z0-9_-]{43}$/u.test(issued.token ?? '') || issued.board !== state.board || issued.machine !== machine) throw new Refused('RELAY_RESPONSE', 'the relay did not issue this board’s machine credential; sign in again');
// Cached agent credentials belong to the account that minted them.
if (state.account !== account) { delete state.agentTokens; delete state.login; }
@@ -1630,6 +1633,7 @@ export async function relayOn(root, address, io, { session, credential, quiet =
state.token = issued.token;
state.tokenId = issued.id;
state.machine = machine;
+ if (named !== undefined) state.computerName = named;
delete state.personReauth;
saveLink(file, state);
// The person's own sign-in sets up the coordinator's token, so no agent can mint it (#579).
@@ -1679,7 +1683,7 @@ export async function relayOff(root, io) {
let joined = [];
try {
const roster = await request(state, '/auth/machines?board=' + state.board, {}, io);
- if (Array.isArray(roster.machines)) joined = roster.machines.filter(entry => typeof entry.machine === 'string' && /^[A-Za-z0-9_.-]{1,128}$/u.test(entry.machine) && entry.machine !== state.machine).map(entry => ({ machine: entry.machine, name: typeof entry.host === 'string' && entry.host.trim() ? entry.host : entry.machine.slice(-8) }));
+ if (Array.isArray(roster.machines)) joined = roster.machines.filter(entry => typeof entry.machine === 'string' && /^[A-Za-z0-9_.-]{1,128}$/u.test(entry.machine) && entry.machine !== state.machine).map(entry => ({ machine: entry.machine, name: typeof entry.name === 'string' ? computerName(entry.name) : 'computer ' + entry.machine.slice(-8) }));
} catch { /* Local unlink still completes when the relay cannot inventory joined computers. */ }
const warning = joined.length ? ' If you approve deletion, joined computers ' + joined.map(entry => entry.name).join(', ') + ' lose the shared copy; their local boards keep working.' : '';
if (warning) io.err(warning.trim());
diff --git a/test/relay-computer-name.test.js b/test/relay-computer-name.test.js
index 47e9c582..602a800d 100644
--- a/test/relay-computer-name.test.js
+++ b/test/relay-computer-name.test.js
@@ -4,6 +4,12 @@ import { hostname } from 'node:os';
import { test } from 'node:test';
import { relayClientFixture } from './relay-client-fixture.js';
import { relayWorkBudgetMs } from './relay-budget.js';
+import { computerLabel } from '../src/coordinator-hold.js';
+import { computerName } from '../src/computer-name.js';
+import { requireCoordinatorHold } from '../src/coordinator-hold.js';
+import { coordinatorHolder } from '../src/coordinator-hold.js';
+import { COMPUTER_NAME_ENGINE } from '../src/computer-name-engine.js';
+import { openBoard, closeBoard } from '../src/board.js';
test('linked computers use person-given names in coordinator holds and devices [E19,H16]', { timeout: relayWorkBudgetMs(12) }, async t => { // budget: real two-device CLI sign-in, pairing, takeover and cleanup; no speed target.
const box = await relayClientFixture(t);
@@ -31,3 +37,22 @@ test('linked computers use person-given names in coordinator holds and devices [
}
}
});
+
+test('unnamed computers retain ID-tail labels and invalid names are refused [E19,H16]', () => {
+ assert.equal(computerLabel('machine-1234567890'), 'computer 34567890');
+ assert.equal(computerLabel(undefined), 'another main checkout');
+ assert.equal(computerName(undefined), undefined);
+ assert.equal(computerName(' Writing desk '), 'Writing desk');
+ for (const name of ['', ' ', '/Users/private/computer', 'C:\\private', 'two\nlines', 'a'.repeat(81), null]) {
+ assert.throws(() => computerName(name), { code: 'BAD_COMPUTER_NAME' });
+ }
+});
+
+test('older coordinator hold receipts retain their ID-tail display [E19,H16]', () => {
+ const board = openBoard(':memory:');
+ try {
+ requireCoordinatorHold(board, { operation: 'addItem', engine: COMPUTER_NAME_ENGINE - 1,
+ holder: 'machine-1234567890', holderName: 'Unrecognized future field' }, 'person-lineage', '2026-10-25T00:00:00Z');
+ assert.equal(coordinatorHolder(board).label, 'computer 34567890');
+ } finally { closeBoard(board); }
+});
diff --git a/test/relay-setup.test.js b/test/relay-setup.test.js
index d6f319fe..ce586b41 100644
--- a/test/relay-setup.test.js
+++ b/test/relay-setup.test.js
@@ -2,7 +2,7 @@
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
-import { hostname, tmpdir } from 'node:os';
+import { tmpdir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { test } from 'node:test';
@@ -273,7 +273,7 @@ async function phoneAndJoinedComputer(t) {
const phone = await pairPhone(box, t);
const printed = await box.cli('relay', 'pair');
assert.equal(printed.code, 0, 'the linked computer prints a one-time code');
- const joined = await box.otherDeviceJoin(printed.document.code);
+ const joined = await box.otherDeviceJoin(printed.document.code, 'Study computer');
return { box, phone, joined };
}
@@ -305,8 +305,8 @@ test('relay devices names phones and joined computers with paired date and board
'the phone line has its paired date, a last seen time and the board it reads');
const computerLine = lines.find(line => line.includes('(computer): '));
assert.ok(computerLine, 'the joined computer is listed on the linked computer');
- assert.match(computerLine, new RegExp(`^${hostname().replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')} \\(computer\\): joined ${day(Date.now())}, last seen (?!unknown)[^;]+; reads ${board}$`, 'u'),
- 'the joined computer is named by its host name, with its joined date, last seen and board');
+ assert.match(computerLine, new RegExp(`^Study computer \\(computer\\): joined ${day(Date.now())}, last seen (?!unknown)[^;]+; reads ${board}$`, 'u'),
+ 'the joined computer is named by the person, with its joined date, last seen and board');
assert.equal(lines.length, 2, 'one line each, with no ids');
assert.ok(!/[0-9a-f]{64}/u.test(lines.join('\n')) && !lines.join('\n').includes(phone.deviceId), 'ids and fingerprints stay out of the default view');
const verbose = await devicesText(box, ['--verbose']);
@@ -357,14 +357,14 @@ test('relay devices names phones and joined computers with paired date and board
assert.deepEqual(afterRevokeThere.document.devices, [], 'the other computer does not restore the revoked phone from local history');
});
-test('relay off names joined computers by host name [H17]', async (t) => {
+test('relay off names joined computers by the person-given name [H17]', async (t) => {
const { box, joined } = await phoneAndJoinedComputer(t);
const off = await box.cli('relay', 'off');
assert.equal(off.code, 0, 'relay off unlinks this computer');
- assert.deepEqual(off.document.joined, [hostname()], 'the joined computer is named by its host name');
+ assert.deepEqual(off.document.joined, ['Study computer'], 'the joined computer is named by the person');
assert.deepEqual(off.document.affectedMachines, [joined.machine], 'the stable machine id stays beside the name');
- assert.ok(off.document.notice.includes('If you approve deletion, joined computers ' + hostname() + ' lose the shared copy'),
- 'the warning names the joined computer by host before the phone approves the delete');
+ assert.ok(off.document.notice.includes('If you approve deletion, joined computers Study computer lose the shared copy'),
+ 'the warning names the joined computer by its explicit name before the phone approves the delete');
});
test('relay join names the board it joined [H17]', async (t) => {