dsh-git-bugfix 0.0.0-stage → 0.1.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.
@@ -0,0 +1,6 @@
1
+ # The dsh-git-bugfix bundle: one host row that registers the authenticated
2
+ # `/api/dsh-git-bugfix/*` routes and the defect-fix orchestrator, plus the browser
3
+ # roster row carried by `dsh.client` in package.json.
4
+ - insert:
5
+ - id: dsh-git-bugfix
6
+ name: 'dsh-git-bugfix'
package/docs/DETAIL.md ADDED
@@ -0,0 +1 @@
1
+ ![Import the defect list, fix each defect in its own local worktree, then review the comparison and apply it](preview.svg)
@@ -0,0 +1 @@
1
+ ![导入缺陷列表,每个缺陷在独立的本地 worktree 中修复,审查差异后合并](preview.svg)
@@ -0,0 +1,62 @@
1
+ <svg width="640" height="300" viewBox="0 0 640 300" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="导入缺陷列表,每个缺陷在独立的本地 Git worktree 中修复,右侧审查代码差异后合并">
2
+ <!-- Left: the imported defect list. -->
3
+ <g>
4
+ <rect x="40" y="60" width="180" height="180" rx="14" fill="#FFFFFF" stroke="#D6DEEB" stroke-width="2" />
5
+ <clipPath id="bugfix_pv_card">
6
+ <rect x="41" y="61" width="178" height="178" rx="13" />
7
+ </clipPath>
8
+ <g clip-path="url(#bugfix_pv_card)">
9
+ <rect x="41" y="61" width="178" height="34" fill="#EAF1FB" />
10
+ <rect x="58" y="72" width="70" height="9" rx="4.5" fill="#9FB6D6" />
11
+ <circle cx="68" cy="124" r="8" fill="#4CC38A" />
12
+ <path d="M64.4 124.2 67 126.8 71.8 121.4" stroke="#FFFFFF" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" />
13
+ <rect x="86" y="119" width="108" height="9" rx="4.5" fill="#C9D6E8" />
14
+ <circle cx="68" cy="154" r="8" fill="#4CC38A" />
15
+ <path d="M64.4 154.2 67 156.8 71.8 151.4" stroke="#FFFFFF" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" />
16
+ <rect x="86" y="149" width="88" height="9" rx="4.5" fill="#C9D6E8" />
17
+ <circle cx="68" cy="184" r="8" fill="#F0B429" />
18
+ <rect x="86" y="179" width="100" height="9" rx="4.5" fill="#C9D6E8" />
19
+ <circle cx="68" cy="214" r="8" fill="#C9D6E8" />
20
+ <rect x="86" y="209" width="72" height="9" rx="4.5" fill="#C9D6E8" />
21
+ </g>
22
+ </g>
23
+ <!-- Arrow: import into the isolated fixer. -->
24
+ <path d="M230 150H262" stroke="#8FA6C4" stroke-width="3" stroke-linecap="round" />
25
+ <path d="M256 142 266 150 256 158" stroke="#8FA6C4" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" />
26
+ <!-- Middle: one local worktree fixing one defect. -->
27
+ <g>
28
+ <rect x="272" y="100" width="96" height="100" rx="22" fill="url(#bugfix_pv_blue)" />
29
+ <g stroke="#FFFFFF" stroke-width="4" stroke-linecap="round">
30
+ <path d="M308 124V176" />
31
+ <path d="M308 132c0 14 24 14 24 10v-6" />
32
+ </g>
33
+ <circle cx="308" cy="122" r="8" fill="#FFFFFF" />
34
+ <circle cx="332" cy="180" r="8" fill="#FFFFFF" />
35
+ <circle cx="332" cy="140" r="8" fill="#FFFFFF" />
36
+ <g transform="translate(348 178) rotate(-30)">
37
+ <circle cx="0" cy="0" r="9" stroke="#FFFFFF" stroke-width="4" fill="none" />
38
+ <path d="M6 6 14 14" stroke="#FFFFFF" stroke-width="4" stroke-linecap="round" />
39
+ </g>
40
+ </g>
41
+ <!-- Arrow: review the comparison. -->
42
+ <path d="M378 150H410" stroke="#8FA6C4" stroke-width="3" stroke-linecap="round" />
43
+ <path d="M404 142 414 150 404 158" stroke="#8FA6C4" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" />
44
+ <!-- Right: the reviewed diff with a passing check. -->
45
+ <g>
46
+ <rect x="420" y="60" width="180" height="180" rx="14" fill="#1F2430" />
47
+ <rect x="440" y="80" width="60" height="8" rx="4" fill="#5A6478" />
48
+ <rect x="440" y="108" width="52" height="9" rx="4.5" fill="#4CC38A" />
49
+ <rect x="440" y="130" width="120" height="9" rx="4.5" fill="#C4574B" />
50
+ <rect x="440" y="152" width="96" height="9" rx="4.5" fill="#4CC38A" />
51
+ <rect x="440" y="174" width="112" height="9" rx="4.5" fill="#8FA6C4" />
52
+ <rect x="440" y="196" width="80" height="9" rx="4.5" fill="#8FA6C4" />
53
+ <circle cx="566" cy="206" r="18" fill="#4CC38A" />
54
+ <path d="M558 206.4 563.8 212.2 574.4 200.6" stroke="#FFFFFF" stroke-width="3.4" stroke-linecap="round" stroke-linejoin="round" />
55
+ </g>
56
+ <defs>
57
+ <linearGradient id="bugfix_pv_blue" x1="320" y1="100" x2="320" y2="200" gradientUnits="userSpaceOnUse">
58
+ <stop stop-color="#69B9FF" />
59
+ <stop offset="1" stop-color="#324DE2" />
60
+ </linearGradient>
61
+ </defs>
62
+ </svg>
package/icon.svg ADDED
@@ -0,0 +1,28 @@
1
+ <svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <!-- One rounded tile in the harness artwork palette (same treatment as the
3
+ subagent/terminal cards), carrying a bug whose body shows a check: a
4
+ defect that was fixed. Canvas stays 36x36 so the consumer keeps control
5
+ of display size; the drawing is inset like the neighbouring icons. -->
6
+ <g transform="translate(18 18) scale(0.9286) translate(-18 -18)">
7
+ <rect x="4" y="4" width="28" height="28" rx="8" fill="url(#bugfix_blue)" />
8
+ <g stroke="#FFFFFF" stroke-width="1.6" stroke-linecap="round">
9
+ <path d="M13.1 16.2 10.4 14.8" />
10
+ <path d="M12.6 19.4H9.7" />
11
+ <path d="M13.1 22.6 10.4 24" />
12
+ <path d="M22.9 16.2 25.6 14.8" />
13
+ <path d="M23.4 19.4H26.3" />
14
+ <path d="M22.9 22.6 25.6 24" />
15
+ <path d="M16.2 10.9 14.6 8.6" />
16
+ <path d="M19.8 10.9 21.4 8.6" />
17
+ </g>
18
+ <circle cx="18" cy="10.4" r="2.5" fill="#FFFFFF" />
19
+ <rect x="12.6" y="12.9" width="10.8" height="12.6" rx="4.2" fill="#FFFFFF" />
20
+ <path d="M15.7 19.2 17.6 21.1 20.7 17.4" stroke="#324DE2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
21
+ </g>
22
+ <defs>
23
+ <linearGradient id="bugfix_blue" x1="18" y1="4" x2="18" y2="32" gradientUnits="userSpaceOnUse">
24
+ <stop stop-color="#69B9FF" />
25
+ <stop offset="1" stop-color="#324DE2" />
26
+ </linearGradient>
27
+ </defs>
28
+ </svg>
package/index.js ADDED
@@ -0,0 +1,278 @@
1
+ /**
2
+ * dsh-git-bugfix — Host half.
3
+ *
4
+ * Registers the authenticated `/api/dsh-git-bugfix/*` routes on the Web connection and
5
+ * owns the per-repository defect-fix state. The browser half registers the
6
+ * 「bug修改」 conversation view and the right-sidebar file comparison tab.
7
+ *
8
+ * Git remains local-only: fixes run in dedicated local worktrees on local
9
+ * `bugfix/*` branches, and applying a fix to the user's branch is a local
10
+ * cherry-pick. No route touches a remote.
11
+ */
12
+
13
+ import { Fixer, FixerError } from './lib/fixer.js'
14
+ import { RepoStore } from './lib/state.js'
15
+
16
+ /** The Host services this plugin requires; the browser surface provides them. */
17
+ export const inject = ['connection']
18
+
19
+ /** Largest request body the import route accepts, in bytes. */
20
+ const MAX_IMPORT_BYTES = 32 * 1024 * 1024
21
+
22
+ /**
23
+ * Wrap one value as a JSON response.
24
+ * @param {unknown} value - JSON-safe payload.
25
+ * @param {number} [status] - HTTP status.
26
+ * @returns {Response} the response.
27
+ */
28
+ function jsonResponse(value, status = 200) {
29
+ return new Response(JSON.stringify(value), {
30
+ status,
31
+ headers: {
32
+ 'content-type': 'application/json; charset=utf-8',
33
+ 'cache-control': 'no-store',
34
+ },
35
+ })
36
+ }
37
+
38
+ /**
39
+ * Extract session facts from query parameters and a JSON body.
40
+ * @param {URLSearchParams} params - query parameters.
41
+ * @param {object} body - parsed JSON body, when any.
42
+ * @returns {{ sessionId: string, cwd: string }} request facts.
43
+ */
44
+ function requestFacts(params, body) {
45
+ const source = body !== null && typeof body === 'object' ? body : {}
46
+ const sessionId = typeof source.sessionId === 'string' ? source.sessionId : (params.get('sessionId') ?? '')
47
+ const cwd = typeof source.cwd === 'string' ? source.cwd : (params.get('cwd') ?? '')
48
+ return { sessionId, cwd }
49
+ }
50
+
51
+ /**
52
+ * Host plugin entry: construct the store and fixer, then register the routes.
53
+ * @param {object} ctx - Host Cordis context.
54
+ */
55
+ export function apply(ctx) {
56
+ const store = new RepoStore({ ctx, logger: ctx.logger })
57
+ const fixer = new Fixer({ ctx, store })
58
+
59
+ /**
60
+ * Register one bounded JSON route.
61
+ * @param {string} path - exact route path.
62
+ * @param {'GET' | 'POST'} method - HTTP method.
63
+ * @param {'json' | 'bytes' | 'none'} bodyMode - request body handling.
64
+ * @param {(context: { request: Request, params: URLSearchParams, body: any, bytes: Buffer | undefined, facts: { sessionId: string, cwd: string } }) => Promise<object>} handler - route body.
65
+ */
66
+ const route = (path, method, bodyMode, handler) => {
67
+ ctx.effect(() => ctx.connection.fetch.register({
68
+ path,
69
+ methods: [method],
70
+ requestBody: 'buffered',
71
+ fetch: async (request) => {
72
+ try {
73
+ const url = new URL(request.url)
74
+ const params = url.searchParams
75
+ let body = null
76
+ let bytes
77
+ if (method !== 'GET') {
78
+ const buffer = Buffer.from(await request.arrayBuffer())
79
+ if (buffer.length > MAX_IMPORT_BYTES) {
80
+ return jsonResponse({ ok: false, code: 'body-too-large', error: '请求内容过大' }, 413)
81
+ }
82
+ if (bodyMode === 'json') {
83
+ const text = buffer.toString('utf8').trim()
84
+ body = text === '' ? {} : JSON.parse(text)
85
+ } else if (bodyMode === 'bytes') {
86
+ bytes = buffer
87
+ }
88
+ }
89
+ const facts = requestFacts(params, body)
90
+ const value = await handler({ request, params, body, bytes, facts })
91
+ return jsonResponse(value)
92
+ } catch (error) {
93
+ if (error instanceof FixerError) {
94
+ return jsonResponse({ ok: false, code: error.code, error: error.message }, 400)
95
+ }
96
+ ctx.logger?.warn?.(`[dsh-git-bugfix] 请求失败:${String(error)}`)
97
+ return jsonResponse({
98
+ ok: false,
99
+ code: 'internal',
100
+ error: error instanceof Error ? error.message : String(error),
101
+ }, 500)
102
+ }
103
+ },
104
+ }), `dsh-git-bugfix: route ${path}`)
105
+ }
106
+
107
+ route('/api/dsh-git-bugfix/state', 'GET', 'none', async ({ facts }) => ({ ok: true, state: await fixer.getState(facts) }))
108
+
109
+ route('/api/dsh-git-bugfix/import', 'POST', 'bytes', async ({ facts, params, bytes }) => {
110
+ if (bytes === undefined || bytes.length === 0) throw new FixerError('empty-body', '没有收到表格文件内容')
111
+ const mode = params.get('mode') === 'append' ? 'append' : 'replace'
112
+ const filename = params.get('name') ?? ''
113
+ const result = await fixer.importExcel(facts, bytes, mode, filename)
114
+ return { ok: true, state: result.state, counts: result.counts }
115
+ })
116
+
117
+ route('/api/dsh-git-bugfix/append-description', 'POST', 'json', async ({ facts, body }) => {
118
+ const key = typeof body?.key === 'string' ? body.key : ''
119
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
120
+ const text = typeof body?.text === 'string' ? body.text : ''
121
+ return { ok: true, state: await fixer.appendDescription(facts, key, text) }
122
+ })
123
+
124
+ route('/api/dsh-git-bugfix/import-text', 'POST', 'json', async ({ facts, body }) => {
125
+ const result = await fixer.importText(facts, {
126
+ title: body?.title,
127
+ content: body?.content,
128
+ mode: body?.mode,
129
+ images: body?.images,
130
+ })
131
+ return { ok: true, state: result.state, bug: result.bug }
132
+ })
133
+
134
+ route('/api/dsh-git-bugfix/edit', 'POST', 'json', async ({ facts, body }) => ({
135
+ ok: true,
136
+ state: await fixer.editDefect(facts, {
137
+ key: body?.key,
138
+ title: body?.title,
139
+ analysis: body?.analysis,
140
+ addImages: body?.addImages,
141
+ removeImages: body?.removeImages,
142
+ }),
143
+ }))
144
+
145
+ route('/api/dsh-git-bugfix/fix', 'POST', 'json', async ({ facts, body }) => {
146
+ const key = typeof body?.key === 'string' ? body.key : ''
147
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
148
+ const state = await fixer.startSingle(facts, key, { verify: body?.verify, retry: body?.retry })
149
+ return { ok: true, state }
150
+ })
151
+
152
+ route('/api/dsh-git-bugfix/continue', 'POST', 'json', async ({ facts, body }) => {
153
+ const key = typeof body?.key === 'string' ? body.key : ''
154
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
155
+ const guidance = typeof body?.guidance === 'string' ? body.guidance : ''
156
+ return { ok: true, state: await fixer.continueFix(facts, key, guidance) }
157
+ })
158
+
159
+ route('/api/dsh-git-bugfix/batch', 'POST', 'json', async ({ facts, body }) => {
160
+ const state = await fixer.startBatch(facts, {
161
+ keys: body?.keys,
162
+ parallel: body?.parallel,
163
+ verify: body?.verify,
164
+ })
165
+ return { ok: true, state }
166
+ })
167
+
168
+ route('/api/dsh-git-bugfix/stop', 'POST', 'json', async ({ facts }) => ({ ok: true, state: await fixer.stop(facts) }))
169
+
170
+ route('/api/dsh-git-bugfix/merge', 'POST', 'json', async ({ facts, body }) => {
171
+ const key = typeof body?.key === 'string' ? body.key : ''
172
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
173
+ const result = await fixer.merge(facts, key)
174
+ return { ok: true, state: result.state, merge: result.merge }
175
+ })
176
+
177
+ route('/api/dsh-git-bugfix/apply-all', 'POST', 'json', async ({ facts }) => {
178
+ const result = await fixer.applyPending(facts)
179
+ return { ok: true, state: result.state, merge: result.merge }
180
+ })
181
+
182
+ route('/api/dsh-git-bugfix/integrate', 'POST', 'json', async ({ facts }) => {
183
+ const result = await fixer.integrate(facts)
184
+ return { ok: true, state: result.state, merge: result.merge }
185
+ })
186
+
187
+ route('/api/dsh-git-bugfix/integration/reset', 'POST', 'json', async ({ facts }) => ({
188
+ ok: true,
189
+ state: await fixer.resetIntegration(facts),
190
+ }))
191
+
192
+ route('/api/dsh-git-bugfix/merge/continue', 'POST', 'json', async ({ facts }) => ({ ok: true, state: await fixer.continueMerge(facts) }))
193
+
194
+ route('/api/dsh-git-bugfix/merge/abort', 'POST', 'json', async ({ facts }) => ({ ok: true, state: await fixer.abortMerge(facts) }))
195
+
196
+ route('/api/dsh-git-bugfix/merge/ai-resolve', 'POST', 'json', async ({ facts, body }) => {
197
+ const guidance = typeof body?.guidance === 'string' ? body.guidance.trim() : ''
198
+ const result = await fixer.resolveMergeWithAi(facts, guidance)
199
+ return { ok: true, state: result.state, resolved: result.resolved, message: result.message }
200
+ })
201
+
202
+ route('/api/dsh-git-bugfix/conflict-file', 'GET', 'none', async ({ facts, params }) => {
203
+ const file = params.get('file') ?? ''
204
+ if (file === '') throw new FixerError('missing-argument', '缺少文件路径')
205
+ return fixer.conflictFile(facts, file)
206
+ })
207
+
208
+ route('/api/dsh-git-bugfix/discard', 'POST', 'json', async ({ facts, body }) => {
209
+ const key = typeof body?.key === 'string' ? body.key : ''
210
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
211
+ return { ok: true, state: await fixer.discard(facts, key) }
212
+ })
213
+
214
+ route('/api/dsh-git-bugfix/withdraw', 'POST', 'json', async ({ facts, body }) => {
215
+ const key = typeof body?.key === 'string' ? body.key : ''
216
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
217
+ return { ok: true, state: await fixer.withdraw(facts, key) }
218
+ })
219
+
220
+ route('/api/dsh-git-bugfix/retry', 'POST', 'json', async ({ facts, body }) => {
221
+ const key = typeof body?.key === 'string' ? body.key : ''
222
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
223
+ return { ok: true, state: await fixer.retry(facts, key) }
224
+ })
225
+
226
+ route('/api/dsh-git-bugfix/settings', 'POST', 'json', async ({ facts, body }) => ({
227
+ ok: true,
228
+ state: await fixer.updateSettings(facts, {
229
+ parallel: body?.parallel,
230
+ verify: body?.verify,
231
+ skillPath: body?.skillPath,
232
+ baseBranch: body?.baseBranch,
233
+ commitTemplate: body?.commitTemplate,
234
+ autoApply: body?.autoApply,
235
+ }),
236
+ }))
237
+
238
+ route('/api/dsh-git-bugfix/rescan', 'POST', 'json', async ({ facts }) => ({ ok: true, state: await fixer.rescan(facts) }))
239
+
240
+ route('/api/dsh-git-bugfix/clear', 'POST', 'json', async ({ facts }) => ({ ok: true, state: await fixer.clear(facts) }))
241
+
242
+ route('/api/dsh-git-bugfix/diff', 'GET', 'none', async ({ facts, params }) => {
243
+ const key = params.get('key') ?? ''
244
+ const file = params.get('file') ?? ''
245
+ if (key === '' || file === '') throw new FixerError('missing-argument', '缺少缺陷标识或文件路径')
246
+ return fixer.diff(facts, key, file)
247
+ })
248
+
249
+ route('/api/dsh-git-bugfix/activity', 'GET', 'none', async ({ facts, params }) => {
250
+ const key = params.get('key') ?? ''
251
+ if (key === '') throw new FixerError('missing-key', '缺少缺陷标识')
252
+ return fixer.activity(facts, key)
253
+ })
254
+
255
+ ctx.effect(() => ctx.connection.fetch.register({
256
+ path: '/api/dsh-git-bugfix/attachment',
257
+ methods: ['GET'],
258
+ requestBody: 'buffered',
259
+ fetch: async (request) => {
260
+ try {
261
+ const url = new URL(request.url)
262
+ const facts = requestFacts(url.searchParams, null)
263
+ const file = url.searchParams.get('path') ?? ''
264
+ if (file === '') return jsonResponse({ ok: false, code: 'missing-argument', error: '缺少附件路径' }, 400)
265
+ const { bytes, mime } = await fixer.readAttachment(facts, file)
266
+ return new Response(bytes, {
267
+ status: 200,
268
+ headers: { 'content-type': mime, 'cache-control': 'no-store' },
269
+ })
270
+ } catch (error) {
271
+ if (error instanceof FixerError) {
272
+ return jsonResponse({ ok: false, code: error.code, error: error.message }, 400)
273
+ }
274
+ return jsonResponse({ ok: false, code: 'internal', error: error instanceof Error ? error.message : String(error) }, 500)
275
+ }
276
+ },
277
+ }), 'dsh-git-bugfix: route /api/dsh-git-bugfix/attachment')
278
+ }