agent-loft 0.2.126 → 0.2.128
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/README.md +4 -1
- package/bin/cli.js +40 -19
- package/package.json +7 -2
- package/src/agents/claude/session.ts +8 -5
- package/src/agents/codex/driver.ts +42 -17
- package/src/agents/codex/session.ts +5 -4
- package/src/agents/dsh/session.ts +3 -1
- package/src/agents/pi/session.ts +4 -3
- package/src/agents/workbuddy/session.ts +6 -3
- package/src/channels/web/api.ts +12 -1
- package/src/channels/web/memo-collab.ts +183 -0
- package/src/channels/web/memo-file.ts +30 -0
- package/src/channels/web/memo-storage.ts +172 -0
- package/src/channels/web/memos-api.ts +129 -0
- package/src/channels/web/server.ts +2 -0
- package/src/cli/service.ts +3 -1
- package/src/core/db.ts +18 -0
- package/src/core/expert-prompt.ts +2 -1
- package/src/core/hub.ts +4 -0
- package/src/core/mcp.ts +2 -2
- package/src/core/memo-index.ts +154 -0
- package/src/core/memo-sources.ts +82 -0
- package/src/core/memo-versions.ts +26 -0
- package/src/core/memos-bridge.ts +63 -0
- package/src/core/personal.ts +2 -0
- package/src/core/tasks-bridge.ts +6 -0
- package/src/core/tasks-mcp.ts +7 -0
- package/src/core/types.ts +2 -0
- package/src/core/ui-prefs.ts +1 -1
- package/src/core/upgrade-health.ts +21 -0
- package/src/core/upgrade-launcher.ts +94 -0
- package/src/core/upgrade-releases.ts +103 -0
- package/src/core/upgrade.ts +54 -18
- package/src/main.ts +14 -0
- package/src/mcp/memo-tools.ts +26 -0
- package/src/mcp/tasks-server.ts +5 -4
- package/web/css/memos.css +50 -0
- package/web/css/sidebar.css +1 -19
- package/web/index.html +1 -0
- package/web/lib/api.js +3 -2
- package/web/lib/markdown.js +9 -2
- package/web/settings/users.js +41 -15
- package/web/vendor-built/codemirror.js +20 -20
- package/web/views/file-editor.js +39 -7
- package/web/views/layout.js +6 -1
- package/web/views/memo-dialogs.js +147 -0
- package/web/views/memos.js +537 -0
- package/web/views/remote.js +2 -1
- package/web/views/sidebar-nav.js +1 -0
- package/web/views/topbar.js +4 -6
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// The revision advances only after the merged text has reached the remote file.
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import type { ServerResponse } from "node:http";
|
|
4
|
+
import { Text, ChangeSet } from "@codemirror/state";
|
|
5
|
+
import { rebaseUpdates, type Update } from "@codemirror/collab";
|
|
6
|
+
import { HttpError } from "./http.js";
|
|
7
|
+
import { TEXT_LIMIT } from "./memo-storage.js";
|
|
8
|
+
|
|
9
|
+
type Client = { id: string; account: string; seen: number; joined: number; waiting?: () => void };
|
|
10
|
+
type Room = {
|
|
11
|
+
doc: Text; crlf: boolean; version: string; offset: number; log: Update[];
|
|
12
|
+
cost: number[]; totalCost: number; clients: Map<string, Client>;
|
|
13
|
+
wake: Set<() => void>; seen: number; writing: boolean;
|
|
14
|
+
};
|
|
15
|
+
const rooms = new Map<string, Room>();
|
|
16
|
+
const locks = new Map<string, Promise<void>>();
|
|
17
|
+
const expiry = 10 * 60_000;
|
|
18
|
+
const expired = () => new HttpError(409, "协作版本已更新,请重新打开文件;未同步的内容可另存副本");
|
|
19
|
+
|
|
20
|
+
export async function withMemoLock<T>(key: string, task: () => Promise<T>) {
|
|
21
|
+
const previous = locks.get(key);
|
|
22
|
+
let release!: () => void;
|
|
23
|
+
const next = new Promise<void>(r => { release = r; });
|
|
24
|
+
locks.set(key, next);
|
|
25
|
+
try { await previous; return await task(); }
|
|
26
|
+
finally { release(); if (locks.get(key) === next) locks.delete(key); }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function wake(room: Room) { for (const resolve of room.wake) resolve(); }
|
|
30
|
+
export function invalidateMemo(key: string) {
|
|
31
|
+
const room = rooms.get(key);
|
|
32
|
+
rooms.delete(key);
|
|
33
|
+
if (room) wake(room);
|
|
34
|
+
}
|
|
35
|
+
export function closeMemoRooms() { for (const key of rooms.keys()) invalidateMemo(key); }
|
|
36
|
+
const sweep = setInterval(() => {
|
|
37
|
+
const cutoff = Date.now() - expiry;
|
|
38
|
+
for (const [key, room] of rooms) {
|
|
39
|
+
for (const [id, c] of room.clients) if (c.seen < cutoff) room.clients.delete(id);
|
|
40
|
+
if (room.seen < cutoff && !room.writing) invalidateMemo(key);
|
|
41
|
+
}
|
|
42
|
+
}, 60_000);
|
|
43
|
+
sweep.unref();
|
|
44
|
+
|
|
45
|
+
export function joinMemo(key: string, account: string, text: string, version: string) {
|
|
46
|
+
let room = rooms.get(key);
|
|
47
|
+
if (!room || room.version !== version || room.doc.sliceString(0, room.doc.length, room.crlf ? "\r\n" : "\n") !== text) {
|
|
48
|
+
invalidateMemo(key);
|
|
49
|
+
if (rooms.size >= 128) {
|
|
50
|
+
const idle = [...rooms].filter(([,r]) => !r.writing && !r.wake.size).sort((a,b) => a[1].seen - b[1].seen)[0];
|
|
51
|
+
if (!idle) throw new HttpError(503, "协作文件较多,请稍后重试");
|
|
52
|
+
invalidateMemo(idle[0]);
|
|
53
|
+
}
|
|
54
|
+
const crlf = text.includes("\r\n") && !/[\r\n]/.test(text.replace(/\r\n/g, ""));
|
|
55
|
+
room = { doc: Text.of(text.split(crlf ? "\r\n" : "\n")), crlf, version, offset: 0, log: [], cost: [],
|
|
56
|
+
totalCost: 0, clients: new Map(), wake: new Set(), seen: Date.now(), writing: false };
|
|
57
|
+
rooms.set(key, room);
|
|
58
|
+
}
|
|
59
|
+
room.seen = Date.now();
|
|
60
|
+
const token = randomUUID(), clientID = randomUUID();
|
|
61
|
+
const startVersion = room.offset + room.log.length;
|
|
62
|
+
room.clients.set(token, { account, id: clientID, seen: room.seen, joined: startVersion });
|
|
63
|
+
return { token, clientID, crlf: room.crlf, startVersion };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function access(key: string, token: string, account: string, since: number) {
|
|
67
|
+
const room = rooms.get(key), client = room?.clients.get(token);
|
|
68
|
+
if (!room || !client || client.account !== account) throw expired();
|
|
69
|
+
if (!Number.isSafeInteger(since) || since < Math.max(client.joined, room.offset) || since > room.offset + room.log.length) throw expired();
|
|
70
|
+
client.seen = room.seen = Date.now();
|
|
71
|
+
return { room, client };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function packet(room: Room, since: number) {
|
|
75
|
+
return { from: since, updates: room.log.slice(since - room.offset), version: room.version };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function pullMemo(key: string, token: string, account: string, since: number, res: ServerResponse) {
|
|
79
|
+
const { room, client } = access(key, token, account, since);
|
|
80
|
+
if (!res.destroyed && since === room.offset + room.log.length) {
|
|
81
|
+
await new Promise<void>(resolve => {
|
|
82
|
+
client.waiting?.();
|
|
83
|
+
const done = () => {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
room.wake.delete(done);
|
|
86
|
+
res.off("close", done);
|
|
87
|
+
client.waiting = undefined;
|
|
88
|
+
resolve();
|
|
89
|
+
};
|
|
90
|
+
const timer = setTimeout(done, 20_000);
|
|
91
|
+
client.waiting = done;
|
|
92
|
+
room.wake.add(done);
|
|
93
|
+
res.once("close", done);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (res.destroyed) return;
|
|
97
|
+
access(key, token, account, since);
|
|
98
|
+
return packet(room, since);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function decodeChanges(raw: unknown, length: number) {
|
|
102
|
+
if (!Array.isArray(raw) || raw.length > 100_000) throw new Error();
|
|
103
|
+
for (const section of raw) {
|
|
104
|
+
const count = Array.isArray(section) ? section[0] : section;
|
|
105
|
+
if (!Number.isSafeInteger(count) || count < 0 || count > TEXT_LIMIT ||
|
|
106
|
+
(Array.isArray(section) && section.slice(1).some(line => typeof line !== "string" || /[\n\0]/.test(line)))) throw new Error();
|
|
107
|
+
}
|
|
108
|
+
const changes = ChangeSet.fromJSON(raw);
|
|
109
|
+
if (changes.length !== length || changes.newLength > TEXT_LIMIT) throw new Error();
|
|
110
|
+
return changes;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Called inside the same per-file lock as full-document opens and saves.
|
|
114
|
+
export async function pushMemo(key: string, token: string, account: string, since: number, raw: unknown,
|
|
115
|
+
persist: (text: string, version: string, expected: string) => Promise<string>) {
|
|
116
|
+
const { room, client } = access(key, token, account, since);
|
|
117
|
+
const over = room.log.slice(since - room.offset);
|
|
118
|
+
if (!Array.isArray(raw) || !raw.length || raw.length > 128) throw new HttpError(400, "协作修改批次无效");
|
|
119
|
+
let length = over[0]?.changes.length ?? room.doc.length;
|
|
120
|
+
let accepted: readonly Update[], doc = room.doc;
|
|
121
|
+
try {
|
|
122
|
+
const updates = raw.map(value => {
|
|
123
|
+
const changes = decodeChanges(value, length);
|
|
124
|
+
length = changes.newLength;
|
|
125
|
+
return { clientID: client.id, changes };
|
|
126
|
+
});
|
|
127
|
+
accepted = rebaseUpdates(updates, over);
|
|
128
|
+
for (const update of accepted) doc = update.changes.apply(doc);
|
|
129
|
+
} catch { throw new HttpError(400, "协作修改与文档不匹配"); }
|
|
130
|
+
if (!accepted.length) return packet(room, since);
|
|
131
|
+
const text = doc.sliceString(0, doc.length, room.crlf ? "\r\n" : "\n");
|
|
132
|
+
if (/[\uD800-\uDFFF]/u.test(text)) throw new HttpError(400, "协作修改拆开了 Unicode 字符");
|
|
133
|
+
if (Buffer.byteLength(text) > TEXT_LIMIT) throw new HttpError(413, "文本上限为 2 MB");
|
|
134
|
+
room.writing = true;
|
|
135
|
+
try { room.version = await persist(text, room.version, room.doc.sliceString(0, room.doc.length, room.crlf ? "\r\n" : "\n")); }
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (err instanceof HttpError && [409,404].includes(err.status)) invalidateMemo(key);
|
|
138
|
+
throw err;
|
|
139
|
+
} finally { room.writing = false; }
|
|
140
|
+
room.doc = doc;
|
|
141
|
+
for (const update of accepted) {
|
|
142
|
+
room.log.push(update);
|
|
143
|
+
const bytes = Buffer.byteLength(JSON.stringify(update));
|
|
144
|
+
room.cost.push(bytes);
|
|
145
|
+
room.totalCost += bytes;
|
|
146
|
+
}
|
|
147
|
+
const result = packet(room, since);
|
|
148
|
+
while (room.log.length > accepted.length && (room.log.length > 1024 || room.totalCost > 4 * TEXT_LIMIT)) {
|
|
149
|
+
room.log.shift();
|
|
150
|
+
room.totalCost -= room.cost.shift()!;
|
|
151
|
+
room.offset++;
|
|
152
|
+
}
|
|
153
|
+
wake(room);
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Called under the file lock after reading the current remote version. Use the
|
|
158
|
+
// same change log as the editors so their pending keystrokes can be rebased.
|
|
159
|
+
export async function editMemoRange(key: string, account: string, original: string, version: string,
|
|
160
|
+
start: number, end: number, insert: string, persist: (text: string, version: string, expected: string) => Promise<string>) {
|
|
161
|
+
const room = rooms.get(key);
|
|
162
|
+
const separator = room?.crlf ? "\r\n" : "\n";
|
|
163
|
+
const matching = room && room.doc.sliceString(0, room.doc.length, separator) === original;
|
|
164
|
+
// Some servers supply an ETag on GET but omit it on PUT. The same text
|
|
165
|
+
// can then have two revision representations while an editor stays open.
|
|
166
|
+
const crlf = matching ? room.crlf : original.includes("\r\n") && !/[\r\n]/.test(original.replaceAll("\r\n", ""));
|
|
167
|
+
if (crlf) insert = insert.replace(/\r?\n/g, "\r\n");
|
|
168
|
+
const text = original.slice(0, start) + insert + original.slice(end);
|
|
169
|
+
if (!matching) {
|
|
170
|
+
const saved = await persist(text, version, original);
|
|
171
|
+
if (room) invalidateMemo(key);
|
|
172
|
+
return saved;
|
|
173
|
+
}
|
|
174
|
+
room.version = version;
|
|
175
|
+
const pos = (offset: number) => Text.of(original.slice(0, offset).split(separator)).length;
|
|
176
|
+
const change = ChangeSet.of({ from: pos(start), to: pos(end), insert: Text.of(insert.split(separator)) }, room.doc.length);
|
|
177
|
+
if (change.apply(room.doc).sliceString(0, change.newLength, separator) !== text) throw new HttpError(409, "修改位置与协作文档不匹配,请重新读取");
|
|
178
|
+
const client = joinMemo(key, account, original, version);
|
|
179
|
+
try {
|
|
180
|
+
const result = await pushMemo(key, client.token, account, client.startVersion, [change.toJSON()], persist);
|
|
181
|
+
return result.version;
|
|
182
|
+
} finally { rooms.get(key)?.clients.delete(client.token); }
|
|
183
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { canReadMemo, memoHistoryKey, memoSources, validMemoPath, type MemoSource } from "../../core/memo-sources.js";
|
|
3
|
+
import { indexSavedMemo } from "../../core/memo-index.js";
|
|
4
|
+
import { rememberMemoVersion } from "../../core/memo-versions.js";
|
|
5
|
+
import { isAdmin, type User } from "../../core/users.js";
|
|
6
|
+
import { HttpError } from "./http.js";
|
|
7
|
+
import { editable, MemoStorage, TEXT_LIMIT } from "./memo-storage.js";
|
|
8
|
+
|
|
9
|
+
export function memoFile(user: User, source: MemoSource, path: string, check: () => void) {
|
|
10
|
+
if (!validMemoPath(path) || !editable(path)) throw new HttpError(400, "请选择可编辑的文本文件");
|
|
11
|
+
const storage = new MemoStorage(source, isAdmin(user));
|
|
12
|
+
const lockKey = storage.objectURL(path).href;
|
|
13
|
+
const key = createHash("sha256").update(JSON.stringify([source.kind, lockKey, source.username, source.secret])).digest("hex");
|
|
14
|
+
const account = JSON.stringify([user.id, source.id, user.role]);
|
|
15
|
+
const persist = async (text: string, version: string | null, expected?: string) => {
|
|
16
|
+
check();
|
|
17
|
+
if (typeof text !== "string" || text.includes("\0") || /[\uD800-\uDFFF]/u.test(text)) throw new HttpError(400, "正文无效");
|
|
18
|
+
const bytes = Buffer.from(text);
|
|
19
|
+
if (bytes.length > TEXT_LIMIT) throw new HttpError(413, "文本上限为 2 MB");
|
|
20
|
+
const saved = await storage.put(path, bytes, /\.md$/i.test(path) ? "text/markdown; charset=utf-8" : "text/plain; charset=utf-8", version, previous => {
|
|
21
|
+
check();
|
|
22
|
+
if (expected !== undefined && !previous.equals(Buffer.from(expected))) throw new HttpError(409, "远端正文已被修改");
|
|
23
|
+
rememberMemoVersion(user.id, memoHistoryKey(source), path, previous);
|
|
24
|
+
});
|
|
25
|
+
const active = memoSources(user.id).find(s => s.id === source.id);
|
|
26
|
+
if (active && canReadMemo(active)) indexSavedMemo(user.id, source.id, path, text, saved);
|
|
27
|
+
return saved;
|
|
28
|
+
};
|
|
29
|
+
return { key, lockKey, account, persist, read: () => storage.readText(path) };
|
|
30
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// WebDAV collections and S3 prefixes both expose one directory level at a time.
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import https from "node:https";
|
|
4
|
+
import dns from "node:dns/promises";
|
|
5
|
+
import { isIP } from "node:net";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import ipaddr from "ipaddr.js";
|
|
8
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
9
|
+
import { SignatureV4 } from "@smithy/signature-v4";
|
|
10
|
+
import { Sha256 } from "@smithy/core/checksum";
|
|
11
|
+
import { HttpRequest } from "@smithy/core/protocols";
|
|
12
|
+
import { validMemoPath, type MemoSource } from "../../core/memo-sources.js";
|
|
13
|
+
import { HttpError } from "./http.js";
|
|
14
|
+
|
|
15
|
+
export const TEXT_LIMIT = 2 * 1024 * 1024;
|
|
16
|
+
export const IMAGE_LIMIT = 12 * 1024 * 1024;
|
|
17
|
+
export const editable = (path: string) => /\.(?:md|markdown|txt|json|ya?ml|toml|ini|csv|tsv|log|css|js|ts|xml|html)$/i.test(path);
|
|
18
|
+
const encode = (path: string) => path.split("/").map(s => encodeURIComponent(s).replace(/[!'()*]/g, c => "%" + c.charCodeAt(0).toString(16).toUpperCase())).join("/");
|
|
19
|
+
type Reply = { status: number; body: Buffer; etag?: string };
|
|
20
|
+
const conflict = () => new HttpError(409, "文件已存在或已被其他设备修改。请保留草稿并重新打开远端版本。");
|
|
21
|
+
function checked(r: Reply) {
|
|
22
|
+
if (r.status === 412 || r.status === 409) throw conflict();
|
|
23
|
+
if (r.status < 200 || r.status >= 300) throw new HttpError(r.status === 404 ? 404 : 502, `存储服务返回 HTTP ${r.status},请检查地址、凭据和目录权限`);
|
|
24
|
+
return r;
|
|
25
|
+
}
|
|
26
|
+
function revision(r: Reply) {
|
|
27
|
+
return r.etag && /^"[^"\r\n]*"$/.test(r.etag) ? r.etag : "sha256:" + createHash("sha256").update(r.body).digest("hex");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function xml(r: Reply, root: string) {
|
|
31
|
+
const value = checked(r).body.toString("utf8");
|
|
32
|
+
if (/<!DOCTYPE/i.test(value)) throw new HttpError(502, "目录响应包含不支持的 XML 声明");
|
|
33
|
+
try {
|
|
34
|
+
const doc = new DOMParser().parseFromString(value, "application/xml");
|
|
35
|
+
if (doc.documentElement?.localName === root) return doc.documentElement;
|
|
36
|
+
} catch { /* generic error without remote response content */ }
|
|
37
|
+
throw new HttpError(502, "存储服务没有返回有效的目录列表");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class MemoStorage {
|
|
41
|
+
constructor(readonly source: MemoSource, private readonly allowPrivate: boolean) {}
|
|
42
|
+
|
|
43
|
+
objectURL(path: string, listing = false) {
|
|
44
|
+
const { kind, bucket, prefix, endpoint } = this.source;
|
|
45
|
+
const url = new URL(endpoint);
|
|
46
|
+
if (kind === "s3") url.pathname += bucket + "/" + (listing ? "" : encode([prefix, path].filter(Boolean).join("/")));
|
|
47
|
+
else url.pathname += encode(path);
|
|
48
|
+
return url;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private async request(method: string, url: URL, headers: Record<string, string> = {}, body?: Buffer, limit = TEXT_LIMIT): Promise<Reply> {
|
|
52
|
+
const { kind, username, secret, region } = this.source;
|
|
53
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
54
|
+
try {
|
|
55
|
+
// Pin the resolved public address for member connections (including literal IPs).
|
|
56
|
+
let address: string | undefined;
|
|
57
|
+
if (!this.allowPrivate) {
|
|
58
|
+
address = isIP(host) ? host : (await dns.lookup(host)).address;
|
|
59
|
+
if (ipaddr.process(address).range() !== "unicast") throw new HttpError(403, "内网存储地址需要使用管理员账号连接");
|
|
60
|
+
}
|
|
61
|
+
headers = { ...headers, host: url.host };
|
|
62
|
+
if (body) headers["content-length"] = String(body.length);
|
|
63
|
+
if (kind === "s3") {
|
|
64
|
+
const signer = new SignatureV4({ service: "s3", region, sha256: Sha256, uriEscapePath: false, credentials: { accessKeyId: username, secretAccessKey: secret } });
|
|
65
|
+
const request = new HttpRequest({ method, protocol: url.protocol, hostname: host, path: url.pathname, headers, query: Object.fromEntries(url.searchParams), body });
|
|
66
|
+
headers = (await signer.sign(request)).headers;
|
|
67
|
+
} else if (username || secret) headers.authorization = "Basic " + Buffer.from(username + ":" + secret).toString("base64");
|
|
68
|
+
return await new Promise<Reply>((resolve, reject) => {
|
|
69
|
+
const client = url.protocol === "https:" ? https : http;
|
|
70
|
+
const req = client.request(url, {
|
|
71
|
+
method, headers, agent: false, signal: AbortSignal.timeout(30_000),
|
|
72
|
+
...(address ? { hostname: address, servername: isIP(host) ? undefined : host } : {}),
|
|
73
|
+
}, async res => {
|
|
74
|
+
try {
|
|
75
|
+
const chunks: Buffer[] = [];
|
|
76
|
+
let size = 0;
|
|
77
|
+
for await (const chunk of res) {
|
|
78
|
+
size += chunk.length;
|
|
79
|
+
if (size > limit) throw new HttpError(413, "文件或目录超出预览大小限制");
|
|
80
|
+
chunks.push(chunk);
|
|
81
|
+
}
|
|
82
|
+
resolve({ body: Buffer.concat(chunks), status: res.statusCode ?? 502, etag: res.headers.etag });
|
|
83
|
+
} catch (err) { res.destroy(); reject(err); }
|
|
84
|
+
});
|
|
85
|
+
req.on("error", reject);
|
|
86
|
+
req.end(body);
|
|
87
|
+
});
|
|
88
|
+
} catch (err) {
|
|
89
|
+
if (err instanceof HttpError) throw err;
|
|
90
|
+
throw new HttpError(502, "无法连接存储服务,请检查地址、网络和 TLS 证书");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async list(dir: string, cursor = "") {
|
|
95
|
+
const entries: { name: string; directory: boolean; etag?: string }[] = [];
|
|
96
|
+
const add = (name: string, directory: boolean, etag?: string | null) => {
|
|
97
|
+
if (!name.includes("/") && validMemoPath(name)) entries.push({ name, directory, ...(etag && /^"[^"\r\n]*"$/.test(etag) ? { etag } : {}) });
|
|
98
|
+
};
|
|
99
|
+
let next = "";
|
|
100
|
+
if (this.source.kind === "s3") {
|
|
101
|
+
const url = this.objectURL("", true);
|
|
102
|
+
const prefix = [this.source.prefix, dir].filter(Boolean).map(s => s + "/").join("");
|
|
103
|
+
url.search = new URLSearchParams({ "list-type": "2", delimiter: "/", prefix, ...(cursor ? { "continuation-token": cursor } : {}) }).toString().replace(/\+/g, "%20");
|
|
104
|
+
const root = xml(await this.request("GET", url), "ListBucketResult");
|
|
105
|
+
for (const [tag, key, directory] of [["Contents", "Key", false], ["CommonPrefixes", "Prefix", true]] as const) {
|
|
106
|
+
for (const el of Array.from(root.getElementsByTagNameNS("*", tag))) {
|
|
107
|
+
const val = el.getElementsByTagNameNS("*", key)[0]?.textContent;
|
|
108
|
+
if (val?.startsWith(prefix)) add(val.slice(prefix.length).replace(/\/$/, ""), directory, el.getElementsByTagNameNS("*", "ETag")[0]?.textContent);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
next = root.getElementsByTagNameNS("*", "NextContinuationToken")[0]?.textContent ?? "";
|
|
112
|
+
} else {
|
|
113
|
+
const url = this.objectURL(dir ? dir + "/" : "");
|
|
114
|
+
const r = await this.request("PROPFIND", url, { depth: "1", "content-type": "application/xml" }, Buffer.from('<propfind xmlns="DAV:"><prop><resourcetype/><getetag/></prop></propfind>'));
|
|
115
|
+
const root = xml(r, "multistatus");
|
|
116
|
+
const base = decodeURIComponent(url.pathname);
|
|
117
|
+
for (const item of Array.from(root.getElementsByTagNameNS("DAV:", "response"))) {
|
|
118
|
+
const href = item.getElementsByTagNameNS("DAV:", "href")[0]?.textContent;
|
|
119
|
+
if (!href) continue;
|
|
120
|
+
const child = new URL(href, url);
|
|
121
|
+
const path = decodeURIComponent(child.pathname);
|
|
122
|
+
if (child.origin === url.origin && path.startsWith(base)) add(path.slice(base.length).replace(/\/$/, ""), item.getElementsByTagNameNS("DAV:", "collection").length > 0, item.getElementsByTagNameNS("DAV:", "getetag")[0]?.textContent);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { entries: entries.sort((a,b) => Number(b.directory) - Number(a.directory) || a.name.localeCompare(b.name, "zh-CN", { numeric: true })), next };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async read(path: string, limit = TEXT_LIMIT) {
|
|
129
|
+
const r = checked(await this.request("GET", this.objectURL(path), {}, undefined, limit));
|
|
130
|
+
return { bytes: r.body, version: revision(r) };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async readText(path: string) {
|
|
134
|
+
const { bytes, version } = await this.read(path);
|
|
135
|
+
let text;
|
|
136
|
+
try { text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes); }
|
|
137
|
+
catch { throw new HttpError(415, "仅支持 UTF-8 文本"); }
|
|
138
|
+
if (text.includes("\0")) throw new HttpError(415, "此文件包含二进制数据");
|
|
139
|
+
return { text, version };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async put(path: string, bytes: Buffer, type: string, version: string | null, beforeReplace?: (bytes: Buffer) => void) {
|
|
143
|
+
const headers: Record<string, string> = { "content-type": type };
|
|
144
|
+
if (version === null) headers["if-none-match"] = "*";
|
|
145
|
+
else {
|
|
146
|
+
const hashed = /^sha256:[a-f0-9]{64}$/.test(version);
|
|
147
|
+
if (!hashed && !/^"[^"\r\n]*"$/.test(version)) throw new HttpError(400, "文件版本无效");
|
|
148
|
+
const current = await this.request("GET", this.objectURL(path));
|
|
149
|
+
if (current.status === 404) throw conflict();
|
|
150
|
+
checked(current);
|
|
151
|
+
const currentVersion = revision(current);
|
|
152
|
+
// A retry after a lost PUT response can acknowledge an already committed edit.
|
|
153
|
+
if (current.body.equals(bytes)) return currentVersion;
|
|
154
|
+
if ((hashed ? revision({ ...current, etag: undefined }) : currentVersion) !== version) throw conflict();
|
|
155
|
+
if (currentVersion === current.etag) headers["if-match"] = currentVersion;
|
|
156
|
+
beforeReplace?.(current.body);
|
|
157
|
+
}
|
|
158
|
+
const result = checked(await this.request("PUT", this.objectURL(path), headers, bytes));
|
|
159
|
+
return revision({ ...result, body: bytes });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async mkdir(path: string, existingOK = false) {
|
|
163
|
+
if (this.source.kind === "s3") {
|
|
164
|
+
try { await this.put(path + "/", Buffer.alloc(0), "application/x-directory", null); }
|
|
165
|
+
catch (err) { if (!(existingOK && err instanceof HttpError && err.status === 409)) throw err; }
|
|
166
|
+
} else {
|
|
167
|
+
const r = await this.request("MKCOL", this.objectURL(path + "/"));
|
|
168
|
+
if (r.status === 405 && existingOK) return; // PUT of the child verifies the collection.
|
|
169
|
+
checked(r);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { memoFile } from "./memo-file.js";
|
|
2
|
+
import { clearMemoIndex, memoIndexStatus, refreshMemoIndex } from "../../core/memo-index.js";
|
|
3
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { invalidateMemo, joinMemo, pullMemo, pushMemo, withMemoLock } from "./memo-collab.js";
|
|
6
|
+
import { posix } from "node:path";
|
|
7
|
+
import { addMemoSource, canReadMemo, parseMemoAccess, setMemoAccess, memoHistoryKey, memoSources, parseMemoSource, publicSource, removeMemoSource, validMemoPath } from "../../core/memo-sources.js";
|
|
8
|
+
import { memoVersions, memoVersionText } from "../../core/memo-versions.js";
|
|
9
|
+
import { sniff } from "../../core/uploads.js";
|
|
10
|
+
import { isAdmin, type User } from "../../core/users.js";
|
|
11
|
+
import { HttpError, readBody, readJsonBody, SECURITY_HEADERS, sendJson } from "./http.js";
|
|
12
|
+
import { editable, IMAGE_LIMIT, MemoStorage, TEXT_LIMIT } from "./memo-storage.js";
|
|
13
|
+
|
|
14
|
+
export async function handleMemosApi(req: IncomingMessage, res: ServerResponse, url: URL, user: User, current: () => User | undefined) {
|
|
15
|
+
const action = url.pathname.slice("/api/memos/".length);
|
|
16
|
+
const method = req.method;
|
|
17
|
+
if (action === "sources" && method === "GET") return sendJson(res, 200, memoSources(user.id).map(publicSource));
|
|
18
|
+
if (action === "sources" && method === "POST") {
|
|
19
|
+
const body = await readJsonBody(req, 16_384);
|
|
20
|
+
let source;
|
|
21
|
+
try { source = parseMemoSource(body); }
|
|
22
|
+
catch (err) { throw new HttpError(400, err instanceof Error ? err.message : "数据源配置无效"); }
|
|
23
|
+
await new MemoStorage(source, isAdmin(user)).list("");
|
|
24
|
+
addMemoSource(user.id, source);
|
|
25
|
+
if (canReadMemo(source)) void refreshMemoIndex(user.id, source);
|
|
26
|
+
return sendJson(res, 201, publicSource(source));
|
|
27
|
+
}
|
|
28
|
+
const source = memoSources(user.id).find(s => s.id === url.searchParams.get("source"));
|
|
29
|
+
if (!source) throw new HttpError(404, "笔记库不存在");
|
|
30
|
+
if (action === "sources" && method === "DELETE") {
|
|
31
|
+
clearMemoIndex(user.id, source.id);
|
|
32
|
+
removeMemoSource(user.id, source.id);
|
|
33
|
+
return sendJson(res, 200, { ok: true });
|
|
34
|
+
}
|
|
35
|
+
if (action === "access" && method === "PUT") {
|
|
36
|
+
const body = await readJsonBody(req, 1024);
|
|
37
|
+
let access;
|
|
38
|
+
try { access = parseMemoAccess(body.access); }
|
|
39
|
+
catch { throw new HttpError(400, "智能体访问权限无效"); }
|
|
40
|
+
if (access === "off" || !canReadMemo(source)) clearMemoIndex(user.id, source.id);
|
|
41
|
+
const updated = setMemoAccess(user.id, source.id, access);
|
|
42
|
+
if (access !== "off" && !canReadMemo(source)) void refreshMemoIndex(user.id, updated);
|
|
43
|
+
return sendJson(res, 200, publicSource(updated));
|
|
44
|
+
}
|
|
45
|
+
if (action === "index" && (method === "GET" || method === "POST")) {
|
|
46
|
+
if (method === "POST" && canReadMemo(source)) void refreshMemoIndex(user.id, source);
|
|
47
|
+
return sendJson(res, 200, memoIndexStatus(user.id, source.id));
|
|
48
|
+
}
|
|
49
|
+
const storage = new MemoStorage(source, isAdmin(user));
|
|
50
|
+
const path = url.searchParams.get("path") ?? "";
|
|
51
|
+
const listing = action === "tree" && method === "GET";
|
|
52
|
+
if (!(listing && path === "") && !validMemoPath(path)) throw new HttpError(400, "笔记路径无效");
|
|
53
|
+
if (listing) return sendJson(res, 200, await storage.list(path, url.searchParams.get("cursor") ?? ""));
|
|
54
|
+
if (action === "folder" && method === "POST") {
|
|
55
|
+
await storage.mkdir(path);
|
|
56
|
+
return sendJson(res, 201, { ok: true });
|
|
57
|
+
}
|
|
58
|
+
if (action === "image" && method === "GET") {
|
|
59
|
+
if (!/\.(png|jpe?g|gif|webp)$/i.test(path)) throw new HttpError(415, "不支持此图片格式");
|
|
60
|
+
const { bytes } = await storage.read(path, IMAGE_LIMIT);
|
|
61
|
+
const type = sniff(bytes)?.mediaType;
|
|
62
|
+
if (!type?.startsWith("image/")) throw new HttpError(415, "图片格式无效");
|
|
63
|
+
res.writeHead(200, { ...SECURITY_HEADERS, "Content-Type": type, "Cache-Control": "private, no-store" });
|
|
64
|
+
res.end(bytes);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!editable(path)) throw new HttpError(415, "此格式暂不支持编辑");
|
|
68
|
+
if (action === "history" && method === "GET") {
|
|
69
|
+
const id = url.searchParams.get("id");
|
|
70
|
+
if (id === null) return sendJson(res, 200, memoVersions(user.id, memoHistoryKey(source), path));
|
|
71
|
+
if (!/^[1-9]\d*$/.test(id) || !Number.isSafeInteger(Number(id))) throw new HttpError(400, "版本编号无效");
|
|
72
|
+
const text = memoVersionText(user.id, memoHistoryKey(source), path, Number(id));
|
|
73
|
+
if (text === null) throw new HttpError(404, "历史版本不存在");
|
|
74
|
+
return sendJson(res, 200, { text });
|
|
75
|
+
}
|
|
76
|
+
if (action === "attachment" && method === "POST") {
|
|
77
|
+
const bytes = await readBody(req, IMAGE_LIMIT);
|
|
78
|
+
const type = sniff(bytes);
|
|
79
|
+
if (!type?.mediaType.startsWith("image/")) throw new HttpError(415, "请选择 PNG、JPEG、GIF 或 WebP 图片");
|
|
80
|
+
const dir = posix.join(posix.dirname(path), "assets");
|
|
81
|
+
const name = `image-${randomUUID()}.${type.ext}`;
|
|
82
|
+
await storage.mkdir(dir, true);
|
|
83
|
+
await storage.put(posix.join(dir, name), bytes, type.mediaType, null);
|
|
84
|
+
return sendJson(res, 201, { relative: "assets/" + name });
|
|
85
|
+
}
|
|
86
|
+
const joining = url.searchParams.get("collab") === "1";
|
|
87
|
+
const checkAccess = () => {
|
|
88
|
+
const active = current();
|
|
89
|
+
if (active?.id !== user.id || active.role !== user.role || !memoSources(user.id).some(s => s.id === source.id)) throw new HttpError(403, "协作连接已失效");
|
|
90
|
+
};
|
|
91
|
+
const { lockKey, key, account, persist, read } = memoFile(user, source, path, checkAccess);
|
|
92
|
+
if (action === "changes") {
|
|
93
|
+
const token = String(req.headers["x-memo-client"] ?? "");
|
|
94
|
+
const since = Number(url.searchParams.get("since") ?? NaN);
|
|
95
|
+
if (method === "GET") {
|
|
96
|
+
const result = await pullMemo(key, token, account, since, res);
|
|
97
|
+
if (!result) return;
|
|
98
|
+
checkAccess();
|
|
99
|
+
return sendJson(res, 200, result);
|
|
100
|
+
}
|
|
101
|
+
if (method === "POST") {
|
|
102
|
+
const body = await readJsonBody(req, TEXT_LIMIT * 8);
|
|
103
|
+
const result = await withMemoLock(lockKey, () => {
|
|
104
|
+
checkAccess();
|
|
105
|
+
return pushMemo(key, token, account, since, body?.updates, persist);
|
|
106
|
+
});
|
|
107
|
+
return sendJson(res, 200, result);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (action === "file" && method === "GET") {
|
|
111
|
+
const result = await withMemoLock(lockKey, async () => {
|
|
112
|
+
const { text, version } = await read();
|
|
113
|
+
return { text, version, collab: joining ? joinMemo(key, account, text, version) : undefined };
|
|
114
|
+
});
|
|
115
|
+
return sendJson(res, 200, result);
|
|
116
|
+
}
|
|
117
|
+
if (action === "file" && method === "PUT") {
|
|
118
|
+
const data = await readJsonBody(req, TEXT_LIMIT * 6 + 1024);
|
|
119
|
+
const { text, version } = data ?? {};
|
|
120
|
+
if (typeof text !== "string" || text.includes("\0") || (version !== null && typeof version !== "string")) throw new HttpError(400, "正文或版本无效");
|
|
121
|
+
const result = await withMemoLock(lockKey, async () => {
|
|
122
|
+
const saved = await persist(text, version);
|
|
123
|
+
invalidateMemo(key);
|
|
124
|
+
return { version: saved, collab: joining ? joinMemo(key, account, text, saved) : undefined };
|
|
125
|
+
});
|
|
126
|
+
return sendJson(res, 200, result);
|
|
127
|
+
}
|
|
128
|
+
throw new HttpError(404, "备忘录操作不存在");
|
|
129
|
+
}
|
|
@@ -33,6 +33,7 @@ import { HttpError, pageHeaders, sameOrigin, SECURITY_HEADERS, sendJson } from "
|
|
|
33
33
|
import { hasSubscriptions, pushToAll } from "./push.js";
|
|
34
34
|
import { closeListener, listen, listening, rebind } from "./listen.js";
|
|
35
35
|
import { closeTerminalClients, pingTerminalClients, recheckTerminalClients, upgradeTerminal } from "./terminal.js";
|
|
36
|
+
import { closeMemoRooms } from "./memo-collab.js";
|
|
36
37
|
import { closeDesktopClients, pingDesktopClients, recheckDesktopClients, upgradeDesktop } from "./desktop.js";
|
|
37
38
|
import { stopDesktop } from "../../core/desktop.js";
|
|
38
39
|
|
|
@@ -829,6 +830,7 @@ function onRevoked(): void {
|
|
|
829
830
|
}
|
|
830
831
|
|
|
831
832
|
export async function stopWeb(): Promise<void> {
|
|
833
|
+
closeMemoRooms();
|
|
832
834
|
authEvents.off("revoked", onRevoked);
|
|
833
835
|
hub.off("event", broadcastEvent);
|
|
834
836
|
hub.off("realtime", broadcastRealtime);
|
package/src/cli/service.ts
CHANGED
|
@@ -6,6 +6,7 @@ import fs from "node:fs";
|
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { releaseStore } from "../core/upgrade-releases.js";
|
|
9
10
|
import { home, logsDir } from "../home.js";
|
|
10
11
|
|
|
11
12
|
const UNIT = "agent-loft";
|
|
@@ -13,7 +14,8 @@ const LABEL = "com.agent-loft";
|
|
|
13
14
|
/** 改名前的服务名。装新服务时顺手卸掉,免得新旧两个进程抢同一个飞书机器人的消息 */
|
|
14
15
|
const LEGACY_UNIT = "im-agent";
|
|
15
16
|
const LEGACY_LABEL = "com.im-agent";
|
|
16
|
-
const
|
|
17
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
18
|
+
const entry = path.join(path.dirname(releaseStore(packageRoot)), "bin/cli.js");
|
|
17
19
|
|
|
18
20
|
function unitPath(): string {
|
|
19
21
|
return process.platform === "darwin"
|
package/src/core/db.ts
CHANGED
|
@@ -43,6 +43,24 @@ function loadSqlite(): typeof import("node:sqlite") {
|
|
|
43
43
|
const SCHEMA = `
|
|
44
44
|
CREATE TABLE IF NOT EXISTS migrations (name TEXT PRIMARY KEY, at INTEGER NOT NULL);
|
|
45
45
|
|
|
46
|
+
CREATE TABLE IF NOT EXISTS memo_scans (
|
|
47
|
+
owner TEXT NOT NULL, source TEXT NOT NULL, success INTEGER NOT NULL, PRIMARY KEY(owner,source)
|
|
48
|
+
);
|
|
49
|
+
CREATE TABLE IF NOT EXISTS memo_documents (
|
|
50
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT, owner TEXT NOT NULL, source TEXT NOT NULL, path TEXT NOT NULL,
|
|
51
|
+
version TEXT NOT NULL, body TEXT NOT NULL, UNIQUE(owner,source,path)
|
|
52
|
+
);
|
|
53
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memo_fts USING fts5(path, body, content='', contentless_delete=1, tokenize='unicode61');
|
|
54
|
+
CREATE TRIGGER IF NOT EXISTS memo_documents_delete AFTER DELETE ON memo_documents BEGIN
|
|
55
|
+
DELETE FROM memo_fts WHERE rowid = old.id;
|
|
56
|
+
END;
|
|
57
|
+
|
|
58
|
+
CREATE TABLE IF NOT EXISTS memo_versions (
|
|
59
|
+
id INTEGER PRIMARY KEY, owner TEXT NOT NULL, source TEXT NOT NULL, path TEXT NOT NULL,
|
|
60
|
+
at INTEGER NOT NULL, digest TEXT NOT NULL, content BLOB NOT NULL
|
|
61
|
+
);
|
|
62
|
+
CREATE INDEX IF NOT EXISTS memo_versions_file ON memo_versions (owner, source, path, id);
|
|
63
|
+
|
|
46
64
|
CREATE TABLE IF NOT EXISTS conversations (
|
|
47
65
|
key TEXT PRIMARY KEY,
|
|
48
66
|
data TEXT NOT NULL
|
|
@@ -126,11 +126,12 @@ export function contextBlock(
|
|
|
126
126
|
expert: { prompt: PromptExpert; cwd: string } | undefined,
|
|
127
127
|
memory: string | undefined,
|
|
128
128
|
skills: string[] = [],
|
|
129
|
+
memoPrompt?: string,
|
|
129
130
|
): string {
|
|
130
131
|
const head = expert
|
|
131
132
|
? [...persona(expert.prompt), "", "## 你能做什么(agent-loft 按这个专家的配置生成)", "", ...capabilityLines(expert.prompt, searchLabel("codex", expert.prompt), expert.cwd)]
|
|
132
133
|
: [];
|
|
133
|
-
const sections = [head, RICH_REPLY_LINES, memory ? [memory] : [], skills].filter((s) => s.length > 0);
|
|
134
|
+
const sections = [head, RICH_REPLY_LINES, memory ? [memory] : [], skills, memoPrompt ? [memoPrompt] : []].filter((s) => s.length > 0);
|
|
134
135
|
return wrapContext(sections.flatMap((s, i) => (i ? ["", ...s] : s)));
|
|
135
136
|
}
|
|
136
137
|
|
package/src/core/hub.ts
CHANGED
|
@@ -37,6 +37,8 @@ import {
|
|
|
37
37
|
} from "./store.js";
|
|
38
38
|
import { formatDateTime } from "./task-schedule.js";
|
|
39
39
|
import { attachmentInfo, ensureUploadsDir, KIND_LABEL } from "./uploads.js";
|
|
40
|
+
import { memoAccessEvents, memoSources, hasWritableMemo } from "./memo-sources.js";
|
|
41
|
+
import { MEMO_WRITING_GUIDE } from "../mcp/memo-tools.js";
|
|
40
42
|
import { memoryOwnerOf, sessionMemory } from "./personal.js";
|
|
41
43
|
import { engineSupports, exceedsPermission, forEngine, minPermission, PERMISSION_LABEL, permissionCapOfAccess, permissionOfSandbox, type PermissionLevel } from "./permission.js";
|
|
42
44
|
import { readMemory } from "./memory.js";
|
|
@@ -372,6 +374,7 @@ class Hub extends EventEmitter<{
|
|
|
372
374
|
}
|
|
373
375
|
});
|
|
374
376
|
// 技能装了、改了、停用了、变量改了:受影响的人空闲的会话换上新的
|
|
377
|
+
memoAccessEvents.on("changed", owner => this.personalChanged(new Set([owner])));
|
|
375
378
|
skillEvents.on("changed", (users) => this.personalChanged(new Set(users)));
|
|
376
379
|
// 专家修改只影响自定义专家;MCP 和内置默认配置修改也更新该账号的内置会话。
|
|
377
380
|
expertEvents.on("changed", (_owner, id) => {
|
|
@@ -835,6 +838,7 @@ class Hub extends EventEmitter<{
|
|
|
835
838
|
...(taskOwner && getUser(taskOwner)?.role !== "admin" ? { noSessionGrant: true } : {}),
|
|
836
839
|
...(expert ? { expert } : {}),
|
|
837
840
|
...(memory ? { memory } : {}),
|
|
841
|
+
...(taskOwner && hasWritableMemo(memoSources(taskOwner)) ? { memoPrompt: MEMO_WRITING_GUIDE } : {}),
|
|
838
842
|
...(taskOwner ? { tasks: { userId: taskOwner, convKey: key } } : {}),
|
|
839
843
|
...(skills ? { skills } : {}),
|
|
840
844
|
...(builtin.builtinMcp ? { builtinMcp: builtin.builtinMcp } : {}),
|
package/src/core/mcp.ts
CHANGED
|
@@ -23,7 +23,7 @@ import path from "node:path";
|
|
|
23
23
|
import { EventEmitter } from "node:events";
|
|
24
24
|
import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
25
25
|
import { MEMORY_MCP_NAME } from "./memory-mcp.js";
|
|
26
|
-
import { SKILLS_MCP_NAME, TASKS_MCP_NAME } from "./tasks-mcp.js";
|
|
26
|
+
import { MEMOS_MCP_NAME, SKILLS_MCP_NAME, TASKS_MCP_NAME } from "./tasks-mcp.js";
|
|
27
27
|
import { getUser, listUsers } from "./users.js";
|
|
28
28
|
|
|
29
29
|
export type McpPair = { name: string; value: string; secret: boolean };
|
|
@@ -57,7 +57,7 @@ export type McpSpec =
|
|
|
57
57
|
|
|
58
58
|
export const MCP_NAME = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
59
59
|
const PAIR_NAME = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
60
|
-
const RESERVED = new Set([MEMORY_MCP_NAME, TASKS_MCP_NAME, SKILLS_MCP_NAME]);
|
|
60
|
+
const RESERVED = new Set([MEMORY_MCP_NAME, TASKS_MCP_NAME, SKILLS_MCP_NAME, MEMOS_MCP_NAME]);
|
|
61
61
|
export const MACHINE_PREFIX = "machine:";
|
|
62
62
|
|
|
63
63
|
export const MCP_LIMITS = { perUser: 50, description: 500, command: 1000, args: 50, arg: 2000, pairs: 30, value: 4000, url: 2000 };
|