@hy-sde-org/dsh-git 0.1.1-rc.2
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/LICENSE +37 -0
- package/README.md +40 -0
- package/cordis.patch.yml +22 -0
- package/dist/commit-message.d.ts +9 -0
- package/dist/commit-message.d.ts.map +1 -0
- package/dist/commit-message.js +16 -0
- package/dist/commit-message.js.map +1 -0
- package/dist/diff.d.ts +26 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +197 -0
- package/dist/diff.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/invariant.d.ts +16 -0
- package/dist/invariant.d.ts.map +1 -0
- package/dist/invariant.js +22 -0
- package/dist/invariant.js.map +1 -0
- package/dist/lock-files.d.ts +28 -0
- package/dist/lock-files.d.ts.map +1 -0
- package/dist/lock-files.js +97 -0
- package/dist/lock-files.js.map +1 -0
- package/dist/service.d.ts +233 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +457 -0
- package/dist/service.js.map +1 -0
- package/dist/topo-sort.d.ts +18 -0
- package/dist/topo-sort.d.ts.map +1 -0
- package/dist/topo-sort.js +53 -0
- package/dist/topo-sort.js.map +1 -0
- package/dist/trivial.d.ts +18 -0
- package/dist/trivial.d.ts.map +1 -0
- package/dist/trivial.js +47 -0
- package/dist/trivial.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/examples/agent-preset/agent.cordis.yml +21 -0
- package/examples/agent-preset/preset.yml +3 -0
- package/package.json +96 -0
package/dist/service.js
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ctx.git` service: a thin, read-through-write wrapper around the `git`
|
|
3
|
+
* CLI via the `ctx.subprocess` seam, plus the diff-parsing primitives and the
|
|
4
|
+
* split-commit execution verbs (hunk staging, dependency-ordered commit, lock
|
|
5
|
+
* files). Host-plane — the service holds no durable state and shells out per
|
|
6
|
+
* call, so one instance serves every session; the model-facing tools live in
|
|
7
|
+
* `@hy-sde-org/dsh-tool-git` and resolve this host instance.
|
|
8
|
+
*
|
|
9
|
+
* Port of the omp (oh-my-pi) git layer, reduced to what the commit + review
|
|
10
|
+
* workflows need: `git` CLI execution, diff capture/parsing, status, hunk
|
|
11
|
+
* staging, commit/push. See port_omp.md item: commit.
|
|
12
|
+
* @module @hy-sde-org/dsh-git/service
|
|
13
|
+
*/
|
|
14
|
+
import { Service } from '@deepseek-ai/cordis';
|
|
15
|
+
import { parseFileDiffs, parseFileHunks, parseNumstat, selectHunks, extractFileHeader, } from "./diff.js";
|
|
16
|
+
/** A failed `git` invocation: exit status plus stderr retained for the agent. */
|
|
17
|
+
export class GitCommandError extends Error {
|
|
18
|
+
exitCode;
|
|
19
|
+
stderr;
|
|
20
|
+
constructor(message, options) {
|
|
21
|
+
super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
|
|
22
|
+
this.exitCode = options.exitCode;
|
|
23
|
+
this.stderr = options.stderr;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Default per-command timeout. */
|
|
27
|
+
export const DEFAULT_TIMEOUT_MS = 120_000;
|
|
28
|
+
/** Default stdout collection cap. */
|
|
29
|
+
export const DEFAULT_MAX_STDOUT_BYTES = 8 * 1024 * 1024;
|
|
30
|
+
const DEFAULT_MAX_STDERR_BYTES = 64 * 1024;
|
|
31
|
+
const DEFAULT_GRACE_MS = 5_000;
|
|
32
|
+
/** The `ctx.git` service. */
|
|
33
|
+
export class GitService extends Service {
|
|
34
|
+
gitPath;
|
|
35
|
+
timeoutMs;
|
|
36
|
+
maxStdoutBytes;
|
|
37
|
+
maxStderrBytes;
|
|
38
|
+
graceMs;
|
|
39
|
+
constructor(ctx, config = {}) {
|
|
40
|
+
super(ctx, 'git');
|
|
41
|
+
this.gitPath = config.gitPath ?? 'git';
|
|
42
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
43
|
+
this.maxStdoutBytes = config.maxStdoutBytes ?? DEFAULT_MAX_STDOUT_BYTES;
|
|
44
|
+
this.maxStderrBytes = config.maxStderrBytes ?? DEFAULT_MAX_STDERR_BYTES;
|
|
45
|
+
this.graceMs = config.graceMs ?? DEFAULT_GRACE_MS;
|
|
46
|
+
}
|
|
47
|
+
/* ── low-level runner ──────────────────────────────────────────────────── */
|
|
48
|
+
subprocess() {
|
|
49
|
+
const subprocess = this.ctx.get('subprocess');
|
|
50
|
+
if (subprocess === undefined) {
|
|
51
|
+
throw new Error('git service requires the subprocess seam: load @deepseek-ai/dsh-subprocess-local');
|
|
52
|
+
}
|
|
53
|
+
return subprocess;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Run one `git` command against `cwd`. A non-zero exit code is returned as
|
|
57
|
+
* data on the run (callers decide whether it is an error); only a launch
|
|
58
|
+
* failure, a signal kill, or a timeout throws {@link GitCommandError}.
|
|
59
|
+
* @param argv - git arguments (never shell-interpreted).
|
|
60
|
+
* @param options - cwd (required), abort signal, stdin text, timeout override.
|
|
61
|
+
* @returns exit code, stdout, stderr; throws {@link GitCommandError} only for launch/timeout/signal failures.
|
|
62
|
+
*/
|
|
63
|
+
async run(argv, options) {
|
|
64
|
+
const { cwd, signal, stdin } = options;
|
|
65
|
+
if (signal?.aborted) {
|
|
66
|
+
throw new GitCommandError('git command was aborted before it could start', { exitCode: null, stderr: '' });
|
|
67
|
+
}
|
|
68
|
+
const limit = options.timeoutMs ?? this.timeoutMs;
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
let timedOut = false;
|
|
71
|
+
const timer = setTimeout(() => {
|
|
72
|
+
timedOut = true;
|
|
73
|
+
controller.abort();
|
|
74
|
+
}, limit);
|
|
75
|
+
const forward = () => controller.abort();
|
|
76
|
+
if (signal !== undefined) {
|
|
77
|
+
signal.addEventListener('abort', forward, { once: true });
|
|
78
|
+
}
|
|
79
|
+
let handle;
|
|
80
|
+
try {
|
|
81
|
+
handle = this.subprocess().spawn({
|
|
82
|
+
argv: [this.gitPath, ...argv],
|
|
83
|
+
cwd,
|
|
84
|
+
graceMs: this.graceMs,
|
|
85
|
+
stdio: {
|
|
86
|
+
stdin: stdin === undefined ? 'ignore' : { data: stdin },
|
|
87
|
+
stdout: { maxBytes: this.maxStdoutBytes },
|
|
88
|
+
stderr: { maxBytes: this.maxStderrBytes },
|
|
89
|
+
},
|
|
90
|
+
signal: controller.signal,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
if (signal !== undefined)
|
|
96
|
+
signal.removeEventListener('abort', forward);
|
|
97
|
+
if (signal?.aborted) {
|
|
98
|
+
throw new GitCommandError('git command was aborted before completion', { exitCode: null, stderr: '', cause: error });
|
|
99
|
+
}
|
|
100
|
+
if (timedOut) {
|
|
101
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} timed out after ${limit}ms`, { exitCode: null, stderr: '', cause: error });
|
|
102
|
+
}
|
|
103
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} could not start (launch failed)`, {
|
|
104
|
+
exitCode: null,
|
|
105
|
+
stderr: '',
|
|
106
|
+
cause: error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
let outcome;
|
|
110
|
+
try {
|
|
111
|
+
outcome = await handle.done;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
if (signal !== undefined)
|
|
116
|
+
signal.removeEventListener('abort', forward);
|
|
117
|
+
if (timedOut) {
|
|
118
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} timed out after ${limit}ms`, { exitCode: null, stderr: '', cause: error });
|
|
119
|
+
}
|
|
120
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} could not start (launch failed)`, {
|
|
121
|
+
exitCode: null,
|
|
122
|
+
stderr: '',
|
|
123
|
+
cause: error,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
clearTimeout(timer);
|
|
127
|
+
if (signal !== undefined)
|
|
128
|
+
signal.removeEventListener('abort', forward);
|
|
129
|
+
const stdout = handle.collected.stdout?.readFrom(0);
|
|
130
|
+
const stderr = handle.collected.stderr?.readFrom(0);
|
|
131
|
+
if (stdout === undefined || stderr === undefined) {
|
|
132
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} produced no collected output streams`, {
|
|
133
|
+
exitCode: null,
|
|
134
|
+
stderr: '',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (timedOut) {
|
|
138
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} timed out after ${limit}ms`, { exitCode: null, stderr: stderr.text });
|
|
139
|
+
}
|
|
140
|
+
if (outcome.signal !== null) {
|
|
141
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} was killed by signal ${outcome.signal}`, {
|
|
142
|
+
exitCode: outcome.exitCode,
|
|
143
|
+
stderr: stderr.text,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (outcome.exitCode === null) {
|
|
147
|
+
throw new GitCommandError(`git ${argv[0] ?? ''} exited without a code`, { exitCode: null, stderr: stderr.text });
|
|
148
|
+
}
|
|
149
|
+
return { stdout: stdout.text, exitCode: outcome.exitCode, killed: false, stderr: stderr.text };
|
|
150
|
+
}
|
|
151
|
+
/** Run a command and require exit 0, throwing a readable {@link GitCommandError}. */
|
|
152
|
+
async checked(argv, options) {
|
|
153
|
+
const run = await this.run(argv, options);
|
|
154
|
+
if (run.exitCode !== 0) {
|
|
155
|
+
const stderr = run.stderr.trim();
|
|
156
|
+
const label = `git ${argv[0] ?? ''} failed (exit ${run.exitCode})`;
|
|
157
|
+
throw new GitCommandError(stderr.length > 0 ? `${label}: ${stderr}` : label, {
|
|
158
|
+
exitCode: run.exitCode,
|
|
159
|
+
stderr: run.stderr,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return run;
|
|
163
|
+
}
|
|
164
|
+
/** Run a command requiring exit 0 and return its stdout text. */
|
|
165
|
+
async text(argv, options) {
|
|
166
|
+
return (await this.checked(argv, options)).stdout;
|
|
167
|
+
}
|
|
168
|
+
/* ── repository state ──────────────────────────────────────────────────── */
|
|
169
|
+
/**
|
|
170
|
+
* True when `cwd` is inside a git working tree.
|
|
171
|
+
* @param cwd - working directory to probe.
|
|
172
|
+
* @param signal - optional abort.
|
|
173
|
+
* @returns whether `cwd` is a git working tree (never throws).
|
|
174
|
+
*/
|
|
175
|
+
async isRepo(cwd, signal) {
|
|
176
|
+
try {
|
|
177
|
+
const run = await this.run(['rev-parse', '--is-inside-work-tree'], { cwd, signal });
|
|
178
|
+
return run.exitCode === 0 && run.stdout.trim() === 'true';
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The repository root (`git rev-parse --show-toplevel`).
|
|
186
|
+
* @param cwd - working directory inside the repository.
|
|
187
|
+
* @param signal - optional abort.
|
|
188
|
+
* @returns the absolute repository root.
|
|
189
|
+
*/
|
|
190
|
+
async root(cwd, signal) {
|
|
191
|
+
return (await this.text(['rev-parse', '--show-toplevel'], { cwd, signal })).trim();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The current branch name, or undefined when detached.
|
|
195
|
+
* @param cwd - working directory inside the repository.
|
|
196
|
+
* @param signal - optional abort.
|
|
197
|
+
* @returns the branch name, or undefined on a detached HEAD.
|
|
198
|
+
*/
|
|
199
|
+
async branch(cwd, signal) {
|
|
200
|
+
const value = (await this.text(['branch', '--show-current'], { cwd, signal })).trim();
|
|
201
|
+
return value.length > 0 ? value : undefined;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Plain status summary: staged/unstaged/untracked counts.
|
|
205
|
+
* @param cwd - working directory inside the repository.
|
|
206
|
+
* @param signal - optional abort.
|
|
207
|
+
* @returns counts of staged, unstaged and untracked entries.
|
|
208
|
+
*/
|
|
209
|
+
async status(cwd, signal) {
|
|
210
|
+
const output = await this.text(['status', '--porcelain'], { cwd, signal });
|
|
211
|
+
let staged = 0;
|
|
212
|
+
let unstaged = 0;
|
|
213
|
+
let untracked = 0;
|
|
214
|
+
for (const line of output.split('\n')) {
|
|
215
|
+
if (!line)
|
|
216
|
+
continue;
|
|
217
|
+
const x = line[0];
|
|
218
|
+
const y = line[1];
|
|
219
|
+
if (x === '?' && y === '?') {
|
|
220
|
+
untracked += 1;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (x && x !== ' ' && x !== '?')
|
|
224
|
+
staged += 1;
|
|
225
|
+
if (y && y !== ' ')
|
|
226
|
+
unstaged += 1;
|
|
227
|
+
}
|
|
228
|
+
return { staged, unstaged, untracked };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* True when the index differs from HEAD (something is staged).
|
|
232
|
+
* @param cwd - working directory inside the repository.
|
|
233
|
+
* @param signal - optional abort.
|
|
234
|
+
* @returns whether there is anything staged.
|
|
235
|
+
*/
|
|
236
|
+
async hasStaged(cwd, signal) {
|
|
237
|
+
const run = await this.run(['diff', '--cached', '--quiet'], { cwd, signal });
|
|
238
|
+
return run.exitCode !== 0;
|
|
239
|
+
}
|
|
240
|
+
/* ── diff ──────────────────────────────────────────────────────────────── */
|
|
241
|
+
/**
|
|
242
|
+
* Whole raw diff text; non-zero exit is an error unless `allowFailure`.
|
|
243
|
+
* @param cwd - working directory inside the repository.
|
|
244
|
+
* @param options - cached vs worktree, pathspec files, binary, name-only, numstat, allowFailure.
|
|
245
|
+
* @param signal - optional abort.
|
|
246
|
+
* @returns the diff text.
|
|
247
|
+
*/
|
|
248
|
+
async diffText(cwd, options = {}, signal) {
|
|
249
|
+
const args = this.buildDiffArgs(options);
|
|
250
|
+
if (options.allowFailure) {
|
|
251
|
+
return (await this.run(args, { cwd, signal })).stdout;
|
|
252
|
+
}
|
|
253
|
+
return this.text(args, { cwd, signal });
|
|
254
|
+
}
|
|
255
|
+
/** Diff namespace (mirrors omp's `diff.*`) for the derived read shapes. */
|
|
256
|
+
diff = {
|
|
257
|
+
changedFiles: (cwd, options = {}) => this.diffText(cwd, { ...options, nameOnly: true }, options.signal).then(splitLines),
|
|
258
|
+
numstat: (cwd, options = {}) => this.diffText(cwd, { ...options, numstat: true }, options.signal).then(parseNumstat),
|
|
259
|
+
has: async (cwd, options = {}) => {
|
|
260
|
+
const args = ['diff'];
|
|
261
|
+
if (options.cached)
|
|
262
|
+
args.push('--cached');
|
|
263
|
+
args.push('--quiet');
|
|
264
|
+
if (options.files?.length)
|
|
265
|
+
args.push('--', ...options.files);
|
|
266
|
+
const run = await this.run(args, { cwd, signal: options.signal });
|
|
267
|
+
return run.exitCode !== 0;
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Parsed file diff sections for `pathSpec` (defaults to the whole cached diff).
|
|
272
|
+
* @param cwd - working directory inside the repository.
|
|
273
|
+
* @param options - cached vs worktree and pathspec filter.
|
|
274
|
+
* @returns one parsed section per changed file.
|
|
275
|
+
*/
|
|
276
|
+
async fileDiffs(cwd, options = {}) {
|
|
277
|
+
const diffText = await this.diffText(cwd, {
|
|
278
|
+
cached: options.cached ?? true,
|
|
279
|
+
...(options.files !== undefined ? { files: options.files } : {}),
|
|
280
|
+
}, options.signal);
|
|
281
|
+
return parseFileDiffs(diffText);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Selectively stage whole files or hunks from a diff that is already in the
|
|
285
|
+
* index (the `--cached` view). Direct port of omp `stage.hunks`: rebuilds a
|
|
286
|
+
* patch from the recorded diff and applies it to the index.
|
|
287
|
+
* @param cwd - working directory inside the repository.
|
|
288
|
+
* @param selections - file/hunk selections to stage.
|
|
289
|
+
* @param options - the raw cached diff to slice from (defaults to `git diff --cached`).
|
|
290
|
+
*/
|
|
291
|
+
async stageHunks(cwd, selections, options = {}) {
|
|
292
|
+
if (selections.length === 0)
|
|
293
|
+
return;
|
|
294
|
+
const rawDiff = options.rawDiff ?? (await this.diffText(cwd, { cached: true }, options.signal));
|
|
295
|
+
const fileDiffMap = new Map(parseFileDiffs(rawDiff).map(entry => [entry.filename, entry]));
|
|
296
|
+
const patchParts = [];
|
|
297
|
+
for (const selection of selections) {
|
|
298
|
+
const fileDiff = fileDiffMap.get(selection.path);
|
|
299
|
+
if (!fileDiff)
|
|
300
|
+
throw new Error(`No diff found for ${selection.path}`);
|
|
301
|
+
if (fileDiff.isBinary) {
|
|
302
|
+
if (selection.hunks.type !== 'all') {
|
|
303
|
+
throw new Error(`Cannot select hunks for binary file ${selection.path}`);
|
|
304
|
+
}
|
|
305
|
+
patchParts.push(fileDiff.content);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (selection.hunks.type === 'all') {
|
|
309
|
+
patchParts.push(fileDiff.content);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const fileHunks = parseFileHunks(fileDiff);
|
|
313
|
+
const selected = selectHunks(fileHunks, selection.hunks);
|
|
314
|
+
if (selected.length === 0)
|
|
315
|
+
throw new Error(`No hunks selected for ${selection.path}`);
|
|
316
|
+
const header = extractFileHeader(fileDiff.content);
|
|
317
|
+
patchParts.push([header, ...selected.map(h => h.content)].join('\n'));
|
|
318
|
+
}
|
|
319
|
+
const patchText = patchJoin(patchParts);
|
|
320
|
+
if (!patchText.trim())
|
|
321
|
+
return;
|
|
322
|
+
await this.applyPatchText(cwd, patchText, { cached: true, signal: options.signal });
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Apply a patch string (to the index with `cached: true`, as split staging needs).
|
|
326
|
+
* @param cwd - working directory inside the repository.
|
|
327
|
+
* @param patchText - unified diff text piped to `git apply`.
|
|
328
|
+
* @param options - cached vs worktree, reverse direction, abort signal.
|
|
329
|
+
*/
|
|
330
|
+
async applyPatchText(cwd, patchText, options = {}) {
|
|
331
|
+
if (!patchText.trim())
|
|
332
|
+
return;
|
|
333
|
+
const args = ['apply'];
|
|
334
|
+
if (options.cached)
|
|
335
|
+
args.push('--cached');
|
|
336
|
+
if (options.reverse)
|
|
337
|
+
args.push('--reverse');
|
|
338
|
+
// `--binary` is only for patches that embed binary content. Passing it for
|
|
339
|
+
// a text patch whose header carries `index <old>..<new>` makes git apply
|
|
340
|
+
// find both blobs and stage the WHOLE new blob instead of honoring hunk
|
|
341
|
+
// granularity — which would silently defeat partial-hunk staging.
|
|
342
|
+
if (/^(?:diff --git .*\n)?Binary files /m.test(patchText) || /^GIT binary patch/m.test(patchText)) {
|
|
343
|
+
args.push('--binary');
|
|
344
|
+
}
|
|
345
|
+
args.push('-');
|
|
346
|
+
await this.checked(args, { cwd, signal: options.signal, stdin: patchText });
|
|
347
|
+
}
|
|
348
|
+
/* ── staging ───────────────────────────────────────────────────────────── */
|
|
349
|
+
/**
|
|
350
|
+
* Stage files; empty list stages everything (`git add -A`).
|
|
351
|
+
* @param cwd - working directory inside the repository.
|
|
352
|
+
* @param files - paths to stage; empty stages everything.
|
|
353
|
+
* @param signal - optional abort.
|
|
354
|
+
*/
|
|
355
|
+
async addAll(cwd, files = [], signal) {
|
|
356
|
+
const args = files.length === 0 ? ['add', '-A'] : ['add', '--', ...files];
|
|
357
|
+
await this.checked(args, { cwd, signal });
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Unstage files; empty list unstages everything (`git reset`).
|
|
361
|
+
* @param cwd - working directory inside the repository.
|
|
362
|
+
* @param files - paths to unstage; empty unstages everything.
|
|
363
|
+
* @param signal - optional abort.
|
|
364
|
+
*/
|
|
365
|
+
async resetIndex(cwd, files = [], signal) {
|
|
366
|
+
const args = files.length === 0 ? ['reset'] : ['reset', '--', ...files];
|
|
367
|
+
await this.checked(args, { cwd, signal });
|
|
368
|
+
}
|
|
369
|
+
/* ── commit / push ─────────────────────────────────────────────────────── */
|
|
370
|
+
/**
|
|
371
|
+
* Create a commit from `message` (passed via stdin).
|
|
372
|
+
* @param cwd - working directory inside the repository.
|
|
373
|
+
* @param message - commit message (subject/body).
|
|
374
|
+
* @param options - allow-empty and abort signal.
|
|
375
|
+
* @returns the underlying command run.
|
|
376
|
+
*/
|
|
377
|
+
async commit(cwd, message, options = {}) {
|
|
378
|
+
const args = ['commit', '-F', '-'];
|
|
379
|
+
if (options.allowEmpty)
|
|
380
|
+
args.push('--allow-empty');
|
|
381
|
+
return this.checked(args, { cwd, signal: options.signal, stdin: message });
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Push the current branch. `--no-follow-tags` so only the branch moves.
|
|
385
|
+
* @param cwd - working directory inside the repository.
|
|
386
|
+
* @param options - optional force-with-lease and abort signal.
|
|
387
|
+
*/
|
|
388
|
+
async push(cwd, options = {}) {
|
|
389
|
+
const args = ['push', '--no-follow-tags'];
|
|
390
|
+
if (options.forceWithLease)
|
|
391
|
+
args.push('--force-with-lease');
|
|
392
|
+
await this.checked(args, { cwd, signal: options.signal });
|
|
393
|
+
}
|
|
394
|
+
/* ── log ───────────────────────────────────────────────────────────────── */
|
|
395
|
+
/**
|
|
396
|
+
* Recent commits (default 20), parseable fields only.
|
|
397
|
+
* @param cwd - working directory inside the repository.
|
|
398
|
+
* @param options - max count, abort signal.
|
|
399
|
+
* @returns newest-first commit entries with hash/author/date/subject.
|
|
400
|
+
*/
|
|
401
|
+
async log(cwd, options = {}) {
|
|
402
|
+
const max = options.max ?? 20;
|
|
403
|
+
const output = await this.text(['log', `--max-count=${max}`, '--pretty=format:%H%x09%h%x09%an%x09%ae%x09%aI%x09%s'], { cwd, signal: options.signal });
|
|
404
|
+
const entries = [];
|
|
405
|
+
for (const line of output.split('\n')) {
|
|
406
|
+
if (!line)
|
|
407
|
+
continue;
|
|
408
|
+
const [hash, shortHash, authorName, authorEmail, date, ...subjectParts] = line.split('\t');
|
|
409
|
+
if (hash === undefined || shortHash === undefined)
|
|
410
|
+
continue;
|
|
411
|
+
entries.push({
|
|
412
|
+
hash,
|
|
413
|
+
shortHash,
|
|
414
|
+
authorName: authorName ?? '',
|
|
415
|
+
authorEmail: authorEmail ?? '',
|
|
416
|
+
date: date ?? '',
|
|
417
|
+
subject: subjectParts.join('\t'),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return entries;
|
|
421
|
+
}
|
|
422
|
+
buildDiffArgs(options) {
|
|
423
|
+
const args = ['diff'];
|
|
424
|
+
if (options.binary)
|
|
425
|
+
args.push('--binary');
|
|
426
|
+
if (options.cached)
|
|
427
|
+
args.push('--cached');
|
|
428
|
+
if (options.nameOnly)
|
|
429
|
+
args.push('--name-only');
|
|
430
|
+
if (options.numstat)
|
|
431
|
+
args.push('--numstat');
|
|
432
|
+
if (options.base) {
|
|
433
|
+
args.push(options.base);
|
|
434
|
+
if (options.head)
|
|
435
|
+
args.push(options.head);
|
|
436
|
+
}
|
|
437
|
+
if (options.files?.length)
|
|
438
|
+
args.push('--', ...options.files);
|
|
439
|
+
return args;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function splitLines(text) {
|
|
443
|
+
const lines = [];
|
|
444
|
+
for (const line of text.split('\n')) {
|
|
445
|
+
if (line.length > 0)
|
|
446
|
+
lines.push(line);
|
|
447
|
+
}
|
|
448
|
+
return lines;
|
|
449
|
+
}
|
|
450
|
+
/** Join patch parts the way `git apply` expects (omp `patch.join`). */
|
|
451
|
+
function patchJoin(parts) {
|
|
452
|
+
return `${parts
|
|
453
|
+
.map(part => (part.endsWith('\n') ? part : `${part}\n`))
|
|
454
|
+
.join('\n')
|
|
455
|
+
.replace(/\n+$/, '')}\n`;
|
|
456
|
+
}
|
|
457
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAA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SACvD,IAAI,CAAC,IAAI,CAAC;SACV,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency-ordered execution of a split-commit plan, with cycle rejection.
|
|
3
|
+
* Direct port of omp's `packages/coding-agent/src/commit/agentic/topo-sort.ts`.
|
|
4
|
+
* @module @hy-sde-org/dsh-git/topo-sort
|
|
5
|
+
*/
|
|
6
|
+
import type { SplitCommitGroup } from './types.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Order the plan's commit groups so every group's declared dependencies are
|
|
9
|
+
* satisfied first. Returns the commit indices in execution order, or a
|
|
10
|
+
* readable error when the dependency graph is invalid — an out-of-range
|
|
11
|
+
* dependency index, or a cycle (which is rejected before anything is written).
|
|
12
|
+
* @param groups - the plan's commit groups (already validated for coverage).
|
|
13
|
+
* @returns indices into {@link groups} in dependency order.
|
|
14
|
+
*/
|
|
15
|
+
export declare function computeDependencyOrder(groups: SplitCommitGroup[]): number[] | {
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=topo-sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topo-sort.d.ts","sourceRoot":"","sources":["../src/topo-sort.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,EAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAyC/F"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency-ordered execution of a split-commit plan, with cycle rejection.
|
|
3
|
+
* Direct port of omp's `packages/coding-agent/src/commit/agentic/topo-sort.ts`.
|
|
4
|
+
* @module @hy-sde-org/dsh-git/topo-sort
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Order the plan's commit groups so every group's declared dependencies are
|
|
8
|
+
* satisfied first. Returns the commit indices in execution order, or a
|
|
9
|
+
* readable error when the dependency graph is invalid — an out-of-range
|
|
10
|
+
* dependency index, or a cycle (which is rejected before anything is written).
|
|
11
|
+
* @param groups - the plan's commit groups (already validated for coverage).
|
|
12
|
+
* @returns indices into {@link groups} in dependency order.
|
|
13
|
+
*/
|
|
14
|
+
export function computeDependencyOrder(groups) {
|
|
15
|
+
const total = groups.length;
|
|
16
|
+
const inDegree = new Array(total).fill(0);
|
|
17
|
+
const edges = Array.from({ length: total }, () => new Set());
|
|
18
|
+
for (let index = 0; index < total; index += 1) {
|
|
19
|
+
const dependencies = groups[index]?.dependencies ?? [];
|
|
20
|
+
for (const dependency of dependencies) {
|
|
21
|
+
if (dependency < 0 || dependency >= total) {
|
|
22
|
+
return { error: `Invalid dependency index: ${dependency}` };
|
|
23
|
+
}
|
|
24
|
+
if (!edges[dependency]?.has(index)) {
|
|
25
|
+
edges[dependency]?.add(index);
|
|
26
|
+
inDegree[index] = (inDegree[index] ?? 0) + 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const queue = [];
|
|
31
|
+
for (let index = 0; index < total; index += 1) {
|
|
32
|
+
if (inDegree[index] === 0)
|
|
33
|
+
queue.push(index);
|
|
34
|
+
}
|
|
35
|
+
const order = [];
|
|
36
|
+
while (queue.length > 0) {
|
|
37
|
+
const current = queue.shift();
|
|
38
|
+
if (current === undefined)
|
|
39
|
+
break;
|
|
40
|
+
order.push(current);
|
|
41
|
+
for (const next of edges[current] ?? []) {
|
|
42
|
+
inDegree[next] = (inDegree[next] ?? 0) - 1;
|
|
43
|
+
if (inDegree[next] === 0) {
|
|
44
|
+
queue.push(next);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (order.length !== total) {
|
|
49
|
+
return { error: 'Circular dependency detected in split commit plan.' };
|
|
50
|
+
}
|
|
51
|
+
return order;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=topo-sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topo-sort.js","sourceRoot":"","sources":["../src/topo-sort.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA0B;IAC/D,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAA;IAC3B,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAS,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,EAAU,CAAC,CAAA;IAEpE,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC9C,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,YAAY,IAAI,EAAE,CAAA;QACtD,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;YACtC,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;gBAC1C,OAAO,EAAE,KAAK,EAAE,6BAA6B,UAAU,EAAE,EAAE,CAAA;YAC7D,CAAC;YACD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnC,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;gBAC7B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC9C,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC9C,CAAC;IAED,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;QAC7B,IAAI,OAAO,KAAK,SAAS;YAAE,MAAK;QAChC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACnB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YACxC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;YAC1C,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC3B,OAAO,EAAE,KAAK,EAAE,oDAAoD,EAAE,CAAA;IACxE,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trivial-change detection for the commit analyzer.
|
|
3
|
+
* Direct port of omp's `packages/coding-agent/src/commit/agentic/trivial.ts`.
|
|
4
|
+
* @module @hy-sde-org/dsh-git/trivial
|
|
5
|
+
*/
|
|
6
|
+
import type { CommitType } from './types.ts';
|
|
7
|
+
export interface TrivialChangeResult {
|
|
8
|
+
isTrivial: true;
|
|
9
|
+
type: CommitType;
|
|
10
|
+
summary: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Classify a diff as a trivial change (whitespace-only or imports-only), which
|
|
14
|
+
* skips the model round entirely and commits directly.
|
|
15
|
+
* @returns a trivial classification, or null when the change is substantive.
|
|
16
|
+
*/
|
|
17
|
+
export declare function detectTrivialChange(diff: string): TrivialChangeResult | null;
|
|
18
|
+
//# sourceMappingURL=trivial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trivial.d.ts","sourceRoot":"","sources":["../src/trivial.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,IAAI,CAAA;IACf,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAMD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAkB5E"}
|
package/dist/trivial.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trivial-change detection for the commit analyzer.
|
|
3
|
+
* Direct port of omp's `packages/coding-agent/src/commit/agentic/trivial.ts`.
|
|
4
|
+
* @module @hy-sde-org/dsh-git/trivial
|
|
5
|
+
*/
|
|
6
|
+
const WHITESPACE_ONLY_PATTERN = /^[-+][\t ]*$/;
|
|
7
|
+
const IMPORT_LINE_PATTERN = /^[-+]\s*(import\s|from\s|export\s.*from|require\(|module\.exports)/;
|
|
8
|
+
const EMPTY_LINE_PATTERN = /^[-+]\s*$/;
|
|
9
|
+
/**
|
|
10
|
+
* Classify a diff as a trivial change (whitespace-only or imports-only), which
|
|
11
|
+
* skips the model round entirely and commits directly.
|
|
12
|
+
* @returns a trivial classification, or null when the change is substantive.
|
|
13
|
+
*/
|
|
14
|
+
export function detectTrivialChange(diff) {
|
|
15
|
+
const lines = diff.split('\n');
|
|
16
|
+
const changeLines = lines.filter(line => line.startsWith('+') || line.startsWith('-'));
|
|
17
|
+
const contentLines = changeLines.filter(line => !line.startsWith('+++') && !line.startsWith('---') && !line.startsWith('@@'));
|
|
18
|
+
if (contentLines.length === 0)
|
|
19
|
+
return null;
|
|
20
|
+
if (isOnlyWhitespace(contentLines)) {
|
|
21
|
+
return { isTrivial: true, type: 'style', summary: 'formatted code' };
|
|
22
|
+
}
|
|
23
|
+
if (isOnlyImports(contentLines)) {
|
|
24
|
+
return { isTrivial: true, type: 'style', summary: 'reorganized imports' };
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function isOnlyWhitespace(lines) {
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
const content = line.slice(1);
|
|
31
|
+
if (content.trim().length > 0 && !WHITESPACE_ONLY_PATTERN.test(line)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
function isOnlyImports(lines) {
|
|
38
|
+
for (const line of lines) {
|
|
39
|
+
if (EMPTY_LINE_PATTERN.test(line))
|
|
40
|
+
continue;
|
|
41
|
+
if (!IMPORT_LINE_PATTERN.test(line)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=trivial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trivial.js","sourceRoot":"","sources":["../src/trivial.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,MAAM,uBAAuB,GAAG,cAAc,CAAA;AAC9C,MAAM,mBAAmB,GAAG,oEAAoE,CAAA;AAChG,MAAM,kBAAkB,GAAG,WAAW,CAAA;AAEtC;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,MAAM,KAAK,GAAG,IAAI,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