@archme/cli 0.26.0 → 0.28.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/dist/cli.js CHANGED
@@ -12652,7 +12652,7 @@ async function runSandboxedJob(deps, job, opts, settle = async (o2) => o2) {
12652
12652
  const cr = cp.result;
12653
12653
  sandbox.memory_peak_bytes.clone = cr.memoryPeakBytes;
12654
12654
  for (const [k, v] of Object.entries(cr.durations_ms ?? {})) durations[`clone_${k}`] = v;
12655
- if (cr.outcome === "skip") return { kind: "skip", metrics };
12655
+ if (cr.outcome === "skip" || cr.outcome === "off_branch") return { kind: "skip", skip: cr.outcome, metrics };
12656
12656
  if (cr.outcome === "rejected") return { kind: "rejected", message: cr.error ?? "job rejected by the clone step", metrics };
12657
12657
  const scan = cr.outcome === "scan";
12658
12658
  if (cr.error || clone.exit.exitCode !== 0 || !scan && !cr.diff) {
@@ -19129,6 +19129,7 @@ function parseLocalRepos(raw) {
19129
19129
  if (typeof raw2.haltedAt === "string" && raw2.haltedAt) entry.haltedAt = raw2.haltedAt;
19130
19130
  if (typeof raw2.haltReason === "string" && raw2.haltReason) entry.haltReason = raw2.haltReason;
19131
19131
  if (typeof raw2.haltCode === "string" && raw2.haltCode) entry.haltCode = raw2.haltCode;
19132
+ if (typeof raw2.haltSha === "string" && raw2.haltSha) entry.haltSha = raw2.haltSha;
19132
19133
  const prPoll = parsePrPollState(raw2.prPoll);
19133
19134
  if (prPoll) entry.prPoll = prPoll;
19134
19135
  if (typeof raw2.prPausedAt === "string" && raw2.prPausedAt) entry.prPausedAt = raw2.prPausedAt;
@@ -19158,9 +19159,9 @@ function removeLocalReposBySlug(repos, slug) {
19158
19159
  const want = slug.toLowerCase();
19159
19160
  return repos.filter((r) => slugOf(r).toLowerCase() !== want);
19160
19161
  }
19161
- function markHalted(repos, watchedRepoId, reason, at, code) {
19162
+ function markHalted(repos, watchedRepoId, reason, at, code, sha2) {
19162
19163
  return repos.map(
19163
- (r) => r.watchedRepoId === watchedRepoId ? { ...r, haltedAt: at, haltReason: reason, haltCode: code } : r
19164
+ (r) => r.watchedRepoId === watchedRepoId ? { ...r, haltedAt: at, haltReason: reason, haltCode: code, haltSha: sha2 } : r
19164
19165
  );
19165
19166
  }
19166
19167
  function setPrPollState(repos, watchedRepoId, prPoll) {
@@ -19176,7 +19177,7 @@ function markPrPaused(repos, watchedRepoId, at) {
19176
19177
  function clearHalt(repos, watchedRepoId) {
19177
19178
  return repos.map((r) => {
19178
19179
  if (r.watchedRepoId !== watchedRepoId) return r;
19179
- const { haltedAt: _at, haltReason: _reason, haltCode: _code, ...rest } = r;
19180
+ const { haltedAt: _at, haltReason: _reason, haltCode: _code, haltSha: _sha, ...rest } = r;
19180
19181
  return rest;
19181
19182
  });
19182
19183
  }
@@ -19355,11 +19356,9 @@ function planPollTick(input) {
19355
19356
  return { kind: "idle", reason: "waiting for the initial scan to establish the diff marker" };
19356
19357
  case "up-to-date":
19357
19358
  return { kind: "idle", reason: "up to date" };
19359
+ // A reset dropped commits the board reflects: the daemon net-diffs their
19360
+ // removal and the marker moves back (`computeDiff`'s reset rule).
19358
19361
  case "upstream-behind":
19359
- return {
19360
- kind: "idle",
19361
- reason: `upstream is behind the marker (reset to ${short3(plan.tip)}); nothing to do`
19362
- };
19363
19362
  case "force-push":
19364
19363
  target = plan.tip;
19365
19364
  break;
@@ -19370,6 +19369,9 @@ function planPollTick(input) {
19370
19369
  if (!input.jobForTarget) {
19371
19370
  return { kind: "enqueue", beforeSha: marker.sha, afterSha: target };
19372
19371
  }
19372
+ if (didNotLand(input.jobForTarget, marker.sha)) {
19373
+ return { kind: "enqueue", beforeSha: marker.sha, afterSha: target, afterJobId: input.jobForTarget.id };
19374
+ }
19373
19375
  const decision = decideGate({
19374
19376
  targetSha: target,
19375
19377
  markerSha: marker.sha,
@@ -19385,7 +19387,8 @@ function planPollTick(input) {
19385
19387
  return {
19386
19388
  kind: "halt",
19387
19389
  code: decision.code,
19388
- reason: localHaltReason(decision, input.jobForTarget, target)
19390
+ reason: localHaltReason(decision, input.jobForTarget, target),
19391
+ ...decision.code === "job-terminal" && input.jobForTarget.status === "failed" ? { sha: target } : {}
19389
19392
  };
19390
19393
  case "advance":
19391
19394
  return { kind: "idle", reason: decision.reason };
@@ -19393,19 +19396,31 @@ function planPollTick(input) {
19393
19396
  return { kind: "idle", reason: `${short3(target)}: ${decision.reason}` };
19394
19397
  }
19395
19398
  }
19399
+ function didNotLand(job, markerSha) {
19400
+ if (job.status !== "completed" || !job.id) return false;
19401
+ if (job.beforeSha && job.beforeSha !== markerSha) return true;
19402
+ const runs = job.unlandedRuns ?? 0;
19403
+ return runs > 0 && runs < MAX_UNLANDED_RUNS;
19404
+ }
19405
+ function haltHasCleared(halt, job, rolledUpThrough) {
19406
+ if (halt.haltCode !== "job-terminal" || !halt.haltSha) return false;
19407
+ return job?.status === "completed" || rolledUpThrough === halt.haltSha;
19408
+ }
19396
19409
  function localHaltReason(decision, job, targetSha) {
19397
19410
  if (decision.code !== "job-terminal" || !job) return decision.reason;
19398
19411
  return `commit ${short3(targetSha)} could not be processed (job ${job.status} after ${job.attemptCount} attempt(s)). Local watch has stopped here rather than skipping it, because skipping would fold its changes into the next update.
19399
- This one needs us \u2014 the failure is recorded against your account and visible to the ArchMe team. Get in touch if it is blocking you.`;
19412
+ ` + (job.status === "failed" ? `Press Retry on it in the board's History tab, and local watch carries on by itself once it completes. If it keeps failing, get in touch: the ArchMe team can see the failure.` : `This one needs us \u2014 the failure is recorded against your account and visible to the ArchMe team. Get in touch if it is blocking you.`);
19400
19413
  }
19401
19414
  function short3(sha2) {
19402
19415
  return sha2.slice(0, 7);
19403
19416
  }
19417
+ var MAX_UNLANDED_RUNS;
19404
19418
  var init_localPoll = __esm({
19405
19419
  "src/daemon/localPoll.ts"() {
19406
19420
  "use strict";
19407
19421
  init_commitAdvance();
19408
19422
  init_commitGate();
19423
+ MAX_UNLANDED_RUNS = 3;
19409
19424
  }
19410
19425
  });
19411
19426
 
@@ -19958,6 +19973,14 @@ var init_pushSubject = __esm({
19958
19973
  });
19959
19974
 
19960
19975
  // src/daemon/localPoller.ts
19976
+ function countUnlandedRuns(rows) {
19977
+ const before = rows[0]?.before_sha;
19978
+ const end = rows.findIndex((r) => r.status !== "completed" || r.result?.marker_kept !== true || r.before_sha !== before);
19979
+ return end === -1 ? rows.length : end;
19980
+ }
19981
+ function jobRepoOf(entry, row) {
19982
+ return row.repoOwner && row.repoName ? `${row.repoOwner}/${row.repoName}` : `${entry.repoOwner}/${entry.repoName}`;
19983
+ }
19961
19984
  async function pollRepoOnce(entry, deps) {
19962
19985
  const repo = `${entry.repoOwner}/${entry.repoName}`;
19963
19986
  const gateTimeoutMs = deps.gateTimeoutMs ?? DEFAULT_GATE_TIMEOUT_MS;
@@ -19990,10 +20013,11 @@ async function pollRepoOnce(entry, deps) {
19990
20013
  return { kind: "idle", reason: `${repo}: watching is disabled on the server` };
19991
20014
  }
19992
20015
  await deps.git.fetchOrigin(entry.mirrorPath, row.repoBranch);
19993
- const jobRepo = row.repoOwner && row.repoName ? `${row.repoOwner}/${row.repoName}` : repo;
20016
+ const jobRepo = jobRepoOf(entry, row);
19994
20017
  const read = await deps.readMarker(row.projectId, row.archmeBranch, jobRepo);
19995
20018
  const marker = { ...read, sha: read.rolledUpThrough ?? read.sha };
19996
20019
  const upstreamTip = await deps.git.revParse(entry.mirrorPath, `origin/${row.repoBranch}`);
20020
+ if (read.sha && read.sha === upstreamTip) return { kind: "idle", reason: "up to date" };
19997
20021
  const base = {
19998
20022
  marker,
19999
20023
  upstreamTip,
@@ -20030,7 +20054,7 @@ async function pollRepoOnce(entry, deps) {
20030
20054
  jobForTarget: jobForTarget ? { ...jobForTarget, createdAtMs: observedAtMs } : null
20031
20055
  });
20032
20056
  if (decision.kind !== "enqueue") return decision;
20033
- const result = await deps.enqueue(entry, row, decision.beforeSha, decision.afterSha);
20057
+ const result = await deps.enqueue(entry, row, decision.beforeSha, decision.afterSha, decision.afterJobId);
20034
20058
  if (result.dedup) {
20035
20059
  deps.log(` ${repo}: ${short4(decision.afterSha)} already enqueued elsewhere`);
20036
20060
  } else {
@@ -20038,14 +20062,35 @@ async function pollRepoOnce(entry, deps) {
20038
20062
  }
20039
20063
  return decision;
20040
20064
  }
20065
+ async function clearHaltIfRetried(entry, key, deps) {
20066
+ if (!entry.haltSha) return false;
20067
+ try {
20068
+ const row = await deps.readWatchedRepo(entry.watchedRepoId);
20069
+ if (!row) return false;
20070
+ const repo = jobRepoOf(entry, row);
20071
+ const [job, marker] = await Promise.all([
20072
+ deps.readJobForSha(row.projectId, row.archmeBranch, repo, entry.haltSha),
20073
+ deps.readMarker(row.projectId, row.archmeBranch, repo)
20074
+ ]);
20075
+ if (!haltHasCleared(entry, job, marker.rolledUpThrough)) return false;
20076
+ await deps.clearHalt(entry);
20077
+ return true;
20078
+ } catch (err4) {
20079
+ deps.log(` local poll ${key}: could not check its halt (checked again next tick): ${err4.message}`);
20080
+ return false;
20081
+ }
20082
+ }
20041
20083
  async function pollAllRepos(repos, deps) {
20042
20084
  const outcomes = [];
20043
20085
  for (const entry of repos) {
20044
20086
  const key = `${entry.repoOwner}/${entry.repoName} (${entry.watchedRepoId.slice(0, 8)})`;
20045
20087
  const { watchedRepoId } = entry;
20046
20088
  if (entry.haltedAt) {
20047
- outcomes.push({ watchedRepoId, outcome: "halted", haltCode: entry.haltCode, haltReason: entry.haltReason, haltedAt: entry.haltedAt });
20048
- continue;
20089
+ if (!await clearHaltIfRetried(entry, key, deps)) {
20090
+ outcomes.push({ watchedRepoId, outcome: "halted", haltCode: entry.haltCode, haltReason: entry.haltReason, haltedAt: entry.haltedAt });
20091
+ continue;
20092
+ }
20093
+ deps.log(` local poll resumed for ${key}: commit ${short4(entry.haltSha)} no longer blocks it`);
20049
20094
  }
20050
20095
  try {
20051
20096
  const action = await pollRepoOnce(entry, deps);
@@ -20059,7 +20104,7 @@ async function pollAllRepos(repos, deps) {
20059
20104
  haltReason: action.reason,
20060
20105
  haltedAt: new Date(deps.now()).toISOString()
20061
20106
  });
20062
- await deps.persistHalt(entry, action.reason, action.code).catch((err4) => {
20107
+ await deps.persistHalt(entry, action.reason, action.code, action.sha).catch((err4) => {
20063
20108
  deps.log(` local poll ${key}: could not save the halt (checked again next tick): ${err4.message}`);
20064
20109
  });
20065
20110
  deps.log(
@@ -20070,8 +20115,9 @@ async function pollAllRepos(repos, deps) {
20070
20115
  No further commits will be processed for this repo.
20071
20116
  Advancing past a failed commit would fold it into the next diff and break the
20072
20117
  one-ArchMe-commit-per-git-commit guarantee, so this stops instead.
20073
- When the cause is fixed: archme local-watch --resume ${entry.repoOwner}/${entry.repoName}
20074
- `
20118
+ ` + (action.sha ? ` Retry it on the board's History tab; local watch carries on by itself once it completes.
20119
+ ` : ` When the cause is fixed: archme local-watch --resume ${entry.repoOwner}/${entry.repoName}
20120
+ `)
20075
20121
  );
20076
20122
  continue;
20077
20123
  }
@@ -20089,8 +20135,11 @@ async function pollAllRepos(repos, deps) {
20089
20135
  }
20090
20136
  return outcomes;
20091
20137
  }
20092
- function enqueueArgs(entry, row, beforeSha, afterSha, commit) {
20138
+ function enqueueArgs(entry, row, beforeSha, afterSha, commit, afterJobId) {
20093
20139
  return {
20140
+ // Migration 172. Sent only for a re-run, so every other enqueue still
20141
+ // works against a server without it.
20142
+ ...afterJobId ? { p_after_job: afterJobId } : {},
20094
20143
  p_watched_repo_id: entry.watchedRepoId,
20095
20144
  // From the ROW, not the registry: these decide which lane the job lands
20096
20145
  // in, and a stale copy would enqueue against the wrong branch.
@@ -20121,12 +20170,15 @@ function makePollerDeps(client, log, gateTimeoutMs) {
20121
20170
  firstSeen.set(key, nowMs);
20122
20171
  return nowMs;
20123
20172
  },
20124
- async persistHalt(entry, reason, code) {
20173
+ async persistHalt(entry, reason, code, sha2) {
20125
20174
  const repos = await loadLocalRepos();
20126
20175
  await saveLocalRepos(
20127
- markHalted(repos, entry.watchedRepoId, reason, (/* @__PURE__ */ new Date()).toISOString(), code)
20176
+ markHalted(repos, entry.watchedRepoId, reason, (/* @__PURE__ */ new Date()).toISOString(), code, sha2)
20128
20177
  );
20129
20178
  },
20179
+ async clearHalt(entry) {
20180
+ await saveLocalRepos(clearHalt(await loadLocalRepos(), entry.watchedRepoId));
20181
+ },
20130
20182
  async readWatchedRepo(watchedRepoId) {
20131
20183
  const { data, error } = await client.from("watched_repos").select("project_id, branch, commit_update_archme_branch, source_kind, enabled, pr_update_mode, repo_owner, repo_name, deleted_at").eq("id", watchedRepoId).maybeSingle();
20132
20184
  if (error) throw new Error(`could not read the watched repo: ${error.message}`);
@@ -20152,16 +20204,20 @@ function makePollerDeps(client, log, gateTimeoutMs) {
20152
20204
  readMarker: (projectId, archmeBranch, repo) => readBranchMarker(client, projectId, archmeBranch, repo),
20153
20205
  async readJobForSha(projectId, archmeBranch, repo, sha2) {
20154
20206
  const [owner, name] = repo.split("/");
20155
- const { data, error } = await client.from("archme_jobs").select("status, attempt_count, created_at").eq("project_id", projectId).eq("archme_branch", archmeBranch).eq("repo_owner", owner ?? "").eq("repo_name", name ?? "").eq("after_sha", sha2).order("created_at", { ascending: false }).limit(1);
20207
+ const { data, error } = await client.from("archme_jobs").select("id, status, attempt_count, created_at, before_sha, result").eq("project_id", projectId).eq("archme_branch", archmeBranch).eq("repo_owner", owner ?? "").eq("repo_name", name ?? "").eq("after_sha", sha2).order("created_at", { ascending: false }).limit(MAX_UNLANDED_RUNS);
20156
20208
  if (error || !data || data.length === 0) return null;
20157
- const row = data[0];
20209
+ const rows = data;
20210
+ const row = rows[0];
20158
20211
  return {
20212
+ id: row.id,
20159
20213
  status: row.status,
20160
20214
  attemptCount: row.attempt_count ?? 0,
20161
- createdAtMs: new Date(row.created_at).getTime()
20215
+ createdAtMs: new Date(row.created_at).getTime(),
20216
+ beforeSha: row.before_sha,
20217
+ unlandedRuns: countUnlandedRuns(rows)
20162
20218
  };
20163
20219
  },
20164
- async enqueue(entry, row, beforeSha, afterSha) {
20220
+ async enqueue(entry, row, beforeSha, afterSha, afterJobId) {
20165
20221
  const meta = await readCommitMeta(entry.mirrorPath, afterSha);
20166
20222
  const subject = await resolvePushSubject(
20167
20223
  meta.message || null,
@@ -20173,7 +20229,7 @@ function makePollerDeps(client, log, gateTimeoutMs) {
20173
20229
  );
20174
20230
  const { data, error } = await client.rpc(
20175
20231
  "enqueue_local_archme_job",
20176
- enqueueArgs(entry, row, beforeSha, afterSha, { subject, meta })
20232
+ enqueueArgs(entry, row, beforeSha, afterSha, { subject, meta }, afterJobId)
20177
20233
  );
20178
20234
  if (error) throw new Error(`enqueue_local_archme_job: ${error.message}`);
20179
20235
  return data ?? {};
@@ -20740,7 +20796,7 @@ function shapeError(o2) {
20740
20796
  if (!isObj(o2.durations_ms) || !Object.values(o2.durations_ms).every((v) => typeof v === "number")) return "durations_ms";
20741
20797
  if (o2.error !== void 0 && typeof o2.error !== "string") return "error";
20742
20798
  if (o2.kind === "clone") {
20743
- if (o2.outcome !== "diff" && o2.outcome !== "skip" && o2.outcome !== "rejected" && o2.outcome !== "scan") return "outcome";
20799
+ if (!["diff", "skip", "off_branch", "rejected", "scan"].includes(o2.outcome)) return "outcome";
20744
20800
  if (o2.diff !== void 0 && !isObj(o2.diff)) return "diff";
20745
20801
  return null;
20746
20802
  }
@@ -23240,6 +23296,7 @@ async function runCloneStep(input, deps = {}) {
23240
23296
  const fetch2 = async (refspecs2) => {
23241
23297
  const r = await tryGit(["fetch", "--filter=blob:none", "--no-tags", "origin", ...refspecs2]);
23242
23298
  if (r.exitCode !== 0) log(`fetch ${refspecs2.join(" ")} failed: ${r.stderr.trim()}`);
23299
+ return r;
23243
23300
  };
23244
23301
  await must(["init", "-q", repoDir]);
23245
23302
  if ((await tryGit(["remote", "add", "origin", input.credentials.https_url])).exitCode !== 0) {
@@ -23247,12 +23304,19 @@ async function runCloneStep(input, deps = {}) {
23247
23304
  }
23248
23305
  await must(["config", "remote.origin.promisor", "true"], repoDir);
23249
23306
  await must(["config", "remote.origin.partialclonefilter", "blob:none"], repoDir);
23250
- const refspecs = [`+refs/heads/${job.repo_branch}:refs/remotes/origin/${job.repo_branch}`];
23307
+ const tracking = `refs/remotes/origin/${job.repo_branch}`;
23308
+ const refspecs = [`+refs/heads/${job.repo_branch}:${tracking}`];
23251
23309
  if (job.source_mode === "pr_update" && job.pr_number) {
23252
23310
  refspecs.push(`+refs/pull/${job.pr_number}/head:refs/remotes/origin/pr/${job.pr_number}`);
23253
23311
  }
23254
- await fetch2(refspecs);
23255
- const wanted = [target];
23312
+ const fetched = await fetch2(refspecs);
23313
+ const push = !scanRef && job.source_mode !== "pr_update";
23314
+ let branchTip = null;
23315
+ if (push) {
23316
+ if (fetched.exitCode !== 0) throw new Error(`could not fetch ${job.repo_branch} from origin: ${fetched.stderr.trim()}`);
23317
+ branchTip = (await must(["rev-parse", "--verify", `${tracking}^{commit}`], repoDir)).stdout.trim();
23318
+ }
23319
+ const wanted = push ? [] : [target];
23256
23320
  if (scanRef) {
23257
23321
  } else if (job.source_mode === "pr_update") {
23258
23322
  if (job.before_sha) wanted.push(job.before_sha);
@@ -23272,11 +23336,11 @@ async function runCloneStep(input, deps = {}) {
23272
23336
  log(`checked out ${scanRef.slice(0, 8)} for a first scan`);
23273
23337
  return { result: { kind: "clone", outcome: "scan" }, exitCode: 0 };
23274
23338
  }
23275
- const diff = await computeDiff(asArchmeJob(job), repoDir, marker, gitEnv);
23339
+ const diff = await computeDiff(asArchmeJob(job), repoDir, marker, branchTip, gitEnv);
23276
23340
  mark("diff");
23277
- if (diff === "skip") {
23278
- log("after_sha is already at or behind the clean marker \u2014 skip");
23279
- return { result: { kind: "clone", outcome: "skip" }, exitCode: EXIT_SKIP };
23341
+ if (isDiffSkip(diff)) {
23342
+ log(diffSkipSummary(diff, job.repo_branch));
23343
+ return { result: { kind: "clone", outcome: diff }, exitCode: EXIT_SKIP };
23280
23344
  }
23281
23345
  const persisted = {
23282
23346
  patch: diff.patch,
@@ -23628,8 +23692,10 @@ __export(run_exports, {
23628
23692
  claudeFailureDetail: () => claudeFailureDetail,
23629
23693
  computeDiff: () => computeDiff,
23630
23694
  createJobWorktree: () => createJobWorktree,
23695
+ diffSkipSummary: () => diffSkipSummary,
23631
23696
  forkRepoScope: () => forkRepoScope,
23632
23697
  isClaudeAuthFailure: () => isClaudeAuthFailure,
23698
+ isDiffSkip: () => isDiffSkip,
23633
23699
  parseClaudeResult: () => parseClaudeResult,
23634
23700
  parseJobTokenResponse: () => parseJobTokenResponse,
23635
23701
  probeMcpAuth: () => probeMcpAuth,
@@ -23807,34 +23873,44 @@ async function buildGitEnv(credentials) {
23807
23873
  return { env, cleanup: () => rm7(dir, { recursive: true, force: true }).catch(() => {
23808
23874
  }) };
23809
23875
  }
23876
+ async function fetchBranchTip(dir, branch, env) {
23877
+ const tracking = `refs/remotes/origin/${branch}`;
23878
+ const fetched = await execa("git", ["fetch", "--no-tags", "origin", `+refs/heads/${branch}:${tracking}`], { cwd: dir, env, reject: false });
23879
+ if (fetched.exitCode !== 0) throw new Error(`could not fetch ${branch} from origin: ${String(fetched.stderr).trim()}`);
23880
+ const { stdout } = await execa("git", ["rev-parse", "--verify", `${tracking}^{commit}`], { cwd: dir, env });
23881
+ return stdout.trim();
23882
+ }
23810
23883
  async function ensureLocalCloneAndFetch(job, entry) {
23811
23884
  const dir = entry.mirrorPath;
23812
23885
  assertLocalJobShape(job);
23886
+ let branchTip = null;
23813
23887
  await cloneMutex.runExclusive(dir, async () => {
23814
23888
  if (!await exists(join24(dir, ".git"))) {
23815
23889
  throw new Error(
23816
23890
  `local mirror ${dir} is missing or not a git repo \u2014 re-run \`archme init ${entry.sourcePath}\``
23817
23891
  );
23818
23892
  }
23819
- await execa("git", ["fetch", "--no-tags", "origin", job.repo_branch], { cwd: dir, env: localGitEnv(), reject: false });
23820
- if (job.source_mode === "pr_update") {
23821
- await verifyLocalPrJob(job, async (args) => {
23822
- const r = await execa("git", args, { cwd: dir, env: localGitEnv(), reject: false });
23823
- return { exitCode: r.exitCode ?? 1, stdout: String(r.stdout ?? ""), stderr: String(r.stderr ?? "") };
23893
+ if (job.source_mode !== "pr_update") {
23894
+ branchTip = await fetchBranchTip(dir, job.repo_branch, localGitEnv()).catch(async (err4) => {
23895
+ const tracked = await execa("git", ["rev-parse", "--verify", `refs/remotes/origin/${job.repo_branch}^{commit}`], { cwd: dir, env: localGitEnv(), reject: false });
23896
+ if (tracked.exitCode !== 0) throw err4;
23897
+ console.warn(`[${job.id}] ${err4.message}; using ${job.repo_branch} as last fetched`);
23898
+ return String(tracked.stdout).trim();
23824
23899
  });
23825
23900
  return;
23826
23901
  }
23827
- const afterCheck = await execa("git", ["cat-file", "-e", job.after_sha], { cwd: dir, env: localGitEnv(), reject: false });
23828
- if (afterCheck.exitCode !== 0) {
23829
- await execa("git", ["fetch", "origin"], { cwd: dir, env: localGitEnv(), reject: false });
23830
- }
23902
+ await execa("git", ["fetch", "--no-tags", "origin", job.repo_branch], { cwd: dir, env: localGitEnv(), reject: false });
23903
+ await verifyLocalPrJob(job, async (args) => {
23904
+ const r = await execa("git", args, { cwd: dir, env: localGitEnv(), reject: false });
23905
+ return { exitCode: r.exitCode ?? 1, stdout: String(r.stdout ?? ""), stderr: String(r.stderr ?? "") };
23906
+ });
23831
23907
  }).catch((err4) => {
23832
23908
  if (err4 instanceof LocalPrJobRejectedError) throw err4;
23833
23909
  const msg = err4 instanceof Error ? err4.message : String(err4);
23834
23910
  throw new Error(`local repo ${job.repo_owner}/${job.repo_name} is not usable: ${msg}`);
23835
23911
  });
23836
23912
  return { dir, gitEnv: localGitEnv(), cleanupGitEnv: async () => {
23837
- } };
23913
+ }, branchTip };
23838
23914
  }
23839
23915
  async function ensureCloneAndFetch(ctx, job, claimDeviceId) {
23840
23916
  const localEntry = findLocalRepoForJob(await loadLocalRepos(), job);
@@ -23846,6 +23922,7 @@ async function ensureCloneAndFetch(ctx, job, claimDeviceId) {
23846
23922
  await mkdir17(ctx.cloneBaseDir, { recursive: true });
23847
23923
  const dir = cloneDirFor(ctx.cloneBaseDir, job.repo_owner, job.repo_name);
23848
23924
  const { env, cleanup: cleanupGitEnv } = await buildGitEnv(credentials);
23925
+ let branchTip = null;
23849
23926
  await cloneMutex.runExclusive(dir, async () => {
23850
23927
  if (!await exists(join24(dir, ".git"))) {
23851
23928
  await mkdir17(join24(ctx.cloneBaseDir, job.repo_owner), { recursive: true });
@@ -23854,16 +23931,20 @@ async function ensureCloneAndFetch(ctx, job, claimDeviceId) {
23854
23931
  } else {
23855
23932
  await execa("git", ["remote", "set-url", "origin", credentials.https_url], { cwd: dir, env, reject: false });
23856
23933
  }
23934
+ if (job.source_mode !== "pr_update") {
23935
+ branchTip = await fetchBranchTip(dir, job.repo_branch, env);
23936
+ return;
23937
+ }
23857
23938
  await execa("git", ["fetch", "origin", job.repo_branch], { cwd: dir, env, reject: false });
23858
23939
  let afterCheck = await execa("git", ["cat-file", "-e", job.after_sha], { cwd: dir, reject: false });
23859
- if (afterCheck.exitCode !== 0 && job.source_mode === "pr_update" && job.pr_number) {
23940
+ if (afterCheck.exitCode !== 0 && job.pr_number) {
23860
23941
  await execa("git", ["fetch", "origin", `pull/${job.pr_number}/head`], { cwd: dir, env, reject: false });
23861
23942
  afterCheck = await execa("git", ["cat-file", "-e", job.after_sha], { cwd: dir, reject: false });
23862
23943
  }
23863
23944
  if (afterCheck.exitCode !== 0) {
23864
23945
  await execa("git", ["fetch", "origin"], { cwd: dir, env, reject: false });
23865
23946
  }
23866
- if (job.source_mode === "pr_update" && job.before_sha) {
23947
+ if (job.before_sha) {
23867
23948
  const baseCheck = await execa("git", ["cat-file", "-e", job.before_sha], { cwd: dir, reject: false });
23868
23949
  if (baseCheck.exitCode !== 0) {
23869
23950
  await execa("git", ["fetch", "origin", job.before_sha], { cwd: dir, env, reject: false });
@@ -23874,7 +23955,7 @@ async function ensureCloneAndFetch(ctx, job, claimDeviceId) {
23874
23955
  const msg = err4 instanceof Error ? err4.message : String(err4);
23875
23956
  throw new Error(`GitHub App cannot access ${job.repo_owner}/${job.repo_name}: ${msg}`);
23876
23957
  });
23877
- return { dir, gitEnv: env, cleanupGitEnv };
23958
+ return { dir, gitEnv: env, cleanupGitEnv, branchTip };
23878
23959
  }
23879
23960
  function checkoutGitEnv(jobDir) {
23880
23961
  const env = {
@@ -23916,6 +23997,12 @@ async function createJobWorktree(repoDir, job) {
23916
23997
  }
23917
23998
  };
23918
23999
  }
24000
+ function isDiffSkip(r) {
24001
+ return r === "skip" || r === "off_branch";
24002
+ }
24003
+ function diffSkipSummary(skip, branch) {
24004
+ return skip === "off_branch" ? `Commit is no longer on ${branch} (a force push removed it); skipped.` : "Push is behind the last reflected commit; skipped.";
24005
+ }
23919
24006
  function noUsableBaseError(branch, markerSha, detail) {
23920
24007
  return new Error(
23921
24008
  `no usable diff base for ${branch} (marker ${markerSha ?? "none"}): run a manual scan or admin replay \u2014 ${detail}`
@@ -23945,6 +24032,9 @@ async function forcePushProvenance(repoDir, base, after) {
23945
24032
  const forkNote = fork.trim() ? ` (history diverged at \`${fork.trim().slice(0, 8)}\`)` : "";
23946
24033
  return `Force push: the branch tip was rewritten${forkNote}. The diff below is the exact net delta from the last reflected commit \`${base.slice(0, 8)}\` to the new tip \`${after.slice(0, 8)}\`, computed tree-to-tree \u2014 the rewrite does not affect it.`;
23947
24034
  }
24035
+ function resetProvenance(base, after) {
24036
+ return `Branch reset: the branch was moved back to \`${after.slice(0, 8)}\`, dropping the commits after it up to \`${base.slice(0, 8)}\`, the last commit this board reflects. The diff below is the exact net removal of those commits, computed tree-to-tree.`;
24037
+ }
23948
24038
  function isGitSha(v) {
23949
24039
  return typeof v === "string" && GIT_SHA_RE.test(v);
23950
24040
  }
@@ -23953,23 +24043,28 @@ function assertGitSha(v, field) {
23953
24043
  throw new Error(`${field} ${v ?? "(null)"} is not a 40-character git SHA`);
23954
24044
  }
23955
24045
  }
23956
- async function computeDiff(job, repoDir, marker, gitEnv) {
24046
+ async function computeDiff(job, repoDir, marker, branchTip, gitEnv) {
23957
24047
  assertGitSha(job.after_sha, "after_sha");
23958
- if (!await isShaReachable(repoDir, job.after_sha)) {
23959
- throw new Error(`after_sha ${job.after_sha} is not reachable after fetch`);
23960
- }
23961
24048
  const after = job.after_sha;
23962
24049
  if (job.source_mode === "pr_update") {
24050
+ if (!await isShaReachable(repoDir, after)) {
24051
+ throw new Error(`after_sha ${after} is not reachable after fetch`);
24052
+ }
23963
24053
  if (!job.before_sha) throw noUsableBaseError(job.archme_branch, marker.sha, "PR job has no before_sha");
23964
24054
  if (!await isShaReachable(repoDir, job.before_sha)) {
23965
24055
  throw noUsableBaseError(job.archme_branch, marker.sha, `PR base ${job.before_sha.slice(0, 8)} is unreachable after fetch`);
23966
24056
  }
23967
- const { stdout, exitCode: exitCode2 } = await execa("git", ["merge-base", job.before_sha, after], { cwd: repoDir, reject: false });
23968
- if (exitCode2 !== 0 || !stdout.trim()) {
24057
+ const { stdout, exitCode } = await execa("git", ["merge-base", job.before_sha, after], { cwd: repoDir, reject: false });
24058
+ if (exitCode !== 0 || !stdout.trim()) {
23969
24059
  throw noUsableBaseError(job.archme_branch, marker.sha, `no merge-base between ${job.before_sha.slice(0, 8)} and ${after.slice(0, 8)}`);
23970
24060
  }
23971
24061
  return buildDiffPayload(repoDir, stdout.trim(), after);
23972
24062
  }
24063
+ if (!isGitSha(branchTip)) {
24064
+ throw new Error(`no fetched tip of ${job.repo_branch} to check ${after.slice(0, 8)} against`);
24065
+ }
24066
+ const onBranch = await isShaReachable(repoDir, after) && (await execa("git", ["merge-base", "--is-ancestor", after, branchTip], { cwd: repoDir, reject: false })).exitCode === 0;
24067
+ if (!onBranch) return "off_branch";
23973
24068
  if (!marker.sha) {
23974
24069
  throw noUsableBaseError(job.archme_branch, null, "no architecture marker for this branch (first scan hasn't established one)");
23975
24070
  }
@@ -23984,9 +24079,16 @@ async function computeDiff(job, repoDir, marker, gitEnv) {
23984
24079
  throw noUsableBaseError(job.archme_branch, base, "marker commit is unreachable after fetch-by-SHA (GC'd or a different clone)");
23985
24080
  }
23986
24081
  }
23987
- const { exitCode } = await execa("git", ["merge-base", "--is-ancestor", after, base], { cwd: repoDir, reject: false });
23988
- if (exitCode === 0) return "skip";
23989
24082
  const before = job.before_sha?.toLowerCase();
24083
+ const isAncestor2 = async (a2, b) => (await execa("git", ["merge-base", "--is-ancestor", a2, b], { cwd: repoDir, reject: false })).exitCode === 0;
24084
+ if (await isAncestor2(after, base)) {
24085
+ const fromMarker = !!before && (before === base.toLowerCase() || before === marker.rolledUpThrough?.toLowerCase());
24086
+ const resetsBoard = (job.forced || fromMarker) && !await isAncestor2(base, branchTip);
24087
+ if (!resetsBoard) return "skip";
24088
+ const payload2 = await buildDiffPayload(repoDir, base, after);
24089
+ payload2.provenance = resetProvenance(base, after);
24090
+ return payload2;
24091
+ }
23990
24092
  if (!job.forced && before && before !== base.toLowerCase() && before !== marker.rolledUpThrough?.toLowerCase()) {
23991
24093
  throw new Error(
23992
24094
  `commit ${after.slice(0, 8)} does not follow ${base.slice(0, 8)}, the last commit this board reflects for ${job.repo_owner}/${job.repo_name}: a commit between them has no architecture update. Requeue it, or roll it up into the next one.`
@@ -24161,7 +24263,9 @@ async function rpcComplete(ctx, jobId, deviceId, summary2, kind, changed, metric
24161
24263
  // `kind` drives lifecycle (squash, marker, retry). `changed` is the
24162
24264
  // decoupled what-changed verdict the Check Run / sticky comment render
24163
24265
  // (migration 083): a structural-only job is kind=applied but changed=false.
24164
- result: { summary: summary2, kind, changed },
24266
+ // `marker_kept`: this job landed nothing, so local watch may run its
24267
+ // commit again (`countUnlandedRuns`).
24268
+ result: { summary: summary2, kind, changed, ...advanceMarker ? {} : { marker_kept: true } },
24165
24269
  metrics,
24166
24270
  logs,
24167
24271
  advance_marker: advanceMarker
@@ -24867,12 +24971,13 @@ async function runJob(ctx, job, claimDeviceId) {
24867
24971
  const sandboxMetrics = outcome.metrics.sandbox;
24868
24972
  try {
24869
24973
  if (outcome.kind === "skip") {
24870
- log(`after_sha is already at or behind the clean marker \u2014 completing no_op without advancing the marker`);
24974
+ const summary2 = diffSkipSummary(outcome.skip, job.repo_branch);
24975
+ log(`${summary2} Completing no_op without advancing the marker.`);
24871
24976
  await rpcComplete(
24872
24977
  ctx,
24873
24978
  job.id,
24874
24979
  deviceId,
24875
- "Push is behind the last reflected commit; skipped.",
24980
+ summary2,
24876
24981
  "no_op",
24877
24982
  false,
24878
24983
  { mode: "skip", sandbox: sandboxMetrics, durations_ms: timings },
@@ -25076,20 +25181,21 @@ async function runJob(ctx, job, claimDeviceId) {
25076
25181
  );
25077
25182
  return;
25078
25183
  }
25079
- const { dir: repoDir, gitEnv, cleanupGitEnv } = clone;
25184
+ const { dir: repoDir, gitEnv, cleanupGitEnv, branchTip } = clone;
25080
25185
  cleanupFns.push(cleanupGitEnv);
25081
25186
  activeCleanups.add(cleanupGitEnv);
25082
25187
  markPhase("clone_fetch");
25083
25188
  const marker = job.source_mode === "pr_update" ? { sha: null, repo: null } : await readBranchMarker(ctx.supabase, job.project_id, job.archme_branch, `${job.repo_owner}/${job.repo_name}`);
25084
- const diffResult = await computeDiff(job, repoDir, marker, gitEnv);
25085
- if (diffResult === "skip") {
25086
- log(`after_sha is already at or behind the clean marker \u2014 completing no_op without advancing the marker`);
25189
+ const diffResult = await computeDiff(job, repoDir, marker, branchTip, gitEnv);
25190
+ if (isDiffSkip(diffResult)) {
25191
+ const summary2 = diffSkipSummary(diffResult, job.repo_branch);
25192
+ log(`${summary2} Completing no_op without advancing the marker.`);
25087
25193
  markPhase("diff", { mode: "skip" });
25088
25194
  await rpcComplete(
25089
25195
  ctx,
25090
25196
  job.id,
25091
25197
  deviceId,
25092
- "Push is behind the last reflected commit; skipped.",
25198
+ summary2,
25093
25199
  "no_op",
25094
25200
  false,
25095
25201
  { mode: "skip", durations_ms: timings },
@@ -27664,7 +27770,7 @@ async function runLocalWatchResume(slug, deps = {}) {
27664
27770
  const stillTerminal = halted.some((m) => m.haltCode === "job-terminal");
27665
27771
  if (stillTerminal) {
27666
27772
  console.log(
27667
- "\nNote: at least one of these stopped because a job failed outright. Resuming\ndoes not re-run a failed job \u2014 local watch will stop again on the next tick.\nThat failure is visible to the ArchMe team; get in touch if it is blocking you."
27773
+ "\nNote: at least one of these stopped because a job failed outright. Resuming\ndoes not re-run a failed job \u2014 local watch will stop again on the next tick.\nPress Retry on that commit in the board's History tab; local watch carries on\nby itself once it completes (if it doesn't, run this command again)."
27668
27774
  );
27669
27775
  } else {
27670
27776
  console.log("\nLocal watch resumes from the recorded commit on the next tick.");
@@ -30160,7 +30266,7 @@ ${project}
30160
30266
 
30161
30267
  ${access}
30162
30268
 
30163
- 4. **Ask whether to review pull requests** too (\`--prs\` or \`--no-prs\`): each push to a PR is one Claude run on their subscription.${opts.githubAppAllowed ? " With local watch, a private repo's PRs need `gh auth login`, and PRs from forks are never reviewed." : " A private repo's PRs need `gh auth login`, and PRs from forks are never reviewed."}
30269
+ 4. **Ask whether to review pull requests** too (\`--prs\` or \`--no-prs\`): each PR's first review is one Claude run on their subscription, and later pushes run only when someone presses Update on the PR.${opts.githubAppAllowed ? " With local watch, a private repo's PRs need `gh auth login`, and PRs from forks are never reviewed." : " A private repo's PRs need `gh auth login`, and PRs from forks are never reviewed."}
30164
30270
 
30165
30271
  ## 5. Hand off
30166
30272
 
@@ -32659,8 +32765,9 @@ Options:
32659
32765
  --project <org/slug> Project to write to (default: derived from the repo name)
32660
32766
  --branch <name> Branch to track (default: the repo's default branch)
32661
32767
  --yes Don't ask for confirmation (needs an explicit repo-path)
32662
- --prs / --no-prs Also review pull requests (each PR push is one Claude run;
32663
- a private repo needs gh auth login)
32768
+ --prs / --no-prs Also review pull requests (a PR's first review is one Claude
32769
+ run, later pushes wait for Update in the app; a private
32770
+ repo needs gh auth login)
32664
32771
 
32665
32772
  Watching queues work; a local daemon does it. After registering: archme daemon start`);
32666
32773
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archme/cli",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "Map your codebase into a living architecture diagram: run `archme init` in a repo to scan it, `archme daemon start` to keep it current on every commit.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "image": "ghcr.io/architectme/archme-job",
3
- "digest": "sha256:eba064bd85a35bf697038defe2bfcadad4c508bc810ef552431344760874e061"
3
+ "digest": "sha256:038dc5478f7d8747821037c0995fe7e8a58bf00b99a4e26d76129cd1f3e70da5"
4
4
  }