@tano.page/protocol 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,148 @@
1
+ import { isAssistantModelId } from '../assistant';
2
+ import type { AgentInbox, AgentInboxStorage, AgentTask, MentionEvent, MentionSource } from '../mentions';
3
+
4
+ /** All transitions use the host's CAS, including claims from another window/device. */
5
+ export class AgentTaskQueue {
6
+ constructor(private readonly storage: AgentInboxStorage, private readonly now = Date.now) {}
7
+
8
+ async update<T>(workspaceId: string, change: (inbox: AgentInbox) => T): Promise<T> {
9
+ for (let attempt = 0; attempt < 12; attempt++) {
10
+ const current = await this.storage.load(workspaceId);
11
+ const next = structuredClone(current);
12
+ const result = change(next);
13
+ if (JSON.stringify(current) === JSON.stringify(next)) return result;
14
+ next.revision = current.revision + 1;
15
+ if (await this.storage.compareExchange(next, current.revision)) return result;
16
+ }
17
+ throw new Error('机器人收件箱正在其他窗口更新,请稍后重试');
18
+ }
19
+
20
+ /** Supply a complete, committed snapshot of this source, including an empty deleted source. */
21
+ async reconcile(workspaceId: string, source: Pick<MentionSource, 'kind' | 'fileId'>, events: MentionEvent[],
22
+ accept: (event: MentionEvent) => boolean = () => true) {
23
+ if (events.some(event => event.workspaceId !== workspaceId || event.source.fileId !== source.fileId || event.source.kind !== source.kind) ||
24
+ new Set(events.map(event => event.id)).size !== events.length) throw new Error('提及事件来源无效');
25
+ await this.update(workspaceId, inbox => {
26
+ const now = this.now();
27
+ for (const event of events) {
28
+ if (!accept(event)) continue;
29
+ const binding = inbox.bindings.find(item => item.personId === event.personId);
30
+ if (!binding) continue;
31
+ const task = inbox.tasks.find(item => item.event.id === event.id && item.event.personId === event.personId);
32
+ if (task) {
33
+ if (task.status === 'queued' && !task.continuation && task.event.revision !== event.revision) {
34
+ task.event = structuredClone(event);
35
+ task.updatedAt = now;
36
+ if (event.source.kind === 'document') task.readyAt = now + 2000;
37
+ }
38
+ continue;
39
+ }
40
+ inbox.tasks.push({ id: crypto.randomUUID(), event: structuredClone(event), binding: { ...binding },
41
+ status: 'queued', sessionId: crypto.randomUUID(), createdAt: now, updatedAt: now, attempts: 0,
42
+ ...(event.source.kind === 'document' ? { readyAt: now + 2000 } : {}) });
43
+ }
44
+ for (const task of inbox.tasks) {
45
+ if (task.event.source.kind !== source.kind || task.event.source.fileId !== source.fileId ||
46
+ !['queued', 'running', 'waiting'].includes(task.status)) continue;
47
+ if (!events.some(event => event.id === task.event.id && event.personId === task.event.personId)) {
48
+ task.status = 'cancelled'; task.updatedAt = now;
49
+ task.error = '原提及已移除'; delete task.claim;
50
+ }
51
+ }
52
+ });
53
+ }
54
+
55
+ async claim(workspaceId: string, owner: string, leaseMs = 60_000): Promise<AgentTask | undefined> {
56
+ if (!owner || !Number.isFinite(leaseMs) || leaseMs < 1000) throw new Error('任务租约无效');
57
+ return this.update(workspaceId, inbox => {
58
+ const now = this.now();
59
+ for (const task of inbox.tasks) {
60
+ if (task.status === 'running' && (!task.claim || task.claim.until <= now)) {
61
+ task.status = 'uncertain'; task.error = '执行进程中断,请核对操作回执';
62
+ task.updatedAt = now; delete task.claim;
63
+ }
64
+ }
65
+ const busy = new Set(inbox.tasks.filter(task => task.status === 'running').map(task => task.binding.personId));
66
+ const firstQueued = new Map<string, AgentTask>();
67
+ for (const item of inbox.tasks) if (item.status === 'queued' && !firstQueued.has(item.binding.personId)) firstQueued.set(item.binding.personId, item);
68
+ const task = [...firstQueued.values()].find(item => (item.readyAt ?? 0) <= now && isAssistantModelId(item.binding.model) && !busy.has(item.binding.personId) &&
69
+ inbox.bindings.some(binding => binding.personId === item.binding.personId && binding.enabled && binding.connectionId === item.binding.connectionId));
70
+ if (!task) return;
71
+ task.status = 'running'; task.attempts++; task.updatedAt = now;
72
+ task.claim = { owner, token: crypto.randomUUID(), until: now + leaseMs };
73
+ return structuredClone(task);
74
+ });
75
+ }
76
+
77
+ async renew(workspaceId: string, taskId: string, token: string, leaseMs = 60_000) {
78
+ if (!Number.isFinite(leaseMs) || leaseMs < 1000) throw new Error('任务租约无效');
79
+ await this.update(workspaceId, inbox => {
80
+ const task = this.owned(inbox, taskId, token);
81
+ task.claim!.until = this.now() + leaseMs;
82
+ });
83
+ }
84
+
85
+ async recordResult(workspaceId: string, taskId: string, token: string, body: string,
86
+ outcome: 'succeeded' | 'waiting' | 'uncertain' = 'succeeded') {
87
+ if (!body.trim() || body.length > 20_000) throw new Error('机器人回复长度无效');
88
+ return this.update(workspaceId, inbox => {
89
+ const task = this.owned(inbox, taskId, token);
90
+ task.result ??= { messageId: crypto.randomUUID(), body, outcome };
91
+ task.updatedAt = this.now();
92
+ return { ...task.result };
93
+ });
94
+ }
95
+
96
+ async settle(workspaceId: string, taskId: string, token: string,
97
+ status: 'succeeded' | 'failed' | 'waiting' | 'uncertain', error?: string) {
98
+ await this.update(workspaceId, inbox => {
99
+ const task = this.owned(inbox, taskId, token);
100
+ if (status === 'succeeded' && !task.result) throw new Error('任务尚未记录回复');
101
+ task.status = status; task.error = error; task.updatedAt = this.now(); delete task.claim;
102
+ });
103
+ }
104
+
105
+ async cancel(workspaceId: string, taskId: string) {
106
+ await this.update(workspaceId, inbox => {
107
+ const task = inbox.tasks.find(item => item.id === taskId);
108
+ if (!task || !['queued', 'running', 'waiting'].includes(task.status)) return;
109
+ task.status = 'cancelled'; task.updatedAt = this.now(); delete task.claim;
110
+ });
111
+ }
112
+
113
+ async resume(workspaceId: string, taskId: string, reply: NonNullable<AgentTask['continuation']>, questionId: string) {
114
+ await this.update(workspaceId, inbox => {
115
+ const task = inbox.tasks.find(item => item.id === taskId);
116
+ if (!task || task.status !== 'waiting' || task.result?.messageId !== questionId) return;
117
+ task.continuation = { ...reply };
118
+ task.status = 'queued'; task.updatedAt = this.now();
119
+ delete task.result; delete task.error;
120
+ });
121
+ }
122
+
123
+ async retry(workspaceId: string, taskId: string, updatedAt: number) {
124
+ await this.update(workspaceId, inbox => {
125
+ const task = inbox.tasks.find(task => task.id === taskId);
126
+ if (!task || task.updatedAt !== updatedAt || !(task.status === 'failed' || task.status === 'uncertain' && task.result))
127
+ throw new Error('任务已变化或执行结果待核对,请先查看执行记录');
128
+ task.status = 'queued'; task.updatedAt = this.now(); delete task.error;
129
+ });
130
+ }
131
+
132
+ /** Only the runner may release a claim before entering its persisted execution path. */
133
+ async releaseUnstarted(workspaceId: string, taskId: string, token: string) {
134
+ await this.update(workspaceId, inbox => {
135
+ const task = this.owned(inbox, taskId, token);
136
+ task.status = 'queued'; task.updatedAt = this.now(); delete task.claim;
137
+ });
138
+ }
139
+
140
+ private owned(inbox: AgentInbox, taskId: string, token: string): AgentTask {
141
+ const task = inbox.tasks.find(item => item.id === taskId);
142
+ if (!task || task.status !== 'running' || task.claim?.token !== token || task.claim.until <= this.now())
143
+ throw new Error('任务执行权已失效');
144
+ if (!inbox.bindings.some(binding => binding.personId === task.binding.personId && binding.enabled &&
145
+ binding.connectionId === task.binding.connectionId)) throw new Error('机器人连接已停用或更换');
146
+ return task;
147
+ }
148
+ }
@@ -0,0 +1,19 @@
1
+ import { isDataTableFilePath, parseDataTable } from '../data-tables';
2
+ import { isMarkdown, validatePath } from '../paths';
3
+ import { isWorkspaceInternalPath } from '../workspace-paths';
4
+
5
+ /** Assistant access is limited to ordinary user documents and portable data tables. */
6
+ export const isAssistantFile = (path: string) =>
7
+ !validatePath(path) &&
8
+ !isWorkspaceInternalPath(path) &&
9
+ (isMarkdown(path) || isDataTableFilePath(path));
10
+
11
+ export function validateAssistantContent(path: string, content: string, base?: string) {
12
+ if (!isAssistantFile(path) || content.length > 512_000) throw new Error('文件路径或内容无效');
13
+ if (isDataTableFilePath(path)) {
14
+ parseDataTable(content, base === undefined ? undefined : parseDataTable(base).id);
15
+ }
16
+ }
17
+
18
+ export const validAssistantDestination = (source: string, destination: string) =>
19
+ isAssistantFile(destination) && isDataTableFilePath(source) === isDataTableFilePath(destination);
@@ -0,0 +1,90 @@
1
+ import type {
2
+ AssistantActivity,
3
+ AssistantMessage,
4
+ AssistantToolResult,
5
+ AssistantUserInput,
6
+ AssistantWireMessage,
7
+ } from '../assistant';
8
+
9
+ export function assistantMessageParts(message: AssistantMessage) {
10
+ const parts: ({ kind: 'text'; content: string } | { kind: 'input'; input: AssistantUserInput })[] = [];
11
+ let offset = 0;
12
+ for (const input of message.userInputs ?? []) {
13
+ if (input.contentOffset > offset) parts.push({ kind: 'text', content: message.content.slice(offset, input.contentOffset) });
14
+ parts.push({ kind: 'input', input });
15
+ offset = input.contentOffset;
16
+ }
17
+ if (offset < message.content.length) parts.push({ kind: 'text', content: message.content.slice(offset) });
18
+ return parts;
19
+ }
20
+
21
+ export type AssistantDisplayPart =
22
+ | { kind: 'text'; content: string; key: string }
23
+ | { kind: 'input'; input: AssistantUserInput; key: string }
24
+ | { kind: 'tool'; tool: Extract<AssistantActivity, { kind: 'tool' }>; result?: AssistantToolResult; key: string };
25
+
26
+ export function assistantDisplayParts(message: AssistantMessage) {
27
+ const process: AssistantDisplayPart[] = [], answer: AssistantDisplayPart[] = [];
28
+ const unfinished = !!message.state && ['failed', 'cancelled', 'interrupted'].includes(message.state);
29
+ if (!message.activity) {
30
+ (unfinished ? process : answer).push(...assistantMessageParts(message).map((part, index) => ({ ...part, key: `legacy-${index}` })));
31
+ return { process, answer };
32
+ }
33
+ for (const [index, item] of message.activity.entries()) {
34
+ const key = `activity-${index}`;
35
+ if (item.kind === 'text') {
36
+ const content = message.content.slice(item.start, item.end);
37
+ const live = message.state === 'running' || message.state === 'waiting';
38
+ if (content.trim()) (unfinished || item.phase === 'working' || (item.phase === 'pending' && !live) ? process : answer).push({ kind: 'text', content, key });
39
+ } else if (item.kind === 'tool') {
40
+ process.push({ kind: 'tool', tool: item, key, result: message.toolResults?.[item.resultIndex!] });
41
+ } else {
42
+ const input = message.userInputs?.find(input => input.id === item.inputId);
43
+ if (input) process.push({ kind: 'input', input, key });
44
+ }
45
+ }
46
+ return { process, answer };
47
+ }
48
+
49
+ /** Copy/export only the final (or currently streaming) answer, never the work log. */
50
+ export function assistantAnswerText(message: AssistantMessage): string {
51
+ if (message.state && !['running', 'waiting', 'completed'].includes(message.state)) return '';
52
+ if (!message.activity) return message.content;
53
+ return message.activity.filter(item => item.kind === 'text' && item.phase === 'answer')
54
+ .map(item => item.kind === 'text' ? message.content.slice(item.start, item.end) : '').join('\n\n');
55
+ }
56
+
57
+ /** Keep the model's prose separate from the application's current review state. */
58
+ export function assistantHistory(messages: readonly AssistantMessage[]): AssistantWireMessage[] {
59
+ return messages.slice(-16).flatMap<AssistantWireMessage>(message => {
60
+ if (message.role === 'user') return [{ role: 'user', content: message.attachments?.length
61
+ ? `${message.content}\nPrevious clipboard attachment names (contents no longer supplied): ${JSON.stringify(message.attachments)}`
62
+ : message.content }];
63
+ const history: AssistantWireMessage[] = [];
64
+ for (const part of assistantMessageParts(message)) {
65
+ if (part.kind === 'text') history.push({ role: 'assistant', content: part.content });
66
+ else if (part.input.status === 'answered') history.push({ role: 'user', content: JSON.stringify({
67
+ questions: part.input.questions, answers: part.input.answers,
68
+ }) });
69
+ }
70
+ // Include actual operation receipts even when a message only asked questions.
71
+ const last = history.at(-1);
72
+ const answer = last?.role === 'assistant' ? history.pop()!.content : '';
73
+ history.push({ role: 'assistant', content: JSON.stringify({ answer, execution: {
74
+ state: message.state ?? 'unknown',
75
+ ...(message.termination ? { termination: message.termination.reason } : {}),
76
+ ...(message.error ? { error: message.error.slice(0, 2000) } : {}),
77
+ // Null distinguishes old conversations without receipts from a verified empty list.
78
+ tools: message.toolResults ?? null,
79
+ proposals: (message.proposals ?? []).map(proposal => ({
80
+ id: proposal.id, kind: proposal.kind, path: proposal.path, status: proposal.status,
81
+ ...(proposal.execution ? { execution: proposal.execution } : {}),
82
+ ...(proposal.destination ? { destination: proposal.destination } : {}),
83
+ review: proposal.suggestionGroupId ? 'document' : 'conversation',
84
+ written: proposal.suggestionGroupId || ['applying', 'unknown'].includes(proposal.status)
85
+ ? null : proposal.status === 'applied',
86
+ })),
87
+ } }) });
88
+ return history;
89
+ });
90
+ }
@@ -0,0 +1,17 @@
1
+ export const PLUGIN_UNTRUSTED_START = '[UNTRUSTED_PLUGIN_DATA';
2
+ export const PLUGIN_UNTRUSTED_END = '[/UNTRUSTED_PLUGIN_DATA]';
3
+
4
+ /** Escape any spoofed boundary tokens so untrusted tool/plugin output cannot break out. */
5
+ export function sanitizePluginBoundaryText(value: string): string {
6
+ return value
7
+ .replaceAll(PLUGIN_UNTRUSTED_START, '[ESCAPED_UNTRUSTED_PLUGIN_DATA')
8
+ .replaceAll(PLUGIN_UNTRUSTED_END, '[/ESCAPED_UNTRUSTED_PLUGIN_DATA]');
9
+ }
10
+
11
+ /** Wrap untrusted plugin/tool-supplied data in explicit boundary markers before sending to an LLM. */
12
+ export function wrapUntrustedPluginData(pluginId: string, source: string, payload: unknown): string {
13
+ const safePluginId = pluginId.replace(/[^a-zA-Z0-9._-]/g, '_');
14
+ const safeSource = source.replace(/[^a-zA-Z0-9._:-]/g, '_');
15
+ const body = typeof payload === 'string' ? payload : JSON.stringify(payload);
16
+ return `${PLUGIN_UNTRUSTED_START} plugin="${safePluginId}" source="${safeSource}"]\n${sanitizePluginBoundaryText(body)}\n${PLUGIN_UNTRUSTED_END}`;
17
+ }
@@ -0,0 +1,148 @@
1
+ import {
2
+ emptyCommentFile,
3
+ parseCommentFile,
4
+ rebaseCommentMentions,
5
+ type CommentAnchor,
6
+ type CommentFile,
7
+ type CommentKind,
8
+ type CommentMention,
9
+ type CommentMessage,
10
+ type CommentThread,
11
+ } from '../comments';
12
+ import { commentDataPath } from '../workspace-paths';
13
+ import type { Workspace, WorkspaceAdapter } from '../types';
14
+
15
+ export interface CommentAuthor { id: string; name: string }
16
+ export type CommentStorage = Pick<WorkspaceAdapter, 'refresh' | 'read' | 'write' | 'create'>;
17
+ export interface CommentMessageEdit { messageId: string; expectedBody: string; body: string; mentions?: CommentMention[] }
18
+ export interface CommentMessageRemoval {
19
+ messageId: string;
20
+ expectedBody: string;
21
+ expectedMessages?: { id: string; body: string }[];
22
+ }
23
+ const pendingWrites = new WeakMap<CommentStorage, Map<string, Promise<unknown>>>();
24
+ export type CommentChange =
25
+ | { type: 'start'; id: string; body: string; author: CommentAuthor; anchor?: CommentAnchor; mentions?: CommentMention[]; agentTaskId?: string }
26
+ | { type: 'reply'; threadId: string; id: string; body: string; author: CommentAuthor; replyTo?: string; mentions?: CommentMention[]; agentTaskId?: string }
27
+ | { type: 'resolve'; threadId: string; resolved: boolean }
28
+ | ({ type: 'edit'; threadId: string; authorId: string } & CommentMessageEdit)
29
+ | ({ type: 'delete'; threadId: string; authorId: string } & CommentMessageRemoval)
30
+ | { type: 'reanchor'; threadId: string; expectedBaseHash: string; anchor: CommentAnchor | null };
31
+
32
+ function message(id: string, body: string, author: CommentAuthor, mentions?: CommentMention[], replyTo?: string): CommentMessage {
33
+ return { id, body: body.trim(), authorId: author.id, authorName: author.name, createdAt: Date.now(),
34
+ ...(mentions?.length ? { mentions: rebaseCommentMentions(mentions, body, body.trim()) } : {}), ...(replyTo ? { replyTo } : {}) };
35
+ }
36
+
37
+ /** Each edit is reapplied to the newest file, so independent replies survive a CAS conflict. */
38
+ export function applyCommentChange(file: CommentFile, change: CommentChange): CommentFile {
39
+ const next = structuredClone(file);
40
+ if (change.type === 'start') {
41
+ if (next.threads.some(thread => thread.id === change.id)) return next;
42
+ if (!change.body.trim()) throw new Error('请输入评论内容');
43
+ if (next.kind === 'annotation' && !change.anchor) throw new Error('请先选择要批注的内容');
44
+ if (next.kind === 'discussion' && change.anchor) throw new Error('整篇讨论不需要局部锚点');
45
+ const createdAt = Date.now();
46
+ next.threads.push({ id: change.id, ...(change.anchor ? { anchor: change.anchor } : {}),
47
+ messages: [{ ...message(change.id, change.body, change.author, change.mentions),
48
+ ...(change.agentTaskId ? { agentTaskId: change.agentTaskId } : {}) }], resolved: false,
49
+ detached: false, createdAt });
50
+ } else {
51
+ const thread = next.threads.find(item => item.id === change.threadId);
52
+ if (!thread && change.type === 'delete') return next;
53
+ if (!thread) throw new Error('评论已被移除,请刷新后重试');
54
+ if (change.type === 'reply') {
55
+ if (thread.messages.some(item => item.id === change.id)) return next;
56
+ if (!change.body.trim()) throw new Error('请输入回复内容');
57
+ thread.messages.push({ ...message(change.id, change.body, change.author, change.mentions, change.replyTo),
58
+ ...(change.agentTaskId ? { agentTaskId: change.agentTaskId } : {}) });
59
+ } else if (change.type === 'resolve') thread.resolved = change.resolved;
60
+ else if (change.type === 'edit' || change.type === 'delete') {
61
+ const index = thread.messages.findIndex(item => item.id === change.messageId);
62
+ const current = thread.messages[index];
63
+ if (!current && change.type === 'delete') return next;
64
+ if (!current) throw new Error('评论已被移除,请刷新后重试');
65
+ if (current.authorId !== change.authorId) throw new Error('只能编辑或删除自己发表的评论');
66
+ if (current.body !== change.expectedBody) throw new Error('评论已由其他编辑更新,请刷新后重试;输入内容仍保留');
67
+ if (change.type === 'edit') {
68
+ if (!change.body.trim()) throw new Error('请输入评论内容');
69
+ current.mentions = change.mentions === undefined
70
+ ? rebaseCommentMentions(current.mentions ?? [], current.body, change.body.trim())
71
+ : rebaseCommentMentions(change.mentions, change.body, change.body.trim());
72
+ current.body = change.body.trim();
73
+ current.updatedAt = Date.now();
74
+ } else if (index === 0) {
75
+ if (!change.expectedMessages || change.expectedMessages.length !== thread.messages.length ||
76
+ thread.messages.some((item, i) => item.id !== change.expectedMessages![i]?.id ||
77
+ item.body !== change.expectedMessages![i]?.body))
78
+ throw new Error('评论或回复已变化,请刷新后重新确认删除');
79
+ next.threads = next.threads.filter(item => item.id !== thread.id);
80
+ } else {
81
+ thread.messages.splice(index, 1);
82
+ for (const item of thread.messages) if (item.replyTo === change.messageId) delete item.replyTo;
83
+ }
84
+ }
85
+ else {
86
+ if (!thread.anchor || thread.anchor.baseHash !== change.expectedBaseHash)
87
+ throw new Error('批注锚点已由其他编辑更新,请刷新后重试');
88
+ if (change.anchor) thread.anchor = change.anchor;
89
+ thread.detached = !change.anchor;
90
+ }
91
+ }
92
+ return parseCommentFile(JSON.stringify(next), next.kind, next.fileId);
93
+ }
94
+
95
+ export async function loadCommentFile(adapter: CommentStorage, kind: CommentKind, fileId: string, workspaceSnapshot?: Workspace) {
96
+ const path = commentDataPath(kind, fileId);
97
+ const workspace = workspaceSnapshot ?? await adapter.refresh();
98
+ if (!workspace.files.some(file => file.kind === 'file' && file.path === path))
99
+ return { file: emptyCommentFile(kind, fileId), hash: null as string | null };
100
+ const snapshot = await adapter.read(path);
101
+ return { file: parseCommentFile(snapshot.content, kind, fileId), hash: snapshot.hash };
102
+ }
103
+
104
+ export async function saveCommentChange(
105
+ adapter: CommentStorage,
106
+ kind: CommentKind,
107
+ fileId: string,
108
+ change: CommentChange,
109
+ ) {
110
+ const path = commentDataPath(kind, fileId);
111
+ let queued = pendingWrites.get(adapter);
112
+ if (!queued) { queued = new Map(); pendingWrites.set(adapter, queued); }
113
+ const previous = queued.get(path);
114
+ const save = async () => {
115
+ await previous?.catch(() => {});
116
+ return writeCommentChange(adapter, kind, fileId, path, change);
117
+ };
118
+ const result = save();
119
+ queued.set(path, result);
120
+ try { return await result; }
121
+ finally { if (queued.get(path) === result) queued.delete(path); }
122
+ }
123
+
124
+ async function writeCommentChange(
125
+ adapter: CommentStorage, kind: CommentKind, fileId: string, path: string, change: CommentChange,
126
+ ) {
127
+ for (let attempt = 0; attempt < 5; attempt++) {
128
+ const current = await loadCommentFile(adapter, kind, fileId);
129
+ const updated = applyCommentChange(current.file, change);
130
+ const content = `${JSON.stringify(updated, null, 2)}\n`;
131
+ if (current.hash) {
132
+ const result = await adapter.write(path, content, current.hash);
133
+ if (result.status === 'saved') return updated;
134
+ if (result.status === 'missing') continue;
135
+ } else {
136
+ try { await adapter.create(path, content); return updated; }
137
+ catch (error) {
138
+ const refreshed = await adapter.refresh();
139
+ if (!refreshed.files.some(file => file.path === path)) throw error;
140
+ }
141
+ }
142
+ }
143
+ throw new Error('评论同时被修改,请稍后重试;输入内容仍保留');
144
+ }
145
+
146
+ export function visibleThreads(file: CommentFile): CommentThread[] {
147
+ return file.threads.filter(thread => !thread.detached);
148
+ }