agent-loft 0.2.89 → 0.2.93
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 +10 -1
- package/package.json +23 -1
- package/src/channels/web/api.ts +14 -66
- package/src/channels/web/file-serve.ts +72 -0
- package/src/channels/web/tasks-api.ts +43 -11
- package/src/channels/web/workspace-api.ts +249 -0
- package/src/core/db.ts +19 -0
- package/src/core/footers.ts +26 -10
- package/src/core/git.ts +782 -0
- package/src/core/hub.ts +237 -31
- package/src/core/reply-files.ts +2 -1
- package/src/core/store.ts +8 -1
- package/src/core/task-runner.ts +5 -2
- package/src/core/tasks-bridge.ts +18 -4
- package/src/core/turn-changes.ts +179 -0
- package/src/core/types.ts +13 -0
- package/src/core/users.ts +15 -2
- package/src/core/workspace-files.ts +315 -0
- package/src/mcp/tasks-server.ts +6 -1
- package/web/css/experts.css +6 -3
- package/web/css/settings.css +31 -0
- package/web/css/tasks.css +21 -0
- package/web/css/workspace.css +1064 -0
- package/web/index.html +1 -0
- package/web/lib/api.js +1 -0
- package/web/lib/csv.js +53 -0
- package/web/lib/diff-parse.js +85 -0
- package/web/lib/dom.js +5 -0
- package/web/lib/eol.js +15 -0
- package/web/settings/users.js +23 -2
- package/web/vendor-built/LICENSE.codemirror +21 -0
- package/web/vendor-built/codemirror.js +41 -0
- package/web/views/diff-view.js +91 -0
- package/web/views/file-editor.js +146 -0
- package/web/views/file-preview.js +83 -6
- package/web/views/messages.js +55 -2
- package/web/views/sidebar-gestures.js +1 -1
- package/web/views/sidebar.js +1 -1
- package/web/views/tasks.js +108 -33
- package/web/views/topbar.js +10 -4
- package/web/views/workspace-entry.js +130 -0
- package/web/views/workspace.js +1346 -0
package/web/index.html
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
<link rel="stylesheet" href="/css/terminal.css" />
|
|
35
35
|
<link rel="stylesheet" href="/css/remote.css" />
|
|
36
36
|
<link rel="stylesheet" href="/css/servers.css" />
|
|
37
|
+
<link rel="stylesheet" href="/css/workspace.css" />
|
|
37
38
|
<link rel="stylesheet" href="/css/mobile.css" />
|
|
38
39
|
</head>
|
|
39
40
|
<body>
|
package/web/lib/api.js
CHANGED
package/web/lib/csv.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// 解析 CSV / TSV。不碰 DOM,方便单独测试。
|
|
2
|
+
|
|
3
|
+
/** 第一行里哪个分隔符多就用哪个(欧洲地区常用分号)。.tsv 直接是制表符 */
|
|
4
|
+
export function csvDelimiter(name, text) {
|
|
5
|
+
if (/\.tsv$/i.test(name)) return "\t";
|
|
6
|
+
const firstLine = text.slice(0, text.search(/\r?\n|$/));
|
|
7
|
+
const count = (ch) => firstLine.split(ch).length;
|
|
8
|
+
return count(";") > count(",") ? ";" : ",";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 按 RFC 4180:双引号里可以有分隔符和换行,两个双引号是一个双引号。
|
|
13
|
+
* cut:文本是从大文件截下来的,最后一行不完整,扔掉。
|
|
14
|
+
* maxRows:只解析这么多行,more 表示后面还有。返回 { rows, more }
|
|
15
|
+
*/
|
|
16
|
+
export function parseCsv(text, { delimiter = ",", cut = false, maxRows = Infinity } = {}) {
|
|
17
|
+
const rows = [];
|
|
18
|
+
let row = [];
|
|
19
|
+
let cell = "";
|
|
20
|
+
let quoted = false;
|
|
21
|
+
let more = false;
|
|
22
|
+
let i = text.charCodeAt(0) === 0xfeff ? 1 : 0;
|
|
23
|
+
const endRow = () => {
|
|
24
|
+
row.push(cell);
|
|
25
|
+
rows.push(row);
|
|
26
|
+
row = [];
|
|
27
|
+
cell = "";
|
|
28
|
+
};
|
|
29
|
+
for (; i < text.length; i++) {
|
|
30
|
+
const ch = text[i];
|
|
31
|
+
if (quoted) {
|
|
32
|
+
if (ch !== '"') cell += ch;
|
|
33
|
+
else if (text[i + 1] === '"') {
|
|
34
|
+
cell += '"';
|
|
35
|
+
i++;
|
|
36
|
+
} else quoted = false;
|
|
37
|
+
} else if (ch === '"' && cell === "") quoted = true;
|
|
38
|
+
else if (ch === delimiter) {
|
|
39
|
+
row.push(cell);
|
|
40
|
+
cell = "";
|
|
41
|
+
} else if (ch === "\n" || ch === "\r") {
|
|
42
|
+
if (ch === "\r" && text[i + 1] === "\n") i++;
|
|
43
|
+
endRow();
|
|
44
|
+
if (rows.length >= maxRows) {
|
|
45
|
+
more = i + 1 < text.length;
|
|
46
|
+
return { rows, more };
|
|
47
|
+
}
|
|
48
|
+
} else cell += ch;
|
|
49
|
+
}
|
|
50
|
+
// 文件末尾没有换行的最后一行
|
|
51
|
+
if (!cut && (cell !== "" || row.length > 0)) endRow();
|
|
52
|
+
return { rows, more: more || cut };
|
|
53
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// 解析 git diff 的 unified 格式。不碰 DOM,方便单独测试。
|
|
2
|
+
|
|
3
|
+
const HUNK = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 返回 { meta, hunks, combined }:
|
|
7
|
+
* meta:第一个 @@ 之前的行(diff --git、rename from、old mode…)
|
|
8
|
+
* hunks:[{ header, section, lines: [{ type: "ctx" | "add" | "del" | "note", text, oldNo, newNo }] }]
|
|
9
|
+
* combined:合并冲突时的 @@@ 格式,每行有两列标记,行号对不上单双栏,由调用方原样显示
|
|
10
|
+
*/
|
|
11
|
+
export function parseUnifiedDiff(text) {
|
|
12
|
+
const meta = [];
|
|
13
|
+
const hunks = [];
|
|
14
|
+
let hunk = null;
|
|
15
|
+
let oldNo = 0;
|
|
16
|
+
let newNo = 0;
|
|
17
|
+
const lines = text.split("\n");
|
|
18
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
19
|
+
if (lines.some((l) => l.startsWith("@@@ "))) return { meta: [], hunks: [], combined: true, raw: lines };
|
|
20
|
+
for (const line of lines) {
|
|
21
|
+
const m = HUNK.exec(line);
|
|
22
|
+
if (m) {
|
|
23
|
+
oldNo = Number(m[1]);
|
|
24
|
+
newNo = Number(m[2]);
|
|
25
|
+
hunk = { header: line, section: m[3].trim(), lines: [] };
|
|
26
|
+
hunks.push(hunk);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!hunk) {
|
|
30
|
+
meta.push(line);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const mark = line[0];
|
|
34
|
+
const body = line.slice(1);
|
|
35
|
+
if (mark === "+") hunk.lines.push({ type: "add", text: body, newNo: newNo++ });
|
|
36
|
+
else if (mark === "-") hunk.lines.push({ type: "del", text: body, oldNo: oldNo++ });
|
|
37
|
+
else if (mark === "\\") hunk.lines.push({ type: "note", text: line.slice(2) });
|
|
38
|
+
else if (mark === " " || line === "") hunk.lines.push({ type: "ctx", text: body, oldNo: oldNo++, newNo: newNo++ });
|
|
39
|
+
else {
|
|
40
|
+
// 下一个文件的头(重命名时可能一次带两段):后面的再遇到 @@ 才算内容
|
|
41
|
+
meta.push(line);
|
|
42
|
+
hunk = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { meta, hunks, combined: false };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 增删行数 */
|
|
49
|
+
export function diffStat(parsed) {
|
|
50
|
+
let added = 0;
|
|
51
|
+
let removed = 0;
|
|
52
|
+
for (const hunk of parsed.hunks) {
|
|
53
|
+
for (const line of hunk.lines) {
|
|
54
|
+
if (line.type === "add") added++;
|
|
55
|
+
else if (line.type === "del") removed++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { added, removed };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 并排显示用:把一段连续的删除和紧跟的新增配成对,其余的上下对齐。
|
|
63
|
+
* 返回 [{ left, right }],没有对应的一侧是 null;note(文件末尾没有换行)跟在它那一行的那一侧后面单独成行
|
|
64
|
+
*/
|
|
65
|
+
export function pairLines(lines) {
|
|
66
|
+
const rows = [];
|
|
67
|
+
let i = 0;
|
|
68
|
+
while (i < lines.length) {
|
|
69
|
+
const line = lines[i];
|
|
70
|
+
if (line.type === "ctx") {
|
|
71
|
+
rows.push({ left: line, right: line });
|
|
72
|
+
i++;
|
|
73
|
+
} else if (line.type === "note") {
|
|
74
|
+
rows.push({ left: line, right: line });
|
|
75
|
+
i++;
|
|
76
|
+
} else {
|
|
77
|
+
const dels = [];
|
|
78
|
+
const adds = [];
|
|
79
|
+
while (lines[i]?.type === "del") dels.push(lines[i++]);
|
|
80
|
+
while (lines[i]?.type === "add") adds.push(lines[i++]);
|
|
81
|
+
for (let k = 0; k < Math.max(dels.length, adds.length); k++) rows.push({ left: dels[k] ?? null, right: adds[k] ?? null });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return rows;
|
|
85
|
+
}
|
package/web/lib/dom.js
CHANGED
|
@@ -53,6 +53,11 @@ export const ICON = {
|
|
|
53
53
|
check: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12.5 4.5 4.5L19 7.5"/></svg>',
|
|
54
54
|
folder: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7.5A2.5 2.5 0 0 1 5.5 5h3.6l2 2.2h7.4A2.5 2.5 0 0 1 21 9.7v7.8a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 17.5Z"/><path d="M3 10h18"/></svg>',
|
|
55
55
|
folderOpen: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 17.5V7.5A2.5 2.5 0 0 1 5.5 5h3.6l2 2.2h6.4A2.5 2.5 0 0 1 20 9.7V11"/><path d="M3 17.5 5.6 12a2 2 0 0 1 1.8-1.1h13a1 1 0 0 1 .9 1.4l-2.4 6.2a2.2 2.2 0 0 1-2 1.5H5.5A2.5 2.5 0 0 1 3 17.5Z"/></svg>',
|
|
56
|
+
file: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z"/><path d="M14 3v5h5"/></svg>',
|
|
57
|
+
panel: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="M15 4v16"/></svg>',
|
|
58
|
+
refresh: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 11a8 8 0 0 0-14.3-4.9L3 9"/><path d="M3 4v5h5"/><path d="M4 13a8 8 0 0 0 14.3 4.9L21 15"/><path d="M21 20v-5h-5"/></svg>',
|
|
59
|
+
minus: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M5 12h14"/></svg>',
|
|
60
|
+
back: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m15 6-6 6 6 6"/></svg>',
|
|
56
61
|
terminal: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/></svg>',
|
|
57
62
|
monitor: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><path d="M8 21h8M12 17v4"/></svg>',
|
|
58
63
|
keyboard: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="20" height="14" rx="2"/><path d="M6 9h.01M10 9h.01M14 9h.01M18 9h.01M6 13h.01M18 13h.01M10 13h4M7 16h10"/></svg>',
|
package/web/lib/eol.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// 文件的换行符。编辑器内部一律按 \n 处理,保存时要还原,不能让改一行变成整个文件都有改动。
|
|
2
|
+
|
|
3
|
+
/** lf / crlf:整个文件统一;mixed:混着用,或者有单独的 \r,编辑器里要原样保留 */
|
|
4
|
+
export function detectEol(text) {
|
|
5
|
+
if (!text.includes("\r")) return "lf";
|
|
6
|
+
const crlf = text.match(/\r\n/g)?.length ?? 0;
|
|
7
|
+
const cr = text.match(/\r/g)?.length ?? 0;
|
|
8
|
+
const lf = text.match(/\n/g)?.length ?? 0;
|
|
9
|
+
return crlf === cr && crlf === lf ? "crlf" : "mixed";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** 编辑器里的文字(\n)还原成文件原来的换行符 */
|
|
13
|
+
export function restoreEol(text, eol) {
|
|
14
|
+
return eol === "crlf" ? text.replace(/\n/g, "\r\n") : text;
|
|
15
|
+
}
|
package/web/settings/users.js
CHANGED
|
@@ -133,6 +133,24 @@ export async function usersTab(page) {
|
|
|
133
133
|
}),
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
+
// 工作区面板:管理员一直能用,成员要单独开
|
|
137
|
+
if (u.role !== "admin") {
|
|
138
|
+
items.push({
|
|
139
|
+
label: u.files ? "关闭工作区面板" : "开通工作区面板…",
|
|
140
|
+
onclick: act(async () => {
|
|
141
|
+
if (!u.files) {
|
|
142
|
+
const sure = await confirmDialog({
|
|
143
|
+
title: `给「${u.name}」开通工作区面板?`,
|
|
144
|
+
message: "他能在自己的对话里浏览、编辑、上传和删除工作目录下的文件,并在 Git 仓库里暂存、丢弃、提交、切换分支、撤销一轮的改动,都不经过授权卡。密钥一类的敏感文件不显示也改不了。他能在工作区任意目录开对话,所以相当于能读写整个工作区。",
|
|
145
|
+
confirmText: "开通",
|
|
146
|
+
});
|
|
147
|
+
if (!sure) return false;
|
|
148
|
+
}
|
|
149
|
+
await patch(u, { files: !u.files });
|
|
150
|
+
toast(u.files ? "已关闭" : "已开通");
|
|
151
|
+
}),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
136
154
|
items.push("sep");
|
|
137
155
|
if (u.feishuLinks) {
|
|
138
156
|
items.push({
|
|
@@ -208,6 +226,7 @@ export async function usersTab(page) {
|
|
|
208
226
|
h("span", { class: "status-tag" }, u.role === "admin" ? "管理员" : "成员"),
|
|
209
227
|
u.disabled ? h("span", { class: "status-tag bad" }, "已停用") : null,
|
|
210
228
|
u.role !== "admin" && u.remote ? h("span", { class: "status-tag" }, "远程控制") : null,
|
|
229
|
+
u.role !== "admin" && u.files ? h("span", { class: "status-tag" }, "工作区面板") : null,
|
|
211
230
|
),
|
|
212
231
|
h("div", { class: "s" }, `创建于 ${relTime(u.createdAt)} · ${u.devices} 台设备已登录${u.feishuLinks ? ` · 绑定了 ${u.feishuLinks} 个飞书账号` : ""}`),
|
|
213
232
|
),
|
|
@@ -227,8 +246,10 @@ export async function usersTab(page) {
|
|
|
227
246
|
const role = h("select", {}, h("option", { value: "member" }, "成员"), h("option", { value: "admin" }, "管理员"));
|
|
228
247
|
const permissions = permissionFields(data.resources);
|
|
229
248
|
const remote = h("input", { type: "checkbox" });
|
|
249
|
+
const files = h("input", { type: "checkbox" });
|
|
230
250
|
const memberOptions = h("div", { class: "user-permissions" }, permissions.el,
|
|
231
|
-
h("div", { class: "field" }, h("span", {}, "远程权限"), h("label", { class: "check-item" }, remote, h("span", {}, "允许使用终端和桌面")))
|
|
251
|
+
h("div", { class: "field" }, h("span", {}, "远程权限"), h("label", { class: "check-item" }, remote, h("span", {}, "允许使用终端和桌面"))),
|
|
252
|
+
h("div", { class: "field" }, h("span", {}, "文件权限"), h("label", { class: "check-item" }, files, h("span", {}, "允许用工作区面板读写文件、操作 Git"))));
|
|
232
253
|
role.onchange = () => { memberOptions.hidden = role.value === "admin"; };
|
|
233
254
|
fill(
|
|
234
255
|
addBox,
|
|
@@ -246,7 +267,7 @@ export async function usersTab(page) {
|
|
|
246
267
|
confirmText: "开通并添加", danger: true,
|
|
247
268
|
}))) return false;
|
|
248
269
|
await api("/api/users", { method: "POST", body: { name: name.value.trim(), password: pw.value, role: role.value,
|
|
249
|
-
...(role.value === "member" ? { remote: remote.checked, permissions: permissions.value() } : {}) } });
|
|
270
|
+
...(role.value === "member" ? { remote: remote.checked, files: files.checked, permissions: permissions.value() } : {}) } });
|
|
250
271
|
toast(`已添加「${name.value.trim()}」`);
|
|
251
272
|
close();
|
|
252
273
|
reload();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|