dsh-supermesh 0.0.3 → 0.0.5
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/assets/prompts/orchestrator.md +3 -0
- package/assets/prompts/worker.md +4 -0
- package/dist/{channel-eDqcOvFj.js → channel-ChqKKcYq.js} +182 -59
- package/dist/client.cjs +96 -13
- package/dist/client.cjs.map +1 -1
- package/dist/index.js +38 -22
- package/dist/shell-DqAUjFxq.js +1 -0
- package/package.json +2 -1
- package/dist/shell-Bj-vzt4e.js +0 -1
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
|
|
20
20
|
收到触发后按这个顺序走,**每一步都可能提前结束**:
|
|
21
21
|
|
|
22
|
+
0. **这条消息是在叫你吗** —— 看邮件里的 `mentioned`。`mentioned: no` 的消息(别人开的 issue、别人的评论)
|
|
23
|
+
只是时间线记录:可以判一次话题归属,但**不建票、不派工、不叫醒任何人**。
|
|
24
|
+
只有 `mentioned: yes`、这条话题已经挂在票上(订阅跟进),或者人直接对你说「做」,才算开工请求。
|
|
22
25
|
1. **已经是老话题了吗** —— 用 `list_ticket` 看这条话题是否已挂在某张票上。
|
|
23
26
|
挂了就别再判一次,那条触发会自动进对应项目的收件箱。
|
|
24
27
|
2. **需要开新票吗** —— 消息明确指向某张已有票 → `attach_thread_to_ticket`,
|
package/assets/prompts/worker.md
CHANGED
|
@@ -12,6 +12,10 @@ GitHub 用 `gh pr create`,GitLab 用 `glab mr create` 发布。
|
|
|
12
12
|
发布前检查当前分支、origin 和已有 PR/MR。**复用当前票分支的已有结果,避免重复发布。**
|
|
13
13
|
不要自动纳入不明文件;仅提交本任务明确暂存的改动,发布前确认本任务改动已全部提交。
|
|
14
14
|
|
|
15
|
+
**推送前先确认 PR 还开着。** 用 `gh pr view <number> --json state,mergedAt`(GitLab 用 `glab mr view`)确认状态。
|
|
16
|
+
已合并或已关闭说明这张票已经结束、授权已经收回:立刻停手,不要推送、不要改基到新 main、不要另开 PR。
|
|
17
|
+
`report` 报「工单已结束」是同一个信号,收到就停,不要再做任何外部动作。
|
|
18
|
+
|
|
15
19
|
PR 描述里的正式 issue 链接必须从 `read_channel` 的 `ticket/<当前任务号>` 及关联话题上下文取得,不得猜造。
|
|
16
20
|
|
|
17
21
|
## 汇报
|
|
@@ -1588,6 +1588,8 @@ var agent_model_catalog_get_default = defineHandler(async () => {
|
|
|
1588
1588
|
return getServerContext(server).sessionController.modelCatalog();
|
|
1589
1589
|
});
|
|
1590
1590
|
const DSH_PLUGIN_HOME = `${process.env.DSH_HOME ?? join(homedir(), ".dsh")}/.supermesh`;
|
|
1591
|
+
/** 代理工作区:角色会话的 cwd 与官方工作区条目都只指向这里,插件状态留在上一层。 */
|
|
1592
|
+
const DSH_WORKSPACE_HOME = join(DSH_PLUGIN_HOME, "workspace");
|
|
1591
1593
|
// src/storage/index.ts
|
|
1592
1594
|
const storage = createStorage({ driver: fs({
|
|
1593
1595
|
atomic: true,
|
|
@@ -1717,7 +1719,9 @@ var agent_model_get_default = defineHandler(async () => (await setting.load()).m
|
|
|
1717
1719
|
// src/service/role-model.ts
|
|
1718
1720
|
const roleModel = defineService({
|
|
1719
1721
|
async resolve(model) {
|
|
1720
|
-
const
|
|
1722
|
+
const llm = getServerContext(server).get("llm");
|
|
1723
|
+
if (!llm) throw new Error("llm_unavailable");
|
|
1724
|
+
const value = await llm.resolveCallConfig({
|
|
1721
1725
|
provider: model.provider,
|
|
1722
1726
|
model: model.model,
|
|
1723
1727
|
...model.reasoningEffort ? { reasoningEffort: ReasoningEffortId(model.reasoningEffort) } : {}
|
|
@@ -1766,7 +1770,7 @@ const roleModel = defineService({
|
|
|
1766
1770
|
];
|
|
1767
1771
|
return () => disposers.forEach((dispose) => dispose());
|
|
1768
1772
|
});
|
|
1769
|
-
await
|
|
1773
|
+
await getServerContext(server).get("sessionPersistence")?.flush();
|
|
1770
1774
|
}
|
|
1771
1775
|
});
|
|
1772
1776
|
// src/server/routes/agent.model.patch.ts
|
|
@@ -1898,6 +1902,12 @@ const session = defineService({
|
|
|
1898
1902
|
registered.delete(id);
|
|
1899
1903
|
};
|
|
1900
1904
|
},
|
|
1905
|
+
/** 同步判定一个 Agent 是不是插件的四个角色会话:只按预设判断,不读会话历史。 */
|
|
1906
|
+
roleOf(agent) {
|
|
1907
|
+
const preset = getServerContext(server).agentPresets.composedPreset(agent.ctx);
|
|
1908
|
+
if (!preset || !registered.has(preset)) return null;
|
|
1909
|
+
return Object.keys(presets$1).find((role) => presets$1[role] === preset) ?? null;
|
|
1910
|
+
},
|
|
1901
1911
|
async attach(agent) {
|
|
1902
1912
|
const ctx = getServerContext(server);
|
|
1903
1913
|
const preset = ctx.agentPresets.composedPreset(agent.ctx);
|
|
@@ -2079,8 +2089,10 @@ const session = defineService({
|
|
|
2079
2089
|
};
|
|
2080
2090
|
},
|
|
2081
2091
|
workspace: singlet("session:workspace", async () => {
|
|
2082
|
-
|
|
2083
|
-
|
|
2092
|
+
const ctx = getServerContext(server);
|
|
2093
|
+
await mkdir(DSH_WORKSPACE_HOME, { recursive: true });
|
|
2094
|
+
await retireLegacyWorkspace(ctx);
|
|
2095
|
+
return ctx.workspaceRegistry.create(DSH_WORKSPACE_HOME, "代理工作区");
|
|
2084
2096
|
}),
|
|
2085
2097
|
activate: (id) => resolveAgent(id),
|
|
2086
2098
|
async lookup(id) {
|
|
@@ -2144,6 +2156,15 @@ const session = defineService({
|
|
|
2144
2156
|
if ((await session.activity(id)).background) throw new Error("background_stop_pending");
|
|
2145
2157
|
}
|
|
2146
2158
|
});
|
|
2159
|
+
/**
|
|
2160
|
+
* 旧版本把「代理工作区」注册在 `.supermesh` 根本身,那里同时存着插件状态。
|
|
2161
|
+
* 工作区路径不可改,只能删掉这条注册;目录与会话日志都保留,旧会话退化为未分组。
|
|
2162
|
+
*/
|
|
2163
|
+
async function retireLegacyWorkspace(ctx) {
|
|
2164
|
+
const legacy = await realpathNormalize(DSH_PLUGIN_HOME).catch(() => void 0);
|
|
2165
|
+
if (!legacy) return;
|
|
2166
|
+
for (const workspace of ctx.workspaceRegistry.list()) if (workspace.path === legacy) await ctx.workspaceRegistry.delete(workspace.id).catch(() => void 0);
|
|
2167
|
+
}
|
|
2147
2168
|
async function bindWorkspace(id, cwd) {
|
|
2148
2169
|
const ctx = getServerContext(server);
|
|
2149
2170
|
const sid = SessionId(id);
|
|
@@ -2151,6 +2172,7 @@ async function bindWorkspace(id, cwd) {
|
|
|
2151
2172
|
if (!directory) return;
|
|
2152
2173
|
const actual = await realpathNormalize(directory).catch(() => void 0);
|
|
2153
2174
|
if (!actual) return;
|
|
2175
|
+
if (actual === await realpathNormalize(DSH_PLUGIN_HOME).catch(() => void 0)) return;
|
|
2154
2176
|
for (const workspace of [await session.workspace(), ...ctx.workspaceRegistry.list()]) {
|
|
2155
2177
|
if (workspace.sessionIds.includes(sid)) return;
|
|
2156
2178
|
if (workspace.path !== actual) continue;
|
|
@@ -2200,7 +2222,21 @@ const inbox = defineService({
|
|
|
2200
2222
|
if (!identity) return null;
|
|
2201
2223
|
const scope = scopeOf(identity);
|
|
2202
2224
|
if (!scope) return null;
|
|
2203
|
-
const
|
|
2225
|
+
const rows = await db.inbox.listScoped(scope, includeChannel);
|
|
2226
|
+
const triggers = /* @__PURE__ */ new Map();
|
|
2227
|
+
for (const triggerId of new Set(rows.map((message) => message.triggerId).filter(Boolean))) {
|
|
2228
|
+
const trigger = await db.trigger.findById(triggerId);
|
|
2229
|
+
if (trigger) triggers.set(triggerId, {
|
|
2230
|
+
kind: trigger.kind,
|
|
2231
|
+
actorName: trigger.actorName,
|
|
2232
|
+
human: Boolean(trigger.human),
|
|
2233
|
+
mentioned: Boolean(trigger.mentioned)
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
const messages = rows.map((message) => ({
|
|
2237
|
+
...message,
|
|
2238
|
+
...message.triggerId && triggers.has(message.triggerId) ? { trigger: triggers.get(message.triggerId) } : {}
|
|
2239
|
+
}));
|
|
2204
2240
|
const projects = (await db.project.listAll()).filter((project) => project.enabled && (identity.role === "main" || project.id === identity.projectId)).map(({ id, name, directory, remoteUrl }) => ({
|
|
2205
2241
|
id,
|
|
2206
2242
|
name,
|
|
@@ -2291,11 +2327,13 @@ const inbox = defineService({
|
|
|
2291
2327
|
continue;
|
|
2292
2328
|
}
|
|
2293
2329
|
if ((await session.activity(id)).running || stopped$2) continue;
|
|
2330
|
+
const trigger = message.triggerId ? await db.trigger.findById(message.triggerId) : void 0;
|
|
2294
2331
|
await session.send(id, [
|
|
2295
2332
|
message.title ?? "",
|
|
2296
2333
|
`[Inbox ${message.id}]`,
|
|
2297
2334
|
message.triggerId ? `triggerId: ${message.triggerId}` : "",
|
|
2298
2335
|
message.threadId ? `threadId: ${message.threadId}` : "",
|
|
2336
|
+
trigger ? `actor: ${trigger.actorName ?? "unknown"} human: ${trigger.human ? "yes" : "no"} mentioned: ${trigger.mentioned ? "yes" : "no"}` : "",
|
|
2299
2337
|
message.message
|
|
2300
2338
|
].filter(Boolean).join(String.fromCharCode(10)), "queue", requestId);
|
|
2301
2339
|
await db.inbox.resetDelivery(message.id);
|
|
@@ -2404,7 +2442,7 @@ var ask__id__answer_post_default = defineHandler(async (event) => {
|
|
|
2404
2442
|
const directory = join(DSH_PLUGIN_HOME, "cli");
|
|
2405
2443
|
const bin = join(directory, "bin");
|
|
2406
2444
|
const gitconfig = join(directory, "gitconfig");
|
|
2407
|
-
const
|
|
2445
|
+
const tokens = [
|
|
2408
2446
|
"GH_TOKEN",
|
|
2409
2447
|
"GITHUB_TOKEN",
|
|
2410
2448
|
"GH_ENTERPRISE_TOKEN",
|
|
@@ -2412,23 +2450,16 @@ const removed = [
|
|
|
2412
2450
|
"GITLAB_TOKEN",
|
|
2413
2451
|
"GLAB_TOKEN",
|
|
2414
2452
|
"OAUTH_TOKEN",
|
|
2415
|
-
"CI_JOB_TOKEN"
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
"GIT_INDEX_FILE",
|
|
2419
|
-
"GIT_PREFIX",
|
|
2420
|
-
"GIT_COMMON_DIR",
|
|
2421
|
-
"GIT_OBJECT_DIRECTORY",
|
|
2422
|
-
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
2423
|
-
"GIT_NAMESPACE",
|
|
2424
|
-
"GIT_CONFIG_COUNT",
|
|
2425
|
-
"GIT_CONFIG_PARAMETERS",
|
|
2453
|
+
"CI_JOB_TOKEN"
|
|
2454
|
+
];
|
|
2455
|
+
const identities = [
|
|
2426
2456
|
"GIT_AUTHOR_NAME",
|
|
2427
2457
|
"GIT_AUTHOR_EMAIL",
|
|
2428
2458
|
"GIT_COMMITTER_NAME",
|
|
2429
|
-
"GIT_COMMITTER_EMAIL"
|
|
2430
|
-
"SSH_ASKPASS"
|
|
2459
|
+
"GIT_COMMITTER_EMAIL"
|
|
2431
2460
|
];
|
|
2461
|
+
/** 角色会话标记:由 `ctx.shellEnv` 按调用会话注入,shim 只在这个变量存在时才切到 bot 身份。 */
|
|
2462
|
+
const ROLE_MARKER = "DSH_SUPERMESH_ROLE";
|
|
2432
2463
|
let restore;
|
|
2433
2464
|
let writing$1 = Promise.resolve();
|
|
2434
2465
|
let basePath = "";
|
|
@@ -2437,21 +2468,22 @@ const shell = defineService({
|
|
|
2437
2468
|
if (restore) throw new Error("shell_already_started");
|
|
2438
2469
|
basePath = (process.env.PATH ?? "").split(delimiter).filter((path) => resolve(path).toLowerCase() !== resolve(bin).toLowerCase()).join(delimiter);
|
|
2439
2470
|
await refresh();
|
|
2440
|
-
const
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
const
|
|
2450
|
-
|
|
2451
|
-
|
|
2471
|
+
const release = getServerContext(server).get("shellEnv")?.register({
|
|
2472
|
+
name: "supermesh-role",
|
|
2473
|
+
variables: { DSH_SUPERMESH_ROLE: { description: "Supermesh 角色会话标记,决定 gh / glab / git 是否使用插件的机器人身份。" } },
|
|
2474
|
+
resolve: (execution) => {
|
|
2475
|
+
const agent = execution.agent;
|
|
2476
|
+
const role = agent ? session.roleOf(agent) : null;
|
|
2477
|
+
return role ? { DSH_SUPERMESH_ROLE: role } : {};
|
|
2478
|
+
}
|
|
2479
|
+
});
|
|
2480
|
+
const previous = process.env.PATH;
|
|
2481
|
+
process.env.PATH = [bin, basePath].join(delimiter);
|
|
2482
|
+
restore = () => {
|
|
2483
|
+
release?.();
|
|
2484
|
+
if (previous === void 0) delete process.env.PATH;
|
|
2485
|
+
else process.env.PATH = previous;
|
|
2452
2486
|
};
|
|
2453
|
-
apply(values);
|
|
2454
|
-
restore = () => apply(previous);
|
|
2455
2487
|
return async () => {
|
|
2456
2488
|
const release = restore;
|
|
2457
2489
|
restore = void 0;
|
|
@@ -2460,10 +2492,7 @@ const shell = defineService({
|
|
|
2460
2492
|
};
|
|
2461
2493
|
},
|
|
2462
2494
|
commandEnvironment() {
|
|
2463
|
-
return {
|
|
2464
|
-
...process.env,
|
|
2465
|
-
...restore ? { PATH: basePath } : {}
|
|
2466
|
-
};
|
|
2495
|
+
return { ...process.env };
|
|
2467
2496
|
},
|
|
2468
2497
|
refresh() {
|
|
2469
2498
|
if (!restore) return Promise.resolve();
|
|
@@ -2503,32 +2532,43 @@ async function refresh() {
|
|
|
2503
2532
|
git_protocol: "https"
|
|
2504
2533
|
} } : {}
|
|
2505
2534
|
}));
|
|
2535
|
+
const shellPath = shellPathOf(basePath);
|
|
2506
2536
|
for (const cli of ["gh", "glab"]) {
|
|
2507
2537
|
const executable = await nativeCli(cli);
|
|
2508
2538
|
const configKey = cli === "gh" ? "GH_CONFIG_DIR" : "GLAB_CONFIG_DIR";
|
|
2509
2539
|
const hostKey = cli === "gh" ? "GH_HOST" : "GITLAB_HOST";
|
|
2510
2540
|
const host = cli === "gh" ? "github.com" : gitlabHost;
|
|
2511
|
-
const shellPath = shellPathOf(basePath);
|
|
2512
2541
|
const keyringKeys = cli === "glab" ? ["GLAB_USE_KEYRING"] : [];
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
`unset ${removed.filter((key) => /TOKEN/.test(key)).join(" ")}`,
|
|
2542
|
+
const botEnv = [
|
|
2543
|
+
...tokens.map((key) => `unset ${key}`),
|
|
2516
2544
|
`export PATH=${quote(shellPath)}`,
|
|
2517
2545
|
`export ${configKey}=${quote(join(directory, cli).replaceAll("\\", "/"))}`,
|
|
2518
2546
|
`export ${hostKey}=${quote(host)}`,
|
|
2519
|
-
...keyringKeys.map((key) => `export ${key}=false`)
|
|
2547
|
+
...keyringKeys.map((key) => `export ${key}=false`)
|
|
2548
|
+
];
|
|
2549
|
+
await own(join(bin, cli), [
|
|
2550
|
+
"#!/bin/sh",
|
|
2551
|
+
`if [ -z "$${ROLE_MARKER}" ]; then exec ${executable ? quote(executable.replaceAll("\\", "/")) : "exit 127"} "$@"; fi`,
|
|
2552
|
+
...botEnv,
|
|
2520
2553
|
executable ? `exec ${quote(executable.replaceAll("\\", "/"))} "$@"` : `echo '${cli} is not installed' >&2; exit 127`,
|
|
2521
2554
|
""
|
|
2522
2555
|
].join("\n"), 448);
|
|
2523
2556
|
const cmd = (value) => value.replaceAll("%", "%%");
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
"setlocal",
|
|
2527
|
-
...removed.filter((key) => /TOKEN/.test(key)).map((key) => `set "${key}="`),
|
|
2557
|
+
const botCmd = [
|
|
2558
|
+
...tokens.map((key) => `set "${key}="`),
|
|
2528
2559
|
`set "PATH=${cmd(basePath)}"`,
|
|
2529
2560
|
`set "${configKey}=${cmd(join(directory, cli))}"`,
|
|
2530
2561
|
`set "${hostKey}=${host}"`,
|
|
2531
|
-
...keyringKeys.map((key) => `set "${key}=false"`)
|
|
2562
|
+
...keyringKeys.map((key) => `set "${key}=false"`)
|
|
2563
|
+
];
|
|
2564
|
+
await own(join(bin, `${cli}.cmd`), [
|
|
2565
|
+
"@echo off",
|
|
2566
|
+
"setlocal",
|
|
2567
|
+
`if not defined ${ROLE_MARKER} goto plain`,
|
|
2568
|
+
...botCmd,
|
|
2569
|
+
executable ? `"${cmd(executable)}" %*` : `echo ${cli} is not installed 1>&2 & exit /b 127`,
|
|
2570
|
+
"exit /b %errorlevel%",
|
|
2571
|
+
":plain",
|
|
2532
2572
|
executable ? `"${cmd(executable)}" %*` : `echo ${cli} is not installed 1>&2 & exit /b 127`,
|
|
2533
2573
|
"exit /b %errorlevel%",
|
|
2534
2574
|
""
|
|
@@ -2538,25 +2578,61 @@ async function refresh() {
|
|
|
2538
2578
|
const escaping = [
|
|
2539
2579
|
"GH_CONFIG_DIR",
|
|
2540
2580
|
"GH_HOST",
|
|
2541
|
-
...
|
|
2581
|
+
...tokens
|
|
2542
2582
|
];
|
|
2543
2583
|
await own(join(bin, "gh-default"), [
|
|
2544
2584
|
"#!/bin/sh",
|
|
2545
|
-
`
|
|
2546
|
-
`
|
|
2585
|
+
`if [ -z "$${ROLE_MARKER}" ]; then exec ${nativeGh ? quote(nativeGh.replaceAll("\\", "/")) : "exit 127"} "$@"; fi`,
|
|
2586
|
+
...escaping.map((key) => `unset ${key}`),
|
|
2587
|
+
`export PATH=${quote(shellPath)}`,
|
|
2547
2588
|
nativeGh ? `exec ${quote(nativeGh.replaceAll("\\", "/"))} "$@"` : "echo gh is not installed >&2; exit 127",
|
|
2548
2589
|
""
|
|
2549
2590
|
].join("\n"), 448);
|
|
2550
2591
|
await own(join(bin, "gh-default.cmd"), [
|
|
2551
2592
|
"@echo off",
|
|
2552
2593
|
"setlocal",
|
|
2594
|
+
`if not defined ${ROLE_MARKER} goto plain`,
|
|
2553
2595
|
...escaping.map((key) => `set "${key}="`),
|
|
2554
2596
|
`set "PATH=${basePath.replaceAll("%", "%%")}"`,
|
|
2555
2597
|
nativeGh ? `"${nativeGh.replaceAll("%", "%%")}" %*` : "echo gh is not installed 1>&2 & exit /b 127",
|
|
2556
2598
|
"exit /b %errorlevel%",
|
|
2599
|
+
":plain",
|
|
2600
|
+
nativeGh ? `"${nativeGh.replaceAll("%", "%%")}" %*` : "echo gh is not installed 1>&2 & exit /b 127",
|
|
2601
|
+
"exit /b %errorlevel%",
|
|
2557
2602
|
""
|
|
2558
2603
|
].join("\r\n"), 448);
|
|
2604
|
+
const nativeGit = await nativeCli("git");
|
|
2559
2605
|
const gitQuote = (value) => JSON.stringify(value);
|
|
2606
|
+
const gitEnv = [
|
|
2607
|
+
...identities.map((key) => `unset ${key}`),
|
|
2608
|
+
`export GIT_CONFIG_GLOBAL=${quote(gitconfig.replaceAll("\\", "/"))}`,
|
|
2609
|
+
"export GIT_CONFIG_NOSYSTEM=1",
|
|
2610
|
+
"export GIT_ASKPASS=",
|
|
2611
|
+
"export GIT_TERMINAL_PROMPT=0"
|
|
2612
|
+
];
|
|
2613
|
+
await own(join(bin, "git"), [
|
|
2614
|
+
"#!/bin/sh",
|
|
2615
|
+
`if [ -z "$${ROLE_MARKER}" ]; then exec ${nativeGit ? quote(nativeGit.replaceAll("\\", "/")) : "exit 127"} "$@"; fi`,
|
|
2616
|
+
...gitEnv,
|
|
2617
|
+
nativeGit ? `exec ${quote(nativeGit.replaceAll("\\", "/"))} "$@"` : "echo git is not installed >&2; exit 127",
|
|
2618
|
+
""
|
|
2619
|
+
].join("\n"), 448);
|
|
2620
|
+
await own(join(bin, "git.cmd"), [
|
|
2621
|
+
"@echo off",
|
|
2622
|
+
"setlocal",
|
|
2623
|
+
`if not defined ${ROLE_MARKER} goto plain`,
|
|
2624
|
+
...identities.map((key) => `set "${key}="`),
|
|
2625
|
+
`set "GIT_CONFIG_GLOBAL=${gitconfig.replaceAll("%", "%%")}"`,
|
|
2626
|
+
"set \"GIT_CONFIG_NOSYSTEM=1\"",
|
|
2627
|
+
"set \"GIT_ASKPASS=\"",
|
|
2628
|
+
"set \"GIT_TERMINAL_PROMPT=0\"",
|
|
2629
|
+
nativeGit ? `"${nativeGit.replaceAll("%", "%%")}" %*` : "echo git is not installed 1>&2 & exit /b 127",
|
|
2630
|
+
"exit /b %errorlevel%",
|
|
2631
|
+
":plain",
|
|
2632
|
+
nativeGit ? `"${nativeGit.replaceAll("%", "%%")}" %*` : "echo git is not installed 1>&2 & exit /b 127",
|
|
2633
|
+
"exit /b %errorlevel%",
|
|
2634
|
+
""
|
|
2635
|
+
].join("\r\n"), 448);
|
|
2560
2636
|
const cliPath = (cli) => quote(join(bin, cli).replaceAll("\\", "/"));
|
|
2561
2637
|
const lines = [
|
|
2562
2638
|
"[user]",
|
|
@@ -2614,6 +2690,24 @@ async function own(path, content, mode = 384) {
|
|
|
2614
2690
|
function quote(value) {
|
|
2615
2691
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
2616
2692
|
}
|
|
2693
|
+
// src/utils/git-identity.ts
|
|
2694
|
+
/**
|
|
2695
|
+
* 平台按邮箱归属提交,名字只影响显示。用账号的 noreply 地址才能让 bot 的提交记在 bot 名下。
|
|
2696
|
+
* GitHub:`<id>+<login>@users.noreply.github.com`;GitLab:`<username>@users.noreply.<host>`。
|
|
2697
|
+
*/
|
|
2698
|
+
function noreplyEmail(kind, login, providerId, host) {
|
|
2699
|
+
const name = login.trim();
|
|
2700
|
+
if (!name) return "";
|
|
2701
|
+
if (kind === "github") {
|
|
2702
|
+
const id = providerId.trim();
|
|
2703
|
+
return /^\d+$/.test(id) ? `${id}+${name}@users.noreply.github.com` : "";
|
|
2704
|
+
}
|
|
2705
|
+
try {
|
|
2706
|
+
return `${name}@users.noreply.${new URL(host).host}`;
|
|
2707
|
+
} catch {
|
|
2708
|
+
return "";
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2617
2711
|
// src/service/devops.ts
|
|
2618
2712
|
const authentications = /* @__PURE__ */ new Map();
|
|
2619
2713
|
const active = /* @__PURE__ */ new Map();
|
|
@@ -2664,14 +2758,14 @@ const devops = defineService({
|
|
|
2664
2758
|
},
|
|
2665
2759
|
save(kind, patch) {
|
|
2666
2760
|
return channel.serialize(() => save(kind, patch)).then(async (view) => {
|
|
2667
|
-
const { shell } = await import("./shell-
|
|
2761
|
+
const { shell } = await import("./shell-DqAUjFxq.js");
|
|
2668
2762
|
await shell.refresh();
|
|
2669
2763
|
return view;
|
|
2670
2764
|
});
|
|
2671
2765
|
},
|
|
2672
2766
|
removeCredentials(kind) {
|
|
2673
2767
|
return channel.serialize(() => removeCredentials(kind)).then(async (view) => {
|
|
2674
|
-
const { shell } = await import("./shell-
|
|
2768
|
+
const { shell } = await import("./shell-DqAUjFxq.js");
|
|
2675
2769
|
await shell.refresh();
|
|
2676
2770
|
return view;
|
|
2677
2771
|
});
|
|
@@ -2719,11 +2813,20 @@ async function save(kind, patch) {
|
|
|
2719
2813
|
if (token) account = await verify(kind, url, token);
|
|
2720
2814
|
const enabled = patch.enabled ?? (Boolean(account) || current.enabled);
|
|
2721
2815
|
if (enabled && !account && !current.accounts.some((account) => account.role === "bot" && account.status === "online")) throw new TypeError("channel_account_required");
|
|
2816
|
+
let identity = account;
|
|
2817
|
+
if (!identity && !current.providerId && (patch.commitName !== void 0 || patch.commitEmail !== void 0)) {
|
|
2818
|
+
const stored = await channel.resolveCredential(kind);
|
|
2819
|
+
if (stored) identity = await verify(kind, url, stored).catch(() => void 0);
|
|
2820
|
+
}
|
|
2821
|
+
const providerId = identity?.providerId ?? current.providerId;
|
|
2822
|
+
const login = identity?.name ?? current.accounts.find((account) => account.role === "bot")?.name ?? "";
|
|
2823
|
+
const commitEmail = (patch.commitEmail?.trim() ?? current.commitEmail) || noreplyEmail(kind, login, providerId, url.origin);
|
|
2722
2824
|
const previous = token ? await channel.storeCredential(kind, token) : void 0;
|
|
2723
2825
|
try {
|
|
2724
2826
|
await db.channel.saveConfiguration(kind, current.name, kind === "gitlab" ? url.origin : null, enabled, {
|
|
2725
2827
|
commitName: patch.commitName?.trim() ?? current.commitName,
|
|
2726
|
-
commitEmail
|
|
2828
|
+
commitEmail,
|
|
2829
|
+
providerId
|
|
2727
2830
|
}, account, ...hostChanged ? [true] : []);
|
|
2728
2831
|
} catch {
|
|
2729
2832
|
if (token) {
|
|
@@ -2767,9 +2870,14 @@ async function verify(kind, url, token) {
|
|
|
2767
2870
|
const user = identity;
|
|
2768
2871
|
const login = kind === "github" ? user.login : user.username ?? user.name;
|
|
2769
2872
|
if (typeof login !== "string" || !login.trim() || login.length > 200 || /[\r\n]/.test(login)) throw new Error("channel_auth_failed");
|
|
2873
|
+
const id = user.id;
|
|
2874
|
+
if (typeof id !== "number" && typeof id !== "string") throw new Error("channel_auth_failed");
|
|
2875
|
+
const providerId = String(id);
|
|
2876
|
+
if (!/^\d+$/.test(providerId)) throw new Error("channel_auth_failed");
|
|
2770
2877
|
return {
|
|
2771
2878
|
name: login.trim(),
|
|
2772
|
-
avatar: null
|
|
2879
|
+
avatar: null,
|
|
2880
|
+
providerId
|
|
2773
2881
|
};
|
|
2774
2882
|
} finally {
|
|
2775
2883
|
await dispatcher.close();
|
|
@@ -3935,7 +4043,15 @@ const worker = defineService({
|
|
|
3935
4043
|
for (const worker of await db.worker.listRunning()) {
|
|
3936
4044
|
if (stopped) break;
|
|
3937
4045
|
const ticket = await db.ticket.findById(worker.ticketId);
|
|
3938
|
-
if (!ticket
|
|
4046
|
+
if (!ticket) {
|
|
4047
|
+
await db.worker.end(worker.id, "stopped", (/* @__PURE__ */ new Date()).toISOString());
|
|
4048
|
+
continue;
|
|
4049
|
+
}
|
|
4050
|
+
if (ticket.status === "done" || ticket.status === "cancelled") {
|
|
4051
|
+
await session.send(worker.id, `票 ${ticket.id} 已${ticket.status === "done" ? "完成" : "取消"},本次授权已收回:立即停手,不要再提交、推送或开 PR。`, "interrupt").catch(() => void 0);
|
|
4052
|
+
await db.worker.end(worker.id, "stopped", (/* @__PURE__ */ new Date()).toISOString());
|
|
4053
|
+
continue;
|
|
4054
|
+
}
|
|
3939
4055
|
if (ticket.prState === "merged" || ticket.prState === "closed") {
|
|
3940
4056
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3941
4057
|
await db.worker.end(worker.id, "stopped", now);
|
|
@@ -4634,6 +4750,8 @@ const channel = defineService({
|
|
|
4634
4750
|
const stored = await db.sourceState.find(preset.id, "configuration");
|
|
4635
4751
|
const configured = hasCredential || members.length > 0 || Boolean(stored);
|
|
4636
4752
|
const metadata = readMetadata(stored?.value);
|
|
4753
|
+
const bot = members.find((account) => account.role === "bot");
|
|
4754
|
+
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")) : "";
|
|
4637
4755
|
return {
|
|
4638
4756
|
id: preset.id,
|
|
4639
4757
|
kind: preset.id,
|
|
@@ -4646,7 +4764,10 @@ const channel = defineService({
|
|
|
4646
4764
|
supported,
|
|
4647
4765
|
hasCredential,
|
|
4648
4766
|
status: !supported ? "unsupported" : !configured ? "unconfigured" : !enabled ? "disabled" : members.some((account) => account.role === "bot" && account.status === "online") ? "online" : "offline",
|
|
4649
|
-
|
|
4767
|
+
commitName: metadata.commitName,
|
|
4768
|
+
commitEmail: metadata.commitEmail,
|
|
4769
|
+
commitEmailSuggestion: suggestion,
|
|
4770
|
+
providerId: metadata.providerId
|
|
4650
4771
|
};
|
|
4651
4772
|
}));
|
|
4652
4773
|
},
|
|
@@ -4695,13 +4816,15 @@ function legacyRef(kind) {
|
|
|
4695
4816
|
function readMetadata(raw) {
|
|
4696
4817
|
if (!raw) return {
|
|
4697
4818
|
commitName: "",
|
|
4698
|
-
commitEmail: ""
|
|
4819
|
+
commitEmail: "",
|
|
4820
|
+
providerId: ""
|
|
4699
4821
|
};
|
|
4700
4822
|
const value = JSON.parse(raw);
|
|
4701
|
-
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");
|
|
4823
|
+
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");
|
|
4702
4824
|
return {
|
|
4703
4825
|
commitName: value.commitName,
|
|
4704
|
-
commitEmail: value.commitEmail
|
|
4826
|
+
commitEmail: value.commitEmail,
|
|
4827
|
+
providerId: "providerId" in value && typeof value.providerId === "string" ? value.providerId : ""
|
|
4705
4828
|
};
|
|
4706
4829
|
}
|
|
4707
4830
|
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 };
|