pantheon-cli 0.2.73 → 0.2.77

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.
Files changed (2) hide show
  1. package/dist/pantheon.mjs +125 -12
  2. package/package.json +1 -1
package/dist/pantheon.mjs CHANGED
@@ -43701,6 +43701,7 @@ import { gzipSync } from "node:zlib";
43701
43701
  var DRIVE_MAX_FILE_BYTES = 200 * 1024 * 1024;
43702
43702
  var DRIVE_MAX_CHANGE_BYTES = 256 * 1024 * 1024;
43703
43703
  var DRIVE_MAX_CHANGES = 100;
43704
+ var DRIVE_MAX_REQUEST_BYTES = 4 * 1024 * 1024;
43704
43705
  var CONTROL_NAMES = /* @__PURE__ */ new Set([
43705
43706
  ".git",
43706
43707
  ".pantheon",
@@ -43757,7 +43758,8 @@ function driveWorkspaceStatePaths(home) {
43757
43758
  return {
43758
43759
  ledger: `${base}.pantheon-sync.json`,
43759
43760
  outbox: `${base}.pantheon-outbox.json`,
43760
- conflicts: `${base}.pantheon-conflicts`
43761
+ conflicts: `${base}.pantheon-conflicts`,
43762
+ skipped: `${base}.pantheon-skipped.json`
43761
43763
  };
43762
43764
  }
43763
43765
  function writeJsonAtomic(path, value) {
@@ -43781,6 +43783,39 @@ function readJsonSafe(path) {
43781
43783
  function writeLedger(path, vaultId, manifest) {
43782
43784
  writeJsonAtomic(path, { ...manifest, vaultId });
43783
43785
  }
43786
+ function updateSkippedLedger(home, vaultId, attempted, deleted, skipped) {
43787
+ const path = driveWorkspaceStatePaths(home).skipped;
43788
+ const previous = readJsonSafe(path);
43789
+ const entries = previous?.vaultId === vaultId ? { ...previous.entries } : {};
43790
+ for (const [key, entry] of Object.entries(entries)) {
43791
+ const file = join7(home, ...key.split("/"));
43792
+ if (!existsSync7(file) || !lstatSync2(file).isFile() || readFileSync6(file).length !== entry.size || sha256(readFileSync6(file)) !== entry.sha256) {
43793
+ delete entries[key];
43794
+ }
43795
+ }
43796
+ for (const change of attempted) delete entries[change.path];
43797
+ for (const deletedPath of deleted) delete entries[deletedPath];
43798
+ const byPath = new Map(attempted.map((change) => [change.path, change]));
43799
+ for (const item of skipped) {
43800
+ const change = byPath.get(item.path);
43801
+ if (!change) continue;
43802
+ entries[item.path] = {
43803
+ path: item.path,
43804
+ sha256: change.sha256,
43805
+ size: change.size,
43806
+ reason: item.reason
43807
+ };
43808
+ }
43809
+ if (Object.keys(entries).length) {
43810
+ writeJsonAtomic(path, {
43811
+ version: 1,
43812
+ vaultId,
43813
+ entries
43814
+ });
43815
+ } else {
43816
+ rmSync5(path, { force: true });
43817
+ }
43818
+ }
43784
43819
  function quarantineUnownedDriveWorkspace(home, vaultId, now = /* @__PURE__ */ new Date()) {
43785
43820
  const paths = driveWorkspaceStatePaths(home);
43786
43821
  const ledger = readJsonSafe(paths.ledger);
@@ -43799,6 +43834,7 @@ function quarantineUnownedDriveWorkspace(home, vaultId, now = /* @__PURE__ */ ne
43799
43834
  if (ledger?.vaultId !== vaultId) {
43800
43835
  rmSync5(paths.ledger, { force: true });
43801
43836
  rmSync5(paths.outbox, { force: true });
43837
+ rmSync5(paths.skipped, { force: true });
43802
43838
  }
43803
43839
  return quarantined;
43804
43840
  }
@@ -43837,9 +43873,13 @@ function scanDriveWorkspace(home) {
43837
43873
  }
43838
43874
  function diffDriveManifest(home, manifest) {
43839
43875
  const local = scanDriveWorkspace(home);
43876
+ const skipped = readJsonSafe(driveWorkspaceStatePaths(home).skipped)?.entries ?? {};
43840
43877
  const changes = [];
43841
43878
  let total = 0;
43842
43879
  for (const [path, entry] of Object.entries(local)) {
43880
+ if (skipped[path]?.sha256 === entry.sha256 && skipped[path]?.size === entry.size) {
43881
+ continue;
43882
+ }
43843
43883
  if (manifest.entries[path]?.sha256 === entry.sha256 && manifest.entries[path]?.size === entry.size) {
43844
43884
  continue;
43845
43885
  }
@@ -43891,17 +43931,66 @@ async function responseError(response) {
43891
43931
  );
43892
43932
  }
43893
43933
  async function publishOutbox(config2, credentials, outbox, fetcher) {
43894
- const response = await fetcher(`${config2.apiUrl}/api/cli/workspace/sync`, {
43895
- method: "POST",
43896
- headers: {
43897
- ...auth(config2, credentials),
43898
- "content-type": "application/json"
43899
- },
43900
- body: JSON.stringify(outbox),
43901
- signal: AbortSignal.timeout(3e4)
43902
- });
43903
- if (!response.ok) throw await responseError(response);
43904
- return await response.json();
43934
+ const requestBudget = DRIVE_MAX_REQUEST_BYTES - 128 * 1024;
43935
+ const groups = [];
43936
+ const skipped = [];
43937
+ let group = [];
43938
+ let groupBytes = 0;
43939
+ for (const change of outbox.changes) {
43940
+ const bytes = Buffer.byteLength(JSON.stringify(change)) + 1;
43941
+ if (bytes > requestBudget) {
43942
+ skipped.push({
43943
+ path: change.path,
43944
+ reason: `${(change.size / 1024 / 1024).toFixed(1)} MB cannot fit safely in one hosted Drive request. The file remains on this machine; the rest of the handoff was saved.`
43945
+ });
43946
+ continue;
43947
+ }
43948
+ if (group.length && groupBytes + bytes > requestBudget) {
43949
+ groups.push(group);
43950
+ group = [];
43951
+ groupBytes = 0;
43952
+ }
43953
+ group.push(change);
43954
+ groupBytes += bytes;
43955
+ }
43956
+ if (group.length || !groups.length) groups.push(group);
43957
+ let baseRevision = outbox.baseRevision;
43958
+ let published;
43959
+ let merged = false;
43960
+ for (let index = 0; index < groups.length; index += 1) {
43961
+ const requestId = groups.length === 1 ? outbox.requestId : `${outbox.requestId}.${index + 1}.${groups.length}`;
43962
+ const batch = {
43963
+ ...outbox,
43964
+ requestId,
43965
+ baseRevision,
43966
+ changes: groups[index],
43967
+ deletes: index === groups.length - 1 ? outbox.deletes : [],
43968
+ message: groups.length === 1 ? outbox.message : `${outbox.message || "Sync Pantheon vault"} (${index + 1}/${groups.length})`
43969
+ };
43970
+ const body = JSON.stringify(batch);
43971
+ if (Buffer.byteLength(body) > DRIVE_MAX_REQUEST_BYTES) {
43972
+ throw new Error("Drive sync batch exceeds the request limit.");
43973
+ }
43974
+ const response = await fetcher(`${config2.apiUrl}/api/cli/workspace/sync`, {
43975
+ method: "POST",
43976
+ headers: {
43977
+ ...auth(config2, credentials),
43978
+ "content-type": "application/json"
43979
+ },
43980
+ body,
43981
+ signal: AbortSignal.timeout(3e4)
43982
+ });
43983
+ if (!response.ok) throw await responseError(response);
43984
+ published = await response.json();
43985
+ baseRevision = published.revision;
43986
+ merged ||= Boolean(published.merged);
43987
+ }
43988
+ if (!published) throw new Error("Drive sync did not publish any batches.");
43989
+ return {
43990
+ ...published,
43991
+ ...merged ? { merged: true } : {},
43992
+ ...skipped.length ? { skipped } : {}
43993
+ };
43905
43994
  }
43906
43995
  function httpDriveWorkspaceHooks(config2, credentials, fetcher = fetch) {
43907
43996
  const paths = driveWorkspaceStatePaths(config2.home);
@@ -43919,6 +44008,12 @@ function httpDriveWorkspaceHooks(config2, credentials, fetcher = fetch) {
43919
44008
  return manifest;
43920
44009
  }
43921
44010
  async function applyManifest(home, manifest, protectedPaths = /* @__PURE__ */ new Set()) {
44011
+ const locallySkipped = readJsonSafe(paths.skipped);
44012
+ if (locallySkipped?.vaultId === config2.vaultId) {
44013
+ for (const path of Object.keys(locallySkipped.entries)) {
44014
+ protectedPaths.add(path);
44015
+ }
44016
+ }
43922
44017
  const staged = [];
43923
44018
  const previous = readJsonSafe(paths.ledger);
43924
44019
  mkdirSync6(home, { recursive: true });
@@ -44032,6 +44127,14 @@ function httpDriveWorkspaceHooks(config2, credentials, fetcher = fetch) {
44032
44127
  fetcher
44033
44128
  );
44034
44129
  writeLedger(paths.ledger, config2.vaultId, published.manifest);
44130
+ updateSkippedLedger(
44131
+ home,
44132
+ config2.vaultId,
44133
+ currentPending.changes,
44134
+ currentPending.deletes,
44135
+ published.skipped ?? []
44136
+ );
44137
+ result.skipped = published.skipped;
44035
44138
  rmSync5(paths.outbox, { force: true });
44036
44139
  pending = null;
44037
44140
  } catch (error2) {
@@ -44098,12 +44201,20 @@ function httpDriveWorkspaceHooks(config2, credentials, fetcher = fetch) {
44098
44201
  }
44099
44202
  const published = await publishOutbox(config2, credentials, outbox, fetcher);
44100
44203
  writeLedger(paths.ledger, config2.vaultId, published.manifest);
44204
+ updateSkippedLedger(
44205
+ home,
44206
+ config2.vaultId,
44207
+ outbox.changes,
44208
+ outbox.deletes,
44209
+ published.skipped ?? []
44210
+ );
44101
44211
  rmSync5(paths.outbox, { force: true });
44102
44212
  result.ok = true;
44103
44213
  result.changed = true;
44104
44214
  result.committed = true;
44105
44215
  result.pushed = true;
44106
44216
  result.revision = { id: published.revision };
44217
+ result.skipped = published.skipped;
44107
44218
  return result;
44108
44219
  } catch (error2) {
44109
44220
  if (outbox && error2 instanceof DriveWorkspaceHttpError && error2.status === 409) {
@@ -45023,6 +45134,7 @@ ${GUIDE}` }]
45023
45134
  ok: sync2.ok !== false,
45024
45135
  ...written,
45025
45136
  sync: sync2,
45137
+ storageSkipped: sync2.skipped ?? [],
45026
45138
  skillReview: review,
45027
45139
  skillReviewAction: !shouldReview ? null : {
45028
45140
  requiresAgentJudgment: true,
@@ -45041,6 +45153,7 @@ ${GUIDE}` }]
45041
45153
  // many there were as well as which ones, because the list is
45042
45154
  // capped and reporting its length as the total is a lie.
45043
45155
  written.skipped?.length ? `Not stored: ${written.skippedTotal} file${written.skippedTotal === 1 ? "" : "s"}${written.skippedTotal > written.skipped.length ? `, of which these ${written.skipped.length}` : ""} \u2014 ${written.skipped.map((file) => `${file.name} (${file.reason})`).join(", ")}. Report the total, not just the named ones, so the human knows what the space does not hold.` : null,
45156
+ sync2.skipped?.length ? `Drive skipped ${sync2.skipped.length} oversized file${sync2.skipped.length === 1 ? "" : "s"} without blocking the handoff: ${sync2.skipped.map((file) => `${file.path} (${file.reason})`).join(", ")}. Clearly tell the human which files remain local.` : null,
45044
45157
  shouldReview ? review ? AUTO_SKILL_REVIEW : `The post-handoff skill review could not run. Call pantheon_skill_review for "${written.slug}" and continue without asking permission.` : null
45045
45158
  ].filter(Boolean).join(" ")
45046
45159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.2.73",
3
+ "version": "0.2.77",
4
4
  "description": "Carry agent conscience between AI coding agents. Hand off a conversation in one agent, resume it in another.",
5
5
  "license": "MIT",
6
6
  "type": "module",