dsh-supermesh 0.0.2 → 0.0.4

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.
@@ -793,6 +793,12 @@ var Project = class extends Model {
793
793
  if (enabled) query = query.where("remoteUrl", "is not", null).where("remoteUrl", "!=", "");
794
794
  return query.returningAll().executeTakeFirst();
795
795
  }
796
+ async setRemoteUrl(id, remoteUrl, updatedAt) {
797
+ await this.db.updateTable("project").set({
798
+ remoteUrl,
799
+ updatedAt
800
+ }).where("id", "=", id).execute();
801
+ }
796
802
  async disableUnavailable(workspaceIds, updatedAt) {
797
803
  let query = this.db.updateTable("project").set({
798
804
  enabled: 0,
@@ -854,6 +860,19 @@ var SourceState = class {
854
860
  async remove(channelId, name) {
855
861
  await this.db.deleteFrom("source_state").where("channelId", "=", channelId).where("name", "=", name).execute();
856
862
  }
863
+ /**
864
+ * 仓库改名后把旧作用域的游标整体搬到新作用域。
865
+ * 不搬的话采集会从「此刻」重新开始,改名瞬间未采集的增量就永久丢了。
866
+ */
867
+ async renameScope(channelId, from, to, updatedAt) {
868
+ for (const row of await this.listByChannel(channelId)) {
869
+ if (!row.name.startsWith(`${from}:`)) continue;
870
+ const name = `${to}:${row.name.slice(from.length + 1)}`;
871
+ if (await this.find(channelId, name)) continue;
872
+ await this.set(channelId, name, row.value, updatedAt);
873
+ await this.remove(channelId, row.name);
874
+ }
875
+ }
857
876
  };
858
877
  // src/database/models/supervisor.ts
859
878
  var Supervisor = class extends Model {
@@ -2595,6 +2614,24 @@ async function own(path, content, mode = 384) {
2595
2614
  function quote(value) {
2596
2615
  return `'${value.replaceAll("'", "'\\''")}'`;
2597
2616
  }
2617
+ // src/utils/git-identity.ts
2618
+ /**
2619
+ * 平台按邮箱归属提交,名字只影响显示。用账号的 noreply 地址才能让 bot 的提交记在 bot 名下。
2620
+ * GitHub:`<id>+<login>@users.noreply.github.com`;GitLab:`<username>@users.noreply.<host>`。
2621
+ */
2622
+ function noreplyEmail(kind, login, providerId, host) {
2623
+ const name = login.trim();
2624
+ if (!name) return "";
2625
+ if (kind === "github") {
2626
+ const id = providerId.trim();
2627
+ return /^\d+$/.test(id) ? `${id}+${name}@users.noreply.github.com` : "";
2628
+ }
2629
+ try {
2630
+ return `${name}@users.noreply.${new URL(host).host}`;
2631
+ } catch {
2632
+ return "";
2633
+ }
2634
+ }
2598
2635
  // src/service/devops.ts
2599
2636
  const authentications = /* @__PURE__ */ new Map();
2600
2637
  const active = /* @__PURE__ */ new Map();
@@ -2645,14 +2682,14 @@ const devops = defineService({
2645
2682
  },
2646
2683
  save(kind, patch) {
2647
2684
  return channel.serialize(() => save(kind, patch)).then(async (view) => {
2648
- const { shell } = await import("./shell-6EeRyaxQ.js");
2685
+ const { shell } = await import("./shell-DzrnBk4C.js");
2649
2686
  await shell.refresh();
2650
2687
  return view;
2651
2688
  });
2652
2689
  },
2653
2690
  removeCredentials(kind) {
2654
2691
  return channel.serialize(() => removeCredentials(kind)).then(async (view) => {
2655
- const { shell } = await import("./shell-6EeRyaxQ.js");
2692
+ const { shell } = await import("./shell-DzrnBk4C.js");
2656
2693
  await shell.refresh();
2657
2694
  return view;
2658
2695
  });
@@ -2700,11 +2737,20 @@ async function save(kind, patch) {
2700
2737
  if (token) account = await verify(kind, url, token);
2701
2738
  const enabled = patch.enabled ?? (Boolean(account) || current.enabled);
2702
2739
  if (enabled && !account && !current.accounts.some((account) => account.role === "bot" && account.status === "online")) throw new TypeError("channel_account_required");
2740
+ let identity = account;
2741
+ if (!identity && !current.providerId && (patch.commitName !== void 0 || patch.commitEmail !== void 0)) {
2742
+ const stored = await channel.resolveCredential(kind);
2743
+ if (stored) identity = await verify(kind, url, stored).catch(() => void 0);
2744
+ }
2745
+ const providerId = identity?.providerId ?? current.providerId;
2746
+ const login = identity?.name ?? current.accounts.find((account) => account.role === "bot")?.name ?? "";
2747
+ const commitEmail = (patch.commitEmail?.trim() ?? current.commitEmail) || noreplyEmail(kind, login, providerId, url.origin);
2703
2748
  const previous = token ? await channel.storeCredential(kind, token) : void 0;
2704
2749
  try {
2705
2750
  await db.channel.saveConfiguration(kind, current.name, kind === "gitlab" ? url.origin : null, enabled, {
2706
2751
  commitName: patch.commitName?.trim() ?? current.commitName,
2707
- commitEmail: patch.commitEmail?.trim() ?? current.commitEmail
2752
+ commitEmail,
2753
+ providerId
2708
2754
  }, account, ...hostChanged ? [true] : []);
2709
2755
  } catch {
2710
2756
  if (token) {
@@ -2748,9 +2794,14 @@ async function verify(kind, url, token) {
2748
2794
  const user = identity;
2749
2795
  const login = kind === "github" ? user.login : user.username ?? user.name;
2750
2796
  if (typeof login !== "string" || !login.trim() || login.length > 200 || /[\r\n]/.test(login)) throw new Error("channel_auth_failed");
2797
+ const id = user.id;
2798
+ if (typeof id !== "number" && typeof id !== "string") throw new Error("channel_auth_failed");
2799
+ const providerId = String(id);
2800
+ if (!/^\d+$/.test(providerId)) throw new Error("channel_auth_failed");
2751
2801
  return {
2752
2802
  name: login.trim(),
2753
- avatar: null
2803
+ avatar: null,
2804
+ providerId
2754
2805
  };
2755
2806
  } finally {
2756
2807
  await dispatcher.close();
@@ -4615,6 +4666,8 @@ const channel = defineService({
4615
4666
  const stored = await db.sourceState.find(preset.id, "configuration");
4616
4667
  const configured = hasCredential || members.length > 0 || Boolean(stored);
4617
4668
  const metadata = readMetadata(stored?.value);
4669
+ const bot = members.find((account) => account.role === "bot");
4670
+ const suggestion = bot && (preset.id === "github" || preset.id === "gitlab") ? noreplyEmail(preset.id, bot.name, metadata.providerId, row?.host ?? (preset.id === "gitlab" ? "https://gitlab.com" : "https://github.com")) : "";
4618
4671
  return {
4619
4672
  id: preset.id,
4620
4673
  kind: preset.id,
@@ -4627,7 +4680,10 @@ const channel = defineService({
4627
4680
  supported,
4628
4681
  hasCredential,
4629
4682
  status: !supported ? "unsupported" : !configured ? "unconfigured" : !enabled ? "disabled" : members.some((account) => account.role === "bot" && account.status === "online") ? "online" : "offline",
4630
- ...metadata
4683
+ commitName: metadata.commitName,
4684
+ commitEmail: metadata.commitEmail,
4685
+ commitEmailSuggestion: suggestion,
4686
+ providerId: metadata.providerId
4631
4687
  };
4632
4688
  }));
4633
4689
  },
@@ -4676,13 +4732,15 @@ function legacyRef(kind) {
4676
4732
  function readMetadata(raw) {
4677
4733
  if (!raw) return {
4678
4734
  commitName: "",
4679
- commitEmail: ""
4735
+ commitEmail: "",
4736
+ providerId: ""
4680
4737
  };
4681
4738
  const value = JSON.parse(raw);
4682
- if (!value || typeof value !== "object" || !("commitName" in value) || !("commitEmail" in value) || typeof value.commitName !== "string" || typeof value.commitEmail !== "string") throw new Error("invalid_channel_metadata");
4739
+ if (!value || typeof value !== "object" || !("commitName" in value) || !("commitEmail" in value) || typeof value.commitName !== "string" || typeof value.commitEmail !== "string" || "providerId" in value && value.providerId !== void 0 && typeof value.providerId !== "string") throw new Error("invalid_channel_metadata");
4683
4740
  return {
4684
4741
  commitName: value.commitName,
4685
- commitEmail: value.commitEmail
4742
+ commitEmail: value.commitEmail,
4743
+ providerId: "providerId" in value && typeof value.providerId === "string" ? value.providerId : ""
4686
4744
  };
4687
4745
  }
4688
4746
  export { project as a, shell as c, singlet as d, setting as f, db as g, channelProxyEnvironment as h, archive as i, inbox as l, DSH_PLUGIN_HOME as m, server as n, worktree as o, defineService as p, worker as r, devops as s, channel as t, session as u };
package/dist/client.cjs CHANGED
@@ -6416,7 +6416,10 @@ const dicts = {
6416
6416
  channelAccountDescription: "通过授权登录或 Token 验证账号,保存实际登录身份。",
6417
6417
  channelCommitName: "Git 提交名称",
6418
6418
  channelCommitEmail: "Git 提交邮箱",
6419
- channelCommitHelp: "保存 Git 提交身份;凭据与提交身份分别管理。",
6419
+ channelCommitHelp: "平台按邮箱归属提交,名字只影响显示;留空时使用渠道账号的 noreply 地址。",
6420
+ channelCommitEmailMismatchTitle: "提交邮箱不属于渠道账号",
6421
+ channelCommitEmailMismatchDescription: "{email} 归属另一个账号,提交会记到那个人名下,审计与隐私都会受影响。渠道账号的 noreply 地址是 {suggestion}。确认后仍会保存。",
6422
+ channelCommitEmailMismatchConfirm: "仍然保存",
6420
6423
  channelLoginMethod: "登录方式",
6421
6424
  channelAuthorize: "授权登录",
6422
6425
  channelAuthorizeRecommended: "推荐",
@@ -6833,7 +6836,10 @@ const dicts = {
6833
6836
  channelAccountDescription: "Specify the expected bot identity. The authenticated account must match.",
6834
6837
  channelCommitName: "Git commit name",
6835
6838
  channelCommitEmail: "Git commit email",
6836
- channelCommitHelp: "Save the Git commit identity. Credentials and commit identity are managed separately.",
6839
+ channelCommitHelp: "Commits are attributed by email; the name only affects display. Leave it empty to use the channel account noreply address.",
6840
+ channelCommitEmailMismatchTitle: "Commit email belongs to another account",
6841
+ channelCommitEmailMismatchDescription: "{email} belongs to another account, so commits are attributed to that person. The channel account noreply address is {suggestion}. Saving continues after you confirm.",
6842
+ channelCommitEmailMismatchConfirm: "Save anyway",
6837
6843
  channelLoginMethod: "Sign-in method",
6838
6844
  channelAuthorize: "Authorize",
6839
6845
  channelAuthorizeRecommended: "Recommended",
@@ -7524,8 +7530,11 @@ function GithubDetail() {
7524
7530
  const [token, setToken] = (0, react.useState)("");
7525
7531
  const [commitName, setCommitName] = (0, react.useState)(null);
7526
7532
  const [commitEmail, setCommitEmail] = (0, react.useState)(null);
7533
+ const [confirmingEmail, setConfirmingEmail] = (0, react.useState)(false);
7534
+ const suggestion = channel_0?.commitEmailSuggestion ?? "";
7527
7535
  const nameValue = commitName ?? channel_0?.commitName ?? "";
7528
- const emailValue = commitEmail ?? channel_0?.commitEmail ?? "";
7536
+ const emailValue = commitEmail ?? channel_0?.commitEmail ?? suggestion;
7537
+ const emailMismatch = Boolean(suggestion) && Boolean(emailValue.trim()) && emailValue.trim().toLowerCase() !== suggestion.toLowerCase();
7529
7538
  const hasCredential = Boolean(channel_0?.hasCredential);
7530
7539
  const identityDirty = nameValue.trim() !== (channel_0?.commitName ?? "").trim() || emailValue.trim() !== (channel_0?.commitEmail ?? "").trim();
7531
7540
  const dirty = token.length > 0 || identityDirty;
@@ -7627,10 +7636,11 @@ function GithubDetail() {
7627
7636
  setAuthNotice("");
7628
7637
  setCopyNotice("");
7629
7638
  setAuthentication(null);
7639
+ setConfirmingEmail(false);
7630
7640
  authId.current = null;
7631
7641
  };
7632
- const save = async (toggle = false) => {
7633
- if (!channel_0 || savingRequest.current || authRequest.current || (toggle ? !hasCredential : !canSave)) return;
7642
+ const commit = async (toggle) => {
7643
+ if (!channel_0 || savingRequest.current || authRequest.current) return;
7634
7644
  savingRequest.current = true;
7635
7645
  setSaving(true);
7636
7646
  setNotice("");
@@ -7653,6 +7663,14 @@ function GithubDetail() {
7653
7663
  setSaving(false);
7654
7664
  }
7655
7665
  };
7666
+ const save = async (toggle_0 = false) => {
7667
+ if (!channel_0 || savingRequest.current || authRequest.current || (toggle_0 ? !hasCredential : !canSave)) return;
7668
+ if (!toggle_0 && emailMismatch) {
7669
+ setConfirmingEmail(true);
7670
+ return;
7671
+ }
7672
+ await commit(toggle_0);
7673
+ };
7656
7674
  const openDelete = () => {
7657
7675
  if (!hasCredential || savingRequest.current || authRequest.current) return;
7658
7676
  savingRequest.current = true;
@@ -7765,17 +7783,19 @@ function GithubDetail() {
7765
7783
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Input, {
7766
7784
  id: `${id}-commit-email`,
7767
7785
  type: "email",
7768
- placeholder: "bot@example.com",
7786
+ placeholder: suggestion || "bot@example.com",
7769
7787
  value: emailValue,
7770
7788
  onChange: (event_0) => setCommitEmail(event_0.target.value),
7771
7789
  disabled: busy,
7772
7790
  maxLength: 254,
7773
7791
  autoComplete: "off",
7774
- spellCheck: false
7792
+ spellCheck: false,
7793
+ "aria-describedby": `${id}-commit-help`
7775
7794
  })]
7776
7795
  })]
7777
7796
  }),
7778
7797
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
7798
+ id: `${id}-commit-help`,
7779
7799
  className: "m-0 text-xs leading-5 text-(--dsw-alias-label-secondary)",
7780
7800
  children: t("channelCommitHelp")
7781
7801
  }),
@@ -7900,6 +7920,30 @@ function GithubDetail() {
7900
7920
  })
7901
7921
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Environment, { description: t("channelGithubWorkerIdentity") })]
7902
7922
  }),
7923
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
7924
+ open: confirmingEmail,
7925
+ onClose: () => setConfirmingEmail(false),
7926
+ title: t("channelCommitEmailMismatchTitle"),
7927
+ closeLabel: t("channelCancel"),
7928
+ description: t("channelCommitEmailMismatchDescription", {
7929
+ email: emailValue.trim(),
7930
+ suggestion
7931
+ }),
7932
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
7933
+ variant: "outline",
7934
+ disabled: saving,
7935
+ onClick: () => setConfirmingEmail(false),
7936
+ children: t("channelCancel")
7937
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
7938
+ variant: "primary",
7939
+ disabled: saving,
7940
+ onClick: () => {
7941
+ setConfirmingEmail(false);
7942
+ commit(false);
7943
+ },
7944
+ children: t("channelCommitEmailMismatchConfirm")
7945
+ })] })
7946
+ }),
7903
7947
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
7904
7948
  open: deletion !== null,
7905
7949
  onClose: closeDelete,
@@ -7943,6 +7987,10 @@ function GitlabDetail() {
7943
7987
  const [token, setToken] = (0, react.useState)("");
7944
7988
  const [commitName, setCommitName] = (0, react.useState)(channel_0?.commitName ?? "");
7945
7989
  const [commitEmail, setCommitEmail] = (0, react.useState)(channel_0?.commitEmail ?? "");
7990
+ const [confirmingEmail, setConfirmingEmail] = (0, react.useState)(false);
7991
+ const suggestion = channel_0?.commitEmailSuggestion ?? "";
7992
+ const emailValue = commitEmail.trim() || suggestion;
7993
+ const emailMismatch = Boolean(suggestion) && Boolean(emailValue.trim()) && emailValue.trim().toLowerCase() !== suggestion.toLowerCase();
7946
7994
  const [host, setHost] = (0, react.useState)(channel_0?.host ?? "https://gitlab.com");
7947
7995
  const [hostInvalid, setHostInvalid] = (0, react.useState)(false);
7948
7996
  const lifetime = (0, react.useRef)(new AbortController());
@@ -7971,9 +8019,8 @@ function GitlabDetail() {
7971
8019
  if (!saved) throw new Error("channel_reload_failed");
7972
8020
  return saved;
7973
8021
  }
7974
- const save = async () => {
8022
+ const commit = async () => {
7975
8023
  if (savingRequest.current) return;
7976
- if (!validateHost()) return;
7977
8024
  savingRequest.current = true;
7978
8025
  setSaving(true);
7979
8026
  setNotice("");
@@ -7982,7 +8029,7 @@ function GitlabDetail() {
7982
8029
  host: host.trim(),
7983
8030
  ...token.trim() && !channel_0?.hasCredential ? { enabled: true } : {},
7984
8031
  commitName: commitName.trim(),
7985
- commitEmail: commitEmail.trim(),
8032
+ commitEmail: emailValue.trim(),
7986
8033
  ...token.trim() ? { token: token.trim() } : {}
7987
8034
  }, { signal: lifetime.current.signal });
7988
8035
  if (lifetime.current.signal.aborted) return;
@@ -7998,6 +8045,15 @@ function GitlabDetail() {
7998
8045
  if (!lifetime.current.signal.aborted) setSaving(false);
7999
8046
  }
8000
8047
  };
8048
+ const save = async () => {
8049
+ if (savingRequest.current) return;
8050
+ if (!validateHost()) return;
8051
+ if (emailMismatch) {
8052
+ setConfirmingEmail(true);
8053
+ return;
8054
+ }
8055
+ await commit();
8056
+ };
8001
8057
  function reset(saved_1 = channel_0) {
8002
8058
  setHost(saved_1?.host ?? "https://gitlab.com");
8003
8059
  setCommitName(saved_1?.commitName ?? "");
@@ -8005,6 +8061,7 @@ function GitlabDetail() {
8005
8061
  setToken("");
8006
8062
  setHostInvalid(false);
8007
8063
  setNotice("");
8064
+ setConfirmingEmail(false);
8008
8065
  }
8009
8066
  const toggle = async () => {
8010
8067
  if (!channel_0?.hasCredential || savingRequest.current) return;
@@ -8093,6 +8150,30 @@ function GitlabDetail() {
8093
8150
  })
8094
8151
  ] })
8095
8152
  }),
8153
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
8154
+ open: confirmingEmail,
8155
+ onClose: () => setConfirmingEmail(false),
8156
+ title: t("channelCommitEmailMismatchTitle"),
8157
+ closeLabel: t("channelCancel"),
8158
+ description: t("channelCommitEmailMismatchDescription", {
8159
+ email: emailValue.trim(),
8160
+ suggestion
8161
+ }),
8162
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
8163
+ variant: "outline",
8164
+ disabled: saving,
8165
+ onClick: () => setConfirmingEmail(false),
8166
+ children: t("channelCancel")
8167
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
8168
+ variant: "primary",
8169
+ disabled: saving,
8170
+ onClick: () => {
8171
+ setConfirmingEmail(false);
8172
+ commit();
8173
+ },
8174
+ children: t("channelCommitEmailMismatchConfirm")
8175
+ })] })
8176
+ }),
8096
8177
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
8097
8178
  open: deleteConfirming,
8098
8179
  onClose: closeDelete,
@@ -8194,17 +8275,19 @@ function GitlabDetail() {
8194
8275
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Input, {
8195
8276
  id: `${id}-commit-email`,
8196
8277
  type: "email",
8197
- placeholder: "bot@example.com",
8198
- value: commitEmail,
8278
+ placeholder: suggestion || "bot@example.com",
8279
+ value: emailValue,
8199
8280
  onChange: (event_1) => setCommitEmail(event_1.target.value),
8200
8281
  disabled: busy,
8201
8282
  maxLength: 254,
8202
8283
  autoComplete: "off",
8203
- spellCheck: false
8284
+ spellCheck: false,
8285
+ "aria-describedby": `${id}-commit-help`
8204
8286
  })]
8205
8287
  })]
8206
8288
  }),
8207
8289
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8290
+ id: `${id}-commit-help`,
8208
8291
  className: "m-0 text-xs leading-5 text-(--dsw-alias-label-secondary)",
8209
8292
  children: t("channelCommitHelp")
8210
8293
  }),