@dungsil/dsh-plugin-ui-setting-vcs 0.2.0 → 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/dist/client.js +169 -14
- package/dist/index.js +57 -21
- package/package.json +3 -1
package/dist/client.js
CHANGED
|
@@ -9,6 +9,15 @@ function useLocaleSnapshot(locale) {
|
|
|
9
9
|
const getSnapshot = (0, react.useCallback)(() => locale.getSnapshot(), [locale]);
|
|
10
10
|
return (0, react.useSyncExternalStore)(subscribe, getSnapshot);
|
|
11
11
|
}
|
|
12
|
+
/** Key of a per-language record for the language's primary subtag, falling back to `fallback`. */
|
|
13
|
+
function localizedLanguage(languages, language, fallback = "en") {
|
|
14
|
+
const base = language.toLowerCase().split(/[-_]/)[0];
|
|
15
|
+
return Object.hasOwn(languages, base) ? base : fallback;
|
|
16
|
+
}
|
|
17
|
+
/** Entry of a per-language record for the language's primary subtag, falling back to `fallback`. */
|
|
18
|
+
function localizedCopy(languages, language, fallback = "en") {
|
|
19
|
+
return languages[localizedLanguage(languages, language, fallback)];
|
|
20
|
+
}
|
|
12
21
|
/** Each effect owns its sheet, even when another plugin installs the same defaults. */
|
|
13
22
|
function installStyles(css) {
|
|
14
23
|
const style = document.createElement("style");
|
|
@@ -37,6 +46,41 @@ function SettingsRow({ label, children }) {
|
|
|
37
46
|
}), children]
|
|
38
47
|
});
|
|
39
48
|
}
|
|
49
|
+
function SettingsPicker({ className = "", value, selectedId, items, onSelect, disabled = false, ...buttonProps }) {
|
|
50
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
51
|
+
(0, react.useEffect)(() => {
|
|
52
|
+
if (disabled) setOpen(false);
|
|
53
|
+
}, [disabled]);
|
|
54
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
|
|
55
|
+
className: `dsh-plugin-settings-picker ${className}`,
|
|
56
|
+
open: open && !disabled,
|
|
57
|
+
onClose: () => setOpen(false),
|
|
58
|
+
items,
|
|
59
|
+
selectedId,
|
|
60
|
+
onSelect: (id) => {
|
|
61
|
+
setOpen(false);
|
|
62
|
+
if (!disabled) onSelect(id);
|
|
63
|
+
},
|
|
64
|
+
align: "end",
|
|
65
|
+
portal: true,
|
|
66
|
+
anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
67
|
+
...buttonProps,
|
|
68
|
+
type: "button",
|
|
69
|
+
className: "dsh-plugin-settings-selector",
|
|
70
|
+
"aria-haspopup": "menu",
|
|
71
|
+
"aria-expanded": open && !disabled,
|
|
72
|
+
disabled,
|
|
73
|
+
onClick: () => setOpen((current) => !current),
|
|
74
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
75
|
+
className: "dsh-plugin-settings-value",
|
|
76
|
+
children: value
|
|
77
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {
|
|
78
|
+
size: 16,
|
|
79
|
+
"aria-hidden": "true"
|
|
80
|
+
})]
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
}
|
|
40
84
|
// src/protocol.ts
|
|
41
85
|
const channel = "/api";
|
|
42
86
|
const readMethod = "dungsil-setting-vcs/read";
|
|
@@ -45,7 +89,12 @@ function validSettings(value, kind) {
|
|
|
45
89
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
46
90
|
const settings = value;
|
|
47
91
|
const target = kind ?? (Object.hasOwn(settings, "directory") ? "worktree" : "panel");
|
|
48
|
-
const keys = target === "worktree" ? [
|
|
92
|
+
const keys = target === "worktree" ? [
|
|
93
|
+
"directory",
|
|
94
|
+
"prefix",
|
|
95
|
+
"cleanupOnArchive"
|
|
96
|
+
] : ["prefix"];
|
|
97
|
+
if (target === "worktree" && typeof settings.cleanupOnArchive !== "boolean") return false;
|
|
49
98
|
if (Object.keys(settings).length !== keys.length || !keys.every((key) => Object.hasOwn(settings, key))) return false;
|
|
50
99
|
if (typeof settings.prefix !== "string" || settings.prefix.length > 100 || settings.prefix !== "" && (!/^[A-Za-z0-9_]/.test(settings.prefix) || /[^A-Za-z0-9_-]/.test(settings.prefix))) return false;
|
|
51
100
|
if (target === "panel") return true;
|
|
@@ -56,14 +105,21 @@ function validSettings(value, kind) {
|
|
|
56
105
|
const copy = {
|
|
57
106
|
en: {
|
|
58
107
|
nav: "Version control",
|
|
59
|
-
scope: "Changes are saved automatically and apply to future worktrees from
|
|
108
|
+
scope: "Changes are saved automatically. Directory and naming settings apply to future worktrees from tools and the Forge UI; changing a setting does not immediately alter existing checkouts or Git configuration.",
|
|
109
|
+
cleanup: "Remove worktree on archive",
|
|
110
|
+
cleanupHint: "When a session is archived, eligible clean Git worktrees are removed. This setting does not delete branches.",
|
|
111
|
+
checkout: "Default checkout for new sessions",
|
|
112
|
+
checkoutHint: "Choose where blank sessions start. Sessions that have started and existing worktree requests are not changed.",
|
|
113
|
+
checkoutCurrent: "Current checkout",
|
|
114
|
+
checkoutWorktree: "New worktree",
|
|
115
|
+
checkoutError: "Could not save the default checkout. Try again.",
|
|
60
116
|
worktree: "Worktrees",
|
|
61
117
|
panel: "Forge panel",
|
|
62
118
|
directory: "Worktree directory",
|
|
63
119
|
prefix: "Worktree name prefix",
|
|
64
120
|
directoryHint: "Use a repository-relative subdirectory with / separators; absolute paths and . or .. segments are not supported.",
|
|
65
121
|
prefixHint: "Used for automatically generated names, not semantic branch naming.",
|
|
66
|
-
unsupported: "The official Forge bundle does not support the previous commit author, commit signing,
|
|
122
|
+
unsupported: "The official Forge bundle does not support the previous commit author, commit signing, tracked remote, or semantic branch naming settings. These settings are not migrated or saved here.",
|
|
67
123
|
empty: "No editable Forge settings were found. Enable the official Forge bundle first.",
|
|
68
124
|
loading: "Loading…",
|
|
69
125
|
saving: "Saving…",
|
|
@@ -77,14 +133,21 @@ const copy = {
|
|
|
77
133
|
},
|
|
78
134
|
ko: {
|
|
79
135
|
nav: "버전 관리",
|
|
80
|
-
scope: "변경 사항은 자동
|
|
136
|
+
scope: "변경 사항은 자동 저장됩니다. 디렉터리와 이름 설정은 이후 도구와 Forge UI에서 생성할 워크트리에 적용되며, 설정 변경만으로 기존 체크아웃이나 Git 설정이 즉시 바뀌지는 않습니다.",
|
|
137
|
+
cleanup: "보관 시 워크트리 제거",
|
|
138
|
+
cleanupHint: "세션을 보관하면 제거 가능한 깨끗한 Git 워크트리가 제거됩니다. 이 설정은 브랜치를 삭제하지 않습니다.",
|
|
139
|
+
checkout: "새 세션의 기본 체크아웃",
|
|
140
|
+
checkoutHint: "빈 세션의 작업 위치를 선택합니다. 이미 시작한 세션과 기존 워크트리 요청은 변경하지 않습니다.",
|
|
141
|
+
checkoutCurrent: "현재 체크아웃",
|
|
142
|
+
checkoutWorktree: "새 워크트리",
|
|
143
|
+
checkoutError: "기본 체크아웃을 저장하지 못했습니다. 다시 시도하세요.",
|
|
81
144
|
worktree: "워크트리",
|
|
82
145
|
panel: "Forge 패널",
|
|
83
146
|
directory: "워크트리 디렉터리",
|
|
84
147
|
prefix: "워크트리 이름 접두사",
|
|
85
148
|
directoryHint: "저장소 아래의 상대 경로를 /로 구분해 입력하세요. 절대 경로와 . 또는 .. 경로 조각은 지원하지 않습니다.",
|
|
86
149
|
prefixHint: "자동 생성 이름에 사용하며, 시멘틱 브랜치 이름 형식은 지원하지 않습니다.",
|
|
87
|
-
unsupported: "공식 Forge 번들은 기존의 커밋 작성자, 커밋 서명,
|
|
150
|
+
unsupported: "공식 Forge 번들은 기존의 커밋 작성자, 커밋 서명, 추적 중인 원격 브랜치, 시멘틱 브랜치 이름 설정을 지원하지 않습니다. 이 항목들은 여기서 이전하거나 저장하지 않습니다.",
|
|
88
151
|
empty: "편집할 수 있는 Forge 설정이 없습니다. 먼저 공식 Forge 번들을 활성화하세요.",
|
|
89
152
|
loading: "불러오는 중…",
|
|
90
153
|
saving: "저장 중…",
|
|
@@ -98,14 +161,21 @@ const copy = {
|
|
|
98
161
|
},
|
|
99
162
|
zh: {
|
|
100
163
|
nav: "版本控制",
|
|
101
|
-
scope: "
|
|
164
|
+
scope: "更改会自动保存。目录和命名设置适用于之后通过工具和 Forge UI 创建的工作树;更改设置不会立即修改现有检出或 Git 配置。",
|
|
165
|
+
cleanup: "归档时移除工作树",
|
|
166
|
+
cleanupHint: "归档会话时,会移除符合条件且干净的 Git 工作树。此设置不会删除分支。",
|
|
167
|
+
checkout: "新会话的默认检出",
|
|
168
|
+
checkoutHint: "选择空白会话的工作位置。不会更改已开始的会话和现有工作树请求。",
|
|
169
|
+
checkoutCurrent: "当前检出",
|
|
170
|
+
checkoutWorktree: "新建工作树",
|
|
171
|
+
checkoutError: "无法保存默认检出,请重试。",
|
|
102
172
|
worktree: "工作树",
|
|
103
173
|
panel: "Forge 面板",
|
|
104
174
|
directory: "工作树目录",
|
|
105
175
|
prefix: "工作树名称前缀",
|
|
106
176
|
directoryHint: "请输入以 / 分隔的仓库内相对目录。不支持绝对路径以及 . 或 .. 路径段。",
|
|
107
177
|
prefixHint: "用于自动生成的名称,不支持语义化分支命名。",
|
|
108
|
-
unsupported: "官方 Forge
|
|
178
|
+
unsupported: "官方 Forge 插件包不支持旧版的提交作者、提交签名、跟踪远程分支或语义化分支命名设置。此处不会迁移或保存这些设置。",
|
|
109
179
|
empty: "未找到可编辑的 Forge 设置。请先启用官方 Forge 插件包。",
|
|
110
180
|
loading: "正在加载…",
|
|
111
181
|
saving: "正在保存…",
|
|
@@ -118,7 +188,67 @@ const copy = {
|
|
|
118
188
|
invalid: "请输入有效的相对目录(最多 4096 个字符)。前缀可留空,或以 ASCII 字母、数字、下划线开头,后接这些字符或连字符(最多 100 个字符)。"
|
|
119
189
|
}
|
|
120
190
|
};
|
|
121
|
-
|
|
191
|
+
// src/default-checkout.tsx
|
|
192
|
+
const read = "dungsil-worktree-preference/read";
|
|
193
|
+
const save = "dungsil-worktree-preference/save";
|
|
194
|
+
function DefaultCheckoutRow({ connection, text }) {
|
|
195
|
+
const id = (0, react.useId)();
|
|
196
|
+
const [value, setValue] = (0, react.useState)();
|
|
197
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
198
|
+
const [error, setError] = (0, react.useState)(false);
|
|
199
|
+
const lifetime = (0, react.useRef)(null);
|
|
200
|
+
(0, react.useEffect)(() => {
|
|
201
|
+
const abort = new AbortController();
|
|
202
|
+
lifetime.current = abort;
|
|
203
|
+
connection.rpc.call("/api", read, {}, abort.signal).then((result) => {
|
|
204
|
+
if (abort.signal.aborted || !result.ok) return;
|
|
205
|
+
const next = result.value?.defaultCheckout;
|
|
206
|
+
if (next === "current" || next === "worktree") setValue(next);
|
|
207
|
+
}).catch(() => {});
|
|
208
|
+
return () => abort.abort();
|
|
209
|
+
}, [connection]);
|
|
210
|
+
if (!value) return null;
|
|
211
|
+
const choose = async (next) => {
|
|
212
|
+
if (busy || next !== "current" && next !== "worktree" || next === value) return;
|
|
213
|
+
const signal = lifetime.current?.signal;
|
|
214
|
+
if (!signal || signal.aborted) return;
|
|
215
|
+
setBusy(true);
|
|
216
|
+
setError(false);
|
|
217
|
+
try {
|
|
218
|
+
const result = await connection.rpc.call("/api", save, { defaultCheckout: next }, signal);
|
|
219
|
+
if (signal.aborted) return;
|
|
220
|
+
if (!result.ok || result.value?.defaultCheckout !== next) throw new Error("unconfirmed");
|
|
221
|
+
setValue(next);
|
|
222
|
+
} catch {
|
|
223
|
+
if (!signal.aborted) setError(true);
|
|
224
|
+
} finally {
|
|
225
|
+
if (!signal.aborted) setBusy(false);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingsRow, {
|
|
229
|
+
label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
230
|
+
id,
|
|
231
|
+
children: text.checkout
|
|
232
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: text.checkoutHint })] }),
|
|
233
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingsPicker, {
|
|
234
|
+
"aria-labelledby": id,
|
|
235
|
+
value: value === "current" ? text.checkoutCurrent : text.checkoutWorktree,
|
|
236
|
+
selectedId: value,
|
|
237
|
+
items: [{
|
|
238
|
+
id: "current",
|
|
239
|
+
label: text.checkoutCurrent
|
|
240
|
+
}, {
|
|
241
|
+
id: "worktree",
|
|
242
|
+
label: text.checkoutWorktree
|
|
243
|
+
}],
|
|
244
|
+
disabled: busy,
|
|
245
|
+
onSelect: (next) => void choose(next)
|
|
246
|
+
})
|
|
247
|
+
}), error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
248
|
+
role: "alert",
|
|
249
|
+
children: text.checkoutError
|
|
250
|
+
})] });
|
|
251
|
+
}
|
|
122
252
|
// src/client.tsx
|
|
123
253
|
const inject = [
|
|
124
254
|
"connection",
|
|
@@ -127,11 +257,13 @@ const inject = [
|
|
|
127
257
|
];
|
|
128
258
|
const validPatch = (patch) => (patch.directory === void 0 || validSettings({
|
|
129
259
|
directory: patch.directory,
|
|
130
|
-
prefix: ""
|
|
260
|
+
prefix: "",
|
|
261
|
+
cleanupOnArchive: true
|
|
131
262
|
}, "worktree")) && (patch.prefix === void 0 || validSettings({ prefix: patch.prefix }, "panel"));
|
|
132
263
|
const common = (values) => values.every((value) => value === values[0]) ? values[0] : void 0;
|
|
133
264
|
function VcsSettings({ ctx }) {
|
|
134
|
-
const
|
|
265
|
+
const { active } = useLocaleSnapshot(ctx.locale);
|
|
266
|
+
const text = localizedCopy(copy, active);
|
|
135
267
|
const id = (0, react.useId)();
|
|
136
268
|
const [view, setView] = (0, react.useState)();
|
|
137
269
|
const [draft, setDraft] = (0, react.useState)({});
|
|
@@ -161,7 +293,8 @@ function VcsSettings({ ctx }) {
|
|
|
161
293
|
setView(next);
|
|
162
294
|
setDraft({
|
|
163
295
|
directory: common(next.entries.filter((entry) => entry.kind === "worktree").map((entry) => entry.settings.directory)),
|
|
164
|
-
prefix: common(next.entries.map((entry) => entry.settings.prefix))
|
|
296
|
+
prefix: common(next.entries.map((entry) => entry.settings.prefix)),
|
|
297
|
+
cleanupOnArchive: common(next.entries.filter((entry) => entry.kind === "worktree").map((entry) => entry.settings.cleanupOnArchive))
|
|
165
298
|
});
|
|
166
299
|
setNotice(void 0);
|
|
167
300
|
setSavedNotice(false);
|
|
@@ -186,7 +319,8 @@ function VcsSettings({ ctx }) {
|
|
|
186
319
|
const settings = {
|
|
187
320
|
...entry.settings,
|
|
188
321
|
...patch.prefix !== void 0 ? { prefix: patch.prefix } : {},
|
|
189
|
-
...entry.kind === "worktree" && patch.directory !== void 0 ? { directory: patch.directory } : {}
|
|
322
|
+
...entry.kind === "worktree" && patch.directory !== void 0 ? { directory: patch.directory } : {},
|
|
323
|
+
...entry.kind === "worktree" && patch.cleanupOnArchive !== void 0 ? { cleanupOnArchive: patch.cleanupOnArchive } : {}
|
|
190
324
|
};
|
|
191
325
|
if (JSON.stringify(settings) === JSON.stringify(entry.settings)) continue;
|
|
192
326
|
const result = await connection.rpc.call(channel, saveMethod, {
|
|
@@ -204,7 +338,11 @@ function VcsSettings({ ctx }) {
|
|
|
204
338
|
if (!next) throw new Error("unavailable");
|
|
205
339
|
saved.current = { entries: saved.current.entries.map((item) => item.id === entry.id ? next : item) };
|
|
206
340
|
}
|
|
207
|
-
for (const key of [
|
|
341
|
+
for (const key of [
|
|
342
|
+
"directory",
|
|
343
|
+
"prefix",
|
|
344
|
+
"cleanupOnArchive"
|
|
345
|
+
]) if (latest.current[key] === patch[key]) delete latest.current[key];
|
|
208
346
|
}
|
|
209
347
|
setSavedNotice(Object.keys(latest.current).length === 0);
|
|
210
348
|
} catch {
|
|
@@ -256,6 +394,10 @@ function VcsSettings({ ctx }) {
|
|
|
256
394
|
"aria-busy": loading || saving,
|
|
257
395
|
children: [
|
|
258
396
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: text.scope }),
|
|
397
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultCheckoutRow, {
|
|
398
|
+
connection,
|
|
399
|
+
text
|
|
400
|
+
}),
|
|
259
401
|
loading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
260
402
|
role: "status",
|
|
261
403
|
children: text.loading
|
|
@@ -283,6 +425,19 @@ function VcsSettings({ ctx }) {
|
|
|
283
425
|
onChange: (event) => change("directory", event.target.value)
|
|
284
426
|
})
|
|
285
427
|
}),
|
|
428
|
+
hasDirectory && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingsRow, {
|
|
429
|
+
label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
430
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: text.cleanup }),
|
|
431
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: text.cleanupHint }),
|
|
432
|
+
draft.cleanupOnArchive === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: text.mixed })
|
|
433
|
+
] }),
|
|
434
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
|
|
435
|
+
label: text.cleanup,
|
|
436
|
+
checked: draft.cleanupOnArchive ?? false,
|
|
437
|
+
disabled: saving,
|
|
438
|
+
onChange: (value) => change("cleanupOnArchive", value)
|
|
439
|
+
})
|
|
440
|
+
}),
|
|
286
441
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingsRow, {
|
|
287
442
|
label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
288
443
|
htmlFor: `${id}-prefix`,
|
|
@@ -338,7 +493,7 @@ function apply(ctx) {
|
|
|
338
493
|
name: "settings.section",
|
|
339
494
|
id: "dungsil-ui-setting-vcs",
|
|
340
495
|
order: 18,
|
|
341
|
-
label: () =>
|
|
496
|
+
label: () => localizedCopy(copy, ctx.locale.getSnapshot().active).nav,
|
|
342
497
|
inject: () => ({ ctx })
|
|
343
498
|
}, VcsSettings));
|
|
344
499
|
ctx.effect(() => installStyles(`${settingsStyles}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { clientRequestSchema } from "@deepseek-ai/dsh-client-connection";
|
|
3
|
+
// ../../tools/plugin-server/src/rpc.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parse a Connection fetch request against one exact method. Returns null for
|
|
6
|
+
* anything the envelope rejects, so the caller answers 400; payload validation
|
|
7
|
+
* stays with the endpoint owner.
|
|
8
|
+
*/
|
|
9
|
+
async function parseRpcRequest(request, method) {
|
|
10
|
+
let parsed;
|
|
11
|
+
try {
|
|
12
|
+
parsed = clientRequestSchema.safeParse(await request.json());
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (!parsed.success || parsed.data.method !== method) return null;
|
|
17
|
+
return {
|
|
18
|
+
rpcId: parsed.data.rpcId,
|
|
19
|
+
payload: parsed.data.payload
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Reply to a parsed request with the server-response envelope. Cache-control
|
|
24
|
+
* keeps proxies and caches from reusing one RPC result for another request.
|
|
25
|
+
*/
|
|
26
|
+
function rpcResponse(rpcId, result) {
|
|
27
|
+
return Response.json({
|
|
28
|
+
type: "server-response",
|
|
29
|
+
rpcId,
|
|
30
|
+
result
|
|
31
|
+
}, { headers: { "Cache-Control": "no-store" } });
|
|
32
|
+
}
|
|
3
33
|
// src/protocol.ts
|
|
4
34
|
const channel = "/api";
|
|
5
35
|
const readMethod = "dungsil-setting-vcs/read";
|
|
@@ -8,7 +38,12 @@ function validSettings(value, kind) {
|
|
|
8
38
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
9
39
|
const settings = value;
|
|
10
40
|
const target = kind ?? (Object.hasOwn(settings, "directory") ? "worktree" : "panel");
|
|
11
|
-
const keys = target === "worktree" ? [
|
|
41
|
+
const keys = target === "worktree" ? [
|
|
42
|
+
"directory",
|
|
43
|
+
"prefix",
|
|
44
|
+
"cleanupOnArchive"
|
|
45
|
+
] : ["prefix"];
|
|
46
|
+
if (target === "worktree" && typeof settings.cleanupOnArchive !== "boolean") return false;
|
|
12
47
|
if (Object.keys(settings).length !== keys.length || !keys.every((key) => Object.hasOwn(settings, key))) return false;
|
|
13
48
|
if (typeof settings.prefix !== "string" || settings.prefix.length > 100 || settings.prefix !== "" && (!/^[A-Za-z0-9_]/.test(settings.prefix) || /[^A-Za-z0-9_-]/.test(settings.prefix))) return false;
|
|
14
49
|
if (target === "panel") return true;
|
|
@@ -42,10 +77,14 @@ function revision(inherited, current) {
|
|
|
42
77
|
function settings(kind, inherited, current) {
|
|
43
78
|
const effective = layers(inherited, current);
|
|
44
79
|
const keys = kind === "worktree" ? ["directory", "namePrefix"] : ["worktreePrefix"];
|
|
80
|
+
if (kind === "worktree") {
|
|
81
|
+
for (const layer of [inherited, current]) if (Object.hasOwn(layer, "retainOnArchive") && typeof layer.retainOnArchive !== "boolean") throw new SettingsError("unavailable");
|
|
82
|
+
}
|
|
45
83
|
for (const layer of [inherited, current]) for (const key of keys) if (Object.hasOwn(layer, key) && typeof layer[key] !== "string") throw new SettingsError("unavailable");
|
|
46
84
|
return kind === "worktree" ? {
|
|
47
85
|
directory: effective.directory ?? ".agents/worktrees",
|
|
48
|
-
prefix: effective.namePrefix ?? "dsh-"
|
|
86
|
+
prefix: effective.namePrefix ?? "dsh-",
|
|
87
|
+
cleanupOnArchive: effective.retainOnArchive !== true
|
|
49
88
|
} : { prefix: effective.worktreePrefix ?? "dsh-" };
|
|
50
89
|
}
|
|
51
90
|
function apply(ctx) {
|
|
@@ -73,17 +112,12 @@ function apply(ctx) {
|
|
|
73
112
|
methods: ["POST"],
|
|
74
113
|
requestBody: "buffered",
|
|
75
114
|
async fetch(request) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
body = clientRequestSchema.safeParse(await request.json());
|
|
79
|
-
} catch {
|
|
80
|
-
return new Response("Invalid request", { status: 400 });
|
|
81
|
-
}
|
|
82
|
-
if (!body.success || body.data.method !== endpoint) return new Response("Invalid request", { status: 400 });
|
|
115
|
+
const parsed = await parseRpcRequest(request, endpoint);
|
|
116
|
+
if (!parsed) return new Response("Invalid request", { status: 400 });
|
|
83
117
|
let result;
|
|
84
118
|
try {
|
|
85
119
|
if (endpoint === "dungsil-setting-vcs/save") {
|
|
86
|
-
const payload =
|
|
120
|
+
const payload = parsed.payload;
|
|
87
121
|
if (!record(payload) || Object.keys(payload).length !== 3 || ![
|
|
88
122
|
"id",
|
|
89
123
|
"revision",
|
|
@@ -96,15 +130,21 @@ function apply(ctx) {
|
|
|
96
130
|
if (!validSettings(next, kind)) throw new SettingsError("invalid_request");
|
|
97
131
|
await editor.edit(target.entry, (current, inherited) => {
|
|
98
132
|
if (revision(inherited, current) !== payload.revision) throw new SettingsError("conflict");
|
|
99
|
-
settings(kind, inherited, current);
|
|
100
|
-
|
|
101
|
-
...layers(inherited, current),
|
|
102
|
-
directory: next.directory,
|
|
103
|
-
namePrefix: next.prefix
|
|
104
|
-
} : {
|
|
133
|
+
const previous = settings(kind, inherited, current);
|
|
134
|
+
if (kind !== "worktree") return {
|
|
105
135
|
...layers(inherited, current),
|
|
106
136
|
worktreePrefix: next.prefix
|
|
107
137
|
};
|
|
138
|
+
if (next.directory === previous.directory && next.prefix === previous.prefix) return {
|
|
139
|
+
...current,
|
|
140
|
+
retainOnArchive: !next.cleanupOnArchive
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
...layers(inherited, current),
|
|
144
|
+
directory: next.directory,
|
|
145
|
+
namePrefix: next.prefix,
|
|
146
|
+
retainOnArchive: !next.cleanupOnArchive
|
|
147
|
+
};
|
|
108
148
|
});
|
|
109
149
|
}
|
|
110
150
|
result = {
|
|
@@ -121,11 +161,7 @@ function apply(ctx) {
|
|
|
121
161
|
}
|
|
122
162
|
};
|
|
123
163
|
}
|
|
124
|
-
return
|
|
125
|
-
type: "server-response",
|
|
126
|
-
rpcId: body.data.rpcId,
|
|
127
|
-
result
|
|
128
|
-
}, { headers: { "Cache-Control": "no-store" } });
|
|
164
|
+
return rpcResponse(parsed.rpcId, result);
|
|
129
165
|
}
|
|
130
166
|
}), "ui-setting-vcs: owner-only settings");
|
|
131
167
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dungsil/dsh-plugin-ui-setting-vcs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Configure Git worktree and forge panel defaults in DeepSeek Harness settings.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.3",
|
|
33
33
|
"@deepseek-ai/dsh-config-editor": "0.2.2-rc.3",
|
|
34
34
|
"@deepseek-ai/dsh-credentials-local": "0.2.2-rc.3",
|
|
35
|
+
"@deepseek-ai/schemastery": "3.19.0",
|
|
36
|
+
"@dungsil/dsh-plugin-server": "0.0.0",
|
|
35
37
|
"@dungsil/dsh-tsconfig": "0.0.0",
|
|
36
38
|
"@dungsil/dsh-tsdown": "0.0.0",
|
|
37
39
|
"@dungsil/dsh-ui": "0.0.0",
|