From d27bede8ec28f0ec8e9ff93e0d2eb03bb954e842 Mon Sep 17 00:00:00 2001 From: TheAnimatrix Date: Tue, 17 Nov 2026 19:01:31 +0530 Subject: [PATCH 1/3] feat(net): a device can be left to view threads and chat with bots Each computer keeps a new switch per device, "Work on threads from this device" (net_node_policy.work, on by default; a store from before it keeps every device on). Off, every call that starts, sends to, steers, stops or changes a thread, reads its files or Git, or makes or changes a bot is refused with the reason work_off, in every family and for a person's call and an agent's alike, also when a saved result is looked up. Reads and bot chat still pass. One table classes every remote method and stream kind as view, bots_chat, bots_manage, work, terminal or editor (src/shared/net/accessClasses.ts); a test reads the methods a real daemon registers and fails on one with no class. mousse-cli bridge limits takes --work on|off. --- docs/GLOSSARY.md | 2 + src/cli/commands/net.ts | 20 +- src/mms/bridge/routed/computerErrors.ts | 1 + src/mms/net/NetService.ts | 28 +- src/mms/net/registerMethods.ts | 7 +- src/mms/net/store/database.ts | 7 +- src/mms/net/store/nodePolicy.ts | 26 +- src/shared/net/accessClasses.ts | 339 ++++++++++++++++++ src/shared/net/errors.ts | 5 +- src/shared/net/local.ts | 6 + tests/net/bridge/nodePolicy.test.ts | 12 +- tests/net/bridge/routed/accessClasses.test.ts | 160 +++++++++ tests/net/cli/net.test.ts | 8 + tests/net/store/nodePolicyMigration.test.ts | 30 ++ 14 files changed, 631 insertions(+), 20 deletions(-) create mode 100644 src/shared/net/accessClasses.ts create mode 100644 tests/net/bridge/routed/accessClasses.test.ts diff --git a/docs/GLOSSARY.md b/docs/GLOSSARY.md index cbbdd4c0e5..14000b57d2 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 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/shared/net/accessClasses.ts b/src/shared/net/accessClasses.ts new file mode 100644 index 0000000000..a3ff8900ac --- /dev/null +++ b/src/shared/net/accessClasses.ts @@ -0,0 +1,339 @@ +import type { RoutedStreamKind } from '../bridge/routed' +import type { StreamKind } from './streams' + +/** + * What a call or stream from another device of the user's list does on this computer, as the receiver's per-device + * switches see it. Every remote method another device can call here (every family: routed, the Bridge remote API, + * the hub, bots, lists, speech and Net's own) and every stream kind has one class. A test reads the methods a real + * daemon registers (`tests/net/bridge/routed/accessClasses.test.ts`) and fails on one with no class, or a row here that + * names none, so a new method is classed when it is added. + * + * - `view`: reads threads, lists and what a transcript already shows, and the connection's own traffic. Passes for + * every device this computer serves. + * - `bots_chat`: a bot's chat, its replies, asks and pictures, and dictation; held to the device's Bots switch and each + * bot's Devices choice, and runs within the bot's own permissions. + * - `bots_manage`: makes a bot or changes one (its name, look, permissions, memory, schedules, pause). + * - `work`: starts, sends to, steers, stops or changes threads, their queue, settings, files and Git, projects, + * automations and agent chats; and reads that expose the computer's files (Files, Git, review). + * - `terminal`: opens, reads or types into a terminal (the device's terminal switch governs it). + * - `editor`: an editor connection or its folder (the device's editor switch governs it). + * + * "Work on threads from this device" off (`net_node_policy.work`) refuses `work` and `bots_manage` in every family, + * with the reason `work_off`. Kept apart from the rows of `ROUTED_METHODS` and keyed by the Net method name. + */ +export const ACCESS_CLASSES = ['view', 'bots_chat', 'bots_manage', 'work', 'terminal', 'editor'] as const +export type AccessClass = (typeof ACCESS_CLASSES)[number] + +const routed = (classes: Record): Record => + Object.fromEntries(Object.entries(classes).map(([name, value]) => [`routed.${name}`, value])) + +/** Every remote method by its Net name. A routed row is `routed.`; the phone API's rows keep their bare names. */ +export const METHOD_ACCESS: Readonly> = Object.freeze({ + // ---------------------------------------------------------------- Net itself + 'net.info': 'view', + 'net.direct.endpoints': 'view', + 'net.direct.webrtc.offer': 'view', + // Moving the keeper role: signed by the user's own keys, and never a thread's or a bot's. + 'authority.transfer.ready': 'view', + 'authority.transfer.import': 'view', + 'authority.transfer.activate': 'view', + 'authority.transfer.ack': 'view', + 'authority.transfer.retirement': 'view', + + // ---------------------------------------------------------------- the Bridge remote API (phones) + 'projects.list': 'view', + 'projects.match': 'view', + 'threads.list': 'view', + 'threads.get': 'view', + 'threads.search': 'view', + 'thread.snapshot': 'view', + 'thread.messages': 'view', + 'reply.page': 'view', + 'orchestrator.isTurnActive': 'view', + 'orchestrator.contextUsage': 'view', + 'orchestrator.pendingQuestions': 'view', + 'composer.options': 'view', + 'queue.list': 'view', + 'storage.usage': 'view', + 'threads.create': 'work', + 'projects.open': 'work', + 'threads.rename': 'work', + 'threads.pin': 'work', + 'threads.settle': 'work', + 'threads.regenerateTitle': 'work', + 'threads.setExpiry': 'work', + 'orchestrator.send': 'work', + 'orchestrator.steer': 'work', + 'orchestrator.abort': 'work', + 'orchestrator.answerQuestions': 'work', + 'orchestrator.dismissQuestions': 'work', + 'threads.setModel': 'work', + // Images for a thread's message or answer; a bot's chat takes none. + 'attachments.stage': 'work', + 'queue.enqueue': 'work', + 'queue.remove': 'work', + 'queue.reorder': 'work', + 'queue.promoteToSteer': 'work', + // Dictation and read-aloud for any message, a bot's included: runs nothing on a thread. + 'speech.options': 'bots_chat', + 'speech.choose': 'bots_chat', + 'speech.download': 'bots_chat', + 'speech.upload': 'bots_chat', + 'speech.transcribe': 'bots_chat', + 'speech.speak': 'bots_chat', + + // ---------------------------------------------------------------- Bridge: streams, lists, agent chats, hub + 'bridge.thread.open': 'view', + 'bridge.lists.open': 'view', + // The method an artifact is for is checked again, with its own class, whenever the artifact is opened or read. + 'bridge.artifacts.open': 'view', + 'chats.send': 'work', + 'chats.cancel': 'work', + 'bridge.dispatch': 'work', + + // ---------------------------------------------------------------- personal bots + 'bots.get': 'bots_chat', + 'bots.chat.list': 'bots_chat', + 'bots.chat.attachment': 'bots_chat', + 'bots.memory.list': 'bots_chat', + 'bots.chat.send': 'bots_chat', + 'bots.chat.stop': 'bots_chat', + 'bots.work.stop': 'bots_chat', + 'bots.chat.markRead': 'bots_chat', + 'bots.actions.answer': 'bots_chat', + 'bots.questions.answer': 'bots_chat', + 'bots.reminders.snooze': 'bots_chat', + // Allow on an ask grants the bot a permission. + 'bots.asks.answer': 'bots_manage', + 'bots.personal.pause': 'bots_manage', + 'bots.personal.resume': 'bots_manage', + 'bots.create': 'bots_manage', + 'bots.update': 'bots_manage', + 'bots.reminders.cancel': 'bots_manage', + 'bots.schedules.remove': 'bots_manage', + 'bots.permissions.set': 'bots_manage', + 'bots.permissions.revoke': 'bots_manage', + 'bots.memory.forget': 'bots_manage', + 'bots.memory.edit': 'bots_manage', + + // ---------------------------------------------------------------- routed: the transport + ...routed({ + page: 'view', + // A terminal's stream is held to the terminal switch where it opens and on every record. + 'stream.open': 'view', + 'stream.close': 'view', + stage: 'work' + }), + + // ---------------------------------------------------------------- routed: reads + ...routed({ + 'threads.get': 'view', + 'threads.markSeen': 'view', + 'thread.snapshot': 'view', + 'thread.messages': 'view', + 'thread.changesSince': 'view', + 'thread.messageImage': 'view', + 'orchestrator.isTurnActive': 'view', + 'orchestrator.contextUsage': 'view', + 'orchestrator.pendingQuestions': 'view', + 'queue.list': 'view', + 'runs.list': 'view', + 'runs.get': 'view', + 'runs.events': 'view', + 'runs.wait': 'view', + 'activity.get': 'view', + 'subagents.list': 'view', + 'agents.list': 'view', + 'tasks.list': 'view', + 'threads.approvalRules': 'view', + 'threads.approvalRequests': 'view', + 'actions.list': 'view', + 'operations.get': 'view', + 'publish.status': 'view', + 'applets.get': 'view', + 'applets.state.get': 'view', + 'applets.export': 'view', + 'workflowRuns.list': 'view', + 'workflowRuns.get': 'view', + 'workflowRuns.trace': 'view', + 'pullRequests.get': 'view', + 'pullRequests.detail': 'view', + 'pullRequests.baseBranches': 'view', + 'pullRequests.mergeMethod': 'view', + 'pullRequests.watchStatus': 'view', + 'pullRequests.list': 'view', + 'pullRequests.resolve': 'view', + 'projects.match': 'view', + 'composer.options': 'view', + 'projects.list': 'view', + 'threads.list': 'view', + 'threads.search': 'view', + 'threads.inventory': 'view', + 'activity.snapshot': 'view', + 'chatReferences.resolve': 'view', + 'providers.snapshots': 'view', + 'skills.list': 'view', + 'skills.read': 'view', + 'github.status': 'view', + 'automations.list': 'view', + // Reads of the computer's files and Git: not a view of the thread. + 'workspace.getStatus': 'work', + 'actions.getAffectedFiles': 'work', + 'review.files': 'work', + 'review.file': 'work', + 'git.status': 'work', + 'git.checkUpstream': 'work', + 'git.changes': 'work', + 'git.revertedList': 'work', + 'git.diff': 'work', + 'git.log': 'work', + 'git.branches': 'work', + 'git.diffStats': 'work', + 'git.lastCommitMessage': 'work', + 'files.list': 'work', + 'files.read': 'work', + 'files.readAsset': 'work', + 'files.stat': 'work', + 'files.search': 'work', + 'files.grep': 'work', + 'editor.folder': 'editor', + // Asks a person here to turn editor connections on; it changes nothing by itself. + 'editor.ask': 'editor', + 'pty.list': 'terminal', + 'pty.lookup': 'terminal', + 'pty.scrollback': 'terminal', + 'pty.isAlive': 'terminal', + 'pty.outputSince': 'terminal' + }), + + // ---------------------------------------------------------------- routed: chat and changes + ...routed({ + 'orchestrator.send': 'work', + 'orchestrator.steer': 'work', + 'orchestrator.abort': 'work', + 'orchestrator.steerNow': 'work', + 'orchestrator.retry': 'work', + 'threads.clearContext': 'work', + 'threads.compact': 'work', + 'threads.stopCompaction': 'work', + 'orchestrator.answerQuestions': 'work', + 'orchestrator.dismissQuestions': 'work', + 'queue.enqueue': 'work', + 'queue.edit': 'work', + 'queue.reorder': 'work', + 'queue.remove': 'work', + 'queue.promoteToSteer': 'work', + 'threads.setModel': 'work', + 'threads.setPermissionMode': 'work', + 'threads.clearApprovalRules': 'work', + 'runs.resumeNow': 'work', + 'runs.cancelPause': 'work', + 'subagents.stopAll': 'work', + 'agents.stop': 'work', + 'tasks.create': 'work', + 'tasks.update': 'work', + 'applets.state.save': 'work', + 'workflowRuns.pause': 'work', + 'workflowRuns.resume': 'work', + 'workflowRuns.cancel': 'work', + 'workflowRuns.approve': 'work', + 'workflowRuns.answer': 'work', + 'pullRequests.startThread': 'work', + 'threads.rename': 'work', + 'threads.pin': 'work', + 'threads.settle': 'work', + 'threads.delete': 'work', + 'threads.regenerateTitle': 'work', + 'threads.setWorktreeEnabled': 'work', + 'threads.setExpiry': 'work', + 'thread.fork': 'work', + 'thread.mergeBack': 'work', + 'actions.undoLatest': 'work', + 'actions.redo': 'work', + 'actions.revertCode': 'work', + 'actions.activateBranch': 'work', + 'actions.fork': 'work', + 'actions.pin': 'work', + 'actions.configureRetention': 'work', + 'actions.sweepRetention': 'work', + 'workspace.restore': 'work', + 'workspace.discardPendingChanges': 'work', + 'operations.abort': 'work', + 'operations.recover': 'work', + 'files.write': 'work', + 'publish.start': 'work', + 'git.checkout': 'work', + 'git.commit': 'work', + 'git.push': 'work', + 'git.suggestCommitMessage': 'work', + 'git.include': 'work', + 'git.undoLastCommit': 'work', + 'git.revert': 'work', + 'git.restoreReverted': 'work', + 'git.stage': 'work', + 'git.unstage': 'work', + 'git.discard': 'work', + 'git.fetch': 'work', + 'git.pull': 'work', + 'git.abortInProgress': 'work', + 'git.continueInProgress': 'work', + 'git.createBranch': 'work', + 'git.renameBranch': 'work', + 'git.deleteBranch': 'work', + 'git.cancelOperation': 'work', + 'git.init': 'work', + 'pullRequests.create': 'work', + 'pullRequests.draft': 'work', + 'pullRequests.merge': 'work', + 'pullRequests.close': 'work', + 'pullRequests.link': 'work', + 'pullRequests.unlink': 'work', + 'pullRequests.pushTarget': 'work', + 'pullRequests.watch': 'work', + 'pty.create': 'terminal', + 'pty.kill': 'terminal', + 'pty.write': 'terminal', + 'pty.resize': 'terminal', + 'threads.create': 'work', + 'projects.rename': 'work', + 'projects.pin': 'work', + 'projects.remove': 'work', + 'projects.open': 'work', + 'scheduled.create': 'work', + 'scheduled.update': 'work', + 'scheduled.run': 'work', + 'scheduled.pause': 'work', + 'scheduled.resume': 'work', + 'scheduled.delete': 'work' + }) +}) + +/** + * Every stream kind. A Space's streams follow its membership; an artifact's stream is checked again against the + * method it is for, with that method's class. + */ +export const STREAM_ACCESS: Readonly> = Object.freeze({ + 'node.thread': 'view', + 'node.artifact': 'view', + 'space.meta': 'view', + 'space.channel': 'view', + 'space.thread': 'view', + 'space.private': 'view' +}) + +/** Every kind of private stream one computer opens on another (`routed.stream.open`). */ +export const ROUTED_STREAM_ACCESS: Readonly> = Object.freeze({ + thread: 'view', + lists: 'view', + // A Git action's progress, for the computer that started it. + channel: 'view', + terminal: 'terminal' +}) + +/** A method with no class counts as work: a device that may only view and chat with bots never reaches it. */ +export const methodAccess = (method: string): AccessClass => + Object.hasOwn(METHOD_ACCESS, method) ? METHOD_ACCESS[method]! : 'work' + +/** The classes "Work on threads from this device" governs: off, each is refused. */ +export const needsWork = (access: AccessClass): boolean => + access === 'work' || access === 'bots_manage' diff --git a/src/shared/net/errors.ts b/src/shared/net/errors.ts index d7e61f3b76..9aad1a95cf 100644 --- a/src/shared/net/errors.ts +++ b/src/shared/net/errors.ts @@ -157,13 +157,16 @@ export function isNetErrorCode(value: unknown): value is NetErrorCode { * bare "not permitted". Fixed words only: it is the one detail of an error that crosses the wire. * `not_connected`: the other computer has not connected this device (a connection it refuses for that reason is * tried again slowly, never given up). + * `work_off`: the other computer lets this device view threads and chat with bots only ("Work on threads from this + * device" is off there), so it refuses every call that would start, change or stop work. */ export const FORBIDDEN_REASONS = [ 'capability', 'blocked', 'setting_off', 'terminal_off', - 'not_connected' + 'not_connected', + 'work_off' ] as const export type ForbiddenReason = (typeof FORBIDDEN_REASONS)[number] export const isForbiddenReason = (value: unknown): value is ForbiddenReason => diff --git a/src/shared/net/local.ts b/src/shared/net/local.ts index f4aec1cb7d..c9016e54ca 100644 --- a/src/shared/net/local.ts +++ b/src/shared/net/local.ts @@ -149,6 +149,12 @@ export interface BridgeNodePolicy { * started here (the default), or all. Absent from a service from before the setting. */ agentReach?: AgentReach + /** + * The device may work on threads here ("Work on threads from this device"): start, send, steer, stop, change + * settings, files and Git, and make or change bots. Off, it reads threads and chats with bots only. On until the + * owner turns it off. Absent from a service from before the switch. + */ + work?: boolean } /** What a device's agents may change on this computer (`net_node_policy.agent_reach`). */ diff --git a/tests/net/bridge/nodePolicy.test.ts b/tests/net/bridge/nodePolicy.test.ts index 9bc4d3511d..0ac245a9f8 100644 --- a/tests/net/bridge/nodePolicy.test.ts +++ b/tests/net/bridge/nodePolicy.test.ts @@ -724,7 +724,8 @@ describe('blocking a device on a computer', () => { terminal: false, editor: false, bots: true, - agentReach: 'launched' + agentReach: 'launched', + work: true }) await a.request('bridge.policy', { node: one.node, maxPermissionMode: 'full', terminal: true }) @@ -734,7 +735,8 @@ describe('blocking a device on a computer', () => { terminal: true, editor: false, bots: true, - agentReach: 'launched' + agentReach: 'launched', + work: true }) // The editor switch is its own: it changes neither of the others, and nothing else changes it. await a.request('bridge.policy', { node: one.node, editor: true }) @@ -744,7 +746,8 @@ describe('blocking a device on a computer', () => { terminal: true, editor: true, bots: true, - agentReach: 'launched' + agentReach: 'launched', + work: true }) // Bots on this computer is its own too: off for one device only, and nothing else moves. await a.request('bridge.policy', { node: one.node, bots: false }) @@ -759,7 +762,8 @@ describe('blocking a device on a computer', () => { terminal: false, editor: false, bots: true, - agentReach: 'launched' + agentReach: 'launched', + work: true }) await expect( a.request('bridge.policy', { node: one.node, editor: 'yes' }) diff --git a/tests/net/bridge/routed/accessClasses.test.ts b/tests/net/bridge/routed/accessClasses.test.ts new file mode 100644 index 0000000000..3f3d0b748f --- /dev/null +++ b/tests/net/bridge/routed/accessClasses.test.ts @@ -0,0 +1,160 @@ +/** + * Every remote method and stream kind has an access class (`shared/net/accessClasses.ts`), and "Work on threads from + * this device" off (`net_node_policy.work`) leaves a device to view threads and chat with bots. Over two real daemons + * linked by Bridge: the keeper (`owner`) and a member (`caller`), each the receiver in turn, so the switch holds on a + * computer that is not the keeper too. What is checked is the receiver's dispatcher, the one place every call and every + * lookup of a saved result passes. + */ +import { afterAll, beforeAll, describe, expect, it } from 'vitest' +import { EventEmitter } from 'node:events' +import { STREAM_KINDS, newId, type NodeId, type RpcId } from '../../../../src/shared/net' +import { ROUTED_STREAM_KINDS, type RoutedAgentMark } from '../../../../src/shared/bridge/routed' +import { + ACCESS_CLASSES, + METHOD_ACCESS, + ROUTED_STREAM_ACCESS, + STREAM_ACCESS +} from '../../../../src/shared/net/accessClasses' +import { accessPresetOf } from '../../../../src/shared/net/accessPresets' +import type { MousseMainService } from '../../../../src/mms/MousseMainService' +import type { BridgeNodePolicy } from '../../../../src/shared/net/local' +import { cleanupAll, cleanups, linked } from './routerFixture' + +let t: Awaited> +beforeAll(async () => { + t = await linked() + // The member lets its other computers work on its threads too, so the keeper can be the caller. + await t.caller.net.request('bridge.workOnThreads', { enabled: true }) +}, 120_000) +afterAll(cleanupAll) + +describe('the access table', () => { + it('classes every method another device can call here, in every family, and names none that is not there', () => { + const registered = t.owner.net.runtime().rpc.methods() + // Each family is there: Net's own, routed rows and transport, the phone API, lists, the hub, bots and speech. + for (const name of ['net.info', 'authority.transfer.import', 'routed.orchestrator.send', 'routed.stream.open', 'routed.stage', 'thread.snapshot', 'bridge.lists.open', 'bridge.dispatch', 'bots.create', 'speech.transcribe']) + expect(registered, name).toContain(name) + expect(registered.filter((name) => !Object.hasOwn(METHOD_ACCESS, name))).toEqual([]) + expect(Object.keys(METHOD_ACCESS).filter((name) => !registered.includes(name))).toEqual([]) + for (const value of Object.values(METHOD_ACCESS)) expect(ACCESS_CLASSES).toContain(value) + }) + + it('classes every stream kind, and a terminal is never a view', () => { + for (const kind of STREAM_KINDS) expect(ACCESS_CLASSES, kind).toContain(STREAM_ACCESS[kind]) + for (const kind of ROUTED_STREAM_KINDS) expect(ACCESS_CLASSES, kind).toContain(ROUTED_STREAM_ACCESS[kind]) + expect(ROUTED_STREAM_ACCESS.terminal).toBe('terminal') + }) +}) + +const forbidden = (reason: string) => ({ code: 'forbidden', details: { reason } }) +const mark = (): RoutedAgentMark => ({ thread: 'sender-thread', run: 'sender-run', title: 'Planner', hops: 1, mode: 'accept_edits' }) +const BOT = 'bot-0123456789ab' + +/** The receiver's bots as Bridge reads them: one bot, and a record of what reached it. No turn runs. */ +function standInBots(receiver: MousseMainService) { + const reached: string[] = [] + const bot = { id: BOT, name: 'Notes' } + const service = { + list: () => ({ bots: [bot] }), + get: (botId: string) => { + if (botId !== BOT) throw Object.assign(new Error('No such bot.'), { code: 'bot_not_found' }) + return { summary: bot, permissions: [], runs: [] } + }, + chatSend: async (input: { text: string }) => { + reached.push(`chatSend:${input.text}`) + return { message: { seq: 1, role: 'owner', text: input.text, at: new Date().toISOString() } } + }, + create: async () => { + reached.push('create') + return { bot } + }, + withdrawQueued: async () => 0 + } + const real = Object.getOwnPropertyDescriptor(receiver, 'personalBots') + Object.defineProperty(receiver, 'personalBots', { value: { service, liveActivity: () => undefined, events: new EventEmitter() }, configurable: true }) + // The daemon's own bots are put back before it stops. + cleanups.push(() => { + if (real) Object.defineProperty(receiver, 'personalBots', real) + }) + return reached +} + +describe('a device that may view threads and chat with bots only', () => { + // The keeper receives from its member, then a member that is not the keeper receives from the keeper. + const directions = () => [ + { receiver: t.owner, caller: t.caller, receiverNode: t.node, callerNode: t.callerNode }, + { receiver: t.caller, caller: t.owner, receiverNode: t.callerNode, callerNode: t.node } + ] + + for (const index of [0, 1]) + it(`reads the transcript and chats with bots; starting, sending, steering, stopping and making a bot are refused (${index ? 'member' : 'keeper'} receives)`, async () => { + const { receiver, caller, receiverNode, callerNode } = directions()[index]! + const reached = standInBots(receiver) + const session = caller.net.session(receiverNode) + const rpc = (method: string, params: unknown, extra: { id?: RpcId; idem?: string } = {}) => + session.rpc(method, params, { id: extra.id ?? newId('rpc'), deadlineMs: 15_000, ...(extra.idem ? { idem: extra.idem } : {}) }) + const policyOf = async () => + ((await receiver.net.request('bridge.nodes', {})) as { nodes: Array<{ node: NodeId; policy: BridgeNodePolicy }> }).nodes.find((row) => row.node === callerNode)!.policy + + // A device starts out working on threads: the Work on threads preset. + expect(accessPresetOf(await policyOf())).toBe('work') + const thread = receiver.threads.createThread('Plan', undefined, undefined, { started: true }) + // A change made while the device could still work, whose result is kept for a retry. + const renamed = newId('rpc') + expect(await rpc('routed.threads.rename', { threadId: thread.id, name: 'Plan B' }, { id: renamed, idem: `rename-${index}` })).toMatchObject({ ok: true }) + + await receiver.net.request('bridge.policy', { node: callerNode, work: false }) + expect(await policyOf()).toMatchObject({ work: false }) + + // Reads pass: the transcript, the list, and a bot's chat. + expect(await rpc('routed.thread.snapshot', { threadId: thread.id })).toMatchObject({ ok: true }) + expect(await rpc('routed.threads.list', {})).toMatchObject({ ok: true }) + expect(await rpc('bots.get', { botId: BOT })).toMatchObject({ summary: { id: BOT } }) + expect(await rpc('bots.chat.send', { botId: BOT, text: 'What is on today?', clientRequestId: `chat-${index}` }, { idem: `chat-${index}` })).toMatchObject({ message: { text: 'What is on today?' } }) + expect(reached).toEqual(['chatSend:What is on today?']) + + // Work is refused, a person's call and an agent's alike, in every family, before anything runs. + const refused: Array<[string, Record]> = [ + ['routed.threads.create', { name: 'New' }], + ['routed.threads.create', { name: 'New', agent: mark() }], + ['routed.orchestrator.send', { threadId: thread.id, content: 'Go on' }], + ['routed.orchestrator.send', { threadId: thread.id, content: 'Go on', agent: mark() }], + ['routed.orchestrator.steer', { threadId: thread.id, text: 'Stop there' }], + ['routed.orchestrator.steer', { threadId: thread.id, text: 'Stop there', agent: mark() }], + ['routed.orchestrator.abort', { threadId: thread.id }], + ['routed.orchestrator.abort', { threadId: thread.id, agent: mark() }], + ['routed.files.read', { threadId: thread.id, path: 'a.txt' }], + ['threads.create', { name: 'From a phone' }], + ['orchestrator.send', { threadId: thread.id, content: 'From a phone' }], + ['bots.create', { look: { colour: 'teal', accessory: 'cap' }, description: 'Tidy notes', clientRequestId: `make-${index}` }] + ] + for (const [method, params] of refused) + await expect(rpc(method, params, { idem: `${method}-${index}-${JSON.stringify(params).length}` }), method).rejects.toMatchObject(forbidden('work_off')) + expect(reached).toEqual(['chatSend:What is on today?']) + expect(receiver.threads.getThread(thread.id)?.name).toBe('Plan B') + // The result it asked for earlier cannot be read back either. + await expect(session.rpcResult(renamed, { deadlineMs: 15_000 })).rejects.toMatchObject(forbidden('work_off')) + + // On again, the same device works again, and gets its saved result. + await receiver.net.request('bridge.policy', { node: callerNode, work: true }) + expect(await session.rpcResult(renamed, { deadlineMs: 15_000 })).toMatchObject({ ok: true }) + expect(await rpc('routed.threads.pin', { threadId: thread.id, pinned: true }, { idem: `pin-${index}` })).toMatchObject({ ok: true }) + }, 120_000) + + it('a person and an agent on the calling computer are told why, in words', async () => { + await t.owner.net.request('bridge.policy', { node: t.callerNode, work: false }) + try { + const thread = t.thread('Shared') + const client = t.client() + const person = await t.refused(client.call(t.node, 'orchestrator.send', { threadId: thread.id, content: 'Go on' }, { idem: 'person-send' })) + expect(person).toMatchObject({ code: 'computer_forbidden', details: { reason: 'work_off' } }) + expect(person.message).toContain('view threads and chat with bots only') + const agent = await t.refused(client.call(t.node, 'threads.create', { name: 'Launched', agent: mark() }, { idem: 'agent-create' })) + expect(agent).toMatchObject({ code: 'computer_forbidden', details: { reason: 'work_off' } }) + // Reading goes on. + expect(await client.call(t.node, 'threads.get', { threadId: thread.id })).toBeTruthy() + } finally { + await t.owner.net.request('bridge.policy', { node: t.callerNode, work: true }) + } + }, 60_000) +}) diff --git a/tests/net/cli/net.test.ts b/tests/net/cli/net.test.ts index 395aec910b..3fd53be3f2 100644 --- a/tests/net/cli/net.test.ts +++ b/tests/net/cli/net.test.ts @@ -170,6 +170,12 @@ describe('network CLI validation', () => { method: 'bridge.policy', params: { node: nodeId, agentReach: reach } }) + // Work on threads from this device: off leaves it to view threads and chat with bots. + for (const [flag, work] of [['off', false], ['on', true]] as const) + expect(prepareNetCommand(args('bridge', 'limits', [nodeId], [['work', flag]]))).toEqual({ + method: 'bridge.policy', + params: { node: nodeId, work } + }) expect( prepareNetCommand(args('bridge', 'caps', [nodeId], [['caps', 'read,chat,write,settings']])) ).toEqual({ @@ -188,6 +194,8 @@ describe('network CLI validation', () => { args('bridge', 'limits', [nodeId], [['terminal', 'maybe']]), args('bridge', 'limits', [nodeId], [['editor', 'maybe']]), args('bridge', 'limits', [nodeId], [['agent-reach', 'everything']]), + args('bridge', 'limits', [nodeId], [['work', 'maybe']]), + args('bridge', 'block', [nodeId], [['work', 'off']]), args('bridge', 'block', [nodeId], [['agent-reach', 'all']]), args('bridge', 'block', [nodeId], [['editor', 'on']]), args('bridge', 'caps', [nodeId]), diff --git a/tests/net/store/nodePolicyMigration.test.ts b/tests/net/store/nodePolicyMigration.test.ts index fcbc609770..f215e575e1 100644 --- a/tests/net/store/nodePolicyMigration.test.ts +++ b/tests/net/store/nodePolicyMigration.test.ts @@ -272,3 +272,33 @@ describe('agent reach in net_node_policy (issue #1160)', () => { expect(policy.get(node).agentReach).toBe('none') }) }) + +describe('"Work on threads from this device" in net_node_policy', () => { + it('adds the column with every device on, an earlier build\'s write leaves it, and only a stored 1 is on', () => { + const dir = profile() + const node = newId('node') + writeOldDatabase(dir, [[node, 0, 'full', 1]]) + let db = new NetDatabase({ profileDir: dir }) + expect(columns(db).find((column) => column.name === 'work')).toMatchObject({ notnull: 1, dflt_value: '1' }) + expect(userVersion(db)).toBe(1) + const first = new SqliteNodePolicy(db, systemClock) + expect(first.get(node)).toMatchObject({ work: true, maxPermissionMode: 'full', terminal: true }) + expect(first.get(newId('node')).work).toBe(true) + expect(first.set(node, { work: false })).toMatchObject({ work: false, terminal: true, maxPermissionMode: 'full' }) + db.close() + db = new NetDatabase({ profileDir: dir }) + cleanups.push(() => db.close()) + const policy = new SqliteNodePolicy(db, systemClock) + expect(policy.get(node).work).toBe(false) + // An earlier build's write names only its own columns: the switch stays off. + 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' + ) + .run(node, 0, 'ask', 0, 0, 1, 'launched', 5) + expect(policy.get(node)).toMatchObject({ work: false, maxPermissionMode: 'ask' }) + expect(() => db.database.prepare('UPDATE net_node_policy SET work=2 WHERE node=?').run(node)).toThrow() + expect(() => policy.set(node, { work: 'no' as never })).toThrow() + }) +}) From e5d342a1b019e67f6baad11192724db8494ff820 Mon Sep 17 00:00:00 2001 From: TheAnimatrix Date: Tue, 17 Nov 2026 19:01:31 +0530 Subject: [PATCH 2/3] feat(devices): pick what a computer may do here from three presets Each computer's row in Settings, Devices has Access from this device: View and chat with bots, Work on threads (the defaults) or Full control. A pick sets the device's switches at once; switches that match none show as Custom, and the single switches stay. Limits has the Work on threads switch on its own. Phones have no preset. The presets are shared (src/shared/net/accessPresets.ts) for later screens. --- src/renderer/components/NetDevicesSection.tsx | 5 + .../components/devices/DeviceLimitsDialog.tsx | 8 +- .../components/devices/DevicePresetRow.tsx | 39 ++++++ src/shared/net/accessPresets.ts | 92 ++++++++++++++ tests/renderer/deviceAccessPreset.test.ts | 117 ++++++++++++++++++ 5 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 src/renderer/components/devices/DevicePresetRow.tsx create mode 100644 src/shared/net/accessPresets.ts create mode 100644 tests/renderer/deviceAccessPreset.test.ts 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 + +
}