@oh-my-pi/pi-coding-agent 14.7.8 → 14.8.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/src/utils/git.ts CHANGED
@@ -40,6 +40,12 @@ export type HunkSelection = {
40
40
  hunks: { type: "all" } | { type: "indices"; indices: number[] } | { type: "lines"; start: number; end: number };
41
41
  };
42
42
 
43
+ export interface StageHunksOptions {
44
+ readonly diffCached?: boolean;
45
+ readonly rawDiff?: string;
46
+ readonly signal?: AbortSignal;
47
+ }
48
+
43
49
  export interface DiffOptions {
44
50
  readonly allowFailure?: boolean;
45
51
  readonly base?: string;
@@ -803,10 +809,10 @@ export const stage = {
803
809
  await runEffect(cwd, args, { signal });
804
810
  },
805
811
 
806
- /** Selectively stage hunks from the working tree diff. */
807
- async hunks(cwd: string, selections: HunkSelection[], signal?: AbortSignal): Promise<void> {
812
+ /** Selectively stage hunks from the provided diff or the current working tree diff. */
813
+ async hunks(cwd: string, selections: HunkSelection[], options: StageHunksOptions = {}): Promise<void> {
808
814
  if (selections.length === 0) return;
809
- const rawDiff = await diff(cwd, { cached: false, signal });
815
+ const rawDiff = options.rawDiff ?? (await diff(cwd, { cached: options.diffCached, signal: options.signal }));
810
816
  const fileDiffs = parseFileDiffs(rawDiff);
811
817
  const fileDiffMap = new Map(fileDiffs.map(entry => [entry.filename, entry]));
812
818
  const patchParts: string[] = [];
@@ -833,7 +839,7 @@ export const stage = {
833
839
 
834
840
  const patchText = patch.join(patchParts);
835
841
  if (!patchText.trim()) return;
836
- await patch.applyText(cwd, patchText, { cached: true, signal });
842
+ await patch.applyText(cwd, patchText, { cached: true, signal: options.signal });
837
843
  },
838
844
 
839
845
  /** Unstage files. Empty array unstages all (`git reset`). */