@tano.page/protocol 0.14.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.
- package/manifest.schema.json +448 -0
- package/package.json +21 -4
- package/src/appearance.ts +19 -4
- package/src/assistant.ts +35 -4
- package/src/domain/agent-identities.ts +110 -0
- package/src/domain/agent-inbox.ts +148 -0
- package/src/domain/assistant-completion.ts +61 -0
- package/src/domain/assistant-engine.ts +614 -0
- package/src/domain/assistant-execution.ts +43 -0
- package/src/domain/assistant-files.ts +19 -0
- package/src/domain/assistant-history.ts +90 -0
- package/src/domain/assistant-language.ts +112 -0
- package/src/domain/assistant-prompts.ts +70 -0
- package/src/domain/assistant-structures.ts +179 -0
- package/src/domain/assistant-task-prompts.json +39 -0
- package/src/domain/assistant-tasks.ts +114 -0
- package/src/domain/locales/de-DE.json +129 -0
- package/src/domain/locales/en-US.json +129 -0
- package/src/domain/locales/es-ES.json +129 -0
- package/src/domain/locales/ja-JP.json +129 -0
- package/src/domain/locales/zh-CN.json +129 -0
- package/src/domain/locales/zh-TW.json +129 -0
- package/src/domain/plugin-data.ts +175 -0
- package/src/domain/plugin-sdk.ts +300 -0
- package/src/domain/untrusted-data.ts +17 -0
- package/src/domain/workspace-comments.ts +148 -0
- package/src/extensions.ts +1100 -19
- package/src/frontmatter.ts +60 -1
- package/src/index.ts +3 -0
- package/src/object-types.ts +30 -20
- package/src/objects.ts +3 -4
- package/src/plan-item.ts +78 -0
- package/src/plugin-archive.ts +395 -0
- package/src/plugin-compat.ts +156 -0
- package/src/plugins.ts +12 -0
- package/src/relations.ts +1 -5
- package/src/task-repeat.ts +55 -8
- package/src/task-review.ts +11 -2
- package/src/view-engine.ts +1 -1
package/src/frontmatter.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isMap, isScalar, parseDocument } from 'yaml';
|
|
1
|
+
import { Document, isMap, isScalar, parseDocument } from 'yaml';
|
|
2
2
|
|
|
3
3
|
export interface FrontmatterProperty {
|
|
4
4
|
name: string;
|
|
@@ -76,3 +76,62 @@ export function frontmatterValue(prefix: string, name: string): { kind: Frontmat
|
|
|
76
76
|
return { kind: 'date', value: value.replaceAll('/', '-') };
|
|
77
77
|
return { kind: 'text', value: String(value) };
|
|
78
78
|
}
|
|
79
|
+
|
|
80
|
+
export function splitFrontmatterSource(markdown: string): { prefix: string; body: string } {
|
|
81
|
+
const opening = /^\uFEFF?---(\r?\n)/.exec(markdown);
|
|
82
|
+
if (!opening) return { prefix: '', body: markdown };
|
|
83
|
+
const remainder = markdown.slice(opening[0].length);
|
|
84
|
+
const match = /(?:^|\r?\n)(---|\.\.\.)(?:\r?\n|$)/.exec(remainder);
|
|
85
|
+
if (!match) return { prefix: '', body: markdown };
|
|
86
|
+
const end = opening[0].length + match.index + match[0].length;
|
|
87
|
+
return { prefix: markdown.slice(0, end), body: markdown.slice(end) };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Structured JSON-safe read of YAML frontmatter without mutating Markdown source. */
|
|
91
|
+
export function readFrontmatterData(markdown: string): { hasFrontmatter: boolean; data: Record<string, unknown> } {
|
|
92
|
+
const { prefix } = splitFrontmatterSource(markdown);
|
|
93
|
+
if (!prefix) return { hasFrontmatter: false, data: {} };
|
|
94
|
+
const parsed = frontmatterDocument(prefix);
|
|
95
|
+
if (!parsed) throw new Error('YAML 属性无法解析,请在源码中修改');
|
|
96
|
+
const raw: unknown = parsed.document.toJS({ maxAliasCount: 100 });
|
|
97
|
+
if (raw === null || raw === undefined) return { hasFrontmatter: true, data: {} };
|
|
98
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) throw new Error('YAML 属性必须为键值对映射');
|
|
99
|
+
const normalized = JSON.parse(JSON.stringify(raw)) as Record<string, unknown>;
|
|
100
|
+
return { hasFrontmatter: true, data: normalized };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Structured AST-preserving patch of YAML frontmatter keys while keeping Markdown body intact. */
|
|
104
|
+
export function patchFrontmatterMarkdown(
|
|
105
|
+
markdown: string,
|
|
106
|
+
patch: { set?: Record<string, unknown>; remove?: string[] },
|
|
107
|
+
): string {
|
|
108
|
+
const setEntries = Object.entries(patch.set ?? {});
|
|
109
|
+
const removeKeys = patch.remove ?? [];
|
|
110
|
+
if (!setEntries.length && !removeKeys.length) return markdown;
|
|
111
|
+
const { prefix, body } = splitFrontmatterSource(markdown);
|
|
112
|
+
const lineEnding = markdown.includes('\r\n') ? '\r\n' : '\n';
|
|
113
|
+
const bom = markdown.startsWith('\uFEFF') ? '\uFEFF' : '';
|
|
114
|
+
if (!prefix) {
|
|
115
|
+
if (!setEntries.length) return markdown;
|
|
116
|
+
const doc = new Document(Object.fromEntries(setEntries));
|
|
117
|
+
const yamlText = doc.toString({ lineWidth: 0 }).replace(/\r?\n/g, lineEnding);
|
|
118
|
+
const bodyWithoutBom = bom ? body.slice(1) : body;
|
|
119
|
+
return `${bom}---${lineEnding}${yamlText}---${lineEnding}${bodyWithoutBom}`;
|
|
120
|
+
}
|
|
121
|
+
const parsed = frontmatterDocument(prefix);
|
|
122
|
+
if (!parsed) throw new Error('YAML 属性无法解析,请在源码中修改');
|
|
123
|
+
const doc: Document = parsed.document;
|
|
124
|
+
if (doc.contents === null) {
|
|
125
|
+
if (!setEntries.length) return `${bom}${body}`;
|
|
126
|
+
doc.contents = doc.createNode({});
|
|
127
|
+
}
|
|
128
|
+
if (!isMap(doc.contents)) throw new Error('YAML 属性必须为键值对映射');
|
|
129
|
+
for (const key of removeKeys) doc.delete(key);
|
|
130
|
+
for (const [key, value] of setEntries) doc.set(key, value);
|
|
131
|
+
if (isMap(doc.contents) && doc.contents.items.length === 0) {
|
|
132
|
+
return `${bom}${body}`;
|
|
133
|
+
}
|
|
134
|
+
const serialized = doc.toString({ lineWidth: 0 }).replace(/\r?\n/g, lineEnding);
|
|
135
|
+
const nextSource = serialized.endsWith(lineEnding) ? serialized : `${serialized}${lineEnding}`;
|
|
136
|
+
return prefix.slice(0, parsed.start) + nextSource + prefix.slice(parsed.end) + body;
|
|
137
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './object-types';
|
|
|
7
7
|
export * from './short-id';
|
|
8
8
|
export * from './relations';
|
|
9
9
|
export * from './plugins';
|
|
10
|
+
export * from './plugin-compat';
|
|
10
11
|
export * from './extensions';
|
|
11
12
|
export * from './workspace-paths';
|
|
12
13
|
export * from './comments';
|
|
@@ -23,6 +24,7 @@ export * from './plugin-connections';
|
|
|
23
24
|
export * from './plugin-automations';
|
|
24
25
|
export * from './task-review';
|
|
25
26
|
export * from './task-repeat';
|
|
27
|
+
export * from './plan-item';
|
|
26
28
|
export * from './file-database';
|
|
27
29
|
export * from './view-engine';
|
|
28
30
|
export * from './agent-gateway';
|
|
@@ -31,3 +33,4 @@ export * from './structured-merge';
|
|
|
31
33
|
export * from './entry-drag';
|
|
32
34
|
export * from './appearance';
|
|
33
35
|
export * from './features';
|
|
36
|
+
export * from './plugin-archive';
|
package/src/object-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Declarative object types shared by the editor, storage validation and future plugin hosts. */
|
|
2
2
|
import { parseTaskReview } from './task-review';
|
|
3
3
|
import { validateTaskRepeat } from './task-repeat';
|
|
4
|
+
import { isActionableTask, isPlanCompleted } from './plan-item';
|
|
4
5
|
export interface ObjectField {
|
|
5
6
|
key: string;
|
|
6
7
|
label: string;
|
|
@@ -15,32 +16,18 @@ export interface ObjectTypeDefinition {
|
|
|
15
16
|
storage: 'record' | 'resource';
|
|
16
17
|
/** Retained for existing files and references; not offered for new objects. */
|
|
17
18
|
legacy?: boolean;
|
|
18
|
-
/** Compatibility metadata only; excluded from available types and all mutations. */
|
|
19
|
-
retired?: boolean;
|
|
20
19
|
plugin?: string;
|
|
21
20
|
fields: readonly ObjectField[];
|
|
22
21
|
}
|
|
23
22
|
export const coreObjectTypes: readonly ObjectTypeDefinition[] = [
|
|
24
23
|
{
|
|
25
|
-
type: 'task', label: '任务', level: 2, category: 'core', storage: 'record', fields: [
|
|
24
|
+
type: 'task', label: '任务', level: 2, category: 'core', storage: 'record', legacy: true, fields: [
|
|
26
25
|
{ key: 'status', label: '状态', type: 'text' },
|
|
27
26
|
{ key: 'due', label: '截止日期', type: 'text' },
|
|
28
27
|
{ key: 'priority', label: '优先级', type: 'number' },
|
|
29
28
|
{ key: 'completed', label: '已完成', type: 'boolean' },
|
|
30
29
|
],
|
|
31
30
|
},
|
|
32
|
-
{ type: 'project', label: '项目', level: 2, category: 'core', storage: 'record', fields: [
|
|
33
|
-
{ key: 'status', label: '状态', type: 'text' },
|
|
34
|
-
{ key: 'goal', label: '项目目标', type: 'text' },
|
|
35
|
-
{ key: 'due', label: '截止日期', type: 'text' },
|
|
36
|
-
] },
|
|
37
|
-
{ type: 'experiment', label: '实验', level: 2, category: 'core', storage: 'record', fields: [
|
|
38
|
-
{ key: 'status', label: '状态', type: 'text' },
|
|
39
|
-
{ key: 'hypothesis', label: '假设', type: 'text' },
|
|
40
|
-
{ key: 'result', label: '实验结果', type: 'text' },
|
|
41
|
-
{ key: 'metric', label: '指标', type: 'number' },
|
|
42
|
-
{ key: 'runAt', label: '运行时间', type: 'datetime' },
|
|
43
|
-
] },
|
|
44
31
|
{ type: 'person', label: '人物', level: 2, category: 'core', storage: 'record', fields: [] },
|
|
45
32
|
{ type: 'document', label: '文档', level: 2, category: 'core', storage: 'resource', fields: [] },
|
|
46
33
|
{
|
|
@@ -52,10 +39,16 @@ export const coreObjectTypes: readonly ObjectTypeDefinition[] = [
|
|
|
52
39
|
fields: [
|
|
53
40
|
{ key: 'checkable', label: '需要完成', type: 'boolean' },
|
|
54
41
|
{ key: 'completed', label: '已完成', type: 'boolean' },
|
|
42
|
+
{ key: 'status', label: '状态', type: 'text' },
|
|
43
|
+
{ key: 'priority', label: '优先级', type: 'number' },
|
|
55
44
|
{ key: 'due', label: '截止日期', type: 'text' },
|
|
56
45
|
{ key: 'date', label: '计划日期(不指定时间)', type: 'text' },
|
|
46
|
+
{ key: 'endDate', label: '结束日期', type: 'text' },
|
|
57
47
|
{ key: 'start', label: '开始时间', type: 'datetime' },
|
|
58
48
|
{ key: 'end', label: '结束时间', type: 'datetime' },
|
|
49
|
+
{ key: 'allDay', label: '全天', type: 'boolean' },
|
|
50
|
+
{ key: 'timezone', label: '时区', type: 'text' },
|
|
51
|
+
{ key: 'location', label: '地点', type: 'text' },
|
|
59
52
|
],
|
|
60
53
|
},
|
|
61
54
|
{ type: 'asset', label: '资产', level: 2, category: 'core', storage: 'resource', fields: [] },
|
|
@@ -180,13 +173,11 @@ export function validateObjectProperties(
|
|
|
180
173
|
validateTaskRepeat(type, properties);
|
|
181
174
|
if (properties.deliveryReview !== undefined) {
|
|
182
175
|
const review = parseTaskReview(properties.deliveryReview);
|
|
183
|
-
if (!(
|
|
184
|
-
if ((
|
|
176
|
+
if (!isActionableTask({ type, properties })) throw new Error('只有任务可以提交交付审阅');
|
|
177
|
+
if (isPlanCompleted({ type, properties }) && review.state !== 'approved') throw new Error('此任务需由指定审阅人确认通过后完成');
|
|
185
178
|
}
|
|
186
179
|
const definition = registry.get(type);
|
|
187
180
|
if (!definition) throw new Error(`类型 ${type} 未启用,请先注册对应领域插件;原文件已保留`);
|
|
188
|
-
if (definition.retired)
|
|
189
|
-
throw new Error('项目对象已停用;请使用工作区文件夹和 Markdown 文档组织项目,旧记录只读保留');
|
|
190
181
|
if (definition.storage !== 'record')
|
|
191
182
|
throw new Error('文档和资产来自工作区文件,不创建重复内容对象');
|
|
192
183
|
for (const field of definition.fields) {
|
|
@@ -208,17 +199,36 @@ export function validateObjectProperties(
|
|
|
208
199
|
`${field.label}格式无效${field.type === 'datetime' ? ',请使用带时区的日期时间' : ''}`,
|
|
209
200
|
);
|
|
210
201
|
}
|
|
211
|
-
if (
|
|
202
|
+
if (type === 'task' && properties.due !== undefined && properties.due !== '' && !validEventDate(properties.due)) throw new Error('截止日期格式无效,请使用 YYYY-MM-DD');
|
|
212
203
|
if (type === 'event') {
|
|
213
204
|
const hasStart = properties.start !== undefined && properties.start !== '';
|
|
214
205
|
const hasEnd = properties.end !== undefined && properties.end !== '';
|
|
215
206
|
const hasDate = properties.date !== undefined && properties.date !== '';
|
|
207
|
+
const hasEndDate = properties.endDate !== undefined && properties.endDate !== '';
|
|
216
208
|
if (hasStart !== hasEnd) throw new Error('开始时间和结束时间需要一起填写');
|
|
217
209
|
if (hasStart && Date.parse(String(properties.end)) < Date.parse(String(properties.start)))
|
|
218
210
|
throw new Error('结束时间不能早于开始时间');
|
|
219
211
|
if (hasDate && !validEventDate(properties.date)) throw new Error('计划日期格式无效');
|
|
212
|
+
if (hasEndDate) {
|
|
213
|
+
if (!hasDate) throw new Error('结束日期需要与计划日期一起填写');
|
|
214
|
+
if (!validEventDate(properties.endDate)) throw new Error('结束日期格式无效');
|
|
215
|
+
if (String(properties.endDate) < String(properties.date)) throw new Error('结束日期不能早于计划日期');
|
|
216
|
+
}
|
|
220
217
|
if (properties.due !== undefined && properties.due !== '' && !validEventDate(properties.due)) throw new Error('截止日期格式无效,请使用 YYYY-MM-DD');
|
|
221
218
|
if (hasDate && hasStart) throw new Error('计划日期与具体时间段只能选择一种安排方式');
|
|
219
|
+
if (properties.timezone !== undefined && properties.timezone !== '' && (typeof properties.timezone !== 'string' || properties.timezone.length > 100))
|
|
220
|
+
throw new Error('时区格式无效');
|
|
221
|
+
if (properties.location !== undefined && properties.location !== '' && (typeof properties.location !== 'string' || properties.location.length > 500))
|
|
222
|
+
throw new Error('地点格式无效');
|
|
223
|
+
if (properties.reminders !== undefined) {
|
|
224
|
+
if (
|
|
225
|
+
!Array.isArray(properties.reminders) ||
|
|
226
|
+
properties.reminders.length > 5 ||
|
|
227
|
+
!properties.reminders.every((item) => typeof item === 'number' && Number.isInteger(item) && item >= 0 && item <= 43200)
|
|
228
|
+
) {
|
|
229
|
+
throw new Error('提醒设置无效');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
222
232
|
if (properties.completed === true && properties.checkable !== true)
|
|
223
233
|
throw new Error('只有需要完成的事件可以标记为已完成');
|
|
224
234
|
}
|
package/src/objects.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FileEntry } from './types';
|
|
2
2
|
import { isMarkdown } from './paths';
|
|
3
|
-
import { isWorkspaceInternalPath } from './workspace-paths';
|
|
3
|
+
import { isWorkspaceInternalPath, objectDirectory } from './workspace-paths';
|
|
4
4
|
import { isShortId } from './short-id';
|
|
5
5
|
import { coreObjectTypes, objectTypeRegistry, validObjectType } from './object-types';
|
|
6
6
|
import { parseTaskReview } from './task-review';
|
|
@@ -35,8 +35,8 @@ export interface ReferenceTarget extends ReferenceIdentity {
|
|
|
35
35
|
properties?: Record<string, unknown>;
|
|
36
36
|
}
|
|
37
37
|
export const objectSuffix = '.tano.json';
|
|
38
|
-
export const isObjectPath = (path: string) =>
|
|
39
|
-
|
|
38
|
+
export const isObjectPath = (path: string) =>
|
|
39
|
+
path.startsWith(`${objectDirectory}/`) && path.endsWith(objectSuffix);
|
|
40
40
|
export const referenceTypeLabel = (type: string) =>
|
|
41
41
|
objectTypeRegistry.get(type)?.label ?? `未启用类型(${type})`;
|
|
42
42
|
export function parseObject(content: string): WorkspaceObject {
|
|
@@ -163,7 +163,6 @@ export function referenceCandidates(
|
|
|
163
163
|
.filter(
|
|
164
164
|
(target) =>
|
|
165
165
|
!!objectTypeRegistry.get(target.type) &&
|
|
166
|
-
!objectTypeRegistry.get(target.type)?.retired &&
|
|
167
166
|
!target.archived &&
|
|
168
167
|
(!qualifier || target.type === qualifier[1]!.toLowerCase()) &&
|
|
169
168
|
`${target.name}\n${target.path}`.normalize('NFKC').toLocaleLowerCase().includes(name),
|
package/src/plan-item.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { WorkspaceObject } from './objects';
|
|
2
|
+
import { taskReview } from './task-review';
|
|
3
|
+
|
|
4
|
+
export interface PlanObjectLike {
|
|
5
|
+
type: string;
|
|
6
|
+
archived?: boolean;
|
|
7
|
+
properties?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const DONE_STATUS_VALUES = new Set(['done', 'completed', '已完成']);
|
|
11
|
+
const CHINESE_STATUS_VALUES = new Set(['待处理', '进行中', '已阻塞', '已完成']);
|
|
12
|
+
|
|
13
|
+
export function isPlanObjectType(type: string): boolean {
|
|
14
|
+
return type === 'event' || type === 'task';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isPlanObject(item: PlanObjectLike): boolean {
|
|
18
|
+
return isPlanObjectType(item.type);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isActionableTask(item: PlanObjectLike): boolean {
|
|
22
|
+
return item.type === 'task' || (item.type === 'event' && item.properties?.checkable === true);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isDoneStatus(status: unknown): boolean {
|
|
26
|
+
return typeof status === 'string' && DONE_STATUS_VALUES.has(status.trim().toLowerCase());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isPlanCompleted(item: PlanObjectLike): boolean {
|
|
30
|
+
if (!isActionableTask(item)) return false;
|
|
31
|
+
return item.properties?.completed === true || isDoneStatus(item.properties?.status);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isPlanCompletionLocked(item: Pick<WorkspaceObject, 'properties'>): boolean {
|
|
35
|
+
const review = taskReview(item);
|
|
36
|
+
return !!review && review.state !== 'approved';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function nextSyncedStatus(
|
|
40
|
+
type: string,
|
|
41
|
+
previousStatus: unknown,
|
|
42
|
+
completed: boolean,
|
|
43
|
+
): string | undefined {
|
|
44
|
+
const current = typeof previousStatus === 'string' ? previousStatus.trim() : '';
|
|
45
|
+
if (!current) {
|
|
46
|
+
return type === 'task' ? (completed ? 'done' : 'todo') : undefined;
|
|
47
|
+
}
|
|
48
|
+
const chinese = CHINESE_STATUS_VALUES.has(current);
|
|
49
|
+
if (completed) return chinese ? '已完成' : 'done';
|
|
50
|
+
if (isDoneStatus(current)) return chinese ? '待处理' : 'todo';
|
|
51
|
+
return current;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function withPlanCompleted<T extends WorkspaceObject>(object: T, completed: boolean): T {
|
|
55
|
+
if (!isActionableTask(object)) throw new Error('只有任务可以标记完成状态');
|
|
56
|
+
if (completed && isPlanCompletionLocked(object)) {
|
|
57
|
+
throw new Error('此任务需由指定审阅人确认通过后完成');
|
|
58
|
+
}
|
|
59
|
+
const properties: Record<string, unknown> = { ...object.properties, completed };
|
|
60
|
+
const status = nextSyncedStatus(object.type, object.properties.status, completed);
|
|
61
|
+
if (status !== undefined) properties.status = status;
|
|
62
|
+
return { ...object, properties };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function withPlanStatus<T extends WorkspaceObject>(object: T, status: string): T {
|
|
66
|
+
const trimmed = status.trim();
|
|
67
|
+
const properties: Record<string, unknown> = { ...object.properties };
|
|
68
|
+
if (trimmed) properties.status = trimmed;
|
|
69
|
+
else delete properties.status;
|
|
70
|
+
if (isActionableTask(object) && trimmed) {
|
|
71
|
+
const completed = isDoneStatus(trimmed);
|
|
72
|
+
if (completed && isPlanCompletionLocked(object)) {
|
|
73
|
+
throw new Error('此任务需由指定审阅人确认通过后完成');
|
|
74
|
+
}
|
|
75
|
+
properties.completed = completed;
|
|
76
|
+
}
|
|
77
|
+
return { ...object, properties };
|
|
78
|
+
}
|