@hearsay-tools/squawk 0.19.0-dev.8846 → 0.19.0-dev.8872

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.
@@ -2,6 +2,18 @@ import type { DelegationRoutes } from './routes.ts';
2
2
  export declare function createDelegationApp(routes: DelegationRoutes): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, import("hono/types").BlankSchema | import("hono/types").MergeSchemaPath<{
3
3
  "/list": {
4
4
  $get: {
5
+ output: {
6
+ error: string;
7
+ code?: "invalid_input" | undefined;
8
+ };
9
+ outputFormat: "json";
10
+ status: 400;
11
+ input: {
12
+ query: {
13
+ offset?: string | undefined;
14
+ };
15
+ };
16
+ } | {
5
17
  output: {
6
18
  workers: {
7
19
  workerId: string;
@@ -54,18 +66,6 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
54
66
  offset?: string | undefined;
55
67
  };
56
68
  };
57
- } | {
58
- output: {
59
- error: string;
60
- code?: "invalid_input" | undefined;
61
- };
62
- outputFormat: "json";
63
- status: 400;
64
- input: {
65
- query: {
66
- offset?: string | undefined;
67
- };
68
- };
69
69
  };
70
70
  };
71
71
  } & {
@@ -652,6 +652,18 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
652
652
  } & {
653
653
  "/:workerId": {
654
654
  $get: {
655
+ output: {
656
+ error: string;
657
+ code?: "invalid_input" | undefined;
658
+ };
659
+ outputFormat: "json";
660
+ status: 400;
661
+ input: {
662
+ param: {
663
+ workerId: string;
664
+ };
665
+ };
666
+ } | {
655
667
  output: {
656
668
  workerId: string;
657
669
  settled: boolean;
@@ -776,7 +788,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
776
788
  workerId: string;
777
789
  };
778
790
  };
779
- } | {
791
+ };
792
+ };
793
+ } & {
794
+ "/:workerId/collect": {
795
+ $post: {
780
796
  output: {
781
797
  error: string;
782
798
  code?: "invalid_input" | undefined;
@@ -787,12 +803,10 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
787
803
  param: {
788
804
  workerId: string;
789
805
  };
806
+ } & {
807
+ json: Record<string, never>;
790
808
  };
791
- };
792
- };
793
- } & {
794
- "/:workerId/collect": {
795
- $post: {
809
+ } | {
796
810
  output: {
797
811
  workerId: string;
798
812
  parentRunId: string;
@@ -915,7 +929,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
915
929
  } & {
916
930
  json: Record<string, never>;
917
931
  };
918
- } | {
932
+ };
933
+ };
934
+ } & {
935
+ "/:workerId/steer": {
936
+ $post: {
919
937
  output: {
920
938
  error: string;
921
939
  code?: "invalid_input" | undefined;
@@ -927,13 +945,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
927
945
  workerId: string;
928
946
  };
929
947
  } & {
930
- json: Record<string, never>;
948
+ json: {
949
+ text: string;
950
+ };
931
951
  };
932
- };
933
- };
934
- } & {
935
- "/:workerId/steer": {
936
- $post: {
952
+ } | {
937
953
  output: {
938
954
  workerId: string;
939
955
  state: "delivered" | "queued";
@@ -949,7 +965,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
949
965
  text: string;
950
966
  };
951
967
  };
952
- } | {
968
+ };
969
+ };
970
+ } & {
971
+ "/:workerId/stop": {
972
+ $post: {
953
973
  output: {
954
974
  error: string;
955
975
  code?: "invalid_input" | undefined;
@@ -961,15 +981,9 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
961
981
  workerId: string;
962
982
  };
963
983
  } & {
964
- json: {
965
- text: string;
966
- };
984
+ json: Record<string, never>;
967
985
  };
968
- };
969
- };
970
- } & {
971
- "/:workerId/stop": {
972
- $post: {
986
+ } | {
973
987
  output: {
974
988
  workerId: string;
975
989
  state: "stopping" | "terminated";
@@ -983,7 +997,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
983
997
  } & {
984
998
  json: Record<string, never>;
985
999
  };
986
- } | {
1000
+ };
1001
+ };
1002
+ } & {
1003
+ "/:workerId/destroy": {
1004
+ $post: {
987
1005
  output: {
988
1006
  error: string;
989
1007
  code?: "invalid_input" | undefined;
@@ -995,13 +1013,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
995
1013
  workerId: string;
996
1014
  };
997
1015
  } & {
998
- json: Record<string, never>;
1016
+ json: {
1017
+ discardWork?: true | undefined;
1018
+ };
999
1019
  };
1000
- };
1001
- };
1002
- } & {
1003
- "/:workerId/destroy": {
1004
- $post: {
1020
+ } | {
1005
1021
  output: {
1006
1022
  workerId: string;
1007
1023
  state: "complete" | "incomplete";
@@ -1030,22 +1046,6 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1030
1046
  discardWork?: true | undefined;
1031
1047
  };
1032
1048
  };
1033
- } | {
1034
- output: {
1035
- error: string;
1036
- code?: "invalid_input" | undefined;
1037
- };
1038
- outputFormat: "json";
1039
- status: 400;
1040
- input: {
1041
- param: {
1042
- workerId: string;
1043
- };
1044
- } & {
1045
- json: {
1046
- discardWork?: true | undefined;
1047
- };
1048
- };
1049
1049
  } | {
1050
1050
  output: {
1051
1051
  workerId: string;
@@ -1081,13 +1081,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1081
1081
  "/:workerId/diff": {
1082
1082
  $get: {
1083
1083
  output: {
1084
- workerId: string;
1085
- baselineSha: string;
1086
- diff: string;
1087
- truncated: boolean;
1084
+ error: string;
1085
+ code?: "invalid_input" | undefined;
1088
1086
  };
1089
1087
  outputFormat: "json";
1090
- status: 200;
1088
+ status: 400;
1091
1089
  input: {
1092
1090
  param: {
1093
1091
  workerId: string;
@@ -1095,11 +1093,13 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1095
1093
  };
1096
1094
  } | {
1097
1095
  output: {
1098
- error: string;
1099
- code?: "invalid_input" | undefined;
1096
+ workerId: string;
1097
+ baselineSha: string;
1098
+ diff: string;
1099
+ truncated: boolean;
1100
1100
  };
1101
1101
  outputFormat: "json";
1102
- status: 400;
1102
+ status: 200;
1103
1103
  input: {
1104
1104
  param: {
1105
1105
  workerId: string;
@@ -6,6 +6,8 @@
6
6
  export interface GitRunResult {
7
7
  ok: boolean;
8
8
  stdout: string;
9
+ /** True when git wrote more than the runner's buffer limit (`git-command.ts`). */
10
+ overflow?: boolean;
9
11
  }
10
12
  /** A caller-supplied `git` invocation, already bound to a working directory (and env). */
11
13
  export type GitRunner = (args: string[]) => Promise<GitRunResult>;
@@ -31,6 +33,21 @@ export interface TaskDiffBase {
31
33
  * HEAD, or a repo with no `origin` all fall through unchanged.
32
34
  */
33
35
  export declare function freshestBaseRef(runGit: GitRunner, base: string): Promise<string>;
36
+ /**
37
+ * A task diff anchor as `resolveTaskDiffAnchor` returns it. With `viaMergeBase`, the anchor is the
38
+ * merge-base of `base` and HEAD, not yet computed: `diffFromMergeBase` lets git compute it inside
39
+ * the diff, so a caller with one diff to run starts one git process instead of two.
40
+ */
41
+ export interface TaskDiffAnchor extends TaskDiffBase {
42
+ viaMergeBase: boolean;
43
+ }
44
+ /**
45
+ * `git diff <diffArgs> $(git merge-base <base> HEAD)`, with the two-step fallback to `base` itself
46
+ * when there is no merge-base. One git process when git can answer `--merge-base` (git 2.30+ and
47
+ * exactly one merge-base); otherwise git fails, and the two-step form gives the same answer it
48
+ * always gave. Every turn end runs this (hearsay-tools/squawk#4430).
49
+ */
50
+ export declare function diffFromMergeBase<R extends GitRunResult>(runGit: (args: string[]) => Promise<R>, base: string, diffArgs: readonly string[]): Promise<R>;
34
51
  /**
35
52
  * Resolve a task diff anchor. Without a task branch, use the merge-base; without a usable
36
53
  * repoint baseline, use HEAD. Failed git calls fall back to the base name.
@@ -39,3 +56,8 @@ export declare function resolveTaskDiffBase(runGit: GitRunner, baseBranch: strin
39
56
  taskBranch?: string | undefined;
40
57
  runStartedAt?: string | undefined;
41
58
  }): Promise<TaskDiffBase>;
59
+ /** `resolveTaskDiffBase`, with the plain merge-base anchor left to the caller's diff. */
60
+ export declare function resolveTaskDiffAnchor(runGit: GitRunner, baseBranch: string, opts?: {
61
+ taskBranch?: string | undefined;
62
+ runStartedAt?: string | undefined;
63
+ }): Promise<TaskDiffAnchor>;
@@ -75,18 +75,37 @@ async function changedLines(runGit, ref) {
75
75
  }
76
76
  return total;
77
77
  }
78
+ /** `git merge-base <base> HEAD`, or `base` itself when git finds none. */
79
+ async function mergeBaseOf(runGit, base) {
80
+ const res = await runGit(['merge-base', base, 'HEAD']);
81
+ return res.ok && res.stdout.trim() ? res.stdout.trim() : base;
82
+ }
83
+ /**
84
+ * `git diff <diffArgs> $(git merge-base <base> HEAD)`, with the two-step fallback to `base` itself
85
+ * when there is no merge-base. One git process when git can answer `--merge-base` (git 2.30+ and
86
+ * exactly one merge-base); otherwise git fails, and the two-step form gives the same answer it
87
+ * always gave. Every turn end runs this (hearsay-tools/squawk#4430).
88
+ */
89
+ export async function diffFromMergeBase(runGit, base, diffArgs) {
90
+ const direct = await runGit(['diff', ...diffArgs, '--merge-base', base]);
91
+ // An overflow means git was already writing the diff: the two-step form would only repeat it.
92
+ if (direct.ok || direct.overflow)
93
+ return direct;
94
+ return runGit(['diff', ...diffArgs, await mergeBaseOf(runGit, base)]);
95
+ }
78
96
  /**
79
97
  * Resolve a task diff anchor. Without a task branch, use the merge-base; without a usable
80
98
  * repoint baseline, use HEAD. Failed git calls fall back to the base name.
81
99
  */
82
100
  export async function resolveTaskDiffBase(runGit, baseBranch, opts = {}) {
101
+ const { viaMergeBase, ...anchor } = await resolveTaskDiffAnchor(runGit, baseBranch, opts);
102
+ return viaMergeBase ? { base: await mergeBaseOf(runGit, anchor.base) } : anchor;
103
+ }
104
+ /** `resolveTaskDiffBase`, with the plain merge-base anchor left to the caller's diff. */
105
+ export async function resolveTaskDiffAnchor(runGit, baseBranch, opts = {}) {
83
106
  const base = await freshestBaseRef(runGit, baseBranch);
84
- const mergeBase = async () => {
85
- const res = await runGit(['merge-base', base, 'HEAD']);
86
- return res.ok && res.stdout.trim() ? res.stdout.trim() : base;
87
- };
88
107
  if (!opts.taskBranch)
89
- return { base: await mergeBase() };
108
+ return { base, viaMergeBase: true };
90
109
  const headBranchResult = await runGit(['rev-parse', '--abbrev-ref', 'HEAD']);
91
110
  const headBranch = headBranchResult.ok ? headBranchResult.stdout.trim() : '';
92
111
  // An unreadable HEAD (no commits yet, broken worktree) is NOT evidence of a
@@ -94,23 +113,23 @@ export async function resolveTaskDiffBase(runGit, baseBranch, opts = {}) {
94
113
  // guess. A detached HEAD, on the other hand, is by definition not the task's
95
114
  // branch and takes the repointed path below.
96
115
  if (!headBranch || headBranch === opts.taskBranch)
97
- return { base: await mergeBase() };
116
+ return { base, viaMergeBase: true };
98
117
  const repointedHead = { headBranch, taskBranch: opts.taskBranch };
99
118
  const baseline = await checkoutBaseline(runGit, headBranch, opts.runStartedAt);
100
119
  if (!baseline)
101
- return { base: 'HEAD', repointedHead };
120
+ return { base: 'HEAD', repointedHead, viaMergeBase: false };
102
121
  // Two defensible anchors, so report the tighter one: the number must never
103
122
  // claim more than the least either measure attributes to this task. The
104
123
  // baseline is usually it — but not when the run merged the base branch in
105
124
  // afterwards, which drags the whole upstream delta past a pre-merge baseline
106
125
  // and leaves the merge-base as the only anchor that still measures the task.
107
- const anchor = await mergeBase();
126
+ const anchor = await mergeBaseOf(runGit, base);
108
127
  const viaBaseline = await changedLines(runGit, baseline);
109
128
  if (viaBaseline === null)
110
- return { base: anchor, repointedHead };
129
+ return { base: anchor, repointedHead, viaMergeBase: false };
111
130
  const viaMergeBase = await changedLines(runGit, anchor);
112
131
  if (viaMergeBase === null || viaBaseline <= viaMergeBase)
113
- return { base: baseline, repointedHead };
114
- return { base: anchor, repointedHead };
132
+ return { base: baseline, repointedHead, viaMergeBase: false };
133
+ return { base: anchor, repointedHead, viaMergeBase: false };
115
134
  }
116
135
  //# sourceMappingURL=git-diff-base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"git-diff-base.js","sourceRoot":"","sources":["../src/git-diff-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MA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,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;IAClE,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/E,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAE3E,2EAA2E;IAC3E,wEAAwE;IACxE,0EAA0E;IAC1E,6EAA6E;IAC7E,6EAA6E;IAC7E,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACzD,IAAI,WAAW,KAAK,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACtF,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxD,IAAI,YAAY,KAAK,IAAI,IAAI,WAAW,IAAI,YAAY;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACxH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AAC9D,CAAC"}
@@ -1,16 +1,63 @@
1
- import { mkdtemp, rm } from 'node:fs/promises';
1
+ import { mkdtemp, readFile, rm, stat } from 'node:fs/promises';
2
2
  import { tmpdir } from 'node:os';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { git } from './git-command.js';
5
5
  import { copyGitIndex } from './git-index-copy.js';
6
6
  import { fallbackProjectWriteError } from './project-paths.js';
7
+ /** Entries kept by `realIndexPath`: one per worktree or checkout read. */
8
+ const INDEX_PATH_CACHE_MAX = 512;
9
+ const indexPathCache = new Map();
10
+ /**
11
+ * What decides where Git keeps the index of `dir`: the text of a `.git` file (a linked worktree's
12
+ * `gitdir:` pointer) or the identity of a `.git` directory. Undefined when `dir` has no `.git` of
13
+ * its own (a subdirectory, not a repository) or it cannot be read: Git is then asked every time.
14
+ */
15
+ async function dotGitEntry(dir) {
16
+ const path = join(dir, '.git');
17
+ try {
18
+ const entry = await stat(path, { bigint: true });
19
+ if (entry.isDirectory())
20
+ return `dir:${entry.dev}:${entry.ino}`;
21
+ if (entry.isFile())
22
+ return `file:${await readFile(path, 'utf8')}`;
23
+ }
24
+ catch { /* No readable `.git` here. */ }
25
+ return undefined;
26
+ }
27
+ /**
28
+ * `git rev-parse --git-path index` for `dir`, or '' when Git cannot tell. The answer is kept while
29
+ * the `.git` entry stays the same, so a repeat read starts no process: every turn end reads one
30
+ * (hearsay-tools/squawk#4430). A worktree removed and added again at the same path can get another
31
+ * admin directory, and its `.git` file then names it, so the next read asks Git again.
32
+ */
33
+ async function realIndexPath(dir) {
34
+ const entry = await dotGitEntry(dir);
35
+ if (entry === undefined)
36
+ return askIndexPath(dir);
37
+ const cached = indexPathCache.get(dir);
38
+ // A read in flight is shared: a turn end and a settlement diff often start together.
39
+ if (cached?.entry === entry)
40
+ return cached.path;
41
+ const kept = { entry, path: askIndexPath(dir) };
42
+ indexPathCache.delete(dir);
43
+ if (indexPathCache.size >= INDEX_PATH_CACHE_MAX)
44
+ indexPathCache.delete(indexPathCache.keys().next().value);
45
+ indexPathCache.set(dir, kept);
46
+ const path = await kept.path;
47
+ if (!path && indexPathCache.get(dir) === kept)
48
+ indexPathCache.delete(dir);
49
+ return path;
50
+ }
51
+ async function askIndexPath(dir) {
52
+ const real = await git(dir, ['rev-parse', '--path-format=absolute', '--git-path', 'index']);
53
+ return real.ok ? real.stdout.trim() : '';
54
+ }
7
55
  /**
8
56
  * Read through a private index copy. Try OS temp, then the Git directory; if neither is
9
57
  * writable, check beforeLiveIndex before the real-index fallback. Always remove scratch state.
10
58
  */
11
59
  export async function withPrivateIndex(worktreePath, read, beforeLiveIndex) {
12
- const real = await git(worktreePath, ['rev-parse', '--path-format=absolute', '--git-path', 'index']);
13
- const realIndex = real.ok ? real.stdout.trim() : '';
60
+ const realIndex = await realIndexPath(worktreePath);
14
61
  let scratch;
15
62
  for (const parent of [tmpdir(), ...(realIndex ? [dirname(realIndex)] : [])]) {
16
63
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"git-private-index.js","sourceRoot":"","sources":["../src/git-private-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAkB,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAO/D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,YAAoB,EACpB,IAAmC,EACnC,eAA2C;IAE3C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,wBAAwB,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;IACrG,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,IAAI,OAA2B,CAAC;IAChC,KAAK,MAAM,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC5E,IAAI,CAAC;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,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,mCAAmC,CAAC,CAAC;QAC5G,CAAC;QACD,IAAI,CAAC,MAAM;YAAE,MAAM,OAAO,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAClD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC"}
@@ -5,7 +5,7 @@ import { ownedWorkspaceSchema } from './contract/index.js';
5
5
  import { existsSync, realpathSync } from 'node:fs';
6
6
  import { chmod, lstat, mkdir, readdir, readFile, rm, rmdir } from 'node:fs/promises';
7
7
  import { basename, dirname, join, resolve } from 'node:path';
8
- import { resolveTaskDiffBase } from './git-diff-base.js';
8
+ import { diffFromMergeBase, resolveTaskDiffAnchor } from './git-diff-base.js';
9
9
  import { withPrivateIndex } from './git-private-index.js';
10
10
  import { isSafeGitRef } from './git-refs.js';
11
11
  import { withWorktreeMutation } from './git-worktree-lock.js';
@@ -591,17 +591,16 @@ async function removeWorktreeLocked(repoRoot, worktreePath, branch, opts, git) {
591
591
  return removeCleanWorktree(repoRoot, worktreePath, protection, git, beforeRemove);
592
592
  return forceRemoveWorktree(repoRoot, worktreePath, branch, reclaimOwnedDirectory, protection, git, beforeRemove);
593
593
  }
594
- async function prepareWholeBranchDiff(git, baseBranch) {
594
+ /** `git diff <diffArgs>` from the merge-base of `baseBranch` and HEAD to the working tree. */
595
+ async function wholeBranchDiff(git, baseBranch, diffArgs) {
595
596
  await git(['add', '-N', '.']); // intent-to-add (private index, hearsay-tools/cezarion#1080): untracked files show up
596
- const mergeBase = await git(['merge-base', baseBranch, 'HEAD']);
597
- return mergeBase.ok && mergeBase.stdout.trim() ? mergeBase.stdout.trim() : baseBranch;
597
+ return diffFromMergeBase(git, baseBranch, diffArgs);
598
598
  }
599
599
  export async function worktreeDiff(worktreePath, baseBranch, cap = DIFF_CAP, beforeLiveIndex) {
600
600
  if (!isSafeGitRef(baseBranch))
601
601
  return '(diff failed: refusing option-like base ref)';
602
602
  return withPrivateIndex(worktreePath, async (git) => {
603
- const base = await prepareWholeBranchDiff(git, baseBranch);
604
- const res = await git(['diff', base]);
603
+ const res = await wholeBranchDiff(git, baseBranch, []);
605
604
  if (!res.ok)
606
605
  return `(diff failed: ${res.stderr.trim() || 'unknown git error'})`;
607
606
  if (res.stdout.length > cap)
@@ -620,8 +619,7 @@ export async function worktreeDiffStat(worktreePath, baseBranch) {
620
619
  if (!isSafeGitRef(baseBranch))
621
620
  return '';
622
621
  return withPrivateIndex(worktreePath, async (git) => {
623
- const base = await prepareWholeBranchDiff(git, baseBranch);
624
- const res = await git(['diff', '--stat', base]);
622
+ const res = await wholeBranchDiff(git, baseBranch, ['--stat']);
625
623
  return res.ok ? res.stdout.trim() : '';
626
624
  });
627
625
  }
@@ -652,10 +650,10 @@ export async function worktreeShortstat(worktreePath, baseBranch, opts = {}) {
652
650
  // Private index (#1080): this runs at every turn end, beside the turn-end autosave.
653
651
  return withPrivateIndex(worktreePath, async (git) => {
654
652
  await git(['add', '-N', '.']); // intent-to-add: untracked files show up
655
- // `resolveTaskDiffBase` may compare two anchors with `git diff --shortstat`, so it
653
+ // `resolveTaskDiffAnchor` may compare two anchors with `git diff --shortstat`, so it
656
654
  // reads the private index too.
657
- const { base, repointedHead } = await resolveTaskDiffBase(git, baseBranch, opts);
658
- const res = await git(['diff', '--shortstat', base]);
655
+ const { base, repointedHead, viaMergeBase } = await resolveTaskDiffAnchor(git, baseBranch, opts);
656
+ const res = viaMergeBase ? await diffFromMergeBase(git, base, ['--shortstat']) : await git(['diff', '--shortstat', base]);
659
657
  if (!res.ok)
660
658
  return null;
661
659
  // The key stays ABSENT (not `false`) on a normal run: `diffStat` is persisted in