agent-loft 0.2.96 → 0.2.97
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 +2 -0
- package/package.json +1 -1
- package/src/channels/web/api.ts +7 -5
- package/src/channels/web/workspace-api.ts +14 -1
- package/src/core/git.ts +192 -2
- package/src/core/users.ts +15 -2
- package/web/css/workspace.css +24 -0
- package/web/settings/users.js +29 -2
- package/web/views/workspace.js +38 -1
package/README.md
CHANGED
|
@@ -95,6 +95,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
95
95
|
- **技能(skills)**:设置 → 技能。技能就是 Claude Code / Codex 用的那种 SKILL.md(可以带脚本和资料),由 agent-loft 按人管理,两个 agent 都能用。**来源**:在页面上写、上传技能包(`.zip` / `.skill` / 单个 SKILL.md / 整个文件夹),或者在对话里让 agent「把刚才的做法存成技能」(agent 用 `create_skill` / `update_skill`,先弹授权卡)。**共享**:新建、编辑时选择「仅自己可见」「指定用户」或「所有人可见」,也可在自己技能的「更多 → 共享」里调整;默认仅自己可见。其他用户在「共享技能」中查看正文和附带文件、安装;安装后出现在「我的技能」,可停用、卸载或重新安装。安装的是作者的同一份技能,更新自动跟随;作者撤回共享后,范围外用户不再可用。只有作者能编辑,管理员可下架自己看得到的共享技能。共享不包含作者填写的变量和密钥,每人使用自己的配置。**使用**:内置专家默认使用你启用的全部技能,也可以在「设置 → Agent」中分别指定 Claude Code / Codex 加载哪些技能;自定义专家只用它选中的;agent 遇到对得上的事自己用。**变量**:技能可以声明要用的环境变量(接口地址、密钥),每个人填自己的值,只注入自己的会话;密钥再写上「只允许发往」的地址就成了**受保护的密钥**——不进环境变量,agent 看不到值,只能用 `skill_request` 工具让 agent-loft 代发请求(在地址、请求头、请求体里写 `{{变量名}}`),只发往你确认过的地址、不跟随跳转、响应里出现的值会被抹掉;作者后来改了地址,要你再确认一次才放行。**机器上原有的技能**(`~/.claude/skills`、`~/.agents/skills`、插件市场和 claude.ai 同步的)只给管理员:成员的会话里看不到、调不了(Claude 用技能白名单,`/技能名` 也会被拦下;Codex 关掉它自己的技能清单),管理员在「设置 → 技能 → 本机技能」里能看到。
|
|
96
96
|
- **工作区面板**:会话右上角「更多 → 文件」打开或折叠,菜单中用绿色新增行数、红色删除行数显示当前分支的改动,在对话旁边(手机上全屏)看和改这条会话工作目录里的文件。「文件」页签是一棵按需展开的文件树,图片、PDF、音视频、Markdown、网页、代码直接预览,CSV / TSV 显示成表格;文本文件(1 MB 以内、UTF-8)可以编辑,Ctrl / ⌘ + S 保存,Markdown 和 CSV 能预览没保存的内容。还能新建、重命名、上传(点按钮或拖到面板上)、删除。保存时如果文件在你编辑期间被 agent 或别人改过,不会覆盖,由你选覆盖还是重新加载;没保存的内容存在本机,换会话、刷新页面都不丢。「改动」页签是 Git 仓库的已暂存 / 未暂存 / 未跟踪文件,点开看 diff,宽度够时可以切并排;顶栏的分支标记显示当前分支和改动数,点面板里的分支行能查看和切换本地、远程分支,也能新建分支。文件行上可以暂存、取消暂存、丢弃改动,写好说明提交已暂存的内容(默认不运行 Git 钩子,要用的话勾上);「历史」页签看提交记录和每个提交的 diff。推送、拉取、合并、变基请交给 agent 或终端。一轮结束、切回窗口时自动刷新。
|
|
97
97
|
- 管理员能用;成员要管理员在 设置 → 用户 里单独「开通工作区面板」。
|
|
98
|
+
- 分支栏下面可以获取、拉取、推送,用的是服务器上配置的 Git 凭据。拉取只做快进,推送从不强制。成员默认没有这个权限,要管理员再单独「开通 Git 远程操作」。
|
|
98
99
|
- **资料库**:像 ChatGPT 的资料库,侧栏的「资料库」。对话里发过的附件、agent 回复里给出的、这一轮新写出来的图片 / 文档 / 音视频(复制一份收进来,之后原文件改了删了不影响)都汇总在这里:按图片 / 文档 / 音视频筛、按文件名搜,点开看大图或下载,「在新对话里用」,单个或批量删除(文件从磁盘上删掉)。从资料库拿到对话里的文件硬链接进那条对话的上传目录,不占双份空间,agent 照常能读。按人隔离,规则同对话:自己的;没主人的对话(飞书群聊等)的归管理员。上传了一直没发出去的一天后清掉;删除会话时立即清理该会话的上传文件和资料库记录,删除原件也会清理复用到其他会话的副本。agent 侧的会话记录仍保留,恢复会话不会恢复已删除的文件。
|
|
99
100
|
- **远程控制**:侧栏「定时任务」下面的「远程控制」,直接操作这台机器的**桌面**和**终端**,上面一键切换;切回对话时连接留在后台(侧栏入口上亮个小绿点),再进来接着用。这台机器没有图形桌面(服务器、NAS)时只有终端。
|
|
100
101
|
- 桌面:走 VNC 协议,网页里用 noVNC 显示,鼠标、键盘、剪贴板都能用,进来时不自动连、点「连接桌面」才连,工具栏上选画质:流畅 / 标准(默认)/ 高清由服务端把画面缩小到长边 1280 / 1920 / 2560、只把变了的地方压成 JPEG 发过来(macOS 屏幕共享只给无损的 ZRLE,5K 屏一整屏 30MB,原样转发隔着公网几秒一帧),原画是原样转发、只适合局域网;远程那边接了几块屏时可以只看其中一块(按系统里的显示器名称选,服务端只截那块再缩,比几块屏拼在一起缩小清楚得多;macOS 的各块屏位置要从屏幕共享发来的画面里学,第一次连上要几秒,原画下不能选);可以缩放到窗口或按原始大小看、全屏(手机上也能,iPhone 上是铺满页面)、「只看不控制」、发送 Ctrl+Alt+Del 之类的组合键。手机上有两种手势(右上角切换,「?」看说明):**触控板模式**(默认)屏幕上有个指针,单指滑动移动、轻点单击、双指轻点右键、长按后拖动是按住左键拖、双指滑动滚动;**触摸模式**点哪就点哪。两种模式都能双指捏合在本地放大画面(放大后小按钮也点得准,右下角「还原」),画面下面一排 Esc / Tab / Ctrl / Alt / Win / 方向键,Ctrl、Alt、Win 点一下会粘住,带给下一个按键或点击;键盘按钮弹出软键盘打字,中文输入法也能用。Linux 上 agent-loft 在有人连时用 x11vnc 共享当前的桌面(Xorg 会话;只听 127.0.0.1、随机端口、每次随机密码,需要 `sudo apt install x11vnc`),没人连着 30 分钟后停掉;macOS 上在 设置 → 远程控制 里改用「已有的 VNC 服务」,接系统自带的屏幕共享:填 VNC 密码,或者屏幕共享没开 VNC 密码时填 Mac 的用户名和登录密码(苹果认证,由服务端登录)。
|
|
@@ -193,6 +194,7 @@ agent-loft service install
|
|
|
193
194
|
- 暴露到公网时,只通过 HTTPS 反向代理(比如 Lucky)或 Cloudflare Tunnel 访问,并把不在本机的反代 IP 加进 `web.trustedProxies`(只有从这些地址来的连接才采信 `X-Forwarded-*`)。不要直接把 8800 端口映射出去。局域网访问可以在 设置 → 系统 → 网络访问 里关掉。
|
|
194
195
|
- 远程控制不经过授权卡:拿到终端就是拿到运行 agent-loft 的那个系统用户的 shell,拿到桌面就是坐在登录桌面的那个人面前。所以默认只给管理员,成员要管理员单独开通(开通时会再提醒一次);收回权限、停用或删除用户、在设置里关掉终端 / 桌面时,他开着的 shell 立刻结束、桌面立刻断开。终端和桌面的 WebSocket 和其他接口一样校验登录态和 Origin。shell 拿不到本服务自己的凭据(和 agent 子进程一样剔除环境变量)。共享桌面用的 x11vnc 只听本机、密码每次随机生成、经文件传过去(不出现在命令行里);用「已有的 VNC 服务」时,配置里的 VNC 密码会交给开通了远程控制的人的页面;填了 Mac 用户名走苹果认证时由服务端登录,登录密码不会发到页面(但和 VNC 密码一样明文存在 config.json 里)。
|
|
195
196
|
- 工作区面板只能操作会话工作目录之内的东西:路径写法跳不出工作目录,符号链接解析后跳不出工作区根目录,敏感文件(私钥、`.env`、云凭据、agent-loft 自己的数据)和 `.git` 目录不显示,读写、新建、改名、删除都不行;有改动的敏感文件只标记,不给 diff 内容。diff 只接受当前改动列表里的文件。面板里的文件操作不经过授权卡,删除不能恢复(有二次确认);删除文件夹会连带里面看不到的隐藏文件、敏感文件和 `.git`。别的会话正在用的工作目录不能在这里删除或改名。因为成员能在工作区任意目录开对话,开通面板约等于能读写整个工作区,所以默认只给管理员。仓库里的配置不可信:调用 git 不经过 shell,并关掉 `core.fsmonitor`、`diff.external`、textconv、钩子和仓库自己定义的 filter,不会执行仓库配置里的程序(包括 `include` 进来的配置);git 子进程拿不到本服务自己的环境变量,也不连网,部分克隆缺的内容不会去懒加载,这种仓库里有些历史 diff 可能看不了;工作树(`core.worktree`)不在工作区之内的仓库不算数,也不会向上找到工作区之外的仓库。提交时只有勾选「运行 Git 钩子」才跑钩子;`.git/config` 里配了签名相关设置时这次提交不签名,只用全局配置的才签名。配了自定义 filter 的仓库(git-crypt 之类)不做快照,面板里也不能暂存、丢弃、提交、切分支,请在终端里操作:不跑 filter 的话,暂存就是把明文写进去。敏感文件不能在面板里暂存、丢弃、提交;嵌在仓库里的另一个仓库也不能在面板里暂存或丢弃。agent 正在这个仓库里干活时,不能丢弃、切分支、撤销一轮。
|
|
197
|
+
- 面板连 Git 远程时只放行 https、http、ssh 地址;仓库 `.git/config` 里有能运行程序或改变连接去向的配置(`credential.*`、`core.sshCommand`、`url.*`、`http.proxy` 等)就拒绝操作。用了 Git LFS 的仓库要勾选运行钩子才能推送,要推送的提交里有敏感文件也会拒绝。
|
|
196
198
|
- 每轮改动的快照是写进这个仓库 `.git` 里的对象,留在 `refs/agent-loft/t/` 这些引用下,不碰你的工作区、暂存区和分支,也不会出现在 `git branch`、`git log --all` 里;默认的 `git push` 和 `git clone` 不带它们,但 `git push --mirror` 会。敏感文件、超过 20 MB 的文件不进快照;改动和未跟踪的文件超过 5000 个时这一轮不做快照。每个仓库只留最近 200 轮、60 天以内的,更早的记录只保留统计。没开通工作区面板的成员的对话不做快照。
|
|
197
199
|
- 审批超时一律按拒绝处理。Codex 默认沙箱为 `workspace-write`,不会因为 `~/.codex/config.toml` 里配了 `never` 或 `danger-full-access` 就绕过审批。
|
|
198
200
|
- agent 子进程拿不到本服务自己的凭据(`FEISHU_*`、`AGENT_LOFT_*` 等环境变量会被剔除)。
|
package/package.json
CHANGED
package/src/channels/web/api.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
createUser,
|
|
18
18
|
getUser,
|
|
19
19
|
canUseFiles,
|
|
20
|
+
canUseGitRemote,
|
|
20
21
|
isAdmin,
|
|
21
22
|
legacyOwnerId,
|
|
22
23
|
listUsers,
|
|
@@ -492,8 +493,8 @@ function adminOnly(p: string): boolean {
|
|
|
492
493
|
);
|
|
493
494
|
}
|
|
494
495
|
|
|
495
|
-
function publicMe(user: Pick<User, "id" | "name" | "role" | "disabled" | "files">) {
|
|
496
|
-
return { id: user.id, name: user.name, role: user.role, ...(canUseFiles(user) ? { files: true } : {}) };
|
|
496
|
+
function publicMe(user: Pick<User, "id" | "name" | "role" | "disabled" | "files" | "gitRemote">) {
|
|
497
|
+
return { id: user.id, name: user.name, role: user.role, ...(canUseFiles(user) ? { files: true } : {}), ...(canUseGitRemote(user) ? { gitRemote: true } : {}) };
|
|
497
498
|
}
|
|
498
499
|
|
|
499
500
|
/** users.ts 抛的是给人看的错误,转成 400 */
|
|
@@ -1715,11 +1716,11 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1715
1716
|
}
|
|
1716
1717
|
}
|
|
1717
1718
|
if (p === "/api/users" && method === "POST") {
|
|
1718
|
-
const body = await readJsonBody<{ name?: string; password?: string; role?: Role; remote?: boolean; files?: boolean; permissions?: unknown }>(req);
|
|
1719
|
+
const body = await readJsonBody<{ name?: string; password?: string; role?: Role; remote?: boolean; files?: boolean; gitRemote?: boolean; permissions?: unknown }>(req);
|
|
1719
1720
|
sendJson(
|
|
1720
1721
|
res,
|
|
1721
1722
|
200,
|
|
1722
|
-
userOp(() => createUser({ name: String(body.name ?? ""), password: String(body.password ?? ""), role: body.role === "admin" ? "admin" : "member", ...(typeof body.remote === "boolean" ? { remote: body.remote } : {}), ...(typeof body.files === "boolean" ? { files: body.files } : {}), ...(body.permissions !== undefined ? { permissions: body.permissions } : {}) })),
|
|
1723
|
+
userOp(() => createUser({ name: String(body.name ?? ""), password: String(body.password ?? ""), role: body.role === "admin" ? "admin" : "member", ...(typeof body.remote === "boolean" ? { remote: body.remote } : {}), ...(typeof body.files === "boolean" ? { files: body.files } : {}), ...(typeof body.gitRemote === "boolean" ? { gitRemote: body.gitRemote } : {}), ...(body.permissions !== undefined ? { permissions: body.permissions } : {}) })),
|
|
1723
1724
|
);
|
|
1724
1725
|
return;
|
|
1725
1726
|
}
|
|
@@ -1728,7 +1729,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1728
1729
|
const id = userMatch[1]!;
|
|
1729
1730
|
if (!getUser(id)) throw new HttpError(404, "用户不存在");
|
|
1730
1731
|
if (method === "PATCH") {
|
|
1731
|
-
const body = await readJsonBody<{ name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean; files?: boolean; permissions?: unknown }>(req);
|
|
1732
|
+
const body = await readJsonBody<{ name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean; files?: boolean; gitRemote?: boolean; permissions?: unknown }>(req);
|
|
1732
1733
|
if (id === user.id && (body.disabled === true || (body.role !== undefined && body.role !== "admin"))) {
|
|
1733
1734
|
throw new HttpError(400, "不能停用自己,也不能取消自己的管理员");
|
|
1734
1735
|
}
|
|
@@ -1741,6 +1742,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1741
1742
|
...(typeof body.password === "string" ? { password: body.password } : {}),
|
|
1742
1743
|
...(typeof body.remote === "boolean" ? { remote: body.remote } : {}),
|
|
1743
1744
|
...(typeof body.files === "boolean" ? { files: body.files } : {}),
|
|
1745
|
+
...(typeof body.gitRemote === "boolean" ? { gitRemote: body.gitRemote } : {}),
|
|
1744
1746
|
...(body.permissions !== undefined ? { permissions: body.permissions } : {}),
|
|
1745
1747
|
}),
|
|
1746
1748
|
);
|
|
@@ -14,6 +14,9 @@ import {
|
|
|
14
14
|
gitCreateBranch,
|
|
15
15
|
gitDiff,
|
|
16
16
|
gitDiscard,
|
|
17
|
+
gitFetch,
|
|
18
|
+
gitPull,
|
|
19
|
+
gitPush,
|
|
17
20
|
GitError,
|
|
18
21
|
gitLog,
|
|
19
22
|
gitStage,
|
|
@@ -24,7 +27,7 @@ import {
|
|
|
24
27
|
import { hub } from "../../core/hub.js";
|
|
25
28
|
import { revertTurn, turnFileDiff, turnState } from "../../core/turn-changes.js";
|
|
26
29
|
import { listConversations, type Conversation } from "../../core/store.js";
|
|
27
|
-
import { canUseFiles, type User } from "../../core/users.js";
|
|
30
|
+
import { canUseFiles, canUseGitRemote, type User } from "../../core/users.js";
|
|
28
31
|
import {
|
|
29
32
|
createWorkspaceEntry,
|
|
30
33
|
deleteWorkspaceEntry,
|
|
@@ -62,6 +65,9 @@ const ROUTES: Record<string, string> = {
|
|
|
62
65
|
"git-commit": "POST",
|
|
63
66
|
"git-switch": "POST",
|
|
64
67
|
"git-branch-new": "POST",
|
|
68
|
+
"git-fetch": "POST",
|
|
69
|
+
"git-pull": "POST",
|
|
70
|
+
"git-push": "POST",
|
|
65
71
|
"git-turn-revert": "POST",
|
|
66
72
|
"workspace-save": "POST",
|
|
67
73
|
"workspace-new": "POST",
|
|
@@ -203,13 +209,20 @@ export async function handleWorkspaceApi(req: IncomingMessage, res: ServerRespon
|
|
|
203
209
|
return true;
|
|
204
210
|
}
|
|
205
211
|
if (req.method === "POST") {
|
|
212
|
+
if ((sub === "git-fetch" || sub === "git-pull" || sub === "git-push") && !canUseGitRemote(user)) {
|
|
213
|
+
throw new HttpError(403, "你没有连接 Git 远程的权限,找管理员在 设置 → 用户 里开通");
|
|
214
|
+
}
|
|
206
215
|
const body = await readJsonBody<{ paths?: unknown; message?: unknown; hooks?: unknown; branch?: unknown; name?: unknown; id?: unknown; direction?: unknown; force?: unknown }>(req);
|
|
207
216
|
const root = repo.root;
|
|
208
217
|
await gitAction(res, async () => {
|
|
209
218
|
if (sub === "git-stage") return gitStage(root, body.paths);
|
|
210
219
|
if (sub === "git-unstage") return gitUnstage(root, body.paths);
|
|
211
220
|
if (sub === "git-commit") return gitCommit(root, body.message, { hooks: body.hooks === true });
|
|
221
|
+
// 获取和推送不动工作区,agent 干活时也能做
|
|
222
|
+
if (sub === "git-fetch") return gitFetch(root);
|
|
223
|
+
if (sub === "git-push") return gitPush(root, { hooks: body.hooks === true });
|
|
212
224
|
assertIdle(root);
|
|
225
|
+
if (sub === "git-pull") return gitPull(root);
|
|
213
226
|
if (sub === "git-discard") return gitDiscard(root, body.paths);
|
|
214
227
|
if (sub === "git-switch") return gitSwitch(root, body.branch);
|
|
215
228
|
if (sub === "git-branch-new") return gitCreateBranch(root, body.name);
|
package/src/core/git.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// - 去掉继承来的 GIT_* 环境变量,从 git 钩子里启动服务时也不会指到别的仓库;
|
|
10
10
|
// - 本服务自己的凭据不传下去(和 agent 子进程一样,见 agent-env.ts):用户勾选了运行钩子时,钩子也拿不到;
|
|
11
11
|
// - 不连网(GIT_ALLOW_PROTOCOL、GIT_NO_LAZY_FETCH):部分克隆缺对象时 git 会去远程地址拿,
|
|
12
|
-
// 而地址是配置里写的,ext::
|
|
12
|
+
// 而地址是配置里写的,ext:: 这种地址就是一条命令。只有用户点的获取、拉取、推送例外,见 networkEnv;
|
|
13
13
|
// - 不抢索引锁(GIT_OPTIONAL_LOCKS=0):面板在后台刷新,不能和正在干活的 agent 抢。
|
|
14
14
|
//
|
|
15
15
|
// 路径都相对仓库根目录。
|
|
@@ -39,7 +39,7 @@ function gitEnv(): NodeJS.ProcessEnv {
|
|
|
39
39
|
for (const [k, v] of Object.entries(agentEnvironment())) if (!k.startsWith("GIT_")) env[k] = v;
|
|
40
40
|
env.GIT_OPTIONAL_LOCKS = "0";
|
|
41
41
|
env.GIT_NO_LAZY_FETCH = "1";
|
|
42
|
-
//
|
|
42
|
+
// 除了获取、拉取、推送(见 networkEnv),这里用到的命令都不需要连网。没有哪个协议叫这个名字,所以都不允许
|
|
43
43
|
env.GIT_ALLOW_PROTOCOL = "none";
|
|
44
44
|
env.GIT_TERMINAL_PROMPT = "0";
|
|
45
45
|
env.GIT_PAGER = "cat";
|
|
@@ -208,6 +208,8 @@ export type GitStatus = {
|
|
|
208
208
|
upstream?: string;
|
|
209
209
|
ahead: number;
|
|
210
210
|
behind: number;
|
|
211
|
+
/** 推送会连到的地址(去掉了里面的账号密码)。只在要 stats 时给;没有远程时没有 */
|
|
212
|
+
pushUrl?: string;
|
|
211
213
|
files: GitFileChange[];
|
|
212
214
|
truncated: boolean;
|
|
213
215
|
/** 工作区相对 HEAD 的总行数变化(含未跟踪文件,不含敏感文件、二进制)。 */
|
|
@@ -279,6 +281,10 @@ export async function gitStatus(root: string, options: { stats?: boolean } = {})
|
|
|
279
281
|
if (isSensitivePath(path.join(root, f.path)) || (f.oldPath && isSensitivePath(path.join(root, f.oldPath)))) f.sensitive = true;
|
|
280
282
|
}
|
|
281
283
|
if (options.stats && !status.truncated) status.stats = await workingTreeStats(root, status, safe).catch(() => undefined);
|
|
284
|
+
if (options.stats) {
|
|
285
|
+
const url = await currentPushUrl(root, status.branch).catch(() => undefined);
|
|
286
|
+
if (url) status.pushUrl = url;
|
|
287
|
+
}
|
|
282
288
|
return status;
|
|
283
289
|
}
|
|
284
290
|
|
|
@@ -796,6 +802,190 @@ export async function gitCreateBranch(root: string, name: unknown): Promise<void
|
|
|
796
802
|
await write(root, ["checkout", "-q", "-b", branch], "新建分支失败");
|
|
797
803
|
}
|
|
798
804
|
|
|
805
|
+
// ---------- 和远程同步 ----------
|
|
806
|
+
//
|
|
807
|
+
// 用的是这台机器全局配置里的凭据,地址和其他设置却可能来自不可信的 .git/config,所以:
|
|
808
|
+
// - 只放行 https、http、ssh,ext:: 这种能跑命令的地址和本地路径都不行;
|
|
809
|
+
// - 仓库配置里有能跑程序、能改去向的项就不操作,让用户去终端(assertNetworkSafe);
|
|
810
|
+
// - 钩子照旧不跑(推送可以勾选),不碰子模块;
|
|
811
|
+
// - 只做快进拉取和不强制的推送:不会产生冲突,也不会覆盖别人的提交。
|
|
812
|
+
|
|
813
|
+
const NETWORK_TIMEOUT_MS = 5 * 60_000;
|
|
814
|
+
const NETWORK_MAX_BYTES = 8 * 1024 * 1024;
|
|
815
|
+
|
|
816
|
+
/** 仓库自己的配置里连网时不能信的项(键名是小写的,http 的单独看,见 unsafeNetworkKey) */
|
|
817
|
+
const UNSAFE_NETWORK_CONFIG =
|
|
818
|
+
/^(credential\.|protocol\.|ssh\.|url\.|core\.(sshcommand|gitproxy|askpass|alternaterefscommand)$|remote\..*\.(uploadpack|receivepack|proxy|vcs)$|merge\..*\.driver$|gpg\.(.*\.)?program$|gpg\.ssh\.defaultkeycommand$|lfs\.(url$|pushurl$|standalonetransferagent$|customtransfer\.|extension\.))/;
|
|
819
|
+
|
|
820
|
+
function unsafeNetworkKey(key: string): boolean {
|
|
821
|
+
const k = key.toLowerCase();
|
|
822
|
+
// 代理、自定义请求头、证书校验都能把请求或凭据转走。只调传输参数的放行
|
|
823
|
+
if (k.startsWith("http.")) return !/\.(postbuffer|lowspeedlimit|lowspeedtime|version)$/.test(k);
|
|
824
|
+
return UNSAFE_NETWORK_CONFIG.test(k);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/** 地址里可能带着账号密码(https://user:token@host/…),不能出现在页面上 */
|
|
828
|
+
function redactUrls(text: string): string {
|
|
829
|
+
return text.replace(/(\b[a-z][a-z0-9+.-]*:\/\/)[^/\s@]+@/gi, "$1");
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
async function assertNetworkSafe(root: string): Promise<void> {
|
|
833
|
+
const unsafe = (await repoConfig(root, ".")).find((c) => unsafeNetworkKey(c.key));
|
|
834
|
+
if (unsafe) throw new GitError(409, `这个仓库的配置里有「${redactUrls(unsafe.key)}」,它能运行程序或改变连接的去向,面板不会带着凭据去连。确认没问题的话请在终端里操作`);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** 连网命令的环境,换掉 gitEnv 里禁止连网的设置。assertNetworkSafe 之后才能调:这里读到的 core.sshCommand 是全局配置的 */
|
|
838
|
+
async function networkEnv(root: string): Promise<NodeJS.ProcessEnv> {
|
|
839
|
+
const ssh = await configValue(root, "core.sshCommand");
|
|
840
|
+
return {
|
|
841
|
+
GIT_ALLOW_PROTOCOL: "https:http:ssh",
|
|
842
|
+
// 部分克隆拉取后检出时要按需下载对象
|
|
843
|
+
GIT_NO_LAZY_FETCH: undefined,
|
|
844
|
+
// 没人能回答提示:要输密码、确认主机指纹的直接失败,不要等到超时
|
|
845
|
+
GIT_SSH_COMMAND: `${ssh || "ssh"} -o BatchMode=yes`,
|
|
846
|
+
SSH_ASKPASS: undefined,
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function explainNetwork(stderr: string, fallback: string): string {
|
|
851
|
+
const text = redactUrls(stderr);
|
|
852
|
+
if (/transport '.*' not allowed/i.test(text)) return "面板只连 https、http、ssh 地址的远程,这个地址请在终端里操作";
|
|
853
|
+
if (/authentication failed|could not read (username|password)|terminal prompts disabled|permission denied \(|host key verification failed|invalid username or|returned error: 40[13]/i.test(text)) {
|
|
854
|
+
return "远程的认证没通过:服务器上的 git 没有这个仓库的凭据,或者没有权限。先在服务器终端里配置好(比如 gh auth login、SSH 密钥、known_hosts)";
|
|
855
|
+
}
|
|
856
|
+
if (/not possible to fast-forward/i.test(text)) return "本地和远程已经分叉,面板只支持快进拉取。请在终端里合并,或者交给 agent";
|
|
857
|
+
if (/\[rejected\]|non-fast-forward|fetch first/i.test(text)) return "远程有本地没有的提交,先拉取再推送";
|
|
858
|
+
if (/could not resolve host|could not connect|failed to connect|connection (timed out|refused)|network is unreachable/i.test(text)) return "连不上远程,检查一下这台服务器的网络和远程地址";
|
|
859
|
+
return explain(text, fallback);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
async function network(root: string, args: string[], fallback: string, opts: { hooks?: boolean } = {}): Promise<void> {
|
|
863
|
+
const hookArgs = opts.hooks ? ["-c", `core.hooksPath=${await hooksDir(root)}`] : [];
|
|
864
|
+
const prefix = [...(await safeArgs(root)), "-c", "submodule.recurse=false", ...hookArgs];
|
|
865
|
+
let out: RunResult;
|
|
866
|
+
try {
|
|
867
|
+
out = await run(root, [...prefix, ...args], NETWORK_MAX_BYTES, { env: await networkEnv(root), timeoutMs: NETWORK_TIMEOUT_MS });
|
|
868
|
+
} catch (err) {
|
|
869
|
+
throw new GitError(504, redactUrls(err instanceof Error ? err.message : String(err)));
|
|
870
|
+
}
|
|
871
|
+
// 超过缓冲区时 git 被杀掉了,run 报的 code 0 不代表成功
|
|
872
|
+
if (out.truncated) throw new GitError(502, "git 的输出太多,操作被中断了。请刷新确认结果,或者在终端里操作");
|
|
873
|
+
if (out.code !== 0) throw new GitError(409, explainNetwork(out.stderr, fallback));
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
async function configValue(root: string, key: string): Promise<string | undefined> {
|
|
877
|
+
const out = await run(root, ["config", "--get", key], 64 * 1024);
|
|
878
|
+
return out.code === 0 ? out.stdout.trim() || undefined : undefined;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
async function remoteNames(root: string): Promise<string[]> {
|
|
882
|
+
const out = await run(root, ["remote"], 256 * 1024);
|
|
883
|
+
// 不会用「-」开头的名字:放到命令行上就成了选项
|
|
884
|
+
const names = out.code === 0 ? out.stdout.split("\n").filter((n) => n && !n.startsWith("-")) : [];
|
|
885
|
+
if (!names.length) throw new GitError(409, "这个仓库还没有配置远程");
|
|
886
|
+
return names;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/** 当前分支跟踪的远程,没有就是 origin,再没有就是唯一的那个 */
|
|
890
|
+
async function fetchRemote(root: string, branch: string | null, remotes: string[]): Promise<string> {
|
|
891
|
+
const tracked = branch ? await configValue(root, `branch.${branch}.remote`) : undefined;
|
|
892
|
+
if (tracked && remotes.includes(tracked)) return tracked;
|
|
893
|
+
if (remotes.includes("origin")) return "origin";
|
|
894
|
+
if (remotes.length === 1) return remotes[0]!;
|
|
895
|
+
throw new GitError(409, "这个仓库有多个远程,不知道该连哪个。请先给当前分支设置上游,或者在终端里操作");
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/** 推送的目标和 git 自己的优先级一样:branch.<名字>.pushRemote、remote.pushDefault,然后才是跟踪的远程 */
|
|
899
|
+
async function pushRemote(root: string, branch: string | null, remotes: string[]): Promise<string> {
|
|
900
|
+
const explicit = (branch ? await configValue(root, `branch.${branch}.pushRemote`) : undefined) ?? (await configValue(root, "remote.pushDefault"));
|
|
901
|
+
if (explicit && remotes.includes(explicit)) return explicit;
|
|
902
|
+
return fetchRemote(root, branch, remotes);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
async function currentPushUrl(root: string, branch: string | null): Promise<string | undefined> {
|
|
906
|
+
const remote = await pushRemote(root, branch, await remoteNames(root));
|
|
907
|
+
const out = await run(root, ["remote", "get-url", "--push", remote], 64 * 1024);
|
|
908
|
+
return out.code === 0 ? redactUrls(out.stdout.trim()) || undefined : undefined;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/** 更新远程分支的引用,不动工作区和本地分支 */
|
|
912
|
+
export async function gitFetch(root: string): Promise<{ remote: string; ahead: number; behind: number }> {
|
|
913
|
+
await assertNetworkSafe(root);
|
|
914
|
+
const { branch } = await gitStatus(root);
|
|
915
|
+
const remote = await fetchRemote(root, branch, await remoteNames(root));
|
|
916
|
+
await network(root, ["fetch", "--no-recurse-submodules", remote], "获取失败");
|
|
917
|
+
const { ahead, behind } = await gitStatus(root);
|
|
918
|
+
return { remote, ahead, behind };
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/** 拉取,只做快进:本地也有新提交(分叉)时不合并,不会把工作区弄成冲突状态 */
|
|
922
|
+
export async function gitPull(root: string): Promise<{ updated: boolean; short: string | null }> {
|
|
923
|
+
await assertWritable(root);
|
|
924
|
+
await assertNetworkSafe(root);
|
|
925
|
+
const before = await gitStatus(root);
|
|
926
|
+
if (!before.branch) throw new GitError(409, "现在不在任何分支上(分离头指针),没法拉取");
|
|
927
|
+
if (!before.upstream) throw new GitError(409, `分支「${before.branch}」还没有上游,没有可以拉取的地方`);
|
|
928
|
+
const tracked = await configValue(root, `branch.${before.branch}.remote`);
|
|
929
|
+
// 「.」是跟踪本地分支,不用连网
|
|
930
|
+
if (tracked && tracked !== ".") {
|
|
931
|
+
if (!(await remoteNames(root)).includes(tracked)) throw new GitError(409, `上游的远程「${redactUrls(tracked)}」不是这个仓库配置的远程,请在终端里操作`);
|
|
932
|
+
await network(root, ["fetch", "--no-recurse-submodules", tracked], "获取失败");
|
|
933
|
+
}
|
|
934
|
+
const after = await gitStatus(root);
|
|
935
|
+
if (!after.behind) return { updated: false, short: after.head };
|
|
936
|
+
if (after.ahead) throw new GitError(409, `本地和远程已经分叉(领先 ${after.ahead},落后 ${after.behind}),面板只支持快进拉取。请在终端里合并,或者交给 agent`);
|
|
937
|
+
await network(root, ["merge", "--ff-only", "--no-stat", "--no-edit", "@{upstream}"], "拉取失败");
|
|
938
|
+
return { updated: true, short: (await gitStatus(root)).head };
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** 用了 Git LFS 的仓库:大文件靠 pre-push 钩子上传,钩子不跑的话远程只收到指针 */
|
|
942
|
+
async function usesLfs(root: string): Promise<boolean> {
|
|
943
|
+
const dir = await run(root, ["rev-parse", "--git-path", "lfs"], 4096);
|
|
944
|
+
if (dir.code === 0 && fs.existsSync(path.resolve(root, dir.stdout.trim()))) return true;
|
|
945
|
+
const attributes = await run(root, ["cat-file", "blob", "HEAD:.gitattributes"], 1024 * 1024);
|
|
946
|
+
return attributes.code === 0 && /\bfilter=lfs\b/.test(attributes.stdout);
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* 面板不让提交敏感文件,它们可能是 agent 或终端提交的;推出去就收不回来了,所以也拦一道。
|
|
951
|
+
* 文件太多看不完时同样拒绝:不能在没看完的情况下放行
|
|
952
|
+
*/
|
|
953
|
+
async function assertNoSensitiveOutgoing(root: string, remote: string): Promise<void> {
|
|
954
|
+
const out = await run(root, [...(await safeArgs(root)), "log", "-z", "--name-only", "--no-renames", "--diff-filter=d", "--format=", "HEAD", "--not", `--remotes=${remote}`], STATUS_MAX_BYTES);
|
|
955
|
+
if (out.code !== 0) throw new GitError(409, redactUrls(out.stderr.trim()) || "读取要推送的提交失败");
|
|
956
|
+
if (out.truncated) throw new GitError(409, "要推送的提交涉及的文件太多,没法检查里面有没有敏感文件,请在终端里推送");
|
|
957
|
+
const secret = out.stdout.split("\0").map((f) => f.trim()).find((f) => f && isSensitivePath(path.join(root, f)));
|
|
958
|
+
if (secret) throw new GitError(403, `要推送的提交里有「${secret}」,是密钥一类的敏感文件,不能在面板里推送。确认没问题的话请在终端里操作`);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* 推送当前分支到同名的远程分支,从不强制。还没有上游时顺手设置。
|
|
963
|
+
* 写明 refspec:不受仓库配置里的 push.default、remote.*.push 影响,点一次只动这一个分支
|
|
964
|
+
*/
|
|
965
|
+
export async function gitPush(root: string, opts: { hooks?: boolean } = {}): Promise<{ remote: string; branch: string; published: boolean }> {
|
|
966
|
+
await assertNetworkSafe(root);
|
|
967
|
+
const status = await gitStatus(root);
|
|
968
|
+
const branch = status.branch;
|
|
969
|
+
if (!branch) throw new GitError(409, "现在不在任何分支上(分离头指针),没法推送");
|
|
970
|
+
if (!status.head) throw new GitError(409, "这个分支还没有提交,没有可以推送的内容");
|
|
971
|
+
const remote = await pushRemote(root, branch, await remoteNames(root));
|
|
972
|
+
// 和 git 默认的 push.default=simple 一样:跟踪的分支名字不同(比如 feature 跟踪 origin/main)时不猜
|
|
973
|
+
if (status.upstream && (await configValue(root, `branch.${branch}.remote`)) === remote) {
|
|
974
|
+
const merge = await configValue(root, `branch.${branch}.merge`);
|
|
975
|
+
if (merge !== `refs/heads/${branch}`) throw new GitError(409, `分支「${branch}」跟踪的是「${status.upstream}」,名字不一样。为了不推错地方,请在终端里操作`);
|
|
976
|
+
}
|
|
977
|
+
if (!opts.hooks && (await usesLfs(root))) throw new GitError(409, "这个仓库用了 Git LFS,不跑钩子时大文件传不上去。请勾选「运行 Git 钩子」,或者在终端里推送");
|
|
978
|
+
await assertNoSensitiveOutgoing(root, remote);
|
|
979
|
+
const published = !status.upstream;
|
|
980
|
+
await network(
|
|
981
|
+
root,
|
|
982
|
+
["push", "--recurse-submodules=no", "--no-signed", ...(published ? ["--set-upstream"] : []), remote, `refs/heads/${branch}:refs/heads/${branch}`],
|
|
983
|
+
"推送失败",
|
|
984
|
+
opts,
|
|
985
|
+
);
|
|
986
|
+
return { remote, branch, published };
|
|
987
|
+
}
|
|
988
|
+
|
|
799
989
|
// ---------- 撤销一轮 ----------
|
|
800
990
|
|
|
801
991
|
/** 两棵 tree 里内容不一样的文件。不做重命名检测:撤销时重命名就是一删一增 */
|
package/src/core/users.ts
CHANGED
|
@@ -32,6 +32,8 @@ export type User = {
|
|
|
32
32
|
remote?: boolean;
|
|
33
33
|
/** 成员能不能用工作区面板(浏览文件、看 Git 改动)。管理员一直能用,不看这个 */
|
|
34
34
|
files?: boolean;
|
|
35
|
+
/** 成员能不能在工作区面板里获取、拉取、推送(用的是服务器上的 Git 凭据)。管理员一直能用,不看这个 */
|
|
36
|
+
gitRemote?: boolean;
|
|
35
37
|
permissions?: ResourcePermissions;
|
|
36
38
|
};
|
|
37
39
|
|
|
@@ -185,6 +187,12 @@ export function canUseFiles(user: Pick<User, "role" | "disabled" | "files"> | un
|
|
|
185
187
|
return user.role === "admin" || user.files === true;
|
|
186
188
|
}
|
|
187
189
|
|
|
190
|
+
/** 能不能在工作区面板里连远程:用的是服务器主人的 Git 身份,所以比面板本身多一道开关。成员要两个都开 */
|
|
191
|
+
export function canUseGitRemote(user: Pick<User, "role" | "disabled" | "files" | "gitRemote"> | undefined): boolean {
|
|
192
|
+
if (!canUseFiles(user)) return false;
|
|
193
|
+
return user!.role === "admin" || user!.gitRemote === true;
|
|
194
|
+
}
|
|
195
|
+
|
|
188
196
|
export function canUseResource(user: Pick<User, "role" | "disabled" | "permissions"> | undefined, kind: ResourceKind, id: string): boolean {
|
|
189
197
|
if (!user || user.disabled) return false;
|
|
190
198
|
return user.role === "admin" || user.permissions?.[kind] == null || user.permissions[kind]!.includes(id);
|
|
@@ -241,7 +249,7 @@ function assertAdminLeft(list: User[]): void {
|
|
|
241
249
|
if (!list.some((u) => u.role === "admin" && !u.disabled)) throw new Error("至少要保留一个能登录的管理员");
|
|
242
250
|
}
|
|
243
251
|
|
|
244
|
-
export function createUser(params: { name: string; password: string; role?: Role; remote?: boolean; files?: boolean; permissions?: unknown }): PublicUser {
|
|
252
|
+
export function createUser(params: { name: string; password: string; role?: Role; remote?: boolean; files?: boolean; gitRemote?: boolean; permissions?: unknown }): PublicUser {
|
|
245
253
|
const list = load();
|
|
246
254
|
const name = checkName(params.name);
|
|
247
255
|
if (list.some((u) => u.name.toLowerCase() === name.toLowerCase())) throw new Error(`用户名「${name}」已经有人用了`);
|
|
@@ -254,6 +262,7 @@ export function createUser(params: { name: string; password: string; role?: Role
|
|
|
254
262
|
createdAt: Date.now(),
|
|
255
263
|
...(params.remote === true ? { remote: true } : {}),
|
|
256
264
|
...(params.files === true ? { files: true } : {}),
|
|
265
|
+
...(params.gitRemote === true ? { gitRemote: true } : {}),
|
|
257
266
|
...(params.permissions !== undefined ? { permissions: cleanPermissions(params.permissions) } : {}),
|
|
258
267
|
};
|
|
259
268
|
save([...list, user]);
|
|
@@ -262,7 +271,7 @@ export function createUser(params: { name: string; password: string; role?: Role
|
|
|
262
271
|
|
|
263
272
|
export function updateUser(
|
|
264
273
|
id: string,
|
|
265
|
-
patch: { name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean; files?: boolean; permissions?: unknown },
|
|
274
|
+
patch: { name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean; files?: boolean; gitRemote?: boolean; permissions?: unknown },
|
|
266
275
|
): PublicUser {
|
|
267
276
|
const list = load().map((u) => ({ ...u }));
|
|
268
277
|
const user = list.find((u) => u.id === id);
|
|
@@ -285,6 +294,10 @@ export function updateUser(
|
|
|
285
294
|
if (patch.files) user.files = true;
|
|
286
295
|
else delete user.files;
|
|
287
296
|
}
|
|
297
|
+
if (patch.gitRemote !== undefined) {
|
|
298
|
+
if (patch.gitRemote) user.gitRemote = true;
|
|
299
|
+
else delete user.gitRemote;
|
|
300
|
+
}
|
|
288
301
|
if (patch.permissions !== undefined) user.permissions = cleanPermissions(patch.permissions, user.permissions);
|
|
289
302
|
if (patch.password !== undefined) {
|
|
290
303
|
checkPassword(patch.password);
|
package/web/css/workspace.css
CHANGED
|
@@ -615,6 +615,30 @@ button.ws-row:hover {
|
|
|
615
615
|
font-size: 12px;
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
+
.ws-sync-bar {
|
|
619
|
+
display: flex;
|
|
620
|
+
align-items: center;
|
|
621
|
+
gap: 6px;
|
|
622
|
+
flex-shrink: 0;
|
|
623
|
+
padding: 6px 12px;
|
|
624
|
+
border-bottom: 1px solid var(--border);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
.ws-sync-url {
|
|
628
|
+
flex: 1;
|
|
629
|
+
min-width: 0;
|
|
630
|
+
overflow: hidden;
|
|
631
|
+
color: var(--fg-faint);
|
|
632
|
+
font-family: var(--mono);
|
|
633
|
+
font-size: 11.5px;
|
|
634
|
+
text-overflow: ellipsis;
|
|
635
|
+
white-space: nowrap;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
.ws-sync-bar .btn {
|
|
639
|
+
flex-shrink: 0;
|
|
640
|
+
}
|
|
641
|
+
|
|
618
642
|
.ws-caret {
|
|
619
643
|
display: inline-grid;
|
|
620
644
|
margin-left: auto;
|
package/web/settings/users.js
CHANGED
|
@@ -151,6 +151,25 @@ export async function usersTab(page) {
|
|
|
151
151
|
}),
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
+
// 连 Git 远程:用的是服务器的凭据,默认谁都没有,开了工作区面板的成员才用得上
|
|
155
|
+
if (u.role !== "admin" && (u.files || u.gitRemote)) {
|
|
156
|
+
items.push({
|
|
157
|
+
label: u.gitRemote ? "关闭 Git 远程操作" : "开通 Git 远程操作…",
|
|
158
|
+
onclick: act(async () => {
|
|
159
|
+
if (!u.gitRemote) {
|
|
160
|
+
const sure = await confirmDialog({
|
|
161
|
+
title: `给「${u.name}」开通 Git 远程操作?`,
|
|
162
|
+
message: "他能在工作区面板里获取、拉取、推送,用的是这台服务器上配置的 Git 账号和密钥,提交会以这个账号的权限推到远程。不会强制推送。只开给你信任的人。",
|
|
163
|
+
confirmText: "开通",
|
|
164
|
+
danger: true,
|
|
165
|
+
});
|
|
166
|
+
if (!sure) return false;
|
|
167
|
+
}
|
|
168
|
+
await patch(u, { gitRemote: !u.gitRemote });
|
|
169
|
+
toast(u.gitRemote ? "已关闭" : "已开通");
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
154
173
|
items.push("sep");
|
|
155
174
|
if (u.feishuLinks) {
|
|
156
175
|
items.push({
|
|
@@ -227,6 +246,7 @@ export async function usersTab(page) {
|
|
|
227
246
|
u.disabled ? h("span", { class: "status-tag bad" }, "已停用") : null,
|
|
228
247
|
u.role !== "admin" && u.remote ? h("span", { class: "status-tag" }, "远程控制") : null,
|
|
229
248
|
u.role !== "admin" && u.files ? h("span", { class: "status-tag" }, "工作区面板") : null,
|
|
249
|
+
u.role !== "admin" && u.files && u.gitRemote ? h("span", { class: "status-tag" }, "Git 远程") : null,
|
|
230
250
|
),
|
|
231
251
|
h("div", { class: "s" }, `创建于 ${relTime(u.createdAt)} · ${u.devices} 台设备已登录${u.feishuLinks ? ` · 绑定了 ${u.feishuLinks} 个飞书账号` : ""}`),
|
|
232
252
|
),
|
|
@@ -247,9 +267,11 @@ export async function usersTab(page) {
|
|
|
247
267
|
const permissions = permissionFields(data.resources);
|
|
248
268
|
const remote = h("input", { type: "checkbox" });
|
|
249
269
|
const files = h("input", { type: "checkbox" });
|
|
270
|
+
const gitRemote = h("input", { type: "checkbox" });
|
|
250
271
|
const memberOptions = h("div", { class: "user-permissions" }, permissions.el,
|
|
251
272
|
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")))
|
|
273
|
+
h("div", { class: "field" }, h("span", {}, "文件权限"), h("label", { class: "check-item" }, files, h("span", {}, "允许用工作区面板读写文件、操作 Git"))),
|
|
274
|
+
h("div", { class: "field" }, h("span", {}, "Git 远程权限"), h("label", { class: "check-item" }, gitRemote, h("span", {}, "允许用服务器的 Git 账号获取、拉取、推送(还要开文件权限)"))));
|
|
253
275
|
role.onchange = () => { memberOptions.hidden = role.value === "admin"; };
|
|
254
276
|
fill(
|
|
255
277
|
addBox,
|
|
@@ -266,8 +288,13 @@ export async function usersTab(page) {
|
|
|
266
288
|
message: "他能以运行 agent-loft 的系统用户直接使用终端和桌面,读写服务器上的文件、安装软件、停止服务,不经过授权卡。只开给完全信任的人。",
|
|
267
289
|
confirmText: "开通并添加", danger: true,
|
|
268
290
|
}))) return false;
|
|
291
|
+
if (role.value === "member" && gitRemote.checked && !(await confirmDialog({
|
|
292
|
+
title: `给「${name.value.trim()}」开通 Git 远程操作?`,
|
|
293
|
+
message: "他能用这台服务器上配置的 Git 账号和密钥获取、拉取、推送。不会强制推送。只开给你信任的人。",
|
|
294
|
+
confirmText: "开通并添加", danger: true,
|
|
295
|
+
}))) return false;
|
|
269
296
|
await api("/api/users", { method: "POST", body: { name: name.value.trim(), password: pw.value, role: role.value,
|
|
270
|
-
...(role.value === "member" ? { remote: remote.checked, files: files.checked, permissions: permissions.value() } : {}) } });
|
|
297
|
+
...(role.value === "member" ? { remote: remote.checked, files: files.checked, gitRemote: gitRemote.checked, permissions: permissions.value() } : {}) } });
|
|
271
298
|
toast(`已添加「${name.value.trim()}」`);
|
|
272
299
|
close();
|
|
273
300
|
reload();
|
package/web/views/workspace.js
CHANGED
|
@@ -627,6 +627,43 @@ function branchBar(s) {
|
|
|
627
627
|
);
|
|
628
628
|
}
|
|
629
629
|
|
|
630
|
+
// 和远程同步:要连网,可能要跑很久,同一时间只做一个。显示连到哪,别人的仓库配置可能把地址改了
|
|
631
|
+
let syncBusy = null;
|
|
632
|
+
|
|
633
|
+
async function sync(kind) {
|
|
634
|
+
if (syncBusy) return;
|
|
635
|
+
syncBusy = kind;
|
|
636
|
+
renderChanges();
|
|
637
|
+
const body = kind === "push" ? { hooks: commitUi.hooks.checked } : {};
|
|
638
|
+
const result = await gitAct(`git-${kind}`, body);
|
|
639
|
+
syncBusy = null;
|
|
640
|
+
renderChanges();
|
|
641
|
+
if (!result) return;
|
|
642
|
+
if (kind === "fetch") toast(result.behind ? `已获取 ${result.remote},落后 ${result.behind} 个提交` : `已获取 ${result.remote}`);
|
|
643
|
+
else if (kind === "pull") toast(result.updated ? `已快进到 ${result.short}` : "已经是最新的");
|
|
644
|
+
else toast(result.published ? `已发布到 ${result.remote}/${result.branch}` : `已推送到 ${result.remote}/${result.branch}`);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function syncBar(s) {
|
|
648
|
+
if (!S.user?.gitRemote || !s.pushUrl) return null;
|
|
649
|
+
const button = (kind, label, busyLabel, title, enabled = true) =>
|
|
650
|
+
h("button", { class: "btn small", title, disabled: !!syncBusy || !enabled, onclick: () => void sync(kind) }, syncBusy === kind ? busyLabel : label);
|
|
651
|
+
return h(
|
|
652
|
+
"div",
|
|
653
|
+
{ class: "ws-sync-bar" },
|
|
654
|
+
h("span", { class: "ws-sync-url", title: `推送到 ${s.pushUrl}` }, s.pushUrl),
|
|
655
|
+
button("fetch", "获取", "获取中…", "更新远程分支的信息,不动工作区"),
|
|
656
|
+
button("pull", s.behind ? `拉取 ↓${s.behind}` : "拉取", "拉取中…", s.upstream ? "只做快进;本地和远程分叉时不会合并" : "这个分支还没有上游", !!s.branch && !!s.upstream),
|
|
657
|
+
button(
|
|
658
|
+
"push",
|
|
659
|
+
!s.upstream ? "发布分支" : s.ahead ? `推送 ↑${s.ahead}` : "推送",
|
|
660
|
+
"推送中…",
|
|
661
|
+
s.branch ? "不会强制推送。勾选了「运行 Git 钩子」时会跑 pre-push 钩子" : "现在不在任何分支上",
|
|
662
|
+
!!s.branch && !!s.head && (!s.upstream || s.ahead > 0),
|
|
663
|
+
),
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
|
|
630
667
|
// 提交框:一直是同一组元素。改动列表刷新时不动它,打到一半的字和光标都还在
|
|
631
668
|
const HOOKS_KEY = "aim.wsCommitHooks";
|
|
632
669
|
const commitUi = {
|
|
@@ -707,7 +744,7 @@ function renderChanges() {
|
|
|
707
744
|
const untracked = s.files.filter((f) => f.unstaged === "untracked");
|
|
708
745
|
commitUi.stagedCount = staged.length;
|
|
709
746
|
updateCommitButton();
|
|
710
|
-
fill(ui.wsBranchSlot, branchBar(s));
|
|
747
|
+
fill(ui.wsBranchSlot, branchBar(s), syncBar(s));
|
|
711
748
|
|
|
712
749
|
const paths = (files) => files.filter((f) => !f.sensitive).map((f) => f.path);
|
|
713
750
|
const stageAll = (files) => (paths(files).length ? { title: "全部暂存", icon: "plus", onclick: () => void gitAct("git-stage", { paths: paths(files) }) } : null);
|