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
package/src/core/upgrade.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { readRelease, releaseStore, stageRelease } from "./upgrade-releases.js";
|
|
9
10
|
import { config, saveConfig } from "./config.js";
|
|
10
11
|
|
|
11
12
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
@@ -32,17 +33,23 @@ function npmEnv(): NodeJS.ProcessEnv {
|
|
|
32
33
|
function run(cmd: string, args: string[], timeoutMs: number): Promise<{ code: number; out: string }> {
|
|
33
34
|
return new Promise((resolve) => {
|
|
34
35
|
let out = "";
|
|
36
|
+
const npmCli = path.join(path.dirname(process.execPath), "node_modules/npm/bin/npm-cli.js");
|
|
37
|
+
if (process.platform === "win32" && cmd === npmBin() && fs.existsSync(npmCli)) {
|
|
38
|
+
args = [npmCli, ...args];
|
|
39
|
+
cmd = process.execPath;
|
|
40
|
+
}
|
|
35
41
|
const child = spawn(cmd, args, { env: npmEnv(), stdio: ["ignore", "pipe", "pipe"] });
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
child.
|
|
42
|
+
let timedOut = false;
|
|
43
|
+
const timer = setTimeout(() => { timedOut = true; child.kill("SIGKILL"); }, timeoutMs);
|
|
44
|
+
child.stdout.on("data", (d) => (out = (out + d).slice(-8000)));
|
|
45
|
+
child.stderr.on("data", (d) => (out = (out + d).slice(-8000)));
|
|
39
46
|
child.on("error", (err) => {
|
|
40
47
|
clearTimeout(timer);
|
|
41
48
|
resolve({ code: -1, out: err.message });
|
|
42
49
|
});
|
|
43
50
|
child.on("close", (code) => {
|
|
44
51
|
clearTimeout(timer);
|
|
45
|
-
resolve({ code: code ?? -1, out: out.trim() });
|
|
52
|
+
resolve({ code: code ?? -1, out: timedOut ? `操作超时(${timeoutMs / 1000} 秒)。${out.trim()}` : out.trim() });
|
|
46
53
|
});
|
|
47
54
|
});
|
|
48
55
|
}
|
|
@@ -68,7 +75,7 @@ function globalPrefix(): string | null {
|
|
|
68
75
|
return null;
|
|
69
76
|
}
|
|
70
77
|
};
|
|
71
|
-
const self = real(root);
|
|
78
|
+
const self = real(path.dirname(releaseStore(root)));
|
|
72
79
|
if (!self || path.basename(path.dirname(self)) !== "node_modules") return null;
|
|
73
80
|
if (process.platform === "win32") {
|
|
74
81
|
const prefix = path.dirname(path.dirname(self));
|
|
@@ -118,9 +125,22 @@ export type VersionInfo = {
|
|
|
118
125
|
/** 不能在线升级时说明原因和手动办法 */
|
|
119
126
|
reason?: string;
|
|
120
127
|
upgrading: boolean;
|
|
128
|
+
pendingVersion?: string;
|
|
129
|
+
upgradeError?: string;
|
|
121
130
|
};
|
|
122
131
|
|
|
123
132
|
let upgrading = false;
|
|
133
|
+
let installError: string | undefined;
|
|
134
|
+
|
|
135
|
+
// npm 安装可能比反向代理的请求时限更长,设置页用短请求读取进度。
|
|
136
|
+
export function upgradeStatus() {
|
|
137
|
+
return { version: RUNNING_VERSION, upgrading, pendingVersion: readRelease(releaseStore(root), "pending")?.version, error: installError };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function beginUpgrade(): void {
|
|
141
|
+
if (upgrading) return;
|
|
142
|
+
void upgrade().catch(err => console.error("[升级]", err.message));
|
|
143
|
+
}
|
|
124
144
|
|
|
125
145
|
export async function versionInfo(refresh = false): Promise<VersionInfo> {
|
|
126
146
|
const [kind, latest] = await Promise.all([installKind(), latestVersion(refresh)]);
|
|
@@ -131,7 +151,16 @@ export async function versionInfo(refresh = false): Promise<VersionInfo> {
|
|
|
131
151
|
: kind === "unknown"
|
|
132
152
|
? "不是用 npm install -g 装的,没法在线升级"
|
|
133
153
|
: undefined;
|
|
154
|
+
const store = releaseStore(root);
|
|
155
|
+
const pending = readRelease(store, "pending");
|
|
156
|
+
let upgradeError: string | undefined;
|
|
157
|
+
try {
|
|
158
|
+
upgradeError = fs.readFileSync(path.join(store, "last-error"), "utf8");
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if ((err as NodeJS.ErrnoException).code !== "ENOENT") throw err;
|
|
161
|
+
}
|
|
134
162
|
return {
|
|
163
|
+
pendingVersion: pending?.version, upgradeError,
|
|
135
164
|
version: RUNNING_VERSION,
|
|
136
165
|
latest: latest.version,
|
|
137
166
|
...(latest.error ? { latestError: latest.error } : {}),
|
|
@@ -150,25 +179,32 @@ export async function versionInfo(refresh = false): Promise<VersionInfo> {
|
|
|
150
179
|
*/
|
|
151
180
|
export async function upgrade(): Promise<{ from: string; to: string; restarting: boolean; output: string }> {
|
|
152
181
|
if (upgrading) throw new Error("正在升级,稍等");
|
|
153
|
-
const info = await versionInfo(true);
|
|
154
|
-
if (!info.canUpgrade) throw new Error(info.reason ?? "没法在线升级");
|
|
155
|
-
if (!info.latest) throw new Error(`查不到最新版本:${info.latestError ?? ""}`);
|
|
156
|
-
if (!info.updateAvailable) throw new Error(`已经是最新版本 ${RUNNING_VERSION}`);
|
|
157
182
|
upgrading = true;
|
|
183
|
+
installError = undefined;
|
|
158
184
|
try {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
185
|
+
const info = await versionInfo(true);
|
|
186
|
+
if (!info.canUpgrade) throw new Error(info.reason ?? "没法在线升级");
|
|
187
|
+
if (info.pendingVersion) throw new Error("已有更新等待重启验证");
|
|
188
|
+
if (!info.latest) throw new Error(`查不到最新版本:${info.latestError ?? ""}`);
|
|
189
|
+
if (!info.updateAvailable) throw new Error(`已经是最新版本 ${RUNNING_VERSION}`);
|
|
190
|
+
const version = info.latest;
|
|
191
|
+
const output = await stageRelease(root, version, async (prefix) => {
|
|
192
|
+
const r = await run(npmBin(), ["install", "-g", "--prefix", prefix, `${NAME}@${version}`, "--no-audit", "--no-fund"], 10 * 60_000);
|
|
193
|
+
if (r.code !== 0) throw new Error(`npm install 失败:${r.out || `退出码 ${r.code}`}`);
|
|
194
|
+
return r.out;
|
|
195
|
+
}, async (cli) => {
|
|
196
|
+
const r = await run(process.execPath, [cli, "--help"], 15_000);
|
|
197
|
+
if (r.code !== 0) throw new Error(`新版 CLI 无法启动:${r.out || r.code}`);
|
|
198
|
+
});
|
|
166
199
|
const restarting = !!info.service;
|
|
167
200
|
if (restarting) {
|
|
168
|
-
console.log(`[升级]
|
|
201
|
+
console.log(`[升级] 已准备 ${version},重启后验证`);
|
|
169
202
|
setTimeout(() => process.exit(0), 1500).unref();
|
|
170
203
|
}
|
|
171
|
-
return { from: RUNNING_VERSION, to:
|
|
204
|
+
return { from: RUNNING_VERSION, to: version, restarting, output: output.slice(-2000) };
|
|
205
|
+
} catch (err) {
|
|
206
|
+
installError = err instanceof Error ? err.message : String(err);
|
|
207
|
+
throw err;
|
|
172
208
|
} finally {
|
|
173
209
|
upgrading = false;
|
|
174
210
|
}
|
package/src/main.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { RUNNING_VERSION } from "./core/upgrade.js";
|
|
2
|
+
import { verifyUpgradeWeb } from "./core/upgrade-health.js";
|
|
3
|
+
import { startMemoIndexer, stopMemoIndexer } from "./core/memo-index.js";
|
|
1
4
|
// 入口:拉起 agent 驱动、飞书机器人和 Web 服务。
|
|
2
5
|
import { config, loadConfig, onConfigChange } from "./core/config.js";
|
|
3
6
|
import { hub } from "./core/hub.js";
|
|
@@ -102,6 +105,7 @@ async function main(): Promise<void> {
|
|
|
102
105
|
});
|
|
103
106
|
// 定时任务:agent 用的工具通道先开,再开始按点运行(停机期间错过的补跑)
|
|
104
107
|
startTasksBridge();
|
|
108
|
+
startMemoIndexer();
|
|
105
109
|
startTaskRunner();
|
|
106
110
|
// 先查一遍 agent 装没装、登没登录,网页打开时新对话里就只列出能用的
|
|
107
111
|
void agentHealth().catch(() => {});
|
|
@@ -123,6 +127,7 @@ async function main(): Promise<void> {
|
|
|
123
127
|
console.log(`[退出] 收到 ${signal},正在收尾…`);
|
|
124
128
|
const force = setTimeout(() => process.exit(0), 8000);
|
|
125
129
|
force.unref();
|
|
130
|
+
stopMemoIndexer();
|
|
126
131
|
stopScheduler();
|
|
127
132
|
stopFeishu();
|
|
128
133
|
stopWeixin();
|
|
@@ -138,6 +143,15 @@ async function main(): Promise<void> {
|
|
|
138
143
|
process.on("SIGINT", () => void shutdown("SIGINT"));
|
|
139
144
|
process.on("exit", (code) => console.log(`[退出] agent-loft 结束,退出码 ${code}`));
|
|
140
145
|
process.on("unhandledRejection", (err) => console.error("[未处理的异常]", err));
|
|
146
|
+
if (process.env.AGENT_LOFT_UPGRADE_TRIAL && process.send) {
|
|
147
|
+
const { host, port } = config().web;
|
|
148
|
+
try {
|
|
149
|
+
await verifyUpgradeWeb(host, port);
|
|
150
|
+
process.send({ type: "upgrade-health", version: RUNNING_VERSION });
|
|
151
|
+
} catch (err) {
|
|
152
|
+
process.send({ type: "upgrade-health", error: String(err) });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
141
155
|
}
|
|
142
156
|
|
|
143
157
|
void main();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const writeIntent = "只有用户表达了留存或更新笔记的意图时才写入备忘录。";
|
|
2
|
+
export const MEMO_WRITING_GUIDE = writeIntent +
|
|
3
|
+
"「这个留着下次用」「加到清单里」都算。普通聊天、问答或任务自然结束时,无需主动归档。" +
|
|
4
|
+
"用 agent_loft_memos 自行选择合适的已授权读写库,搜索相关笔记,先读取再更新。已有相同内容就跳过,没有合适的笔记就沿用目录和命名习惯新建 Markdown。" +
|
|
5
|
+
"根据对话拟标题、提炼正文,保存成功后告诉用户库名和文件路径。";
|
|
6
|
+
|
|
7
|
+
const fields = {
|
|
8
|
+
source: "笔记库 ID,从 list_memo_sources 获取", path: "库内相对文件路径", folder: "库内目录,默认根目录",
|
|
9
|
+
cursor: "上一页返回的分页标记", query: "文件名、路径或正文关键词", version: "read_memo 返回的最新版本",
|
|
10
|
+
text: "要新建、追加或替换成的文本", original: "要替换的唯一原文(精确匹配)",
|
|
11
|
+
};
|
|
12
|
+
type Field = keyof typeof fields;
|
|
13
|
+
function tool(name: string, description: string, required: Field[], optional: Field[] = [], write = false) {
|
|
14
|
+
const properties = Object.fromEntries([...required, ...optional].map(f => [f, { type: "string", description: fields[f] }]));
|
|
15
|
+
return { name, description: write ? writeIntent + description : description, inputSchema: { type: "object", properties, required, additionalProperties: false },
|
|
16
|
+
annotations: { readOnlyHint: !write, openWorldHint: true } };
|
|
17
|
+
}
|
|
18
|
+
export const MEMO_TOOLS = [
|
|
19
|
+
tool("list_memo_sources", "用户想留下笔记、清单或排障经验时,用此工具找到合适的读写库,再搜索、更新或新建笔记。库名、文件名和正文可以由你根据对话确定。", []),
|
|
20
|
+
tool("list_memo_files", "浏览笔记库中的一层目录。", ["source"], ["folder", "cursor"]),
|
|
21
|
+
tool("search_memos", "在授权笔记库的全文索引里搜索文件名和正文,返回路径和片段。success 为零表示首次索引未完成。", ["query"], ["source", "folder"]),
|
|
22
|
+
tool("read_memo", "从远端读取备忘录的最新正文和版本号。", ["source", "path"]),
|
|
23
|
+
tool("create_memo", "在已有目录中新建文本备忘录,同名文件会返回冲突。", ["source", "path", "text"], [], true),
|
|
24
|
+
tool("append_memo", "追加文本(自行包含所需换行)。先读取最新版本。", ["source", "path", "version", "text"], [], true),
|
|
25
|
+
tool("edit_memo", "精确替换一处唯一原文,先读取笔记。遇到版本冲突请重新读取并核对修改。", ["source", "path", "version", "original", "text"], [], true),
|
|
26
|
+
];
|
package/src/mcp/tasks-server.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MEMO_TOOLS } from "./memo-tools.js";
|
|
1
2
|
// 定时任务工具的 MCP 服务(stdio):给 agent 用的 list / create / update / delete。
|
|
2
3
|
// 环境变量 AGENT_LOFT_TOOLSET=skills 时换成技能工具(list / get / create / update_skill),走同一条通道。
|
|
3
4
|
//
|
|
@@ -227,8 +228,8 @@ const SKILL_TOOLS = [
|
|
|
227
228
|
},
|
|
228
229
|
];
|
|
229
230
|
|
|
230
|
-
const
|
|
231
|
-
const ACTIVE =
|
|
231
|
+
const toolset = process.env.AGENT_LOFT_TOOLSET;
|
|
232
|
+
const ACTIVE = toolset === "memos" ? MEMO_TOOLS : toolset === "skills" ? SKILL_TOOLS : TOOLS;
|
|
232
233
|
|
|
233
234
|
function text(t: string, isError = false) {
|
|
234
235
|
return { content: [{ type: "text", text: t }], ...(isError ? { isError: true } : {}) };
|
|
@@ -238,7 +239,7 @@ function text(t: string, isError = false) {
|
|
|
238
239
|
function forward(tool: string, args: Record<string, unknown>): Promise<{ text: string; isError?: boolean }> {
|
|
239
240
|
return new Promise((resolve) => {
|
|
240
241
|
if (!socketPath || !caller.user || !caller.conv) {
|
|
241
|
-
resolve({ text:
|
|
242
|
+
resolve({ text: `内置工具没有正确配置(缺少用户或对话)。`, isError: true });
|
|
242
243
|
return;
|
|
243
244
|
}
|
|
244
245
|
const sock = net.createConnection(socketPath);
|
|
@@ -274,7 +275,7 @@ async function handle(req: Request): Promise<unknown> {
|
|
|
274
275
|
return {
|
|
275
276
|
protocolVersion: typeof req.params?.protocolVersion === "string" ? req.params.protocolVersion : "2025-06-18",
|
|
276
277
|
capabilities: { tools: {} },
|
|
277
|
-
serverInfo: { name:
|
|
278
|
+
serverInfo: { name: `agent-loft-${toolset ?? "tasks"}`, version: "1.0.0" },
|
|
278
279
|
};
|
|
279
280
|
case "ping":
|
|
280
281
|
return {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
.main .messages-inner:has(> .memo-page) { max-width: none; height: 100%; padding-inline: 12px; padding-bottom: 12px; }
|
|
2
|
+
.memo-page { flex: 1; min-height: 0; display: grid; grid-template-columns: clamp(170px, 23%, 280px) minmax(0,1fr); overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); }
|
|
3
|
+
.memo-page.no-source { grid-template-columns: 1fr; }
|
|
4
|
+
.memo-side, .memo-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
|
|
5
|
+
.memo-side { background: var(--bg-side); border-right: 1px solid var(--border); }
|
|
6
|
+
.memo-sources, .memo-tree-tools, .memo-bar, .memo-blankbar { display: flex; align-items: center; gap: 6px; padding: 8px; }
|
|
7
|
+
.memo-sources .input { flex: 1; min-width: 0; }
|
|
8
|
+
.memo-side .icon-btn { width: 30px; height: 30px; flex-shrink: 0; }
|
|
9
|
+
.memo-tree { overflow: auto; flex: 1; padding: 0 6px 12px; }
|
|
10
|
+
.memo-tree .memo-branch { margin-left: 10px; padding-left: 3px; border-left: 1px solid var(--border); }
|
|
11
|
+
.memo-tree small { color: var(--fg-soft); padding: 4px 8px; }
|
|
12
|
+
.memo-row { display: flex; align-items: center; gap: 6px; text-align: left; padding: 5px 7px; width: 100%; border-radius: 6px; line-height: 1.45; }
|
|
13
|
+
.memo-row span, .memo-path { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
14
|
+
.memo-row svg, .memo-empty > svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--fg-soft); }
|
|
15
|
+
.memo-row:hover { background: var(--bg-hover); }
|
|
16
|
+
.memo-row.selected { background: var(--bg-hover); font-weight: 600; }
|
|
17
|
+
.memo-row[aria-expanded]::before { content: "›"; width: 8px; color: var(--fg-soft); }
|
|
18
|
+
.memo-row[aria-expanded=true]::before { transform: rotate(90deg); }
|
|
19
|
+
.memo-bar { min-height: 48px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
|
|
20
|
+
.memo-path { flex: 1; min-width: 60px; font-size: 14px; }
|
|
21
|
+
.memo-status { color: var(--fg-soft); font-size: 12px; }
|
|
22
|
+
.memo-editor, .memo-reading { flex: 1; min-height: 0; overflow: auto; }
|
|
23
|
+
.memo-editor .cm-editor { height: 100%; background: var(--bg); }
|
|
24
|
+
.memo-editor .cm-content { padding: 14px 8px 40px; }
|
|
25
|
+
.memo-editor .cm-scroller { font-family: var(--mono); }
|
|
26
|
+
.memo-reading { padding: 18px clamp(14px, 4%, 56px); overflow-wrap: anywhere; }
|
|
27
|
+
.memo-reading .md { max-width: 85ch; margin-inline: auto; }
|
|
28
|
+
.memo-reading pre { white-space: pre-wrap; }
|
|
29
|
+
.memo-reading img { max-width: 100%; height: auto; }
|
|
30
|
+
.memo-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 18px; text-align: center; }
|
|
31
|
+
.memo-empty > svg { width: 32px; height: 32px; }
|
|
32
|
+
.memo-empty h2, .memo-empty p { margin: 0; }
|
|
33
|
+
.memo-empty p { color: var(--fg-soft); }
|
|
34
|
+
.memo-fields, .memo-fields label { display: flex; flex-direction: column; gap: 5px; }
|
|
35
|
+
.memo-fields { gap: 12px; }
|
|
36
|
+
.memo-fields label { font-size: 13px; }
|
|
37
|
+
.memo-fields .input { width: 100%; }
|
|
38
|
+
.memo-fields .btn { align-self: flex-end; }
|
|
39
|
+
.memo-error { color: var(--danger); }
|
|
40
|
+
.memo-page [hidden], .memo-fields[hidden], .memo-blankbar, .memo-bar > button:first-child, .memo-return { display: none; }
|
|
41
|
+
@media (max-width: 768px) {
|
|
42
|
+
.main .messages-inner:has(> .memo-page) { padding-inline: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
|
|
43
|
+
.memo-page { display: flex; flex-direction: column; }
|
|
44
|
+
.memo-side, .memo-pane { flex: 1; }
|
|
45
|
+
.memo-side { display: none; border-right: none; }
|
|
46
|
+
.memo-page.show-tree .memo-side:not([hidden]), .memo-blankbar, .memo-bar > button:first-child, .memo-page.has-file .memo-return { display: flex; }
|
|
47
|
+
.memo-page.show-tree:not(.no-source) .memo-pane { display: none; }
|
|
48
|
+
.memo-fields input, .memo-editor { font-size: 16px; }
|
|
49
|
+
}
|
|
50
|
+
.memo-snapshot { min-height: 5rem; max-height: 45vh; overflow: auto; margin: 0; padding: 12px; background: var(--bg-soft); white-space: pre-wrap; overflow-wrap: anywhere; }
|
package/web/css/sidebar.css
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
padding-top: env(safe-area-inset-top);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/*
|
|
22
|
+
/* 侧栏右边缘的拖动热区 */
|
|
23
23
|
.side-resizer {
|
|
24
24
|
position: absolute;
|
|
25
25
|
top: 0;
|
|
@@ -31,24 +31,6 @@
|
|
|
31
31
|
touch-action: none;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
.side-resizer::after {
|
|
35
|
-
content: "";
|
|
36
|
-
position: absolute;
|
|
37
|
-
top: 0;
|
|
38
|
-
bottom: 0;
|
|
39
|
-
left: 3px;
|
|
40
|
-
width: 2px;
|
|
41
|
-
background: var(--accent);
|
|
42
|
-
opacity: 0;
|
|
43
|
-
transition: opacity 0.15s;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.side-resizer:hover::after,
|
|
47
|
-
.side-resizing .side-resizer::after {
|
|
48
|
-
opacity: 0.6;
|
|
49
|
-
transition-delay: 0.1s;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
34
|
body.side-resizing {
|
|
53
35
|
cursor: col-resize;
|
|
54
36
|
user-select: none;
|
package/web/index.html
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
<link rel="stylesheet" href="/css/todos.css" />
|
|
31
31
|
<link rel="stylesheet" href="/css/tasks.css" />
|
|
32
32
|
<link rel="stylesheet" href="/css/library.css" />
|
|
33
|
+
<link rel="stylesheet" href="/css/memos.css" />
|
|
33
34
|
<link rel="stylesheet" href="/css/skills.css" />
|
|
34
35
|
<link rel="stylesheet" href="/css/experts.css" />
|
|
35
36
|
<link rel="stylesheet" href="/css/terminal.css" />
|
package/web/lib/api.js
CHANGED
|
@@ -5,7 +5,8 @@ export async function api(path, opts = {}) {
|
|
|
5
5
|
method: opts.method ?? "GET",
|
|
6
6
|
credentials: "same-origin",
|
|
7
7
|
keepalive: opts.keepalive ?? false,
|
|
8
|
-
|
|
8
|
+
signal: opts.signal,
|
|
9
|
+
headers: opts.body !== undefined && !(opts.body instanceof Blob) ? { "Content-Type": "application/json", ...opts.headers } : opts.headers,
|
|
9
10
|
body: opts.body === undefined ? undefined : opts.body instanceof Blob ? opts.body : JSON.stringify(opts.body),
|
|
10
11
|
});
|
|
11
12
|
let data = null;
|
|
@@ -16,7 +17,7 @@ export async function api(path, opts = {}) {
|
|
|
16
17
|
}
|
|
17
18
|
if (res.status === 401 && !path.startsWith("/api/me") && !path.startsWith("/api/login")) {
|
|
18
19
|
showAuth();
|
|
19
|
-
throw new Error("请先登录");
|
|
20
|
+
throw Object.assign(new Error("请先登录"), { status: 401 });
|
|
20
21
|
}
|
|
21
22
|
if (!res.ok) {
|
|
22
23
|
const err = new Error(data?.error ?? `请求失败(${res.status})`);
|
package/web/lib/markdown.js
CHANGED
|
@@ -21,7 +21,7 @@ export function renderMarkdown(text, opts) {
|
|
|
21
21
|
* enhance(box, { final }):每块画好后再加工一下(比如把文件路径变成链接、完整相册块变成网格)。
|
|
22
22
|
* 按块拼起来和整段解析的结果一样(marked 的 parser 本来就是逐块拼接的)。
|
|
23
23
|
*/
|
|
24
|
-
export function patchMarkdown(div, text, { live = false, enhance } = {}) {
|
|
24
|
+
export function patchMarkdown(div, text, { live = false, enhance, prepare, sanitizeOptions } = {}) {
|
|
25
25
|
const tokens = marked.lexer(text ?? "");
|
|
26
26
|
const links = JSON.stringify(tokens.links ?? {});
|
|
27
27
|
// 引用式链接的定义可能在后面才出现(流式输出时地址还会一点点变长),会影响前面的块:定义变了就整个重画
|
|
@@ -53,7 +53,14 @@ export function patchMarkdown(div, text, { live = false, enhance } = {}) {
|
|
|
53
53
|
chunk.links = tokens.links;
|
|
54
54
|
// 在本页的元素里解析(DOMPurify 直接返回的节点属于另一个 document,搬过来后 IntersectionObserver 就不灵了)
|
|
55
55
|
const box = document.createElement("div");
|
|
56
|
-
|
|
56
|
+
const html = DOMPurify.sanitize(marked.parser(chunk), sanitizeOptions ?? { ADD_ATTR: ["target"] });
|
|
57
|
+
if (prepare) {
|
|
58
|
+
// Resolve vault links while the document is inert, before the browser fetches images.
|
|
59
|
+
const template = document.createElement("template");
|
|
60
|
+
template.innerHTML = html;
|
|
61
|
+
prepare(template.content);
|
|
62
|
+
box.append(template.content);
|
|
63
|
+
} else box.innerHTML = html;
|
|
57
64
|
decorate(box, final);
|
|
58
65
|
enhance?.(box, { final });
|
|
59
66
|
const nodes = [...box.childNodes];
|
package/web/settings/users.js
CHANGED
|
@@ -348,28 +348,26 @@ export async function systemTab(cfg, page) {
|
|
|
348
348
|
const render = () => {
|
|
349
349
|
const recheck = h("button", { class: "btn small", disabled: checking }, checking ? "检查中…" : "检查更新");
|
|
350
350
|
recheck.onclick = () => void checkVersion(true);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const upgradeBtn = v?.updateAvailable && v.canUpgrade && !checking ? h("button", { class: "btn small primary" }, `升级到 ${v.latest}`) : null;
|
|
351
|
+
let status = null;
|
|
352
|
+
if (checking) status = h("span", { class: "status-tag" }, "正在检查更新…");
|
|
353
|
+
else if (v?.upgrading) status = h("span", { class: "status-tag" }, "正在下载并检查新版…");
|
|
354
|
+
else if (v?.pendingVersion) {
|
|
355
|
+
const state = v.version === v.pendingVersion ? "正在验证" : "等待重启验证";
|
|
356
|
+
status = h("span", { class: "status-tag" }, `${v.pendingVersion} ${state}`);
|
|
357
|
+
} else if (v?.updateAvailable) status = h("span", { class: "status-tag ok" }, `有新版本 ${v.latest}`);
|
|
358
|
+
else if (v?.latest) status = h("span", { class: "status-tag" }, "已是最新版本");
|
|
359
|
+
else if (v) status = h("span", { class: "status-tag bad", title: v.latestError ?? "" }, "查不到最新版本");
|
|
360
|
+
const upgradeBtn = v?.updateAvailable && v.canUpgrade && !v.upgrading && !v.pendingVersion && !checking ? h("button", { class: "btn small primary" }, `升级到 ${v.latest}`) : null;
|
|
361
361
|
if (upgradeBtn) {
|
|
362
362
|
upgradeBtn.onclick = async () => {
|
|
363
363
|
upgradeBtn.disabled = true;
|
|
364
364
|
upgradeBtn.textContent = "正在升级…";
|
|
365
365
|
try {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
void checkVersion(false);
|
|
366
|
+
await api("/api/server/upgrade?background=1", { method: "POST" });
|
|
367
|
+
await followUpgrade(v.latest);
|
|
369
368
|
} catch (err) {
|
|
370
369
|
toast(`升级失败:${err.message}`, 6000);
|
|
371
|
-
|
|
372
|
-
upgradeBtn.textContent = `升级到 ${v.latest}`;
|
|
370
|
+
void checkVersion(false);
|
|
373
371
|
}
|
|
374
372
|
};
|
|
375
373
|
}
|
|
@@ -378,6 +376,7 @@ export async function systemTab(cfg, page) {
|
|
|
378
376
|
h("h4", {}, "服务端"),
|
|
379
377
|
h("div", { class: "row" }, h("b", {}, `agent-loft ${v?.version ?? sys.version}`), status),
|
|
380
378
|
h("div", { class: "muted" }, `Node ${sys.node} · 已运行 ${uptime(sys.uptimeMs)} · ${sys.underSystemd ? "以系统服务运行" : "前台运行(重启需要在终端里操作)"}`),
|
|
379
|
+
v?.upgradeError && !v.pendingVersion ? h("div", { class: "muted" }, v.upgradeError) : null,
|
|
381
380
|
v && !checking && !v.latest && v.latestError ? h("div", { class: "muted" }, v.latestError) : null,
|
|
382
381
|
v?.updateAvailable && !v.canUpgrade && v.reason ? h("div", { class: "muted" }, v.reason) : null,
|
|
383
382
|
v?.updateAvailable && v.canUpgrade && !v.service ? h("div", { class: "muted" }, "agent-loft 是在前台手动运行的,升级后要自己重启一下。") : null,
|
|
@@ -404,6 +403,32 @@ export async function systemTab(cfg, page) {
|
|
|
404
403
|
checking = false;
|
|
405
404
|
if (sys) render();
|
|
406
405
|
};
|
|
406
|
+
async function followUpgrade(target) {
|
|
407
|
+
let disconnectedAt = 0;
|
|
408
|
+
while (sysBox.isConnected) {
|
|
409
|
+
let progress;
|
|
410
|
+
try {
|
|
411
|
+
progress = await api("/api/server/upgrade");
|
|
412
|
+
disconnectedAt = 0;
|
|
413
|
+
} catch (err) {
|
|
414
|
+
if (err.status && err.status < 500) throw err;
|
|
415
|
+
// 服务重启时反向代理可能短暂返回 502,继续等新进程报告结果。
|
|
416
|
+
disconnectedAt ||= Date.now();
|
|
417
|
+
if (Date.now() - disconnectedAt > 150_000) {
|
|
418
|
+
toast("暂时连不上服务,恢复连接后可在设置里查看升级结果", 6000);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (progress?.error) throw new Error(progress.error);
|
|
423
|
+
if (progress && !progress.upgrading && (!progress.pendingVersion || !v?.service)) {
|
|
424
|
+
if (progress.pendingVersion) toast("新版已准备好,重启 agent-loft 后验证并启用", 6000);
|
|
425
|
+
else if (progress.version === target) toast(`已验证并启用 ${target}`, 6000);
|
|
426
|
+
await checkVersion(false);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
407
432
|
const versionDone = checkVersion(false);
|
|
408
433
|
try {
|
|
409
434
|
sys = await api("/api/system");
|
|
@@ -413,6 +438,7 @@ export async function systemTab(cfg, page) {
|
|
|
413
438
|
}
|
|
414
439
|
render();
|
|
415
440
|
await versionDone;
|
|
441
|
+
if (v?.upgrading || (v?.pendingVersion && v.service)) void followUpgrade(v.pendingVersion || v.latest).catch(err => { toast(err.message); void checkVersion(false); });
|
|
416
442
|
}
|
|
417
443
|
|
|
418
444
|
/** 运行了多久:分钟 / 小时 / 天 */
|