vibe-coding-master 0.4.5 → 0.4.7

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.
@@ -135,6 +135,42 @@ export function createGitAdapter(runner) {
135
135
  }
136
136
  return result.stdout;
137
137
  },
138
+ async getCommitList(repoRoot, range) {
139
+ const result = await runGit(runner, repoRoot, ["log", "--format=%H%x00%s%x00%cI%x1e", range]);
140
+ if (result.exitCode !== 0) {
141
+ throw new VcmError({
142
+ code: "GIT_ERROR",
143
+ message: "Unable to read Git commit list.",
144
+ statusCode: 400,
145
+ hint: result.stderr
146
+ });
147
+ }
148
+ return result.stdout
149
+ .split("\x1e")
150
+ .map((record) => record.trim())
151
+ .filter(Boolean)
152
+ .map((record) => {
153
+ const [sha = "", subject = "", committedAt = ""] = record.split("\0");
154
+ return {
155
+ sha: sha.trim(),
156
+ subject: subject.trim(),
157
+ committedAt: committedAt.trim() || undefined
158
+ };
159
+ })
160
+ .filter((commit) => commit.sha.length > 0);
161
+ },
162
+ async getMergeBase(repoRoot, leftRef, rightRef) {
163
+ const result = await runGit(runner, repoRoot, ["merge-base", leftRef, rightRef]);
164
+ if (result.exitCode !== 0) {
165
+ throw new VcmError({
166
+ code: "GIT_ERROR",
167
+ message: "Unable to find Git merge base.",
168
+ statusCode: 400,
169
+ hint: result.stderr
170
+ });
171
+ }
172
+ return result.stdout.trim();
173
+ },
138
174
  async isIgnored(repoRoot, repoRelativePath) {
139
175
  const result = await runGit(runner, repoRoot, ["check-ignore", "-q", "--", repoRelativePath]);
140
176
  if (result.exitCode === 0) {
@@ -32,9 +32,11 @@ export function registerHarnessRoutes(app, deps) {
32
32
  return deps.harnessService.updateHarnessFileContent(task.worktreePath, request.query.path ?? "", request.body.content);
33
33
  });
34
34
  app.get("/api/projects/harness/repository-diff", async (request) => {
35
- const { task } = await requireHarnessTaskContext(deps, request.query.taskSlug);
36
- const scope = request.query.scope === "all" ? "all" : "harness";
37
- return deps.harnessService.getRepositoryDiff(task.worktreePath, scope);
35
+ const { project, task } = await requireHarnessTaskContext(deps, request.query.taskSlug);
36
+ return deps.harnessService.getRepositoryDiff(task.worktreePath, {
37
+ baseRepoRoot: project.repoRoot,
38
+ commitSha: request.query.commit
39
+ });
38
40
  });
39
41
  app.get("/api/projects/harness/bootstrap", async (request) => {
40
42
  const { project, task } = await requireHarnessTaskContext(deps, request.query.taskSlug);
@@ -246,15 +246,8 @@ export function createHarnessService(deps) {
246
246
  : formatHarnessApplyMessage(committed.harnessCommit, true)
247
247
  };
248
248
  },
249
- async getRepositoryDiff(repoRoot, scope = "harness") {
250
- if (!deps.git) {
251
- throw new VcmError({
252
- code: "HARNESS_GIT_UNAVAILABLE",
253
- message: "Git-backed repository diff is not available in this VCM runtime.",
254
- statusCode: 501
255
- });
256
- }
257
- return getRepositoryDiffReport(deps.git, repoRoot, scope, now());
249
+ async getRepositoryDiff(repoRoot, input = {}) {
250
+ return getRepositoryDiffReport(requireRepositoryDiffGit(deps.git), repoRoot, input, now());
258
251
  },
259
252
  async getBootstrapStatus(repoRoot, targetRepoRoot = repoRoot) {
260
253
  return getHarnessBootstrapStatus(deps, repoRoot, targetRepoRoot, now);
@@ -448,12 +441,42 @@ function shortCommit(commit) {
448
441
  }
449
442
  const REPOSITORY_DIFF_MAX_FILES = 250;
450
443
  const REPOSITORY_DIFF_MAX_DIFF_CHARS = 180_000;
451
- async function getRepositoryDiffReport(git, repoRoot, scope, generatedAt) {
452
- const commitInfo = await git.getCommitInfo(repoRoot, "HEAD");
453
- const rawDiff = await git.getCommitDiff(repoRoot, "HEAD");
454
- const allFiles = parseCommitDiffFiles(rawDiff)
455
- .filter((file) => scope === "all" || file.category !== "product_code");
444
+ function requireRepositoryDiffGit(git) {
445
+ if (!git?.getCommitDiff ||
446
+ !git.getCommitInfo ||
447
+ !git.getCommitList ||
448
+ !git.getHeadCommit ||
449
+ !git.getMergeBase) {
450
+ throw new VcmError({
451
+ code: "HARNESS_GIT_UNAVAILABLE",
452
+ message: "Git-backed repository diff is not available in this VCM runtime.",
453
+ statusCode: 501
454
+ });
455
+ }
456
+ return git;
457
+ }
458
+ async function getRepositoryDiffReport(git, repoRoot, input, generatedAt) {
459
+ const baseRef = input.baseRepoRoot
460
+ ? await git.getHeadCommit(input.baseRepoRoot)
461
+ : "HEAD^";
462
+ const mergeBase = await git.getMergeBase(repoRoot, baseRef, "HEAD");
463
+ const commits = (await git.getCommitList(repoRoot, `${mergeBase}..HEAD`)).map(toRepositoryDiffCommit);
456
464
  const warnings = [];
465
+ const selectedCommit = selectRepositoryDiffCommit(commits, input.commitSha);
466
+ if (!selectedCommit) {
467
+ return {
468
+ version: 1,
469
+ repoRoot,
470
+ generatedAt,
471
+ commits,
472
+ summary: createEmptyRepositoryDiffSummary(),
473
+ files: [],
474
+ warnings
475
+ };
476
+ }
477
+ const commitInfo = await git.getCommitInfo(repoRoot, selectedCommit.sha);
478
+ const rawDiff = await git.getCommitDiff(repoRoot, selectedCommit.sha);
479
+ const allFiles = parseCommitDiffFiles(rawDiff);
457
480
  const files = allFiles.slice(0, REPOSITORY_DIFF_MAX_FILES);
458
481
  if (allFiles.length > files.length) {
459
482
  warnings.push(`Diff file list is truncated to ${REPOSITORY_DIFF_MAX_FILES} files.`);
@@ -465,8 +488,8 @@ async function getRepositoryDiffReport(git, repoRoot, scope, generatedAt) {
465
488
  return {
466
489
  version: 1,
467
490
  repoRoot,
468
- scope,
469
491
  generatedAt,
492
+ commits,
470
493
  commit: {
471
494
  sha: commitInfo.sha,
472
495
  shortSha: commitInfo.sha.slice(0, 12),
@@ -490,6 +513,36 @@ async function getRepositoryDiffReport(git, repoRoot, scope, generatedAt) {
490
513
  warnings
491
514
  };
492
515
  }
516
+ function toRepositoryDiffCommit(commit) {
517
+ return {
518
+ sha: commit.sha,
519
+ shortSha: commit.sha.slice(0, 12),
520
+ subject: commit.subject,
521
+ committedAt: commit.committedAt
522
+ };
523
+ }
524
+ function selectRepositoryDiffCommit(commits, requestedSha) {
525
+ const normalizedSha = requestedSha?.trim();
526
+ if (normalizedSha) {
527
+ return commits.find((commit) => commit.sha === normalizedSha || commit.shortSha === normalizedSha);
528
+ }
529
+ return commits[0];
530
+ }
531
+ function createEmptyRepositoryDiffSummary() {
532
+ return {
533
+ totalFiles: 0,
534
+ committedFiles: 0,
535
+ stagedFiles: 0,
536
+ unstagedFiles: 0,
537
+ untrackedFiles: 0,
538
+ additions: 0,
539
+ deletions: 0,
540
+ harnessFiles: 0,
541
+ productCodeFiles: 0,
542
+ truncatedFiles: 0,
543
+ binaryFiles: 0
544
+ };
545
+ }
493
546
  function parseCommitDiffFiles(rawDiff) {
494
547
  const chunks = rawDiff.split(/(?=^diff --git )/m).filter((chunk) => chunk.startsWith("diff --git "));
495
548
  return chunks.map(parseCommitDiffFile);