@kangyishuai/dsh-projects 0.2.2 → 0.3.0
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/lib/client.js +329 -47
- package/lib/executor.js +8 -0
- package/lib/service.js +58 -0
- package/lib/settings.js +79 -0
- package/locale/en.json +13 -1
- package/locale/zh.json +13 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -114,6 +114,19 @@ window.__ModuleLoader__.load({
|
|
|
114
114
|
"settings.danger.editProfile.risk": "协调器可能借此放宽自己的限制;风险最高",
|
|
115
115
|
"detail.archive": "归档项目",
|
|
116
116
|
"detail.unarchive": "取消归档",
|
|
117
|
+
"detail.execute": "执行",
|
|
118
|
+
"detail.executed": "已执行(结果见审计)",
|
|
119
|
+
"detail.refused": "未执行:{reason}",
|
|
120
|
+
"detail.grantsTitle": "仓库授权(直推保护分支用)",
|
|
121
|
+
"detail.grantsEmpty": "尚未授权任何仓库;直推保护分支前必须在这里加 owner/repo",
|
|
122
|
+
"detail.grantAdd": "添加",
|
|
123
|
+
"detail.purgeTitle": "回收站清理",
|
|
124
|
+
"detail.purgeHint":
|
|
125
|
+
"只清理本项目回收站里**超过保留期**的条目;先预览,再确认。需要打开 purgeAfterRetention 开关。",
|
|
126
|
+
"detail.purgePreview": "预览可清理项",
|
|
127
|
+
"detail.purgeConfirm": "确认清理 {count} 项",
|
|
128
|
+
"detail.purgeNothing": "没有超过保留期的条目",
|
|
129
|
+
"detail.purged": "已清理 {count} 项,清单已写入 trash/",
|
|
117
130
|
};
|
|
118
131
|
var EN = {
|
|
119
132
|
title: "Projects",
|
|
@@ -218,6 +231,20 @@ window.__ModuleLoader__.load({
|
|
|
218
231
|
"the coordinator could loosen its own limits; highest risk",
|
|
219
232
|
"detail.archive": "Archive project",
|
|
220
233
|
"detail.unarchive": "Unarchive project",
|
|
234
|
+
"detail.execute": "Execute",
|
|
235
|
+
"detail.executed": "Executed (see audit)",
|
|
236
|
+
"detail.refused": "Not executed: {reason}",
|
|
237
|
+
"detail.grantsTitle": "Repository grants (for pushing protected branches)",
|
|
238
|
+
"detail.grantsEmpty":
|
|
239
|
+
"No repository granted yet; add owner/repo before pushing a protected branch",
|
|
240
|
+
"detail.grantAdd": "Add",
|
|
241
|
+
"detail.purgeTitle": "Trash purge",
|
|
242
|
+
"detail.purgeHint":
|
|
243
|
+
"Only purges entries in this project's trash that are **past the retention period**; preview first, then confirm. Requires the purgeAfterRetention switch.",
|
|
244
|
+
"detail.purgePreview": "Preview purgeable",
|
|
245
|
+
"detail.purgeConfirm": "Purge {count} entries",
|
|
246
|
+
"detail.purgeNothing": "Nothing past the retention period",
|
|
247
|
+
"detail.purged": "Purged {count} entries; manifest written under trash/",
|
|
221
248
|
};
|
|
222
249
|
var PANEL_ID = "projects";
|
|
223
250
|
var SERVICE = "projects";
|
|
@@ -634,6 +661,108 @@ window.__ModuleLoader__.load({
|
|
|
634
661
|
[api, load, setData],
|
|
635
662
|
);
|
|
636
663
|
|
|
664
|
+
const execState = useState({ busy: "", ok: null, message: "" });
|
|
665
|
+
const exec = execState[0];
|
|
666
|
+
const setExec = execState[1];
|
|
667
|
+
// 执行一次已批准的申请:这是「批准 ≠ 可执行」里那独立的一步。
|
|
668
|
+
// 服务端还会再过一遍开关/阈值/幂等,所以这里不做乐观判断——把真实结果回显出来。
|
|
669
|
+
const executeApproval = useCallback(
|
|
670
|
+
(/** @type {any} */ requestId) => {
|
|
671
|
+
setExec({ busy: requestId, ok: null, message: "" });
|
|
672
|
+
call(api.ctx, "executeApproval", { requestId }).then(
|
|
673
|
+
(/** @type {any} */ result) => {
|
|
674
|
+
const ok = result?.executed === true;
|
|
675
|
+
setExec({
|
|
676
|
+
busy: "",
|
|
677
|
+
ok,
|
|
678
|
+
message: ok
|
|
679
|
+
? text(t, "detail.executed")
|
|
680
|
+
: text(t, "detail.refused", { reason: String(result?.reason ?? "?") }),
|
|
681
|
+
});
|
|
682
|
+
load();
|
|
683
|
+
},
|
|
684
|
+
(error) => {
|
|
685
|
+
setExec({ busy: "", ok: false, message: String(error?.message ?? error) });
|
|
686
|
+
},
|
|
687
|
+
);
|
|
688
|
+
},
|
|
689
|
+
[api, load, setExec, t],
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
const grantsState = useState("");
|
|
693
|
+
const grantsDraft = grantsState[0];
|
|
694
|
+
const setGrantsDraft = grantsState[1];
|
|
695
|
+
const grants = Object.keys(project?.policy?.repoGrants ?? {});
|
|
696
|
+
const setGrants = useCallback(
|
|
697
|
+
(/** @type {string[]} */ next) => {
|
|
698
|
+
/** @type {Record<string, true>} */
|
|
699
|
+
const map = {};
|
|
700
|
+
for (const key of next) map[key] = true;
|
|
701
|
+
const policy = { ...(project?.policy ?? {}), repoGrants: map };
|
|
702
|
+
call(api.ctx, "updateProject", { id: project.id, patch: { policy } }).then(
|
|
703
|
+
() => load(),
|
|
704
|
+
(error) =>
|
|
705
|
+
setData((/** @type {any} */ prev) => ({
|
|
706
|
+
...prev,
|
|
707
|
+
error: String(error?.message ?? error),
|
|
708
|
+
})),
|
|
709
|
+
);
|
|
710
|
+
},
|
|
711
|
+
[api, load, project?.policy, project.id, setData],
|
|
712
|
+
);
|
|
713
|
+
|
|
714
|
+
const purgeState = useState({ phase: "idle", eligible: 0, kept: 0, message: "" });
|
|
715
|
+
const purge = purgeState[0];
|
|
716
|
+
const setPurge = purgeState[1];
|
|
717
|
+
const previewPurge = useCallback(() => {
|
|
718
|
+
setPurge({ phase: "loading", eligible: 0, kept: 0, message: "" });
|
|
719
|
+
call(api.ctx, "purgeTrash", { dryRun: true, projectId: project.id }).then(
|
|
720
|
+
(/** @type {any} */ result) => {
|
|
721
|
+
const eligible = Array.isArray(result?.eligible) ? result.eligible.length : 0;
|
|
722
|
+
setPurge({
|
|
723
|
+
phase: eligible > 0 ? "confirm" : "idle",
|
|
724
|
+
eligible,
|
|
725
|
+
kept: Number(result?.kept ?? 0),
|
|
726
|
+
message: eligible > 0 ? "" : text(t, "detail.purgeNothing"),
|
|
727
|
+
});
|
|
728
|
+
},
|
|
729
|
+
(error) =>
|
|
730
|
+
setPurge({
|
|
731
|
+
phase: "idle",
|
|
732
|
+
eligible: 0,
|
|
733
|
+
kept: 0,
|
|
734
|
+
message: String(error?.message ?? error),
|
|
735
|
+
}),
|
|
736
|
+
);
|
|
737
|
+
}, [api, project.id, setPurge, t]);
|
|
738
|
+
const runPurge = useCallback(() => {
|
|
739
|
+
setPurge((/** @type {any} */ prev) => ({ ...prev, phase: "loading" }));
|
|
740
|
+
call(api.ctx, "purgeTrash", {
|
|
741
|
+
dryRun: false,
|
|
742
|
+
confirm: "purge",
|
|
743
|
+
projectId: project.id,
|
|
744
|
+
}).then(
|
|
745
|
+
(/** @type {any} */ result) => {
|
|
746
|
+
const ok = result?.ok === true;
|
|
747
|
+
setPurge({
|
|
748
|
+
phase: "idle",
|
|
749
|
+
eligible: 0,
|
|
750
|
+
kept: Number(result?.kept ?? 0),
|
|
751
|
+
message: ok
|
|
752
|
+
? text(t, "detail.purged", { count: (result?.purged ?? []).length })
|
|
753
|
+
: text(t, "detail.refused", { reason: String(result?.reason ?? "?") }),
|
|
754
|
+
});
|
|
755
|
+
},
|
|
756
|
+
(error) =>
|
|
757
|
+
setPurge({
|
|
758
|
+
phase: "idle",
|
|
759
|
+
eligible: 0,
|
|
760
|
+
kept: 0,
|
|
761
|
+
message: String(error?.message ?? error),
|
|
762
|
+
}),
|
|
763
|
+
);
|
|
764
|
+
}, [api, project.id, setPurge, t]);
|
|
765
|
+
|
|
637
766
|
const askDelete = useCallback(() => {
|
|
638
767
|
call(api.ctx, "previewDeleteProject", { id: project.id }).then(
|
|
639
768
|
(preview) => setDel({ confirming: true, busy: false, impact: preview }),
|
|
@@ -1029,62 +1158,215 @@ window.__ModuleLoader__.load({
|
|
|
1029
1158
|
text(t, "detail.dirSave"),
|
|
1030
1159
|
),
|
|
1031
1160
|
),
|
|
1032
|
-
(
|
|
1033
|
-
.
|
|
1034
|
-
|
|
1161
|
+
(() => {
|
|
1162
|
+
const all = Array.isArray(data.approvals) ? data.approvals : [];
|
|
1163
|
+
const pending = all.filter((/** @type {any} */ item) => item.status === "pending");
|
|
1164
|
+
// 已批准但还没执行:这才是「批准 ≠ 可执行」里那独立的一步,必须有入口
|
|
1165
|
+
const runnable = all.filter(
|
|
1166
|
+
(/** @type {any} */ item) =>
|
|
1167
|
+
item.status === "approved" &&
|
|
1168
|
+
!(typeof item.executedAt === "string" && item.executedAt !== ""),
|
|
1169
|
+
);
|
|
1170
|
+
if (pending.length === 0 && runnable.length === 0) return null;
|
|
1171
|
+
const row = (/** @type {any} */ item, /** @type {any} */ actions) =>
|
|
1172
|
+
h(
|
|
1035
1173
|
"div",
|
|
1036
1174
|
{
|
|
1037
|
-
|
|
1038
|
-
style: {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1175
|
+
key: item.requestId,
|
|
1176
|
+
style: { display: "flex", gap: "8px", alignItems: "center" },
|
|
1177
|
+
"data-projects-approval-row": item.requestId,
|
|
1178
|
+
},
|
|
1179
|
+
h(
|
|
1180
|
+
"span",
|
|
1181
|
+
{ style: { ...styles.meta, flex: 1, minWidth: 0 } },
|
|
1182
|
+
`${item.action} · ${item.reason}`,
|
|
1183
|
+
),
|
|
1184
|
+
...actions,
|
|
1185
|
+
);
|
|
1186
|
+
return h(
|
|
1187
|
+
"div",
|
|
1188
|
+
{
|
|
1189
|
+
"data-projects-approvals": "",
|
|
1190
|
+
style: {
|
|
1191
|
+
border: `1px solid ${T.border}`,
|
|
1192
|
+
borderRadius: "8px",
|
|
1193
|
+
padding: "8px 10px",
|
|
1194
|
+
marginTop: "8px",
|
|
1195
|
+
display: "flex",
|
|
1196
|
+
flexDirection: "column",
|
|
1197
|
+
gap: "6px",
|
|
1198
|
+
},
|
|
1199
|
+
},
|
|
1200
|
+
h("div", { style: styles.name }, text(t, "detail.approvalsTitle")),
|
|
1201
|
+
pending.map((/** @type {any} */ item) =>
|
|
1202
|
+
row(item, [
|
|
1203
|
+
h(
|
|
1204
|
+
"button",
|
|
1205
|
+
{
|
|
1206
|
+
key: "approve",
|
|
1207
|
+
type: "button",
|
|
1208
|
+
style: styles.button,
|
|
1209
|
+
"data-projects-approval-approve": item.requestId,
|
|
1210
|
+
onClick: () => resolveApproval(item.requestId, "approved"),
|
|
1211
|
+
},
|
|
1212
|
+
text(t, "detail.approve"),
|
|
1213
|
+
),
|
|
1214
|
+
h(
|
|
1215
|
+
"button",
|
|
1216
|
+
{
|
|
1217
|
+
key: "reject",
|
|
1218
|
+
type: "button",
|
|
1219
|
+
style: { ...styles.button, color: T.danger },
|
|
1220
|
+
"data-projects-approval-reject": item.requestId,
|
|
1221
|
+
onClick: () => resolveApproval(item.requestId, "rejected"),
|
|
1222
|
+
},
|
|
1223
|
+
text(t, "detail.reject"),
|
|
1224
|
+
),
|
|
1225
|
+
]),
|
|
1226
|
+
),
|
|
1227
|
+
runnable.map((/** @type {any} */ item) =>
|
|
1228
|
+
row(item, [
|
|
1229
|
+
h(
|
|
1230
|
+
"button",
|
|
1231
|
+
{
|
|
1232
|
+
key: "execute",
|
|
1233
|
+
type: "button",
|
|
1234
|
+
style: styles.button,
|
|
1235
|
+
disabled: exec.busy === item.requestId,
|
|
1236
|
+
"data-projects-approval-execute": item.requestId,
|
|
1237
|
+
onClick: () => executeApproval(item.requestId),
|
|
1238
|
+
},
|
|
1239
|
+
text(t, "detail.execute"),
|
|
1240
|
+
),
|
|
1241
|
+
]),
|
|
1242
|
+
),
|
|
1243
|
+
exec.message !== ""
|
|
1244
|
+
? h(
|
|
1245
|
+
"div",
|
|
1246
|
+
{
|
|
1247
|
+
style: { ...styles.meta, color: exec.ok === false ? T.danger : T.text },
|
|
1248
|
+
"data-projects-approval-exec-result": "",
|
|
1249
|
+
},
|
|
1250
|
+
exec.message,
|
|
1251
|
+
)
|
|
1252
|
+
: null,
|
|
1253
|
+
);
|
|
1254
|
+
})(),
|
|
1255
|
+
// 仓库授权:直推保护分支需要 per-repo 首次授予(规格 §7.5 行 2),没有界面就只能手编 JSON
|
|
1256
|
+
h(
|
|
1257
|
+
"div",
|
|
1258
|
+
{
|
|
1259
|
+
"data-projects-grants": "",
|
|
1260
|
+
style: {
|
|
1261
|
+
border: `1px solid ${T.border}`,
|
|
1262
|
+
borderRadius: "8px",
|
|
1263
|
+
padding: "8px 10px",
|
|
1264
|
+
marginTop: "8px",
|
|
1265
|
+
display: "flex",
|
|
1266
|
+
flexDirection: "column",
|
|
1267
|
+
gap: "6px",
|
|
1268
|
+
},
|
|
1269
|
+
},
|
|
1270
|
+
h("div", { style: styles.name }, text(t, "detail.grantsTitle")),
|
|
1271
|
+
h(
|
|
1272
|
+
"div",
|
|
1273
|
+
{ style: styles.meta },
|
|
1274
|
+
grants.length > 0 ? grants.join(" · ") : text(t, "detail.grantsEmpty"),
|
|
1275
|
+
),
|
|
1276
|
+
h(
|
|
1277
|
+
"div",
|
|
1278
|
+
{ style: { display: "flex", gap: "8px", alignItems: "center" } },
|
|
1279
|
+
h("input", {
|
|
1280
|
+
value: grantsDraft,
|
|
1281
|
+
placeholder: "owner/repo",
|
|
1282
|
+
"data-projects-grant-input": "",
|
|
1283
|
+
style: { ...styles.input, flex: 1, minWidth: 0 },
|
|
1284
|
+
onInput: (/** @type {any} */ event) => setGrantsDraft(event.target.value),
|
|
1285
|
+
}),
|
|
1286
|
+
h(
|
|
1287
|
+
"button",
|
|
1288
|
+
{
|
|
1289
|
+
type: "button",
|
|
1290
|
+
style: styles.button,
|
|
1291
|
+
"data-projects-grant-add": "",
|
|
1292
|
+
onClick: () => {
|
|
1293
|
+
const slug = String(grantsDraft).trim();
|
|
1294
|
+
if (!/^[\w.-]+\/[\w.-]+$/u.test(slug)) return;
|
|
1295
|
+
setGrants([...grants, slug]);
|
|
1296
|
+
setGrantsDraft("");
|
|
1046
1297
|
},
|
|
1047
1298
|
},
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1299
|
+
text(t, "detail.grantAdd"),
|
|
1300
|
+
),
|
|
1301
|
+
),
|
|
1302
|
+
grants.length > 0
|
|
1303
|
+
? h(
|
|
1304
|
+
"div",
|
|
1305
|
+
{ style: { display: "flex", gap: "6px", flexWrap: "wrap" } },
|
|
1306
|
+
...grants.map((/** @type {string} */ slug) =>
|
|
1052
1307
|
h(
|
|
1053
|
-
"
|
|
1308
|
+
"button",
|
|
1054
1309
|
{
|
|
1055
|
-
key:
|
|
1056
|
-
|
|
1057
|
-
|
|
1310
|
+
key: slug,
|
|
1311
|
+
type: "button",
|
|
1312
|
+
style: { ...styles.button, fontSize: "11px" },
|
|
1313
|
+
"data-projects-grant-remove": slug,
|
|
1314
|
+
onClick: () => setGrants(grants.filter((item) => item !== slug)),
|
|
1058
1315
|
},
|
|
1059
|
-
|
|
1060
|
-
"span",
|
|
1061
|
-
{ style: { ...styles.meta, flex: 1, minWidth: 0 } },
|
|
1062
|
-
`${item.action} · ${item.reason}`,
|
|
1063
|
-
),
|
|
1064
|
-
h(
|
|
1065
|
-
"button",
|
|
1066
|
-
{
|
|
1067
|
-
type: "button",
|
|
1068
|
-
style: styles.button,
|
|
1069
|
-
"data-projects-approval-approve": item.requestId,
|
|
1070
|
-
onClick: () => resolveApproval(item.requestId, "approved"),
|
|
1071
|
-
},
|
|
1072
|
-
text(t, "detail.approve"),
|
|
1073
|
-
),
|
|
1074
|
-
h(
|
|
1075
|
-
"button",
|
|
1076
|
-
{
|
|
1077
|
-
type: "button",
|
|
1078
|
-
style: { ...styles.button, color: T.danger },
|
|
1079
|
-
"data-projects-approval-reject": item.requestId,
|
|
1080
|
-
onClick: () => resolveApproval(item.requestId, "rejected"),
|
|
1081
|
-
},
|
|
1082
|
-
text(t, "detail.reject"),
|
|
1083
|
-
),
|
|
1316
|
+
`${slug} ✕`,
|
|
1084
1317
|
),
|
|
1085
1318
|
),
|
|
1086
|
-
|
|
1087
|
-
|
|
1319
|
+
)
|
|
1320
|
+
: null,
|
|
1321
|
+
),
|
|
1322
|
+
// 回收站清理:只处理本项目的、超保留期的条目;先预览再确认(规格 §7.5 行 4c)
|
|
1323
|
+
h(
|
|
1324
|
+
"div",
|
|
1325
|
+
{
|
|
1326
|
+
"data-projects-purge": "",
|
|
1327
|
+
style: {
|
|
1328
|
+
border: `1px solid ${T.border}`,
|
|
1329
|
+
borderRadius: "8px",
|
|
1330
|
+
padding: "8px 10px",
|
|
1331
|
+
marginTop: "8px",
|
|
1332
|
+
display: "flex",
|
|
1333
|
+
flexDirection: "column",
|
|
1334
|
+
gap: "6px",
|
|
1335
|
+
},
|
|
1336
|
+
},
|
|
1337
|
+
h("div", { style: styles.name }, text(t, "detail.purgeTitle")),
|
|
1338
|
+
h("div", { style: styles.meta }, text(t, "detail.purgeHint")),
|
|
1339
|
+
h(
|
|
1340
|
+
"div",
|
|
1341
|
+
{ style: { display: "flex", gap: "8px", alignItems: "center" } },
|
|
1342
|
+
h(
|
|
1343
|
+
"button",
|
|
1344
|
+
{
|
|
1345
|
+
type: "button",
|
|
1346
|
+
style: styles.button,
|
|
1347
|
+
disabled: purge.phase === "loading",
|
|
1348
|
+
"data-projects-purge-preview": "",
|
|
1349
|
+
onClick: previewPurge,
|
|
1350
|
+
},
|
|
1351
|
+
text(t, "detail.purgePreview"),
|
|
1352
|
+
),
|
|
1353
|
+
purge.phase === "confirm"
|
|
1354
|
+
? h(
|
|
1355
|
+
"button",
|
|
1356
|
+
{
|
|
1357
|
+
type: "button",
|
|
1358
|
+
style: { ...styles.button, color: T.danger },
|
|
1359
|
+
"data-projects-purge-confirm": "",
|
|
1360
|
+
onClick: runPurge,
|
|
1361
|
+
},
|
|
1362
|
+
text(t, "detail.purgeConfirm", { count: purge.eligible }),
|
|
1363
|
+
)
|
|
1364
|
+
: null,
|
|
1365
|
+
),
|
|
1366
|
+
purge.message !== ""
|
|
1367
|
+
? h("div", { style: styles.meta, "data-projects-purge-result": "" }, purge.message)
|
|
1368
|
+
: null,
|
|
1369
|
+
),
|
|
1088
1370
|
del.confirming
|
|
1089
1371
|
? h(
|
|
1090
1372
|
"div",
|
package/lib/executor.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// 三种授权来源之外一律拒绝;模型输出/外部内容/peer 消息永远不算授权。
|
|
6
6
|
|
|
7
7
|
import { planForcePush } from "./git-push.js";
|
|
8
|
+
import { sanitizeSettingsPatch } from "./settings.js";
|
|
8
9
|
|
|
9
10
|
/** 可执行的危险动作(与 tools.js 的 REQUESTABLE_ACTIONS 同集合,但语义不同:
|
|
10
11
|
* 这里问的是「能不能执行」,那边问的是「能不能申请」。 */
|
|
@@ -137,6 +138,13 @@ export function planCommand(action, args) {
|
|
|
137
138
|
return { argv: ["git", "push", "origin", branch] };
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
if (action === "change-settings") {
|
|
142
|
+
// 只为「改本插件自己的配置」:白名单在 settings.js 里,越界直接拒
|
|
143
|
+
const checked = sanitizeSettingsPatch(args?.patch);
|
|
144
|
+
if (!checked.ok) return { error: checked.reason };
|
|
145
|
+
return { argv: ["update-settings", checked.keys.join(",")] };
|
|
146
|
+
}
|
|
147
|
+
|
|
140
148
|
if (action === "purge-trash") {
|
|
141
149
|
// 真正的删除由 service 用 fs 做;这里只表达「这是内部动作」
|
|
142
150
|
return { argv: ["purge-trash", String(args?.confirm ?? "")] };
|
package/lib/service.js
CHANGED
|
@@ -41,6 +41,7 @@ import { buildPersona } from "./persona.js";
|
|
|
41
41
|
import { readProjectFiles } from "./project-files.js";
|
|
42
42
|
import { buildPurgeManifest, DEFAULT_RETENTION_DAYS, selectExpired } from "./purge.js";
|
|
43
43
|
import { decideRoute } from "./routing.js";
|
|
44
|
+
import { applySettingsPatch, sanitizeSettingsPatch } from "./settings.js";
|
|
44
45
|
import { ProjectStore } from "./store.js";
|
|
45
46
|
import { createIsolatedThread, reclaimThreadWorktree, reconcileWorktrees } from "./thread.js";
|
|
46
47
|
import { buildCoordinatorTools, REQUESTABLE_ACTIONS } from "./tools.js";
|
|
@@ -1903,6 +1904,63 @@ export class ProjectsService extends TypertRemoteService {
|
|
|
1903
1904
|
return ok ? { executed: true, evidence } : { executed: false, reason: "gh-merge-failed" };
|
|
1904
1905
|
}
|
|
1905
1906
|
|
|
1907
|
+
// 改本插件自己的配置(规格 §7.5 行 5a):只允许白名单键,安全面一律拒绝
|
|
1908
|
+
if (approval.action === "change-settings") {
|
|
1909
|
+
const checked = sanitizeSettingsPatch(approval.args?.patch);
|
|
1910
|
+
if (!checked.ok) {
|
|
1911
|
+
store.appendAudit({
|
|
1912
|
+
action: "approval/execution-refused",
|
|
1913
|
+
projectId: approval.projectId,
|
|
1914
|
+
requestId,
|
|
1915
|
+
dangerAction: approval.action,
|
|
1916
|
+
reason: checked.reason,
|
|
1917
|
+
});
|
|
1918
|
+
store.save();
|
|
1919
|
+
return { executed: false, reason: checked.reason };
|
|
1920
|
+
}
|
|
1921
|
+
const before = store.getProject(approval.projectId);
|
|
1922
|
+
const nextPolicy = applySettingsPatch(before?.policy ?? {}, checked.patch);
|
|
1923
|
+
store.updateProject(approval.projectId, { policy: nextPolicy });
|
|
1924
|
+
const evidence = recoveryEvidence(approval.action, { keys: checked.keys }, {});
|
|
1925
|
+
store.appendAudit({
|
|
1926
|
+
action: "approval/executed",
|
|
1927
|
+
projectId: approval.projectId,
|
|
1928
|
+
requestId,
|
|
1929
|
+
dangerAction: approval.action,
|
|
1930
|
+
keys: checked.keys,
|
|
1931
|
+
evidence,
|
|
1932
|
+
});
|
|
1933
|
+
store.save();
|
|
1934
|
+
return { executed: true, evidence, keys: checked.keys };
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
// 回收站清理(规格 §7.5 行 4c):审批路径复用 purgeTrash,开关与项目都按本次申请的项目判定
|
|
1938
|
+
if (approval.action === "purge-trash") {
|
|
1939
|
+
const purged = this.purgeTrash({
|
|
1940
|
+
dryRun: false,
|
|
1941
|
+
confirm: "purge",
|
|
1942
|
+
projectId: approval.projectId,
|
|
1943
|
+
});
|
|
1944
|
+
const ok = purged.ok === true;
|
|
1945
|
+
const evidence = recoveryEvidence(approval.action, approval.args ?? {}, {
|
|
1946
|
+
purged: purged.purged.length,
|
|
1947
|
+
kept: purged.kept,
|
|
1948
|
+
manifestPath: purged.manifestPath ?? "",
|
|
1949
|
+
});
|
|
1950
|
+
store.appendAudit({
|
|
1951
|
+
action: ok ? "approval/executed" : "approval/execution-failed",
|
|
1952
|
+
projectId: approval.projectId,
|
|
1953
|
+
requestId,
|
|
1954
|
+
dangerAction: approval.action,
|
|
1955
|
+
evidence,
|
|
1956
|
+
...(ok ? {} : { reason: purged.reason ?? "purge-failed" }),
|
|
1957
|
+
});
|
|
1958
|
+
store.save();
|
|
1959
|
+
return ok
|
|
1960
|
+
? { executed: true, evidence, purged: purged.purged.length, kept: purged.kept }
|
|
1961
|
+
: { executed: false, reason: purged.reason ?? "purge-failed" };
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1906
1964
|
store.appendAudit({
|
|
1907
1965
|
action: "approval/execution-deferred",
|
|
1908
1966
|
projectId: approval.projectId,
|
package/lib/settings.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 规格 §7.5 行 5a:模型可以申请「改本插件自己的配置」,但**不能**改安全约束本身。
|
|
3
|
+
// 这条白名单就是「自己的配置」与「自我提权」的分界线,纯函数便于单测。
|
|
4
|
+
|
|
5
|
+
/** 允许通过审批修改的项目策略键(都是非安全面)。 */
|
|
6
|
+
export const EDITABLE_KEYS = Object.freeze(["persona", "routing", "goal"]);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 明确禁止的键(规格 §7.5 行 5b:改审批/预算/审计开关本身 = 自我提权)。
|
|
10
|
+
* 命中就拒绝,且要给出可读理由。
|
|
11
|
+
*/
|
|
12
|
+
export const FORBIDDEN_KEYS = Object.freeze([
|
|
13
|
+
"danger",
|
|
14
|
+
"autonomy",
|
|
15
|
+
"preapprove",
|
|
16
|
+
"budget",
|
|
17
|
+
"repoGrants",
|
|
18
|
+
"coordinatorSessionId",
|
|
19
|
+
"state",
|
|
20
|
+
"id",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 校验一个「改配置」补丁。
|
|
25
|
+
* @param {any} patch
|
|
26
|
+
* @returns {{ ok: true, patch: Record<string, any>, keys: string[] } | { ok: false, reason: string }}
|
|
27
|
+
*/
|
|
28
|
+
export function sanitizeSettingsPatch(patch) {
|
|
29
|
+
if (!patch || typeof patch !== "object" || Array.isArray(patch)) {
|
|
30
|
+
return { ok: false, reason: "settings/patch-required" };
|
|
31
|
+
}
|
|
32
|
+
const entries = Object.entries(patch);
|
|
33
|
+
if (entries.length === 0) return { ok: false, reason: "settings/patch-empty" };
|
|
34
|
+
/** @type {Record<string, any>} */
|
|
35
|
+
const clean = {};
|
|
36
|
+
for (const [key, value] of entries) {
|
|
37
|
+
if (FORBIDDEN_KEYS.includes(key)) return { ok: false, reason: `settings/forbidden:${key}` };
|
|
38
|
+
if (!EDITABLE_KEYS.includes(key)) return { ok: false, reason: `settings/not-editable:${key}` };
|
|
39
|
+
if (key === "persona" && typeof value !== "string") {
|
|
40
|
+
return { ok: false, reason: "settings/persona-must-be-string" };
|
|
41
|
+
}
|
|
42
|
+
if (key === "goal" && typeof value !== "string") {
|
|
43
|
+
return { ok: false, reason: "settings/goal-must-be-string" };
|
|
44
|
+
}
|
|
45
|
+
if (key === "routing") {
|
|
46
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
47
|
+
return { ok: false, reason: "settings/routing-must-be-object" };
|
|
48
|
+
}
|
|
49
|
+
const rules = Array.isArray(value.rules) ? value.rules : [];
|
|
50
|
+
for (const rule of rules) {
|
|
51
|
+
const shape = rule && typeof rule === "object" ? rule : {};
|
|
52
|
+
if (typeof shape.id !== "string" || typeof shape.when !== "string") {
|
|
53
|
+
return { ok: false, reason: "settings/routing-rule-shape" };
|
|
54
|
+
}
|
|
55
|
+
if (typeof shape.action !== "string") {
|
|
56
|
+
return { ok: false, reason: "settings/routing-rule-shape" };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
clean.routing = { rules, fallback: value.fallback !== false };
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
clean[key] = value;
|
|
63
|
+
}
|
|
64
|
+
return { ok: true, patch: clean, keys: Object.keys(clean) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 把补丁应用到策略上(只覆盖白名单键,其余原样保留)。
|
|
69
|
+
* @param {any} policy
|
|
70
|
+
* @param {Record<string, any>} patch
|
|
71
|
+
* @returns {any}
|
|
72
|
+
*/
|
|
73
|
+
export function applySettingsPatch(policy, patch) {
|
|
74
|
+
const next = { ...(policy ?? {}) };
|
|
75
|
+
for (const [key, value] of Object.entries(patch ?? {})) {
|
|
76
|
+
next[key] = value;
|
|
77
|
+
}
|
|
78
|
+
return next;
|
|
79
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -89,6 +89,18 @@
|
|
|
89
89
|
"settings.danger.editProfile.label": "edit project policy itself",
|
|
90
90
|
"settings.danger.editProfile.risk": "the coordinator could loosen its own limits; highest risk",
|
|
91
91
|
"detail.archive": "Archive project",
|
|
92
|
-
"detail.unarchive": "Unarchive project"
|
|
92
|
+
"detail.unarchive": "Unarchive project",
|
|
93
|
+
"detail.execute": "Execute",
|
|
94
|
+
"detail.executed": "Executed (see audit)",
|
|
95
|
+
"detail.refused": "Not executed: {reason}",
|
|
96
|
+
"detail.grantsTitle": "Repository grants (for pushing protected branches)",
|
|
97
|
+
"detail.grantsEmpty": "No repository granted yet; add owner/repo before pushing a protected branch",
|
|
98
|
+
"detail.grantAdd": "Add",
|
|
99
|
+
"detail.purgeTitle": "Trash purge",
|
|
100
|
+
"detail.purgeHint": "Only purges entries in this project's trash that are **past the retention period**; preview first, then confirm. Requires the purgeAfterRetention switch.",
|
|
101
|
+
"detail.purgePreview": "Preview purgeable",
|
|
102
|
+
"detail.purgeConfirm": "Purge {count} entries",
|
|
103
|
+
"detail.purgeNothing": "Nothing past the retention period",
|
|
104
|
+
"detail.purged": "Purged {count} entries; manifest written under trash/"
|
|
93
105
|
}
|
|
94
106
|
}
|
package/locale/zh.json
CHANGED
|
@@ -89,6 +89,18 @@
|
|
|
89
89
|
"settings.danger.editProfile.label": "允许修改项目策略本身",
|
|
90
90
|
"settings.danger.editProfile.risk": "协调器可能借此放宽自己的限制;风险最高",
|
|
91
91
|
"detail.archive": "归档项目",
|
|
92
|
-
"detail.unarchive": "取消归档"
|
|
92
|
+
"detail.unarchive": "取消归档",
|
|
93
|
+
"detail.execute": "执行",
|
|
94
|
+
"detail.executed": "已执行(结果见审计)",
|
|
95
|
+
"detail.refused": "未执行:{reason}",
|
|
96
|
+
"detail.grantsTitle": "仓库授权(直推保护分支用)",
|
|
97
|
+
"detail.grantsEmpty": "尚未授权任何仓库;直推保护分支前必须在这里加 owner/repo",
|
|
98
|
+
"detail.grantAdd": "添加",
|
|
99
|
+
"detail.purgeTitle": "回收站清理",
|
|
100
|
+
"detail.purgeHint": "只清理本项目回收站里**超过保留期**的条目;先预览,再确认。需要打开 purgeAfterRetention 开关。",
|
|
101
|
+
"detail.purgePreview": "预览可清理项",
|
|
102
|
+
"detail.purgeConfirm": "确认清理 {count} 项",
|
|
103
|
+
"detail.purgeNothing": "没有超过保留期的条目",
|
|
104
|
+
"detail.purged": "已清理 {count} 项,清单已写入 trash/"
|
|
93
105
|
}
|
|
94
106
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangyishuai/dsh-projects",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|