codex-supervisor-mcp 0.7.3 → 0.9.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/worktree.js CHANGED
@@ -11,9 +11,10 @@
11
11
  // so the committed part is read as `git diff --name-only <base> HEAD`, where
12
12
  // base is the commit the worktree was created from.
13
13
  import { execFileSync } from "node:child_process";
14
- import { existsSync, readFileSync } from "node:fs";
14
+ import { existsSync, readFileSync, lstatSync } from "node:fs";
15
15
  import { join } from "node:path";
16
16
  import { truncateMiddleChars } from "./truncate.js";
17
+ import { createHash } from "node:crypto";
17
18
 
18
19
  const defaultGitBin = process.env.GIT_BIN?.trim() || "git";
19
20
 
@@ -211,3 +212,54 @@ export function worktreeRef(task) {
211
212
  export function readTaskChanges(task) {
212
213
  return mergeChangedFiles(task.changed_files, readWorktreeChanges(task.worktree_path, worktreeRef(task)));
213
214
  }
215
+
216
+ // Compare output at this run's start/end, rather than treating the previous
217
+ // run's committed or uncommitted work as fresh evidence. If the bounded read
218
+ // cannot prove the full state, leave the fingerprint unknown.
219
+ export function snapshotTaskOutput(task) {
220
+ const diff = readWorktreeDiff(task.worktree_path, worktreeRef(task), { maxChars: 2_000_000 });
221
+ if (diff.error || diff.truncated_files > 0 || diff.files.some((file) => file.patch == null)) return null;
222
+ try {
223
+ let remaining = 2_000_000;
224
+ const files = diff.files.map((file) => {
225
+ let content = "deleted";
226
+ if (file.status !== "deleted") {
227
+ const path = join(task.worktree_path, file.path);
228
+ const info = lstatSync(path);
229
+ if (!info.isFile() || info.size > remaining) throw new Error("unknown output");
230
+ remaining -= info.size;
231
+ content = createHash("sha256").update(readFileSync(path)).digest("hex");
232
+ }
233
+ return { path: file.path, from: file.from, status: file.status, patch: file.patch, content };
234
+ });
235
+ return createHash("sha256").update(JSON.stringify(files)).digest("hex");
236
+ } catch { return null; }
237
+ }
238
+
239
+ // How far the project has moved since the worktree was cut. Compared with
240
+ // the project directory's HEAD, which is the branch the main thread
241
+ // integrates on. contains_base false means the base was rewritten (an
242
+ // amend or a rebase on the main branch) and the count is of a history the
243
+ // base is not in; every git error is reported as null, never as 0.
244
+ export function baseBehind(projectRoot, baseCommit) {
245
+ if (!projectRoot || !baseCommit || !existsSync(projectRoot)) return { behind: null, contains_base: null, ref: null };
246
+ let ref = null;
247
+ try {
248
+ ref = git(projectRoot, ["symbolic-ref", "--short", "-q", "HEAD"]).trim() || "HEAD";
249
+ } catch {
250
+ ref = "HEAD";
251
+ }
252
+ try {
253
+ const behind = Number(git(projectRoot, ["rev-list", "--count", `${baseCommit}..HEAD`]).trim());
254
+ let containsBase = true;
255
+ try {
256
+ git(projectRoot, ["merge-base", "--is-ancestor", baseCommit, "HEAD"]);
257
+ } catch (error) {
258
+ if (error.status === 1) containsBase = false;
259
+ else return { behind: null, contains_base: null, ref };
260
+ }
261
+ return { behind: Number.isFinite(behind) ? behind : null, contains_base: containsBase, ref };
262
+ } catch {
263
+ return { behind: null, contains_base: null, ref };
264
+ }
265
+ }