Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <device> may change"; or `mousse-cli bridge limits <node> --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 <node> --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.
Expand Down
20 changes: 14 additions & 6 deletions src/cli/commands/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const BRIDGE_HELP = `Usage:
mousse-cli bridge connect <node-id>
mousse-cli bridge disconnect <node-id>
mousse-cli bridge limits <node-id> [--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 <node-id> --caps read,chat,write,settings
mousse-cli bridge kind <node-id> computer|phone
mousse-cli bridge threads [on|off]
Expand All @@ -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.
Expand Down Expand Up @@ -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': [],
Expand Down Expand Up @@ -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.')
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/mms/bridge/routed/computerErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const FORBIDDEN_WORDS: Record<ComputerForbiddenReason, (name: string) => 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.`
}

Expand Down
28 changes: 26 additions & 2 deletions src/mms/net/NetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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".
Expand Down
7 changes: 5 additions & 2 deletions src/mms/net/registerMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const keys: Record<NetLocalMethod, readonly string[]> = {
'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'],
Expand Down Expand Up @@ -285,9 +285,12 @@ function validate(method: NetLocalMethod, value: unknown): Record<string, unknow
params.terminal === undefined &&
params.editor === undefined &&
params.bots === undefined &&
params.agentReach === undefined
params.agentReach === undefined &&
params.work === undefined
)
throw new DomainRpcError('invalid_params', 'Choose a limit to change')
if (params.work !== undefined && typeof params.work !== 'boolean')
throw new DomainRpcError('invalid_params', 'work must be boolean')
if (params.blocked !== undefined && typeof params.blocked !== 'boolean')
throw new DomainRpcError('invalid_params', 'blocked must be boolean')
if (params.terminal !== undefined && typeof params.terminal !== 'boolean')
Expand Down
7 changes: 6 additions & 1 deletion src/mms/net/store/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export class NetDatabase {
this.database.exec(
"ALTER TABLE net_node_policy ADD COLUMN agent_reach TEXT NOT NULL DEFAULT 'launched'"
)
// "Work on threads from this device": on for every device that already has a row, as before the switch.
if (!has('net_node_policy', 'work'))
this.database.exec(
'ALTER TABLE net_node_policy ADD COLUMN work INTEGER NOT NULL DEFAULT 1 CHECK(work IN (0,1))'
)
// Who made a routed call: null for a person on the device, `agent` for a call marked as an agent's.
if (!has('bridge_audit', 'actor'))
this.database.exec('ALTER TABLE bridge_audit ADD COLUMN actor TEXT')
Expand Down Expand Up @@ -366,7 +371,7 @@ CREATE TABLE IF NOT EXISTS net_quota_reservations(scope TEXT NOT NULL REFERENCES
CREATE TABLE IF NOT EXISTS net_rate_config(scope TEXT NOT NULL, principal TEXT NOT NULL, max_units INTEGER NOT NULL, window_ms INTEGER NOT NULL, last_now INTEGER NOT NULL, PRIMARY KEY(scope,principal)) STRICT;
CREATE TABLE IF NOT EXISTS net_rate_charges(scope TEXT NOT NULL, principal TEXT NOT NULL, id TEXT NOT NULL, created_at INTEGER NOT NULL, units INTEGER NOT NULL, PRIMARY KEY(scope,principal,id), FOREIGN KEY(scope,principal) REFERENCES net_rate_config(scope,principal)) STRICT;
CREATE INDEX IF NOT EXISTS net_rate_window ON net_rate_charges(scope,principal,created_at);
CREATE TABLE IF NOT EXISTS net_node_policy(node TEXT PRIMARY KEY, blocked INTEGER NOT NULL CHECK(blocked IN (0,1)), max_permission_mode TEXT NOT NULL, terminal INTEGER NOT NULL CHECK(terminal IN (0,1)), editor INTEGER NOT NULL DEFAULT 0 CHECK(editor IN (0,1)), bots INTEGER NOT NULL DEFAULT 1 CHECK(bots IN (0,1)), agent_reach TEXT NOT NULL DEFAULT 'launched', created_at INTEGER NOT NULL) STRICT;
CREATE TABLE IF NOT EXISTS net_node_policy(node TEXT PRIMARY KEY, blocked INTEGER NOT NULL CHECK(blocked IN (0,1)), max_permission_mode TEXT NOT NULL, terminal INTEGER NOT NULL CHECK(terminal IN (0,1)), editor INTEGER NOT NULL DEFAULT 0 CHECK(editor IN (0,1)), bots INTEGER NOT NULL DEFAULT 1 CHECK(bots IN (0,1)), agent_reach TEXT NOT NULL DEFAULT 'launched', work INTEGER NOT NULL DEFAULT 1 CHECK(work IN (0,1)), created_at INTEGER NOT NULL) STRICT;
CREATE TABLE IF NOT EXISTS bridge_audit(id INTEGER PRIMARY KEY AUTOINCREMENT, at INTEGER NOT NULL, node TEXT NOT NULL, kind TEXT NOT NULL CHECK(kind IN ('change','refused')), method TEXT NOT NULL, thread TEXT, project TEXT, outcome TEXT NOT NULL, actor TEXT) STRICT;
CREATE INDEX IF NOT EXISTS bridge_audit_node ON bridge_audit(node,kind,id);
CREATE TABLE IF NOT EXISTS bridge_audit_reads(node TEXT NOT NULL, hour INTEGER NOT NULL, calls INTEGER NOT NULL, bytes INTEGER NOT NULL, PRIMARY KEY(node,hour)) STRICT;
Expand Down
Loading
Loading