@tano.page/workbench 0.15.0 → 0.16.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.
Files changed (118) hide show
  1. package/package.json +35 -14
  2. package/src/App.vue +68 -797
  3. package/src/assistant/agent-identities.ts +1 -97
  4. package/src/assistant/agent-task-context.ts +1 -54
  5. package/src/assistant/attachments.ts +1 -1
  6. package/src/assistant/completion.ts +1 -61
  7. package/src/assistant/components/AssistantPanel.vue +1 -1
  8. package/src/assistant/connection-actions.ts +237 -0
  9. package/src/assistant/document-mentions.ts +1 -33
  10. package/src/assistant/engine.ts +1 -585
  11. package/src/assistant/execution.ts +6 -33
  12. package/src/assistant/hash.ts +1 -4
  13. package/src/assistant/language.ts +10 -37
  14. package/src/assistant/plugin-bridge-builder.ts +146 -0
  15. package/src/assistant/prompts.ts +1 -65
  16. package/src/assistant/proposal-actions.ts +336 -0
  17. package/src/assistant/store.ts +87 -554
  18. package/src/assistant/structures.ts +1 -157
  19. package/src/assistant/tasks.ts +8 -94
  20. package/src/assistant/tool-rules.ts +1 -7
  21. package/src/composables/use-workbench-help.ts +177 -0
  22. package/src/composables/use-workbench-lifecycle.ts +249 -0
  23. package/src/composables/use-workbench-settings.ts +185 -0
  24. package/src/composables/use-workbench-shortcuts.ts +37 -1022
  25. package/src/composables/use-workbench-views.ts +325 -0
  26. package/src/documents/components/DocumentActionMenu.vue +279 -0
  27. package/src/documents/components/DocumentInspector.vue +168 -0
  28. package/src/documents/components/DocumentPane.vue +482 -0
  29. package/src/documents/description-merge.ts +1 -9
  30. package/src/files/components/FileMetadataPanel.vue +49 -15
  31. package/src/i18n/locale-catalogs.ts +7 -6
  32. package/src/i18n/locale-registry.ts +8 -6
  33. package/src/i18n/locales/de-DE.json +23 -1
  34. package/src/i18n/locales/en-US.json +23 -1
  35. package/src/i18n/locales/es-ES.json +23 -1
  36. package/src/i18n/locales/ja-JP.json +23 -1
  37. package/src/i18n/locales/zh-TW.json +23 -1
  38. package/src/mail/components/MailAccountDialog.vue +1 -0
  39. package/src/mail/components/MailComposerDialog.vue +1 -0
  40. package/src/mail/components/MailWorkspaceView.vue +1 -0
  41. package/src/mail/components/SidebarMail.vue +1 -0
  42. package/src/objects/content-references.ts +6 -56
  43. package/src/objects/wiki-links.ts +1 -48
  44. package/src/objects/workspace-objects.ts +2 -3
  45. package/src/plans/calendar.ts +2 -2
  46. package/src/plans/components/CalendarAgendaView.vue +165 -0
  47. package/src/plans/components/CalendarFilterBar.vue +128 -0
  48. package/src/plans/components/CalendarMonthView.vue +224 -0
  49. package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
  50. package/src/plans/components/CalendarTimelineView.vue +517 -0
  51. package/src/plans/components/CalendarTopbarControls.vue +101 -0
  52. package/src/plans/components/CalendarView.vue +162 -2106
  53. package/src/plans/components/CalendarYearView.vue +138 -0
  54. package/src/plans/components/PlanConnectionsDialog.vue +1 -1
  55. package/src/plans/components/calendar-shared.css +192 -0
  56. package/src/plans/composables/use-calendar-interactions.ts +396 -0
  57. package/src/plans/composables/use-calendar-scroll.ts +420 -0
  58. package/src/plugins/components/PluginDetailPage.vue +10 -6
  59. package/src/plugins/components/PluginDeveloperArea.vue +192 -0
  60. package/src/plugins/components/PluginExplorer.vue +6 -4
  61. package/src/plugins/components/PluginImportDialog.vue +1 -1
  62. package/src/plugins/components/PluginInstaller.vue +269 -178
  63. package/src/plugins/components/PluginMaintenance.vue +37 -49
  64. package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
  65. package/src/plugins/components/PluginSettingsForm.vue +2 -1
  66. package/src/plugins/components/PluginsTabPage.vue +61 -0
  67. package/src/plugins/components/plugin-center.css +5 -0
  68. package/src/plugins/data.ts +9 -86
  69. package/src/plugins/editor-plugin-adapters.ts +169 -0
  70. package/src/plugins/plugin-data.ts +2 -3
  71. package/src/plugins/plugin-rpc-router.ts +558 -0
  72. package/src/plugins/plugin-sdk.ts +1 -260
  73. package/src/plugins/plugin-ui-dialogs.ts +167 -0
  74. package/src/plugins/queries.ts +1 -75
  75. package/src/plugins/view-header.ts +2 -7
  76. package/src/runtime.ts +3 -2
  77. package/src/settings/components/SettingsPanel.vue +8 -3
  78. package/src/settings/components/WorkbenchSettings.vue +20 -7
  79. package/src/settings/components/settings-context.ts +1 -1
  80. package/src/settings/settings-tab.ts +1 -0
  81. package/src/shell/command-palette.ts +3 -3
  82. package/src/shell/components/EditorToolbar.vue +8 -9
  83. package/src/shell/components/EditorTools.vue +1 -5
  84. package/src/shell/components/PaneTopbar.vue +393 -0
  85. package/src/shell/components/SelectionToolbar.vue +0 -2
  86. package/src/shell/components/WorkbenchContextMenus.vue +37 -26
  87. package/src/shell/components/WorkbenchModals.vue +22 -18
  88. package/src/shell/components/WorkbenchPanes.vue +358 -1512
  89. package/src/shell/components/WorkbenchSidebar.vue +486 -0
  90. package/src/shell/pane-registry.ts +69 -0
  91. package/src/shell/use-surface-dismissal.ts +219 -0
  92. package/src/shell/use-workbench-commands.ts +599 -0
  93. package/src/shell/use-workbench-keybindings.ts +337 -0
  94. package/src/shell/use-workbench.ts +488 -1081
  95. package/src/shell/workbench-context.ts +30 -3
  96. package/src/stores/workspace-document-io.ts +807 -0
  97. package/src/stores/workspace-file-ops.ts +1 -1
  98. package/src/stores/workspace-knowledge.ts +1 -1
  99. package/src/stores/workspace-lifecycle.ts +459 -0
  100. package/src/stores/workspace-plugins-state.ts +71 -599
  101. package/src/stores/workspace-session.ts +287 -0
  102. package/src/stores/workspace-tabs-layout.ts +1 -1
  103. package/src/stores/workspace-types.ts +50 -0
  104. package/src/stores/workspace.ts +163 -1345
  105. package/src/styles.css +0 -1
  106. package/src/tabs/components/DesktopTabs.vue +19 -11
  107. package/src/windows/AuxiliaryWindows.vue +2 -2
  108. package/src/windows/use-window-event-bridge.ts +152 -0
  109. package/src/workspace/components/TemplateLibrary.vue +1 -1
  110. package/src/workspace/components/WorkspaceIconPicker.vue +5 -4
  111. package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
  112. package/src/assistant/locales/de-DE.json +0 -129
  113. package/src/assistant/locales/en-US.json +0 -129
  114. package/src/assistant/locales/es-ES.json +0 -129
  115. package/src/assistant/locales/ja-JP.json +0 -129
  116. package/src/assistant/locales/zh-CN.json +0 -129
  117. package/src/assistant/locales/zh-TW.json +0 -129
  118. package/src/assistant/task-prompts.json +0 -39
@@ -1,157 +1 @@
1
- import { isActionableTask, parseObject, parseRelations, referenceKey, relationKey, validateObjectProperties, validateRelation, withPlanCompleted, workspaceRelationPath } from '@tano/protocol';
2
- import type { AssistantProposal, AssistantRequest, AssistantToolCall, ReferenceTarget, RelationTypeDefinition, WorkspaceRelation, WorkspaceObject, RelationFile } from '@tano/protocol';
3
-
4
- const text = { type: 'string' };
5
- const endpoint = { type: 'object', properties: { type: text, id: text }, required: ['type', 'id'], additionalProperties: false };
6
- const tool = (name: string, description: string, properties: Record<string, unknown>, required: string[]) => ({ type: 'function' as const,
7
- function: { name, description, parameters: { type: 'object', properties, required, additionalProperties: false } } });
8
- export const structureTools: NonNullable<AssistantRequest['tools']> = [
9
- tool('read_workspace_objects', '读取用户授权的工作区对象、可引用目标与关系类型;不包含个人计划,不读取附件正文。', {}, []),
10
- tool('propose_event', '建议创建工作区事件。任务也用事件表示,checkable=true;只提出建议,不发布到个人计划或外部日历。', {
11
- name: text, description: text, reason: text, properties: { type: 'object', properties: {
12
- checkable: { type: 'boolean' }, completed: { type: 'boolean' }, due: text, date: text, start: text, end: text,
13
- }, additionalProperties: false },
14
- }, ['name', 'description', 'properties', 'reason']),
15
- tool('propose_relation', '建议在两个已有工作区目标之间新增关系,必须使用读取结果中的 type 和稳定 id;只提出建议。', {
16
- type: text, source: endpoint, target: endpoint, reason: text,
17
- }, ['type', 'source', 'target', 'reason']),
18
- tool('propose_task_update', '基于已读取的任务快照建议修改名称、描述或日期及完成状态。patch 只包含需要修改的字段;属性 null 表示清除。描述保留引用。完成建议须在 reason 中注明验收依据;等待用户确认。', {
19
- target: endpoint, patch: { type: 'object', properties: { name: text, description: text, properties: { type: 'object', properties: {
20
- completed: { type: 'boolean' }, due: { type: ['string', 'null'] }, date: { type: ['string', 'null'] },
21
- start: { type: ['string', 'null'] }, end: { type: ['string', 'null'] },
22
- }, additionalProperties: false } }, additionalProperties: false }, reason: text,
23
- }, ['target', 'patch', 'reason']),
24
- tool('propose_assignment', '建议替换任务负责人或清除分配。target 必须是已读取任务,personId 必须是已读取人物的稳定 ID,null 清除。保留其他任务的负责人;等待用户确认。', {
25
- target: endpoint, personId: { type: ['string', 'null'] }, reason: text,
26
- }, ['target', 'personId', 'reason']),
27
- tool('propose_relation_change', '建议修改或移除已有关系。使用已读 relationId;remove 时 type/source/target 均为 null。修改保留关系身份;等待用户确认。', {
28
- relationId: text, action: { type: 'string', enum: ['update', 'remove'] }, type: { type: ['string', 'null'] },
29
- source: { anyOf: [endpoint, { type: 'null' }] }, target: { anyOf: [endpoint, { type: 'null' }] }, reason: text,
30
- }, ['relationId', 'action', 'type', 'source', 'target', 'reason']),
31
- ];
32
-
33
- export const structureToolNames = new Set(structureTools.map(item => item.function.name));
34
- export interface StructureSnapshot {
35
- targets: readonly ReferenceTarget[];
36
- relationTypes: readonly RelationTypeDefinition[];
37
- relationContent: string;
38
- objects: readonly { object: WorkspaceObject; path: string; content: string; fileId: string }[];
39
- }
40
- const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
41
- const available = (targets: readonly ReferenceTarget[], identity: { type: string; id: string }) =>
42
- targets.some(target => referenceKey(target) === referenceKey(identity) && !target.archived);
43
- export function requireTask(object: WorkspaceObject) {
44
- if (object.archived || !isActionableTask(object))
45
- throw new Error('只能修改可用的已有任务');
46
- }
47
- export function validateTaskUpdate(base: WorkspaceObject, proposed: WorkspaceObject) {
48
- requireTask(base); requireTask(proposed);
49
- if (!same({ ...base, name: '', description: '', properties: {} }, { ...proposed, name: '', description: '', properties: {} }))
50
- throw new Error('任务身份、类型和扩展字段不能修改');
51
- for (const key of new Set([...Object.keys(base.properties), ...Object.keys(proposed.properties)])) {
52
- if (!['completed', 'due', 'date', 'start', 'end', 'status'].includes(key) && !same(base.properties[key], proposed.properties[key]))
53
- throw new Error('任务属性修改超出允许范围');
54
- }
55
- validateObjectProperties('event', proposed.properties);
56
- }
57
-
58
- export function structureProposal(call: AssistantToolCall, context: {
59
- workspaceId: string; runId: string; id: string; relationContent: string; targets: readonly ReferenceTarget[];
60
- relationTypes: readonly RelationTypeDefinition[];
61
- objects?: StructureSnapshot['objects'];
62
- }): AssistantProposal {
63
- const args = JSON.parse(call.function.arguments);
64
- const keys = ({ propose_event: ['name', 'description', 'properties', 'reason'],
65
- propose_relation: ['type', 'source', 'target', 'reason'], propose_task_update: ['target', 'patch', 'reason'],
66
- propose_assignment: ['target', 'personId', 'reason'], propose_relation_change: ['relationId', 'action', 'type', 'source', 'target', 'reason'],
67
- } as Record<string, string[]>)[call.function.name];
68
- if (!keys) throw new Error('工作区工具未授权');
69
- if (!args || typeof args !== 'object' || Array.isArray(args) || Object.keys(args).some(key => !keys.includes(key)) ||
70
- keys.some(key => !(key in args)) || typeof args.reason !== 'string' || !args.reason.trim() || args.reason.length > 4000)
71
- throw new Error('工作区建议参数无效');
72
- const common = { id: crypto.randomUUID(), workspaceId: context.workspaceId, runId: context.runId, reason: args.reason, status: 'ready' as const };
73
- if (call.function.name === 'propose_event') {
74
- const object = parseObject(JSON.stringify({ version: 1, id: context.id, type: 'event', name: args.name,
75
- description: args.description, properties: args.properties, archived: false }));
76
- validateObjectProperties('event', object.properties);
77
- return { ...common, kind: 'object', path: `.tano/objects/${object.id}.tano.json`, base: '', content: JSON.stringify(object, null, 2) + '\n' };
78
- }
79
- if (['propose_task_update', 'propose_assignment'].includes(call.function.name)) {
80
- if (!args.target || Object.keys(args.target).sort().join() !== 'id,type') throw new Error('任务目标无效');
81
- const record = context.objects?.find(record => referenceKey(record.object) === referenceKey(args.target));
82
- if (!record) throw new Error('必须先读取已有任务快照');
83
- requireTask(record.object);
84
- if (call.function.name === 'propose_task_update') {
85
- const patch = args.patch;
86
- if (!patch || typeof patch !== 'object' || Array.isArray(patch) || !Object.keys(patch).length ||
87
- Object.keys(patch).some(key => !['name', 'description', 'properties'].includes(key))) throw new Error('任务修改字段无效');
88
- const properties = { ...record.object.properties };
89
- if ('properties' in patch) {
90
- if (!patch.properties || typeof patch.properties !== 'object' || Array.isArray(patch.properties) ||
91
- Object.keys(patch.properties).some(key => !['completed', 'due', 'date', 'start', 'end'].includes(key))) throw new Error('任务属性修改无效');
92
- for (const [key, value] of Object.entries(patch.properties)) {
93
- if (value === null && key !== 'completed') delete properties[key];
94
- else properties[key] = value;
95
- }
96
- if ('completed' in patch.properties) {
97
- const synced = withPlanCompleted({ ...record.object, properties }, Boolean(patch.properties.completed));
98
- Object.assign(properties, synced.properties);
99
- }
100
- }
101
- const object = parseObject(JSON.stringify({ ...record.object, ...patch, properties }));
102
- validateTaskUpdate(record.object, object);
103
- if (same(record.object, object)) throw new Error('任务没有变化');
104
- return { ...common, kind: 'object', path: record.path, fileId: record.fileId, base: record.content, content: JSON.stringify(object, null, 2) + '\n' };
105
- }
106
- }
107
- const base = context.relationContent ? parseRelations(context.relationContent) : { version: 1 as const, relations: [] };
108
- let rows = [...base.relations];
109
- if (call.function.name === 'propose_assignment') {
110
- if (args.personId !== null && (typeof args.personId !== 'string' || !available(context.targets, { type: 'person', id: args.personId })))
111
- throw new Error('负责人不属于可用工作区人物');
112
- const matches = (row: WorkspaceRelation) => row.type === 'assigned' && referenceKey(row.target) === referenceKey(args.target);
113
- const existing = rows.find(row => matches(row) && row.source.id === args.personId);
114
- rows = rows.filter(row => !matches(row));
115
- if (args.personId !== null) rows.push(existing ?? { id: context.id, type: 'assigned', source: { type: 'person', id: args.personId }, target: args.target });
116
- } else if (call.function.name === 'propose_relation_change') {
117
- const previous = rows.find(row => row.id === args.relationId);
118
- if (!previous) throw new Error('必须使用已读取的关系 ID');
119
- if (args.action === 'remove') {
120
- if (args.type !== null || args.source !== null || args.target !== null) throw new Error('移除关系参数无效');
121
- rows = rows.filter(row => row.id !== previous.id);
122
- } else if (args.action === 'update') {
123
- rows = rows.map(row => row.id === previous.id ? { ...previous, type: args.type, source: args.source, target: args.target } : row);
124
- } else throw new Error('关系维护操作无效');
125
- } else rows.push({ id: context.id, type: args.type, source: args.source, target: args.target });
126
- const file = parseRelations(JSON.stringify({ ...base, relations: rows }));
127
- mergeStructureRelations(base, file, base, context.targets, context.relationTypes);
128
- return { ...common, kind: 'relation', path: workspaceRelationPath, base: context.relationContent, content: JSON.stringify(file, null, 2) + '\n' };
129
- }
130
-
131
- /** Compare changed rows and assignment groups; preserve unrelated concurrent edges. */
132
- export function mergeStructureRelations(base: RelationFile, proposed: RelationFile, current: RelationFile,
133
- targets: readonly ReferenceTarget[], definitions: readonly RelationTypeDefinition[]): RelationFile | null {
134
- if (!same({ ...base, relations: [] }, { ...proposed, relations: [] })) throw new Error('关系文件扩展字段不能修改');
135
- const previous = base.relations.filter(row => !same(row, proposed.relations.find(next => next.id === row.id)));
136
- const next = proposed.relations.filter(row => !same(row, base.relations.find(old => old.id === row.id)));
137
- if (!previous.length && !next.length) throw new Error('关系没有变化');
138
- const changed = [...previous, ...next];
139
- const assignment = changed.every(row => row.type === 'assigned' && referenceKey(row.target) === referenceKey(changed[0].target));
140
- if (!assignment && new Set(changed.map(row => row.id)).size > 1) throw new Error('一次只能维护一条关系');
141
- if (assignment) {
142
- const matches = (row: WorkspaceRelation) => row.type === 'assigned' && referenceKey(row.target) === referenceKey(changed[0].target);
143
- const ordered = (rows: WorkspaceRelation[]) => [...rows].sort((a, b) => a.id.localeCompare(b.id));
144
- if (!same(ordered(base.relations.filter(matches)), ordered(current.relations.filter(matches)))) return null;
145
- }
146
- for (const row of previous) if (!same(row, current.relations.find(old => old.id === row.id))) return null;
147
- for (const row of next) {
148
- validateRelation(row, definitions);
149
- for (const identity of [row.source, row.target])
150
- if (!available(targets, identity)) throw new Error('关系端点不属于可用工作区目标');
151
- if (!base.relations.some(old => old.id === row.id) && current.relations.some(old => old.id === row.id)) return null;
152
- }
153
- const ids = new Set(previous.map(row => row.id));
154
- const rows = [...current.relations.filter(row => !ids.has(row.id)), ...next];
155
- if (new Set(rows.map(relationKey)).size !== rows.length) throw new Error('关系已经存在');
156
- return parseRelations(JSON.stringify({ ...current, relations: rows }));
157
- }
1
+ export * from '@tano/protocol/assistant-structures';
@@ -1,94 +1,8 @@
1
- import { isActionableTask, isPlanCompleted, referenceKey, referenceUrl, taskReview, validatePath, validEventDate } from '@tano/protocol';
2
- import type { ReferenceIdentity, ReferenceTarget, WorkspaceRelation } from '@tano/protocol';
3
- import type { ContentReference } from '../objects/content-references';
4
- import { localDayKey } from '../plans/calendar';
5
-
6
- export interface TaskQuery {
7
- documentId: string | null;
8
- directory: string | null;
9
- state: 'all' | 'unfinished' | 'completed' | 'overdue';
10
- personId: string | null;
11
- query: string | null;
12
- }
13
- export const isTaskTarget = (target: ReferenceTarget) => isActionableTask(target);
14
- export const taskCompleted = (target: ReferenceTarget) => isPlanCompleted(target);
15
- export function parseTaskQuery(value: unknown): TaskQuery {
16
- const args = value as TaskQuery;
17
- const keys = ['documentId', 'directory', 'state', 'personId', 'query'];
18
- if (!args || typeof args !== 'object' || Array.isArray(args) || Object.keys(args).some(key => !keys.includes(key)) ||
19
- keys.some(key => !(key in args)) || !['all', 'unfinished', 'completed', 'overdue'].includes(args.state) ||
20
- [args.documentId, args.personId].some(id => id !== null && (typeof id !== 'string' || !/^[0-9a-f]{6}$/.test(id))) ||
21
- (args.query !== null && (typeof args.query !== 'string' || args.query.length > 200)) ||
22
- (args.directory !== null && (typeof args.directory !== 'string' ||
23
- (args.directory !== '' && !!validatePath(args.directory)))) ||
24
- (args.documentId !== null && args.directory !== null)) throw new Error('任务查询范围或筛选无效');
25
- return args;
26
- }
27
-
28
- export function queryTasks(targets: readonly ReferenceTarget[], relations: readonly WorkspaceRelation[],
29
- edges: readonly ContentReference[], query: TaskQuery, today = localDayKey(new Date())) {
30
- if (!validEventDate(today)) throw new Error('任务查询日期无效');
31
- const documents = targets.filter(target => target.type === 'document' && !target.archived);
32
- if (query.documentId && !documents.some(target => target.id === query.documentId)) throw new Error('来源文档不可用');
33
- if (query.personId && !targets.some(target => target.type === 'person' && target.id === query.personId && !target.archived))
34
- throw new Error('负责人不可用');
35
- const scoped = documents.filter(target => query.documentId ? target.id === query.documentId :
36
- query.directory !== null ? !query.directory || target.path.startsWith(`${query.directory}/`) : true);
37
- const scopeKeys = new Set(scoped.map(referenceKey));
38
- const restricted = query.documentId !== null || query.directory !== null;
39
- const rows = targets.filter(target => isTaskTarget(target) && !target.archived).map(task => {
40
- const key = referenceKey(task);
41
- const evidence = new Map<string, { document: ReferenceIdentity; name: string; path: string; url: string; excerpt: string; kind: string }>();
42
- const add = (identity: ReferenceIdentity, excerpt: string, kind: string) => {
43
- const doc = scoped.find(target => referenceKey(target) === referenceKey(identity));
44
- if (doc) evidence.set(`${referenceKey(doc)}:${kind}`, { document: { type: 'document', id: doc.id },
45
- name: doc.name, path: doc.path, url: referenceUrl(doc), excerpt, kind });
46
- };
47
- for (const edge of edges) {
48
- if (edge.missing) continue;
49
- if (referenceKey(edge.target) === key) add(edge.source, edge.excerpt, '文档引用任务');
50
- if (referenceKey(edge.source) === key) add(edge.target, edge.excerpt, '任务引用文档');
51
- }
52
- for (const relation of relations) {
53
- if (referenceKey(relation.source) === key && scopeKeys.has(referenceKey(relation.target))) add(relation.target, '', `关系:${relation.type}`);
54
- if (referenceKey(relation.target) === key && scopeKeys.has(referenceKey(relation.source))) add(relation.source, '', `关系:${relation.type}`);
55
- }
56
- const assignees = relations.filter(row => row.type === 'assigned' && referenceKey(row.target) === key)
57
- .flatMap(row => {
58
- const person = targets.find(target => referenceKey(target) === referenceKey(row.source) && !target.archived);
59
- return person ? [{ id: person.id, name: person.name, url: referenceUrl(person) }] : [];
60
- });
61
- const properties = task.properties ?? {};
62
- const review = taskReview({ properties });
63
- const completed = taskCompleted(task);
64
- const due = validEventDate(properties.due) ? properties.due : null;
65
- const overdue = !completed && due !== null && due < today;
66
- const blockedReason = typeof properties.blockedReason === 'string' && properties.blockedReason.trim()
67
- ? properties.blockedReason.trim() : review?.state === 'changes-requested' ? review.comment : null;
68
- return { type: task.type, id: task.id, name: task.name, url: referenceUrl(task), description: task.description ?? '',
69
- completed, status: completed ? '已完成' : overdue ? '逾期' : '待处理', due,
70
- date: validEventDate(properties.date) ? properties.date : null,
71
- start: properties.start ?? null, end: properties.end ?? null, assignees,
72
- blockedReason: blockedReason ?? '未知', review, evidence: [...evidence.values()] };
73
- }).filter(task => (!restricted || task.evidence.length > 0) &&
74
- (!query.personId || task.assignees.some(person => person.id === query.personId)) &&
75
- (!query.query || `${task.name}\n${task.description}`.toLocaleLowerCase().includes(query.query.toLocaleLowerCase())));
76
- const totals = { completed: rows.filter(task => task.completed).length,
77
- pending: rows.filter(task => !task.completed && task.status !== '逾期').length,
78
- overdue: rows.filter(task => task.status === '逾期').length };
79
- const tasks = rows.filter(task => query.state === 'all' || (query.state === 'unfinished' && !task.completed) ||
80
- (query.state === 'completed' && task.completed) || (query.state === 'overdue' && task.status === '逾期'))
81
- .sort((a, b) => Number(a.completed) - Number(b.completed) || (a.due ?? '9999').localeCompare(b.due ?? '9999') || a.name.localeCompare(b.name));
82
- return { asOf: today, scope: query, totals, tasks };
83
- }
84
-
85
- const normalizedName = (name: string) => name.normalize('NFKC').toLocaleLowerCase().replace(/[\p{P}\p{S}\s]/gu, '');
86
- export function possibleDuplicateTasks(targets: readonly ReferenceTarget[], name: string, exceptId?: string) {
87
- const normalized = normalizedName(name);
88
- return targets.filter(target => isTaskTarget(target) && !target.archived && target.id !== exceptId).filter(target => {
89
- const candidate = normalizedName(target.name);
90
- return normalized === candidate || (Math.min(normalized.length, candidate.length) >= 4 &&
91
- Math.min(normalized.length, candidate.length) / Math.max(normalized.length, candidate.length) >= 0.6 &&
92
- (normalized.includes(candidate) || candidate.includes(normalized)));
93
- });
94
- }
1
+ export {
2
+ isTaskTarget,
3
+ parseTaskQuery,
4
+ possibleDuplicateTasks,
5
+ queryTasks,
6
+ taskCompleted,
7
+ type TaskQuery,
8
+ } from '@tano/protocol/assistant-tasks';
@@ -1,7 +1 @@
1
- /** Shared by edit/proposal tool descriptions and system prompts. Keep aligned with proposalFromTool. */
2
- export const editDocumentRules = [
3
- 'sourceId 必须指向已读取的当前快照。非空 oldText 必须是完整来源中唯一的原始片段。',
4
- '空 oldText 仅允许两种情况,且 newText 必须非空:完整来源为空且没有 selection 时初始化;非空来源带有明确的零长度选区(selection.from === selection.to)时在该位置插入。其他情况不得使用空 oldText。',
5
- '修改必须在 selection.from/to 的源码边界内;选区没有可用源码位置时不得猜测位置或扩大范围。保留未涉及内容、YAML、引用、代码和附件。',
6
- '.table.json 修改后必须是合法的表结构 JSON,保留表身份、已有行/字段/视图 ID 和未涉及字段;不要包裹 Markdown 代码围栏。',
7
- ].join('\n');
1
+ export { editDocumentRules } from '@tano/protocol/assistant-execution';
@@ -0,0 +1,177 @@
1
+ import { computed, type Ref } from 'vue';
2
+ import { storeToRefs } from 'pinia';
3
+ import {
4
+ isDataTableFilePath,
5
+ isMarkdown,
6
+ isWorkspaceInternalPath,
7
+ type WorkspaceAdapter,
8
+ } from '@tano/protocol';
9
+ import { ASSISTANT_TAB_ID } from '../assistant/navigation';
10
+ import type { useAssistantStore } from '../assistant/store';
11
+ import { isTableTab } from '../data-tables/data-tables';
12
+ import { GRAPH_TAB_ID } from '../documents/document-graph';
13
+ import type { HelpAvailability, HelpContext } from '../help/help-content';
14
+ import { CALENDAR_TAB_ID } from '../plans/calendar';
15
+ import { PLUGINS_TAB_ID } from '../plugins/workspace-plugins';
16
+ import type { WorkbenchExtensions } from '../runtime';
17
+ import { SETTINGS_TAB_ID } from '../settings/settings-tab';
18
+ import type { usePlanStore } from '../stores/plans';
19
+ import type { useWorkspaceStore } from '../stores/workspace';
20
+
21
+ export interface WorkbenchHelpDeps {
22
+ store: ReturnType<typeof useWorkspaceStore>;
23
+ assistant: ReturnType<typeof useAssistantStore>;
24
+ plans: ReturnType<typeof usePlanStore>;
25
+ workspaceAdapter: WorkspaceAdapter;
26
+ editing: WorkbenchExtensions['editing'];
27
+ compactPanes: Ref<boolean>;
28
+ sidebarView: Ref<string>;
29
+ activeExtensionView: Ref<unknown>;
30
+ editorReadonly: Ref<boolean>;
31
+ source: Ref<boolean>;
32
+ workspaceMenu: Ref<boolean>;
33
+ menu: Ref<boolean>;
34
+ modal: Ref<string>;
35
+ settingsPanel: Ref<boolean>;
36
+ importPanel: Ref<boolean>;
37
+ templateLibraryOpen: Ref<boolean>;
38
+ agentPanel: Ref<boolean>;
39
+ objectDetail: Ref<unknown>;
40
+ planArchiveOpen: Ref<boolean>;
41
+ selectedDiff: Ref<unknown>;
42
+ selectionTodo: Ref<unknown>;
43
+ recyclePanel: Ref<boolean>;
44
+ referenceGraphOpened: Ref<boolean>;
45
+ fileContextMenu: Ref<unknown>;
46
+ directoryContextMenu: Ref<unknown>;
47
+ pageContextMenu: Ref<unknown>;
48
+ outlineContextMenu: Ref<unknown>;
49
+ resizingSidebar: Ref<boolean>;
50
+ draggedEntry: Ref<unknown>;
51
+ updateLock: Ref<boolean>;
52
+ }
53
+
54
+ export function useWorkbenchHelp(deps: WorkbenchHelpDeps) {
55
+ const {
56
+ store,
57
+ assistant,
58
+ plans,
59
+ workspaceAdapter,
60
+ editing,
61
+ compactPanes,
62
+ sidebarView,
63
+ activeExtensionView,
64
+ editorReadonly,
65
+ source,
66
+ workspaceMenu,
67
+ menu,
68
+ modal,
69
+ settingsPanel,
70
+ importPanel,
71
+ templateLibraryOpen,
72
+ agentPanel,
73
+ objectDetail,
74
+ planArchiveOpen,
75
+ selectedDiff,
76
+ selectionTodo,
77
+ recyclePanel,
78
+ referenceGraphOpened,
79
+ fileContextMenu,
80
+ directoryContextMenu,
81
+ pageContextMenu,
82
+ outlineContextMenu,
83
+ resizingSidebar,
84
+ draggedEntry,
85
+ updateLock,
86
+ } = deps;
87
+ const { workspace, active, activeId, fatal, busy } = storeToRefs(store);
88
+
89
+ const noteCount = computed(
90
+ () =>
91
+ workspace.value?.files.filter(
92
+ (f) =>
93
+ f.kind === 'file' &&
94
+ !isWorkspaceInternalPath(f.path) &&
95
+ (isMarkdown(f.path) || isDataTableFilePath(f.path)),
96
+ ).length ?? 0,
97
+ );
98
+
99
+ const helpContext = computed<HelpContext>(() => {
100
+ if (activeId.value === ASSISTANT_TAB_ID || sidebarView.value === 'assistant')
101
+ return 'assistant';
102
+ if (isTableTab(activeId.value)) return 'tables';
103
+ if (activeId.value === GRAPH_TAB_ID) return 'graph';
104
+ if (activeId.value === PLUGINS_TAB_ID) return 'plugins';
105
+ if (activeId.value === CALENDAR_TAB_ID || sidebarView.value === 'plan') return 'plan';
106
+ if (!active.value) return 'welcome';
107
+ if (editorReadonly.value) return 'reading';
108
+ if (source.value) return 'source';
109
+ return active.value.content.trim() ? 'document' : 'empty-document';
110
+ });
111
+
112
+ const helpAvailability = computed<HelpAvailability>(() => ({
113
+ 'document-write': !!active.value && !editorReadonly.value,
114
+ 'workspace-write': !!workspace.value && !workspace.value.readOnly,
115
+ plans: plans.personalWritable || plans.workspaceWritable,
116
+ comments: !!active.value && !editorReadonly.value,
117
+ templates: !!workspace.value && !workspace.value.readOnly,
118
+ import: !!workspace.value && !workspace.value.readOnly,
119
+ duplicate: !!workspace.value && !workspace.value.readOnly && !!workspaceAdapter.duplicate,
120
+ 'folder-home': !!workspace.value && !!store.workspaceSettings.folderHomeFileName,
121
+ 'folder-conversion':
122
+ !!workspace.value &&
123
+ !workspace.value.readOnly &&
124
+ store.canConvertFolderDocuments &&
125
+ !!store.workspaceSettings.folderHomeFileName,
126
+ panes: !!workspace.value && !compactPanes.value,
127
+ assistant: !!workspace.value && assistant.available,
128
+ 'assistant-configure':
129
+ !!workspace.value && assistant.available && assistant.canConfigure && !assistant.demo,
130
+ suggestions:
131
+ !!active.value && !editorReadonly.value && !editing.isManaging(active.value.id),
132
+ math: !!active.value && !editorReadonly.value && store.capabilities.features.math,
133
+ mermaid: !!active.value && !editorReadonly.value && store.capabilities.features.mermaid,
134
+ }));
135
+
136
+ const helpBlocked = computed(
137
+ () =>
138
+ !!(
139
+ activeExtensionView.value ||
140
+ activeId.value === SETTINGS_TAB_ID ||
141
+ activeId.value.startsWith('attachment:') ||
142
+ (assistant.opened && assistant.displayMode === 'fullscreen') ||
143
+ busy.value ||
144
+ fatal.value ||
145
+ store.pending ||
146
+ active.value?.conflict ||
147
+ active.value?.error ||
148
+ workspaceMenu.value ||
149
+ menu.value ||
150
+ modal.value ||
151
+ settingsPanel.value ||
152
+ importPanel.value ||
153
+ templateLibraryOpen.value ||
154
+ agentPanel.value ||
155
+ objectDetail.value ||
156
+ planArchiveOpen.value ||
157
+ selectedDiff.value ||
158
+ selectionTodo.value ||
159
+ recyclePanel.value ||
160
+ referenceGraphOpened.value ||
161
+ fileContextMenu.value ||
162
+ directoryContextMenu.value ||
163
+ pageContextMenu.value ||
164
+ outlineContextMenu.value ||
165
+ resizingSidebar.value ||
166
+ draggedEntry.value ||
167
+ updateLock.value
168
+ ),
169
+ );
170
+
171
+ return {
172
+ noteCount,
173
+ helpContext,
174
+ helpAvailability,
175
+ helpBlocked,
176
+ };
177
+ }