diff --git a/docs/GLOSSARY.md b/docs/GLOSSARY.md index cbbdd4c0e5..ee74400fe5 100644 --- a/docs/GLOSSARY.md +++ b/docs/GLOSSARY.md @@ -91,6 +91,8 @@ Use these terms in issues, PRs, comments, and docs. If you need a term that is n - **Block (a device):** a setting on one computer that refuses every Bridge call, stream and request from one other device, at once. It is kept on that computer only, needs no authority, and is undone with Unblock. - **Highest permission mode (for a device):** the most permissive permission mode a person on another computer can run a turn or create an "Always" rule in on this computer, and the most a remote subagent that computer's agents start here can run in. A new computer starts at Auto-accept edits. - **Agent reach (for a device):** which threads of this computer another computer's agents may change (start, message, steer, stop), set beside its highest permission mode in Settings → Devices → Limits ("Agents on may change"; or `mousse-cli bridge limits --agent-reach`): Nothing, Threads they started (the default) or All threads. Reading follows the device's ordinary access. It is a rule for a computer that marks its agents' calls as it should, not a barrier: blocking the device and its highest permission mode are the controls for one that is not trusted. +- **Work on threads from this device:** the per-device switch on one computer (Settings → Devices → Limits, or `mousse-cli bridge limits --work on|off`) that lets another device start, send to, steer, stop and change threads there, see its files and Git, and make or change bots. It is on by default. Off, the device still reads threads and chats with bots (within each bot's own permissions), and every other call from it, a person's or an agent's, is refused with the reason `work_off`. Which call is which is the access table, `src/shared/net/accessClasses.ts`. +- **Access from this device (presets):** three choices on a computer's row in Settings → Devices that set its switches at once: **View and chat** (reads threads and chats with bots; work, terminals and editor off), **Work on threads** (the defaults) and **Full control** (terminals and editor on, Full access, agents may change all threads). Switches that match none show as Custom. Phones have none. The presets are in `src/shared/net/accessPresets.ts`. - **Share bots with other devices:** the switch on each computer (Settings, Devices; or `mousse-cli bridge bots on|off`) that lets the user's phones and other computers list this computer's personal bots and chat with them. It is on by default and stored on that computer. While it is off, the lists other devices read carry no bots and every `bots.*` call they make is refused (`forbidden`, reason `setting_off`). - **Devices (of a bot):** which of the owner's devices reach one personal bot, set in its About on the computer that holds it: All my devices (the default), Only this computer, or Chosen devices. **Bots on this computer** is the switch per device in Settings, Devices that lets that device reach none of the bots there. A device that is left out finds no such bot: it is in none of its lists, and every call about it answers as for a bot that is not there. See `docs/bots.md`, Two layers. - **Editor connections from this device:** the per-device switch on the computer that runs a thread that lets one other computer open its editor on this computer's folders: its `ssh` signs in to this computer, carried inside Mousse Net, and always ends there (the other computer never names a host or a port): at Mousse's own SSH server inside the daemon, which needs no SSH server, no key and no setup on this computer, or at the computer's own SSH server when its owner chose "Use this computer's SSH server". It is off by default and separate from "Terminals from this device". It ends at once when the device is blocked, the switch (or "Let my other computers work on this computer's threads") goes off, the device loses "Works on threads" or is revoked, or Net is turned off. It is the same as shell access for the user on that computer. A Windows computer uses its own OpenSSH server instead only when the endpoint's helper is missing or does not run. diff --git a/src/cli/commands/net.ts b/src/cli/commands/net.ts index dc3fbe3081..f2c9e0adba 100644 --- a/src/cli/commands/net.ts +++ b/src/cli/commands/net.ts @@ -100,7 +100,7 @@ export const BRIDGE_HELP = `Usage: mousse-cli bridge connect mousse-cli bridge disconnect mousse-cli bridge limits [--max-mode ask|accept_edits|auto|full] [--terminal on|off] - [--editor on|off] [--bots on|off] [--agent-reach none|launched|all] + [--editor on|off] [--bots on|off] [--agent-reach none|launched|all] [--work on|off] mousse-cli bridge caps --caps read,chat,write,settings mousse-cli bridge kind computer|phone mousse-cli bridge threads [on|off] @@ -119,7 +119,9 @@ default and only changes this computer. Only the current authority can invite, revoke or rename nodes, change capabilities or set a device's kind. block, unblock and limits act on this computer only, on any computer: a blocked device is refused every Bridge call and stream here until unblocked. limits --bots off keeps -one device from every personal bot on this computer. +one device from every personal bot on this computer. limits --work off lets one device view +threads and chat with bots only: it can't start, send to, change or stop threads, or make or +change bots, here. connect and disconnect also act on this computer only: a device of your list that is not connected here gets nothing from it, and two computers open no session until each connected the other. Disconnect ends the device's streams and editor connections here; what it started runs on. @@ -362,7 +364,7 @@ export function prepareNetCommand(args: ParsedArgs): NetCliRequest { 'bridge.rename': [], 'bridge.setCaps': ['caps'], 'bridge.setKind': [], - 'bridge.policy': args.subcommand === 'limits' ? ['max-mode', 'terminal', 'editor', 'bots', 'agent-reach'] : [], + 'bridge.policy': args.subcommand === 'limits' ? ['max-mode', 'terminal', 'editor', 'bots', 'agent-reach', 'work'] : [], 'bridge.connect': [], 'bridge.disconnect': [], 'bridge.workOnThreads': [], @@ -645,16 +647,18 @@ export function prepareNetCommand(args: ParsedArgs): NetCliRequest { terminal = stringFlag(args, 'terminal'), editor = stringFlag(args, 'editor'), bots = stringFlag(args, 'bots'), - reach = stringFlag(args, 'agent-reach') + reach = stringFlag(args, 'agent-reach'), + work = stringFlag(args, 'work') if ( mode === undefined && terminal === undefined && editor === undefined && bots === undefined && - reach === undefined + reach === undefined && + work === undefined ) invalid( - 'bridge limits requires --max-mode ask|accept_edits|auto|full, --terminal on|off, --editor on|off, --bots on|off and/or --agent-reach none|launched|all.' + 'bridge limits requires --max-mode ask|accept_edits|auto|full, --terminal on|off, --editor on|off, --bots on|off, --agent-reach none|launched|all and/or --work on|off.' ) if (mode !== undefined) { if (!isPermissionMode(mode)) invalid('--max-mode requires ask, accept_edits, auto or full.') @@ -676,6 +680,10 @@ export function prepareNetCommand(args: ParsedArgs): NetCliRequest { if (!isAgentReach(reach)) invalid('--agent-reach requires none, launched or all.') params.agentReach = reach } + if (work !== undefined) { + if (work !== 'on' && work !== 'off') invalid('--work requires on or off.') + params.work = work === 'on' + } } } return { diff --git a/src/mms/bridge/routed/computerErrors.ts b/src/mms/bridge/routed/computerErrors.ts index d5c2dbb360..186ddd89b2 100644 --- a/src/mms/bridge/routed/computerErrors.ts +++ b/src/mms/bridge/routed/computerErrors.ts @@ -34,6 +34,7 @@ const FORBIDDEN_WORDS: Record string> `This computer is not allowed to work on threads on ${name}. Turn on Works on threads for this computer in Settings, Devices, on the computer that manages your devices.`, terminal_off: terminalOffMessage, not_connected: (name) => `${name} hasn't connected this computer.`, + work_off: (name) => `${name} lets this computer view threads and chat with bots only.`, unknown: (name) => `${name} refused this request.` } diff --git a/src/mms/net/NetService.ts b/src/mms/net/NetService.ts index ec66422e6d..6a198890aa 100644 --- a/src/mms/net/NetService.ts +++ b/src/mms/net/NetService.ts @@ -37,6 +37,12 @@ import { newId, isId } from '../../shared/net' +import { + methodAccess, + needsWork, + ROUTED_STREAM_ACCESS, + STREAM_ACCESS +} from '../../shared/net/accessClasses' import type { NetAddonActionResult, NetAddonRecords, @@ -160,7 +166,8 @@ const policyView = (policy: NodePolicy): BridgeNodePolicy => ({ terminal: policy.terminal, editor: policy.editor, bots: policy.bots, - agentReach: policy.agentReach + agentReach: policy.agentReach, + work: policy.work }) interface NetConfiguration { @@ -215,6 +222,8 @@ const CONTROL_METHOD = /^authority\.transfer\./ /** The refusal of a device of this user's list that is not connected here. */ const notConnected = () => new NetError('forbidden', undefined, { details: { reason: 'not_connected' } }) +/** The refusal of a device this computer lets view threads and chat with bots only. */ +const workOff = () => new NetError('forbidden', undefined, { details: { reason: 'work_off' } }) /** * The other devices of this computer's list now (not this one, none revoked), read with the pinned root key so a * locked key store reads it too. Undefined when the list cannot be read; empty when this computer has none. @@ -613,6 +622,10 @@ export class NetService { if (method.needsTerminal && !policy.get(peer.node).terminal) throw new NetError('forbidden', undefined, { details: { reason: 'terminal_off' } }) } + // "Work on threads from this device" off: the device views threads and chats with bots, and every call + // that would start, change or stop work is refused, in every family, a saved result's lookup included. + if (needsWork(methodAccess(method.method)) && !policy.get(peer.node).work) + throw workOff() } }), transfer = new AuthorityTransferDelivery({ db, identity, keys }) @@ -1163,6 +1176,7 @@ export class NetService { ...(params.terminal === undefined ? {} : { terminal: params.terminal as boolean }), ...(params.editor === undefined ? {} : { editor: params.editor as boolean }), ...(params.bots === undefined ? {} : { bots: params.bots as boolean }), + ...(params.work === undefined ? {} : { work: params.work as boolean }), ...(params.agentReach === undefined ? {} : { agentReach: params.agentReach as AgentReach }) @@ -2093,9 +2107,19 @@ export class NetService { // A device this computer blocked reads, fetches and writes none of its Bridge streams. A device of this user's // list that is not connected here has none of its streams, its Spaces' included (another user's device is // governed by its Space membership alone). + // A stream whose kind is work (none is today) is not for a device that may only view and chat with bots; the + // class is read first, so the record-by-record check costs no query for the kinds every device reads. + const streamWorkOff = (stream: StreamId, peer: { node: NodeId }): boolean => { + const kind = store.getStream(stream)?.kind + if (!kind) return false + const own = this.domain?.privateStreams?.access(stream) + const access = own ? ROUTED_STREAM_ACCESS[own.kind] : STREAM_ACCESS[kind] + return needsWork(access) && !rt.policy.get(peer.node).work + } const blockedFor = (stream: StreamId, peer: { node: NodeId; user: UserId }): boolean => !this.connectedHere(peer) || - (!store.getStream(stream)?.kind.startsWith('space.') && rt.policy.isBlocked(peer.node)) + (!store.getStream(stream)?.kind.startsWith('space.') && + (rt.policy.isBlocked(peer.node) || streamWorkOff(stream, peer))) // A private stream is read by its computer only, while the owner's switch for other computers is on // (read on every record, so turning it off is also a kill switch) and, for a terminal, the device's // terminal switch is on. The authority checks the reader and "Works on threads". diff --git a/src/mms/net/registerMethods.ts b/src/mms/net/registerMethods.ts index a20aa12419..a54cde860b 100644 --- a/src/mms/net/registerMethods.ts +++ b/src/mms/net/registerMethods.ts @@ -81,7 +81,7 @@ const keys: Record = { 'bridge.rename': ['node', 'name'], 'bridge.setCaps': ['node', 'caps'], 'bridge.setKind': ['node', 'kind'], - 'bridge.policy': ['node', 'blocked', 'maxPermissionMode', 'terminal', 'editor', 'bots', 'agentReach'], + 'bridge.policy': ['node', 'blocked', 'maxPermissionMode', 'terminal', 'editor', 'bots', 'agentReach', 'work'], 'bridge.connect': ['node'], 'bridge.disconnect': ['node'], 'bridge.workOnThreads': ['enabled'], @@ -285,9 +285,12 @@ function validate(method: NetLocalMethod, value: unknown): Record + Pick< + NodePolicy, + 'blocked' | 'maxPermissionMode' | 'terminal' | 'editor' | 'bots' | 'agentReach' | 'work' + > > export { AGENT_REACHES, isAgentReach, type AgentReach } @@ -49,6 +58,8 @@ export const DEFAULT_TERMINAL_ACCESS = false export const DEFAULT_EDITOR_ACCESS = false /** Every device reaches this computer's bots until the owner switches bots off for it (as before the switch existed). */ export const DEFAULT_BOTS_ACCESS = true +/** Every device works on threads here until the owner makes it view only (as before the switch existed). */ +export const DEFAULT_WORK_ACCESS = true export interface NodePolicyEvent { node: NodeId @@ -64,10 +75,11 @@ interface Row { editor: number bots: number agent_reach: string + work: number created_at: number } -const COLUMNS = 'node,blocked,max_permission_mode,terminal,editor,bots,agent_reach,created_at' +const COLUMNS = 'node,blocked,max_permission_mode,terminal,editor,bots,agent_reach,work,created_at' /** `net_node_policy`, in the Net database. A node without a row has the defaults. */ export class SqliteNodePolicy { @@ -112,6 +124,7 @@ export class SqliteNodePolicy { (change.terminal !== undefined && typeof change.terminal !== 'boolean') || (change.editor !== undefined && typeof change.editor !== 'boolean') || (change.bots !== undefined && typeof change.bots !== 'boolean') || + (change.work !== undefined && typeof change.work !== 'boolean') || (change.maxPermissionMode !== undefined && !isPermissionMode(change.maxPermissionMode)) || (change.agentReach !== undefined && !isAgentReach(change.agentReach)) ) @@ -125,6 +138,7 @@ export class SqliteNodePolicy { ...(change.terminal === undefined ? {} : { terminal: change.terminal }), ...(change.editor === undefined ? {} : { editor: change.editor }), ...(change.bots === undefined ? {} : { bots: change.bots }), + ...(change.work === undefined ? {} : { work: change.work }), ...(change.agentReach === undefined ? {} : { agentReach: change.agentReach }), ...(change.maxPermissionMode === undefined ? {} @@ -133,8 +147,8 @@ export class SqliteNodePolicy { this.db.charge(1) this.db.database .prepare( - 'INSERT INTO net_node_policy(node,blocked,max_permission_mode,terminal,editor,bots,agent_reach,created_at) VALUES(?,?,?,?,?,?,?,?) ' + - 'ON CONFLICT(node) DO UPDATE SET blocked=excluded.blocked,max_permission_mode=excluded.max_permission_mode,terminal=excluded.terminal,editor=excluded.editor,bots=excluded.bots,agent_reach=excluded.agent_reach' + 'INSERT INTO net_node_policy(node,blocked,max_permission_mode,terminal,editor,bots,agent_reach,work,created_at) VALUES(?,?,?,?,?,?,?,?,?) ' + + 'ON CONFLICT(node) DO UPDATE SET blocked=excluded.blocked,max_permission_mode=excluded.max_permission_mode,terminal=excluded.terminal,editor=excluded.editor,bots=excluded.bots,agent_reach=excluded.agent_reach,work=excluded.work' ) .run( node, @@ -144,6 +158,7 @@ export class SqliteNodePolicy { after.editor ? 1 : 0, after.bots ? 1 : 0, after.agentReach, + after.work ? 1 : 0, after.createdAt || this.clock.now() ) event = { node, before, after: this.get(node) } @@ -179,6 +194,7 @@ export class SqliteNodePolicy { editor: DEFAULT_EDITOR_ACCESS, bots: DEFAULT_BOTS_ACCESS, agentReach: DEFAULT_AGENT_REACH, + work: DEFAULT_WORK_ACCESS, createdAt: 0 } } @@ -197,6 +213,8 @@ export class SqliteNodePolicy { bots: row.bots === 1, // A value this version does not know reaches nothing. agentReach: isAgentReach(row.agent_reach) ? row.agent_reach : 'none', + // Only a stored 1 is on: a value this version does not know leaves the device to view and chat with bots. + work: row.work === 1, createdAt: row.created_at } } diff --git a/src/renderer/components/NetDevicesSection.tsx b/src/renderer/components/NetDevicesSection.tsx index e628dc2a99..a04dd90c73 100644 --- a/src/renderer/components/NetDevicesSection.tsx +++ b/src/renderer/components/NetDevicesSection.tsx @@ -16,6 +16,7 @@ import { DeviceLimitsDialog } from './devices/DeviceLimitsDialog' import { DeviceActivityRows } from './devices/DeviceActivityRows' import { DeviceAccessRows } from './devices/DeviceAccessRows' import { DeviceBotsRow } from './devices/DeviceBotsRow' +import { DevicePresetRow } from './devices/DevicePresetRow' import { pendingEditorAsk, useEditorAskStore } from '../stores/editorAskStore' import { connectedHere, connectStep, joinErrorWords, netErrorWords, startOverRefusal, bindSettings, workOnThreadsDisclosure, canWorkOnThreads, deviceLine, isComputer, isIncompatible, listedDevices, readDevices, routeDetails, serveSettings, sshRecordFor, updateInstructions, worksOnThreads, WORKS_ON_THREADS, type Device } from '../lib/netDevices' import type { NetDoctor, NetStatus } from '../../shared/net' @@ -506,6 +507,10 @@ export function NetDevicesSection() { : selfDevice?.version && } /> ), + // What it may do here, as one of three presets above the single switches. A phone has none. + connected && device.policy && isComputer(device) && worksOnThreads(device) && !device.policy.blocked && ( + + ), // Terminals and editor connections from it, side by side, with a waiting ask answered here too. connected && device.policy && isComputer(device) && worksOnThreads(device) && !device.policy.blocked && ( (policy.agentReach) - const changed = mode !== policy.maxPermissionMode || terminal !== policy.terminal || editor !== policy.editor || reach !== policy.agentReach + const [work, setWork] = useState(policy.work) + const changed = mode !== policy.maxPermissionMode || terminal !== policy.terminal || editor !== policy.editor || reach !== policy.agentReach || work !== policy.work const save = async () => { const answer = await call('bridge.policy', { node, + ...(work !== policy.work ? { work } : {}), ...(mode !== policy.maxPermissionMode ? { maxPermissionMode: mode } : {}), ...(terminal !== policy.terminal ? { terminal } : {}), ...(editor !== policy.editor ? { editor } : {}), @@ -55,6 +57,10 @@ export function DeviceLimitsDialog({ node, name, policy, onClose, onDone }: { >

These apply here only. {name} keeps its own limits for what this computer may do there.

+ {work !== undefined &&
+ Work on threads from this device + +
}