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: 1 addition & 1 deletion docs/GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Use these terms in issues, PRs, comments, and docs. If you need a term that is n
- **Settle notice:** what Mousse tells a thread's agent about work it started in another thread with `notify` (`thread_send`, or `thread_create` with a first message): once if the work waits for a person, and once when it ends. Mousse writes it, not either agent; the chat shows it as a notice row that opens the other thread. It starts a turn when the thread is idle and waits in its queue otherwise.
- **Subagent title:** the short name a thread gives a subagent when it starts it, such as "API reviewer". It is unique among that thread's subagents and is how the thread later continues, reads or cancels that subagent.
- **Continue (a subagent):** send a follow-up to a subagent that already exists, by its title. It carries on in the same thread with what it already read, as a new delegation, instead of a new subagent starting from nothing. A message a person types in a subagent's thread is also a follow-up, and its parent hears the result.
- **Remote subagent:** a subagent an agent starts on another of the user's computers (`delegate_task` with `computer`). That computer runs it as an ordinary thread, under its own agents and accounts, in its project that holds the same repository, and its questions are answered there. Its parent continues, reads and stops it like any subagent; its result names the branch its work is on there. Agents may start one only when "Let agents work on your other devices" is on in Settings → Agents → Agent access (off at first), and only on the computers turned on under it. It runs no looser than its parent and within the highest permission mode that computer set for this one, which can be Full access.
- **Remote subagent:** a subagent an agent starts on another of the user's computers (`delegate_task` with `computer`). That computer runs it as an ordinary thread, under its own agents and accounts, in its project that holds the same repository, and its questions are answered there. Its parent continues, reads and stops it like any subagent; its result names the branch its work is on there. That computer decides whether this one's agents may work there (Settings → Devices on that computer). It runs no looser than its parent and within the highest permission mode that computer set for this one, which can be Full access. A read-only one is held read-only there, in that computer's project folder.
- **Background work:** agents and shells a provider started that keep running after the turn that started them ended. Claude keeps one live process per thread so they survive. While a thread has background work it shows Waiting, and a subagent's task waits too.
- **Wake-up:** a thread agent's or bot's note to carry on later in its own thread without the person writing (`wake`): at a time, when another thread finishes its turn, or when a pull request merges, its checks settle or it gets a review. It is kept across restarts and sleep, grants nothing, and waits while the thread waits on the person's answer. A thread's pending wake-ups show with its background work; Stop, archive and delete cancel them. Subagents set none.
- **Continuation run:** a run of a thread that records a turn the provider started on its own, because background work finished and the provider wants to read the report. It opens with a short note and ends at the provider's result.
Expand Down
23 changes: 12 additions & 11 deletions docs/net/threat-model.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/run-engine/SPEC.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/mms/bridge/BridgeProfileService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from 'node:path'
import { accessPresetOf } from '../../shared/net/accessPresets'
import type { MmsProfileServices } from '../MmsProfileServices'
import type { NetDomainComposition, NetRuntime, NetService } from '../net/NetService'
import type { BotRuntimeAdapter, Clock, RpcCaller, SyncSession } from '../net/contracts'
Expand Down Expand Up @@ -393,7 +394,7 @@ export class BridgeProfileService {
}
})
this.remote = new RemoteApi(
new MmsRemoteBackend(services, undefined, undefined, (node) => rt.policy.get(node).maxPermissionMode),
new MmsRemoteBackend(services, undefined, undefined, (node) => rt.policy.get(node).maxPermissionMode, (node) => accessPresetOf(rt.policy.get(node)) === 'full'),
this.clock
)
for (const method of this.remote.methods())
Expand Down
53 changes: 38 additions & 15 deletions src/mms/bridge/remote/MmsBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { COMPOSER_COMMANDS } from '../../../shared/composerCommands'
import { withHiddenBots } from './botReach'
import { withLegacySettledAt, withLegacySettledAtIn } from '../../../shared/archivedAt'
import { resolveThreadProjectPath } from '../../data/resolveActiveProjectPath'
import type { ChatMessage, OrchestratorSendRequest, QueuedMessage, Thread, ThreadStartedFrom } from '../../../shared/types'
import type { ChatMessage, OrchestratorSendRequest, QueuedMessage, SubagentWorkspaceBinding, Thread, ThreadStartedFrom } from '../../../shared/types'
import { defaultIntegrationActor } from '../../../shared/integrations/actor'
import { resolveEffectiveSkills } from '../../integrations/catalog/EffectiveIntegrationResolver'

Expand Down Expand Up @@ -149,6 +149,12 @@ function failure(error: unknown): { ok: false; error: string } {
}

/** Adapts the actual profile services, never a client-supplied ingress/profile/path. */
/** The workspace binding of a read-only subagent another computer's agent started here, in the project's own folder. */
function readOnlyBinding(services: MmsProfileServices, projectId: string | undefined): SubagentWorkspaceBinding {
const path = projectId ? services.projects.getProject(projectId)?.path : undefined
return { policy: 'shared', access: 'read-only', ...(path ? { sharedPath: path } : {}) }
}

export class MmsRemoteBackend implements RemoteBackendPort {
/** The newest page of a thread `warm` read from its database, by thread and byte budget, for the next snapshot. */
private readonly pages = new Map<string, { page: MessagePageResult; saves: number; readAt: number }>()
Expand All @@ -158,7 +164,13 @@ export class MmsRemoteBackend implements RemoteBackendPort {
/** Where this computer keeps credentials and settings (the user's home, the platform, tool folders). */
private readonly folderRules: () => FolderRuleEnvironment = currentFolderEnvironment,
/** The highest permission mode this computer lets a device run a turn in (`net_node_policy`); absent for a build without limits. */
private readonly deviceLimit?: (node: NodeId) => PermissionMode
private readonly deviceLimit?: (node: NodeId) => PermissionMode,
/**
* Whether this computer gives the device Full control (`accessPresetOf(policy) === 'full'`): it already has shell
* access as the owner here, so the hidden, credential, home and Mousse-data folder rules don't hold it back. The
* network and device path refusal stays for every device. Absent: no device has it.
*/
private readonly fullControl?: (node: NodeId) => boolean
) {}
/**
* The thread a caller on another device may reach: one of this profile's, and never a private one
Expand Down Expand Up @@ -207,7 +219,7 @@ export class MmsRemoteBackend implements RemoteBackendPort {
async createThreadForAgent(
params: Record<string, unknown>,
caller: { node: NodeId },
started: { agent: NonNullable<ThreadStartedFrom['agent']>; permissionMode: PermissionMode }
started: { agent: NonNullable<ThreadStartedFrom['agent']>; permissionMode: PermissionMode; readOnly?: true }
): Promise<unknown> {
if (typeof params.projectId === 'string' && !this.services.projects.listProjects().some((project) => project.id === params.projectId))
throw new NetError('bad_request', 'Project is outside this profile inventory.')
Expand All @@ -233,11 +245,11 @@ export class MmsRemoteBackend implements RemoteBackendPort {
)
return { ok: false }
}
if (method === 'projects.open') return mmsJson(this.openProject(params.path))
if (method === 'projects.open') return mmsJson(this.openProject(params.path, caller))
if (method === 'projects.setPath') {
// An expected refusal (another project's folder) reaches the device in words, as the folder checks' do.
try {
return mmsJson(this.setProjectPath(params.projectId as string, params.path))
return mmsJson(this.setProjectPath(params.projectId as string, params.path, caller))
} catch (error) {
if (error instanceof DomainRpcError) return failure(error)
throw error
Expand Down Expand Up @@ -289,10 +301,12 @@ export class MmsRemoteBackend implements RemoteBackendPort {
private async createThread(
params: Record<string, unknown>,
caller?: { node: NodeId },
started?: { agent: NonNullable<ThreadStartedFrom['agent']>; permissionMode: PermissionMode }
started?: { agent: NonNullable<ThreadStartedFrom['agent']>; permissionMode: PermissionMode; readOnly?: true }
): Promise<{ thread: { id: string } } & Record<string, unknown>> {
// `subagent` is read only from an agent's call, which brings it in `started`; a person's is left out.
const { startedFromProjectId, hidden, subagent: _subagent, ...create } = params
// `subagent` and `readOnly` are read only from an agent's call, which brings them in `started`; a person's are left out.
const { startedFromProjectId, hidden, subagent: _subagent, readOnly: _readOnly, ...create } = params
// A read-only subagent works in the project's own folder, never a worktree of its own.
if (started?.readOnly) create.worktreeEnabled = false
const result = (await dispatchMethod({ mms: this.services, globalSequence: this.revision }, 'threads.create', create)) as
{ thread: { id: string } } & Record<string, unknown>
if (!caller) return result
Expand All @@ -306,7 +320,11 @@ export class MmsRemoteBackend implements RemoteBackendPort {
result.thread.id,
{
startedFrom: { node: caller.node, ...(typeof startedFromProjectId === 'string' ? { projectId: startedFromProjectId } : {}), ...(agent ? { agent } : {}) },
...(started ? { permissionMode: started.permissionMode } : {})
...(started ? { permissionMode: started.permissionMode } : {}),
// A read-only subagent of another computer's agent: held to the read-only tools in its project's folder, as a
// read-only subagent here is in its parent's (`OrchestratorService.restoreDelegatedWorkspace`). With no project
// there is no folder to hold it in, and its turn is refused (`read_only_needs_folder`) rather than run with every tool.
...(started?.readOnly && agent?.subagent ? { workspaceBinding: readOnlyBinding(this.services, typeof create.projectId === 'string' ? create.projectId : undefined) } : {})
},
{ touch: false }
)
Expand Down Expand Up @@ -375,25 +393,29 @@ export class MmsRemoteBackend implements RemoteBackendPort {
* directory is never created. Refusals answer `{ ok: false, error }` so the reason survives a
* mutating RPC.
*/
private openProject(path: unknown): { ok: true; project: unknown } | { ok: false; error: string } {
const folder = this.allowedFolder(path)
private openProject(path: unknown, caller?: { node: NodeId }): { ok: true; project: unknown } | { ok: false; error: string } {
const folder = this.allowedFolder(path, caller)
if (!folder.ok) return folder
const s = this.services
const project = s.projects.openProject(folder.real)
s.events.broadcast('projects:updated', s.projects.listProjects())
return { ok: true, project }
}
/** A project's folder moved to another folder here, picked from another device: the folder `projects.open` would take. */
private setProjectPath(projectId: string, path: unknown): { ok: true; project: unknown } | { ok: false; error: string } {
const folder = this.allowedFolder(path)
private setProjectPath(projectId: string, path: unknown, caller?: { node: NodeId }): { ok: true; project: unknown } | { ok: false; error: string } {
const folder = this.allowedFolder(path, caller)
if (!folder.ok) return folder
const s = this.services
const project = s.projects.setProjectPath(projectId, folder.real)
s.events.broadcast('projects:updated', s.projects.listProjects())
return { ok: true, project }
}
/** The folder another device may make a project of, as its real path, or why not. */
private allowedFolder(path: unknown): { ok: true; real: string } | { ok: false; error: string } {
/**
* The folder another device may make a project of, as its real path, or why not. A device with Full control here
* skips the folder rules (`fullControl`); every device is held to a local, absolute, existing folder that is not a
* network or device path.
*/
private allowedFolder(path: unknown, caller?: { node: NodeId }): { ok: true; real: string } | { ok: false; error: string } {
const refuse = (error: string) => ({ ok: false as const, error })
if (typeof path !== 'string' || !path.trim() || path.includes('\0'))
return refuse('Enter the full path of a folder.')
Expand All @@ -411,6 +433,7 @@ export class MmsRemoteBackend implements RemoteBackendPort {
} catch {
return refuse('That folder does not exist on this computer.')
}
if (caller && this.fullControl?.(caller.node) === true) return { ok: true, real }
const s = this.services
// Inside the data folder, or a folder that holds it: file tools may edit anything below the project folder, so a
// thread there could change the keys and databases without asking. The same for the user's credentials and
Expand Down
11 changes: 6 additions & 5 deletions src/mms/bridge/routed/OwnerRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createHash } from 'node:crypto'
import { accessPresetOf } from '../../../shared/net/accessPresets'
import { isLocalOnlyThread } from '../../../shared/threadLineage'
import { threadFolderIsLocalOnly } from '../../data/localOnlyThreads'
import { isAbsolute, win32 } from 'node:path'
Expand Down Expand Up @@ -101,7 +102,7 @@ export interface OwnerRoutesOptions {
rpc: RpcDispatcher & { authorizedMethod(name: string, caller: RpcContext['caller']): unknown }
/** What this computer lets each device do here. */
policy: Pick<SqliteNodePolicy, 'get' | 'list' | 'onChange'>
audit: Pick<SqliteBridgeAudit, 'record' | 'countRead' | 'has' | 'countAgentCalls'>
audit: Pick<SqliteBridgeAudit, 'record' | 'countRead' | 'has'>
/** Keeps a call owned by the profile, so it drains when the profile closes. */
track<T>(work: Promise<T>): Promise<T>
/**
Expand Down Expand Up @@ -356,7 +357,8 @@ export class OwnerRoutes {
options.services,
() => options.services.protocolSequence(),
undefined,
(node) => options.policy.get(node).maxPermissionMode
(node) => options.policy.get(node).maxPermissionMode,
(node) => accessPresetOf(options.policy.get(node)) === 'full'
)
this.clock = options.clock ?? systemClock
this.pages = options.pages ?? new ReplyPages(this.clock)
Expand All @@ -375,9 +377,7 @@ export class OwnerRoutes {
this.remoteAgent = new RemoteAgentCalls({
services: options.services,
policy: options.policy,
audit: options.audit,
deviceName: (node) => options.deviceName?.(node) ?? 'another computer',
clock: this.clock
deviceName: (node) => options.deviceName?.(node) ?? 'another computer'
})
}
/** Calls marked as an agent's (`remoteAgent.ts`). */
Expand Down Expand Up @@ -1191,6 +1191,7 @@ export class OwnerRoutes {
node,
user: context.caller.user,
maxPermissionMode: policy.get(node).maxPermissionMode,
...(accessPresetOf(policy.get(node)) === 'full' ? { fullControl: true } : {}),
// A terminal is the device's from the moment its shell exists, so a block that lands while it starts catches it.
...(slot ? { onTerminalCreated: (ptyId: string) => slot.created(ptyId) } : {})
},
Expand Down
Loading
Loading