@kangyishuai/dsh-projects 0.1.1 → 0.1.3
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 +7 -4
- package/README.zh-CN.md +7 -4
- package/lib/executor.js +51 -1
- package/lib/service.js +100 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/de
|
|
|
12
12
|
> Details: `docs/runtime/0.2.2-rc.3.md` §11.24–§11.26.
|
|
13
13
|
|
|
14
14
|
> **Status: M4 done, pre-1.0.** Projects, context injection, isolated parallel threads, an opt-in coordinator,
|
|
15
|
-
> and a gated approval/executor layer are implemented, unit-tested (
|
|
15
|
+
> and a gated approval/executor layer are implemented, unit-tested (276 tests) and covered by a 50-assertion
|
|
16
16
|
> web end-to-end smoke plus an 11-assertion desktop read-only regression.
|
|
17
17
|
> Remote writes (push / PR / merge) are wired and verified locally against a bare remote and a stub `gh`;
|
|
18
18
|
> the real-GitHub effect still needs one release confirmation. Project **sharing** is deferred ([ADR 0018](../../docs/adr/0018-projects-defer-liveshare-sharing.md)).
|
|
@@ -65,9 +65,12 @@ does not do over a remote connection.
|
|
|
65
65
|
|
|
66
66
|
## Compatibility
|
|
67
67
|
|
|
68
|
-
| Plugin | Verified on DSH
|
|
69
|
-
| ------ |
|
|
70
|
-
| 0.1.
|
|
68
|
+
| Plugin | Verified on DSH |
|
|
69
|
+
| ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
70
|
+
| 0.1.1 | 0.2.2-rc.5: no code change needed. 276 unit tests + `pnpm probe:runtime` 72/72 + web smoke 50/0/0 + desktop read-only regression **11 PASS / 0 SKIP / 0 FAIL** |
|
|
71
|
+
| 0.1.x | 0.2.2-rc.3 |
|
|
72
|
+
|
|
73
|
+
The private host seams this plugin uses (`dsh-session`, `dsh-workspace`, `dsh-api-gateway`, `dsh-typert-protocol`, `dsh-agent`, …) are byte-identical between rc.3 and rc.5 — a 43-package diff found no change ([runtime rc.5 §1.1](../../docs/runtime/0.2.2-rc.5.md)).
|
|
71
74
|
|
|
72
75
|
## License
|
|
73
76
|
|
package/README.zh-CN.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
> 细节见 `docs/runtime/0.2.2-rc.3.md` §11.24–§11.26。
|
|
12
12
|
|
|
13
13
|
> **状态:M4 已完成,仍是 1.0 之前。** 项目、上下文注入、隔离的并行线程、可选协调器,以及带闸门的审批/执行层均已实现,
|
|
14
|
-
> 有
|
|
14
|
+
> 有 276 项单测、50 项 web 端到端冒烟与 11 项桌面只读回归覆盖。
|
|
15
15
|
> 远端写入(推分支 / 开 PR / 合并)已接线,并用本地 bare 远端 + 桩 `gh` 完成端到端验证;
|
|
16
16
|
> 真实 GitHub 上的效果还需发版后确认一次。**项目共享**已推迟([ADR 0018](../../docs/adr/0018-projects-defer-liveshare-sharing.md))。
|
|
17
17
|
|
|
@@ -64,9 +64,12 @@ dsh plugin --profile desktop add @kangyishuai/dsh-projects
|
|
|
64
64
|
|
|
65
65
|
## 兼容性
|
|
66
66
|
|
|
67
|
-
| 插件版本 | 已验证的 DSH 版本
|
|
68
|
-
| -------- |
|
|
69
|
-
| 0.1.
|
|
67
|
+
| 插件版本 | 已验证的 DSH 版本 |
|
|
68
|
+
| -------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
69
|
+
| 0.1.1 | 0.2.2-rc.5:这一版不需要改代码。276 项单测 + `pnpm probe:runtime` 72/72 + web 冒烟 50/0/0 + 桌面只读回归 **11 PASS / 0 SKIP / 0 FAIL** |
|
|
70
|
+
| 0.1.x | 0.2.2-rc.3 |
|
|
71
|
+
|
|
72
|
+
本插件依赖的私有 seam(`dsh-session`、`dsh-workspace`、`dsh-api-gateway`、`dsh-typert-protocol`、`dsh-agent` 等)在 rc.3 与 rc.5 之间**逐字节相同**(43 包逐包 diff 未发现变化,[runtime rc.5 §1.1](../../docs/runtime/0.2.2-rc.5.md))。
|
|
70
73
|
|
|
71
74
|
## License
|
|
72
75
|
|
package/lib/executor.js
CHANGED
|
@@ -117,7 +117,12 @@ export function planCommand(action, args) {
|
|
|
117
117
|
if (action === "merge") {
|
|
118
118
|
const prNumber = Number(args?.prNumber);
|
|
119
119
|
if (!Number.isInteger(prNumber) || prNumber <= 0) return { error: "pr-required" };
|
|
120
|
-
|
|
120
|
+
// **必须**带 --repo:否则 gh 会合并「宿主进程当前目录所在仓库」里同号的 PR。
|
|
121
|
+
// 这是 2026-11-21 真机 e2e 抓到的真缺陷:命令跑在 dsh-plugins 仓库里,
|
|
122
|
+
// 恰好那里 PR #1 已合并、gh 返回 0,于是插件误判成功,而目标 PR 根本没动。
|
|
123
|
+
const repo = String(args?.repo ?? "").trim();
|
|
124
|
+
if (!/^[\w.-]+\/[\w.-]+$/u.test(repo)) return { error: "repo-required" };
|
|
125
|
+
return { argv: ["gh", "pr", "merge", String(prNumber), "--squash", "--repo", repo] };
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
if (action === "delete-thread") {
|
|
@@ -165,3 +170,48 @@ export function recoveryEvidence(action, args, result) {
|
|
|
165
170
|
return { ...base, before: String(result?.before ?? ""), after: String(result?.after ?? "") };
|
|
166
171
|
return base;
|
|
167
172
|
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 合并前的前置校验(规格 §7.5 行 3 的硬前提)。纯函数便于单测:
|
|
176
|
+
* 只从 `gh pr view --json` 的结果判断,不假设任何外部状态。
|
|
177
|
+
* @param {{ isDraft?: boolean, mergeable?: string, state?: string }|null} pr
|
|
178
|
+
* @returns {{ ok: boolean, reason?: string }}
|
|
179
|
+
*/
|
|
180
|
+
export function checkMergePreflight(pr) {
|
|
181
|
+
if (!pr || typeof pr !== "object") return { ok: false, reason: "merge/pr-unknown" };
|
|
182
|
+
if (String(pr.state ?? "OPEN").toUpperCase() !== "OPEN")
|
|
183
|
+
return { ok: false, reason: "merge/pr-not-open" };
|
|
184
|
+
// draft PR 合并会被 GitHub 拒绝;auto-merge 也不该替人「先转正再合并」
|
|
185
|
+
if (pr.isDraft === true) return { ok: false, reason: "merge/pr-is-draft" };
|
|
186
|
+
const mergeable = String(pr.mergeable ?? "UNKNOWN").toUpperCase();
|
|
187
|
+
if (mergeable === "CONFLICTING") return { ok: false, reason: "merge/pr-conflicting" };
|
|
188
|
+
if (mergeable !== "MERGEABLE") return { ok: false, reason: "merge/pr-mergeable-unknown" };
|
|
189
|
+
return { ok: true };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 从 git remote URL 里取 owner/repo(支持 https 与 ssh 两种写法)。
|
|
194
|
+
* @param {string|null} url
|
|
195
|
+
* @returns {string}
|
|
196
|
+
*/
|
|
197
|
+
export function parseRepoFromRemote(url) {
|
|
198
|
+
const text = String(url ?? "")
|
|
199
|
+
.trim()
|
|
200
|
+
.replace(/\.git$/u, "");
|
|
201
|
+
const https = text.match(/github\.com[/:]([\w.-]+)\/([\w.-]+)$/u);
|
|
202
|
+
if (https) return `${https[1]}/${https[2]}`;
|
|
203
|
+
const ssh = text.match(/^git@[\w.-]+:([\w.-]+)\/([\w.-]+)$/u);
|
|
204
|
+
if (ssh) return `${ssh[1]}/${ssh[2]}`;
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 哪些前置失败值得等一会儿再试。GitHub 在 PR 刚创建后的一两秒内可能返回
|
|
210
|
+
* `mergeable: UNKNOWN`(服务端还在算),这不是「不能合并」,重试几次就会变成 MERGEABLE。
|
|
211
|
+
* 其余失败(draft / 冲突 / 已关闭)重试没有意义,直接拒绝。
|
|
212
|
+
* @param {string} reason
|
|
213
|
+
* @returns {boolean}
|
|
214
|
+
*/
|
|
215
|
+
export function shouldRetryPreflight(reason) {
|
|
216
|
+
return String(reason ?? "") === "merge/pr-mergeable-unknown";
|
|
217
|
+
}
|
package/lib/service.js
CHANGED
|
@@ -20,7 +20,14 @@ import { buildFixTask, errorSignature, shouldContinueFix } from "./autofix.js";
|
|
|
20
20
|
import { buildPrText, nextPrAction, parsePrNumber, planPrCreate } from "./autopr.js";
|
|
21
21
|
import { checkThreadBudget, checkTokenBudget, tokensOf } from "./budget.js";
|
|
22
22
|
import { runCommand } from "./exec.js";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
checkExecutable,
|
|
25
|
+
checkMergePreflight,
|
|
26
|
+
parseRepoFromRemote,
|
|
27
|
+
planCommand,
|
|
28
|
+
recoveryEvidence,
|
|
29
|
+
shouldRetryPreflight,
|
|
30
|
+
} from "./executor.js";
|
|
24
31
|
import { appendEntry } from "./memory.js";
|
|
25
32
|
import { initialView, reduce, sortRows } from "./overview.js";
|
|
26
33
|
import { resolveDataRoot } from "./paths.js";
|
|
@@ -1374,7 +1381,32 @@ export class ProjectsService extends TypertRemoteService {
|
|
|
1374
1381
|
return { executed: false, reason: "already-executed" };
|
|
1375
1382
|
}
|
|
1376
1383
|
|
|
1377
|
-
|
|
1384
|
+
// merge 的目标仓库必须**先**解析出来:早期 planCommand 就要用它,
|
|
1385
|
+
// 否则它会因为缺 repo 直接拒绝(也防止落到「宿主当前目录所在仓库」)。
|
|
1386
|
+
let mergeRepo = "";
|
|
1387
|
+
if (approval.action === "merge") {
|
|
1388
|
+
const project = store.getProject(approval.projectId);
|
|
1389
|
+
const repoDir = Array.isArray(project?.dirs) ? String(project.dirs[0] ?? "") : "";
|
|
1390
|
+
const remote =
|
|
1391
|
+
repoDir === ""
|
|
1392
|
+
? { code: 1, stdout: "", stderr: "" }
|
|
1393
|
+
: await runGit(["remote", "get-url", "origin"], repoDir);
|
|
1394
|
+
mergeRepo = remote.code === 0 ? parseRepoFromRemote(remote.stdout) : "";
|
|
1395
|
+
if (mergeRepo === "") {
|
|
1396
|
+
store.appendAudit({
|
|
1397
|
+
action: "approval/execution-refused",
|
|
1398
|
+
projectId: approval.projectId,
|
|
1399
|
+
requestId,
|
|
1400
|
+
dangerAction: approval.action,
|
|
1401
|
+
reason: "merge/repo-unknown",
|
|
1402
|
+
});
|
|
1403
|
+
store.save();
|
|
1404
|
+
return { executed: false, reason: "merge/repo-unknown" };
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
const planArgs =
|
|
1408
|
+
mergeRepo === "" ? (approval.args ?? {}) : { ...(approval.args ?? {}), repo: mergeRepo };
|
|
1409
|
+
const planned = planCommand(approval.action, planArgs);
|
|
1378
1410
|
if ("error" in planned) {
|
|
1379
1411
|
store.appendAudit({
|
|
1380
1412
|
action: "approval/execution-refused",
|
|
@@ -1440,7 +1472,72 @@ export class ProjectsService extends TypertRemoteService {
|
|
|
1440
1472
|
// merge:走 gh pr merge(argv 里已含 --squash,不带 --admin/--force)。
|
|
1441
1473
|
// 只合并我们自己的 PR:planCommand 已保证 PR 号是正整数,且危险开关与阈值都过了。
|
|
1442
1474
|
if (approval.action === "merge") {
|
|
1443
|
-
const
|
|
1475
|
+
const prNumber = Number(approval.args?.prNumber);
|
|
1476
|
+
const repo = mergeRepo;
|
|
1477
|
+
|
|
1478
|
+
// 前置校验:非 draft、可合并、仍 open(规格 §7.5 行 3 的硬前提)
|
|
1479
|
+
const view = await runGh([
|
|
1480
|
+
"pr",
|
|
1481
|
+
"view",
|
|
1482
|
+
String(prNumber),
|
|
1483
|
+
"--repo",
|
|
1484
|
+
repo,
|
|
1485
|
+
"--json",
|
|
1486
|
+
"isDraft,mergeable,state",
|
|
1487
|
+
]);
|
|
1488
|
+
if (view.code !== 0) {
|
|
1489
|
+
store.appendAudit({
|
|
1490
|
+
action: "approval/execution-failed",
|
|
1491
|
+
projectId: approval.projectId,
|
|
1492
|
+
requestId,
|
|
1493
|
+
dangerAction: approval.action,
|
|
1494
|
+
reason: String(view.stderr).split("\n")[0].slice(0, 200) || "merge/pr-view-failed",
|
|
1495
|
+
});
|
|
1496
|
+
store.save();
|
|
1497
|
+
return { executed: false, reason: "merge/pr-view-failed" };
|
|
1498
|
+
}
|
|
1499
|
+
const parsed = (() => {
|
|
1500
|
+
try {
|
|
1501
|
+
return JSON.parse(view.stdout);
|
|
1502
|
+
} catch {
|
|
1503
|
+
return null;
|
|
1504
|
+
}
|
|
1505
|
+
})();
|
|
1506
|
+
// GitHub 刚建 PR 时 mergeable 可能是 UNKNOWN(服务端还在算):有界重试几次。
|
|
1507
|
+
let preflight = checkMergePreflight(parsed);
|
|
1508
|
+
let attempt = 0;
|
|
1509
|
+
while (!preflight.ok && shouldRetryPreflight(preflight.reason ?? "") && attempt < 5) {
|
|
1510
|
+
attempt += 1;
|
|
1511
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1512
|
+
const again = await runGh([
|
|
1513
|
+
"pr",
|
|
1514
|
+
"view",
|
|
1515
|
+
String(prNumber),
|
|
1516
|
+
"--repo",
|
|
1517
|
+
repo,
|
|
1518
|
+
"--json",
|
|
1519
|
+
"isDraft,mergeable,state",
|
|
1520
|
+
]);
|
|
1521
|
+
if (again.code !== 0) break;
|
|
1522
|
+
try {
|
|
1523
|
+
preflight = checkMergePreflight(JSON.parse(again.stdout));
|
|
1524
|
+
} catch {
|
|
1525
|
+
break;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
if (!preflight.ok) {
|
|
1529
|
+
store.appendAudit({
|
|
1530
|
+
action: "approval/execution-refused",
|
|
1531
|
+
projectId: approval.projectId,
|
|
1532
|
+
requestId,
|
|
1533
|
+
dangerAction: approval.action,
|
|
1534
|
+
reason: preflight.reason,
|
|
1535
|
+
});
|
|
1536
|
+
store.save();
|
|
1537
|
+
return { executed: false, reason: preflight.reason };
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
const ghArgs = planned.argv.slice(1); // 去掉 argv[0] 的 "gh"(planArgs 已带 --repo)
|
|
1444
1541
|
const merged = await runGh(ghArgs);
|
|
1445
1542
|
const ok = merged.code === 0;
|
|
1446
1543
|
const evidence = recoveryEvidence(approval.action, approval.args ?? {}, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangyishuai/dsh-projects",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Project-level context for DeepSeek Harness: group sessions into projects, inject instructions and memory, run isolated parallel threads, and coordinate them with an optional auditable coordinator.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|