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/web/views/file-editor.js
CHANGED
|
@@ -88,20 +88,21 @@ function languageFor(name, CM) {
|
|
|
88
88
|
* 在 parent 里建一个编辑器。onChange:内容变了;onSave:按了 Ctrl / ⌘ + S。
|
|
89
89
|
* 返回 { text, setText, focus, measure, destroy };text() 给的是还原了换行符、可以直接存的内容
|
|
90
90
|
*/
|
|
91
|
-
export async function createEditor({ parent, text, name, onChange, onSave }) {
|
|
91
|
+
export async function createEditor({ parent, text, name, onChange, onSave, collaboration }) {
|
|
92
92
|
const CM = await loadCodeMirror();
|
|
93
93
|
const dark = matchMedia("(prefers-color-scheme: dark)");
|
|
94
94
|
const theme = new CM.Compartment();
|
|
95
95
|
const themeOf = () => (dark.matches ? CM.oneDark : []);
|
|
96
|
-
let eol = detectEol(text);
|
|
96
|
+
let eol = collaboration ? (collaboration.crlf ? "crlf" : "mixed") : detectEol(text);
|
|
97
|
+
const editorText = value => collaboration?.crlf ? value.replace(/\r\n/g, "\n") : value;
|
|
97
98
|
const language = languageFor(name, CM);
|
|
98
99
|
// 混用换行符的文件:只认 \n,\r 留在文字里(显示成特殊字符),存回去一字不差
|
|
99
100
|
const separator = new CM.Compartment();
|
|
100
|
-
const separatorOf = () => (eol === "mixed" ? CM.EditorState.lineSeparator.of("\n") : []);
|
|
101
|
+
const separatorOf = () => (collaboration || eol === "mixed" ? CM.EditorState.lineSeparator.of("\n") : []);
|
|
101
102
|
const view = new CM.EditorView({
|
|
102
103
|
parent,
|
|
103
104
|
state: CM.EditorState.create({
|
|
104
|
-
doc: text,
|
|
105
|
+
doc: editorText(text),
|
|
105
106
|
extensions: [
|
|
106
107
|
CM.keymap.of([
|
|
107
108
|
{
|
|
@@ -115,6 +116,7 @@ export async function createEditor({ parent, text, name, onChange, onSave }) {
|
|
|
115
116
|
// Tab 缩进。键盘用户按 Esc 再按 Tab 可以离开编辑器(CodeMirror 自带)
|
|
116
117
|
CM.indentWithTab,
|
|
117
118
|
]),
|
|
119
|
+
...(collaboration ? [CM.collab(collaboration)] : []),
|
|
118
120
|
CM.basicSetup,
|
|
119
121
|
CM.EditorView.lineWrapping,
|
|
120
122
|
theme.of(themeOf()),
|
|
@@ -128,13 +130,43 @@ export async function createEditor({ parent, text, name, onChange, onSave }) {
|
|
|
128
130
|
});
|
|
129
131
|
const onTheme = () => view.dispatch({ effects: theme.reconfigure(themeOf()) });
|
|
130
132
|
dark.addEventListener("change", onTheme);
|
|
133
|
+
let confirmed = view.state.doc;
|
|
131
134
|
return {
|
|
135
|
+
collaboration: collaboration && {
|
|
136
|
+
revision: () => CM.getSyncedVersion(view.state),
|
|
137
|
+
pending: () => CM.sendableUpdates(view.state).length,
|
|
138
|
+
outgoing() {
|
|
139
|
+
const updates = [];
|
|
140
|
+
let size = 0;
|
|
141
|
+
for (const update of CM.sendableUpdates(view.state).slice(0, 128)) {
|
|
142
|
+
const json = update.changes.toJSON();
|
|
143
|
+
const length = JSON.stringify(json).length;
|
|
144
|
+
if (updates.length && size + length > 3_000_000) break;
|
|
145
|
+
size += length;
|
|
146
|
+
updates.push(json);
|
|
147
|
+
}
|
|
148
|
+
return updates;
|
|
149
|
+
},
|
|
150
|
+
receive(packet) {
|
|
151
|
+
const skip = CM.getSyncedVersion(view.state) - packet.from;
|
|
152
|
+
if (skip < 0) throw new Error("缺少协作修改记录");
|
|
153
|
+
if (skip >= packet.updates.length) return false;
|
|
154
|
+
const updates = packet.updates.slice(skip).map(u => ({ clientID: u.clientID, changes: CM.ChangeSet.fromJSON(u.changes) }));
|
|
155
|
+
for (const u of updates) confirmed = u.changes.apply(confirmed);
|
|
156
|
+
view.dispatch(CM.receiveUpdates(view.state, updates));
|
|
157
|
+
return true;
|
|
158
|
+
},
|
|
159
|
+
savedText: () => restoreEol(confirmed.toString(), eol),
|
|
160
|
+
},
|
|
132
161
|
text: () => restoreEol(view.state.doc.toString(), eol),
|
|
133
162
|
setText(next) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
163
|
+
if (!collaboration) {
|
|
164
|
+
eol = detectEol(next);
|
|
165
|
+
view.dispatch({ effects: separator.reconfigure(separatorOf()) });
|
|
166
|
+
}
|
|
167
|
+
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: editorText(next) } });
|
|
137
168
|
},
|
|
169
|
+
insertAtSelection: (text) => view.dispatch(view.state.replaceSelection(text)),
|
|
138
170
|
focus: () => view.focus(),
|
|
139
171
|
/** 编辑器被藏起来再放回来之后要重新量尺寸 */
|
|
140
172
|
measure: () => view.requestMeasure(),
|
package/web/views/layout.js
CHANGED
|
@@ -124,6 +124,10 @@ export function openLibraryView() {
|
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
export function openMemosView() {
|
|
128
|
+
return import("./memos.js").then(m => m.openMemos(), err => toast(`备忘录加载失败:${err.message}`));
|
|
129
|
+
}
|
|
130
|
+
|
|
127
131
|
export async function boot() {
|
|
128
132
|
const me = await api("/api/me");
|
|
129
133
|
if (!me.authed) return showAuth();
|
|
@@ -164,6 +168,7 @@ export async function boot() {
|
|
|
164
168
|
const latest = latestConversation("web");
|
|
165
169
|
if (restoreSettings) void openSettings();
|
|
166
170
|
if (fromHash === "tasks") openTasksView();
|
|
171
|
+
else if (fromHash === "memos") await openMemosView();
|
|
167
172
|
else if (fromHash === "library") openLibraryView();
|
|
168
173
|
else if (fromHash === "new") newDraft({ inheritLatest: true });
|
|
169
174
|
else if (fromHash.startsWith("remote") && remoteTabs().length) {
|
|
@@ -267,7 +272,7 @@ function renderLayout() {
|
|
|
267
272
|
{ class: "side-top" },
|
|
268
273
|
h("button", { class: "btn new-chat", onclick: () => navigate(() => (newDraft({ inheritLatest: true }), closeSide())) }, icon("plus"), "新建"),
|
|
269
274
|
),
|
|
270
|
-
createSidebarNav({ search: () => navigate(openSearch), tasks: () => navigate(openTasksView), library: () => navigate(openLibraryView), remote: () => navigate(openRemoteView), settings: openSettings }),
|
|
275
|
+
createSidebarNav({ search: () => navigate(openSearch), tasks: () => navigate(openTasksView), library: () => navigate(openLibraryView), memos: () => navigate(openMemosView), remote: () => navigate(openRemoteView), settings: openSettings }),
|
|
271
276
|
ui.convList,
|
|
272
277
|
// 底部只有额度:没有额度可显示(关了查询、还没查到)时整块藏起来,连分隔线一起
|
|
273
278
|
(ui.sideBottom = h(
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { h } from "../lib/dom.js";
|
|
2
|
+
import { modal } from "../lib/overlay.js";
|
|
3
|
+
import { api } from "../lib/api.js";
|
|
4
|
+
|
|
5
|
+
function memoAccessField(value = "off") {
|
|
6
|
+
const select = h("select", { class: "input", name: "access", "aria-label": "智能体访问" },
|
|
7
|
+
h("option", { value: "off" }, "关闭"), h("option", { value: "read" }, "只读"), h("option", { value: "write" }, "读写"));
|
|
8
|
+
select.value = value;
|
|
9
|
+
const hint = h("small", {}, "授权后,Agent Loft 会在服务器建立本库的全文索引。");
|
|
10
|
+
const update = () => { hint.hidden = select.value === "off"; };
|
|
11
|
+
select.addEventListener("change", update);
|
|
12
|
+
update();
|
|
13
|
+
return { select, field: h("label", {}, "智能体访问", select, hint) };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function memoAccessSettings(source) {
|
|
17
|
+
const { field, select } = memoAccessField(source.access);
|
|
18
|
+
const status = h("p", { role: "status" });
|
|
19
|
+
const refresh = h("button", { class: "btn", type: "button" }, "立即刷新索引");
|
|
20
|
+
const save = h("button", { class: "btn primary", type: "submit" }, "保存权限");
|
|
21
|
+
const form = h("form", { class: "modal-body memo-fields" }, field, status, refresh, save);
|
|
22
|
+
let timer, sequence = 0;
|
|
23
|
+
const url = action => "/api/memos/" + action + "?" + new URLSearchParams({ source: source.id });
|
|
24
|
+
async function load(method = "GET") {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
const request = ++sequence;
|
|
27
|
+
refresh.hidden = source.access === "off" || !source.access;
|
|
28
|
+
if (refresh.hidden) { status.textContent = ""; return; }
|
|
29
|
+
try {
|
|
30
|
+
const index = await api(url("index"), { method });
|
|
31
|
+
if (!form.isConnected || sequence !== request) return;
|
|
32
|
+
const last = index.success ? "最近成功:" + new Date(index.success).toLocaleString() : "首次索引尚未完成";
|
|
33
|
+
status.textContent = [index.running ? "正在扫描,已检查 " + index.scanned + " 份文本" : "", index.error, last].filter(Boolean).join(" · ");
|
|
34
|
+
refresh.disabled = index.running;
|
|
35
|
+
if (index.running) timer = setTimeout(load, 1500);
|
|
36
|
+
} catch (err) { if (sequence === request) status.textContent = err.message; }
|
|
37
|
+
}
|
|
38
|
+
modal({ title: source.name + " · 智能体访问", body: form, beforeClose: () => { if (save.disabled) return false; clearTimeout(timer); ++sequence; } });
|
|
39
|
+
refresh.onclick = () => void load("POST");
|
|
40
|
+
form.onsubmit = async e => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
save.disabled = true;
|
|
43
|
+
try {
|
|
44
|
+
Object.assign(source, await api(url("access"), { method: "PUT", body: { access: select.value } }));
|
|
45
|
+
await load();
|
|
46
|
+
} catch (err) { status.textContent = err.message; }
|
|
47
|
+
finally { save.disabled = false; }
|
|
48
|
+
};
|
|
49
|
+
void load();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function connectSource(onConnect) {
|
|
53
|
+
const kind = h("select", { class: "input" }, h("option", { value: "webdav" }, "WebDAV"), h("option", { value: "s3" }, "S3 / 兼容存储"));
|
|
54
|
+
const input = (name, placeholder = "", type = "text") => h("input", { class: "input", name, placeholder, type, autocomplete: "off" });
|
|
55
|
+
const name = input("name", "我的笔记"), endpoint = input("endpoint", "https://nas.example.com/dav/Notes/", "url");
|
|
56
|
+
const username = input("username"), secret = input("secret", "", "password");
|
|
57
|
+
const bucket = input("bucket"), region = input("region", "us-east-1"), prefix = input("prefix", "可选,如 Notes");
|
|
58
|
+
const label = (caption, field) => h("label", {}, caption, field);
|
|
59
|
+
const userLabel = h("span"), secretLabel = h("span");
|
|
60
|
+
const s3 = h("div", { class: "memo-fields" }, label("存储桶", bucket), label("区域", region), label("目录前缀", prefix));
|
|
61
|
+
const configure = () => {
|
|
62
|
+
const aws = kind.value === "s3";
|
|
63
|
+
s3.hidden = !aws;
|
|
64
|
+
bucket.required = username.required = secret.required = aws;
|
|
65
|
+
endpoint.required = !aws;
|
|
66
|
+
endpoint.placeholder = aws ? "兼容存储填写端点,AWS 可留空" : "https://nas.example.com/dav/Notes/";
|
|
67
|
+
userLabel.textContent = aws ? "Access Key ID" : "用户名";
|
|
68
|
+
secretLabel.textContent = aws ? "Secret Access Key" : "密码 / 应用专用密码";
|
|
69
|
+
};
|
|
70
|
+
configure();
|
|
71
|
+
kind.onchange = configure;
|
|
72
|
+
name.required = true;
|
|
73
|
+
const error = h("div", { class: "memo-error", role: "alert" });
|
|
74
|
+
const submit = h("button", { class: "btn primary", type: "submit" }, "连接笔记库");
|
|
75
|
+
const form = h("form", { class: "modal-body memo-fields" }, label("名称", name), label("数据源", kind), label("服务地址", endpoint), s3, label(userLabel, username), label(secretLabel, secret), memoAccessField().field, error, submit);
|
|
76
|
+
const close = modal({ title: "连接笔记库", body: form, beforeClose: () => !submit.disabled });
|
|
77
|
+
form.onsubmit = async e => {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
if (submit.disabled) return;
|
|
80
|
+
submit.disabled = true;
|
|
81
|
+
submit.textContent = "正在验证连接…";
|
|
82
|
+
error.textContent = "";
|
|
83
|
+
try {
|
|
84
|
+
const source = await api("/api/memos/sources", { method: "POST", body: {
|
|
85
|
+
...Object.fromEntries(new FormData(form)), kind: kind.value,
|
|
86
|
+
} });
|
|
87
|
+
close();
|
|
88
|
+
await onConnect(source);
|
|
89
|
+
} catch (err) { error.textContent = err.message; }
|
|
90
|
+
finally { submit.disabled = false; submit.textContent = "连接笔记库"; }
|
|
91
|
+
};
|
|
92
|
+
name.focus();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function askMemoName(title, initial, directory) {
|
|
96
|
+
return new Promise(resolve => {
|
|
97
|
+
const input = h("input", { class: "input", required: true, value: initial, "aria-label": "名称" });
|
|
98
|
+
const form = h("form", { class: "modal-body memo-fields" },
|
|
99
|
+
h("label", {}, "位置", h("span", { class: "memo-path" }, "/" + directory)),
|
|
100
|
+
h("label", {}, "名称", input), h("button", { class: "btn primary" }, "确定"));
|
|
101
|
+
const close = modal({ title, body: form, beforeClose: () => { resolve(null); } });
|
|
102
|
+
input.oninput = () => input.setCustomValidity("");
|
|
103
|
+
form.onsubmit = e => {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
const name = input.value.trim();
|
|
106
|
+
if (!name || name === "." || name === ".." || /[\\/]/.test(name)) {
|
|
107
|
+
input.setCustomValidity("请输入单个文件或文件夹名称");
|
|
108
|
+
input.reportValidity();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
close();
|
|
112
|
+
resolve(name);
|
|
113
|
+
};
|
|
114
|
+
input.focus();
|
|
115
|
+
input.setSelectionRange(0, initial.lastIndexOf(".") > 0 ? initial.lastIndexOf(".") : initial.length);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Only fetch the selected snapshot. Restoring returns its text to the normal conditional save path. */
|
|
120
|
+
export async function chooseMemoVersion(url) {
|
|
121
|
+
const versions = await api(url);
|
|
122
|
+
return new Promise(resolve => {
|
|
123
|
+
let request = 0, selected = null;
|
|
124
|
+
const select = h("select", { class: "input", "aria-label": "选择历史版本" },
|
|
125
|
+
versions.map(v => h("option", { value: v.id }, new Date(v.at).toLocaleString() + " · #" + v.id)));
|
|
126
|
+
const preview = h("pre", { class: "memo-snapshot", "aria-label": "版本正文" });
|
|
127
|
+
const apply = h("button", { class: "btn primary", disabled: true, onclick: () => { close(); resolve(selected); } }, "恢复此版本");
|
|
128
|
+
const body = h("div", { class: "modal-body memo-fields" },
|
|
129
|
+
versions.length ? [select, preview, apply] : h("p", {}, "还没有历史版本。下次保存修改时,会保留修改前的正文。"));
|
|
130
|
+
const close = modal({ title: "版本历史", body, beforeClose: () => { resolve(null); } });
|
|
131
|
+
async function load() {
|
|
132
|
+
const seq = ++request;
|
|
133
|
+
selected = null;
|
|
134
|
+
apply.disabled = true;
|
|
135
|
+
preview.textContent = "正在读取…";
|
|
136
|
+
try {
|
|
137
|
+
const { text } = await api(url + "&id=" + encodeURIComponent(select.value));
|
|
138
|
+
if (seq !== request) return;
|
|
139
|
+
selected = text;
|
|
140
|
+
preview.textContent = text || "(空文件)";
|
|
141
|
+
apply.disabled = false;
|
|
142
|
+
} catch (err) { if (seq === request) preview.textContent = err.message; }
|
|
143
|
+
}
|
|
144
|
+
select.onchange = load;
|
|
145
|
+
if (versions.length) void load();
|
|
146
|
+
});
|
|
147
|
+
}
|