agent-loft 0.2.96 → 0.2.98

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.
@@ -189,7 +189,7 @@ const SKILL_TOOLS = [
189
189
  name: "skill_request",
190
190
  description:
191
191
  "替你发一个 HTTP 请求,url、headers、body 里的 {{变量名}} 由 agent-loft 换成用户在技能里填的值 —— 你看不到密钥本身。" +
192
- "技能里的受保护密钥(list_skills 里标了「受保护」的)只能这样用,而且只能发往用户确认过的地址;普通变量也可以这样用。" +
192
+ "技能里的受保护密钥(list_skills 里标了「受保护」的)只能这样用:只能写在 headers 或 url 的查询参数(? 后面)里,不能写进 body 和 url 的主机、路径;只发往用户确认过的地址,公网地址要用 https。普通变量写在哪都行。" +
193
193
  "不跟随跳转;响应里出现的变量值会被抹掉;最多返回 256KB 文本。",
194
194
  inputSchema: {
195
195
  type: "object",
@@ -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;
@@ -522,7 +522,11 @@ export async function mcpTab(panel) {
522
522
  await load();
523
523
  }
524
524
 
525
+ /** 这个账号能不能添加本机进程(stdio)MCP:只有管理员 */
526
+ let canStdio = true;
527
+
525
528
  function renderMcp(box, data, reload) {
529
+ canStdio = data.stdio !== false;
526
530
  fill(
527
531
  box,
528
532
  h(
@@ -531,7 +535,8 @@ function renderMcp(box, data, reload) {
531
535
  h(
532
536
  "p",
533
537
  { class: "skill-note" },
534
- "MCP 服务提供查数据、调接口等工具,只供你自己的账号使用。这里加好后,自定义专家在「专家」里勾选;内置的 Claude Code / Codex 在「Agent」各自卡片的「默认加载」中选择。",
538
+ "MCP 服务提供查数据、调接口等工具。这里加好后,自定义专家在「专家」里勾选;内置的 Claude Code / Codex 在「Agent」各自卡片的「默认加载」中选择。可以把自己的 MCP 共享给所有账号:别人拿到的是地址、命令这些设置,标成密钥的项各自填自己的值,你的密钥不会给出去;别人用共享的 MCP 时,调用工具前都会先询问。" +
539
+ (canStdio ? "" : "本机进程(stdio)会在服务器上直接执行命令,只有管理员能添加。"),
535
540
  ),
536
541
  h("div", { class: "skill-head-btns" }, h("button", { class: "btn primary", onclick: () => openMcpEditor(null, reload) }, icon("plus"), "添加")),
537
542
  ),
@@ -540,23 +545,30 @@ function renderMcp(box, data, reload) {
540
545
  "div",
541
546
  { class: "task-list" },
542
547
  data.servers.map((s) => {
548
+ const secrets = [...(s.env ?? []), ...(s.headers ?? [])].filter((p) => p.secret);
549
+ const open = () => (s.mine ? openMcpEditor(s, reload) : secrets.length ? openMcpValues(s, secrets, reload) : null);
543
550
  const more = h("button", { class: "icon-btn", title: "更多" }, icon("more"));
544
551
  more.onclick = () =>
545
- showMenu(more, [
546
- { label: "编辑…", onclick: () => openMcpEditor(s, reload) },
547
- "sep",
548
- { label: "删除", danger: true, onclick: () => removeMcp(s, reload) },
549
- ]);
552
+ showMenu(
553
+ more,
554
+ s.mine
555
+ ? [{ label: "编辑…", onclick: () => openMcpEditor(s, reload) }, "sep", { label: "删除", danger: true, onclick: () => removeMcp(s, reload) }]
556
+ : [{ label: secrets.length ? "填写我的密钥…" : "不需要填写密钥", onclick: () => secrets.length && openMcpValues(s, secrets, reload) }],
557
+ );
558
+ const missing = !s.mine && secrets.some((p) => !p.set);
550
559
  return h(
551
560
  "div",
552
561
  { class: "task-card skill-card" },
553
- h("div", { class: "task-top" }, h("button", { class: "task-title skill-name", onclick: () => openMcpEditor(s, reload) }, s.name), more),
562
+ h("div", { class: "task-top" }, h("button", { class: "task-title skill-name", onclick: open }, s.name), more),
554
563
  h(
555
564
  "div",
556
565
  { class: "task-meta" },
566
+ s.mine ? (s.shared ? h("span", {}, "已共享给所有人") : null) : h("span", {}, `${s.ownerName} 共享`),
557
567
  h("span", {}, s.type === "http" ? "HTTP" : "本机进程"),
558
568
  h("span", { class: "mono" }, s.type === "http" ? s.url : [s.command, ...s.args].join(" ")),
559
- s.ask ? h("span", {}, "调用前询问") : null,
569
+ !s.runnable ? h("span", { class: "skill-warn" }, "已停用:本机进程只有管理员能用,请改用 HTTP 或删除") : null,
570
+ missing ? h("span", { class: "skill-warn" }, "密钥没填") : null,
571
+ s.ask || !s.mine ? h("span", {}, "调用前询问") : null,
560
572
  h("span", {}, s.usedBy.length ? `${s.usedBy.join("、")} 在用` : "还没有专家用它"),
561
573
  ),
562
574
  s.description ? h("div", { class: "task-prompt" }, s.description) : null,
@@ -567,6 +579,40 @@ function renderMcp(box, data, reload) {
567
579
  );
568
580
  }
569
581
 
582
+ /** 别人共享的 MCP:填自己的密钥(作者的不会给你) */
583
+ function openMcpValues(s, secrets, reload) {
584
+ const rows = secrets.map((p) => {
585
+ const input = h("input", { type: "password", autocomplete: "off", spellcheck: "false", placeholder: p.set ? "已填写(不显示),留空不改" : "填你自己的值" });
586
+ const clear = p.set ? h("button", { type: "button", class: "btn ghost", onclick: () => ((input.dataset.clear = "1"), (input.value = ""), (clear.hidden = true)) }, "清除") : null;
587
+ return { p, input, el: h("div", { class: "field" }, h("span", {}, h("code", {}, p.name)), h("div", { class: "skill-var-row" }, input, clear)) };
588
+ });
589
+ const save = h("button", { class: "btn primary" }, "保存");
590
+ const close = modal({
591
+ title: `${s.name} 的密钥`,
592
+ body: h("div", { class: "modal-body task-form" }, h("p", { class: "skill-note" }, `${s.ownerName} 共享的 MCP。这些值只给你自己的会话用,作者看不到;不填就不带这一项。`), rows.map((r) => r.el)),
593
+ foot: h("div", { class: "modal-foot" }, save),
594
+ });
595
+ rows[0]?.input.focus();
596
+ save.onclick = async () => {
597
+ const values = {};
598
+ for (const r of rows) {
599
+ if (r.input.value) values[r.p.name] = r.input.value;
600
+ else if (r.input.dataset.clear === "1") values[r.p.name] = null;
601
+ }
602
+ if (!Object.keys(values).length) return close();
603
+ save.disabled = true;
604
+ try {
605
+ await api(`/api/mcp/${s.id}/values`, { method: "PUT", body: { values } });
606
+ close();
607
+ toast("已保存,新消息起生效");
608
+ void reload();
609
+ } catch (err) {
610
+ save.disabled = false;
611
+ toast(err.message);
612
+ }
613
+ };
614
+ }
615
+
570
616
  async function removeMcp(s, reload) {
571
617
  const sure = await confirmDialog({
572
618
  title: `删除 MCP「${s.name}」?`,
@@ -611,8 +657,8 @@ function openMcpEditor(s, reload) {
611
657
  const type = h(
612
658
  "select",
613
659
  { disabled: !!s },
614
- h("option", { value: "stdio", selected: (s?.type ?? "stdio") === "stdio" }, "本机进程(stdio)"),
615
- h("option", { value: "http", selected: s?.type === "http" }, "HTTP 地址"),
660
+ canStdio || s?.type === "stdio" ? h("option", { value: "stdio", selected: (s?.type ?? (canStdio ? "stdio" : "http")) === "stdio" }, "本机进程(stdio)") : null,
661
+ h("option", { value: "http", selected: (s?.type ?? (canStdio ? "stdio" : "http")) === "http" }, "HTTP 地址"),
616
662
  );
617
663
  const command = h("input", { value: s?.command ?? "", placeholder: "比如 npx、python、/usr/local/bin/xxx-mcp", spellcheck: "false" });
618
664
  const args = h("textarea", { rows: 3, placeholder: "一行一个参数,比如:\n-y\n@modelcontextprotocol/server-fetch", spellcheck: "false" });
@@ -621,6 +667,7 @@ function openMcpEditor(s, reload) {
621
667
  const env = pairsEditor(s?.env, "env");
622
668
  const headers = pairsEditor(s?.headers, "header");
623
669
  const ask = h("input", { type: "checkbox", checked: !!s?.ask });
670
+ const shared = h("input", { type: "checkbox", checked: !!s?.shared });
624
671
  const stdioPart = h("div", { class: "field-group" }, field("命令", command), field("参数", args), field("环境变量", env.el, "比如 API 密钥。标成密钥的网页上不回显,只交给这个 MCP 进程,agent 看不到"));
625
672
  const httpPart = h("div", { class: "field-group" }, field("地址", url), field("请求头", headers.el, "比如 Authorization: Bearer xxx。标成密钥的网页上不回显"));
626
673
  const sync = () => {
@@ -638,6 +685,11 @@ function openMcpEditor(s, reload) {
638
685
  stdioPart,
639
686
  httpPart,
640
687
  field("授权", h("label", { class: "check-item" }, ask, h("span", {}, "调用它的工具前先问我(不勾就直接用:这是你自己给专家挂的)"))),
688
+ field(
689
+ "共享",
690
+ h("label", { class: "check-item" }, shared, h("span", {}, "共享给所有账号")),
691
+ "别人拿到命令、地址和普通的环境变量 / 请求头;标成「密钥」的项各自填自己的值,你填的不会给出去。取消共享后别人填的值一起删掉",
692
+ ),
641
693
  );
642
694
  const save = h("button", { class: "btn primary" }, s ? "保存" : "添加");
643
695
  const close = modal({ title: s ? `编辑 ${s.name}` : "添加 MCP", wide: true, body, foot: h("div", { class: "modal-foot" }, save) });
@@ -646,6 +698,7 @@ function openMcpEditor(s, reload) {
646
698
  const payload = {
647
699
  description: desc.value,
648
700
  ask: ask.checked,
701
+ shared: shared.checked,
649
702
  ...(type.value === "stdio"
650
703
  ? {
651
704
  command: command.value,
@@ -121,7 +121,7 @@ function renderList() {
121
121
  if (K.tab === "shared") {
122
122
  const list = shared().filter(matches);
123
123
  return [
124
- h("p", { class: "skill-note" }, "这里是其他用户共享给你的技能。安装前可点开查看说明和附带文件;安装后跟随作者更新,撤回共享后将无法再用。变量和密钥使用你自己填写的值。"),
124
+ h("p", { class: "skill-note" }, "这里是其他用户共享给你的技能。安装前可点开查看说明和附带文件;作者改了内容后,要你看过并确认新版才会继续加载,撤回共享后将无法再用。变量和密钥使用你自己填写的值。"),
125
125
  list.length ? h("div", { class: "task-list" }, list.map(sharedCard)) : h("div", { class: "skill-empty" }, K.query ? "没有找到" : "还没有别人共享给你的技能"),
126
126
  ];
127
127
  }
@@ -142,7 +142,7 @@ function renderList() {
142
142
  function varsState(s) {
143
143
  if (!s.vars.length) return null;
144
144
  const missing = s.vars.filter((v) => v.required && !K.data.vars[v.name]?.set);
145
- const pending = s.vars.filter((v) => K.data.vars[v.name]?.pending);
145
+ const pending = s.vars.filter((v) => s.hosts?.[v.name]?.pending?.length);
146
146
  if (missing.length) return h("span", { class: "skill-warn" }, `${missing.length} 个变量没填`);
147
147
  if (pending.length) return h("span", { class: "skill-warn" }, "密钥的发送地址待确认");
148
148
  return h("span", {}, `${s.vars.length} 个变量`);
@@ -150,7 +150,7 @@ function varsState(s) {
150
150
 
151
151
  /** 要去「填写变量」处理的:必填的没填,或者受保护密钥的地址待确认 */
152
152
  function varsNeedAttention(s) {
153
- return s.vars.some((v) => (v.required && !K.data.vars[v.name]?.set) || K.data.vars[v.name]?.pending);
153
+ return s.vars.some((v) => (v.required && !K.data.vars[v.name]?.set) || s.hosts?.[v.name]?.pending?.length);
154
154
  }
155
155
 
156
156
  function mineCard(s) {
@@ -199,26 +199,29 @@ function mineCard(s) {
199
199
  s.mine && SHARED[s.visibility] ? h("span", {}, SHARED[s.visibility]) : null,
200
200
  s.mine && s.installs ? h("span", {}, `${s.installs} 人安装`) : null,
201
201
  s.source === "agent" ? h("span", {}, "agent 生成") : null,
202
+ s.updatePending ? h("span", { class: "skill-warn" }, "作者已更新,待确认") : null,
202
203
  varsState(s),
203
204
  ),
204
205
  h("div", { class: "task-prompt" }, s.description),
205
- varsNeedAttention(s)
206
+ s.updatePending
207
+ ? h("button", { class: "task-run", onclick: () => openDetail(s) }, "作者更新了内容,查看并确认后才会继续加载 →")
208
+ : varsNeedAttention(s)
206
209
  ? h("button", { class: "task-run", onclick: () => openVars(s) }, s.vars.some((v) => v.required && !K.data.vars[v.name]?.set) ? "填写变量后才能正常使用 →" : "确认密钥的发送地址 →")
207
210
  : null,
208
211
  );
209
212
  }
210
213
 
211
214
  function sharedCard(s) {
212
- const install = h("button", { class: "btn primary", onclick: () => installShared(s, install) }, "安装");
215
+ const install = s.canInstall ? h("button", { class: "btn primary", onclick: () => installShared(s, install) }, "安装") : null;
213
216
  return h(
214
217
  "div",
215
218
  { class: "task-card skill-card" },
216
219
  h("div", { class: "task-top" },
217
220
  h("button", { class: "task-title skill-name", title: "查看", onclick: () => openDetail(s) }, s.name),
218
- s.installed ? h("span", { class: "badge" }, s.enabled ? "已安装" : "已安装 · 已停用") : install,
221
+ s.installed ? h("span", { class: "badge" }, s.updatePending ? "已安装 · 有更新待确认" : s.enabled ? "已安装" : "已安装 · 已停用") : install,
219
222
  s.canDelete ? h("button", { class: "btn", onclick: () => removeSkill(s) }, "下架") : null,
220
223
  ),
221
- h("div", { class: "task-meta" }, h("span", {}, `${s.ownerName} 建的`), h("span", {}, SHARED[s.visibility]), s.vars.length ? h("span", {}, `${s.vars.length} 个变量`) : null),
224
+ h("div", { class: "task-meta" }, h("span", {}, `${s.ownerName} 建的`), h("span", {}, s.canInstall ? SHARED[s.visibility] : "分享给了别人(管理员可查看、下架)"), s.vars.length ? h("span", {}, `${s.vars.length} 个变量`) : null),
222
225
  h("div", { class: "task-prompt" }, s.description),
223
226
  );
224
227
  }
@@ -298,7 +301,23 @@ async function openDetail(s) {
298
301
  return;
299
302
  }
300
303
  if (d.mine) foot.append(h("button", { class: "btn", onclick: () => (close(), openSharing(d)) }, "共享…"));
301
- else if (!d.installed) {
304
+ else if (d.updatePending) {
305
+ const accept = h("button", { class: "btn primary" }, "确认使用新版");
306
+ accept.onclick = async () => {
307
+ accept.disabled = true;
308
+ try {
309
+ const next = await api(`/api/skills/${d.id}/accept`, { method: "POST", body: {} });
310
+ toast("已确认,新消息起加载新版");
311
+ close();
312
+ await reload();
313
+ if (varsNeedAttention(next)) openVars(next);
314
+ } catch (err) {
315
+ accept.disabled = false;
316
+ toast(err.message);
317
+ }
318
+ };
319
+ foot.append(accept);
320
+ } else if (!d.installed && d.canInstall) {
302
321
  const install = h("button", { class: "btn primary", onclick: async () => { if (await installShared(d, install)) close(); } }, "安装");
303
322
  foot.append(install);
304
323
  }
@@ -312,6 +331,9 @@ async function openDetail(s) {
312
331
  h("span", {}, SHARED[d.visibility]),
313
332
  h("span", {}, `更新于 ${new Date(d.updatedAt).toLocaleString()}`),
314
333
  ),
334
+ d.updatePending
335
+ ? h("p", { class: "skill-pending" }, "作者在你安装之后改过这个技能(说明、附带文件或变量)。下面是现在的内容,看过没问题再点「确认使用新版」;确认之前你的会话不会加载它。")
336
+ : null,
315
337
  h("p", { class: "skill-desc" }, d.description),
316
338
  d.vars.length
317
339
  ? h(
@@ -400,15 +422,18 @@ function openVars(s) {
400
422
  });
401
423
  const clear = cur?.set ? h("button", { type: "button", class: "btn ghost", onclick: () => ((input.value = ""), (input.dataset.clear = "1"), (clear.hidden = true)) }, "清除") : null;
402
424
  // 受保护的密钥:agent 看不到值,只能经 agent-loft 发往这些地址;作者改了地址要这里再确认
425
+ const hosts = s.hosts?.[v.name];
403
426
  const guard = v.secret && v.hosts?.length
404
- ? h("small", { class: "skill-guard" }, `受保护:agent 看不到这个值,只能通过 agent-loft 代发请求,发往 ${(cur?.hosts?.length ? cur.hosts : v.hosts).join("、")}。填写即表示同意发往这些地址。`)
405
- : null;
427
+ ? h("small", { class: "skill-guard" }, `受保护:agent 看不到这个值,只能通过 agent-loft 代发请求。${cur?.set && hosts?.allowed?.length ? `这个技能可以发往 ${hosts.allowed.join("、")}。` : `填写即表示同意这个技能发往 ${v.hosts.join("、")}(别的技能声明的地址要在各自的变量页里另外确认)。`}`)
428
+ : cur?.guarded
429
+ ? h("small", { class: "skill-guard" }, "这个值是按受保护的密钥填的,不会作为环境变量交给 agent。要当普通变量用,请在这里重新填写。")
430
+ : null;
406
431
  const r = { v, input, approve: false };
407
- const pending = cur?.pending?.length
432
+ const pending = hosts?.pending?.length
408
433
  ? h(
409
434
  "div",
410
435
  { class: "skill-pending" },
411
- `作者新加了发送地址:${cur.pending.join("、")}。确认之前,这个密钥不会发往新地址。`,
436
+ `这个技能要把 ${v.name} 发往还没确认过的地址:${hosts.pending.join("、")}。确认之前,不会发往这些地址。`,
412
437
  h("button", { type: "button", class: "btn small", onclick: (e) => ((r.approve = true), (e.currentTarget.textContent = "保存后生效"), (e.currentTarget.disabled = true)) }, "确认"),
413
438
  )
414
439
  : null;
@@ -446,7 +471,7 @@ function openVars(s) {
446
471
  if (!Object.keys(values).length && !approve.length) return close();
447
472
  save.disabled = true;
448
473
  try {
449
- await api("/api/skills/vars", { method: "PUT", body: { values, approve } });
474
+ await api("/api/skills/vars", { method: "PUT", body: { values, approve, skill: s.id } });
450
475
  close();
451
476
  toast("已保存,新消息起生效");
452
477
  void reload();
@@ -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();
@@ -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);