@tano.page/protocol 0.13.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.
- package/manifest.schema.json +419 -0
- package/package.json +12 -4
- package/src/appearance.ts +19 -4
- package/src/assistant.ts +35 -4
- package/src/domain/agent-inbox.ts +148 -0
- package/src/domain/assistant-files.ts +19 -0
- package/src/domain/assistant-history.ts +90 -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/features.ts +28 -0
- package/src/file-core.ts +1 -1
- package/src/frontmatter.ts +60 -1
- package/src/index.ts +5 -168
- package/src/object-types.ts +30 -20
- package/src/objects.ts +1 -2
- 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/types.ts +166 -0
- package/src/view-engine.ts +3 -2
- package/src/workspace-contract.ts +1 -1
package/src/features.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
export type FeatureChannel = 'dev' | 'stable';
|
|
3
|
+
export type FeatureDefinition = { status: FeatureChannel; note: string };
|
|
4
|
+
|
|
5
|
+
export function defineFeatures<const T extends Record<string, FeatureDefinition>>(
|
|
6
|
+
definitions: T,
|
|
7
|
+
): T {
|
|
8
|
+
return definitions;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function resolveFeatureChannel(env: {
|
|
12
|
+
DEV?: boolean;
|
|
13
|
+
VITE_TANO_CHANNEL?: string;
|
|
14
|
+
}): FeatureChannel {
|
|
15
|
+
return env.DEV === true || env.VITE_TANO_CHANNEL === 'dev' ? 'dev' : 'stable';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createFeatureGate<T extends Record<string, FeatureDefinition>>(
|
|
19
|
+
definitions: T,
|
|
20
|
+
channel: FeatureChannel,
|
|
21
|
+
) {
|
|
22
|
+
return {
|
|
23
|
+
isEnabled(id: keyof T): boolean {
|
|
24
|
+
if (!Object.hasOwn(definitions, id)) throw new Error(`Unknown feature: ${String(id)}`);
|
|
25
|
+
return definitions[id].status === 'stable' || channel === 'dev';
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/file-core.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FileEntry, Workspace } from './
|
|
1
|
+
import type { FileEntry, Workspace } from './types';
|
|
2
2
|
import { isWorkspaceInternalPath } from './workspace-paths';
|
|
3
3
|
|
|
4
4
|
export type FilePreviewKind = 'markdown' | 'table' | 'image' | 'pdf' | 'office' | 'csv' | 'json' | 'code' | 'text' | 'audio' | 'video' | 'binary';
|
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './types';
|
|
1
2
|
export * from './references';
|
|
2
3
|
export * from './agent';
|
|
3
4
|
export * from './assistant';
|
|
@@ -6,6 +7,7 @@ export * from './object-types';
|
|
|
6
7
|
export * from './short-id';
|
|
7
8
|
export * from './relations';
|
|
8
9
|
export * from './plugins';
|
|
10
|
+
export * from './plugin-compat';
|
|
9
11
|
export * from './extensions';
|
|
10
12
|
export * from './workspace-paths';
|
|
11
13
|
export * from './comments';
|
|
@@ -16,184 +18,19 @@ export * from './data-tables';
|
|
|
16
18
|
export * from './workspace-contract';
|
|
17
19
|
export * from './file-core';
|
|
18
20
|
export * from './file-metadata';
|
|
19
|
-
|
|
20
|
-
export interface FileEntry {
|
|
21
|
-
id: string;
|
|
22
|
-
path: string;
|
|
23
|
-
name: string;
|
|
24
|
-
kind: 'file' | 'directory';
|
|
25
|
-
size: number;
|
|
26
|
-
modified: number;
|
|
27
|
-
/** Content hash supplied by the authority when available, never inferred from mtime. */
|
|
28
|
-
contentHash?: string;
|
|
29
|
-
readOnly?: boolean;
|
|
30
|
-
/** Local draft; the authority has not yet confirmed creation. */
|
|
31
|
-
pendingCreation?: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface Workspace {
|
|
35
|
-
id: string;
|
|
36
|
-
name: string;
|
|
37
|
-
path: string;
|
|
38
|
-
files: FileEntry[];
|
|
39
|
-
readOnly?: boolean;
|
|
40
|
-
/** Transient creation result; omitted on subsequent opens and refreshes. */
|
|
41
|
-
newlyCreated?: boolean;
|
|
42
|
-
/** Local metadata was deleted; this open initialized a new workspace identity. */
|
|
43
|
-
reinitialized?: boolean;
|
|
44
|
-
/** True only when the current user may delete this workspace. */
|
|
45
|
-
canDelete?: boolean;
|
|
46
|
-
/** Supplied by the authority owning workspace membership, never by portable files. */
|
|
47
|
-
canManagePlugins?: boolean;
|
|
48
|
-
/** Supplied by the authority; content editing alone does not grant settings access. */
|
|
49
|
-
canManageSettings?: boolean;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class WorkspaceAccessRevokedError extends Error {
|
|
53
|
-
constructor() {
|
|
54
|
-
super('你已失去此工作区的访问权限');
|
|
55
|
-
this.name = 'WorkspaceAccessRevokedError';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface FileSnapshot {
|
|
60
|
-
content: string;
|
|
61
|
-
hash: string;
|
|
62
|
-
modified: number;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type WriteResult =
|
|
66
|
-
| { status: 'saved'; snapshot: FileSnapshot }
|
|
67
|
-
| { status: 'conflict'; snapshot: FileSnapshot }
|
|
68
|
-
| { status: 'missing' };
|
|
69
|
-
|
|
70
|
-
/** Compare identity and content at the filesystem boundary before moving/deleting a document. */
|
|
71
|
-
export interface FileChangeRequest {
|
|
72
|
-
workspaceId: string;
|
|
73
|
-
fileId: string;
|
|
74
|
-
path: string;
|
|
75
|
-
expectedHash: string;
|
|
76
|
-
/** Omitted for deletion. Saved returns the source snapshot, including for deletion. */
|
|
77
|
-
destination?: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface WorkspaceAdapter {
|
|
81
|
-
readonly mode: 'desktop' | 'demo' | 'web';
|
|
82
|
-
reserveObjectId?(occupied: string[]): Promise<string>;
|
|
83
|
-
/** Reserve an externally proposed, never-used object or table ID before exclusive creation. */
|
|
84
|
-
createAgentRecord?(path: string, content: string): Promise<void>;
|
|
85
|
-
/** Select a folder without opening it or changing the active workspace; null cancels. */
|
|
86
|
-
selectWorkspacePath?(): Promise<string | null>;
|
|
87
|
-
open(path?: string): Promise<Workspace | null>;
|
|
88
|
-
close?(workspaceId: string): Promise<void>;
|
|
89
|
-
createWorkspace?(name: string): Promise<Workspace>;
|
|
90
|
-
deleteWorkspace?(workspaceId: string): Promise<void>;
|
|
91
|
-
recent?(): Promise<RecentWorkspace[]>;
|
|
92
|
-
loadSession?(workspaceId: string): Promise<WorkspaceSession | null>;
|
|
93
|
-
saveSession?(workspaceId: string, session: WorkspaceSession): Promise<void>;
|
|
94
|
-
refresh(): Promise<Workspace>;
|
|
95
|
-
search?(workspaceId: string, query: string, signal?: AbortSignal): Promise<SearchHit[]>;
|
|
96
|
-
read(path: string): Promise<FileSnapshot>;
|
|
97
|
-
/** Optional version-checked, synchronous cache. Never returns speculative content. */
|
|
98
|
-
readCached?(path: string): FileSnapshot | undefined;
|
|
99
|
-
/** Best-effort read ahead; implementations bound speculative network work. */
|
|
100
|
-
prefetch?(path: string): Promise<void>;
|
|
101
|
-
write(path: string, content: string, expectedHash: string): Promise<WriteResult>;
|
|
102
|
-
/** May return the workspace including the confirmed creation to avoid a redundant refresh. */
|
|
103
|
-
create(path: string, content: string): Promise<void | Workspace>;
|
|
104
|
-
/** Persist a recoverable local draft without waiting for the remote authority. */
|
|
105
|
-
stageCreate?(path: string, content: string): Promise<{ workspace: Workspace; file: FileEntry }>;
|
|
106
|
-
/** Confirm the staged request, reusing its durable identity and idempotency key on retry. */
|
|
107
|
-
commitCreate?(id: string): Promise<{ file: FileEntry; snapshot: FileSnapshot }>;
|
|
108
|
-
createFolder(path: string): Promise<void>;
|
|
109
|
-
/** Must reject nonempty directories, including hidden/unindexed entries; never recurse. */
|
|
110
|
-
removeEmptyFolder?(workspaceId: string, path: string): Promise<void>;
|
|
111
|
-
rename(from: string, to: string): Promise<void>;
|
|
112
|
-
move(from: string, to: string, kind: FileEntry['kind']): Promise<void>;
|
|
113
|
-
duplicate?(workspaceId: string, path: string): Promise<string>;
|
|
114
|
-
remove(path: string): Promise<void>;
|
|
115
|
-
changeFile?(request: FileChangeRequest): Promise<WriteResult>;
|
|
116
|
-
/** Object-only compare-and-delete. Keeps the assistant file boundary unchanged. */
|
|
117
|
-
removeObjectFile?(request: FileChangeRequest): Promise<WriteResult>;
|
|
118
|
-
reveal(): Promise<void>;
|
|
119
|
-
watch(callback: () => void): Promise<() => void>;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface SearchHit {
|
|
123
|
-
id: string;
|
|
124
|
-
path: string;
|
|
125
|
-
excerpt: string;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface RecentWorkspace {
|
|
129
|
-
id: string;
|
|
130
|
-
name: string;
|
|
131
|
-
path: string;
|
|
132
|
-
openedAt: number;
|
|
133
|
-
/** Owner display label supplied by the storage adapter, when available. */
|
|
134
|
-
owner?: string;
|
|
135
|
-
/** Stable owner identity used by workspace dashboard filters. */
|
|
136
|
-
ownerUserId?: string;
|
|
137
|
-
/** Display identity for a cloud workspace owner, when the server provides it. */
|
|
138
|
-
ownerProfile?: { userId: string; name: string; avatar?: string };
|
|
139
|
-
/** Workspace creation time in milliseconds; absent for legacy workspaces. */
|
|
140
|
-
createdAt?: number | null;
|
|
141
|
-
/** Optional user selection state supplied by a storage adapter. */
|
|
142
|
-
favorite?: boolean;
|
|
143
|
-
/** Whether this workspace was explicitly shared with the current user. */
|
|
144
|
-
shared?: boolean;
|
|
145
|
-
icon?: string;
|
|
146
|
-
}
|
|
147
|
-
export interface SessionDocument {
|
|
148
|
-
id: string;
|
|
149
|
-
path: string;
|
|
150
|
-
draft?: { content: string; base: FileSnapshot };
|
|
151
|
-
}
|
|
152
|
-
export interface WorkspaceSession {
|
|
153
|
-
version: 1;
|
|
154
|
-
activeId: string;
|
|
155
|
-
documents: SessionDocument[];
|
|
156
|
-
tabs?: string[];
|
|
157
|
-
layout?: WorkspaceLayout;
|
|
158
|
-
dataTables?: {
|
|
159
|
-
id: string;
|
|
160
|
-
fileId?: string;
|
|
161
|
-
path?: string;
|
|
162
|
-
content: string;
|
|
163
|
-
base: FileSnapshot;
|
|
164
|
-
}[];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export interface WorkspacePane {
|
|
168
|
-
kind: 'pane';
|
|
169
|
-
id: string;
|
|
170
|
-
tabs: string[];
|
|
171
|
-
activeId: string;
|
|
172
|
-
}
|
|
173
|
-
export interface WorkspaceSplit {
|
|
174
|
-
kind: 'split';
|
|
175
|
-
id: string;
|
|
176
|
-
axis: 'horizontal' | 'vertical';
|
|
177
|
-
ratio: number;
|
|
178
|
-
first: WorkspaceLayout;
|
|
179
|
-
second: WorkspaceLayout;
|
|
180
|
-
}
|
|
181
|
-
export type WorkspaceLayout = WorkspacePane | WorkspaceSplit;
|
|
182
|
-
|
|
183
21
|
export * from './paths';
|
|
184
22
|
export * from './plugin-catalog';
|
|
185
23
|
export * from './plugin-connections';
|
|
186
24
|
export * from './plugin-automations';
|
|
187
25
|
export * from './task-review';
|
|
188
26
|
export * from './task-repeat';
|
|
27
|
+
export * from './plan-item';
|
|
189
28
|
export * from './file-database';
|
|
190
29
|
export * from './view-engine';
|
|
191
30
|
export * from './agent-gateway';
|
|
192
|
-
|
|
193
31
|
export * from './data-table-query';
|
|
194
|
-
|
|
195
32
|
export * from './structured-merge';
|
|
196
|
-
|
|
197
33
|
export * from './entry-drag';
|
|
198
|
-
|
|
199
34
|
export * from './appearance';
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import type { FileEntry } from './
|
|
1
|
+
import type { FileEntry } from './types';
|
|
2
2
|
import { isMarkdown } from './paths';
|
|
3
3
|
import { isWorkspaceInternalPath } from './workspace-paths';
|
|
4
4
|
import { isShortId } from './short-id';
|
|
@@ -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
|
+
}
|