pantheon-cli 0.2.64 → 0.2.69

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 +1060 -281
  2. package/package.json +2 -1
package/dist/pantheon.mjs CHANGED
@@ -2992,7 +2992,7 @@ var require_compile = __commonJS({
2992
2992
  const schOrFunc = root.refs[ref];
2993
2993
  if (schOrFunc)
2994
2994
  return schOrFunc;
2995
- let _sch = resolve4.call(this, root, ref);
2995
+ let _sch = resolve5.call(this, root, ref);
2996
2996
  if (_sch === void 0) {
2997
2997
  const schema = (_a2 = root.localRefs) === null || _a2 === void 0 ? void 0 : _a2[ref];
2998
2998
  const { schemaId } = this.opts;
@@ -3019,7 +3019,7 @@ var require_compile = __commonJS({
3019
3019
  function sameSchemaEnv(s1, s2) {
3020
3020
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
3021
3021
  }
3022
- function resolve4(root, ref) {
3022
+ function resolve5(root, ref) {
3023
3023
  let sch;
3024
3024
  while (typeof (sch = this.refs[ref]) == "string")
3025
3025
  ref = sch;
@@ -3650,7 +3650,7 @@ var require_fast_uri = __commonJS({
3650
3650
  }
3651
3651
  return uri;
3652
3652
  }
3653
- function resolve4(baseURI, relativeURI, options) {
3653
+ function resolve5(baseURI, relativeURI, options) {
3654
3654
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
3655
3655
  const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed } = parseWithStatus(baseURI, schemelessOptions);
3656
3656
  const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed } = parseWithStatus(relativeURI, schemelessOptions);
@@ -3661,49 +3661,49 @@ var require_fast_uri = __commonJS({
3661
3661
  schemelessOptions.skipEscape = true;
3662
3662
  return serialize2(resolved, schemelessOptions);
3663
3663
  }
3664
- function resolveComponent(base, relative3, options, skipNormalization) {
3664
+ function resolveComponent(base, relative4, options, skipNormalization) {
3665
3665
  const target = {};
3666
3666
  if (!skipNormalization) {
3667
3667
  base = parse4(serialize2(base, options), options);
3668
- relative3 = parse4(serialize2(relative3, options), options);
3668
+ relative4 = parse4(serialize2(relative4, options), options);
3669
3669
  }
3670
3670
  options = options || {};
3671
- if (!options.tolerant && relative3.scheme) {
3672
- target.scheme = relative3.scheme;
3673
- target.userinfo = relative3.userinfo;
3674
- target.host = relative3.host;
3675
- target.port = relative3.port;
3676
- target.path = removeDotSegments(relative3.path || "");
3677
- target.query = relative3.query;
3671
+ if (!options.tolerant && relative4.scheme) {
3672
+ target.scheme = relative4.scheme;
3673
+ target.userinfo = relative4.userinfo;
3674
+ target.host = relative4.host;
3675
+ target.port = relative4.port;
3676
+ target.path = removeDotSegments(relative4.path || "");
3677
+ target.query = relative4.query;
3678
3678
  } else {
3679
- if (relative3.userinfo !== void 0 || relative3.host !== void 0 || relative3.port !== void 0) {
3680
- target.userinfo = relative3.userinfo;
3681
- target.host = relative3.host;
3682
- target.port = relative3.port;
3683
- target.path = removeDotSegments(relative3.path || "");
3684
- target.query = relative3.query;
3679
+ if (relative4.userinfo !== void 0 || relative4.host !== void 0 || relative4.port !== void 0) {
3680
+ target.userinfo = relative4.userinfo;
3681
+ target.host = relative4.host;
3682
+ target.port = relative4.port;
3683
+ target.path = removeDotSegments(relative4.path || "");
3684
+ target.query = relative4.query;
3685
3685
  } else {
3686
- if (!relative3.path) {
3686
+ if (!relative4.path) {
3687
3687
  target.path = base.path;
3688
- if (relative3.query !== void 0) {
3689
- target.query = relative3.query;
3688
+ if (relative4.query !== void 0) {
3689
+ target.query = relative4.query;
3690
3690
  } else {
3691
3691
  target.query = base.query;
3692
3692
  }
3693
3693
  } else {
3694
- if (relative3.path[0] === "/") {
3695
- target.path = removeDotSegments(relative3.path);
3694
+ if (relative4.path[0] === "/") {
3695
+ target.path = removeDotSegments(relative4.path);
3696
3696
  } else {
3697
3697
  if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
3698
- target.path = "/" + relative3.path;
3698
+ target.path = "/" + relative4.path;
3699
3699
  } else if (!base.path) {
3700
- target.path = relative3.path;
3700
+ target.path = relative4.path;
3701
3701
  } else {
3702
- target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative3.path;
3702
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative4.path;
3703
3703
  }
3704
3704
  target.path = removeDotSegments(target.path);
3705
3705
  }
3706
- target.query = relative3.query;
3706
+ target.query = relative4.query;
3707
3707
  }
3708
3708
  target.userinfo = base.userinfo;
3709
3709
  target.host = base.host;
@@ -3711,7 +3711,7 @@ var require_fast_uri = __commonJS({
3711
3711
  }
3712
3712
  target.scheme = base.scheme;
3713
3713
  }
3714
- target.fragment = relative3.fragment;
3714
+ target.fragment = relative4.fragment;
3715
3715
  return target;
3716
3716
  }
3717
3717
  function equal(uriA, uriB, options) {
@@ -3934,7 +3934,7 @@ var require_fast_uri = __commonJS({
3934
3934
  var fastUri = {
3935
3935
  SCHEMES,
3936
3936
  normalize,
3937
- resolve: resolve4,
3937
+ resolve: resolve5,
3938
3938
  resolveComponent,
3939
3939
  equal,
3940
3940
  serialize: serialize2,
@@ -8851,9 +8851,9 @@ var require_dispatcher_base = __commonJS({
8851
8851
  }
8852
8852
  close(callback) {
8853
8853
  if (callback === void 0) {
8854
- return new Promise((resolve4, reject) => {
8854
+ return new Promise((resolve5, reject) => {
8855
8855
  this.close((err2, data) => {
8856
- return err2 ? reject(err2) : resolve4(data);
8856
+ return err2 ? reject(err2) : resolve5(data);
8857
8857
  });
8858
8858
  });
8859
8859
  }
@@ -8891,12 +8891,12 @@ var require_dispatcher_base = __commonJS({
8891
8891
  err2 = null;
8892
8892
  }
8893
8893
  if (callback === void 0) {
8894
- return new Promise((resolve4, reject) => {
8894
+ return new Promise((resolve5, reject) => {
8895
8895
  this.destroy(err2, (err3, data) => {
8896
8896
  return err3 ? (
8897
8897
  /* istanbul ignore next: should never error */
8898
8898
  reject(err3)
8899
- ) : resolve4(data);
8899
+ ) : resolve5(data);
8900
8900
  });
8901
8901
  });
8902
8902
  }
@@ -11163,8 +11163,8 @@ var require_util3 = __commonJS({
11163
11163
  function createDeferredPromise() {
11164
11164
  let res;
11165
11165
  let rej;
11166
- const promise = new Promise((resolve4, reject) => {
11167
- res = resolve4;
11166
+ const promise = new Promise((resolve5, reject) => {
11167
+ res = resolve5;
11168
11168
  rej = reject;
11169
11169
  });
11170
11170
  return { promise, resolve: res, reject: rej };
@@ -13410,12 +13410,12 @@ upgrade: ${upgrade}\r
13410
13410
  cb();
13411
13411
  }
13412
13412
  }
13413
- const waitForDrain = () => new Promise((resolve4, reject) => {
13413
+ const waitForDrain = () => new Promise((resolve5, reject) => {
13414
13414
  assert2(callback === null);
13415
13415
  if (socket[kError]) {
13416
13416
  reject(socket[kError]);
13417
13417
  } else {
13418
- callback = resolve4;
13418
+ callback = resolve5;
13419
13419
  }
13420
13420
  });
13421
13421
  socket.on("close", onDrain).on("drain", onDrain);
@@ -14052,12 +14052,12 @@ var require_client_h2 = __commonJS({
14052
14052
  cb();
14053
14053
  }
14054
14054
  }
14055
- const waitForDrain = () => new Promise((resolve4, reject) => {
14055
+ const waitForDrain = () => new Promise((resolve5, reject) => {
14056
14056
  assert2(callback === null);
14057
14057
  if (socket[kError]) {
14058
14058
  reject(socket[kError]);
14059
14059
  } else {
14060
- callback = resolve4;
14060
+ callback = resolve5;
14061
14061
  }
14062
14062
  });
14063
14063
  h2stream.on("close", onDrain).on("drain", onDrain);
@@ -14535,16 +14535,16 @@ var require_client = __commonJS({
14535
14535
  return this[kNeedDrain] < 2;
14536
14536
  }
14537
14537
  async [kClose]() {
14538
- return new Promise((resolve4) => {
14538
+ return new Promise((resolve5) => {
14539
14539
  if (this[kSize]) {
14540
- this[kClosedResolve] = resolve4;
14540
+ this[kClosedResolve] = resolve5;
14541
14541
  } else {
14542
- resolve4(null);
14542
+ resolve5(null);
14543
14543
  }
14544
14544
  });
14545
14545
  }
14546
14546
  async [kDestroy](err2) {
14547
- return new Promise((resolve4) => {
14547
+ return new Promise((resolve5) => {
14548
14548
  const requests = this[kQueue].splice(this[kPendingIdx]);
14549
14549
  for (let i2 = 0; i2 < requests.length; i2++) {
14550
14550
  const request = requests[i2];
@@ -14555,7 +14555,7 @@ var require_client = __commonJS({
14555
14555
  this[kClosedResolve]();
14556
14556
  this[kClosedResolve] = null;
14557
14557
  }
14558
- resolve4(null);
14558
+ resolve5(null);
14559
14559
  };
14560
14560
  if (this[kHTTPContext]) {
14561
14561
  this[kHTTPContext].destroy(err2, callback);
@@ -14606,7 +14606,7 @@ var require_client = __commonJS({
14606
14606
  });
14607
14607
  }
14608
14608
  try {
14609
- const socket = await new Promise((resolve4, reject) => {
14609
+ const socket = await new Promise((resolve5, reject) => {
14610
14610
  client[kConnector]({
14611
14611
  host,
14612
14612
  hostname: hostname4,
@@ -14618,7 +14618,7 @@ var require_client = __commonJS({
14618
14618
  if (err2) {
14619
14619
  reject(err2);
14620
14620
  } else {
14621
- resolve4(socket2);
14621
+ resolve5(socket2);
14622
14622
  }
14623
14623
  });
14624
14624
  });
@@ -14954,8 +14954,8 @@ var require_pool_base = __commonJS({
14954
14954
  if (this[kQueue].isEmpty()) {
14955
14955
  await Promise.all(this[kClients].map((c) => c.close()));
14956
14956
  } else {
14957
- await new Promise((resolve4) => {
14958
- this[kClosedResolve] = resolve4;
14957
+ await new Promise((resolve5) => {
14958
+ this[kClosedResolve] = resolve5;
14959
14959
  });
14960
14960
  }
14961
14961
  }
@@ -16198,7 +16198,7 @@ var require_readable = __commonJS({
16198
16198
  if (this._readableState.closeEmitted) {
16199
16199
  return null;
16200
16200
  }
16201
- return await new Promise((resolve4, reject) => {
16201
+ return await new Promise((resolve5, reject) => {
16202
16202
  if (this[kContentLength] > limit) {
16203
16203
  this.destroy(new AbortError());
16204
16204
  }
@@ -16211,7 +16211,7 @@ var require_readable = __commonJS({
16211
16211
  if (signal?.aborted) {
16212
16212
  reject(signal.reason ?? new AbortError());
16213
16213
  } else {
16214
- resolve4(null);
16214
+ resolve5(null);
16215
16215
  }
16216
16216
  }).on("error", noop).on("data", function(chunk) {
16217
16217
  limit -= chunk.length;
@@ -16230,7 +16230,7 @@ var require_readable = __commonJS({
16230
16230
  }
16231
16231
  async function consume(stream, type) {
16232
16232
  assert2(!stream[kConsume]);
16233
- return new Promise((resolve4, reject) => {
16233
+ return new Promise((resolve5, reject) => {
16234
16234
  if (isUnusable(stream)) {
16235
16235
  const rState = stream._readableState;
16236
16236
  if (rState.destroyed && rState.closeEmitted === false) {
@@ -16247,7 +16247,7 @@ var require_readable = __commonJS({
16247
16247
  stream[kConsume] = {
16248
16248
  type,
16249
16249
  stream,
16250
- resolve: resolve4,
16250
+ resolve: resolve5,
16251
16251
  reject,
16252
16252
  length: 0,
16253
16253
  body: []
@@ -16317,18 +16317,18 @@ var require_readable = __commonJS({
16317
16317
  return buffer;
16318
16318
  }
16319
16319
  function consumeEnd(consume2) {
16320
- const { type, body, resolve: resolve4, stream, length } = consume2;
16320
+ const { type, body, resolve: resolve5, stream, length } = consume2;
16321
16321
  try {
16322
16322
  if (type === "text") {
16323
- resolve4(chunksDecode(body, length));
16323
+ resolve5(chunksDecode(body, length));
16324
16324
  } else if (type === "json") {
16325
- resolve4(JSON.parse(chunksDecode(body, length)));
16325
+ resolve5(JSON.parse(chunksDecode(body, length)));
16326
16326
  } else if (type === "arrayBuffer") {
16327
- resolve4(chunksConcat(body, length).buffer);
16327
+ resolve5(chunksConcat(body, length).buffer);
16328
16328
  } else if (type === "blob") {
16329
- resolve4(new Blob(body, { type: stream[kContentType] }));
16329
+ resolve5(new Blob(body, { type: stream[kContentType] }));
16330
16330
  } else if (type === "bytes") {
16331
- resolve4(chunksConcat(body, length));
16331
+ resolve5(chunksConcat(body, length));
16332
16332
  }
16333
16333
  consumeFinish(consume2);
16334
16334
  } catch (err2) {
@@ -16585,9 +16585,9 @@ var require_api_request = __commonJS({
16585
16585
  };
16586
16586
  function request(opts, callback) {
16587
16587
  if (callback === void 0) {
16588
- return new Promise((resolve4, reject) => {
16588
+ return new Promise((resolve5, reject) => {
16589
16589
  request.call(this, opts, (err2, data) => {
16590
- return err2 ? reject(err2) : resolve4(data);
16590
+ return err2 ? reject(err2) : resolve5(data);
16591
16591
  });
16592
16592
  });
16593
16593
  }
@@ -16810,9 +16810,9 @@ var require_api_stream = __commonJS({
16810
16810
  };
16811
16811
  function stream(opts, factory, callback) {
16812
16812
  if (callback === void 0) {
16813
- return new Promise((resolve4, reject) => {
16813
+ return new Promise((resolve5, reject) => {
16814
16814
  stream.call(this, opts, factory, (err2, data) => {
16815
- return err2 ? reject(err2) : resolve4(data);
16815
+ return err2 ? reject(err2) : resolve5(data);
16816
16816
  });
16817
16817
  });
16818
16818
  }
@@ -17097,9 +17097,9 @@ var require_api_upgrade = __commonJS({
17097
17097
  };
17098
17098
  function upgrade(opts, callback) {
17099
17099
  if (callback === void 0) {
17100
- return new Promise((resolve4, reject) => {
17100
+ return new Promise((resolve5, reject) => {
17101
17101
  upgrade.call(this, opts, (err2, data) => {
17102
- return err2 ? reject(err2) : resolve4(data);
17102
+ return err2 ? reject(err2) : resolve5(data);
17103
17103
  });
17104
17104
  });
17105
17105
  }
@@ -17191,9 +17191,9 @@ var require_api_connect = __commonJS({
17191
17191
  };
17192
17192
  function connect2(opts, callback) {
17193
17193
  if (callback === void 0) {
17194
- return new Promise((resolve4, reject) => {
17194
+ return new Promise((resolve5, reject) => {
17195
17195
  connect2.call(this, opts, (err2, data) => {
17196
- return err2 ? reject(err2) : resolve4(data);
17196
+ return err2 ? reject(err2) : resolve5(data);
17197
17197
  });
17198
17198
  });
17199
17199
  }
@@ -21055,7 +21055,7 @@ var require_fetch = __commonJS({
21055
21055
  function dispatch({ body }) {
21056
21056
  const url = requestCurrentURL(request);
21057
21057
  const agent = fetchParams.controller.dispatcher;
21058
- return new Promise((resolve4, reject) => agent.dispatch(
21058
+ return new Promise((resolve5, reject) => agent.dispatch(
21059
21059
  {
21060
21060
  path: url.pathname + url.search,
21061
21061
  origin: url.origin,
@@ -21131,7 +21131,7 @@ var require_fetch = __commonJS({
21131
21131
  }
21132
21132
  }
21133
21133
  const onError = this.onError.bind(this);
21134
- resolve4({
21134
+ resolve5({
21135
21135
  status,
21136
21136
  statusText,
21137
21137
  headersList,
@@ -21177,7 +21177,7 @@ var require_fetch = __commonJS({
21177
21177
  for (let i2 = 0; i2 < rawHeaders.length; i2 += 2) {
21178
21178
  headersList.append(bufferToLowerCasedHeaderName(rawHeaders[i2]), rawHeaders[i2 + 1].toString("latin1"), true);
21179
21179
  }
21180
- resolve4({
21180
+ resolve5({
21181
21181
  status,
21182
21182
  statusText: STATUS_CODES[status],
21183
21183
  headersList,
@@ -24907,8 +24907,8 @@ var require_util9 = __commonJS({
24907
24907
  return true;
24908
24908
  }
24909
24909
  function delay(ms) {
24910
- return new Promise((resolve4) => {
24911
- setTimeout(resolve4, ms).unref();
24910
+ return new Promise((resolve5) => {
24911
+ setTimeout(resolve5, ms).unref();
24912
24912
  });
24913
24913
  }
24914
24914
  module.exports = {
@@ -37695,7 +37695,7 @@ var Protocol = class {
37695
37695
  return;
37696
37696
  }
37697
37697
  const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
37698
- await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
37698
+ await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
37699
37699
  options?.signal?.throwIfAborted();
37700
37700
  }
37701
37701
  } catch (error2) {
@@ -37712,7 +37712,7 @@ var Protocol = class {
37712
37712
  */
37713
37713
  request(request, resultSchema, options) {
37714
37714
  const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
37715
- return new Promise((resolve4, reject) => {
37715
+ return new Promise((resolve5, reject) => {
37716
37716
  const earlyReject = (error2) => {
37717
37717
  reject(error2);
37718
37718
  };
@@ -37790,7 +37790,7 @@ var Protocol = class {
37790
37790
  if (!parseResult.success) {
37791
37791
  reject(parseResult.error);
37792
37792
  } else {
37793
- resolve4(parseResult.data);
37793
+ resolve5(parseResult.data);
37794
37794
  }
37795
37795
  } catch (error2) {
37796
37796
  reject(error2);
@@ -38051,12 +38051,12 @@ var Protocol = class {
38051
38051
  }
38052
38052
  } catch {
38053
38053
  }
38054
- return new Promise((resolve4, reject) => {
38054
+ return new Promise((resolve5, reject) => {
38055
38055
  if (signal.aborted) {
38056
38056
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
38057
38057
  return;
38058
38058
  }
38059
- const timeoutId = setTimeout(resolve4, interval);
38059
+ const timeoutId = setTimeout(resolve5, interval);
38060
38060
  signal.addEventListener("abort", () => {
38061
38061
  clearTimeout(timeoutId);
38062
38062
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
@@ -39147,7 +39147,7 @@ var McpServer = class {
39147
39147
  let task = createTaskResult.task;
39148
39148
  const pollInterval = task.pollInterval ?? 5e3;
39149
39149
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
39150
- await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
39150
+ await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
39151
39151
  const updatedTask = await extra.taskStore.getTask(taskId);
39152
39152
  if (!updatedTask) {
39153
39153
  throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
@@ -39811,12 +39811,12 @@ var StdioServerTransport = class {
39811
39811
  this.onclose?.();
39812
39812
  }
39813
39813
  send(message) {
39814
- return new Promise((resolve4) => {
39814
+ return new Promise((resolve5) => {
39815
39815
  const json = serializeMessage(message);
39816
39816
  if (this._stdout.write(json)) {
39817
- resolve4();
39817
+ resolve5();
39818
39818
  } else {
39819
- this._stdout.once("drain", resolve4);
39819
+ this._stdout.once("drain", resolve5);
39820
39820
  }
39821
39821
  });
39822
39822
  }
@@ -40972,9 +40972,14 @@ function searchRoots() {
40972
40972
  function collectDiskArtifacts(turns) {
40973
40973
  const found = [];
40974
40974
  for (const doc of mentionedDocuments(turns)) {
40975
- const candidates = [doc.path, ...searchRoots().map((root) => join3(root, doc.name))].filter(
40976
- (path) => Boolean(path)
40977
- );
40975
+ const candidates = [
40976
+ doc.path,
40977
+ ...searchRoots().map((root) => join3(
40978
+ /* turbopackIgnore: true */
40979
+ root,
40980
+ doc.name
40981
+ ))
40982
+ ].filter((path) => Boolean(path));
40978
40983
  for (const path of candidates) {
40979
40984
  try {
40980
40985
  if (!existsSync3(path)) continue;
@@ -43045,11 +43050,11 @@ Tutorial
43045
43050
  owner, and resume the same way \u2014 /pantheon-resume preorders, or
43046
43051
  /pantheon-resume obirikan/preorders when two spaces share a name.
43047
43052
  They are read-only: handoff, park and remember refuse before writing.
43048
- They refresh on every pull, and stop appearing when access is revoked.
43053
+ They refresh with vault storage, and stop appearing when access is revoked.
43049
43054
 
43050
43055
  Terminal (this CLI)
43051
- connect <code> bind this machine to the private GitHub vault
43052
- status show account, repo, and home
43056
+ connect <code> bind this machine to its private vault storage
43057
+ status show account, storage binding, and home
43053
43058
  sync optional escape hatch \u2014 handoff/resume already sync
43054
43059
  spaces list local consciences (spaces)
43055
43060
  help this guide
@@ -43061,12 +43066,12 @@ Terminal (this CLI)
43061
43066
  MCP tools \u2014 always the pantheon_ prefix
43062
43067
  pantheon_help this same guide
43063
43068
  pantheon_list_spaces list consciences
43064
- pantheon_resume pull vault, then load the packet, memory, story,
43069
+ pantheon_resume refresh storage, then load the packet, memory, story,
43065
43070
  session list, and artifact names
43066
- pantheon_handoff archive this chat from local history, commit and push
43071
+ pantheon_handoff archive this chat from local history and persist it
43067
43072
  pantheon_local_sessions list recorded chats capture can see
43068
43073
  (Cursor/Codex/Claude Code)
43069
- pantheon_park archive without rewriting the packet, then push
43074
+ pantheon_park archive without rewriting the packet, then persist
43070
43075
  pantheon_remember add one durable fact, then push
43071
43076
  pantheon_search search every session \u2014 messages and tool calls
43072
43077
  pantheon_get_turns fetch a turn range
@@ -43094,6 +43099,7 @@ Chat shortcuts (namespaced \u2014 use these, not /resume)
43094
43099
 
43095
43100
  // ../core/src/config.ts
43096
43101
  import { chmodSync, existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
43102
+ import { createHash as createHash2 } from "node:crypto";
43097
43103
  import { homedir as homedir3 } from "node:os";
43098
43104
  import { join as join4 } from "node:path";
43099
43105
  var LEGACY_API_URLS = /* @__PURE__ */ new Set(["https://pantheon-ui-web.vercel.app"]);
@@ -43106,6 +43112,65 @@ function migrateApiUrl(config2, configPath) {
43106
43112
  `);
43107
43113
  return migrated;
43108
43114
  }
43115
+ function isText(value) {
43116
+ return typeof value === "string" && value.length > 0;
43117
+ }
43118
+ function bootstrapTokenFingerprint(token) {
43119
+ return createHash2("sha256").update(`pantheon-bootstrap-token:v1:${token}`).digest("hex");
43120
+ }
43121
+ function normalizedFingerprint(value) {
43122
+ return typeof value === "string" && /^[a-f0-9]{64}$/.test(value) ? value : void 0;
43123
+ }
43124
+ function normalizeMachineConfig(value) {
43125
+ if (!value || typeof value !== "object") throw new Error("Pantheon config is invalid.");
43126
+ const raw = value;
43127
+ if (!isText(raw.home) || !isText(raw.apiUrl) || !isText(raw.account) || !isText(raw.machineId)) {
43128
+ throw new Error("Pantheon config is incomplete.");
43129
+ }
43130
+ if (raw.version === 2 && raw.provider === "drive") {
43131
+ if (!isText(raw.vaultId) || !isText(raw.folderId)) {
43132
+ throw new Error("Pantheon Drive config is incomplete.");
43133
+ }
43134
+ return {
43135
+ version: 2,
43136
+ provider: "drive",
43137
+ home: raw.home,
43138
+ apiUrl: raw.apiUrl,
43139
+ account: raw.account,
43140
+ machineId: raw.machineId,
43141
+ vaultId: raw.vaultId,
43142
+ folderId: raw.folderId,
43143
+ ...normalizedFingerprint(raw.bootstrapTokenFingerprint) ? {
43144
+ bootstrapTokenFingerprint: normalizedFingerprint(
43145
+ raw.bootstrapTokenFingerprint
43146
+ )
43147
+ } : {}
43148
+ };
43149
+ }
43150
+ if (raw.provider !== void 0 && raw.provider !== "github") {
43151
+ throw new Error("Pantheon config has an unsupported provider.");
43152
+ }
43153
+ if (typeof raw.installationId !== "number" || !isText(raw.repo) || !isText(raw.cloneUrl)) {
43154
+ throw new Error("Pantheon GitHub config is incomplete.");
43155
+ }
43156
+ return {
43157
+ version: 2,
43158
+ provider: "github",
43159
+ home: raw.home,
43160
+ apiUrl: raw.apiUrl,
43161
+ account: raw.account,
43162
+ machineId: raw.machineId,
43163
+ vaultId: isText(raw.vaultId) ? raw.vaultId : `legacy-github:${raw.installationId}`,
43164
+ installationId: raw.installationId,
43165
+ repo: raw.repo,
43166
+ cloneUrl: raw.cloneUrl,
43167
+ ...normalizedFingerprint(raw.bootstrapTokenFingerprint) ? {
43168
+ bootstrapTokenFingerprint: normalizedFingerprint(
43169
+ raw.bootstrapTokenFingerprint
43170
+ )
43171
+ } : {}
43172
+ };
43173
+ }
43109
43174
  function configDir() {
43110
43175
  return process.env.PANTHEON_CONFIG_DIR || join4(homedir3(), ".config", "pantheon");
43111
43176
  }
@@ -43114,7 +43179,12 @@ function loadMachineConfig() {
43114
43179
  const configPath = join4(dir, "config.json");
43115
43180
  const credPath = join4(dir, "credentials.json");
43116
43181
  if (!existsSync4(configPath) || !existsSync4(credPath)) return null;
43117
- const config2 = JSON.parse(readFileSync4(configPath, "utf8"));
43182
+ const parsed = JSON.parse(readFileSync4(configPath, "utf8"));
43183
+ const config2 = normalizeMachineConfig(parsed);
43184
+ if (JSON.stringify(parsed) !== JSON.stringify(config2)) {
43185
+ writeFileSync3(configPath, `${JSON.stringify(config2, null, 2)}
43186
+ `);
43187
+ }
43118
43188
  return {
43119
43189
  config: migrateApiUrl(config2, configPath),
43120
43190
  credentials: JSON.parse(readFileSync4(credPath, "utf8"))
@@ -43139,6 +43209,16 @@ import { homedir as homedir4, tmpdir } from "node:os";
43139
43209
  import { dirname, join as join5, resolve as resolve2 } from "node:path";
43140
43210
  import { promisify } from "node:util";
43141
43211
  var execFileAsync = promisify(execFile);
43212
+ function gitReceipt(operation, ok = false) {
43213
+ return {
43214
+ ok,
43215
+ operation,
43216
+ provider: "github",
43217
+ committed: false,
43218
+ pulled: false,
43219
+ pushed: false
43220
+ };
43221
+ }
43142
43222
  function gitEnv(extra = {}) {
43143
43223
  return {
43144
43224
  ...process.env,
@@ -43172,7 +43252,7 @@ function wait(ms) {
43172
43252
  return new Promise((resolveWait) => setTimeout(resolveWait, ms));
43173
43253
  }
43174
43254
  async function withVaultMutationLock(home, task, timeoutMs = MUTATION_LOCK_WAIT_MS) {
43175
- const lock = join5(home, ".git", "pantheon-mutation.lock");
43255
+ const lock = `${resolve2(home)}.pantheon-mutation.lock`;
43176
43256
  const deadline = Date.now() + timeoutMs;
43177
43257
  while (true) {
43178
43258
  try {
@@ -43233,6 +43313,9 @@ function pullRebase(home, run) {
43233
43313
  async function mintToken() {
43234
43314
  const stored = loadMachineConfig();
43235
43315
  if (!stored) throw new Error("Not connected. Run pantheon connect <code> first.");
43316
+ if (stored.config.provider !== "github") {
43317
+ throw new Error("Git credentials are unavailable for Drive vaults.");
43318
+ }
43236
43319
  const res = await fetch(`${stored.config.apiUrl}/api/cli/token`, {
43237
43320
  method: "POST",
43238
43321
  headers: {
@@ -43281,7 +43364,7 @@ esac
43281
43364
  function boundElsewhere(home) {
43282
43365
  try {
43283
43366
  const stored = loadMachineConfig();
43284
- if (!stored?.config.cloneUrl) return null;
43367
+ if (!stored || stored.config.provider !== "github") return null;
43285
43368
  if (resolve2(stored.config.home) !== resolve2(home)) return null;
43286
43369
  const origin = git(home, ["remote", "get-url", "origin"]);
43287
43370
  if (origin === stored.config.cloneUrl) return null;
@@ -43291,9 +43374,9 @@ function boundElsewhere(home) {
43291
43374
  }
43292
43375
  }
43293
43376
  function syncVaultWithToken(home, token, opts = {}) {
43294
- const result = { ok: false, committed: false, pulled: false, pushed: false };
43377
+ const result = gitReceipt(opts.push ? "persist" : "refresh");
43295
43378
  if (!existsSync5(join5(home, ".git"))) {
43296
- result.error = "Vault is not a git repo.";
43379
+ result.error = "Vault workspace is not prepared.";
43297
43380
  return result;
43298
43381
  }
43299
43382
  const bound = boundElsewhere(home);
@@ -43303,13 +43386,13 @@ function syncVaultWithToken(home, token, opts = {}) {
43303
43386
  }
43304
43387
  try {
43305
43388
  return withGitAuth(token, (env) => {
43306
- const auth = [
43389
+ const auth2 = [
43307
43390
  "-c",
43308
43391
  "credential.helper=",
43309
43392
  "-c",
43310
43393
  "credential.helper=!f() { echo username=x-access-token; echo password=$PANTHEON_GIT_PASSWORD; }; f"
43311
43394
  ];
43312
- const run = (args) => git(home, [...auth, ...args], env);
43395
+ const run = (args) => git(home, [...auth2, ...args], env);
43313
43396
  recoverInterruptedGit(home, run);
43314
43397
  if (opts.push) {
43315
43398
  run(["add", "-A"]);
@@ -43359,24 +43442,53 @@ function ensureVaultClone(home, cloneUrl, token) {
43359
43442
  })
43360
43443
  });
43361
43444
  });
43362
- return { ok: true, committed: false, pulled: true, pushed: false };
43445
+ return { ...gitReceipt("prepare", true), pulled: true, changed: true };
43363
43446
  } catch (error2) {
43364
- return { ok: false, committed: false, pulled: false, pushed: false, error: sanitize(error2) };
43447
+ return { ...gitReceipt("prepare"), error: sanitize(error2) };
43365
43448
  }
43366
43449
  }
43367
43450
  async function syncVault(home, opts = {}) {
43368
43451
  if (!existsSync5(join5(home, ".git"))) {
43369
- return { ok: false, committed: false, pulled: false, pushed: false, error: "Vault is not a git repo. Run pantheon connect first." };
43452
+ return {
43453
+ ...gitReceipt(opts.push ? "persist" : "refresh"),
43454
+ error: "Vault storage is not prepared. Run pantheon connect first."
43455
+ };
43370
43456
  }
43371
43457
  try {
43372
43458
  return syncVaultWithToken(home, await mintToken(), opts);
43373
43459
  } catch (error2) {
43374
- return { ok: false, committed: false, pulled: false, pushed: false, error: sanitize(error2) };
43460
+ return { ...gitReceipt(opts.push ? "persist" : "refresh"), error: sanitize(error2) };
43375
43461
  }
43376
43462
  }
43463
+ function nativeGitWorkspaceHooks() {
43464
+ return {
43465
+ refresh: (home) => syncVault(home, { push: false }),
43466
+ persist: (home, message) => syncVault(home, { push: true, message })
43467
+ };
43468
+ }
43469
+
43470
+ // ../core/src/workspace.ts
43471
+ var MCP_READ_FRESHNESS_POLICY = Object.freeze({
43472
+ mode: "always",
43473
+ maxAgeMs: 0,
43474
+ onRefreshError: "allow-stale"
43475
+ });
43476
+ function shouldRefreshWorkspace(policy, lastRefreshedAt, now = Date.now()) {
43477
+ return policy.mode === "always" || lastRefreshedAt === void 0 || now - lastRefreshedAt >= policy.maxAgeMs;
43478
+ }
43377
43479
 
43378
43480
  // ../core/src/shares.ts
43379
- import { existsSync as existsSync6, mkdirSync as mkdirSync5, readdirSync as readdirSync4, readFileSync as readFileSync5, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
43481
+ import { createHash as createHash3, randomUUID } from "node:crypto";
43482
+ import {
43483
+ existsSync as existsSync6,
43484
+ lstatSync,
43485
+ mkdirSync as mkdirSync5,
43486
+ readdirSync as readdirSync4,
43487
+ readFileSync as readFileSync5,
43488
+ renameSync,
43489
+ rmSync as rmSync4,
43490
+ writeFileSync as writeFileSync5
43491
+ } from "node:fs";
43380
43492
  import { dirname as dirname2, join as join6 } from "node:path";
43381
43493
  function ledgerPath(root) {
43382
43494
  return join6(root, "manifest.json");
@@ -43400,8 +43512,19 @@ function safeRelative(value) {
43400
43512
  if (parts.some((part) => !safeSegment(part))) return null;
43401
43513
  return parts.join("/");
43402
43514
  }
43403
- async function fetchShares(apiUrl, auth) {
43404
- const res = await fetch(`${apiUrl}/api/cli/shares`, { headers: { authorization: auth } });
43515
+ function matchesSharedManifestFile(bytes, file) {
43516
+ return Number.isSafeInteger(file.size) && file.size >= 0 && /^[a-f0-9]{64}$/.test(file.sha) && bytes.length === file.size && createHash3("sha256").update(bytes).digest("hex") === file.sha;
43517
+ }
43518
+ function matchesExistingSharedFile(path, file) {
43519
+ try {
43520
+ const stat2 = lstatSync(path);
43521
+ return stat2.isFile() && !stat2.isSymbolicLink() && stat2.size === file.size && matchesSharedManifestFile(readFileSync5(path), file);
43522
+ } catch {
43523
+ return false;
43524
+ }
43525
+ }
43526
+ async function fetchShares(apiUrl, auth2) {
43527
+ const res = await fetch(`${apiUrl}/api/cli/shares`, { headers: { authorization: auth2 } });
43405
43528
  if (!res.ok) throw new Error(`Could not list shares (${res.status}).`);
43406
43529
  const body = await res.json();
43407
43530
  if (!Array.isArray(body.shares)) throw new Error("Could not read the share list.");
@@ -43410,11 +43533,11 @@ async function fetchShares(apiUrl, auth) {
43410
43533
  async function pullShares(home, options = {}) {
43411
43534
  const stored = loadMachineConfig();
43412
43535
  if (!stored) return { ok: false, spaces: 0, fetched: 0, error: "Not connected." };
43413
- const auth = `Bearer ${stored.config.machineId}.${stored.credentials.machineSecret}`;
43536
+ const auth2 = `Bearer ${stored.config.machineId}.${stored.credentials.machineSecret}`;
43414
43537
  const root = sharedHome(home);
43415
43538
  let shares;
43416
43539
  try {
43417
- shares = await fetchShares(stored.config.apiUrl, auth);
43540
+ shares = await fetchShares(stored.config.apiUrl, auth2);
43418
43541
  } catch (error2) {
43419
43542
  return {
43420
43543
  ok: false,
@@ -43437,17 +43560,41 @@ async function pullShares(home, options = {}) {
43437
43560
  const slug = safeSegment(share.slug);
43438
43561
  if (!owner || !slug) continue;
43439
43562
  keep.add(`${owner}/${slug}`);
43440
- const spaceDir2 = join6(root, owner, slug);
43563
+ const spaceDir2 = join6(
43564
+ /* turbopackIgnore: true */
43565
+ root,
43566
+ owner,
43567
+ slug
43568
+ );
43441
43569
  const wanted = /* @__PURE__ */ new Set();
43442
43570
  for (const file of share.files || []) {
43443
- const relative3 = safeRelative(file.path);
43444
- if (!relative3) continue;
43445
- wanted.add(relative3);
43446
- const key = `${owner}/${slug}/${relative3}`;
43571
+ const relative4 = safeRelative(file.path);
43572
+ if (!relative4 || !Number.isSafeInteger(file.size) || file.size < 0 || !/^[a-f0-9]{64}$/.test(file.sha)) {
43573
+ continue;
43574
+ }
43575
+ wanted.add(relative4);
43576
+ const key = `${owner}/${slug}/${relative4}`;
43447
43577
  next[key] = file.sha;
43448
- const dest = join6(spaceDir2, relative3);
43449
- if (ledger[key] === file.sha && existsSync6(dest)) continue;
43450
- jobs.push({ key, owner, slug, relative: relative3, dest });
43578
+ const dest = join6(
43579
+ /* turbopackIgnore: true */
43580
+ spaceDir2,
43581
+ relative4
43582
+ );
43583
+ if (ledger[key] === file.sha && existsSync6(
43584
+ /* turbopackIgnore: true */
43585
+ dest
43586
+ ) && matchesExistingSharedFile(dest, file)) {
43587
+ continue;
43588
+ }
43589
+ jobs.push({
43590
+ key,
43591
+ owner,
43592
+ slug,
43593
+ relative: relative4,
43594
+ dest,
43595
+ sha: file.sha,
43596
+ size: file.size
43597
+ });
43451
43598
  }
43452
43599
  prune(spaceDir2, spaceDir2, wanted);
43453
43600
  }
@@ -43456,14 +43603,33 @@ async function pullShares(home, options = {}) {
43456
43603
  options.onProgress?.(0, jobs.length);
43457
43604
  await pool(jobs, async (job) => {
43458
43605
  const url = `${stored.config.apiUrl}/api/cli/shares/${encodeURIComponent(job.owner)}/${encodeURIComponent(job.slug)}?path=${encodeURIComponent(job.relative)}`;
43459
- const res = await fetch(url, { headers: { authorization: auth } }).catch(() => null);
43606
+ const res = await fetch(url, { headers: { authorization: auth2 } }).catch(() => null);
43460
43607
  if (!res?.ok) {
43461
43608
  delete next[job.key];
43462
43609
  options.onProgress?.(finished += 1, jobs.length);
43463
43610
  return;
43464
43611
  }
43612
+ const bytes = new Uint8Array(await res.arrayBuffer());
43613
+ if (!matchesSharedManifestFile(bytes, {
43614
+ path: job.relative,
43615
+ sha: job.sha,
43616
+ size: job.size
43617
+ })) {
43618
+ delete next[job.key];
43619
+ options.onProgress?.(finished += 1, jobs.length);
43620
+ return;
43621
+ }
43465
43622
  mkdirSync5(dirname2(job.dest), { recursive: true });
43466
- writeFileSync5(job.dest, Buffer.from(await res.arrayBuffer()));
43623
+ const temp = `${job.dest}.pantheon-${process.pid}-${randomUUID()}.tmp`;
43624
+ try {
43625
+ writeFileSync5(temp, bytes, { mode: 384 });
43626
+ renameSync(temp, job.dest);
43627
+ } catch {
43628
+ rmSync4(temp, { force: true });
43629
+ delete next[job.key];
43630
+ options.onProgress?.(finished += 1, jobs.length);
43631
+ return;
43632
+ }
43467
43633
  fetched += 1;
43468
43634
  options.onProgress?.(finished += 1, jobs.length);
43469
43635
  });
@@ -43497,8 +43663,8 @@ function prune(base, dir, wanted) {
43497
43663
  if (!readdirSync4(full).length) rmSync4(full, { recursive: true, force: true });
43498
43664
  continue;
43499
43665
  }
43500
- const relative3 = full.slice(base.length + 1).split("\\").join("/");
43501
- if (!wanted.has(relative3)) rmSync4(full, { force: true });
43666
+ const relative4 = full.slice(base.length + 1).split("\\").join("/");
43667
+ if (!wanted.has(relative4)) rmSync4(full, { force: true });
43502
43668
  }
43503
43669
  }
43504
43670
  function dirNames(root) {
@@ -43509,6 +43675,441 @@ function dirNames(root) {
43509
43675
  }
43510
43676
  }
43511
43677
 
43678
+ // ../core/src/drive-workspace.ts
43679
+ import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
43680
+ import {
43681
+ copyFileSync,
43682
+ existsSync as existsSync7,
43683
+ lstatSync as lstatSync2,
43684
+ mkdirSync as mkdirSync6,
43685
+ readdirSync as readdirSync5,
43686
+ readFileSync as readFileSync6,
43687
+ renameSync as renameSync2,
43688
+ rmSync as rmSync5,
43689
+ writeFileSync as writeFileSync6
43690
+ } from "node:fs";
43691
+ import { dirname as dirname3, join as join7, relative as relative2, resolve as resolve3, sep } from "node:path";
43692
+
43693
+ // ../core/src/drive-protocol.ts
43694
+ var DRIVE_MAX_FILE_BYTES = 4 * 1024 * 1024;
43695
+ var DRIVE_MAX_CHANGE_BYTES = 12 * 1024 * 1024;
43696
+ var DRIVE_MAX_CHANGES = 100;
43697
+ var CONTROL_NAMES = /* @__PURE__ */ new Set([
43698
+ ".git",
43699
+ ".pantheon",
43700
+ ".pantheon-sync",
43701
+ ".pantheon-sync.json",
43702
+ ".pantheon-outbox.json",
43703
+ ".pantheon-drive-manifest.json",
43704
+ "credentials.json"
43705
+ ]);
43706
+ var SECRET_PATH2 = /(^|\/)(\.env(\.[\w-]+)*|\.npmrc|\.netrc|\.pgpass|id_(rsa|dsa|ecdsa|ed25519)|(credentials|secrets?)(\.[\w-]+)?)$|\.(pem|key|p12|pfx|keystore|jks)$/i;
43707
+ function normalizeWorkspacePath(input) {
43708
+ if (typeof input !== "string" || !input.trim()) {
43709
+ throw new Error("Workspace path is empty.");
43710
+ }
43711
+ if (input.includes("\0") || input.includes("\\") || input.startsWith("/")) {
43712
+ throw new Error(`Unsafe workspace path: ${input}`);
43713
+ }
43714
+ const normalized = input.split("/").reduce((parts2, part) => {
43715
+ if (part === "." || part === "") return parts2;
43716
+ if (part === "..") parts2.pop();
43717
+ else parts2.push(part);
43718
+ return parts2;
43719
+ }, []).join("/");
43720
+ if (normalized === "." || normalized === ".." || input.startsWith("../") || input.includes("/../") || normalized !== input) {
43721
+ throw new Error(`Unsafe workspace path: ${input}`);
43722
+ }
43723
+ const parts = normalized.split("/");
43724
+ if (parts.some(
43725
+ (part) => !part || part === "." || part === ".." || CONTROL_NAMES.has(part.toLowerCase()) || part.toLowerCase().startsWith(".pantheon-")
43726
+ )) {
43727
+ throw new Error(`Reserved workspace path: ${input}`);
43728
+ }
43729
+ if (SECRET_PATH2.test(normalized)) {
43730
+ throw new Error(`Sensitive workspace path: ${input}`);
43731
+ }
43732
+ return normalized;
43733
+ }
43734
+
43735
+ // ../core/src/drive-workspace.ts
43736
+ var DriveWorkspaceHttpError = class extends Error {
43737
+ constructor(message, status, conflicts = []) {
43738
+ super(message);
43739
+ this.status = status;
43740
+ this.conflicts = conflicts;
43741
+ }
43742
+ status;
43743
+ conflicts;
43744
+ };
43745
+ function sha256(bytes) {
43746
+ return createHash4("sha256").update(bytes).digest("hex");
43747
+ }
43748
+ function driveWorkspaceStatePaths(home) {
43749
+ const base = resolve3(home);
43750
+ return {
43751
+ ledger: `${base}.pantheon-sync.json`,
43752
+ outbox: `${base}.pantheon-outbox.json`,
43753
+ conflicts: `${base}.pantheon-conflicts`
43754
+ };
43755
+ }
43756
+ function writeJsonAtomic(path, value) {
43757
+ mkdirSync6(dirname3(path), { recursive: true });
43758
+ const temp = `${path}.${process.pid}.tmp`;
43759
+ writeFileSync6(temp, `${JSON.stringify(value, null, 2)}
43760
+ `, { mode: 384 });
43761
+ renameSync2(temp, path);
43762
+ }
43763
+ function readJson(path) {
43764
+ if (!existsSync7(path)) return null;
43765
+ return JSON.parse(readFileSync6(path, "utf8"));
43766
+ }
43767
+ function readJsonSafe(path) {
43768
+ try {
43769
+ return readJson(path);
43770
+ } catch {
43771
+ return null;
43772
+ }
43773
+ }
43774
+ function writeLedger(path, vaultId, manifest) {
43775
+ writeJsonAtomic(path, { ...manifest, vaultId });
43776
+ }
43777
+ function quarantineUnownedDriveWorkspace(home, vaultId, now = /* @__PURE__ */ new Date()) {
43778
+ const paths = driveWorkspaceStatePaths(home);
43779
+ const ledger = readJsonSafe(paths.ledger);
43780
+ const populated = existsSync7(home) && readdirSync5(home).length > 0;
43781
+ if (populated && ledger?.vaultId === vaultId) return "";
43782
+ let quarantined = "";
43783
+ if (populated) {
43784
+ const stamp2 = now.toISOString().replace(/[:.]/g, "-").slice(0, 19);
43785
+ const base = `${home}.pantheon-quarantine-${stamp2}`;
43786
+ quarantined = base;
43787
+ for (let suffix = 2; existsSync7(quarantined); suffix += 1) {
43788
+ quarantined = `${base}-${suffix}`;
43789
+ }
43790
+ renameSync2(home, quarantined);
43791
+ }
43792
+ if (ledger?.vaultId !== vaultId) {
43793
+ rmSync5(paths.ledger, { force: true });
43794
+ rmSync5(paths.outbox, { force: true });
43795
+ }
43796
+ return quarantined;
43797
+ }
43798
+ function walk(home, directory = home) {
43799
+ if (!existsSync7(directory)) return [];
43800
+ const result = [];
43801
+ for (const name of readdirSync5(directory)) {
43802
+ const absolute = join7(directory, name);
43803
+ const stat2 = lstatSync2(absolute);
43804
+ if (stat2.isSymbolicLink()) {
43805
+ throw new Error(`Symbolic links are not supported in Drive workspaces: ${name}`);
43806
+ }
43807
+ const path = relative2(home, absolute).split(sep).join("/");
43808
+ normalizeWorkspacePath(path);
43809
+ if (stat2.isDirectory()) result.push(...walk(home, absolute));
43810
+ else if (stat2.isFile()) result.push(path);
43811
+ }
43812
+ return result;
43813
+ }
43814
+ function scanDriveWorkspace(home) {
43815
+ const entries = {};
43816
+ let total = 0;
43817
+ for (const path of walk(home).sort()) {
43818
+ const bytes = readFileSync6(join7(home, ...path.split("/")));
43819
+ if (bytes.length > DRIVE_MAX_FILE_BYTES) {
43820
+ throw new Error(
43821
+ `Workspace file ${path} exceeds the ${DRIVE_MAX_FILE_BYTES / 1024 / 1024}MB file limit.`
43822
+ );
43823
+ }
43824
+ total += bytes.length;
43825
+ if (total > DRIVE_MAX_CHANGE_BYTES) {
43826
+ throw new Error(
43827
+ `Workspace changes exceed the ${DRIVE_MAX_CHANGE_BYTES / 1024 / 1024}MB sync limit.`
43828
+ );
43829
+ }
43830
+ entries[path] = {
43831
+ path,
43832
+ sha256: sha256(bytes),
43833
+ size: bytes.length
43834
+ };
43835
+ }
43836
+ return entries;
43837
+ }
43838
+ function diffDriveManifest(home, manifest) {
43839
+ const local = scanDriveWorkspace(home);
43840
+ const changes = [];
43841
+ for (const [path, entry] of Object.entries(local)) {
43842
+ if (manifest.entries[path]?.sha256 === entry.sha256 && manifest.entries[path]?.size === entry.size) {
43843
+ continue;
43844
+ }
43845
+ const bytes = readFileSync6(join7(home, ...path.split("/")));
43846
+ changes.push({ ...entry, content: bytes.toString("base64") });
43847
+ }
43848
+ const deletes = Object.keys(manifest.entries).filter((path) => !(path in local)).sort();
43849
+ if (changes.length + deletes.length > DRIVE_MAX_CHANGES) {
43850
+ throw new Error(`Workspace sync exceeds the ${DRIVE_MAX_CHANGES} path limit.`);
43851
+ }
43852
+ return { changes, deletes };
43853
+ }
43854
+ function receipt(operation) {
43855
+ return {
43856
+ ok: false,
43857
+ operation,
43858
+ provider: "google",
43859
+ committed: false,
43860
+ pulled: false,
43861
+ pushed: false
43862
+ };
43863
+ }
43864
+ function auth(config2, credentials) {
43865
+ return {
43866
+ authorization: `Bearer ${config2.machineId}.${credentials.machineSecret}`
43867
+ };
43868
+ }
43869
+ async function responseError(response) {
43870
+ const body = await response.json().catch(() => null);
43871
+ const conflicts = body?.conflicts?.map(normalizeWorkspacePath) ?? [];
43872
+ const conflict = conflicts.length ? ` Conflicting paths: ${conflicts.join(", ")}.` : "";
43873
+ return new DriveWorkspaceHttpError(
43874
+ `${body?.error || `Drive workspace request failed (${response.status}).`}${conflict}`,
43875
+ response.status,
43876
+ conflicts
43877
+ );
43878
+ }
43879
+ async function publishOutbox(config2, credentials, outbox, fetcher) {
43880
+ const response = await fetcher(`${config2.apiUrl}/api/cli/workspace/sync`, {
43881
+ method: "POST",
43882
+ headers: {
43883
+ ...auth(config2, credentials),
43884
+ "content-type": "application/json"
43885
+ },
43886
+ body: JSON.stringify(outbox),
43887
+ signal: AbortSignal.timeout(3e4)
43888
+ });
43889
+ if (!response.ok) throw await responseError(response);
43890
+ return await response.json();
43891
+ }
43892
+ function httpDriveWorkspaceHooks(config2, credentials, fetcher = fetch) {
43893
+ const paths = driveWorkspaceStatePaths(config2.home);
43894
+ async function fetchManifest() {
43895
+ const response = await fetcher(`${config2.apiUrl}/api/cli/workspace/manifest`, {
43896
+ headers: auth(config2, credentials),
43897
+ signal: AbortSignal.timeout(3e4)
43898
+ });
43899
+ if (!response.ok) throw await responseError(response);
43900
+ const manifest = await response.json();
43901
+ for (const [key, entry] of Object.entries(manifest.entries)) {
43902
+ const path = normalizeWorkspacePath(entry.path);
43903
+ if (key !== path) throw new Error(`Drive manifest path mismatch: ${key}`);
43904
+ }
43905
+ return manifest;
43906
+ }
43907
+ async function applyManifest(home, manifest, protectedPaths = /* @__PURE__ */ new Set()) {
43908
+ const staged = [];
43909
+ const previous = readJsonSafe(paths.ledger);
43910
+ mkdirSync6(home, { recursive: true });
43911
+ let changed = false;
43912
+ try {
43913
+ for (const entry of Object.values(manifest.entries)) {
43914
+ const path = normalizeWorkspacePath(entry.path);
43915
+ if (protectedPaths.has(path)) continue;
43916
+ const target = join7(home, ...path.split("/"));
43917
+ const current = existsSync7(target) && lstatSync2(target).isFile() ? sha256(readFileSync6(target)) : null;
43918
+ if (current === entry.sha256) continue;
43919
+ const file = await fetcher(
43920
+ `${config2.apiUrl}/api/cli/workspace/file/${path.split("/").map(encodeURIComponent).join("/")}`,
43921
+ {
43922
+ headers: auth(config2, credentials),
43923
+ signal: AbortSignal.timeout(3e4)
43924
+ }
43925
+ );
43926
+ if (!file.ok) throw await responseError(file);
43927
+ const bytes = new Uint8Array(await file.arrayBuffer());
43928
+ if (bytes.length !== entry.size || sha256(bytes) !== entry.sha256) {
43929
+ throw new Error(`Drive returned invalid content for ${path}.`);
43930
+ }
43931
+ mkdirSync6(dirname3(target), { recursive: true });
43932
+ const temp = `${target}.pantheon-${process.pid}-${randomUUID2()}.tmp`;
43933
+ writeFileSync6(temp, bytes);
43934
+ staged.push({ temp, target });
43935
+ changed = true;
43936
+ }
43937
+ for (const item of staged) renameSync2(item.temp, item.target);
43938
+ for (const path of Object.keys(previous?.entries ?? {}).filter(
43939
+ (value) => !(value in manifest.entries) && !protectedPaths.has(value)
43940
+ )) {
43941
+ const target = join7(home, ...normalizeWorkspacePath(path).split("/"));
43942
+ if (existsSync7(target)) {
43943
+ rmSync5(target, { recursive: true, force: true });
43944
+ changed = true;
43945
+ }
43946
+ }
43947
+ writeLedger(paths.ledger, config2.vaultId, manifest);
43948
+ return changed;
43949
+ } catch (error2) {
43950
+ for (const item of staged) rmSync5(item.temp, { force: true });
43951
+ throw error2;
43952
+ }
43953
+ }
43954
+ function preserveConflicts(home, outbox, conflicts) {
43955
+ const root = join7(paths.conflicts, outbox.requestId);
43956
+ const deleted = [];
43957
+ for (const conflict of conflicts) {
43958
+ const path = normalizeWorkspacePath(conflict);
43959
+ const source = join7(home, ...path.split("/"));
43960
+ if (existsSync7(source) && lstatSync2(source).isFile()) {
43961
+ const target = join7(root, ...path.split("/"));
43962
+ mkdirSync6(dirname3(target), { recursive: true });
43963
+ copyFileSync(source, target);
43964
+ } else if (outbox.deletes.includes(path)) {
43965
+ deleted.push(path);
43966
+ }
43967
+ }
43968
+ mkdirSync6(root, { recursive: true });
43969
+ writeJsonAtomic(join7(root, "conflict.json"), {
43970
+ requestId: outbox.requestId,
43971
+ baseRevision: outbox.baseRevision,
43972
+ conflicts,
43973
+ deleted
43974
+ });
43975
+ return root;
43976
+ }
43977
+ async function resolveConflict(home, outbox, error2, operation) {
43978
+ const result = receipt(operation);
43979
+ const manifest = await fetchManifest();
43980
+ const conflictRoot = preserveConflicts(home, outbox, error2.conflicts);
43981
+ rmSync5(paths.outbox, { force: true });
43982
+ const incoming = /* @__PURE__ */ new Set([
43983
+ ...outbox.changes.map((change) => change.path),
43984
+ ...outbox.deletes
43985
+ ]);
43986
+ for (const path of error2.conflicts) incoming.delete(path);
43987
+ const changed = await applyManifest(home, manifest, incoming);
43988
+ const retryable = diffDriveManifest(home, manifest);
43989
+ if (retryable.changes.length || retryable.deletes.length) {
43990
+ writeJsonAtomic(paths.outbox, {
43991
+ version: 1,
43992
+ requestId: randomUUID2(),
43993
+ baseRevision: manifest.revision,
43994
+ message: outbox.message,
43995
+ ...retryable
43996
+ });
43997
+ result.pending = true;
43998
+ }
43999
+ result.changed = changed;
44000
+ result.pulled = true;
44001
+ result.revision = { id: manifest.revision };
44002
+ result.conflicts = error2.conflicts;
44003
+ result.conflictRoot = conflictRoot;
44004
+ result.error = `${error2.message} Local conflicting files were preserved in ${conflictRoot}. Resolve them there, copy the desired versions back into the vault, and sync again.`;
44005
+ return result;
44006
+ }
44007
+ async function refresh(home) {
44008
+ const result = receipt(existsSync7(home) ? "refresh" : "prepare");
44009
+ quarantineUnownedDriveWorkspace(home, config2.vaultId);
44010
+ let pending = readJsonSafe(paths.outbox);
44011
+ if (pending) {
44012
+ const currentPending = pending;
44013
+ try {
44014
+ const published = await publishOutbox(
44015
+ config2,
44016
+ credentials,
44017
+ currentPending,
44018
+ fetcher
44019
+ );
44020
+ writeLedger(paths.ledger, config2.vaultId, published.manifest);
44021
+ rmSync5(paths.outbox, { force: true });
44022
+ pending = null;
44023
+ } catch (error2) {
44024
+ if (error2 instanceof DriveWorkspaceHttpError && error2.status === 409) {
44025
+ try {
44026
+ return await resolveConflict(home, currentPending, error2, "refresh");
44027
+ } catch (resolutionError) {
44028
+ rmSync5(paths.outbox, { force: true });
44029
+ result.conflicts = error2.conflicts;
44030
+ result.error = resolutionError instanceof Error ? `Drive conflict recovery failed: ${resolutionError.message}` : String(resolutionError);
44031
+ return result;
44032
+ }
44033
+ }
44034
+ result.pending = true;
44035
+ result.stale = true;
44036
+ result.error = error2 instanceof Error ? error2.message : String(error2);
44037
+ return result;
44038
+ }
44039
+ }
44040
+ try {
44041
+ const manifest = await fetchManifest();
44042
+ const changed = await applyManifest(home, manifest);
44043
+ result.ok = true;
44044
+ result.changed = changed;
44045
+ result.pulled = true;
44046
+ result.revision = { id: manifest.revision };
44047
+ return result;
44048
+ } catch (error2) {
44049
+ result.stale = existsSync7(
44050
+ /* turbopackIgnore: true */
44051
+ paths.ledger
44052
+ );
44053
+ result.error = error2 instanceof Error ? error2.message : String(error2);
44054
+ return result;
44055
+ }
44056
+ }
44057
+ async function persist(home, message) {
44058
+ const result = receipt("persist");
44059
+ const existing = readJsonSafe(paths.outbox);
44060
+ let outbox = existing;
44061
+ try {
44062
+ if (!outbox) {
44063
+ const ledger = readJsonSafe(paths.ledger);
44064
+ if (!ledger || ledger.vaultId !== config2.vaultId) {
44065
+ throw new Error(
44066
+ "Drive cache identity is missing or belongs to another vault. Reconnect before syncing."
44067
+ );
44068
+ }
44069
+ const changes = diffDriveManifest(home, ledger);
44070
+ if (!changes.changes.length && !changes.deletes.length) {
44071
+ result.ok = true;
44072
+ result.changed = false;
44073
+ result.revision = { id: ledger.revision };
44074
+ return result;
44075
+ }
44076
+ outbox = {
44077
+ version: 1,
44078
+ requestId: randomUUID2(),
44079
+ baseRevision: ledger.revision,
44080
+ message,
44081
+ ...changes
44082
+ };
44083
+ writeJsonAtomic(paths.outbox, outbox);
44084
+ }
44085
+ const published = await publishOutbox(config2, credentials, outbox, fetcher);
44086
+ writeLedger(paths.ledger, config2.vaultId, published.manifest);
44087
+ rmSync5(paths.outbox, { force: true });
44088
+ result.ok = true;
44089
+ result.changed = true;
44090
+ result.committed = true;
44091
+ result.pushed = true;
44092
+ result.revision = { id: published.revision };
44093
+ return result;
44094
+ } catch (error2) {
44095
+ if (outbox && error2 instanceof DriveWorkspaceHttpError && error2.status === 409) {
44096
+ try {
44097
+ return await resolveConflict(home, outbox, error2, "persist");
44098
+ } catch (resolutionError) {
44099
+ rmSync5(paths.outbox, { force: true });
44100
+ result.conflicts = error2.conflicts;
44101
+ result.error = resolutionError instanceof Error ? `Drive conflict recovery failed: ${resolutionError.message}` : String(resolutionError);
44102
+ return result;
44103
+ }
44104
+ }
44105
+ result.pending = Boolean(outbox);
44106
+ result.error = error2 instanceof Error ? error2.message : String(error2);
44107
+ return result;
44108
+ }
44109
+ }
44110
+ return { refresh, persist };
44111
+ }
44112
+
43512
44113
  // ../mcp/src/artifacts.ts
43513
44114
  var import_undici = __toESM(require_undici(), 1);
43514
44115
  import { lookup } from "node:dns/promises";
@@ -43524,7 +44125,7 @@ import {
43524
44125
  writeFile
43525
44126
  } from "node:fs/promises";
43526
44127
  import { homedir as homedir5, tmpdir as tmpdir2 } from "node:os";
43527
- import { basename as basename4, dirname as dirname3, extname, isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as resolve3 } from "node:path";
44128
+ import { basename as basename4, dirname as dirname4, extname, isAbsolute as isAbsolute2, join as join8, relative as relative3, resolve as resolve4 } from "node:path";
43528
44129
  import { isIP } from "node:net";
43529
44130
  var MAX_FILE_BYTES = 8 * 1024 * 1024;
43530
44131
  var MAX_TOTAL_BYTES = 24 * 1024 * 1024;
@@ -43532,7 +44133,7 @@ var MAX_ARTIFACTS = 200;
43532
44133
  var MAX_TRANSCRIPT_EXPORT_BYTES = 256 * 1024 * 1024;
43533
44134
  var MAX_REDIRECTS = 4;
43534
44135
  var FETCH_TIMEOUT_MS = 15e3;
43535
- var SECRET_PATH2 = /(^|\/)(\.env(\.[\w-]+)*|\.npmrc|\.netrc|\.pgpass|id_(rsa|dsa|ecdsa|ed25519)|(credentials|secrets?)(\.[\w-]+)?)$|\.(pem|key|p12|pfx|keystore|jks)$/i;
44136
+ var SECRET_PATH3 = /(^|\/)(\.env(\.[\w-]+)*|\.npmrc|\.netrc|\.pgpass|id_(rsa|dsa|ecdsa|ed25519)|(credentials|secrets?)(\.[\w-]+)?)$|\.(pem|key|p12|pfx|keystore|jks)$/i;
43536
44137
  var MIME_BY_EXTENSION = {
43537
44138
  ".avif": "image/avif",
43538
44139
  ".csv": "text/csv",
@@ -43565,27 +44166,27 @@ function publicName(value) {
43565
44166
  if (!name || name === "." || name === "..") {
43566
44167
  throw new Error("Artifact name is empty.");
43567
44168
  }
43568
- if (SECRET_PATH2.test(name)) {
44169
+ if (SECRET_PATH3.test(name)) {
43569
44170
  throw new Error(`Refusing sensitive artifact: ${name}`);
43570
44171
  }
43571
44172
  return name;
43572
44173
  }
43573
44174
  function within(root, path) {
43574
- const rel = relative2(resolve3(root), resolve3(path));
44175
+ const rel = relative3(resolve4(root), resolve4(path));
43575
44176
  return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
43576
44177
  }
43577
44178
  function localRoots(clientRoots = []) {
43578
- const workspace = resolve3(
44179
+ const workspace = resolve4(
43579
44180
  /*turbopackIgnore: true*/
43580
44181
  process.cwd()
43581
44182
  );
43582
- const home = resolve3(homedir5());
44183
+ const home = resolve4(homedir5());
43583
44184
  return [
43584
- ...dirname3(workspace) === workspace || workspace === home ? [] : [workspace],
43585
- join7(home, "Desktop"),
43586
- join7(home, "Documents"),
43587
- join7(home, "Downloads"),
43588
- resolve3(tmpdir2()),
44185
+ ...dirname4(workspace) === workspace || workspace === home ? [] : [workspace],
44186
+ join8(home, "Desktop"),
44187
+ join8(home, "Documents"),
44188
+ join8(home, "Downloads"),
44189
+ resolve4(tmpdir2()),
43589
44190
  "/mnt/user-data/outputs",
43590
44191
  "/mnt/user-data/uploads",
43591
44192
  ...clientRoots
@@ -43597,7 +44198,7 @@ async function localArtifact(input, options) {
43597
44198
  "Local artifact paths are unavailable on the hosted MCP server. Pass a public HTTPS URL or inline content instead."
43598
44199
  );
43599
44200
  }
43600
- const requested = isAbsolute2(input.path) ? resolve3(input.path) : resolve3(options.cwd, input.path);
44201
+ const requested = isAbsolute2(input.path) ? resolve4(input.path) : resolve4(options.cwd, input.path);
43601
44202
  const canonical2 = await realpath(requested).catch(() => {
43602
44203
  throw new Error(`Artifact path does not exist: ${input.path}`);
43603
44204
  });
@@ -43605,7 +44206,7 @@ async function localArtifact(input, options) {
43605
44206
  if (!roots.some((root) => within(root, canonical2))) {
43606
44207
  throw new Error("Artifact path must be inside the workspace, user documents, downloads, or temp output.");
43607
44208
  }
43608
- if (SECRET_PATH2.test(canonical2.replaceAll("\\", "/"))) {
44209
+ if (SECRET_PATH3.test(canonical2.replaceAll("\\", "/"))) {
43609
44210
  throw new Error(`Refusing sensitive artifact: ${basename4(canonical2)}`);
43610
44211
  }
43611
44212
  const handle = await open(canonical2, "r");
@@ -43630,11 +44231,11 @@ async function readTranscriptExport(inputPath, options) {
43630
44231
  "Transcript-file imports require the local Pantheon MCP server."
43631
44232
  );
43632
44233
  }
43633
- const cwd = resolve3(
44234
+ const cwd = resolve4(
43634
44235
  /*turbopackIgnore: true*/
43635
44236
  options.cwd || process.cwd()
43636
44237
  );
43637
- const requested = isAbsolute2(inputPath) ? resolve3(inputPath) : resolve3(cwd, inputPath);
44238
+ const requested = isAbsolute2(inputPath) ? resolve4(inputPath) : resolve4(cwd, inputPath);
43638
44239
  const canonical2 = await realpath(requested).catch(() => {
43639
44240
  throw new Error(`Transcript export does not exist: ${inputPath}`);
43640
44241
  });
@@ -43822,7 +44423,7 @@ async function materializeArtifacts(artifacts, options) {
43822
44423
  if (artifacts.length > MAX_ARTIFACTS) {
43823
44424
  throw new Error(`A handoff can store at most ${MAX_ARTIFACTS} artifacts.`);
43824
44425
  }
43825
- const cwd = resolve3(
44426
+ const cwd = resolve4(
43826
44427
  /*turbopackIgnore: true*/
43827
44428
  options.cwd || process.cwd()
43828
44429
  );
@@ -43872,19 +44473,19 @@ async function restoreArtifact(artifact, destination, cwd = process.cwd(), clien
43872
44473
  if (!allowedRoots.some((allowed) => within(allowed, root))) {
43873
44474
  throw new Error("cwd must be the current workspace, user documents, downloads, or temp output.");
43874
44475
  }
43875
- const requestedOutput = resolve3(root, destination);
44476
+ const requestedOutput = resolve4(root, destination);
43876
44477
  if (!within(root, requestedOutput)) {
43877
44478
  throw new Error("save_to must stay inside the current workspace.");
43878
44479
  }
43879
- if (SECRET_PATH2.test(requestedOutput.replaceAll("\\", "/"))) {
44480
+ if (SECRET_PATH3.test(requestedOutput.replaceAll("\\", "/"))) {
43880
44481
  throw new Error(`Refusing sensitive output path: ${destination}`);
43881
44482
  }
43882
- await mkdir(dirname3(requestedOutput), { recursive: true });
43883
- const parent = await realpath(dirname3(requestedOutput));
44483
+ await mkdir(dirname4(requestedOutput), { recursive: true });
44484
+ const parent = await realpath(dirname4(requestedOutput));
43884
44485
  if (!within(root, parent)) {
43885
44486
  throw new Error("save_to cannot pass through a symlink outside the current workspace.");
43886
44487
  }
43887
- const output = join7(parent, basename4(requestedOutput));
44488
+ const output = join8(parent, basename4(requestedOutput));
43888
44489
  await stat(output).then(() => {
43889
44490
  throw new Error(`Refusing to overwrite existing file: ${destination}`);
43890
44491
  }).catch((error2) => {
@@ -43903,7 +44504,7 @@ async function restoreArtifact(artifact, destination, cwd = process.cwd(), clien
43903
44504
  }
43904
44505
  return {
43905
44506
  name: artifact.name,
43906
- savedTo: relative2(root, output),
44507
+ savedTo: relative3(root, output),
43907
44508
  bytes: bytes.length
43908
44509
  };
43909
44510
  }
@@ -43948,14 +44549,14 @@ function handoffPreflight(input) {
43948
44549
  // ../mcp/src/index.ts
43949
44550
  async function mutateVault(home, vault, message, write) {
43950
44551
  return withVaultMutationLock(home, async () => {
43951
- const pulled = await vault.pull(home);
43952
- if (pulled.ok === false) {
44552
+ const refreshed = await vault.refresh(home);
44553
+ if (refreshed.ok === false && !(refreshed.provider === "google" && refreshed.stale)) {
43953
44554
  throw new Error(
43954
- `Could not refresh the vault before writing: ${pulled.error || "unknown sync error"}`
44555
+ `Could not refresh vault storage before writing: ${refreshed.error || "unknown sync error"}`
43955
44556
  );
43956
44557
  }
43957
44558
  const written = await write();
43958
- const sync2 = await vault.push(
44559
+ const sync2 = await vault.persist(
43959
44560
  home,
43960
44561
  typeof message === "function" ? message(written) : message
43961
44562
  );
@@ -43969,14 +44570,19 @@ function writeRoot(home, space) {
43969
44570
  return resolveForWrite(home, space).root;
43970
44571
  }
43971
44572
  function defaultHooks() {
44573
+ const stored = loadMachineConfig();
44574
+ if (stored?.config.provider === "drive") {
44575
+ return httpDriveWorkspaceHooks(stored.config, stored.credentials);
44576
+ }
44577
+ const local = nativeGitWorkspaceHooks();
43972
44578
  return {
43973
- pull: async (home) => {
43974
- const sync2 = await syncVault(home, { push: false });
44579
+ refresh: async (home) => {
44580
+ const sync2 = await local.refresh(home);
43975
44581
  await pullShares(home).catch(() => {
43976
44582
  });
43977
44583
  return sync2;
43978
44584
  },
43979
- push: (home, message) => syncVault(home, { push: true, message })
44585
+ persist: local.persist
43980
44586
  };
43981
44587
  }
43982
44588
  var turnSchema = external_exports.object({
@@ -44109,13 +44715,44 @@ function hint(message) {
44109
44715
  if (text2.includes("not a space name") || text2.includes("no conscience name")) {
44110
44716
  return "Stop. Ask the human what to name this conscience. Do not guess. Then retry with that slug.";
44111
44717
  }
44112
- if (text2.includes("vault token") || text2.includes("not a git repo") || text2.includes("not connected")) {
44718
+ if (text2.includes("vault token") || text2.includes("not a git repo") || text2.includes("storage is not prepared") || text2.includes("not connected")) {
44113
44719
  return "The dump was saved locally. Start the Pantheon web app (or run pantheon connect), then pantheon sync once.";
44114
44720
  }
44115
44721
  return "Check the space name and call pantheon_resume, or pantheon_list_spaces.";
44116
44722
  }
44117
44723
  function vaultHooks(hooks) {
44118
- return hooks ?? defaultHooks();
44724
+ if (!hooks) return defaultHooks();
44725
+ if ("refresh" in hooks) return hooks;
44726
+ return {
44727
+ refresh: hooks.pull,
44728
+ persist: hooks.push
44729
+ };
44730
+ }
44731
+ function readFreshness(vault) {
44732
+ let lastRefreshedAt;
44733
+ return async (home) => {
44734
+ if (!shouldRefreshWorkspace(
44735
+ MCP_READ_FRESHNESS_POLICY,
44736
+ lastRefreshedAt
44737
+ )) {
44738
+ return {
44739
+ ok: true,
44740
+ operation: "refresh",
44741
+ changed: false,
44742
+ committed: false,
44743
+ pulled: false,
44744
+ pushed: false
44745
+ };
44746
+ }
44747
+ const sync2 = await vault.refresh(home);
44748
+ if (sync2.ok) lastRefreshedAt = Date.now();
44749
+ if (!sync2.ok && MCP_READ_FRESHNESS_POLICY.onRefreshError === "fail") {
44750
+ throw new Error(
44751
+ `Could not refresh vault storage before reading: ${sync2.error || "unknown sync error"}`
44752
+ );
44753
+ }
44754
+ return sync2;
44755
+ };
44119
44756
  }
44120
44757
  async function safe(run) {
44121
44758
  try {
@@ -44144,6 +44781,7 @@ function registerTool(server, name, description, schema, handler) {
44144
44781
  }
44145
44782
  function createPantheonServer(home = defaultHome(), hooks, options = {}) {
44146
44783
  const vault = vaultHooks(hooks);
44784
+ const refreshForRead = readFreshness(vault);
44147
44785
  const allowCapture = options.allowCapture !== false;
44148
44786
  const configuredSite = (process.env.NEXT_PUBLIC_APP_URL || "https://www.pantheonvault.space").replace(/\/$/, "");
44149
44787
  const site = configuredSite === "https://pantheon-ui-web.vercel.app" ? "https://www.pantheonvault.space" : configuredSite;
@@ -44198,7 +44836,7 @@ ${GUIDE}` }]
44198
44836
  "List existing Pantheon consciences from the private vault. Trigger: /pantheon-spaces. For listing only \u2014 never invent extra names. If the human already typed a new slug for handoff, do not block that handoff because it is missing here. An entry with shared: true belongs to another person and is named owner/slug: it can be resumed and searched, but never handed off to, parked in, or remembered into. Say whose it is when you show the list.",
44199
44837
  {},
44200
44838
  async () => safe(async () => {
44201
- const sync2 = await vault.pull(home);
44839
+ const sync2 = await refreshForRead(home);
44202
44840
  return {
44203
44841
  home,
44204
44842
  spaces: listSpaces(home),
@@ -44211,10 +44849,10 @@ ${GUIDE}` }]
44211
44849
  registerTool(
44212
44850
  server,
44213
44851
  "pantheon_resume",
44214
- "Pull the vault, then load a Pantheon conscience: the latest handoff packet, durable memory, packets from earlier handoffs (story), every archived session with its turn count (sessions), and stored artifact names. Trigger: /pantheon-resume <space>. If the space name is missing or empty, this tool lists live spaces \u2014 show that list and ask which conscience. The packet covers the whole space \u2014 totals, stored files, the most recent turns wherever they happened, and summaries of earlier handoffs \u2014 but it is a summary, not the conversation: when the human asks about anything it does not cover, call pantheon_search before saying you lack context, and read detail with pantheon_get_turns or pantheon_get_session using any id from sessions. Fetch files with pantheon_get_artifact. Never call a generic resume tool for this. Do not run pantheon sync. A space named owner/slug was shared with you by someone else: resume and search work, writing does not, so tell the human at the end that this chat has to be handed off to one of their own spaces. REPORT THE RESULT as a two-column table \u2014 space, sessions (with total turns), earlier handoffs, memory facts, artifacts, skills (live and awaiting review), pulled \u2014 and then, outside the table, two or three sentences on where the work actually stood, any open threads, and the available skills by name and trigger. The table proves the load worked; it does not tell the human where the work was, so never collapse that prose into cells.",
44852
+ "Refresh vault storage, then load a Pantheon conscience: the latest handoff packet, durable memory, packets from earlier handoffs (story), every archived session with its turn count (sessions), and stored artifact names. Trigger: /pantheon-resume <space>. If the space name is missing or empty, this tool lists live spaces \u2014 show that list and ask which conscience. The packet covers the whole space \u2014 totals, stored files, the most recent turns wherever they happened, and summaries of earlier handoffs \u2014 but it is a summary, not the conversation: when the human asks about anything it does not cover, call pantheon_search before saying you lack context, and read detail with pantheon_get_turns or pantheon_get_session using any id from sessions. Fetch files with pantheon_get_artifact. Never call a generic resume tool for this. Do not run pantheon sync. A space named owner/slug was shared with you by someone else: resume and search work, writing does not, so tell the human at the end that this chat has to be handed off to one of their own spaces. REPORT THE RESULT as a two-column table \u2014 space, sessions (with total turns), earlier handoffs, memory facts, artifacts, skills (live and awaiting review), refreshed \u2014 and then, outside the table, two or three sentences on where the work actually stood, any open threads, and the available skills by name and trigger. The table proves the load worked; it does not tell the human where the work was, so never collapse that prose into cells.",
44215
44853
  { space: external_exports.string().optional() },
44216
44854
  async ({ space }) => safe(async () => {
44217
- const sync2 = await vault.pull(home);
44855
+ const sync2 = await refreshForRead(home);
44218
44856
  const spaces = listSpaces(home);
44219
44857
  const raw = (space || "").trim();
44220
44858
  if (missingSpaceName(raw)) {
@@ -44379,7 +45017,7 @@ ${GUIDE}` }]
44379
45017
  saveTool: "pantheon_save_skill_drafts",
44380
45018
  instruction: review ? AUTO_SKILL_REVIEW : `Call pantheon_skill_review for "${written.slug}". ${AUTO_SKILL_REVIEW}`
44381
45019
  },
44382
- note: sync2.ok === false ? `Saved locally (${written.turns} turns) but the push failed: ${sync2.error || "unknown error"}. Tell the human it is not yet in GitHub.` : [
45020
+ note: sync2.ok === false ? `Saved locally (${written.turns} turns) but storage persistence failed: ${sync2.error || "unknown error"}. Tell the human it has not reached the configured vault storage yet.` : [
44383
45021
  `Archived ${written.turns} turns${written.added !== written.turns ? ` (${written.added} new)` : ""} from ${written.capturedFrom || "the supplied transcript"}.`,
44384
45022
  // Capture reads a chat off disk, so name what it read: if a
44385
45023
  // second conversation was open, this is where that shows.
@@ -44470,10 +45108,12 @@ ${GUIDE}` }]
44470
45108
  context: external_exports.number().optional().describe("Turns of surrounding conversation to return with each hit (0-5). Use 2 to read a moment without a second call."),
44471
45109
  limit: external_exports.number().optional().describe("Maximum hits (default 20, max 50).")
44472
45110
  },
44473
- async ({ space, query, context, limit }) => safe(() => {
45111
+ async ({ space, query, context, limit }) => safe(async () => {
45112
+ const sync2 = await refreshForRead(home);
44474
45113
  const hits = searchSpace(home, space, query, { context, limit });
44475
45114
  return {
44476
45115
  hits,
45116
+ sync: sync2,
44477
45117
  note: hits.length ? "Each hit names its session. Widen with pantheon_get_turns (space, session_id, from, to) or read the session end to end with pantheon_get_session." : "No match. Try a different word, or list what exists with pantheon_resume \u2014 its sessions array names every archived conversation in this space."
44478
45118
  };
44479
45119
  })
@@ -44488,14 +45128,20 @@ ${GUIDE}` }]
44488
45128
  from: external_exports.number(),
44489
45129
  to: external_exports.number()
44490
45130
  },
44491
- async ({ space, session_id, from, to }) => safe(() => ({ turns: getTurns(home, space, session_id, from, to) }))
45131
+ async ({ space, session_id, from, to }) => safe(async () => {
45132
+ const sync2 = await refreshForRead(home);
45133
+ return { turns: getTurns(home, space, session_id, from, to), sync: sync2 };
45134
+ })
44492
45135
  );
44493
45136
  registerTool(
44494
45137
  server,
44495
45138
  "pantheon_get_session",
44496
45139
  "Fetch a full stored Pantheon session transcript.",
44497
45140
  { space: external_exports.string(), session_id: external_exports.string() },
44498
- async ({ space, session_id }) => safe(() => getSession(home, space, session_id))
45141
+ async ({ space, session_id }) => safe(async () => {
45142
+ const sync2 = await refreshForRead(home);
45143
+ return { ...getSession(home, space, session_id), sync: sync2 };
45144
+ })
44499
45145
  );
44500
45146
  registerTool(
44501
45147
  server,
@@ -44510,6 +45156,7 @@ ${GUIDE}` }]
44510
45156
  },
44511
45157
  async ({ space, session_id, name, save_to, cwd }) => {
44512
45158
  try {
45159
+ const sync2 = await refreshForRead(home);
44513
45160
  const artifact = getArtifact(home, space, session_id, name);
44514
45161
  if (save_to) {
44515
45162
  if (!allowCapture) {
@@ -44517,14 +45164,15 @@ ${GUIDE}` }]
44517
45164
  "save_to is unavailable on hosted MCP. Fetch the embedded resource and let the client download it."
44518
45165
  );
44519
45166
  }
44520
- return text(
44521
- await restoreArtifact(
45167
+ return text({
45168
+ ...await restoreArtifact(
44522
45169
  artifact,
44523
45170
  save_to,
44524
45171
  cwd || process.cwd(),
44525
45172
  await clientFileRoots()
44526
- )
44527
- );
45173
+ ),
45174
+ sync: sync2
45175
+ });
44528
45176
  }
44529
45177
  const uri = `pantheon://artifact/${encodeURIComponent(space)}/${encodeURIComponent(session_id)}/${encodeURIComponent(artifact.name)}`;
44530
45178
  return {
@@ -44534,6 +45182,7 @@ ${GUIDE}` }]
44534
45182
  text: JSON.stringify({
44535
45183
  name: artifact.name,
44536
45184
  encoding: artifact.encoding,
45185
+ sync: sync2,
44537
45186
  note: "The actual file is attached as an MCP resource."
44538
45187
  })
44539
45188
  },
@@ -44564,7 +45213,7 @@ ${GUIDE}` }]
44564
45213
  ok: sync2.ok !== false,
44565
45214
  ...removed,
44566
45215
  sync: sync2,
44567
- note: sync2.ok === false ? `Removed locally but the push failed: ${sync2.error || "unknown error"}. Tell the human it is still in GitHub.` : `Removed ${removed.turns} turns and ${removed.artifacts} files. "${removed.slug}" now holds ${removed.remainingSessions} sessions and ${removed.remainingTurns} turns.`
45216
+ note: sync2.ok === false ? `Removed locally but storage persistence failed: ${sync2.error || "unknown error"}. Tell the human the configured vault storage may still contain it.` : `Removed ${removed.turns} turns and ${removed.artifacts} files. "${removed.slug}" now holds ${removed.remainingSessions} sessions and ${removed.remainingTurns} turns.`
44568
45217
  };
44569
45218
  })
44570
45219
  );
@@ -44573,7 +45222,10 @@ ${GUIDE}` }]
44573
45222
  "pantheon_get_skill",
44574
45223
  "Read one skill from a Pantheon space: guidance written from failures that already happened in this project. Resume lists the names and when to use each; call this for the body before doing work in an area a skill covers. Every claim cites the session and turn it came from, so pantheon_get_turns will show the original moment if the guidance does not fit your situation.",
44575
45224
  { space: external_exports.string(), name: external_exports.string() },
44576
- async ({ space, name }) => safe(() => readSkill(readRoot(home, space), name))
45225
+ async ({ space, name }) => safe(async () => {
45226
+ await refreshForRead(home);
45227
+ return readSkill(readRoot(home, space), name);
45228
+ })
44577
45229
  );
44578
45230
  registerTool(
44579
45231
  server,
@@ -44609,14 +45261,14 @@ ${GUIDE}` }]
44609
45261
  ok: sync2.ok !== false,
44610
45262
  ...saved,
44611
45263
  sync: sync2,
44612
- note: sync2.ok === false ? `Draft saved locally but the push failed: ${sync2.error || "unknown error"}. Tell the human it is not yet in GitHub.` : `Saved as a draft, waiting for review on the space page. Name it in your report; do not explain the draft system.`
45264
+ note: sync2.ok === false ? `Draft saved locally but storage persistence failed: ${sync2.error || "unknown error"}. Tell the human it has not reached the configured vault storage yet.` : `Saved as a draft, waiting for review on the space page. Name it in your report; do not explain the draft system.`
44613
45265
  };
44614
45266
  })
44615
45267
  );
44616
45268
  registerTool(
44617
45269
  server,
44618
45270
  "pantheon_save_skill_drafts",
44619
- `Save one post-handoff review as a single batch of at most ${MAX_REVIEW_DRAFTS} inert drafts. Use this after reading the turns cited by pantheon_handoff or pantheon_skill_review. Submit every justified lesson together so Pantheon can enforce the review limit, reject duplicates before writing, derive support counts from citations, and push once. Do not ask permission; the human approves or rejects drafts in the UI.`,
45271
+ `Save one post-handoff review as a single batch of at most ${MAX_REVIEW_DRAFTS} inert drafts. Use this after reading the turns cited by pantheon_handoff or pantheon_skill_review. Submit every justified lesson together so Pantheon can enforce the review limit, reject duplicates before writing, derive support counts from citations, and persist once. Do not ask permission; the human approves or rejects drafts in the UI.`,
44620
45272
  {
44621
45273
  space: external_exports.string(),
44622
45274
  skills: external_exports.array(skillDraftSchema).min(1).max(MAX_REVIEW_DRAFTS)
@@ -44642,7 +45294,7 @@ ${GUIDE}` }]
44642
45294
  ok: sync2.ok !== false,
44643
45295
  saved,
44644
45296
  sync: sync2,
44645
- note: sync2.ok === false ? `Drafts saved locally but the push failed: ${sync2.error || "unknown error"}. Tell the human they are not yet in GitHub.` : `Saved ${saved.length} draft${saved.length === 1 ? "" : "s"}, waiting for review on the space page.`
45297
+ note: sync2.ok === false ? `Drafts saved locally but storage persistence failed: ${sync2.error || "unknown error"}. Tell the human they have not reached the configured vault storage yet.` : `Saved ${saved.length} draft${saved.length === 1 ? "" : "s"}, waiting for review on the space page.`
44646
45298
  };
44647
45299
  })
44648
45300
  );
@@ -44651,7 +45303,10 @@ ${GUIDE}` }]
44651
45303
  "pantheon_skill_review",
44652
45304
  `Review a Pantheon space for lessons worth writing down as a skill. Trigger: /pantheon-skills <space>. Returns what this space already has \u2014 live and draft names with their triggers \u2014 how many live slots are spent, and the recurring signals its archive still holds: times the human corrected an agent, commands run across several conversations, and any deterministic candidates. These are raw material, not findings \u2014 read the turns with pantheon_get_turns before believing any of them. Judge the conversation you are having now as well, and weigh it heavily: most clients never archive what a tool printed, so a failure you hit in this chat is evidence that exists nowhere else. Then submit AT MOST ${MAX_REVIEW_DRAFTS} together with pantheon_save_skill_drafts, and save none if nothing genuinely recurred \u2014 none is the ordinary answer and a space with no skills is healthier than one with skills nobody reads. Do not repeat an existing live or draft lesson under different wording, and never write a skill for something AGENTS.md or the README already says. Do not ask permission first: a saved skill is a draft and no agent is ever given it until the human promotes it on the space page, which is where they approve or reject. Cite evidence with the turns you read. Report only the names you saved and what each tells a future agent, in a line or two. If no draft is justified, say only "Nothing worth creating a skill for." No preamble about which tools you have or what you are about to do.`,
44653
45305
  { space: external_exports.string(), cwd: external_exports.string().optional() },
44654
- async ({ space, cwd }) => safe(() => skillReview(home, space, allowCapture ? cwd || process.cwd() : void 0))
45306
+ async ({ space, cwd }) => safe(async () => {
45307
+ await refreshForRead(home);
45308
+ return skillReview(home, space, allowCapture ? cwd || process.cwd() : void 0);
45309
+ })
44655
45310
  );
44656
45311
  registerTool(
44657
45312
  server,
@@ -44709,33 +45364,35 @@ async function startMcpServer(home = defaultHome()) {
44709
45364
  }
44710
45365
 
44711
45366
  // src/bootstrap.ts
45367
+ import { existsSync as existsSync10 } from "node:fs";
44712
45368
  import { hostname as hostname3 } from "node:os";
45369
+ import { join as join11 } from "node:path";
44713
45370
 
44714
45371
  // src/connect.ts
44715
45372
  import { execFileSync as execFileSync3 } from "node:child_process";
44716
- import { existsSync as existsSync8, mkdirSync as mkdirSync7, renameSync as renameSync2 } from "node:fs";
45373
+ import { existsSync as existsSync9, mkdirSync as mkdirSync8, renameSync as renameSync4 } from "node:fs";
44717
45374
  import { hostname as hostname2 } from "node:os";
44718
- import { join as join9 } from "node:path";
45375
+ import { join as join10 } from "node:path";
44719
45376
 
44720
45377
  // src/mcp-install.ts
44721
- import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync6, renameSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync6 } from "node:fs";
45378
+ import { existsSync as existsSync8, mkdirSync as mkdirSync7, readFileSync as readFileSync7, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync7 } from "node:fs";
44722
45379
  import { homedir as homedir6 } from "node:os";
44723
- import { dirname as dirname4, join as join8 } from "node:path";
45380
+ import { dirname as dirname5, join as join9 } from "node:path";
44724
45381
  import { fileURLToPath as fileURLToPath2 } from "node:url";
44725
- var here = dirname4(fileURLToPath2(import.meta.url));
45382
+ var here = dirname5(fileURLToPath2(import.meta.url));
44726
45383
  function pantheonBin() {
44727
45384
  const self = fileURLToPath2(import.meta.url);
44728
- if (self.endsWith(".ts")) return join8(here, "../bin/pantheon.mjs");
45385
+ if (self.endsWith(".ts")) return join9(here, "../bin/pantheon.mjs");
44729
45386
  return self;
44730
45387
  }
44731
45388
  function launchEnv(home) {
44732
- const nodeDir = dirname4(process.execPath);
44733
- const binDir = dirname4(pantheonBin());
44734
- const sep = process.platform === "win32" ? ";" : ":";
45389
+ const nodeDir = dirname5(process.execPath);
45390
+ const binDir = dirname5(pantheonBin());
45391
+ const sep2 = process.platform === "win32" ? ";" : ":";
44735
45392
  const pathKey = process.platform === "win32" ? "Path" : "PATH";
44736
45393
  return {
44737
45394
  PANTHEON_HOME: home,
44738
- [pathKey]: [nodeDir, binDir, process.env[pathKey] || process.env.PATH || ""].filter(Boolean).join(sep)
45395
+ [pathKey]: [nodeDir, binDir, process.env[pathKey] || process.env.PATH || ""].filter(Boolean).join(sep2)
44739
45396
  };
44740
45397
  }
44741
45398
  function mcpServer(home, withType = false) {
@@ -44817,9 +45474,9 @@ function stripTrailingCommas(text2) {
44817
45474
  function isPlainObject3(value) {
44818
45475
  return typeof value === "object" && value !== null && !Array.isArray(value);
44819
45476
  }
44820
- function readJson(path) {
44821
- if (!existsSync7(path)) return {};
44822
- const text2 = readFileSync6(path, "utf8").replace(/^\uFEFF/, "");
45477
+ function readJson2(path) {
45478
+ if (!existsSync8(path)) return {};
45479
+ const text2 = readFileSync7(path, "utf8").replace(/^\uFEFF/, "");
44823
45480
  if (!text2.trim()) return {};
44824
45481
  let value;
44825
45482
  try {
@@ -44838,13 +45495,13 @@ function readJson(path) {
44838
45495
  return value;
44839
45496
  }
44840
45497
  function writeAtomic(path, text2) {
44841
- mkdirSync6(dirname4(path), { recursive: true });
45498
+ mkdirSync7(dirname5(path), { recursive: true });
44842
45499
  const temp = `${path}.pantheon-${process.pid}.tmp`;
44843
45500
  try {
44844
- writeFileSync6(temp, text2);
44845
- renameSync(temp, path);
45501
+ writeFileSync7(temp, text2);
45502
+ renameSync3(temp, path);
44846
45503
  } catch (error2) {
44847
- if (existsSync7(temp)) unlinkSync2(temp);
45504
+ if (existsSync8(temp)) unlinkSync2(temp);
44848
45505
  throw error2;
44849
45506
  }
44850
45507
  }
@@ -44853,7 +45510,7 @@ function writeJson(path, data) {
44853
45510
  `);
44854
45511
  }
44855
45512
  function mergeMcpJson(path, home, server, key = "mcpServers") {
44856
- const current = readJson(path);
45513
+ const current = readJson2(path);
44857
45514
  const servers = current[key] ?? {};
44858
45515
  current[key] = { ...servers, pantheon: server };
44859
45516
  writeJson(path, current);
@@ -44863,20 +45520,20 @@ function tomlString(value) {
44863
45520
  }
44864
45521
  function chatgptDesktopPath() {
44865
45522
  if (process.platform !== "darwin") return null;
44866
- return join8(homedir6(), "Library", "Application Support", "ChatGPT", "chatgpt_mcp_config.json");
45523
+ return join9(homedir6(), "Library", "Application Support", "ChatGPT", "chatgpt_mcp_config.json");
44867
45524
  }
44868
45525
  function claudeDesktopPath() {
44869
45526
  if (process.platform === "darwin") {
44870
- return join8(homedir6(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
45527
+ return join9(homedir6(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
44871
45528
  }
44872
45529
  if (process.platform === "win32") {
44873
- return join8(process.env.APPDATA || homedir6(), "Claude", "claude_desktop_config.json");
45530
+ return join9(process.env.APPDATA || homedir6(), "Claude", "claude_desktop_config.json");
44874
45531
  }
44875
- return join8(homedir6(), ".config", "Claude", "claude_desktop_config.json");
45532
+ return join9(homedir6(), ".config", "Claude", "claude_desktop_config.json");
44876
45533
  }
44877
45534
  function upsertCodex(home) {
44878
- const path = join8(homedir6(), ".codex", "config.toml");
44879
- mkdirSync6(dirname4(path), { recursive: true });
45535
+ const path = join9(homedir6(), ".codex", "config.toml");
45536
+ mkdirSync7(dirname5(path), { recursive: true });
44880
45537
  const server = mcpServer(home);
44881
45538
  const args = server.args.map(tomlString).join(", ");
44882
45539
  const block2 = [
@@ -44889,11 +45546,11 @@ function upsertCodex(home) {
44889
45546
  `PANTHEON_HOME = ${tomlString(home)}`,
44890
45547
  ""
44891
45548
  ].join("\n");
44892
- if (!existsSync7(path)) {
45549
+ if (!existsSync8(path)) {
44893
45550
  writeAtomic(path, block2);
44894
45551
  return;
44895
45552
  }
44896
- const existing = readFileSync6(path, "utf8");
45553
+ const existing = readFileSync7(path, "utf8");
44897
45554
  if (existing.includes("[mcp_servers.pantheon]")) {
44898
45555
  const next = existing.replace(
44899
45556
  /\[mcp_servers\.pantheon\][\s\S]*?(?=\n\[(?!mcp_servers\.pantheon)|\s*$)/,
@@ -44983,7 +45640,7 @@ ${quiet}`
44983
45640
  }
44984
45641
  ];
44985
45642
  function writeCodexSkill() {
44986
- const dirs2 = [join8(homedir6(), ".agents", "skills", "pantheon"), join8(homedir6(), ".codex", "skills", "pantheon")];
45643
+ const dirs2 = [join9(homedir6(), ".agents", "skills", "pantheon"), join9(homedir6(), ".codex", "skills", "pantheon")];
44987
45644
  const skill = `---
44988
45645
  name: pantheon
44989
45646
  description: Use when the user types /pantheon-handoff, /pantheon-resume, /pantheon-park, /pantheon-remember, /pantheon-spaces, /pantheon-skills, /pantheon-help, mentions Pantheon, conscience, spaces, or wants to hand off or resume an agent conversation. Always call pantheon_* MCP tools first. Never invent Pantheon space names from memory.
@@ -45066,17 +45723,17 @@ that genuinely fails is worth one line saying what failed \u2014 that is a resul
45066
45723
  not narration.
45067
45724
  `;
45068
45725
  for (const dir of dirs2) {
45069
- mkdirSync6(dir, { recursive: true });
45070
- writeFileSync6(join8(dir, "SKILL.md"), skill);
45726
+ mkdirSync7(dir, { recursive: true });
45727
+ writeFileSync7(join9(dir, "SKILL.md"), skill);
45071
45728
  }
45072
45729
  }
45073
45730
  function writeSlashCommands() {
45074
- const dirs2 = [join8(homedir6(), ".cursor", "commands"), join8(homedir6(), ".claude", "commands")];
45731
+ const dirs2 = [join9(homedir6(), ".cursor", "commands"), join9(homedir6(), ".claude", "commands")];
45075
45732
  for (const dir of dirs2) {
45076
- mkdirSync6(dir, { recursive: true });
45733
+ mkdirSync7(dir, { recursive: true });
45077
45734
  for (const command of slashCommands) {
45078
- writeFileSync6(
45079
- join8(dir, `${command.name}.md`),
45735
+ writeFileSync7(
45736
+ join9(dir, `${command.name}.md`),
45080
45737
  `---
45081
45738
  description: ${command.description}
45082
45739
  ---
@@ -45099,42 +45756,42 @@ function detectApps() {
45099
45756
  const home = homedir6();
45100
45757
  const mac = process.platform === "darwin";
45101
45758
  const win = process.platform === "win32";
45102
- const local = process.env.LOCALAPPDATA || join8(home, "AppData", "Local");
45103
- const roaming = process.env.APPDATA || join8(home, "AppData", "Roaming");
45759
+ const local = process.env.LOCALAPPDATA || join9(home, "AppData", "Local");
45760
+ const roaming = process.env.APPDATA || join9(home, "AppData", "Roaming");
45104
45761
  const evidence = {
45105
45762
  Cursor: [
45106
- join8(home, ".cursor", "extensions"),
45107
- join8(home, ".cursor", "argv.json"),
45108
- join8(home, ".cursor", "cli"),
45109
- ...mac ? ["/Applications/Cursor.app", join8(home, "Applications", "Cursor.app")] : [],
45110
- ...win ? [join8(local, "Programs", "cursor")] : []
45763
+ join9(home, ".cursor", "extensions"),
45764
+ join9(home, ".cursor", "argv.json"),
45765
+ join9(home, ".cursor", "cli"),
45766
+ ...mac ? ["/Applications/Cursor.app", join9(home, "Applications", "Cursor.app")] : [],
45767
+ ...win ? [join9(local, "Programs", "cursor")] : []
45111
45768
  ],
45112
45769
  "Claude Code": [
45113
- join8(home, ".claude", "projects"),
45114
- join8(home, ".claude", "settings.json"),
45115
- join8(home, ".claude", "history.jsonl"),
45116
- join8(home, ".claude", "statsig")
45770
+ join9(home, ".claude", "projects"),
45771
+ join9(home, ".claude", "settings.json"),
45772
+ join9(home, ".claude", "history.jsonl"),
45773
+ join9(home, ".claude", "statsig")
45117
45774
  ],
45118
45775
  "Claude Desktop": [
45119
- ...mac ? ["/Applications/Claude.app", join8(home, "Applications", "Claude.app")] : [],
45120
- ...win ? [join8(local, "AnthropicClaude"), join8(roaming, "Claude", "window-state.json")] : [],
45121
- ...!mac && !win ? [join8(home, ".config", "Claude", "window-state.json")] : []
45776
+ ...mac ? ["/Applications/Claude.app", join9(home, "Applications", "Claude.app")] : [],
45777
+ ...win ? [join9(local, "AnthropicClaude"), join9(roaming, "Claude", "window-state.json")] : [],
45778
+ ...!mac && !win ? [join9(home, ".config", "Claude", "window-state.json")] : []
45122
45779
  ],
45123
- "ChatGPT.app": mac ? ["/Applications/ChatGPT.app", join8(home, "Applications", "ChatGPT.app")] : [],
45780
+ "ChatGPT.app": mac ? ["/Applications/ChatGPT.app", join9(home, "Applications", "ChatGPT.app")] : [],
45124
45781
  Codex: [
45125
- join8(home, ".codex", "sessions"),
45126
- join8(home, ".codex", "auth.json"),
45127
- join8(home, ".codex", "history.jsonl"),
45128
- join8(home, ".codex", "log")
45782
+ join9(home, ".codex", "sessions"),
45783
+ join9(home, ".codex", "auth.json"),
45784
+ join9(home, ".codex", "history.jsonl"),
45785
+ join9(home, ".codex", "log")
45129
45786
  ],
45130
45787
  Windsurf: [
45131
- join8(home, ".codeium", "windsurf"),
45132
- ...mac ? ["/Applications/Windsurf.app", join8(home, "Applications", "Windsurf.app")] : []
45788
+ join9(home, ".codeium", "windsurf"),
45789
+ ...mac ? ["/Applications/Windsurf.app", join9(home, "Applications", "Windsurf.app")] : []
45133
45790
  ]
45134
45791
  };
45135
45792
  const found = /* @__PURE__ */ new Set();
45136
45793
  for (const [name, paths] of Object.entries(evidence)) {
45137
- if (paths.some((path) => existsSync7(path))) found.add(name);
45794
+ if (paths.some((path) => existsSync8(path))) found.add(name);
45138
45795
  }
45139
45796
  return found;
45140
45797
  }
@@ -45158,25 +45815,25 @@ function installMcpClients(home) {
45158
45815
  skipped.push({ name, detail: why.replace(homedir6(), "~") });
45159
45816
  }
45160
45817
  };
45161
- install("Cursor", join8(homedir6(), ".cursor", "mcp.json"), server);
45162
- install("Claude Code", join8(homedir6(), ".claude.json"), mcpServer(home, true));
45818
+ install("Cursor", join9(homedir6(), ".cursor", "mcp.json"), server);
45819
+ install("Claude Code", join9(homedir6(), ".claude.json"), mcpServer(home, true));
45163
45820
  const desktop = claudeDesktopPath();
45164
- if (existsSync7(dirname4(desktop)) || process.platform === "darwin" || process.platform === "win32") {
45821
+ if (existsSync8(dirname5(desktop)) || process.platform === "darwin" || process.platform === "win32") {
45165
45822
  install("Claude Desktop", desktop, server);
45166
45823
  } else {
45167
45824
  skipped.push({ name: "Claude Desktop", detail: "app not found" });
45168
45825
  }
45169
45826
  const chatgpt = chatgptDesktopPath();
45170
- if (chatgpt && existsSync7(dirname4(chatgpt))) install("ChatGPT.app", chatgpt, server);
45171
- const codex = join8(homedir6(), ".codex", "config.toml");
45827
+ if (chatgpt && existsSync8(dirname5(chatgpt))) install("ChatGPT.app", chatgpt, server);
45828
+ const codex = join9(homedir6(), ".codex", "config.toml");
45172
45829
  try {
45173
45830
  upsertCodex(home);
45174
45831
  (found.has("Codex") ? written : ahead).push({ name: "Codex", detail: tilde(codex) });
45175
45832
  } catch {
45176
45833
  skipped.push({ name: "Codex", detail: `could not write ${tilde(codex)}` });
45177
45834
  }
45178
- const windsurf = join8(homedir6(), ".codeium", "windsurf", "mcp_config.json");
45179
- if (existsSync7(dirname4(windsurf))) {
45835
+ const windsurf = join9(homedir6(), ".codeium", "windsurf", "mcp_config.json");
45836
+ if (existsSync8(dirname5(windsurf))) {
45180
45837
  install("Windsurf", windsurf, server);
45181
45838
  } else {
45182
45839
  skipped.push({ name: "Windsurf", detail: "app not found" });
@@ -45193,10 +45850,10 @@ function installMcpClients(home) {
45193
45850
  return { written, ahead, skipped, found: [...found] };
45194
45851
  }
45195
45852
  function removeServerFromJson(path, key = "mcpServers") {
45196
- if (!existsSync7(path)) return false;
45853
+ if (!existsSync8(path)) return false;
45197
45854
  let current;
45198
45855
  try {
45199
- current = readJson(path);
45856
+ current = readJson2(path);
45200
45857
  } catch {
45201
45858
  return false;
45202
45859
  }
@@ -45208,9 +45865,9 @@ function removeServerFromJson(path, key = "mcpServers") {
45208
45865
  return true;
45209
45866
  }
45210
45867
  function removeCodex() {
45211
- const path = join8(homedir6(), ".codex", "config.toml");
45212
- if (!existsSync7(path)) return false;
45213
- const existing = readFileSync6(path, "utf8");
45868
+ const path = join9(homedir6(), ".codex", "config.toml");
45869
+ if (!existsSync8(path)) return false;
45870
+ const existing = readFileSync7(path, "utf8");
45214
45871
  if (!existing.includes("[mcp_servers.pantheon]")) return false;
45215
45872
  const next = existing.replace(/\[mcp_servers\.pantheon\][\s\S]*?(?=\n\[(?!mcp_servers\.pantheon)|\s*$)/, "").replace(/\n{3,}/g, "\n\n").trimEnd();
45216
45873
  writeAtomic(path, next ? `${next}
@@ -45218,12 +45875,12 @@ function removeCodex() {
45218
45875
  return true;
45219
45876
  }
45220
45877
  function removeSlashCommands() {
45221
- const dirs2 = [join8(homedir6(), ".cursor", "commands"), join8(homedir6(), ".claude", "commands")];
45878
+ const dirs2 = [join9(homedir6(), ".cursor", "commands"), join9(homedir6(), ".claude", "commands")];
45222
45879
  let removed = 0;
45223
45880
  for (const dir of dirs2) {
45224
45881
  for (const command of slashCommands) {
45225
- const file = join8(dir, `${command.name}.md`);
45226
- if (!existsSync7(file)) continue;
45882
+ const file = join9(dir, `${command.name}.md`);
45883
+ if (!existsSync8(file)) continue;
45227
45884
  unlinkSync2(file);
45228
45885
  removed += 1;
45229
45886
  }
@@ -45232,32 +45889,32 @@ function removeSlashCommands() {
45232
45889
  }
45233
45890
  function uninstallMcpClients() {
45234
45891
  const removed = [];
45235
- if (removeServerFromJson(join8(homedir6(), ".cursor", "mcp.json"))) removed.push("Cursor");
45236
- if (removeServerFromJson(join8(homedir6(), ".claude.json"))) removed.push("Claude Code");
45892
+ if (removeServerFromJson(join9(homedir6(), ".cursor", "mcp.json"))) removed.push("Cursor");
45893
+ if (removeServerFromJson(join9(homedir6(), ".claude.json"))) removed.push("Claude Code");
45237
45894
  if (removeServerFromJson(claudeDesktopPath())) removed.push("Claude Desktop");
45238
45895
  const chatgpt = chatgptDesktopPath();
45239
45896
  if (chatgpt && removeServerFromJson(chatgpt)) removed.push("ChatGPT.app (shared MCP file)");
45240
45897
  if (removeCodex()) removed.push("ChatGPT.app / Codex");
45241
- if (removeServerFromJson(join8(homedir6(), ".codeium", "windsurf", "mcp_config.json"))) {
45898
+ if (removeServerFromJson(join9(homedir6(), ".codeium", "windsurf", "mcp_config.json"))) {
45242
45899
  removed.push("Windsurf");
45243
45900
  }
45244
45901
  const slash2 = removeSlashCommands();
45245
45902
  if (slash2) removed.push("/pantheon-* commands");
45246
45903
  for (const dir of [
45247
- join8(homedir6(), ".agents", "skills", "pantheon"),
45248
- join8(homedir6(), ".codex", "skills", "pantheon")
45904
+ join9(homedir6(), ".agents", "skills", "pantheon"),
45905
+ join9(homedir6(), ".codex", "skills", "pantheon")
45249
45906
  ]) {
45250
- const file = join8(dir, "SKILL.md");
45251
- if (!existsSync7(file)) continue;
45907
+ const file = join9(dir, "SKILL.md");
45908
+ if (!existsSync8(file)) continue;
45252
45909
  unlinkSync2(file);
45253
45910
  removed.push("ChatGPT / Codex skill");
45254
45911
  break;
45255
45912
  }
45256
45913
  for (const launcher of [
45257
- join8(homedir6(), ".local", "bin", "pantheon-mcp"),
45258
- join8(homedir6(), ".local", "bin", "pantheon-mcp.cmd")
45914
+ join9(homedir6(), ".local", "bin", "pantheon-mcp"),
45915
+ join9(homedir6(), ".local", "bin", "pantheon-mcp.cmd")
45259
45916
  ]) {
45260
- if (!existsSync7(launcher)) continue;
45917
+ if (!existsSync8(launcher)) continue;
45261
45918
  unlinkSync2(launcher);
45262
45919
  removed.push("pantheon-mcp launcher");
45263
45920
  }
@@ -45351,7 +46008,7 @@ var PHASES = {
45351
46008
  };
45352
46009
  var PROGRESS_LINE = new RegExp(`(${Object.keys(PHASES).join("|")}):\\s+(\\d+)%`);
45353
46010
  function runGit(args, onProgress) {
45354
- return new Promise((resolve4, reject) => {
46011
+ return new Promise((resolve5, reject) => {
45355
46012
  const child = spawn("git", args, { stdio: ["ignore", "pipe", "pipe"] });
45356
46013
  let errors = "";
45357
46014
  child.stderr.setEncoding("utf8");
@@ -45365,7 +46022,7 @@ function runGit(args, onProgress) {
45365
46022
  });
45366
46023
  child.on("error", reject);
45367
46024
  child.on("close", (code) => {
45368
- if (code === 0) return resolve4();
46025
+ if (code === 0) return resolve5();
45369
46026
  const detail = errors.split("\n").filter(Boolean).slice(-3).join("\n").trim();
45370
46027
  reject(new Error(detail || `git ${args.find((arg) => !arg.startsWith("-")) || ""} failed`));
45371
46028
  });
@@ -45445,11 +46102,57 @@ async function connect(opts) {
45445
46102
  throw new Error(lastError);
45446
46103
  }
45447
46104
  pairing.done(body.account);
46105
+ if (body.provider === "drive") {
46106
+ if (!body.vaultId || !body.folderId) {
46107
+ throw new Error("Drive pairing response is incomplete.");
46108
+ }
46109
+ const config2 = {
46110
+ version: 2,
46111
+ provider: "drive",
46112
+ home,
46113
+ apiUrl,
46114
+ account: body.account,
46115
+ vaultId: body.vaultId,
46116
+ folderId: body.folderId,
46117
+ machineId: body.machineId
46118
+ };
46119
+ const credentials = { machineSecret: body.machineSecret };
46120
+ const archived2 = quarantineUnownedDriveWorkspace(home, body.vaultId);
46121
+ saveMachineConfig(config2, credentials);
46122
+ mkdirSync8(home, { recursive: true });
46123
+ const prepared = await httpDriveWorkspaceHooks(config2, credentials).refresh(home);
46124
+ if (!prepared.ok && !prepared.stale) {
46125
+ throw new Error(prepared.error || "Could not materialize the Drive vault.");
46126
+ }
46127
+ const result = installMcpClients(home);
46128
+ console.log(
46129
+ report(
46130
+ [
46131
+ field("Connected", body.account),
46132
+ field("Provider", "Google Drive"),
46133
+ field("Vault", `${home} (materialized cache)`),
46134
+ field("Revision", prepared.revision?.id || "pending"),
46135
+ ...archived2 ? [field("Set aside", archived2)] : []
46136
+ ].join("\n"),
46137
+ block("Configured", result.written),
46138
+ block(AHEAD, result.ahead),
46139
+ block("Skipped", result.skipped),
46140
+ nextSteps(result.found)
46141
+ )
46142
+ );
46143
+ return;
46144
+ }
46145
+ if (typeof body.installationId !== "number" || !body.repo || !body.cloneUrl) {
46146
+ throw new Error("GitHub pairing response is incomplete.");
46147
+ }
45448
46148
  saveMachineConfig(
45449
46149
  {
46150
+ version: 2,
46151
+ provider: "github",
45450
46152
  home,
45451
46153
  apiUrl,
45452
46154
  account: body.account,
46155
+ vaultId: body.vaultId || `legacy-github:${body.installationId}`,
45453
46156
  installationId: body.installationId,
45454
46157
  repo: body.repo,
45455
46158
  cloneUrl: body.cloneUrl,
@@ -45457,15 +46160,15 @@ async function connect(opts) {
45457
46160
  },
45458
46161
  { machineSecret: body.machineSecret }
45459
46162
  );
45460
- mkdirSync7(home, { recursive: true });
45461
- const auth = authArgs();
46163
+ mkdirSync8(home, { recursive: true });
46164
+ const auth2 = authArgs();
45462
46165
  const quiet2 = { stdio: ["ignore", "pipe", "pipe"] };
45463
- const fresh = !existsSync8(join9(home, ".git"));
46166
+ const fresh = !existsSync9(join10(home, ".git"));
45464
46167
  let archived = "";
45465
46168
  if (fresh) {
45466
- await clone2(body.cloneUrl, home, auth, "Cloning the vault");
46169
+ await clone2(body.cloneUrl, home, auth2, "Cloning the vault");
45467
46170
  } else {
45468
- archived = await syncVault2(home, body.cloneUrl, auth, quiet2);
46171
+ archived = await syncVault2(home, body.cloneUrl, auth2, quiet2);
45469
46172
  }
45470
46173
  claimCredentials(home, quiet2);
45471
46174
  execFileSync3("git", ["-C", home, "config", "user.name", "Pantheon"], quiet2);
@@ -45506,15 +46209,15 @@ async function connect(opts) {
45506
46209
  )
45507
46210
  );
45508
46211
  }
45509
- async function syncVault2(home, cloneUrl, auth, quiet2) {
46212
+ async function syncVault2(home, cloneUrl, auth2, quiet2) {
45510
46213
  retarget(home, cloneUrl, quiet2);
45511
46214
  const updating = step("Updating the vault");
45512
46215
  try {
45513
- execFileSync3("git", [...auth, "-C", home, "pull", "--ff-only"], quiet2);
46216
+ execFileSync3("git", [...auth2, "-C", home, "pull", "--ff-only"], quiet2);
45514
46217
  updating.done();
45515
46218
  return "";
45516
46219
  } catch (error2) {
45517
- if (!existsSync8(join9(home, ".git"))) {
46220
+ if (!existsSync9(join10(home, ".git"))) {
45518
46221
  updating.fail();
45519
46222
  throw error2;
45520
46223
  }
@@ -45523,7 +46226,7 @@ async function syncVault2(home, cloneUrl, auth, quiet2) {
45523
46226
  updating.note("merging work from another machine");
45524
46227
  try {
45525
46228
  await runGit(
45526
- [...auth, "-C", home, "pull", "--no-rebase", "--no-edit", "--progress"],
46229
+ [...auth2, "-C", home, "pull", "--no-rebase", "--no-edit", "--progress"],
45527
46230
  (percent, phase) => updating.progress(percent, phase)
45528
46231
  );
45529
46232
  } catch (error2) {
@@ -45536,17 +46239,17 @@ async function syncVault2(home, cloneUrl, auth, quiet2) {
45536
46239
  const stamp2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
45537
46240
  const archive = `${home}-${stamp2}`;
45538
46241
  updating.done("belongs to a different account");
45539
- renameSync2(home, archive);
46242
+ renameSync4(home, archive);
45540
46243
  const aside = step("Setting the old vault aside");
45541
46244
  aside.done(archive);
45542
- await clone2(cloneUrl, home, auth, "Cloning the new vault");
46245
+ await clone2(cloneUrl, home, auth2, "Cloning the new vault");
45543
46246
  return archive;
45544
46247
  }
45545
- async function clone2(cloneUrl, home, auth, label) {
46248
+ async function clone2(cloneUrl, home, auth2, label) {
45546
46249
  const cloning = step(label);
45547
46250
  try {
45548
46251
  await runGit(
45549
- [...auth, "clone", "--progress", cloneUrl, home],
46252
+ [...auth2, "clone", "--progress", cloneUrl, home],
45550
46253
  (percent, phase) => cloning.progress(percent, phase)
45551
46254
  );
45552
46255
  } catch (error2) {
@@ -45600,6 +46303,9 @@ function log(message) {
45600
46303
  process.stderr.write(`pantheon: ${message}
45601
46304
  `);
45602
46305
  }
46306
+ function needsTokenBootstrap(config2, token) {
46307
+ return !config2?.bootstrapTokenFingerprint || config2.bootstrapTokenFingerprint !== bootstrapTokenFingerprint(token);
46308
+ }
45603
46309
  async function mintVaultToken(apiUrl, machineId, machineSecret) {
45604
46310
  const res = await fetch(`${apiUrl}/api/cli/token`, {
45605
46311
  method: "POST",
@@ -45646,27 +46352,80 @@ async function bootstrapFromToken(token, opts = {}) {
45646
46352
  }
45647
46353
  }
45648
46354
  if (!body) throw new Error(lastError);
45649
- saveMachineConfig(
45650
- {
46355
+ if (body.provider === "drive") {
46356
+ if (!body.vaultId || !body.folderId) {
46357
+ throw new Error("Drive bootstrap response is incomplete.");
46358
+ }
46359
+ const config3 = {
46360
+ version: 2,
46361
+ provider: "drive",
45651
46362
  home,
45652
46363
  apiUrl,
45653
46364
  account: body.account,
45654
- installationId: body.installationId,
45655
- repo: body.repo,
45656
- cloneUrl: body.cloneUrl,
45657
- machineId: body.machineId
45658
- },
45659
- { machineSecret: body.machineSecret }
46365
+ vaultId: body.vaultId,
46366
+ folderId: body.folderId,
46367
+ machineId: body.machineId,
46368
+ bootstrapTokenFingerprint: bootstrapTokenFingerprint(token)
46369
+ };
46370
+ const credentials2 = { machineSecret: body.machineSecret };
46371
+ const archived2 = quarantineUnownedDriveWorkspace(home, body.vaultId);
46372
+ saveMachineConfig(config3, credentials2);
46373
+ const prepared = await httpDriveWorkspaceHooks(config3, credentials2).refresh(home);
46374
+ if (!prepared.ok && !prepared.stale) {
46375
+ throw new Error(prepared.error || "Could not materialize the Drive vault.");
46376
+ }
46377
+ try {
46378
+ installAgentAssets();
46379
+ } catch {
46380
+ }
46381
+ log(
46382
+ `paired ${body.account} \xB7 Google Drive \xB7 home ${home}${archived2 ? ` \xB7 set aside ${archived2}` : ""}${prepared.pending ? " \xB7 sync pending" : ""}`
46383
+ );
46384
+ return home;
46385
+ }
46386
+ if (typeof body.installationId !== "number" || !body.repo || !body.cloneUrl) {
46387
+ throw new Error("GitHub bootstrap response is incomplete.");
46388
+ }
46389
+ let archived = body.vaultId && previous?.config.vaultId !== body.vaultId ? quarantineUnownedDriveWorkspace(home, body.vaultId) : "";
46390
+ if (!existsSync10(join11(home, ".git"))) {
46391
+ archived ||= quarantineUnownedDriveWorkspace(
46392
+ home,
46393
+ body.vaultId || `legacy-github:${body.installationId}`
46394
+ );
46395
+ }
46396
+ const config2 = {
46397
+ version: 2,
46398
+ provider: "github",
46399
+ home,
46400
+ apiUrl,
46401
+ account: body.account,
46402
+ vaultId: body.vaultId || `legacy-github:${body.installationId}`,
46403
+ installationId: body.installationId,
46404
+ repo: body.repo,
46405
+ cloneUrl: body.cloneUrl,
46406
+ machineId: body.machineId
46407
+ };
46408
+ const credentials = { machineSecret: body.machineSecret };
46409
+ saveMachineConfig(
46410
+ config2,
46411
+ credentials
45660
46412
  );
45661
46413
  const vaultToken = await mintVaultToken(apiUrl, body.machineId, body.machineSecret);
45662
46414
  const clone3 = ensureVaultClone(home, body.cloneUrl, vaultToken);
45663
46415
  if (!clone3.ok) throw new Error(clone3.error || "Could not clone the vault.");
46416
+ saveMachineConfig(
46417
+ {
46418
+ ...config2,
46419
+ bootstrapTokenFingerprint: bootstrapTokenFingerprint(token)
46420
+ },
46421
+ credentials
46422
+ );
45664
46423
  try {
45665
46424
  installAgentAssets();
45666
46425
  } catch {
45667
46426
  }
45668
46427
  log(
45669
- `${body.switchedFrom ? `switched ${body.switchedFrom} \u2192 ${body.account}` : `paired ${body.account}`} \xB7 vault ${body.repo} \xB7 home ${home}${body.switchedFrom ? " \xB7 reconnect remote MCP clients" : ""}`
46428
+ `${body.switchedFrom ? `switched ${body.switchedFrom} \u2192 ${body.account}` : `paired ${body.account}`} \xB7 vault ${body.repo} \xB7 home ${home}${archived ? ` \xB7 set aside ${archived}` : ""}${body.switchedFrom ? " \xB7 reconnect remote MCP clients" : ""}`
45670
46429
  );
45671
46430
  return home;
45672
46431
  }
@@ -45677,7 +46436,7 @@ async function handleGitCredential(operation) {
45677
46436
  const request = parse3(await readStdin());
45678
46437
  if (request.host && request.host !== "github.com") return;
45679
46438
  const stored = loadMachineConfig();
45680
- if (!stored) return;
46439
+ if (!stored || stored.config.provider !== "github") return;
45681
46440
  const res = await fetch(`${stored.config.apiUrl}/api/cli/token`, {
45682
46441
  method: "POST",
45683
46442
  headers: {
@@ -45699,14 +46458,14 @@ function parse3(input) {
45699
46458
  return fields;
45700
46459
  }
45701
46460
  function readStdin() {
45702
- return new Promise((resolve4) => {
46461
+ return new Promise((resolve5) => {
45703
46462
  let data = "";
45704
46463
  process.stdin.setEncoding("utf8");
45705
46464
  process.stdin.on("data", (chunk) => {
45706
46465
  data += chunk;
45707
46466
  });
45708
- process.stdin.on("end", () => resolve4(data));
45709
- setTimeout(() => resolve4(data), 50);
46467
+ process.stdin.on("end", () => resolve5(data));
46468
+ setTimeout(() => resolve5(data), 50);
45710
46469
  });
45711
46470
  }
45712
46471
 
@@ -45768,7 +46527,7 @@ function printSpaces() {
45768
46527
  }
45769
46528
 
45770
46529
  // src/status.ts
45771
- import { existsSync as existsSync9 } from "node:fs";
46530
+ import { existsSync as existsSync11 } from "node:fs";
45772
46531
  function printStatus() {
45773
46532
  const stored = loadMachineConfig();
45774
46533
  if (!stored) {
@@ -45776,13 +46535,20 @@ function printStatus() {
45776
46535
  return;
45777
46536
  }
45778
46537
  const { config: config2 } = stored;
46538
+ const provider = config2.provider === "drive" ? [
46539
+ field("Provider", "Google Drive"),
46540
+ field("Account", config2.account),
46541
+ field("Folder", config2.folderId)
46542
+ ] : [
46543
+ field("GitHub", config2.account),
46544
+ field("Install", String(config2.installationId)),
46545
+ field("Repo", `${config2.repo} (private)`)
46546
+ ];
45779
46547
  console.log(
45780
46548
  report(
45781
46549
  [
45782
- field("GitHub", config2.account),
45783
- field("Install", String(config2.installationId)),
45784
- field("Repo", `${config2.repo} (private)`),
45785
- field("Vault", `${config2.home}${existsSync9(config2.home) ? "" : " (missing)"}`),
46550
+ ...provider,
46551
+ field("Vault", `${config2.home}${existsSync11(config2.home) ? "" : " (missing)"}`),
45786
46552
  field("API", config2.apiUrl),
45787
46553
  field("Machine", config2.machineId)
45788
46554
  ].join("\n")
@@ -45795,10 +46561,16 @@ async function sync() {
45795
46561
  const stored = loadMachineConfig();
45796
46562
  if (!stored) throw new Error("Not connected. Run pantheon connect <code> first.");
45797
46563
  const vault = step("Syncing the vault");
45798
- const result = await syncVault(stored.config.home, { push: true, message: "pantheon sync" });
46564
+ const driveHooks = stored.config.provider === "drive" ? httpDriveWorkspaceHooks(stored.config, stored.credentials) : null;
46565
+ const result = driveHooks ? await driveHooks.persist(stored.config.home, "pantheon sync") : await syncVault(stored.config.home, {
46566
+ push: true,
46567
+ message: "pantheon sync"
46568
+ });
45799
46569
  if (!result.ok) {
45800
46570
  vault.fail();
45801
- throw new Error(result.error || "Sync failed");
46571
+ throw new Error(
46572
+ `${result.error || "Sync failed"}${result.pending ? " Changes remain saved locally and will retry on the next sync." : ""}`
46573
+ );
45802
46574
  }
45803
46575
  const bits2 = [
45804
46576
  result.committed ? "committed" : "clean",
@@ -45806,6 +46578,13 @@ async function sync() {
45806
46578
  result.pushed ? "pushed" : null
45807
46579
  ].filter(Boolean);
45808
46580
  vault.done(bits2.join(", "));
46581
+ if (driveHooks) {
46582
+ const refreshed = await driveHooks.refresh(stored.config.home);
46583
+ if (!refreshed.ok) {
46584
+ throw new Error(refreshed.error || "Drive refresh failed after sync.");
46585
+ }
46586
+ return;
46587
+ }
45809
46588
  const shared = step("Refreshing shared consciences");
45810
46589
  const pull = await pullShares(stored.config.home, {
45811
46590
  onProgress: (done, total) => {
@@ -45932,7 +46711,7 @@ async function main() {
45932
46711
  }
45933
46712
  if (cmd === "mcp") {
45934
46713
  let stored = loadMachineConfig();
45935
- if (!stored && process.env.PANTHEON_TOKEN) {
46714
+ if (process.env.PANTHEON_TOKEN && needsTokenBootstrap(stored?.config, process.env.PANTHEON_TOKEN)) {
45936
46715
  try {
45937
46716
  await bootstrapFromToken(process.env.PANTHEON_TOKEN, { home: process.env.PANTHEON_HOME });
45938
46717
  stored = loadMachineConfig();