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/chat-links-and-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Project/thread references are resolved in the daemon for the active profile with

Right-click a thread wherever it shows (a sidebar row, a Nest row, a subagent card, a thread chip, a thread a bot started) and choose **Copy reference**: it copies the thread's link, `mousse://thread/<id>` (with `<node>:` for a thread of another computer, and for a thread of this one while the user has another computer). Pasting it into a composer shows the thread's chip at the caret, in the line being typed: its title, a status dot, and "· <computer>" for a thread of another computer. A click opens the thread; the × on hover, or Backspace after it, removes it. A link typed and followed by a space or new line, dropped, or in a draft that opens gets the chip too; a thread this computer does not list stays link text. The text box holds a stand-in token for the chip (`src/renderer/lib/composerThreadChips.ts`), the same glyphs the input backdrop draws as the chip, so the caret, selection, undo and input methods stay the text box's own; the sent text, a copied selection and the bot chat's send get the exact link back. The sent message draws it as the thread's chip in place (`promptSegments`), and the agent gets the link in the text and reads it with its thread tools. Dragging a sidebar thread onto the composer adds a thread pill instead.

Typing `#` in an agent thread's or a bot chat's composer (at the start of the text, or after a space or an opening bracket or quote) lists the owner's threads by title in the same list `@` uses (`src/renderer/lib/threadTags.ts`). The threads the window lists show at once, every computer's, then a title-only search (`threads.search` with `titlesOnly`) adds older and archived ones from this computer and from each other computer that answers within 2 seconds; the line under the rows names the computers not searched ("Not searched: Laptop (offline)"). Each row reads "<project> · <computer>" with "Archived", "offline" or "not sharing" at the end; a thread on an offline computer is still picked. A thread the chat may not point at is greyed with why: a private thread from a shared thread or a bot chat, and, from a private thread, a thread of another computer. A pick leaves the same chip a pasted link makes, with a link that carries the thread's computer, as one edit undo takes back. An issue number (`#123`), a colour (`#fff`), a heading (`# Title`), `C#`, `page#top` and anything in code never open the list. Agents and bots are told to pass the id in the link to `thread_read` as it is (`THREAD_TAG_GUIDANCE` in `src/shared/threadLink.ts`).

The agent gets the thread by reference, never its transcript. In a thread chat, a pill goes into the message's `[Mousse references]` block as the thread's title, `Link` and `Thread ID`, and a line telling the agent to read it with `thread_read`, as far as the request needs:

| `thread_read` view | Holds |
Expand Down
9 changes: 6 additions & 3 deletions src/main/ipc/registerGuiIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3307,12 +3307,15 @@ export function registerGuiIpc(
return res.threads
}
)
registerHandler('threads:search', async (_e, query: string, limit?: number, options?: { perThread?: boolean; others?: boolean }) => {
registerHandler('threads:search', async (_e, query: string, limit?: number, options?: { perThread?: boolean; titlesOnly?: boolean; others?: boolean }) => {
const perThread = options?.perThread === true
const titlesOnly = !perThread && options?.titlesOnly === true
const res = await guiMms.request<ThreadSearchResponse>('threads.search', {
query,
limit,
...(options?.perThread === true ? { perThread: true } : {}),
...(options?.perThread === true && options.others === true ? { others: true } : {})
...(perThread ? { perThread: true } : {}),
...(titlesOnly ? { titlesOnly: true } : {}),
...((perThread || titlesOnly) && options?.others === true ? { others: true } : {})
})
// The computers that were not searched are named with the matches of the others.
return { results: res.results, ...(res.skipped?.length ? { skipped: res.skipped } : {}) }
Expand Down
18 changes: 11 additions & 7 deletions src/mms/bridge/routed/mergedLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,11 +1390,11 @@ export class MergedLists implements RemoteListsPort {

/**
* Calls `work` on every computer that is listed, each with its own short deadline. A call of a kind
* (`search`, or the sidebar's `filter`) from a window ends the call of the same kind the window still has running,
* and nothing else.
* (`search`, the sidebar's `filter`, or the composer's `#` list, `tags`) from a window ends the call of the same kind
* the window still has running, and nothing else.
*/
private async fanOut<T>(
kind: 'search' | 'filter',
kind: 'search' | 'filter' | 'tags',
connection: string | undefined,
work: (c: Computer, signal: AbortSignal) => Promise<T>
): Promise<{
Expand Down Expand Up @@ -1465,24 +1465,27 @@ export class MergedLists implements RemoteListsPort {

/**
* Searches the other computers. `perThread` is the sidebar's filter: one message hit per thread, run apart from the
* window's other search, so neither replaces the other.
* window's other search, so neither replaces the other. `titlesOnly` is the composer's `#` list: thread titles only,
* archived ones too, on a lane of its own; a computer from before it answers with every hit, and only its title
* matches are kept.
*/
async search(
connection: string | undefined,
query: string,
limit: number,
options: { perThread?: boolean } = {}
options: { perThread?: boolean; titlesOnly?: boolean } = {}
): Promise<{ results: ThreadSearchResult[]; skipped: ThreadSearchSkipped[] }> {
if (!this.options.enabled()) return { results: [], skipped: [] }
const perThread = options.perThread === true
const titlesOnly = options.titlesOnly === true && !perThread
const { answers, skipped, superseded } = await this.fanOut(
perThread ? 'filter' : 'search',
perThread ? 'filter' : titlesOnly ? 'tags' : 'search',
connection,
async (c, signal) => {
const raw = await this.options.client.call(
c.node,
'threads.search',
{ query, limit, ...(perThread ? { perThread } : {}) },
{ query, limit, ...(perThread ? { perThread } : {}), ...(titlesOnly ? { titlesOnly } : {}) },
{ signal }
)
const found = qualifyRoutedResult('threads.search', raw, {
Expand All @@ -1492,6 +1495,7 @@ export class MergedLists implements RemoteListsPort {
const results = isRecord(found) && Array.isArray(found.results) ? found.results : []
return results
.filter(isRecord)
.filter((result) => !titlesOnly || result.matchType === 'thread')
.map((result) => ({ ...result, node: c.node }) as unknown as ThreadSearchResult)
}
)
Expand Down
4 changes: 3 additions & 1 deletion src/mms/data/ThreadDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ export interface ThreadSearchResult {
matchType: 'thread' | 'project' | 'message'
snippet?: string
messageId?: string
/** The thread is archived. */
archived?: true
}

type ScoredSearchResult = ThreadSearchResult & { score: number }
Expand Down Expand Up @@ -3259,7 +3261,7 @@ export class ThreadDataStore extends EventEmitter {
// Skip pure empty drafts; startedAt may be backfilled above via ensureStartedAt.
if (!thread.startedAt && isDefaultThreadName(thread.name)) continue
const projectName = thread.projectId ? projectNameById.get(thread.projectId) : undefined
const base = { threadId: thread.id, threadName: thread.name, projectId: thread.projectId, projectName }
const base = { threadId: thread.id, threadName: thread.name, projectId: thread.projectId, projectName, ...(thread.archivedAt ? { archived: true as const } : {}) }
if (thread.name.toLowerCase().includes(normalized)) titles.push({ ...base, matchType: 'thread', score: 0 })
if (projectName && projectName.toLowerCase().includes(normalized)) titles.push({ ...base, matchType: 'project', score: 1 })
candidates.push(thread)
Expand Down
12 changes: 8 additions & 4 deletions src/mms/protocol/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3059,15 +3059,18 @@ async function dispatchOwnedMethod(ctx: HandlerContext, method: string, params:
// `perThread`: which threads match (the sidebar's filter), one message hit each, from this computer only; a window
// may ask for every thread of the profile. With `others`, a window's filter asks the user's other computers
// instead (each with a short deadline), apart from this computer's answer, so a slow computer never holds it.
// `titlesOnly`: thread titles only, archived ones too (the composer's `#` list); with `others`, those of the
// user's other computers, on a lane of their own so neither the palette's search nor the filter is cut short.
const perThread = p.perThread === true
const others = perThread && p.others === true
const titlesOnly = p.titlesOnly === true && !perThread
const others = (perThread || titlesOnly) && p.others === true
const limit =
typeof p.limit === 'number' && Number.isFinite(p.limit) && p.limit > 0
? Math.min(Math.floor(p.limit), perThread && connectionIsLocal(ctx.connection) ? SEARCH_PER_THREAD_MAX_LIMIT : 200)
: 50
if (others) {
if (ctx.connection?.clientType !== 'gui' || !ctx.mms.remoteLists) return { results: [] }
const remote = await ctx.mms.remoteLists.search(ctx.connection.id, query, Math.min(limit, 200), { perThread })
const remote = await ctx.mms.remoteLists.search(ctx.connection.id, query, Math.min(limit, 200), { perThread, titlesOnly })
return { results: remote.results, ...(remote.skipped.length ? { skipped: remote.skipped } : {}) }
}
// Search hides subagents for every client, the desktop app included: a subagent is reached
Expand All @@ -3081,12 +3084,13 @@ async function dispatchOwnedMethod(ctx: HandlerContext, method: string, params:
includeArchived: true,
allow: (thread: Thread) => !thread.botOwned && !hidden?.has(thread.id),
...(ctx.connection?.clientType === 'bridge' ? { maxMessageThreads: ROUTED_SEARCH_MESSAGE_THREADS } : {}),
...(perThread ? { perThread } : {})
...(perThread ? { perThread } : {}),
...(titlesOnly ? { titlesOnly } : {})
})
// A window also searches the user's other computers (each with a short deadline) and is told which it could not.
const remote =
ctx.connection?.clientType === 'gui' && ctx.mms.remoteLists && !perThread
? await ctx.mms.remoteLists.search(ctx.connection.id, query, limit)
? await ctx.mms.remoteLists.search(ctx.connection.id, query, limit, { titlesOnly })
: undefined
if (!remote) return { results }
return {
Expand Down
5 changes: 3 additions & 2 deletions src/mms/protocol/remoteListsPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export interface RemoteListsPort {
/**
* The matches on other computers for a search, each computer asked with a short deadline. A newer search
* from the same connection ends the older one's calls. `perThread` (the sidebar's filter) names one message hit per
* thread and is a search of its own: it neither ends nor is ended by the window's other search.
* thread and is a search of its own: it neither ends nor is ended by the window's other search. `titlesOnly` (the
* composer's `#` list) matches thread titles only, archived ones too, and is a search of its own as well.
*/
search(
connection: string | undefined,
query: string,
limit: number,
options?: { perThread?: boolean }
options?: { perThread?: boolean; titlesOnly?: boolean }
): Promise<{ results: ThreadSearchResult[]; skipped: ThreadSearchSkipped[] }>
/**
* A drag in the sidebar: the rows of other computers among `orderedIds` (qualified ids of the group, in the
Expand Down
6 changes: 3 additions & 3 deletions src/mms/run/mcp/appTools/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { isAgentMessageHeld } from '../../AgentChains'
import type { AgentArchiveResult, AgentCreatedThread, AgentQueueCommand, AgentQueueResult, AgentRunCommandResult, AgentThreadRequest, AppToolHost, ApprovalRequestInfo } from './host'
import { archiveBlockersForAgent } from '../../../../shared/archiveBlockers'
import { BOT_HELD_NOTE, type BotAppToolDeps } from './bots'
import { threadLink } from '../../../../shared/threadLink'
import { THREAD_TAG_GUIDANCE, threadLink } from '../../../../shared/threadLink'
import { jobStopCauseOf, PARENT_MESSAGE_MAX_CHARS } from '../../../../shared/bots/personal/jobs'
import { MAX_BOT_MESSAGES_UNANSWERED_BY_OWNER } from '../../../../shared/bots/personal/botMessages'
import { ROUTED_AGENT_BODY_MAX } from '../../../../shared/bridge/routed'
Expand Down Expand Up @@ -991,7 +991,7 @@ function remoteWaitView(threadId: string, computer: string, result: RemoteWaitRe
}

/** What the descriptions of the five tools say about a thread on another computer. */
const REMOTE_REACH = 'A thread on another of the user\'s computers is reached by its qualified id (<computer id>:<thread id>, from thread_create, thread_list or thread_search with computer), as that computer allows. Reading it works as that computer shares it with this one; a change there (send, steer, Stop) is decided by that computer: its person chose which threads this computer\'s agents may change there (only the threads they started, by default; all threads; or none), and a refusal of that (outside_agent_reach) is final: tell the user, never try again. A refusal there names its reason in code: computer_offline, computer_not_used, computer_not_shared, computer_outdated, computer_not_allowed, outside_agent_reach, private_thread, unknown_computer, computers_unreadable, remote_thread_not_found (that computer shares no thread by that id: it may be private or deleted there, or on another computer) or remote_thread_gone (a thread it launched there that is no longer shared: deleted there, or made private).'
const REMOTE_REACH = 'A thread on another of the user\'s computers is reached by its qualified id (<computer id>:<thread id>, from a mousse://thread link in a message, or thread_create, thread_list or thread_search with computer), as that computer allows. Reading it works as that computer shares it with this one; a change there (send, steer, Stop) is decided by that computer: its person chose which threads this computer\'s agents may change there (only the threads they started, by default; all threads; or none), and a refusal of that (outside_agent_reach) is final: tell the user, never try again. A refusal there names its reason in code: computer_offline, computer_not_used, computer_not_shared, computer_outdated, computer_not_allowed, outside_agent_reach, private_thread, unknown_computer, computers_unreadable, remote_thread_not_found (that computer shares no thread by that id: it may be private or deleted there, or on another computer) or remote_thread_gone (a thread it launched there that is no longer shared: deleted there, or made private).'

/** What `thread_list` and `thread_search` say about `computer`. */
/** One of the caller's subagents named the way `task_status` and `task_cancel` named it (`toolVariant`). */
Expand Down Expand Up @@ -2176,7 +2176,7 @@ export function threadTools(host: AppToolHost, engine: RunEngine, bots?: () => B
inputSchema: {
type: 'object',
properties: {
threadId: { type: 'string', description: 'Defaults to your thread. Its id or its link (mousse://thread/…). A plain id pasted from another of your computers is read on the computer that lists it.' },
threadId: { type: 'string', description: `Defaults to your thread. Its id or its link (mousse://thread/…). A plain id pasted from another of your computers is read on the computer that lists it. ${THREAD_TAG_GUIDANCE}` },
view: { type: 'string', enum: ['summary', 'recent', 'messages', 'events', 'delegations'], description: 'Defaults to events (summary for a personal bot). delegations: the work your thread delegated, with its status; no threadId.' },
turns: { type: 'integer', minimum: 1, maximum: RECENT_TURNS_MAX, description: `recent: how many of the last turns (default ${RECENT_TURNS_DEFAULT}).` },
afterSeq: { type: 'integer', minimum: 0, description: 'events: return events after this sequence number.' },
Expand Down
Loading
Loading